Search code examples
makefile

Two '=' in Makefile variable assignment


What does

FOO := BAR=$(BAZ)

mean in a Makefile? It is the second '=' I'm curious about.


Solution

  • The second = is part of the data being assigned. Given that the := signifies assignment to a simply expanded variable, everything appearing after it is expanded at the time that the assignment is processed, and the result is the value of the variable. That will depend on the value of variable BAZ at that time, but for example, given this makefile:

    BAZ = 42
    FOO := BAR=$(BAZ)
    BAZ = 37
    
    all:
            @echo "$(FOO)"
    

    The output of the command make all will be

    BAR=42