InitSupport.gmk revision 1745:b75a6740986a
1169689Skan#
2169689Skan# Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
3169689Skan# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4169689Skan#
5169689Skan# This code is free software; you can redistribute it and/or modify it
6169689Skan# under the terms of the GNU General Public License version 2 only, as
7169689Skan# published by the Free Software Foundation.  Oracle designates this
8169689Skan# particular file as subject to the "Classpath" exception as provided
9169689Skan# by Oracle in the LICENSE file that accompanied this code.
10169689Skan#
11169689Skan# This code is distributed in the hope that it will be useful, but WITHOUT
12169689Skan# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13169689Skan# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14169689Skan# version 2 for more details (a copy is included in the LICENSE file that
15169689Skan# accompanied this code).
16169689Skan#
17169689Skan# You should have received a copy of the GNU General Public License version
18169689Skan# 2 along with this work; if not, write to the Free Software Foundation,
19169689Skan# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20169689Skan#
21169689Skan# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22169689Skan# or visit www.oracle.com if you need additional information or have any
23169689Skan# questions.
24169689Skan#
25169689Skan
26169689Skan################################################################################
27169689Skan# This file contains helper functions for Init.gmk.
28169689Skan# It is divided in two parts, depending on if a SPEC is present or not
29169689Skan# (HAS_SPEC is true or not).
30169689Skan################################################################################
31169689Skan
32169689Skanifndef _INITSUPPORT_GMK
33169689Skan_INITSUPPORT_GMK := 1
34169689Skan
35169689Skanifeq ($(HAS_SPEC),)
36169689Skan  ##############################################################################
37169689Skan  # Helper functions for the initial part of Init.gmk, before the spec file is
38169689Skan  # loaded. Most of these functions provide parsing and setting up make options
39169689Skan  # from the command-line.
40169689Skan  ##############################################################################
41169689Skan
42169689Skan  # Make control variables, handled by Init.gmk
43169689Skan  INIT_CONTROL_VARIABLES := LOG CONF SPEC JOBS CONF_CHECK COMPARE_BUILD
44169689Skan
45169689Skan  # All known make control variables
46169689Skan  MAKE_CONTROL_VARIABLES := $(INIT_CONTROL_VARIABLES) TEST JDK_FILTER
47169689Skan
48169689Skan  # Define a simple reverse function.
49169689Skan  # Should maybe move to MakeBase.gmk, but we can't include that file now.
50169689Skan  reverse = \
51169689Skan      $(if $(strip $(1)), $(call reverse, $(wordlist 2, $(words $(1)), $(1)))) \
52169689Skan          $(firstword $(1))
53169689Skan
54169689Skan  # The variable MAKEOVERRIDES contains variable assignments from the command
55169689Skan  # line, but in reverse order to what the user entered.
56169689Skan  # The '\#' <=> '\ 'dance is needed to keep values with space in them connected.
57169689Skan  COMMAND_LINE_VARIABLES := $(subst \#,\ , $(call reverse, $(subst \ ,\#,$(MAKEOVERRIDES))))
58169689Skan
59169689Skan  # A list like FOO="val1" BAR="val2" containing all user-supplied make
60169689Skan  # variables that we should propagate.
61169689Skan  # The '\#' <=> '\ 'dance is needed to keep values with space in them connected.
62169689Skan  USER_MAKE_VARS := $(subst \#,\ , $(filter-out $(addsuffix =%, $(INIT_CONTROL_VARIABLES)), \
63169689Skan      $(subst \ ,\#,$(MAKEOVERRIDES))))
64169689Skan
65169689Skan  # Setup information about available configurations, if any.
66169689Skan  build_dir=$(topdir)/build
67169689Skan  all_spec_files=$(wildcard $(build_dir)/*/spec.gmk)
68169689Skan  # Extract the configuration names from the path
69169689Skan  all_confs=$(patsubst %/spec.gmk, %, $(patsubst $(build_dir)/%, %, $(all_spec_files)))
70169689Skan
71169689Skan  # Check for unknown command-line variables
72169689Skan  define CheckControlVariables
73169689Skan    command_line_variables := $$(strip $$(foreach var, \
74169689Skan        $$(subst \ ,_,$$(MAKEOVERRIDES)), \
75169689Skan        $$(firstword $$(subst =, , $$(var)))))
76169689Skan    unknown_command_line_variables := $$(strip \
77169689Skan        $$(filter-out $$(MAKE_CONTROL_VARIABLES), $$(command_line_variables)))
78169689Skan    ifneq ($$(unknown_command_line_variables), )
79169689Skan      $$(info Note: Command line contains non-control variables:)
80169689Skan      $$(foreach var, $$(unknown_command_line_variables), $$(info * $$(var)=$$($$(var))))
81169689Skan      $$(info Make sure it is not mistyped, and that you intend to override this variable.)
82169689Skan      $$(info 'make help' will list known control variables.)
83169689Skan      $$(info )
84169689Skan    endif
85169689Skan  endef
86169689Skan
87169689Skan  # Check for deprecated ALT_ variables
88169689Skan  define CheckDeprecatedEnvironment
89169689Skan    defined_alt_variables := $$(filter ALT_%, $$(.VARIABLES))
90169689Skan    ifneq ($$(defined_alt_variables), )
91169689Skan      $$(info Warning: You have the following ALT_ variables set:)
92169689Skan      $$(foreach var, $$(defined_alt_variables), $$(info * $$(var)=$$($$(var))))
93169689Skan      $$(info ALT_ variables are deprecated, and may result in a failed build.)
94169689Skan      $$(info Please clean your environment.)
95169689Skan      $$(info )
96169689Skan    endif
97169689Skan  endef
98169689Skan
99169689Skan  # Check for invalid make flags like -j
100169689Skan  define CheckInvalidMakeFlags
101169689Skan    # This is a trick to get this rule to execute before any other rules
102169689Skan    # MAKEFLAGS only indicate -j if read in a recipe (!)
103169689Skan    $$(topdir)/make/Init.gmk: .FORCE
104169689Skan	$$(if $$(findstring --jobserver, $$(MAKEFLAGS)), \
105169689Skan	    $$(info Error: 'make -jN' is not supported, use 'make JOBS=N') \
106169689Skan	    $$(error Cannot continue) \
107169689Skan	)
108169689Skan    .FORCE:
109169689Skan    .PHONY: .FORCE
110169689Skan  endef
111169689Skan
112169689Skan  # Check that the CONF_CHECK option is valid and set up handling
113169689Skan  define ParseConfCheckOption
114169689Skan    ifeq ($$(CONF_CHECK), )
115169689Skan      # Default behavior is fail
116169689Skan      CONF_CHECK := fail
117169689Skan    else ifneq ($$(filter-out auto fail ignore, $$(CONF_CHECK)),)
118169689Skan      $$(info Error: CONF_CHECK must be one of: auto, fail or ignore.)
119169689Skan      $$(error Cannot continue)
120169689Skan    endif
121169689Skan  endef
122169689Skan
123169689Skan  define ParseLogLevel
124169689Skan    # Catch old-style VERBOSE= command lines.
125169689Skan    ifneq ($$(origin VERBOSE), undefined)
126169689Skan      $$(info Error: VERBOSE is deprecated. Use LOG=<warn|info|debug|trace> instead.)
127169689Skan      $$(error Cannot continue)
128169689Skan    endif
129169689Skan
130169689Skan    # Setup logging according to LOG
131169689Skan
132169689Skan    # If the "nofile" argument is given, act on it and strip it away
133169689Skan    ifneq ($$(findstring nofile, $$(LOG)),)
134169689Skan      LOG_NOFILE := true
135169689Skan      # COMMA is defined in spec.gmk, but that is not included yet
136169689Skan      COMMA := ,
137169689Skan      # First try to remove ",nofile" if it exists, otherwise just remove "nofile"
138169689Skan      LOG_STRIPPED := $$(subst nofile,, $$(subst $$(COMMA)nofile,, $$(LOG)))
139169689Skan      # We might have ended up with a leading comma. Remove it
140169689Skan      LOG_LEVEL := $$(strip $$(patsubst $$(COMMA)%, %, $$(LOG_STRIPPED)))
141169689Skan    else
142169689Skan      LOG_LEVEL := $$(LOG)
143169689Skan    endif
144169689Skan
145169689Skan    ifeq ($$(LOG_LEVEL),)
146169689Skan      # Set LOG to "warn" as default if not set
147169689Skan      LOG_LEVEL := warn
148169689Skan    endif
149169689Skan
150169689Skan    ifeq ($$(LOG_LEVEL), warn)
151169689Skan      MAKE_LOG_FLAGS := -s
152169689Skan    else ifeq ($$(LOG_LEVEL), info)
153169689Skan      MAKE_LOG_FLAGS := -s
154169689Skan    else ifeq ($$(LOG_LEVEL), debug)
155169689Skan      MAKE_LOG_FLAGS :=
156169689Skan    else ifeq ($$(LOG_LEVEL), trace)
157169689Skan      MAKE_LOG_FLAGS := -d
158169689Skan    else
159169689Skan      $$(info Error: LOG must be one of: warn, info, debug or trace.)
160169689Skan      $$(error Cannot continue)
161169689Skan    endif
162169689Skan  endef
163169689Skan
164169689Skan  define ParseConfAndSpec
165169689Skan    ifneq ($$(origin SPEC), undefined)
166169689Skan      # We have been given a SPEC, check that it works out properly
167169689Skan      ifneq ($$(origin CONF), undefined)
168169689Skan        # We also have a CONF argument. We can't have both.
169169689Skan        $$(info Error: Cannot use CONF=$$(CONF) and SPEC=$$(SPEC) at the same time. Choose one.)
170169689Skan        $$(error Cannot continue)
171169689Skan      endif
172169689Skan      ifeq ($$(wildcard $$(SPEC)),)
173169689Skan        $$(info Error: Cannot locate spec.gmk, given by SPEC=$$(SPEC).)
174169689Skan        $$(error Cannot continue)
175169689Skan      endif
176169689Skan      ifeq ($$(filter /%, $$(SPEC)),)
177169689Skan        # If given with relative path, make it absolute
178169689Skan        SPECS := $$(CURDIR)/$$(strip $$(SPEC))
179169689Skan      else
180169689Skan        SPECS := $$(SPEC)
181169689Skan      endif
182169689Skan
183169689Skan      # For now, unset this SPEC variable.
184169689Skan      override SPEC :=
185169689Skan    else
186169689Skan      # Use spec.gmk files in the build output directory
187169689Skan      ifeq ($$(all_spec_files),)
188169689Skan        $$(info Error: No configurations found for $$(topdir).)
189169689Skan        $$(info Please run 'bash configure' to create a configuration.)
190169689Skan        $$(info )
191169689Skan        $$(error Cannot continue)
192169689Skan      endif
193169689Skan
194169689Skan      ifneq ($$(origin CONF), undefined)
195169689Skan        # User have given a CONF= argument.
196169689Skan        ifeq ($$(CONF),)
197169689Skan          # If given CONF=, match all configurations
198169689Skan          matching_confs := $$(strip $$(all_confs))
199169689Skan        else
200169689Skan          # Otherwise select those that contain the given CONF string
201169689Skan          matching_confs := $$(strip $$(foreach var, $$(all_confs), \
202169689Skan              $$(if $$(findstring $$(CONF), $$(var)), $$(var))))
203169689Skan        endif
204169689Skan        ifeq ($$(matching_confs),)
205169689Skan          $$(info Error: No configurations found matching CONF=$$(CONF).)
206169689Skan          $$(info Available configurations in $$(build_dir):)
207169689Skan          $$(foreach var, $$(all_confs), $$(info * $$(var)))
208169689Skan          $$(error Cannot continue)
209169689Skan        else
210169689Skan          ifeq ($$(words $$(matching_confs)), 1)
211169689Skan            $$(info Building configuration '$$(matching_confs)' (matching CONF=$$(CONF)))
212169689Skan          else
213169689Skan            $$(info Building these configurations (matching CONF=$$(CONF)):)
214169689Skan            $$(foreach var, $$(matching_confs), $$(info * $$(var)))
215169689Skan          endif
216169689Skan        endif
217169689Skan
218169689Skan        # Create a SPEC definition. This will contain the path to one or more spec.gmk files.
219169689Skan        SPECS := $$(addsuffix /spec.gmk, $$(addprefix $$(build_dir)/, $$(matching_confs)))
220169689Skan      else
221169689Skan        # No CONF or SPEC given, check the available configurations
222169689Skan        ifneq ($$(words $$(all_spec_files)), 1)
223169689Skan          $$(info Error: No CONF given, but more than one configuration found.)
224169689Skan          $$(info Available configurations in $$(build_dir):)
225169689Skan          $$(foreach var, $$(all_confs), $$(info * $$(var)))
226169689Skan          $$(info Please retry building with CONF=<config pattern> (or SPEC=<spec file>).)
227169689Skan          $$(info )
228169689Skan          $$(error Cannot continue)
229169689Skan        endif
230169689Skan
231169689Skan        # We found exactly one configuration, use it
232169689Skan        SPECS := $$(strip $$(all_spec_files))
233169689Skan      endif
234169689Skan    endif
235169689Skan  endef
236169689Skan
237169689Skan  # Extract main targets from Main.gmk using the spec provided in $2.
238169689Skan  #
239169689Skan  # Param 1: FORCE = force generation of main-targets.gmk or LAZY = do not force.
240169689Skan  # Param 2: The SPEC file to use.
241169689Skan  define DefineMainTargets
242169689Skan
243169689Skan    # We will start by making sure the main-targets.gmk file is removed, if
244169689Skan    # make has not been restarted. By the -include, we will trigger the
245169689Skan    # rule for generating the file (which is never there since we removed it),
246169689Skan    # thus generating it fresh, and make will restart, incrementing the restart
247169689Skan    # count.
248169689Skan    main_targets_file := $$(dir $(strip $2))make-support/main-targets.gmk
249169689Skan
250169689Skan    ifeq ($$(MAKE_RESTARTS),)
251169689Skan      # Only do this if make has not been restarted, and if we do not force it.
252169689Skan      ifeq ($(strip $1), FORCE)
253169689Skan        $$(shell rm -f $$(main_targets_file))
254169689Skan      endif
255169689Skan    endif
256169689Skan
257169689Skan    $$(main_targets_file):
258169689Skan	@( cd $$(topdir) && \
259169689Skan	    $$(MAKE) $$(MAKE_LOG_FLAGS) -r -R -f $$(topdir)/make/Main.gmk \
260169689Skan	    -I $$(topdir)/make/common SPEC=$(strip $2) NO_RECIPES=true \
261169689Skan	    LOG_LEVEL=$$(LOG_LEVEL) \
262169689Skan	    create-main-targets-include )
263169689Skan
264169689Skan    # Now include main-targets.gmk. This will define ALL_MAIN_TARGETS.
265169689Skan    -include $$(main_targets_file)
266169689Skan  endef
267169689Skan
268169689Skan  define PrintConfCheckFailed
269169689Skan	@echo ' '
270169689Skan	@echo "Please rerun configure! Easiest way to do this is by running"
271169689Skan	@echo "'make reconfigure'."
272169689Skan	@echo "This behavior may also be changed using CONF_CHECK=<ignore|auto>."
273169689Skan	@echo ' '
274169689Skan  endef
275169689Skan
276169689Skanelse # $(HAS_SPEC)=true
277169689Skan  ##############################################################################
278169689Skan  # Helper functions for the 'main' target. These functions assume a single,
279169689Skan  # proper and existing SPEC is included.
280169689Skan  ##############################################################################
281169689Skan
282169689Skan  include $(SRC_ROOT)/make/common/MakeBase.gmk
283169689Skan
284169689Skan  # Define basic logging setup
285169689Skan  BUILD_LOG := $(OUTPUT_ROOT)/build.log
286169689Skan  BUILD_TRACE_LOG := $(OUTPUT_ROOT)/build-trace-time.log
287169689Skan
288169689Skan  BUILD_LOG_WRAPPER := $(BASH) $(SRC_ROOT)/common/bin/logger.sh $(BUILD_LOG)
289169689Skan
290169689Skan  # Disable the build log wrapper on sjavac+windows until
291169689Skan  # we have solved how to prevent the log wrapper to wait
292169689Skan  # for the background sjavac server process.
293169689Skan  ifeq ($(ENABLE_SJAVAC)X$(OPENJDK_BUILD_OS),yesXwindows)
294169689Skan    LOG_NOFILE := true
295169689Skan  endif
296169689Skan
297169689Skan  # Sanity check the spec file, so it matches this source code
298169689Skan  define CheckSpecSanity
299169689Skan    ifneq ($$(ACTUAL_TOPDIR), $$(TOPDIR))
300169689Skan      ifneq ($$(ACTUAL_TOPDIR), $$(ORIGINAL_TOPDIR))
301169689Skan        ifneq ($$(ACTUAL_TOPDIR), $$(CANONICAL_TOPDIR))
302169689Skan          $$(info Error: SPEC mismatch! Current working directory)
303169689Skan          $$(info $$(ACTUAL_TOPDIR))
304169689Skan          $$(info does not match either TOPDIR, ORIGINAL_TOPDIR or CANONICAL_TOPDIR)
305169689Skan          $$(info $$(TOPDIR))
306169689Skan          $$(info $$(ORIGINAL_TOPDIR))
307169689Skan          $$(info $$(CANONICAL_TOPDIR))
308169689Skan          $$(error Cannot continue)
309169689Skan        endif
310169689Skan      endif
311169689Skan    endif
312169689Skan  endef
313169689Skan
314169689Skan  # Parse COMPARE_BUILD into COMPARE_BUILD_*
315169689Skan  # Syntax: COMPARE_BUILD=CONF=<configure options>:PATCH=<patch file>:
316169689Skan  #         MAKE=<make targets>:COMP_OPTS=<compare script options>:
317169689Skan  #         COMP_DIR=<compare script base dir>|<default>
318169689Skan  # If neither CONF or PATCH is given, assume <default> means CONF if it
319169689Skan  # begins with "--", otherwise assume it means PATCH.
320169689Skan  # MAKE and COMP_OPTS can only be used with CONF and/or PATCH specified.
321169689Skan  # If any value contains "+", it will be replaced by space.
322169689Skan  define ParseCompareBuild
323169689Skan    ifneq ($$(COMPARE_BUILD), )
324169689Skan      COMPARE_BUILD_OUTPUT_ROOT := $(TOPDIR)/build/compare-build/$(CONF_NAME)
325169689Skan
326169689Skan      ifneq ($$(findstring :, $$(COMPARE_BUILD)), )
327169689Skan        $$(foreach part, $$(subst :, , $$(COMPARE_BUILD)), \
328169689Skan          $$(if $$(filter PATCH=%, $$(part)), \
329169689Skan            $$(eval COMPARE_BUILD_PATCH=$$(strip $$(patsubst PATCH=%, %, $$(part)))) \
330169689Skan          ) \
331169689Skan          $$(if $$(filter CONF=%, $$(part)), \
332169689Skan            $$(eval COMPARE_BUILD_CONF=$$(strip $$(subst +, , $$(patsubst CONF=%, %, $$(part))))) \
333169689Skan          ) \
334169689Skan          $$(if $$(filter MAKE=%, $$(part)), \
335169689Skan            $$(eval COMPARE_BUILD_MAKE=$$(strip $$(subst +, , $$(patsubst MAKE=%, %, $$(part))))) \
336169689Skan          ) \
337169689Skan          $$(if $$(filter COMP_OPTS=%, $$(part)), \
338169689Skan            $$(eval COMPARE_BUILD_COMP_OPTS=$$(strip $$(subst +, , $$(patsubst COMP_OPTS=%, %, $$(part))))) \
339169689Skan          ) \
340169689Skan          $$(if $$(filter COMP_DIR=%, $$(part)), \
341169689Skan            $$(eval COMPARE_BUILD_COMP_DIR=$$(strip $$(subst +, , $$(patsubst COMP_DIR=%, %, $$(part))))) \
342169689Skan          ) \
343169689Skan        )
344169689Skan      else
345169689Skan        # Separate handling for single field case, to allow for spaces in values.
346169689Skan        ifneq ($$(filter PATCH=%, $$(COMPARE_BUILD)), )
347169689Skan          COMPARE_BUILD_PATCH=$$(strip $$(patsubst PATCH=%, %, $$(COMPARE_BUILD)))
348169689Skan        else ifneq ($$(filter CONF=%, $$(COMPARE_BUILD)), )
349169689Skan          COMPARE_BUILD_CONF=$$(strip $$(subst +, , $$(patsubst CONF=%, %, $$(COMPARE_BUILD))))
350169689Skan        else ifneq ($$(filter --%, $$(COMPARE_BUILD)), )
351169689Skan          # Assume CONF if value begins with --
352169689Skan          COMPARE_BUILD_CONF=$$(strip $$(subst +, , $$(COMPARE_BUILD)))
353169689Skan        else
354169689Skan          # Otherwise assume patch file
355169689Skan          COMPARE_BUILD_PATCH=$$(strip $$(COMPARE_BUILD))
356169689Skan        endif
357169689Skan      endif
358169689Skan      ifneq ($$(COMPARE_BUILD_PATCH), )
359169689Skan        ifneq ($$(wildcard $$(TOPDIR)/$$(COMPARE_BUILD_PATCH)), )
360169689Skan          # Assume relative path, if file exists
361169689Skan          COMPARE_BUILD_PATCH := $$(wildcard $$(TOPDIR)/$$(COMPARE_BUILD_PATCH))
362169689Skan        else ifeq ($$(wildcard $$(COMPARE_BUILD_PATCH)), )
363169689Skan          $$(error Patch file $$(COMPARE_BUILD_PATCH) does not exist)
364169689Skan        endif
365169689Skan      endif
366169689Skan    endif
367169689Skan  endef
368169689Skan
369169689Skan  # Prepare for a comparison rebuild
370169689Skan  define PrepareCompareBuild
371169689Skan	$(ECHO) "Preparing for comparison rebuild"
372169689Skan        # Apply patch, if any
373169689Skan	$(if $(COMPARE_BUILD_PATCH), $(PATCH) -p1 < $(COMPARE_BUILD_PATCH))
374169689Skan        # Move the first build away temporarily
375169689Skan	$(RM) -r $(TOPDIR)/build/.compare-build-temp
376169689Skan	$(MKDIR) -p $(TOPDIR)/build/.compare-build-temp
377169689Skan	$(MV) $(OUTPUT_ROOT) $(TOPDIR)/build/.compare-build-temp
378169689Skan        # Restore an old compare-build, or create a new compare-build directory.
379169689Skan	if test -d $(COMPARE_BUILD_OUTPUT_ROOT); then \
380169689Skan	  $(MV) $(COMPARE_BUILD_OUTPUT_ROOT) $(OUTPUT_ROOT); \
381169689Skan	else \
382169689Skan	  $(MKDIR) -p $(OUTPUT_ROOT); \
383169689Skan	fi
384169689Skan        # Re-run configure with the same arguments (and possibly some additional),
385169689Skan        # must be done after patching.
386169689Skan	( cd $(OUTPUT_ROOT) && PATH="$(ORIGINAL_PATH)" \
387169689Skan	    $(BASH) $(TOPDIR)/configure $(CONFIGURE_COMMAND_LINE) $(COMPARE_BUILD_CONF))
388169689Skan  endef
389169689Skan
390169689Skan  # Cleanup after a compare build
391169689Skan  define CleanupCompareBuild
392169689Skan        # If running with a COMPARE_BUILD patch, reverse-apply it
393169689Skan	$(if $(COMPARE_BUILD_PATCH), $(PATCH) -R -p1 < $(COMPARE_BUILD_PATCH))
394169689Skan        # Move this build away and restore the original build
395169689Skan	$(MKDIR) -p $(TOPDIR)/build/compare-build
396169689Skan	$(MV) $(OUTPUT_ROOT) $(COMPARE_BUILD_OUTPUT_ROOT)
397169689Skan	$(MV) $(TOPDIR)/build/.compare-build-temp/$(CONF_NAME) $(OUTPUT_ROOT)
398169689Skan	$(RM) -r $(TOPDIR)/build/.compare-build-temp
399169689Skan  endef
400169689Skan
401169689Skan  # Do the actual comparison of two builds
402169689Skan  define CompareBuildDoComparison
403169689Skan        # Compare first and second build. Ignore any error code from compare.sh.
404169689Skan	$(ECHO) "Comparing between comparison rebuild (this/new) and baseline (other/old)"
405169689Skan	$(if $(COMPARE_BUILD_COMP_DIR), \
406169689Skan	  +(cd $(COMPARE_BUILD_OUTPUT_ROOT) && ./compare.sh $(COMPARE_BUILD_COMP_OPTS) \
407169689Skan	      -2dirs $(COMPARE_BUILD_OUTPUT_ROOT)/$(COMPARE_BUILD_COMP_DIR) $(OUTPUT_ROOT)/$(COMPARE_BUILD_COMP_DIR) || true), \
408169689Skan	  +(cd $(COMPARE_BUILD_OUTPUT_ROOT) && ./compare.sh $(COMPARE_BUILD_COMP_OPTS) \
409169689Skan	      -o $(OUTPUT_ROOT) || true) \
410169689Skan	)
411169689Skan  endef
412169689Skan
413169689Skan  define PrintFailureReports
414169689Skan	$(if $(wildcard $(MAKESUPPORT_OUTPUTDIR)/failure-logs/*), \
415169689Skan	  $(PRINTF) "=== Output from failing command(s) repeated here ===\n" $(NEWLINE) \
416169689Skan	  $(foreach logfile, $(sort $(wildcard $(MAKESUPPORT_OUTPUTDIR)/failure-logs/*)), \
417169689Skan	      $(PRINTF) "* For target $(notdir $(basename $(logfile))):\n" $(NEWLINE) \
418169689Skan	      $(CAT) $(logfile) | $(GREP) -v -e "^Note: including file:" $(NEWLINE) \
419169689Skan	  ) \
420169689Skan	  $(PRINTF) "=== End of repeated output ===\n" \
421169689Skan	)
422169689Skan  endef
423169689Skan
424169689Skan  define PrintBuildLogFailures
425169689Skan	if $(GREP) -q "recipe for target .* failed" $(BUILD_LOG) 2> /dev/null; then  \
426169689Skan	  $(PRINTF) "=== Make failure sequence repeated here ===\n" ; \
427169689Skan	  $(GREP) "recipe for target .* failed" $(BUILD_LOG) ; \
428169689Skan	  $(PRINTF) "=== End of repeated output ===\n" ; \
429169689Skan	  $(PRINTF) "Hint: Try searching the build log for the name of the first failed target.\n" ; \
430169689Skan	else \
431169689Skan	  $(PRINTF) "No indication of failed target found.\n" ; \
432169689Skan	  $(PRINTF) "Hint: Try searching the build log for '] Error'.\n" ; \
433169689Skan	fi
434169689Skan  endef
435169689Skan
436169689Skan  define RotateLogFiles
437169689Skan	$(RM) $(BUILD_LOG).old 2> /dev/null
438169689Skan	$(MV) $(BUILD_LOG) $(BUILD_LOG).old 2> /dev/null || true
439169689Skan	$(if $(findstring trace, $(LOG_LEVEL)), \
440169689Skan	  $(RM) $(BUILD_TRACE_LOG).old 2> /dev/null && \
441169689Skan	  $(MV) $(BUILD_TRACE_LOG) $(BUILD_TRACE_LOG).old 2> /dev/null || true \
442169689Skan	)
443169689Skan  endef
444169689Skan
445169689Skan  define PrepareFailureLogs
446169689Skan	$(RM) -r $(MAKESUPPORT_OUTPUTDIR)/failure-logs 2> /dev/null
447169689Skan	$(MKDIR) -p $(MAKESUPPORT_OUTPUTDIR)/failure-logs
448169689Skan  endef
449169689Skan
450169689Skan  # Remove any javac server logs and port files. This
451169689Skan  # prevents a new make run to reuse the previous servers.
452169689Skan  define PrepareSmartJavac
453169689Skan	$(if $(SJAVAC_SERVER_DIR), \
454169689Skan	  $(RM) -r $(SJAVAC_SERVER_DIR) 2> /dev/null && \
455169689Skan	  $(MKDIR) -p $(SJAVAC_SERVER_DIR) \
456169689Skan	)
457169689Skan  endef
458169689Skan
459169689Skan  define CleanupSmartJavac
460169689Skan	[ -f $(SJAVAC_SERVER_DIR)/server.port ] && $(ECHO) Stopping sjavac server && \
461169689Skan	    $(TOUCH) $(SJAVAC_SERVER_DIR)/server.port.stop; true
462169689Skan  endef
463169689Skan
464169689Skan  define StartGlobalTimer
465169689Skan	$(RM) -r $(BUILDTIMESDIR) 2> /dev/null
466169689Skan	$(MKDIR) -p $(BUILDTIMESDIR)
467169689Skan	$(call RecordStartTime,TOTAL)
468169689Skan  endef
469169689Skan
470169689Skan  define StopGlobalTimer
471169689Skan	$(call RecordEndTime,TOTAL)
472169689Skan  endef
473169689Skan
474169689Skan  # Find all build_time_* files and print their contents in a list sorted
475169689Skan  # on the name of the sub repository.
476169689Skan  define ReportBuildTimes
477169689Skan	$(BUILD_LOG_WRAPPER) $(PRINTF) $(LOG_INFO) -- \
478169689Skan	    "----- Build times -------\nStart %s\nEnd   %s\n%s\n%s\n-------------------------\n" \
479169689Skan	    "`$(CAT) $(BUILDTIMESDIR)/build_time_start_TOTAL_human_readable`" \
480169689Skan	    "`$(CAT) $(BUILDTIMESDIR)/build_time_end_TOTAL_human_readable`" \
481169689Skan	    "`$(LS) $(BUILDTIMESDIR)/build_time_diff_* | $(GREP) -v _TOTAL | \
482169689Skan	    $(XARGS) $(CAT) | $(SORT) -k 2`" \
483169689Skan	    "`$(CAT) $(BUILDTIMESDIR)/build_time_diff_TOTAL`"
484  endef
485
486endif # HAS_SPEC
487
488endif # _INITSUPPORT_GMK
489