File: | /tmp/build/aclocal |
Coverage: | 94.7% |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | #!/usr/bin/perl -w | ||||||
2 | # -*- perl -*- | ||||||
3 | # Generated from aclocal.in; do not edit by hand. | ||||||
4 | |||||||
5 | 1041 | 2575 | eval 'case $# in 0) exec /usr/bin/perl -S "$0";; *) exec /usr/bin/perl -S "$0" "$@";; esac' | ||||
6 | if 0; | ||||||
7 | |||||||
8 | # aclocal - create aclocal.m4 by scanning configure.ac | ||||||
9 | |||||||
10 | # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, | ||||||
11 | # 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. | ||||||
12 | |||||||
13 | # This program is free software; you can redistribute it and/or modify | ||||||
14 | # it under the terms of the GNU General Public License as published by | ||||||
15 | # the Free Software Foundation; either version 2, or (at your option) | ||||||
16 | # any later version. | ||||||
17 | |||||||
18 | # This program is distributed in the hope that it will be useful, | ||||||
19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||
21 | # GNU General Public License for more details. | ||||||
22 | |||||||
23 | # You should have received a copy of the GNU General Public License | ||||||
24 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||||
25 | |||||||
26 | # Written by Tom Tromey <tromey@redhat.com>, and | ||||||
27 | # Alexandre Duret-Lutz <adl@gnu.org>. | ||||||
28 | |||||||
29 | BEGIN | ||||||
30 | { | ||||||
31 | 1041 | 11492 | my $perllibdir = $ENV{'perllibdir'} || '/usr/local/share/automake-1.11a'; | ||||
32 | 1041 | 5009 | unshift @INC, (split ':', $perllibdir); | ||||
33 | } | ||||||
34 | |||||||
35 | 1041 1041 1041 | 9013 984 3437 | use strict; | ||||
36 | |||||||
37 | 1041 1041 1041 | 10571 1167 7389 | use Automake::Config; | ||||
38 | 1041 1041 1041 | 7415 1169 5977 | use Automake::General; | ||||
39 | 1041 1041 1041 | 7327 1442 6409 | use Automake::Configure_ac; | ||||
40 | 1041 1041 1041 | 4002 1041 2636 | use Automake::Channels; | ||||
41 | 1041 1041 1041 | 3878 1127 2422 | use Automake::ChannelDefs; | ||||
42 | 1041 1041 1041 | 8434 1672 8236 | use Automake::XFile; | ||||
43 | 1041 1041 1041 | 4367 1241 2901 | use Automake::FileUtils; | ||||
44 | 1041 1041 1041 | 4548 1206 7255 | use File::Basename; | ||||
45 | 1041 1041 1041 | 4253 1133 5424 | use File::stat; | ||||
46 | 1041 1041 1041 | 4036 1101 5617 | use Cwd; | ||||
47 | |||||||
48 | # Some globals. | ||||||
49 | |||||||
50 | # We do not operate in threaded mode. | ||||||
51 | 1041 | 2241 | $perl_threads = 0; | ||||
52 | |||||||
53 | # Include paths for searching macros. We search macros in this order: | ||||||
54 | # user-supplied directories first, then the directory containing the | ||||||
55 | # automake macros, and finally the system-wide directories for | ||||||
56 | # third-party macro. @user_includes can be augmented with -I. | ||||||
57 | # @system_includes can be augmented with the `dirlist' file. Also | ||||||
58 | # --acdir will reset both @automake_includes and @system_includes. | ||||||
59 | 1041 | 1995 | my @user_includes = (); | ||||
60 | 1041 | 3460 | my @automake_includes = ("/usr/local/share/aclocal-$APIVERSION"); | ||||
61 | 1041 | 2170 | my @system_includes = ('/usr/local/share/aclocal'); | ||||
62 | |||||||
63 | # Whether we should copy M4 file in $user_includes[0]. | ||||||
64 | 1041 | 1522 | my $install = 0; | ||||
65 | |||||||
66 | # --diff | ||||||
67 | 1041 | 1173 | my @diff_command; | ||||
68 | |||||||
69 | # --dry-run | ||||||
70 | 1041 | 1518 | my $dry_run = 0; | ||||
71 | |||||||
72 | # configure.ac or configure.in. | ||||||
73 | 1041 | 1252 | my $configure_ac; | ||||
74 | |||||||
75 | # Output file name. | ||||||
76 | 1041 | 1651 | my $output_file = 'aclocal.m4'; | ||||
77 | |||||||
78 | # Option --force. | ||||||
79 | 1041 | 1551 | my $force_output = 0; | ||||
80 | |||||||
81 | # Modification time of the youngest dependency. | ||||||
82 | 1041 | 1554 | my $greatest_mtime = 0; | ||||
83 | |||||||
84 | # Which macros have been seen. | ||||||
85 | 1041 | 1856 | my %macro_seen = (); | ||||
86 | |||||||
87 | # Remember the order into which we scanned the files. | ||||||
88 | # It's important to output the contents of aclocal.m4 in the opposite order. | ||||||
89 | # (Definitions in first files we have scanned should override those from | ||||||
90 | # later files. So they must appear last in the output.) | ||||||
91 | 1041 | 1564 | my @file_order = (); | ||||
92 | |||||||
93 | # Map macro names to file names. | ||||||
94 | 1041 | 1541 | my %map = (); | ||||
95 | |||||||
96 | # Ditto, but records the last definition of each macro as returned by --trace. | ||||||
97 | 1041 | 1541 | my %map_traced_defs = (); | ||||
98 | |||||||
99 | # Map basenames to macro names. | ||||||
100 | 1041 | 1489 | my %invmap = (); | ||||
101 | |||||||
102 | # Map file names to file contents. | ||||||
103 | 1041 | 1560 | my %file_contents = (); | ||||
104 | |||||||
105 | # Map file names to file types. | ||||||
106 | 1041 | 1673 | my %file_type = (); | ||||
107 | 1041 1041 1041 | 4480 1255 5918 | use constant FT_USER => 1; | ||||
108 | 1041 1041 1041 | 4760 1155 2802 | use constant FT_AUTOMAKE => 2; | ||||
109 | 1041 1041 1041 | 4030 1163 3428 | use constant FT_SYSTEM => 3; | ||||
110 | |||||||
111 | # Map file names to included files (transitively closed). | ||||||
112 | 1041 | 1829 | my %file_includes = (); | ||||
113 | |||||||
114 | # Files which have already been added. | ||||||
115 | 1041 | 1775 | my %file_added = (); | ||||
116 | |||||||
117 | # Files that have already been scanned. | ||||||
118 | 1041 | 1775 | my %scanned_configure_dep = (); | ||||
119 | |||||||
120 | # Serial numbers, for files that have one. | ||||||
121 | # The key is the basename of the file, | ||||||
122 | # the value is the serial number represented as a list. | ||||||
123 | 1041 | 1571 | my %serial = (); | ||||
124 | |||||||
125 | # Matches a macro definition. | ||||||
126 | # AC_DEFUN([macroname], ...) | ||||||
127 | # or | ||||||
128 | # AC_DEFUN(macroname, ...) | ||||||
129 | # When macroname is `['-quoted , we accept any character in the name, | ||||||
130 | # except `]'. Otherwise macroname stops on the first `]', `,', `)', | ||||||
131 | # or `\n' encountered. | ||||||
132 | 1041 | 1723 | my $ac_defun_rx = | ||||
133 | "(?:AU_ALIAS|A[CU]_DEFUN|AC_DEFUN_ONCE)\\((?:\\[([^]]+)\\]|([^],)\n]+))"; | ||||||
134 | |||||||
135 | # Matches an AC_REQUIRE line. | ||||||
136 | 1041 | 1701 | my $ac_require_rx = "AC_REQUIRE\\((?:\\[([^]]+)\\]|([^],)\n]+))\\)"; | ||||
137 | |||||||
138 | # Matches an m4_include line. | ||||||
139 | 1041 | 1701 | my $m4_include_rx = "(m4_|m4_s|s)include\\((?:\\[([^]]+)\\]|([^],)\n]+))\\)"; | ||||
140 | |||||||
141 | # Match a serial number. | ||||||
142 | 1041 | 1512 | my $serial_line_rx = '^#\s*serial\s+(\S*)'; | ||||
143 | 1041 | 1442 | my $serial_number_rx = '^\d+(?:\.\d+)*$'; | ||||
144 | |||||||
145 | # Autoconf version | ||||||
146 | # Set by trace_used_macros. | ||||||
147 | 1041 | 1107 | my $ac_version; | ||||
148 | |||||||
149 | # If set, names a temporary file that must be erased on abnormal exit. | ||||||
150 | 1041 | 1423 | my $erase_me; | ||||
151 | |||||||
152 | ################################################################ | ||||||
153 | |||||||
154 | # Erase temporary file ERASE_ME. Handle signals. | ||||||
155 | sub unlink_tmp | ||||||
156 | { | ||||||
157 | 1042 | 2733 | my ($sig) = @_; | ||||
158 | |||||||
159 | 1042 | 3143 | if ($sig) | ||||
160 | { | ||||||
161 | 0 | 0 | verb "caught SIG$sig, bailing out"; | ||||
162 | } | ||||||
163 | 1042 | 5151 | if (defined $erase_me && -e $erase_me && !unlink ($erase_me)) | ||||
164 | { | ||||||
165 | 0 | 0 | fatal "could not remove `$erase_me': $!"; | ||||
166 | } | ||||||
167 | 1042 | 1722 | undef $erase_me; | ||||
168 | |||||||
169 | # reraise default handler. | ||||||
170 | 1042 | 3278 | if ($sig) | ||||
171 | { | ||||||
172 | 0 | 0 | $SIG{$sig} = 'DEFAULT'; | ||||
173 | 0 | 0 | kill $sig => $$; | ||||
174 | } | ||||||
175 | } | ||||||
176 | |||||||
177 | 1041 | 28476 | $SIG{'INT'} = $SIG{'TERM'} = $SIG{'QUIT'} = $SIG{'HUP'} = 'unlink_tmp'; | ||||
178 | 1041 | 4468 | END { unlink_tmp } | ||||
179 | |||||||
180 | sub reset_maps () | ||||||
181 | { | ||||||
182 | 1031 | 2001 | $greatest_mtime = 0; | ||||
183 | 1031 | 2060 | %macro_seen = (); | ||||
184 | 1031 | 1815 | @file_order = (); | ||||
185 | 1031 | 1655 | %map = (); | ||||
186 | 1031 | 1534 | %map_traced_defs = (); | ||||
187 | 1031 | 1548 | %file_contents = (); | ||||
188 | 1031 | 1555 | %file_type = (); | ||||
189 | 1031 | 1614 | %file_includes = (); | ||||
190 | 1031 | 1481 | %file_added = (); | ||||
191 | 1031 | 1523 | %scanned_configure_dep = (); | ||||
192 | 1031 | 1889 | %invmap = (); | ||||
193 | 1031 | 4881 | %serial = (); | ||||
194 | 1031 | 12220 | undef &search; | ||||
195 | } | ||||||
196 | |||||||
197 | # install_file ($SRC, $DEST) | ||||||
198 | sub install_file ($$) | ||||||
199 | { | ||||||
200 | 26 | 70 | my ($src, $dest) = @_; | ||||
201 | 26 | 30 | my $diff_dest; | ||||
202 | |||||||
203 | 26 | 234 | if ($force_output | ||||
204 | || !exists $file_contents{$dest} | ||||||
205 | || $file_contents{$src} ne $file_contents{$dest}) | ||||||
206 | { | ||||||
207 | 26 | 220 | if (-e $dest) | ||||
208 | { | ||||||
209 | 0 | 0 | msg 'note', "overwriting `$dest' with `$src'"; | ||||
210 | 0 | 0 | $diff_dest = $dest; | ||||
211 | } | ||||||
212 | else | ||||||
213 | { | ||||||
214 | 26 | 111 | msg 'note', "installing `$dest' from `$src'"; | ||||
215 | } | ||||||
216 | |||||||
217 | 26 | 100 | if (@diff_command) | ||||
218 | { | ||||||
219 | 1 | 3 | if (! defined $diff_dest) | ||||
220 | { | ||||||
221 | # $dest does not exist. We create an empty one just to | ||||||
222 | # run diff, and we erase it afterward. Using the real | ||||||
223 | # the destination file (rather than a temporary file) is | ||||||
224 | # good when diff is run with options that display the | ||||||
225 | # file name. | ||||||
226 | # | ||||||
227 | # If creating $dest fails, fall back to /dev/null. At | ||||||
228 | # least one diff implementation (Tru64's) cannot deal | ||||||
229 | # with /dev/null. However working around this is not | ||||||
230 | # worth the trouble since nobody run aclocal on a | ||||||
231 | # read-only tree anyway. | ||||||
232 | 1 | 2 | $erase_me = $dest; | ||||
233 | 1 | 12 | my $f = new IO::File "> $dest"; | ||||
234 | 1 | 149 | if (! defined $f) | ||||
235 | { | ||||||
236 | 0 | 0 | undef $erase_me; | ||||
237 | 0 | 0 | $diff_dest = '/dev/null'; | ||||
238 | } | ||||||
239 | else | ||||||
240 | { | ||||||
241 | 1 | 1 | $diff_dest = $dest; | ||||
242 | 1 | 10 | $f->close; | ||||
243 | } | ||||||
244 | } | ||||||
245 | 1 | 17 | my @cmd = (@diff_command, $diff_dest, $src); | ||||
246 | 1 | 6 | $! = 0; | ||||
247 | 1 | 5 | verb "running: @cmd"; | ||||
248 | 1 | 2367 | my $res = system (@cmd); | ||||
249 | 1 | 35 | Automake::FileUtils::handle_exec_errors "@cmd", 1 | ||||
250 | if $res; | ||||||
251 | 1 | 5 | unlink_tmp; | ||||
252 | } | ||||||
253 | elsif (!$dry_run) | ||||||
254 | { | ||||||
255 | 25 | 117 | xsystem ('cp', $src, $dest); | ||||
256 | } | ||||||
257 | } | ||||||
258 | } | ||||||
259 | |||||||
260 | # Compare two lists of numbers. | ||||||
261 | sub list_compare (\@\@) | ||||||
262 | { | ||||||
263 | 66 66 | 69 134 | my @l = @{$_[0]}; | ||||
264 | 66 66 | 75 116 | my @r = @{$_[1]}; | ||||
265 | 66 | 70 | while (1) | ||||
266 | { | ||||||
267 | 140 | 523 | if (0 == @l) | ||||
268 | { | ||||||
269 | 56 | 274 | return (0 == @r) ? 0 : -1; | ||||
270 | } | ||||||
271 | elsif (0 == @r) | ||||||
272 | { | ||||||
273 | 0 | 0 | return 1; | ||||
274 | } | ||||||
275 | elsif ($l[0] < $r[0]) | ||||||
276 | { | ||||||
277 | 4 | 18 | return -1; | ||||
278 | } | ||||||
279 | elsif ($l[0] > $r[0]) | ||||||
280 | { | ||||||
281 | 6 | 31 | return 1; | ||||
282 | } | ||||||
283 | 74 | 86 | shift @l; | ||||
284 | 74 | 89 | shift @r; | ||||
285 | } | ||||||
286 | } | ||||||
287 | |||||||
288 | ################################################################ | ||||||
289 | |||||||
290 | # scan_m4_dirs($TYPE, @DIRS) | ||||||
291 | # -------------------------- | ||||||
292 | # Scan all M4 files installed in @DIRS for new macro definitions. | ||||||
293 | # Register each file as of type $TYPE (one of the FT_* constants). | ||||||
294 | sub scan_m4_dirs ($@) | ||||||
295 | { | ||||||
296 | 3090 | 7704 | my ($type, @dirlist) = @_; | ||||
297 | |||||||
298 | 3090 | 5854 | foreach my $m4dir (@dirlist) | ||||
299 | { | ||||||
300 | 2332 | 37994 | if (! opendir (DIR, $m4dir)) | ||||
301 | { | ||||||
302 | 0 | 0 | fatal "couldn't open directory `$m4dir': $!"; | ||||
303 | } | ||||||
304 | |||||||
305 | # We reverse the directory contents so that foo2.m4 gets | ||||||
306 | # used in preference to foo1.m4. | ||||||
307 | 2332 | 106611 | foreach my $file (reverse sort grep (! /^\./, readdir (DIR))) | ||||
308 | { | ||||||
309 | # Only examine .m4 files. | ||||||
310 | 50097 | 129953 | next unless $file =~ /\.m4$/; | ||||
311 | |||||||
312 | # Skip some files when running out of srcdir. | ||||||
313 | 44573 | 88467 | next if $file eq 'aclocal.m4'; | ||||
314 | |||||||
315 | 44572 | 208513 | my $fullfile = File::Spec->canonpath ("$m4dir/$file"); | ||||
316 | 44572 | 1259477 | &scan_file ($type, $fullfile, 'aclocal'); | ||||
317 | } | ||||||
318 | 2332 | 27726 | closedir (DIR); | ||||
319 | } | ||||||
320 | } | ||||||
321 | |||||||
322 | # Scan all the installed m4 files and construct a map. | ||||||
323 | sub scan_m4_files () | ||||||
324 | { | ||||||
325 | # First, scan configure.ac. It may contain macro definitions, | ||||||
326 | # or may include other files that define macros. | ||||||
327 | 1031 | 4725 | &scan_file (FT_USER, $configure_ac, 'aclocal'); | ||||
328 | |||||||
329 | # Then, scan acinclude.m4 if it exists. | ||||||
330 | 1031 | 8941 | if (-f 'acinclude.m4') | ||||
331 | { | ||||||
332 | 13 | 30 | &scan_file (FT_USER, 'acinclude.m4', 'aclocal'); | ||||
333 | } | ||||||
334 | |||||||
335 | # Finally, scan all files in our search paths. | ||||||
336 | 1030 | 3711 | scan_m4_dirs (FT_USER, @user_includes); | ||||
337 | 1030 | 3006 | scan_m4_dirs (FT_AUTOMAKE, @automake_includes); | ||||
338 | 1030 | 2473 | scan_m4_dirs (FT_SYSTEM, @system_includes); | ||||
339 | |||||||
340 | # Construct a new function that does the searching. We use a | ||||||
341 | # function (instead of just evaluating $search in the loop) so that | ||||||
342 | # "die" is correctly and easily propagated if run. | ||||||
343 | 1030 | 3054 | my $search = "sub search {\nmy \$found = 0;\n"; | ||||
344 | 1030 | 41752 | foreach my $key (reverse sort keys %map) | ||||
345 | { | ||||||
346 | 81522 | 193594 | $search .= ('if (/\b\Q' . $key . '\E(?!\w)/) { & add_macro ("' . $key | ||||
347 | . '"); $found = 1; }' . "\n"); | ||||||
348 | } | ||||||
349 | 1030 | 5108 | $search .= "return \$found;\n};\n"; | ||||
350 | 1030 885999 885999 11 11 885999 0 0 885999 2 2 885999 17 17 885999 10 10 885999 13 13 885999 12 12 885999 12 12 885999 10 10 885999 12 12 885999 23 23 885999 7696 7696 885999 1929 1929 885999 2879 2879 885999 3853 3853 885999 1918 1918 885999 2880 2880 885999 5758 5758 885999 6728 6728 885999 972 972 885999 101 101 885999 56 56 885999 36 36 885999 934 934 885999 1966 1966 885999 2802 2802 885999 1940 1940 885999 2028 2028 885999 118 118 885999 1866 1866 885999 3729 3729 885999 201 201 885999 80 80 885999 48 48 885999 1826 1826 885999 68 68 885999 1836 1836 885999 2791 2791 885999 113 113 885999 59 59 885999 133 133 885999 334 334 885999 241 241 885999 84 84 885999 87 87 885999 2088 2088 885999 6458 6458 885999 2194 2194 885999 363 363 885999 2107 2107 885999 538 538 885999 192 192 885999 2940 2940 885999 556 556 885999 499 499 885999 76 76 885999 73 73 885999 1849 1849 885999 159 159 885999 96 96 885999 90 90 885999 78 78 885999 3795 3795 885999 2917 2917 885999 2018 2018 885999 211 211 885999 155 155 885999 | 1853 987759 2190898 37 16 1983544 0 0 1945698 4 2 1931715 46 26 1917030 25 16 1918315 36 18 1916069 30 20 1904135 34 19 1907876 27 13 1898859 31 19 1923287 62 34 1924777 16393 10402 1918658 4656 2752 1935349 6480 3917 1922299 8599 5417 1919833 4786 2889 1918406 6564 3934 1906868 12554 8256 1927374 14386 9025 1915403 2647 1605 1909834 261 160 1900113 151 87 1907691 91 58 1902017 2857 1709 1899314 4919 2919 1905844 6661 4107 1904600 4856 2871 1916653 4864 3194 1908014 289 175 1909273 4530 3108 1914762 8526 5149 1907725 483 287 1899799 187 119 1900815 127 69 1902217 4405 2934 1899388 173 107 1905729 4441 2700 1898301 6366 4000 1903167 266 169 1888724 133 94 1902330 405 227 1909052 878 491 1897573 654 338 1891868 232 133 1890870 259 137 1914851 5294 3160 1902134 13993 8375 1908957 5200 3136 1903489 1009 529 1904037 5235 3182 1907285 1273 726 1895221 525 292 1903827 10100 4372 1917828 1614 764 1904286 1345 627 1903648 237 125 1894689 213 120 1899144 4658 2701 1899904 407 250 1894467 258 153 1900164 243 142 1893291 224 125 1897369 9428 5285 1912473 8070 4420 1906863 5660 2912 1895526 609 340 1896135 456 242 3433784 | eval $search; | ||||
351 | 1030 | 123023 | prog_error "$@\n search is $search" if $@; | ||||
352 | } | ||||||
353 | |||||||
354 | ################################################################ | ||||||
355 | |||||||
356 | # Add a macro to the output. | ||||||
357 | sub add_macro ($) | ||||||
358 | { | ||||||
359 | 131144 | 220098 | my ($macro) = @_; | ||||
360 | |||||||
361 | # Ignore unknown required macros. Either they are not really | ||||||
362 | # needed (e.g., a conditional AC_REQUIRE), in which case aclocal | ||||||
363 | # should be quiet, or they are needed and Autoconf itself will | ||||||
364 | # complain when we trace for macro usage later. | ||||||
365 | 131144 | 291849 | return unless defined $map{$macro}; | ||||
366 | |||||||
367 | 556054 | 1297397 | verb "saw macro $macro"; | ||||
368 | 124481 | 247570 | $macro_seen{$macro} = 1; | ||||
369 | 124481 | 243405 | &add_file ($map{$macro}); | ||||
370 | } | ||||||
371 | |||||||
372 | # scan_configure_dep ($file) | ||||||
373 | # -------------------------- | ||||||
374 | # Scan a configure dependency (configure.ac, or separate m4 files) | ||||||
375 | # for uses of known macros and AC_REQUIREs of possibly unknown macros. | ||||||
376 | # Recursively scan m4_included files. | ||||||
377 | sub scan_configure_dep ($) | ||||||
378 | { | ||||||
379 | 435535 | 959005 | my ($file) = @_; | ||||
380 | # Do not scan a file twice. | ||||||
381 | return () | ||||||
382 | 20261 | 43054 | if exists $scanned_configure_dep{$file}; | ||||
383 | 20245 | 35185 | $scanned_configure_dep{$file} = 1; | ||||
384 | |||||||
385 | 424855 | 934148 | my $mtime = mtime $file; | ||||
386 | 20241 | 40640 | $greatest_mtime = $mtime if $greatest_mtime < $mtime; | ||||
387 | |||||||
388 | 20241 | 121180 | my $contents = exists $file_contents{$file} ? | ||||
389 | $file_contents{$file} : contents $file; | ||||||
390 | |||||||
391 | 421293 | 882246 | my $line = 0; | ||||
392 | 20241 | 25766 | my @rlist = (); | ||||
393 | 20241 | 22156 | my @ilist = (); | ||||
394 | 419732 | 1234639 | foreach (split ("\n", $contents)) | ||||
395 | { | ||||||
396 | 1539280 | 1424950 | ++$line; | ||||
397 | # Remove comments from current line. | ||||||
398 | 1539280 | 1807725 | s/\bdnl\b.*$//; | ||||
399 | 1937736 | 2663037 | s/\#.*$//; | ||||
400 | # Avoid running all the following regexes on white lines. | ||||||
401 | 1539280 | 3333656 | next if /^\s*$/; | ||||
402 | |||||||
403 | 887069 | 2032272 | while (/$m4_include_rx/go) | ||||
404 | { | ||||||
405 | 398549 | 860396 | my $ifile = $2 || $3; | ||||
406 | # Skip missing `sinclude'd files. | ||||||
407 | 147 | 536 | next if $1 ne 'm4_' && ! -f $ifile; | ||||
408 | 145 | 293 | push @ilist, $ifile; | ||||
409 | } | ||||||
410 | |||||||
411 | 1285525 | 2764639 | while (/$ac_require_rx/go) | ||||
412 | { | ||||||
413 | 25147 | 135679 | push (@rlist, $1 || $2); | ||||
414 | } | ||||||
415 | |||||||
416 | # The search function is constructed dynamically by | ||||||
417 | # scan_m4_files. The last parenthetical match makes sure we | ||||||
418 | # don't match things that look like macro assignments or | ||||||
419 | # AC_SUBSTs. | ||||||
420 | 887487 | 1747997 | if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/) | ||||
421 | { | ||||||
422 | # Macro not found, but AM_ prefix found. | ||||||
423 | # Make this just a warning, because we do not know whether | ||||||
424 | # the macro is actually used (it could be called conditionally). | ||||||
425 | 398513 | 857113 | msg ('unsupported', "$file:$line", | ||||
426 | "macro `$2' not found in library"); | ||||||
427 | } | ||||||
428 | } | ||||||
429 | |||||||
430 | 20305 20305 | 102572 43915 | add_macro ($_) foreach (@rlist); | ||||
431 | 418697 20364 | 872710 57372 | &scan_configure_dep ($_) foreach @ilist; | ||||
432 | } | ||||||
433 | |||||||
434 | # add_file ($FILE) | ||||||
435 | # ---------------- | ||||||
436 | # Add $FILE to output. | ||||||
437 | sub add_file ($) | ||||||
438 | { | ||||||
439 | 124604 | 175761 | my ($file) = @_; | ||||
440 | |||||||
441 | # Only add a file once. | ||||||
442 | 522937 | 1223321 | return if ($file_added{$file}); | ||||
443 | 19372 | 37237 | $file_added{$file} = 1; | ||||
444 | |||||||
445 | 19372 | 42812 | scan_configure_dep $file; | ||||
446 | } | ||||||
447 | |||||||
448 | # Point to the documentation for underquoted AC_DEFUN only once. | ||||||
449 | 1041 | 2258 | my $underquoted_manual_once = 0; | ||||
450 | |||||||
451 | # scan_file ($TYPE, $FILE, $WHERE) | ||||||
452 | # -------------------------------- | ||||||
453 | # Scan a single M4 file ($FILE), and all files it includes. | ||||||
454 | # Return the list of included files. | ||||||
455 | # $TYPE is one of FT_USER, FT_AUTOMAKE, or FT_SYSTEM, depending | ||||||
456 | # on where the file comes from. | ||||||
457 | # $WHERE is the location to use in the diagnostic if the file | ||||||
458 | # does not exist. | ||||||
459 | sub scan_file ($$$) | ||||||
460 | { | ||||||
461 | 444166 | 944101 | my ($type, $file, $where) = @_; | ||||
462 | 45774 | 88943 | my $basename = basename $file; | ||||
463 | |||||||
464 | # Do not scan the same file twice. | ||||||
465 | 45774 400755 | 106226 869397 | return @{$file_includes{$file}} if exists $file_includes{$file}; | ||||
466 | # Prevent potential infinite recursion (if two files include each other). | ||||||
467 | 43588 | 86497 | return () if exists $file_contents{$file}; | ||||
468 | |||||||
469 | 43588 | 68237 | unshift @file_order, $file; | ||||
470 | |||||||
471 | 441921 | 950705 | $file_type{$file} = $type; | ||||
472 | |||||||
473 | 43765 | 387835 | fatal "$where: file `$file' does not exist" if ! -e $file; | ||||
474 | |||||||
475 | 43764 | 186042 | my $fh = new Automake::XFile $file; | ||||
476 | 441920 | 910414 | my $contents = ''; | ||||
477 | 43823 | 56779 | my @inc_files = (); | ||||
478 | 43823 | 54491 | my %inc_lines = (); | ||||
479 | |||||||
480 | 441920 | 900869 | my $defun_seen = 0; | ||||
481 | 43425 | 41763 | my $serial_seen = 0; | ||||
482 | 43425 | 43322 | my $serial_older = 0; | ||||
483 | |||||||
484 | 441920 | 966815 | while ($_ = $fh->getline) | ||||
485 | { | ||||||
486 | # Ignore `##' lines. | ||||||
487 | 3208866 | 5749789 | next if /^##/; | ||||
488 | |||||||
489 | 3161939 | 3562267 | $contents .= $_; | ||||
490 | 3560395 | 4160023 | my $line = $_; | ||||
491 | |||||||
492 | 3161944 | 6287375 | if ($line =~ /$serial_line_rx/go) | ||||
493 | { | ||||||
494 | 30927 | 60709 | my $number = $1; | ||||
495 | 429378 | 1066124 | if ($number !~ /$serial_number_rx/go) | ||||
496 | { | ||||||
497 | 57 | 181 | msg ('syntax', "$file:$.", | ||||
498 | "ill-formed serial number `$number', " | ||||||
499 | . "expecting a version string with only digits and dots"); | ||||||
500 | } | ||||||
501 | elsif ($defun_seen) | ||||||
502 | { | ||||||
503 | # aclocal removes all definitions from M4 file with the | ||||||
504 | # same basename if a greater serial number is found. | ||||||
505 | # Encountering a serial after some macros will undefine | ||||||
506 | # these macros... | ||||||
507 | 55 | 95 | msg ('syntax', "$file:$.", | ||||
508 | 'the serial number must appear before any macro definition'); | ||||||
509 | } | ||||||
510 | # We really care about serials only for non-automake macros | ||||||
511 | # and when --install is used. But the above diagnostics are | ||||||
512 | # made regardless of this, because not using --install is | ||||||
513 | # not a reason not the fix macro files. | ||||||
514 | elsif ($install && $type != FT_AUTOMAKE) | ||||||
515 | { | ||||||
516 | 398884 | 869596 | $serial_seen = 1; | ||||
517 | 590 | 1640 | my @new = split (/\./, $number); | ||||
518 | |||||||
519 | 590 | 2274 | verb "$file:$.: serial $number"; | ||||
520 | |||||||
521 | 398884 228 | 866662 594 | if (!exists $serial{$basename} | ||||
522 | || list_compare (@new, @{$serial{$basename}}) > 0) | ||||||
523 | { | ||||||
524 | # Delete any definition we knew from the old macro. | ||||||
525 | 476 398824 | 545 851142 | foreach my $def (@{$invmap{$basename}}) | ||||
526 | { | ||||||
527 | 170 | 485 | verb "$file:$.: ignoring previous definition of $def"; | ||||
528 | 170 | 254 | delete $map{$def}; | ||||
529 | } | ||||||
530 | 398824 | 853733 | $invmap{$basename} = []; | ||||
531 | 476 | 1224 | $serial{$basename} = \@new; | ||||
532 | } | ||||||
533 | else | ||||||
534 | { | ||||||
535 | 222 | 346 | $serial_older = 1; | ||||
536 | } | ||||||
537 | } | ||||||
538 | } | ||||||
539 | |||||||
540 | # Remove comments from current line. | ||||||
541 | # Do not do it earlier, because the serial line is a comment. | ||||||
542 | 3560395 | 4839411 | $line =~ s/\bdnl\b.*$//; | ||||
543 | 3162047 | 4348485 | $line =~ s/\#.*$//; | ||||
544 | |||||||
545 | 3162047 | 8902178 | while ($line =~ /$ac_defun_rx/go) | ||||
546 | { | ||||||
547 | 488714 | 976800 | $defun_seen = 1; | ||||
548 | 90366 | 215936 | if (! defined $1) | ||||
549 | { | ||||||
550 | 163 | 254 | msg ('syntax', "$file:$.", "underquoted definition of $2" | ||||
551 | . "\n run info Automake 'Extending aclocal'\n" | ||||||
552 | . " or see http://sources.redhat.com/automake/" | ||||||
553 | . "automake.html#Extending-aclocal") | ||||||
554 | unless $underquoted_manual_once; | ||||||
555 | 398511 | 863462 | $underquoted_manual_once = 1; | ||||
556 | } | ||||||
557 | |||||||
558 | # If this macro does not have a serial and we have already | ||||||
559 | # seen a macro with the same basename earlier, we should | ||||||
560 | # ignore the macro (don't exit immediately so we can still | ||||||
561 | # diagnose later #serial numbers and underquoted macros). | ||||||
562 | 90366 | 708681 | $serial_older ||= ($type != FT_AUTOMAKE | ||||
563 | && !$serial_seen && exists $serial{$basename}); | ||||||
564 | |||||||
565 | 90366 | 235661 | my $macro = $1 || $2; | ||||
566 | 488714 | 1290099 | if (!$serial_older && !defined $map{$macro}) | ||||
567 | { | ||||||
568 | 81800 | 395162 | verb "found macro $macro in $file: $."; | ||||
569 | 81800 | 245390 | $map{$macro} = $file; | ||||
570 | 480040 81854 | 933005 385032 | push @{$invmap{$basename}}, $macro; | ||||
571 | } | ||||||
572 | else | ||||||
573 | { | ||||||
574 | # Note: we used to give an error here if we saw a | ||||||
575 | # duplicated macro. However, this turns out to be | ||||||
576 | # extremely unpopular. It causes actual problems which | ||||||
577 | # are hard to work around, especially when you must | ||||||
578 | # mix-and-match tool versions. | ||||||
579 | 8998 | 40423 | verb "ignoring macro $macro in $file: $."; | ||||
580 | } | ||||||
581 | } | ||||||
582 | |||||||
583 | 3560395 | 12889065 | while ($line =~ /$m4_include_rx/go) | ||||
584 | { | ||||||
585 | 366 | 1133 | my $ifile = $2 || $3; | ||||
586 | # Skip missing `sinclude'd files. | ||||||
587 | 366 | 713 | next if $1 ne 'm4_' && ! -f $ifile; | ||||
588 | 398550 | 857270 | push (@inc_files, $ifile); | ||||
589 | 418 | 1299 | $inc_lines{$ifile} = $.; | ||||
590 | } | ||||||
591 | } | ||||||
592 | |||||||
593 | # Ignore any file that has an old serial (or no serial if we know | ||||||
594 | # another one with a serial). | ||||||
595 | return () | ||||||
596 | 43788 | 407784 | if ($serial_older || | ||||
597 | ($type != FT_AUTOMAKE && !$serial_seen && exists $serial{$basename})); | ||||||
598 | |||||||
599 | 441860 | 1045419 | $file_contents{$file} = $contents; | ||||
600 | |||||||
601 | # For some reason I don't understand, it does not work | ||||||
602 | # to do `map { scan_file ($_, ...) } @inc_files' below. | ||||||
603 | # With Perl 5.8.2 it undefines @inc_files. | ||||||
604 | 43567 | 66099 | my @copy = @inc_files; | ||||
605 | 398550 | 860862 | my @all_inc_files = (@inc_files, | ||||
606 | 43567 | 64922 | map { scan_file ($type, $_, | ||||
607 | "$file:$inc_lines{$_}") } @copy); | ||||||
608 | 43456 | 86441 | $file_includes{$file} = \@all_inc_files; | ||||
609 | 43456 | 334300 | return @all_inc_files; | ||||
610 | } | ||||||
611 | |||||||
612 | # strip_redundant_includes (%FILES) | ||||||
613 | # --------------------------------- | ||||||
614 | # Each key in %FILES is a file that must be present in the output. | ||||||
615 | # However some of these files might already include other files in %FILES, | ||||||
616 | # so there is no point in including them another time. | ||||||
617 | # This removes items of %FILES which are already included by another file. | ||||||
618 | sub strip_redundant_includes (%) | ||||||
619 | { | ||||||
620 | 400546 | 874424 | my %files = @_; | ||||
621 | |||||||
622 | # Always include acinclude.m4, even if it does not appear to be used. | ||||||
623 | 2198 | 21176 | $files{'acinclude.m4'} = 1 if -f 'acinclude.m4'; | ||||
624 | # File included by $configure_ac are redundant. | ||||||
625 | 2198 | 6968 | $files{$configure_ac} = 1; | ||||
626 | |||||||
627 | # Files at the end of @file_order should override those at the beginning, | ||||||
628 | # so it is important to preserve these trailing files. We can remove | ||||||
629 | # a file A if it is going to be output before a file B that includes | ||||||
630 | # file A, not the converse. | ||||||
631 | 400546 | 866492 | foreach my $file (reverse @file_order) | ||||
632 | { | ||||||
633 | 86911 | 208605 | next unless exists $files{$file}; | ||||
634 | 36780 434156 | 33280 959286 | foreach my $ifile (@{$file_includes{$file}}) | ||||
635 | { | ||||||
636 | 1962 | 4537 | next unless exists $files{$ifile}; | ||||
637 | 1909 | 2395 | delete $files{$ifile}; | ||||
638 | 398529 | 862771 | verb "$ifile is already included by $file"; | ||||
639 | } | ||||||
640 | } | ||||||
641 | |||||||
642 | # configure.ac is implicitly included. | ||||||
643 | 2198 | 4928 | delete $files{$configure_ac}; | ||||
644 | |||||||
645 | 2198 | 23337 | return %files; | ||||
646 | } | ||||||
647 | |||||||
648 | sub trace_used_macros () | ||||||
649 | { | ||||||
650 | 399533 36474 | 887357 85340 | my %files = map { $map{$_} => 1 } keys %macro_seen; | ||||
651 | 1131 | 9320 | %files = strip_redundant_includes %files; | ||||
652 | |||||||
653 | 399533 | 877967 | my $traces = ($ENV{AUTOM4TE} || 'autom4te'); | ||||
654 | 1185 | 2516 | $traces .= " --language Autoconf-without-aclocal-m4 "; | ||||
655 | # All candidate files. | ||||||
656 | 417497 | 890066 | $traces .= join (' ', | ||||
657 | 43193 | 82092 | (map { "'$_'" } | ||||
658 | 1185 | 2968 | (grep { exists $files{$_} } @file_order))) . " "; | ||||
659 | # All candidate macros. | ||||||
660 | 402602 | 872857 | $traces .= join (' ', | ||||
661 | 36420 | 66266 | (map { "--trace='$_:\$f::\$n::\$1'" } | ||||
662 | ('AC_DEFUN', | ||||||
663 | 'AC_DEFUN_ONCE', | ||||||
664 | 'AU_DEFUN', | ||||||
665 | '_AM_AUTOCONF_VERSION')), | ||||||
666 | # Do not trace $1 for all other macros as we do | ||||||
667 | # not need it and it might contains harmful | ||||||
668 | # characters (like newlines). | ||||||
669 | 1131 | 6140 | (map { "--trace='$_:\$f::\$n'" } (keys %macro_seen))); | ||||
670 | |||||||
671 | 1077 | 11273 | verb "running $traces $configure_ac"; | ||||
672 | |||||||
673 | 399533 | 870874 | my $tracefh = new Automake::XFile ("$traces $configure_ac |"); | ||||
674 | |||||||
675 | 1077 | 12357 | my %traced = (); | ||||
676 | |||||||
677 | 1077 | 16078 | while ($_ = $tracefh->getline) | ||||
678 | { | ||||||
679 | 477088 | 949679 | chomp; | ||||
680 | 78632 | 223624 | my ($file, $macro, $arg1) = split (/::/); | ||||
681 | |||||||
682 | 78632 | 195241 | $traced{$macro} = 1 if exists $macro_seen{$macro}; | ||||
683 | |||||||
684 | 477088 | 1393946 | $map_traced_defs{$arg1} = $file | ||||
685 | if ($macro eq 'AC_DEFUN' | ||||||
686 | || $macro eq 'AC_DEFUN_ONCE' | ||||||
687 | || $macro eq 'AU_DEFUN'); | ||||||
688 | |||||||
689 | 78686 | 284036 | $ac_version = $arg1 if $macro eq '_AM_AUTOCONF_VERSION'; | ||||
690 | } | ||||||
691 | |||||||
692 | 1131 | 15234 | $tracefh->close; | ||||
693 | |||||||
694 | 399523 | 972661 | return %traced; | ||||
695 | } | ||||||
696 | |||||||
697 | sub scan_configure () | ||||||
698 | { | ||||||
699 | # Make sure we include acinclude.m4 if it exists. | ||||||
700 | 1138 | 7736 | if (-f 'acinclude.m4') | ||||
701 | { | ||||||
702 | 120 | 222 | add_file ('acinclude.m4'); | ||||
703 | } | ||||||
704 | 399540 | 865396 | scan_configure_dep ($configure_ac); | ||||
705 | } | ||||||
706 | |||||||
707 | ################################################################ | ||||||
708 | |||||||
709 | # Write output. | ||||||
710 | # Return 0 iff some files were installed locally. | ||||||
711 | sub write_aclocal ($@) | ||||||
712 | { | ||||||
713 | 1121 | 7698 | my ($output_file, @macros) = @_; | ||||
714 | 1121 | 2370 | my $output = ''; | ||||
715 | |||||||
716 | 399523 | 860722 | my %files = (); | ||||
717 | # Get the list of files containing definitions for the macros used. | ||||||
718 | # (Filter out unused macro definitions with $map_traced_defs. This | ||||||
719 | # can happen when an Autoconf macro is conditionally defined: | ||||||
720 | # aclocal sees the potential definition, but this definition is | ||||||
721 | # actually never processed and the Autoconf implementation is used | ||||||
722 | # instead.) | ||||||
723 | 1121 | 4886 | for my $m (@macros) | ||||
724 | { | ||||||
725 | 21142 | 154433 | $files{$map{$m}} = 1 | ||||
726 | if (exists $map_traced_defs{$m} | ||||||
727 | && $map{$m} eq $map_traced_defs{$m}); | ||||||
728 | } | ||||||
729 | # Do not explicitly include a file that is already indirectly included. | ||||||
730 | 399523 | 866025 | %files = strip_redundant_includes %files; | ||||
731 | |||||||
732 | 1067 | 4588 | my $installed = 0; | ||||
733 | |||||||
734 | 1067 441202 | 2724 929362 | for my $file (grep { exists $files{$_} } @file_order) | ||||
735 | { | ||||||
736 | # Check the time stamp of this file, and of all files it includes. | ||||||
737 | 15379 15379 | 18490 35802 | for my $ifile ($file, @{$file_includes{$file}}) | ||||
738 | { | ||||||
739 | 413148 | 899894 | my $mtime = mtime $ifile; | ||||
740 | 14692 | 43877 | $greatest_mtime = $mtime if $greatest_mtime < $mtime; | ||||
741 | } | ||||||
742 | |||||||
743 | # If the file to add looks like outside the project, copy it | ||||||
744 | # to the output. The regex catches filenames starting with | ||||||
745 | # things like `/', `\', or `c:\'. | ||||||
746 | 14677 | 58527 | if ($file_type{$file} != FT_USER | ||||
747 | || $file =~ m,^(?:\w:)?[\\/],) | ||||||
748 | { | ||||||
749 | 412981 | 897691 | if (!$install || $file_type{$file} != FT_SYSTEM) | ||||
750 | { | ||||||
751 | # Copy the file into aclocal.m4. | ||||||
752 | 14445 | 119227 | $output .= $file_contents{$file} . "\n"; | ||||
753 | } | ||||||
754 | else | ||||||
755 | { | ||||||
756 | # Install the file (and any file it includes). | ||||||
757 | 26 | 30 | my $dest; | ||||
758 | 398536 26 | 862300 78 | for my $ifile (@{$file_includes{$file}}, $file) | ||||
759 | { | ||||||
760 | 26 | 249 | $dest = "$user_includes[0]/" . basename $ifile; | ||||
761 | 398536 | 860294 | verb "installing $ifile to $dest"; | ||||
762 | 26 | 115 | install_file ($ifile, $dest); | ||||
763 | } | ||||||
764 | 26 | 202 | $installed = 1; | ||||
765 | } | ||||||
766 | } | ||||||
767 | else | ||||||
768 | { | ||||||
769 | # Otherwise, simply include the file. | ||||||
770 | 398662 | 863670 | $output .= "m4_include([$file])\n"; | ||||
771 | } | ||||||
772 | } | ||||||
773 | |||||||
774 | 1013 | 7163 | if ($installed) | ||||
775 | { | ||||||
776 | 3 | 28 | verb "running aclocal anew, because some files were installed locally"; | ||||
777 | 398513 | 855581 | return 0; | ||||
778 | } | ||||||
779 | |||||||
780 | # Nothing to output?! | ||||||
781 | # FIXME: Shouldn't we diagnose this? | ||||||
782 | 1010 | 21676 | return 1 if ! length ($output); | ||||
783 | |||||||
784 | 1010 | 7161 | if ($ac_version) | ||||
785 | { | ||||||
786 | # Do not use "$output_file" here for the same reason we do not | ||||||
787 | # use it in the header below. autom4te will output the name of | ||||||
788 | # the file in the diagnostic anyway. | ||||||
789 | 399508 | 917111 | $output = "m4_ifndef([AC_AUTOCONF_VERSION], | ||||
790 | [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl | ||||||
791 | m4_if(m4_defn([AC_AUTOCONF_VERSION]), [$ac_version],, | ||||||
792 | [m4_warning([this file was generated for autoconf $ac_version. | ||||||
793 | You have another version of autoconf. It may work, but is not guaranteed to. | ||||||
794 | If you have problems, you may need to regenerate the build system entirely. | ||||||
795 | To do so, use the procedure documented by the package, typically `autoreconf'.])]) | ||||||
796 | |||||||
797 | $output"; | ||||||
798 | } | ||||||
799 | |||||||
800 | # We used to print `# $output_file generated automatically etc.' But | ||||||
801 | # this creates spurious differences when using autoreconf. Autoreconf | ||||||
802 | # creates aclocal.m4t and then rename it to aclocal.m4, but the | ||||||
803 | # rebuild rules generated by Automake create aclocal.m4 directly -- | ||||||
804 | # this would gives two ways to get the same file, with a different | ||||||
805 | # name in the header. | ||||||
806 | 1010 | 54970 | $output = "# generated automatically by aclocal $VERSION -*- Autoconf -*- | ||||
807 | |||||||
808 | # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, | ||||||
809 | # 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. | ||||||
810 | # This file is free software; the Free Software Foundation | ||||||
811 | # gives unlimited permission to copy and/or distribute it, | ||||||
812 | # with or without modifications, as long as this notice is preserved. | ||||||
813 | |||||||
814 | # This program is distributed in the hope that it will be useful, | ||||||
815 | # but WITHOUT ANY WARRANTY, to the extent permitted by law; without | ||||||
816 | # even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||||||
817 | # PARTICULAR PURPOSE. | ||||||
818 | |||||||
819 | $output"; | ||||||
820 | |||||||
821 | # We try not to update $output_file unless necessary, because | ||||||
822 | # doing so invalidate Autom4te's cache and therefore slows down | ||||||
823 | # tools called after aclocal. | ||||||
824 | # | ||||||
825 | # We need to overwrite $output_file in the following situations. | ||||||
826 | # * The --force option is in use. | ||||||
827 | # * One of the dependencies is younger. | ||||||
828 | # (Not updating $output_file in this situation would cause | ||||||
829 | # make to call aclocal in loop.) | ||||||
830 | # * The contents of the current file are different from what | ||||||
831 | # we have computed. | ||||||
832 | 1010 | 7693 | if (!$force_output | ||||
833 | && $greatest_mtime < mtime ($output_file) | ||||||
834 | && $output eq contents ($output_file)) | ||||||
835 | { | ||||||
836 | 398529 | 853817 | verb "$output_file unchanged"; | ||||
837 | 19 | 184 | return 1; | ||||
838 | } | ||||||
839 | |||||||
840 | 991 | 10111 | verb "writing $output_file"; | ||||
841 | |||||||
842 | 399501 | 860351 | if (!$dry_run) | ||||
843 | { | ||||||
844 | 990 | 13703 | if (-e $output_file && !unlink $output_file) | ||||
845 | { | ||||||
846 | 0 | 0 | fatal "could not remove `$output_file': $!"; | ||||
847 | } | ||||||
848 | 399500 | 861908 | my $out = new Automake::XFile "> $output_file"; | ||||
849 | 990 | 138248 | print $out $output; | ||||
850 | } | ||||||
851 | 991 | 10280 | return 1; | ||||
852 | } | ||||||
853 | |||||||
854 | ################################################################ | ||||||
855 | |||||||
856 | # Print usage and exit. | ||||||
857 | sub usage ($) | ||||||
858 | { | ||||||
859 | 398513 | 860958 | my ($status) = @_; | ||||
860 | |||||||
861 | 3 | 32 | print "Usage: aclocal [OPTION]... | ||||
862 | |||||||
863 | Generate `aclocal.m4' by scanning `configure.ac' or `configure.in' | ||||||
864 | |||||||
865 | Options: | ||||||
866 | --acdir=DIR directory holding config files (for debugging) | ||||||
867 | --diff[=COMMAND] run COMMAND [diff -u] on M4 files that would be | ||||||
868 | changed (implies --install and --dry-run) | ||||||
869 | --dry-run pretend to, but do not actually update any file | ||||||
870 | --force always update output file | ||||||
871 | --help print this help, then exit | ||||||
872 | -I DIR add directory to search list for .m4 files | ||||||
873 | --install copy third-party files to the first -I directory | ||||||
874 | --output=FILE put output in FILE (default aclocal.m4) | ||||||
875 | --print-ac-dir print name of directory holding m4 files, then exit | ||||||
876 | --verbose don't be silent | ||||||
877 | --version print version number, then exit | ||||||
878 | -W, --warnings=CATEGORY report the warnings falling in CATEGORY | ||||||
879 | |||||||
880 | Warning categories include: | ||||||
881 | `syntax' dubious syntactic constructs (default) | ||||||
882 | `unsupported' unknown macros (default) | ||||||
883 | `all' all the warnings (default) | ||||||
884 | `no-CATEGORY' turn off warnings in CATEGORY | ||||||
885 | `none' turn off all the warnings | ||||||
886 | `error' treat warnings as errors | ||||||
887 | |||||||
888 | " . 'Report bugs to <bug-automake@gnu.org>. | ||||||
889 | GNU Automake home page: <http://www.gnu.org/software/automake/>. | ||||||
890 | General help using GNU software: <http://www.gnu.org/gethelp/>. | ||||||
891 | '; | ||||||
892 | |||||||
893 | 3 | 5 | exit $status; | ||||
894 | } | ||||||
895 | |||||||
896 | # Print version and exit. | ||||||
897 | sub version() | ||||||
898 | { | ||||||
899 | 398514 | 859955 | print <<EOF; | ||||
900 | aclocal (GNU $PACKAGE) $VERSION | ||||||
901 | Copyright (C) 2010 Free Software Foundation, Inc. | ||||||
902 | License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl-2.0.html> | ||||||
903 | This is free software: you are free to change and redistribute it. | ||||||
904 | There is NO WARRANTY, to the extent permitted by law. | ||||||
905 | |||||||
906 | Written by Tom Tromey <tromey\@redhat.com> | ||||||
907 | and Alexandre Duret-Lutz <adl\@gnu.org>. | ||||||
908 | EOF | ||||||
909 | 14 | 39 | exit 0; | ||||
910 | } | ||||||
911 | |||||||
912 | # Parse command line. | ||||||
913 | sub parse_arguments () | ||||||
914 | { | ||||||
915 | 1051 | 1904 | my $print_and_exit = 0; | ||||
916 | 399551 | 858769 | my $diff_command; | ||||
917 | |||||||
918 | my %cli_options = | ||||||
919 | ( | ||||||
920 | 'acdir=s' => sub # Setting --acdir overrides both the | ||||||
921 | { # automake (versioned) directory and the | ||||||
922 | # public (unversioned) system directory. | ||||||
923 | 1039 | 1568621 | @automake_includes = (); | ||||
924 | 399544 | 863970 | @system_includes = ($_[1]) | ||||
925 | }, | ||||||
926 | 'diff:s' => \$diff_command, | ||||||
927 | 'dry-run' => \$dry_run, | ||||||
928 | 'force' => \$force_output, | ||||||
929 | 'I=s' => \@user_includes, | ||||||
930 | 'install' => \$install, | ||||||
931 | 'output=s' => \$output_file, | ||||||
932 | 'print-ac-dir' => \$print_and_exit, | ||||||
933 | 1 | 197 | 'verbose' => sub { setup_channel 'verb', silent => 0; }, | ||||
934 | 1046 | 17539 | 'W|warnings=s' => \&parse_warnings, | ||||
935 | ); | ||||||
936 | 1041 1041 1041 | 10088 1551 4409 | use Getopt::Long; | ||||
937 | 1041 | 5861 | Getopt::Long::config ("bundling", "pass_through"); | ||||
938 | |||||||
939 | # See if --version or --help is used. We want to process these before | ||||||
940 | # anything else because the GNU Coding Standards require us to | ||||||
941 | # `exit 0' after processing these options, and we can't guarantee this | ||||||
942 | # if we treat other options first. (Handling other options first | ||||||
943 | # could produce error diagnostics, and in this condition it is | ||||||
944 | # confusing if aclocal does `exit 0'.) | ||||||
945 | my %cli_options_1st_pass = | ||||||
946 | ( | ||||||
947 | 'version' => \&version, | ||||||
948 | 3 | 586 | 'help' => sub { usage(0); }, | ||||
949 | # Recognize all other options (and their arguments) but do nothing. | ||||||
950 | 399551 10410 401943 | 969054 35548 2914158 | map { $_ => sub {} } (keys %cli_options) | ||||
951 | ); | ||||||
952 | 1041 | 5479 | my @ARGV_backup = @ARGV; | ||||
953 | 1041 | 5799 | Getopt::Long::GetOptions %cli_options_1st_pass | ||||
954 | or exit 1; | ||||||
955 | 399544 | 893501 | @ARGV = @ARGV_backup; | ||||
956 | |||||||
957 | # Now *really* process the options. This time we know that --help | ||||||
958 | # and --version are not present, but we specify them nonetheless so | ||||||
959 | # that ambiguous abbreviation are diagnosed. | ||||||
960 | 59 398510 | 156 861965 | Getopt::Long::GetOptions %cli_options, 'version' => sub {}, 'help' => sub {} | ||||
961 | 1093 | 8868 | or exit 1; | ||||
962 | |||||||
963 | 1155 | 70341 | if (@ARGV) | ||||
964 | { | ||||||
965 | 124 | 201 | my %argopts; | ||||
966 | 398513 | 859742 | for my $k (keys %cli_options) | ||||
967 | { | ||||||
968 | 207 | 530 | if ($k =~ /(.*)=s$/) | ||||
969 | { | ||||||
970 | 189 398525 | 319 858882 | map { $argopts{(length ($_) == 1) | ||||
971 | ? "-$_" : "--$_" } = 1; } (split (/\|/, $1)); | ||||||
972 | } | ||||||
973 | } | ||||||
974 | 121 | 400 | if (exists $argopts{$ARGV[0]}) | ||||
975 | { | ||||||
976 | 119 | 225 | fatal ("option `$ARGV[0]' requires an argument.\n" | ||||
977 | . "Try `$0 --help' for more information"); | ||||||
978 | } | ||||||
979 | else | ||||||
980 | { | ||||||
981 | 398512 | 870300 | fatal ("unrecognized option `$ARGV[0]'\n" | ||||
982 | . "Try `$0 --help' for more information"); | ||||||
983 | } | ||||||
984 | } | ||||||
985 | |||||||
986 | 1149 | 2960 | if ($print_and_exit) | ||||
987 | { | ||||||
988 | 119 | 198 | print "@system_includes\n"; | ||||
989 | 398511 | 854398 | exit 0; | ||||
990 | } | ||||||
991 | |||||||
992 | 1030 | 2647 | if (defined $diff_command) | ||||
993 | { | ||||||
994 | 1 | 3 | $diff_command = 'diff -u' if $diff_command eq ''; | ||||
995 | 398511 | 860229 | @diff_command = split (' ', $diff_command); | ||||
996 | 119 | 315 | $install = 1; | ||||
997 | 119 | 215 | $dry_run = 1; | ||||
998 | } | ||||||
999 | |||||||
1000 | 399540 | 864847 | if ($install && !@user_includes) | ||||
1001 | { | ||||||
1002 | 236 | 640 | fatal ("--install should copy macros in the directory indicated by the" | ||||
1003 | . "\nfirst -I option, but no -I was supplied"); | ||||||
1004 | } | ||||||
1005 | |||||||
1006 | 1266 | 24286 | if (! -d $system_includes[0]) | ||||
1007 | { | ||||||
1008 | # By default $(datadir)/aclocal doesn't exist. We don't want to | ||||||
1009 | # get an error in the case where we are searching the default | ||||||
1010 | # directory and it hasn't been created. (We know | ||||||
1011 | # @system_includes has its default value if @automake_includes | ||||||
1012 | # is not empty, because --acdir is the only way to change this.) | ||||||
1013 | 398510 | 870396 | @system_includes = () if @automake_includes; | ||||
1014 | } | ||||||
1015 | else | ||||||
1016 | { | ||||||
1017 | # Finally, adds any directory listed in the `dirlist' file. | ||||||
1018 | 1030 | 40124 | if (open (DIRLIST, "$system_includes[0]/dirlist")) | ||||
1019 | { | ||||||
1020 | 1030 | 33172 | while (<DIRLIST>) | ||||
1021 | { | ||||||
1022 | # Ignore '#' lines. | ||||||
1023 | 402630 | 869553 | next if /^#/; | ||||
1024 | # strip off newlines and end-of-line comments | ||||||
1025 | 2066 | 3861 | s/\s*\#.*$//; | ||||
1026 | 2066 | 3606 | chomp; | ||||
1027 | 400570 | 868720 | foreach my $dir (glob) | ||||
1028 | { | ||||||
1029 | 1032 | 87257 | push (@system_includes, $dir) if -d $dir; | ||||
1030 | } | ||||||
1031 | } | ||||||
1032 | 1030 | 550419 | close (DIRLIST); | ||||
1033 | } | ||||||
1034 | } | ||||||
1035 | } | ||||||
1036 | |||||||
1037 | ################################################################ | ||||||
1038 | |||||||
1039 | 1041 | 4688 | parse_WARNINGS; # Parse the WARNINGS environment variable. | ||||
1040 | 1041 | 2689 | parse_arguments; | ||||
1041 | 1030 | 4917 | $configure_ac = require_configure_ac; | ||||
1042 | |||||||
1043 | # We may have to rerun aclocal if some file have been installed, but | ||||||
1044 | # it should not happen more than once. The reason we must run again | ||||||
1045 | # is that once the file has been moved from /usr/share/aclocal/ to the | ||||||
1046 | # local m4/ directory it appears at a new place in the search path, | ||||||
1047 | # hence it should be output at a different position in aclocal.m4. If | ||||||
1048 | # we did not rerun aclocal, the next run of aclocal would produce a | ||||||
1049 | # different aclocal.m4. | ||||||
1050 | 1029 | 1750 | my $loop = 0; | ||||
1051 | 1029 | 1428 | while (1) | ||||
1052 | { | ||||||
1053 | 1031 | 1440 | ++$loop; | ||||
1054 | 1031 | 3331 | prog_error "too many loops" if $loop > 2; | ||||
1055 | |||||||
1056 | 1031 | 3182 | reset_maps; | ||||
1057 | 1031 | 3448 | scan_m4_files; | ||||
1058 | 1030 | 3899 | scan_configure; | ||||
1059 | 1030 | 3586 | last if $exit_code; | ||||
1060 | 1023 | 3376 | my %macro_traced = trace_used_macros; | ||||
1061 | 1013 | 11367 | last if write_aclocal ($output_file, keys %macro_traced); | ||||
1062 | 3 | 46 | last if $dry_run; | ||||
1063 | } | ||||||
1064 | |||||||
1065 | 1018 | 2064 | exit $exit_code; | ||||
1066 | |||||||
1067 | ### Setup "GNU" style for perl-mode and cperl-mode. | ||||||
1068 | ## Local Variables: | ||||||
1069 | ## perl-indent-level: 2 | ||||||
1070 | ## perl-continued-statement-offset: 2 | ||||||
1071 | ## perl-continued-brace-offset: 0 | ||||||
1072 | ## perl-brace-offset: 0 | ||||||
1073 | ## perl-brace-imaginary-offset: 0 | ||||||
1074 | ## perl-label-offset: -2 | ||||||
1075 | ## cperl-indent-level: 2 | ||||||
1076 | ## cperl-brace-offset: 0 | ||||||
1077 | ## cperl-continued-brace-offset: 0 | ||||||
1078 | ## cperl-label-offset: -2 | ||||||
1079 | ## cperl-extra-newline-before-brace: t | ||||||
1080 | ## cperl-merge-trailing-else: nil | ||||||
1081 | ## cperl-continued-statement-offset: 2 | ||||||
1082 | ## End: |