help-make
[Top][All Lists]
Advanced

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

Setting Variables depending on target being made


From: Gary Hall
Subject: Setting Variables depending on target being made
Date: Wed, 4 Jun 2008 14:59:37 +0200


Hi,

I'm trying to create a Makefile which alters its behaviour depending on which target is initially used. In the example below 'compile' is the main compilation target whose behaviour I want to change depending on whether I invoked make with the target 'cmp' or 'cmpDbg'.

MY_OPT1 and MY_OPT2 are arbitrary options I've created for this example. MY_OPTS is defined from MY_OPT1 and MY_OPT2 depending on which target is used during invocation. The Makefile is only ever invoked with the targets 'cmp' or 'cmpDbg'.

 
===== Start of Makefile =====
MY_OPT1 = +1

MY_OPT2 = -I/include \
       -I/home/include
cmp :
        @ if [ ${dbg} = 0 ] ; then \
                MY_OPTS="${MY_OPT1} ${MY_OPT2}"; export MY_OPTS; \
                echo "Debug Off : dbg = ${dbg}"; \
        else \
            MY_OPTS="${MY_OPT1} ; \
                echo "Debug On : dbg = ${dbg}"; \
        fi

        echo "Options : ${OPTS}"; \

cmp : dbg = 0
cmp : compile
        @ echo "Starting Compile - dbg = ${dbg}"
        @ echo "done"


cmpDbg : dbg = 1
cmpDbg : compile
        @ echo "Starting Compile - dbg = ${dbg}"
        @ echo "done"

===== End of Makefile =====

The problem is the value of MY_OPTS never seems to get set. I suspect that it is being set in a different shell which I can not access? I've tried a few experiments but can't seem to get this to work, any suggestions would be gratefully appreciated.

Thanks,
Gary


reply via email to

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