1 # 2 # Copyright (c) 2009, 2010, 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 BUILDDIR = .. 27 PRODUCT = modules 28 include $(BUILDDIR)/common/Defs.gmk 29 30 CLASSANALYZER_JAR_FILE = $(BUILDTOOLJARDIR)/classanalyzer.jar 31 MODULES_CONFIG = modules.config 32 MODULES_GROUP = modules.group 33 MODULES_PROPERTIES = modules.properties 34 DEP_CONFIG = jdk.depconfig 35 OPTIONAL_DEP_CONFIG = optional.depconfig 36 37 # 38 # Modularizing the JDK 39 # - Post jdk build process until the source tree is restructured 40 # for modules build 41 # - <outputdir>/modules/<module> will be created for each module 42 # - modules are installed in <outputdir>/lib/modules (jigsaw module 43 # library) 44 # 45 # Steps: 46 # 0. During jdk build before this makefile is invoked, classes, 47 # resource files, and other non-class files such as native libraries, 48 # properties file, images, etc are created. 49 # 50 # Non-class files are copied to <outputdir>/submodules/<MODULE> 51 # directory in this step to prepare for the post-build modularization. 52 # 53 # The MODULE variable defined in other makefiles specifies 54 # the lowest-level module that the non-class files belong to. 55 # The name might or might not be the same as the name of the modules 56 # in the resulting <outputdir>/modules directory. 57 # 58 # 1. Run ClassAnalyzer tool to analyze all jdk classes and generate 59 # class list for all modules and also perform dependency analysis. 60 # 61 # Input configuration files :- 62 # 63 # modules.config : defines the low-level modules and specifies 64 # what classes and resource files each module includes. 65 # modules.group : defines the module groups and its members. 66 # jdk.depconfig : lists the dynamic dependencies including 67 # use of reflection Class.forName and JNI FindClass and 68 # service provider. 69 # optional.depconfig : lists the optional dependencies 70 # 71 # For incremental build, ClassAnalyzer tool will only parse files 72 # that are updated since the last build (by comparing the timestamp 73 # of modules.list). 74 # 75 # 2. Compile module-info.java files generated by the ClassAnalyzer tool. 76 # (only updated module-info.java files for incremental build) 77 # 78 # 3. Modularize the JDK. It creates one directory for each module 79 # (<outputdir>/modules/<module>) based on the output files 80 # from (1) and also creates a jigsaw module library. 81 # 82 # a. Run Modularizer tool to copy files listed in $m.classlist and 83 # $m.resources to <outputdir>/modules/$m/classes and 84 # <outputdir>/modules/$m/resources respectively. 85 # 86 # For incremental build, Modularizer tool will only copy files 87 # that are modified since the last run (by comparing the timestamp 88 # between the source and destination). 89 # 90 # b. copy all non-class files from its members (such as bin, lib, include) 91 # to <outputdir>/modules/$m. 92 # 93 # modules.list lists the modules to be created for the modules 94 # build and its members. 95 # 96 # c. Install each module in the jigsaw module library 97 # 98 ORB_IDL=$(MODULEPATH_DIR)/$(IDLJ_MODULE)/etc/orb.idl 99 IR_IDL=$(MODULEPATH_DIR)/$(IDLJ_MODULE)/etc/ir.idl 100 101 102 all: $(MODULES_LIST) module-info-classes $(ORB_IDL) $(IR_IDL) modularize 103 104 105 # clean modules build 106 define clean-build 107 $(RM) -rf $(JIGSAW_MODULE_LIB) 108 $(RM) -rf $(MODULEINFO_DIR) 109 $(RM) -rf $(MODULEPATH_DIR) 110 $(RM) -rf $(MODULES_TEMPDIR) 111 $(ECHO) "" > $(MODULES_UPDATE_MARKER) 112 endef 113 114 # Do a clean modules build if any of the input modules.config 115 # files is modified. 116 $(MODULES_LIST):: $(MODULES_CONFIG) $(MODULES_GROUP) \ 117 $(MODULES_PROPERTIES) \ 118 $(DEP_CONFIG) $(OPTIONAL_DEP_CONFIG) \ 119 $(CLASSANALYZER_JAR_FILE) 120 $(clean-build) 121 122 # 123 # Run class analyzer to analyze the jdk. For incremental build, 124 # only recompiled classes are parsed. module-info.java source 125 # files for all or just the updated modules are generated. 126 $(MODULES_LIST):: $(MODULES_UPDATE_MARKER) 127 @$(ECHO) ">>>Making "$@" @ `$(DATE)` ..." 128 $(clean-build) 129 $(HOST_JAVA_CMD) \ 130 -jar $(CLASSANALYZER_JAR_FILE) \ 131 -jdkhome $(OUTPUTDIR) \ 132 -config $(MODULES_CONFIG) \ 133 -config $(MODULES_GROUP) \ 134 -depconfig $(DEP_CONFIG) \ 135 -depconfig $(OPTIONAL_DEP_CONFIG) \ 136 -properties $(MODULES_PROPERTIES) \ 137 -version $(MODULE_VERSION) \ 138 -base $(BASE_MODULE) \ 139 -output $(MODULE_CLASSLIST_DIR) \ 140 -moduleinfo $(MODULEINFO_SRC) 141 @$(java-vm-cleanup) 142 @$(ECHO) ">>>Finished making "$@" @ `$(DATE)` ..." 143 144 # Rules for compiling module-info.java 145 # -Xbootclasspath is needed to compile module-info.java 146 # if JDK_HOST_PATH is a legacy jdk and the main class 147 # for some modules are not in rt.jar (or $outputdir/classes) 148 BOOTCLASSPATH := $(shell bcp="$(OUTPUTDIR)/classes"; \ 149 jfiles=`$(FIND) $(OUTPUTDIR)/lib -name \*.jar -print` ; \ 150 for jf in $$jfiles ; do \ 151 if [ -f $$jf ] ; then \ 152 bcp="$$bcp$(CLASSPATH_SEPARATOR)$$jf"; \ 153 fi \ 154 done; \ 155 $(ECHO) $$bcp) 156 JAVAC_CMD := $(HOST_JAVAC_CMD) \ 157 -Xbootclasspath:"$(BOOTCLASSPATH)" \ 158 -modulepath $(MODULEPATH_DIR) \ 159 -sourcepath $(MODULEINFO_SRC) 160 FILES_java := $(shell $(NAWK) '{print $$1 "/module-info.java"}' ${MODULES_LIST}) 161 CLASSDESTDIR = $(MODULEPATH_DIR) 162 163 include $(BUILDDIR)/common/Classes.gmk 164 165 # Compile module-info.java 166 # javac depends on the jigsaw module library to exist 167 module-info-classes: 168 if [ ! -d $(JIGSAW_MODULE_LIB) ] ; then \ 169 $(HOST_JMOD_CMD) create -N $(JMOD_CREATE_ARGS) -L $(JIGSAW_MODULE_LIB) ; \ 170 fi 171 $(MAKE) classes || exit 1 172 173 $(MODULEPATH_DIR)/%/module-info.class: $(MODULEINFO_SRC)/%/module-info.java 174 @$(add-java-file) 175 176 # copy module-info.class from modules/$m directory to 177 # modules/$m/classes. Default module-info destination for javac 178 # multi-module path is <modulepath>/<module>. 179 $(MODULEPATH_DIR)/%/classes/module-info.class: $(MODULEPATH_DIR)/%/module-info.class 180 @$(install-non-module-file) 181 182 # 183 # Modularize JDK and install the modules in the jigsaw library 184 modularize: $(MODULES_LIST) 185 @$(ECHO) ">>>Making "$@" @ `$(DATE)` ..." 186 $(HOST_JAVA_CMD) \ 187 -cp $(CLASSANALYZER_JAR_FILE) \ 188 com.sun.classanalyzer.Modularizer \ 189 -jdkhome $(OUTPUTDIR) \ 190 -classlistdir $(MODULE_CLASSLIST_DIR) \ 191 -modulepath $(ABS_MODULEPATH_DIR) 192 @$(java-vm-cleanup) 193 $(MAKE) `$(NAWK) '{print "$(JIGSAW_MODULE_LIB)/" $$1 "/$(MODULE_VERSION)/info" }' $<` || exit 1 194 @$(ECHO) ">>>Finished making "$@" @ `$(DATE)` ..." 195 196 197 # copy-module-content 198 # $1 - module 199 # 200 # TODO: 201 # How should the *.map (symbol -> address mappings) and 202 # the .pdb (debug info) files be packaged? one for each module 203 # their .dll resides? We need to make them available for 204 # troubleshooting and support purpose. 205 # 206 define copy-module-content 207 m=$(strip $1); \ 208 mlib=$(ABS_MODULEPATH_DIR)/$$m ; \ 209 $(MKDIR) -p $$mlib ; \ 210 for s in `$(GREP) "^$$m " $(MODULES_LIST)` ; do \ 211 if [ -d $(ABS_SUBMODULES_DIR)/$$s ] ; then \ 212 for d in bin lib etc include ; do \ 213 if [ -d $(ABS_SUBMODULES_DIR)/$$s/$$d ] ; then \ 214 $(MKDIR) -p $$mlib/$$d ; \ 215 $(CP) -rf $(ABS_SUBMODULES_DIR)/$$s/$$d/* $$mlib/$$d; \ 216 fi ; \ 217 done \ 218 fi ; \ 219 done ; \ 220 $(FIND) $$mlib -name '*.map' -exec $(RM) \{} \; ; \ 221 $(FIND) $$mlib -name '*.pdb' -exec $(RM) \{} \; ; 222 endef 223 224 define install-module 225 m=$(strip $*); \ 226 $(RM) -r $(JIGSAW_MODULE_LIB)/$$m ; \ 227 $(ECHO) "Installing module $$m" ; \ 228 $(CD) $(MODULEPATH_DIR) && \ 229 $(HOST_JMOD_CMD) -J-esa install $$m/classes $$m -L $(JIGSAW_MODULE_LIB) $(JMOD_INSTALL_ARGS) || exit 1 ; 230 endef 231 232 define patch-module-classes 233 m=$(strip $*); \ 234 tmp=$(ABS_MODULES_TEMPDIR)/$$m.files ; \ 235 $(SED) -e 's%\\%\/%g' $(MODULE_CLASSLIST_DIR)/$$m.classlist > $$tmp || exit 1 ; \ 236 if [ -f $(MODULE_CLASSLIST_DIR)/$$m.resources ] ; then \ 237 $(SED) -e 's%\\%\/%g' $(MODULE_CLASSLIST_DIR)/$$m.resources | \ 238 $(EGREP) -v "default_US_export.policy|default_local.policy|exempt_local.policy" \ 239 >> $$tmp || exit 1 ; \ 240 fi ; \ 241 $(ECHO) "Patching classes for module $$m" ; \ 242 rsync -v -t --files-from=$$tmp $(ABS_OUTPUTDIR)/classes $(ABS_MODULEPATH_DIR)/$$m/classes || exit 1; 243 endef 244 245 # 246 # Install the module if module-info.class is updated 247 # or <module>.summary is updated 248 # 249 $(JIGSAW_MODULE_LIB)/%/$(MODULE_VERSION)/info: $(MODULEPATH_DIR)/%/classes/module-info.class \ 250 $(MODULE_CLASSLIST_DIR)/%.summary 251 @if [ $* = "other" ] ; then \ 252 $(ECHO) "ERROR: Check module \"other\". modules.config possibly requires update." ; \ 253 exit 1; \ 254 fi 255 @$(call copy-module-content,$*) 256 @$(call install-module,$*) 257 @$(java-vm-cleanup) 258 259 # 260 # Temporary workaround: 261 # Copy orb.idl and ir.idl to idlj module 262 # The *.idl files are imported during the build 263 # 264 # A better fix would be in make/common/internal/ImportComponents.gmk 265 # to install imported files in a module 266 $(MODULEPATH_DIR)/$(IDLJ_MODULE)/etc/%.idl : $(LIBDIR)/%.idl 267 $(install-non-module-file) 268 269 clean clobber:: classes.clean 270 $(clean-build) 271 272 273 # '<module-name>' development target to update the module content 274 # of a specific module in the jigsaw module library in the outputdir 275 # and also in jdk-module-library if exists. 276 # $ make jdk.boot 277 # 278 # TODO: modify Modularizer to take a parameter to only copy 279 # classes and resources for one module 280 %: 281 @if [ `$(GREP) -c "^$@ " $(MODULES_LIST)` != "1" ] ; then \ 282 $(ECHO) 'Invalid target: "$@" expected a valid module name' ; \ 283 exit 1; \ 284 fi 285 $(call patch-module-classes,$@) 286 $(call install-module,$@) 287 @$(java-vm-cleanup) 288 @if [ -d $(OUTPUTDIR)/jdk-module-image/lib/modules ] ; then \ 289 $(RM) -r $(OUTPUTDIR)/jdk-module-image/lib/modules/$@ ; \ 290 $(CP) -r $(JIGSAW_MODULE_LIB)/$@ $(OUTPUTDIR)/jdk-module-image/lib/modules/$@ ; \ 291 fi 292 293 .PHONY: modularize module-info-classes 294 295 # GNU make bug: make pattern rules delete intermediate files 296 # Workaround: marks the files as precious 297 .PRECIOUS: $(MODULEPATH_DIR)/%/classes/module-info.class \ 298 $(MODULEPATH_DIR)/%/module-info.class \ 299 $(MODULEPATH_DIR)/%/.modules.update