jdk/make/modules/tools/Makefile
changeset 4681 7d382dfe6e55
parent 4524 697144bd8b04
child 4975 fff33270dd84
--- a/jdk/make/modules/tools/Makefile	Mon Jan 18 17:53:26 2010 +0100
+++ b/jdk/make/modules/tools/Makefile	Mon Jan 18 15:23:14 2010 -0800
@@ -28,58 +28,128 @@
 #
 
 BUILDDIR = ../..
-PACKAGE = com.sun.classanalyzer
-PRODUCT = tools
-PROGRAM = classanalyzer
 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)/$(PROGRAM)_manifest.mf
-BUILDTOOL_JAR_FILE         = $(BUILDTOOLJARDIR)/$(PROGRAM).jar
+BUILDTOOL_MANIFEST_FILE    = $(BUILDTOOLCLASSDIR)/classanalyzer_manifest.mf
 
 FILES_java := $(shell $(CD) $(BUILDTOOL_SOURCE_ROOT) \
-    && $(FIND) $(PKGDIR) $(SCM_DIRS_prune) -o -type f -print)
+    && $(FIND) $(PKGDIR) -type f -print)
+
 FILES_class = $(FILES_java:%.java=$(BUILDTOOLCLASSDIR)/%.class)
 
-all build: $(BUILDTOOL_JAR_FILE) tool_info
+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)
-	$(JAVAC_CMD) \
+	$(BUILDTOOL_JAVAC) \
             -sourcepath $(BUILDTOOL_SOURCE_ROOT) \
             -d $(BUILDTOOLCLASSDIR) $<
 
-$(BUILDTOOL_JAR_FILE): $(BUILDTOOL_MANIFEST_FILE) $(FILES_class)
+$(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)
+	$(CD) $(BUILDTOOLCLASSDIR) && \
+	    $(BOOT_JAR_CMD) cfm $@ $(BUILDTOOL_MANIFEST_FILE) \
+	       $(PKGDIR) $(BOOT_JAR_JFLAGS) || $(RM) $@
+	@$(java-vm-cleanup)
 
-# Printing out a build tool information line
-define printBuildToolSetting
-if [ "$2" != "" ] ; then $(PRINTF) "%-25s %s\n" "$1:" "$2"; fi
-endef
-
-# Print out the build tool information
-tool_info:
-	@$(ECHO) "========================================================="
-	@$(call printBuildToolSetting,BUILDTOOL,$(PROGRAM))
-	@$(call printBuildToolSetting,PACKAGE,$(PACKAGE))
-	@$(call printBuildToolSetting,BUILDTOOL_SOURCE_ROOT,$(BUILDTOOL_SOURCE_ROOT))
-	@$(call printBuildToolSetting,BUILTTOOL_MAINCLASS,$(BUILTTOOL_MAINCLASS))
-	@$(call printBuildToolSetting,BUILDTOOL_JAR_FILE,$(BUILDTOOL_JAR_FILE))
-	@$(ECHO) "========================================================="
+$(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) $(BUILDTOOL_JAR_FILE)
+	@$(RM) $(CLASSANALYZER_JAR_FILE)
+	@$(RM) $(CLASSFILE_JAR_FILE)