jdk

Форк
0
/
MakeBase.gmk 
318 строк · 12.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
################################################################
27
# MakeBase provides the core functionality needed and used by all makefiles. It
28
# should be included by all makefiles. MakeBase provides essential
29
# functionality for named parameter functions, variable dependency, tool
30
# execution, logging and fixpath functionality.
31
################################################################
32

33
ifndef _MAKEBASE_GMK
34
_MAKEBASE_GMK := 1
35

36
ifeq ($(wildcard $(SPEC)),)
37
  $(error MakeBase.gmk needs SPEC set to a proper spec.gmk)
38
endif
39

40
# By defining this pseudo target, make will automatically remove targets
41
# if their recipe fails so that a rebuild is automatically triggered on the
42
# next make invocation.
43
.DELETE_ON_ERROR:
44

45
################################################################################
46
# Definitions for special characters
47
################################################################################
48

49
# When calling macros, the spaces between arguments are
50
# often semantically important! Sometimes we need to subst
51
# spaces and commas, therefore we need the following macros.
52
X:=
53
SPACE:=$(X) $(X)
54
COMMA:=,
55
DOLLAR:=$$
56
HASH:=\#
57
LEFT_PAREN:=(
58
RIGHT_PAREN:=)
59
SQUOTE:='
60
#'
61
DQUOTE:="
62
#"
63
define NEWLINE
64

65

66
endef
67

68
# Certain features only work in newer version of GNU Make. The build will still
69
# function in 3.81, but will be less performant.
70
ifeq (4.0, $(firstword $(sort 4.0 $(MAKE_VERSION))))
71
  HAS_FILE_FUNCTION := true
72
  CORRECT_FUNCTION_IN_RECIPE_EVALUATION := true
73
  RWILDCARD_WORKS := true
74
endif
75

76
# For convenience, MakeBase.gmk continues to include these separate files, at
77
# least for now.
78
# Utils.gmk must be included before FileUtils.gmk, since it uses some of the
79
# basic utility functions there.
80
include $(TOPDIR)/make/common/Utils.gmk
81
include $(TOPDIR)/make/common/FileUtils.gmk
82

83
################################################################################
84
# Make sure we have a value (could be overridden on command line by caller)
85
CREATING_BUILDJDK ?= false
86

87
################################################################################
88

89
define SetupLogging
90
  ifeq ($$(LOG_PROFILE_TIMES_FILE), true)
91
    ifeq ($$(IS_GNU_TIME), yes)
92
      SHELL :=  $$(BASH) $$(TOPDIR)/make/scripts/shell-profiler.sh \
93
                gnutime $$(TIME) \
94
                $$(OUTPUTDIR)/build-profile.log $$(SHELL)
95
    else ifneq ($$(FLOCK), )
96
      SHELL :=  $$(BASH) $$(TOPDIR)/make/scripts/shell-profiler.sh \
97
                flock $$(FLOCK) \
98
                $$(OUTPUTDIR)/build-profile.log $$(SHELL)
99
    endif
100
  endif
101

102
  ifneq ($$(findstring $$(LOG_LEVEL), debug trace),)
103
    SHELL := $$(SHELL) -x
104
  endif
105

106
  ifeq ($$(LOG_LEVEL), trace)
107
    SHELL_NO_RECURSE := $$(SHELL)
108
    # Shell redefinition trick inspired by http://www.cmcrossroads.com/ask-mr-make/6535-tracing-rule-execution-in-gnu-make
109
    # For each target executed, will print
110
    # Building <TARGET> (from <FIRST PREREQUISITE>) (<ALL NEWER PREREQUISITES> newer)
111
    # but with a limit of 20 on <ALL NEWER PREREQUISITES>, to avoid cluttering logs too much
112
    # (and causing a crash on Cygwin).
113
    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
114
  endif
115

116
  # The LOG_PREFIX is set for sub recursive calls like buildjdk and bootcycle.
117
  # The warn level can never be turned off
118
  LogWarn = $$(info $(LOG_PREFIX)$$(strip $$1))
119
  LOG_WARN :=
120
  ifneq ($$(findstring $$(LOG_LEVEL), info debug trace),)
121
    LogInfo = $$(info $(LOG_PREFIX)$$(strip $$1))
122
    LOG_INFO :=
123
  else
124
    LogInfo =
125
    LOG_INFO := > /dev/null
126
  endif
127
  ifneq ($$(findstring $$(LOG_LEVEL), debug trace),)
128
    LogDebug = $$(info $(LOG_PREFIX)$$(strip $$1))
129
    LOG_DEBUG :=
130
  else
131
    LogDebug =
132
    LOG_DEBUG := > /dev/null
