1 #
   2 # Copyright (c) 2011, 2012, 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 # This must be the first rule
  27 default: all
  28 
  29 include $(SPEC)
  30 include MakeBase.gmk
  31 include JavaCompilation.gmk
  32 
  33 # The BOOT_JAVAC setup uses the bootdir compiler to compile the tools
  34 # and the bootstrap javac, to be run by the bootdir jvm.
  35 $(eval $(call SetupJavaCompiler,BOOT_JAVAC,\
  36         JAVAC:=$(JAVAC),\
  37         SERVER_DIR:=$(SJAVAC_SERVER_DIR),\
  38         SERVER_JVM:=$(SJAVAC_SERVER_JAVA),\
  39         FLAGS:=-XDignore.symbol.file=true -g -Xlint:all$(COMMA)-deprecation -Werror))
  40 
  41 # javax.tools.JavaCompilerTool isn't really a suffix but this gets the file copied.
  42 RESOURCE_SUFFIXES:=.gif .xml .css .js javax.tools.JavaCompilerTool
  43 
  44 # Now setup the compilation of the properties compilation tool. You can depend
  45 # upon $(BUILD_TOOLS) to trigger a compilation of the tools. Note that we
  46 # add src/share/classes to the sourcepath. This is necessary since the GenStubs
  47 # program needs to be linked and run towards the new javac sources.
  48 $(eval $(call SetupJavaCompilation,BUILD_TOOLS,\
  49                 SETUP:=BOOT_JAVAC,\
  50                 DISABLE_SJAVAC:=true,\
  51                 ADD_JAVAC_FLAGS:=-Xprefer:source,\
  52                 SRC:=$(LANGTOOLS_TOPDIR)/make/tools $(LANGTOOLS_TOPDIR)/src/share/classes,\
  53                 INCLUDES:=compileproperties genstubs,\
  54                 BIN:=$(LANGTOOLS_OUTPUTDIR)/btclasses))
  55 
  56 # The compileprops tools compiles a properties file into a resource bundle.
  57 TOOL_COMPILEPROPS_CMD:=$(JAVA) -cp $(LANGTOOLS_OUTPUTDIR)/btclasses compileproperties.CompileProperties -quiet
  58 # Lookup the properties that need to be compiled into resource bundles.
  59 PROPSOURCES:=$(shell find $(LANGTOOLS_TOPDIR)/src/share/classes -name "*.properties")
  60 # Strip away prefix and suffix, leaving for example only: "com/sun/tools/javac/resources/javac_zh_CN"
  61 PROPPATHS:=$(patsubst $(LANGTOOLS_TOPDIR)/src/share/classes/%.properties,%,$(PROPSOURCES))
  62 # Generate the list of java files to be created.
  63 PROPJAVAS:=$(patsubst %,$(LANGTOOLS_OUTPUTDIR)/gensrc/%.java,$(PROPPATHS))
  64 # Generate the package dirs for the tobe generated java files.
  65 PROPDIRS:=$(dir $(PROPJAVAS))
  66 # Now generate a sequence of "-compile ...javac_zh_CN.properties ...javac_zh_CN.java java.util.ListResourceBundle"
  67 # suitable to be fed into the CompileProperties command.
  68 PROPCMDLINE:=$(subst _SPACE_,$(SPACE),$(join $(addprefix -compile_SPACE_,$(PROPSOURCES)), \
  69                 $(addsuffix _SPACE_java.util.ListResourceBundle,$(addprefix _SPACE_$(LANGTOOLS_OUTPUTDIR)/gensrc/,$(addsuffix .java,$(PROPPATHS))))))
  70 
  71 # Now setup the rule for the generation of the resource bundles.
  72 $(LANGTOOLS_OUTPUTDIR)/gensrc/_the_props.d : $(PROPSOURCES) $(BUILD_TOOLS)
  73         rm -rf $(@D)/*
  74         mkdir -p $(@D) $(PROPDIRS)
  75         printf "jdk=$(JDK_VERSION)\nfull=$(FULL_VERSION)\nrelease=$(RELEASE)\n" > $(LANGTOOLS_OUTPUTDIR)/gensrc/com/sun/tools/javah/resources/version.properties
  76         printf "jdk=$(JDK_VERSION)\nfull=$(FULL_VERSION)\nrelease=$(RELEASE)\n" > $(LANGTOOLS_OUTPUTDIR)/gensrc/com/sun/tools/javap/resources/version.properties
  77         printf "jdk=$(JDK_VERSION)\nfull=$(FULL_VERSION)\nrelease=$(RELEASE)\n" > $(LANGTOOLS_OUTPUTDIR)/gensrc/com/sun/tools/javac/resources/version.properties
  78         printf "jdk=$(JDK_VERSION)\nfull=$(FULL_VERSION)\nrelease=$(RELEASE)\n" > $(LANGTOOLS_OUTPUTDIR)/gensrc/com/sun/tools/jdeps/resources/version.properties
  79         echo Compiling $(words $(PROPSOURCES) v1 v2 v3) properties into resource bundles
  80         $(TOOL_COMPILEPROPS_CMD) $(PROPCMDLINE) \
  81                 -compile        $(LANGTOOLS_OUTPUTDIR)/gensrc/com/sun/tools/javah/resources/version.properties \
  82                                 $(LANGTOOLS_OUTPUTDIR)/gensrc/com/sun/tools/javah/resources/version.java \
  83                                 java.util.ListResourceBundle \
  84                 -compile        $(LANGTOOLS_OUTPUTDIR)/gensrc/com/sun/tools/javap/resources/version.properties \
  85                                 $(LANGTOOLS_OUTPUTDIR)/gensrc/com/sun/tools/javap/resources/version.java \
  86                                 java.util.ListResourceBundle \
  87                 -compile        $(LANGTOOLS_OUTPUTDIR)/gensrc/com/sun/tools/javac/resources/version.properties \
  88                                 $(LANGTOOLS_OUTPUTDIR)/gensrc/com/sun/tools/javac/resources/version.java \
  89                                 java.util.ListResourceBundle \
  90                 -compile        $(LANGTOOLS_OUTPUTDIR)/gensrc/com/sun/tools/jdeps/resources/version.properties \
  91                                 $(LANGTOOLS_OUTPUTDIR)/gensrc/com/sun/tools/jdeps/resources/version.java \
  92                                 java.util.ListResourceBundle
  93         echo PROPS_ARE_CREATED=yes > $@
  94 
  95 # Trigger the generation of the resource bundles. After the resource bundles have
  96 # been compiled, then the makefile will restart and the newly created java files
  97 # will become part of the build further along in the makefile.
  98 -include $(LANGTOOLS_OUTPUTDIR)/gensrc/_the_props.d
  99 
 100 ifeq ($(PROPS_ARE_CREATED),yes)
 101         # Setup the rules to build a dist/bootstrap/lib/javac.jar, ie a smaller intermediate javac
 102         # that can be compiled with an old javac. The intermediate javac is then used
 103         # to compile javac again and to build the complete new jdk.
 104         $(eval $(call SetupJavaCompilation,BUILD_BOOTSTRAP_LANGTOOLS,\
 105                 SETUP:=BOOT_JAVAC,\
 106                 DISABLE_SJAVAC:=true,\
 107                 SRC:=$(LANGTOOLS_TOPDIR)/src/share/classes $(LANGTOOLS_OUTPUTDIR)/gensrc,\
 108                 EXCLUDES:=com/sun/tools/javac/nio,\
 109                 COPY:=$(RESOURCE_SUFFIXES),\
 110                 BIN:=$(LANGTOOLS_OUTPUTDIR)/btclasses/bootstrap))
 111 
 112         $(eval $(call SetupArchive,ARCHIVE_BOOTSTRAP_JAVAC,$(BUILD_BOOTSTRAP_LANGTOOLS),\
 113                 SRCS:=$(LANGTOOLS_OUTPUTDIR)/btclasses/bootstrap,\
 114                 JAR:=$(LANGTOOLS_OUTPUTDIR)/dist/bootstrap/lib/javac.jar,\
 115                 JARMAIN:=com.sun.tools.javac.Main))
 116 
 117         $(eval $(call SetupArchive,ARCHIVE_BOOTSTRAP_JAVAH,$(BUILD_BOOTSTRAP_LANGTOOLS),\
 118                 SRCS:=$(LANGTOOLS_OUTPUTDIR)/btclasses/bootstrap,\
 119                 JAR:=$(LANGTOOLS_OUTPUTDIR)/dist/bootstrap/lib/javah.jar,\
 120                 JARMAIN:=com.sun.tools.javah.Main))
 121 
 122         $(eval $(call SetupArchive,ARCHIVE_BOOTSTRAP_JAVAP,$(BUILD_BOOTSTRAP_LANGTOOLS),\
 123                 SRCS:=$(LANGTOOLS_OUTPUTDIR)/btclasses/bootstrap,\
 124                 JAR:=$(LANGTOOLS_OUTPUTDIR)/dist/bootstrap/lib/javap.jar,\
 125                 JARMAIN:=com.sun.tools.javap.Main))
 126 
 127         $(eval $(call SetupArchive,ARCHIVE_BOOTSTRAP_JAVADOC,$(BUILD_BOOTSTRAP_LANGTOOLS),\
 128                 SRCS:=$(LANGTOOLS_OUTPUTDIR)/btclasses/bootstrap,\
 129                 JAR:=$(LANGTOOLS_OUTPUTDIR)/dist/bootstrap/lib/javadoc.jar,\
 130                 SUFFIXES:=.class $(RESOURCE_SUFFIXES),\
 131                 JARMAIN:=com.sun.tools.javadoc.Main))
 132 
 133         # GenStubs is used to bootstrap any dependencies from javac to the new JDK that is not 
 134         # yet built. It is currently not needed but might be again in the future. The following
 135         # exercises the functionality to verify that it works.
 136         TOOL_GENSTUBS_CMD=$(JAVA) \
 137              "-Xbootclasspath/p:$(LANGTOOLS_OUTPUTDIR)/dist/bootstrap/lib/javac.jar" \
 138              -classpath $(LANGTOOLS_OUTPUTDIR)/btclasses \
 139              genstubs.GenStubs
 140         # We fetch source from the JDK...
 141         JDKS=$(JDK_TOPDIR)/src/share/classes
 142         # Build the list of classes to generate stubs from. java/util/Objects.java isn't
 143         # currently needed, but is used as a demo for now.
 144          STUBSOURCES:=$(shell $(FIND) $(JDKS) -name "*.java" | $(GREP) \
 145                     -e "$(JDKS)/java/util/Objects.java")
 146         # Rewrite the file names into class names because the GenStubs tool require this.
 147         STUBCLASSES:=$(subst /,.,$(patsubst $(JDKS)/%.java,%,$(STUBSOURCES)))
 148 
 149         # Now setup the build recipe for genstubs.
 150         $(LANGTOOLS_OUTPUTDIR)/genstubs/_the_stubs.d : $(STUBSOURCES) $(BUILD_TOOLS) \
 151                                 $(LANGTOOLS_OUTPUTDIR)/dist/bootstrap/lib/javac.jar \
 152                                 $(LANGTOOLS_OUTPUTDIR)/gensrc/_the_props.d
 153                 mkdir -p $(@D)
 154                 mkdir -p $(LANGTOOLS_OUTPUTDIR)/tmpstubs
 155                 echo $(LOG_INFO) Generating stubs from JDK sources.
 156                 ($(TOOL_GENSTUBS_CMD) -s $(LANGTOOLS_OUTPUTDIR)/tmpstubs -sourcepath $(JDKS) $(STUBCLASSES) && echo STUBS_ARE_CREATED=yes > $@)
 157                 if $(DIFF) -x "_the*" -rq $(LANGTOOLS_OUTPUTDIR)/tmpstubs $(LANGTOOLS_OUTPUTDIR)/genstubs > /dev/null 2>&1; then \
 158                         echo $(LOG_INFO) No changes in the stubs!; \
 159                         rm -rf $(LANGTOOLS_OUTPUTDIR)/tmpstubs; \
 160                 else \
 161                         echo $(LOG_INFO) Changes in stubs detected!; \
 162                         rm -rf $(@D); \
 163                         mv $(LANGTOOLS_OUTPUTDIR)/tmpstubs $(@D); \
 164                 fi
 165                 echo STUBS_ARE_CREATED=yes > $@
 166 
 167         # Trigger a generation of the genstubs java source code and a restart
 168         # of the makefile to make sure that the following build setup use the 
 169         # newly created java files.
 170         -include $(LANGTOOLS_OUTPUTDIR)/genstubs/_the_stubs.d
 171 
 172         ifeq ($(STUBS_ARE_CREATED),yes)
 173                 # Setup a compiler configuration using the intermediate javac in dist/bootstrap/lib/javac.jar
 174                 # that generates code for the new jdk that is being built.
 175                 # The code compiled by this compiler setup, cannot necessarily be run with the bootstrap jvm.
 176                 $(eval $(call SetupJavaCompiler,GENERATE_NEWBYTECODE,\
 177                   JVM:=$(JAVA),\
 178                   JAVAC:="-Xbootclasspath/p:$(LANGTOOLS_OUTPUTDIR)/dist/bootstrap/lib/javac.jar" \
 179                          -jar $(LANGTOOLS_OUTPUTDIR)/dist/bootstrap/lib/javac.jar,\
 180                   FLAGS:=-XDignore.symbol.file=true -Xlint:all$(COMMA)-deprecation -Werror,\
 181                   SERVER_DIR:=$(SJAVAC_SERVER_DIR),\
 182                   SERVER_JVM:=$(SJAVAC_SERVER_JAVA)))
 183 
 184                 $(eval $(call SetupJavaCompilation,BUILD_FULL_JAVAC,\
 185                         SETUP:=GENERATE_NEWBYTECODE,\
 186                         SRC:=$(LANGTOOLS_TOPDIR)/src/share/classes $(LANGTOOLS_OUTPUTDIR)/gensrc \
 187                              $(LANGTOOLS_OUTPUTDIR)/genstubs,\
 188                         EXCLUDES:=java/util java/io java/nio,\
 189                         COPY:=$(RESOURCE_SUFFIXES),\
 190                         BIN:=$(LANGTOOLS_OUTPUTDIR)/classes))
 191 
 192                 $(eval $(call SetupArchive,ARCHIVE_FULL_JAVAC,$(BUILD_FULL_JAVAC),\
 193                         SETUP:=GENERATE_NEWBYTECODE,\
 194                         SRCS:=$(LANGTOOLS_OUTPUTDIR)/classes,\
 195                         SUFFIXES:=.class $(RESOURCE_SUFFIXES),\
 196                         JAR:=$(LANGTOOLS_OUTPUTDIR)/dist/lib/classes.jar))
 197 
 198                 $(eval $(call SetupZipArchive,ZIP_FULL_JAVAC_SOURCE,\
 199                         SRC:=$(LANGTOOLS_TOPDIR)/src/share/classes $(LANGTOOLS_OUTPUTDIR)/gensrc,\
 200                         ZIP:=$(LANGTOOLS_OUTPUTDIR)/dist/lib/src.zip))
 201 
 202                 all:            $(LANGTOOLS_OUTPUTDIR)/dist/lib/classes.jar \
 203                                 $(LANGTOOLS_OUTPUTDIR)/dist/lib/src.zip \
 204                                 $(LANGTOOLS_OUTPUTDIR)/dist/bootstrap/lib/javac.jar \
 205                                 $(LANGTOOLS_OUTPUTDIR)/dist/bootstrap/lib/javah.jar \
 206                                 $(LANGTOOLS_OUTPUTDIR)/dist/bootstrap/lib/javap.jar \
 207                                 $(LANGTOOLS_OUTPUTDIR)/dist/bootstrap/lib/javadoc.jar
 208 
 209 
 210         endif
 211 endif