From owner-freebsd-ports@FreeBSD.ORG Sun Jul 20 10:49:32 2008 Return-Path: Delivered-To: ports@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 02F8E1065679 for ; Sun, 20 Jul 2008 10:49:32 +0000 (UTC) (envelope-from kris@FreeBSD.org) Received: from weak.local (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 630978FC19; Sun, 20 Jul 2008 10:49:30 +0000 (UTC) (envelope-from kris@FreeBSD.org) Message-ID: <4883183A.7090100@FreeBSD.org> Date: Sun, 20 Jul 2008 12:49:30 +0200 From: Kris Kennaway User-Agent: Thunderbird 2.0.0.14 (Macintosh/20080421) MIME-Version: 1.0 To: Matthew Seaman References: <484EAFAC.3020208@FreeBSD.org> <488232AE.4090701@FreeBSD.org> <4882FFB7.1090501@infracaninophile.co.uk> In-Reply-To: <4882FFB7.1090501@infracaninophile.co.uk> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: ports@freebsd.org Subject: Re: porter's handbook documentation on avoiding != variable assignments X-BeenThere: freebsd-ports@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting software to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 20 Jul 2008 10:49:32 -0000 Matthew Seaman wrote: > Kris Kennaway wrote: >> 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. > > Would it be acceptable to use something like: > > .if !defined(BUILDING_INDEX) > VARIABLE!= something or other > .endif > > or > .if !make(describe) > VARIABLE!= whatever > .endif No because that only avoids one particular case, not the default case :) Kris