pythonic
pythonic

Reputation: 21615

How to include the value of a parameter into a string in a makefile

I have a makefile and I pass a parameter to it through command line. Say I pass parameter for clock frequency such as this.

make run FREQ=500

In my makefile, I want to include the value of FREQ inside a string, for example, I want to expand it like this.

RUN_FLG = "--frequency = 500"

I know you can use $(FREQ) if you are using that parameter normally (not inside strings), but how do you expand it inside a string?

Upvotes: 1

Views: 161

Answers (2)

Vincenzo Pii
Vincenzo Pii

Reputation: 19805

Just use $(value)

Example:

freq = 500
x = "--frequency = $(freq)"

run:
    @$(/bin/echo -e) $(x)

Output of make -n:

"--frequency = 500"

Upvotes: 1

Jonathan Leffler
Jonathan Leffler

Reputation: 753705

make doesn't know what a string is; you embed the macro reference into the string the same as outside a string:

DEFAULT_FREQ = 60
FREQ         = $(DEFAULT_FREQ)

RUN_FLG = "--frequency=$(FREQ)"

I've 'corrected' the spacing in the --frequency; you would not normally have the = separate from the option text, and the value would also follow without spaces.

I've provided a default value for FREQ inside the makefile so that if it is invoked without any FREQ=500 override, you still have the default value as part of $(RUN_FLG).

Upvotes: 1

Related Questions