jdk

Форк
0
/
Utils.gmk 
400 строк · 15.4 Кб
1
#
2
# Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
3
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
#
5
# This code is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License version 2 only, as
7
# published by the Free Software Foundation.  Oracle designates this
8
# particular file as subject to the "Classpath" exception as provided
9
# by Oracle in the LICENSE file that accompanied this code.
10
#
11
# This code is distributed in the hope that it will be useful, but WITHOUT
12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14
# version 2 for more details (a copy is included in the LICENSE file that
15
# accompanied this code).
16
#
17
# You should have received a copy of the GNU General Public License version
18
# 2 along with this work; if not, write to the Free Software Foundation,
19
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
#
21
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
# or visit www.oracle.com if you need additional information or have any
23
# questions.
24
#
25

26
ifeq (,$(_MAKEBASE_GMK))
27
  $(error You must include MakeBase.gmk prior to including Utils.gmk)
28
endif
29

30
################################################################################
31
#
32
# Basic utility functions available to MakeBase.gmk itself
33
#
34
################################################################################
35

36
# String equals
37
equals = \
38
    $(if $(strip $1)$(strip $2),$(strip \
39
      $(and $(findstring $(strip $1),$(strip $2)),\
40
        $(findstring $(strip $2),$(strip $1)))), \
41
      true \
42
    )
43

44
# Convert the string given to upper case, without any $(shell)
45
# Inspired by http://lists.gnu.org/archive/html/help-make/2013-09/msg00009.html
46
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 \
47
    p,P q,Q r,R s,S t,T u,U v,V w,W x,X y,Y z,Z
48

49
uppercase_internal = \
50
  $(if $(strip $1), $$(subst $(firstword $1), $(call uppercase_internal, \
51
      $(wordlist 2, $(words $1), $1), $2)), $2)
52

53
# Convert a string to upper case. Works only on a-z.
54
# $1 - The string to convert
55
uppercase = \
56
  $(strip \
57
    $(eval uppercase_result := $(call uppercase_internal, $(uppercase_table), $1)) \
58
    $(uppercase_result) \
59
  )
60

61
################################################################################
62
# Creates a sequence of increasing numbers (inclusive).
63
# Param 1 - starting number
64
# Param 2 - ending number
65
sequence = \
66
    $(wordlist $1, $2, $(strip \
67
        $(eval SEQUENCE_COUNT :=) \
68
        $(call _sequence-do,$(strip $2))))
69

70
_sequence-do = \
71
    $(if $(word $1, $(SEQUENCE_COUNT)),, \
72
      $(eval SEQUENCE_COUNT += .) \
73
      $(words $(SEQUENCE_COUNT)) \
74
      $(call _sequence-do,$1))
75

76
################################################################################
77
# This macro translates $ into \$ to protect the $ from expansion in the shell.
78
# To make this macro resilient against already escaped strings, first remove
79
# any present escapes before escaping so that no double escapes are added.
80
EscapeDollar = $(subst $$,\$$,$(subst \$$,$$,$(strip $1)))
81

