# Declare targets that do not generate files of the same name.
# http://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
-.PHONY: all help clean dist run
+.PHONY: all help clean dist run print- printvars
# target: all - the default target
all: $(PROGRAM)
# The comments from the C++ rule above also apply here
%.o: %.c
$(CC) $(CFLAGS) -c $<
+
+# target: print-% - display a variable value (e.g. print-PROGRAMS)
+# Take some of the mystery out of variable manipulation. For example,
+# $ make print-hello_world_OBJECTS
+# The `@` suppresses recipe echoing. See
+# http://www.gnu.org/software/make/manual/html_node/Echoing.html
+# The `info` function acts like the shell `echo` command. See
+# http://www.gnu.org/software/make/manual/html_node/Make-Control-Functions.html
+# For an explanation of $* and other special variables, see
+# http://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html
+print-%:
+ @$(info $* = $($*))
+
+# target: printvars - display all non-default variables
+# .VARIBALES holds a list of all global variables. See
+# http://www.gnu.org/software/make/manual/html_node/Special-Variables.html
+# The functions---`sort`, `if`, `filter-out`, `origin`, `warning`, and
+# `value`--- are discussed, respectively, here:
+# http://www.gnu.org/software/make/manual/html_node/Text-Functions.html#index-sort-580
+# http://www.gnu.org/software/make/manual/html_node/Conditional-Functions.html
+# http://www.gnu.org/software/make/manual/html_node/Text-Functions.html#index-filter_002dout-577
+# http://www.gnu.org/software/make/manual/html_node/Origin-Function.html
+# http://www.gnu.org/software/make/manual/html_node/Value-Function.html
+printvars:
+ @$(foreach V, \
+ $(sort $(.VARIABLES)), \
+ $(if \
+ $(filter-out environment default automatic, \
+ $(origin $V)), \
+ $(info $V=$($V) (origin: $(origin $V), value: $(value $V))) \
+ ) \
+ )