2
0

aclocal.in 35 KB

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