82
################################################################################
83
# This macro works just like EscapeDollar above, but for #.
84
EscapeHash = $(subst \#,\\\#,$(subst \\\#,\#,$(strip $1)))
85

86
################################################################################
87
# This macro translates $ into $$ to protect the string from make itself.
88
DoubleDollar = $(subst $$,$$$$,$(strip $1))
89

90
################################################################################
91
# ShellQuote
92
#
93
# Quotes a string with single quotes and replaces single quotes with '\'' so
94
# that the contents survives being given to the shell.
95
ShellQuote = \
96
    $(SQUOTE)$(subst $(SQUOTE),$(SQUOTE)\$(SQUOTE)$(SQUOTE),$(strip $1))$(SQUOTE)
97

98
################################################################################
99
# Write to and read from file
100

101
# Param 1 - File to read
102
ReadFile = \
103
    $(shell $(CAT) $1)
104

105
# Param 1 - Text to write
106
# Param 2 - File to write to
107
ifeq ($(HAS_FILE_FUNCTION), true)
108
  WriteFile = \
109
      $(file >$2,$(strip $1))
110
else
111
  # Use printf to get consistent behavior on all platforms.
112
  WriteFile = \
113
      $(shell $(PRINTF) "%s\n" $(strip $(call ShellQuote, $1)) > $2)
114
endif
115

116
# Param 1 - Text to write
117
# Param 2 - File to write to
118
ifeq ($(HAS_FILE_FUNCTION), true)
119
  AppendFile = \
120
      $(file >>$2,$(strip $1))
121
else
122
  # Use printf to get consistent behavior on all platforms.
123
  AppendFile = \
124
      $(shell $(PRINTF) "%s\n" $(strip $(call ShellQuote, $1)) >> $2)
125
endif
126

127
################################################################################
128
# Make directory without forking mkdir if not needed.
129
#
130
# If a directory with an encoded space is provided, the wildcard function
131
# sometimes returns false answers (typically if the dir existed when the
132
# makefile was parsed, but was deleted by a previous rule). In that case, always
133
# call mkdir regardless of what wildcard says.
134
#
135
# 1: List of directories to create
136
MakeDir = \
137
    $(strip \
138
        $(eval MakeDir_dirs_to_make := $(strip $(foreach d, $1, \
139
          $(if $(findstring ?, $d), '$(call DecodeSpace, $d)', \
140
            $(if $(wildcard $d), , $d) \
141
          ) \
142
        ))) \
143
        $(if $(MakeDir_dirs_to_make), $(shell $(MKDIR) -p $(MakeDir_dirs_to_make))) \
144
    )
145

146
################################################################################
147
# Check if our build or target conforms to certain restrictions. This set of
148
# functions all work in similar ways, testing the property that the name
149
# implies, so e.g. isTargetCpu test the CPU of the target system.
150
#
151
# $1 - A property, or a space separated list of properties to test for.
152
#
153
# Returns true if the actual property matches one of the properties in the list,
154
# and false otherwise.
155
#
156
# Examples: $(call isTargetOs, linux windows) will return true when executed
157
# on either linux or windows, and false otherwise.
158
# $(call isBuildCpuArch, x86) will return true iff the build CPU Arch is x86.
159

160
isTargetOs = \
161
  $(strip $(if $(filter $(OPENJDK_TARGET_OS), $1), true, false))
162

163
isTargetOsType = \
164
  $(strip $(if $(filter $(OPENJDK_TARGET_OS_TYPE), $1), true, false))
165

166
isTargetCpu = \
167
  $(strip $(if $(filter $(OPENJDK_TARGET_CPU), $1), true, false))
168

169
isTargetCpuArch = \
170
  $(strip $(if $(filter $(OPENJDK_TARGET_CPU_ARCH), $1), true, false))
171

172
isTargetCpuBits = \
173
  $(strip $(if $(filter $(OPENJDK_TARGET_CPU_BITS), $1), true, false))
174

175
isBuildOs = \
176
  $(strip $(if $(filter $(OPENJDK_BUILD_OS), $1), true, false))
177

178
isBuildOsType = \
179
  $(strip $(if $(filter $(OPENJDK_BUILD_OS_TYPE), $1), true, false))
180

181
isBuildOsEnv = \
182
  $(strip $(if $(filter $(OPENJDK_BUILD_OS_ENV), $1), true, false))
183

184
isBuildCpu = \
185
  $(strip $(if $(filter $(OPENJDK_BUILD_CPU), $1), true, false))
186

187
isBuildCpuArch = \
188
  $(strip $(if $(filter $(OPENJDK_BUILD_CPU_ARCH), $1), true, false))
189

190
isCompiler = \
191
  $(strip $(if $(filter $(TOOLCHAIN_TYPE), $1), true, false))
192

193
################################################################################
194
#
195
# Common utility functions
196
#
197
################################################################################
198

199
### Debug functions
200

201
# Prints the name and value of a variable
202
PrintVar = \
203
    $(info $(strip $1) >$($(strip $1))<)
204

205

206
################################################################################
207
# Strip both arguments. Append the first argument to the second argument. If the
208
# first argument is empty, return the empty string.
209
IfAppend = \
210
    $(if $(strip $1),$(strip $1)$(strip $2),)
211

212
################################################################################
213
# Assign a variable only if it is empty
214
# Param 1 - Variable to assign
215
# Param 2 - Value to assign
216
SetIfEmpty = \
217
    $(if $($(strip $1)),,$(eval $(strip $1) := $2))
218

219
################################################################################
220
# Filter out duplicate sub strings while preserving order. Keeps the first occurrence.
221
uniq = \
222
    $(strip $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1))))
223

