--- old/make/modules/Makefile Wed Oct 20 09:30:43 2010 +++ new/make/modules/Makefile Wed Oct 20 09:30:43 2010 @@ -24,13 +24,23 @@ # 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/ 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, @@ -37,7 +47,7 @@ # resource files, and other non-class files such as native libraries, # properties file, images, etc are created. # -# Non-class files are copied to /tmp/modules/ +# 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 @@ -45,11 +55,7 @@ # The name might or might not be the same as the name of the modules # in the resulting /modules directory. # -# 1. Unpack all jars in the /lib directory to a temporary -# location (/tmp/modules/classes) to prepare for modules -# creation. -# -# 2. Run ClassAnalyzer tool to analyze all jdk classes and generate +# 1. Run ClassAnalyzer tool to analyze all jdk classes and generate # class list for all modules and also perform dependency analysis. # # Input configuration files :- @@ -62,52 +68,58 @@ # service provider. # optional.depconfig : lists the optional dependencies # -# 3. Create one directory for each module (/modules/) -# based on the output files from (2). +# 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. # -# modules.list lists the modules to be created for the modules -# build and its members. For each module (m) in modules.list, -# a. copy classes listed in $m.classlist and $m.resources to -# /modules/$m/classes and /modules/$m/resources -# respectively. -# b. copy all other files from its members (such as bin, lib, include) +# 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. -# c. move module-info.class from modules/$m directory to -# modules/$m/classes. Default module-info destination for javac -# multi-module path is /. +# +# modules.list lists the modules to be created for the modules +# build and its members. +# +# c. Install each module in the jigsaw module library # -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 -MODULE_CLASSES = $(ABS_MODULES_TEMPDIR)/classes +all: $(MODULES_LIST) module-info-classes modularize $(ORB_IDL) $(IR_IDL) -all:: $(MODULES_LIST) install-modules +# clean modules build +define clean-build +$(RM) -rf $(JIGSAW_MODULE_LIB) +$(RM) -rf $(MODULEINFO_DIR) +$(RM) -rf $(MODULEPATH_DIR) +$(ECHO) "" > $(MODULES_UPDATE_MARKER) +endef -JAR_LIST := $(shell $(FIND) $(ABS_OUTPUTDIR)/lib -name \*.jar -print) -unpack-jars: - @$(ECHO) ">>>Making "$@" @ `$(DATE)` ..." - $(RM) -rf $(MODULE_CLASSES) - $(MKDIR) -p $(MODULE_CLASSES) - @for jf in $(JAR_LIST) ; do \ - if [ -f $$jf ] ; then \ - $(CD) $(MODULE_CLASSES) && $(BOOT_JAR_CMD) xf $$jf $(BOOT_JAR_JFLAGS); \ - fi ; \ - done - $(CP) -rf $(CLASSBINDIR)/* $(MODULE_CLASSES) - @$(ECHO) ">>>Finished making "$@" @ `$(DATE)` ..." - -$(MODULES_LIST): $(MODULES_CONFIG) $(MODULES_GROUP) \ +# 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)` ..." - @$(RM) -rf $(MODULE_CLASSLIST_DIR) - @$(RM) -rf $(MODULEINFO_SRC) - @$(MKDIR) -p $(MODULE_CLASSLIST_DIR) $(HOST_JAVA_CMD) \ -Dclassanalyzer.debug \ -jar $(CLASSANALYZER_JAR_FILE) \ @@ -117,36 +129,72 @@ -depconfig $(DEP_CONFIG) \ -depconfig $(OPTIONAL_DEP_CONFIG) \ -properties $(MODULES_PROPERTIES) \ - -base $(BASE_MODULE) \ -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)` ..." -# -# TODO: create only modules that belong to the specified -# BUILD_MODULES. Currently, all jdk modules are created -# but some modules may be in partial state since some -# classes are compiled due to the dependencies. - -# Modularize the jdk: - -# -# Compile module-info.java for all modules +# 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) + # -# Create modules listed in the modules.list output by the ClassAnalyzer -# 1. Merge all non-class and non-resource files from module members -# to modules/$m -# 2. Copy all class files into modules/$m/classes -# 3. Copy all resource files into modules/$m/resources -# 4. Move module-info.class from modules/$m directory to -# modules/$m/classes. Default module-info destination for -# javac multi-module path is /. -# jmod only takes a directory with classes only. -# What should be the modules directory hierachy for packaging? +# 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 @@ -154,51 +202,43 @@ # 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 -prep-module-lib: - $(RM) -rf $(JIGSAW_MODULE_LIB) - $(HOST_JMOD_CMD) create -N -L $(JIGSAW_MODULE_LIB) +# +# 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) -modularize: unpack-jars prep-module-lib - @$(ECHO) ">>>Making "$@" @ `$(DATE)` ..." - $(RM) -rf $(MODULES_DIR) - @$(MKDIR) -p $(MODULES_DIR) - $(HOST_JAVAC_CMD) -d $(MODULES_DIR) \ - -Xbootclasspath:$(MODULE_CLASSES) \ - -modulepath $(MODULES_DIR) \ - -sourcepath $(MODULEINFO_SRC) \ - $(MODULEINFO_SRC)/*/module-info.java - $(CD) $(MODULE_CLASSES) && \ - for m in `$(NAWK) '{print $$1}' $(MODULES_LIST)` ; do \ - $(ECHO) "Creating module $$m" ; \ - mlib=$(ABS_MODULES_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 ; \ - $(MKDIR) -p $$mlib/classes ; \ - $(MV) $$mlib/module-info.class $$mlib/classes ; \ - if [ -f $(MODULE_CLASSLIST_DIR)/$$m.classlist ] ; then \ - $(SED) -e 's%\\%\/%g' < $(MODULE_CLASSLIST_DIR)/$$m.classlist \ - | $(CPIO) -pdum $$mlib/classes ; \ - fi ; \ - if [ -f $(MODULE_CLASSLIST_DIR)/$$m.resources ] ; then \ - $(MKDIR) -p $$mlib/resources ; \ - $(SED) -e 's%\\%\/%g' < $(MODULE_CLASSLIST_DIR)/$$m.resources \ - | $(CPIO) -pdum $$mlib/resources ; \ - fi ; \ - $(FIND) $$mlib -name '*.map' -exec $(RM) \{} \; ; \ - $(FIND) $$mlib -name '*.pdb' -exec $(RM) \{} \; ; \ - done - @$(CD) $(MODULE_CLASSES) && $(java-vm-cleanup) - @$(ECHO) ">>>Finished making "$@" @ `$(DATE)` ..." - # # Temporary workaround: # Copy orb.idl and ir.idl to idlj module @@ -206,29 +246,18 @@ # # A better fix would be in make/common/internal/ImportComponents.gmk # to install imported files in a module -ORB_IDL=$(MODULES_DIR)/$(IDLJ_MODULE)/lib/orb.idl -IR_IDL=$(MODULES_DIR)/$(IDLJ_MODULE)/lib/ir.idl -$(MODULES_DIR)/$(IDLJ_MODULE)/lib/%.idl : $(LIBDIR)/%.idl +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) -install-modules: modularize $(ORB_IDL) $(IR_IDL) - @$(ECHO) ">>>Making "$@" @ `$(DATE)` ..." - $(CD) $(MODULES_DIR) && \ - for m in `$(NAWK) '{print $$1}' $(MODULES_LIST)` ; do \ - $(ECHO) "Installing module $$m" ; \ - 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 ; \ - done - @$(ECHO) ">>>Finished making "$@" @ `$(DATE)` ..." - clean clobber:: - $(RM) -rf $(MODULEINFO_DIR) - $(RM) -rf $(MODULES_DIR) - $(RM) -rf $(JIGSAW_MODULE_LIB) + $(clean-build) -.PHONY: unpack-jars gen-classlist prep-module-lib modularize install-modules +.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