Cyan
Cyan

Reputation: 13948

force variable evaluation within Makefile

In one of my Makefiles, a variable receives a value determined by a sed script :

VAR_SCRIPT:=`sed -n '/expression/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < file.h`

The sed script will find the appropriate value within file.h. It works fine. Later on this value is used to create versioned file names.

But in fact, the sed program is not evaluated at the moment VAR_SCRIPT is created. It keeps its script format all along, and is only evaluated at the last moment.

This cause problems in later parts of the Makefile. Typically, I would like the result of VAR_VALUE later on in another sed script, not the script formula itself.

Trying to transfer the value of the sed script through :

VAR_VALUE := $(VAR_SCRIPT)

only transfers the script, not the result of the script.

How to force evaluation of the sed script ?

Edit : one solution found :

VAR_VALUE := $(shell echo $(VAR_SCRIPT))

See also @Andrey suggestion

Upvotes: 0

Views: 443

Answers (1)

Andrey
Andrey

Reputation: 2583

You can try shell function:

VARIABLE := $(shell command)

For example, check this Makefile (no tabs):

C := sed -n 'p' <<< 'test'
V := $(shell $(C))
all: ; @echo $(V)

Upvotes: 1

Related Questions