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

Subversion Repositories core_arm

[/] [core_arm/] [trunk/] [build/] [extract.pl] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 tarookumic
#!/usr/bin/perl
2
 
3
if ($#ARGV < 1) {
4
    die ("# Call: extract.pl <config> <basedir> \n");
5
}
6
$config = $ARGV[0];
7
 
8
$base = $ARGV[1];
9
$cmd = "find $base";
10
print STDERR $cmd;
11
$a = `$cmd`;
12
@a = split("\n",$a);
13
%h = ();
14
%d = ();
15
 
16
foreach $f (@a) {
17
    if ( $f =~ /\.vhd$/) {
18
        ($fn,$pn) = splitpath($f);
19
        if ($fn =~ /^([^\.]*)\.vhd$/) {
20
            $h{$1} = $f;
21
        }
22
    }
23
}
24
 
25
%trans = ();
26
%noread = ();
27
if (open(FILEH, "$config")) {
28
    while (<FILEH>) {
29
        @c = split("=",$_);
30
        if ($#c == 1) {
31
            $k = $c[0];
32
            $v = $c[1];
33
            $k =~ s/[\s\n\r]//gi;
34
            $v =~ s/[\s\n\r]//gi;
35
            if (exists($h{$k})) {
36
                if ($v =~ /trans/) {
37
                    $n = $h{$k};
38
                    @tmp = ();
39
                    $trans{$n} = [@tmp];
40
                } elsif ($v =~ /exclude/) {
41
                    $n = $h{$k};
42
                    $noread{$n} = 1;
43
                }
44
            }
45
        }
46
    }
47
    close(FILEH);
48
} else {
49
    die ("opening \"$config\": $!\n");
50
}
51
 
52
 
53
foreach $f (@a) {
54
    $dep = "$f: ";
55
    if ( $f =~ /\.vhd$/) {
56
        if (1) { #if (!$noread{$f}){
57
            ($fn,$pn) = splitpath($f);
58
            if (open(FILEH, "$f")) {
59
                @tmp = ();
60
                $d{$f} = [@tmp];
61
                print STDERR ("Scanning $f\n");
62
                while (<FILEH>) {
63
                    if (!(/\$\(do-not-add-to-makefile\)/)) {
64
                        if (/use[[:space:]]*work\.([[:print:]]*)\.all/) {
65
                            $m = $1;
66
                            $m =~ s/[\s\r\n]$//;
67
                            if (exists($h{$m})) {
68
                                $m = $h{$m};
69
                                @tmp = @{$d{$f}};
70
                                push(@tmp,$m);
71
                                $d{$f} = [@tmp];
72
                            }
73
                        }
74
                        elsif (/component [[:space:]]*([[:print:]]*)/) {
75
                            $m = $1;
76
                            $m =~ s/[\s\r\n]$//;
77
                            if (exists($trans{$f})) {
78
                                @tmp = @{$trans{$f}};
79
                                if (exists($h{$m})) {
80
                                    $m = $h{$m};
81
                                    push (@tmp,$m);
82
                                    $trans{$f} = [@tmp];
83
                                }
84
                            } else {
85
                                if (exists($h{$m})) {
86
                                    $m = $h{$m};
87
                                    @tmp = @{$d{$f}};
88
                                    push(@tmp,$m);
89
                                    $d{$f} = [@tmp];
90
                                }
91
                            }
92
                        }
93
                    }
94
 
95
                    if (/\$\(add-to-dep:([[:print:]]*)\)/) {
96
                        if (exists($h{$1})) {
97
                            $m = $h{$1};
98
                            @tmp = @{$d{$m}};
99
                            push(@tmp,$f);
100
                            $d{$m} = [@tmp];
101
                        }
102
                    }
103
                    if (/\$\(add-rule:([[:print:]]*)\)/) {
104
                        $m = ":rule:$1";
105
                        @tmp = @{$d{$f}};
106
                        push(@tmp,$m);
107
                        $d{$f} = [@tmp];
108
                    }
109
                }
110
                close(FILEH);
111
            }
112
            else {
113
                print "opening \"$_\": $!\n";
114
            }
115
        }
116
    }
117
}
118
 
119
print ("# Automatically generated by \"make dep\"\n");
120
%f = ();
121
foreach $k (sort keys %d) {
122
 
123
    ($fn,$pn) = splitpath($k);
124
    $f{$fn} = "$pn/$fn";
125
 
126
    $tf = tagfile($k);
127
    print ("$tf: work tags ");
128
    @tmp = @{$d{$k}};
129
    foreach $f (@tmp) {
130
        if (exists($trans{$f})) {
131
            print STDERR ("Trans $f:\n");
132
            $l = readin($k);
133
            @tmp2 = @{$trans{$f}};
134
            foreach $e (@tmp2) {
135
                $dn = compname($e);
136
                if (!($dn eq compname($k))) {
137
                    if ($l =~ /[a-zA-Z0-9_][[:space:]\n\r]*:[[:space:]]*$dn[[:space:]\n\r]/) {
138
                        print STDERR ("Found $dn in $k\n");
139
                        print (" ".tagfile($e));
140
                    }
141
                }
142
            }
143
        }
144
        if ($f =~ /^:rule:/i) {
145
            $f =~ s/^:rule://gi;
146
            print (" ".$f);
147
        }
148
        elsif (!(compname($f) eq compname($k))) {
149
            print (" ".tagfile($f));
150
        }
151
    }
152
    if (exists($noread{$k})) {
153
        print (" $k\n\n");
154
    }
155
    else {
156
        print (" $k\n\t\$(VCOM) $k\n\t\@touch $tf\n");
157
    }
158
}
159
 
160
foreach $k (sort keys %f) {
161
    $n = $k;
162
    $n =~ s/\.vhd$//gi;
163
    print ("$n: ".tagfile($f{$k})."\n");
164
}
165
 
166
print <<MAKEFILE_END;
167
tags :
168
\t\@mkdir tags
169
work :
170
\t\$(if \$(shell \@ls work), ,\$(VLIB) work)
171
 
172
MAKEFILE_END
173
 
174
 
175
sub tagfile() {
176
    my ($n) = @_;
177
    $n =~ s/\//_/gi;
178
    $n =~ s/\.vhd$//gi;
179
    $n = "tags/$n";
180
    return $n;
181
}
182
 
183
sub compname() {
184
    my ($n) = @_;
185
    my ($f,$p) = splitpath($n);
186
    $f =~ s/\.vhd$//gi;
187
    return $f;
188
}
189
 
190
sub splitpath() {
191
    my ($n) = @_;
192
    my @n = split("/",$n);
193
    if ($#n > -1) {
194
        my $f = splice(@n,$#n,1);
195
        my $p = join("/",@n);
196
        return ($f,$p);
197
    }
198
    return $n;
199
}
200
 
201
 
202
sub readin() {
203
    my ($n) = @_;
204
    my $l = "";
205
    if (open(RF, "$n")) {
206
        while (<RF>) {
207
            $l .= $_;
208
        }
209
        close(RF);
210
    }
211
    return $l;
212
}
213
 
214
 

powered by: WebSVN 2.1.0

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