1

Say I have a makefile called Foo, and it has a variable called Bar.

in Foo I have:

Bar := /some/initial/path
Other_var := ${Bar}/more/paths

and then in my main makefile I use Foo

include Path/to/Foo

But How can I make it such in my main makefile I can set Bar and have my value of Bar be the one used in Foo? I tried using eval but the := is a real challenge. A big goal is to not change the source of Foo.

2

My GNU make 4.0 online info says if you use the override keyword on an assignment, normally used to override command line var=value settings, then the value will not be changed by further assignments which do not use the override keyword.

So you could try in your main makefile:

override Bar := myvalueforbar
include Path/to/Foo
  • Yes! this was correct, override was my next thought to try out too – Edgar Aroutiounian Mar 3 '16 at 17:35
1

If you define Bar before including Foo in your Makefile, then the Bar is available in Foo.

E.g. I have the following in each of my Makefile's for Python packages (the first two lines differing per Makefile of course):

UTILNAME:=yaml
PKGNAME:=ruamel.yaml
VERSION:=$(shell python setup.py --version)

include ~/.config/ruamel_util_new/Makefile.inc

And in the Makefile.inc I have generic routines that among other things now how to create a distribution file:

DIST:=dist/$(PKGNAME)-$(VERSION).tar.gz
WHL:=dist/$(PKGNAME)-$(VERSION)-py*-any.whl

$(DIST): $(SRC)
        make check
        python setup.py sdist
  • I don't understand how this answers the question.  Your Makefile.inc doesn't (re)define PKGNAME or VERSION.  The OP's Foo (subordinate makefile) does (re)define Bar, and he has a goal of not modifying Foo. – Scott Mar 3 '16 at 10:53
  • as I understand it the OP wants to know how to create Makefile and Foo so that Foo doesn't need changing after that even if Bar changes. – Anthon Mar 3 '16 at 13:23
  • Well, we interpreted the question differently.  The answer that the OP accepted suggests that my interpretation was correct (which seems to happen slightly more than 51% of the time    :-)    ). – Scott Mar 3 '16 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.