skalee
skalee

Reputation: 12665

How to print expanded variables from Makefile?

Given Makefile in which libdir is defined as libdir = ${exec_prefix}/lib, how to print its final (expanded) value?

Running make -pns | grep -e "^libdir" | uniq prints libdir = ${exec_prefix}/lib, whereas I rather want to see /usr/local/lib (provided that exec_prefix is /usr/local).

Is it possible without appending that Makefile with yet another rule?

Upvotes: 0

Views: 503

Answers (2)

Renaud Pacalet
Renaud Pacalet

Reputation: 28965

What about:

printf 'include Makefile\nfoo:\n\t@echo "$(libdir)"\n' | make -f - foo

Note that the concept of final value is difficult to define with make. It may depend on the specific target...

Upvotes: 2

Matt
Matt

Reputation: 15081

The problem is what you mean by "a final value". For recursive variable it's a literal string $(exec_prefix}/lib. And the expansion only takes place when the variable is referred with ${libdir}.

However simple variables are immediately expanded. So libdir:=${libdir} and make -np will produce the desired result. But other way it's not possible.

BTW. You can write a common "printing" rule like this (seen in GMSL):

print-%:
    @echo value of "$*" is "$($*)"

And then just do make print-libdir

Upvotes: 1

Related Questions