I am trying to create a makefile that will auto-discover dependencies
by using what I call "iteration thru makefile reloading" (no recursive
make).
It doesn't work for some reason (but found a workaround) and I would like to understand the problem....
Following, is a "simple makefile" showing it.
ifneq "$(words $(wildcard c*))" "6"
$(warning doing setup)
# depending on make version, ';' may be backslashed ...
$(shell x=0; while test $$x -lt 6; do f=c$$x; x=`expr $$x + 1`; echo $$x > $$f ; done; echo "" > $$f)
endif
Usually, it stops after the second iteration, and I suspected it had
something to do with the "1 second precision" of the file timestamps.
This seems to be confirmed by the fact that adding a "1 second delay" somewhere makes it work fine.
What I don't understand, is the following debug info I get when running (g)make with -d and -r options.
..................................
Must remake target `p1'.
echo "x += `cat c1`" > p1
Putting child 0x08072b80 (p1) PID 17482 on the chain.
Live child 0x08072b80 (p1) PID 17482
Reaping winning child 0x08072b80 PID 17482
Removing child 0x08072b80 PID 17482 from chain.
Successfully remade target file `p1'.
Finished prerequisites of target file `a'.
Prerequisite `p0' is older than target `a'.
--> Prerequisite `p1' is newer than target `a'.
--> ?? No need to remake target `a'.
Considering target file `makefile.2'.
...................................
With a sleep I get the expected thing:
...................................
Must remake target `p1'.
echo "x += `cat c1`" > p1
Putting child 0x08072b60 (p1) PID 17441 on the chain.
Live child 0x08072b60 (p1) PID 17441
Reaping winning child 0x08072b60 PID 17441
Removing child 0x08072b60 PID 17441 from chain.
Successfully remade target file `p1'.
Finished prerequisites of target file `a'.
Prerequisite `p0' is older than target `a'.
--> Prerequisite `p1' is newer than target `a'.
--> ok Must remake target `a'.
cat p0 p1 > a; sleep 1
Putting child 0x08072b60 (a) PID 17444 on the chain.
........................................