1 #
  2 # Copyright (c) 2014, 2021, 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 ifeq ($(INCLUDE_JEXTRACT), false)
 63   MODULES_FILTER += jdk.incubator.jextract
 64 endif
 65 
 66 # Filter out jvmci specific modules if jvmci is disabled
 67 ifeq ($(INCLUDE_JVMCI), false)
 68   MODULES_FILTER += jdk.internal.vm.ci
 69   MODULES_FILTER += jdk.internal.vm.compiler
 70   MODULES_FILTER += jdk.internal.vm.compiler.management
 71 endif
 72 
 73 # jpackage is only on windows, macosx, and linux
 74 ifeq ($(call isTargetOs, windows macosx linux), false)
 75   MODULES_FILTER += jdk.jpackage
 76 endif
 77 
 78 ################################################################################
 79 # Module list macros
 80 
 81 # Use append so that the custom extension may add to these variables
 82 
 83 GENERATED_SRC_DIRS += \
 84     $(SUPPORT_OUTPUTDIR)/gensrc \
 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 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 # Construct the complete module source path
166 GetModuleSrcPath = \
167     $(call PathList, \
168         $(addsuffix /*, $(GENERATED_SRC_DIRS) $(IMPORT_MODULES_SRC)) \
169         $(foreach sub, $(SRC_SUBDIRS), $(addsuffix /*/$(sub), $(TOP_SRC_DIRS))))
170 
171 ################################################################################
172 # Extract module dependencies from module-info.java files, both normal
173 # dependencies ("requires"), and indirect exports ("requires transitive").
174 
175 MODULE_DEPS_MAKEFILE := $(MAKESUPPORT_OUTPUTDIR)/module-deps.gmk
176 
177 MODULE_INFOS := $(call FindAllModuleInfos, *)
178 
179 $(MODULE_DEPS_MAKEFILE): $(MODULE_INFOS) \
180     $(call DependOnVariable, MODULE_INFOS, $(MAKESUPPORT_OUTPUTDIR)/MODULE_INFOS.vardeps)
181 	$(call MakeTargetDir)
182 	$(RM) $@
183 	$(foreach m, $(MODULE_INFOS), \
184 	    ( $(PRINTF) "DEPS_$(call GetModuleNameFromModuleInfo, $m) :=" && \
185 	      $(AWK) -v MODULE=$(call GetModuleNameFromModuleInfo, $m) '\
186 	          BEGIN      { if (MODULE != "java.base") printf(" java.base"); } \
187 	          /^ *requires/ { sub(/;/, ""); \
188 	                          sub(/requires /, " "); \
189 	                          sub(/ static /, " "); \
190 	                          sub(/ transitive /, " "); \
191 	                          sub(/\/\/.*/, ""); \
192 	                          sub(/\/\*.*\*\//, ""); \
193 	                          gsub(/^ +\*.*/, ""); \
194 	                          gsub(/ /, ""); \
195 	                          gsub(/\r/, ""); \
196 	                          printf(" %s", $$0) } \
197 	          END           { printf("\n") }' $m && \
198 	      $(PRINTF) "TRANSITIVE_MODULES_$(call GetModuleNameFromModuleInfo, $m) :=" && \
199 	      $(AWK) -v MODULE=$(call GetModuleNameFromModuleInfo, $m) '\
200 	          BEGIN      { if (MODULE != "java.base") printf(" java.base"); } \
201 	          /^ *requires  *transitive/ { \
202 	                          sub(/;/, ""); \
203 	                          sub(/requires/, ""); \
204 	                          sub(/transitive/, ""); \
205 	                          sub(/\/\/.*/, ""); \
206 	                          sub(/\/\*.*\*\//, ""); \
207 	                          gsub(/^ +\*.*/, ""); \
208 	                          gsub(/ /, ""); \
209 	                          gsub(/\r/, ""); \
210 	                          printf(" %s", $$0) } \
211 	          END           { printf("\n") }' $m \
212 	    ) >> $@ $(NEWLINE))
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 # _MODULES_GMK