help-make
[Top][All Lists]
Advanced

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

Re: environment variables in command part of rule


From: Paul Smith
Subject: Re: environment variables in command part of rule
Date: Sat, 22 Oct 2011 08:43:51 -0400

On Sat, 2011-10-22 at 06:50 -0200, José Romildo Malaquias wrote:
> %.a : %.txt
>         p=$$(cat $< | wc -l)
>         q=$$((p+10))
>         echo $$q > $@
> 
> That is, I want to:
> * set $p to the number of lines in the prerequisite file $<, s
> * set $q to that value plus 10
> * create the target file using $q

GNU make will invoke each separate line of the rule in a different shell
(check the docs).

To do what you want you have to ensure that all the lines are invoked in
a single shell, otherwise the first variable settings have no effect
(they're lost as soon as their shell exits).

Do this with backslash continuations, and adding ";" to separate shell
commands:

%.a : %.txt
        p=$$(cat $< | wc -l); \
        q=$$((p+10)); \
        echo $$q > $@

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.mad-scientist.net
 "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]