2
# Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
3
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.
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
26
################################################################################
27
# This file contains helper functions for Main.gmk.
28
################################################################################
30
ifndef _MAINSUPPORT_GMK
33
# Setup make rules for creating a top-level target.
34
# Parameter 1 is the name of the rule. This name is used as variable prefix.
36
# Remaining parameters are named arguments. These include:
37
# MAKEFILE the makefile to delegate to
38
# TARGET the makefile target
39
# ARGS arguments to the makefile
40
# DEPS the target(s) this new rule depends on
41
# DIR the directory of the makefile (defaults to $(TOPDIR)/make)
43
SetupTarget = $(NamedParamsMacroTemplate)
46
$1_DIR := $(TOPDIR)/make
50
+($(CD) $$($1_DIR) && $(MAKE) $(MAKE_ARGS) -f $$($1_MAKEFILE).gmk $$($1_TARGET) $$($1_ARGS))
60
@$(PRINTF) "Cleaning docs ..."
61
@$(PRINTF) "\n" $(LOG_DEBUG)
62
$(RM) -r $(SUPPORT_OUTPUTDIR)/docs
63
$(RM) -r $(SUPPORT_OUTPUTDIR)/javadoc
64
$(RM) -r $(IMAGES_OUTPUTDIR)/docs
68
# Cleans the dir given as $1
70
@$(PRINTF) "Cleaning $(strip $1) build artifacts ..."
71
@$(PRINTF) "\n" $(LOG_DEBUG)
72
($(CD) $(OUTPUTDIR) && $(RM) -r $1)
77
@$(PRINTF) "Cleaning $(strip $1) build artifacts ..."
78
@$(PRINTF) "\n" $(LOG_DEBUG)
79
$(RM) -r $(SUPPORT_OUTPUTDIR)/$(strip $1)
83
define CleanMakeSupportDir
84
@$(PRINTF) "Cleaning $(strip $1) make support artifacts ..."
85
@$(PRINTF) "\n" $(LOG_DEBUG)
86
$(RM) -r $(MAKESUPPORT_OUTPUTDIR)/$(strip $1)
91
@$(PRINTF) "Cleaning test $(strip $1) ..."
92
@$(PRINTF) "\n" $(LOG_DEBUG)
93
$(RM) -r $(SUPPORT_OUTPUTDIR)/test/$(strip $(subst -,/,$1))
94
# Remove as much of the test directory structure as is empty
95
$(RMDIR) -p $(dir $(SUPPORT_OUTPUTDIR)/test/$(strip $(subst -,/,$1))) 2> /dev/null || true
100
@$(PRINTF) "Cleaning gensrc $(if $1,for $(strip $1) )..."
101
@$(PRINTF) "\n" $(LOG_DEBUG)
102
$(RM) -r $(SUPPORT_OUTPUTDIR)/gensrc/$(strip $1)
107
@$(PRINTF) "Cleaning java $(if $1,for $(strip $1) )..."
108
@$(PRINTF) "\n" $(LOG_DEBUG)
109
$(RM) -r $(JDK_OUTPUTDIR)/modules/$(strip $1)
110
$(RM) -r $(SUPPORT_OUTPUTDIR)/special_classes/$(strip $1)
112
$(PRINTF) "Cleaning headers $(if $1,for $(strip $1)) ..."
113
$(RM) -r $(SUPPORT_OUTPUTDIR)/headers/$(strip $1)
118
@$(PRINTF) "Cleaning native $(if $1,for $(strip $1) )..."
119
@$(PRINTF) "\n" $(LOG_DEBUG)
120
$(RM) -r $(SUPPORT_OUTPUTDIR)/native/$(strip $1)
121
$(RM) -r $(SUPPORT_OUTPUTDIR)/modules_libs/$(strip $1)
122
$(RM) -r $(SUPPORT_OUTPUTDIR)/modules_cmds/$(strip $1)
127
@$(PRINTF) "Cleaning include $(if $1,for $(strip $1) )..."
128
@$(PRINTF) "\n" $(LOG_DEBUG)
129
$(RM) -r $(SUPPORT_OUTPUTDIR)/modules_include/$(strip $1)
134
$(call Clean-gensrc, $1)
135
$(call Clean-java, $1)
136
$(call Clean-native, $1)
137
$(call Clean-include, $1)
141
################################################################################
143
PHASE_MAKEDIRS := $(TOPDIR)/make
145
# Helper macro for DeclareRecipesForPhase
146
# Declare a recipe for calling the module and phase specific makefile.
147
# If there are multiple makefiles to call, create a rule for each topdir
148
# that contains a makefile with the target $module-$suffix-$repodir,
149
# (i.e: java.base-gensrc-src)
150
# Normally there is only one makefile, and the target will just be
152
# Param 1: Name of list to add targets to
153
# Param 2: Module name
154
define DeclareRecipeForModuleMakefile
155
$2-$$($1_TARGET_SUFFIX):
156
+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) \
157
-f ModuleWrapper.gmk -I $$(TOPDIR)/make/common/modules \
158
$$(patsubst %,-I%/modules/$2,$$(PHASE_MAKEDIRS)) \
159
MODULE=$2 MAKEFILE_PREFIX=$$($1_FILE_PREFIX) $$($1_EXTRA_ARGS))
163
# Helper macro for DeclareRecipesForPhase
164
# Param 1: Name of list to add targets to
165
# Param 2: Module name
166
define DeclareRecipesForPhaseAndModule
167
$1_$2_MAKEFILES := $$(strip $$(wildcard \
168
$$(addsuffix /modules/$2/$$($1_FILE_PREFIX).gmk, $$(PHASE_MAKEDIRS))))
170
# Only declare recipes if there are makefiles to call
171
ifneq ($$($1_$2_MAKEFILES), )
172
# Add the top dir specific target to target list regardless of if recipe
173
# generation is disabled.
174
ifeq ($$($1_MULTIPLE_MAKEFILES), true)
175
$$(foreach d, $$($1_$2_TOPDIRS), \
176
$$(eval $1 += $2-$$($1_TARGET_SUFFIX)-$$(notdir $$d)))
178
ifeq ($(NO_RECIPES),)
179
$$(eval $$(call DeclareRecipeForModuleMakefile,$1,$2))
181
$1 += $2-$$($1_TARGET_SUFFIX)
186
# Declare recipes for a specific module and build phase if there are makefiles
187
# present for the specific combination.
188
# Param 1: Name of list to add targets to
190
# TARGET_SUFFIX : Suffix of target to create for recipe
191
# FILE_PREFIX : File prefix for this build phase
192
# CHECK_MODULES : List of modules to try
193
# MULTIPLE_MAKEFILES : Set to true to handle makefiles for the same module and
194
# phase in multiple repos
195
# EXTRA_ARGS : Add extra make args to each makefile call
197
# $1_MODULES : All modules that had rules generated
198
# $1_TARGETS : All targets generated
199
define DeclareRecipesForPhase
200
$(foreach i,2 3 4 5 6 7 8, $(if $(strip $($i)),$(strip $1)_$(strip $($i)))$(NEWLINE))
201
$(if $(9),$(error Internal makefile error: Too many arguments to \
202
DeclareRecipesForPhase, please update MakeHelper.gmk))
204
$$(foreach m, $$($(strip $1)_CHECK_MODULES), \
205
$$(eval $$(call DeclareRecipesForPhaseAndModule,$(strip $1),$$m)))
207
$(strip $1)_TARGETS := $$($(strip $1))
210
################################################################################
212
endif # _MAINSUPPORT_GMK