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