Wed 21 Jul 2010 07:43:12 AM UTC, original submission:
I have found a case where 'make' will update a target, and then fail to update things that depend on that target.
Consider the following Makefile (also attached in case the indentation gets messed up):
all: test
PREVIOUS_VAR := $(shell cat previous_var)
ifneq ($(PREVIOUS_VAR),$(VAR))
previous_var:
echo $(VAR) > previous_var
.PHONY: previous_var
endif
test: test.o
$(LD) -o test test.o
test.o: test.c previous_var
$(CC) -o test.o test.c
As you can see, the Makefile attempts to remember the value of VAR= that was passed in on the command line, and rebuild the 'test' program whenever the value changes.
Now, lets try it out:
/source/test $ make VAR=abc
cat: previous_var: No such file or directory
echo abc > previous_var
cc -o test.o test.c
ld -o test test.o
/source/test $ make VAR=abc
make: Nothing to be done for `all'.
/source/test $ make VAR=def
echo def > previous_var
cc -o test.o test.c
ld -o test test.o
All is looking good so far. However:
/source/test $ while true ; do make VAR=abc ; make VAR=def ; done
echo abc > previous_var
cc -o test.o test.c
ld -o test test.o
echo def > previous_var
cc -o test.o test.c
echo abc > previous_var
cc -o test.o test.c
echo def > previous_var
cc -o test.o test.c
echo abc > previous_var
cc -o test.o test.c
^C
What happened to the link step? Why isn't it being executed anymore? Lets look at the debug output:
Must remake target `test.o'.
cc -o test.o test.c
Putting child 0x018f3120 (test.o) PID 3074 on the chain.
Live child 0x018f3120 (test.o) PID 3074
Reaping winning child 0x018f3120 PID 3074
Removing child 0x018f3120 PID 3074 from chain.
Successfully remade target file `test.o'.
Finished prerequisites of target file `test'.
Prerequisite `test.o' is older than target `test'.
No need to remake target `test'.
How can 'test.o' possibly be older than 'test'? 'test.o' just got rebuilt! It's the newest thing on the entire system.
|