make/BuildLangtools.gmk

changeset 2197
8043b9cf31ab
parent 2094
343aeb2033f0
child 2198
f42a22e2b2cd
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/make/BuildLangtools.gmk	Mon Nov 04 11:08:41 2013 +0100
     1.3 @@ -0,0 +1,201 @@
     1.4 +#
     1.5 +# Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 +#
     1.8 +# This code is free software; you can redistribute it and/or modify it
     1.9 +# under the terms of the GNU General Public License version 2 only, as
    1.10 +# published by the Free Software Foundation.  Oracle designates this
    1.11 +# particular file as subject to the "Classpath" exception as provided
    1.12 +# by Oracle in the LICENSE file that accompanied this code.
    1.13 +#
    1.14 +# This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 +# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 +# version 2 for more details (a copy is included in the LICENSE file that
    1.18 +# accompanied this code).
    1.19 +#
    1.20 +# You should have received a copy of the GNU General Public License version
    1.21 +# 2 along with this work; if not, write to the Free Software Foundation,
    1.22 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 +#
    1.24 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 +# or visit www.oracle.com if you need additional information or have any
    1.26 +# questions.
    1.27 +#
    1.28 +
    1.29 +# This must be the first rule
    1.30 +default: all
    1.31 +
    1.32 +include $(SPEC)
    1.33 +include MakeBase.gmk
    1.34 +include JavaCompilation.gmk
    1.35 +
    1.36 +# The BOOT_JAVAC setup uses the bootdir compiler to compile the tools
    1.37 +# and the bootstrap javac, to be run by the bootdir jvm.
    1.38 +$(eval $(call SetupJavaCompiler,BOOT_JAVAC, \
    1.39 +    JAVAC := $(JAVAC), \
    1.40 +    SERVER_DIR := $(SJAVAC_SERVER_DIR), \
    1.41 +    SERVER_JVM := $(SJAVAC_SERVER_JAVA), \
    1.42 +    FLAGS := -XDignore.symbol.file=true -g -Xlint:all$(COMMA)-deprecation -Werror))
    1.43 +
    1.44 +# javax.tools.JavaCompilerTool isn't really a suffix but this gets the file copied.
    1.45 +RESOURCE_SUFFIXES := .gif .xml .css .js javax.tools.JavaCompilerTool
    1.46 +
    1.47 +# Now setup the compilation of the properties compilation tool. You can depend
    1.48 +# upon $(BUILD_TOOLS) to trigger a compilation of the tools. Note that we
    1.49 +# add src/share/classes to the sourcepath. This is necessary since the GenStubs
    1.50 +# program needs to be linked and run towards the new javac sources.
    1.51 +$(eval $(call SetupJavaCompilation,BUILD_TOOLS, \
    1.52 +    SETUP := BOOT_JAVAC, \
    1.53 +    DISABLE_SJAVAC := true, \
    1.54 +    ADD_JAVAC_FLAGS := -Xprefer:source, \
    1.55 +    SRC := $(LANGTOOLS_TOPDIR)/make/tools $(LANGTOOLS_TOPDIR)/src/share/classes, \
    1.56 +    INCLUDES := compileproperties genstubs, \
    1.57 +    BIN := $(LANGTOOLS_OUTPUTDIR)/btclasses))
    1.58 +
    1.59 +# The compileprops tools compiles a properties file into a resource bundle.
    1.60 +TOOL_COMPILEPROPS_CMD := $(JAVA) -cp $(LANGTOOLS_OUTPUTDIR)/btclasses compileproperties.CompileProperties -quiet
    1.61 +
    1.62 +# Lookup the properties that need to be compiled into resource bundles.
    1.63 +PROPSOURCES := $(shell $(FIND) $(LANGTOOLS_TOPDIR)/src/share/classes -name "*.properties")
    1.64 +
    1.65 +# Strip away prefix and suffix, leaving for example only: "com/sun/tools/javac/resources/javac_zh_CN"
    1.66 +PROPPATHS := $(patsubst $(LANGTOOLS_TOPDIR)/src/share/classes/%.properties, %, $(PROPSOURCES))
    1.67 +
    1.68 +# Generate the list of java files to be created.
    1.69 +PROPJAVAS := $(patsubst %, $(LANGTOOLS_OUTPUTDIR)/gensrc/%.java, $(PROPPATHS))
    1.70 +
    1.71 +# Generate the package dirs for the tobe generated java files.
    1.72 +PROPDIRS := $(dir $(PROPJAVAS))
    1.73 +
    1.74 +# Now generate a sequence of "-compile ...javac_zh_CN.properties ...javac_zh_CN.java java.util.ListResourceBundle"
    1.75 +# suitable to be fed into the CompileProperties command.
    1.76 +PROPCMDLINE := $(subst _SPACE_, $(SPACE), $(join $(addprefix -compile_SPACE_, $(PROPSOURCES)), \
    1.77 +    $(addsuffix _SPACE_java.util.ListResourceBundle, $(addprefix _SPACE_$(LANGTOOLS_OUTPUTDIR)/gensrc/, $(addsuffix .java, $(PROPPATHS))))))
    1.78 +
    1.79 +# Now setup the rule for the generation of the resource bundles.
    1.80 +$(LANGTOOLS_OUTPUTDIR)/gensrc/_the_props.d: $(PROPSOURCES) $(BUILD_TOOLS)
    1.81 +	$(RM) -r $(@D)/*
    1.82 +	$(MKDIR) -p $(@D) $(PROPDIRS)
    1.83 +	$(PRINTF) "jdk=$(JDK_VERSION)\nfull=$(FULL_VERSION)\nrelease=$(RELEASE)\n" > $(LANGTOOLS_OUTPUTDIR)/gensrc/com/sun/tools/javah/resources/version.properties
    1.84 +	$(PRINTF) "jdk=$(JDK_VERSION)\nfull=$(FULL_VERSION)\nrelease=$(RELEASE)\n" > $(LANGTOOLS_OUTPUTDIR)/gensrc/com/sun/tools/javap/resources/version.properties
    1.85 +	$(PRINTF) "jdk=$(JDK_VERSION)\nfull=$(FULL_VERSION)\nrelease=$(RELEASE)\n" > $(LANGTOOLS_OUTPUTDIR)/gensrc/com/sun/tools/javac/resources/version.properties
    1.86 +	$(PRINTF) "jdk=$(JDK_VERSION)\nfull=$(FULL_VERSION)\nrelease=$(RELEASE)\n" > $(LANGTOOLS_OUTPUTDIR)/gensrc/com/sun/tools/jdeps/resources/version.properties
    1.87 +	$(ECHO) Compiling $(words $(PROPSOURCES) v1 v2 v3) properties into resource bundles
    1.88 +	$(TOOL_COMPILEPROPS_CMD) $(PROPCMDLINE) \
    1.89 +	    -compile $(LANGTOOLS_OUTPUTDIR)/gensrc/com/sun/tools/javah/resources/version.properties \
    1.90 +	        $(LANGTOOLS_OUTPUTDIR)/gensrc/com/sun/tools/javah/resources/version.java \
    1.91 +	        java.util.ListResourceBundle \
    1.92 +	    -compile $(LANGTOOLS_OUTPUTDIR)/gensrc/com/sun/tools/javap/resources/version.properties \
    1.93 +	        $(LANGTOOLS_OUTPUTDIR)/gensrc/com/sun/tools/javap/resources/version.java \
    1.94 +	        java.util.ListResourceBundle \
    1.95 +	    -compile $(LANGTOOLS_OUTPUTDIR)/gensrc/com/sun/tools/javac/resources/version.properties \
    1.96 +	        $(LANGTOOLS_OUTPUTDIR)/gensrc/com/sun/tools/javac/resources/version.java \
    1.97 +	        java.util.ListResourceBundle \
    1.98 +	    -compile $(LANGTOOLS_OUTPUTDIR)/gensrc/com/sun/tools/jdeps/resources/version.properties \
    1.99 +	        $(LANGTOOLS_OUTPUTDIR)/gensrc/com/sun/tools/jdeps/resources/version.java \
   1.100 +	        java.util.ListResourceBundle
   1.101 +	$(ECHO) PROPS_ARE_CREATED = yes > $@
   1.102 +
   1.103 +# Trigger the generation of the resource bundles. After the resource bundles have
   1.104 +# been compiled, then the makefile will restart and the newly created java files
   1.105 +# will become part of the build further along in the makefile.
   1.106 +-include $(LANGTOOLS_OUTPUTDIR)/gensrc/_the_props.d
   1.107 +
   1.108 +ifeq ($(PROPS_ARE_CREATED), yes)
   1.109 +  # Setup the rules to build a dist/bootstrap/lib/javac.jar, ie a smaller intermediate javac
   1.110 +  # that can be compiled with an old javac. The intermediate javac is then used
   1.111 +  # to compile javac again and to build the complete new jdk.
   1.112 +  $(eval $(call SetupJavaCompilation,BUILD_BOOTSTRAP_LANGTOOLS, \
   1.113 +      SETUP := BOOT_JAVAC, \
   1.114 +      DISABLE_SJAVAC := true, \
   1.115 +      SRC := $(LANGTOOLS_TOPDIR)/src/share/classes $(LANGTOOLS_OUTPUTDIR)/gensrc, \
   1.116 +      EXCLUDES := com/sun/tools/javac/nio, \
   1.117 +      COPY := $(RESOURCE_SUFFIXES), \
   1.118 +      BIN := $(LANGTOOLS_OUTPUTDIR)/btclasses/bootstrap))
   1.119 +
   1.120 +  $(eval $(call SetupArchive,ARCHIVE_BOOTSTRAP_JAVAC, $(BUILD_BOOTSTRAP_LANGTOOLS), \
   1.121 +      SRCS := $(LANGTOOLS_OUTPUTDIR)/btclasses/bootstrap, \
   1.122 +      JAR := $(LANGTOOLS_OUTPUTDIR)/dist/bootstrap/lib/javac.jar, \
   1.123 +      SUFFIXES := .class $(RESOURCE_SUFFIXES)))
   1.124 +
   1.125 +  # GenStubs is used to bootstrap any dependencies from javac to the new JDK that is not
   1.126 +  # yet built. It is currently not needed but might be again in the future. The following
   1.127 +  # exercises the functionality to verify that it works.
   1.128 +  TOOL_GENSTUBS_CMD = $(JAVA) \
   1.129 +       "-Xbootclasspath/p:$(LANGTOOLS_OUTPUTDIR)/dist/bootstrap/lib/javac.jar" \
   1.130 +       -classpath $(LANGTOOLS_OUTPUTDIR)/btclasses \
   1.131 +       genstubs.GenStubs
   1.132 +
   1.133 +  # We fetch source from the JDK...
   1.134 +  JDKS = $(JDK_TOPDIR)/src/share/classes
   1.135 +
   1.136 +  # Build the list of classes to generate stubs from. java/util/function/Predicate.java isn't
   1.137 +  # currently needed, but is used as a demo for now.
   1.138 +
   1.139 +  STUBSOURCES := $(shell $(FIND) $(JDKS) -name "*.java" | $(GREP) \
   1.140 +      -e "$(JDKS)/java/util/function/Predicate.java")
   1.141 +
   1.142 +  # Rewrite the file names into class names because the GenStubs tool require this.
   1.143 +  STUBCLASSES := $(subst /,., $(patsubst $(JDKS)/%.java, %, $(STUBSOURCES)))
   1.144 +
   1.145 +  # Now setup the build recipe for genstubs.
   1.146 +  $(LANGTOOLS_OUTPUTDIR)/genstubs/_the_stubs.d: $(STUBSOURCES) $(BUILD_TOOLS) \
   1.147 +      $(LANGTOOLS_OUTPUTDIR)/dist/bootstrap/lib/javac.jar \
   1.148 +      $(LANGTOOLS_OUTPUTDIR)/gensrc/_the_props.d
   1.149 +	$(MKDIR) -p $(@D)
   1.150 +	$(MKDIR) -p $(LANGTOOLS_OUTPUTDIR)/tmpstubs
   1.151 +	$(ECHO) $(LOG_INFO) Generating stubs from JDK sources.
   1.152 +	($(TOOL_GENSTUBS_CMD) -s $(LANGTOOLS_OUTPUTDIR)/tmpstubs -sourcepath $(JDKS) $(STUBCLASSES) && $(ECHO) STUBS_ARE_CREATED = yes > $@)
   1.153 +	if $(DIFF) -x "_the*" -rq $(LANGTOOLS_OUTPUTDIR)/tmpstubs $(LANGTOOLS_OUTPUTDIR)/genstubs > /dev/null 2>&1; then \
   1.154 +	  $(ECHO) $(LOG_INFO) No changes in the stubs!; \
   1.155 +	  $(RM) -r $(LANGTOOLS_OUTPUTDIR)/tmpstubs; \
   1.156 +	else \
   1.157 +	  $(ECHO) $(LOG_INFO) Changes in stubs detected!; \
   1.158 +	  $(RM) -r $(@D); \
   1.159 +	  $(MV) $(LANGTOOLS_OUTPUTDIR)/tmpstubs $(@D); \
   1.160 +	fi
   1.161 +	$(ECHO) STUBS_ARE_CREATED = yes > $@
   1.162 +
   1.163 +  # Trigger a generation of the genstubs java source code and a restart
   1.164 +  # of the makefile to make sure that the following build setup use the
   1.165 +  # newly created java files.
   1.166 +  -include $(LANGTOOLS_OUTPUTDIR)/genstubs/_the_stubs.d
   1.167 +
   1.168 +  ifeq ($(STUBS_ARE_CREATED), yes)
   1.169 +    # Setup a compiler configuration using the intermediate javac in dist/bootstrap/lib/javac.jar
   1.170 +    # that generates code for the new jdk that is being built.
   1.171 +    # The code compiled by this compiler setup, cannot necessarily be run with the bootstrap jvm.
   1.172 +    $(eval $(call SetupJavaCompiler,GENERATE_NEWBYTECODE, \
   1.173 +        JVM := $(JAVA), \
   1.174 +        JAVAC := "-Xbootclasspath/p:$(LANGTOOLS_OUTPUTDIR)/dist/bootstrap/lib/javac.jar" \
   1.175 +            -cp $(LANGTOOLS_OUTPUTDIR)/dist/bootstrap/lib/javac.jar \
   1.176 +            com.sun.tools.javac.Main, \
   1.177 +        FLAGS := -XDignore.symbol.file=true -Xlint:all$(COMMA)-deprecation -Werror, \
   1.178 +        SERVER_DIR := $(SJAVAC_SERVER_DIR), \
   1.179 +        SERVER_JVM := $(SJAVAC_SERVER_JAVA)))
   1.180 +
   1.181 +    $(eval $(call SetupJavaCompilation,BUILD_FULL_JAVAC, \
   1.182 +        SETUP := GENERATE_NEWBYTECODE, \
   1.183 +        SRC := $(LANGTOOLS_TOPDIR)/src/share/classes $(LANGTOOLS_OUTPUTDIR)/gensrc \
   1.184 +            $(LANGTOOLS_OUTPUTDIR)/genstubs, \
   1.185 +        EXCLUDES := java/util java/io java/nio, \
   1.186 +        COPY := $(RESOURCE_SUFFIXES), \
   1.187 +        BIN := $(LANGTOOLS_OUTPUTDIR)/classes))
   1.188 +
   1.189 +    $(eval $(call SetupArchive,ARCHIVE_FULL_JAVAC, $(BUILD_FULL_JAVAC), \
   1.190 +        SETUP := GENERATE_NEWBYTECODE, \
   1.191 +        SRCS := $(LANGTOOLS_OUTPUTDIR)/classes, \
   1.192 +        SUFFIXES := .class $(RESOURCE_SUFFIXES), \
   1.193 +        JAR := $(LANGTOOLS_OUTPUTDIR)/dist/lib/classes.jar))
   1.194 +
   1.195 +    $(eval $(call SetupZipArchive,ZIP_FULL_JAVAC_SOURCE, \
   1.196 +        SRC := $(LANGTOOLS_TOPDIR)/src/share/classes $(LANGTOOLS_OUTPUTDIR)/gensrc, \
   1.197 +        ZIP := $(LANGTOOLS_OUTPUTDIR)/dist/lib/src.zip))
   1.198 +
   1.199 +    all: $(LANGTOOLS_OUTPUTDIR)/dist/lib/classes.jar \
   1.200 +        $(LANGTOOLS_OUTPUTDIR)/dist/lib/src.zip \
   1.201 +        $(LANGTOOLS_OUTPUTDIR)/dist/bootstrap/lib/javac.jar
   1.202 +
   1.203 +  endif
   1.204 +endif

mercurial