1.1 --- a/common/makefiles/MakeBase.gmk Wed Oct 24 13:11:42 2012 -0700 1.2 +++ b/common/makefiles/MakeBase.gmk Fri Oct 26 14:29:57 2012 -0700 1.3 @@ -33,129 +33,13 @@ 1.4 ifndef _MAKEBASE_GMK 1.5 _MAKEBASE_GMK := 1 1.6 1.7 -ifeq (,$(findstring 3.81,$(MAKE_VERSION))) 1.8 - ifeq (,$(findstring 3.82,$(MAKE_VERSION))) 1.9 - $(error This version of GNU Make is too low ($(MAKE_VERSION)). Please upgrade to 3.81 or newer.) 1.10 - endif 1.11 -endif 1.12 - 1.13 -ifneq (,$(CYGPATH)) 1.14 - # Cygwin styff, if needed but most is going to be 1.15 - # done in configure! 1.16 - ifeq (yes,$(CHECK_FOR_VCINSTALLDIR)) 1.17 - ifeq (,$(VCINSTALLDIR)) 1.18 - $(info Could not find compiler paths!) 1.19 - $(info You probably configured the build from within a) 1.20 - $(info VS command prompt, but you are not using such a) 1.21 - $(info prompt right now.) 1.22 - $(info If you instead run configure from a plain cygwin shell, it) 1.23 - $(info will attempt to setup VS for you! Please try that.) 1.24 - $(error Giving up for now.) 1.25 - endif 1.26 - endif 1.27 -endif 1.28 - 1.29 -# The build times report is turned off by setting REPORT_BUILD_TIMES to nothing. 1.30 -# This is necessary for the target clean which will erase the 1.31 -# directories where the buildtimes are stored. 1.32 -REPORT_BUILD_TIMES=1 1.33 -# Store the build times in this directory. 1.34 -BUILDTIMESDIR=$(OUTPUT_ROOT)/tmp/buildtimes 1.35 - 1.36 -# Record starting time for build of a sub repository. 1.37 -define RecordStartTime 1.38 -$(MKDIR) -p $(BUILDTIMESDIR) 1.39 -$(DATE) '+%Y %m %d %H %M %S' | $(NAWK) '{ print $$1,$$2,$$3,$$4,$$5,$$6,($$4*3600+$$5*60+$$6) }' > $(BUILDTIMESDIR)/build_time_start_$1 1.40 -$(DATE) '+%Y-%m-%d %H:%M:%S' > $(BUILDTIMESDIR)/build_time_start_$1_human_readable 1.41 -endef 1.42 - 1.43 -# Indicate that we started to build a sub repository and record starting time. 1.44 -define MakeStart 1.45 -$(call RecordStartTime,$1) 1.46 -$(BUILD_LOG_WRAPPER) $(PRINTF) "\n\n%s\n%s\n##### %-60.60s #####\n%s\n\n" \ 1.47 -"########################################################################" \ 1.48 -"########################################################################" \ 1.49 -"Entering $1 for target(s) $2" \ 1.50 -"########################################################################" 1.51 -endef 1.52 - 1.53 -# Record ending time and calculate the difference and store it in a 1.54 -# easy to read format. Handles builds that cross midnight. Expects 1.55 -# that a build will never take 24 hours or more. 1.56 -define RecordEndTime 1.57 -$(DATE) '+%Y %m %d %H %M %S' | $(NAWK) '{ print $$1,$$2,$$3,$$4,$$5,$$6,($$4*3600+$$5*60+$$6) }' > $(BUILDTIMESDIR)/build_time_end_$1 1.58 -$(DATE) '+%Y-%m-%d %H:%M:%S' > $(BUILDTIMESDIR)/build_time_end_$1_human_readable 1.59 -$(ECHO) `$(CAT) $(BUILDTIMESDIR)/build_time_start_$1` `$(CAT) $(BUILDTIMESDIR)/build_time_end_$1` $1 | \ 1.60 - $(NAWK) '{ F=$$7; T=$$14; if (F > T) { T+=3600*24 }; D=T-F; H=int(D/3600); \ 1.61 - M=int((D-H*3600)/60); S=D-H*3600-M*60; printf("%02d:%02d:%02d %s\n",H,M,S,$$15); }' \ 1.62 - > $(BUILDTIMESDIR)/build_time_diff_$1 1.63 -endef 1.64 - 1.65 -# Check if the current target is the final target, as specified by 1.66 -# the user on the command line. If so, call PrintEndMessage. 1.67 -define CheckIfFinished 1.68 -$(if $(filter $@,$(MAKECMDGOALS)),$(call PrintEndMessage)) 1.69 -# If no taget is given, "all" is default. Check for that, too. 1.70 -# At most one of the tests can be true. 1.71 -$(if $(MAKECMDGOALS),,$(if $(filter $@,all),$(call PrintEndMessage))) 1.72 -endef 1.73 - 1.74 -# Indicate that we are done. 1.75 -# Record ending time and print out the total time it took to build. 1.76 -define MakeFinish 1.77 -$(if $(REPORT_BUILD_TIMES),$(call RecordEndTime,$1),) 1.78 -$(BUILD_LOG_WRAPPER) $(PRINTF) "%s\n##### %-60.60s #####\n%s\n##### %-60.60s #####\n%s\n\n" \ 1.79 -"########################################################################" \ 1.80 -"Leaving $1 for target(s) $2" \ 1.81 -"########################################################################" \ 1.82 -$(if $(REPORT_BUILD_TIMES),"Build time `$(CAT) $(BUILDTIMESDIR)/build_time_diff_$1` for target(s) $2","") \ 1.83 -"########################################################################" 1.84 -$(call CheckIfFinished) 1.85 -endef 1.86 - 1.87 -# Find all build_time_* files and print their contents in a list sorted 1.88 -# on the name of the sub repository. 1.89 -define ReportBuildTimes 1.90 -$(BUILD_LOG_WRAPPER) $(PRINTF) -- "-- Build times ----------\nTarget %s\nStart %s\nEnd %s\n%s\n%s\n-------------------------\n" \ 1.91 -"$1" \ 1.92 -"`$(CAT) $(BUILDTIMESDIR)/build_time_start_TOTAL_human_readable`" \ 1.93 -"`$(CAT) $(BUILDTIMESDIR)/build_time_end_TOTAL_human_readable`" \ 1.94 -"`$(LS) $(BUILDTIMESDIR)/build_time_diff_* | $(GREP) -v _TOTAL | $(XARGS) $(CAT) | $(SORT) -k 2`" \ 1.95 -"`$(CAT) $(BUILDTIMESDIR)/build_time_diff_TOTAL`" 1.96 -endef 1.97 - 1.98 -define ResetTimers 1.99 -$$(shell $(MKDIR) -p $(BUILDTIMESDIR) && $(RM) $(BUILDTIMESDIR)/build_time_*) 1.100 -endef 1.101 - 1.102 -define StartTimer 1.103 - $(call RecordStartTime,TOTAL) 1.104 -endef 1.105 - 1.106 -define StopTimer 1.107 - $(if $(REPORT_BUILD_TIMES),$(call RecordEndTime,TOTAL) && $(call ReportBuildTimes,$1),) 1.108 -endef 1.109 - 1.110 -# Hook to be called as the very first thing when running a normal build 1.111 -define AtRootMakeStart 1.112 - $(if $(findstring --jobserver,$(MAKEFLAGS)), $(error make -j is not supported, use make JOBS=n)) 1.113 - $(call PrintStartMessage) 1.114 - $(call StartTimer) 1.115 -endef 1.116 - 1.117 -# Hook to be called as the very last thing for targets that are "top level" targets 1.118 -define AtRootMakeEnd 1.119 - $(call StopTimer) 1.120 - $(call CheckIfFinished) 1.121 -endef 1.122 - 1.123 # If the variable that you want to send to stdout for piping into a file or otherwise, 1.124 # is potentially long, for example the a list of file paths, eg a list of all package directories. 1.125 # Then you need to use ListPathsSafely, which optimistically splits the output into several shell 1.126 # calls as well as use compression on recurrent file paths segments, to get around the potential 1.127 # command line length problem that exists in cygwin and other shells. 1.128 -compress_pre:=$(strip $(shell cat $(SRC_ROOT)/common/makefiles/compress.pre)) 1.129 -compress_post:=$(strip $(shell cat $(SRC_ROOT)/common/makefiles/compress.post)) 1.130 +compress_pre:=$(strip $(shell $(CAT) $(SRC_ROOT)/common/makefiles/support/ListPathsSafely-pre-compress.incl)) 1.131 +compress_post:=$(strip $(shell $(CAT) $(SRC_ROOT)/common/makefiles/support/ListPathsSafely-post-compress.incl)) 1.132 compress_paths=$(compress_pre)\ 1.133 $(subst $(SRC_ROOT),X97,\ 1.134 $(subst $(OUTPUT_ROOT),X98,\ 1.135 @@ -163,7 +47,7 @@ 1.136 $(subst $(SPACE),\n,$(strip $1)))))\ 1.137 $(compress_post) 1.138 1.139 -decompress_paths=sed -f $(SRC_ROOT)/common/makefiles/uncompress.sed -e 's|X99|\\n|g' \ 1.140 +decompress_paths=$(SED) -f $(SRC_ROOT)/common/makefiles/support/ListPathsSafely-uncompress.sed -e 's|X99|\\n|g' \ 1.141 -e 's|X98|$(OUTPUT_ROOT)|g' -e 's|X97|$(SRC_ROOT)|g' \ 1.142 -e 's|X00|X|g' | tr '\n' '$2' 1.143 1.144 @@ -384,14 +268,67 @@ 1.145 endef 1.146 1.147 define SetupLogging 1.148 - ifneq ($(findstring $(LOG),debug trace),) 1.149 + ifeq ($$(LOG), trace) 1.150 # Shell redefinition trick inspired by http://www.cmcrossroads.com/ask-mr-make/6535-tracing-rule-execution-in-gnu-make 1.151 + # For each target executed, will print 1.152 + # Building <TARGET> (from <FIRST PREREQUISITE>) (<ALL NEWER PREREQUISITES> newer) 1.153 + # but with a limit of 20 on <ALL NEWER PREREQUISITES>, to avoid cluttering logs too much (and causing a crash on Cygwin). 1.154 OLD_SHELL:=$$(SHELL) 1.155 - SHELL = $$(warning Building $$@$$(if $$<, (from $$<))$(if $$?, ($$? newer)))$$(OLD_SHELL) -x 1.156 + WRAPPER_SHELL:=$$(OLD_SHELL) $$(SRC_ROOT)/common/bin/shell-tracer.sh $$(if $$(TIME),$$(TIME),-) $$(OUTPUT_ROOT)/build-trace-time.log $$(OLD_SHELL) 1.157 + SHELL=$$(warning $$(if $$@,Building $$@,Running shell command) $$(if $$<, (from $$<))$$(if $$?, ($$(wordlist 1, 20, $$?) $$(if $$(wordlist 21, 22, $$?), ... [in total $$(words $$?) files]) newer)))$$(WRAPPER_SHELL) 1.158 + endif 1.159 + # Never remove warning messages; this is just for completeness 1.160 + LOG_WARN= 1.161 + ifneq ($$(findstring $$(LOG),info debug trace),) 1.162 + LOG_INFO= 1.163 + else 1.164 + LOG_INFO=> /dev/null 1.165 + endif 1.166 + ifneq ($$(findstring $$(LOG),debug trace),) 1.167 + LOG_DEBUG= 1.168 + else 1.169 + LOG_DEBUG=> /dev/null 1.170 + endif 1.171 + ifneq ($$(findstring $$(LOG),trace),) 1.172 + LOG_TRACE= 1.173 + else 1.174 + LOG_TRACE=> /dev/null 1.175 endif 1.176 endef 1.177 1.178 # Make sure logging is setup for everyone that includes MakeBase.gmk. 1.179 $(eval $(call SetupLogging)) 1.180 1.181 +# This is to be called by all SetupFoo macros 1.182 +define LogSetupMacroEntry 1.183 + $(if $(26),$(error Internal makefile error: Too many arguments to LogSetupMacroEntry, please update MakeBase.gmk)) 1.184 + $(if $(findstring $(LOG),debug trace), $(info $1 $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25,$(if $($i),$(NEWLINE) $(strip [$i] $($i)))))) 1.185 +endef 1.186 + 1.187 +# Make directory without forking mkdir if not needed 1.188 +define MakeDir 1.189 + ifneq ($$(wildcard $1 $2 $3 $4 $5 $6 $7 $8 $9),$$(strip $1 $2 $3 $4 $5 $6 $7 $8 $9)) 1.190 + $$(shell $(MKDIR) -p $1 $2 $3 $4 $5 $6 $7 $8 $9) 1.191 + endif 1.192 +endef 1.193 + 1.194 +ifeq ($(OPENJDK_TARGET_OS),solaris) 1.195 +# On Solaris, if the target is a symlink and exists, cp won't overwrite. 1.196 +define install-file 1.197 + $(MKDIR) -p $(@D) 1.198 + $(RM) '$@' 1.199 + $(CP) -f -r -P '$<' '$(@D)' 1.200 +endef 1.201 +else ifeq ($(OPENJDK_TARGET_OS),macosx) 1.202 +define install-file 1.203 + $(MKDIR) -p $(@D) 1.204 + $(CP) -fpRP '$<' '$@' 1.205 +endef 1.206 +else 1.207 +define install-file 1.208 + $(MKDIR) -p $(@D) 1.209 + $(CP) -fP '$<' '$@' 1.210 +endef 1.211 +endif 1.212 + 1.213 endif # _MAKEBASE_GMK