1 #
  2 # Copyright (c) 2014, 2023, 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 ifndef _MODULES_GMK
 27 _MODULES_GMK := 1
 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 # Hook to include the corresponding custom file, if present.
 50 # Allowing MODULE list extensions setup above.
 51 $(eval $(call IncludeCustomExtension, common/Modules.gmk))
 52 
 53 ################################################################################
 54 # Depending on the configuration, we might need to filter out some modules that
 55 # normally should have been included
 56 
 57 # Some platforms don't have the serviceability agent
 58 ifeq ($(INCLUDE_SA), false)
 59   MODULES_FILTER += jdk.hotspot.agent
 60 endif
 61 
 62 # Filter out jvmci specific modules if jvmci is disabled
 63 ifeq ($(INCLUDE_JVMCI), false)
 64   MODULES_FILTER += jdk.internal.vm.ci
 65   MODULES_FILTER += jdk.graal.compiler
 66   MODULES_FILTER += jdk.graal.compiler.management
 67 endif
 68 
 69 # jpackage is only on windows, macosx, and linux
 70 ifeq ($(call isTargetOs, windows macosx linux), false)
 71   MODULES_FILTER += jdk.jpackage
 72 endif
 73 
 74 ################################################################################
 75 # Module list macros
 76 
 77 # Use append so that the custom extension may add to these variables
 78 
 79 GENERATED_SRC_DIRS += \
 80     $(SUPPORT_OUTPUTDIR)/gensrc \
 81     #
 82 
 83 GENERATED_VALUE_CLASS_SUBDIRS += \
 84     $(SUPPORT_OUTPUTDIR)/gensrc-valueclasses \
 85     #
 86 
 87 TOP_SRC_DIRS += \
 88     $(TOPDIR)/src \
 89     #
 90 
 91 SRC_SUBDIRS += $(OPENJDK_TARGET_OS)/classes
 92 ifneq ($(OPENJDK_TARGET_OS), $(OPENJDK_TARGET_OS_TYPE))
 93   SRC_SUBDIRS += $(OPENJDK_TARGET_OS_TYPE)/classes
 94 endif
 95 SRC_SUBDIRS += share/classes
 96 
 97 SPEC_SUBDIRS += share/specs
 98 
 99 MAN_SUBDIRS += share/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 value class source dirs for a particular module  (only generated)
