Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ask a makefile to print a variable value

I have some generated GNUmakefiles from which I need to extract the value of a variable.

Is there an easy way to see the value of a variable without modifying the makefiles ?

FYI, the variables contain the path of some include files necessary for the emacs c-macro-expand function.

like image 903
BenjaminB Avatar asked Dec 26 '22 11:12

BenjaminB


2 Answers

You could do:

$ make -n -p | grep VAR

to pick out the value

the flags are:

-n  # don't really make
-p  # print database
like image 44
jeberle Avatar answered Jan 02 '23 12:01

jeberle


You could create a wrapper makefile, which includes necessary GNUmakefiles and prints the variable. For example, create wrapper.mk with the content

include GNUmakefile

$(info $(value VAR_NAME))

and then invoke Make with -n flag (see @jeberle's answer):

make -f wrapper.mk -n  # will print the variable value to stdout
like image 89
Eldar Abusalimov Avatar answered Jan 02 '23 12:01

Eldar Abusalimov