133
  endif
134
  ifneq ($$(findstring $$(LOG_LEVEL), trace),)
135
    LogTrace = $$(info $(LOG_PREFIX)$$(strip $$1))
136
    LOG_TRACE :=
137
  else
138
    LogTrace =
139
    LOG_TRACE := > /dev/null
140
  endif
141
endef
142

143
# Make sure logging is setup for everyone that includes MakeBase.gmk.
144
$(eval $(call SetupLogging))
145

146
################################################################################
147

148
MAX_PARAMS := 96
149
PARAM_SEQUENCE := $(call sequence, 2, $(MAX_PARAMS))
150

151
# Template for creating a macro taking named parameters. To use it, assign the
152
# template to a variable with the name you want for your macro, using '='
153
# assignment. Then define a macro body with the suffix "Body". The Body macro
154
# should take 1 parameter which should be a unique string for that invocation
155
# of the macro.
156
# Ex:
157
# SetupFoo = $(NamedParamsMacroTemplate)
158
# define SetupFooBody
159
#   # do something
160
#   # access parameters as $$($1_BAR)
161
# endef
162
# Call it like this
163
# $(eval $(call SetupFoo, BUILD_SOMETHING, \
164
#     BAR := some parameter value, \
165
# ))
166
define NamedParamsMacroTemplate
167
  $(if $($(MAX_PARAMS)),$(error Internal makefile error: \
168
      Too many named arguments to macro, please update MAX_PARAMS in MakeBase.gmk))
169
  # Iterate over 2 3 4... and evaluate the named parameters with $1_ as prefix
170
  $(foreach i,$(PARAM_SEQUENCE), $(if $(strip $($i)),\
171
    $(strip $1)_$(strip $(call EscapeHash, $(call DoubleDollar, $($i))))$(NEWLINE)))
172
  # Debug print all named parameter names and values
173
  $(if $(findstring $(LOG_LEVEL), trace), \
174
    $(info $0 $(strip $1) $(foreach i,$(PARAM_SEQUENCE), \
175
      $(if $(strip $($i)),$(NEWLINE) $(strip [$i] $(if $(filter $(LOG_LEVEL), trace), \
176
        $($i), $(wordlist 1, 20, $($(i))) $(if $(word 21, $($(i))), ...)))))))
177

178
  $(if $(DEBUG_$(strip $1)),
179
    $(info -------- <<< Begin expansion of $(strip $1)) \
180
    $(info $(call $(0)Body,$(strip $1))) \
181
    $(info -------- >>> End expansion of $(strip $1)) \
182
  )
183

184
  $(call $(0)Body,$(strip $1))
185
endef
186

187
################################################################################
188
# FixPath
189
#
190
# On Windows, converts a path from cygwin/unix style (e.g. /bin/foo) into
191
# "mixed mode" (e.g. c:/cygwin/bin/foo). On other platforms, return the path
192
# unchanged.
193
# This also converts a colon-separated list of paths to a semicolon-separated
194
# list.
195
# This is normally not needed since we use the FIXPATH prefix for command lines,
196
# but might be needed in certain circumstances.
197
#
198
# FixPathFile is the file version of FixPath. It instead takes a file with paths in $1
199
# and outputs the 'fixed' paths into the file in $2. If the file in $2 already exists
200
# it is overwritten.
201
# On non-Windows platforms this instead does a copy, so that $2 can still be used
202
# as a depenendency of a make rule, instead of having to conditionally depend on
203
# $1 instead, based on the target platform.
204
ifeq ($(call isTargetOs, windows), true)
205
  FixPath = \
206
    $(strip $(subst \,\\, $(shell $(FIXPATH_BASE) print $(patsubst $(FIXPATH), , $1))))
207
  FixPathFile = \
208
    $(shell $(FIXPATH_BASE) convert $1 $2)
209
else
210
  FixPath = \
211
      $1
212
  FixPathFile = \
213
      $(shell $(CP) $1 $2)
214
endif
215

216
################################################################################
217
# DependOnVariable
218
#
219
# This macro takes a variable name and puts the value in a file only if the
220
# value has changed since last. The name of the file is returned. This can be
221
# used to create rule dependencies on make variable values. The following
222
# example would get rebuilt if the value of SOME_VAR was changed:
223
#
224
# path/to/some-file: $(call DependOnVariable, SOME_VAR)
225
#         echo $(SOME_VAR) > $@
226
#
227
# Note that leading and trailing white space in the value is ignored.
228
#
229

