I have a test directory with a makefile like:
EXECS = pgm1 pgm2 pgm3 pgm4 pgm5 ...
OBJS = $(addsuffix .o, $(EXECS))
all: $(EXECS)
%.o : %.c
$(CC) -c $< -o $@ $(IFLAGS)
$(EXECS) : $(OBJS)
$(CC) $@.o -o $@ $(LFLAGS)
pgm1 : pgm1.o
$(CC) $< -o $@ $(LFLAGS)
% : %.o
$(CC) $< -o $@ $(LFLAGS)
The pgm1 : pgm1.o
link rule works, but I don't want to have to enter one for each program.
The % : %.o
rule doesn't work (it picks up a default rule with no link flags)
The $(EXECS) : $(OBJS)
rule works, but all the executables are linked every time a .o
file changes. This doesn't really matter 'cos the programs are small, but it would be nice to fix.
Any suggestions, please?
Later...
Thanks to all for your suggestions. The solution is a gloriously simple combination of all of them:
% : %.c
$(CC) $(IFLAGS) $< -o $@ $(LFLAGS)