From: Decare on

Hi,
I am reading a book on GNU make. There is an example
in it puzzled me. The makefile is as follows:

VPATH = src include
CPPFLAGS = -I include

LEX=flex
SOURCE=count_words.c lexer.c counter.c

count_words: counter.o lexer.o -lfl

-include $(subst .c,.d,$(SOURCE))

%.d: %.c
$(CC) -M $(CPPFLAGS) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$

and it produce the following message:

cc -M -I include src/counter.c > counter.d.$$; \
sed 's,\(counter\)\.o[ :]*,\1.o counter.d : ,g' < counter.d.$$ > counter.d; \
rm -f counter.d.$$
flex -t src/lexer.l > lexer.c
cc -M -I include lexer.c > lexer.d.$$; \
sed 's,\(lexer\)\.o[ :]*,\1.o lexer.d : ,g' < lexer.d.$$ > lexer.d; \
rm -f lexer.d.$$
cc -M -I include src/count_words.c > count_words.d.$$; \
sed 's,\(count_words\)\.o[ :]*,\1.o count_words.d : ,g' < count_words.d.$$ > count_words.d; \
rm -f count_words.d.$$
rm lexer.c
flex -t src/lexer.l > lexer.c
cc -M -I include lexer.c > lexer.d.$$; \
sed 's,\(lexer\)\.o[ :]*,\1.o lexer.d : ,g' < lexer.d.$$ > lexer.d; \
rm -f lexer.d.$$
cc -I include -c -o count_words.o src/count_words.c
cc -I include -c -o counter.o src/counter.c
cc -I include -c -o lexer.o lexer.c
cc count_words.o counter.o lexer.o /lib/libfl.a -o count_words

The flex command has executed twice, but the first one has deleted the
lexer.c, whereas the second not. If they two invoked the same implicit
rule, why resulting in different effects?

--
cogito ergo sum!