help-make
[Top][All Lists]
Advanced

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

Re: Problem with conditional directive ifeq and variables


From: Paul Smith
Subject: Re: Problem with conditional directive ifeq and variables
Date: Fri, 28 Mar 2008 13:40:17 -0400

On Fri, 2008-03-28 at 08:29 -0700, Jetjockey wrote:
> I hope you can help my effort to use an environment variable within the
> condition directive ifeq within a makefile.
> 
> My code is to be run twice, setting 
> export DONOTREDOAOD := 0
> during the first run and
> export DONOTREDOAOD := 1
> during the second one (in the theaodanalysisdatadir% rule).
> 
> The environment variable is retrieved in another rule:
> 
> theaodanalysis%: donotredoaod = $(shell echo ${DONOTREDOAOD})
> theaodanalysis%: remake_jobids theaodanalysisdatadir%
>       echo ${donotredoaod}
>       @echo TEST
>       @echo $(shell if [ '$(donotredoaod)' == '1' ]; then echo 1; else echo 0;
> fi)
> ifeq ($(shell if [ '$(donotredoaod)' == '1' ]; then echo 1; else echo 0;
> fi),1)
> ifeq ($(thetest),)
>       @echo true
> else
>       @echo false

Wow, you're REALLY making this more complex than it needs to be.  Check
the GNU make manual and you'll see that make imports all environment
variables as make variables.  So, you don't have to use $(shell ...) and
all that mess to find the value of DONOTREDOAOD in the environment; just
use the make variable $(DONOTREDOAOD).

Second, you have to understand that make has a very definitive two-phase
operation.  The first phase is reading all the makefiles and
constructing internal dependency graphs, etc. based on what it finds.

The second phase uses that internal graph to determine out-of-date
targets and rebuild them.

Make preprocessor statements like ifeq, etc. are ALL, ALWAYS, completely
parsed during the first phase.  It doesn't matter if they appear inside
recipes, or what.

Values that are set via target-specific rules, on the other hand, are
always parsed during the second phase.


Your example can be simplified into just a few lines.  Unfortunately, my
mind reels a bit when I look at what you're doing here :-).  If you
could just state in a sentence or two what you want to accomplish, we'll
better be able to help.  Also be sure to specify what version of GNU
make you're using and what operating system/platform you're using.

-- 
-----------------------------------------------------------------------------
 Paul D. Smith <address@hidden>                 http://make.mad-scientist.us
 "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]