make: Using target specific variables in prerequisites

前端 未结 1 656
故里飘歌
故里飘歌 2020-12-09 20:39

I\'m trying to write a Makefile where prerequisites using target specific variables

version=

target1: override version=1
target1: package

target2: override         


        
1条回答
  •  北海茫月
    2020-12-09 21:28

    Use Secondary Expansion:

    .SECONDEXPANSION:
    
    package: dir=package-$${version}
    package: source
    
    source: src/$${version}.c
    

    UPD.

    This answer is wrong, the suggested code won't work because of the reasons explained in the answer to a similar question.

    TL;DR: Target-specific variables take their effect based on the target that make is currently building [1]. Second expansion, in turn, takes place right at the end of the read-in phase [2], before building anything.

    Thanks to @koniiiik for pointing out.

    0 讨论(0)
提交回复
热议问题