How to print out a variable in makefile

后端 未结 15 1083
臣服心动
臣服心动 2020-12-07 06:51

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" st

15条回答
  •  悲哀的现实
    2020-12-07 07:30

    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:

    # if the first command line argument is "print"
    ifeq ($(firstword $(MAKECMDGOALS)),print)
    
      # take the rest of the arguments as variable names
      VAR_NAMES := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
    
      # turn them into do-nothing targets
      $(eval $(VAR_NAMES):;@:))
    
      # then print them
      .PHONY: print
      print:
              @$(foreach var,$(VAR_NAMES),\
                echo '$(var) = $($(var))';)
    endif
    

    Then you can just do "make print" to dump the value of any variable:

    $ make print CXXFLAGS
    CXXFLAGS = -g -Wall
    

提交回复
热议问题