Tech Support > Operating Systems > UNIX / Variants > Makefile help
Makefile help
Posted by skyfaye@gmail.com on August 4th, 2005


Hi,

Is it possible to pass the value of a shell var in one target to
another target? The code below does not work because each target uses
a different subshell to execute it's command. Of course I can set
NAME=John when I invoke this Makefile but I want my Makefile to handle
all this.


////////////////////////////////////////
SHELL=/bin/sh

x :
echo "My name is $$NAME"

y: y_pre x

y_pre:
NAME=John
/////////////////////////////////////////

What I want to see when I execute the target y is --> My name is John.

Thanks,
Hung

Posted by Jamie Beverly on August 4th, 2005


skyfaye@gmail.com wrote:

Unfortunately, the answer to your question is simply no, however, you can
often accomplish something similar using Makefile macros, i.e.

macronumberone = `ls -al somefile.in | awk '{print $$5}'`
macronumbertwo = `echo $(macronumberone) | wc -c`

somefile: somefile.in
sed -e 's/filesize=.*/filesize='$(macronumbertwo)'/g' somefile.in \
Unfortunately this is somewhat limited; which means that if you really need
to do some scripting, it's better done in a script that the Makefile calls
to build a rule.

Hope it helps.


Similar Posts