On Sun, 2018-10-07 at 01:29 +0000, Bogdan wrote:
> $(MAKE_DIR)/%.mk: $(SRC_DIR)/%.m4 | $(MAKE_DIR)/$(MODULE); m4 $< $@
> $(MAKE_DIR)/$(MODULE): ; mkdir -p $@
> 
> I know MODULE isn't defined at the point of the inclusion; that is
> because I want the macro to expand to the empty string such that the
> "makefiles" subdirectory can be created. This macro will be relevant
> later and should expand on usage.

This is your problem.  You may want the macro to expand on usage, but
that's not how it works.

The GNU make manual section describing how variable expansion works is
here: https://www.gnu.org/software/make/manual/html_node/Reading-Makefiles.html

It shows that variables appearing in a target or prerequisite are
expanded immediately when the rule is parsed. At that time the variable
$(MODULE) is not set, so the rule is parsed like this:

  makefiles/%.mk: src/%.m4 | makefiles/ ; m4 $< $@

There are various ways to do what you want.  One option is secondary
expansion: 
https://www.gnu.org/software/make/manual/html_node/Secondary-Expansion.html

which would look like:

  .SECONDEXPANSION:
  $(MAKE_DIR)/%.mk: $(SRC_DIR)/%.m4 | $(MAKE_DIR)/$$(MODULE); m4 $< $@
  $(MAKE_DIR)/$$(MODULE): ; mkdir -p $@

(note the extra "$" when referencing the MODULE variable)


_______________________________________________
Help-make mailing list
Help-make@gnu.org
https://lists.gnu.org/mailman/listinfo/help-make

Reply via email to