help-make
[Top][All Lists]
Advanced

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

Re: Variable order of operations


From: Philip Guenther
Subject: Re: Variable order of operations
Date: Mon, 2 Mar 2009 08:44:17 -0800

On Mon, Mar 2, 2009 at 7:56 AM, Harvey Chapman
<address@hidden> wrote:
> In the makefile below, the ifeq section gets evaluated *after* the "cgi"
> target. This is not what I want. Would someone please point out what I'm
> doing wrong?

What behavior makes you say that the ifeq is being evaluated after the
'cgi' target?


> Also, on a separate note, is it better to have one ".PHONY:" target or
> multiple, one for each phony target?

That's a local style choice, in my experience.


> ifndef DEBUG
> DEBUG=0
> endif
>
> .PHONY: all cgi clean
> all: cgi
>
> ifeq ($(DEBUG),1)
>    HIDE=
> else
>    HIDE=@
> endif
>
> # For some reason in this particular Makefile, the "ifeq" above gets
> evaluated AFTER
> # the targets below. This is a quick hack around that.
> HIDE=@
>
> cgi:
> #   address@hidden "DEBUG is \""$(DEBUG)"\""
> #   address@hidden "HIDE is \""$(HIDE)"\""
>   address@hidden "Building... " $@
>    $(HIDE) DEBUG="$(DEBUG)" GUMSTIX="$(GUMSTIX)" BUILD_ARM="$(BUILD_ARM)"
> CC="$(CC)" CXX="$(CXX)" AR="$(AR)" make -C cgi
>
> clean:
>    $(HIDE) DEBUG="$(DEBUG)" GUMSTIX="$(GUMSTIX)" BUILD_ARM="$(BUILD_ARM)"
> CC="$(CC)" CXX="$(CXX)" AR="$(AR)" make -C cgi clean

So after removing the unconditional HIDE=@, this is what I see:

$ make
Building...  cgi
make: *** cgi: No such file or directory.  Stop.
make: *** [cgi] Error 2
$ make DEBUG=1
Building...  cgi
DEBUG="1" GUMSTIX="" BUILD_ARM="" CC="cc" CXX="g++" AR="ar" make -C cgi
make: *** cgi: No such file or directory.  Stop.
make: *** [cgi] Error 2
$

So it seems to be working for me.  What do you get when you try that?
Also, what's the output of "make --version"?

BTW, when invoking make recursively, you almost certainly should use
$(MAKE) instead of just 'make'.  This has two effects:
1) it expands to the command used to invoke the toplevel make, so if you
   have multiple versions of make on your system, you can use any of them
   and the same version will be used for the recursive invocation and not just
   the one named 'make' in your path.
2) GNU make (and System V's make) treat commands containing $(MAKE) or ${MAKE}
   as if they had the '+' prefix, so that they are always processed,
even when the -n option
   is used.


Philip Guenther




reply via email to

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