224
# Returns all whitespace-separated words in $2 where at least one of the
225
# whitespace-separated words in $1 is a substring.
226
containing = \
227
    $(strip \
228
        $(foreach v,$(strip $2),\
229
          $(call uniq,$(foreach p,$(strip $1),$(if $(findstring $p,$v),$v)))))
230

231
# Returns all whitespace-separated words in $2 where none of the
232
# whitespace-separated words in $1 is a substring.
233
not-containing = \
234
    $(strip $(filter-out $(call containing,$1,$2),$2))
235

236
# Return a list of all string elements that are duplicated in $1.
237
dups = \
238
    $(strip $(foreach v, $(sort $1), $(if $(filter-out 1, \
239
        $(words $(filter $v, $1))), $v)))
240

241
# Remove a whole list of prefixes
242
# $1 - List of prefixes
243
# $2 - List of elements to process
244
remove-prefixes = \
245
    $(strip $(if $1,$(patsubst $(firstword $1)%,%,\
246
      $(call remove-prefixes,$(filter-out $(firstword $1),$1),$2)),$2))
247

248
################################################################################
249
# Boolean operators.
250

251
# Return the word "true" if all the boolean words given as argument is "true",
252
# and returns "false" otherwise. Boolean words must be "true" or "false". It is
253
# an error to supply a non-boolean word. An empty string is considered "true".
254
And = \
255
  $(strip $(if $(filter-out true false, $1), $(error Non-boolean values: $1)) \
256
  $(if $(strip $(filter-out true, $1)), false, true))
257

258
# Return the word "false" if all the boolean words given as argument is "false",
259
# and returns "true" otherwise. Boolean words must be "true" or "false". It is
260
# an error to supply a non-boolean word.  An empty string is considered "false".
261
Or = \
262
  $(strip $(if $(filter-out true false, $1), $(error Non-boolean values: $1)) \
263
  $(if $(strip $(filter-out false, $1)), true, false))
264

265

266
################################################################################
267
# Convert an UNIX epoch based timestamp (as an integer) to an ISO 8601 date
268
# string.
269
# Param 1 - timestamp
270
ifeq ($(IS_GNU_DATE), yes)
271
  EpochToISO8601 = \
272
    $(shell $(DATE) --utc --date="@$(strip $1)" \
273
         +"$(ISO_8601_FORMAT_STRING)" 2> /dev/null)
274
else
275
  EpochToISO8601 = \
276
    $(shell $(DATE) -u -j -f "%s" "$(strip $1)" \
277
         +"$(ISO_8601_FORMAT_STRING)" 2> /dev/null)
278
endif
279

280
################################################################################
281
# Parse a multiple-keyword variable, like FOO="KEYWORD1=val1;KEYWORD2=val2;..."
282
# These will be converted into a series of variables like FOO_KEYWORD1=val1,
283
# FOO_KEYWORD2=val2, etc. Unknown keywords will cause an error.
284
#
285
# Parameter 1 is the name of the rule, and is also the name of the variable.
286
#
287
# Remaining parameters are named arguments. These include:
288
#   SINGLE_KEYWORDS   A list of valid keywords with single string values
289
#   STRING_KEYWORDS   A list of valid keywords, processed as string. This means
290
#       that '%20' will be replaced by ' ' to allow for multi-word strings.
291
#
292
ParseKeywordVariable = $(NamedParamsMacroTemplate)
293
define ParseKeywordVariableBody
294
  ifneq ($$($1), )
295
    # To preserve spaces, substitute them with a hopefully unique pattern
296
    # before splitting and then re-substitute spaces back.
297
    $1_MANGLED := $$(subst $$(SPACE),||||,$$($1))
