From ec599fb69b8ebd8ebf63718a52ecf508d58dda32 Mon Sep 17 00:00:00 2001 From: jochen Date: Thu, 15 Jul 1999 13:04:56 +0000 Subject: [PATCH] New perl script to build dependencies out of java class files. git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@1078 379699f6-c40d-0410-875b-85095c16579e --- jode/Makefile.am | 2 - jode/configure.in | 4 +- jode/javaDependencies.pl.in | 140 +++++++++++++++++++++++++++++++ jode/javacWithDeps.sh.in | 15 ---- jode/jode/Makefile.am | 11 ++- jode/jode/bytecode/Makefile.am | 11 ++- jode/jode/decompiler/Makefile.am | 11 ++- jode/jode/expr/Makefile.am | 11 ++- jode/jode/flow/Makefile.am | 11 ++- jode/jode/jvm/Makefile.am | 11 ++- jode/jode/obfuscator/Makefile.am | 11 ++- jode/jode/swingui/Makefile.am | 11 ++- jode/jode/type/Makefile.am | 11 ++- jode/jode/util/Makefile.am | 11 ++- 14 files changed, 221 insertions(+), 50 deletions(-) create mode 100755 jode/javaDependencies.pl.in delete mode 100644 jode/javacWithDeps.sh.in diff --git a/jode/Makefile.am b/jode/Makefile.am index d68d7ce..b0ee681 100644 --- a/jode/Makefile.am +++ b/jode/Makefile.am @@ -3,5 +3,3 @@ SUBDIRS = jode bin doc test EXTRA_DIST = TODO - -all_recursive: javacWithDeps.sh diff --git a/jode/configure.in b/jode/configure.in index 4be73b0..7bbe537 100644 --- a/jode/configure.in +++ b/jode/configure.in @@ -125,7 +125,7 @@ AC_SUBST(CLASSPATH) AC_SUBST(JAVAC) AC_OUTPUT(Makefile -javacWithDeps.sh +javaDependencies.pl jode/Makefile jode/bytecode/Makefile jode/decompiler/Makefile @@ -144,5 +144,5 @@ bin/jode doc/Makefile test/Makefile) -AC_OUTPUT_COMMANDS(chmod 755 javacWithDeps.sh) +AC_OUTPUT_COMMANDS(chmod 755 javaDependencies.pl) AC_OUTPUT_COMMANDS(chmod 755 bin/jode) diff --git a/jode/javaDependencies.pl.in b/jode/javaDependencies.pl.in new file mode 100755 index 0000000..2e05ff8 --- /dev/null +++ b/jode/javaDependencies.pl.in @@ -0,0 +1,140 @@ +#!@PERL@ -s -w +# +# javaDependencies Copyright (C) 1999 Jochen Hoenicke. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program 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 for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; see the file COPYING. If not, write to +# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. +# +# $Id$ + +# This scripts create Makefile dependencies out of class files. It +# simply scans the constant pool of the class files, finding all +# references to other classes and adding a dependency to that class. +# +# It doesn't do a perfect job, since it can't handle dependencies to +# constant values in different classes: The compiler inlines the +# constant and thus doesn't include a reference to the class. +# +# Usage: +# javaDependencies.pl -classpath [-dependdir ] +# +# cp: colon separated paths to the java files we should depend on. +# depdir: if set, use this path as path to the java files when printing +# dependencies, not the path where the java files were found. +# useful, if you want to make use of VPATH settings in Makefile. +# class: The class file (not an inner class) for which the dependencies +# should be generated. We will also look for inner and anon +# classes. + +my $buff; + +sub readUTF { + read FILE, $buff, 2 or die "Can't read UTF8 length"; + my $ulength = unpack("n", $buff) & 0xffff; + return "" if $ulength == 0; + read FILE, $buff, $ulength or die "Can't read UTF8 string $ulength"; + unpack("a$ulength", $buff); +} + +$clazz = pop; +$clazz =~ /(.*)\.class/ or die "not a class file"; +$base = $1; +my ($filename, %done); +%done=(); +for $filename ($clazz, glob("$base\\\$*.class")) { + open FILE, $filename; + + read FILE, $buff, 8 or die "Can't read header"; + my ($magic, $minor, $major) = unpack("Nnn", $buff); + + die "Wrong magic $magic" if $magic != 0xcafebabe; + die "Wrong minor $minor" if $minor > 3; + die "Wrong minor $major" if $major != 45; + + read FILE, $buff, 2 or die "Can't read cpool length"; + + + my ($length) = unpack("n", $buff) & 0xffff; + + my $number; + my @strings = (); + my @clazzes; + for ($number = 1; $number < $length; $number++) { + + read FILE, $buff, 1 or die "Can't read constant tag"; + my ($tag) = unpack("C", $buff); + + #print STDERR "$number/$length: $tag"; + tags: + for ($tag) { + /^1$/ && do { + # UTF 8 + $strings[$number] = &readUTF(); + #print STDERR ": $strings[$number]"; + last tags; + }; + + /^(3|4|9|10|11|12)$/ && do { + # INTEGER, FLOAT, FIELDREF, METHODREF, IFACEREF, NAMEANDTYPE + read FILE, $buff, 4; + last tags; + }; + + /^(5|6)$/ && do { + # LONG, DOUBLE + read FILE, $buff, 8; + $number++; + last tags; + }; + + /^7$/ && do { + # CLASS + read FILE, $buff, 2; + push @clazzes, (unpack("n", $buff) & 0xffff); + last tags; + }; + + /^8$/ && do { + # STRING + read FILE, $buff, 2; + last tags; + }; + die "Unknown tag: $tag, $number/$length, $filename"; + } + #print STDERR "\n"; + } + + + my @deplist = (); + clazz: + for $c (@clazzes) { + $clzz = $strings[$c]; + next if $clzz =~ /^\[/; + next if defined $done{"$clzz"}; + $done{$clzz} = 1; + + for $p (split ':', $classpath) { + if (-e "$p/$clzz.java") { + push @deplist, (defined $dependdir + ? "$dependdir/$clzz.java" + : "$p/$clzz.java"); + next clazz; + } + } + } + if (@deplist) { + print "# Dependencies of $filename\n"; + print "$clazz: ". join (" ", @deplist) . "\n"; + } +} diff --git a/jode/javacWithDeps.sh.in b/jode/javacWithDeps.sh.in deleted file mode 100644 index 2792a77..0000000 --- a/jode/javacWithDeps.sh.in +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh -JAVAC=@JAVAC@ -JIKES=@JIKES@ -PERL=@PERL@ - -abs_top_builddir=`cd $top_builddir; pwd` -abs_top_srcdir=`cd $top_srcdir; pwd` -if [ "$JAVAC" = "$JIKES" -a -n "$PERL" ]; then - TEMPDEPS=`mktemp "deps.XXXXXX"` - trap "rm $TEMPDEPS" EXIT - $JAVAC +M=$TEMPDEPS $* - sort $TEMPDEPS | $PERL -ne 's"^(\Q'$top_srcdir'\E|\Q'$top_builddir'\E)"'$abs_top_builddir'"; s": \Q'$top_srcdir'\E": '$abs_top_srcdir'"; s": \Q'$top_builddir'\E": '$abs_top_builddir'"; m"(\Q'$abs_top_builddir'\E[^\.:]+)\.class: [^\.]*.java$" or next; if ($1 ne $last) { $last = $1; open DEP, ">$1.u" }; print DEP $_' -else - $JAVAC $* -fi diff --git a/jode/jode/Makefile.am b/jode/jode/Makefile.am index 00e83ec..9bb3e39 100644 --- a/jode/jode/Makefile.am +++ b/jode/jode/Makefile.am @@ -3,11 +3,12 @@ SUBDIRS = util bytecode type jvm expr flow decompiler obfuscator @SWINGUI@ JAR = @JAR@ -JAVAC = top_srcdir=$(top_srcdir) top_builddir=$(top_builddir) $(top_builddir)/javacWithDeps.sh +JAVAC = @JAVAC@ +JAVADEP = $(top_builddir)/javaDependencies.pl \ + -dependdir=$(top_builddir) -classpath=$(top_builddir):$(top_srcdir) CLASSPATH = @CLASSPATH@ CLASSLIB = @CLASSLIB@ BUILD_CLASSPATH = $(top_srcdir):$(top_builddir):.:$(CLASSPATH):$(CLASSLIB) -VPATH=$(srcdir):$(top_srcdir):$(top_builddir) MY_JAVA_FILES = \ AssertError.java \ @@ -23,14 +24,16 @@ EXTRA_DIST = $(MY_JAVA_FILES) JARFILE = jode-@VERSION@.jar data_DATA = $(JARFILE) -@QUOTE@-include *.u +@QUOTE@-include $(MY_JAVA_FILES:.java=.dep) %.class: %.java $(JAVAC) -classpath $(BUILD_CLASSPATH):$(CLASSLIB) -d $(top_builddir) $< +%.dep: %.class + $(JAVADEP) $< >$@ clean-local: @rm -f *.class - @rm -f *.u + @rm -f *.dep $(JARFILE): $(noinst_DATA) CLASSPATH=$(top_builddir):$(CLASSPATH) $(JAVA) -mx80m \ diff --git a/jode/jode/bytecode/Makefile.am b/jode/jode/bytecode/Makefile.am index fc9d35f..626e680 100644 --- a/jode/jode/bytecode/Makefile.am +++ b/jode/jode/bytecode/Makefile.am @@ -1,7 +1,9 @@ ## Input file for automake to generate the Makefile.in used by configure JAR = @JAR@ -JAVAC = top_srcdir=$(top_srcdir) top_builddir=$(top_builddir) $(top_builddir)/javacWithDeps.sh +JAVAC = @JAVAC@ +JAVADEP = $(top_builddir)/javaDependencies.pl\ + -dependdir=$(top_builddir) -classpath=$(top_builddir):$(top_srcdir) CLASSPATH = @CLASSPATH@ CLASSLIB = @CLASSLIB@ BUILD_CLASSPATH = $(top_srcdir):$(top_builddir):$(CLASSPATH):$(CLASSLIB) @@ -27,11 +29,14 @@ MY_JAVA_FILES = \ noinst_DATA = $(MY_JAVA_FILES:.java=.class) EXTRA_DIST = $(MY_JAVA_FILES) -@QUOTE@-include *.u +@QUOTE@-include $(MY_JAVA_FILES:.java=.dep) %.class: %.java $(JAVAC) -classpath $(BUILD_CLASSPATH):$(CLASSLIB) -d $(top_builddir) $< +%.dep: %.class + $(JAVADEP) $< >$@ + clean-local: @rm -f *.class - @rm -f *.u + @rm -f *.dep diff --git a/jode/jode/decompiler/Makefile.am b/jode/jode/decompiler/Makefile.am index 13e83c9..3a0365d 100644 --- a/jode/jode/decompiler/Makefile.am +++ b/jode/jode/decompiler/Makefile.am @@ -1,7 +1,9 @@ ## Input file for automake to generate the Makefile.in used by configure JAR = @JAR@ -JAVAC = top_srcdir=$(top_srcdir) top_builddir=$(top_builddir) $(top_builddir)/javacWithDeps.sh +JAVAC = @JAVAC@ +JAVADEP = $(top_builddir)/javaDependencies.pl\ + -dependdir=$(top_builddir) -classpath=$(top_builddir):$(top_srcdir) CLASSPATH = @CLASSPATH@ CLASSLIB = @CLASSLIB@ BUILD_CLASSPATH = $(top_srcdir):$(top_builddir):$(CLASSPATH):$(CLASSLIB) @@ -27,11 +29,14 @@ MY_JAVA_FILES = \ noinst_DATA = $(MY_JAVA_FILES:.java=.class) EXTRA_DIST = $(MY_JAVA_FILES) -@QUOTE@-include *.u +@QUOTE@-include $(MY_JAVA_FILES:.java=.dep) %.class: %.java $(JAVAC) -classpath $(BUILD_CLASSPATH):$(CLASSLIB) -d $(top_builddir) $< +%.dep: %.class + $(JAVADEP) $< >$@ + clean-local: @rm -f *.class - @rm -f *.u + @rm -f *.dep diff --git a/jode/jode/expr/Makefile.am b/jode/jode/expr/Makefile.am index 09ba961..b9c03e4 100644 --- a/jode/jode/expr/Makefile.am +++ b/jode/jode/expr/Makefile.am @@ -1,7 +1,9 @@ ## Input file for automake to generate the Makefile.in used by configure JAR = @JAR@ -JAVAC = top_srcdir=$(top_srcdir) top_builddir=$(top_builddir) $(top_builddir)/javacWithDeps.sh +JAVAC = @JAVAC@ +JAVADEP = $(top_builddir)/javaDependencies.pl\ + -dependdir=$(top_builddir) -classpath=$(top_builddir):$(top_srcdir) CLASSPATH = @CLASSPATH@ CLASSLIB = @CLASSLIB@ BUILD_CLASSPATH = $(top_srcdir):$(top_builddir):$(CLASSPATH):$(CLASSLIB) @@ -54,11 +56,14 @@ MY_JAVA_FILES = \ noinst_DATA = $(MY_JAVA_FILES:.java=.class) EXTRA_DIST = $(MY_JAVA_FILES) -@QUOTE@-include *.u +@QUOTE@-include $(MY_JAVA_FILES:.java=.dep) %.class: %.java $(JAVAC) -classpath $(BUILD_CLASSPATH):$(CLASSLIB) -d $(top_builddir) $< +%.dep: %.class + $(JAVADEP) $< >$@ + clean-local: @rm -f *.class - @rm -f *.u + @rm -f *.dep diff --git a/jode/jode/flow/Makefile.am b/jode/jode/flow/Makefile.am index d5f01a7..9697f2e 100644 --- a/jode/jode/flow/Makefile.am +++ b/jode/jode/flow/Makefile.am @@ -1,7 +1,9 @@ ## Input file for automake to generate the Makefile.in used by configure JAR = @JAR@ -JAVAC = top_srcdir=$(top_srcdir) top_builddir=$(top_builddir) $(top_builddir)/javacWithDeps.sh +JAVAC = @JAVAC@ +JAVADEP = $(top_builddir)/javaDependencies.pl\ + -dependdir=$(top_builddir) -classpath=$(top_builddir):$(top_srcdir) CLASSPATH = @CLASSPATH@ CLASSLIB = @CLASSLIB@ BUILD_CLASSPATH = $(top_srcdir):$(top_builddir):$(CLASSPATH):$(CLASSLIB) @@ -51,11 +53,14 @@ MY_JAVA_FILES = \ noinst_DATA = $(MY_JAVA_FILES:.java=.class) EXTRA_DIST = $(MY_JAVA_FILES) -@QUOTE@-include *.u +@QUOTE@-include $(MY_JAVA_FILES:.java=.dep) %.class: %.java $(JAVAC) -classpath $(BUILD_CLASSPATH):$(CLASSLIB) -d $(top_builddir) $< +%.dep: %.class + $(JAVADEP) $< >$@ + clean-local: @rm -f *.class - @rm -f *.u + @rm -f *.dep diff --git a/jode/jode/jvm/Makefile.am b/jode/jode/jvm/Makefile.am index 590051e..a23808e 100644 --- a/jode/jode/jvm/Makefile.am +++ b/jode/jode/jvm/Makefile.am @@ -1,7 +1,9 @@ ## Input file for automake to generate the Makefile.in used by configure JAR = @JAR@ -JAVAC = top_srcdir=$(top_srcdir) top_builddir=$(top_builddir) $(top_builddir)/javacWithDeps.sh +JAVAC = @JAVAC@ +JAVADEP = $(top_builddir)/javaDependencies.pl\ + -dependdir=$(top_builddir) -classpath=$(top_builddir):$(top_srcdir) CLASSPATH = @CLASSPATH@ CLASSLIB = @CLASSLIB@ BUILD_CLASSPATH = $(top_builddir):$(top_srcdir):$(CLASSPATH):$(CLASSLIB) @@ -20,11 +22,14 @@ MY_JAVA_FILES = \ noinst_DATA = $(MY_JAVA_FILES:.java=.class) EXTRA_DIST = $(MY_JAVA_FILES) -@QUOTE@-include *.u +@QUOTE@-include $(MY_JAVA_FILES:.java=.dep) %.class: %.java $(JAVAC) -classpath $(BUILD_CLASSPATH):$(CLASSLIB) -d $(top_builddir) $< +%.dep: %.class + $(JAVADEP) $< >$@ + clean-local: @rm -f *.class - @rm -f *.u + @rm -f *.dep diff --git a/jode/jode/obfuscator/Makefile.am b/jode/jode/obfuscator/Makefile.am index c5edf26..f8d28d1 100644 --- a/jode/jode/obfuscator/Makefile.am +++ b/jode/jode/obfuscator/Makefile.am @@ -1,7 +1,9 @@ ## Input file for automake to generate the Makefile.in used by configure JAR = @JAR@ -JAVAC = top_srcdir=$(top_srcdir) top_builddir=$(top_builddir) $(top_builddir)/javacWithDeps.sh +JAVAC = @JAVAC@ +JAVADEP = $(top_builddir)/javaDependencies.pl\ + -dependdir=$(top_builddir) -classpath=$(top_builddir):$(top_srcdir) CLASSPATH = @CLASSPATH@ CLASSLIB = @CLASSLIB@ BUILD_CLASSPATH = $(top_srcdir):$(top_builddir):$(CLASSPATH):$(CLASSLIB) @@ -34,11 +36,14 @@ MY_JAVA_FILES = \ noinst_DATA = $(MY_JAVA_FILES:.java=.class) EXTRA_DIST = $(MY_JAVA_FILES) -@QUOTE@-include *.u +@QUOTE@-include $(MY_JAVA_FILES:.java=.dep) %.class: %.java $(JAVAC) -classpath $(BUILD_CLASSPATH):$(CLASSLIB) -d $(top_builddir) $< +%.dep: %.class + $(JAVADEP) $< >$@ + clean-local: @rm -f *.class - @rm -f *.u + @rm -f *.dep diff --git a/jode/jode/swingui/Makefile.am b/jode/jode/swingui/Makefile.am index 1ba93c7..278482c 100644 --- a/jode/jode/swingui/Makefile.am +++ b/jode/jode/swingui/Makefile.am @@ -1,7 +1,9 @@ ## Input file for automake to generate the Makefile.in used by configure JAR = @JAR@ -JAVAC = top_srcdir=$(top_srcdir) top_builddir=$(top_builddir) $(top_builddir)/javacWithDeps.sh +JAVAC = @JAVAC@ +JAVADEP = $(top_builddir)/javaDependencies.pl\ + -dependdir=$(top_builddir) -classpath=$(top_builddir):$(top_srcdir) CLASSPATH = @CLASSPATH@ CLASSLIB = @CLASSLIB@ BUILD_CLASSPATH = $(top_srcdir):$(top_builddir):$(CLASSPATH):$(CLASSLIB) @@ -13,11 +15,14 @@ MY_JAVA_FILES = \ noinst_DATA = $(MY_JAVA_FILES:.java=.class) EXTRA_DIST = $(MY_JAVA_FILES) -@QUOTE@-include *.u +@QUOTE@-include $(MY_JAVA_FILES:.java=.dep) %.class: %.java $(JAVAC) -classpath $(BUILD_CLASSPATH):$(CLASSLIB) -d $(top_builddir) $< +%.dep: %.class + $(JAVADEP) $< >$@ + clean-local: @rm -f *.class - @rm -f *.u + @rm -f *.dep diff --git a/jode/jode/type/Makefile.am b/jode/jode/type/Makefile.am index 007bd06..06b20e9 100644 --- a/jode/jode/type/Makefile.am +++ b/jode/jode/type/Makefile.am @@ -1,7 +1,9 @@ ## Input file for automake to generate the Makefile.in used by configure JAR = @JAR@ -JAVAC = top_srcdir=$(top_srcdir) top_builddir=$(top_builddir) $(top_builddir)/javacWithDeps.sh +JAVAC = @JAVAC@ +JAVADEP = $(top_builddir)/javaDependencies.pl\ + -dependdir=$(top_builddir) -classpath=$(top_builddir):$(top_srcdir) CLASSPATH = @CLASSPATH@ CLASSLIB = @CLASSLIB@ BUILD_CLASSPATH = $(top_srcdir):$(top_builddir):$(CLASSPATH):$(CLASSLIB) @@ -19,11 +21,14 @@ MY_JAVA_FILES = \ noinst_DATA = $(MY_JAVA_FILES:.java=.class) EXTRA_DIST = $(MY_JAVA_FILES) -@QUOTE@-include *.u +@QUOTE@-include $(MY_JAVA_FILES:.java=.dep) %.class: %.java $(JAVAC) -classpath $(BUILD_CLASSPATH):$(CLASSLIB) -d $(top_builddir) $< +%.dep: %.class + $(JAVADEP) $< >$@ + clean-local: @rm -f *.class - @rm -f *.u + @rm -f *.dep diff --git a/jode/jode/util/Makefile.am b/jode/jode/util/Makefile.am index 49cd915..8074039 100644 --- a/jode/jode/util/Makefile.am +++ b/jode/jode/util/Makefile.am @@ -1,7 +1,9 @@ ## Input file for automake to generate the Makefile.in used by configure JAR = @JAR@ -JAVAC = top_srcdir=$(top_srcdir) top_builddir=$(top_builddir) $(top_builddir)/javacWithDeps.sh +JAVAC = @JAVAC@ +JAVADEP = $(top_builddir)/javaDependencies.pl\ + -dependdir=$(top_builddir) -classpath=$(top_builddir):$(top_srcdir) CLASSPATH = @CLASSPATH@ CLASSLIB = @CLASSLIB@ BUILD_CLASSPATH = $(top_srcdir):$(top_builddir):$(CLASSPATH):$(CLASSLIB) @@ -41,11 +43,14 @@ MY_JAVA_FILES = \ noinst_DATA = $(MY_JAVA_FILES:.java=.class) EXTRA_DIST = $(MY_JAVA_FILES) -@QUOTE@-include *.u +@QUOTE@-include $(MY_JAVA_FILES:.java=.dep) %.class: %.java $(JAVAC) -classpath $(BUILD_CLASSPATH):$(CLASSLIB) -d $(top_builddir) $< +%.dep: %.class + $(JAVADEP) $< >$@ + clean-local: @rm -f *.class - @rm -f *.u + @rm -f *.dep