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