Makefile help - Unix

This is a discussion on Makefile help - Unix ; 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 ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Makefile help

  1. Makefile help

    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


  2. Re: Makefile help

    skyfaye@gmail.com wrote:

    > 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.
    >


    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 \
    > somefile


    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.

+ Reply to Thread