InitSupport.gmk revision 1817:a151b3ec17a1
1#
2# Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
3# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4#
5# This code is free software; you can redistribute it and/or modify it
6# under the terms of the GNU General Public License version 2 only, as
7# published by the Free Software Foundation.  Oracle designates this
8# particular file as subject to the "Classpath" exception as provided
9# by Oracle in the LICENSE file that accompanied this code.
10#
11# This code is distributed in the hope that it will be useful, but WITHOUT
12# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14# version 2 for more details (a copy is included in the LICENSE file that
15# accompanied this code).
16#
17# You should have received a copy of the GNU General Public License version
18# 2 along with this work; if not, write to the Free Software Foundation,
19# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20#
21# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22# or visit www.oracle.com if you need additional information or have any
23# questions.
24#
25
26################################################################################
27# This file contains helper functions for Init.gmk.
28# It is divided in two parts, depending on if a SPEC is present or not
29# (HAS_SPEC is true or not).
30################################################################################
31
32ifndef _INITSUPPORT_GMK
33_INITSUPPORT_GMK := 1
34
35ifeq ($(HAS_SPEC),)
36  ##############################################################################
37  # Helper functions for the initial part of Init.gmk, before the spec file is
38  # loaded. Most of these functions provide parsing and setting up make options
39  # from the command-line.
40  ##############################################################################
41
42  # Make control variables, handled by Init.gmk
43  INIT_CONTROL_VARIABLES := LOG CONF CONF_NAME SPEC JOBS CONF_CHECK COMPARE_BUILD
44
45  # All known make control variables
46  MAKE_CONTROL_VARIABLES := $(INIT_CONTROL_VARIABLES) TEST JDK_FILTER
47
48  # Define a simple reverse function.
49  # Should maybe move to MakeBase.gmk, but we can't include that file now.
50  reverse = \
51      $(if $(strip $(1)), $(call reverse, $(wordlist 2, $(words $(1)), $(1)))) \
52          $(firstword $(1))
53
54  # The variable MAKEOVERRIDES contains variable assignments from the command
55  # line, but in reverse order to what the user entered.
56  # The '\#' <=> '\ 'dance is needed to keep values with space in them connected.
57  COMMAND_LINE_VARIABLES := $(subst \#,\ , $(call reverse, $(subst \ ,\#,$(MAKEOVERRIDES))))
58
59  # A list like FOO="val1" BAR="val2" containing all user-supplied make
60  # variables that we should propagate.
61  # The '\#' <=> '\ 'dance is needed to keep values with space in them connected.
62  USER_MAKE_VARS := $(subst \#,\ , $(filter-out $(addsuffix =%, $(INIT_CONTROL_VARIABLES)), \
63      $(subst \ ,\#,$(MAKEOVERRIDES))))
64
65  # Setup information about available configurations, if any.
66  build_dir=$(topdir)/build
67  all_spec_files=$(wildcard $(build_dir)/*/spec.gmk)
68  # Extract the configuration names from the path
69  all_confs=$(patsubst %/spec.gmk, %, $(patsubst $(build_dir)/%, %, $(all_spec_files)))
70
71  # Check for unknown command-line variables
72  define CheckControlVariables
73    command_line_variables := $$(strip $$(foreach var, \
74        $$(subst \ ,_,$$(MAKEOVERRIDES)), \
75        $$(firstword $$(subst =, , $$(var)))))
76    unknown_command_line_variables := $$(strip \
77        $$(filter-out $$(MAKE_CONTROL_VARIABLES), $$(command_line_variables)))
78    ifneq ($$(unknown_command_line_variables), )
79      $$(info Note: Command line contains non-control variables:)
80      $$(foreach var, $$(unknown_command_line_variables), $$(info * $$(var)=$$($$(var))))
81      $$(info Make sure it is not mistyped, and that you intend to override this variable.)
82      $$(info 'make help' will list known control variables.)
83      $$(info )
84    endif
85  endef
86
87  # Check for deprecated ALT_ variables
88  define CheckDeprecatedEnvironment
89    defined_alt_variables := $$(filter ALT_%, $$(.VARIABLES))
90    ifneq ($$(defined_alt_variables), )
91      $$(info Warning: You have the following ALT_ variables set:)
92      $$(foreach var, $$(defined_alt_variables), $$(info * $$(var)=$$($$(var))))
93      $$(info ALT_ variables are deprecated, and may result in a failed build.)
94      $$(info Please clean your environment.)
95      $$(info )
96    endif
97  endef
98
99  # Check for invalid make flags like -j
100  define CheckInvalidMakeFlags
101    # This is a trick to get this rule to execute before any other rules
102    # MAKEFLAGS only indicate -j if read in a recipe (!)
103    $$(topdir)/make/Init.gmk: .FORCE
104	$$(if $$(findstring --jobserver, $$(MAKEFLAGS)), \
105	    $$(info Error: 'make -jN' is not supported, use 'make JOBS=N') \
106	    $$(error Cannot continue) \
107	)
108    .FORCE:
109    .PHONY: .FORCE
110  endef
111
112  # Check that the CONF_CHECK option is valid and set up handling
113  define ParseConfCheckOption
114    ifeq ($$(CONF_CHECK), )
115      # Default behavior is fail
116      CONF_CHECK := fail
117    else ifneq ($$(filter-out auto fail ignore, $$(CONF_CHECK)),)
118      $$(info Error: CONF_CHECK must be one of: auto, fail or ignore.)
119      $$(error Cannot continue)
120    endif
121  endef
122
123  define ParseLogLevel
124    # Catch old-style VERBOSE= command lines.
125    ifneq ($$(origin VERBOSE), undefined)
126      $$(info Error: VERBOSE is deprecated. Use LOG=<warn|info|debug|trace> instead.)
127      $$(error Cannot continue)
128    endif
129
130    # Setup logging according to LOG
131
132    # If the "nofile" argument is given, act on it and strip it away
133    ifneq ($$(findstring nofile, $$(LOG)),)
134      LOG_NOFILE := true
135      # COMMA is defined in spec.gmk, but that is not included yet
136      COMMA := ,
137      # First try to remove ",nofile" if it exists, otherwise just remove "nofile"
138      LOG_STRIPPED := $$(subst nofile,, $$(subst $$(COMMA)nofile,, $$(LOG)))
139      # We might have ended up with a leading comma. Remove it
140      LOG_LEVEL := $$(strip $$(patsubst $$(COMMA)%, %, $$(LOG_STRIPPED)))
141    else
142      LOG_LEVEL := $$(LOG)
143    endif
144
145    ifeq ($$(LOG_LEVEL),)
146      # Set LOG to "warn" as default if not set
147      LOG_LEVEL := warn
148    endif
149
150    ifeq ($$(LOG_LEVEL), warn)
151      MAKE_LOG_FLAGS := -s
152    else ifeq ($$(LOG_LEVEL), info)
153      MAKE_LOG_FLAGS := -s
154    else ifeq ($$(LOG_LEVEL), debug)
155      MAKE_LOG_FLAGS :=
156    else ifeq ($$(LOG_LEVEL), trace)
157      MAKE_LOG_FLAGS := -d
158    else
159      $$(info Error: LOG must be one of: warn, info, debug or trace.)
160      $$(error Cannot continue)
161    endif
162  endef
163
164  define ParseConfAndSpec
165    ifneq ($$(origin SPEC), undefined)
166      # We have been given a SPEC, check that it works out properly
167      ifneq ($$(origin CONF), undefined)
168        # We also have a CONF argument. We can't have both.
169        $$(info Error: Cannot use CONF=$$(CONF) and SPEC=$$(SPEC) at the same time. Choose one.)
170        $$(error Cannot continue)
171      endif
172      ifneq ($$(origin CONF_NAME), undefined)
173        # We also have a CONF_NAME argument. We can't have both.
174        $$(info Error: Cannot use CONF_NAME=$$(CONF_NAME) and SPEC=$$(SPEC) at the same time. Choose one.)
175        $$(error Cannot continue)
176      endif
177      ifeq ($$(wildcard $$(SPEC)),)
178        $$(info Error: Cannot locate spec.gmk, given by SPEC=$$(SPEC).)
179        $$(error Cannot continue)
180      endif
181      ifeq ($$(filter /%, $$(SPEC)),)
182        # If given with relative path, make it absolute
183        SPECS := $$(CURDIR)/$$(strip $$(SPEC))
184      else
185        SPECS := $$(SPEC)
186      endif
187
188      # For now, unset this SPEC variable.
189      override SPEC :=
190    else
191      # Use spec.gmk files in the build output directory
192      ifeq ($$(all_spec_files),)
193        $$(info Error: No configurations found for $$(topdir).)
194        $$(info Please run 'bash configure' to create a configuration.)
195        $$(info )
196        $$(error Cannot continue)
197      endif
198
199      ifneq ($$(origin CONF_NAME), undefined)
200        ifneq ($$(origin CONF), undefined)
201          # We also have a CONF argument. We can't have both.
202          $$(info Error: Cannot use CONF=$$(CONF) and CONF_NAME=$$(CONF_NAME) at the same time. Choose one.)
203          $$(error Cannot continue)
204        endif
205        matching_conf := $$(strip $$(filter $$(CONF_NAME), $$(all_confs)))
206        ifeq ($$(matching_conf),)
207          $$(info Error: No configurations found matching CONF_NAME=$$(CONF_NAME).)
208          $$(info Available configurations in $$(build_dir):)
209          $$(foreach var, $$(all_confs), $$(info * $$(var)))
210          $$(error Cannot continue)
211        else ifneq ($$(words $$(matching_conf)), 1)
212          $$(info Error: Matching more than one configuration CONF_NAME=$$(CONF_NAME).)
213          $$(info Available configurations in $$(build_dir):)
214          $$(foreach var, $$(all_confs), $$(info * $$(var)))
215          $$(error Cannot continue)
216        else
217          $$(info Building configuration '$$(matching_conf)' (matching CONF_NAME=$$(CONF_NAME)))
218        endif
219        # Create a SPEC definition. This will contain the path to exactly one spec file.
220        SPECS := $$(build_dir)/$$(matching_conf)/spec.gmk
221      else ifneq ($$(origin CONF), undefined)
222        # User have given a CONF= argument.
223        ifeq ($$(CONF),)
224          # If given CONF=, match all configurations
225          matching_confs := $$(strip $$(all_confs))
226        else
227          # Otherwise select those that contain the given CONF string
228          matching_confs := $$(strip $$(foreach var, $$(all_confs), \
229              $$(if $$(findstring $$(CONF), $$(var)), $$(var))))
230        endif
231        ifeq ($$(matching_confs),)
232          $$(info Error: No configurations found matching CONF=$$(CONF).)
233          $$(info Available configurations in $$(build_dir):)
234          $$(foreach var, $$(all_confs), $$(info * $$(var)))
235          $$(error Cannot continue)
236        else
237          ifeq ($$(words $$(matching_confs)), 1)
238            $$(info Building configuration '$$(matching_confs)' (matching CONF=$$(CONF)))
239          else
240            $$(info Building these configurations (matching CONF=$$(CONF)):)
241            $$(foreach var, $$(matching_confs), $$(info * $$(var)))
242          endif
243        endif
244
245        # Create a SPEC definition. This will contain the path to one or more spec.gmk files.
246        SPECS := $$(addsuffix /spec.gmk, $$(addprefix $$(build_dir)/, $$(matching_confs)))
247      else
248        # No CONF or SPEC given, check the available configurations
249        ifneq ($$(words $$(all_spec_files)), 1)
250          $$(info Error: No CONF given, but more than one configuration found.)
251          $$(info Available configurations in $$(build_dir):)
252          $$(foreach var, $$(all_confs), $$(info * $$(var)))
253          $$(info Please retry building with CONF=<config pattern> (or SPEC=<spec file>).)
254          $$(info )
255          $$(error Cannot continue)
256        endif
257
258        # We found exactly one configuration, use it
259        SPECS := $$(strip $$(all_spec_files))
260      endif
261    endif
262  endef
263
264  # Extract main targets from Main.gmk using the spec provided in $2.
265  #
266  # Param 1: FORCE = force generation of main-targets.gmk or LAZY = do not force.
267  # Param 2: The SPEC file to use.
268  define DefineMainTargets
269
270    # We will start by making sure the main-targets.gmk file is removed, if
271    # make has not been restarted. By the -include, we will trigger the
272    # rule for generating the file (which is never there since we removed it),
273    # thus generating it fresh, and make will restart, incrementing the restart
274    # count.
275    main_targets_file := $$(dir $(strip $2))make-support/main-targets.gmk
276
277    ifeq ($$(MAKE_RESTARTS),)
278      # Only do this if make has not been restarted, and if we do not force it.
279      ifeq ($(strip $1), FORCE)
280        $$(shell rm -f $$(main_targets_file))
281      endif
282    endif
283
284    $$(main_targets_file):
285	@( cd $$(topdir) && \
286	    $$(MAKE) $$(MAKE_LOG_FLAGS) -r -R -f $$(topdir)/make/Main.gmk \
287	    -I $$(topdir)/make/common SPEC=$(strip $2) NO_RECIPES=true \
288	    LOG_LEVEL=$$(LOG_LEVEL) \
289	    create-main-targets-include )
290
291    # Now include main-targets.gmk. This will define ALL_MAIN_TARGETS.
292    -include $$(main_targets_file)
293  endef
294
295  define PrintConfCheckFailed
296	@echo ' '
297	@echo "Please rerun configure! Easiest way to do this is by running"
298	@echo "'make reconfigure'."
299	@echo "This behavior may also be changed using CONF_CHECK=<ignore|auto>."
300	@echo ' '
301  endef
302
303else # $(HAS_SPEC)=true
304  ##############################################################################
305  # Helper functions for the 'main' target. These functions assume a single,
306  # proper and existing SPEC is included.
307  ##############################################################################
308
309  include $(SRC_ROOT)/make/common/MakeBase.gmk
310
311  # Define basic logging setup
312  BUILD_LOG := $(OUTPUT_ROOT)/build.log
313  BUILD_TRACE_LOG := $(OUTPUT_ROOT)/build-trace-time.log
314
315  BUILD_LOG_WRAPPER := $(BASH) $(SRC_ROOT)/common/bin/logger.sh $(BUILD_LOG)
316
317  # Sanity check the spec file, so it matches this source code
318  define CheckSpecSanity
319    ifneq ($$(ACTUAL_TOPDIR), $$(TOPDIR))
320      ifneq ($$(ACTUAL_TOPDIR), $$(ORIGINAL_TOPDIR))
321        ifneq ($$(ACTUAL_TOPDIR), $$(CANONICAL_TOPDIR))
322          $$(info Error: SPEC mismatch! Current working directory)
323          $$(info $$(ACTUAL_TOPDIR))
324          $$(info does not match either TOPDIR, ORIGINAL_TOPDIR or CANONICAL_TOPDIR)
325          $$(info $$(TOPDIR))
326          $$(info $$(ORIGINAL_TOPDIR))
327          $$(info $$(CANONICAL_TOPDIR))
328          $$(error Cannot continue)
329        endif
330      endif
331    endif
332  endef
333
334  # Parse COMPARE_BUILD into COMPARE_BUILD_*
335  # Syntax: COMPARE_BUILD=CONF=<configure options>:PATCH=<patch file>:
336  #         MAKE=<make targets>:COMP_OPTS=<compare script options>:
337  #         COMP_DIR=<compare script base dir>|<default>
338  # If neither CONF or PATCH is given, assume <default> means CONF if it
339  # begins with "--", otherwise assume it means PATCH.
340  # MAKE and COMP_OPTS can only be used with CONF and/or PATCH specified.
341  # If any value contains "+", it will be replaced by space.
342  define ParseCompareBuild
343    ifneq ($$(COMPARE_BUILD), )
344      COMPARE_BUILD_OUTPUT_ROOT := $(TOPDIR)/build/compare-build/$(CONF_NAME)
345
346      ifneq ($$(findstring :, $$(COMPARE_BUILD)), )
347        $$(foreach part, $$(subst :, , $$(COMPARE_BUILD)), \
348          $$(if $$(filter PATCH=%, $$(part)), \
349            $$(eval COMPARE_BUILD_PATCH=$$(strip $$(patsubst PATCH=%, %, $$(part)))) \
350          ) \
351          $$(if $$(filter CONF=%, $$(part)), \
352            $$(eval COMPARE_BUILD_CONF=$$(strip $$(subst +, , $$(patsubst CONF=%, %, $$(part))))) \
353          ) \
354          $$(if $$(filter MAKE=%, $$(part)), \
355            $$(eval COMPARE_BUILD_MAKE=$$(strip $$(subst +, , $$(patsubst MAKE=%, %, $$(part))))) \
356          ) \
357          $$(if $$(filter COMP_OPTS=%, $$(part)), \
358            $$(eval COMPARE_BUILD_COMP_OPTS=$$(strip $$(subst +, , $$(patsubst COMP_OPTS=%, %, $$(part))))) \
359          ) \
360          $$(if $$(filter COMP_DIR=%, $$(part)), \
361            $$(eval COMPARE_BUILD_COMP_DIR=$$(strip $$(subst +, , $$(patsubst COMP_DIR=%, %, $$(part))))) \
362          ) \
363        )
364      else
365        # Separate handling for single field case, to allow for spaces in values.
366        ifneq ($$(filter PATCH=%, $$(COMPARE_BUILD)), )
367          COMPARE_BUILD_PATCH=$$(strip $$(patsubst PATCH=%, %, $$(COMPARE_BUILD)))
368        else ifneq ($$(filter CONF=%, $$(COMPARE_BUILD)), )
369          COMPARE_BUILD_CONF=$$(strip $$(subst +, , $$(patsubst CONF=%, %, $$(COMPARE_BUILD))))
370        else ifneq ($$(filter --%, $$(COMPARE_BUILD)), )
371          # Assume CONF if value begins with --
372          COMPARE_BUILD_CONF=$$(strip $$(subst +, , $$(COMPARE_BUILD)))
373        else
374          # Otherwise assume patch file
375          COMPARE_BUILD_PATCH=$$(strip $$(COMPARE_BUILD))
376        endif
377      endif
378      ifneq ($$(COMPARE_BUILD_PATCH), )
379        ifneq ($$(wildcard $$(TOPDIR)/$$(COMPARE_BUILD_PATCH)), )
380          # Assume relative path, if file exists
381          COMPARE_BUILD_PATCH := $$(wildcard $$(TOPDIR)/$$(COMPARE_BUILD_PATCH))
382        else ifeq ($$(wildcard $$(COMPARE_BUILD_PATCH)), )
383          $$(error Patch file $$(COMPARE_BUILD_PATCH) does not exist)
384        endif
385      endif
386    endif
387  endef
388
389  # Prepare for a comparison rebuild
390  define PrepareCompareBuild
391	$(ECHO) "Preparing for comparison rebuild"
392        # Apply patch, if any
393	$(if $(COMPARE_BUILD_PATCH), $(PATCH) -p1 < $(COMPARE_BUILD_PATCH))
394        # Move the first build away temporarily
395	$(RM) -r $(TOPDIR)/build/.compare-build-temp
396	$(MKDIR) -p $(TOPDIR)/build/.compare-build-temp
397	$(MV) $(OUTPUT_ROOT) $(TOPDIR)/build/.compare-build-temp
398        # Restore an old compare-build, or create a new compare-build directory.
399	if test -d $(COMPARE_BUILD_OUTPUT_ROOT); then \
400	  $(MV) $(COMPARE_BUILD_OUTPUT_ROOT) $(OUTPUT_ROOT); \
401	else \
402	  $(MKDIR) -p $(OUTPUT_ROOT); \
403	fi
404        # Re-run configure with the same arguments (and possibly some additional),
405        # must be done after patching.
406	( cd $(OUTPUT_ROOT) && PATH="$(ORIGINAL_PATH)" \
407	    $(BASH) $(TOPDIR)/configure $(CONFIGURE_COMMAND_LINE) $(COMPARE_BUILD_CONF))
408  endef
409
410  # Cleanup after a compare build
411  define CleanupCompareBuild
412        # If running with a COMPARE_BUILD patch, reverse-apply it
413	$(if $(COMPARE_BUILD_PATCH), $(PATCH) -R -p1 < $(COMPARE_BUILD_PATCH))
414        # Move this build away and restore the original build
415	$(MKDIR) -p $(TOPDIR)/build/compare-build
416	$(MV) $(OUTPUT_ROOT) $(COMPARE_BUILD_OUTPUT_ROOT)
417	$(MV) $(TOPDIR)/build/.compare-build-temp/$(CONF_NAME) $(OUTPUT_ROOT)
418	$(RM) -r $(TOPDIR)/build/.compare-build-temp
419  endef
420
421  # Do the actual comparison of two builds
422  define CompareBuildDoComparison
423        # Compare first and second build. Ignore any error code from compare.sh.
424	$(ECHO) "Comparing between comparison rebuild (this/new) and baseline (other/old)"
425	$(if $(COMPARE_BUILD_COMP_DIR), \
426	  +(cd $(COMPARE_BUILD_OUTPUT_ROOT) && ./compare.sh $(COMPARE_BUILD_COMP_OPTS) \
427	      -2dirs $(COMPARE_BUILD_OUTPUT_ROOT)/$(COMPARE_BUILD_COMP_DIR) $(OUTPUT_ROOT)/$(COMPARE_BUILD_COMP_DIR) || true), \
428	  +(cd $(COMPARE_BUILD_OUTPUT_ROOT) && ./compare.sh $(COMPARE_BUILD_COMP_OPTS) \
429	      -o $(OUTPUT_ROOT) || true) \
430	)
431  endef
432
433  define PrintFailureReports
434	$(if $(wildcard $(MAKESUPPORT_OUTPUTDIR)/failure-logs/*), \
435	  $(PRINTF) "=== Output from failing command(s) repeated here ===\n" $(NEWLINE) \
436	  $(foreach logfile, $(sort $(wildcard $(MAKESUPPORT_OUTPUTDIR)/failure-logs/*)), \
437	      $(PRINTF) "* For target $(notdir $(basename $(logfile))):\n" $(NEWLINE) \
438	      $(CAT) $(logfile) | $(GREP) -v -e "^Note: including file:" $(NEWLINE) \
439	  ) \
440	  $(PRINTF) "=== End of repeated output ===\n" \
441	)
442  endef
443
444  define PrintBuildLogFailures
445	if $(GREP) -q "recipe for target .* failed" $(BUILD_LOG) 2> /dev/null; then  \
446	  $(PRINTF) "=== Make failure sequence repeated here ===\n" ; \
447	  $(GREP) "recipe for target .* failed" $(BUILD_LOG) ; \
448	  $(PRINTF) "=== End of repeated output ===\n" ; \
449	  $(PRINTF) "Hint: Try searching the build log for the name of the first failed target.\n" ; \
450	else \
451	  $(PRINTF) "No indication of failed target found.\n" ; \
452	  $(PRINTF) "Hint: Try searching the build log for '] Error'.\n" ; \
453	fi
454  endef
455
456  define RotateLogFiles
457	$(RM) $(BUILD_LOG).old 2> /dev/null
458	$(MV) $(BUILD_LOG) $(BUILD_LOG).old 2> /dev/null || true
459	$(if $(findstring trace, $(LOG_LEVEL)), \
460	  $(RM) $(BUILD_TRACE_LOG).old 2> /dev/null && \
461	  $(MV) $(BUILD_TRACE_LOG) $(BUILD_TRACE_LOG).old 2> /dev/null || true \
462	)
463  endef
464
465  define PrepareFailureLogs
466	$(RM) -r $(MAKESUPPORT_OUTPUTDIR)/failure-logs 2> /dev/null
467	$(MKDIR) -p $(MAKESUPPORT_OUTPUTDIR)/failure-logs
468  endef
469
470  # Remove any javac server logs and port files. This
471  # prevents a new make run to reuse the previous servers.
472  define PrepareSmartJavac
473	$(if $(SJAVAC_SERVER_DIR), \
474	  $(RM) -r $(SJAVAC_SERVER_DIR) 2> /dev/null && \
475	  $(MKDIR) -p $(SJAVAC_SERVER_DIR) \
476	)
477  endef
478
479  define CleanupSmartJavac
480	[ -f $(SJAVAC_SERVER_DIR)/server.port ] && $(ECHO) Stopping sjavac server && \
481	    $(TOUCH) $(SJAVAC_SERVER_DIR)/server.port.stop; true
482  endef
483
484  define StartGlobalTimer
485	$(RM) -r $(BUILDTIMESDIR) 2> /dev/null
486	$(MKDIR) -p $(BUILDTIMESDIR)
487	$(call RecordStartTime,TOTAL)
488  endef
489
490  define StopGlobalTimer
491	$(call RecordEndTime,TOTAL)
492  endef
493
494  # Find all build_time_* files and print their contents in a list sorted
495  # on the name of the sub repository.
496  define ReportBuildTimes
497	$(BUILD_LOG_WRAPPER) $(PRINTF) $(LOG_INFO) -- \
498	    "----- Build times -------\nStart %s\nEnd   %s\n%s\n%s\n-------------------------\n" \
499	    "`$(CAT) $(BUILDTIMESDIR)/build_time_start_TOTAL_human_readable`" \
500	    "`$(CAT) $(BUILDTIMESDIR)/build_time_end_TOTAL_human_readable`" \
501	    "`$(LS) $(BUILDTIMESDIR)/build_time_diff_* | $(GREP) -v _TOTAL | \
502	    $(XARGS) $(CAT) | $(SORT) -k 2`" \
503	    "`$(CAT) $(BUILDTIMESDIR)/build_time_diff_TOTAL`"
504  endef
505
506endif # HAS_SPEC
507
508endif # _INITSUPPORT_GMK
509