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 <[email protected]>          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


_______________________________________________
Help-make mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/help-make

Reply via email to