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