1 #
2 # Copyright (c) 2014, 2025, 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 include MakeIncludeStart.gmk
27 ifeq ($(INCLUDE), true)
28
29 ################################################################################
30 # Setup module sets for classloaders
31
32 include $(TOPDIR)/make/conf/module-loader-map.conf
33
34 # Append platform-specific and upgradeable modules
35 PLATFORM_MODULES += $(PLATFORM_MODULES_$(OPENJDK_TARGET_OS)) \
36 $(UPGRADEABLE_PLATFORM_MODULES) $(CUSTOM_UPGRADEABLE_PLATFORM_MODULES)
37
38 ################################################################################
39 # Setup module sets for docs
40
41 include $(TOPDIR)/make/conf/docs-modules.conf
42
43 ################################################################################
44 # Setup module sets needed by the build system
45
46 include $(TOPDIR)/make/conf/build-module-sets.conf
47
48 ################################################################################
49 # Depending on the configuration, we might need to filter out some modules that
50 # normally should have been included
51
52 # Some platforms don't have the serviceability agent
53 ifeq ($(INCLUDE_SA), false)
54 MODULES_FILTER += jdk.hotspot.agent
55 endif
56
57 # Filter out jvmci specific modules if jvmci is disabled
58 ifeq ($(INCLUDE_JVMCI), false)
59 MODULES_FILTER += jdk.internal.vm.ci
60 MODULES_FILTER += jdk.graal.compiler
61 MODULES_FILTER += jdk.graal.compiler.management
62 endif
63
64 # jpackage is only on windows, macosx, and linux
65 ifeq ($(call isTargetOs, windows macosx linux), false)
66 MODULES_FILTER += jdk.jpackage
67 endif
68
69 ################################################################################
70 # Module list macros
71
72 # Use append so that the custom extension may add to these variables
73
74 GENERATED_SRC_DIRS += \
75 $(SUPPORT_OUTPUTDIR)/gensrc \
76 #
77
78 # Directories in which generated preview classes may exist.
79 # Currently this is restricted to generated value classes, but can be extended.
80 GENERATED_PREVIEW_SUBDIRS += \
81 $(SUPPORT_OUTPUTDIR)/gensrc-valueclasses \
82 #
83
84 TOP_SRC_DIRS += \
85 $(TOPDIR)/src \
86 #
87
88 SRC_SUBDIRS += $(OPENJDK_TARGET_OS)/classes
89 ifneq ($(OPENJDK_TARGET_OS), $(OPENJDK_TARGET_OS_TYPE))
90 SRC_SUBDIRS += $(OPENJDK_TARGET_OS_TYPE)/classes
91 endif
92 SRC_SUBDIRS += share/classes
93
94 SPEC_SUBDIRS += share/specs
95
96 MAN_SUBDIRS += share/man $(TARGET_OS)/man
97
98 # The docs should include the sum of all man pages for all platforms
99 MAN_DOCS_SUBDIRS += share/man windows/man
100
101 # Find all module-info.java files for the current build target platform and
102 # configuration.
103 # Param 1 - Module to find for, set to * for finding all
104 FindAllModuleInfos = \
105 $(sort $(wildcard \
106 $(foreach sub, $(SRC_SUBDIRS), \
107 $(patsubst %,%/$(strip $1)/$(sub)/module-info.java, $(TOP_SRC_DIRS))) \
108 $(patsubst %,%/$(strip $1)/module-info.java, $(IMPORT_MODULES_SRC))))
109
110 # Find module-info.java files in the specific source dir
111 # Param 1 - Src dir to find module-info.java files in
112 FindModuleInfosForSrcDir = \
113 $(wildcard \
114 $(foreach sub, $(SRC_SUBDIRS), \
115 $(patsubst %,%/*/$(sub)/module-info.java, $(strip $1)) \
116 ) \
117 $(patsubst %,%/*/module-info.java, $(strip $1)) \
118 )
119
120 # Extract the module names from the paths of module-info.java files. The
121 # position of the module directory differs depending on if this is an imported
122 # src dir or not.
123 GetModuleNameFromModuleInfo = \
124 $(strip $(foreach mi, $1, \
125 $(if $(filter $(addsuffix %, $(IMPORT_MODULES_SRC)), $(mi)), \
126 $(notdir $(patsubst %/,%, $(dir $(mi)))), \
127 $(notdir $(patsubst %/,%, $(dir $(patsubst %/,%, $(dir $(patsubst %/,%, $(dir $(mi)))))))))))
128
129 # Find all modules by looking for module-info.java files and looking at parent
130 # directories.
131 FindAllModules = \
132 $(sort $(filter-out $(MODULES_FILTER), \
133 $(call GetModuleNameFromModuleInfo, $(MODULE_INFOS))))
134
135 # Find all modules in a specific src dir
136 # Param 1 - Src dir to find modules in
137 FindModulesForSrcDir = \
138 $(sort $(filter-out $(MODULES_FILTER), \
139 $(call GetModuleNameFromModuleInfo, $(call FindModuleInfosForSrcDir, $1)) \
140 ))
141
142 FindImportedModules = \
143 $(filter-out $(MODULES_FILTER), \
144 $(if $(IMPORT_MODULES_CLASSES), $(notdir $(wildcard $(IMPORT_MODULES_CLASSES)/*))))
145
146 # Find all source dirs for a particular module
147 # $1 - Module to find source dirs for
148 FindModuleSrcDirs = \
149 $(strip $(wildcard \
150 $(addsuffix /$(strip $1), $(GENERATED_SRC_DIRS) $(IMPORT_MODULES_SRC)) \
151 $(foreach sub, $(SRC_SUBDIRS), $(addsuffix /$(strip $1)/$(sub), $(TOP_SRC_DIRS)))))
152
153 # Find preview class source dirs for a particular module.
154 # Currently this is restricted to generated value classes, but can be extended.
155 # $1 - Module to find source dirs for
156 FindModulePreviewSrcDirs = \
157 $(strip $(wildcard \
158 $(addsuffix /$(strip $1), $(GENERATED_PREVIEW_SUBDIRS))))
159
160 # Find all specs dirs for a particular module
161 # $1 - Module to find specs dirs for
162 FindModuleSpecsDirs = \
163 $(strip $(wildcard \
164 $(foreach sub, $(SPEC_SUBDIRS), $(addsuffix /$(strip $1)/$(sub), $(TOP_SRC_DIRS)))))
165
166 # Find all man dirs for a particular module
167 # $1 - Module to find man dirs for
168 FindModuleManDirs = \
169 $(strip $(wildcard \
170 $(foreach sub, $(MAN_SUBDIRS), $(addsuffix /$(strip $1)/$(sub), $(TOP_SRC_DIRS)))))
171
172 FindModuleManDirsForDocs = \
173 $(strip $(wildcard \
174 $(foreach sub, $(MAN_DOCS_SUBDIRS), $(addsuffix /$(strip $1)/$(sub), $(TOP_SRC_DIRS)))))
175
176 # Construct the complete module source path
177 GetModuleSrcPath = \
178 $(call PathList, \
179 $(addsuffix /*, $(GENERATED_SRC_DIRS) $(IMPORT_MODULES_SRC)) \
180 $(foreach sub, $(SRC_SUBDIRS), $(addsuffix /*/$(sub), $(TOP_SRC_DIRS))))
181
182 # Construct the complete module source path for preview classes.
183 # Currently this is restricted to generated value classes, but can be extended.
184 GetModulePreviewSrcPath = \
185 $(call PathList, \
186 $(addsuffix /*, $(GENERATED_PREVIEW_SUBDIRS) $(GENERATED_SRC_DIRS) $(IMPORT_MODULES_SRC)) \
187 $(foreach sub, $(SRC_SUBDIRS), $(addsuffix /*/$(sub), $(TOP_SRC_DIRS))))
188
189 ################################################################################
190 # Extract module dependencies from module-info.java files, both normal
191 # dependencies ("requires"), and indirect exports ("requires transitive").
192
193 MODULE_DEPS_MAKEFILE := $(MAKESUPPORT_OUTPUTDIR)/module-deps.gmk
194
195 MODULE_INFOS := $(call FindAllModuleInfos, *)
196
197 ifeq ($(GENERATE_MODULE_DEPS_FILE), true)
198 $(MODULE_DEPS_MAKEFILE): $(MODULE_INFOS) \
199 $(call DependOnVariable, MODULE_INFOS, $(MAKESUPPORT_OUTPUTDIR)/MODULE_INFOS.vardeps)
200 $(call MakeTargetDir)
201 $(RM) $@
202 $(foreach m, $(MODULE_INFOS), \
203 ( $(PRINTF) "DEPS_%s := " "$(call GetModuleNameFromModuleInfo, $m)" && \
204 $(AWK) -v MODULE=$(call GetModuleNameFromModuleInfo, $m) ' \
205 BEGIN { if (MODULE != "java.base") printf(" java.base"); } \
206 /^ *requires/ { sub(/;/, ""); \
207 sub(/requires /, " "); \
208 sub(/ static /, " "); \
209 sub(/ transitive /, " "); \
210 sub(/\/\/.*/, ""); \
211 sub(/\/\*.*\*\//, ""); \
212 gsub(/^ +\*.*/, ""); \
213 gsub(/ /, ""); \
214 gsub(/\r/, ""); \
215 printf(" %s", $$0) } \
216 END { printf("\n") }' $m && \
217 $(PRINTF) "TRANSITIVE_MODULES_%s := " "$(call GetModuleNameFromModuleInfo, $m)" && \
218 $(AWK) -v MODULE=$(call GetModuleNameFromModuleInfo, $m) ' \
219 BEGIN { if (MODULE != "java.base") printf(" java.base"); } \
220 /^ *requires *transitive/ { \
221 sub(/;/, ""); \
222 sub(/requires/, ""); \
223 sub(/transitive/, ""); \
224 sub(/\/\/.*/, ""); \
225 sub(/\/\*.*\*\//, ""); \
226 gsub(/^ +\*.*/, ""); \
227 gsub(/ /, ""); \
228 gsub(/\r/, ""); \
229 printf(" %s", $$0) } \
230 END { printf("\n") }' $m \
231 ) >> $@ $(NEWLINE))
232 endif
233
234 -include $(MODULE_DEPS_MAKEFILE)
235
236 # Find dependencies ("requires") for a given module.
237 # Param 1: Module to find dependencies for.
238 FindDepsForModule = \
239 $(filter-out $(IMPORT_MODULES), $(DEPS_$(strip $1)))
240
241 # Find dependencies ("requires") transitively in 3 levels for a given module.
242 # Param 1: Module to find dependencies for.
243 FindTransitiveDepsForModule = \
244 $(sort $(call FindDepsForModule, $1) \
245 $(foreach m, $(call FindDepsForModule, $1), \
246 $(call FindDepsForModule, $m) \
247 $(foreach n, $(call FindDepsForModule, $m), \
248 $(call FindDepsForModule, $n))))
249
250 # Find dependencies ("requires") transitively in 3 levels for a set of modules.
251 # Param 1: List of modules to find dependencies for.
252 FindTransitiveDepsForModules = \
253 $(sort $(foreach m, $1, $(call FindTransitiveDepsForModule, $m)))
254
255 # Find indirect exported modules ("requires transitive") for a given module .
256 # Param 1: Module to find indirect exported modules for.
257 FindIndirectExportsForModule = \
258 $(TRANSITIVE_MODULES_$(strip $1))
259
260 # Finds indirect exported modules transitively in 3 levels for a given module.
261 # Param 1: Module to find indirect exported modules for.
262 FindTransitiveIndirectDepsForModule = \
263 $(sort $(call FindIndirectExportsForModule, $1) \
264 $(foreach m, $(call FindIndirectExportsForModule, $1), \
265 $(call FindIndirectExportsForModule, $m) \
266 $(foreach n, $(call FindIndirectExportsForModule, $m), \
267 $(call FindIndirectExportsForModule, $n))))
268
269 # Finds indirect exported modules transitively in 3 levels for a set of modules.
270 # Param 1: List of modules to find indirect exported modules for.
271 FindTransitiveIndirectDepsForModules = \
272 $(sort $(foreach m, $1, $(call FindTransitiveIndirectDepsForModule, $m)))
273
274 # Upgradeable modules are those that are either defined as upgradeable or that
275 # require an upradeable module.
276 FindAllUpgradeableModules = \
277 $(sort $(filter-out $(MODULES_FILTER), \
278 $(UPGRADEABLE_PLATFORM_MODULES) $(CUSTOM_UPGRADEABLE_PLATFORM_MODULES)))
279
280 ################################################################################
281
282 LEGAL_SUBDIRS += $(OPENJDK_TARGET_OS)/legal
283 ifneq ($(OPENJDK_TARGET_OS), $(OPENJDK_TARGET_OS_TYPE))
284 LEGAL_SUBDIRS += $(OPENJDK_TARGET_OS_TYPE)/legal
285 endif
286 LEGAL_SUBDIRS += share/legal
287
288 # Find all legal src dirs for a particular module
289 # $1 - Module to find legal dirs for
290 FindModuleLegalSrcDirs = \
291 $(strip $(wildcard \
292 $(addsuffix /$(strip $1), $(IMPORT_MODULES_LEGAL)) \
293 $(foreach sub, $(LEGAL_SUBDIRS), $(addsuffix /$(strip $1)/$(sub), $(TOP_SRC_DIRS))) \
294 ))
295
296 ################################################################################
297
298 # Param 1 - Name of module
299 define ReadSingleImportMetaData
300 ifneq ($$(wildcard $(IMPORT_MODULES_MAKE)/$$(strip $1)/build.properties), )
301 classloader :=
302 include_in_jre :=
303 include_in_jdk :=
304 include $(IMPORT_MODULES_MAKE)/$$(strip $1)/build.properties
305 ifeq ($$(include_in_jre), true)
306 JRE_MODULES += $1
307 endif
308 ifeq ($$(include_in_jdk), true)
309 JDK_MODULES += $1
310 endif
311 ifeq ($$(classloader), boot)
312 BOOT_MODULES += $1
313 else ifeq ($$(classloader), ext)
314 PLATFORM_MODULES += $1
315 endif
316 ifneq ($$(include_in_docs), false)
317 # defaults to true if unspecified
318 DOCS_MODULES += $1
319 endif
320 else
321 # Default to include in all
322 JRE_MODULES += $1
323 JDK_MODULES += $1
324 endif
325 endef
326
327 # Reading the imported modules metadata has a cost, so to make it available,
328 # a makefile needs to eval-call this macro first. After calling this, the
329 # following variables are populated with data from the imported modules:
330 # * JRE_MODULES
331 # * JDK_MODULES
332 # * BOOT_MODULES
333 # * PLATFORM_MODULES
334 define ReadImportMetaData
335 IMPORTED_MODULES := $$(call FindImportedModules)
336 $$(foreach m, $$(IMPORTED_MODULES), \
337 $$(eval $$(call ReadSingleImportMetaData, $$m)))
338 endef
339
340 ################################################################################
341 # Get a full snippet path for the current module and a given base name.
342 #
343 # Param 1 - The base name of the snippet file to include
344 GetModuleSnippetName = \
345 $(if $(CUSTOM_MODULE_MAKE_ROOT), \
346 $(if $(wildcard $(CUSTOM_MODULE_MAKE_ROOT)/$(MODULE)/$(strip $1).gmk), \
347 $(CUSTOM_MODULE_MAKE_ROOT)/$(MODULE)/$(strip $1).gmk, \
348 $(wildcard modules/$(MODULE)/$(strip $1).gmk) \
349 ), \
350 $(wildcard modules/$(MODULE)/$(strip $1).gmk) \
351 )
352
353 ################################################################################
354
355 endif # include guard
356 include MakeIncludeEnd.gmk