help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: passing quoted variables to submakes


From: psmith
Subject: Re: passing quoted variables to submakes
Date: Thu, 2 Feb 2006 17:49:13 -0500

%% Johann Cairns <address@hidden> writes:

  jc> Makefile A looks like this:
  jc> World::
  jc>   cd subdir && $(MAKE) BSTRAPFLAGS="$(BSTRAPFLAGS)"

This is incorrect.

GNU make automatically makes arrangements to forward all command-line
overrides into sub-makes.  If you put them on the command line again
like this, then you have to manage the quoting issues yourself which, as
you've discovered, can be quite challenging.  Note this is not an issue
with make per se, nor is it anything make can help you with: these
commands are passed verbatim to the shell and it's the shell's quoting
that you have to manipulate to get this to work.

This is very difficult (although not impossible) unless you can be sure
that the contents won't contain certain characters (for example,
single-quotes (')).

You should write this as just:

    World::
        cd subdir && $(MAKE)

and it will work.  Or, you could use:

    World::
        $(MAKE) -C subdir


In situations like this, unfortunately, it's important to understand
both make AND your shell's quoting rules.  That can be a challenge.

The next thing to note is that I'm assuming from the name of the
variable it might contain more than one flag in it.  In that case,
putting "" around it in the "compile" line is a mistake:

  all:
       @echo "BSTRAPFLAGS is $(BSTRAPFLAGS)"

This will cause the entire contents to look like one argument to
whatever command you're invoking.  Rather you want:

  all:
       @echo BSTRAPFLAGS is $(BSTRAPFLAGS)


So, all that said, with the above change to World then running: 

    make World BSTRAPFLAGS='-DBSTRAPFLAGS=\"bar\"'

will do what (I think) you want.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.paulandlesley.org
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist




reply via email to

[Prev in Thread] Current Thread [Next in Thread]