help-make
[Top][All Lists]
Advanced

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

Re: HELP! Can I construct individial shell commands using a function


From: Oleksandr Gavenko
Subject: Re: HELP! Can I construct individial shell commands using a function
Date: Sun, 27 Feb 2011 10:29:54 +0000
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.12) Gecko/20101027 Thunderbird/3.1.6

On 2011-02-27 5:10, address@hidden wrote:
Thank you so much, Luke. You've revealed this great trick just in time,
about which GNU make manual does not say. Correct me if it does say.

On Sat, 26 Feb 2011 21:23:15 -0500, Luke Shumaker<address@hidden>
wrote:
The trick is to get the different commands on different lines.  Try
this:

define _ExecuteShcmdArray
$(foreach c,$1,@$($c)
)
endef

shellcmd1 = cd .. ; pwd
shellcmd2 = cd .. ; pwd

all:
        $(call _ExecuteShcmdArray,shellcmd1 shellcmd2)
This seems VERY tricky!

I simply wrote your function as recursively expanded variable
with command invoked in separate shells (e.g. '(echo 1);(echo 2);' ):

_ExecuteShcmdArray = $(foreach c,$1,($($c));)

So in addition to

shellcmd1 = cd .. ; pwd
shellcmd2 = cd .. ; pwd

all:
        $(call _ExecuteShcmdArray,shellcmd1 shellcmd2)

it evaluated as expected:

  $ make
(cd .. ; pwd); (cd .. ; pwd);
/cygdrive/e/home/devel
/cygdrive/e/home/devel

You can put @ before call to suppress printing of command.

Question to GNU Make GURU: 'foreach' with newline in 'define'
documented behavior?

--
Best regards!




reply via email to

[Prev in Thread] Current Thread [Next in Thread]