In my makefile, I have a variable 'NDK_PROJECT_PATH', my question is how can I print it out when it compiles?
I read Make file echo displaying "$PATH" string and I tried:
@echo $(NDK_PROJECT_PATH)
@echo $(value NDK_PROJECT_PATH)
Both gives me
"build-local.mk:102: *** missing separator. Stop."
Any one knows why it is not working for me?
If you simply want some output, you want to use
$(info)
by itself. You can do that anywhere in a Makefile, and it will show when that line is evaluated:Will output
VAR="<value of VAR>"
whenever make processes that line. This behavior is very position dependent, so you must make sure that the$(info)
expansion happens AFTER everything that could modify$(VAR)
has already happened!A more generic option is to create a special rule for printing the value of a variable. Generally speaking, rules are executed after variables are assigned, so this will show you the value that is actually being used. (Though, it is possible for a rule to change a variable.) Good formatting will help clarify what a variable is set to, and the
$(flavor)
function will tell you what kind of a variable something is. So in this rule:$*
expands to the stem that the%
pattern matched in the rule.$($*)
expands to the value of the variable whose name is given by by$*
.[
and]
clearly delineate the variable expansion. You could also use"
and"
or similar.$(flavor $*)
tells you what kind of variable it is. NOTE:$(flavor)
takes a variable name, and not its expansion. So if you saymake print-LDFLAGS
, you get$(flavor LDFLAGS)
, which is what you want.$(info text)
provides output. Make printstext
on its stdout as a side-effect of the expansion. The expansion of$(info)
though is empty. You can think of it like@echo
, but importantly it doesn't use the shell, so you don't have to worry about shell quoting rules.@true
is there just to provide a command for the rule. Without that, make will also outputprint-blah is up to date
. I feel@true
makes it more clear that it's meant to be a no-op.Running it, you get
from a "Mr. Make post" https://www.cmcrossroads.com/article/printing-value-makefile-variable
Add the following rule to your Makefile:
Then, if you want to find out the value of a makefile variable, just:
and it will return:
No need to modify the Makefile.
@echo $(NDK_PROJECT_PATH) is the good way to do it. I don't think the error comes from there. Generally this error appears when you mistyped the intendation : I think you have spaces where you should have a tab.
This
makefile
will generate the 'missing separator' error message:There's a tab before the
@echo "All done"
(though thedone:
rule and action are largely superfluous), but not before the@echo PATH=$(PATH)
.The trouble is that the line starting
all
should either have a colon:
or an equals=
to indicate that it is a target line or a macro line, and it has neither, so the separator is missing.The action that echoes the value of a variable must be associated with a target, possibly a dummy or PHONEY target. And that target line must have a colon on it. If you add a
:
afterall
in the examplemakefile
and replace the leading blanks on the next line by a tab, it will work sanely.You probably have an analogous problem near line 102 in the original
makefile
. If you showed 5 non-blank, non-comment lines before the echo operations that are failing, it would probably be possible to finish the diagnosis. However, since the question was asked in May 2013, it is unlikely that the brokenmakefile
is still available now (August 2014), so this answer can't be validated formally. It can only be used to illustrate a plausible way in which the problem occurred.This can be done in a generic way and can be very useful when debugging a complex makefile. Following the same technique as described in another answer, you can insert the following into any makefile:
Then you can just do "make print" to dump the value of any variable: