help target for NewMakeFile.gmk

Mike Duigou mike.duigou at oracle.com
Wed Oct 17 21:49:26 PDT 2012


When confronted with a new makefile I always wonder what targets are available. It's useful to have a help target that prints out the available targets.

Here's a patch for the NewMakeFile.gmk that prints out the phony list as available targets. In other projects with phonies that aren't directly usable two lists are kept, one for usable targets and another for targets that can't or shouldn't be directly executed. Help will print just the usable list.

Mike

@@ -203,9 +203,29 @@
               jprt_build_generic
 
 ###########################################################################
+# Help target
+
+THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST))
+ifeq ($(THIS_MAKEFILE),Makefile)
+   MINUS_F := ""
+else
+   MINUS_F := " -f $(THIS_MAKEFILE)"
+endif
+
+help:
+	@$(ECHO) -n "# Usage : make$(MINUS_F)"
+	@for eachtarget in $(PHONY_LIST) ; do $(ECHO) -n " [$$eachtarget]" ; done
+	@$(ECHO) ""
+
+# Keep track of phony targets
+PHONY_LIST += help
+
+###########################################################################




More information about the build-infra-dev mailing list