1 #
   2 # Copyright (c) 2009, 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 = jdk7.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 #    jdk7.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 
  99 all: $(MODULES_LIST) module-info-classes modularize $(ORB_IDL) $(IR_IDL)
 100 
 101 # clean modules build
 102 define clean-build
 103 $(RM) -rf $(JIGSAW_MODULE_LIB)
 104 $(RM) -rf $(MODULEINFO_DIR)
 105 $(RM) -rf $(MODULEPATH_DIR)
 106 $(ECHO) "" > $(MODULES_UPDATE_MARKER)
 107 endef
 108 
 109 # Do a clean modules build if any of the input modules.config
 110 # files is modified.
 111 $(MODULES_LIST):: $(MODULES_CONFIG) $(MODULES_GROUP) \
 112                  $(MODULES_PROPERTIES) \
 113                  $(DEP_CONFIG) $(OPTIONAL_DEP_CONFIG) \
 114                  $(CLASSANALYZER_JAR_FILE)
 115         $(clean-build)
 116 
 117 #
 118 # Run class analyzer to analyze the jdk.  For incremental build,
 119 # only recompiled classes are parsed.  module-info.java source
 120 # files for all or just the updated modules are generated.
 121 $(MODULES_LIST):: $(MODULES_UPDATE_MARKER)
 122         @$(ECHO) ">>>Making "$@" @ `$(DATE)` ..."
 123         $(HOST_JAVA_CMD) \
 124                 -Dclassanalyzer.debug \
 125                 -jar $(CLASSANALYZER_JAR_FILE) \
 126                 -jdkhome $(OUTPUTDIR) \
 127                 -config $(MODULES_CONFIG) \
 128                 -config $(MODULES_GROUP) \
 129                 -depconfig $(DEP_CONFIG) \
 130                 -depconfig $(OPTIONAL_DEP_CONFIG) \
 131                 -properties $(MODULES_PROPERTIES) \
 132                 -version $(MODULE_VERSION) \
 133                 -update \
 134                 -output $(MODULE_CLASSLIST_DIR) \
 135                 -moduleinfo $(MODULEINFO_SRC) \
 136                 -noncorepkgs $(BUILDDIR)/docs/NON_CORE_PKGS.gmk
 137         @$(java-vm-cleanup)
 138         @$(ECHO) ">>>Finished making "$@" @ `$(DATE)` ..."
 139 
 140 # Rules for compiling module-info.java
 141 # -Xbootclasspath is needed to compile module-info.java
 142 # if JDK_HOST_PATH is a legacy jdk and the main class
 143 # for some modules are not in rt.jar (or $outputdir/classes) 
 144 BOOTCLASSPATH := $(shell bcp="$(OUTPUTDIR)/classes"; \
 145                       $(CD) $(OUTPUTDIR)/lib && ( \
 146                       jfiles=`$(FIND) . -name \*.jar -print`) ; \
 147                       for jf in  $$jfiles ; do \
 148                           if [ -f $$jf ] ; then \
 149                               bcp="$$bcp$(CLASSPATH_SEPARATOR)$(OUTPUTDIR)/lib/$$jf"; \
 150                           fi \
 151                       done; \
 152                       $(ECHO) $$bcp) 
 153 JAVAC_CMD = $(HOST_JAVAC_CMD) \
 154                     -Xbootclasspath:$(BOOTCLASSPATH) \
 155                     -modulepath $(MODULEPATH_DIR) \
 156                     -sourcepath $(MODULEINFO_SRC) 
 157 FILES_java := $(shell $(CD) $(MODULEINFO_SRC) && \
 158                    $(FIND) . -name '*.java' -print)
 159 CLASSDESTDIR = $(MODULEPATH_DIR)
 160 
 161 include $(BUILDDIR)/common/Classes.gmk
 162 
 163 # Compile module-info.java
 164 # javac depends on the jigsaw module library to exist
 165 module-info-classes:
 166         if [ ! -d $(JIGSAW_MODULE_LIB) ] ; then \
 167            $(HOST_JMOD_CMD) create -N -L $(JIGSAW_MODULE_LIB) ; \
 168         fi
 169         $(MAKE) classes
 170 
 171 $(MODULEPATH_DIR)/%/module-info.class: $(MODULEINFO_SRC)/%/module-info.java
 172         @$(add-java-file)
 173 
 174 #  copy module-info.class from modules/$m directory to 
 175 #  modules/$m/classes. Default module-info destination for javac 
 176 #  multi-module path is <modulepath>/<module>.
 177 $(MODULEPATH_DIR)/%/classes/module-info.class: $(MODULEPATH_DIR)/%/module-info.class
 178         @$(install-non-module-file)
 179 
 180 #
 181 # Modularize JDK and install the modules in the jigsaw library
 182 modularize: $(MODULES_LIST)
 183         @$(ECHO) ">>>Making "$@" @ `$(DATE)` ..."
 184         $(HOST_JAVA_CMD) \
 185                 -Dclassanalyzer.debug \
 186                 -cp $(CLASSANALYZER_JAR_FILE) \
 187                 com.sun.classanalyzer.Modularizer \
 188                 -jdkhome $(OUTPUTDIR) \
 189                 -update \
 190                 -classlist $(MODULE_CLASSLIST_DIR) \
 191                 -modulepath $(ABS_MODULEPATH_DIR)
 192         @$(java-vm-cleanup)
 193         $(MAKE) `$(NAWK) '{print "$(JIGSAW_MODULE_LIB)/" $$1 "/$(MODULE_VERSION)/info" }' $<`
 194         @$(ECHO) ">>>Finished making "$@" @ `$(DATE)` ..."
 195 
 196 # copy-module-content
 197 #    $1 - module
 198 #
 199 # TODO:
 200 # How should the *.map (symbol -> address mappings) and
 201 # the .pdb (debug info) files be packaged?  one for each module
 202 # their .dll resides?  We need to make them available for 
 203 # troubleshooting and support purpose.
 204 #
 205 define copy-module-content
 206   m=$(strip $1); \
 207   mlib=$(ABS_MODULEPATH_DIR)/$$m ; \
 208   $(MKDIR) -p $$mlib ; \
 209   for s in `$(GREP) "^$$m " $(MODULES_LIST)` ; do \
 210      if [ -d $(ABS_SUBMODULES_DIR)/$$s ] ; then \
 211          for d in bin lib etc include ; do \
 212             if [ -d $(ABS_SUBMODULES_DIR)/$$s/$$d ] ; then \
 213                 $(CP) -rf $(ABS_SUBMODULES_DIR)/$$s/$$d  $$mlib; \
 214             fi ; \
 215          done \
 216      fi ; \
 217   done ; \
 218   $(FIND) $$mlib -name '*.map' -exec $(RM) \{} \; ; \
 219   $(FIND) $$mlib -name '*.pdb' -exec $(RM) \{} \; ;
 220 endef
 221 
 222 #
 223 # Install the module if module-info.class is updated
 224 # or <module>.summary is updated
 225 #
 226 $(JIGSAW_MODULE_LIB)/%/$(MODULE_VERSION)/info: $(MODULEPATH_DIR)/%/classes/module-info.class \
 227                                                $(MODULE_CLASSLIST_DIR)/%.summary
 228         $(call copy-module-content,$*)
 229         $(RM) -r $(JIGSAW_MODULE_LIB)/$*
 230         m=$(strip $*); \
 231         $(ECHO) "Installing module $$m" ; \
 232         $(CD) $(MODULEPATH_DIR) && \
 233         if [ -f $(MODULE_CLASSLIST_DIR)/$$m.resources ] ; then \
 234            $(HOST_JMOD_CMD) install $$m/classes -r $$m/resources $$m \
 235                -L $(JIGSAW_MODULE_LIB) || exit 1 ; \
 236         else \
 237            $(HOST_JMOD_CMD) install $$m/classes $$m \
 238                -L $(JIGSAW_MODULE_LIB) || exit 1 ; \
 239         fi
 240         @$(java-vm-cleanup)
 241 
 242 #
 243 # Temporary workaround:
 244 # Copy orb.idl and ir.idl to idlj module
 245 # The *.idl files are imported during the build
 246 # 
 247 # A better fix would be in make/common/internal/ImportComponents.gmk
 248 # to install imported files in a module 
 249 ORB_IDL=$(MODULEPATH_DIR)/$(IDLJ_MODULE)/lib/orb.idl
 250 IR_IDL=$(MODULEPATH_DIR)/$(IDLJ_MODULE)/lib/ir.idl
 251 $(MODULEPATH_DIR)/$(IDLJ_MODULE)/lib/%.idl : $(LIBDIR)/%.idl
 252         $(install-non-module-file)
 253 
 254 clean clobber::
 255         $(clean-build)
 256 
 257 .PHONY: modularize module-info-classes
 258 
 259 # GNU make bug: make pattern rules delete intermediate files
 260 # Workaround: marks the files as precious
 261 .PRECIOUS: $(MODULEPATH_DIR)/%/classes/module-info.class \
 262            $(MODULEPATH_DIR)/%/module-info.class \
 263            $(MODULEPATH_DIR)/%/.modules.update