Looking for some help passing variables from one level to the next in a makefile. I have a source tree that needs to be built to run on various target architectures. To keep the higher level makefile clean I created separate makefiles that contain architecture specific information and include only the one that is required using the include directive :)
Later in the makefile I transfer to another directory to build the source files. The build fails and I see that the failure is caused by the architecture-specific variables not being passed.
ifeq ($(ARCH), my_arch) |
include build/my_archdefs.mk | section 1
endif |
<more commands>
debug:
$(MAKE) -C src debug
The makefile to build the code tree is in the src directory. As a stop gap measure I included section 1 referenced above in the lower level makefile and in this case I noticed that the variable ARCH was not being passed down.
Here are a couple of links I found that seemed related but I'm not able to figure out what I need to do make this work. http://www.gnu.org/software/make/manual/html_node/Options_002fRecursion.html#Options_002fRecursion http://www.gnu.org/software/make/manual/html_node/Include.html
It seems to me that the info I need is lurking in the links I referenced above but I'm just not seeing it. Any pointers will be much appreciated.
Thanks.
Variable values of the top-level make can be passed to the sub- make through the environment by explicit request. These variables are defined in the sub- make as defaults, but they do not override variables defined in the makefile used by the sub- make unless you use the ' -e ' switch (see Summary of Options).
The include directive tells make to suspend reading the current makefile and read one or more other makefiles before continuing. The directive is a line in the makefile that looks like this: include filenames … filenames can contain shell file name patterns.
= defines a recursively-expanded variable. := defines a simply-expanded variable.
This link should help: http://www.gnu.org/software/make/manual/html_node/Variables_002fRecursion.html#Variables_002fRecursion
In your top level Makefile just add the line export
and all of your variables will be exported to your submakes.
Example:
File Makefile
:
ID=asdf
export
all:
@echo ${ID}
@make -f Makefile2
File Makefile2
:
all:
@echo ${ID}
Output:
$ make
asdf
make[1]: Entering directory `/home/user/Desktop/a'
asdf
make[1]: Leaving directory `/home/user/Desktop/a'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With