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