author | rriggs |
Wed, 21 Aug 2019 16:19:17 -0400 | |
changeset 57827 | 425412369353 |
parent 55292 | f4b2d5b83ebf |
child 58663 | 11a574b352d0 |
permissions | -rw-r--r-- |
12258
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
1 |
# |
53484 | 2 |
# Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. |
12258
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
3 |
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
4 |
# |
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
5 |
# This code is free software; you can redistribute it and/or modify it |
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
6 |
# under the terms of the GNU General Public License version 2 only, as |
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
7 |
# published by the Free Software Foundation. Oracle designates this |
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
8 |
# particular file as subject to the "Classpath" exception as provided |
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
9 |
# by Oracle in the LICENSE file that accompanied this code. |
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
10 |
# |
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
11 |
# This code is distributed in the hope that it will be useful, but WITHOUT |
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
13 |
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
14 |
# version 2 for more details (a copy is included in the LICENSE file that |
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
15 |
# accompanied this code). |
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
16 |
# |
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
17 |
# You should have received a copy of the GNU General Public License version |
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
18 |
# 2 along with this work; if not, write to the Free Software Foundation, |
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
19 |
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
20 |
# |
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
21 |
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
22 |
# or visit www.oracle.com if you need additional information or have any |
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
23 |
# questions. |
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
24 |
# |
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
25 |
|
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
26 |
################################################################ |
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
27 |
# |
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
28 |
# Setup common utility functions. |
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
29 |
# |
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
30 |
################################################################ |
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
31 |
|
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
32 |
ifndef _MAKEBASE_GMK |
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
33 |
_MAKEBASE_GMK := 1 |
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
34 |
|
29662 | 35 |
ifeq ($(wildcard $(SPEC)),) |
36 |
$(error MakeBase.gmk needs SPEC set to a proper spec.gmk) |
|
37 |
endif |
|
38 |
||
29861 | 39 |
# By defining this pseudo target, make will automatically remove targets |
40 |
# if their recipe fails so that a rebuild is automatically triggered on the |
|
41 |
# next make invocation. |
|
42 |
.DELETE_ON_ERROR: |
|
29662 | 43 |
|
32460
9e9bffb3029a
8065912: Better handling of classpath in build-infra
ihse
parents:
32344
diff
changeset
|
44 |
################################################################################ |
9e9bffb3029a
8065912: Better handling of classpath in build-infra
ihse
parents:
32344
diff
changeset
|
45 |
# Definitions for special characters |
9e9bffb3029a
8065912: Better handling of classpath in build-infra
ihse
parents:
32344
diff
changeset
|
46 |
################################################################################ |
9e9bffb3029a
8065912: Better handling of classpath in build-infra
ihse
parents:
32344
diff
changeset
|
47 |
|
9e9bffb3029a
8065912: Better handling of classpath in build-infra
ihse
parents:
32344
diff
changeset
|
48 |
# When calling macros, the spaces between arguments are |
9e9bffb3029a
8065912: Better handling of classpath in build-infra
ihse
parents:
32344
diff
changeset
|
49 |
# often semantically important! Sometimes we need to subst |
9e9bffb3029a
8065912: Better handling of classpath in build-infra
ihse
parents:
32344
diff
changeset
|
50 |
# spaces and commas, therefore we need the following macros. |
9e9bffb3029a
8065912: Better handling of classpath in build-infra
ihse
parents:
32344
diff
changeset
|
51 |
X:= |
9e9bffb3029a
8065912: Better handling of classpath in build-infra
ihse
parents:
32344
diff
changeset
|
52 |
SPACE:=$(X) $(X) |
9e9bffb3029a
8065912: Better handling of classpath in build-infra
ihse
parents:
32344
diff
changeset
|
53 |
COMMA:=, |
9e9bffb3029a
8065912: Better handling of classpath in build-infra
ihse
parents:
32344
diff
changeset
|
54 |
DOLLAR:=$$ |
9e9bffb3029a
8065912: Better handling of classpath in build-infra
ihse
parents:
32344
diff
changeset
|
55 |
HASH:=\# |
9e9bffb3029a
8065912: Better handling of classpath in build-infra
ihse
parents:
32344
diff
changeset
|
56 |
LEFT_PAREN:=( |
9e9bffb3029a
8065912: Better handling of classpath in build-infra
ihse
parents:
32344
diff
changeset
|
57 |
RIGHT_PAREN:=) |
9e9bffb3029a
8065912: Better handling of classpath in build-infra
ihse
parents:
32344
diff
changeset
|
58 |
SQUOTE:=' |
9e9bffb3029a
8065912: Better handling of classpath in build-infra
ihse
parents:
32344
diff
changeset
|
59 |
#' |
9e9bffb3029a
8065912: Better handling of classpath in build-infra
ihse
parents:
32344
diff
changeset
|
60 |
DQUOTE:=" |
9e9bffb3029a
8065912: Better handling of classpath in build-infra
ihse
parents:
32344
diff
changeset
|
61 |
#" |
9e9bffb3029a
8065912: Better handling of classpath in build-infra
ihse
parents:
32344
diff
changeset
|
62 |
define NEWLINE |
9e9bffb3029a
8065912: Better handling of classpath in build-infra
ihse
parents:
32344
diff
changeset
|
63 |
|
9e9bffb3029a
8065912: Better handling of classpath in build-infra
ihse
parents:
32344
diff
changeset
|
64 |
|
9e9bffb3029a
8065912: Better handling of classpath in build-infra
ihse
parents:
32344
diff
changeset
|
65 |
endef |
9e9bffb3029a
8065912: Better handling of classpath in build-infra
ihse
parents:
32344
diff
changeset
|
66 |
|
54380 | 67 |
# Certain features only work in newer version of GNU Make. The build will still |
68 |
# function in 3.81, but will be less performant. |
|
32807
20386e6d858f
8136385: Various build speed improvements for windows
erikj
parents:
32553
diff
changeset
|
69 |
ifeq (4.0, $(firstword $(sort 4.0 $(MAKE_VERSION)))) |
20386e6d858f
8136385: Various build speed improvements for windows
erikj
parents:
32553
diff
changeset
|
70 |
HAS_FILE_FUNCTION := true |
49270 | 71 |
CORRECT_FUNCTION_IN_RECIPE_EVALUATION := true |
54380 | 72 |
RWILDCARD_WORKS := true |
32807
20386e6d858f
8136385: Various build speed improvements for windows
erikj
parents:
32553
diff
changeset
|
73 |
endif |
20386e6d858f
8136385: Various build speed improvements for windows
erikj
parents:
32553
diff
changeset
|
74 |
|
29662 | 75 |
|
53484 | 76 |
# For convenience, MakeBase.gmk continues to include these separate files, at |
77 |
# least for now. |
|
30095
0034766ccb09
8079344: Allow custom or platform specific java source to automatically override shared source
erikj
parents:
29866
diff
changeset
|
78 |
|
53484 | 79 |
include $(TOPDIR)/make/common/Utils.gmk |
80 |
include $(TOPDIR)/make/common/MakeIO.gmk |
|
81 |
include $(TOPDIR)/make/common/CopyFiles.gmk |
|
29662 | 82 |
|
53484 | 83 |
################################################################################ |
84 |
# Functions for timers |
|
85 |
################################################################################ |
|
29662 | 86 |
|
87 |
# Store the build times in this directory. |
|
47253
92fd0e04e0e1
8187544: Replace BUILD_OUTPUT and OUTPUT_ROOT with OUTPUTDIR
ihse
parents:
47217
diff
changeset
|
88 |
BUILDTIMESDIR=$(OUTPUTDIR)/make-support/build-times |
29662 | 89 |
|
90 |
# Record starting time for build of a sub repository. |
|
91 |
define RecordStartTime |
|
35008 | 92 |
$(DATE) '+%Y %m %d %H %M %S' | $(NAWK) '{ print $$1,$$2,$$3,$$4,$$5,$$6,($$4*3600+$$5*60+$$6) }' > $(BUILDTIMESDIR)/build_time_start_$(strip $1) && \ |
29662 | 93 |
$(DATE) '+%Y-%m-%d %H:%M:%S' > $(BUILDTIMESDIR)/build_time_start_$(strip $1)_human_readable |
94 |
endef |
|
95 |
||
96 |
# Record ending time and calculate the difference and store it in a |
|
97 |
# easy to read format. Handles builds that cross midnight. Expects |
|
98 |
# that a build will never take 24 hours or more. |
|
99 |
define RecordEndTime |
|
100 |
$(DATE) '+%Y %m %d %H %M %S' | $(NAWK) '{ print $$1,$$2,$$3,$$4,$$5,$$6,($$4*3600+$$5*60+$$6) }' > $(BUILDTIMESDIR)/build_time_end_$(strip $1) |
|
101 |
$(DATE) '+%Y-%m-%d %H:%M:%S' > $(BUILDTIMESDIR)/build_time_end_$(strip $1)_human_readable |
|
102 |
$(ECHO) `$(CAT) $(BUILDTIMESDIR)/build_time_start_$(strip $1)` `$(CAT) $(BUILDTIMESDIR)/build_time_end_$(strip $1)` $1 | \ |
|
103 |
$(NAWK) '{ F=$$7; T=$$14; if (F > T) { T+=3600*24 }; D=T-F; H=int(D/3600); \ |
|
104 |
M=int((D-H*3600)/60); S=D-H*3600-M*60; printf("%02d:%02d:%02d %s\n",H,M,S,$$15); }' \ |
|
105 |
> $(BUILDTIMESDIR)/build_time_diff_$(strip $1) |
|
106 |
endef |
|
107 |
||
108 |
# Hook to be called when starting to execute a top-level target |
|
109 |
define TargetEnter |
|
110 |
$(PRINTF) "## Starting $(patsubst %-only,%,$@)\n" |
|
111 |
$(call RecordStartTime,$(patsubst %-only,%,$@)) |
|
112 |
endef |
|
113 |
||
114 |
# Hook to be called when finish executing a top-level target |
|
115 |
define TargetExit |
|
116 |
$(call RecordEndTime,$(patsubst %-only,%,$@)) |
|
117 |
$(PRINTF) "## Finished $(patsubst %-only,%,$@) (build time %s)\n\n" \ |
|
118 |
"`$(CAT) $(BUILDTIMESDIR)/build_time_diff_$(patsubst %-only,%,$@) | $(CUT) -f 1 -d ' '`" |
|
119 |
endef |
|
120 |
||
25854 | 121 |
################################################################################ |
42282
faf3b6722c44
8031567: Better model for storing source revision information
ihse
parents:
42134
diff
changeset
|
122 |
|
faf3b6722c44
8031567: Better model for storing source revision information
ihse
parents:
42134
diff
changeset
|
123 |
# A file containing a way to uniquely identify the source code revision that |
faf3b6722c44
8031567: Better model for storing source revision information
ihse
parents:
42134
diff
changeset
|
124 |
# the build was created from |
faf3b6722c44
8031567: Better model for storing source revision information
ihse
parents:
42134
diff
changeset
|
125 |
SOURCE_REVISION_TRACKER := $(SUPPORT_OUTPUTDIR)/src-rev/source-revision-tracker |
faf3b6722c44
8031567: Better model for storing source revision information
ihse
parents:
42134
diff
changeset
|
126 |
|
faf3b6722c44
8031567: Better model for storing source revision information
ihse
parents:
42134
diff
changeset
|
127 |
# Locate all hg repositories included in the forest, as absolute paths |
39110
712f29ba8708
8136771: Implement the license-swap logic as a make target
erikj
parents:
37972
diff
changeset
|
128 |
FindAllReposAbs = \ |
47217 | 129 |
$(strip $(sort $(dir $(filter-out $(TOPDIR)/build/%, $(wildcard \ |
130 |
$(addprefix $(TOPDIR)/, .hg */.hg */*/.hg */*/*/.hg */*/*/*/.hg) \ |
|
51676
5a1be00ea4f6
8210283: Support git as an SCM alternative in the build
erikj
parents:
51069
diff
changeset
|
131 |
$(addprefix $(TOPDIR)/, .git */.git */*/.git */*/*/.git */*/*/*/.git) \ |
39110
712f29ba8708
8136771: Implement the license-swap logic as a make target
erikj
parents:
37972
diff
changeset
|
132 |
))))) |
712f29ba8708
8136771: Implement the license-swap logic as a make target
erikj
parents:
37972
diff
changeset
|
133 |
|
42282
faf3b6722c44
8031567: Better model for storing source revision information
ihse
parents:
42134
diff
changeset
|
134 |
# Locate all hg repositories included in the forest, as relative paths |
39110
712f29ba8708
8136771: Implement the license-swap logic as a make target
erikj
parents:
37972
diff
changeset
|
135 |
FindAllReposRel = \ |
47217 | 136 |
$(strip $(subst $(TOPDIR)/,.,$(patsubst $(TOPDIR)/%/, %, $(FindAllReposAbs)))) |
12801 | 137 |
|
35008 | 138 |
################################################################################ |
139 |
||
12801 | 140 |
define SetupLogging |
44465
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
44027
diff
changeset
|
141 |
ifeq ($$(LOG_PROFILE_TIMES_FILE), true) |
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
44027
diff
changeset
|
142 |
ifeq ($$(IS_GNU_TIME), yes) |
47217 | 143 |
SHELL := $$(BASH) $$(TOPDIR)/make/scripts/shell-profiler.sh \ |
44465
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
44027
diff
changeset
|
144 |
gnutime $$(TIME) \ |
47253
92fd0e04e0e1
8187544: Replace BUILD_OUTPUT and OUTPUT_ROOT with OUTPUTDIR
ihse
parents:
47217
diff
changeset
|
145 |
$$(OUTPUTDIR)/build-profile.log $$(SHELL) |
44465
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
44027
diff
changeset
|
146 |
else ifneq ($$(FLOCK), ) |
47217 | 147 |
SHELL := $$(BASH) $$(TOPDIR)/make/scripts/shell-profiler.sh \ |
44465
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
44027
diff
changeset
|
148 |
flock $$(FLOCK) \ |
47253
92fd0e04e0e1
8187544: Replace BUILD_OUTPUT and OUTPUT_ROOT with OUTPUTDIR
ihse
parents:
47217
diff
changeset
|
149 |
$$(OUTPUTDIR)/build-profile.log $$(SHELL) |
44465
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
44027
diff
changeset
|
150 |
endif |
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
44027
diff
changeset
|
151 |
endif |
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
44027
diff
changeset
|
152 |
|
29662 | 153 |
ifeq ($$(LOG_LEVEL), trace) |
44465
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
44027
diff
changeset
|
154 |
SHELL_NO_RECURSE := $$(SHELL) |
20363 | 155 |
# Shell redefinition trick inspired by http://www.cmcrossroads.com/ask-mr-make/6535-tracing-rule-execution-in-gnu-make |
156 |
# For each target executed, will print |
|
157 |
# Building <TARGET> (from <FIRST PREREQUISITE>) (<ALL NEWER PREREQUISITES> newer) |
|
158 |
# but with a limit of 20 on <ALL NEWER PREREQUISITES>, to avoid cluttering logs too much |
|
159 |
# (and causing a crash on Cygwin). |
|
44465
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
44027
diff
changeset
|
160 |
SHELL = $$(warning $$(if $$@,Building $$@,Running shell command) $$(if $$<, (from $$<))$$(if $$?, ($$(wordlist 1, 20, $$?) $$(if $$(wordlist 21, 22, $$?), ... [in total $$(words $$?) files]) newer)))$$(SHELL_NO_RECURSE) -x |
20363 | 161 |
endif |
44465
26fabd8abee9
8177770: Need more precise control on build system logging
asemenyuk
parents:
44027
diff
changeset
|
162 |
|
55292
f4b2d5b83ebf
8217739: Cannot reuse java.base UnixConstants.java from target in BuildJDK when cross compiling
erikj
parents:
55166
diff
changeset
|
163 |
# The LOG_PREFIX is set for sub recursive calls like buildjdk and bootcycle. |
35444 | 164 |
# The warn level can never be turned off |
55292
f4b2d5b83ebf
8217739: Cannot reuse java.base UnixConstants.java from target in BuildJDK when cross compiling
erikj
parents:
55166
diff
changeset
|
165 |
LogWarn = $$(info $(LOG_PREFIX)$$(strip $$1)) |
29662 | 166 |
LOG_WARN := |
167 |
ifneq ($$(findstring $$(LOG_LEVEL), info debug trace),) |
|
55292
f4b2d5b83ebf
8217739: Cannot reuse java.base UnixConstants.java from target in BuildJDK when cross compiling
erikj
parents:
55166
diff
changeset
|
168 |
LogInfo = $$(info $(LOG_PREFIX)$$(strip $$1)) |
29662 | 169 |
LOG_INFO := |
20363 | 170 |
else |
34596
e8328ce5b64e
8142907: Integration of minor fixes from the build-infra project
ihse
parents:
33394
diff
changeset
|
171 |
LogInfo = |
29662 | 172 |
LOG_INFO := > /dev/null |
20363 | 173 |
endif |
29662 | 174 |
ifneq ($$(findstring $$(LOG_LEVEL), debug trace),) |
55292
f4b2d5b83ebf
8217739: Cannot reuse java.base UnixConstants.java from target in BuildJDK when cross compiling
erikj
parents:
55166
diff
changeset
|
175 |
LogDebug = $$(info $(LOG_PREFIX)$$(strip $$1)) |
29662 | 176 |
LOG_DEBUG := |
20363 | 177 |
else |
34596
e8328ce5b64e
8142907: Integration of minor fixes from the build-infra project
ihse
parents:
33394
diff
changeset
|
178 |
LogDebug = |
29662 | 179 |
LOG_DEBUG := > /dev/null |
20363 | 180 |
endif |
29662 | 181 |
ifneq ($$(findstring $$(LOG_LEVEL), trace),) |
55292
f4b2d5b83ebf
8217739: Cannot reuse java.base UnixConstants.java from target in BuildJDK when cross compiling
erikj
parents:
55166
diff
changeset
|
182 |
LogTrace = $$(info $(LOG_PREFIX)$$(strip $$1)) |
29662 | 183 |
LOG_TRACE := |
20363 | 184 |
else |
34596
e8328ce5b64e
8142907: Integration of minor fixes from the build-infra project
ihse
parents:
33394
diff
changeset
|
185 |
LogTrace = |
29662 | 186 |
LOG_TRACE := > /dev/null |
20363 | 187 |
endif |
12801 | 188 |
endef |
189 |
||
190 |
# Make sure logging is setup for everyone that includes MakeBase.gmk. |
|
191 |
$(eval $(call SetupLogging)) |
|
192 |
||
29312
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
193 |
################################################################################ |
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
194 |
|
49024
953b3fd36b08
8196997: VS2017 The non-Standard std::tr1 namespace and TR1-only machinery are deprecated and will be removed
lfoltan
parents:
48078
diff
changeset
|
195 |
MAX_PARAMS := 36 |
29312
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
196 |
PARAM_SEQUENCE := $(call sequence, 2, $(MAX_PARAMS)) |
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
197 |
|
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
198 |
# Template for creating a macro taking named parameters. To use it, assign the |
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
199 |
# template to a variable with the name you want for your macro, using '=' |
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
200 |
# assignment. Then define a macro body with the suffix "Body". The Body macro |
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
201 |
# should take 1 parameter which should be a unique string for that invocation |
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
202 |
# of the macro. |
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
203 |
# Ex: |
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
204 |
# SetupFoo = $(NamedParamsMacroTemplate) |
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
205 |
# define SetupFooBody |
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
206 |
# # do something |
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
207 |
# # access parameters as $$($1_BAR) |
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
208 |
# endef |
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
209 |
# Call it like this |
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
210 |
# $(eval $(call SetupFoo, BUILD_SOMETHING, \ |
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
211 |
# BAR := some parameter value, \ |
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
212 |
# )) |
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
213 |
define NamedParamsMacroTemplate |
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
214 |
$(if $($(MAX_PARAMS)),$(error Internal makefile error: \ |
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
215 |
Too many named arguments to macro, please update MAX_PARAMS in MakeBase.gmk)) |
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
216 |
# Iterate over 2 3 4... and evaluate the named parameters with $1_ as prefix |
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
217 |
$(foreach i,$(PARAM_SEQUENCE), $(if $(strip $($i)),\ |
43044 | 218 |
$(strip $1)_$(strip $(call EscapeHash, $(call DoubleDollar, $($i))))$(NEWLINE))) |
29312
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
219 |
# Debug print all named parameter names and values |
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
220 |
$(if $(findstring $(LOG_LEVEL),debug trace), \ |
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
221 |
$(info $0 $(strip $1) $(foreach i,$(PARAM_SEQUENCE), \ |
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
222 |
$(if $(strip $($i)),$(NEWLINE) $(strip [$i] $(if $(filter $(LOG_LEVEL), trace), \ |
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
223 |
$($i), $(wordlist 1, 20, $($(i))) $(if $(word 21, $($(i))), ...))))))) |
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
224 |
|
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
225 |
$(if $(DEBUG_$(strip $1)), |
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
226 |
$(info -------- <<< Begin expansion of $(strip $1)) \ |
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
227 |
$(info $(call $(0)Body,$(strip $1))) \ |
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
228 |
$(info -------- >>> End expansion of $(strip $1)) \ |
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
229 |
) |
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
230 |
|
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
231 |
$(call $(0)Body,$(strip $1)) |
14111 | 232 |
endef |
233 |
||
29312
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
234 |
################################################################################ |
47751
f7e430cbfe34
8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents:
47715
diff
changeset
|
235 |
# Make directory without forking mkdir if not needed. |
f7e430cbfe34
8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents:
47715
diff
changeset
|
236 |
# |
f7e430cbfe34
8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents:
47715
diff
changeset
|
237 |
# If a directory with an encoded space is provided, the wildcard function |
f7e430cbfe34
8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents:
47715
diff
changeset
|
238 |
# sometimes returns false answers (typically if the dir existed when the |
f7e430cbfe34
8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents:
47715
diff
changeset
|
239 |
# makefile was parsed, but was deleted by a previous rule). In that case, always |
f7e430cbfe34
8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents:
47715
diff
changeset
|
240 |
# call mkdir regardless of what wildcard says. |
f7e430cbfe34
8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents:
47715
diff
changeset
|
241 |
# |
35008 | 242 |
# 1: List of directories to create |
28600
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
243 |
MakeDir = \ |
35444 | 244 |
$(strip \ |
47751
f7e430cbfe34
8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents:
47715
diff
changeset
|
245 |
$(eval MakeDir_dirs_to_make := $(strip $(foreach d, $1, \ |
f7e430cbfe34
8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents:
47715
diff
changeset
|
246 |
$(if $(findstring ?, $d), '$(call DecodeSpace, $d)', \ |
f7e430cbfe34
8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents:
47715
diff
changeset
|
247 |
$(if $(wildcard $d), , $d) \ |
f7e430cbfe34
8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents:
47715
diff
changeset
|
248 |
) \ |
f7e430cbfe34
8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents:
47715
diff
changeset
|
249 |
))) \ |
35444 | 250 |
$(if $(MakeDir_dirs_to_make), $(shell $(MKDIR) -p $(MakeDir_dirs_to_make))) \ |
251 |
) |
|
14111 | 252 |
|
47751
f7e430cbfe34
8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents:
47715
diff
changeset
|
253 |
# Make directory for target file. Should handle spaces in filenames. Just |
f7e430cbfe34
8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents:
47715
diff
changeset
|
254 |
# calling $(call MakeDir $(@D)) will not work if the directory contains a space |
f7e430cbfe34
8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents:
47715
diff
changeset
|
255 |
# and the target file already exists. In that case, the target file will have |
f7e430cbfe34
8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents:
47715
diff
changeset
|
256 |
# its wildcard ? resolved and the $(@D) will evaluate each space separated dir |
f7e430cbfe34
8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents:
47715
diff
changeset
|
257 |
# part on its own. |
f7e430cbfe34
8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents:
47715
diff
changeset
|
258 |
MakeTargetDir = \ |
f7e430cbfe34
8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents:
47715
diff
changeset
|
259 |
$(call MakeDir, $(dir $(call EncodeSpace, $@))) |
f7e430cbfe34
8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents:
47715
diff
changeset
|
260 |
|
29312
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
261 |
################################################################################ |
47334
09d386ddaa42
8189095: Import JMC from artifactory using Jib and main makefiles
erikj
parents:
47314
diff
changeset
|
262 |
# All install-file and related macros automatically call DecodeSpace when needed. |
29312
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
263 |
|
53683 | 264 |
ifeq ($(call isTargetOs, solaris), true) |
20363 | 265 |
# On Solaris, if the target is a symlink and exists, cp won't overwrite. |
266 |
# Cp has to operate in recursive mode to allow for -P flag, to preserve soft links. If the |
|
267 |
# name of the target file differs from the source file, rename after copy. |
|
23168
d20a4165e3d2
8036948: Solaris builds broken by fix for 8036611: Cleanup of handling of properties ...
erikj
parents:
21759
diff
changeset
|
268 |
# If the source and target parent directories are the same, recursive copy doesn't work |
d20a4165e3d2
8036948: Solaris builds broken by fix for 8036611: Cleanup of handling of properties ...
erikj
parents:
21759
diff
changeset
|
269 |
# so we fall back on regular copy, which isn't preserving symlinks. |
20363 | 270 |
define install-file |
47751
f7e430cbfe34
8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents:
47715
diff
changeset
|
271 |
$(call MakeTargetDir) |
47348
504e70cd64ad
8189324: install-file macro no longer handles files with $ in them
erikj
parents:
47334
diff
changeset
|
272 |
$(RM) '$(call DecodeSpace, $@)' |
49205
d1a19a08389a
8199428: install-file macro fails on filenames with space on Solaris
erikj
parents:
49067
diff
changeset
|
273 |
if [ '$(call DecodeSpace, $(dir $(call EncodeSpace, $@)))' != \ |
47348
504e70cd64ad
8189324: install-file macro no longer handles files with $ in them
erikj
parents:
47334
diff
changeset
|
274 |
'$(call DecodeSpace, $(dir $(call EncodeSpace, $<)))' ]; then \ |
49205
d1a19a08389a
8199428: install-file macro fails on filenames with space on Solaris
erikj
parents:
49067
diff
changeset
|
275 |
$(CP) -f -r -P '$(call DecodeSpace, $<)' \ |
d1a19a08389a
8199428: install-file macro fails on filenames with space on Solaris
erikj
parents:
49067
diff
changeset
|
276 |
'$(call DecodeSpace, $(dir $(call EncodeSpace, $@)))'; \ |
d1a19a08389a
8199428: install-file macro fails on filenames with space on Solaris
erikj
parents:
49067
diff
changeset
|
277 |
if [ '$(call DecodeSpace, $(notdir $(call EncodeSpace, $@)))' != \ |
47348
504e70cd64ad
8189324: install-file macro no longer handles files with $ in them
erikj
parents:
47334
diff
changeset
|
278 |
'$(call DecodeSpace, $(notdir $(call EncodeSpace, $(<))))' ]; then \ |
49205
d1a19a08389a
8199428: install-file macro fails on filenames with space on Solaris
erikj
parents:
49067
diff
changeset
|
279 |
$(MV) '$(call DecodeSpace, $(dir $(call EncodeSpace, $@))/$(notdir $(call EncodeSpace, $<)))' \ |
d1a19a08389a
8199428: install-file macro fails on filenames with space on Solaris
erikj
parents:
49067
diff
changeset
|
280 |
'$(call DecodeSpace, $@)'; \ |
23168
d20a4165e3d2
8036948: Solaris builds broken by fix for 8036611: Cleanup of handling of properties ...
erikj
parents:
21759
diff
changeset
|
281 |
fi; \ |
d20a4165e3d2
8036948: Solaris builds broken by fix for 8036611: Cleanup of handling of properties ...
erikj
parents:
21759
diff
changeset
|
282 |
else \ |
47348
504e70cd64ad
8189324: install-file macro no longer handles files with $ in them
erikj
parents:
47334
diff
changeset
|
283 |
if [ -L '$(call DecodeSpace, $<)' ]; then \ |
23168
d20a4165e3d2
8036948: Solaris builds broken by fix for 8036611: Cleanup of handling of properties ...
erikj
parents:
21759
diff
changeset
|
284 |
$(ECHO) "Source file is a symlink and target is in the same directory: $< $@" ; \ |
d20a4165e3d2
8036948: Solaris builds broken by fix for 8036611: Cleanup of handling of properties ...
erikj
parents:
21759
diff
changeset
|
285 |
exit 1; \ |
d20a4165e3d2
8036948: Solaris builds broken by fix for 8036611: Cleanup of handling of properties ...
erikj
parents:
21759
diff
changeset
|
286 |
fi; \ |
47348
504e70cd64ad
8189324: install-file macro no longer handles files with $ in them
erikj
parents:
47334
diff
changeset
|
287 |
$(CP) -f '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)'; \ |
23168
d20a4165e3d2
8036948: Solaris builds broken by fix for 8036611: Cleanup of handling of properties ...
erikj
parents:
21759
diff
changeset
|
288 |
fi |
20363 | 289 |
endef |
53683 | 290 |
else ifeq ($(call isTargetOs, macosx), true) |
20363 | 291 |
# On mac, extended attributes sometimes creep into the source files, which may later |
292 |
# cause the creation of ._* files which confuses testing. Clear these with xattr if |
|
293 |
# set. Some files get their write permissions removed after being copied to the |
|
294 |
# output dir. When these are copied again to images, xattr would fail. By only clearing |
|
295 |
# attributes when they are present, failing on this is avoided. |
|
37972 | 296 |
# |
297 |
# If copying a soft link to a directory, need to delete the target first to avoid |
|
298 |
# weird errors. |
|
20363 | 299 |
define install-file |
47751
f7e430cbfe34
8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents:
47715
diff
changeset
|
300 |
$(call MakeTargetDir) |
47348
504e70cd64ad
8189324: install-file macro no longer handles files with $ in them
erikj
parents:
47334
diff
changeset
|
301 |
$(RM) '$(call DecodeSpace, $@)' |
48912 | 302 |
# Work around a weirdness with cp on Macosx. When copying a symlink, if |
303 |
# the target of the link is write protected (e.g. 444), cp will add |
|
304 |
# write permission for the user on the target file (644). Avoid this by |
|
305 |
# using ln to create a new link instead. |
|
306 |
if [ -h '$(call DecodeSpace, $<)' ]; then \ |
|
307 |
$(LN) -s "`$(READLINK) '$(call DecodeSpace, $<)'`" '$(call DecodeSpace, $@)'; \ |
|
308 |
else \ |
|
309 |
$(CP) -fRP '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)'; \ |
|
310 |
fi |
|
311 |
if [ -n "`$(XATTR) -ls '$(call DecodeSpace, $@)'`" ]; then \ |
|
312 |
$(XATTR) -cs '$(call DecodeSpace, $@)'; \ |
|
313 |
fi |
|
20363 | 314 |
endef |
14111 | 315 |
else |
20363 | 316 |
define install-file |
47751
f7e430cbfe34
8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents:
47715
diff
changeset
|
317 |
$(call MakeTargetDir) |
47348
504e70cd64ad
8189324: install-file macro no longer handles files with $ in them
erikj
parents:
47334
diff
changeset
|
318 |
$(CP) -fP '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)' |
20363 | 319 |
endef |
14111 | 320 |
endif |
321 |
||
42425 | 322 |
# Variant of install file that does not preserve symlinks |
323 |
define install-file-nolink |
|
47751
f7e430cbfe34
8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents:
47715
diff
changeset
|
324 |
$(call MakeTargetDir) |
47348
504e70cd64ad
8189324: install-file macro no longer handles files with $ in them
erikj
parents:
47334
diff
changeset
|
325 |
$(CP) -f '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)' |
42425 | 326 |
endef |
327 |
||
29312
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
328 |
################################################################################ |
41658
14de1ab85d25
8062810: Examine src.zip in JDK image and decide if source classes should be organized by module
erikj
parents:
41260
diff
changeset
|
329 |
# link-file-* works similarly to install-file but creates a symlink instead. |
14de1ab85d25
8062810: Examine src.zip in JDK image and decide if source classes should be organized by module
erikj
parents:
41260
diff
changeset
|
330 |
# There are two versions, either creating a relative or an absolute link. Be |
14de1ab85d25
8062810: Examine src.zip in JDK image and decide if source classes should be organized by module
erikj
parents:
41260
diff
changeset
|
331 |
# careful when using this on Windows since the symlink created is only valid in |
14de1ab85d25
8062810: Examine src.zip in JDK image and decide if source classes should be organized by module
erikj
parents:
41260
diff
changeset
|
332 |
# the unix emulation environment. |
14de1ab85d25
8062810: Examine src.zip in JDK image and decide if source classes should be organized by module
erikj
parents:
41260
diff
changeset
|
333 |
define link-file-relative |
47751
f7e430cbfe34
8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents:
47715
diff
changeset
|
334 |
$(call MakeTargetDir) |
47348
504e70cd64ad
8189324: install-file macro no longer handles files with $ in them
erikj
parents:
47334
diff
changeset
|
335 |
$(RM) '$(call DecodeSpace, $@)' |
504e70cd64ad
8189324: install-file macro no longer handles files with $ in them
erikj
parents:
47334
diff
changeset
|
336 |
$(LN) -s '$(call DecodeSpace, $(call RelativePath, $<, $(@D)))' '$(call DecodeSpace, $@)' |
41658
14de1ab85d25
8062810: Examine src.zip in JDK image and decide if source classes should be organized by module
erikj
parents:
41260
diff
changeset
|
337 |
endef |
41260 | 338 |
|
41658
14de1ab85d25
8062810: Examine src.zip in JDK image and decide if source classes should be organized by module
erikj
parents:
41260
diff
changeset
|
339 |
define link-file-absolute |
47751
f7e430cbfe34
8190702: JMC packaging causing errors in JDK 10 consolidated repo (macOS)
erikj
parents:
47715
diff
changeset
|
340 |
$(call MakeTargetDir) |
47348
504e70cd64ad
8189324: install-file macro no longer handles files with $ in them
erikj
parents:
47334
diff
changeset
|
341 |
$(RM) '$(call DecodeSpace, $@)' |
504e70cd64ad
8189324: install-file macro no longer handles files with $ in them
erikj
parents:
47334
diff
changeset
|
342 |
$(LN) -s '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)' |
41658
14de1ab85d25
8062810: Examine src.zip in JDK image and decide if source classes should be organized by module
erikj
parents:
41260
diff
changeset
|
343 |
endef |
41260 | 344 |
|
345 |
################################################################################ |
|
29312
f3f859137ce6
8074988: Reduce boilerplate in Setup* macro definitions
erikj
parents:
29304
diff
changeset
|
346 |
|
54380 | 347 |
# Recursive wildcard function. Walks down directories recursively and matches |
348 |
# files with the search patterns. Patterns use standard file wildcards (* and |
|
349 |
# ?). |
|
350 |
# |
|
351 |
# $1 - Directories to start search in |
|
352 |
# $2 - Search patterns |
|
353 |
rwildcard = \ |
|
354 |
$(strip \ |
|
355 |
$(foreach d, \ |
|
356 |
$(patsubst %/,%,$(sort $(dir $(wildcard $(addsuffix /*/*, $(strip $1)))))), \ |
|
357 |
$(call rwildcard,$d,$2) \ |
|
358 |
) \ |
|
359 |
$(call DoubleDollar, $(wildcard $(foreach p, $2, $(addsuffix /$(strip $p), $(strip $1))))) \ |
|
360 |
) |
|
361 |
||
362 |
# Find non directories using recursive wildcard function. This function may |
|
363 |
# be used directly when a small amount of directories is expected to be |
|
364 |
# searched and caching is not expected to be of use. |
|
365 |
# |
|
366 |
# $1 - Directory to start search in |
|
367 |
# $2 - Optional search patterns, defaults to '*'. |
|
368 |
WildcardFindFiles = \ |
|
369 |
$(sort $(strip \ |
|
370 |
$(eval WildcardFindFiles_result := $(call rwildcard,$(patsubst %/,%,$1),$(if $(strip $2),$2,*))) \ |
|
371 |
$(filter-out $(patsubst %/,%,$(sort $(dir $(WildcardFindFiles_result)))), \ |
|
372 |
$(WildcardFindFiles_result) \ |
|
373 |
) \ |
|
374 |
)) |
|
375 |
||
376 |
# Find non directories using the find utility in the shell. Safe to call for |
|
377 |
# non existing directories, or directories containing wildcards. |
|
378 |
# |
|
379 |
# Files containing space will get spaces replaced with ? because GNU Make |
|
380 |
# cannot handle lists of files with space in them. By using ?, make will match |
|
381 |
# the wildcard to space in many situations so we don't need to replace back |
|
382 |
# to space on every use. While not a complete solution it does allow some uses |
|
383 |
# of FindFiles to function with spaces in file names, including for |
|
384 |
# SetupCopyFiles. Unfortunately this does not work for WildcardFindFiles so |
|
385 |
# if files with spaces are anticipated, use ShellFindFiles directly. |
|
386 |
# |
|
387 |
# $1 - Directories to start search in. |
|
388 |
# $2 - Optional search patterns, empty means find everything. Patterns use |
|
389 |
# standard file wildcards (* and ?) and should not be quoted. |
|
390 |
# $3 - Optional options to find. |
|
391 |
ShellFindFiles = \ |
|
392 |
$(if $(wildcard $1), \ |
|
393 |
$(sort \ |
|
394 |
$(shell $(FIND) $3 $(patsubst %/,%,$(wildcard $1)) \( -type f -o -type l \) \ |
|
395 |
$(if $(strip $2), -a \( -name "$(firstword $2)" \ |
|
396 |
$(foreach p, $(filter-out $(firstword $2), $2), -o -name "$(p)") \)) \ |
|
397 |
| $(TR) ' ' '?' \ |
|
398 |
) \ |
|
399 |
) \ |
|
400 |
) |
|
15051
d32ad37472e6
8005540: build-infra: Improve incremental build speed on windows by caching find results
erikj
parents:
14279
diff
changeset
|
401 |
|
54380 | 402 |
# Find non directories using the method most likely to work best for the |
403 |
# current build host |
|
404 |
# |
|
405 |
# $1 - Directory to start search in |
|
406 |
# $2 - Optional search patterns, defaults to '*'. |
|
407 |
ifeq ($(OPENJDK_BUILD_OS)-$(RWILDCARD_WORKS), windows-true) |
|
408 |
DirectFindFiles = $(WildcardFindFiles) |
|
409 |
else |
|
410 |
DirectFindFiles = $(ShellFindFiles) |
|
411 |
endif |
|
25854 | 412 |
|
54380 | 413 |
# Finds files using a cache that is populated by FillFindCache below. If any of |
414 |
# the directories given have not been cached, DirectFindFiles is used for |
|
415 |
# everything. Caching is especially useful in Cygwin, where file finds are very |
|
416 |
# costly. |
|
417 |
# |
|
418 |
# $1 - Directories to start search in. |
|
419 |
# $2 - Optional search patterns. If used, no caching is done. |
|
420 |
CacheFindFiles_CACHED_DIRS := |
|
421 |
CacheFindFiles_CACHED_FILES := |
|
422 |
CacheFindFiles = \ |
|
423 |
$(if $2, \ |
|
424 |
$(call DirectFindFiles, $1, $2) \ |
|
425 |
, \ |
|
426 |
$(if $(filter-out $(addsuffix /%, $(CacheFindFiles_CACHED_DIRS)) \ |
|
427 |
$(CacheFindFiles_CACHED_DIRS), $1), \ |
|
428 |
$(call DirectFindFiles, $1) \ |
|
429 |
, \ |
|
430 |
$(filter $(addsuffix /%,$(patsubst %/,%,$1)) $1,$(CacheFindFiles_CACHED_FILES)) \ |
|
431 |
) \ |
|
432 |
) |
|
433 |
||
434 |
# Explicitly adds files to the find cache used by CacheFindFiles. |
|
435 |
# |
|
436 |
# $1 - Directories to start search in |
|
437 |
FillFindCache = \ |
|
438 |
$(eval CacheFindFiles_NEW_DIRS := $$(filter-out $$(addsuffix /%,\ |
|
439 |
$$(CacheFindFiles_CACHED_DIRS)) $$(CacheFindFiles_CACHED_DIRS), $1)) \ |
|
440 |
$(if $(CacheFindFiles_NEW_DIRS), \ |
|
441 |
$(eval CacheFindFiles_CACHED_DIRS += $$(patsubst %/,%,$$(CacheFindFiles_NEW_DIRS))) \ |
|
442 |
$(eval CacheFindFiles_CACHED_FILES := $$(sort $$(CacheFindFiles_CACHED_FILES) \ |
|
443 |
$$(call DirectFindFiles, $$(CacheFindFiles_NEW_DIRS)))) \ |
|
444 |
) |
|
445 |
||
446 |
# Findfiles is the default macro that should be used to find files in the file |
|
447 |
# system. This function does not always support files with spaces in the names. |
|
448 |
# If files with spaces are anticipated, use ShellFindFiles directly. |
|
449 |
# |
|
450 |
# $1 - Directories to start search in. |
|
451 |
# $2 - Optional search patterns, empty means find everything. Patterns use |
|
452 |
# standard file wildcards (* and ?) and should not be quoted. |
|
453 |
ifeq ($(DISABLE_CACHE_FIND), true) |
|
454 |
FindFiles = $(DirectFindFiles) |
|
23170
51e606ecede5
8037281: Improve CacheFind and enable on all platforms
erikj
parents:
23169
diff
changeset
|
455 |
else |
54380 | 456 |
FindFiles = $(CacheFindFiles) |
23170
51e606ecede5
8037281: Improve CacheFind and enable on all platforms
erikj
parents:
23169
diff
changeset
|
457 |
endif |
15051
d32ad37472e6
8005540: build-infra: Improve incremental build speed on windows by caching find results
erikj
parents:
14279
diff
changeset
|
458 |
|
d32ad37472e6
8005540: build-infra: Improve incremental build speed on windows by caching find results
erikj
parents:
14279
diff
changeset
|
459 |
################################################################################ |
44027 | 460 |
# FixPath |
461 |
# |
|
462 |
# On Windows, converts a path from cygwin/unix style (e.g. /bin/foo) into |
|
463 |
# "mixed mode" (e.g. c:/cygwin/bin/foo). On other platforms, return the path |
|
464 |
# unchanged. |
|
465 |
# This is normally not needed since we use the FIXPATH prefix for command lines, |
|
466 |
# but might be needed in certain circumstances. |
|
53683 | 467 |
ifeq ($(call isTargetOs, windows), true) |
44027 | 468 |
FixPath = \ |
469 |
$(shell $(CYGPATH) -m $1) |
|
470 |
else |
|
471 |
FixPath = \ |
|
472 |
$1 |
|
473 |
endif |
|
474 |
||
475 |
################################################################################ |
|
55166
2ae056696b15
8223678: Add Visual Studio Code workspace generation support (for native code)
rwestberg
parents:
54380
diff
changeset
|
476 |
# FixPathList |
2ae056696b15
8223678: Add Visual Studio Code workspace generation support (for native code)
rwestberg
parents:
54380
diff
changeset
|
477 |
# |
2ae056696b15
8223678: Add Visual Studio Code workspace generation support (for native code)
rwestberg
parents:
54380
diff
changeset
|
478 |
# On Windows, converts a cygwin/unix style path list (colon-separated) into |
2ae056696b15
8223678: Add Visual Studio Code workspace generation support (for native code)
rwestberg
parents:
54380
diff
changeset
|
479 |
# the native format (mixed mode, semicolon-separated). On other platforms, |
2ae056696b15
8223678: Add Visual Studio Code workspace generation support (for native code)
rwestberg
parents:
54380
diff
changeset
|
480 |
# return the path list unchanged. |
2ae056696b15
8223678: Add Visual Studio Code workspace generation support (for native code)
rwestberg
parents:
54380
diff
changeset
|
481 |
################################################################################ |
2ae056696b15
8223678: Add Visual Studio Code workspace generation support (for native code)
rwestberg
parents:
54380
diff
changeset
|
482 |
ifeq ($(call isTargetOs, windows), true) |
2ae056696b15
8223678: Add Visual Studio Code workspace generation support (for native code)
rwestberg
parents:
54380
diff
changeset
|
483 |
FixPathList = \ |
2ae056696b15
8223678: Add Visual Studio Code workspace generation support (for native code)
rwestberg
parents:
54380
diff
changeset
|
484 |
$(subst @,$(SPACE),$(subst $(SPACE),;,$(foreach entry,$(subst :,$(SPACE),\ |
2ae056696b15
8223678: Add Visual Studio Code workspace generation support (for native code)
rwestberg
parents:
54380
diff
changeset
|
485 |
$(subst $(SPACE),@,$(strip $1))),$(call FixPath, $(entry))))) |
2ae056696b15
8223678: Add Visual Studio Code workspace generation support (for native code)
rwestberg
parents:
54380
diff
changeset
|
486 |
else |
2ae056696b15
8223678: Add Visual Studio Code workspace generation support (for native code)
rwestberg
parents:
54380
diff
changeset
|
487 |
FixPathList = \ |
2ae056696b15
8223678: Add Visual Studio Code workspace generation support (for native code)
rwestberg
parents:
54380
diff
changeset
|
488 |
$1 |
2ae056696b15
8223678: Add Visual Studio Code workspace generation support (for native code)
rwestberg
parents:
54380
diff
changeset
|
489 |
endif |
2ae056696b15
8223678: Add Visual Studio Code workspace generation support (for native code)
rwestberg
parents:
54380
diff
changeset
|
490 |
|
2ae056696b15
8223678: Add Visual Studio Code workspace generation support (for native code)
rwestberg
parents:
54380
diff
changeset
|
491 |
################################################################################ |
28600
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
492 |
# DependOnVariable |
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
493 |
# |
29156
bd932374081c
8072842: Add support for building native JTReg tests
ihse
parents:
28906
diff
changeset
|
494 |
# This macro takes a variable name and puts the value in a file only if the |
bd932374081c
8072842: Add support for building native JTReg tests
ihse
parents:
28906
diff
changeset
|
495 |
# value has changed since last. The name of the file is returned. This can be |
28600
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
496 |
# used to create rule dependencies on make variable values. The following |
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
497 |
# example would get rebuilt if the value of SOME_VAR was changed: |
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
498 |
# |
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
499 |
# path/to/some-file: $(call DependOnVariable, SOME_VAR) |
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
500 |
# echo $(SOME_VAR) > $@ |
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
501 |
# |
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
502 |
# Note that leading and trailing white space in the value is ignored. |
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
503 |
# |
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
504 |
|
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
505 |
# Defines the sub directory structure to store variable value file in |
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
506 |
DependOnVariableDirName = \ |
36506 | 507 |
$(strip $(addsuffix $(if $(MODULE),/$(MODULE)), \ |
47217 | 508 |
$(subst $(TOPDIR)/,, $(if $(filter /%, $(firstword $(MAKEFILE_LIST))), \ |
28600
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
509 |
$(firstword $(MAKEFILE_LIST)), \ |
36506 | 510 |
$(CURDIR)/$(firstword $(MAKEFILE_LIST)))))) |
28600
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
511 |
|
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
512 |
# Defines the name of the file to store variable value in. Generates a name |
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
513 |
# unless parameter 2 is given. |
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
514 |
# Param 1 - Name of variable |
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
515 |
# Param 2 - (optional) name of file to store value in |
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
516 |
DependOnVariableFileName = \ |
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
517 |
$(strip $(if $(strip $2), $2, \ |
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
518 |
$(MAKESUPPORT_OUTPUTDIR)/vardeps/$(DependOnVariableDirName)/$(strip $1).vardeps)) |
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
519 |
|
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
520 |
# Does the actual work with parameters stripped. |
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
521 |
# If the file exists AND the contents is the same as the variable, do nothing |
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
522 |
# else print a new file. |
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
523 |
# Always returns the name of the file where the value was printed. |
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
524 |
# Param 1 - Name of variable |
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
525 |
# Param 2 - (optional) name of file to store value in |
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
526 |
DependOnVariableHelper = \ |
32807
20386e6d858f
8136385: Various build speed improvements for windows
erikj
parents:
32553
diff
changeset
|
527 |
$(strip \ |
20386e6d858f
8136385: Various build speed improvements for windows
erikj
parents:
32553
diff
changeset
|
528 |
$(eval -include $(call DependOnVariableFileName, $1, $2)) \ |
20386e6d858f
8136385: Various build speed improvements for windows
erikj
parents:
32553
diff
changeset
|
529 |
$(if $(call equals, $(strip $($1)), $(strip $($1_old))),,\ |
20386e6d858f
8136385: Various build speed improvements for windows
erikj
parents:
32553
diff
changeset
|
530 |
$(call MakeDir, $(dir $(call DependOnVariableFileName, $1, $2))) \ |
20386e6d858f
8136385: Various build speed improvements for windows
erikj
parents:
32553
diff
changeset
|
531 |
$(if $(findstring $(LOG_LEVEL), trace), \ |
20386e6d858f
8136385: Various build speed improvements for windows
erikj
parents:
32553
diff
changeset
|
532 |
$(info NewVariable $1: >$(strip $($1))<) \ |
20386e6d858f
8136385: Various build speed improvements for windows
erikj
parents:
32553
diff
changeset
|
533 |
$(info OldVariable $1: >$(strip $($1_old))<)) \ |
42134
bbcdb49521b1
8169860: Clean up and unify the refactored Javadoc generation
ihse
parents:
41875
diff
changeset
|
534 |
$(call WriteFile, $1_old:=$(call DoubleDollar,$(call EscapeHash,$($1))), \ |
33054
bcb9f5ea5761
8140484: Vardeps broken when variable value contains '$'
erikj
parents:
32812
diff
changeset
|
535 |
$(call DependOnVariableFileName, $1, $2))) \ |
32807
20386e6d858f
8136385: Various build speed improvements for windows
erikj
parents:
32553
diff
changeset
|
536 |
$(call DependOnVariableFileName, $1, $2) \ |
20386e6d858f
8136385: Various build speed improvements for windows
erikj
parents:
32553
diff
changeset
|
537 |
) |
28600
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
538 |
|
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
539 |
# Main macro |
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
540 |
# Param 1 - Name of variable |
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
541 |
# Param 2 - (optional) name of file to store value in |
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
542 |
DependOnVariable = \ |
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
543 |
$(call DependOnVariableHelper,$(strip $1),$(strip $2)) |
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
544 |
|
35444 | 545 |
# LogCmdlines is only intended to be used by ExecuteWithLog |
546 |
ifeq ($(LOG_CMDLINES), true) |
|
547 |
LogCmdlines = $(info $(strip $1)) |
|
548 |
else |
|
549 |
LogCmdlines = |
|
550 |
endif |
|
551 |
||
28600
09dd1740f176
8069261: Create make dependencies on make variable values
erikj
parents:
27595
diff
changeset
|
552 |
################################################################################ |
35444 | 553 |
# ExecuteWithLog will run a command and log the output appropriately. This is |
554 |
# meant to be used by commands that do "real" work, like a compilation. |
|
555 |
# The output is stored in a specified log file, which is displayed at the end |
|
556 |
# of the build in case of failure. The command line itself is stored in a file, |
|
557 |
# and also logged to stdout if the LOG=cmdlines option has been given. |
|
32344
0b288e0efcfa
8062618: Create a build failure summary at end of build log
ihse
parents:
31312
diff
changeset
|
558 |
# |
39607
ace2c0283dce
8158629: bash >(...) construct still causes race conditions
erikj
parents:
39110
diff
changeset
|
559 |
# NOTE: If the command redirects stdout, the caller needs to wrap it in a |
ace2c0283dce
8158629: bash >(...) construct still causes race conditions
erikj
parents:
39110
diff
changeset
|
560 |
# subshell (by adding parentheses around it), otherwise the redirect to the |
ace2c0283dce
8158629: bash >(...) construct still causes race conditions
erikj
parents:
39110
diff
changeset
|
561 |
# subshell tee process will create a race condition where the target file may |
ace2c0283dce
8158629: bash >(...) construct still causes race conditions
erikj
parents:
39110
diff
changeset
|
562 |
# not be fully written when the make recipe is done. |
ace2c0283dce
8158629: bash >(...) construct still causes race conditions
erikj
parents:
39110
diff
changeset
|
563 |
# |
35444 | 564 |
# Param 1 - The path to base the name of the log file / command line file on |
565 |
# Param 2 - The command to run |
|
566 |
ExecuteWithLog = \ |
|
567 |
$(call LogCmdlines, Exececuting: [$(strip $2)]) \ |
|
48912 | 568 |
$(call MakeDir, $(dir $(strip $1))) \ |
35444 | 569 |
$(call WriteFile, $2, $(strip $1).cmdline) \ |
51069
d5d5f6658b12
8207001: *.obj.log files get truncated causing unreliable incremental builds on Windows
erikj
parents:
50590
diff
changeset
|
570 |
( $(RM) $(strip $1).log && $(strip $2) > >($(TEE) -a $(strip $1).log) 2> >($(TEE) -a $(strip $1).log >&2) || \ |
35444 | 571 |
( exitcode=$(DOLLAR)? && \ |
47253
92fd0e04e0e1
8187544: Replace BUILD_OUTPUT and OUTPUT_ROOT with OUTPUTDIR
ihse
parents:
47217
diff
changeset
|
572 |
$(CP) $(strip $1).log $(MAKESUPPORT_OUTPUTDIR)/failure-logs/$(subst /,_,$(patsubst $(OUTPUTDIR)/%,%,$(strip $1))).log && \ |
92fd0e04e0e1
8187544: Replace BUILD_OUTPUT and OUTPUT_ROOT with OUTPUTDIR
ihse
parents:
47217
diff
changeset
|
573 |
$(CP) $(strip $1).cmdline $(MAKESUPPORT_OUTPUTDIR)/failure-logs/$(subst /,_,$(patsubst $(OUTPUTDIR)/%,%,$(strip $1))).cmdline && \ |
39607
ace2c0283dce
8158629: bash >(...) construct still causes race conditions
erikj
parents:
39110
diff
changeset
|
574 |
exit $(DOLLAR)exitcode ) ) |
32344
0b288e0efcfa
8062618: Create a build failure summary at end of build log
ihse
parents:
31312
diff
changeset
|
575 |
|
0b288e0efcfa
8062618: Create a build failure summary at end of build log
ihse
parents:
31312
diff
changeset
|
576 |
################################################################################ |
25854 | 577 |
|
578 |
# Hook to include the corresponding custom file, if present. |
|
47314 | 579 |
$(eval $(call IncludeCustomExtension, common/MakeBase.gmk)) |
25854 | 580 |
|
12258
6ec26f6cc53e
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
diff
changeset
|
581 |
endif # _MAKEBASE_GMK |