1#
2# Copyright (c) 2014, 2020, 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
26ifndef _MODULES_GMK
27_MODULES_GMK := 1
28
29################################################################################
30#
31# BOOT_MODULES are modules defined by the boot loader
32# PLATFORM_MODULES are modules defined by the platform loader
33# JRE_TOOL_MODULES are tools included in JRE and defined by the application loader
34#
35# All other modules not declared below are defined by the application loader
36# and are not included in JRE.
37
38BOOT_MODULES :=
39PLATFORM_MODULES :=
40JRE_TOOL_MODULES :=
41UPGRADEABLE_MODULES :=
42AGGREGATOR_MODULES :=
43DOCS_MODULES :=
44
45# Hook to include the corresponding custom file, if present.
46$(eval $(call IncludeCustomExtension, common/Modules.gmk))
47
48BOOT_MODULES += \
49    java.base \
50    java.datatransfer \
51    java.desktop \
52    java.instrument \
53    java.logging \
54    java.management \
55    java.management.rmi \
56    java.naming \
57    java.prefs \
58    java.rmi \
59    java.security.sasl \
60    java.xml \
61    jdk.incubator.foreign \
62    jdk.internal.vm.ci \
63    jdk.jfr \
64    jdk.management \
65    jdk.management.jfr \
66    jdk.management.agent \
67    jdk.net \
68    jdk.nio.mapmode \
69    jdk.sctp \
70    jdk.unsupported \
71    #
72
73# to be deprivileged
74BOOT_MODULES += \
75    jdk.naming.rmi \
76    #
77
78# Modules that directly or indirectly requiring upgradeable modules
79# should carefully be considered if it should be upgradeable or not.
80UPGRADEABLE_MODULES += \
81    java.compiler \
82    jdk.aot \
83    jdk.internal.vm.compiler \
84    jdk.internal.vm.compiler.management \
85    #
86
87
88AGGREGATOR_MODULES += \
89    java.se \
90    #
91
92PLATFORM_MODULES += \
93    $(UPGRADEABLE_MODULES) \
94    $(AGGREGATOR_MODULES)
95    #
96
97PLATFORM_MODULES += \
98    java.net.http \
99    java.scripting \
100    java.security.jgss \
101    java.smartcardio \
102    java.sql \
103    java.sql.rowset \
104    java.transaction.xa \
105    java.xml.crypto \
106    jdk.accessibility \
107    jdk.charsets \
108    jdk.crypto.cryptoki \
109    jdk.crypto.ec \
110    jdk.dynalink \
111    jdk.httpserver \
112    jdk.jsobject \
113    jdk.localedata \
114    jdk.naming.dns \
115    jdk.security.auth \
116    jdk.security.jgss \
117    jdk.xml.dom \
118    jdk.zipfs \
119    #
120
121ifeq ($(call isTargetOs, windows), true)
122  PLATFORM_MODULES += jdk.crypto.mscapi
123endif
124
125JRE_TOOL_MODULES += \
126    jdk.jdwp.agent \
127    jdk.incubator.jpackage \
128    #
129
130################################################################################
131
132# DOCS_MODULES defines the root modules for javadoc generation.
133# All of their `require transitive` modules directly and indirectly will be included.
134DOCS_MODULES += \
135    java.se \
136    java.smartcardio \
137    jdk.accessibility \
138    jdk.attach \
139    jdk.charsets \
140    jdk.compiler \
141    jdk.crypto.cryptoki \
142    jdk.crypto.ec \
143    jdk.dynalink \
144    jdk.editpad \
145    jdk.hotspot.agent \
146    jdk.httpserver \
147    jdk.incubator.jpackage \
148    jdk.jartool \
149    jdk.javadoc \
150    jdk.jcmd \
151    jdk.jconsole \
152    jdk.jdeps \
153    jdk.jdi \
154    jdk.jdwp.agent \
155    jdk.jfr \
156    jdk.jlink \
157    jdk.jsobject \
158    jdk.jshell \
159    jdk.jstatd \
160    jdk.incubator.foreign \
161    jdk.localedata \
162    jdk.management \
163    jdk.management.agent \
164    jdk.management.jfr \
165    jdk.naming.dns \
166    jdk.naming.rmi \
167    jdk.net \
168    jdk.nio.mapmode \
169    jdk.sctp \
170    jdk.security.auth \
171    jdk.security.jgss \
172    jdk.xml.dom \
173    jdk.zipfs \
174    #
175
176# These modules are included in the interim image which is used to run profiling
177# before building the real images.
178INTERIM_IMAGE_MODULES := java.base java.logging
179
180LANGTOOLS_MODULES := \
181    java.compiler \
182    jdk.compiler \
183    jdk.javadoc \
184    jdk.jdeps \
185    jdk.jshell \
186    #
187
188HOTSPOT_MODULES := \
189    jdk.aot \
190    jdk.hotspot.agent \
191    jdk.internal.vm.ci \
192    jdk.internal.vm.compiler \
193    jdk.internal.vm.compiler.management \
194    #
195
196################################################################################
197# Some platforms don't have the serviceability agent
198
199ifeq ($(INCLUDE_SA), false)
200  MODULES_FILTER += jdk.hotspot.agent
201endif
202
203################################################################################
204# Filter out jvmci specific modules if jvmci is disabled
205
206ifeq ($(INCLUDE_JVMCI), false)
207  MODULES_FILTER += jdk.internal.vm.ci
208endif
209
210################################################################################
211# Filter out Graal specific modules if Graal is disabled
212
213ifeq ($(INCLUDE_GRAAL), false)
214  MODULES_FILTER += jdk.internal.vm.compiler
215  MODULES_FILTER += jdk.internal.vm.compiler.management
216endif
217
218################################################################################
219# Filter out aot specific modules if aot is disabled
220
221ifeq ($(ENABLE_AOT), false)
222  MODULES_FILTER += jdk.aot
223endif
224
225################################################################################
226# jpackage is only on windows, macosx, and linux
227
228ifeq ($(call isTargetOs, windows macosx linux), false)
229  MODULES_FILTER += jdk.incubator.jpackage
230endif
231
232################################################################################
233# Module list macros
234
235# Use append so that the custom extension may add to these variables
236
237GENERATED_SRC_DIRS += \
238    $(SUPPORT_OUTPUTDIR)/gensrc \
239    #
240
241TOP_SRC_DIRS += \
242    $(TOPDIR)/src \
243    #
244
245SRC_SUBDIRS += $(OPENJDK_TARGET_OS)/classes
246ifneq ($(OPENJDK_TARGET_OS), $(OPENJDK_TARGET_OS_TYPE))
247  SRC_SUBDIRS += $(OPENJDK_TARGET_OS_TYPE)/classes
248endif
249SRC_SUBDIRS += share/classes
250
251SPEC_SUBDIRS += share/specs
252
253MAN_SUBDIRS += share/man
254
255# Find all module-info.java files for the current build target platform and
256# configuration.
257# Param 1 - Module to find for, set to * for finding all
258FindAllModuleInfos = \
259    $(sort $(wildcard \
260        $(foreach sub, $(SRC_SUBDIRS), \
261          $(patsubst %,%/$(strip $1)/$(sub)/module-info.java, $(TOP_SRC_DIRS))) \
262        $(patsubst %,%/$(strip $1)/module-info.java, $(IMPORT_MODULES_SRC))))
263
264# Find module-info.java files in the specific source dir
265# Param 1 - Src dir to find module-info.java files in
266FindModuleInfosForSrcDir = \
267    $(wildcard \
268        $(foreach sub, $(SRC_SUBDIRS), \
269          $(patsubst %,%/*/$(sub)/module-info.java, $(strip $1)) \
270        ) \
271        $(patsubst %,%/*/module-info.java, $(strip $1)) \
272    )
273
274# Extract the module names from the paths of module-info.java files. The
275# position of the module directory differs depending on if this is an imported
276# src dir or not.
277GetModuleNameFromModuleInfo = \
278    $(strip $(foreach mi, $1, \
279      $(if $(filter $(addsuffix %, $(IMPORT_MODULES_SRC)), $(mi)), \
280        $(notdir $(patsubst %/,%, $(dir $(mi)))), \
281        $(notdir $(patsubst %/,%, $(dir $(patsubst %/,%, $(dir $(patsubst %/,%, $(dir $(mi)))))))))))
282
283# Find all modules by looking for module-info.java files and looking at parent
284# directories.
285FindAllModules = \
286    $(sort $(filter-out $(MODULES_FILTER), \
287    $(call GetModuleNameFromModuleInfo, $(MODULE_INFOS))))
288
289# Find all modules in a specific src dir
290# Param 1 - Src dir to find modules in
291FindModulesForSrcDir = \
292    $(sort $(filter-out $(MODULES_FILTER), \
293        $(call GetModuleNameFromModuleInfo, $(call FindModuleInfosForSrcDir, $1)) \
294    ))
295
296FindImportedModules = \
297    $(filter-out $(MODULES_FILTER), \
298    $(if $(IMPORT_MODULES_CLASSES), $(notdir $(wildcard $(IMPORT_MODULES_CLASSES)/*))))
299
300# Find all source dirs for a particular module
301# $1 - Module to find source dirs for
302FindModuleSrcDirs = \
303    $(strip $(wildcard \
304        $(addsuffix /$(strip $1), $(GENERATED_SRC_DIRS) $(IMPORT_MODULES_SRC)) \
305        $(foreach sub, $(SRC_SUBDIRS), $(addsuffix /$(strip $1)/$(sub), $(TOP_SRC_DIRS)))))
306
307# Find all specs dirs for a particular module
308# $1 - Module to find specs dirs for
309FindModuleSpecsDirs = \
310    $(strip $(wildcard \
311        $(foreach sub, $(SPEC_SUBDIRS), $(addsuffix /$(strip $1)/$(sub), $(TOP_SRC_DIRS)))))
312
313# Find all man dirs for a particular module
314# $1 - Module to find man dirs for
315FindModuleManDirs = \
316    $(strip $(wildcard \
317        $(foreach sub, $(MAN_SUBDIRS), $(addsuffix /$(strip $1)/$(sub), $(TOP_SRC_DIRS)))))
318
319# Construct the complete module source path
320GetModuleSrcPath = \
321    $(call PathList, \
322        $(addsuffix /*, $(GENERATED_SRC_DIRS) $(IMPORT_MODULES_SRC)) \
323        $(foreach sub, $(SRC_SUBDIRS), $(addsuffix /*/$(sub), $(TOP_SRC_DIRS))))
324
325################################################################################
326# Extract module dependencies from module-info.java files, both normal
327# dependencies ("requires"), and indirect exports ("requires transitive").
328
329MODULE_DEPS_MAKEFILE := $(MAKESUPPORT_OUTPUTDIR)/module-deps.gmk
330
331MODULE_INFOS := $(call FindAllModuleInfos, *)
332
333$(MODULE_DEPS_MAKEFILE): $(MODULE_INFOS) \
334    $(call DependOnVariable, MODULE_INFOS, $(MAKESUPPORT_OUTPUTDIR)/MODULE_INFOS.vardeps)
335	$(call MakeTargetDir)
336	$(RM) $@
337	$(foreach m, $(MODULE_INFOS), \
338	    ( $(PRINTF) "DEPS_$(call GetModuleNameFromModuleInfo, $m) :=" && \
339	      $(NAWK) -v MODULE=$(call GetModuleNameFromModuleInfo, $m) '\
340	          BEGIN      { if (MODULE != "java.base") printf(" java.base"); } \
341	          /^ *requires/ { sub(/;/, ""); \
342	                          sub(/requires /, " "); \
343	                          sub(/ static /, " "); \
344	                          sub(/ transitive /, " "); \
345	                          sub(/\/\/.*/, ""); \
346	                          sub(/\/\*.*\*\//, ""); \
347	                          gsub(/^ +\*.*/, ""); \
348	                          gsub(/ /, ""); \
349	                          printf(" %s", $$0) } \
350	          END           { printf("\n") }' $m && \
351	      $(PRINTF) "TRANSITIVE_MODULES_$(call GetModuleNameFromModuleInfo, $m) :=" && \
352	      $(NAWK) -v MODULE=$(call GetModuleNameFromModuleInfo, $m) '\
353	          BEGIN      { if (MODULE != "java.base") printf(" java.base"); } \
354	          /^ *requires  *transitive/ { \
355	                          sub(/;/, ""); \
356	                          sub(/requires/, ""); \
357	                          sub(/transitive/, ""); \
358	                          sub(/\/\/.*/, ""); \
359	                          sub(/\/\*.*\*\//, ""); \
360	                          gsub(/^ +\*.*/, ""); \
361	                          gsub(/ /, ""); \
362	                          printf(" %s", $$0) } \
363	          END           { printf("\n") }' $m \
364	    ) >> $@ $(NEWLINE))
365
366-include $(MODULE_DEPS_MAKEFILE)
367
368# Find dependencies ("requires") for a given module.
369# Param 1: Module to find dependencies for.
370FindDepsForModule = \
371  $(DEPS_$(strip $1))
372
373# Find dependencies ("requires") transitively in 3 levels for a given module.
374# Param 1: Module to find dependencies for.
375FindTransitiveDepsForModule = \
376    $(sort $(call FindDepsForModule, $1) \
377        $(foreach m, $(call FindDepsForModule, $1), \
378            $(call FindDepsForModule, $m) \
379            $(foreach n, $(call FindDepsForModule, $m), \
380                 $(call FindDepsForModule, $n))))
381
382# Find dependencies ("requires") transitively in 3 levels for a set of modules.
383# Param 1: List of modules to find dependencies for.
384FindTransitiveDepsForModules = \
385    $(sort $(foreach m, $1, $(call FindTransitiveDepsForModule, $m)))
386
387# Find indirect exported modules ("requires transitive") for a given module .
388# Param 1: Module to find indirect exported modules for.
389FindIndirectExportsForModule = \
390  $(TRANSITIVE_MODULES_$(strip $1))
391
392# Finds indirect exported modules transitively in 3 levels for a given module.
393# Param 1: Module to find indirect exported modules for.
394FindTransitiveIndirectDepsForModule = \
395    $(sort $(call FindIndirectExportsForModule, $1) \
396        $(foreach m, $(call FindIndirectExportsForModule, $1), \
397            $(call FindIndirectExportsForModule, $m) \
398            $(foreach n, $(call FindIndirectExportsForModule, $m), \
399                 $(call FindIndirectExportsForModule, $n))))
400
401# Finds indirect exported modules transitively in 3 levels for a set of modules.
402# Param 1: List of modules to find indirect exported modules for.
403FindTransitiveIndirectDepsForModules = \
404    $(sort $(foreach m, $1, $(call FindTransitiveIndirectDepsForModule, $m)))
405
406# Upgradeable modules are those that are either defined as upgradeable or that
407# require an upradeable module.
408FindAllUpgradeableModules = \
409    $(sort $(filter-out $(MODULES_FILTER), $(UPGRADEABLE_MODULES)))
410
411
412################################################################################
413
414LEGAL_SUBDIRS += $(OPENJDK_TARGET_OS)/legal
415ifneq ($(OPENJDK_TARGET_OS), $(OPENJDK_TARGET_OS_TYPE))
416  LEGAL_SUBDIRS += $(OPENJDK_TARGET_OS_TYPE)/legal
417endif
418LEGAL_SUBDIRS += share/legal
419
420# Find all legal src dirs for a particular module
421# $1 - Module to find legal dirs for
422FindModuleLegalSrcDirs = \
423    $(strip $(wildcard \
424        $(addsuffix /$(strip $1), $(IMPORT_MODULES_LEGAL)) \
425        $(foreach sub, $(LEGAL_SUBDIRS), $(addsuffix /$(strip $1)/$(sub), $(TOP_SRC_DIRS))) \
426    ))
427
428################################################################################
429
430# Param 1 - Name of module
431define ReadSingleImportMetaData
432    ifneq ($$(wildcard $(IMPORT_MODULES_MAKE)/$$(strip $1)/build.properties), )
433      classloader :=
434      include_in_jre :=
435      include_in_jdk :=
436      include $(IMPORT_MODULES_MAKE)/$$(strip $1)/build.properties
437      ifeq ($$(include_in_jre), true)
438        JRE_MODULES += $1
439      endif
440      ifeq ($$(include_in_jdk), true)
441        JDK_MODULES += $1
442      endif
443      ifeq ($$(classloader), boot)
444        BOOT_MODULES += $1
445      else ifeq ($$(classloader), ext)
446        PLATFORM_MODULES += $1
447      endif
448      ifneq ($$(include_in_docs), false)
449        # defaults to true if unspecified
450        DOCS_MODULES += $1
451      endif
452    else
453      # Default to include in all
454      JRE_MODULES += $1
455      JDK_MODULES += $1
456    endif
457endef
458
459# Reading the imported modules metadata has a cost, so to make it available,
460# a makefile needs to eval-call this macro first. After calling this, the
461# following variables are populated with data from the imported modules:
462# * JRE_MODULES
463# * JDK_MODULES
464# * BOOT_MODULES
465# * PLATFORM_MODULES
466# * JRE_TOOL_MODULES
467define ReadImportMetaData
468    IMPORTED_MODULES := $$(call FindImportedModules)
469    $$(foreach m, $$(IMPORTED_MODULES), \
470      $$(eval $$(call ReadSingleImportMetaData, $$m)))
471endef
472
473################################################################################
474
475endif # _MODULES_GMK
476