help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem Creating Directories


From: Paul Smith
Subject: Re: Problem Creating Directories
Date: Sun, 07 Oct 2018 09:01:16 -0400

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)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]