# # Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License version 2 only, as # published by the Free Software Foundation. Oracle designates this # particular file as subject to the "Classpath" exception as provided # by Oracle in the LICENSE file that accompanied this code. # # This code is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # version 2 for more details (a copy is included in the LICENSE file that # accompanied this code). # # You should have received a copy of the GNU General Public License version # 2 along with this work; if not, write to the Free Software Foundation, # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. # # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA # or visit www.oracle.com if you need additional information or have any # questions. # BUILDDIR = .. PRODUCT = modules include $(BUILDDIR)/common/Defs.gmk CLASSANALYZER_JAR_FILE = $(BUILDTOOLJARDIR)/classanalyzer.jar MODULES_CONFIG = modules.config MODULES_GROUP = modules.group MODULES_PROPERTIES = modules.properties DEP_CONFIG = jdk7.depconfig OPTIONAL_DEP_CONFIG = optional.depconfig # # Modularizing the JDK # - Post jdk build process until the source tree is restructured # for modules build # - /modules/ will be created for each module # - modules are installed in /lib/modules (jigsaw module # library) # # Steps: # 0. During jdk build before this makefile is invoked, classes, # resource files, and other non-class files such as native libraries, # properties file, images, etc are created. # # Non-class files are copied to /submodules/ # directory in this step to prepare for the post-build modularization. # # The MODULE variable defined in other makefiles specifies # the lowest-level module that the non-class files belong to. # The name might or might not be the same as the name of the modules # in the resulting /modules directory. # # 1. Run ClassAnalyzer tool to analyze all jdk classes and generate # class list for all modules and also perform dependency analysis. # # Input configuration files :- # # modules.config : defines the low-level modules and specifies # what classes and resource files each module includes. # modules.group : defines the module groups and its members. # jdk7.depconfig : lists the dynamic dependencies including # use of reflection Class.forName and JNI FindClass and # service provider. # optional.depconfig : lists the optional dependencies # # For incremental build, ClassAnalyzer tool will only parse files # that are updated since the last build (by comparing the timestamp # of modules.list). # # 2. Compile module-info.java files generated by the ClassAnalyzer tool. # (only updated module-info.java files for incremental build) # # 3. Modularize the JDK. It creates one directory for each module # (/modules/) based on the output files # from (1) and also creates a jigsaw module library. # # a. Run Modularizer tool to copy files listed in $m.classlist and # $m.resources to /modules/$m/classes and # /modules/$m/resources respectively. # # For incremental build, Modularizer tool will only copy files # that are modified since the last run (by comparing the timestamp # between the source and destination). # # b. copy all non-class files from its members (such as bin, lib, include) # to /modules/$m. # # modules.list lists the modules to be created for the modules # build and its members. # # c. Install each module in the jigsaw module library # all: $(MODULES_LIST) module-info-classes modularize $(ORB_IDL) $(IR_IDL) # clean modules build define clean-build $(RM) -rf $(JIGSAW_MODULE_LIB) $(RM) -rf $(MODULEINFO_DIR) $(RM) -rf $(MODULEPATH_DIR) $(ECHO) "" > $(MODULES_UPDATE_MARKER) endef # Do a clean modules build if any of the input modules.config # files is modified. $(MODULES_LIST):: $(MODULES_CONFIG) $(MODULES_GROUP) \ $(MODULES_PROPERTIES) \ $(DEP_CONFIG) $(OPTIONAL_DEP_CONFIG) \ $(CLASSANALYZER_JAR_FILE) $(clean-build) # # Run class analyzer to analyze the jdk. For incremental build, # only recompiled classes are parsed. module-info.java source # files for all or just the updated modules are generated. $(MODULES_LIST):: $(MODULES_UPDATE_MARKER) @$(ECHO) ">>>Making "$@" @ `$(DATE)` ..." $(HOST_JAVA_CMD) \ -Dclassanalyzer.debug \ -jar $(CLASSANALYZER_JAR_FILE) \ -jdkhome $(OUTPUTDIR) \ -config $(MODULES_CONFIG) \ -config $(MODULES_GROUP) \ -depconfig $(DEP_CONFIG) \ -depconfig $(OPTIONAL_DEP_CONFIG) \ -properties $(MODULES_PROPERTIES) \ -version $(MODULE_VERSION) \ -update \ -output $(MODULE_CLASSLIST_DIR) \ -moduleinfo $(MODULEINFO_SRC) \ -noncorepkgs $(BUILDDIR)/docs/NON_CORE_PKGS.gmk @$(java-vm-cleanup) @$(ECHO) ">>>Finished making "$@" @ `$(DATE)` ..." # Rules for compiling module-info.java # -Xbootclasspath is needed to compile module-info.java # if JDK_HOST_PATH is a legacy jdk and the main class # for some modules are not in rt.jar (or $outputdir/classes) BOOTCLASSPATH := $(shell bcp="$(OUTPUTDIR)/classes"; \ $(CD) $(OUTPUTDIR)/lib && ( \ jfiles=`$(FIND) . -name \*.jar -print`) ; \ for jf in $$jfiles ; do \ if [ -f $$jf ] ; then \ bcp="$$bcp$(CLASSPATH_SEPARATOR)$(OUTPUTDIR)/lib/$$jf"; \ fi \ done; \ $(ECHO) $$bcp) JAVAC_CMD = $(HOST_JAVAC_CMD) \ -Xbootclasspath:$(BOOTCLASSPATH) \ -modulepath $(MODULEPATH_DIR) \ -sourcepath $(MODULEINFO_SRC) FILES_java := $(shell $(CD) $(MODULEINFO_SRC) && \ $(FIND) . -name '*.java' -print) CLASSDESTDIR = $(MODULEPATH_DIR) include $(BUILDDIR)/common/Classes.gmk # Compile module-info.java # javac depends on the jigsaw module library to exist module-info-classes: if [ ! -d $(JIGSAW_MODULE_LIB) ] ; then \ $(HOST_JMOD_CMD) create -N -L $(JIGSAW_MODULE_LIB) ; \ fi $(MAKE) classes $(MODULEPATH_DIR)/%/module-info.class: $(MODULEINFO_SRC)/%/module-info.java @$(add-java-file) # copy module-info.class from modules/$m directory to # modules/$m/classes. Default module-info destination for javac # multi-module path is /. $(MODULEPATH_DIR)/%/classes/module-info.class: $(MODULEPATH_DIR)/%/module-info.class @$(install-non-module-file) # # Modularize JDK and install the modules in the jigsaw library modularize: $(MODULES_LIST) @$(ECHO) ">>>Making "$@" @ `$(DATE)` ..." $(HOST_JAVA_CMD) \ -Dclassanalyzer.debug \ -cp $(CLASSANALYZER_JAR_FILE) \ com.sun.classanalyzer.Modularizer \ -jdkhome $(OUTPUTDIR) \ -update \ -classlist $(MODULE_CLASSLIST_DIR) \ -modulepath $(ABS_MODULEPATH_DIR) @$(java-vm-cleanup) $(MAKE) `$(NAWK) '{print "$(JIGSAW_MODULE_LIB)/" $$1 "/$(MODULE_VERSION)/info" }' $<` @$(ECHO) ">>>Finished making "$@" @ `$(DATE)` ..." # copy-module-content # $1 - module # # TODO: # How should the *.map (symbol -> address mappings) and # the .pdb (debug info) files be packaged? one for each module # their .dll resides? We need to make them available for # troubleshooting and support purpose. # define copy-module-content m=$(strip $1); \ mlib=$(ABS_MODULEPATH_DIR)/$$m ; \ $(MKDIR) -p $$mlib ; \ for s in `$(GREP) "^$$m " $(MODULES_LIST)` ; do \ if [ -d $(ABS_SUBMODULES_DIR)/$$s ] ; then \ for d in bin lib etc include ; do \ if [ -d $(ABS_SUBMODULES_DIR)/$$s/$$d ] ; then \ $(CP) -rf $(ABS_SUBMODULES_DIR)/$$s/$$d $$mlib; \ fi ; \ done \ fi ; \ done ; \ $(FIND) $$mlib -name '*.map' -exec $(RM) \{} \; ; \ $(FIND) $$mlib -name '*.pdb' -exec $(RM) \{} \; ; endef # # Install the module if module-info.class is updated # or .summary is updated # $(JIGSAW_MODULE_LIB)/%/$(MODULE_VERSION)/info: $(MODULEPATH_DIR)/%/classes/module-info.class \ $(MODULE_CLASSLIST_DIR)/%.summary $(call copy-module-content,$*) $(RM) -r $(JIGSAW_MODULE_LIB)/$* m=$(strip $*); \ $(ECHO) "Installing module $$m" ; \ $(CD) $(MODULEPATH_DIR) && \ if [ -f $(MODULE_CLASSLIST_DIR)/$$m.resources ] ; then \ $(HOST_JMOD_CMD) install $$m/classes -r $$m/resources $$m \ -L $(JIGSAW_MODULE_LIB) || exit 1 ; \ else \ $(HOST_JMOD_CMD) install $$m/classes $$m \ -L $(JIGSAW_MODULE_LIB) || exit 1 ; \ fi @$(java-vm-cleanup) # # Temporary workaround: # Copy orb.idl and ir.idl to idlj module # The *.idl files are imported during the build # # A better fix would be in make/common/internal/ImportComponents.gmk # to install imported files in a module ORB_IDL=$(MODULEPATH_DIR)/$(IDLJ_MODULE)/lib/orb.idl IR_IDL=$(MODULEPATH_DIR)/$(IDLJ_MODULE)/lib/ir.idl $(MODULEPATH_DIR)/$(IDLJ_MODULE)/lib/%.idl : $(LIBDIR)/%.idl $(install-non-module-file) clean clobber:: $(clean-build) .PHONY: modularize module-info-classes # GNU make bug: make pattern rules delete intermediate files # Workaround: marks the files as precious .PRECIOUS: $(MODULEPATH_DIR)/%/classes/module-info.class \ $(MODULEPATH_DIR)/%/module-info.class \ $(MODULEPATH_DIR)/%/.modules.update