Makefile 5.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
#
# Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.  Sun designates this
# particular file as subject to the "Classpath" exception as provided
# by Sun in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#

#
# Makefile for building the classanalyzer tool
#

BUILDDIR = ../..
include $(BUILDDIR)/common/Defs.gmk

33
PKGDIR = com/sun/classanalyzer
34 35 36 37 38
BUILDTOOL_SOURCE_ROOT = src
BUILDTOOL_MAIN        = $(PKGDIR)/ClassAnalyzer.java
BUILTTOOL_MAINCLASS   = $(subst /,.,$(BUILDTOOL_MAIN:%.java=%))

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 43
    && $(FIND) $(PKGDIR) -type f -print)

44 45
FILES_class = $(FILES_java:%.java=$(BUILDTOOLCLASSDIR)/%.class)

46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
CLASSANALYZER_JAR_FILE     = $(BUILDTOOLJARDIR)/classanalyzer.jar

#
# ClassAnalyzer depends on the com.sun.tools.classfile API.
# The tool is compiled with the latest version of the classfile 
# library in the langtools repo to make sure that synchronized
# change is made if the classfile API is changed. 
#
# If langtools repo exists, build its own copy of the
# classfile library and use it for compile time and runtime.
# If not exist (the top level repo is not a forest), use 
# the built jdk tools that imports tools.jar from the latest
# promoted build.
#
# If the classfile API is changed but not yet in a promoted build,
# the build might fail and the tool would need the langtools repo
# to build in that case.
#
ifndef LANGTOOLS_TOPDIR
  LANGTOOLS_TOPDIR=$(JDK_TOPDIR)/../langtools
endif

LANGTOOLS_TOPDIR_EXISTS := $(shell \
  if [ -d $(LANGTOOLS_TOPDIR) ] ; then \
    echo true; \
  else \
    echo false; \
  fi)

CLASSFILE_SRC = $(LANGTOOLS_TOPDIR)/src/share/classes
CLASSFILE_PKGDIR = com/sun/tools/classfile

ifeq ($(LANGTOOLS_TOPDIR_EXISTS), true)
  FILES_classfile_java := $(shell \
       $(CD) $(CLASSFILE_SRC) && \
           $(FIND) $(CLASSFILE_PKGDIR) -name '*.java' -print)
  FILES_classfile_class = $(FILES_classfile_java:%.java=$(BUILDTOOLCLASSDIR)/%.class)
  CLASSFILE_JAR_FILE = $(BUILDTOOLJARDIR)/classfile.jar
  BUILDTOOL_JAVAC    = $(BOOT_JAVAC_CMD) $(JAVAC_JVM_FLAGS) \
                          $(BOOT_JAVACFLAGS) -classpath $(CLASSFILE_JAR_FILE)
  BUILDTOOL_JAVA     = $(BOOT_JAVA_CMD) $(JAVA_TOOLS_FLAGS) \
                          -Xbootclasspath/p:$(CLASSFILE_JAR_FILE)
else
  # if langtools doesn't exist, use tools from the built jdk
  BUILDTOOL_JAVAC = $(BINDIR)/javac $(JAVAC_JVM_FLAGS) \
                       $(BOOT_JAVACFLAGS)
  BUILDTOOL_JAVA  = $(BINDIR)/java $(JAVA_TOOLS_FLAGS)
endif

# Location of the output modules.list, <module>.classlist
# and other output files generated by the class analyzer tool.
#
MODULE_CLASSLIST = $(MODULES_TEMPDIR)/classlist

all build: classanalyzer gen-classlist

classanalyzer: $(CLASSFILE_JAR_FILE) $(CLASSANALYZER_JAR_FILE) 

gen-classlist:
	@$(ECHO) ">>>Making "$@" @ `$(DATE)` ..."
	@$(RM) -rf $(MODULE_CLASSLIST)
	@$(MKDIR) -p $(MODULE_CLASSLIST)
	$(BUILDTOOL_JAVA) \
                -Dclassanalyzer.debug \
                -jar $(CLASSANALYZER_JAR_FILE) \
                -jdkhome $(OUTPUTDIR) \
                -config ../modules.config \
                -config ../modules.group \
                -depconfig ../jdk7.depconfig \
                -depconfig ../optional.depconfig \
                -showdynamic \
                -output $(MODULE_CLASSLIST)
	@$(ECHO) ">>>Finished making "$@" @ `$(DATE)` ..."
119 120 121 122 123

$(BUILDTOOL_MANIFEST_FILE): $(BUILDTOOL_MAIN_SOURCE_FILE)
	@$(prep-target)
	$(ECHO) "Main-Class: $(BUILTTOOL_MAINCLASS)" > $@

124 125 126 127 128 129
$(BUILDTOOLCLASSDIR)/$(CLASSFILE_PKGDIR)/%.class : $(CLASSFILE_SRC)/$(CLASSFILE_PKGDIR)/%.java
	@$(prep-target)
	@$(BUILDTOOL_JAVAC) \
            -sourcepath $(CLASSFILE_SRC) \
            -d $(BUILDTOOLCLASSDIR) $<

130 131
$(BUILDTOOLCLASSDIR)/%.class : $(BUILDTOOL_SOURCE_ROOT)/%.java
	@$(prep-target)
132
	$(BUILDTOOL_JAVAC) \
133 134 135
            -sourcepath $(BUILDTOOL_SOURCE_ROOT) \
            -d $(BUILDTOOLCLASSDIR) $<

136 137 138 139 140 141 142 143
$(CLASSANALYZER_JAR_FILE): $(BUILDTOOL_MANIFEST_FILE) $(FILES_class)
	@$(prep-target)
	$(CD) $(BUILDTOOLCLASSDIR) && \
	    $(BOOT_JAR_CMD) cfm $@ $(BUILDTOOL_MANIFEST_FILE) \
	       $(PKGDIR) $(BOOT_JAR_JFLAGS) || $(RM) $@
	@$(java-vm-cleanup)

$(BUILDTOOLJARDIR)/classfile.jar: $(FILES_classfile_class)
144
	@$(prep-target)
145 146 147 148
	$(CD) $(BUILDTOOLCLASSDIR) && \
	    $(BOOT_JAR_CMD) cf $@ \
	        $(CLASSFILE_PKGDIR) $(BOOT_JAR_JFLAGS) || $(RM) $@
	@$(java-vm-cleanup)
149 150 151

clean clobber::
	@$(RM) -rf $(BUILDTOOLCLASSDIR)/$(PKGDIR)
152
	@$(RM) -rf $(BUILDTOOLCLASSDIR)/$(CLASSFILE_PKGDIR)
153
	@$(RM) $(BUILDTOOL_MANIFEST_FILE)
154 155
	@$(RM) $(CLASSANALYZER_JAR_FILE)
	@$(RM) $(CLASSFILE_JAR_FILE)