I have a directory structure where I want one main makefile in my main folder, and then another makefile in both my test and src folder.
In my main makefile, I have directives for both test / all that call the individual folder makefiles. I'm trying to declare variables in my main makefile and have them accessible to those other folders.
For instance in my main Makefile
PACKAGES = jansson mysql ....
all:
do something here
test:
cd test
make test
And then in my test/Makefile I want to be able to access the previous PACKAGES variable and add this makefile's individual dependencies onto it.
In the test/Makefile
PACKAGES += googletest googlemock
test
do something here
Could anyone help me solve this problem?
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).
If you use more than one ' -f ' or ' --file ' option, you can specify several makefiles. All the makefiles are effectively concatenated in the order specified. The default makefile names GNUmakefile , makefile and Makefile are not checked automatically if you specify ' -f ' or ' --file '.
You can create another file, for instance Makefile.variable
where those shared variables are defined and include the file using
include $(PATHTOSHAREDMAKEFILE)/Makefile.variable
Look at the include manual for more information
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