Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | # ========== Copyright Header Begin ========================================== |
2 | # | |
3 | # OpenSPARC T2 Processor File: make_lib_depends3.pl | |
4 | # Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved | |
5 | # 4150 Network Circle, Santa Clara, California 95054, U.S.A. | |
6 | # | |
7 | # * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
8 | # | |
9 | # This program is free software; you can redistribute it and/or modify | |
10 | # it under the terms of the GNU General Public License as published by | |
11 | # the Free Software Foundation; version 2 of the License. | |
12 | # | |
13 | # This program is distributed in the hope that it will be useful, | |
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | # GNU General Public License for more details. | |
17 | # | |
18 | # You should have received a copy of the GNU General Public License | |
19 | # along with this program; if not, write to the Free Software | |
20 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 | # | |
22 | # For the avoidance of doubt, and except that if any non-GPL license | |
23 | # choice is available it will apply instead, Sun elects to use only | |
24 | # the General Public License version 2 (GPLv2) at this time for any | |
25 | # software where a choice of GPL license versions is made | |
26 | # available with the language indicating that GPLv2 or any later version | |
27 | # may be used, or where a choice of which version of the GPL is applied is | |
28 | # otherwise unspecified. | |
29 | # | |
30 | # Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
31 | # CA 95054 USA or visit www.sun.com if you need additional information or | |
32 | # have any questions. | |
33 | # | |
34 | # ========== Copyright Header End ============================================ | |
35 | ||
36 | ||
37 | use File::Basename; | |
38 | use FileHandle; | |
39 | use Getopt::Long; | |
40 | ||
41 | sub usage () { | |
42 | print STDERR <<USAGE; | |
43 | ||
44 | Usage: $0 -libn libname -current_dir cwd -o output_file -VERA_LIBDIR object_dir | |
45 | ||
46 | USAGE | |
47 | exit(1); | |
48 | } | |
49 | ||
50 | #---------------------------------------------------------------- | |
51 | # Protos, globals | |
52 | @libnames = (); # list of seed libraries. find all the libs these depend on. | |
53 | @libpaths = (); # Array returned from GetVlibs script setting list of paths to search for the libraries (in order) | |
54 | %paths = (); # directory part of actual path to library, per library, hashed by libname | |
55 | %deps = (); # libvrl dependencies per library hashed by libname | |
56 | %srcs = (); # source and obj dependencies per library, hashed by libname | |
57 | %cvera = (); # combine_vera flag per library, hashed by libname | |
58 | $depth = 0; # for debug of traverse code | |
59 | ||
60 | #---------------------------------------------------------------- | |
61 | usage if (! GetOptions("help", | |
62 | "o=s", | |
63 | "libn=s@", \@libnames, | |
64 | "current_dir=s", \$current_directory, | |
65 | "VERA_LIBDIR=s", \$VERA_LIBDIR, | |
66 | "debug", \$debug, | |
67 | "no_peu", \$NO_PEU, | |
68 | ) | |
69 | ); | |
70 | usage if (defined $opt_help); | |
71 | usage if (not defined $opt_o); | |
72 | usage if (not defined $current_directory); | |
73 | usage if (not defined $VERA_LIBDIR); | |
74 | ||
75 | #---------------------------------------------------------------- | |
76 | ||
77 | if (defined $debug) { | |
78 | print "libnames is: @libnames\n" ; | |
79 | print "remainder is: @ARGV\n" ; | |
80 | } | |
81 | ||
82 | #---------------------------------------------------------------- | |
83 | ||
84 | # added this... | |
85 | ||
86 | main(); | |
87 | ||
88 | ||
89 | sub get_vlib_paths { | |
90 | my($cwd) = @_; | |
91 | my(@result); | |
92 | my $dv_root = $ENV{DV_ROOT}; | |
93 | ||
94 | # Our search path is currently two locations: | |
95 | # The testbench directory itself, and | |
96 | # "$DV_ROOT/verif/env/fnx/vlib", in that order. | |
97 | push(@result, $cwd); | |
98 | push(@result, "$dv_root/verif/env/fnx/vlib"); | |
99 | ||
100 | return @result; | |
101 | } | |
102 | ||
103 | ||
104 | # Start here | |
105 | sub main { | |
106 | my %seen = (); | |
107 | my %udeps = (); # unique dependency list | |
108 | my $out_fh = new FileHandle; | |
109 | ||
110 | # If there are no libnames provided, we are likely in a non-vlib, | |
111 | # non-testbench place. Don't bother to check. Make an output file | |
112 | # though since gmake will try to include it. | |
113 | if (scalar(@libnames) != 0) { | |
114 | # Call subroutine to get list of vlib paths to | |
115 | # search for library includes. | |
116 | @libpaths = get_vlib_paths($current_directory); | |
117 | print "libpaths are: @libpaths\n" if (defined $debug); | |
118 | } | |
119 | ||
120 | # Open the output file only if everything is cool so far. | |
121 | $out_fh->open("> $opt_o") or die basename($0), ": Cannot open $opt_o: $!\n"; | |
122 | ||
123 | # Parse all the lib config files | |
124 | foreach $libname (@libnames) { | |
125 | traverse($libname); | |
126 | } | |
127 | ||
128 | # Uniquify the libvrl dependency list | |
129 | foreach $libname (keys %paths) { | |
130 | %seen = (); | |
131 | @{$udeps{$libname}} = grep { ! $seen{$_} ++ } @{$deps{$libname}} | |
132 | } | |
133 | ||
134 | # tell xemacs to colorize | |
135 | print $out_fh "# -*-Makefile-*-\n"; | |
136 | ||
137 | # Make a macro to define the actual complete list of .libvrls | |
138 | print $out_fh "actual_lib_list = \\\n"; | |
139 | foreach $libname (keys %paths) { | |
140 | print $out_fh "\t$libname \\\n"; | |
141 | } | |
142 | print $out_fh "\n#" . "-"x40 . "\n"; # print a separator | |
143 | ||
144 | ||
145 | # Make a macro to define the actual complete list of lib dirs | |
146 | print $out_fh "actual_libdir_list = \\\n"; | |
147 | foreach $libname (keys %paths) { | |
148 | print $out_fh "\t$paths{$libname} \\\n"; | |
149 | } | |
150 | print $out_fh "\n#" . "-"x40 . "\n"; # print a separator | |
151 | ||
152 | $out_fh->close(); | |
153 | # Done. | |
154 | } | |
155 | ||
156 | # Walk the dependency tree for the libs on the command line. Gather | |
157 | # dependencies for all the dependent libs on the way. Return a list of | |
158 | # library names on which $libname depends. | |
159 | sub traverse { | |
160 | my $libname = shift; | |
161 | # commenting these out because they are PEU dependent | |
162 | next if ($libname eq "DenaliPCIE") && (defined $NO_PEU); | |
163 | next if ($libname eq "FNXPCIEXactor") && (defined $NO_PEU); | |
164 | #if FC_NO_PEU_T2 == 1 | |
165 | # next if $libname eq "DenaliPCIE"; | |
166 | # next if $libname eq "FNXPCIEXactor"; | |
167 | #endif | |
168 | my @tdeps = (); | |
169 | $depth++; | |
170 | #print "traverse($depth): " . " "x$depth . "traversing $libname\n"; | |
171 | ||
172 | # Find the path to the lib | |
173 | foreach $libpath (@libpaths) { | |
174 | last if ($paths{$libname}); # skip if we've been here already | |
175 | $configpath = "$libpath/$libname/GNUmakefile" ; | |
176 | next unless ( -e $configpath); | |
177 | # get the seed dependencies | |
178 | open(LIB_FILE, "$configpath") or die "Can't open lib config file $configpath : $!\n"; | |
179 | @{$deps{$libname}} = get_libvrl_deps(\*LIB_FILE, $libname, "lib_list"); | |
180 | @{$srcs{$libname}} = get_libsrc_deps(\*LIB_FILE, $libname, "lib_" . $libname . "_vera_src"); | |
181 | get_combine_vera( \*LIB_FILE, $libname ); | |
182 | #print "traverse($depth): " . " "x$depth . "$libname seed: @{$deps{$libname}}\n" ; | |
183 | close(LIB_FILE); | |
184 | # get the dependencies for the dependencies ... | |
185 | foreach $rlibname (@{$deps{$libname}}) { | |
186 | push @tdeps, traverse($rlibname); | |
187 | } | |
188 | push @{$deps{$libname}}, @tdeps; | |
189 | ||
190 | #print "traverse($depth): " . " "x$depth . "$libname depends on: @{$deps{$libname}}\n"; | |
191 | ||
192 | # remember the path to the lib. this also serves as a flag to | |
193 | # indicate the lib has been traversed already. | |
194 | $paths{$libname} = "$libpath/$libname" ; | |
195 | ||
196 | # stop looking after first lib with the right name | |
197 | last ; | |
198 | } | |
199 | $depth--; | |
200 | @{$deps{$libname}} ; | |
201 | } | |
202 | ||
203 | ||
204 | sub get_libvrl_deps { | |
205 | my $lib_file = shift; | |
206 | my $libname = shift; | |
207 | my $matcher = shift; | |
208 | get_lib_list($lib_file, $libname, $matcher); | |
209 | } | |
210 | ||
211 | sub get_libsrc_deps { | |
212 | my $lib_file = shift; | |
213 | my $libname = shift; | |
214 | my $matcher = shift; | |
215 | get_lib_list($lib_file, $libname, $matcher, fix_addprefix); | |
216 | ||
217 | } | |
218 | ||
219 | ||
220 | # Fixup $(addprefix foo, bar) in makefile. This does *not* support use of | |
221 | # make macros in the arguments to addprefix. | |
222 | sub fix_addprefix { | |
223 | my $line = shift; | |
224 | my $prefix = ""; | |
225 | ||
226 | # If the line is written with addprefix, do the addprefix. | |
227 | if ($$line =~ /\$\(\s*addprefix/) { | |
228 | ||
229 | # Delete the addprefix function name, retrieve the prefix string | |
230 | # this does *not* support variable names for the prefix. | |
231 | $$line =~ s!\$\(\s*addprefix\s+(\w+/?)\s*,\s*!! ; | |
232 | $prefix = $1; | |
233 | ||
234 | # Delete the trailing close paren | |
235 | $$line =~ s/\)// ; | |
236 | ||
237 | # print "Line is: \`$$line\`\n"; | |
238 | ||
239 | # Do the addprefix using map and make it back into a single string | |
240 | $$line = join (" ", map "$prefix$_", split (/\s+/, $$line)); | |
241 | } | |
242 | } | |
243 | ||
244 | ||
245 | # Look for the string in $matcher. Return the list of things the matched | |
246 | # pattern was set equal to. Call $fixer with the RHS string if $fixer is | |
247 | # defined. | |
248 | sub get_lib_list { | |
249 | my $lib_file = shift; | |
250 | my $libname = shift; | |
251 | my $matcher = shift; | |
252 | my $fixer = shift; | |
253 | my @list = (); | |
254 | ||
255 | seek $lib_file, 0, 0; | |
256 | while ($line=<$lib_file>) { | |
257 | chomp($line); | |
258 | if ($line =~ s/\\$//) { | |
259 | $line .= <$lib_file>; | |
260 | redo; | |
261 | } | |
262 | next if $line =~ /^\s*$/ ; | |
263 | next if $line =~ /^\s*#/ ; | |
264 | ||
265 | # find the lib list | |
266 | if ($line =~ /^\s*$matcher\s*=\s*(.*$)/ ) { | |
267 | $foo = $1; | |
268 | if (defined $fixer) { | |
269 | &$fixer(\$foo); | |
270 | } | |
271 | @list = split (/\s+/, $foo) ; | |
272 | last; | |
273 | } | |
274 | } | |
275 | #print "get_lib_list: liblist is: @list\n" ; | |
276 | ||
277 | @list ; | |
278 | } | |
279 | ||
280 | sub get_combine_vera { | |
281 | my $lib_file = shift; | |
282 | my $libname = shift; | |
283 | my $matcher; | |
284 | ||
285 | $matcher = "lib_" . "$libname" . "_combine_vera"; | |
286 | $cvera{$libname} = 0; | |
287 | ||
288 | seek $lib_file, 0, 0; | |
289 | while ($line=<$lib_file>) { | |
290 | chomp($line); | |
291 | if ($line =~ s/\\$//) { | |
292 | $line .= <$lib_file>; | |
293 | redo; | |
294 | } | |
295 | next if $line =~ /^\s*$/ ; | |
296 | next if $line =~ /^\s*#/ ; | |
297 | ||
298 | # find the lib_$(lib_name)_combine_vera | |
299 | if ($line =~ /^\s*$matcher\s*=\s*1.*$/ ) { | |
300 | $cvera{$libname} = 1; | |
301 | } | |
302 | } | |
303 | } |