annotate make/InitSupport.gmk @ 51482:d7029542d67a

8209420: Track membars for volatile accesses so they can be properly optimized Reviewed-by: adinn, aph, thartmann
author roland
date Tue, 14 Aug 2018 16:54:47 +0200
parents e5cdf2569510
children 2ed42e41e712
rev   line source
erikj@13133 1 #
ihse@49568 2 # Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
erikj@13133 3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
erikj@13133 4 #
erikj@13133 5 # This code is free software; you can redistribute it and/or modify it
erikj@13133 6 # under the terms of the GNU General Public License version 2 only, as
erikj@13133 7 # published by the Free Software Foundation. Oracle designates this
erikj@13133 8 # particular file as subject to the "Classpath" exception as provided
erikj@13133 9 # by Oracle in the LICENSE file that accompanied this code.
erikj@13133 10 #
erikj@13133 11 # This code is distributed in the hope that it will be useful, but WITHOUT
erikj@13133 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
erikj@13133 13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
erikj@13133 14 # version 2 for more details (a copy is included in the LICENSE file that
erikj@13133 15 # accompanied this code).
erikj@13133 16 #
erikj@13133 17 # You should have received a copy of the GNU General Public License version
erikj@13133 18 # 2 along with this work; if not, write to the Free Software Foundation,
erikj@13133 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
erikj@13133 20 #
erikj@13133 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
erikj@13133 22 # or visit www.oracle.com if you need additional information or have any
erikj@13133 23 # questions.
erikj@13133 24 #
erikj@13133 25
ihse@29662 26 ################################################################################
ihse@29662 27 # This file contains helper functions for Init.gmk.
ihse@29662 28 # It is divided in two parts, depending on if a SPEC is present or not
ihse@29662 29 # (HAS_SPEC is true or not).
ihse@29662 30 ################################################################################
erikj@13133 31
ihse@29662 32 ifndef _INITSUPPORT_GMK
ihse@29662 33 _INITSUPPORT_GMK := 1
erikj@13133 34
ihse@29662 35 ifeq ($(HAS_SPEC),)
ihse@44027 36
ihse@50507 37 # COMMA is defined in spec.gmk, but that is not included yet
ihse@50507 38 COMMA := ,
ihse@50507 39
ihse@44027 40 # Include the corresponding closed file, if present.
ihse@47313 41 ifneq ($(CUSTOM_MAKE_DIR), )
ihse@47313 42 -include $(CUSTOM_MAKE_DIR)/InitSupport.gmk
ihse@47313 43 endif
ihse@44027 44
ihse@29662 45 ##############################################################################
ihse@29662 46 # Helper functions for the initial part of Init.gmk, before the spec file is
ihse@29662 47 # loaded. Most of these functions provide parsing and setting up make options
ihse@29662 48 # from the command-line.
ihse@29662 49 ##############################################################################
erikj@13133 50
ihse@29662 51 # Make control variables, handled by Init.gmk
ihse@44027 52 INIT_CONTROL_VARIABLES += LOG CONF CONF_NAME SPEC JOBS TEST_JOBS CONF_CHECK \
ihse@47956 53 COMPARE_BUILD JTREG GTEST TEST_OPTS TEST_VM_OPTS
erikj@13133 54
ihse@29662 55 # All known make control variables
ihse@29662 56 MAKE_CONTROL_VARIABLES := $(INIT_CONTROL_VARIABLES) TEST JDK_FILTER
ohair@14111 57
ihse@29662 58 # Define a simple reverse function.
ihse@29662 59 # Should maybe move to MakeBase.gmk, but we can't include that file now.
ihse@29662 60 reverse = \
ihse@29662 61 $(if $(strip $(1)), $(call reverse, $(wordlist 2, $(words $(1)), $(1)))) \
ihse@29662 62 $(firstword $(1))
ohair@14111 63
ihse@29662 64 # The variable MAKEOVERRIDES contains variable assignments from the command
ihse@29662 65 # line, but in reverse order to what the user entered.
ihse@32715 66 # The '\#' <=> '\ 'dance is needed to keep values with space in them connected.
ihse@29662 67 COMMAND_LINE_VARIABLES := $(subst \#,\ , $(call reverse, $(subst \ ,\#,$(MAKEOVERRIDES))))
erikj@13133 68
ihse@29788 69 # A list like FOO="val1" BAR="val2" containing all user-supplied make
ihse@29788 70 # variables that we should propagate.
ihse@32715 71 # The '\#' <=> '\ 'dance is needed to keep values with space in them connected.
ihse@32715 72 USER_MAKE_VARS := $(subst \#,\ , $(filter-out $(addsuffix =%, $(INIT_CONTROL_VARIABLES)), \
ihse@32715 73 $(subst \ ,\#,$(MAKEOVERRIDES))))
ihse@29662 74
ihse@29788 75 # Setup information about available configurations, if any.
ihse@47346 76 ifneq ($(CUSTOM_ROOT), )
ihse@47346 77 build_dir=$(CUSTOM_ROOT)/build
ihse@47346 78 else
erikj@47217 79 build_dir=$(topdir)/build
erikj@47217 80 endif
ihse@29788 81 all_spec_files=$(wildcard $(build_dir)/*/spec.gmk)
ihse@29788 82 # Extract the configuration names from the path
ihse@29788 83 all_confs=$(patsubst %/spec.gmk, %, $(patsubst $(build_dir)/%, %, $(all_spec_files)))
ihse@29788 84
ihse@29662 85 # Check for unknown command-line variables
ihse@29662 86 define CheckControlVariables
ihse@29662 87 command_line_variables := $$(strip $$(foreach var, \
ihse@29662 88 $$(subst \ ,_,$$(MAKEOVERRIDES)), \
ihse@29662 89 $$(firstword $$(subst =, , $$(var)))))
ihse@29788 90 unknown_command_line_variables := $$(strip \
ihse@29788 91 $$(filter-out $$(MAKE_CONTROL_VARIABLES), $$(command_line_variables)))
ihse@29662 92 ifneq ($$(unknown_command_line_variables), )
ihse@29662 93 $$(info Note: Command line contains non-control variables:)
ihse@29662 94 $$(foreach var, $$(unknown_command_line_variables), $$(info * $$(var)=$$($$(var))))
ihse@29662 95 $$(info Make sure it is not mistyped, and that you intend to override this variable.)
ihse@29662 96 $$(info 'make help' will list known control variables.)
ihse@29662 97 $$(info )
ihse@29662 98 endif
ihse@29662 99 endef
ihse@29662 100
ihse@29662 101 # Check for deprecated ALT_ variables
ihse@29662 102 define CheckDeprecatedEnvironment
ihse@29662 103 defined_alt_variables := $$(filter ALT_%, $$(.VARIABLES))
ihse@29662 104 ifneq ($$(defined_alt_variables), )
ihse@29662 105 $$(info Warning: You have the following ALT_ variables set:)
ihse@29662 106 $$(foreach var, $$(defined_alt_variables), $$(info * $$(var)=$$($$(var))))
ihse@29662 107 $$(info ALT_ variables are deprecated, and may result in a failed build.)
ihse@29662 108 $$(info Please clean your environment.)
ihse@29662 109 $$(info )
ihse@29662 110 endif
ihse@29662 111 endef
ihse@29662 112
ihse@29662 113 # Check for invalid make flags like -j
ihse@29662 114 define CheckInvalidMakeFlags
ihse@29662 115 # This is a trick to get this rule to execute before any other rules
ihse@29662 116 # MAKEFLAGS only indicate -j if read in a recipe (!)
ihse@29662 117 $$(topdir)/make/Init.gmk: .FORCE
ihse@29662 118 $$(if $$(findstring --jobserver, $$(MAKEFLAGS)), \
ihse@29662 119 $$(info Error: 'make -jN' is not supported, use 'make JOBS=N') \
ihse@29662 120 $$(error Cannot continue) \
ihse@20363 121 )
ihse@29662 122 .FORCE:
ihse@29662 123 .PHONY: .FORCE
ihse@29662 124 endef
ohair@14111 125
ihse@29662 126 # Check that the CONF_CHECK option is valid and set up handling
ihse@29662 127 define ParseConfCheckOption
ihse@29662 128 ifeq ($$(CONF_CHECK), )
ihse@29662 129 # Default behavior is fail
ihse@29662 130 CONF_CHECK := fail
ihse@29662 131 else ifneq ($$(filter-out auto fail ignore, $$(CONF_CHECK)),)
ihse@29662 132 $$(info Error: CONF_CHECK must be one of: auto, fail or ignore.)
ihse@29662 133 $$(error Cannot continue)
ihse@29662 134 endif
ihse@29662 135 endef
ohair@14111 136
ihse@29662 137 define ParseConfAndSpec
ihse@29662 138 ifneq ($$(origin SPEC), undefined)
ihse@20363 139 # We have been given a SPEC, check that it works out properly
ihse@29662 140 ifneq ($$(origin CONF), undefined)
ihse@29662 141 # We also have a CONF argument. We can't have both.
ihse@29662 142 $$(info Error: Cannot use CONF=$$(CONF) and SPEC=$$(SPEC) at the same time. Choose one.)
ihse@29662 143 $$(error Cannot continue)
ihse@20363 144 endif
erikj@34491 145 ifneq ($$(origin CONF_NAME), undefined)
erikj@34491 146 # We also have a CONF_NAME argument. We can't have both.
erikj@34491 147 $$(info Error: Cannot use CONF_NAME=$$(CONF_NAME) and SPEC=$$(SPEC) at the same time. Choose one.)
erikj@34491 148 $$(error Cannot continue)
erikj@34491 149 endif
ihse@27595 150 ifeq ($$(wildcard $$(SPEC)),)
ihse@27595 151 $$(info Error: Cannot locate spec.gmk, given by SPEC=$$(SPEC).)
ihse@29662 152 $$(error Cannot continue)
ihse@27595 153 endif
ihse@29662 154 ifeq ($$(filter /%, $$(SPEC)),)
ihse@29662 155 # If given with relative path, make it absolute
ihse@29662 156 SPECS := $$(CURDIR)/$$(strip $$(SPEC))
ihse@29662 157 else
ihse@29662 158 SPECS := $$(SPEC)
ihse@29662 159 endif
ihse@29662 160
ihse@29662 161 # For now, unset this SPEC variable.
ihse@29662 162 override SPEC :=
ihse@20363 163 else
ihse@29662 164 # Use spec.gmk files in the build output directory
ihse@29788 165 ifeq ($$(all_spec_files),)
ihse@47346 166 ifneq ($(CUSTOM_ROOT), )
ihse@47346 167 $$(info Error: No configurations found for $$(CUSTOM_ROOT).)
ihse@47346 168 else
ihse@47346 169 $$(info Error: No configurations found for $$(topdir).)
ihse@47346 170 endif
ihse@27595 171 $$(info Please run 'bash configure' to create a configuration.)
ihse@29662 172 $$(info )
ihse@29662 173 $$(error Cannot continue)
ihse@20363 174 endif
ihse@20363 175
erikj@34491 176 ifneq ($$(origin CONF_NAME), undefined)
erikj@34491 177 ifneq ($$(origin CONF), undefined)
erikj@34491 178 # We also have a CONF argument. We can't have both.
erikj@34491 179 $$(info Error: Cannot use CONF=$$(CONF) and CONF_NAME=$$(CONF_NAME) at the same time. Choose one.)
erikj@34491 180 $$(error Cannot continue)
erikj@34491 181 endif
erikj@34491 182 matching_conf := $$(strip $$(filter $$(CONF_NAME), $$(all_confs)))
erikj@34491 183 ifeq ($$(matching_conf),)
erikj@34491 184 $$(info Error: No configurations found matching CONF_NAME=$$(CONF_NAME).)
erikj@34491 185 $$(info Available configurations in $$(build_dir):)
erikj@34491 186 $$(foreach var, $$(all_confs), $$(info * $$(var)))
erikj@34491 187 $$(error Cannot continue)
erikj@34491 188 else ifneq ($$(words $$(matching_conf)), 1)
erikj@34491 189 $$(info Error: Matching more than one configuration CONF_NAME=$$(CONF_NAME).)
erikj@34491 190 $$(info Available configurations in $$(build_dir):)
erikj@34491 191 $$(foreach var, $$(all_confs), $$(info * $$(var)))
erikj@34491 192 $$(error Cannot continue)
erikj@34491 193 else
erikj@34491 194 $$(info Building configuration '$$(matching_conf)' (matching CONF_NAME=$$(CONF_NAME)))
erikj@34491 195 endif
erikj@34491 196 # Create a SPEC definition. This will contain the path to exactly one spec file.
erikj@34491 197 SPECS := $$(build_dir)/$$(matching_conf)/spec.gmk
erikj@34491 198 else ifneq ($$(origin CONF), undefined)
ihse@20363 199 # User have given a CONF= argument.
ihse@20363 200 ifeq ($$(CONF),)
ihse@20363 201 # If given CONF=, match all configurations
ihse@29662 202 matching_confs := $$(strip $$(all_confs))
ohair@14111 203 else
ihse@20363 204 # Otherwise select those that contain the given CONF string
ihse@29788 205 matching_confs := $$(strip $$(foreach var, $$(all_confs), \
ihse@29788 206 $$(if $$(findstring $$(CONF), $$(var)), $$(var))))
ihse@20363 207 endif
ihse@20363 208 ifeq ($$(matching_confs),)
ihse@27595 209 $$(info Error: No configurations found matching CONF=$$(CONF).)
ihse@29662 210 $$(info Available configurations in $$(build_dir):)
ihse@29662 211 $$(foreach var, $$(all_confs), $$(info * $$(var)))
ihse@29662 212 $$(error Cannot continue)
ihse@20363 213 else
erikj@35008 214 # Don't repeat this output on make restarts caused by including
erikj@35008 215 # generated files.
erikj@35008 216 ifeq ($$(MAKE_RESTARTS),)
erikj@35008 217 ifeq ($$(words $$(matching_confs)), 1)
ihse@48057 218 ifneq ($$(findstring $$(LOG_LEVEL), info debug trace),)
ihse@48057 219 $$(info Building configuration '$$(matching_confs)' (matching CONF=$$(CONF)))
ihse@48057 220 endif
erikj@35008 221 else
erikj@35008 222 $$(info Building these configurations (matching CONF=$$(CONF)):)
erikj@35008 223 $$(foreach var, $$(matching_confs), $$(info * $$(var)))
erikj@35008 224 endif
ihse@20363 225 endif
ihse@20363 226 endif
erikj@13133 227
ihse@20363 228 # Create a SPEC definition. This will contain the path to one or more spec.gmk files.
ihse@29662 229 SPECS := $$(addsuffix /spec.gmk, $$(addprefix $$(build_dir)/, $$(matching_confs)))
ihse@20363 230 else
ihse@20363 231 # No CONF or SPEC given, check the available configurations
ihse@29662 232 ifneq ($$(words $$(all_spec_files)), 1)
ihse@27595 233 $$(info Error: No CONF given, but more than one configuration found.)
ihse@29662 234 $$(info Available configurations in $$(build_dir):)
ihse@29662 235 $$(foreach var, $$(all_confs), $$(info * $$(var)))
ihse@29662 236 $$(info Please retry building with CONF=<config pattern> (or SPEC=<spec file>).)
ihse@29662 237 $$(info )
ihse@29662 238 $$(error Cannot continue)
ihse@20363 239 endif
ohair@14111 240
ihse@20363 241 # We found exactly one configuration, use it
ihse@29662 242 SPECS := $$(strip $$(all_spec_files))
ihse@20363 243 endif
erikj@13133 244 endif
ihse@29662 245 endef
ihse@29662 246
ihse@29788 247 # Extract main targets from Main.gmk using the spec provided in $2.
ihse@29788 248 #
ihse@29788 249 # Param 1: FORCE = force generation of main-targets.gmk or LAZY = do not force.
ihse@29788 250 # Param 2: The SPEC file to use.
ihse@29788 251 define DefineMainTargets
ihse@29788 252
ihse@29788 253 # We will start by making sure the main-targets.gmk file is removed, if
ihse@29788 254 # make has not been restarted. By the -include, we will trigger the
ihse@29788 255 # rule for generating the file (which is never there since we removed it),
ihse@29788 256 # thus generating it fresh, and make will restart, incrementing the restart
ihse@29788 257 # count.
ihse@29788 258 main_targets_file := $$(dir $(strip $2))make-support/main-targets.gmk
ihse@29788 259
ihse@29788 260 ifeq ($$(MAKE_RESTARTS),)
ihse@29788 261 # Only do this if make has not been restarted, and if we do not force it.
ihse@29788 262 ifeq ($(strip $1), FORCE)
ihse@29788 263 $$(shell rm -f $$(main_targets_file))
ihse@29788 264 endif
ihse@29788 265 endif
ihse@29788 266
ihse@29788 267 $$(main_targets_file):
ihse@29788 268 @( cd $$(topdir) && \
erikj@35008 269 $$(MAKE) $$(MAKE_LOG_FLAGS) -r -R -f $$(topdir)/make/Main.gmk \
ihse@29788 270 -I $$(topdir)/make/common SPEC=$(strip $2) NO_RECIPES=true \
asemenyuk@44465 271 $$(MAKE_LOG_VARS) \
ihse@29788 272 create-main-targets-include )
ihse@29788 273
ihse@29788 274 # Now include main-targets.gmk. This will define ALL_MAIN_TARGETS.
ihse@29788 275 -include $$(main_targets_file)
ihse@29788 276 endef
ihse@29788 277
ihse@29662 278 define PrintConfCheckFailed
ihse@29662 279 @echo ' '
ihse@29662 280 @echo "Please rerun configure! Easiest way to do this is by running"
ihse@29662 281 @echo "'make reconfigure'."
ihse@29662 282 @echo "This behavior may also be changed using CONF_CHECK=<ignore|auto>."
ihse@29662 283 @echo ' '
ihse@29662 284 endef
ihse@29662 285
ihse@29662 286 else # $(HAS_SPEC)=true
ihse@29662 287 ##############################################################################
ihse@29662 288 # Helper functions for the 'main' target. These functions assume a single,
ihse@29788 289 # proper and existing SPEC is included.
ihse@29662 290 ##############################################################################
ihse@29662 291
erikj@47217 292 include $(TOPDIR)/make/common/MakeBase.gmk
ihse@29662 293
ihse@29662 294 # Define basic logging setup
ihse@47253 295 BUILD_LOG := $(OUTPUTDIR)/build.log
ihse@47253 296 BUILD_PROFILE_LOG := $(OUTPUTDIR)/build-profile.log
ihse@29662 297
erikj@37410 298 BUILD_LOG_PIPE := > >($(TEE) -a $(BUILD_LOG)) 2> >($(TEE) -a $(BUILD_LOG) >&2) && wait
ihse@29662 299
ihse@48907 300 ifneq ($(CUSTOM_ROOT), )
ihse@48907 301 topdir=$(CUSTOM_ROOT)
ihse@48907 302 else
ihse@48907 303 topdir=$(TOPDIR)
ihse@48907 304 endif
ihse@48907 305
ihse@32715 306 # Parse COMPARE_BUILD into COMPARE_BUILD_*
ihse@32715 307 # Syntax: COMPARE_BUILD=CONF=<configure options>:PATCH=<patch file>:
ihse@32720 308 # MAKE=<make targets>:COMP_OPTS=<compare script options>:
erikj@35744 309 # COMP_DIR=<compare script base dir>|<default>:
erikj@35744 310 # FAIL=<bool>
ihse@32715 311 # If neither CONF or PATCH is given, assume <default> means CONF if it
ihse@32715 312 # begins with "--", otherwise assume it means PATCH.
ihse@32715 313 # MAKE and COMP_OPTS can only be used with CONF and/or PATCH specified.
ihse@32715 314 # If any value contains "+", it will be replaced by space.
erikj@35744 315 # FAIL can be set to false to have the return value of compare be ignored.
ihse@32715 316 define ParseCompareBuild
ihse@32715 317 ifneq ($$(COMPARE_BUILD), )
ihse@48907 318 COMPARE_BUILD_OUTPUTDIR := $(topdir)/build/compare-build/$(CONF_NAME)
erikj@35744 319 COMPARE_BUILD_FAIL := true
ihse@33572 320
ihse@32715 321 ifneq ($$(findstring :, $$(COMPARE_BUILD)), )
ihse@32715 322 $$(foreach part, $$(subst :, , $$(COMPARE_BUILD)), \
ihse@32715 323 $$(if $$(filter PATCH=%, $$(part)), \
ihse@32715 324 $$(eval COMPARE_BUILD_PATCH=$$(strip $$(patsubst PATCH=%, %, $$(part)))) \
ihse@32715 325 ) \
ihse@32715 326 $$(if $$(filter CONF=%, $$(part)), \
ihse@32715 327 $$(eval COMPARE_BUILD_CONF=$$(strip $$(subst +, , $$(patsubst CONF=%, %, $$(part))))) \
ihse@32715 328 ) \
ihse@32715 329 $$(if $$(filter MAKE=%, $$(part)), \
ihse@32715 330 $$(eval COMPARE_BUILD_MAKE=$$(strip $$(subst +, , $$(patsubst MAKE=%, %, $$(part))))) \
ihse@32715 331 ) \
ihse@32715 332 $$(if $$(filter COMP_OPTS=%, $$(part)), \
ihse@32715 333 $$(eval COMPARE_BUILD_COMP_OPTS=$$(strip $$(subst +, , $$(patsubst COMP_OPTS=%, %, $$(part))))) \
ihse@32715 334 ) \
ihse@32720 335 $$(if $$(filter COMP_DIR=%, $$(part)), \
ihse@32720 336 $$(eval COMPARE_BUILD_COMP_DIR=$$(strip $$(subst +, , $$(patsubst COMP_DIR=%, %, $$(part))))) \
ihse@32720 337 ) \
erikj@35744 338 $$(if $$(filter FAIL=%, $$(part)), \
erikj@35744 339 $$(eval COMPARE_BUILD_FAIL=$$(strip $$(subst +, , $$(patsubst FAIL=%, %, $$(part))))) \
erikj@35744 340 ) \
ihse@32715 341 )
ihse@32715 342 else
ihse@32715 343 # Separate handling for single field case, to allow for spaces in values.
ihse@32715 344 ifneq ($$(filter PATCH=%, $$(COMPARE_BUILD)), )
ihse@32715 345 COMPARE_BUILD_PATCH=$$(strip $$(patsubst PATCH=%, %, $$(COMPARE_BUILD)))
ihse@32715 346 else ifneq ($$(filter CONF=%, $$(COMPARE_BUILD)), )
ihse@32715 347 COMPARE_BUILD_CONF=$$(strip $$(subst +, , $$(patsubst CONF=%, %, $$(COMPARE_BUILD))))
ihse@32715 348 else ifneq ($$(filter --%, $$(COMPARE_BUILD)), )
ihse@32715 349 # Assume CONF if value begins with --
ihse@32715 350 COMPARE_BUILD_CONF=$$(strip $$(subst +, , $$(COMPARE_BUILD)))
ihse@32715 351 else
ihse@32715 352 # Otherwise assume patch file
ihse@32715 353 COMPARE_BUILD_PATCH=$$(strip $$(COMPARE_BUILD))
ihse@32715 354 endif
ihse@32715 355 endif
ihse@32715 356 ifneq ($$(COMPARE_BUILD_PATCH), )
ihse@48907 357 ifneq ($$(wildcard $$(topdir)/$$(COMPARE_BUILD_PATCH)), )
ihse@32715 358 # Assume relative path, if file exists
ihse@48907 359 COMPARE_BUILD_PATCH := $$(wildcard $$(topdir)/$$(COMPARE_BUILD_PATCH))
ihse@32715 360 else ifeq ($$(wildcard $$(COMPARE_BUILD_PATCH)), )
ihse@32715 361 $$(error Patch file $$(COMPARE_BUILD_PATCH) does not exist)
ihse@32715 362 endif
ihse@32715 363 endif
erikj@35744 364 ifneq ($$(COMPARE_BUILD_FAIL), true)
erikj@35744 365 COMPARE_BUILD_IGNORE_RESULT := || true
erikj@35744 366 endif
ihse@32715 367 endif
ihse@32715 368 endef
ihse@32715 369
ihse@33572 370 # Prepare for a comparison rebuild
ihse@33572 371 define PrepareCompareBuild
ihse@33572 372 $(ECHO) "Preparing for comparison rebuild"
ihse@33572 373 # Apply patch, if any
ihse@49138 374 $(if $(COMPARE_BUILD_PATCH), cd $(topdir) && $(PATCH) -p1 < $(COMPARE_BUILD_PATCH))
ihse@33572 375 # Move the first build away temporarily
ihse@48907 376 $(RM) -r $(topdir)/build/.compare-build-temp
ihse@48907 377 $(MKDIR) -p $(topdir)/build/.compare-build-temp
ihse@48907 378 $(MV) $(OUTPUTDIR) $(topdir)/build/.compare-build-temp
ihse@33572 379 # Restore an old compare-build, or create a new compare-build directory.
ihse@47253 380 if test -d $(COMPARE_BUILD_OUTPUTDIR); then \
ihse@47253 381 $(MV) $(COMPARE_BUILD_OUTPUTDIR) $(OUTPUTDIR); \
ihse@33572 382 else \
ihse@47253 383 $(MKDIR) -p $(OUTPUTDIR); \
ihse@33572 384 fi
ihse@33572 385 # Re-run configure with the same arguments (and possibly some additional),
ihse@33572 386 # must be done after patching.
ihse@47253 387 ( cd $(OUTPUTDIR) && PATH="$(ORIGINAL_PATH)" \
ihse@48907 388 $(BASH) $(topdir)/configure $(CONFIGURE_COMMAND_LINE) $(COMPARE_BUILD_CONF))
ihse@33572 389 endef
ihse@33572 390
ihse@33572 391 # Cleanup after a compare build
ihse@33572 392 define CleanupCompareBuild
ihse@33572 393 # If running with a COMPARE_BUILD patch, reverse-apply it
ihse@49138 394 $(if $(COMPARE_BUILD_PATCH), cd $(topdir) && $(PATCH) -R -p1 < $(COMPARE_BUILD_PATCH))
ihse@33572 395 # Move this build away and restore the original build
ihse@48907 396 $(MKDIR) -p $(topdir)/build/compare-build
ihse@47253 397 $(MV) $(OUTPUTDIR) $(COMPARE_BUILD_OUTPUTDIR)
ihse@48907 398 $(MV) $(topdir)/build/.compare-build-temp/$(CONF_NAME) $(OUTPUTDIR)
ihse@48907 399 $(RM) -r $(topdir)/build/.compare-build-temp
ihse@33572 400 endef
ihse@33572 401
ihse@33572 402 # Do the actual comparison of two builds
ihse@33572 403 define CompareBuildDoComparison
ihse@33572 404 # Compare first and second build. Ignore any error code from compare.sh.
ihse@33572 405 $(ECHO) "Comparing between comparison rebuild (this/new) and baseline (other/old)"
ihse@33572 406 $(if $(COMPARE_BUILD_COMP_DIR), \
ihse@47253 407 +(cd $(COMPARE_BUILD_OUTPUTDIR) && ./compare.sh $(COMPARE_BUILD_COMP_OPTS) \
ihse@47253 408 -2dirs $(COMPARE_BUILD_OUTPUTDIR)/$(COMPARE_BUILD_COMP_DIR) \
ihse@47253 409 $(OUTPUTDIR)/$(COMPARE_BUILD_COMP_DIR) $(COMPARE_BUILD_IGNORE_RESULT)), \
ihse@47253 410 +(cd $(COMPARE_BUILD_OUTPUTDIR) && ./compare.sh $(COMPARE_BUILD_COMP_OPTS) \
ihse@47253 411 -o $(OUTPUTDIR) $(COMPARE_BUILD_IGNORE_RESULT)) \
ihse@33572 412 )
ihse@33572 413 endef
ihse@33572 414
ihse@33572 415 define PrintFailureReports
ihse@49568 416 $(if $(filter none, $(LOG_REPORT)), , \
ihse@49568 417 $(if $(wildcard $(MAKESUPPORT_OUTPUTDIR)/failure-logs/*.log), \
ihse@49568 418 $(PRINTF) "\n=== Output from failing command(s) repeated here ===\n" $(NEWLINE) \
ihse@49568 419 $(foreach logfile, $(sort $(wildcard $(MAKESUPPORT_OUTPUTDIR)/failure-logs/*.log)), \
ihse@49568 420 $(PRINTF) "* For target $(notdir $(basename $(logfile))):\n" $(NEWLINE) \
ihse@49568 421 $(if $(filter all, $(LOG_REPORT)), \
ihse@49568 422 $(GREP) -v -e "^Note: including file:" < $(logfile) || true $(NEWLINE) \
ihse@49568 423 , \
ihse@49568 424 ($(GREP) -v -e "^Note: including file:" < $(logfile) || true) | $(HEAD) -n 12 $(NEWLINE) \
ihse@49568 425 if test `$(WC) -l < $(logfile)` -gt 12; then \
ihse@49568 426 $(ECHO) " ... (rest of output omitted)" ; \
ihse@49568 427 fi $(NEWLINE) \
ihse@49568 428 ) \
ihse@49568 429 ) \
ihse@49568 430 $(PRINTF) "\n* All command lines available in $(MAKESUPPORT_OUTPUTDIR)/failure-logs.\n" $(NEWLINE) \
ihse@49568 431 $(PRINTF) "=== End of repeated output ===\n" \
ihse@33572 432 ) \
ihse@33572 433 )
ihse@33572 434 endef
ihse@33572 435
ihse@33572 436 define PrintBuildLogFailures
ihse@49568 437 $(if $(filter none, $(LOG_REPORT)), , \
ihse@49568 438 if $(GREP) -q "recipe for target .* failed" $(BUILD_LOG) 2> /dev/null; then \
ihse@49568 439 $(PRINTF) "\n=== Make failed targets repeated here ===\n" ; \
ihse@49568 440 $(GREP) "recipe for target .* failed" $(BUILD_LOG) ; \
ihse@49568 441 $(PRINTF) "=== End of repeated output ===\n" ; \
ihse@49568 442 $(PRINTF) "\nHint: Try searching the build log for the name of the first failed target.\n" ; \
ihse@49568 443 else \
ihse@49568 444 $(PRINTF) "\nNo indication of failed target found.\n" ; \
ihse@49568 445 $(PRINTF) "Hint: Try searching the build log for '] Error'.\n" ; \
ihse@49568 446 fi \
ihse@49568 447 )
ihse@33572 448 endef
ihse@33572 449
ihse@29662 450 define RotateLogFiles
erikj@35008 451 $(RM) $(BUILD_LOG).old 2> /dev/null && \
ihse@29662 452 $(MV) $(BUILD_LOG) $(BUILD_LOG).old 2> /dev/null || true
asemenyuk@44465 453 $(if $(findstring true, $(LOG_PROFILE_TIMES_FILE)), \
asemenyuk@44465 454 $(RM) $(BUILD_PROFILE_LOG).old 2> /dev/null && \
asemenyuk@44465 455 $(MV) $(BUILD_PROFILE_LOG) $(BUILD_PROFILE_LOG).old 2> /dev/null || true \
ihse@29662 456 )
ihse@29662 457 endef
ihse@29156 458
ihse@50562 459 # Failure logs are only supported for "parallel" main targets, not the
ihse@50562 460 # (trivial) sequential make targets (such as clean and reconfigure),
ihse@50562 461 # since the failure-logs directory creation will conflict with clean.
ihse@32344 462 define PrepareFailureLogs
erikj@35008 463 $(RM) -r $(MAKESUPPORT_OUTPUTDIR)/failure-logs 2> /dev/null && \
ihse@32344 464 $(MKDIR) -p $(MAKESUPPORT_OUTPUTDIR)/failure-logs
ihse@44027 465 $(RM) $(MAKESUPPORT_OUTPUTDIR)/exit-with-error 2> /dev/null
ihse@32344 466 endef
ihse@32344 467
ihse@29662 468 # Remove any javac server logs and port files. This
ihse@29662 469 # prevents a new make run to reuse the previous servers.
ihse@29662 470 define PrepareSmartJavac
ihse@29662 471 $(if $(SJAVAC_SERVER_DIR), \
ihse@29662 472 $(RM) -r $(SJAVAC_SERVER_DIR) 2> /dev/null && \
ihse@29662 473 $(MKDIR) -p $(SJAVAC_SERVER_DIR) \
ihse@29662 474 )
ihse@29662 475 endef
ohair@13697 476
ihse@29662 477 define CleanupSmartJavac
ihse@29662 478 [ -f $(SJAVAC_SERVER_DIR)/server.port ] && $(ECHO) Stopping sjavac server && \
ihse@29662 479 $(TOUCH) $(SJAVAC_SERVER_DIR)/server.port.stop; true
ihse@29662 480 endef
ihse@29156 481
ihse@35370 482 ifeq ($(OPENJDK_BUILD_OS), windows)
ihse@35370 483 # On windows we need to synchronize with the javac server to be able to
ihse@35370 484 # move or remove the build output directory. Since we have no proper
ihse@35370 485 # synchronization process, wait for a while and hope it helps. This is only
ihse@35370 486 # used by build comparisons.
ihse@35370 487 define WaitForSmartJavacFinish
ihse@35370 488 $(if $(SJAVAC_SERVER_DIR), \
ihse@35370 489 sleep 5\
ihse@35370 490 )
ihse@35370 491 endef
ihse@35370 492 else
ihse@35370 493 define WaitForSmartJavacFinish
ihse@35370 494 endef
ihse@35370 495 endif
ihse@35370 496
ihse@29662 497 define StartGlobalTimer
erikj@35008 498 $(RM) -r $(BUILDTIMESDIR) 2> /dev/null && \
erikj@35008 499 $(MKDIR) -p $(BUILDTIMESDIR) && \
ihse@29662 500 $(call RecordStartTime,TOTAL)
ihse@29662 501 endef
chegar@27560 502
ihse@29662 503 define StopGlobalTimer
ihse@29662 504 $(call RecordEndTime,TOTAL)
ihse@29662 505 endef
chegar@27560 506
ihse@29662 507 # Find all build_time_* files and print their contents in a list sorted
ihse@29662 508 # on the name of the sub repository.
ihse@29662 509 define ReportBuildTimes
erikj@35008 510 $(PRINTF) $(LOG_INFO) -- \
ihse@29662 511 "----- Build times -------\nStart %s\nEnd %s\n%s\n%s\n-------------------------\n" \
ihse@29662 512 "`$(CAT) $(BUILDTIMESDIR)/build_time_start_TOTAL_human_readable`" \
ihse@29662 513 "`$(CAT) $(BUILDTIMESDIR)/build_time_end_TOTAL_human_readable`" \
ihse@29662 514 "`$(LS) $(BUILDTIMESDIR)/build_time_diff_* | $(GREP) -v _TOTAL | \
ihse@29662 515 $(XARGS) $(CAT) | $(SORT) -k 2`" \
erikj@35008 516 "`$(CAT) $(BUILDTIMESDIR)/build_time_diff_TOTAL`" \
erikj@35008 517 $(BUILD_LOG_PIPE)
ihse@29662 518 endef
chegar@27560 519
asemenyuk@44465 520 define ReportProfileTimes
asemenyuk@44465 521 $(if $(findstring true, $(LOG_PROFILE_TIMES_LOG)), \
asemenyuk@44465 522 [ ! -f $(BUILD_PROFILE_LOG) ] || \
asemenyuk@44465 523 { $(ECHO) Begin $(notdir $(BUILD_PROFILE_LOG)) && \
asemenyuk@44465 524 $(CAT) $(BUILD_PROFILE_LOG) && \
asemenyuk@44465 525 $(ECHO) End $(notdir $(BUILD_PROFILE_LOG)); \
asemenyuk@44465 526 } \
asemenyuk@44465 527 $(BUILD_LOG_PIPE)
asemenyuk@44465 528 )
asemenyuk@44465 529 endef
asemenyuk@44465 530
ihse@29662 531 endif # HAS_SPEC
chegar@27560 532
ihse@49568 533 # Look for a given option in the LOG variable, and if found, set a variable
ihse@49568 534 # and remove the option from the LOG variable
ihse@49568 535 # $1: The option to look for
ihse@49568 536 # $2: The variable to set to "true" if the option is found
ihse@49568 537 define ParseLogOption
ihse@49568 538 ifneq ($$(findstring $1, $$(LOG)),)
ihse@49568 539 override $2 := true
ihse@49568 540 # First try to remove ",<option>" if it exists, otherwise just remove "<option>"
ihse@49568 541 LOG_STRIPPED := $$(subst $1,, $$(subst $$(COMMA)$$(strip $1),, $$(LOG)))
ihse@49568 542 # We might have ended up with a leading comma. Remove it. Need override
ihse@49568 543 # since LOG is set from the command line.
ihse@49568 544 override LOG := $$(strip $$(patsubst $$(COMMA)%, %, $$(LOG_STRIPPED)))
ihse@49568 545 endif
ihse@49568 546 endef
ihse@49568 547
ihse@49568 548 # Look for a given option with an assignment in the LOG variable, and if found,
ihse@49568 549 # set a variable to that value and remove the option from the LOG variable
ihse@49568 550 # $1: The option to look for
ihse@49568 551 # $2: The variable to set to the value of the option, if found
ihse@49568 552 define ParseLogValue
ihse@49568 553 ifneq ($$(findstring $1=, $$(LOG)),)
ihse@49568 554 # Make words of out comma-separated list and find the one with opt=val
ihse@49568 555 value := $$(strip $$(subst $$(strip $1)=,, $$(filter $$(strip $1)=%, $$(subst $$(COMMA), , $$(LOG)))))
ihse@49568 556 override $2 := $$(value)
ihse@49568 557 # First try to remove ",<option>" if it exists, otherwise just remove "<option>"
ihse@49568 558 LOG_STRIPPED := $$(subst $$(strip $1)=$$(value),, \
ihse@49568 559 $$(subst $$(COMMA)$$(strip $1)=$$(value),, $$(LOG)))
ihse@49568 560 # We might have ended up with a leading comma. Remove it. Need override
ihse@49568 561 # since LOG is set from the command line.
ihse@49568 562 override LOG := $$(strip $$(patsubst $$(COMMA)%, %, $$(LOG_STRIPPED)))
ihse@49568 563 endif
ihse@49568 564 endef
ihse@49568 565
ihse@49568 566
ihse@49568 567 define ParseLogLevel
ihse@49568 568 # Catch old-style VERBOSE= command lines.
ihse@49568 569 ifneq ($$(origin VERBOSE), undefined)
ihse@49568 570 $$(info Error: VERBOSE is deprecated. Use LOG=<warn|info|debug|trace> instead.)
ihse@49568 571 $$(error Cannot continue)
ihse@49568 572 endif
ihse@49568 573
ihse@49568 574 # Setup logging according to LOG
ihse@49568 575
ihse@49568 576 # If "nofile" is present, do not log to a file
ihse@49568 577 $$(eval $$(call ParseLogOption, nofile, LOG_NOFILE))
ihse@49568 578
ihse@49568 579 # If "cmdline" is present, print all executes "important" command lines.
ihse@49568 580 $$(eval $$(call ParseLogOption, cmdlines, LOG_CMDLINES))
ihse@49568 581
ihse@49568 582 # If "report" is present, use non-standard reporting options at build failure.
ihse@49568 583 $$(eval $$(call ParseLogValue, report, LOG_REPORT))
ihse@49568 584 ifneq ($$(LOG_REPORT), )
ihse@49568 585 ifeq ($$(filter $$(LOG_REPORT), none all default), )
ihse@49568 586 $$(info Error: LOG=report has invalid value: $$(LOG_REPORT).)
ihse@49568 587 $$(info Valid values: LOG=report=<none>|<all>|<default>)
ihse@49568 588 $$(error Cannot continue)
ihse@49568 589 endif
ihse@49568 590 endif
ihse@49568 591
ihse@49568 592 # If "profile-to-log" is present, write shell times in build log
ihse@49568 593 $$(eval $$(call ParseLogOption, profile-to-log, LOG_PROFILE_TIMES_LOG))
ihse@49568 594
ihse@49568 595 # If "profile" is present, write shell times in separate log file
ihse@49568 596 # IMPORTANT: $(ParseLogOption profile-to-log) should go first. Otherwise
ihse@49568 597 # parsing of 'LOG=debug,profile-to-log,nofile' ends up in the following error:
ihse@49568 598 # Error: LOG contains unknown option or log level: debug-to-log.
ihse@49568 599 $$(eval $$(call ParseLogOption, profile, LOG_PROFILE_TIMES_FILE))
ihse@49568 600
ihse@49568 601 # Treat LOG=profile-to-log as if it were LOG=profile,profile-to-log
ihse@49568 602 LOG_PROFILE_TIMES_FILE := $$(firstword $$(LOG_PROFILE_TIMES_FILE) $$(LOG_PROFILE_TIMES_LOG))
ihse@49568 603
ihse@49568 604 override LOG_LEVEL := $$(LOG)
ihse@49568 605
ihse@49568 606 ifeq ($$(LOG_LEVEL),)
ihse@49568 607 # Set LOG to "warn" as default if not set
ihse@49568 608 override LOG_LEVEL := warn
ihse@49568 609 endif
ihse@49568 610
ihse@49568 611 ifeq ($$(LOG_LEVEL), warn)
ihse@49568 612 override MAKE_LOG_FLAGS := -s
ihse@49568 613 else ifeq ($$(LOG_LEVEL), info)
ihse@49568 614 override MAKE_LOG_FLAGS := -s
ihse@49568 615 else ifeq ($$(LOG_LEVEL), debug)
ihse@49568 616 override MAKE_LOG_FLAGS :=
ihse@49568 617 else ifeq ($$(LOG_LEVEL), trace)
ihse@49568 618 override MAKE_LOG_FLAGS :=
ihse@49568 619 else
ihse@49568 620 $$(info Error: LOG contains unknown option or log level: $$(LOG).)
ihse@49568 621 $$(info LOG can be <level>[,<opt>[...]] where <opt> is nofile | cmdlines | profile | profile-to-log)
ihse@49568 622 $$(info and <level> is warn | info | debug | trace)
ihse@49568 623 $$(error Cannot continue)
ihse@49568 624 endif
ihse@49568 625 endef
ihse@49568 626
asemenyuk@44465 627 MAKE_LOG_VARS = $(foreach v, \
ihse@49568 628 LOG_LEVEL LOG_NOFILE LOG_CMDLINES LOG_REPORT LOG_PROFILE_TIMES_LOG \
ihse@49568 629 LOG_PROFILE_TIMES_FILE, \
asemenyuk@44465 630 $v=$($v) \
asemenyuk@44465 631 )
asemenyuk@44465 632
ihse@29662 633 endif # _INITSUPPORT_GMK