GNUMake document says

"An argument that contains ‘=’ specifies the value of a variable: ‘v=x’ sets the value of the variable v to x. If you specify a value in this way, all ordinary assignments of the same variable in the makefile are ignored; we say they have been overridden by the command line argument"


This means, value defined as command-line argument has top priority in terms of variable definition.


< Make file >

PRIV_V=hello_OUT

$(info $(PRIV_V))


all: a b

@echo all


a: PRIV_V := hello_A

a:

@echo $(PRIV_V)


b: PRIV_V := hello_B

b:

@echo $(PRIV_V)




< Test >

$ export PRIV_V=ENV

$ make

hello_OUT

hello_A

hello_B

all


$ make PRIV_V=CMD

CMD

CMD

CMD

all


* Tips : Variable definition in gnumake command line.

Variable definition syntax in the Makefile, is also available as command line argument.

Example.

$ make CC=Hello

$ make CC:=Hello

$ make CC+=Hello

+ Recent posts