5

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.

3
  • Why without modifying the makefiles? Commented Jan 4, 2013 at 20:00
  • I work in a MegaCorp where it's difficult to modify anything. The makefiles are generated, I would have to modify the engine which create makefiles, and that seems very difficult. Commented Jan 7, 2013 at 7:11
  • 2
    You have my sympathy. MegaCorps and code generators have the same fault: layers of inflexible heirarchy that make change difficult. Commented Jan 7, 2013 at 16:26

2 Answers 2

7

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 
Sign up to request clarification or add additional context in comments.

Comments

3

You could do:

$ make -n -p | grep VAR 

to pick out the value

the flags are:

-n # don't really make -p # print database 

2 Comments

It does not evaluate the value of the variables, so it prints something like : INCFLAGS=$(MYINCFLAGS) -I...
You can grep for any name, e.g., grep MYINCFLAGS. If MYINCFLAGS is not set, it will evaluate to an empty string.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.