c - Gnu-Make fails to include a makefile -
from docs:
the
includedirective tellsmakesuspend reading current makefile , read 1 or more other makefiles before continuing. directive line in makefile looks this:include filenames...filenames can contain shell file name patterns.
now, given makefile:
# define 'include' command-line. ifdef include # create included makefile $(shell echo 'all : ;' >makefile.include) # , include it. # docs say: "filenames can contain shell file name patterns." include *.include else endif running, get:
$ rm -rf makefile.include && make include=1 makefile:6: *.include: no such file or directory so, happened here? had:
created makefile included, in:
$(shell echo 'all : ;' >makefile.include)and later included makefile, given can using "shell file name patterns", quoted above documentation - , thus, have in makefile:
include *.include
so, why did gnu-make failed find newly-created makefile?
the problem facing not of inclusion, of order of execution.
make not procedural language, instead declarative one, order-of-execution gets bit tricky.
in specific case, make parse entire makefile in first pass, including include statements, resulting in erroneous makefile, since there no makefile.include yet.
it then execute shell command create makefile.include (but again late: inclusion have happened before).
a second run of make correctly include makefile.include.
note:
the same true both directly using include *.include , include $(wildcard *.include) former result in error (since latter expand *.include empty set (not) included, whereas former try include literal *.include - similar stray cat *.nonexistent on shell).
Comments
Post a Comment