linuxmakefilecommand-line

Variables based on targets in Makefile


when creating a Makefile, im trying to figure out how(if) i can change a variable based on the target.

So something likes this:

VER = $(if target=release then 1.0.0 elseif target=nightly then 20110411)

nightly:
    @@echo ${VER} >> version.txt

release:
    @@echo ${VER} >> version.txt

Solution

  • If your make is GNU make, Target-Specific Variable is allowed.
    For example, in your question's case, the following definitions will meet the purpose:

    nightly: VER = 20110411
    release: VER = 1.0.0
    
    nightly:
        @echo ${VER}
    
    release:
        @echo ${VER}
    

    Hope this helps