What's the difference between := and = in Makefile?

前端 未结 4 1541
既然无缘
既然无缘 2021-01-30 02:23

For variable assignment in Make, I see := and = operator. What\'s the difference between them?

4条回答
  •  无人及你
    2021-01-30 02:40

    For me, the best way to see it in practice is during this Makefile snippet:

    Simple assignment

    XX := $(shell date) // date will be executed once
    tt:
        @echo $(XX)
        $(shell sleep 2)
        @echo $(XX)
    
    

    Running

    make tt
    

    Will produce:

    sex 22 jan 2021 14:56:08 -03
    sex 22 jan 2021 14:56:08 -03
    

    ( Same value )

    Expanded assignment

    XX = $(shell date) // date will be executed every time you use XX
    tt:
        @echo $(XX)
        $(shell sleep 2)
        @echo $(XX)
    
    

    Running

    make tt
    

    Will produce:

    sex 22 jan 2021 14:56:08 -03
    sex 22 jan 2021 14:58:08 -03
    

    Different values

提交回复
热议问题