Saturday, June 12, 2021

handy makefile script

I frequently find myself looking for default make rules, and inevitably how to print their values.  Here's a script to help.

Adapted from https://blog.melski.net/2010/11/30/makefile-hacks-print-the-value-of-any-variable/

$ cat ~/bin/make-vars 
#!/bin/bash

_vars=
for v in $@; do
  _vars="${_vars} print-${v}"
done

make -f- ${_vars} <<'EOF'
print-%:
	@echo '$*=$($*)'
	@echo '  origin = $(origin $*)'
	@echo '  flavor = $(flavor $*)'
	@echo '   value = $(value  $*)'
EOF

Here it is in use

$ make-vars LINK.cc
LINK.cc=c++    
  origin = default
  flavor = recursive
   value = $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)

No comments: