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