diff common/makefiles/MakeBase.gmk @ 443:efd26e051e50

7170079: Adjustments to build-infra makefiles Reviewed-by: ohair, ohrstrom, ihse, jonas Contributed-by: jonas <jonas.oreland@oracle.com>, erikj <erik.joelsson@oracle.com>, ihse <magnus.ihse.bursie@oracle.com>, tgranat <torbjorn.granat@oracle.com>, ykantser <yekaterina.kantserova@oracle.com>
author erikj
date Thu, 07 Jun 2012 20:25:06 -0700
parents e1830598f0b7
children c8d320b48626
line wrap: on
line diff
--- a/common/makefiles/MakeBase.gmk	Fri Jun 01 14:11:59 2012 -0700
+++ b/common/makefiles/MakeBase.gmk	Thu Jun 07 20:25:06 2012 -0700
@@ -91,6 +91,15 @@
   > $(BUILDTIMESDIR)/build_time_diff_$1
 endef
 
+# Check if the current target is the final target, as specified by
+# the user on the command line. If so, call PrintEndMessage.
+define CheckIfFinished
+$(if $(filter $@,$(MAKECMDGOALS)),$(call PrintEndMessage))
+# If no taget is given, "all" is default. Check for that, too.
+# At most one of the tests can be true.
+$(if $(MAKECMDGOALS),,$(if $(filter $@,all),$(call PrintEndMessage)))
+endef
+
 # Indicate that we are done.
 # Record ending time and print out the total time it took to build.
 define MakeFinish 
@@ -101,6 +110,7 @@
 "########################################################################" \
 $(if $(REPORT_BUILD_TIMES),"Build time `$(CAT) $(BUILDTIMESDIR)/build_time_diff_$1` for target(s) $2","") \
 "########################################################################"
+$(call CheckIfFinished)
 endef
 
 # Find all build_time_* files and print their contents in a list sorted
@@ -126,6 +136,18 @@
 	$(if $(REPORT_BUILD_TIMES),$(call RecordEndTime,TOTAL) && $(call ReportBuildTimes,$1),)
 endef
 
+# Hook to be called as the very first thing when running a normal build
+define AtRootMakeStart
+	$(call PrintStartMessage)
+	$(call StartTimer)
+endef
+
+# Hook to be called as the very last thing for targets that are "top level" targets
+define AtRootMakeEnd
+	$(call StopTimer)
+	$(call CheckIfFinished)
+endef
+
 # If the variable that you want to send to stdout for piping into a file or otherwise,
 # is potentially long, for example the a list of file paths, eg a list of all package directories.
 # Then you need to use ListPathsSafely, which optimistically splits the output into several shell
@@ -324,4 +346,51 @@
 
 endef
 
+# The source tips can come from the Mercurial repository, or in the files
+#   $(HGTIP_FILENAME) which contains the tip but is also positioned in the same
+#   directory as the original $(HGDIR) directory.
+#   These should not be := assignments, only used from the root Makefile.
+HG_VERSION = $(shell $(HG) version 2> /dev/null)
+HG_DIRECTORY=.hg
+HGTIP_FILENAME=.hgtip
+HG_SEARCH = ./REPO ./*/REPO ./*/*/REPO ./*/*/*/REPO
+REPO_LIST = $(patsubst ./%,%,$(patsubst %/,%,$(sort $(dir \
+    $(shell $(CD) $(SRC_ROOT) ; ( $(LS) -d $(HG_SEARCH:%/REPO=%/$(HG_DIRECTORY)) ; \
+                                   $(LS)    $(HG_SEARCH:%/REPO=%/$(HGTIP_FILENAME)) ) \
+	        2> /dev/null)))))
+
+# Emit the repo:tip pairs to $@
+define GetSourceTips
+$(CD) $(SRC_ROOT) ; \
+for i in $(REPO_LIST) IGNORE ; do \
+  if [ "$${i}" = "IGNORE" ] ; then \
+    continue; \
+  elif [ -d $${i}/$(HG_DIRECTORY) -a "$(HG_VERSION)" != "" ] ; then \
+    $(PRINTF) " %s:%s" \
+      "$${i}" `$(HG) tip --repository $${i} --template '{node|short}\n'` ; \
+  elif [ -f $${i}/$(HGTIP_FILENAME) ] ; then \
+    $(PRINTF) " %s:%s" \
+      "$${i}" `$(CAT) $${i}/$(HGTIP_FILENAME)` ; \
+  fi; \
+done >> $@
+$(PRINTF) "\n" >> $@
+endef
+
+# Create the HGTIP_FILENAME file. Called from jdk/make/closed/bundles.gmk
+define CreateHgTip
+$(HG) tip --repository $1 --template '{node|short}\n' > $1/$(HGTIP_FILENAME);\
+$(ECHO) $1/$(HGTIP_FILENAME)
+endef
+
+define SetupLogging
+    ifneq ($(findstring $(LOG),debug trace),)
+        # Shell redefinition trick inspired by http://www.cmcrossroads.com/ask-mr-make/6535-tracing-rule-execution-in-gnu-make
+        OLD_SHELL:=$$(SHELL)
+        SHELL = $$(warning Building $$@$$(if $$<, (from $$<))$(if $$?, ($$? newer)))$$(OLD_SHELL) -x
+    endif
+endef
+
+# Make sure logging is setup for everyone that includes MakeBase.gmk.
+$(eval $(call SetupLogging))
+
 endif # _MAKEBASE_GMK