Re: Script to compile all files with a given extension?



The Natural Philosopher staggered into the Black Sun and said:
Dan Espen wrote:
Dances With Crows writes:
sk8terg1rl staggered into the Black Sun and said:
Found out what make does with man make just now ;-) Unfortunately I
don't think this would help much. Depending on the purpose of the
programs, they have different names. This would mean I would need a
makefile for each subset of programs.
Makefiles can have multiple dependencies and action lines. Like so:
OBJS=crud.o barf.o junk.o
SRCS=crud.c barf.c junk.c
Once you have $(SRC) $(OBJS) is simply:
OBJS:=$(subst .c,.o,$(SRC))

The book that I was reading when I wrote that makefile in 1998 was ...
slightly out of date and aimed at as much cross-platformability as
possible, hence no GNU make extensions. (And why is it that everything
that does string manipulation feels the need to invent its own syntax
for s/NN/MM/ ?)

This assumes 1 program and many subs. I prefer something like:
SRCS:=$(wildcard *.c)
MAINS:=program.c program2.c
SUBS:=$(filter-out $(MAINS),$(SRCS))

Then you need specific rules for the mains and generic rules for the
subs.
Writing the makefile is one of the main jobs to do in any compilation
project. It doesn't just happen naturally ;-)

Systems have sub-systems and sub-systems have sub-systems and so on ad
infinitum -- which is why we're always starting over.
-- Epigrams in Programming, ACM SIGPLAN Sept. 1982

--
Kimono dragon: found mainly on Pacific islands and atolls, this is the
more dangerous version of the somewhat placid bathrobe gecko.
--jghanc
Matt G|There is no Darkness in Eternity/But only Light too dim for us to see
.