Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 19 Jul 2008 20:30:06 +0200
From:      Kris Kennaway <kris@FreeBSD.org>
To:        ports@FreeBSD.org
Subject:   porter's handbook documentation on avoiding != variable assignments
Message-ID:  <488232AE.4090701@FreeBSD.org>
In-Reply-To: <484EAFAC.3020208@FreeBSD.org>
References:  <484EAFAC.3020208@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Can someone add to the PH a version of the advice below?  It might need 
to be fleshed out a bit to provide more context.

Kris

> Variable assignments with != are bad!  Try as hard as you can to avoid 
> using them -- especially in Mk/*!  Every time something processes your 
> makefile it will spawn a command, even if it is not relevant for the 
> operation being performed.  If you need to run shell commands, try to 
> isolate them within a makefile target.  You can avoid code duplication 
> by assigning the *shell commands* (not their output) to a variable and 
> inserting it into your code block.
> 
> e.g. instead of
> 
> -- 
> VARIABLE!=    do some shell stuff; do some other stuff
> 
> target:
>     echo ${VARIABLE}
> -- 
> 
> do this (or similar):
> 
> -- 
> VARIABLE_CMDS=    do some shell stuff; do some other stuff
> 
> target:
>     echo $$(${VARIABLE_CMDS})
> -- 
> 
> This defers the command execution to the point where the target runs, so 
> in the case when the target is *not* run (e.g. during INDEX builds or
> other recursive port traversals), then you avoid wasting one or 
> more process executions.





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?488232AE.4090701>