autoconf: Macros and Submakes
1
1 12.7 `make macro=value' and Submakes
1 ====================================
1
1 A command-line variable definition such as `foo=bar' overrides any
1 definition of `foo' in a makefile. Some `make' implementations (such
1 as GNU `make') propagate this override to subsidiary invocations of
1 `make'. Some other implementations do not pass the substitution along
1 to submakes.
1
1 $ cat Makefile
1 foo = foo
1 one:
1 @echo $(foo)
1 $(MAKE) two
1 two:
1 @echo $(foo)
1 $ make foo=bar # GNU make 3.79.1
1 bar
1 make two
1 make[1]: Entering directory `/home/adl'
1 bar
1 make[1]: Leaving directory `/home/adl'
1 $ pmake foo=bar # BSD make
1 bar
1 pmake two
1 foo
1
1 You have a few possibilities if you do want the `foo=bar' override
1 to propagate to submakes. One is to use the `-e' option, which causes
1 all environment variables to have precedence over the makefile macro
1 definitions, and declare foo as an environment variable:
1
1 $ env foo=bar make -e
1
1 The `-e' option is propagated to submakes automatically, and since
1 the environment is inherited between `make' invocations, the `foo'
1 macro is overridden in submakes as expected.
1
1 This syntax (`foo=bar make -e') is portable only when used outside
1 of a makefile, for instance from a script or from the command line.
1 When run inside a `make' rule, GNU `make' 3.80 and prior versions
1 forget to propagate the `-e' option to submakes.
1
1 Moreover, using `-e' could have unexpected side effects if your
1 environment contains some other macros usually defined by the makefile.
1 (See also the note about `make -e' and `SHELL' below.)
1
1 If you can foresee all macros that a user might want to override,
1 then you can propagate them to submakes manually, from your makefile:
1
1 foo = foo
1 one:
1 @echo $(foo)
1 $(MAKE) foo=$(foo) two
1 two:
1 @echo $(foo)
1
1 Another way to propagate a variable to submakes in a portable way is
1 to expand an extra variable in every invocation of `$(MAKE)' within
1 your makefile:
1
1 foo = foo
1 one:
1 @echo $(foo)
1 $(MAKE) $(SUBMAKEFLAGS) two
1 two:
1 @echo $(foo)
1
1 Users must be aware that this technique is in use to take advantage
1 of it, e.g. with `make foo=bar SUBMAKEFLAGS='foo=bar'', but it allows
1 any macro to be overridden. Makefiles generated by `automake' use this
1 technique, expanding `$(AM_MAKEFLAGS)' on the command lines of submakes
1 (⇒Automake (automake)Subdirectories.).
1