Discussion:
Why is --include-dir option effective only in sub make ?
Masahiro Yamada
2018-09-13 05:18:32 UTC
Permalink
Hello,


I wonder why --include-dir does not become
effective in the current Makefile.

Here is the test case.



[ Not working sample ]


-------------(Makefile)--------------
MAKEFLAGS += --include-dir=foo

include inc.mk

all:
@echo hello
-------------(Makefile END)------------


$ mkdir foo
$ touch foo/inc.mk
$ make
Makefile:3: inc.mk: No such file or directory
make: *** No rule to make target 'inc.mk'. Stop.






[ Working sample ]

-------------(Makefile)--------------
MAKEFLAGS += --include-dir=foo

ifneq ($(IN_SUBMAKE),1)
all:
@$(MAKE) IN_SUBMAKE=1

else

include inc.mk

all:
@echo hello

endif
-------------(Makefile END)------------


$ mkdir foo
$ touch foo/inc.mk
$ make
make[1]: Entering directory '/home/masahiro/workspace'
hello
make[1]: Leaving directory '/home/masahiro/workspace'





From the example above, --include-dir is effective
only after diving into sub make.

Is this an intentional behavior?


Is there a way to make it effective in the current make?
--
Best Regards
Masahiro Yamada
Paul Smith
2018-09-13 12:34:52 UTC
Permalink
Post by Masahiro Yamada
I wonder why --include-dir does not become
effective in the current Makefile.
In order for this to work, the MAKEFLAGS variable would have to be re-
parsed every time MAKEFLAGS was set in the makefile and that's not how
it works: MAKEFLAGS is re-parsed once after all the makefiles are read.

There are various potential oddities and unexpected outcomes if the
variable is re-parsed every time, just as this unexpected outcome (not
being able to add --include-dir and have it take effect immediately) if
the variable is NOT re-parsed every time.

In this case, could you just write:

include foo/inc.mk

directly?
Masahiro Yamada
2018-09-14 01:26:26 UTC
Permalink
Hi Paul,
Post by Paul Smith
Post by Masahiro Yamada
I wonder why --include-dir does not become
effective in the current Makefile.
In order for this to work, the MAKEFLAGS variable would have to be re-
parsed every time MAKEFLAGS was set in the makefile and that's not how
it works: MAKEFLAGS is re-parsed once after all the makefiles are read.
There are various potential oddities and unexpected outcomes if the
variable is re-parsed every time, just as this unexpected outcome (not
being able to add --include-dir and have it take effect immediately) if
the variable is NOT re-parsed every time.
Ah, I see.

Thanks for clear explanation!
Post by Paul Smith
include foo/inc.mk
directly?
Yes, I can.


My impression is, --include-dir is not so useful as VPATH.

In fact, the Linux kernel build system uses --include-dir,
but there is no strong reason to search included makefiles
in multiple location.


Thanks.
--
Best Regards
Masahiro Yamada
Loading...