Dump Variables In Makefiles

Just a useful snippet to dump the variables in a Makefile. It’s a bit obtuse, but it’s useful for debugging.

# can also exclude on environment or environment-override (notice the dash instead of space)
.PHONY: dumpvars
dumpvars: N := $(filter-out PATH, $(sort $(.VARIABLES)))
dumpvars: E := $(if $(exclude),$(exclude),default automatic)
dumpvars: S := $(eval) $(eval)
dumpvars:
	$(foreach V, $N, $(if $(filter-out $E, $(subst $S,-,$(origin $V))), $(info $V=$($V) ($(origin $V))),))

Can invoke with make dumpvars or make dumpvars exclude="environment-override", for example.