help-make
[Top][All Lists]
Advanced

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

RE: Determine if variable exists on make side from sh side


From: Paul D. Smith
Subject: RE: Determine if variable exists on make side from sh side
Date: Mon, 10 Apr 2006 15:45:11 -0400

%% "PATTON, BILLY \(SBCSI\)" <address@hidden> writes:

  pb> REFRESH+ldb+celltools+pub := dogs

  pb> all :
  pb>         @list=REFRESH+ldb+celltools+pub ;\
  pb>         echo "list = '$$list'" ;\
  pb>         echo "contents = '$($$list)'" ; \
  pb>         def=$(origin $$list); \
  pb>         echo "def = $$def" ; \
  pb>         if ! [ "$$def" = "undefined" ] ; then \
  pb>                 echo "if defined"; \
  pb>         else \
  pb>                 echo "else undefined" ; \
  pb>         fi

This is a mess as well.  You're still trying to access make constructs
from the shell script, and shell constructs (variables) from make
functions.

You can't do it.

No matter how many different ways you try to do it, it still won't
work.  Trust me :-).


Expand your script as make would, and you get:

        list=REFRESH+ldb+celltools+pub ;\
        echo "list = '$list'" ;\
        echo "contents = ''" ; \
        def=undefined; \
        echo "def = $def" ; \
        if ! [ "$def" = "undefined" ] ; then \
                echo "if defined"; \
        else \
                echo "else undefined" ; \
        fi

Getting rid of the useless lines the guts of this script is:

        def=undefined; \
        if ! [ "$def" = "undefined" ] ; then \
                echo "if defined"; \
        else \
                echo "else undefined" ; \
        fi

Obviously, the shell variable $def is always "undefined" here.


Why?  Here's how make expands things:

  - echo "list = '$$list'" ;

        ->  echo "list = '$list'"
    This is pretty obvious.

  - echo "contents = '$($$list)'" ;

        ->  echo "contents = '$($list)'"
    "$$list" expands to a literal string '$list'.

        ->  echo "contents = ''"
    There's no make variable with the name '$list', so '$($list)'
    expands to the empty string.

  - def=$(origin $$list);

        -> def=$(origin $list);
    Again, '$$list' expands to '$list'

        -> def=undefined;
    Again, there is no make variable '$list', so the $(origin ...)
    function expands to "undefined".

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.paulandlesley.org
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist




reply via email to

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