jdk/make/modules/tools/Makefile
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 4975 fff33270dd84
child 7668 d4a77089c587
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun

#
# Copyright (c) 2009, Oracle and/or its affiliates. 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.  Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#

#
# Makefile for building the classanalyzer tool
#

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

PKGDIR = com/sun/classanalyzer
BUILDTOOL_SOURCE_ROOT = src
BUILDTOOL_MAIN        = $(PKGDIR)/ClassAnalyzer.java
BUILTTOOL_MAINCLASS   = $(subst /,.,$(BUILDTOOL_MAIN:%.java=%))

BUILDTOOL_MAIN_SOURCE_FILE = $(BUILDTOOL_SOURCE_ROOT)/$(BUILDTOOL_MAIN)
BUILDTOOL_MANIFEST_FILE    = $(BUILDTOOLCLASSDIR)/classanalyzer_manifest.mf

FILES_java := $(shell $(CD) $(BUILDTOOL_SOURCE_ROOT) \
    && $(FIND) $(PKGDIR) -type f -print)

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

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)` ..."

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

$(BUILDTOOLCLASSDIR)/$(CLASSFILE_PKGDIR)/%.class : $(CLASSFILE_SRC)/$(CLASSFILE_PKGDIR)/%.java
	@$(prep-target)
	@$(BUILDTOOL_JAVAC) \
            -sourcepath $(CLASSFILE_SRC) \
            -d $(BUILDTOOLCLASSDIR) $<

$(BUILDTOOLCLASSDIR)/%.class : $(BUILDTOOL_SOURCE_ROOT)/%.java
	@$(prep-target)
	$(BUILDTOOL_JAVAC) \
            -sourcepath $(BUILDTOOL_SOURCE_ROOT) \
            -d $(BUILDTOOLCLASSDIR) $<

$(CLASSANALYZER_JAR_FILE): $(BUILDTOOL_MANIFEST_FILE) $(FILES_class)
	@$(prep-target)
	$(BOOT_JAR_CMD) cfm $@ $(BUILDTOOL_MANIFEST_FILE) \
	    -C $(BUILDTOOLCLASSDIR) $(PKGDIR) $(BOOT_JAR_JFLAGS) || $(RM) $@
	@$(java-vm-cleanup)

$(BUILDTOOLJARDIR)/classfile.jar: $(FILES_classfile_class)
	@$(prep-target)
	$(CD) $(BUILDTOOLCLASSDIR) && \
	    $(BOOT_JAR_CMD) cf $@ \
	        $(CLASSFILE_PKGDIR) $(BOOT_JAR_JFLAGS) || $(RM) $@
	@$(java-vm-cleanup)

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