I can't understand chapter 3 of official gmake documentation starting from section 3.5
https://www.gnu.org/software/make/manual/make.html#Remaking-Makefiles
Docs say: ... after reading in all makefiles make will consider each as a goal target and attempt to update it. If a makefile has a rule which says how to update it ...., it will be updated if necessary. After all makefiles have been checked, if any have actually been changed, make starts with a clean slate and reads all the makefiles over again. (It will also attempt to update each of them over again, but normally this will not change them again, since they are already up to date.) Each restart will cause the special variable MAKE_RESTARTS to be updated.
So I try with this mkfile ( presence of the -include as G.M. has suggested changes nothing ):
all:
echo all $(MAKE_RESTARTS) aaa
#-include: mkfile
mkfile:
echo touch
touch mkfile
I expect that after mkfile runs first time mkfile modification time changed and make must run it again and again. But nothing happens:
$ make -f mkfile
echo all aaa
all aaa
$
Moreover, target "mkfile" not called as expecting from docs: after reading in all makefiles make will consider each as a goal target and attempt to update it.
What I'm misunderstand ? Can you, please, give an example of what docs mean about "remading" makefiles?
UPD: I've tried Andreas' suggestions but got strange results again :
- original mkfile but run with --always-make
$ make --always-make -f mkfile
echo touch
touch
touch mkfile
echo all 1 aaa
all 1 aaa
here target "mkfile" runs once and target "all" runs once too. The results of consequence runs are repeatable.
- If I change target "mkfile" to force run, results a strange and differ from invocation to invocation: mkfile:
all:
echo all $(MAKE_RESTARTS) aaa
mkfile: force
echo touch
touch mkfile
force: ;
results:
$ make -f mkfile
echo touch
touch
touch mkfile
echo touch
touch
touch mkfile
echo touch
touch
touch mkfile
................
touch mkfile
echo touch
touch
touch mkfile
echo all 16 aaa
all 16 aaa
$ make -f mkfile
echo touch
touch
touch mkfile
echo touch
touch
touch mkfile
echo touch
touch
touch mkfile
echo all 2 aaa
all 2 aaa
$ make -f mkfile
echo touch
touch
touch mkfile
...............
touch mkfile
echo all 13 aaa
all 13 aaa
$
UPD2 - about MAKE_RESTARTS
--always-make respects MAKE_RESTARTS only if makefile's target has no prerequisites.
mkfile:
all:
echo all $(MAKE_RESTARTS) aaa
mkfile:
echo touch $(MAKE_RESTARTS)
sleep 0.5
touch mkfile
result:
$ make --always-make -f mkfile
echo touch
touch
sleep 0.5
touch mkfile
echo all 1 aaa
all 1 aaa
$
if makefile's target has force prerequisite, loop is infinite (I even try to set MAKE_RESTARTS by force to value greater than 0 )
mkfile:
MAKE_RESTARTS := 1
all:
echo all $(MAKE_RESTARTS) aaa
mkfile: force
echo touch $(MAKE_RESTARTS)
sleep 0.5
touch mkfile
force: ;
result:
$ make --always-make -f mkfile
echo touch 1
touch 1
sleep 0.5
touch mkfile
echo touch 1
touch 1
sleep 0.5
touch mkfile
echo touch 1
touch 1
sleep 0.5
touch mkfile
^C