aclocal 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235
  1. #! /usr/bin/env perl
  2. # -*- perl -*-
  3. # Generated from bin/aclocal.in; do not edit by hand.
  4. eval 'case $# in 0) exec /usr/bin/env perl -S "$0";; *) exec /usr/bin/env perl -S "$0" "$@";; esac'
  5. if 0;
  6. # aclocal - create aclocal.m4 by scanning configure.ac
  7. # Copyright (C) 1996-2014 Free Software Foundation, Inc.
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2, or (at your option)
  11. # any later version.
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. # Written by Tom Tromey <tromey@redhat.com>, and
  19. # Alexandre Duret-Lutz <adl@gnu.org>.
  20. BEGIN
  21. {
  22. @Aclocal::perl_libdirs = ('/opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/linux-devkit/sysroots/x86_64-arago-linux/usr/share/automake-1.15')
  23. unless @Aclocal::perl_libdirs;
  24. unshift @INC, @Aclocal::perl_libdirs;
  25. }
  26. use strict;
  27. use Automake::Config;
  28. use Automake::General;
  29. use Automake::Configure_ac;
  30. use Automake::Channels;
  31. use Automake::ChannelDefs;
  32. use Automake::XFile;
  33. use Automake::FileUtils;
  34. use File::Basename;
  35. use File::Path ();
  36. # Some globals.
  37. # Support AC_CONFIG_MACRO_DIRS also with older autoconf.
  38. # FIXME: To be removed in Automake 2.0, once we can assume autoconf
  39. # 2.70 or later.
  40. # FIXME: keep in sync with 'internal/ac-config-macro-dirs.m4'.
  41. my $ac_config_macro_dirs_fallback =
  42. 'm4_ifndef([AC_CONFIG_MACRO_DIRS], [' .
  43. 'm4_defun([_AM_CONFIG_MACRO_DIRS], [])' .
  44. 'm4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])' .
  45. '])';
  46. # We do not operate in threaded mode.
  47. $perl_threads = 0;
  48. # Include paths for searching macros. We search macros in this order:
  49. # user-supplied directories first, then the directory containing the
  50. # automake macros, and finally the system-wide directories for
  51. # third-party macros.
  52. # @user_includes can be augmented with -I or AC_CONFIG_MACRO_DIRS.
  53. # @automake_includes can be reset with the '--automake-acdir' option.
  54. # @system_includes can be augmented with the 'dirlist' file or the
  55. # ACLOCAL_PATH environment variable, and reset with the '--system-acdir'
  56. # option.
  57. my @user_includes = ();
  58. my @automake_includes = ("/opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/linux-devkit/sysroots/x86_64-arago-linux/usr/share/aclocal-$APIVERSION");
  59. my @system_includes = ('/opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/linux-devkit/sysroots/x86_64-arago-linux/usr/share/aclocal');
  60. # Whether we should copy M4 file in $user_includes[0].
  61. my $install = 0;
  62. # --diff
  63. my @diff_command;
  64. # --dry-run
  65. my $dry_run = 0;
  66. # configure.ac or configure.in.
  67. my $configure_ac;
  68. # Output file name.
  69. my $output_file = 'aclocal.m4';
  70. # Option --force.
  71. my $force_output = 0;
  72. # Modification time of the youngest dependency.
  73. my $greatest_mtime = 0;
  74. # Which macros have been seen.
  75. my %macro_seen = ();
  76. # Remember the order into which we scanned the files.
  77. # It's important to output the contents of aclocal.m4 in the opposite order.
  78. # (Definitions in first files we have scanned should override those from
  79. # later files. So they must appear last in the output.)
  80. my @file_order = ();
  81. # Map macro names to file names.
  82. my %map = ();
  83. # Ditto, but records the last definition of each macro as returned by --trace.
  84. my %map_traced_defs = ();
  85. # Map basenames to macro names.
  86. my %invmap = ();
  87. # Map file names to file contents.
  88. my %file_contents = ();
  89. # Map file names to file types.
  90. my %file_type = ();
  91. use constant FT_USER => 1;
  92. use constant FT_AUTOMAKE => 2;
  93. use constant FT_SYSTEM => 3;
  94. # Map file names to included files (transitively closed).
  95. my %file_includes = ();
  96. # Files which have already been added.
  97. my %file_added = ();
  98. # Files that have already been scanned.
  99. my %scanned_configure_dep = ();
  100. # Serial numbers, for files that have one.
  101. # The key is the basename of the file,
  102. # the value is the serial number represented as a list.
  103. my %serial = ();
  104. # Matches a macro definition.
  105. # AC_DEFUN([macroname], ...)
  106. # or
  107. # AC_DEFUN(macroname, ...)
  108. # When macroname is '['-quoted , we accept any character in the name,
  109. # except ']'. Otherwise macroname stops on the first ']', ',', ')',
  110. # or '\n' encountered.
  111. my $ac_defun_rx =
  112. "(?:AU_ALIAS|A[CU]_DEFUN|AC_DEFUN_ONCE)\\((?:\\[([^]]+)\\]|([^],)\n]+))";
  113. # Matches an AC_REQUIRE line.
  114. my $ac_require_rx = "AC_REQUIRE\\((?:\\[([^]]+)\\]|([^],)\n]+))\\)";
  115. # Matches an m4_include line.
  116. my $m4_include_rx = "(m4_|m4_s|s)include\\((?:\\[([^]]+)\\]|([^],)\n]+))\\)";
  117. # Match a serial number.
  118. my $serial_line_rx = '^#\s*serial\s+(\S*)';
  119. my $serial_number_rx = '^\d+(?:\.\d+)*$';
  120. # Autoconf version. This variable is set by 'trace_used_macros'.
  121. my $ac_version;
  122. # User directory containing extra m4 files for macros definition,
  123. # as extracted from calls to the macro AC_CONFIG_MACRO_DIRS.
  124. # This variable is updated by 'trace_used_macros'.
  125. my @ac_config_macro_dirs;
  126. # If set, names a temporary file that must be erased on abnormal exit.
  127. my $erase_me;
  128. # Constants for the $ERR_LEVEL parameter of the 'scan_m4_dirs' function.
  129. use constant SCAN_M4_DIRS_SILENT => 0;
  130. use constant SCAN_M4_DIRS_WARN => 1;
  131. use constant SCAN_M4_DIRS_ERROR => 2;
  132. ################################################################
  133. # Prototypes for all subroutines.
  134. # BEGIN AUTOMATICALLY GENERATED PROTOTYPES
  135. sub add_file ($);
  136. sub add_macro ($);
  137. sub check_acinclude ();
  138. sub install_file ($$);
  139. sub list_compare (\@\@);
  140. sub parse_ACLOCAL_PATH ();
  141. sub parse_arguments ();
  142. sub reset_maps ();
  143. sub scan_configure ();
  144. sub scan_configure_dep ($);
  145. sub scan_file ($$$);
  146. sub scan_m4_dirs ($$@);
  147. sub scan_m4_files ();
  148. sub strip_redundant_includes (%);
  149. sub trace_used_macros ();
  150. sub unlink_tmp (;$);
  151. sub usage ($);
  152. sub version ();
  153. sub write_aclocal ($@);
  154. sub xmkdir_p ($);
  155. # END AUTOMATICALLY GENERATED PROTOTYPES
  156. ################################################################
  157. # Erase temporary file ERASE_ME. Handle signals.
  158. sub unlink_tmp (;$)
  159. {
  160. my ($sig) = @_;
  161. if ($sig)
  162. {
  163. verb "caught SIG$sig, bailing out";
  164. }
  165. if (defined $erase_me && -e $erase_me && !unlink ($erase_me))
  166. {
  167. fatal "could not remove '$erase_me': $!";
  168. }
  169. undef $erase_me;
  170. # reraise default handler.
  171. if ($sig)
  172. {
  173. $SIG{$sig} = 'DEFAULT';
  174. kill $sig => $$;
  175. }
  176. }
  177. $SIG{'INT'} = $SIG{'TERM'} = $SIG{'QUIT'} = $SIG{'HUP'} = 'unlink_tmp';
  178. END { unlink_tmp }
  179. sub xmkdir_p ($)
  180. {
  181. my $dir = shift;
  182. local $@ = undef;
  183. return
  184. if -d $dir or eval { File::Path::mkpath $dir };
  185. chomp $@;
  186. $@ =~ s/\s+at\s.*\bline\s\d+.*$//;
  187. fatal "could not create directory '$dir': $@";
  188. }
  189. # Check macros in acinclude.m4. If one is not used, warn.
  190. sub check_acinclude ()
  191. {
  192. foreach my $key (keys %map)
  193. {
  194. # FIXME: should print line number of acinclude.m4.
  195. msg ('syntax', "macro '$key' defined in acinclude.m4 but never used")
  196. if $map{$key} eq 'acinclude.m4' && ! exists $macro_seen{$key};
  197. }
  198. }
  199. sub reset_maps ()
  200. {
  201. $greatest_mtime = 0;
  202. %macro_seen = ();
  203. @file_order = ();
  204. %map = ();
  205. %map_traced_defs = ();
  206. %file_contents = ();
  207. %file_type = ();
  208. %file_includes = ();
  209. %file_added = ();
  210. %scanned_configure_dep = ();
  211. %invmap = ();
  212. %serial = ();
  213. undef &search;
  214. }
  215. # install_file ($SRC, $DESTDIR)
  216. sub install_file ($$)
  217. {
  218. my ($src, $destdir) = @_;
  219. my $dest = $destdir . "/" . basename ($src);
  220. my $diff_dest;
  221. verb "installing $src to $dest";
  222. if ($force_output
  223. || !exists $file_contents{$dest}
  224. || $file_contents{$src} ne $file_contents{$dest})
  225. {
  226. if (-e $dest)
  227. {
  228. msg 'note', "overwriting '$dest' with '$src'";
  229. $diff_dest = $dest;
  230. }
  231. else
  232. {
  233. msg 'note', "installing '$dest' from '$src'";
  234. }
  235. if (@diff_command)
  236. {
  237. if (! defined $diff_dest)
  238. {
  239. # $dest does not exist. We create an empty one just to
  240. # run diff, and we erase it afterward. Using the real
  241. # the destination file (rather than a temporary file) is
  242. # good when diff is run with options that display the
  243. # file name.
  244. #
  245. # If creating $dest fails, fall back to /dev/null. At
  246. # least one diff implementation (Tru64's) cannot deal
  247. # with /dev/null. However working around this is not
  248. # worth the trouble since nobody run aclocal on a
  249. # read-only tree anyway.
  250. $erase_me = $dest;
  251. my $f = new IO::File "> $dest";
  252. if (! defined $f)
  253. {
  254. undef $erase_me;
  255. $diff_dest = '/dev/null';
  256. }
  257. else
  258. {
  259. $diff_dest = $dest;
  260. $f->close;
  261. }
  262. }
  263. my @cmd = (@diff_command, $diff_dest, $src);
  264. $! = 0;
  265. verb "running: @cmd";
  266. my $res = system (@cmd);
  267. Automake::FileUtils::handle_exec_errors "@cmd", 1
  268. if $res;
  269. unlink_tmp;
  270. }
  271. elsif (!$dry_run)
  272. {
  273. xmkdir_p ($destdir);
  274. xsystem ('cp', $src, $dest);
  275. }
  276. }
  277. }
  278. # Compare two lists of numbers.
  279. sub list_compare (\@\@)
  280. {
  281. my @l = @{$_[0]};
  282. my @r = @{$_[1]};
  283. while (1)
  284. {
  285. if (0 == @l)
  286. {
  287. return (0 == @r) ? 0 : -1;
  288. }
  289. elsif (0 == @r)
  290. {
  291. return 1;
  292. }
  293. elsif ($l[0] < $r[0])
  294. {
  295. return -1;
  296. }
  297. elsif ($l[0] > $r[0])
  298. {
  299. return 1;
  300. }
  301. shift @l;
  302. shift @r;
  303. }
  304. }
  305. ################################################################
  306. # scan_m4_dirs($TYPE, $ERR_LEVEL, @DIRS)
  307. # -----------------------------------------------
  308. # Scan all M4 files installed in @DIRS for new macro definitions.
  309. # Register each file as of type $TYPE (one of the FT_* constants).
  310. # If a directory in @DIRS cannot be read:
  311. # - fail hard if $ERR_LEVEL == SCAN_M4_DIRS_ERROR
  312. # - just print a warning if $ERR_LEVEL == SCAN_M4_DIRS_WA
  313. # - continue silently if $ERR_LEVEL == SCAN_M4_DIRS_SILENT
  314. sub scan_m4_dirs ($$@)
  315. {
  316. my ($type, $err_level, @dirlist) = @_;
  317. foreach my $m4dir (@dirlist)
  318. {
  319. if (! opendir (DIR, $m4dir))
  320. {
  321. # TODO: maybe avoid complaining only if errno == ENONENT?
  322. my $message = "couldn't open directory '$m4dir': $!";
  323. if ($err_level == SCAN_M4_DIRS_ERROR)
  324. {
  325. fatal $message;
  326. }
  327. elsif ($err_level == SCAN_M4_DIRS_WARN)
  328. {
  329. msg ('unsupported', $message);
  330. next;
  331. }
  332. elsif ($err_level == SCAN_M4_DIRS_SILENT)
  333. {
  334. next; # Silently ignore.
  335. }
  336. else
  337. {
  338. prog_error "invalid \$err_level value '$err_level'";
  339. }
  340. }
  341. # We reverse the directory contents so that foo2.m4 gets
  342. # used in preference to foo1.m4.
  343. foreach my $file (reverse sort grep (! /^\./, readdir (DIR)))
  344. {
  345. # Only examine .m4 files.
  346. next unless $file =~ /\.m4$/;
  347. # Skip some files when running out of srcdir.
  348. next if $file eq 'aclocal.m4';
  349. my $fullfile = File::Spec->canonpath ("$m4dir/$file");
  350. scan_file ($type, $fullfile, 'aclocal');
  351. }
  352. closedir (DIR);
  353. }
  354. }
  355. # Scan all the installed m4 files and construct a map.
  356. sub scan_m4_files ()
  357. {
  358. # First, scan configure.ac. It may contain macro definitions,
  359. # or may include other files that define macros.
  360. scan_file (FT_USER, $configure_ac, 'aclocal');
  361. # Then, scan acinclude.m4 if it exists.
  362. if (-f 'acinclude.m4')
  363. {
  364. scan_file (FT_USER, 'acinclude.m4', 'aclocal');
  365. }
  366. # Finally, scan all files in our search paths.
  367. if (@user_includes)
  368. {
  369. # Don't explore the same directory multiple times. This is here not
  370. # only for speedup purposes. We need this when the user has e.g.
  371. # specified 'ACLOCAL_AMFLAGS = -I m4' and has also set
  372. # AC_CONFIG_MACRO_DIR[S]([m4]) in configure.ac. This makes the 'm4'
  373. # directory to occur twice here and fail on the second call to
  374. # scan_m4_dirs([m4]) when the 'm4' directory doesn't exist.
  375. # TODO: Shouldn't there be rather a check in scan_m4_dirs for
  376. # @user_includes[0]?
  377. @user_includes = uniq @user_includes;
  378. # Don't complain if the first user directory doesn't exist, in case
  379. # we need to create it later (can happen if '--install' was given).
  380. scan_m4_dirs (FT_USER,
  381. $install ? SCAN_M4_DIRS_SILENT : SCAN_M4_DIRS_WARN,
  382. $user_includes[0]);
  383. scan_m4_dirs (FT_USER,
  384. SCAN_M4_DIRS_ERROR,
  385. @user_includes[1..$#user_includes]);
  386. }
  387. scan_m4_dirs (FT_AUTOMAKE, SCAN_M4_DIRS_ERROR, @automake_includes);
  388. scan_m4_dirs (FT_SYSTEM, SCAN_M4_DIRS_ERROR, @system_includes);
  389. # Construct a new function that does the searching. We use a
  390. # function (instead of just evaluating $search in the loop) so that
  391. # "die" is correctly and easily propagated if run.
  392. my $search = "sub search {\nmy \$found = 0;\n";
  393. foreach my $key (reverse sort keys %map)
  394. {
  395. $search .= ('if (/\b\Q' . $key . '\E(?!\w)/) { add_macro ("' . $key
  396. . '"); $found = 1; }' . "\n");
  397. }
  398. $search .= "return \$found;\n};\n";
  399. eval $search;
  400. prog_error "$@\n search is $search" if $@;
  401. }
  402. ################################################################
  403. # Add a macro to the output.
  404. sub add_macro ($)
  405. {
  406. my ($macro) = @_;
  407. # Ignore unknown required macros. Either they are not really
  408. # needed (e.g., a conditional AC_REQUIRE), in which case aclocal
  409. # should be quiet, or they are needed and Autoconf itself will
  410. # complain when we trace for macro usage later.
  411. return unless defined $map{$macro};
  412. verb "saw macro $macro";
  413. $macro_seen{$macro} = 1;
  414. add_file ($map{$macro});
  415. }
  416. # scan_configure_dep ($file)
  417. # --------------------------
  418. # Scan a configure dependency (configure.ac, or separate m4 files)
  419. # for uses of known macros and AC_REQUIREs of possibly unknown macros.
  420. # Recursively scan m4_included files.
  421. sub scan_configure_dep ($)
  422. {
  423. my ($file) = @_;
  424. # Do not scan a file twice.
  425. return ()
  426. if exists $scanned_configure_dep{$file};
  427. $scanned_configure_dep{$file} = 1;
  428. my $mtime = mtime $file;
  429. $greatest_mtime = $mtime if $greatest_mtime < $mtime;
  430. my $contents = exists $file_contents{$file} ?
  431. $file_contents{$file} : contents $file;
  432. my $line = 0;
  433. my @rlist = ();
  434. my @ilist = ();
  435. foreach (split ("\n", $contents))
  436. {
  437. ++$line;
  438. # Remove comments from current line.
  439. s/\bdnl\b.*$//;
  440. s/\#.*$//;
  441. # Avoid running all the following regexes on white lines.
  442. next if /^\s*$/;
  443. while (/$m4_include_rx/go)
  444. {
  445. my $ifile = $2 || $3;
  446. # Skip missing 'sinclude'd files.
  447. next if $1 ne 'm4_' && ! -f $ifile;
  448. push @ilist, $ifile;
  449. }
  450. while (/$ac_require_rx/go)
  451. {
  452. push (@rlist, $1 || $2);
  453. }
  454. # The search function is constructed dynamically by
  455. # scan_m4_files. The last parenthetical match makes sure we
  456. # don't match things that look like macro assignments or
  457. # AC_SUBSTs.
  458. if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/)
  459. {
  460. # Macro not found, but AM_ prefix found.
  461. # Make this just a warning, because we do not know whether
  462. # the macro is actually used (it could be called conditionally).
  463. msg ('unsupported', "$file:$line",
  464. "macro '$2' not found in library");
  465. }
  466. }
  467. add_macro ($_) foreach (@rlist);
  468. scan_configure_dep ($_) foreach @ilist;
  469. }
  470. # add_file ($FILE)
  471. # ----------------
  472. # Add $FILE to output.
  473. sub add_file ($)
  474. {
  475. my ($file) = @_;
  476. # Only add a file once.
  477. return if ($file_added{$file});
  478. $file_added{$file} = 1;
  479. scan_configure_dep $file;
  480. }
  481. # Point to the documentation for underquoted AC_DEFUN only once.
  482. my $underquoted_manual_once = 0;
  483. # scan_file ($TYPE, $FILE, $WHERE)
  484. # --------------------------------
  485. # Scan a single M4 file ($FILE), and all files it includes.
  486. # Return the list of included files.
  487. # $TYPE is one of FT_USER, FT_AUTOMAKE, or FT_SYSTEM, depending
  488. # on where the file comes from.
  489. # $WHERE is the location to use in the diagnostic if the file
  490. # does not exist.
  491. sub scan_file ($$$)
  492. {
  493. my ($type, $file, $where) = @_;
  494. my $basename = basename $file;
  495. # Do not scan the same file twice.
  496. return @{$file_includes{$file}} if exists $file_includes{$file};
  497. # Prevent potential infinite recursion (if two files include each other).
  498. return () if exists $file_contents{$file};
  499. unshift @file_order, $file;
  500. $file_type{$file} = $type;
  501. fatal "$where: file '$file' does not exist" if ! -e $file;
  502. my $fh = new Automake::XFile $file;
  503. my $contents = '';
  504. my @inc_files = ();
  505. my %inc_lines = ();
  506. my $defun_seen = 0;
  507. my $serial_seen = 0;
  508. my $serial_older = 0;
  509. while ($_ = $fh->getline)
  510. {
  511. # Ignore '##' lines.
  512. next if /^##/;
  513. $contents .= $_;
  514. my $line = $_;
  515. if ($line =~ /$serial_line_rx/go)
  516. {
  517. my $number = $1;
  518. if ($number !~ /$serial_number_rx/go)
  519. {
  520. msg ('syntax', "$file:$.",
  521. "ill-formed serial number '$number', "
  522. . "expecting a version string with only digits and dots");
  523. }
  524. elsif ($defun_seen)
  525. {
  526. # aclocal removes all definitions from M4 file with the
  527. # same basename if a greater serial number is found.
  528. # Encountering a serial after some macros will undefine
  529. # these macros...
  530. msg ('syntax', "$file:$.",
  531. 'the serial number must appear before any macro definition');
  532. }
  533. # We really care about serials only for non-automake macros
  534. # and when --install is used. But the above diagnostics are
  535. # made regardless of this, because not using --install is
  536. # not a reason not the fix macro files.
  537. elsif ($install && $type != FT_AUTOMAKE)
  538. {
  539. $serial_seen = 1;
  540. my @new = split (/\./, $number);
  541. verb "$file:$.: serial $number";
  542. if (!exists $serial{$basename}
  543. || list_compare (@new, @{$serial{$basename}}) > 0)
  544. {
  545. # Delete any definition we knew from the old macro.
  546. foreach my $def (@{$invmap{$basename}})
  547. {
  548. verb "$file:$.: ignoring previous definition of $def";
  549. delete $map{$def};
  550. }
  551. $invmap{$basename} = [];
  552. $serial{$basename} = \@new;
  553. }
  554. else
  555. {
  556. $serial_older = 1;
  557. }
  558. }
  559. }
  560. # Remove comments from current line.
  561. # Do not do it earlier, because the serial line is a comment.
  562. $line =~ s/\bdnl\b.*$//;
  563. $line =~ s/\#.*$//;
  564. while ($line =~ /$ac_defun_rx/go)
  565. {
  566. $defun_seen = 1;
  567. if (! defined $1)
  568. {
  569. msg ('syntax', "$file:$.", "underquoted definition of $2"
  570. . "\n run info Automake 'Extending aclocal'\n"
  571. . " or see http://www.gnu.org/software/automake/manual/"
  572. . "automake.html#Extending-aclocal")
  573. unless $underquoted_manual_once;
  574. $underquoted_manual_once = 1;
  575. }
  576. # If this macro does not have a serial and we have already
  577. # seen a macro with the same basename earlier, we should
  578. # ignore the macro (don't exit immediately so we can still
  579. # diagnose later #serial numbers and underquoted macros).
  580. $serial_older ||= ($type != FT_AUTOMAKE
  581. && !$serial_seen && exists $serial{$basename});
  582. my $macro = $1 || $2;
  583. if (!$serial_older && !defined $map{$macro})
  584. {
  585. verb "found macro $macro in $file: $.";
  586. $map{$macro} = $file;
  587. push @{$invmap{$basename}}, $macro;
  588. }
  589. else
  590. {
  591. # Note: we used to give an error here if we saw a
  592. # duplicated macro. However, this turns out to be
  593. # extremely unpopular. It causes actual problems which
  594. # are hard to work around, especially when you must
  595. # mix-and-match tool versions.
  596. verb "ignoring macro $macro in $file: $.";
  597. }
  598. }
  599. while ($line =~ /$m4_include_rx/go)
  600. {
  601. my $ifile = $2 || $3;
  602. # Skip missing 'sinclude'd files.
  603. next if $1 ne 'm4_' && ! -f $ifile;
  604. push (@inc_files, $ifile);
  605. $inc_lines{$ifile} = $.;
  606. }
  607. }
  608. # Ignore any file that has an old serial (or no serial if we know
  609. # another one with a serial).
  610. return ()
  611. if ($serial_older ||
  612. ($type != FT_AUTOMAKE && !$serial_seen && exists $serial{$basename}));
  613. $file_contents{$file} = $contents;
  614. # For some reason I don't understand, it does not work
  615. # to do "map { scan_file ($_, ...) } @inc_files" below.
  616. # With Perl 5.8.2 it undefines @inc_files.
  617. my @copy = @inc_files;
  618. my @all_inc_files = (@inc_files,
  619. map { scan_file ($type, $_,
  620. "$file:$inc_lines{$_}") } @copy);
  621. $file_includes{$file} = \@all_inc_files;
  622. return @all_inc_files;
  623. }
  624. # strip_redundant_includes (%FILES)
  625. # ---------------------------------
  626. # Each key in %FILES is a file that must be present in the output.
  627. # However some of these files might already include other files in %FILES,
  628. # so there is no point in including them another time.
  629. # This removes items of %FILES which are already included by another file.
  630. sub strip_redundant_includes (%)
  631. {
  632. my %files = @_;
  633. # Always include acinclude.m4, even if it does not appear to be used.
  634. $files{'acinclude.m4'} = 1 if -f 'acinclude.m4';
  635. # File included by $configure_ac are redundant.
  636. $files{$configure_ac} = 1;
  637. # Files at the end of @file_order should override those at the beginning,
  638. # so it is important to preserve these trailing files. We can remove
  639. # a file A if it is going to be output before a file B that includes
  640. # file A, not the converse.
  641. foreach my $file (reverse @file_order)
  642. {
  643. next unless exists $files{$file};
  644. foreach my $ifile (@{$file_includes{$file}})
  645. {
  646. next unless exists $files{$ifile};
  647. delete $files{$ifile};
  648. verb "$ifile is already included by $file";
  649. }
  650. }
  651. # configure.ac is implicitly included.
  652. delete $files{$configure_ac};
  653. return %files;
  654. }
  655. sub trace_used_macros ()
  656. {
  657. my %files = map { $map{$_} => 1 } keys %macro_seen;
  658. %files = strip_redundant_includes %files;
  659. # When AC_CONFIG_MACRO_DIRS is used, avoid possible spurious warnings
  660. # from autom4te about macros being "m4_require'd but not m4_defun'd";
  661. # for more background, see:
  662. # http://lists.gnu.org/archive/html/autoconf-patches/2012-11/msg00004.html
  663. # as well as autoconf commit 'v2.69-44-g1ed0548', "warn: allow aclocal
  664. # to silence m4_require warnings".
  665. my $early_m4_code .= "m4_define([m4_require_silent_probe], [-])";
  666. my $traces = ($ENV{AUTOM4TE} || 'autom4te');
  667. $traces .= " --language Autoconf-without-aclocal-m4 ";
  668. $traces = "echo '$early_m4_code' | $traces - ";
  669. # Support AC_CONFIG_MACRO_DIRS also with older autoconf.
  670. # Note that we can't use '$ac_config_macro_dirs_fallback' here, because
  671. # a bug in option parsing code of autom4te 2.68 and earlier will cause
  672. # it to read standard input last, even if the "-" argument is specified
  673. # early.
  674. # FIXME: To be removed in Automake 2.0, once we can assume autoconf
  675. # 2.70 or later.
  676. $traces .= "$automake_includes[0]/internal/ac-config-macro-dirs.m4 ";
  677. # All candidate files.
  678. $traces .= join (' ',
  679. (map { "'$_'" }
  680. (grep { exists $files{$_} } @file_order))) . " ";
  681. # All candidate macros.
  682. $traces .= join (' ',
  683. (map { "--trace='$_:\$f::\$n::\${::}%'" }
  684. ('AC_DEFUN',
  685. 'AC_DEFUN_ONCE',
  686. 'AU_DEFUN',
  687. '_AM_AUTOCONF_VERSION',
  688. 'AC_CONFIG_MACRO_DIR_TRACE',
  689. # FIXME: Tracing the next two macros is a hack for
  690. # compatibility with older autoconf. Remove this in
  691. # Automake 2.0, when we can assume Autoconf 2.70 or
  692. # later.
  693. 'AC_CONFIG_MACRO_DIR',
  694. '_AM_CONFIG_MACRO_DIRS')),
  695. # Do not trace $1 for all other macros as we do
  696. # not need it and it might contains harmful
  697. # characters (like newlines).
  698. (map { "--trace='$_:\$f::\$n'" } (keys %macro_seen)));
  699. verb "running $traces $configure_ac";
  700. my $tracefh = new Automake::XFile ("$traces $configure_ac |");
  701. @ac_config_macro_dirs = ();
  702. my %traced = ();
  703. while ($_ = $tracefh->getline)
  704. {
  705. chomp;
  706. my ($file, $macro, $arg1) = split (/::/);
  707. $traced{$macro} = 1 if exists $macro_seen{$macro};
  708. if ($macro eq 'AC_DEFUN' || $macro eq 'AC_DEFUN_ONCE'
  709. || $macro eq 'AU_DEFUN')
  710. {
  711. $map_traced_defs{$arg1} = $file;
  712. }
  713. elsif ($macro eq '_AM_AUTOCONF_VERSION')
  714. {
  715. $ac_version = $arg1;
  716. }
  717. elsif ($macro eq 'AC_CONFIG_MACRO_DIR_TRACE')
  718. {
  719. push @ac_config_macro_dirs, $arg1;
  720. }
  721. # FIXME: We still need to trace AC_CONFIG_MACRO_DIR
  722. # for compatibility with older autoconf. Remove this
  723. # once we can assume Autoconf 2.70 or later.
  724. elsif ($macro eq 'AC_CONFIG_MACRO_DIR')
  725. {
  726. @ac_config_macro_dirs = ($arg1);
  727. }
  728. # FIXME:This is an hack for compatibility with older autoconf.
  729. # Remove this once we can assume Autoconf 2.70 or later.
  730. elsif ($macro eq '_AM_CONFIG_MACRO_DIRS')
  731. {
  732. # Empty leading/trailing fields might be produced by split,
  733. # hence the grep is really needed.
  734. push @ac_config_macro_dirs, grep (/./, (split /\s+/, $arg1));
  735. }
  736. }
  737. # FIXME: in Autoconf >= 2.70, AC_CONFIG_MACRO_DIR calls
  738. # AC_CONFIG_MACRO_DIR_TRACE behind the scenes, which could
  739. # leave unwanted duplicates in @ac_config_macro_dirs.
  740. # Remove this in Automake 2.0, when we'll stop tracing
  741. # AC_CONFIG_MACRO_DIR explicitly.
  742. @ac_config_macro_dirs = uniq @ac_config_macro_dirs;
  743. $tracefh->close;
  744. return %traced;
  745. }
  746. sub scan_configure ()
  747. {
  748. # Make sure we include acinclude.m4 if it exists.
  749. if (-f 'acinclude.m4')
  750. {
  751. add_file ('acinclude.m4');
  752. }
  753. scan_configure_dep ($configure_ac);
  754. }
  755. ################################################################
  756. # Write output.
  757. # Return 0 iff some files were installed locally.
  758. sub write_aclocal ($@)
  759. {
  760. my ($output_file, @macros) = @_;
  761. my $output = '';
  762. my %files = ();
  763. # Get the list of files containing definitions for the macros used.
  764. # (Filter out unused macro definitions with $map_traced_defs. This
  765. # can happen when an Autoconf macro is conditionally defined:
  766. # aclocal sees the potential definition, but this definition is
  767. # actually never processed and the Autoconf implementation is used
  768. # instead.)
  769. for my $m (@macros)
  770. {
  771. $files{$map{$m}} = 1
  772. if (exists $map_traced_defs{$m}
  773. && $map{$m} eq $map_traced_defs{$m});
  774. }
  775. # Do not explicitly include a file that is already indirectly included.
  776. %files = strip_redundant_includes %files;
  777. my $installed = 0;
  778. for my $file (grep { exists $files{$_} } @file_order)
  779. {
  780. # Check the time stamp of this file, and of all files it includes.
  781. for my $ifile ($file, @{$file_includes{$file}})
  782. {
  783. my $mtime = mtime $ifile;
  784. $greatest_mtime = $mtime if $greatest_mtime < $mtime;
  785. }
  786. # If the file to add looks like outside the project, copy it
  787. # to the output. The regex catches filenames starting with
  788. # things like '/', '\', or 'c:\'.
  789. if ($file_type{$file} != FT_USER
  790. || $file =~ m,^(?:\w:)?[\\/],)
  791. {
  792. if (!$install || $file_type{$file} != FT_SYSTEM)
  793. {
  794. # Copy the file into aclocal.m4.
  795. $output .= $file_contents{$file} . "\n";
  796. }
  797. else
  798. {
  799. # Install the file (and any file it includes).
  800. my $dest;
  801. for my $ifile (@{$file_includes{$file}}, $file)
  802. {
  803. install_file ($ifile, $user_includes[0]);
  804. }
  805. $installed = 1;
  806. }
  807. }
  808. else
  809. {
  810. # Otherwise, simply include the file.
  811. $output .= "m4_include([$file])\n";
  812. }
  813. }
  814. if ($installed)
  815. {
  816. verb "running aclocal anew, because some files were installed locally";
  817. return 0;
  818. }
  819. # Nothing to output?!
  820. # FIXME: Shouldn't we diagnose this?
  821. return 1 if ! length ($output);
  822. if ($ac_version)
  823. {
  824. # Do not use "$output_file" here for the same reason we do not
  825. # use it in the header below. autom4te will output the name of
  826. # the file in the diagnostic anyway.
  827. $output = "m4_ifndef([AC_AUTOCONF_VERSION],
  828. [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
  829. m4_if(m4_defn([AC_AUTOCONF_VERSION]), [$ac_version],,
  830. [m4_warning([this file was generated for autoconf $ac_version.
  831. You have another version of autoconf. It may work, but is not guaranteed to.
  832. If you have problems, you may need to regenerate the build system entirely.
  833. To do so, use the procedure documented by the package, typically 'autoreconf'.])])
  834. $output";
  835. }
  836. # We used to print "# $output_file generated automatically etc." But
  837. # this creates spurious differences when using autoreconf. Autoreconf
  838. # creates aclocal.m4t and then rename it to aclocal.m4, but the
  839. # rebuild rules generated by Automake create aclocal.m4 directly --
  840. # this would gives two ways to get the same file, with a different
  841. # name in the header.
  842. $output = "# generated automatically by aclocal $VERSION -*- Autoconf -*-
  843. # Copyright (C) 1996-$RELEASE_YEAR Free Software Foundation, Inc.
  844. # This file is free software; the Free Software Foundation
  845. # gives unlimited permission to copy and/or distribute it,
  846. # with or without modifications, as long as this notice is preserved.
  847. # This program is distributed in the hope that it will be useful,
  848. # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
  849. # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  850. # PARTICULAR PURPOSE.
  851. $ac_config_macro_dirs_fallback
  852. $output";
  853. # We try not to update $output_file unless necessary, because
  854. # doing so invalidate Autom4te's cache and therefore slows down
  855. # tools called after aclocal.
  856. #
  857. # We need to overwrite $output_file in the following situations.
  858. # * The --force option is in use.
  859. # * One of the dependencies is younger.
  860. # (Not updating $output_file in this situation would cause
  861. # make to call aclocal in loop.)
  862. # * The contents of the current file are different from what
  863. # we have computed.
  864. if (!$force_output
  865. && $greatest_mtime < mtime ($output_file)
  866. && $output eq contents ($output_file))
  867. {
  868. verb "$output_file unchanged";
  869. return 1;
  870. }
  871. verb "writing $output_file";
  872. if (!$dry_run)
  873. {
  874. if (-e $output_file && !unlink $output_file)
  875. {
  876. fatal "could not remove '$output_file': $!";
  877. }
  878. my $out = new Automake::XFile "> $output_file";
  879. print $out $output;
  880. }
  881. return 1;
  882. }
  883. ################################################################
  884. # Print usage and exit.
  885. sub usage ($)
  886. {
  887. my ($status) = @_;
  888. print <<'EOF';
  889. Usage: aclocal [OPTION]...
  890. Generate 'aclocal.m4' by scanning 'configure.ac' or 'configure.in'
  891. Options:
  892. --automake-acdir=DIR directory holding automake-provided m4 files
  893. --system-acdir=DIR directory holding third-party system-wide files
  894. --diff[=COMMAND] run COMMAND [diff -u] on M4 files that would be
  895. changed (implies --install and --dry-run)
  896. --dry-run pretend to, but do not actually update any file
  897. --force always update output file
  898. --help print this help, then exit
  899. -I DIR add directory to search list for .m4 files
  900. --install copy third-party files to the first -I directory
  901. --output=FILE put output in FILE (default aclocal.m4)
  902. --print-ac-dir print name of directory holding system-wide
  903. third-party m4 files, then exit
  904. --verbose don't be silent
  905. --version print version number, then exit
  906. -W, --warnings=CATEGORY report the warnings falling in CATEGORY
  907. Warning categories include:
  908. syntax dubious syntactic constructs (default)
  909. unsupported unknown macros (default)
  910. all all the warnings (default)
  911. no-CATEGORY turn off warnings in CATEGORY
  912. none turn off all the warnings
  913. error treat warnings as errors
  914. Report bugs to <bug-automake@gnu.org>.
  915. GNU Automake home page: <http://www.gnu.org/software/automake/>.
  916. General help using GNU software: <http://www.gnu.org/gethelp/>.
  917. EOF
  918. exit $status;
  919. }
  920. # Print version and exit.
  921. sub version ()
  922. {
  923. print <<EOF;
  924. aclocal (GNU $PACKAGE) $VERSION
  925. Copyright (C) $RELEASE_YEAR Free Software Foundation, Inc.
  926. License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl-2.0.html>
  927. This is free software: you are free to change and redistribute it.
  928. There is NO WARRANTY, to the extent permitted by law.
  929. Written by Tom Tromey <tromey\@redhat.com>
  930. and Alexandre Duret-Lutz <adl\@gnu.org>.
  931. EOF
  932. exit 0;
  933. }
  934. # Parse command line.
  935. sub parse_arguments ()
  936. {
  937. my $print_and_exit = 0;
  938. my $diff_command;
  939. my %cli_options =
  940. (
  941. 'help' => sub { usage(0); },
  942. 'version' => \&version,
  943. 'system-acdir=s' => sub { shift; @system_includes = @_; },
  944. 'automake-acdir=s' => sub { shift; @automake_includes = @_; },
  945. 'diff:s' => \$diff_command,
  946. 'dry-run' => \$dry_run,
  947. 'force' => \$force_output,
  948. 'I=s' => \@user_includes,
  949. 'install' => \$install,
  950. 'output=s' => \$output_file,
  951. 'print-ac-dir' => \$print_and_exit,
  952. 'verbose' => sub { setup_channel 'verb', silent => 0; },
  953. 'W|warnings=s' => \&parse_warnings,
  954. );
  955. use Automake::Getopt ();
  956. Automake::Getopt::parse_options %cli_options;
  957. if (@ARGV > 0)
  958. {
  959. fatal ("non-option arguments are not accepted: '$ARGV[0]'.\n"
  960. . "Try '$0 --help' for more information.");
  961. }
  962. if ($print_and_exit)
  963. {
  964. print "@system_includes\n";
  965. exit 0;
  966. }
  967. if (defined $diff_command)
  968. {
  969. $diff_command = 'diff -u' if $diff_command eq '';
  970. @diff_command = split (' ', $diff_command);
  971. $install = 1;
  972. $dry_run = 1;
  973. }
  974. # Finally, adds any directory listed in the 'dirlist' file.
  975. if (open (DIRLIST, "$system_includes[0]/dirlist"))
  976. {
  977. while (<DIRLIST>)
  978. {
  979. # Ignore '#' lines.
  980. next if /^#/;
  981. # strip off newlines and end-of-line comments
  982. s/\s*\#.*$//;
  983. chomp;
  984. foreach my $dir (glob)
  985. {
  986. push (@system_includes, $dir) if -d $dir;
  987. }
  988. }
  989. close (DIRLIST);
  990. }
  991. }
  992. # Add any directory listed in the 'ACLOCAL_PATH' environment variable
  993. # to the list of system include directories.
  994. sub parse_ACLOCAL_PATH ()
  995. {
  996. return if not defined $ENV{"ACLOCAL_PATH"};
  997. # Directories in ACLOCAL_PATH should take precedence over system
  998. # directories, so we use unshift. However, directories that
  999. # come first in ACLOCAL_PATH take precedence over directories
  1000. # coming later, which is why the result of split is reversed.
  1001. foreach my $dir (reverse split /:/, $ENV{"ACLOCAL_PATH"})
  1002. {
  1003. unshift (@system_includes, $dir) if $dir ne '' && -d $dir;
  1004. }
  1005. }
  1006. ################################################################
  1007. parse_WARNINGS; # Parse the WARNINGS environment variable.
  1008. parse_arguments;
  1009. parse_ACLOCAL_PATH;
  1010. $configure_ac = require_configure_ac;
  1011. # We may have to rerun aclocal if some file have been installed, but
  1012. # it should not happen more than once. The reason we must run again
  1013. # is that once the file has been moved from /usr/share/aclocal/ to the
  1014. # local m4/ directory it appears at a new place in the search path,
  1015. # hence it should be output at a different position in aclocal.m4. If
  1016. # we did not rerun aclocal, the next run of aclocal would produce a
  1017. # different aclocal.m4.
  1018. my $loop = 0;
  1019. my $rerun_due_to_macrodir = 0;
  1020. while (1)
  1021. {
  1022. ++$loop;
  1023. prog_error "too many loops" if $loop > 2 + $rerun_due_to_macrodir;
  1024. reset_maps;
  1025. scan_m4_files;
  1026. scan_configure;
  1027. last if $exit_code;
  1028. my %macro_traced = trace_used_macros;
  1029. if (!$rerun_due_to_macrodir && @ac_config_macro_dirs)
  1030. {
  1031. # The directory specified in calls to the AC_CONFIG_MACRO_DIRS
  1032. # m4 macro (if any) must go after the user includes specified
  1033. # explicitly with the '-I' option.
  1034. push @user_includes, @ac_config_macro_dirs;
  1035. # We might have to scan some new directory of .m4 files.
  1036. $rerun_due_to_macrodir++;
  1037. next;
  1038. }
  1039. if ($install && !@user_includes)
  1040. {
  1041. fatal "installation of third-party macros impossible without " .
  1042. "-I options nor AC_CONFIG_MACRO_DIR{,S} m4 macro(s)";
  1043. }
  1044. last if write_aclocal ($output_file, keys %macro_traced);
  1045. last if $dry_run;
  1046. }
  1047. check_acinclude;
  1048. exit $exit_code;
  1049. ### Setup "GNU" style for perl-mode and cperl-mode.
  1050. ## Local Variables:
  1051. ## perl-indent-level: 2
  1052. ## perl-continued-statement-offset: 2
  1053. ## perl-continued-brace-offset: 0
  1054. ## perl-brace-offset: 0
  1055. ## perl-brace-imaginary-offset: 0
  1056. ## perl-label-offset: -2
  1057. ## cperl-indent-level: 2
  1058. ## cperl-brace-offset: 0
  1059. ## cperl-continued-brace-offset: 0
  1060. ## cperl-label-offset: -2
  1061. ## cperl-extra-newline-before-brace: t
  1062. ## cperl-merge-trailing-else: nil
  1063. ## cperl-continued-statement-offset: 2
  1064. ## End: