3 # Create a dependency file for use with make that will
4 # a) not have duplicate entries
5 # b) not include the source of a file as a dependency to separate file,
6 # just the class of the file
7 # c) use jikes .u files
8 # d) includes classes which need native compilation via simple parsing
9 # to find native methods requiring use of javah
13 my ( $dir, $dep ) = "";
14 my @dirs = ( 'java', 'javax', 'gnu' );
15 my ( $depout ) = "makefile.dep";
16 my ( $classout ) = "classes.dep";
17 my ( $headerout ) = "headers.dep";
18 my ( $javaout ) = "java.dep";
21 use vars qw
( $classout $headerout @dirs @deps @natives $dir $dep $depout );
27 if ($ARGV[0] =~ /^-h/)
32 elsif ($ARGV[0] =~ /^-d/)
36 # find all .u files recursively and parse'm
41 elsif ($ARGV[0] =~ /^-c/)
46 elsif ($ARGV[0] =~ /^-j/)
55 print "mkdep.pl -h \tfor header files\n";
56 print "mkdep.pl -c \tfor a list of classes\n";
57 print "mkdep.pl -j \tfor a list of java files\n";
58 print "mkdep.pl -d \tfor dependency generation from jikes .u files\n";
64 my ($i, $j, $k, $l) = "";
65 my $top_srcdir = "../";
66 if (defined $ENV{'top_srcdir'}) {
67 $top_srcdir = $ENV{'top_srcdir'};
69 my $top_srcdir_regex = $top_srcdir;
70 if ($top_srcdir_regex !~ /.*\/$/) {
71 $top_srcdir_regex .= '/';
73 $top_srcdir_regex =~ s/\./\\\./g; # replace . with \.
74 $top_srcdir_regex =~ s/\//\\\
//g; # replace / with \/
75 # print "regex is $top_srcdir_regex\n";
76 open(MAKEDEP
, ">$headerout") || die "Could not open file ", $headerout;
78 # the HEADERS = ... stuff
81 print MAKEDEP
"CP_HEADERS = \\", "\n";
82 foreach $i (0 .. $#natives-1)
85 $j =~ s/^$top_srcdir_regex//; # remove ../ or similar
86 $j =~ s/^(\.\.\/)+//g; # remove all preceding ../
87 $j =~ s/^vm\/reference\///; # remove vm/reference/
88 $j =~ s/\//_
/g; # replace / with _
89 $j =~ s/\.java$/\.h/; # replace .java with .h
90 print MAKEDEP
" \$(top_builddir)/include/", $j, " \\", "\n";
92 $j = $natives[$#natives];
93 $j =~ s/^$top_srcdir_regex//; # remove ../
94 $j =~ s/^(\.\.\/)+//g; # remove all preceding ../
95 $j =~ s/^vm\/reference\///; # remove vm/reference/
96 $j =~ s/\//_
/g; # replace / with _
97 $j =~ s/\.java/\.h/; # replace .java with .h
98 print MAKEDEP
" \$(top_builddir)/include/", $j, "\n\n";
100 # print rules to make .h files
102 # y/x.h : ../z/x.java
104 # mv y_x.h $(top_srcdir)/include
110 foreach $i (0 .. $#natives-1)
113 $j =~ s/^$top_srcdir_regex//; # remove ../
114 $j =~ s/^(\.\.\/)+//g; # remove all preceding ../
115 $j =~ s/^vm\/reference\///; # remove vm/reference/
118 $j =~ s/\//_
/g; # replace / with _
119 $j =~ s/\.java$/\.h/; # replace .java with .h
121 $k = $natives[$i]; # the original .java file
122 # $k =~ s/\.java$/\.class/; # replace .java with .class
124 $l =~ s/\.java$//; # remove .class
125 $l =~ s/\//\
./g; # replace / with
.
127 print MAKEDEP
"\$(top_builddir)/include/", $j, " : ", $k, "\n";
128 print MAKEDEP
"\t\$(JAVAH) ", $l, "\n";
129 print MAKEDEP
"\tmv ", $j, " \$(top_builddir)/include\n\n";
131 $j = $natives[$#natives];
132 $j =~ s/^$top_srcdir_regex//; # remove ../
133 $j =~ s/^(\.\.\/)+//g; # remove all preceding ../
134 $j =~ s/^vm\/reference\///; # remove vm/reference/
137 $j =~ s/\//_
/g; # replace / with _
138 $j =~ s/\.java/\.h/; # replace .java with .h
140 $k = $natives[$#natives]; # the original .java file
141 # $k =~ s/\.java$/\.class/; # replace .java with .class
143 $l =~ s/\.java$//; # remove .class
144 $l =~ s/\//\
./g; # replace / with
.
146 print MAKEDEP
"\$(top_builddir)/include/", $j, " : ", $k, "\n";
147 print MAKEDEP
"\t\$(JAVAH) ", $l, "\n";
148 print MAKEDEP
"\tmv ", $j, " \$(top_builddir)/include\n\n";
155 my ($i, $j, $class, $depend, $source, $depend_source) = "";
157 open(MAKEDEP
, ">$javaout") || die "Could not open file ", $classout;
159 # the JAVA_SRCS = ... stuff
162 print MAKEDEP
"JAVA_SRCS = \\", "\n";
163 foreach $i (0 .. $#natives-1)
166 print MAKEDEP
" ", $j, " \\", "\n";
168 $j = $natives[$#natives];
169 print MAKEDEP
" ", $j, "\n\n";
176 my ($i, $j, $class, $depend, $source, $depend_source) = "";
178 open(MAKEDEP
, ">$classout") || die "Could not open file ", $classout;
180 # the CLASSES = ... stuff
183 print MAKEDEP
"CLASSES = \\", "\n";
184 foreach $i (0 .. $#natives-1)
187 $j =~ s/\.java$/\.class/;
188 print MAKEDEP
" ", $j, " \\", "\n";
190 $j = $natives[$#natives];
191 $j =~ s/\.java$/\.class/;
192 print MAKEDEP
" ", $j, "\n\n";
199 my ($i, $j, $class, $depend, $source, $depend_source) = "";
201 open(MAKEDEP
, ">$depout") || die "Could not open file ", $depout;
203 # the class dependencies
206 open(FILE
, "<$i") || die "Could not open file ", $i, "\n";
210 ($class, $depend) = /(.+) : (.+)$/;
212 $source =~ s/\.class$/\.java/;
213 if (($source eq $depend) || ($depend !~ /\.java$/))
215 if ($depend =~ /^\.\.\/.+\
.class$/)
217 $depend =~ s/^\.\.\///;
219 if (($depend =~ /\.java$/) && ($depend !~ /^\.\.\//))
221 $depend = "../" . $depend;
223 print MAKEDEP
$class, " : ", $depend, "\n";
235 open(CLASSES
, "<classes") || die "Could not open file classes\n";
240 push @natives, $file;
248 open(CLASSES
, "<classes") || die "Could not open file classes\n";
253 $file =~ s/^\.\.\///;
254 push @natives, $file;
262 open(CLASSES
, "<classes") || die "Could not open file classes\n";
267 if (hasNativeMethod
($file))
269 push @natives, $file;
279 my ($line, $one, $two) = "";
280 open(FILE
, "<$file") || die "Could not open file ", $file, "\n";
287 $line = $one . " " . $two;
288 if ( ($line =~ /^\s*public\s.*native\s+\S+\s+\S+\s*\(/) ||
289 ($line =~ /^\s*public\s.*native\s+\S+\s+\S+\s+\S+\s*\(/) ||
290 ($line =~ /^\s*protected\s.*native\s+\S+\s+\S+\s*\(/) ||
291 ($line =~ /^\s*protected\s.*native\s+\S+\s+\S+\s+\S+\s*\(/) ||
292 ($line =~ /^\s*private\s.*native\s+\S+\s+\S+\s*\(/) ||
293 ($line =~ /^\s*private\s.*native\s+\S+\s+\S+\s+\S+\s*\(/) ||
294 ($line =~ /^\s*abstract\s.*native\s+\S+\s+\S+\s*\(/) ||
295 ($line =~ /^\s*final\s.*native\s+\S+\s+\S+\s*\(/) ||
296 ($line =~ /^\s*synchronized\s.*native\s+\S+\s+\S+\s*\(/) ||
297 ($line =~ /^\s*native\s.*/) )
312 my (@local_deps) = ();
314 my ($i, $local_dep) = "";
315 if (opendir(DIR
, $dir))
317 @entries = grep(-d
"$dir/$_" && !/^\
.\
.?
$/, readdir(DIR
));
318 foreach $i (@entries)
320 push @dirs, "$dir/$i";
323 @entries= grep(/\.u$/, readdir(DIR
));
325 foreach $i (@entries)
327 push @local_deps, "$dir/$i";
329 push @deps, @local_deps;