Find the answer to your Linux question:
Results 1 to 5 of 5
Hi. I'm new to make. How do I make the variable defined in shell script to be visible to the rest of makefile? Here is a simplified makefile: --------------------------------- aaa ...
  1. #1
    Just Joined!
    Join Date
    Jul 2007
    Posts
    7

    help with makefile

    Hi. I'm new to make.

    How do I make the variable defined in shell script to be visible to the rest of makefile?

    Here is a simplified makefile:
    ---------------------------------
    aaa = mypc

    all:

    .PHONY: foo
    foo:
    var=foo1
    @echo "0var is:" $(var)
    @echo "1var is:" $$var
    @echo "2var is:" $${var}
    @echo "localhost:" $(aaa)
    -------------------------------

    Variable 'var' is defined as foo1 in shell script. In contrast, if I define variable 'aaa' as in the beginning, then this is visible everywhere.

    Is there a way to make 'var' visible throughtout make?

    Thanks

  2. #2
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    Make desired variables environment variables:

    Code:
    #!/bin/sh
    
    # @(#) s1       Demonstrate existence of environment shell variables in make.
    
    echo " sh version: $BASH_VERSION" >&2
    
    cat >Makefile <<'EOF'
    target:
            @ echo " Hello, world."
            @ echo var1 is $(var1)
            @ echo var2 is $(var2)
    EOF
    
    echo
    echo " Makefile:"
    cat Makefile
    
    echo
    echo -----
    echo " Results of make:"
    export var1="/media"
    make
    
    exit 0
    producing:
    Code:
    % ./s1
     sh version: 2.05b.0(1)-release
    
     Makefile:
    target:
            @ echo " Hello, world."
            @ echo var1 is $(var1)
            @ echo var2 is $(var2)
    
    -----
     Results of make:
     Hello, world.
    var1 is /media
    var2 is
    cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  3. #3
    Just Joined!
    Join Date
    Jul 2007
    Posts
    7
    Thanks drl, it works...I'm using your method.

    OK... So you mean there is no way to embed shell script lines within makefile to pass shell variables back to own makefile environment?
    I'm aware that variables can be passed to sub-make using export.


    Quote Originally Posted by drl View Post
    Hi.
    Make desired variables environment variables:
    cheers, drl

  4. #4
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    If you are talking in terms of processes, a child inherits the environment from the parent, including the names and values of those variables marked as exported. A child cannot pass values back up to the parent.

    If that's not substance of your question, then please provide an example of what you mean, what actually happens, and what you expect or want to happen ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  5. #5
    Just Joined!
    Join Date
    Apr 2007
    Posts
    59

    other way?

    My requirement is same as ploceus.
    But I already have a big Makefile in my clearcase vobs. So may be I can't use the method suggested by drl. to create the Makefile using shell script.
    Is there any other way to achieve this ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...