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