OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libjava/] [classpath/] [lib/] [mkdep.pl.in] - Blame information for rev 20

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
#!@PERL@
2
#
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
10
 
11
use strict;
12
 
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";
19
my @deps = ();
20
my @natives = ();
21
use vars qw ( $classout $headerout @dirs @deps @natives $dir $dep $depout );
22
 
23
# main
24
{
25
    if ($#ARGV == 0)
26
    {
27
        if ($ARGV[0] =~ /^-h/)
28
        {
29
            findNativeFiles();
30
            writeNativeFile();
31
        }
32
        elsif ($ARGV[0] =~ /^-d/)
33
        {
34
            foreach $dir (@dirs)
35
            {
36
                # find all .u files recursively and parse'm
37
                findDepFiles($dir);
38
            }
39
            writeDepFile();
40
        }
41
        elsif ($ARGV[0] =~ /^-c/)
42
        {
43
            findClassFiles();
44
            writeClassFile();
45
        }
46
        elsif ($ARGV[0] =~ /^-j/)
47
        {
48
            findJavaFiles();
49
            writeJavaFile();
50
        }
51
    }
52
    else
53
    {
54
        print "Usage:\n";
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";
59
    }
60
}
61
 
62
sub writeNativeFile
63
{
64
    my ($i, $j, $k, $l) = "";
65
    my $top_srcdir = "../";
66
    if (defined $ENV{'top_srcdir'}) {
67
        $top_srcdir = $ENV{'top_srcdir'};
68
    }
69
    my $top_srcdir_regex = $top_srcdir;
70
    if ($top_srcdir_regex !~ /.*\/$/) {
71
        $top_srcdir_regex .= '/';
72
    }
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;
77
 
78
    # the HEADERS = ... stuff
79
    if ($#natives > -1)
80
    {
81
        print MAKEDEP "CP_HEADERS = \\", "\n";
82
        foreach $i (0 .. $#natives-1)
83
        {
84
            $j = $natives[$i];
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";
91
        }
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";
99
 
100
        # print rules to make .h files
101
        # y/x.h : z/x.class
102
        # y/x.h : ../z/x.java
103
        #     javah -jni z.x
104
        #     mv y_x.h $(top_srcdir)/include
105
 
106
        # j = y/x.h
107
        # k = z/x.class
108
        # k = ../z/x.java
109
        # l = z.x
110
        foreach $i (0 .. $#natives-1)
111
        {
112
            $j = $natives[$i];
113
            $j =~ s/^$top_srcdir_regex//;   # remove ../
114
            $j =~ s/^(\.\.\/)+//g;          # remove all preceding ../
115
            $j =~ s/^vm\/reference\///;   # remove vm/reference/
116
#           $k = $l = $j;
117
            $l = $j;
118
            $j =~ s/\//_/g;             # replace / with _
119
            $j =~ s/\.java$/\.h/;       # replace .java with .h
120
 
121
            $k = $natives[$i];          # the original .java file
122
#           $k =~ s/\.java$/\.class/;   # replace .java with .class
123
 
124
            $l =~ s/\.java$//;          # remove .class
125
            $l =~ s/\//\./g;            # replace / with .
126
 
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";
130
        }
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/
135
#       $k = $l = $j;
136
        $l = $j;
137
        $j =~ s/\//_/g;             # replace / with _
138
        $j =~ s/\.java/\.h/;        # replace .java with .h
139
 
140
        $k = $natives[$#natives];          # the original .java file
141
#       $k =~ s/\.java$/\.class/;   # replace .java with .class
142
 
143
        $l =~ s/\.java$//;          # remove .class
144
        $l =~ s/\//\./g;            # replace / with .
145
 
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";
149
    }
150
    close(MAKEDEP);
151
}
152
 
153
sub writeJavaFile
154
{
155
    my ($i, $j, $class, $depend, $source, $depend_source) = "";
156
 
157
    open(MAKEDEP, ">$javaout") || die "Could not open file ", $classout;
158
 
159
    # the JAVA_SRCS = ... stuff
160
    if ($#natives > -1)
161
    {
162
        print MAKEDEP "JAVA_SRCS = \\", "\n";
163
        foreach $i (0 .. $#natives-1)
164
        {
165
            $j = $natives[$i];
166
            print MAKEDEP "           ", $j, " \\", "\n";
167
        }
168
        $j = $natives[$#natives];
169
        print MAKEDEP "           ", $j, "\n\n";
170
    }
171
    close(MAKEDEP);
172
}
173
 
174
sub writeClassFile
175
{
176
    my ($i, $j, $class, $depend, $source, $depend_source) = "";
177
 
178
    open(MAKEDEP, ">$classout") || die "Could not open file ", $classout;
179
 
180
    # the CLASSES = ... stuff
181
    if ($#natives > -1)
182
    {
183
        print MAKEDEP "CLASSES = \\", "\n";
184
        foreach $i (0 .. $#natives-1)
185
        {
186
            $j = $natives[$i];
187
            $j =~ s/\.java$/\.class/;
188
            print MAKEDEP "           ", $j, " \\", "\n";
189
        }
190
        $j = $natives[$#natives];
191
        $j =~ s/\.java$/\.class/;
192
        print MAKEDEP "           ", $j, "\n\n";
193
    }
194
    close(MAKEDEP);
195
}
196
 
197
sub writeDepFile
198
{
199
    my ($i, $j, $class, $depend, $source, $depend_source) = "";
200
 
201
    open(MAKEDEP, ">$depout") || die "Could not open file ", $depout;
202
 
203
    # the class dependencies
204
    foreach $i (@deps)
205
    {
206
        open(FILE, "<$i") || die "Could not open file ", $i, "\n";
207
        while()
208
        {
209
            chop;
210
            ($class, $depend) = /(.+) : (.+)$/;
211
            $source = $class;
212
            $source =~ s/\.class$/\.java/;
213
            if (($source eq $depend) || ($depend !~ /\.java$/))
214
            {
215
                if ($depend =~ /^\.\.\/.+\.class$/)
216
                {
217
                    $depend =~ s/^\.\.\///;
218
                }
219
                if (($depend =~ /\.java$/) && ($depend !~ /^\.\.\//))
220
                {
221
                    $depend = "../" . $depend;
222
                }
223
                print MAKEDEP $class, " : ", $depend, "\n";
224
            }
225
        }
226
        print MAKEDEP "\n";
227
        close(FILE);
228
    }
229
    close(MAKEDEP);
230
}
231
 
232
sub findJavaFiles
233
{
234
    my ($file) = "";
235
    open(CLASSES, "
236
    while()
237
    {
238
        chop;
239
        $file = $_;
240
        push @natives, $file;
241
    }
242
    close(CLASSES);
243
}
244
 
245
sub findClassFiles
246
{
247
    my ($file) = "";
248
    open(CLASSES, "
249
    while()
250
    {
251
        chop;
252
        $file = $_;
253
        $file =~ s/^\.\.\///;
254
        push @natives, $file;
255
    }
256
    close(CLASSES);
257
}
258
 
259
sub findNativeFiles
260
{
261
    my ($file) = "";
262
    open(CLASSES, "
263
    while()
264
    {
265
        chop;
266
        $file = $_;
267
        if (hasNativeMethod($file))
268
        {
269
            push @natives, $file;
270
        }
271
 
272
    }
273
    close(CLASSES);
274
}
275
 
276
sub hasNativeMethod
277
{
278
    my ($file) = @_;
279
    my ($line, $one, $two) = "";
280
    open(FILE, "<$file") || die "Could not open file ", $file, "\n";
281
    while()
282
    {
283
        chop;
284
        $one = $two;
285
        $two = $_;
286
 
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.*/) )
298
        {
299
            close(FILE);
300
            return 1;
301
        }
302
    }
303
    close(FILE);
304
    return 0;
305
}
306
 
307
sub findDepFiles
308
{
309
 
310
    my ($dir) = @_;
311
    my (@dirs) = ();
312
    my (@local_deps) = ();
313
    my (@entries) = ();
314
    my ($i, $local_dep) = "";
315
    if (opendir(DIR, $dir))
316
    {
317
      @entries = grep(-d "$dir/$_" && !/^\.\.?$/, readdir(DIR));
318
      foreach $i (@entries)
319
      {
320
          push @dirs, "$dir/$i";
321
      }
322
      rewinddir(DIR);
323
      @entries= grep(/\.u$/, readdir(DIR));
324
      closedir(DIR);
325
      foreach $i (@entries)
326
      {
327
          push @local_deps, "$dir/$i";
328
      }
329
      push @deps, @local_deps;
330
      foreach $i (@dirs)
331
      {
332
          findDepFiles($i);
333
      }
334
    }
335
}
336
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.