154 # $1 - Module to find source dirs for
155 FindModuleValueClassSrcDirs = \
156     $(strip $(wildcard \
157         $(addsuffix /$(strip $1), $(GENERATED_VALUE_CLASS_SUBDIRS))))
158 
159 # Find all specs dirs for a particular module
160 # $1 - Module to find specs dirs for
161 FindModuleSpecsDirs = \
162     $(strip $(wildcard \
163         $(foreach sub, $(SPEC_SUBDIRS), $(addsuffix /$(strip $1)/$(sub), $(TOP_SRC_DIRS)))))
164 
165 # Find all man dirs for a particular module
166 # $1 - Module to find man dirs for
167 FindModuleManDirs = \
168     $(strip $(wildcard \
169         $(foreach sub, $(MAN_SUBDIRS), $(addsuffix /$(strip $1)/$(sub), $(TOP_SRC_DIRS)))))
170 
171 # Construct the complete module source path
172 GetModuleSrcPath = \
173     $(call PathList, \
174         $(addsuffix /*, $(GENERATED_SRC_DIRS) $(IMPORT_MODULES_SRC)) \
175         $(foreach sub, $(SRC_SUBDIRS), $(addsuffix /*/$(sub), $(TOP_SRC_DIRS))))
176 
177 # Construct the complete module source path for value classes
178 GetModuleValueClassSrcPath = \
179     $(call PathList, \
180         $(addsuffix /*, $(GENERATED_VALUE_CLASS_SUBDIRS) $(GENERATED_SRC_DIRS) $(IMPORT_MODULES_SRC)) \
181         $(foreach sub, $(SRC_SUBDIRS), $(addsuffix /*/$(sub), $(TOP_SRC_DIRS))))
182 
183 ################################################################################
184 # Extract module dependencies from module-info.java files, both normal
185 # dependencies ("requires"), and indirect exports ("requires transitive").
186 
187 MODULE_DEPS_MAKEFILE := $(MAKESUPPORT_OUTPUTDIR)/module-deps.gmk
188 
189 MODULE_INFOS := $(call FindAllModuleInfos, *)
190 
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_$(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_$(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 
226 -include $(MODULE_DEPS_MAKEFILE)
227 
228 # Find dependencies ("requires") for a given module.
229 # Param 1: Module to find dependencies for.
230 FindDepsForModule = \
231   $(DEPS_$(strip $1))
232 
233 # Find dependencies ("requires") transitively in 3 levels for a given module.
234 # Param 1: Module to find dependencies for.
235 FindTransitiveDepsForModule = \
236     $(sort $(call FindDepsForModule, $1) \
237         $(foreach m, $(call FindDepsForModule, $1), \
238             $(call FindDepsForModule, $m) \
239             $(foreach n, $(call FindDepsForModule, $m), \
240                 $(call FindDepsForModule, $n))))
241 
242 # Find dependencies ("requires") transitively in 3 levels for a set of modules.
243 # Param 1: List of modules to find dependencies for.
244 FindTransitiveDepsForModules = \
245     $(sort $(foreach m, $1, $(call FindTransitiveDepsForModule, $m)))
246 
247 # Find indirect exported modules ("requires transitive") for a given module .
248 # Param 1: Module to find indirect exported modules for.
249 FindIndirectExportsForModule = \
250   $(TRANSITIVE_MODULES_$(strip $1))
251 
252 # Finds indirect exported modules transitively in 3 levels for a given module.
253 # Param 1: Module to find indirect exported modules for.
254 FindTransitiveIndirectDepsForModule = \
255     $(sort $(call FindIndirectExportsForModule, $1) \
256         $(foreach m, $(call FindIndirectExportsForModule, $1), \
257             $(call FindIndirectExportsForModule, $m) \
258             $(foreach n, $(call FindIndirectExportsForModule, $m), \
259                 $(call FindIndirectExportsForModule, $n))))
260 
261 # Finds indirect exported modules transitively in 3 levels for a set of modules.
262 # Param 1: List of modules to find indirect exported modules for.
263 FindTransitiveIndirectDepsForModules = \
264     $(sort $(foreach m, $1, $(call FindTransitiveIndirectDepsForModule, $m)))
265 
266 # Upgradeable modules are those that are either defined as upgradeable or that
267 # require an upradeable module.
268 FindAllUpgradeableModules = \
269     $(sort $(filter-out $(MODULES_FILTER), $(UPGRADEABLE_PLATFORM_MODULES)))
270 
271 ################################################################################
272 
273 LEGAL_SUBDIRS += $(OPENJDK_TARGET_OS)/legal
274 ifneq ($(OPENJDK_TARGET_OS), $(OPENJDK_TARGET_OS_TYPE))
275   LEGAL_SUBDIRS += $(OPENJDK_TARGET_OS_TYPE)/legal
276 endif
277 LEGAL_SUBDIRS += share/legal
278 
279 # Find all legal src dirs for a particular module
280 # $1 - Module to find legal dirs for
281 FindModuleLegalSrcDirs = \
282     $(strip $(wildcard \
283         $(addsuffix /$(strip $1), $(IMPORT_MODULES_LEGAL)) \
284         $(foreach sub, $(LEGAL_SUBDIRS), $(addsuffix /$(strip $1)/$(sub), $(TOP_SRC_DIRS))) \
285     ))
286 
287 ################################################################################
288 
289 # Param 1 - Name of module
290 define ReadSingleImportMetaData
291     ifneq ($$(wildcard $(IMPORT_MODULES_MAKE)/$$(strip $1)/build.properties), )
292       classloader :=
293       include_in_jre :=
294       include_in_jdk :=
295       include $(IMPORT_MODULES_MAKE)/$$(strip $1)/build.properties
296       ifeq ($$(include_in_jre), true)
297         JRE_MODULES += $1
298       endif
299       ifeq ($$(include_in_jdk), true)
300         JDK_MODULES += $1
301       endif
302       ifeq ($$(classloader), boot)
303         BOOT_MODULES += $1
304       else ifeq ($$(classloader), ext)
305         PLATFORM_MODULES += $1
306       endif
307       ifneq ($$(include_in_docs), false)
308         # defaults to true if unspecified
309         DOCS_MODULES += $1
310       endif
311     else
312       # Default to include in all
313       JRE_MODULES += $1
314       JDK_MODULES += $1
315     endif
316 endef
317 
318 # Reading the imported modules metadata has a cost, so to make it available,
319 # a makefile needs to eval-call this macro first. After calling this, the
320 # following variables are populated with data from the imported modules:
321 # * JRE_MODULES
322 # * JDK_MODULES
323 # * BOOT_MODULES
324 # * PLATFORM_MODULES
325 define ReadImportMetaData
326     IMPORTED_MODULES := $$(call FindImportedModules)
327     $$(foreach m, $$(IMPORTED_MODULES), \
328       $$(eval $$(call ReadSingleImportMetaData, $$m)))
329 endef
330 
331 ################################################################################
332 
333 endif # _MODULES_GMK