Share variables between makefiles

makefile

Solution

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

Problem

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?

Original source