Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share variables between makefiles

Tags:

makefile

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?

like image 933
JonMorehouse Avatar asked Feb 14 '13 17:02

JonMorehouse


People also ask

How can we pass variables from top level makefile to sub makefiles?

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).

Can you have two makefiles?

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 '.


1 Answers

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

like image 148
UmNyobe Avatar answered Sep 27 '22 22:09

UmNyobe