diff --git a/make/Bundles.gmk b/make/Bundles.gmk index 33d51d3f613..0901e415a8a 100644 --- a/make/Bundles.gmk +++ b/make/Bundles.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -28,6 +28,9 @@ default: all include $(SPEC) include MakeBase.gmk +include CopyFiles.gmk +include MakeIO.gmk + PRODUCT_TARGETS := LEGACY_TARGETS := TEST_TARGETS := diff --git a/make/CompileDemos.gmk b/make/CompileDemos.gmk index 3aee428602d..9339250c4fb 100644 --- a/make/CompileDemos.gmk +++ b/make/CompileDemos.gmk @@ -31,6 +31,8 @@ default: all include $(SPEC) include MakeBase.gmk + +include CopyFiles.gmk include JavaCompilation.gmk include TextFileProcessing.gmk include ZipArchive.gmk diff --git a/make/CompileInterimLangtools.gmk b/make/CompileInterimLangtools.gmk index 990ec06aca2..1a8b6382f81 100644 --- a/make/CompileInterimLangtools.gmk +++ b/make/CompileInterimLangtools.gmk @@ -28,6 +28,8 @@ default: all include $(SPEC) include MakeBase.gmk + +include CopyFiles.gmk include JavaCompilation.gmk include Modules.gmk diff --git a/make/CompileToolsJdk.gmk b/make/CompileToolsJdk.gmk index 13101c7cccf..50ffe73a096 100644 --- a/make/CompileToolsJdk.gmk +++ b/make/CompileToolsJdk.gmk @@ -27,6 +27,8 @@ default: all include $(SPEC) include MakeBase.gmk + +include CopyFiles.gmk include JavaCompilation.gmk include TextFileProcessing.gmk diff --git a/make/CopyImportModules.gmk b/make/CopyImportModules.gmk index 34baaf9d37b..52515ebd314 100644 --- a/make/CopyImportModules.gmk +++ b/make/CopyImportModules.gmk @@ -31,6 +31,8 @@ default: all include $(SPEC) include MakeBase.gmk +include CopyFiles.gmk + LIBS_DIR := $(wildcard $(addsuffix /$(MODULE), $(IMPORT_MODULES_LIBS))) CMDS_DIR := $(wildcard $(addsuffix /$(MODULE), $(IMPORT_MODULES_CMDS))) CONF_DIR := $(wildcard $(addsuffix /$(MODULE), $(IMPORT_MODULES_CONF))) diff --git a/make/CopyInterimTZDB.gmk b/make/CopyInterimTZDB.gmk index 6ce41865e2c..ac390580aa9 100644 --- a/make/CopyInterimTZDB.gmk +++ b/make/CopyInterimTZDB.gmk @@ -28,6 +28,8 @@ default: all include $(SPEC) include MakeBase.gmk +include CopyFiles.gmk + ########################################################################################## ### TZDB tool needs files from java.time.zone package diff --git a/make/CreateJmods.gmk b/make/CreateJmods.gmk index d1e83c8c8e0..fd36554358b 100644 --- a/make/CreateJmods.gmk +++ b/make/CreateJmods.gmk @@ -27,6 +27,8 @@ default: all include $(SPEC) include MakeBase.gmk + +include CopyFiles.gmk include Execute.gmk include Modules.gmk diff --git a/make/Docs.gmk b/make/Docs.gmk index d0c01f0283d..2977f6f66f9 100644 --- a/make/Docs.gmk +++ b/make/Docs.gmk @@ -26,6 +26,8 @@ default: all include $(SPEC) include MakeBase.gmk + +include CopyFiles.gmk include Execute.gmk include Modules.gmk include ModuleTools.gmk diff --git a/make/GenerateLinkOptData.gmk b/make/GenerateLinkOptData.gmk index 5dd766c8c07..e7d6962fb79 100644 --- a/make/GenerateLinkOptData.gmk +++ b/make/GenerateLinkOptData.gmk @@ -31,6 +31,8 @@ default: all include $(SPEC) include MakeBase.gmk + +include CopyFiles.gmk include JavaCompilation.gmk ################################################################################ diff --git a/make/GraalBuilderImage.gmk b/make/GraalBuilderImage.gmk index 8c4d66aa9d5..7fa90c66019 100644 --- a/make/GraalBuilderImage.gmk +++ b/make/GraalBuilderImage.gmk @@ -31,6 +31,8 @@ default: all include $(SPEC) include MakeBase.gmk +include CopyFiles.gmk + ################################################################################ TARGETS := diff --git a/make/Images.gmk b/make/Images.gmk index 3048eb3eda9..bfad1ad563c 100644 --- a/make/Images.gmk +++ b/make/Images.gmk @@ -27,6 +27,8 @@ default: all include $(SPEC) include MakeBase.gmk + +include CopyFiles.gmk include Execute.gmk include Modules.gmk include Utils.gmk diff --git a/make/InitSupport.gmk b/make/InitSupport.gmk index 2bdab7f907d..c59e685bf4f 100644 --- a/make/InitSupport.gmk +++ b/make/InitSupport.gmk @@ -536,6 +536,31 @@ else # $(HAS_SPEC)=true endef endif + ############################################################################## + # Functions for timers + ############################################################################## + + # Store the build times in this directory. + BUILDTIMESDIR=$(OUTPUTDIR)/make-support/build-times + + # Record starting time for build of a sub repository. + define RecordStartTime + $(DATE) '+%Y %m %d %H %M %S' | $(AWK) '{ print $$1,$$2,$$3,$$4,$$5,$$6,($$4*3600+$$5*60+$$6) }' > $(BUILDTIMESDIR)/build_time_start_$(strip $1) && \ + $(DATE) '+%Y-%m-%d %H:%M:%S' > $(BUILDTIMESDIR)/build_time_start_$(strip $1)_human_readable + endef + + # Record ending time and calculate the difference and store it in a + # easy to read format. Handles builds that cross midnight. Expects + # that a build will never take 24 hours or more. + define RecordEndTime + $(DATE) '+%Y %m %d %H %M %S' | $(AWK) '{ print $$1,$$2,$$3,$$4,$$5,$$6,($$4*3600+$$5*60+$$6) }' > $(BUILDTIMESDIR)/build_time_end_$(strip $1) + $(DATE) '+%Y-%m-%d %H:%M:%S' > $(BUILDTIMESDIR)/build_time_end_$(strip $1)_human_readable + $(ECHO) `$(CAT) $(BUILDTIMESDIR)/build_time_start_$(strip $1)` `$(CAT) $(BUILDTIMESDIR)/build_time_end_$(strip $1)` $1 | \ + $(AWK) '{ F=$$7; T=$$14; if (F > T) { T+=3600*24 }; D=T-F; H=int(D/3600); \ + M=int((D-H*3600)/60); S=D-H*3600-M*60; printf("%02d:%02d:%02d %s\n",H,M,S,$$15); }' \ + > $(BUILDTIMESDIR)/build_time_diff_$(strip $1) + endef + define StartGlobalTimer $(RM) -r $(BUILDTIMESDIR) 2> /dev/null && \ $(MKDIR) -p $(BUILDTIMESDIR) && \ diff --git a/make/JrtfsJar.gmk b/make/JrtfsJar.gmk index b0b7ed6ce08..990c8a7e1ed 100644 --- a/make/JrtfsJar.gmk +++ b/make/JrtfsJar.gmk @@ -27,6 +27,8 @@ default: all include $(SPEC) include MakeBase.gmk + +include CopyFiles.gmk include JavaCompilation.gmk include JarArchive.gmk include TextFileProcessing.gmk diff --git a/make/MacBundles.gmk b/make/MacBundles.gmk index 39da6c9cdb3..8ed6476c506 100644 --- a/make/MacBundles.gmk +++ b/make/MacBundles.gmk @@ -25,6 +25,8 @@ include $(SPEC) include MakeBase.gmk + +include CopyFiles.gmk include TextFileProcessing.gmk default: bundles diff --git a/make/ModuleWrapper.gmk b/make/ModuleWrapper.gmk index d83af819a9b..14298d25a53 100644 --- a/make/ModuleWrapper.gmk +++ b/make/ModuleWrapper.gmk @@ -35,6 +35,8 @@ default: all include $(SPEC) include MakeBase.gmk +include CopyFiles.gmk + MODULE_SRC := $(TOPDIR)/src/$(MODULE) # All makefiles should add the targets to be built to this variable. diff --git a/make/SourceRevision.gmk b/make/SourceRevision.gmk index 9a47ae456e2..63bbe5b62fb 100644 --- a/make/SourceRevision.gmk +++ b/make/SourceRevision.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -41,6 +41,16 @@ $(eval $(call IncludeCustomExtension, SourceRevision-pre.gmk)) STORED_SOURCE_REVISION := $(TOPDIR)/.src-rev +# Locate all sourcecode repositories included in the forest, as absolute paths +FindAllReposAbs = \ + $(strip $(sort $(dir $(filter-out $(TOPDIR)/build/%, $(wildcard \ + $(addprefix $(TOPDIR)/, .git */.git */*/.git */*/*/.git */*/*/*/.git) \ + ))))) + +# Locate all sourcecode repositories included in the forest, as relative paths +FindAllReposRel = \ + $(strip $(subst $(TOPDIR)/,.,$(patsubst $(TOPDIR)/%/, %, $(FindAllReposAbs)))) + USE_SCM := false ifneq ($(and $(GIT), $(wildcard $(TOPDIR)/.git)), ) USE_SCM := true diff --git a/make/StaticLibsImage.gmk b/make/StaticLibsImage.gmk index 44a4ba56782..84e97b13b29 100644 --- a/make/StaticLibsImage.gmk +++ b/make/StaticLibsImage.gmk @@ -30,6 +30,8 @@ default: all include $(SPEC) include MakeBase.gmk + +include CopyFiles.gmk include Modules.gmk ALL_MODULES = $(call FindAllModules) diff --git a/make/autoconf/spec.gmk.template b/make/autoconf/spec.gmk.template index e90d9aabf04..2f2525a662a 100644 --- a/make/autoconf/spec.gmk.template +++ b/make/autoconf/spec.gmk.template @@ -677,6 +677,10 @@ BUILD_JAR = @FIXPATH@ $(BUILD_JDK)/bin/jar DOCS_REFERENCE_JAVADOC := @DOCS_REFERENCE_JAVADOC@ +# A file containing a way to uniquely identify the source code revision that +# the build was created from +SOURCE_REVISION_TRACKER := $(SUPPORT_OUTPUTDIR)/src-rev/source-revision-tracker + # Interim langtools modules and arguments INTERIM_LANGTOOLS_BASE_MODULES := java.compiler jdk.compiler jdk.javadoc INTERIM_LANGTOOLS_MODULES := $(addsuffix .interim, $(INTERIM_LANGTOOLS_BASE_MODULES)) diff --git a/make/common/FileUtils.gmk b/make/common/FileUtils.gmk new file mode 100644 index 00000000000..114f3adefbe --- /dev/null +++ b/make/common/FileUtils.gmk @@ -0,0 +1,303 @@ +# +# Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved. +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# This code is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 2 only, as +# published by the Free Software Foundation. Oracle designates this +# particular file as subject to the "Classpath" exception as provided +# by Oracle in the LICENSE file that accompanied this code. +# +# This code is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# version 2 for more details (a copy is included in the LICENSE file that +# accompanied this code). +# +# You should have received a copy of the GNU General Public License version +# 2 along with this work; if not, write to the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA +# or visit www.oracle.com if you need additional information or have any +# questions. +# + +ifeq (,$(_MAKEBASE_GMK)) + $(error You must include MakeBase.gmk prior to including FileUtils.gmk) +endif + +################################################################################ +# +# Common file utility functions +# +################################################################################ + +################################################################################ +# Replace question marks with space in string. This macro needs to be called on +# files from FindFiles in case any of them contains space in their file name, +# since FindFiles replaces space with ?. +# Param 1 - String to replace in +DecodeSpace = \ + $(subst ?,$(SPACE),$(strip $1)) + +EncodeSpace = \ + $(subst $(SPACE),?,$(strip $1)) + +################################################################################ +# Take two paths and return the path of the last common directory. +# Ex: /foo/bar/baz, /foo/bar/banan -> /foo/bar +# foo/bar/baz, /foo/bar -> +# +# The x prefix is used to preserve the presence of the initial slash +# On Windows paths are treated as case-insensitive +# +# $1 - Path to compare +# $2 - Other path to compare +FindCommonPathPrefix = \ + $(call DecodeSpace,$(patsubst x%,%,$(subst $(SPACE),/,$(strip \ + $(call FindCommonPathPrefixHelper1, \ + $(subst /,$(SPACE),x$(call EncodeSpace,$(strip $1))), \ + $(subst /,$(SPACE),x$(call EncodeSpace,$(strip $2)))) \ + )))) + +FindCommonPathPrefixHelper1 = \ + $(if $(filter $(OPENJDK_TARGET_OS), windows), \ + $(call FindCommonPathPrefixHelper2,$(call uppercase,$1),$(call uppercase,$2),$1), \ + $(call FindCommonPathPrefixHelper2,$1,$2,$1)) + +FindCommonPathPrefixHelper2 = \ + $(if $(call equals, $(firstword $1), $(firstword $2)), \ + $(if $(call equals, $(firstword $1),),, \ + $(firstword $3) \ + $(call FindCommonPathPrefixHelper2, \ + $(wordlist 2, $(words $1), $1), \ + $(wordlist 2, $(words $2), $2), \ + $(wordlist 2, $(words $3), $3) \ + ) \ + ) \ + ) + +# Computes the relative path from a directory to a file +# $1 - File to compute the relative path to +# $2 - Directory to compute the relative path from +RelativePath = \ + $(call DecodeSpace,$(strip $(call RelativePathHelper,$(call EncodeSpace \ + ,$(strip $1)),$(call EncodeSpace \ + ,$(strip $2)),$(call EncodeSpace \ + ,$(call FindCommonPathPrefix,$1,$2))))) + +RelativePathHelper = \ + $(eval $3_prefix_length := $(words $(subst /,$(SPACE),$3))) \ + $(eval $1_words := $(subst /,$(SPACE),$1)) \ + $(eval $2_words := $(subst /,$(SPACE),$2)) \ + $(if $(call equals,$($3_prefix_length),0),, \ + $(eval $1_words := $(wordlist 2,$(words $($1_words)),$(wordlist \ + $($3_prefix_length),$(words $($1_words)),$($1_words)))) \ + $(eval $2_words := $(wordlist 2,$(words $($2_words)),$(wordlist \ + $($3_prefix_length),$(words $($2_words)),$($2_words)))) \ + ) \ + $(eval $1_suffix := $(subst $(SPACE),/,$($1_words))) \ + $(eval $2_dotdots := $(subst $(SPACE),/,$(foreach d,$($2_words),..))) \ + $(if $($1_suffix), \ + $(if $($2_dotdots), $($2_dotdots)/$($1_suffix), $($1_suffix)), \ + $(if $($2_dotdots), $($2_dotdots), .)) + +# Make directory for target file. Should handle spaces in filenames. Just +# calling $(call MakeDir $(@D)) will not work if the directory contains a space +# and the target file already exists. In that case, the target file will have +# its wildcard ? resolved and the $(@D) will evaluate each space separated dir +# part on its own. +MakeTargetDir = \ + $(call MakeDir, $(dir $(call EncodeSpace, $@))) + +################################################################################ +# All install-file and related macros automatically call DecodeSpace when needed. + +ifeq ($(call isTargetOs, macosx), true) + # On mac, extended attributes sometimes creep into the source files, which may later + # cause the creation of ._* files which confuses testing. Clear these with xattr if + # set. Some files get their write permissions removed after being copied to the + # output dir. When these are copied again to images, xattr would fail. By only clearing + # attributes when they are present, failing on this is avoided. + # + # If copying a soft link to a directory, need to delete the target first to avoid + # weird errors. + define install-file + $(call MakeTargetDir) + $(RM) '$(call DecodeSpace, $@)' + # Work around a weirdness with cp on Macosx. When copying a symlink, if + # the target of the link is write protected (e.g. 444), cp will add + # write permission for the user on the target file (644). Avoid this by + # using ln to create a new link instead. + if [ -h '$(call DecodeSpace, $<)' ]; then \ + $(LN) -s "`$(READLINK) '$(call DecodeSpace, $<)'`" '$(call DecodeSpace, $@)'; \ + else \ + $(CP) -fRP '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)'; \ + fi + if [ -n "`$(XATTR) -ls '$(call DecodeSpace, $@)'`" ]; then \ + $(XATTR) -cs '$(call DecodeSpace, $@)'; \ + fi + endef +else + define install-file + $(call MakeTargetDir) + $(CP) -fP '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)' + endef +endif + +# Variant of install file that does not preserve symlinks +define install-file-nolink + $(call MakeTargetDir) + $(CP) -f '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)' +endef + +################################################################################ +# link-file-* works similarly to install-file but creates a symlink instead. +# There are two versions, either creating a relative or an absolute link. Be +# careful when using this on Windows since the symlink created is only valid in +# the unix emulation environment. +# In msys2 we use mklink /J because its ln would perform a deep copy of the target. +# This inhibits performance and can lead to issues with long paths. With mklink /J +# relative linking does not work, so we handle the link as absolute path. +ifeq ($(OPENJDK_BUILD_OS_ENV), windows.msys2) + define link-file-relative + $(call MakeTargetDir) + $(RM) '$(call DecodeSpace, $@)' + cmd //c "mklink /J $(call FixPath, $(call DecodeSpace, $@)) $(call FixPath, $(call DecodeSpace, $<))" + endef +else + define link-file-relative + $(call MakeTargetDir) + $(RM) '$(call DecodeSpace, $@)' + $(LN) -s '$(call DecodeSpace, $(call RelativePath, $<, $(@D)))' '$(call DecodeSpace, $@)' + endef +endif + +ifeq ($(OPENJDK_BUILD_OS_ENV), windows.msys2) + define link-file-absolute + $(call MakeTargetDir) + $(RM) '$(call DecodeSpace, $@)' + cmd //c "mklink /J $(call FixPath, $(call DecodeSpace, $@)) $(call FixPath, $(call DecodeSpace, $<))" + endef +else + define link-file-absolute + $(call MakeTargetDir) + $(RM) '$(call DecodeSpace, $@)' + $(LN) -s '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)' + endef +endif + +################################################################################ + +# Recursive wildcard function. Walks down directories recursively and matches +# files with the search patterns. Patterns use standard file wildcards (* and +# ?). +# +# $1 - Directories to start search in +# $2 - Search patterns +rwildcard = \ + $(strip \ + $(foreach d, \ + $(patsubst %/,%,$(sort $(dir $(wildcard $(addsuffix /*/*, $(strip $1)))))), \ + $(call rwildcard,$d,$2) \ + ) \ + $(call DoubleDollar, $(wildcard $(foreach p, $2, $(addsuffix /$(strip $p), $(strip $1))))) \ + ) + +# Find non directories using recursive wildcard function. This function may +# be used directly when a small amount of directories is expected to be +# searched and caching is not expected to be of use. +# +# $1 - Directory to start search in +# $2 - Optional search patterns, defaults to '*'. +WildcardFindFiles = \ + $(sort $(strip \ + $(eval WildcardFindFiles_result := $(call rwildcard,$(patsubst %/,%,$1),$(if $(strip $2),$2,*))) \ + $(filter-out $(patsubst %/,%,$(sort $(dir $(WildcardFindFiles_result)))), \ + $(WildcardFindFiles_result) \ + ) \ + )) + +# Find non directories using the find utility in the shell. Safe to call for +# non existing directories, or directories containing wildcards. +# +# Files containing space will get spaces replaced with ? because GNU Make +# cannot handle lists of files with space in them. By using ?, make will match +# the wildcard to space in many situations so we don't need to replace back +# to space on every use. While not a complete solution it does allow some uses +# of FindFiles to function with spaces in file names, including for +# SetupCopyFiles. Unfortunately this does not work for WildcardFindFiles so +# if files with spaces are anticipated, use ShellFindFiles directly. +# +# $1 - Directories to start search in. +# $2 - Optional search patterns, empty means find everything. Patterns use +# standard file wildcards (* and ?) and should not be quoted. +# $3 - Optional options to find. +ShellFindFiles = \ + $(if $(wildcard $1), \ + $(sort \ + $(shell $(FIND) $3 $(patsubst %/,%,$(wildcard $1)) \( -type f -o -type l \) \ + $(if $(strip $2), -a \( -name "$(firstword $2)" \ + $(foreach p, $(filter-out $(firstword $2), $2), -o -name "$(p)") \)) \ + | $(TR) ' ' '?' \ + ) \ + ) \ + ) + +# Find non directories using the method most likely to work best for the +# current build host +# +# $1 - Directory to start search in +# $2 - Optional search patterns, defaults to '*'. +ifeq ($(OPENJDK_BUILD_OS)-$(RWILDCARD_WORKS), windows-true) + DirectFindFiles = $(WildcardFindFiles) +else + DirectFindFiles = $(ShellFindFiles) +endif + +# Finds files using a cache that is populated by FillFindCache below. If any of +# the directories given have not been cached, DirectFindFiles is used for +# everything. Caching is especially useful in Cygwin, where file finds are very +# costly. +# +# $1 - Directories to start search in. +# $2 - Optional search patterns. If used, no caching is done. +CacheFindFiles_CACHED_DIRS := +CacheFindFiles_CACHED_FILES := +CacheFindFiles = \ + $(if $2, \ + $(call DirectFindFiles, $1, $2) \ + , \ + $(if $(filter-out $(addsuffix /%, $(CacheFindFiles_CACHED_DIRS)) \ + $(CacheFindFiles_CACHED_DIRS), $1), \ + $(call DirectFindFiles, $1) \ + , \ + $(filter $(addsuffix /%,$(patsubst %/,%,$1)) $1,$(CacheFindFiles_CACHED_FILES)) \ + ) \ + ) + +# Explicitly adds files to the find cache used by CacheFindFiles. +# +# $1 - Directories to start search in +FillFindCache = \ + $(eval CacheFindFiles_NEW_DIRS := $$(filter-out $$(addsuffix /%,\ + $$(CacheFindFiles_CACHED_DIRS)) $$(CacheFindFiles_CACHED_DIRS), $1)) \ + $(if $(CacheFindFiles_NEW_DIRS), \ + $(eval CacheFindFiles_CACHED_DIRS += $$(patsubst %/,%,$$(CacheFindFiles_NEW_DIRS))) \ + $(eval CacheFindFiles_CACHED_FILES := $$(sort $$(CacheFindFiles_CACHED_FILES) \ + $$(call DirectFindFiles, $$(CacheFindFiles_NEW_DIRS)))) \ + ) + +# Findfiles is the default macro that should be used to find files in the file +# system. This function does not always support files with spaces in the names. +# If files with spaces are anticipated, use ShellFindFiles directly. +# +# $1 - Directories to start search in. +# $2 - Optional search patterns, empty means find everything. Patterns use +# standard file wildcards (* and ?) and should not be quoted. +ifeq ($(DISABLE_CACHE_FIND), true) + FindFiles = $(DirectFindFiles) +else + FindFiles = $(CacheFindFiles) +endif diff --git a/make/common/JarArchive.gmk b/make/common/JarArchive.gmk index 684736cb289..25b42186666 100644 --- a/make/common/JarArchive.gmk +++ b/make/common/JarArchive.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -30,6 +30,8 @@ ifeq (,$(_MAKEBASE_GMK)) $(error You must include MakeBase.gmk prior to including JarArchive.gmk) endif +include MakeIO.gmk + FALSE_FIND_PATTERN:=-name FILE_NAME_THAT_DOESNT_EXIST # Setup make rules for creating a jar archive. diff --git a/make/common/JavaCompilation.gmk b/make/common/JavaCompilation.gmk index ff7c90e5785..259c1834da3 100644 --- a/make/common/JavaCompilation.gmk +++ b/make/common/JavaCompilation.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -30,6 +30,8 @@ ifeq (,$(_MAKEBASE_GMK)) $(error You must include MakeBase.gmk prior to including JavaCompilation.gmk) endif +include MakeIO.gmk + # Java compilation needs SetupJarArchive and/or SetupZipArchive, if we're # generating a jar file or a source zip. include JarArchive.gmk diff --git a/make/common/MakeBase.gmk b/make/common/MakeBase.gmk index 3858b652ee6..5af1967e54b 100644 --- a/make/common/MakeBase.gmk +++ b/make/common/MakeBase.gmk @@ -24,9 +24,10 @@ # ################################################################ -# -# Setup common utility functions. -# +# MakeBase provides the core functionality needed and used by all makefiles. It +# should be included by all makefiles. MakeBase provides essential +# functionality for named parameter functions, variable dependency, tool +# execution, logging and fixpath functionality. ################################################################ ifndef _MAKEBASE_GMK @@ -64,9 +65,6 @@ define NEWLINE endef -# Make sure we have a value (could be overridden on command line by caller) -CREATING_BUILDJDK ?= false - # Certain features only work in newer version of GNU Make. The build will still # function in 3.81, but will be less performant. ifeq (4.0, $(firstword $(sort 4.0 $(MAKE_VERSION)))) @@ -75,67 +73,16 @@ ifeq (4.0, $(firstword $(sort 4.0 $(MAKE_VERSION)))) RWILDCARD_WORKS := true endif - # For convenience, MakeBase.gmk continues to include these separate files, at # least for now. - +# Utils.gmk must be included before FileUtils.gmk, since it uses some of the +# basic utility functions there. include $(TOPDIR)/make/common/Utils.gmk -include $(TOPDIR)/make/common/MakeIO.gmk -include $(TOPDIR)/make/common/CopyFiles.gmk +include $(TOPDIR)/make/common/FileUtils.gmk ################################################################################ -# Functions for timers -################################################################################ - -# Store the build times in this directory. -BUILDTIMESDIR=$(OUTPUTDIR)/make-support/build-times - -# Record starting time for build of a sub repository. -define RecordStartTime - $(DATE) '+%Y %m %d %H %M %S' | $(AWK) '{ print $$1,$$2,$$3,$$4,$$5,$$6,($$4*3600+$$5*60+$$6) }' > $(BUILDTIMESDIR)/build_time_start_$(strip $1) && \ - $(DATE) '+%Y-%m-%d %H:%M:%S' > $(BUILDTIMESDIR)/build_time_start_$(strip $1)_human_readable -endef - -# Record ending time and calculate the difference and store it in a -# easy to read format. Handles builds that cross midnight. Expects -# that a build will never take 24 hours or more. -define RecordEndTime - $(DATE) '+%Y %m %d %H %M %S' | $(AWK) '{ print $$1,$$2,$$3,$$4,$$5,$$6,($$4*3600+$$5*60+$$6) }' > $(BUILDTIMESDIR)/build_time_end_$(strip $1) - $(DATE) '+%Y-%m-%d %H:%M:%S' > $(BUILDTIMESDIR)/build_time_end_$(strip $1)_human_readable - $(ECHO) `$(CAT) $(BUILDTIMESDIR)/build_time_start_$(strip $1)` `$(CAT) $(BUILDTIMESDIR)/build_time_end_$(strip $1)` $1 | \ - $(AWK) '{ F=$$7; T=$$14; if (F > T) { T+=3600*24 }; D=T-F; H=int(D/3600); \ - M=int((D-H*3600)/60); S=D-H*3600-M*60; printf("%02d:%02d:%02d %s\n",H,M,S,$$15); }' \ - > $(BUILDTIMESDIR)/build_time_diff_$(strip $1) -endef - -# Hook to be called when starting to execute a top-level target -define TargetEnter - $(PRINTF) "## Starting $(patsubst %-only,%,$@)\n" - $(call RecordStartTime,$(patsubst %-only,%,$@)) -endef - -# Hook to be called when finish executing a top-level target -define TargetExit - $(call RecordEndTime,$(patsubst %-only,%,$@)) - $(PRINTF) "## Finished $(patsubst %-only,%,$@) (build time %s)\n\n" \ - "`$(CAT) $(BUILDTIMESDIR)/build_time_diff_$(patsubst %-only,%,$@) | $(CUT) -f 1 -d ' '`" -endef - -################################################################################ - -# A file containing a way to uniquely identify the source code revision that -# the build was created from -SOURCE_REVISION_TRACKER := $(SUPPORT_OUTPUTDIR)/src-rev/source-revision-tracker - -# Locate all sourcecode repositories included in the forest, as absolute paths -FindAllReposAbs = \ - $(strip $(sort $(dir $(filter-out $(TOPDIR)/build/%, $(wildcard \ - $(addprefix $(TOPDIR)/, .git */.git */*/.git */*/*/.git */*/*/*/.git) \ - ))))) - -# Locate all sourcecode repositories included in the forest, as relative paths -FindAllReposRel = \ - $(strip $(subst $(TOPDIR)/,.,$(patsubst $(TOPDIR)/%/, %, $(FindAllReposAbs)))) +# Make sure we have a value (could be overridden on command line by caller) +CREATING_BUILDJDK ?= false ################################################################################ @@ -237,224 +184,6 @@ define NamedParamsMacroTemplate $(call $(0)Body,$(strip $1)) endef -################################################################################ -# Make directory without forking mkdir if not needed. -# -# If a directory with an encoded space is provided, the wildcard function -# sometimes returns false answers (typically if the dir existed when the -# makefile was parsed, but was deleted by a previous rule). In that case, always -# call mkdir regardless of what wildcard says. -# -# 1: List of directories to create -MakeDir = \ - $(strip \ - $(eval MakeDir_dirs_to_make := $(strip $(foreach d, $1, \ - $(if $(findstring ?, $d), '$(call DecodeSpace, $d)', \ - $(if $(wildcard $d), , $d) \ - ) \ - ))) \ - $(if $(MakeDir_dirs_to_make), $(shell $(MKDIR) -p $(MakeDir_dirs_to_make))) \ - ) - -# Make directory for target file. Should handle spaces in filenames. Just -# calling $(call MakeDir $(@D)) will not work if the directory contains a space -# and the target file already exists. In that case, the target file will have -# its wildcard ? resolved and the $(@D) will evaluate each space separated dir -# part on its own. -MakeTargetDir = \ - $(call MakeDir, $(dir $(call EncodeSpace, $@))) - -################################################################################ -# All install-file and related macros automatically call DecodeSpace when needed. - -ifeq ($(call isTargetOs, macosx), true) - # On mac, extended attributes sometimes creep into the source files, which may later - # cause the creation of ._* files which confuses testing. Clear these with xattr if - # set. Some files get their write permissions removed after being copied to the - # output dir. When these are copied again to images, xattr would fail. By only clearing - # attributes when they are present, failing on this is avoided. - # - # If copying a soft link to a directory, need to delete the target first to avoid - # weird errors. - define install-file - $(call MakeTargetDir) - $(RM) '$(call DecodeSpace, $@)' - # Work around a weirdness with cp on Macosx. When copying a symlink, if - # the target of the link is write protected (e.g. 444), cp will add - # write permission for the user on the target file (644). Avoid this by - # using ln to create a new link instead. - if [ -h '$(call DecodeSpace, $<)' ]; then \ - $(LN) -s "`$(READLINK) '$(call DecodeSpace, $<)'`" '$(call DecodeSpace, $@)'; \ - else \ - $(CP) -fRP '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)'; \ - fi - if [ -n "`$(XATTR) -ls '$(call DecodeSpace, $@)'`" ]; then \ - $(XATTR) -cs '$(call DecodeSpace, $@)'; \ - fi - endef -else - define install-file - $(call MakeTargetDir) - $(CP) -fP '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)' - endef -endif - -# Variant of install file that does not preserve symlinks -define install-file-nolink - $(call MakeTargetDir) - $(CP) -f '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)' -endef - -################################################################################ -# link-file-* works similarly to install-file but creates a symlink instead. -# There are two versions, either creating a relative or an absolute link. Be -# careful when using this on Windows since the symlink created is only valid in -# the unix emulation environment. -# In msys2 we use mklink /J because its ln would perform a deep copy of the target. -# This inhibits performance and can lead to issues with long paths. With mklink /J -# relative linking does not work, so we handle the link as absolute path. -ifeq ($(OPENJDK_BUILD_OS_ENV), windows.msys2) - define link-file-relative - $(call MakeTargetDir) - $(RM) '$(call DecodeSpace, $@)' - cmd //c "mklink /J $(call FixPath, $(call DecodeSpace, $@)) $(call FixPath, $(call DecodeSpace, $<))" - endef -else - define link-file-relative - $(call MakeTargetDir) - $(RM) '$(call DecodeSpace, $@)' - $(LN) -s '$(call DecodeSpace, $(call RelativePath, $<, $(@D)))' '$(call DecodeSpace, $@)' - endef -endif - -ifeq ($(OPENJDK_BUILD_OS_ENV), windows.msys2) - define link-file-absolute - $(call MakeTargetDir) - $(RM) '$(call DecodeSpace, $@)' - cmd //c "mklink /J $(call FixPath, $(call DecodeSpace, $@)) $(call FixPath, $(call DecodeSpace, $<))" - endef -else - define link-file-absolute - $(call MakeTargetDir) - $(RM) '$(call DecodeSpace, $@)' - $(LN) -s '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)' - endef -endif - -################################################################################ - -# Recursive wildcard function. Walks down directories recursively and matches -# files with the search patterns. Patterns use standard file wildcards (* and -# ?). -# -# $1 - Directories to start search in -# $2 - Search patterns -rwildcard = \ - $(strip \ - $(foreach d, \ - $(patsubst %/,%,$(sort $(dir $(wildcard $(addsuffix /*/*, $(strip $1)))))), \ - $(call rwildcard,$d,$2) \ - ) \ - $(call DoubleDollar, $(wildcard $(foreach p, $2, $(addsuffix /$(strip $p), $(strip $1))))) \ - ) - -# Find non directories using recursive wildcard function. This function may -# be used directly when a small amount of directories is expected to be -# searched and caching is not expected to be of use. -# -# $1 - Directory to start search in -# $2 - Optional search patterns, defaults to '*'. -WildcardFindFiles = \ - $(sort $(strip \ - $(eval WildcardFindFiles_result := $(call rwildcard,$(patsubst %/,%,$1),$(if $(strip $2),$2,*))) \ - $(filter-out $(patsubst %/,%,$(sort $(dir $(WildcardFindFiles_result)))), \ - $(WildcardFindFiles_result) \ - ) \ - )) - -# Find non directories using the find utility in the shell. Safe to call for -# non existing directories, or directories containing wildcards. -# -# Files containing space will get spaces replaced with ? because GNU Make -# cannot handle lists of files with space in them. By using ?, make will match -# the wildcard to space in many situations so we don't need to replace back -# to space on every use. While not a complete solution it does allow some uses -# of FindFiles to function with spaces in file names, including for -# SetupCopyFiles. Unfortunately this does not work for WildcardFindFiles so -# if files with spaces are anticipated, use ShellFindFiles directly. -# -# $1 - Directories to start search in. -# $2 - Optional search patterns, empty means find everything. Patterns use -# standard file wildcards (* and ?) and should not be quoted. -# $3 - Optional options to find. -ShellFindFiles = \ - $(if $(wildcard $1), \ - $(sort \ - $(shell $(FIND) $3 $(patsubst %/,%,$(wildcard $1)) \( -type f -o -type l \) \ - $(if $(strip $2), -a \( -name "$(firstword $2)" \ - $(foreach p, $(filter-out $(firstword $2), $2), -o -name "$(p)") \)) \ - | $(TR) ' ' '?' \ - ) \ - ) \ - ) - -# Find non directories using the method most likely to work best for the -# current build host -# -# $1 - Directory to start search in -# $2 - Optional search patterns, defaults to '*'. -ifeq ($(OPENJDK_BUILD_OS)-$(RWILDCARD_WORKS), windows-true) - DirectFindFiles = $(WildcardFindFiles) -else - DirectFindFiles = $(ShellFindFiles) -endif - -# Finds files using a cache that is populated by FillFindCache below. If any of -# the directories given have not been cached, DirectFindFiles is used for -# everything. Caching is especially useful in Cygwin, where file finds are very -# costly. -# -# $1 - Directories to start search in. -# $2 - Optional search patterns. If used, no caching is done. -CacheFindFiles_CACHED_DIRS := -CacheFindFiles_CACHED_FILES := -CacheFindFiles = \ - $(if $2, \ - $(call DirectFindFiles, $1, $2) \ - , \ - $(if $(filter-out $(addsuffix /%, $(CacheFindFiles_CACHED_DIRS)) \ - $(CacheFindFiles_CACHED_DIRS), $1), \ - $(call DirectFindFiles, $1) \ - , \ - $(filter $(addsuffix /%,$(patsubst %/,%,$1)) $1,$(CacheFindFiles_CACHED_FILES)) \ - ) \ - ) - -# Explicitly adds files to the find cache used by CacheFindFiles. -# -# $1 - Directories to start search in -FillFindCache = \ - $(eval CacheFindFiles_NEW_DIRS := $$(filter-out $$(addsuffix /%,\ - $$(CacheFindFiles_CACHED_DIRS)) $$(CacheFindFiles_CACHED_DIRS), $1)) \ - $(if $(CacheFindFiles_NEW_DIRS), \ - $(eval CacheFindFiles_CACHED_DIRS += $$(patsubst %/,%,$$(CacheFindFiles_NEW_DIRS))) \ - $(eval CacheFindFiles_CACHED_FILES := $$(sort $$(CacheFindFiles_CACHED_FILES) \ - $$(call DirectFindFiles, $$(CacheFindFiles_NEW_DIRS)))) \ - ) - -# Findfiles is the default macro that should be used to find files in the file -# system. This function does not always support files with spaces in the names. -# If files with spaces are anticipated, use ShellFindFiles directly. -# -# $1 - Directories to start search in. -# $2 - Optional search patterns, empty means find everything. Patterns use -# standard file wildcards (* and ?) and should not be quoted. -ifeq ($(DISABLE_CACHE_FIND), true) - FindFiles = $(DirectFindFiles) -else - FindFiles = $(CacheFindFiles) -endif - ################################################################################ # FixPath # diff --git a/make/common/MakeIO.gmk b/make/common/MakeIO.gmk index 75a387c34d9..865c5cae2e5 100644 --- a/make/common/MakeIO.gmk +++ b/make/common/MakeIO.gmk @@ -241,32 +241,3 @@ else # HAS_FILE_FUNCTION = false $$(call ListPathsSafely_IfPrintf,$1,$2,29751,30000) endef endif # HAS_FILE_FUNCTION - -################################################################################ -# Write to and read from file - -# Param 1 - File to read -ReadFile = \ - $(shell $(CAT) $1) - -# Param 1 - Text to write -# Param 2 - File to write to -ifeq ($(HAS_FILE_FUNCTION), true) - WriteFile = \ - $(file >$2,$(strip $1)) -else - # Use printf to get consistent behavior on all platforms. - WriteFile = \ - $(shell $(PRINTF) "%s\n" $(strip $(call ShellQuote, $1)) > $2) -endif - -# Param 1 - Text to write -# Param 2 - File to write to -ifeq ($(HAS_FILE_FUNCTION), true) - AppendFile = \ - $(file >>$2,$(strip $1)) -else - # Use printf to get consistent behavior on all platforms. - AppendFile = \ - $(shell $(PRINTF) "%s\n" $(strip $(call ShellQuote, $1)) >> $2) -endif diff --git a/make/common/NativeCompilation.gmk b/make/common/NativeCompilation.gmk index afae920f755..3f31865c247 100644 --- a/make/common/NativeCompilation.gmk +++ b/make/common/NativeCompilation.gmk @@ -36,6 +36,7 @@ ifeq ($(_MAKEBASE_GMK), ) $(error You must include MakeBase.gmk prior to including NativeCompilation.gmk) endif +include MakeIO.gmk include native/CompileFile.gmk include native/DebugSymbols.gmk include native/Flags.gmk diff --git a/make/common/Utils.gmk b/make/common/Utils.gmk index 00e73f7dd6c..7f1cbd61f38 100644 --- a/make/common/Utils.gmk +++ b/make/common/Utils.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -29,29 +29,34 @@ endif ################################################################################ # -# Common utility functions +# Basic utility functions available to MakeBase.gmk itself # ################################################################################ -### Debug functions +# String equals +equals = \ + $(if $(strip $1)$(strip $2),$(strip \ + $(and $(findstring $(strip $1),$(strip $2)),\ + $(findstring $(strip $2),$(strip $1)))), \ + true \ + ) -# Prints the name and value of a variable -PrintVar = \ - $(info $(strip $1) >$($(strip $1))<) +# Convert the string given to upper case, without any $(shell) +# Inspired by http://lists.gnu.org/archive/html/help-make/2013-09/msg00009.html +uppercase_table := a,A b,B c,C d,D e,E f,F g,G h,H i,I j,J k,K l,L m,M n,N o,O \ + p,P q,Q r,R s,S t,T u,U v,V w,W x,X y,Y z,Z -################################################################################ -# This macro translates $ into \$ to protect the $ from expansion in the shell. -# To make this macro resilient against already escaped strings, first remove -# any present escapes before escaping so that no double escapes are added. -EscapeDollar = $(subst $$,\$$,$(subst \$$,$$,$(strip $1))) +uppercase_internal = \ + $(if $(strip $1), $$(subst $(firstword $1), $(call uppercase_internal, \ + $(wordlist 2, $(words $1), $1), $2)), $2) -################################################################################ -# This macro works just like EscapeDollar above, but for #. -EscapeHash = $(subst \#,\\\#,$(subst \\\#,\#,$(strip $1))) - -################################################################################ -# This macro translates $ into $$ to protect the string from make itself. -DoubleDollar = $(subst $$,$$$$,$(strip $1)) +# Convert a string to upper case. Works only on a-z. +# $1 - The string to convert +uppercase = \ + $(strip \ + $(eval uppercase_result := $(call uppercase_internal, $(uppercase_table), $1)) \ + $(uppercase_result) \ + ) ################################################################################ # Creates a sequence of increasing numbers (inclusive). @@ -68,23 +73,142 @@ _sequence-do = \ $(words $(SEQUENCE_COUNT)) \ $(call _sequence-do,$1)) +################################################################################ +# This macro translates $ into \$ to protect the $ from expansion in the shell. +# To make this macro resilient against already escaped strings, first remove +# any present escapes before escaping so that no double escapes are added. +EscapeDollar = $(subst $$,\$$,$(subst \$$,$$,$(strip $1))) + +################################################################################ +# This macro works just like EscapeDollar above, but for #. +EscapeHash = $(subst \#,\\\#,$(subst \\\#,\#,$(strip $1))) + +################################################################################ +# This macro translates $ into $$ to protect the string from make itself. +DoubleDollar = $(subst $$,$$$$,$(strip $1)) + +################################################################################ +# ShellQuote +# +# Quotes a string with single quotes and replaces single quotes with '\'' so +# that the contents survives being given to the shell. +ShellQuote = \ + $(SQUOTE)$(subst $(SQUOTE),$(SQUOTE)\$(SQUOTE)$(SQUOTE),$(strip $1))$(SQUOTE) + +################################################################################ +# Write to and read from file + +# Param 1 - File to read +ReadFile = \ + $(shell $(CAT) $1) + +# Param 1 - Text to write +# Param 2 - File to write to +ifeq ($(HAS_FILE_FUNCTION), true) + WriteFile = \ + $(file >$2,$(strip $1)) +else + # Use printf to get consistent behavior on all platforms. + WriteFile = \ + $(shell $(PRINTF) "%s\n" $(strip $(call ShellQuote, $1)) > $2) +endif + +# Param 1 - Text to write +# Param 2 - File to write to +ifeq ($(HAS_FILE_FUNCTION), true) + AppendFile = \ + $(file >>$2,$(strip $1)) +else + # Use printf to get consistent behavior on all platforms. + AppendFile = \ + $(shell $(PRINTF) "%s\n" $(strip $(call ShellQuote, $1)) >> $2) +endif + +################################################################################ +# Make directory without forking mkdir if not needed. +# +# If a directory with an encoded space is provided, the wildcard function +# sometimes returns false answers (typically if the dir existed when the +# makefile was parsed, but was deleted by a previous rule). In that case, always +# call mkdir regardless of what wildcard says. +# +# 1: List of directories to create +MakeDir = \ + $(strip \ + $(eval MakeDir_dirs_to_make := $(strip $(foreach d, $1, \ + $(if $(findstring ?, $d), '$(call DecodeSpace, $d)', \ + $(if $(wildcard $d), , $d) \ + ) \ + ))) \ + $(if $(MakeDir_dirs_to_make), $(shell $(MKDIR) -p $(MakeDir_dirs_to_make))) \ + ) + +################################################################################ +# Check if our build or target conforms to certain restrictions. This set of +# functions all work in similar ways, testing the property that the name +# implies, so e.g. isTargetCpu test the CPU of the target system. +# +# $1 - A property, or a space separated list of properties to test for. +# +# Returns true if the actual property matches one of the properties in the list, +# and false otherwise. +# +# Examples: $(call isTargetOs, linux windows) will return true when executed +# on either linux or windows, and false otherwise. +# $(call isBuildCpuArch, x86) will return true iff the build CPU Arch is x86. + +isTargetOs = \ + $(strip $(if $(filter $(OPENJDK_TARGET_OS), $1), true, false)) + +isTargetOsType = \ + $(strip $(if $(filter $(OPENJDK_TARGET_OS_TYPE), $1), true, false)) + +isTargetCpu = \ + $(strip $(if $(filter $(OPENJDK_TARGET_CPU), $1), true, false)) + +isTargetCpuArch = \ + $(strip $(if $(filter $(OPENJDK_TARGET_CPU_ARCH), $1), true, false)) + +isTargetCpuBits = \ + $(strip $(if $(filter $(OPENJDK_TARGET_CPU_BITS), $1), true, false)) + +isBuildOs = \ + $(strip $(if $(filter $(OPENJDK_BUILD_OS), $1), true, false)) + +isBuildOsType = \ + $(strip $(if $(filter $(OPENJDK_BUILD_OS_TYPE), $1), true, false)) + +isBuildOsEnv = \ + $(strip $(if $(filter $(OPENJDK_BUILD_OS_ENV), $1), true, false)) + +isBuildCpu = \ + $(strip $(if $(filter $(OPENJDK_BUILD_CPU), $1), true, false)) + +isBuildCpuArch = \ + $(strip $(if $(filter $(OPENJDK_BUILD_CPU_ARCH), $1), true, false)) + +isCompiler = \ + $(strip $(if $(filter $(TOOLCHAIN_TYPE), $1), true, false)) + +################################################################################ +# +# Common utility functions +# +################################################################################ + +### Debug functions + +# Prints the name and value of a variable +PrintVar = \ + $(info $(strip $1) >$($(strip $1))<) + + ################################################################################ # Strip both arguments. Append the first argument to the second argument. If the # first argument is empty, return the empty string. IfAppend = \ $(if $(strip $1),$(strip $1)$(strip $2),) -################################################################################ -# Replace question marks with space in string. This macro needs to be called on -# files from FindFiles in case any of them contains space in their file name, -# since FindFiles replaces space with ?. -# Param 1 - String to replace in -DecodeSpace = \ - $(subst ?,$(SPACE),$(strip $1)) - -EncodeSpace = \ - $(subst $(SPACE),?,$(strip $1)) - ################################################################################ # Assign a variable only if it is empty # Param 1 - Variable to assign @@ -92,65 +216,6 @@ EncodeSpace = \ SetIfEmpty = \ $(if $($(strip $1)),,$(eval $(strip $1) := $2)) -################################################################################ -# Take two paths and return the path of the last common directory. -# Ex: /foo/bar/baz, /foo/bar/banan -> /foo/bar -# foo/bar/baz, /foo/bar -> -# -# The x prefix is used to preserve the presence of the initial slash -# On Windows paths are treated as case-insensitive -# -# $1 - Path to compare -# $2 - Other path to compare -FindCommonPathPrefix = \ - $(call DecodeSpace,$(patsubst x%,%,$(subst $(SPACE),/,$(strip \ - $(call FindCommonPathPrefixHelper1, \ - $(subst /,$(SPACE),x$(call EncodeSpace,$(strip $1))), \ - $(subst /,$(SPACE),x$(call EncodeSpace,$(strip $2)))) \ - )))) - -FindCommonPathPrefixHelper1 = \ - $(if $(filter $(OPENJDK_TARGET_OS), windows), \ - $(call FindCommonPathPrefixHelper2,$(call uppercase,$1),$(call uppercase,$2),$1), \ - $(call FindCommonPathPrefixHelper2,$1,$2,$1)) - -FindCommonPathPrefixHelper2 = \ - $(if $(call equals, $(firstword $1), $(firstword $2)), \ - $(if $(call equals, $(firstword $1),),, \ - $(firstword $3) \ - $(call FindCommonPathPrefixHelper2, \ - $(wordlist 2, $(words $1), $1), \ - $(wordlist 2, $(words $2), $2), \ - $(wordlist 2, $(words $3), $3) \ - ) \ - ) \ - ) - -# Computes the relative path from a directory to a file -# $1 - File to compute the relative path to -# $2 - Directory to compute the relative path from -RelativePath = \ - $(call DecodeSpace,$(strip $(call RelativePathHelper,$(call EncodeSpace \ - ,$(strip $1)),$(call EncodeSpace \ - ,$(strip $2)),$(call EncodeSpace \ - ,$(call FindCommonPathPrefix,$1,$2))))) - -RelativePathHelper = \ - $(eval $3_prefix_length := $(words $(subst /,$(SPACE),$3))) \ - $(eval $1_words := $(subst /,$(SPACE),$1)) \ - $(eval $2_words := $(subst /,$(SPACE),$2)) \ - $(if $(call equals,$($3_prefix_length),0),, \ - $(eval $1_words := $(wordlist 2,$(words $($1_words)),$(wordlist \ - $($3_prefix_length),$(words $($1_words)),$($1_words)))) \ - $(eval $2_words := $(wordlist 2,$(words $($2_words)),$(wordlist \ - $($3_prefix_length),$(words $($2_words)),$($2_words)))) \ - ) \ - $(eval $1_suffix := $(subst $(SPACE),/,$($1_words))) \ - $(eval $2_dotdots := $(subst $(SPACE),/,$(foreach d,$($2_words),..))) \ - $(if $($1_suffix), \ - $(if $($2_dotdots), $($2_dotdots)/$($1_suffix), $($1_suffix)), \ - $(if $($2_dotdots), $($2_dotdots), .)) - ################################################################################ # Filter out duplicate sub strings while preserving order. Keeps the first occurrence. uniq = \ @@ -173,14 +238,6 @@ dups = \ $(strip $(foreach v, $(sort $1), $(if $(filter-out 1, \ $(words $(filter $v, $1))), $v))) -# String equals -equals = \ - $(if $(strip $1)$(strip $2),$(strip \ - $(and $(findstring $(strip $1),$(strip $2)),\ - $(findstring $(strip $2),$(strip $1)))), \ - true \ - ) - # Remove a whole list of prefixes # $1 - List of prefixes # $2 - List of elements to process @@ -188,23 +245,6 @@ remove-prefixes = \ $(strip $(if $1,$(patsubst $(firstword $1)%,%,\ $(call remove-prefixes,$(filter-out $(firstword $1),$1),$2)),$2)) -# Convert the string given to upper case, without any $(shell) -# Inspired by http://lists.gnu.org/archive/html/help-make/2013-09/msg00009.html -uppercase_table := a,A b,B c,C d,D e,E f,F g,G h,H i,I j,J k,K l,L m,M n,N o,O \ - p,P q,Q r,R s,S t,T u,U v,V w,W x,X y,Y z,Z - -uppercase_internal = \ - $(if $(strip $1), $$(subst $(firstword $1), $(call uppercase_internal, \ - $(wordlist 2, $(words $1), $1), $2)), $2) - -# Convert a string to upper case. Works only on a-z. -# $1 - The string to convert -uppercase = \ - $(strip \ - $(eval uppercase_result := $(call uppercase_internal, $(uppercase_table), $1)) \ - $(uppercase_result) \ - ) - ################################################################################ # Boolean operators. @@ -290,14 +330,6 @@ define ParseKeywordVariableBody endif endef -################################################################################ -# ShellQuote -# -# Quotes a string with single quotes and replaces single quotes with '\'' so -# that the contents survives being given to the shell. -ShellQuote = \ - $(SQUOTE)$(subst $(SQUOTE),$(SQUOTE)\$(SQUOTE)$(SQUOTE),$(strip $1))$(SQUOTE) - ################################################################################ # Find lib dir for module # Param 1 - module name @@ -329,53 +361,6 @@ check-jvm-variant = \ $(error Internal error: Invalid variant tested: $1)) \ $(if $(filter $1, $(JVM_VARIANTS)), true, false)) -################################################################################ -# Check if our build or target conforms to certain restrictions. This set of -# functions all work in similar ways, testing the property that the name -# implies, so e.g. isTargetCpu test the CPU of the target system. -# -# $1 - A property, or a space separated list of properties to test for. -# -# Returns true if the actual property matches one of the properties in the list, -# and false otherwise. -# -# Examples: $(call isTargetOs, linux windows) will return true when executed -# on either linux or windows, and false otherwise. -# $(call isBuildCpuArch, x86) will return true iff the build CPU Arch is x86. - -isTargetOs = \ - $(strip $(if $(filter $(OPENJDK_TARGET_OS), $1), true, false)) - -isTargetOsType = \ - $(strip $(if $(filter $(OPENJDK_TARGET_OS_TYPE), $1), true, false)) - -isTargetCpu = \ - $(strip $(if $(filter $(OPENJDK_TARGET_CPU), $1), true, false)) - -isTargetCpuArch = \ - $(strip $(if $(filter $(OPENJDK_TARGET_CPU_ARCH), $1), true, false)) - -isTargetCpuBits = \ - $(strip $(if $(filter $(OPENJDK_TARGET_CPU_BITS), $1), true, false)) - -isBuildOs = \ - $(strip $(if $(filter $(OPENJDK_BUILD_OS), $1), true, false)) - -isBuildOsType = \ - $(strip $(if $(filter $(OPENJDK_BUILD_OS_TYPE), $1), true, false)) - -isBuildOsEnv = \ - $(strip $(if $(filter $(OPENJDK_BUILD_OS_ENV), $1), true, false)) - -isBuildCpu = \ - $(strip $(if $(filter $(OPENJDK_BUILD_CPU), $1), true, false)) - -isBuildCpuArch = \ - $(strip $(if $(filter $(OPENJDK_BUILD_CPU_ARCH), $1), true, false)) - -isCompiler = \ - $(strip $(if $(filter $(TOOLCHAIN_TYPE), $1), true, false)) - ################################################################################ # Converts a space separated list to a comma separated list. # diff --git a/make/common/modules/CopyCommon.gmk b/make/common/modules/CopyCommon.gmk index b8cf880d673..75bfb0d62b1 100644 --- a/make/common/modules/CopyCommon.gmk +++ b/make/common/modules/CopyCommon.gmk @@ -23,6 +23,8 @@ # questions. # +include CopyFiles.gmk + LIB_DST_DIR := $(SUPPORT_OUTPUTDIR)/modules_libs/$(MODULE) CONF_DST_DIR := $(SUPPORT_OUTPUTDIR)/modules_conf/$(MODULE) LEGAL_DST_DIR := $(SUPPORT_OUTPUTDIR)/modules_legal/$(MODULE) diff --git a/make/common/modules/LauncherCommon.gmk b/make/common/modules/LauncherCommon.gmk index f072cbfb9bf..a801631a9c9 100644 --- a/make/common/modules/LauncherCommon.gmk +++ b/make/common/modules/LauncherCommon.gmk @@ -23,6 +23,7 @@ # questions. # +include CopyFiles.gmk include JdkNativeCompilation.gmk include Modules.gmk include ProcessMarkdown.gmk diff --git a/make/hotspot/CopyToExplodedJdk.gmk b/make/hotspot/CopyToExplodedJdk.gmk index d8012f6878f..4462af0dc3b 100644 --- a/make/hotspot/CopyToExplodedJdk.gmk +++ b/make/hotspot/CopyToExplodedJdk.gmk @@ -23,6 +23,8 @@ # questions. # +include CopyFiles.gmk + # Copy all built libraries into exploded jdk LIB_TARGETS := $(filter $(LIB_OUTPUTDIR)/%, $(TARGETS)) ifeq ($(call isTargetOs, windows), true) diff --git a/make/hotspot/gensrc/GensrcJvmti.gmk b/make/hotspot/gensrc/GensrcJvmti.gmk index b31a6f52292..718766cacae 100644 --- a/make/hotspot/gensrc/GensrcJvmti.gmk +++ b/make/hotspot/gensrc/GensrcJvmti.gmk @@ -23,6 +23,8 @@ # questions. # +include CopyFiles.gmk + $(eval $(call IncludeCustomExtension, hotspot/gensrc/GensrcJvmti.gmk)) ################################################################################ diff --git a/make/hotspot/lib/CompileJvm.gmk b/make/hotspot/lib/CompileJvm.gmk index e887885db2c..47f987092f9 100644 --- a/make/hotspot/lib/CompileJvm.gmk +++ b/make/hotspot/lib/CompileJvm.gmk @@ -23,6 +23,8 @@ # questions. # +include CopyFiles.gmk + # Include support files that will setup compiler flags due to the selected # jvm feature set, specific file overrides, and general flags. include lib/JvmFeatures.gmk diff --git a/make/hotspot/test/GtestImage.gmk b/make/hotspot/test/GtestImage.gmk index 9b2a37962cd..b6256cd575b 100644 --- a/make/hotspot/test/GtestImage.gmk +++ b/make/hotspot/test/GtestImage.gmk @@ -28,6 +28,8 @@ default: all include $(SPEC) include MakeBase.gmk +include CopyFiles.gmk + $(foreach v, $(JVM_VARIANTS), \ $(eval $(call SetupCopyFiles, COPY_GTEST_$v, \ SRC := $(HOTSPOT_OUTPUTDIR)/variant-$v/libjvm/gtest, \ diff --git a/make/modules/java.base/Lib.gmk b/make/modules/java.base/Lib.gmk index d09e33d489f..3a24c5e4550 100644 --- a/make/modules/java.base/Lib.gmk +++ b/make/modules/java.base/Lib.gmk @@ -23,6 +23,7 @@ # questions. # +include CopyFiles.gmk include LibCommon.gmk # Hook to include the corresponding custom file, if present. diff --git a/make/modules/java.desktop/lib/Awt2dLibraries.gmk b/make/modules/java.desktop/lib/Awt2dLibraries.gmk index c30901e1543..868e6fb7a7c 100644 --- a/make/modules/java.desktop/lib/Awt2dLibraries.gmk +++ b/make/modules/java.desktop/lib/Awt2dLibraries.gmk @@ -23,6 +23,8 @@ # questions. # +include CopyFiles.gmk + LIBAWT_DEFAULT_HEADER_DIRS := \ common/awt/utility \ libawt/awt/image \ diff --git a/make/modules/jdk.compiler/Gendata.gmk b/make/modules/jdk.compiler/Gendata.gmk index e9ff3c439be..32fa70462b2 100644 --- a/make/modules/jdk.compiler/Gendata.gmk +++ b/make/modules/jdk.compiler/Gendata.gmk @@ -23,6 +23,7 @@ # questions. # +include CopyFiles.gmk include JarArchive.gmk include JavaCompilation.gmk include Modules.gmk diff --git a/make/test/BuildFailureHandler.gmk b/make/test/BuildFailureHandler.gmk index 6c9876f80c7..005cbb330f6 100644 --- a/make/test/BuildFailureHandler.gmk +++ b/make/test/BuildFailureHandler.gmk @@ -27,6 +27,8 @@ default: build include $(SPEC) include MakeBase.gmk + +include CopyFiles.gmk include JavaCompilation.gmk TARGETS := diff --git a/make/test/BuildJtregTestThreadFactory.gmk b/make/test/BuildJtregTestThreadFactory.gmk index b096ae303ea..aa9808dd584 100644 --- a/make/test/BuildJtregTestThreadFactory.gmk +++ b/make/test/BuildJtregTestThreadFactory.gmk @@ -27,6 +27,8 @@ default: build include $(SPEC) include MakeBase.gmk + +include CopyFiles.gmk include JavaCompilation.gmk TARGETS := diff --git a/make/test/BuildMicrobenchmark.gmk b/make/test/BuildMicrobenchmark.gmk index ba502a56128..bb1e6111baa 100644 --- a/make/test/BuildMicrobenchmark.gmk +++ b/make/test/BuildMicrobenchmark.gmk @@ -28,6 +28,8 @@ default: all include $(SPEC) include MakeBase.gmk + +include CopyFiles.gmk include JavaCompilation.gmk include TestFilesCompilation.gmk diff --git a/make/test/BuildTestLib.gmk b/make/test/BuildTestLib.gmk index 54c4c61642c..00642a1e7cf 100644 --- a/make/test/BuildTestLib.gmk +++ b/make/test/BuildTestLib.gmk @@ -33,6 +33,8 @@ default: all include $(SPEC) include MakeBase.gmk + +include CopyFiles.gmk include JavaCompilation.gmk ################################################################################ diff --git a/make/test/BuildTestLibNative.gmk b/make/test/BuildTestLibNative.gmk index 455936d163f..63dcbbf008b 100644 --- a/make/test/BuildTestLibNative.gmk +++ b/make/test/BuildTestLibNative.gmk @@ -33,6 +33,8 @@ default: all include $(SPEC) include MakeBase.gmk + +include CopyFiles.gmk include TestFilesCompilation.gmk ################################################################################ diff --git a/make/test/JtregNativeHotspot.gmk b/make/test/JtregNativeHotspot.gmk index 33532f77974..887b530bfca 100644 --- a/make/test/JtregNativeHotspot.gmk +++ b/make/test/JtregNativeHotspot.gmk @@ -33,6 +33,8 @@ default: all include $(SPEC) include MakeBase.gmk + +include CopyFiles.gmk include TestFilesCompilation.gmk $(eval $(call IncludeCustomExtension, test/JtregNativeHotspot.gmk)) diff --git a/make/test/JtregNativeJdk.gmk b/make/test/JtregNativeJdk.gmk index ae830501635..46eeb7684b6 100644 --- a/make/test/JtregNativeJdk.gmk +++ b/make/test/JtregNativeJdk.gmk @@ -33,6 +33,8 @@ default: all include $(SPEC) include MakeBase.gmk + +include CopyFiles.gmk include TestFilesCompilation.gmk $(eval $(call IncludeCustomExtension, test/JtregNativeJdk.gmk)) diff --git a/make/test/JtregNativeLibTest.gmk b/make/test/JtregNativeLibTest.gmk index 7ab45cce878..838d37f8145 100644 --- a/make/test/JtregNativeLibTest.gmk +++ b/make/test/JtregNativeLibTest.gmk @@ -33,6 +33,8 @@ default: all include $(SPEC) include MakeBase.gmk + +include CopyFiles.gmk include TestFilesCompilation.gmk $(eval $(call IncludeCustomExtension, test/JtregNativeLibTest.gmk)) diff --git a/test/make/TestCopyFiles.gmk b/test/make/TestCopyFiles.gmk index cbfa1cc003c..cc05f89db23 100644 --- a/test/make/TestCopyFiles.gmk +++ b/test/make/TestCopyFiles.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -25,6 +25,7 @@ default: all include $(SPEC) include MakeBase.gmk +include CopyFiles.gmk include UtilsForTests.gmk THIS_FILE := $(TOPDIR)/test/make/TestCopyFiles.gmk