jdk/make/modules/tools/Makefile
changeset 8642 a6cccd458bef
parent 8641 fbf4a969ccba
parent 8608 8e043a4d3cf6
child 8643 def8e16dd237
equal deleted inserted replaced
8641:fbf4a969ccba 8642:a6cccd458bef
     1 #
       
     2 # Copyright (c) 2009, 2010, 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 #
       
    27 # Makefile for building the classanalyzer tool
       
    28 #
       
    29 
       
    30 BUILDDIR = ../..
       
    31 include $(BUILDDIR)/common/Defs.gmk
       
    32 
       
    33 PKGDIR = com/sun/classanalyzer
       
    34 BUILDTOOL_SOURCE_ROOT = src
       
    35 BUILDTOOL_MAIN        = $(PKGDIR)/ClassAnalyzer.java
       
    36 BUILTTOOL_MAINCLASS   = $(subst /,.,$(BUILDTOOL_MAIN:%.java=%))
       
    37 
       
    38 BUILDTOOL_MAIN_SOURCE_FILE = $(BUILDTOOL_SOURCE_ROOT)/$(BUILDTOOL_MAIN)
       
    39 BUILDTOOL_MANIFEST_FILE    = $(BUILDTOOLCLASSDIR)/classanalyzer_manifest.mf
       
    40 
       
    41 FILES_java := $(shell $(CD) $(BUILDTOOL_SOURCE_ROOT) \
       
    42     && $(FIND) $(PKGDIR) -type f -print)
       
    43 
       
    44 FILES_class = $(FILES_java:%.java=$(BUILDTOOLCLASSDIR)/%.class)
       
    45 
       
    46 CLASSANALYZER_JAR_FILE     = $(BUILDTOOLJARDIR)/classanalyzer.jar
       
    47 
       
    48 #
       
    49 # ClassAnalyzer depends on the com.sun.tools.classfile API.
       
    50 # The tool is compiled with the latest version of the classfile 
       
    51 # library in the langtools repo to make sure that synchronized
       
    52 # change is made if the classfile API is changed. 
       
    53 #
       
    54 # If langtools repo exists, build its own copy of the
       
    55 # classfile library and use it for compile time and runtime.
       
    56 # If not exist (the top level repo is not a forest), use 
       
    57 # the built jdk tools that imports tools.jar from the latest
       
    58 # promoted build.
       
    59 #
       
    60 # If the classfile API is changed but not yet in a promoted build,
       
    61 # the build might fail and the tool would need the langtools repo
       
    62 # to build in that case.
       
    63 #
       
    64 ifndef LANGTOOLS_TOPDIR
       
    65   LANGTOOLS_TOPDIR=$(JDK_TOPDIR)/../langtools
       
    66 endif
       
    67 
       
    68 LANGTOOLS_TOPDIR_EXISTS := $(shell \
       
    69   if [ -d $(LANGTOOLS_TOPDIR) ] ; then \
       
    70     echo true; \
       
    71   else \
       
    72     echo false; \
       
    73   fi)
       
    74 
       
    75 CLASSFILE_SRC = $(LANGTOOLS_TOPDIR)/src/share/classes
       
    76 CLASSFILE_PKGDIR = com/sun/tools/classfile
       
    77 
       
    78 ifeq ($(LANGTOOLS_TOPDIR_EXISTS), true)
       
    79   FILES_classfile_java := $(shell \
       
    80        $(CD) $(CLASSFILE_SRC) && \
       
    81            $(FIND) $(CLASSFILE_PKGDIR) -name '*.java' -print)
       
    82   FILES_classfile_class = $(FILES_classfile_java:%.java=$(BUILDTOOLCLASSDIR)/%.class)
       
    83   CLASSFILE_JAR_FILE = $(BUILDTOOLJARDIR)/classfile.jar
       
    84   BUILDTOOL_JAVAC    = $(BOOT_JAVAC_CMD) $(JAVAC_JVM_FLAGS) \
       
    85                           $(BOOT_JAVACFLAGS) -classpath $(CLASSFILE_JAR_FILE)
       
    86   BUILDTOOL_JAVA     = $(BOOT_JAVA_CMD) $(JAVA_TOOLS_FLAGS) \
       
    87                           -Xbootclasspath/p:$(CLASSFILE_JAR_FILE)
       
    88 else
       
    89   # if langtools doesn't exist, use tools from the built jdk
       
    90   BUILDTOOL_JAVAC = $(BINDIR)/javac $(JAVAC_JVM_FLAGS) \
       
    91                        $(BOOT_JAVACFLAGS)
       
    92   BUILDTOOL_JAVA  = $(BINDIR)/java $(JAVA_TOOLS_FLAGS)
       
    93 endif
       
    94 
       
    95 # Location of the output modules.list, <module>.classlist
       
    96 # and other output files generated by the class analyzer tool.
       
    97 #
       
    98 MODULE_CLASSLIST = $(MODULES_TEMPDIR)/classlist
       
    99 
       
   100 all build: classanalyzer gen-classlist
       
   101 
       
   102 classanalyzer: $(CLASSFILE_JAR_FILE) $(CLASSANALYZER_JAR_FILE) 
       
   103 
       
   104 gen-classlist:
       
   105 	@$(ECHO) ">>>Making "$@" @ `$(DATE)` ..."
       
   106 	@$(RM) -rf $(MODULE_CLASSLIST)
       
   107 	@$(MKDIR) -p $(MODULE_CLASSLIST)
       
   108 	$(BUILDTOOL_JAVA) \
       
   109                 -Dclassanalyzer.debug \
       
   110                 -jar $(CLASSANALYZER_JAR_FILE) \
       
   111                 -jdkhome $(OUTPUTDIR) \
       
   112                 -config ../modules.config \
       
   113                 -config ../modules.group \
       
   114                 -depconfig ../jdk7.depconfig \
       
   115                 -depconfig ../optional.depconfig \
       
   116                 -showdynamic \
       
   117                 -output $(MODULE_CLASSLIST)
       
   118 	@$(ECHO) ">>>Finished making "$@" @ `$(DATE)` ..."
       
   119 
       
   120 $(BUILDTOOL_MANIFEST_FILE): $(BUILDTOOL_MAIN_SOURCE_FILE)
       
   121 	@$(prep-target)
       
   122 	$(ECHO) "Main-Class: $(BUILTTOOL_MAINCLASS)" > $@
       
   123 
       
   124 $(BUILDTOOLCLASSDIR)/$(CLASSFILE_PKGDIR)/%.class : $(CLASSFILE_SRC)/$(CLASSFILE_PKGDIR)/%.java
       
   125 	@$(prep-target)
       
   126 	@$(BUILDTOOL_JAVAC) \
       
   127             -sourcepath $(CLASSFILE_SRC) \
       
   128             -d $(BUILDTOOLCLASSDIR) $<
       
   129 
       
   130 $(BUILDTOOLCLASSDIR)/%.class : $(BUILDTOOL_SOURCE_ROOT)/%.java
       
   131 	@$(prep-target)
       
   132 	$(BUILDTOOL_JAVAC) \
       
   133             -sourcepath $(BUILDTOOL_SOURCE_ROOT) \
       
   134             -d $(BUILDTOOLCLASSDIR) $<
       
   135 
       
   136 $(CLASSANALYZER_JAR_FILE): $(BUILDTOOL_MANIFEST_FILE) $(FILES_class)
       
   137 	@$(prep-target)
       
   138 	$(BOOT_JAR_CMD) cfm $@ $(BUILDTOOL_MANIFEST_FILE) \
       
   139 	    -C $(BUILDTOOLCLASSDIR) $(PKGDIR) $(BOOT_JAR_JFLAGS) || $(RM) $@
       
   140 	@$(java-vm-cleanup)
       
   141 
       
   142 $(BUILDTOOLJARDIR)/classfile.jar: $(FILES_classfile_class)
       
   143 	@$(prep-target)
       
   144 	$(CD) $(BUILDTOOLCLASSDIR) && \
       
   145 	    $(BOOT_JAR_CMD) cf $@ \
       
   146 	        $(CLASSFILE_PKGDIR) $(BOOT_JAR_JFLAGS) || $(RM) $@
       
   147 	@$(java-vm-cleanup)
       
   148 
       
   149 clean clobber::
       
   150 	@$(RM) -rf $(BUILDTOOLCLASSDIR)/$(PKGDIR)
       
   151 	@$(RM) -rf $(BUILDTOOLCLASSDIR)/$(CLASSFILE_PKGDIR)
       
   152 	@$(RM) $(BUILDTOOL_MANIFEST_FILE)
       
   153 	@$(RM) $(CLASSANALYZER_JAR_FILE)
       
   154 	@$(RM) $(CLASSFILE_JAR_FILE)