InitSupport.gmk revision 1862:5f3d162d11fc
154331Sarchie#
254331Sarchie# Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
3139823Simp# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4139823Simp#
5139823Simp# This code is free software; you can redistribute it and/or modify it
654331Sarchie# under the terms of the GNU General Public License version 2 only, as
754331Sarchie# published by the Free Software Foundation.  Oracle designates this
854331Sarchie# particular file as subject to the "Classpath" exception as provided
954331Sarchie# by Oracle in the LICENSE file that accompanied this code.
1054331Sarchie#
1154331Sarchie# This code is distributed in the hope that it will be useful, but WITHOUT
1254331Sarchie# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1354331Sarchie# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1454331Sarchie# version 2 for more details (a copy is included in the LICENSE file that
1554331Sarchie# accompanied this code).
1654331Sarchie#
1754331Sarchie# You should have received a copy of the GNU General Public License version
1854331Sarchie# 2 along with this work; if not, write to the Free Software Foundation,
1954331Sarchie# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2054331Sarchie#
2154331Sarchie# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2254331Sarchie# or visit www.oracle.com if you need additional information or have any
2354331Sarchie# questions.
2454331Sarchie#
2554331Sarchie
2654331Sarchie################################################################################
2754331Sarchie# This file contains helper functions for Init.gmk.
2854331Sarchie# It is divided in two parts, depending on if a SPEC is present or not
2954331Sarchie# (HAS_SPEC is true or not).
3054331Sarchie################################################################################
3154331Sarchie
3254331Sarchieifndef _INITSUPPORT_GMK
3354331Sarchie_INITSUPPORT_GMK := 1
3454331Sarchie
3554331Sarchieifeq ($(HAS_SPEC),)
3654331Sarchie  ##############################################################################
3754331Sarchie  # Helper functions for the initial part of Init.gmk, before the spec file is
3867506Sjulian  # loaded. Most of these functions provide parsing and setting up make options
3954331Sarchie  # from the command-line.
4054331Sarchie  ##############################################################################
4154331Sarchie
4254331Sarchie  # Make control variables, handled by Init.gmk
4354331Sarchie  INIT_CONTROL_VARIABLES := LOG CONF CONF_NAME SPEC JOBS TEST_JOBS CONF_CHECK \
4454331Sarchie      COMPARE_BUILD
4554331Sarchie
4654331Sarchie  # All known make control variables
4754331Sarchie  MAKE_CONTROL_VARIABLES := $(INIT_CONTROL_VARIABLES) TEST JDK_FILTER
4854331Sarchie
4954331Sarchie  # Define a simple reverse function.
5054331Sarchie  # Should maybe move to MakeBase.gmk, but we can't include that file now.
5154331Sarchie  reverse = \
5254331Sarchie      $(if $(strip $(1)), $(call reverse, $(wordlist 2, $(words $(1)), $(1)))) \
5354331Sarchie          $(firstword $(1))
5454331Sarchie
5554331Sarchie  # The variable MAKEOVERRIDES contains variable assignments from the command
5654331Sarchie  # line, but in reverse order to what the user entered.
5754331Sarchie  # The '\#' <=> '\ 'dance is needed to keep values with space in them connected.
5854331Sarchie  COMMAND_LINE_VARIABLES := $(subst \#,\ , $(call reverse, $(subst \ ,\#,$(MAKEOVERRIDES))))
5954331Sarchie
6054331Sarchie  # A list like FOO="val1" BAR="val2" containing all user-supplied make
61149615Sglebius  # variables that we should propagate.
62149615Sglebius  # The '\#' <=> '\ 'dance is needed to keep values with space in them connected.
6354331Sarchie  USER_MAKE_VARS := $(subst \#,\ , $(filter-out $(addsuffix =%, $(INIT_CONTROL_VARIABLES)), \
64149615Sglebius      $(subst \ ,\#,$(MAKEOVERRIDES))))
6554331Sarchie
6654331Sarchie  # Setup information about available configurations, if any.
6754331Sarchie  build_dir=$(topdir)/build
6854331Sarchie  all_spec_files=$(wildcard $(build_dir)/*/spec.gmk)
6954331Sarchie  # Extract the configuration names from the path
7054331Sarchie  all_confs=$(patsubst %/spec.gmk, %, $(patsubst $(build_dir)/%, %, $(all_spec_files)))
7154331Sarchie
7254331Sarchie  # Check for unknown command-line variables
7354331Sarchie  define CheckControlVariables
7454331Sarchie    command_line_variables := $$(strip $$(foreach var, \
7554331Sarchie        $$(subst \ ,_,$$(MAKEOVERRIDES)), \
7654331Sarchie        $$(firstword $$(subst =, , $$(var)))))
7754331Sarchie    unknown_command_line_variables := $$(strip \
7854331Sarchie        $$(filter-out $$(MAKE_CONTROL_VARIABLES), $$(command_line_variables)))
7954331Sarchie    ifneq ($$(unknown_command_line_variables), )
8054331Sarchie      $$(info Note: Command line contains non-control variables:)
8154331Sarchie      $$(foreach var, $$(unknown_command_line_variables), $$(info * $$(var)=$$($$(var))))
8254331Sarchie      $$(info Make sure it is not mistyped, and that you intend to override this variable.)
8354331Sarchie      $$(info 'make help' will list known control variables.)
8454331Sarchie      $$(info )
8554331Sarchie    endif
8654331Sarchie  endef
8754331Sarchie
8854331Sarchie  # Check for deprecated ALT_ variables
8954331Sarchie  define CheckDeprecatedEnvironment
9054331Sarchie    defined_alt_variables := $$(filter ALT_%, $$(.VARIABLES))
9154331Sarchie    ifneq ($$(defined_alt_variables), )
9254331Sarchie      $$(info Warning: You have the following ALT_ variables set:)
9354331Sarchie      $$(foreach var, $$(defined_alt_variables), $$(info * $$(var)=$$($$(var))))
9454331Sarchie      $$(info ALT_ variables are deprecated, and may result in a failed build.)
9554331Sarchie      $$(info Please clean your environment.)
9654331Sarchie      $$(info )
9754331Sarchie    endif
9854331Sarchie  endef
9954331Sarchie
10054331Sarchie  # Check for invalid make flags like -j
10154331Sarchie  define CheckInvalidMakeFlags
10254331Sarchie    # This is a trick to get this rule to execute before any other rules
10354331Sarchie    # MAKEFLAGS only indicate -j if read in a recipe (!)
10454331Sarchie    $$(topdir)/make/Init.gmk: .FORCE
10554331Sarchie	$$(if $$(findstring --jobserver, $$(MAKEFLAGS)), \
10654331Sarchie	    $$(info Error: 'make -jN' is not supported, use 'make JOBS=N') \
10754331Sarchie	    $$(error Cannot continue) \
10854331Sarchie	)
10954331Sarchie    .FORCE:
11054331Sarchie    .PHONY: .FORCE
11154331Sarchie  endef
11254331Sarchie
11354331Sarchie  # Check that the CONF_CHECK option is valid and set up handling
11454331Sarchie  define ParseConfCheckOption
11554331Sarchie    ifeq ($$(CONF_CHECK), )
11654331Sarchie      # Default behavior is fail
11754331Sarchie      CONF_CHECK := fail
11862222Sarchie    else ifneq ($$(filter-out auto fail ignore, $$(CONF_CHECK)),)
11963822Sarchie      $$(info Error: CONF_CHECK must be one of: auto, fail or ignore.)
12054331Sarchie      $$(error Cannot continue)
12154331Sarchie    endif
12262222Sarchie  endef
12362222Sarchie
12494667Sarchie  define ParseLogLevel
125134865Sglebius    # Catch old-style VERBOSE= command lines.
12654331Sarchie    ifneq ($$(origin VERBOSE), undefined)
12763852Sarchie      $$(info Error: VERBOSE is deprecated. Use LOG=<warn|info|debug|trace> instead.)
12863852Sarchie      $$(error Cannot continue)
12963852Sarchie    endif
13063852Sarchie
13163852Sarchie    # Setup logging according to LOG
13263852Sarchie
13363852Sarchie    # If the "nofile" argument is given, act on it and strip it away
13462222Sarchie    ifneq ($$(findstring nofile, $$(LOG)),)
135166424Sglebius      LOG_NOFILE := true
136166424Sglebius      # COMMA is defined in spec.gmk, but that is not included yet
13754331Sarchie      COMMA := ,
13854331Sarchie      # First try to remove ",nofile" if it exists, otherwise just remove "nofile"
13954331Sarchie      LOG_STRIPPED := $$(subst nofile,, $$(subst $$(COMMA)nofile,, $$(LOG)))
14060009Sarchie      # We might have ended up with a leading comma. Remove it
14160009Sarchie      LOG_LEVEL := $$(strip $$(patsubst $$(COMMA)%, %, $$(LOG_STRIPPED)))
14254331Sarchie    else
14354331Sarchie      LOG_LEVEL := $$(LOG)
14454331Sarchie    endif
14554331Sarchie
14654331Sarchie    ifeq ($$(LOG_LEVEL),)
14754331Sarchie      # Set LOG to "warn" as default if not set
14894667Sarchie      LOG_LEVEL := warn
14994667Sarchie    endif
15062129Sarchie
15154331Sarchie    ifeq ($$(LOG_LEVEL), warn)
15263822Sarchie      MAKE_LOG_FLAGS := -s
15363852Sarchie    else ifeq ($$(LOG_LEVEL), info)
15463852Sarchie      MAKE_LOG_FLAGS := -s
15563822Sarchie    else ifeq ($$(LOG_LEVEL), debug)
15654331Sarchie      MAKE_LOG_FLAGS :=
15754331Sarchie    else ifeq ($$(LOG_LEVEL), trace)
15854331Sarchie      MAKE_LOG_FLAGS :=
15954331Sarchie    else
16054331Sarchie      $$(info Error: LOG must be one of: warn, info, debug or trace.)
16154331Sarchie      $$(error Cannot continue)
16254331Sarchie    endif
16354331Sarchie  endef
16454331Sarchie
16554331Sarchie  define ParseConfAndSpec
16654331Sarchie    ifneq ($$(origin SPEC), undefined)
16754331Sarchie      # We have been given a SPEC, check that it works out properly
16854331Sarchie      ifneq ($$(origin CONF), undefined)
16960009Sarchie        # We also have a CONF argument. We can't have both.
170149615Sglebius        $$(info Error: Cannot use CONF=$$(CONF) and SPEC=$$(SPEC) at the same time. Choose one.)
17154331Sarchie        $$(error Cannot continue)
17254331Sarchie      endif
17354331Sarchie      ifneq ($$(origin CONF_NAME), undefined)
17454331Sarchie        # We also have a CONF_NAME argument. We can't have both.
17554331Sarchie        $$(info Error: Cannot use CONF_NAME=$$(CONF_NAME) and SPEC=$$(SPEC) at the same time. Choose one.)
17654331Sarchie        $$(error Cannot continue)
17770700Sjulian      endif
17854331Sarchie      ifeq ($$(wildcard $$(SPEC)),)
17954331Sarchie        $$(info Error: Cannot locate spec.gmk, given by SPEC=$$(SPEC).)
18054331Sarchie        $$(error Cannot continue)
18154331Sarchie      endif
18254331Sarchie      ifeq ($$(filter /%, $$(SPEC)),)
18370700Sjulian        # If given with relative path, make it absolute
18470700Sjulian        SPECS := $$(CURDIR)/$$(strip $$(SPEC))
18563852Sarchie      else
18694667Sarchie        SPECS := $$(SPEC)
18754331Sarchie      endif
18894667Sarchie
189138618Sglebius      # For now, unset this SPEC variable.
190138618Sglebius      override SPEC :=
191138618Sglebius    else
192138618Sglebius      # Use spec.gmk files in the build output directory
19354331Sarchie      ifeq ($$(all_spec_files),)
19454331Sarchie        $$(info Error: No configurations found for $$(topdir).)
19554331Sarchie        $$(info Please run 'bash configure' to create a configuration.)
19654331Sarchie        $$(info )
19797685Sarchie        $$(error Cannot continue)
19897685Sarchie      endif
19954331Sarchie
20054331Sarchie      ifneq ($$(origin CONF_NAME), undefined)
20197685Sarchie        ifneq ($$(origin CONF), undefined)
20254331Sarchie          # We also have a CONF argument. We can't have both.
20354331Sarchie          $$(info Error: Cannot use CONF=$$(CONF) and CONF_NAME=$$(CONF_NAME) at the same time. Choose one.)
20460009Sarchie          $$(error Cannot continue)
20597685Sarchie        endif
20697685Sarchie        matching_conf := $$(strip $$(filter $$(CONF_NAME), $$(all_confs)))
20760009Sarchie        ifeq ($$(matching_conf),)
20860009Sarchie          $$(info Error: No configurations found matching CONF_NAME=$$(CONF_NAME).)
20997685Sarchie          $$(info Available configurations in $$(build_dir):)
21060009Sarchie          $$(foreach var, $$(all_confs), $$(info * $$(var)))
21160009Sarchie          $$(error Cannot continue)
21254331Sarchie        else ifneq ($$(words $$(matching_conf)), 1)
21354331Sarchie          $$(info Error: Matching more than one configuration CONF_NAME=$$(CONF_NAME).)
21454331Sarchie          $$(info Available configurations in $$(build_dir):)
21554331Sarchie          $$(foreach var, $$(all_confs), $$(info * $$(var)))
21654331Sarchie          $$(error Cannot continue)
21754331Sarchie        else
21854331Sarchie          $$(info Building configuration '$$(matching_conf)' (matching CONF_NAME=$$(CONF_NAME)))
21954331Sarchie        endif
22054331Sarchie        # Create a SPEC definition. This will contain the path to exactly one spec file.
22154331Sarchie        SPECS := $$(build_dir)/$$(matching_conf)/spec.gmk
22254331Sarchie      else ifneq ($$(origin CONF), undefined)
22354331Sarchie        # User have given a CONF= argument.
22454331Sarchie        ifeq ($$(CONF),)
22554331Sarchie          # If given CONF=, match all configurations
22654331Sarchie          matching_confs := $$(strip $$(all_confs))
22754331Sarchie        else
22860009Sarchie          # Otherwise select those that contain the given CONF string
22960009Sarchie          matching_confs := $$(strip $$(foreach var, $$(all_confs), \
23060009Sarchie              $$(if $$(findstring $$(CONF), $$(var)), $$(var))))
23160009Sarchie        endif
23260009Sarchie        ifeq ($$(matching_confs),)
23360009Sarchie          $$(info Error: No configurations found matching CONF=$$(CONF).)
23460009Sarchie          $$(info Available configurations in $$(build_dir):)
23560009Sarchie          $$(foreach var, $$(all_confs), $$(info * $$(var)))
23660009Sarchie          $$(error Cannot continue)
23760009Sarchie        else
23860009Sarchie          # Don't repeat this output on make restarts caused by including
23960009Sarchie          # generated files.
24060009Sarchie          ifeq ($$(MAKE_RESTARTS),)
24160009Sarchie            ifeq ($$(words $$(matching_confs)), 1)
24260009Sarchie              $$(info Building configuration '$$(matching_confs)' (matching CONF=$$(CONF)))
24360009Sarchie            else
24460009Sarchie              $$(info Building these configurations (matching CONF=$$(CONF)):)
24560009Sarchie              $$(foreach var, $$(matching_confs), $$(info * $$(var)))
24660009Sarchie            endif
24760009Sarchie          endif
24860009Sarchie        endif
24954331Sarchie
25054331Sarchie        # Create a SPEC definition. This will contain the path to one or more spec.gmk files.
25154331Sarchie        SPECS := $$(addsuffix /spec.gmk, $$(addprefix $$(build_dir)/, $$(matching_confs)))
25254331Sarchie      else
25354331Sarchie        # No CONF or SPEC given, check the available configurations
254129823Sjulian        ifneq ($$(words $$(all_spec_files)), 1)
255129823Sjulian          $$(info Error: No CONF given, but more than one configuration found.)
256129823Sjulian          $$(info Available configurations in $$(build_dir):)
257129823Sjulian          $$(foreach var, $$(all_confs), $$(info * $$(var)))
258129823Sjulian          $$(info Please retry building with CONF=<config pattern> (or SPEC=<spec file>).)
259129823Sjulian          $$(info )
260129823Sjulian          $$(error Cannot continue)
261129823Sjulian        endif
262129823Sjulian
26354331Sarchie        # We found exactly one configuration, use it
26454331Sarchie        SPECS := $$(strip $$(all_spec_files))
26554331Sarchie      endif
26654331Sarchie    endif
26754331Sarchie  endef
26854331Sarchie
26954331Sarchie  # Extract main targets from Main.gmk using the spec provided in $2.
27054331Sarchie  #
27154331Sarchie  # Param 1: FORCE = force generation of main-targets.gmk or LAZY = do not force.
27254331Sarchie  # Param 2: The SPEC file to use.
27354331Sarchie  define DefineMainTargets
27454331Sarchie
27554331Sarchie    # We will start by making sure the main-targets.gmk file is removed, if
27670700Sjulian    # make has not been restarted. By the -include, we will trigger the
27754331Sarchie    # rule for generating the file (which is never there since we removed it),
27854331Sarchie    # thus generating it fresh, and make will restart, incrementing the restart
27954331Sarchie    # count.
28054331Sarchie    main_targets_file := $$(dir $(strip $2))make-support/main-targets.gmk
28168876Sdwmalone
28254331Sarchie    ifeq ($$(MAKE_RESTARTS),)
28354331Sarchie      # Only do this if make has not been restarted, and if we do not force it.
28454331Sarchie      ifeq ($(strip $1), FORCE)
28570784Sjulian        $$(shell rm -f $$(main_targets_file))
28654331Sarchie      endif
28754331Sarchie    endif
288149615Sglebius
289149880Sglebius    $$(main_targets_file):
290149880Sglebius	@( cd $$(topdir) && \
29154331Sarchie	$$(MAKE) $$(MAKE_LOG_FLAGS) -r -R -f $$(topdir)/make/Main.gmk \
29254331Sarchie	    -I $$(topdir)/make/common SPEC=$(strip $2) NO_RECIPES=true \
29354331Sarchie	    LOG_LEVEL=$$(LOG_LEVEL) \
29454331Sarchie	    create-main-targets-include )
29554331Sarchie
29654331Sarchie    # Now include main-targets.gmk. This will define ALL_MAIN_TARGETS.
29754331Sarchie    -include $$(main_targets_file)
29854331Sarchie  endef
29954331Sarchie
30054331Sarchie  define PrintConfCheckFailed
30154331Sarchie	@echo ' '
30270784Sjulian	@echo "Please rerun configure! Easiest way to do this is by running"
30354331Sarchie	@echo "'make reconfigure'."
30454331Sarchie	@echo "This behavior may also be changed using CONF_CHECK=<ignore|auto>."
30554331Sarchie	@echo ' '
30654331Sarchie  endef
30754331Sarchie
30854331Sarchieelse # $(HAS_SPEC)=true
30954331Sarchie  ##############################################################################
31054331Sarchie  # Helper functions for the 'main' target. These functions assume a single,
31154331Sarchie  # proper and existing SPEC is included.
31254331Sarchie  ##############################################################################
31354331Sarchie
31454331Sarchie  include $(SRC_ROOT)/make/common/MakeBase.gmk
31554331Sarchie
31654331Sarchie  # Define basic logging setup
31754331Sarchie  BUILD_LOG := $(OUTPUT_ROOT)/build.log
31854331Sarchie  BUILD_TRACE_LOG := $(OUTPUT_ROOT)/build-trace-time.log
31954331Sarchie
32054331Sarchie  BUILD_LOG_PIPE := > >($(TEE) -a $(BUILD_LOG)) 2> >($(TEE) -a $(BUILD_LOG) >&2)
32154331Sarchie
32254331Sarchie  # Sanity check the spec file, so it matches this source code
32354331Sarchie  define CheckSpecSanity
32454331Sarchie    ifneq ($$(ACTUAL_TOPDIR), $$(TOPDIR))
32554331Sarchie      ifneq ($$(ACTUAL_TOPDIR), $$(ORIGINAL_TOPDIR))
32670700Sjulian        ifneq ($$(ACTUAL_TOPDIR), $$(CANONICAL_TOPDIR))
32754331Sarchie          $$(info Error: SPEC mismatch! Current working directory)
32870784Sjulian          $$(info $$(ACTUAL_TOPDIR))
32954331Sarchie          $$(info does not match either TOPDIR, ORIGINAL_TOPDIR or CANONICAL_TOPDIR)
33054331Sarchie          $$(info $$(TOPDIR))
33170700Sjulian          $$(info $$(ORIGINAL_TOPDIR))
33254331Sarchie          $$(info $$(CANONICAL_TOPDIR))
33370700Sjulian          $$(error Cannot continue)
33454331Sarchie        endif
33554331Sarchie      endif
33654331Sarchie    endif
33754331Sarchie  endef
33854331Sarchie
33954331Sarchie  # Parse COMPARE_BUILD into COMPARE_BUILD_*
34054331Sarchie  # Syntax: COMPARE_BUILD=CONF=<configure options>:PATCH=<patch file>:
34154331Sarchie  #         MAKE=<make targets>:COMP_OPTS=<compare script options>:
34254331Sarchie  #         COMP_DIR=<compare script base dir>|<default>
34354331Sarchie  # If neither CONF or PATCH is given, assume <default> means CONF if it
34454331Sarchie  # begins with "--", otherwise assume it means PATCH.
34554331Sarchie  # MAKE and COMP_OPTS can only be used with CONF and/or PATCH specified.
34654331Sarchie  # If any value contains "+", it will be replaced by space.
34754331Sarchie  define ParseCompareBuild
34854331Sarchie    ifneq ($$(COMPARE_BUILD), )
34954331Sarchie      COMPARE_BUILD_OUTPUT_ROOT := $(TOPDIR)/build/compare-build/$(CONF_NAME)
35054331Sarchie
35154331Sarchie      ifneq ($$(findstring :, $$(COMPARE_BUILD)), )
35254331Sarchie        $$(foreach part, $$(subst :, , $$(COMPARE_BUILD)), \
35354331Sarchie          $$(if $$(filter PATCH=%, $$(part)), \
35454331Sarchie            $$(eval COMPARE_BUILD_PATCH=$$(strip $$(patsubst PATCH=%, %, $$(part)))) \
35560009Sarchie          ) \
35660009Sarchie          $$(if $$(filter CONF=%, $$(part)), \
35760009Sarchie            $$(eval COMPARE_BUILD_CONF=$$(strip $$(subst +, , $$(patsubst CONF=%, %, $$(part))))) \
35860009Sarchie          ) \
35960009Sarchie          $$(if $$(filter MAKE=%, $$(part)), \
36060009Sarchie            $$(eval COMPARE_BUILD_MAKE=$$(strip $$(subst +, , $$(patsubst MAKE=%, %, $$(part))))) \
36160009Sarchie          ) \
36260009Sarchie          $$(if $$(filter COMP_OPTS=%, $$(part)), \
36360009Sarchie            $$(eval COMPARE_BUILD_COMP_OPTS=$$(strip $$(subst +, , $$(patsubst COMP_OPTS=%, %, $$(part))))) \
36460009Sarchie          ) \
36560009Sarchie          $$(if $$(filter COMP_DIR=%, $$(part)), \
36660009Sarchie            $$(eval COMPARE_BUILD_COMP_DIR=$$(strip $$(subst +, , $$(patsubst COMP_DIR=%, %, $$(part))))) \
36760009Sarchie          ) \
36860009Sarchie        )
36960009Sarchie      else
37060009Sarchie        # Separate handling for single field case, to allow for spaces in values.
37154331Sarchie        ifneq ($$(filter PATCH=%, $$(COMPARE_BUILD)), )
37254331Sarchie          COMPARE_BUILD_PATCH=$$(strip $$(patsubst PATCH=%, %, $$(COMPARE_BUILD)))
37354331Sarchie        else ifneq ($$(filter CONF=%, $$(COMPARE_BUILD)), )
37454331Sarchie          COMPARE_BUILD_CONF=$$(strip $$(subst +, , $$(patsubst CONF=%, %, $$(COMPARE_BUILD))))
37554331Sarchie        else ifneq ($$(filter --%, $$(COMPARE_BUILD)), )
37654331Sarchie          # Assume CONF if value begins with --
37754331Sarchie          COMPARE_BUILD_CONF=$$(strip $$(subst +, , $$(COMPARE_BUILD)))
37854331Sarchie        else
37954331Sarchie          # Otherwise assume patch file
38070159Sjulian          COMPARE_BUILD_PATCH=$$(strip $$(COMPARE_BUILD))
38170700Sjulian        endif
38270700Sjulian      endif
38354331Sarchie      ifneq ($$(COMPARE_BUILD_PATCH), )
38454331Sarchie        ifneq ($$(wildcard $$(TOPDIR)/$$(COMPARE_BUILD_PATCH)), )
38554331Sarchie          # Assume relative path, if file exists
38654331Sarchie          COMPARE_BUILD_PATCH := $$(wildcard $$(TOPDIR)/$$(COMPARE_BUILD_PATCH))
38754331Sarchie        else ifeq ($$(wildcard $$(COMPARE_BUILD_PATCH)), )
38854331Sarchie          $$(error Patch file $$(COMPARE_BUILD_PATCH) does not exist)
38954331Sarchie        endif
39070700Sjulian      endif
39154331Sarchie    endif
39270784Sjulian  endef
39370784Sjulian
394149615Sglebius  # Prepare for a comparison rebuild
39554331Sarchie  define PrepareCompareBuild
39654331Sarchie	$(ECHO) "Preparing for comparison rebuild"
39754331Sarchie        # Apply patch, if any
39870700Sjulian	$(if $(COMPARE_BUILD_PATCH), $(PATCH) -p1 < $(COMPARE_BUILD_PATCH))
39954331Sarchie        # Move the first build away temporarily
40054331Sarchie	$(RM) -r $(TOPDIR)/build/.compare-build-temp
40154331Sarchie	$(MKDIR) -p $(TOPDIR)/build/.compare-build-temp
402149615Sglebius	$(MV) $(OUTPUT_ROOT) $(TOPDIR)/build/.compare-build-temp
403149615Sglebius        # Restore an old compare-build, or create a new compare-build directory.
40454331Sarchie	if test -d $(COMPARE_BUILD_OUTPUT_ROOT); then \
40554331Sarchie	  $(MV) $(COMPARE_BUILD_OUTPUT_ROOT) $(OUTPUT_ROOT); \
406149615Sglebius	else \
407149615Sglebius	  $(MKDIR) -p $(OUTPUT_ROOT); \
408149615Sglebius	fi
409149615Sglebius        # Re-run configure with the same arguments (and possibly some additional),
410149615Sglebius        # must be done after patching.
411149615Sglebius	( cd $(OUTPUT_ROOT) && PATH="$(ORIGINAL_PATH)" \
412149880Sglebius	    $(BASH) $(TOPDIR)/configure $(CONFIGURE_COMMAND_LINE) $(COMPARE_BUILD_CONF))
413149615Sglebius  endef
414149615Sglebius
41554331Sarchie  # Cleanup after a compare build
41654331Sarchie  define CleanupCompareBuild
41754331Sarchie        # If running with a COMPARE_BUILD patch, reverse-apply it
41854331Sarchie	$(if $(COMPARE_BUILD_PATCH), $(PATCH) -R -p1 < $(COMPARE_BUILD_PATCH))
41954331Sarchie        # Move this build away and restore the original build
42054331Sarchie	$(MKDIR) -p $(TOPDIR)/build/compare-build
42170700Sjulian	$(MV) $(OUTPUT_ROOT) $(COMPARE_BUILD_OUTPUT_ROOT)
42254331Sarchie	$(MV) $(TOPDIR)/build/.compare-build-temp/$(CONF_NAME) $(OUTPUT_ROOT)
42370784Sjulian	$(RM) -r $(TOPDIR)/build/.compare-build-temp
42454331Sarchie  endef
425138618Sglebius
42654331Sarchie  # Do the actual comparison of two builds
42754331Sarchie  define CompareBuildDoComparison
428149615Sglebius        # Compare first and second build. Ignore any error code from compare.sh.
429149615Sglebius	$(ECHO) "Comparing between comparison rebuild (this/new) and baseline (other/old)"
430138618Sglebius	$(if $(COMPARE_BUILD_COMP_DIR), \
43194667Sarchie	  +(cd $(COMPARE_BUILD_OUTPUT_ROOT) && ./compare.sh $(COMPARE_BUILD_COMP_OPTS) \
43294667Sarchie	      -2dirs $(COMPARE_BUILD_OUTPUT_ROOT)/$(COMPARE_BUILD_COMP_DIR) $(OUTPUT_ROOT)/$(COMPARE_BUILD_COMP_DIR) || true), \
43370784Sjulian	  +(cd $(COMPARE_BUILD_OUTPUT_ROOT) && ./compare.sh $(COMPARE_BUILD_COMP_OPTS) \
43454331Sarchie	      -o $(OUTPUT_ROOT) || true) \
43554331Sarchie	)
43654331Sarchie  endef
43754331Sarchie
43854331Sarchie  define PrintFailureReports
43954331Sarchie	$(if $(wildcard $(MAKESUPPORT_OUTPUTDIR)/failure-logs/*), \
44054331Sarchie	  $(PRINTF) "=== Output from failing command(s) repeated here ===\n" $(NEWLINE) \
44154331Sarchie	  $(foreach logfile, $(sort $(wildcard $(MAKESUPPORT_OUTPUTDIR)/failure-logs/*)), \
44254331Sarchie	      $(PRINTF) "* For target $(notdir $(basename $(logfile))):\n" $(NEWLINE) \
44370784Sjulian	      $(CAT) $(logfile) | $(GREP) -v -e "^Note: including file:" $(NEWLINE) \
44470784Sjulian	  ) \
44554331Sarchie	  $(PRINTF) "=== End of repeated output ===\n" \
44654331Sarchie	)
44754331Sarchie  endef
44854331Sarchie
44954331Sarchie  define PrintBuildLogFailures
45054331Sarchie	if $(GREP) -q "recipe for target .* failed" $(BUILD_LOG) 2> /dev/null; then  \
45154331Sarchie	  $(PRINTF) "=== Make failure sequence repeated here ===\n" ; \
45287599Sobrien	  $(GREP) "recipe for target .* failed" $(BUILD_LOG) ; \
45354331Sarchie	  $(PRINTF) "=== End of repeated output ===\n" ; \
45454331Sarchie	  $(PRINTF) "Hint: Try searching the build log for the name of the first failed target.\n" ; \
45570784Sjulian	else \
45670784Sjulian	  $(PRINTF) "No indication of failed target found.\n" ; \
45770700Sjulian	  $(PRINTF) "Hint: Try searching the build log for '] Error'.\n" ; \
45854331Sarchie	fi
45954331Sarchie  endef
46054331Sarchie
46154331Sarchie  define RotateLogFiles
46254331Sarchie	$(RM) $(BUILD_LOG).old 2> /dev/null && \
46354331Sarchie	$(MV) $(BUILD_LOG) $(BUILD_LOG).old 2> /dev/null || true
46454331Sarchie	$(if $(findstring trace, $(LOG_LEVEL)), \
46554331Sarchie	  $(RM) $(BUILD_TRACE_LOG).old 2> /dev/null && \
46654331Sarchie	  $(MV) $(BUILD_TRACE_LOG) $(BUILD_TRACE_LOG).old 2> /dev/null || true \
46754331Sarchie	)
46854331Sarchie  endef
46970700Sjulian
47054331Sarchie  define PrepareFailureLogs
47170784Sjulian	$(RM) -r $(MAKESUPPORT_OUTPUTDIR)/failure-logs 2> /dev/null && \
47254331Sarchie	$(MKDIR) -p $(MAKESUPPORT_OUTPUTDIR)/failure-logs
47354331Sarchie  endef
47454331Sarchie
47554331Sarchie  # Remove any javac server logs and port files. This
47670700Sjulian  # prevents a new make run to reuse the previous servers.
47754331Sarchie  define PrepareSmartJavac
478149880Sglebius	$(if $(SJAVAC_SERVER_DIR), \
479149880Sglebius	  $(RM) -r $(SJAVAC_SERVER_DIR) 2> /dev/null && \
48070700Sjulian	  $(MKDIR) -p $(SJAVAC_SERVER_DIR) \
48170700Sjulian	)
48270700Sjulian  endef
48370700Sjulian
48470700Sjulian  define CleanupSmartJavac
48560009Sarchie	[ -f $(SJAVAC_SERVER_DIR)/server.port ] && $(ECHO) Stopping sjavac server && \
48660009Sarchie	    $(TOUCH) $(SJAVAC_SERVER_DIR)/server.port.stop; true
48754331Sarchie  endef
488128657Sarchie
489128657Sarchie  define StartGlobalTimer
490128657Sarchie	$(RM) -r $(BUILDTIMESDIR) 2> /dev/null && \
491128657Sarchie	$(MKDIR) -p $(BUILDTIMESDIR) && \
492128657Sarchie	$(call RecordStartTime,TOTAL)
493128657Sarchie  endef
494149880Sglebius
495128657Sarchie  define StopGlobalTimer
49660009Sarchie	$(call RecordEndTime,TOTAL)
49754331Sarchie  endef
49860009Sarchie
49960009Sarchie  # Find all build_time_* files and print their contents in a list sorted
50060009Sarchie  # on the name of the sub repository.
501149880Sglebius  define ReportBuildTimes
50260009Sarchie	$(PRINTF) $(LOG_INFO) -- \
50370700Sjulian	    "----- Build times -------\nStart %s\nEnd   %s\n%s\n%s\n-------------------------\n" \
50460009Sarchie	    "`$(CAT) $(BUILDTIMESDIR)/build_time_start_TOTAL_human_readable`" \
50570700Sjulian	    "`$(CAT) $(BUILDTIMESDIR)/build_time_end_TOTAL_human_readable`" \
50660009Sarchie	    "`$(LS) $(BUILDTIMESDIR)/build_time_diff_* | $(GREP) -v _TOTAL | \
50754331Sarchie	    $(XARGS) $(CAT) | $(SORT) -k 2`" \
50863822Sarchie	    "`$(CAT) $(BUILDTIMESDIR)/build_time_diff_TOTAL`" \
50954331Sarchie	    $(BUILD_LOG_PIPE)
51054331Sarchie  endef
51154331Sarchie
51254331Sarchieendif # HAS_SPEC
51354331Sarchie
51454331Sarchieendif # _INITSUPPORT_GMK
515128657Sarchie