< prev index next >

make/InitSupport.gmk

Print this page


   1 #
   2 # Copyright (c) 2011, 2019, 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


 247   # Extract main targets from Main.gmk using the spec provided in $2.
 248   #
 249   # Param 1: FORCE = force generation of main-targets.gmk or LAZY = do not force.
 250   # Param 2: The SPEC file to use.
 251   define DefineMainTargets
 252 
 253     # We will start by making sure the main-targets.gmk file is removed, if
 254     # make has not been restarted. By the -include, we will trigger the
 255     # rule for generating the file (which is never there since we removed it),
 256     # thus generating it fresh, and make will restart, incrementing the restart
 257     # count.
 258     main_targets_file := $$(dir $(strip $2))make-support/main-targets.gmk
 259 
 260     ifeq ($$(MAKE_RESTARTS),)
 261       # Only do this if make has not been restarted, and if we do not force it.
 262       ifeq ($(strip $1), FORCE)
 263         $$(shell rm -f $$(main_targets_file))
 264       endif
 265     endif
 266 



 267     $$(main_targets_file):
 268         @( cd $$(topdir) && \
 269         $$(MAKE) $$(MAKE_LOG_FLAGS) -r -R -f $$(topdir)/make/Main.gmk \

 270             -I $$(topdir)/make/common SPEC=$(strip $2) NO_RECIPES=true \
 271             $$(MAKE_LOG_VARS) \
 272             create-main-targets-include )
 273 
 274     # Now include main-targets.gmk. This will define ALL_MAIN_TARGETS.
 275     -include $$(main_targets_file)
 276   endef
 277 
 278   define PrintConfCheckFailed
 279         @echo ' '
 280         @echo "Please rerun configure! Easiest way to do this is by running"
 281         @echo "'make reconfigure'."
 282         @echo "This behavior may also be changed using CONF_CHECK=<ignore|auto>."
 283         @echo ' '
 284   endef
 285 
 286 else # $(HAS_SPEC)=true
 287   ##############################################################################
 288   # Helper functions for the 'main' target. These functions assume a single,
 289   # proper and existing SPEC is included.
 290   ##############################################################################
 291 
 292   include $(TOPDIR)/make/common/MakeBase.gmk
 293 
 294   # Define basic logging setup
 295   BUILD_LOG := $(OUTPUTDIR)/build.log
 296   BUILD_PROFILE_LOG := $(OUTPUTDIR)/build-profile.log
 297 
 298   BUILD_LOG_PIPE := > >($(TEE) -a $(BUILD_LOG)) 2> >($(TEE) -a $(BUILD_LOG) >&2) && wait
 299   # Use this for simple echo/printf commands that are never expected to print
 300   # to stderr.
 301   BUILD_LOG_PIPE_SIMPLE := | $(TEE) -a $(BUILD_LOG)
 302 
 303   ifneq ($(CUSTOM_ROOT), )
 304     topdir=$(CUSTOM_ROOT)
 305   else
 306     topdir=$(TOPDIR)
 307   endif
 308 
 309   # Parse COMPARE_BUILD into COMPARE_BUILD_*
 310   # Syntax: COMPARE_BUILD=CONF=<configure options>:PATCH=<patch file>:
 311   #         MAKE=<make targets>:COMP_OPTS=<compare script options>:
 312   #         COMP_DIR=<compare script base dir>|<default>:
 313   #         FAIL=<bool>
 314   # If neither CONF or PATCH is given, assume <default> means CONF if it
 315   # begins with "--", otherwise assume it means PATCH.
 316   # MAKE and COMP_OPTS can only be used with CONF and/or PATCH specified.
 317   # If any value contains "+", it will be replaced by space.
 318   # FAIL can be set to false to have the return value of compare be ignored.
 319   define ParseCompareBuild
 320     ifneq ($$(COMPARE_BUILD), )
 321       COMPARE_BUILD_OUTPUTDIR := $(topdir)/build/compare-build/$(CONF_NAME)


 370     endif
 371   endef
 372 
 373   # Prepare for a comparison rebuild
 374   define PrepareCompareBuild
 375         $(ECHO) "Preparing for comparison rebuild"
 376         # Apply patch, if any
 377         $(if $(COMPARE_BUILD_PATCH), cd $(topdir) && $(PATCH) -p1 < $(COMPARE_BUILD_PATCH))
 378         # Move the first build away temporarily
 379         $(RM) -r $(topdir)/build/.compare-build-temp
 380         $(MKDIR) -p $(topdir)/build/.compare-build-temp
 381         $(MV) $(OUTPUTDIR) $(topdir)/build/.compare-build-temp
 382         # Restore an old compare-build, or create a new compare-build directory.
 383         if test -d $(COMPARE_BUILD_OUTPUTDIR); then \
 384           $(MV) $(COMPARE_BUILD_OUTPUTDIR) $(OUTPUTDIR); \
 385         else \
 386           $(MKDIR) -p $(OUTPUTDIR); \
 387         fi
 388         # Re-run configure with the same arguments (and possibly some additional),
 389         # must be done after patching.
 390         ( cd $(CONFIGURE_START_DIR) && PATH="$(ORIGINAL_PATH)" \
 391             $(BASH) $(topdir)/configure $(CONFIGURE_COMMAND_LINE) $(COMPARE_BUILD_CONF))
 392   endef
 393 
 394   # Cleanup after a compare build
 395   define CleanupCompareBuild
 396         # If running with a COMPARE_BUILD patch, reverse-apply it
 397         $(if $(COMPARE_BUILD_PATCH), cd $(topdir) && $(PATCH) -R -p1 < $(COMPARE_BUILD_PATCH))
 398         # Move this build away and restore the original build
 399         $(MKDIR) -p $(topdir)/build/compare-build
 400         $(MV) $(OUTPUTDIR) $(COMPARE_BUILD_OUTPUTDIR)
 401         $(MV) $(topdir)/build/.compare-build-temp/$(CONF_NAME) $(OUTPUTDIR)
 402         $(RM) -r $(topdir)/build/.compare-build-temp
 403   endef
 404 
 405   # Do the actual comparison of two builds
 406   define CompareBuildDoComparison
 407         # Compare first and second build. Ignore any error code from compare.sh.
 408         $(ECHO) "Comparing between comparison rebuild (this/new) and baseline (other/old)"
 409         $(if $(COMPARE_BUILD_COMP_DIR), \
 410           +(cd $(COMPARE_BUILD_OUTPUTDIR) && ./compare.sh $(COMPARE_BUILD_COMP_OPTS) \


 465   define PrepareFailureLogs
 466         $(RM) -r $(MAKESUPPORT_OUTPUTDIR)/failure-logs 2> /dev/null && \
 467         $(MKDIR) -p $(MAKESUPPORT_OUTPUTDIR)/failure-logs
 468         $(RM) $(MAKESUPPORT_OUTPUTDIR)/exit-with-error 2> /dev/null
 469   endef
 470 
 471   # Remove any javac server logs and port files. This
 472   # prevents a new make run to reuse the previous servers.
 473   define PrepareSmartJavac
 474         $(if $(SJAVAC_SERVER_DIR), \
 475           $(RM) -r $(SJAVAC_SERVER_DIR) 2> /dev/null && \
 476           $(MKDIR) -p $(SJAVAC_SERVER_DIR) \
 477         )
 478   endef
 479 
 480   define CleanupSmartJavac
 481         [ -f $(SJAVAC_SERVER_DIR)/server.port ] && $(ECHO) Stopping sjavac server && \
 482             $(TOUCH) $(SJAVAC_SERVER_DIR)/server.port.stop; true
 483   endef
 484 
 485   ifeq ($(call isBuildOs, windows), true)
 486     # On windows we need to synchronize with the javac server to be able to
 487     # move or remove the build output directory. Since we have no proper
 488     # synchronization process, wait for a while and hope it helps. This is only
 489     # used by build comparisons.
 490     define WaitForSmartJavacFinish
 491         $(if $(SJAVAC_SERVER_DIR), \
 492           sleep 5\
 493         )
 494     endef
 495   else
 496     define WaitForSmartJavacFinish
 497     endef
 498   endif
 499 
 500   define StartGlobalTimer
 501         $(RM) -r $(BUILDTIMESDIR) 2> /dev/null && \
 502         $(MKDIR) -p $(BUILDTIMESDIR) && \
 503         $(call RecordStartTime,TOTAL)
 504   endef
 505 
 506   define StopGlobalTimer
 507         $(call RecordEndTime,TOTAL)
 508   endef
 509 
 510   # Find all build_time_* files and print their contents in a list sorted
 511   # on the name of the sub repository.
 512   define ReportBuildTimes
 513         $(PRINTF) $(LOG_INFO) -- \
 514             "----- Build times -------\nStart %s\nEnd   %s\n%s\n%s\n-------------------------\n" \
 515             "`$(CAT) $(BUILDTIMESDIR)/build_time_start_TOTAL_human_readable`" \
 516             "`$(CAT) $(BUILDTIMESDIR)/build_time_end_TOTAL_human_readable`" \
 517             "`$(LS) $(BUILDTIMESDIR)/build_time_diff_* | $(GREP) -v _TOTAL | \
 518             $(XARGS) $(CAT) | $(SORT) -k 2`" \
 519             "`$(CAT) $(BUILDTIMESDIR)/build_time_diff_TOTAL`" \
 520             $(BUILD_LOG_PIPE_SIMPLE)
 521   endef
 522 
 523   define ReportProfileTimes
 524     $(if $(findstring true, $(LOG_PROFILE_TIMES_LOG)), \
 525       [ ! -f $(BUILD_PROFILE_LOG) ] || \
 526       { $(ECHO) Begin $(notdir $(BUILD_PROFILE_LOG)) && \
 527         $(CAT) $(BUILD_PROFILE_LOG) && \
 528         $(ECHO) End $(notdir $(BUILD_PROFILE_LOG)); \
 529       } \
 530       $(BUILD_LOG_PIPE_SIMPLE)
 531     )
 532   endef
 533 
 534 endif # HAS_SPEC
 535 
 536 # Look for a given option in the LOG variable, and if found, set a variable
 537 # and remove the option from the LOG variable
 538 # $1: The option to look for
 539 # $2: The variable to set to "true" if the option is found
 540 define ParseLogOption
 541   ifneq ($$(findstring $1, $$(LOG)),)
 542     override $2 := true
 543     # First try to remove ",<option>" if it exists, otherwise just remove "<option>"
 544     LOG_STRIPPED := $$(subst $1,, $$(subst $$(COMMA)$$(strip $1),, $$(LOG)))
 545     # We might have ended up with a leading comma. Remove it. Need override
 546     # since LOG is set from the command line.
 547     override LOG := $$(strip $$(patsubst $$(COMMA)%, %, $$(LOG_STRIPPED)))
 548   endif
 549 endef
 550 


   1 #
   2 # Copyright (c) 2011, 2018, 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


 247   # Extract main targets from Main.gmk using the spec provided in $2.
 248   #
 249   # Param 1: FORCE = force generation of main-targets.gmk or LAZY = do not force.
 250   # Param 2: The SPEC file to use.
 251   define DefineMainTargets
 252 
 253     # We will start by making sure the main-targets.gmk file is removed, if
 254     # make has not been restarted. By the -include, we will trigger the
 255     # rule for generating the file (which is never there since we removed it),
 256     # thus generating it fresh, and make will restart, incrementing the restart
 257     # count.
 258     main_targets_file := $$(dir $(strip $2))make-support/main-targets.gmk
 259 
 260     ifeq ($$(MAKE_RESTARTS),)
 261       # Only do this if make has not been restarted, and if we do not force it.
 262       ifeq ($(strip $1), FORCE)
 263         $$(shell rm -f $$(main_targets_file))
 264       endif
 265     endif
 266 
 267     # The --no-print-directory is needed to make the call from
 268     # FindTest.gmk to Test.gmk work with LOG=debug/trace. See
 269     # JDK-8213736
 270     $$(main_targets_file):
 271         @( cd $$(topdir) && \
 272         $$(MAKE) $$(MAKE_LOG_FLAGS) -r -R --no-print-directory \
 273             -f $$(topdir)/make/Main.gmk \
 274             -I $$(topdir)/make/common SPEC=$(strip $2) NO_RECIPES=true \
 275             $$(MAKE_LOG_VARS) \
 276             create-main-targets-include )
 277 
 278     # Now include main-targets.gmk. This will define ALL_MAIN_TARGETS.
 279     -include $$(main_targets_file)
 280   endef
 281 
 282   define PrintConfCheckFailed
 283         @echo ' '
 284         @echo "Please rerun configure! Easiest way to do this is by running"
 285         @echo "'make reconfigure'."
 286         @echo "This behavior may also be changed using CONF_CHECK=<ignore|auto>."
 287         @echo ' '
 288   endef
 289 
 290 else # $(HAS_SPEC)=true
 291   ##############################################################################
 292   # Helper functions for the 'main' target. These functions assume a single,
 293   # proper and existing SPEC is included.
 294   ##############################################################################
 295 
 296   include $(TOPDIR)/make/common/MakeBase.gmk
 297 
 298   # Define basic logging setup
 299   BUILD_LOG := $(OUTPUTDIR)/build.log
 300   BUILD_PROFILE_LOG := $(OUTPUTDIR)/build-profile.log
 301 
 302   BUILD_LOG_PIPE := > >($(TEE) -a $(BUILD_LOG)) 2> >($(TEE) -a $(BUILD_LOG) >&2) && wait



 303 
 304   ifneq ($(CUSTOM_ROOT), )
 305     topdir=$(CUSTOM_ROOT)
 306   else
 307     topdir=$(TOPDIR)
 308   endif
 309 
 310   # Parse COMPARE_BUILD into COMPARE_BUILD_*
 311   # Syntax: COMPARE_BUILD=CONF=<configure options>:PATCH=<patch file>:
 312   #         MAKE=<make targets>:COMP_OPTS=<compare script options>:
 313   #         COMP_DIR=<compare script base dir>|<default>:
 314   #         FAIL=<bool>
 315   # If neither CONF or PATCH is given, assume <default> means CONF if it
 316   # begins with "--", otherwise assume it means PATCH.
 317   # MAKE and COMP_OPTS can only be used with CONF and/or PATCH specified.
 318   # If any value contains "+", it will be replaced by space.
 319   # FAIL can be set to false to have the return value of compare be ignored.
 320   define ParseCompareBuild
 321     ifneq ($$(COMPARE_BUILD), )
 322       COMPARE_BUILD_OUTPUTDIR := $(topdir)/build/compare-build/$(CONF_NAME)


 371     endif
 372   endef
 373 
 374   # Prepare for a comparison rebuild
 375   define PrepareCompareBuild
 376         $(ECHO) "Preparing for comparison rebuild"
 377         # Apply patch, if any
 378         $(if $(COMPARE_BUILD_PATCH), cd $(topdir) && $(PATCH) -p1 < $(COMPARE_BUILD_PATCH))
 379         # Move the first build away temporarily
 380         $(RM) -r $(topdir)/build/.compare-build-temp
 381         $(MKDIR) -p $(topdir)/build/.compare-build-temp
 382         $(MV) $(OUTPUTDIR) $(topdir)/build/.compare-build-temp
 383         # Restore an old compare-build, or create a new compare-build directory.
 384         if test -d $(COMPARE_BUILD_OUTPUTDIR); then \
 385           $(MV) $(COMPARE_BUILD_OUTPUTDIR) $(OUTPUTDIR); \
 386         else \
 387           $(MKDIR) -p $(OUTPUTDIR); \
 388         fi
 389         # Re-run configure with the same arguments (and possibly some additional),
 390         # must be done after patching.
 391         ( cd $(OUTPUTDIR) && PATH="$(ORIGINAL_PATH)" \
 392             $(BASH) $(topdir)/configure $(CONFIGURE_COMMAND_LINE) $(COMPARE_BUILD_CONF))
 393   endef
 394 
 395   # Cleanup after a compare build
 396   define CleanupCompareBuild
 397         # If running with a COMPARE_BUILD patch, reverse-apply it
 398         $(if $(COMPARE_BUILD_PATCH), cd $(topdir) && $(PATCH) -R -p1 < $(COMPARE_BUILD_PATCH))
 399         # Move this build away and restore the original build
 400         $(MKDIR) -p $(topdir)/build/compare-build
 401         $(MV) $(OUTPUTDIR) $(COMPARE_BUILD_OUTPUTDIR)
 402         $(MV) $(topdir)/build/.compare-build-temp/$(CONF_NAME) $(OUTPUTDIR)
 403         $(RM) -r $(topdir)/build/.compare-build-temp
 404   endef
 405 
 406   # Do the actual comparison of two builds
 407   define CompareBuildDoComparison
 408         # Compare first and second build. Ignore any error code from compare.sh.
 409         $(ECHO) "Comparing between comparison rebuild (this/new) and baseline (other/old)"
 410         $(if $(COMPARE_BUILD_COMP_DIR), \
 411           +(cd $(COMPARE_BUILD_OUTPUTDIR) && ./compare.sh $(COMPARE_BUILD_COMP_OPTS) \


 466   define PrepareFailureLogs
 467         $(RM) -r $(MAKESUPPORT_OUTPUTDIR)/failure-logs 2> /dev/null && \
 468         $(MKDIR) -p $(MAKESUPPORT_OUTPUTDIR)/failure-logs
 469         $(RM) $(MAKESUPPORT_OUTPUTDIR)/exit-with-error 2> /dev/null
 470   endef
 471 
 472   # Remove any javac server logs and port files. This
 473   # prevents a new make run to reuse the previous servers.
 474   define PrepareSmartJavac
 475         $(if $(SJAVAC_SERVER_DIR), \
 476           $(RM) -r $(SJAVAC_SERVER_DIR) 2> /dev/null && \
 477           $(MKDIR) -p $(SJAVAC_SERVER_DIR) \
 478         )
 479   endef
 480 
 481   define CleanupSmartJavac
 482         [ -f $(SJAVAC_SERVER_DIR)/server.port ] && $(ECHO) Stopping sjavac server && \
 483             $(TOUCH) $(SJAVAC_SERVER_DIR)/server.port.stop; true
 484   endef
 485 
 486   ifeq ($(OPENJDK_BUILD_OS), windows)
 487     # On windows we need to synchronize with the javac server to be able to
 488     # move or remove the build output directory. Since we have no proper
 489     # synchronization process, wait for a while and hope it helps. This is only
 490     # used by build comparisons.
 491     define WaitForSmartJavacFinish
 492         $(if $(SJAVAC_SERVER_DIR), \
 493           sleep 5\
 494         )
 495     endef
 496   else
 497     define WaitForSmartJavacFinish
 498     endef
 499   endif
 500 
 501   define StartGlobalTimer
 502         $(RM) -r $(BUILDTIMESDIR) 2> /dev/null && \
 503         $(MKDIR) -p $(BUILDTIMESDIR) && \
 504         $(call RecordStartTime,TOTAL)
 505   endef
 506 
 507   define StopGlobalTimer
 508         $(call RecordEndTime,TOTAL)
 509   endef
 510 
 511   # Find all build_time_* files and print their contents in a list sorted
 512   # on the name of the sub repository.
 513   define ReportBuildTimes
 514         $(PRINTF) $(LOG_INFO) -- \
 515             "----- Build times -------\nStart %s\nEnd   %s\n%s\n%s\n-------------------------\n" \
 516             "`$(CAT) $(BUILDTIMESDIR)/build_time_start_TOTAL_human_readable`" \
 517             "`$(CAT) $(BUILDTIMESDIR)/build_time_end_TOTAL_human_readable`" \
 518             "`$(LS) $(BUILDTIMESDIR)/build_time_diff_* | $(GREP) -v _TOTAL | \
 519             $(XARGS) $(CAT) | $(SORT) -k 2`" \
 520             "`$(CAT) $(BUILDTIMESDIR)/build_time_diff_TOTAL`" \
 521             $(BUILD_LOG_PIPE)
 522   endef
 523 
 524   define ReportProfileTimes
 525     $(if $(findstring true, $(LOG_PROFILE_TIMES_LOG)), \
 526       [ ! -f $(BUILD_PROFILE_LOG) ] || \
 527       { $(ECHO) Begin $(notdir $(BUILD_PROFILE_LOG)) && \
 528         $(CAT) $(BUILD_PROFILE_LOG) && \
 529         $(ECHO) End $(notdir $(BUILD_PROFILE_LOG)); \
 530       } \
 531       $(BUILD_LOG_PIPE)
 532     )
 533   endef
 534 
 535 endif # HAS_SPEC
 536 
 537 # Look for a given option in the LOG variable, and if found, set a variable
 538 # and remove the option from the LOG variable
 539 # $1: The option to look for
 540 # $2: The variable to set to "true" if the option is found
 541 define ParseLogOption
 542   ifneq ($$(findstring $1, $$(LOG)),)
 543     override $2 := true
 544     # First try to remove ",<option>" if it exists, otherwise just remove "<option>"
 545     LOG_STRIPPED := $$(subst $1,, $$(subst $$(COMMA)$$(strip $1),, $$(LOG)))
 546     # We might have ended up with a leading comma. Remove it. Need override
 547     # since LOG is set from the command line.
 548     override LOG := $$(strip $$(patsubst $$(COMMA)%, %, $$(LOG_STRIPPED)))
 549   endif
 550 endef
 551 


< prev index next >