298
    $$(foreach mangled_part, $$(subst ;, , $$($1_MANGLED)), \
299
      $$(eval mangled_part_eval := $$(call DoubleDollar, $$(mangled_part))) \
300
      $$(eval part := $$$$(subst ||||,$$$$(SPACE),$$$$(mangled_part_eval))) \
301
      $$(eval $1_NO_MATCH := true) \
302
      $$(if $$(filter help, $$(part)), \
303
        $$(info Valid keywords for $1:) \
304
        $$(info $$($1_SINGLE_KEYWORDS) $$($1_STRING_KEYWORDS).) \
305
        $$(error Re-run without 'help' to continue)) \
306
      $$(foreach keyword, $$($1_SINGLE_KEYWORDS), \
307
        $$(eval keyword_eval := $$(call DoubleDollar, $$(keyword))) \
308
        $$(if $$(filter $$(keyword)=%, $$(part)), \
309
          $$(eval $(strip $1)_$$$$(keyword_eval) := $$$$(strip $$$$(patsubst $$$$(keyword_eval)=%, %, $$$$(part)))) \
310
          $$(eval $1_NO_MATCH := ) \
311
        ) \
312
      ) \
313
      $$(foreach keyword, $$($1_STRING_KEYWORDS), \
314
        $$(eval keyword_eval := $$(call DoubleDollar, $$(keyword))) \
315
        $$(if $$(filter $$(keyword)=%, $$(part)), \
316
          $$(eval $(strip $1)_$$$$(keyword_eval) := $$$$(strip $$$$(subst %20, , $$$$(patsubst $$$$(keyword_eval)=%, %, $$$$(part))))) \
317
          $$(eval $1_NO_MATCH := ) \
318
        ) \
319
      ) \
320
      $$(if $$($1_NO_MATCH), \
321
        $$(if $$(filter $$(part), $$($1_SINGLE_KEYWORDS) $$($1_STRING_KEYWORDS)), \
322
          $$(info Keyword $$(part) for $1 needs to be assigned a value.) \
323
        , \
324
          $$(info $$(part) is not a valid keyword for $1.) \
325
          $$(info Valid keywords: $$($1_SINGLE_KEYWORDS) $$($1_STRING_KEYWORDS).) \
326
        ) \
327
        $$(error Cannot continue) \
328
      ) \
329
    )
330
  endif
331
endef
332

333
################################################################################
334
# Find lib dir for module
335
# Param 1 - module name
336
FindLibDirForModule = \
337
    $(SUPPORT_OUTPUTDIR)/modules_libs/$(strip $1)
338

339
################################################################################
340
# Find executable dir for module
341
# Param 1 - module name
342
FindExecutableDirForModule = \
343
    $(SUPPORT_OUTPUTDIR)/modules_cmds/$(strip $1)
344

345
################################################################################
346
# Return a string suitable for use after a -classpath or --module-path option. It
347
# will be correct and safe to use on all platforms. Arguments are given as space
348
# separate classpath entries. Safe for multiple nested calls.
349
# param 1 : A space separated list of classpath entries
350
# The surrounding strip is needed to keep additional whitespace out
351
PathList = \
352
  "$(subst $(SPACE),:,$(strip $(subst $(DQUOTE),,$1)))"
353

354
################################################################################
355
# Check if a specified hotspot variant is being built, or at least one of a
356
# list of variants. Will return 'true' or 'false'.
357
# $1 - the variant to test for
358
check-jvm-variant = \
359
  $(strip \
360
    $(if $(filter-out $(VALID_JVM_VARIANTS), $1), \
361
      $(error Internal error: Invalid variant tested: $1)) \
362
    $(if $(filter $1, $(JVM_VARIANTS)), true, false))
363

364
################################################################################
365
# Converts a space separated list to a comma separated list.
366
#
367
# Replacing double-comma with a single comma is to workaround the issue with
368
# some version of make on windows that doesn't substitute spaces with one comma
369
# properly.
370
CommaList = \
371
  $(strip \
372
      $(subst $(COMMA)$(COMMA),$(COMMA),$(subst $(SPACE),$(COMMA),$(strip $1))) \
373
  )
374

375
################################################################################
376
# Converts a space separated list to a colon separated list.
377
#
378
# Replacing double-colon with a single colon is to workaround the issue with
379
# some version of make on windows that doesn't substitute spaces with one colon
380
# properly.
381
ColonList = \
382
  $(strip \
383
      $(subst ::,:,$(subst $(SPACE),:,$(strip $1))) \
384
  )
385

386
################################################################################
387
# Given a list of files, filters out locale specific files for translations
388
# that should be excluded from this build.
389
# $1 - The list of files to filter
390
# $2 - The suffix of the files that should be considered (.java or .properties)
391
FilterExcludedTranslations = \
392
  $(strip $(if $(EXCLUDE_TRANSLATIONS), \
393
    $(filter-out \
394
        $(foreach suffix, $2, \
395
          $(addprefix %_, $(addsuffix $(suffix), $(EXCLUDE_TRANSLATIONS))) \
396
        ), \
397
        $1 \
398
    ), \
399
    $1 \
400
  ))
401

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.