230
# Defines the sub directory structure to store variable value file in
231
DependOnVariableDirName = \
232
    $(strip $(addsuffix $(if $(MODULE),/$(MODULE)), \
233
        $(subst $(WORKSPACE_ROOT)/,, $(if $(filter /%, $(firstword $(MAKEFILE_LIST))), \
234
          $(firstword $(MAKEFILE_LIST)), \
235
          $(CURDIR)/$(firstword $(MAKEFILE_LIST))))))
236

237
# Defines the name of the file to store variable value in. Generates a name
238
# unless parameter 2 is given.
239
# Param 1 - Name of variable
240
# Param 2 - (optional) name of file to store value in
241
DependOnVariableFileName = \
242
    $(strip $(if $(strip $2), $2, \
243
      $(MAKESUPPORT_OUTPUTDIR)/vardeps/$(DependOnVariableDirName)/$(strip $1).vardeps))
244

245
# Writes the vardeps file. Assumes $1_filename has been setup
246
# Param 1 - Name of variable
247
DependOnVariableWriteFile = \
248
    $(call MakeDir, $(dir $($1_filename))) \
249
    $(call WriteFile, $1_old:=$(call DoubleDollar,$(call EscapeHash,$($1))), \
250
         $($1_filename)) \
251

252
# Does the actual work with parameters stripped.
253
# If the file exists AND the contents is the same as the variable, do nothing
254
# else print a new file.
255
# Always returns the name of the file where the value was printed.
256
# Param 1 - Name of variable
257
# Param 2 - (optional) name of file to store value in
258
DependOnVariableHelper = \
259
    $(strip \
260
        $(eval $1_filename := $(call DependOnVariableFileName, $1, $2)) \
261
        $(if $(wildcard $($1_filename)), \
262
          $(eval include $($1_filename)) \
263
          $(if $(call equals, $(strip $($1)), $(strip $($1_old))),,\
264
            $(if $(findstring $(LOG_LEVEL), trace), \
265
                $(info NewVariable $1: >$(strip $($1))<) \
266
                $(info OldVariable $1: >$(strip $($1_old))<) \
267
            ) \
268
            $(call DependOnVariableWriteFile,$1) \
269
          ) \
270
        , \
271
          $(call DependOnVariableWriteFile,$1) \
272
        ) \
273
        $($1_filename) \
274
    )
275

276
# Main macro
277
# Param 1 - Name of variable
278
# Param 2 - (optional) name of file to store value in
279
DependOnVariable = \
280
    $(call DependOnVariableHelper,$(strip $1),$(strip $2))
281

282
# LogCmdlines is only intended to be used by ExecuteWithLog
283
ifeq ($(LOG_CMDLINES), true)
284
  LogCmdlines = $(info $(strip $1))
285
else
286
  LogCmdlines =
287
endif
288

289
################################################################################
290
# ExecuteWithLog will run a command and log the output appropriately. This is
291
# meant to be used by commands that do "real" work, like a compilation.
292
# The output is stored in a specified log file, which is displayed at the end
293
# of the build in case of failure. The  command line itself is stored in a file,
294
# and also logged to stdout if the LOG=cmdlines option has been given.
295
#
296
# NOTE: If the command redirects stdout, the caller needs to wrap it in a
297
# subshell (by adding parentheses around it), otherwise the redirect to the
298
# subshell tee process will create a race condition where the target file may
299
# not be fully written when the make recipe is done.
300
#
301
# Param 1 - The path to base the name of the log file / command line file on
302
# Param 2 - The command to run
303
ExecuteWithLog = \
304
  $(call LogCmdlines, Executing: [$(strip $2)]) \
305
  $(call MakeDir, $(dir $(strip $1)) $(MAKESUPPORT_OUTPUTDIR)/failure-logs) \
306
  $(call WriteFile, $2, $(strip $1).cmdline) \
307
  ( $(RM) $(strip $1).log && $(strip $2) > >($(TEE) -a $(strip $1).log) 2> >($(TEE) -a $(strip $1).log >&2) || \
308
      ( exitcode=$(DOLLAR)? && \
309
      $(CP) $(strip $1).log $(MAKESUPPORT_OUTPUTDIR)/failure-logs/$(subst /,_,$(patsubst $(OUTPUTDIR)/%,%,$(strip $1))).log && \
310
      $(CP) $(strip $1).cmdline $(MAKESUPPORT_OUTPUTDIR)/failure-logs/$(subst /,_,$(patsubst $(OUTPUTDIR)/%,%,$(strip $1))).cmdline && \
311
      exit $(DOLLAR)exitcode ) )
312

313
################################################################################
314

315
# Hook to include the corresponding custom file, if present.
316
$(eval $(call IncludeCustomExtension, common/MakeBase.gmk))
317

318
endif # _MAKEBASE_GMK
319

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

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

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

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