home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / automake-1.1e-bin.lha / bin / automake < prev   
Encoding:
Text File  |  1996-10-12  |  103.9 KB  |  4,059 lines

  1. #!/bin/perl
  2. # -*- perl -*-
  3. # Generated automatically from automake.in by configure.
  4.  
  5. eval 'exec /bin/perl -S $0 ${1+"$@"}'
  6.     if 0;
  7.  
  8. # automake - create Makefile.in from Makefile.am
  9. # Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
  10.  
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; either version 2, or (at your option)
  14. # any later version.
  15.  
  16. # This program is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. # GNU General Public License for more details.
  20.  
  21. # You should have received a copy of the GNU General Public License
  22. # along with this program; if not, write to the Free Software
  23. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  24. # 02111-1307, USA.
  25.  
  26. # Originally written by David Mackenzie <djm@gnu.ai.mit.edu>.
  27. # Perl reimplementation by Tom Tromey <tromey@drip.colorado.edu>.
  28.  
  29.  
  30. # Parameters set by configure.  Not to be changed.  NOTE: assign
  31. # VERSION as string so that eg version 0.30 will print correctly.
  32. $VERSION = "1.1e";
  33. $PACKAGE = "automake";
  34. $prefix = "/ade";
  35. $am_dir = "${prefix}/share/automake";
  36.  
  37. # String constants.
  38. $IGNORE_PATTERN = "^##([^#].*)?\$";
  39. $WHITE_PATTERN = "^[ \t]*\$";
  40. $COMMENT_PATTERN = "^#";
  41. $RULE_PATTERN = "^([\$a-zA-Z_.][-.a-zA-Z0-9_(){}/]*) *:";
  42. $MACRO_PATTERN = "^([A-Za-z][A-Za-z0-9_]*)[ \t]*=[ \t]*(.*)\$";
  43. $BOGUS_MACRO_PATTERN = "^([^ \t]*)[ \t]*=[ \t]*(.*)\$";
  44. $GNITS_VERSION_PATTERN = "[0-9]+\\.[0-9]+([a-z]|\\.[0-9]+)?";
  45.  
  46. # Constants to define the "strictness" level.
  47. $FOREIGN = 0;
  48. $GNU = 1;
  49. $AMIGA = 1;
  50. $GNITS = 2;
  51.  
  52.  
  53.  
  54. # Variables global to entire run.
  55.  
  56. # TRUE if on Amiga, as set on command line.
  57. # ADE note: This defaults to 1 here.  If these enhancements are incorporated into
  58. # the baseline automake distribution, it should default to 0 there.  Also note that
  59. # "on_amiga" is a slight misnomer, since this is an ADE feature, not just an
  60. # Amiga feature.  The ADE may eventually run on other systems like BeOS.
  61. $on_amiga = 1;
  62.  
  63. # TRUE if we should always generate Makefile.in.
  64. $force_generation = 1;
  65.  
  66. # Strictness level as set on command line.
  67. $default_strictness = $GNU;
  68.  
  69. # Name of strictness level, as set on command line.
  70. $default_strictness_name = 'gnu';
  71.  
  72. # This is TRUE if GNU make specific automatic dependency generation
  73. # code should be included in generated Makefile.in.
  74. $cmdline_use_dependencies = 1;
  75.  
  76. # TRUE if in verbose mode.
  77. $verbose = 0;
  78.  
  79. # This holds our (eventual) exit status.  We don't actually exit until
  80. # we have processed all input files.
  81. $exit_status = 0;
  82.  
  83. # From the Perl manual.
  84. $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
  85.  
  86. # TRUE if missing standard files should be installed.
  87. $add_missing = 0;
  88.  
  89. # Files found by scanning configure.in for LIBOBJS.
  90. %libsources = ();
  91.  
  92. # True if AM_C_PROTOTYPES appears in configure.in.
  93. $am_c_prototypes = 0;
  94.  
  95. # Names used in AC_CONFIG_HEADER call.  $config_name is the actual
  96. # (first) argument.  $config_header is the '.in' file.  Ordinarily the
  97. # second is derived from the first, but they can be different if the
  98. # weird "NAME:FILE" syntax is used.
  99. $config_name = '';
  100. $config_header = '';
  101. # Line number at which AC_CONFIG_HEADER appears in configure.in.
  102. $config_header_line = 0;
  103.  
  104. # Directory where output files go.  Actually, output files are
  105. # relative to this directory.
  106. $output_directory = '.';
  107.  
  108. # Relative location of top build directory.
  109. $top_builddir = '';
  110.  
  111. # Absolute location of top build directory.
  112. $build_directory = '';
  113.  
  114. # Name of srcdir as given in build directory's Makefile.  For
  115. # dependencies only.
  116. $srcdir_name = '';
  117.  
  118. # List of Makefile.am's to process.
  119. @input_files = ();
  120.  
  121. # List of files in AC_OUTPUT without Makefile.am.
  122. @other_input_files = ();
  123. # Line number at which AC_OUTPUT seen.
  124. $ac_output_line = 0;
  125.  
  126. # List of directories to search for configure-required files.  This
  127. # can be set by AC_CONFIG_AUX_DIR.
  128. @config_aux_path = ('.', '..', '../..');
  129. $config_aux_dir = '';
  130.  
  131. # Whether AC_PROG_MAKE_SET has been seen in configure.in.
  132. $seen_make_set = 0;
  133.  
  134. # Whether ud_GNU_GETTEXT has been seen in configure.in.
  135. $seen_gettext = 0;
  136. # Line number at which ud_GNU_GETTEXT seen.
  137. $ac_gettext_line = 0;
  138.  
  139. # Whether ALL_LINGUAS has been seen.
  140. $seen_linguas = '';
  141. # The actual text.
  142. $all_linguas = '';
  143. # Line number at which it appears.
  144. $all_linguas_line = 0;
  145.  
  146. # 1 if AC_PROG_INSTALL seen, 2 if AM_PROG_INSTALL seen.
  147. $seen_prog_install = 0;
  148.  
  149. # 1 if any scripts installed, 0 otherwise.
  150. $scripts_installed = 0;
  151.  
  152. # Whether AC_PATH_XTRA has been seen in configure.in.
  153. $seen_path_xtra = 0;
  154.  
  155. # Whether YACC variable has been seen in configure.in.
  156. $seen_prog_yacc = 0;
  157.  
  158. # Two variables to control lex use.  One is for AC_DECL_YYTEXT and the
  159. # other is for AC_PROG_LEX.
  160. $seen_decl_yytext = 0;
  161. $seen_prog_lex = 0;
  162.  
  163. # TRUE if we've seen AC_PROG_CC.
  164. $seen_prog_cc = 0;
  165.  
  166. # TRUE if we've seen AC_PROG_CXX.
  167. $seen_prog_cxx = 0;
  168.  
  169. # TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM).  The presence of
  170. # AC_CHECK_TOOL also sets this.
  171. $seen_canonical = 0;
  172.  
  173. # TRUE if we've seen AC_PROG_RANLIB.
  174. $seen_ranlib = 0;
  175.  
  176. # TRUE if we've seen AC_ARG_PROGRAM.
  177. $seen_arg_prog = 0;
  178.  
  179. # TRUE if we've seen AM_PROG_LIBTOOL.
  180. $seen_libtool = 0;
  181. $libtool_line = 0;
  182.  
  183. # TRUE if we've seen AM_MAINTAINER_MODE.
  184. $seen_maint_mode = 0;
  185.  
  186. # TRUE if we've seen PACKAGE and VERSION.
  187. $seen_package = 0;
  188. $seen_version = 0;
  189.  
  190. # Actual version we've seen.
  191. $package_version = '';
  192.  
  193. # Line number where we saw version definition.
  194. $package_version_line = 0;
  195.  
  196. # TRUE if we've seen AM_PATH_LISPDIR.
  197. $seen_lispdir = 0;
  198.  
  199.  
  200. # Charsets used by maintainer and in distribution.  MAINT_CHARSET is
  201. # handled in a funny way: if seen in the top-level Makefile.am, it is
  202. # used for every directory which does not specify a different value.
  203. # The rationale here is that some directories (eg gettext) might be
  204. # distributions of other packages, and thus require their own charset
  205. # info.  However, the DIST_CHARSET must be the same for the entire
  206. # package; it can only be set at top-level.
  207. # FIXME: this yields bugs when rebuilding.  What to do?  Always
  208. # read (and sometimes discard) top-level Makefile.am?
  209. $maint_charset = '';
  210. $dist_charset = 'utf8';        # recode doesn't support this yet.
  211.  
  212. # Name of input file ("Makefile.in") and output file ("Makefile.am").
  213. # These have no directory components.
  214. $am_file_name = '';
  215. $in_file_name = '';
  216.  
  217.  
  218.  
  219. &initialize_global_constants;
  220.  
  221. # Parse command line.
  222. &parse_arguments (@ARGV);
  223.  
  224. # Do configure.in scan only once.
  225. &scan_configure;
  226.  
  227. die "automake: no \`Makefile.am' found or specified\n"
  228.     if ! @input_files;
  229.  
  230. # Now do all the work on each file.
  231. foreach $am_file (@input_files)
  232. {
  233.     # FIXME: should support the AC_OUTPUT ":" syntax here.
  234.     if (! -f ($am_file . '.am'))
  235.     {
  236.     &am_error ('no such file');
  237.     }
  238.     else
  239.     {
  240.     &generate_makefile ($am_file);
  241.     }
  242. }
  243.  
  244. if ($seen_prog_install <= $scripts_installed)
  245. {
  246.     &am_conf_error (($scripts_installed ? 'AM_PROG_INSTALL' : 'AC_PROG_INSTALL')
  247.             . " must be used in configure.in");
  248.     &keyed_aclocal_warning ('AM_PROG_INSTALL')
  249.     if $scripts_installed;
  250. }
  251.  
  252. exit $exit_status;
  253.  
  254.  
  255. ################################################################
  256.  
  257. # Parse command line.
  258. sub parse_arguments
  259. {
  260.     local (@arglist) = @_;
  261.  
  262.     # Start off as gnu.
  263.     &set_strictness ('gnu');
  264.  
  265.     while (@arglist)
  266.     {
  267.     if ($arglist[0] eq "--version")
  268.     {
  269.         print "automake - GNU $PACKAGE $VERSION\n";
  270.         exit 0;
  271.     }
  272.     elsif ($arglist[0] eq "--help")
  273.     {
  274.         &usage;
  275.     }
  276.     elsif ($arglist[0] =~ /^--amdir=(.+)$/)
  277.     {
  278.         $am_dir = $1;
  279.     }
  280.     elsif ($arglist[0] eq '--amdir')
  281.     {
  282.         &require_argument (@arglist);
  283.         shift (@arglist);
  284.         $am_dir = $arglist[0];
  285.     }
  286.     elsif ($arglist[0] =~ /^--build-dir=(.+)$/)
  287.     {
  288.         # Must end in /.
  289.         $build_directory = $1 . '/';
  290.     }
  291.     elsif ($arglist[0] eq '--build-dir')
  292.     {
  293.         &require_argument (@arglist);
  294.         shift (@arglist);
  295.         # Must end in /.
  296.         $build_directory = $arglist[0] . '/';
  297.     }
  298.     elsif ($arglist[0] =~ /^--srcdir-name=(.+)$/)
  299.     {
  300.         $srcdir_name = $1;
  301.     }
  302.     elsif ($arglist[0] eq '--srcdir-name')
  303.     {
  304.         &require_argument (@arglist);
  305.         shift (@arglist);
  306.         $srcdir_name = $arglist[0];
  307.     }
  308.     elsif ($arglist[0] =~ /^--strictness=(.+)$/)
  309.     {
  310.         &set_strictness ($1);
  311.     }
  312.     elsif ($arglist[0] eq '--gnu')
  313.     {
  314.         &set_strictness ('gnu');
  315.     }
  316.     elsif ($arglist[0] eq '--amiga')
  317.     {
  318.         &set_strictness ('amiga');
  319.         $on_amiga = 1;
  320.     }
  321.     elsif ($arglist[0] eq '--gnits')
  322.     {
  323.         &set_strictness ('gnits');
  324.     }
  325.     elsif ($arglist[0] eq '--foreign')
  326.     {
  327.         &set_strictness ('foreign');
  328.     }
  329.     elsif ($arglist[0] eq '--strictness' || $arglist[0] eq '-s')
  330.     {
  331.         &require_argument (@arglist);
  332.         shift (@arglist);
  333.         &set_strictness ($arglist[0]);
  334.     }
  335.     elsif ($arglist[0] eq '--include-deps' || $arglist[0] eq '-i')
  336.     {
  337.         $cmdline_use_dependencies = 0;
  338.     }
  339.     elsif ($arglist[0] eq '--no-force')
  340.     {
  341.         $force_generation = 0;
  342.     }
  343.     elsif ($arglist[0] =~ /^--output-dir=(.*)$/)
  344.     {
  345.         # Set output directory.
  346.         $output_directory = $1;
  347.     }
  348.     elsif ($arglist[0] eq '--output-dir' || $arglist[0] eq '-o')
  349.     {
  350.         &require_argument (@arglist);
  351.         shift (@arglist);
  352.         $output_directory = $arglist[0];
  353.     }
  354.     elsif ($arglist[0] eq '--add-missing' || $arglist[0] eq '-a')
  355.     {
  356.         $add_missing = 1;
  357.     }
  358.     elsif ($arglist[0] eq '--verbose' || $arglist[0] eq '-v')
  359.     {
  360.         $verbose = 1;
  361.     }
  362.     elsif ($arglist[0] eq '--')
  363.     {
  364.         # Stop option processing.
  365.         shift (@arglist);
  366.         push (@input_files, @arglist);
  367.         last;
  368.     }
  369.     elsif ($arglist[0] =~ /^-/)
  370.     {
  371.         die "automake: unrecognized option -- \`$arglist[0]'\n";
  372.     }
  373.     else
  374.     {
  375.         push (@input_files, $arglist[0]);
  376.     }
  377.  
  378.     shift (@arglist);
  379.     }
  380.  
  381.     # Take global strictness from whatever we currently have set.
  382.     $default_strictness = $strictness;
  383.     $default_strictness_name = $strictness_name;
  384. }
  385.  
  386. # Ensure argument exists, or die.
  387. sub require_argument
  388. {
  389.     local ($arg, @arglist) = @_;
  390.     die "automake: no argument given for option \`$arg'\n"
  391.     if ! @arglist;
  392. }
  393.  
  394. ################################################################
  395.  
  396. # Generate a Makefile.in given the name of the corresponding Makefile.
  397. sub generate_makefile
  398. {
  399.     local ($makefile) = @_;
  400.  
  401.     ($am_file_name = $makefile) =~ s/^.*\///;
  402.     $in_file_name = $am_file_name . '.in';
  403.     $am_file_name .= '.am';
  404.  
  405.     &initialize_per_input;
  406.     $relative_dir = &dirname ($makefile);
  407.  
  408.     # At the toplevel directory, we might need config.guess, config.sub
  409.     # or libtool.
  410.     if ($relative_dir eq '.')
  411.     {
  412.      # libtool requires some files.
  413.      &require_conf_file_with_conf_line ($libtool_line, $FOREIGN,
  414.                         'config.sub', 'config.guess',
  415.                         'libtool') if $seen_libtool;
  416.  
  417.         # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
  418.         # config.sub.
  419.         &require_config_file ($FOREIGN, 'config.guess', 'config.sub')
  420.         if $seen_canonical;
  421.     }
  422.  
  423.     # We still need Makefile.in here, because sometimes the `dist'
  424.     # target doesn't re-run automake.
  425.     &push_dist_common ($in_file_name, $am_file_name);
  426.     push (@sources, '$(SOURCES)')
  427.     if &variable_defined ('SOURCES');
  428.     push (@objects, '$(OBJECTS)')
  429.     if &variable_defined ('OBJECTS');
  430.  
  431.     # This is always the default target.  This gives us freedom to do
  432.     # things in whatever order is convenient.
  433.     $output_rules .= "default: all\n\n";
  434.     push (@phony, 'default');
  435.  
  436.     &read_am_file ($makefile . '.am');
  437.     &handle_options;
  438.  
  439.     # Check first, because we might modify some state.
  440.     &check_gnu_standards;
  441.     &check_gnits_standards;
  442.  
  443.     &handle_configure;
  444.     &handle_gettext;
  445.     &handle_libraries;
  446.     &handle_programs;
  447.     &handle_scripts;
  448.  
  449.     # This must be run after all the sources are scanned.
  450.     &handle_yacc_lex_cxx;
  451.  
  452.     # Re-init SOURCES and OBJECTS.  FIXME: other code shouldn't depend
  453.     # on this (but currently does).
  454.     $contents{'SOURCES'} = join (' ', @sources);
  455.     $contents{'OBJECTS'} = join (' ', @objects);
  456.  
  457.     &handle_texinfo;
  458.     &handle_emacs_lisp;
  459.     &handle_man_pages;
  460.     &handle_data;
  461.     &handle_headers;
  462.     &handle_subdirs;
  463.     &handle_tags;
  464.     &handle_dist;
  465.     &handle_dependencies;
  466.     &handle_tests;
  467.     &handle_footer;
  468.     &handle_merge_targets;
  469.     &handle_installdirs;
  470.     &handle_clean;
  471.     &handle_phony;
  472.  
  473.     if (! -d ($output_directory . '/' . $relative_dir))
  474.     {
  475.     mkdir ($output_directory . '/' . $relative_dir, 0755);
  476.     }
  477.  
  478.     local ($out_file) = $output_directory . '/' . $makefile . ".in";
  479.     if (! $force_generation && -e $out_file)
  480.     {
  481.     local ($am_time) = (stat ($makefile . '.am'))[9];
  482.     local ($in_time) = (stat ($out_file))[9];
  483.     # FIXME: how to do unsigned comparison?
  484.     if ($am_time < $in_time)
  485.     {
  486.         # No need to update.
  487.         return;
  488.     }
  489.     }
  490.  
  491.     if (! open (GM_FILE, "> " . $out_file))
  492.     {
  493.     warn "automake: ${am_file}.in: cannot open: $!\n";
  494.     $exit_status = 1;
  495.     return;
  496.     }
  497.     print "automake: creating ", $makefile, ".in\n" if $verbose;
  498.  
  499.     print GM_FILE $output_vars;
  500.     print GM_FILE $output_rules;
  501.     print GM_FILE $output_trailer;
  502.  
  503.     close (GM_FILE);
  504. }
  505.  
  506. ################################################################
  507.  
  508. # Handle AUTOMAKE_OPTIONS variable.
  509. sub handle_options
  510. {
  511.     return if ! &variable_defined ('AUTOMAKE_OPTIONS');
  512.  
  513.     foreach (&variable_value_as_list ('AUTOMAKE_OPTIONS'))
  514.     {
  515.     last if /^#/;
  516.  
  517.     $options{$_} = 1;
  518.     if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign' || $_ eq 'amiga')
  519.     {
  520.         &set_strictness ($_);
  521.     }
  522.     elsif (/ansi2knr/)
  523.     {
  524.         # An option like "../lib/ansi2knr" is allowed.  With no
  525.         # path prefix, we assume the required programs are in this
  526.         # directory.  We save the actual option for later.
  527.         $options{'ansi2knr'} = $_;
  528.     }
  529.     elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
  530.            || $_ eq 'dist-shar' || $_ eq 'dist-zip'
  531.            || $_ eq 'dist-tarZ' || $_ eq 'dejagnu')
  532.     {
  533.         # Explicitly recognize these.
  534.     }
  535.     elsif ($_ eq 'no-dependencies')
  536.     {
  537.         $use_dependencies = 0;
  538.     }
  539.     elsif (/[0-9]+\.?[0-9]+/)
  540.     {
  541.         # Got a version number.  Is the syntax too strict?
  542.         local ($num_version);
  543.         ($num_version = $VERSION) =~ tr/0-9//cd;
  544.         if ($num_version < $_)
  545.         {
  546.         &am_line_error ('AUTOMAKE_OPTIONS',
  547.                 "require version $_, only have $VERSION");
  548.         exit 1;
  549.         }
  550.     }
  551.     else
  552.     {
  553.         &am_line_error ('AUTOMAKE_OPTIONS',
  554.                 'option ', $_, 'not recognized');
  555.     }
  556.     }
  557. }
  558.  
  559. # Return object extension.  Just once, put some code into the output.
  560. sub get_object_extension
  561. {
  562.     if (! $dir_holds_sources)
  563.     {
  564.     # Boilerplate.
  565.     local ($xform) = '';
  566.     if (&variable_defined ('CONFIG_HEADER'))
  567.     {
  568.         ($xform = &dirname ($contents{'CONFIG_HEADER'}))
  569.         =~ s/(\W)/\\$1/g;
  570.         $xform = '-I' . $xform;
  571.     }
  572.     $xform = 's/\@CONFIG_INCLUDE_SPEC\@/' . $xform . '/go';
  573.     $output_vars .= &file_contents_with_transform ($xform,
  574.                                'compile-vars');
  575.     $output_rules .= &file_contents ('compile');
  576.     &push_phony_cleaners ('compile');
  577.  
  578.     # If using X, include some extra variable definitions.  NOTE
  579.     # we don't want to force these into CFLAGS or anything,
  580.     # because not all programs will necessarily use X.
  581.     if ($seen_path_xtra)
  582.     {
  583.         $output_vars .= ("X_CFLAGS = \@X_CFLAGS\@\n"
  584.                  . "X_LIBS = \@X_LIBS\@\n"
  585.                  . "X_EXTRA_LIBS = \@X_EXTRA_LIBS\@\n"
  586.                  . "X_PRE_LIBS = \@X_PRE_LIBS\@\n");
  587.     }
  588.  
  589.     # Check for automatic de-ANSI-fication.
  590.     $dir_holds_sources = '.o';
  591.     push (@suffixes, '.c', '.o');
  592.     push (@clean, 'compile');
  593.  
  594.     if (defined $options{'ansi2knr'})
  595.     {
  596.         if (! $am_c_prototypes)
  597.         {
  598.         &am_line_error ('AUTOMAKE_OPTIONS',
  599.                 "option \`ansi2knr' in use but \`AM_C_PROTOTYPES' not in configure.in");
  600.         &keyed_aclocal_warning ('AM_C_PROTOTYPES');
  601.         # Only give this error once.
  602.         $am_c_prototypes = 1;
  603.         }
  604.  
  605.         $dir_holds_sources = '$o';
  606.         push (@suffixes, '._c', '._o');
  607.  
  608.         # Only require ansi2knr files if they should appear in
  609.         # this directory.
  610.         if ($options{'ansi2knr'} eq 'ansi2knr')
  611.         {
  612.         &require_file_with_line ('AUTOMAKE_OPTIONS', $FOREIGN,
  613.                      'ansi2knr.c', 'ansi2knr.1');
  614.         $output_rules .= &file_contents ('kr-extra');
  615.         push (@clean, 'krextra');
  616.         &push_phony_cleaners ('krextra');
  617.         }
  618.  
  619.         $output_vars .= "o = .\@U\@o\n";
  620.  
  621.         # Make sure ansi2knr can be found: if no path specified,
  622.         # specify "./".
  623.         local ($apath) = $options{'ansi2knr'};
  624.         $apath = './' . $apath
  625.         unless $apath =~ /\//;
  626.         $output_vars .= "ANSI2KNR = " . $apath . "\n";
  627.  
  628.         $output_rules .= &file_contents ('compile-kr');
  629.         $output_rules .= &file_contents ('clean-kr');
  630.  
  631.         push (@clean, 'kr');
  632.         &push_phony_cleaners ('kr');
  633.     }
  634.     }
  635.     return $dir_holds_sources;
  636. }
  637.  
  638. # Handle yacc and lex.
  639. sub handle_yacc_lex_cxx
  640. {
  641.     #
  642.     # First do yacc and lex.
  643.     #
  644.  
  645.     local ($yacc_count) = scalar (keys %yacc_sources);
  646.     local ($lex_count) = scalar (keys %lex_sources);
  647.     if ($yacc_count)
  648.     {
  649.     push (@suffixes, '.y');
  650.     $output_vars .= "YACC = \@YACC\@\n";
  651.     $output_rules .= ".y.c:\n\t";
  652.     if ($yacc_count > 1)
  653.     {
  654.         $output_rules .= '$(INTERLOCK) =yacclockdir $(YLWRAP) y.tab.c $@ $(YACC) $(YFLAGS) $<';
  655.     }
  656.     else
  657.     {
  658.         $output_rules .= '$(YACC) $(YFLAGS) $< && mv y.tab.c $@';
  659.     }
  660.     $output_rules .= "\n";
  661.  
  662.     if (! $seen_prog_yacc)
  663.     {
  664.         # FIXME: should include a reference line.  FIXME: maybe
  665.         # directly reference AC_PROG_YACC somehow?
  666.         &am_error ("yacc source seen but \`YACC' not defined in \`configure.in'\n");
  667.     }
  668.     }
  669.     if ($lex_count)
  670.     {
  671.     push (@suffixes, '.l');
  672.     $output_vars .= ("LEX = \@LEX\@\n"
  673.              . "LEX_OUTPUT_ROOT = \@LEX_OUTPUT_ROOT\@\n");
  674.     $output_rules .= ".l.c:\n\t";
  675.     if ($lex_count > 1)
  676.     {
  677.         $output_rules .= '$(INTERLOCK) =lexlockdir $(YLWRAP) $(LEX_OUTPUT_ROOT).c $@ $(LEX) $(LFLAGS) $<';
  678.     }
  679.     else
  680.     {
  681.         $output_rules .= '$(LEX) $(LFLAGS) $< && mv $(LEX_OUTPUT_ROOT).c $@';
  682.     }
  683.     $output_rules .= "\n";
  684.  
  685.     if (! $seen_prog_lex)
  686.     {
  687.         &am_error ("lex source seen but \`AC_PROG_LEX' not in \`configure.in'\n");
  688.     }
  689.     if (! $seen_decl_yytext)
  690.     {
  691.         &am_error ("lex source seen but \`AC_DECL_YYTEXT' not in \`configure.in'\n");
  692.     }
  693.     }
  694.  
  695.     if ($yacc_count > 1 || $lex_count > 1)
  696.     {
  697.     # If there is more than one distinct yacc (resp lex) source
  698.     # file in a given directory, then the `interlock' program is
  699.     # required to allow parallel builds to work correctly.  FIXME:
  700.     # for now, no line number.
  701.     &require_config_file ($FOREIGN, 'interlock', 'ylwrap');
  702.     $output_vars .= ('INTERLOCK = ' . $config_aux_dir . "/interlock\n"
  703.              . 'YLWRAP = ' . $config_aux_dir . "/ylwrap\n");
  704.     }
  705.  
  706.     #
  707.     # Now handle C++.
  708.     #
  709.     local (@cxx_list) = keys %cxx_extensions;
  710.     local ($cxx_count) = scalar @cxx_list;
  711.     if ($cxx_count)
  712.     {
  713.     push (@suffixes, @cxx_list);
  714.  
  715.     $output_vars .= ("CXX = \@CXX\@\n"
  716.              . "CXXFLAGS = \@CXXFLAGS\@\n"
  717.              . 'CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)'
  718.              . "\n"
  719.              . 'CXXLINK = $(CXX) $(LDFLAGS) -o $@'
  720.              . "\n");
  721.  
  722.     local ($ext);
  723.     foreach $ext (@cxx_list)
  724.     {
  725.         $output_rules .= ("$ext.o:\n"
  726.                   . "\t\$(CXXCOMPILE) -c \$<\n");
  727.     }
  728.  
  729.     if (! $seen_prog_cxx)
  730.     {
  731.         &am_error ("C++ source seen but \`AC_PROG_CXX' not in \`configure.in'\n");
  732.     }
  733.     }
  734.  
  735.     #
  736.     # Last, handle some C cleanup.
  737.     #
  738.     if ($seen_c_source)
  739.     {
  740.     $output_vars .= ("CC = \@CC\@\n"
  741.              . "CFLAGS = \@CFLAGS\@\n"
  742.              . 'COMPILE = $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)'
  743.              . "\n"
  744.              . 'LINK = $(CC) $(LDFLAGS) -o $@'
  745.              . "\n");
  746.     }
  747. }
  748.  
  749. # Handle SOURCE->OBJECT transform for one program or library.
  750. # Arguments are:
  751. #   canonical (transformed) name of object to build
  752. #   actual name of object to build
  753. #   object extension (ie either `.o' or `$o'.
  754. # Return result is name of linker variable that must be used.
  755. # Empty return means just use `LINK'.
  756. sub handle_source_transform
  757. {
  758.     # one_file is canonical name.  unxformed is given name.  obj is
  759.     # object extension.
  760.     local ($one_file, $unxformed, $obj) = @_;
  761.     local ($objpat) = $obj;
  762.     $objpat =~ s/(\W)/\\$1/g;
  763.  
  764.     local ($linker) = '';
  765.  
  766.     if (&variable_defined ($one_file . "_OBJECTS"))
  767.     {
  768.     &am_line_error ($one_file . '_OBJECTS',
  769.             $one_file . '_OBJECTS', 'should not be defined');
  770.     # No point in continuing.
  771.     return;
  772.     }
  773.  
  774.     local (@files);
  775.     local ($prefix);
  776.     foreach $prefix ('', 'EXTRA_')
  777.     {
  778.     @files = ();
  779.     if (&variable_defined ($prefix . $one_file . "_SOURCES"))
  780.     {
  781.         push (@sources, '$(' . $prefix . $one_file . "_SOURCES)");
  782.         push (@objects, '$(' . $prefix . $one_file . "_OBJECTS)")
  783.         unless $prefix eq 'EXTRA_';
  784.         @files = &variable_value_as_list ($prefix
  785.                           . $one_file . "_SOURCES");
  786.     }
  787.     elsif ($prefix eq '')
  788.     {
  789.         $output_vars .= $one_file . "_SOURCES = " . $unxformed . ".c\n";
  790.         push (@sources, $unxformed . '.c');
  791.         push (@objects, $unxformed . $obj);
  792.         push (@files, $unxformed . ".c ");
  793.     }
  794.     else
  795.     {
  796.         $output_vars .= "EXTRA_" . $one_file . "_SOURCES =\n";
  797.     }
  798.  
  799.     if (length (@files))
  800.     {
  801.         # Turn sources into objects.
  802.         local (@result) = ();
  803.         foreach (@files)
  804.         {
  805.         # Skip header files, including C++-ish ones.  The list
  806.         # of C++ header extensions comes from Emacs 19.32
  807.         # etags.
  808.         next if /\.[hH]$/;
  809.         next if /\.hxx$/;
  810.         next if /\.h\+\+$/;
  811.         next if /\.hh$/;
  812.         next if /\.hpp$/;
  813.         # Skip things that look like configure substitutions.
  814.         next if /^\@.*\@$/;
  815.  
  816.         # Include .c file for lex or yacc source in distribution.
  817.         if (/^(.*)\.y$/)
  818.         {
  819.             # Yacc source.
  820.             &push_dist_common ($1 . '.c');
  821.             $yacc_sources{$_} = 1;
  822.         }
  823.         elsif (/^(.*)\.l$/)
  824.         {
  825.             # Lex source.
  826.             &push_dist_common ($1 . '.c');
  827.             $lex_sources{$_} = 1;
  828.         }
  829.  
  830.         # Transform source files into .o files.  List of C++
  831.         # extensions comes from Emacs 19.32 etags.
  832.         if (s/\.c\+\+$/$obj/g
  833.             || s/\.cc$/$obj/g
  834.             || s/\.cpp$/$obj/g
  835.             || s/\.cxx$/$obj/g
  836.             || s/\.C$/$obj/g)
  837.         {
  838.             $cxx_extensions{$&} = 1;
  839.             $linker = 'CXXLINK';
  840.         }
  841.         else
  842.         {
  843.             # FORTRAN support.  FIXME: not finished.
  844.             s/\.f90$/$obj/g;
  845.             s/\.for$/$obj/g;
  846.  
  847.             # .y is yacc.  .l is lex.  .f and .F is fortran.
  848.             # .s is assembly.  .M is Objective-C++.  .m is
  849.             # Objective-C.
  850.             s/\.[cylfFsmM]$/$obj/g;
  851.  
  852.             # FIXME: of course, this should only happen for C
  853.             # source.  The multi-language support must really
  854.             # be cleaned up more globally.
  855.             $seen_c_source = 1;
  856.         }
  857.  
  858.         push (@result, $_)
  859.             unless $prefix eq 'EXTRA_';
  860.  
  861.         # Transform .o or $o file into .P file (for automatic
  862.         # dependency code).
  863.         s/$objpat$/.P/g;
  864.         $dep_files{'.deps/' . $_} = 1;
  865.         }
  866.  
  867.         &pretty_print ($one_file . "_OBJECTS =", "", @result)
  868.         unless $prefix eq 'EXTRA_';
  869.     }
  870.     }
  871.  
  872.     if (&variable_defined ('CONFIG_HEADER'))
  873.     {
  874.     $output_rules .= ('$(' . $one_file . "_OBJECTS): "
  875.               . $contents{'CONFIG_HEADER'} . "\n");
  876.     }
  877.  
  878.     return $linker;
  879. }
  880.  
  881. # Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
  882. # Also, generate _DEPENDENCIES variable if appropriate.
  883. # Arguments are:
  884. #   transformed name of object being built, or empty string if no object
  885. #   name of _LDADD/_LIBADD-type variable to examine
  886. sub handle_lib_objects
  887. {
  888.     local ($xname, $var) = @_;
  889.  
  890.     die "programming error in handle_lib_objects"
  891.     if ! &variable_defined ($var);
  892.  
  893.     # We recognize certain things that are commonly put in LIBADD or
  894.     # LDADD.
  895.     local ($lsearch);
  896.     local (@dep_list) = ();
  897.  
  898.     foreach $lsearch (&variable_value_as_list ($var))
  899.     {
  900.     # Skip -lfoo and -Ldir.
  901.     next if $lsearch =~ /^-[lL]/;
  902.  
  903.     # Assume we have a file of some sort, and push it onto the
  904.     # dependency list.  This isn't perfect, but hopefully people
  905.     # will point out the exceptions I'm obviously too lazy to
  906.     # think of myself.
  907.     push (@dep_list, $lsearch);
  908.  
  909.     # Automatically handle @LIBOBJS@ and @ALLOCA@.  Basically this
  910.     # means adding entries to dep_files.
  911.     if ($lsearch eq '@LIBOBJS@')
  912.     {
  913.         if (! keys %libsources)
  914.         {
  915.         &am_line_error ($var, "\@LIBOBJS\@ seen but never set in \`configure.in'");
  916.         }
  917.  
  918.         local ($iter, $rewrite);
  919.         foreach $iter (keys %libsources)
  920.         {
  921.         if ($iter =~ /\.h$/)
  922.         {
  923.             &require_file_with_line ($var, $FOREIGN, $iter);
  924.         }
  925.         elsif ($iter ne 'alloca.c')
  926.         {
  927.             ($rewrite = $iter) =~ s/\.c$/.P/;
  928.             $dep_files{'.deps/' . $rewrite} = 1;
  929.             &require_file_with_line ($var, $FOREIGN, $iter);
  930.         }
  931.         }
  932.     }
  933.     elsif ($lsearch eq '@ALLOCA@')
  934.     {
  935.         &am_line_error ($var,
  936.                 "\@ALLOCA\@ seen but \`AC_FUNC_ALLOCA' not in \`configure.in'")
  937.         if ! defined $libsources{'alloca.c'};
  938.         $dep_files{'.deps/alloca.P'} = 1;
  939.         &require_file_with_line ($var, $FOREIGN, 'alloca.c');
  940.     }
  941.     }
  942.  
  943.     if ($xname ne '' && ! &variable_defined ($xname . '_DEPENDENCIES'))
  944.     {
  945.     &pretty_print ($xname . '_DEPENDENCIES = ', '', @dep_list);
  946.     }
  947. }
  948.  
  949. # Handle C programs.
  950. sub handle_programs
  951. {
  952.     local (@proglist) = &am_install_var ('-clean',
  953.                      'programs', 'PROGRAMS',
  954.                      'bin', 'sbin', 'libexec', 'pkglib',
  955.                      'noinst', 'check');
  956.     return if ! @proglist;
  957.  
  958.     # If a program is installed, this is required.  We only want this
  959.     # error to appear once.
  960.     &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
  961.     unless $seen_arg_prog;
  962.     $seen_arg_prog = 1;
  963.  
  964.     local ($obj) = &get_object_extension;
  965.     local ($one_file, $xname, $munge);
  966.  
  967.     foreach $one_file (@proglist)
  968.     {
  969.     # Canonicalize names.
  970.     ($xname = $one_file) =~ tr/A-Za-z0-9_/_/c;
  971.     if ($xname ne $one_file)
  972.     {
  973.         local ($xt);
  974.         foreach $xt ('_LDADD', '_SOURCES', '_OBJECTS', '_DEPENDENCIES')
  975.         {
  976.         &am_line_error ($one_file . $xt,
  977.                 "invalid variable \`" . $one_file . $xt
  978.                 . "'; should be \`" . $xname . $xt . "'")
  979.             if &variable_defined ($one_file . $xt);
  980.         }
  981.     }
  982.  
  983.     local ($linker) = &handle_source_transform ($xname, $one_file, $obj);
  984.  
  985.     if (&variable_defined ($xname . "_LDADD"))
  986.     {
  987.         &handle_lib_objects ($xname, $xname . '_LDADD');
  988.     }
  989.     else
  990.     {
  991.         # User didn't define prog_LDADD override.  So do it.
  992.         $output_vars .= $xname . '_LDADD = $(LDADD)' . "\n";
  993.  
  994.         # This does a bit too much work.  But we need it to
  995.         # generate _DEPENDENCIES when appropriate.
  996.         &handle_lib_objects ($xname, 'LDADD')
  997.         if (&variable_defined ('LDADD'));
  998.     }
  999.  
  1000.     # Determine program to use for link.
  1001.     local ($xlink);
  1002.     if (&variable_defined ($xname . '_LINK'))
  1003.     {
  1004.         $xlink = $xname . '_LINK';
  1005.     }
  1006.     else
  1007.     {
  1008.         $xlink = $linker ? $linker : 'LINK';
  1009.     }
  1010.  
  1011.     $output_rules .=
  1012.         &file_contents_with_transform
  1013.         ('s/\@PROGRAM\@/' . $one_file . '/go;'
  1014.          . 's/\@XPROGRAM\@/' . $xname . '/go;'
  1015.          . 's/\@XLINK\@/' . $xlink . '/go;',
  1016.          'program');
  1017.     }
  1018.  
  1019.     &handle_lib_objects ('', 'LDADD')
  1020.     if &variable_defined ('LDADD');
  1021. }
  1022.  
  1023. # Handle libraries.
  1024. sub handle_libraries
  1025. {
  1026.     local (@liblist) = &am_install_var ('-no-all', '-clean',
  1027.                     'libraries', 'LIBRARIES',
  1028.                     'lib', 'pkglib', 'noinst', 'check');
  1029.     return if ! @liblist;
  1030.  
  1031.     local (%valid) = &am_primary_prefixes ('LIBRARIES', 'lib', 'pkglib',
  1032.                        'noinst', 'check');
  1033.     if (! $seen_ranlib)
  1034.     {
  1035.     local ($key);
  1036.     foreach $key (keys %valid)
  1037.     {
  1038.         if (&variable_defined ($key . '_LIBRARIES'))
  1039.         {
  1040.         &am_line_error ($key . '_LIBRARIES', "library requires either \`AC_PROG_RANLIB' or `AM_PROG_LIBTOOL' in configure.in");
  1041.         # Only get this error once.
  1042.         $seen_ranlib = 1;
  1043.         last;
  1044.         }
  1045.     }
  1046.     }
  1047.  
  1048.     # Generate _LIBFILES variables.  Too bad we can't do this in
  1049.     # am_install_var.
  1050.     local ($onedir, $onelib);
  1051.     local (@outlist);
  1052.     local (@libfiles_list);
  1053.     foreach $onedir (keys %valid) 
  1054.     {
  1055.     if (&variable_defined ($onedir . '_LIBRARIES'))
  1056.     {
  1057.         @outlist = ();
  1058.         foreach $onelib (&variable_value_as_list ($onedir . '_LIBRARIES'))
  1059.         {
  1060.         push (@outlist, 'lib' . $onelib . '.a');
  1061.         }
  1062.         &pretty_print ($onedir . '_LIBFILES =', "", @outlist);
  1063.     }
  1064.  
  1065.     push (@libfiles_list, '$(' . $onedir . '_LIBFILES)')
  1066.         unless $onedir eq 'EXTRA';
  1067.     }
  1068.     push (@all, '$(LIBFILES)');
  1069.  
  1070.     local ($obj) = &get_object_extension;
  1071.     local ($munge);
  1072.     local ($xlib);
  1073.     foreach $onelib (@liblist)
  1074.     {
  1075.     # Canonicalize names.
  1076.     ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
  1077.     if ($xlib ne $onelib)
  1078.     {
  1079.         local ($xt);
  1080.         foreach $xt ('_LIBADD', '_SOURCES', '_OBJECTS', '_DEPENDENCIES')
  1081.         {
  1082.         &am_line_error ($one_file . $xt,
  1083.                 "invalid variable \`" . $onelib . $xt
  1084.                 . "'; should be \`" . $xlib . $xt . "'")
  1085.             if &variable_defined ($onelib . $xt);
  1086.         }
  1087.     }
  1088.  
  1089.     if (&variable_defined ($xlib . '_LIBADD'))
  1090.     {
  1091.         &handle_lib_objects ($xlib, $xlib . '_LIBADD');
  1092.     }
  1093.     else
  1094.     {
  1095.         # Generate support for conditional object inclusion in
  1096.         # libraries.
  1097.         $output_vars .= $xlib . "_LIBADD =\n";
  1098.     }
  1099.  
  1100.     &handle_source_transform ($xlib, $onelib, $obj);
  1101.  
  1102.     $output_rules .=
  1103.         &file_contents_with_transform ('s/\@LIBRARY\@/' . $onelib . '/go;'
  1104.                        . 's/\@XLIBRARY\@/'
  1105.                        . $xlib . '/go;',
  1106.                        'library');
  1107.     }
  1108.  
  1109.     # Turn "foo" into "libfoo.a" and include macro definition.
  1110.     grep (($_ = 'lib' . $_ . '.a') && 0, @liblist);
  1111.  
  1112.     if (! &variable_defined ('LIBFILES'))
  1113.     {
  1114.     &pretty_print ('LIBFILES = ', "", @libfiles_list);
  1115.     }
  1116.  
  1117.     if ($seen_libtool)
  1118.     {
  1119.     $output_vars .= ('AR = $(LIBTOOL) archive' . "\n"
  1120.              . 'RANLIB = $(LIBTOOL) ranlib' . "\n"
  1121.              . 'LCOMPILE = $(LIBTOOL) compile $(DEFS) $(INCLUDES)'
  1122.              . ' $(CPPFLAGS) $(CFLAGS)' . "\n");
  1123.     }
  1124.     else
  1125.     {
  1126.     $output_vars .= ('AR = ar' . "\n"
  1127.              . 'RANLIB = @RANLIB@' . "\n");
  1128.     }
  1129. }
  1130.  
  1131. # Handle scripts.
  1132. sub handle_scripts
  1133. {
  1134.     # NOTE we no longer automatically clean SCRIPTS, because it is
  1135.     # useful to sometimes distribute scripts verbatim.  This happens
  1136.     # eg in Automake itself.
  1137.     &am_install_var ('scripts', 'SCRIPTS',
  1138.              'bin', 'sbin', 'libexec', 'pkgdata',
  1139.              'noinst', 'check');
  1140.  
  1141.     # Set $scripts_installed if appropriate.  Make sure we only find
  1142.     # scripts which are actually installed -- this is why we can't
  1143.     # simply use the return value of am_install_var.
  1144.     local (%valid) = &am_primary_prefixes ('SCRIPTS', 'bin', 'sbin',
  1145.                        'libexec', 'pkgdata',
  1146.                        'noinst', 'check');
  1147.     local ($key);
  1148.     foreach $key (keys %valid)
  1149.     {
  1150.     if ($key ne 'noinst'
  1151.         && $key ne 'check'
  1152.         && &variable_defined ($key . '_SCRIPTS'))
  1153.     {
  1154.         $scripts_installed = 1;
  1155.         last;
  1156.     }
  1157.     }
  1158.  
  1159.     if ($scripts_installed)
  1160.     {
  1161.     # If a program is installed, this is required.  We only want this
  1162.     # error to appear once.
  1163.     &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
  1164.         unless $seen_arg_prog;
  1165.     $seen_arg_prog = 1;
  1166.     }
  1167. }
  1168.  
  1169. # Search a file for a "version.texi" Texinfo include.  Return the name
  1170. # of the include file if found, or the empty string if not.  A
  1171. # "version.texi" file is actually any file whose name matches
  1172. # "vers*.texi".
  1173. sub grep_for_vers_texi
  1174. {
  1175.     local ($filename) = @_;
  1176.  
  1177.     if (! open (TEXI, $filename))
  1178.     {
  1179.     &am_error ("couldn't open \`$filename': $!");
  1180.     return '';
  1181.     }
  1182.     print "automake: reading $filename\n" if $verbose;
  1183.  
  1184.     while (<TEXI>)
  1185.     {
  1186.     if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
  1187.     {
  1188.         # Found it.
  1189.         close (TEXI);
  1190.         return $1;
  1191.     }
  1192.     }
  1193.  
  1194.     close (TEXI);
  1195.     return '';
  1196. }
  1197.  
  1198. # Handle all Texinfo source.
  1199. sub handle_texinfo
  1200. {
  1201.     &am_line_error ('TEXINFOS',
  1202.             "\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
  1203.     if &variable_defined ('TEXINFOS');
  1204.     return if (! &variable_defined ('info_TEXINFOS')
  1205.            && ! &variable_defined ('html_TEXINFOS'));
  1206.  
  1207.     local (@texis) = &variable_value_as_list ('info_TEXINFOS');
  1208.  
  1209.     local (@infos_list, @info_deps_list, @dvis_list, @texi_deps);
  1210.  
  1211.     if ($on_amiga) { local (@guides_list, @guide_deps_list); }
  1212.  
  1213.     local ($infobase, $info_cursor);
  1214.     local (%versions);
  1215.     local ($done) = 0;
  1216.     local ($vti);
  1217.     local ($tc_cursor, @texi_cleans);
  1218.     local ($canonical);
  1219.  
  1220.     foreach $info_cursor (@texis)
  1221.     {
  1222.     ($infobase = $info_cursor) =~ s/\.texi(nfo)?$//;
  1223.  
  1224.     # If 'version.texi' is referenced by input file, then include
  1225.     # automatic versioning capability.
  1226.     local ($vtexi)
  1227.         = &grep_for_vers_texi ($relative_dir . "/" . $info_cursor);
  1228.     if ($vtexi)
  1229.     {
  1230.         &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
  1231.         if (defined $versions{$vtexi});
  1232.         $versions{$vtexi} = $info_cursor;
  1233.  
  1234.         # We number the stamp-vti files.  This is doable since the
  1235.         # actual names don't matter much.  We only number starting
  1236.         # with the second one, so that the common case looks nice.
  1237.         $vti = 'vti' . ($done ? $done : '');
  1238.         &push_dist_common ($vtexi, 'stamp-' . $vti);
  1239.         push (@clean, $vti);
  1240.  
  1241.         # Only require once.
  1242.         &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
  1243.                       'mdate-sh')
  1244.         if ! $done;
  1245.         ++$done;
  1246.  
  1247.         local ($conf_pat);
  1248.         ($conf_pat = $config_aux_dir) =~ s/(\W)/\\$1/g;
  1249.         $output_rules .=
  1250.         &file_contents_with_transform
  1251.             ('s/\@TEXI\@/' . $info_cursor . '/g; '
  1252.              . 's/\@VTI\@/' . $vti . '/g; '
  1253.              . 's/\@VTEXI\@/' . $vtexi . '/g;'
  1254.              . 's,\@MDDIR\@,' . $conf_pat . ',g;',
  1255.              'texi-version');
  1256.  
  1257.         &push_phony_cleaners ($vti);
  1258.     }
  1259.  
  1260.     # If user specified file_TEXINFOS, then use that as explicit
  1261.     # dependency list.
  1262.     @texi_deps = ();
  1263.     push (@texi_deps, $info_cursor);
  1264.     push (@texi_deps, $vtexi) if $vtexi;
  1265.  
  1266.     # Canonicalize name first.
  1267.     ($canonical = $infobase) =~ tr/A-Za-z0-9_/_/c;
  1268.     if (&variable_defined ($canonical . "_TEXINFOS"))
  1269.     {
  1270.         push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
  1271.         &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
  1272.     }
  1273.  
  1274.     if ($on_amiga)
  1275.     {
  1276.     $output_rules .= ("\n" . $infobase . ".info: "
  1277.               . join (' ', @texi_deps)
  1278.               . "\n" . $infobase . ".guide: "
  1279.               . join (' ', @texi_deps)
  1280.               . "\n" . $infobase . ".dvi: "
  1281.               . join (' ', @texi_deps)
  1282.               . "\n\n");
  1283.     } 
  1284.     else
  1285.     {
  1286.     $output_rules .= ("\n" . $infobase . ".info: "
  1287.               . join (' ', @texi_deps)
  1288.               . "\n" . $infobase . ".dvi: "
  1289.               . join (' ', @texi_deps)
  1290.               . "\n\n");
  1291.     }
  1292.  
  1293.     # FIXME: this distributes too much.  How to find out precisely
  1294.     # which files will be generated by `makeinfo'?
  1295.     push (@infos_list, $infobase . '.info', $infobase . '.info[-0-9]*');
  1296.     push (@info_deps_list, $infobase . '.info');
  1297.     if ($on_amiga)
  1298.     {
  1299.         push (@guides_list, $infobase . '.guide*');
  1300.         push (@guide_deps_list, $infobase . '.guide');
  1301.     }
  1302.     push (@dvis_list, $infobase . '.dvi');
  1303.  
  1304.     # Generate list of things to clean for this target.  We do
  1305.     # this explicitly because otherwise too many things could be
  1306.     # removed.  In particular the ".log" extension might
  1307.     # reasonably be used in other contexts by the user.
  1308.     foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns',
  1309.                 'ky', 'log', 'pg', 'toc', 'tp', 'vr', 'op')
  1310.     {
  1311.         push (@texi_cleans, $infobase . '.' . $tc_cursor);
  1312.     }
  1313.     }
  1314.  
  1315.     # Some boilerplate.
  1316.     $output_vars .= &file_contents ('texinfos-vars');
  1317.     $output_rules .= &file_contents ('texinfos');
  1318.     push (@phony, 'install-info', 'uninstall-info');
  1319.  
  1320.     if ($on_amiga) { 
  1321.     $output_vars .= &file_contents ('guide-vars');
  1322.     $output_rules .= &file_contents ('guide');
  1323.     push(@phony, 'install-guide', 'uninstall-guide');
  1324.     }
  1325.  
  1326.     # How to clean.
  1327.     if ($on_amiga) {
  1328.     $output_rules .= "\nmostlyclean-guide:\n";
  1329.     &pretty_print_rule ("\trm -f", "\t  ", @texi_cleans);
  1330.     $output_rules .= ("\nclean-guide:\n\ndistclean-guide:\n\n"
  1331.               . "maintainer-clean-guide:\n\t"
  1332.               . 'rm -f $(GUIDES)' . "\n");
  1333.     &push_phony_cleaners ('guide');
  1334.     }
  1335.     $output_rules .= "\nmostlyclean-info:\n";
  1336.     &pretty_print_rule ("\trm -f", "\t  ", @texi_cleans);
  1337.     $output_rules .= ("\nclean-info:\n\ndistclean-info:\n\n"
  1338.               . "maintainer-clean-info:\n\t"
  1339.               . 'rm -f $(INFOS)' . "\n");
  1340.     &push_phony_cleaners ('info');
  1341.  
  1342.     push (@suffixes, '.texi', '.texinfo', '.info', '.dvi');
  1343.     if ($on_amiga) { push (@suffixes, '.guide'); }
  1344.  
  1345.     if (! defined $options{'no-installinfo'})
  1346.     {
  1347.     push (@uninstall, 'uninstall-info');
  1348.     push (@installdirs, '$(infodir)');
  1349.     unshift (@install_data, 'install-info');
  1350.     if ($on_amiga) {
  1351.         push (@uninstall, 'uninstall-guide');
  1352.         push (@installdirs, '$(guidedir)');
  1353.         unshift (@install_data, 'install-guide');
  1354.     }
  1355.  
  1356.     # Make sure documentation is made and installed first.  Use
  1357.     # $(INFO_DEPS), not 'info', because otherwise recursive makes
  1358.     # get run twice during "make all".
  1359.     unshift (@all, '$(INFO_DEPS)');
  1360.     if ($on_amiga) { unshift (@all, '$(GUIDE_DEPS)'); }
  1361.     }
  1362.     push (@clean, 'info');
  1363.     push (@info, '$(INFO_DEPS)');
  1364.     if ($on_amiga) { 
  1365.         push (@clean, 'guide');
  1366.         push (@guide, '$(GUIDE_DEPS)'); 
  1367. }
  1368.     push (@dvi, '$(DVIS)');
  1369.  
  1370. if ($on_amiga) {
  1371.     $output_vars .= ("INFOS = " . join (' ', @infos_list) . "\n"
  1372.              . "INFO_DEPS = " . join (' ', @info_deps_list)  . "\n"
  1373.              . "GUIDES = " . join (' ', @guides_list) . "\n"
  1374.              . "GUIDE_DEPS = " . join (' ', @guide_deps_list)  . "\n"
  1375.              . "DVIS = " . join (' ', @dvis_list) . "\n"
  1376.              # This next isn't strictly needed now -- the
  1377.              # places that look here could easily be changed
  1378.              # to look in info_TEXINFOS.  But this is probably
  1379.              # better, in case noinst_TEXINFOS is ever
  1380.              # supported.
  1381.              . "TEXINFOS = " . $contents{'info_TEXINFOS'} . "\n\n");
  1382. }
  1383. else 
  1384. {
  1385.     $output_vars .= ("INFOS = " . join (' ', @infos_list) . "\n"
  1386.              . "INFO_DEPS = " . join (' ', @info_deps_list)  . "\n"
  1387.              . "DVIS = " . join (' ', @dvis_list) . "\n"
  1388.              # This next isn't strictly needed now -- the
  1389.              # places that look here could easily be changed
  1390.              # to look in info_TEXINFOS.  But this is probably
  1391.              # better, in case noinst_TEXINFOS is ever
  1392.              # supported.
  1393.              . "TEXINFOS = " . $contents{'info_TEXINFOS'} . "\n\n");
  1394. }
  1395.  
  1396.     # Do some error checking.
  1397.     &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex');
  1398. }
  1399.  
  1400. # Handle any man pages.
  1401. sub handle_man_pages
  1402. {
  1403.     &am_line_error ('MANS', "\`MANS' is an anachronism; use \`man_MANS'")
  1404.     if &variable_defined ('MANS');
  1405.     return if ! &variable_defined ('man_MANS');
  1406.  
  1407.     # We generate the manpage install code by hand to avoid the use of
  1408.     # basename in the generated Makefile.
  1409.     local (@mans) = &variable_value_as_list ('man_MANS');
  1410.     local (%sections, %inames, %mbases, %secmap, %fullsecmap);
  1411.     local ($i) = 1;
  1412.     foreach (@mans)
  1413.     {
  1414.     # FIXME: statement without effect:
  1415.     /^(.*)\.([0-9])([a-z]*)$/;
  1416.     $sections{$2} = 1;
  1417.     $inames{$i} = $_;
  1418.     $mbases{$i} = $1;
  1419.     $secmap{$i} = $2;
  1420.     $fullsecmap{$i} = $2 . $3;
  1421.     $i++;
  1422.     }
  1423.  
  1424.     # We don't really need this, but we use it in case we ever want to
  1425.     # support noinst_MANS.
  1426.     $output_vars .= "MANS = " . $contents{'man_MANS'} . "\n";
  1427.  
  1428.     # Generate list of install dirs.
  1429.     $output_rules .= "install-man: \$(MANS)\n";
  1430.     $output_rules .= "\t\$(NORMAL_INSTALL)\n";
  1431.     foreach (keys %sections)
  1432.     {
  1433.     push (@installdirs, '$(mandir)/man' . $_)
  1434.         unless defined $options{'no-installman'};
  1435.     $output_rules .= ("\t" . '$(mkinstalldirs) $(mandir)/man'
  1436.               . $_ . "\n");
  1437.     }
  1438.     push (@phony, 'install-man');
  1439.  
  1440.     # Generate install target.
  1441.     local ($key);
  1442.     foreach $key (keys %inames)
  1443.     {
  1444.     $_ = $install_man_format;
  1445.     s/\@SECTION\@/$secmap{$key}/g;
  1446.     s/\@MAN\@/$inames{$key}/g;
  1447.     s/\@FULLSECT\@/$fullsecmap{$key}/g;
  1448.     s/\@MANBASE\@/$mbases{$key}/g;
  1449.     $output_rules .= $_;
  1450.     }
  1451.     $output_rules .= "\n";
  1452.  
  1453.     $output_rules .= "uninstall-man:\n";
  1454.     foreach $key (keys %inames)
  1455.     {
  1456.     $_ = $uninstall_man_format;
  1457.     s/\@SECTION\@/$secmap{$key}/g;
  1458.     s/\@MAN\@/$inames{$key}/g;
  1459.     s/\@FULLSECT\@/$fullsecmap{$key}/g;
  1460.     s/\@MANBASE\@/$mbases{$key}/g;
  1461.     $output_rules .= $_;
  1462.     }
  1463.     $output_rules .= "\n";
  1464.     push (@phony, 'uninstall-man');
  1465.  
  1466.     $output_vars .= &file_contents ('mans-vars');
  1467.  
  1468.     if (! defined $options{'no-installman'})
  1469.     {
  1470.     push (@install_data, 'install-man');
  1471.     push (@uninstall, 'uninstall-man');
  1472.     push (@all, '$(MANS)');
  1473.     }
  1474. }
  1475.  
  1476. # Handle DATA variables.
  1477. sub handle_data
  1478. {
  1479.     &am_install_var ('data', 'DATA', 'data', 'sysconf',
  1480.              'sharedstate', 'localstate', 'pkgdata',
  1481.              'noinst', 'check');
  1482. }
  1483.  
  1484. # Handle TAGS.
  1485. sub handle_tags
  1486. {
  1487.     local ($tagging) = 0;
  1488.  
  1489.     push (@phony, 'tags');
  1490.     if (&variable_defined ('SUBDIRS'))
  1491.     {
  1492.     $output_rules .= &file_contents ('tags');
  1493.     push (@phony, 'tags-recursive');
  1494.     $tagging = 1;
  1495.     }
  1496.     elsif ($dir_holds_sources
  1497.        || $dir_holds_headers
  1498.        || &variable_defined ('ETAGS_ARGS'))
  1499.     {
  1500.     $output_rules .= &file_contents ('tags-subd');
  1501.     $tagging = 1;
  1502.     }
  1503.  
  1504.     if ($tagging)
  1505.     {
  1506.     $output_rules .= &file_contents ('tags-clean');
  1507.     push (@clean, 'tags');
  1508.     &push_phony_cleaners ('tags');
  1509.     }
  1510.     else
  1511.     {
  1512.     # Every Makefile must define some sort of TAGS rule.
  1513.     # Otherwise, it would be possible for a top-level "make TAGS"
  1514.     # to fail because some subdirectory failed.
  1515.     $output_rules .= "tags: TAGS\nTAGS:\n\n";
  1516.     }
  1517. }
  1518.  
  1519. # Worker for handle_dist.
  1520. sub handle_dist_worker
  1521. {
  1522.     $output_rules .= 'distdir: $(DEP_DISTFILES)' . "\n";
  1523.  
  1524.     # Initialization; only at top level.
  1525.     if ($relative_dir eq '.')
  1526.     {
  1527.     if ($strictness >= $GNITS)
  1528.     {
  1529.         # For Gnits users, this is pretty handy.  Look at 15 lines
  1530.         # in case some explanatory text is desirable.
  1531.         $output_rules .= '    @if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" > /dev/null; then :; else \\
  1532.       echo "NEWS not updated; not releasing" 1>&2; \\
  1533.       exit 1;                \\
  1534.     fi
  1535. ';
  1536.     }
  1537.  
  1538.  
  1539.     $output_rules .=
  1540.         # Create dist directory.
  1541.         '    rm -rf $(distdir)
  1542.     mkdir $(distdir)
  1543.     -chmod 755 $(distdir)
  1544. ';
  1545.  
  1546.     # Only run automake in `dist' target if --include-deps not
  1547.     # specified.  That way the recipient of a distribution can run
  1548.     # "make dist" and not need Automake.
  1549.     if ($cmdline_use_dependencies)
  1550.     {
  1551.         $output_rules .=
  1552.         (
  1553.          # We need an absolute path for --output-dir.  Thus the
  1554.          # weirdness.
  1555.          '    here=`pwd`; distdir=`cd $(distdir) && pwd` \\
  1556.       && cd $(srcdir) \\
  1557.       && automake --include-deps --build-dir=$$here --srcdir-name=$(srcdir) --output-dir=$$distdir --strictness='
  1558.          # Set strictness of output.
  1559.          . $strictness_name . "\n"
  1560.          );
  1561.     }
  1562.     }
  1563.  
  1564.     # In loop, test for file existence because sometimes a file gets
  1565.     # included in DISTFILES twice.  For example this happens when a
  1566.     # single source file is used in building more than one program.
  1567.     # Also, there are situations in which "ln" can fail.  For instance
  1568.     # a file to distribute could actually be a cross-filesystem
  1569.     # symlink -- this can easily happen if "gettextize" was run on the
  1570.     # distribution.  Note that DISTFILES can contain a wildcard (for
  1571.     # info files, sigh), so we must use the echo trick.
  1572.     $output_rules .= '    @for file in `cd $(srcdir) && echo $(DISTFILES)`; do \\
  1573.       test -f $(distdir)/$$file \\
  1574.       || ln $(srcdir)/$$file $(distdir)/$$file 2> /dev/null \\
  1575.       || cp -p $(srcdir)/$$file $(distdir)/$$file; \\
  1576.     done
  1577. ';
  1578.  
  1579.     # If we have SUBDIRS, create all dist subdirectories and do
  1580.     # recursive build.
  1581.     if (&variable_defined ('SUBDIRS'))
  1582.     {
  1583.     # Test for directory existence here because previous automake
  1584.     # invocation might have created some directories.  Note that
  1585.     # we explicitly set distdir for the subdir make; that lets us
  1586.     # mix-n-match many automake-using packages into one large
  1587.     # package, and have "dist" at the top level do the right
  1588.     # thing.
  1589.     $output_rules .= '    for subdir in $(SUBDIRS); do        \\
  1590.       test -d $(distdir)/$$subdir        \\
  1591.       || mkdir $(distdir)/$$subdir        \\
  1592.       || exit 1;                \\
  1593.       chmod 755 $(distdir)/$$subdir;    \\
  1594.       (cd $$subdir && $(MAKE) distdir=../$(distdir)/$$subdir distdir) \\
  1595.         || exit 1; \\
  1596.     done
  1597. ';
  1598.     }
  1599.  
  1600.     # If the target `dist-hook' exists, run it now.  This allows
  1601.     # users to do random weird things to the distribution before it is
  1602.     # packaged up.
  1603.     if (defined $contents{'dist-hook'})
  1604.     {
  1605.     $output_rules .= "\t\$(MAKE) dist-hook\n";
  1606.     }
  1607.  
  1608.     push (@phony, 'distdir');
  1609. }
  1610.  
  1611. # Handle 'dist' target.
  1612. sub handle_dist
  1613. {
  1614.     # Set up maint_charset.
  1615.     $local_maint_charset = $contents{'MAINT_CHARSET'}
  1616.     if &variable_defined ('MAINT_CHARSET');
  1617.     $maint_charset = $local_maint_charset
  1618.     if $relative_dir eq '.';
  1619.  
  1620.     if (&variable_defined ('DIST_CHARSET'))
  1621.     {
  1622.     &am_line_error ('DIST_CHARSET',
  1623.             "DIST_CHARSET defined but no MAINT_CHARSET defined")
  1624.         if ! $local_maint_charset;
  1625.     if ($relative_dir eq '.')
  1626.     {
  1627.         $dist_charset = $contents{'DIST_CHARSET'}
  1628.     }
  1629.     else
  1630.     {
  1631.         &am_line_error ('DIST_CHARSET',
  1632.                 "DIST_CHARSET can only be defined at top level");
  1633.     }
  1634.     }
  1635.  
  1636.     # Look for common files that should be included in distribution.
  1637.     local ($cfile);
  1638.     foreach $cfile (@common_files)
  1639.     {
  1640.     if (-f ($relative_dir . "/" . $cfile))
  1641.     {
  1642.         &push_dist_common ($cfile);
  1643.     }
  1644.     }
  1645.  
  1646.     # Keys of %dist_common are names of files to distributed.  We put
  1647.     # README first because it then becomes easier to make a
  1648.     # Usenet-compliant shar file (in these, README must be first).
  1649.     # FIXME: do more ordering of files here.
  1650.     local (@coms);
  1651.     if (defined $dist_common{'README'})
  1652.     {
  1653.     push (@coms, 'README');
  1654.     undef $dist_common{'README'};
  1655.     }
  1656.     push (@coms, sort keys %dist_common);
  1657.  
  1658.     &pretty_print ("DIST_COMMON =", "", @coms);
  1659.     $output_vars .= "\n";
  1660.  
  1661.     # Some boilerplate.
  1662.     if ($on_amiga) 
  1663.     {
  1664.     $output_vars .= &file_contents ('amiga-dist-vars');
  1665.     }
  1666.     else 
  1667.     {
  1668.     $output_vars .= &file_contents ('dist-vars');
  1669.     }
  1670.  
  1671.     # Put these things in rules section so it is easier for whoever
  1672.     # reads Makefile.in.
  1673.     if (! &variable_defined ('distdir'))
  1674.     {
  1675.     if ($relative_dir eq '.')
  1676.     {
  1677.         $output_rules .= "\n" . 'distdir = $(PACKAGE)-$(VERSION)' . "\n";
  1678.     }
  1679.     else
  1680.     {
  1681.         $output_rules .= ("\n"
  1682.                   . 'distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)'
  1683.                   . "\n");
  1684.     }
  1685.     }
  1686.     if ($relative_dir ne '.')
  1687.     {
  1688.     $output_rules .= "\nsubdir = " . $relative_dir . "\n";
  1689.     }
  1690.  
  1691.     # Generate 'dist' target, and maybe dist-shar / dist-zip / dist-tarZ.
  1692.     if ($relative_dir eq '.')
  1693.     {
  1694.     # Rule to check whether a distribution is viable.
  1695.     $output_rules .= ('# This target untars the dist file and tries a VPATH configuration.  Then
  1696. # it guarantees that the distribution is self-contained by making another
  1697. # tarfile.
  1698. distcheck: dist
  1699.     rm -rf $(distdir)
  1700.     $(TAR) zxf $(distdir).tar.gz
  1701.     mkdir $(distdir)/=build
  1702.     mkdir $(distdir)/=inst
  1703.     dc_install_base=`cd $(distdir)/=inst && pwd`; \\'
  1704.               . (defined $contents{'distcheck-hook'}
  1705.                  ? "\t\$(MAKE) distcheck-hook"
  1706.                  : '')
  1707.               . '
  1708.     cd $(distdir)/=build \\
  1709.       && ../configure '
  1710.  
  1711.               . ($seen_gettext ? '--with-included-gettext ' : '')
  1712.               . '--srcdir=.. --prefix=$$dc_install_base \\
  1713.       && $(MAKE) \\
  1714.       && $(MAKE) dvi \\
  1715.       && $(MAKE) check \\
  1716.       && $(MAKE) install \\
  1717.       && $(MAKE) installcheck \\
  1718.       && $(MAKE) dist
  1719.     rm -rf $(distdir)
  1720.     @echo "========================"; \\
  1721.     echo "$(distdir).tar.gz is ready for distribution"; \\
  1722.     echo "========================"
  1723. ');
  1724.  
  1725.     $output_rules .= 'dist: distdir' . "\n\t";
  1726.     # Ignore return result from chmod, because it might give an
  1727.     # error if we chmod a symlink.
  1728.     $output_rules .= '-chmod -R a+r $(distdir)' . "\n\t";
  1729.     $output_rules .= '$(TAR) chozf $(distdir).tar.gz $(distdir)';
  1730.     $output_rules .= "\n\t" . 'rm -rf $(distdir)' . "\n";
  1731.  
  1732.     if (defined $options{'dist-shar'})
  1733.     {
  1734.         $output_rules .= 'dist-shar: distdir' . "\n\t";
  1735.         # Ignore return result from chmod, because it might give
  1736.         # an error if we chmod a symlink.
  1737.         $output_rules .= '-chmod -R a+r $(distdir)' . "\n\t";
  1738.         $output_rules .= 'shar $(distdir) | gzip > $(distdir).shar.gz';
  1739.         $output_rules .= "\n\t" . 'rm -rf $(distdir)' . "\n";
  1740.     }
  1741.  
  1742.     if (defined $options{'dist-zip'})
  1743.     {
  1744.         $output_rules .= 'dist-zip: distdir' . "\n\t";
  1745.         $output_rules .= '-chmod -R a+r $(distdir)' . "\n\t";
  1746.         $output_rules .= 'zip -rq $(distdir).zip $(distdir)';
  1747.         $output_rules .= "\n\t" . 'rm -rf $(distdir)' . "\n";
  1748.     }
  1749.  
  1750.     if (defined $options{'dist-tarZ'})
  1751.     {
  1752.         $output_rules .= 'dist-tarZ: distdir' . "\n\t";
  1753.         $output_rules .= '-chmod -R a+r $(distdir)' . "\n\t";
  1754.         $output_rules .= '$(TAR) chf - $(distdir) | compress -c > $(distdir).tar.Z';
  1755.         $output_rules .= "\n\t" . 'rm -rf $(distdir)' . "\n";
  1756.     }
  1757.     }
  1758.  
  1759.     # Generate distdir target.
  1760.     &handle_dist_worker;
  1761. }
  1762.  
  1763. # Scan a single dependency file and rewrite the dependencies as
  1764. # appropriate.  Essentially this means:
  1765. # * Clean out absolute dependencies which are not desirable.
  1766. # * Rewrite other dependencies to be relative to $(top_srcdir).
  1767. sub scan_dependency_file
  1768. {
  1769.     local ($depfile) = @_;
  1770.  
  1771.     if (! open (DEP_FILE, $depfile))
  1772.     {
  1773.     &am_error ("couldn't open \`$depfile': $!");
  1774.     return;
  1775.     }
  1776.     print "automake: reading $depfile\n" if $verbose;
  1777.  
  1778.     local ($first_line) = 1;
  1779.     local ($last_line) = 0;
  1780.     local ($target, @dependencies);
  1781.     local ($one_dep, $xform);
  1782.  
  1783.     local ($srcdir_rx, $fixup_rx, $fixup2_rx);
  1784.     ($srcdir_rx = $srcdir_name) =~ s/(\W)/\\$1/g;
  1785.  
  1786.     # If the top srcdir is absolute, then the current directory is
  1787.     # just relative_dir.
  1788.     ($fixup_rx = $srcdir_name . '/' . $relative_dir . '/') =~ s/(\W)/\\$1/g;
  1789.  
  1790.     # But if the top srcdir is relative, then we need some dots first.
  1791.     ($fixup2_rx = ($srcdir_name . '/' . $top_builddir . '/'
  1792.            . $relative_dir . '/')) =~ s/(\W)/\\$1/g;
  1793.  
  1794.     while (<DEP_FILE>)
  1795.     {
  1796.     if ($last_line)
  1797.     {
  1798.         # If LAST_LINE set then we've already seen what we thought
  1799.         # was the last line.
  1800.         goto bad_format;
  1801.     }
  1802.     next if (/$WHITE_PATTERN/o);
  1803.     chop;
  1804.     if (! s/\\$//)
  1805.     {
  1806.         # No trailing "\" means this should be the last line.
  1807.         $last_line = 1;
  1808.     }
  1809.  
  1810.     if ($first_line)
  1811.     {
  1812.         if (! /^([^:]+:)(.+)$/)
  1813.         {
  1814.           bad_format:
  1815.         &am_error ("\`$depfile' has incorrect format");
  1816.         close (DEP_FILE);
  1817.         return;
  1818.         }
  1819.  
  1820.         $target = $1;
  1821.         $_ = $2;
  1822.  
  1823.         $first_line = 0;
  1824.     }
  1825.  
  1826.     foreach $one_dep (split (' ', $_))
  1827.     {
  1828.         if ($one_dep =~ /^$fixup_rx/)
  1829.         {
  1830.         # The dependency points to the current directory in
  1831.         # some way.
  1832.         ($xform = $one_dep) =~ s/^$fixup_rx//;
  1833.         push (@dependencies, $xform);
  1834.         }
  1835.         elsif ($one_dep =~ /^$fixup2_rx/)
  1836.         {
  1837.         # The dependency points to the current directory in
  1838.         # some way.
  1839.         ($xform = $one_dep) =~ s/^$fixup2_rx//;
  1840.         push (@dependencies, $xform);
  1841.         }
  1842.         elsif ($one_dep =~ /^$srcdir_rx\//)
  1843.         {
  1844.         # The dependency is in some other directory in the package.
  1845.         ($xform = $one_dep) =~ s/^$srcdir_rx/$top_builddir/;
  1846.         push (@dependencies, $xform);
  1847.         }
  1848.         elsif ($one_dep =~ /^\//)
  1849.         {
  1850.         # Absolute path; ignore.
  1851.         }
  1852.         else
  1853.         {
  1854.         # Anything else is assumed to be correct.
  1855.         push (@dependencies, $one_dep);
  1856.         }
  1857.     }
  1858.     }
  1859.  
  1860.     &pretty_print_rule ($target, "\t", @dependencies);
  1861.  
  1862.     close (DEP_FILE);
  1863. }
  1864.  
  1865. # Handle auto-dependency code.
  1866. sub handle_dependencies
  1867. {
  1868.     if ($use_dependencies)
  1869.     {
  1870.     # Include GNU-make-specific auto-dep code.
  1871.     if ($dir_holds_sources)
  1872.     {
  1873.         &pretty_print ('DEP_FILES =', "", sort keys %dep_files);
  1874.         $output_rules .= &file_contents ('depend');
  1875.         push (@clean, 'depend');
  1876.         &push_phony_cleaners ('depend');
  1877.         $output_rules .=
  1878.         &file_contents_with_transform ('s/\@EXT\@/.c/g;'
  1879.                            . 's/\@MKDEP\@/MKDEP/g',
  1880.                            'depend2');
  1881.         local ($ext);
  1882.         local ($need_cxx) = 0;
  1883.         foreach $ext (keys %cxx_extensions)
  1884.         {
  1885.         $output_rules .=
  1886.             &file_contents_with_transform ('s/\@EXT\@/' . $ext .'/g;'
  1887.                            . 's/\@MKDEP\@/CXXMKDEP/g',
  1888.                            'depend2');
  1889.         $need_cxx = 1;
  1890.         }
  1891.         if ($need_cxx)
  1892.         {
  1893.         $output_vars .= 'CXXMKDEP = $(CXX) -MM $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)' . "\n";
  1894.         }
  1895.     }
  1896.     }
  1897.     else
  1898.     {
  1899.     # FIXME: consider requiring --build-dir here.  What about case
  1900.     # where this is done via an option?
  1901.  
  1902.     # Include any auto-generated deps that are present.  Note that
  1903.     # $build_directory ends in a "/".
  1904.     if (-d ($build_directory . $relative_dir . "/.deps")
  1905.         && -f ($build_directory . $relative_dir . "/.deps/.P"))
  1906.     {
  1907.         local ($depfile);
  1908.         local ($gpat) = $build_directory . $relative_dir . "/.deps/*.P";
  1909.  
  1910.         foreach $depfile (<${gpat}>)
  1911.         {
  1912.         &scan_dependency_file ($depfile);
  1913.         }
  1914.  
  1915.         $output_rules .= "\n";
  1916.     }
  1917.     }
  1918. }
  1919.  
  1920. # Handle subdirectories.
  1921. sub handle_subdirs
  1922. {
  1923.     if (! &variable_defined ('SUBDIRS'))
  1924.     {
  1925.     &am_conf_error
  1926.         ("ud_GNU_GETTEXT in configure.in but SUBDIRS not defined")
  1927.         if $seen_gettext && $relative_dir eq '.';
  1928.     return;
  1929.     }
  1930.  
  1931.     &require_file_with_conf_line ($ac_gettext_line, $FOREIGN, 'ABOUT-NLS')
  1932.     if $seen_gettext;
  1933.  
  1934.     return if ! &variable_defined ('SUBDIRS');
  1935.  
  1936.     # Make sure each directory mentioned in SUBDIRS actually exists.
  1937.     local ($dir);
  1938.     foreach $dir (&variable_value_as_list ('SUBDIRS'))
  1939.     {
  1940.     # Skip directories substituted by configure.
  1941.     next if $dir =~ /^\@.*\@$/;
  1942.     &am_line_error ('SUBDIRS',
  1943.             "required directory $relative_dir/$dir does not exist")
  1944.         if ! -d $relative_dir . '/' . $dir;
  1945.     }
  1946.  
  1947.     if ($on_amiga) 
  1948.     {    
  1949.         $output_rules .= &file_contents ('amiga-subdirs');
  1950.     }
  1951.     else
  1952.     {
  1953.         $output_rules .= &file_contents ('subdirs');
  1954.     }
  1955.  
  1956.     # Push a bunch of phony targets.
  1957.     local ($phonies);
  1958.     foreach $phonies ('-data', '-exec', 'dirs')
  1959.     {
  1960.     push (@phony, 'install' . $phonies . '-recursive');
  1961.     push (@phony, 'uninstall' . $phonies . '-recursive');
  1962.     }
  1963.     foreach $phonies ('all', 'check', 'installcheck', 'info', 'guide', 'dvi')
  1964.     {
  1965.     push (@phony, $phonies . '-recursive');
  1966.     }
  1967.     &push_phony_cleaners ('recursive');
  1968.  
  1969.     push (@check, "check-recursive");
  1970.     push (@installcheck, "installcheck-recursive");
  1971.     push (@info, "info-recursive");
  1972.     if ($on_amiga) { push (@guide, "guide-recursive"); }
  1973.     push (@dvi, "dvi-recursive");
  1974.  
  1975.     $recursive_install = 1;
  1976. }
  1977.  
  1978. # Handle aclocal.m4.
  1979. sub handle_aclocal_m4
  1980. {
  1981.     local ($regen_aclocal) = 0;
  1982.     if (-f 'aclocal.m4')
  1983.     {
  1984.     $output_vars .= "ACLOCAL = aclocal.m4\n";
  1985.     &push_dist_common ('aclocal.m4');
  1986.  
  1987.     if (open (ACLOCAL, '< aclocal.m4'))
  1988.     {
  1989.         local ($line);
  1990.         $line = <ACLOCAL>;
  1991.         close (ACLOCAL);
  1992.  
  1993.         if ($line =~ 'generated automatically by aclocal')
  1994.         {
  1995.         $regen_aclocal = 1;
  1996.         }
  1997.     }
  1998.     }
  1999.  
  2000.     local ($acinclude) = 0;
  2001.     if (-f 'acinclude.m4')
  2002.     {
  2003.     $regen_aclocal = 1;
  2004.     $acinclude = 1;
  2005.     }
  2006.     else
  2007.     {
  2008.     # FIXME: how to tell if aclocal.m4 should be automatically
  2009.     # regenerated?
  2010.     }
  2011.  
  2012.     if ($regen_aclocal)
  2013.     {
  2014.     $output_rules .= ("aclocal.m4: "
  2015.               . ($seen_maint_mode ? "\@MAINT\@" : "")
  2016.               . "configure.in"
  2017.               . ($acinclude ? ' acinclude.m4' : '')
  2018.               . "\n\t"
  2019.               . 'cd $(srcdir) && aclocal'
  2020.               . "\n");
  2021.     }
  2022. }
  2023.  
  2024. # Handle remaking and configure stuff.
  2025. sub handle_configure
  2026. {
  2027.     # If SUBDIRS defined, require AC_PROG_MAKE_SET.
  2028.     &am_line_error ('SUBDIRS', "AC_PROG_MAKE_SET must be used in configure.in")
  2029.     if &variable_defined ('SUBDIRS') && ! $seen_make_set;
  2030.  
  2031.     local ($top_reldir);
  2032.     if ($relative_dir ne '.')
  2033.     {
  2034.     # In subdirectory.
  2035.     $output_rules .= &file_contents ('remake-subd');
  2036.     $top_reldir = '../';
  2037.     }
  2038.     else
  2039.     {
  2040.     &handle_aclocal_m4;
  2041.     $output_rules .= &file_contents_with_transform ('s/\@STRICTNESS\@/'
  2042.                             . $strictness_name
  2043.                             . '/g',
  2044.                             'remake');
  2045.  
  2046.     &am_error
  2047.         ("\`install.sh' is an anachronism; use \`install-sh' instead")
  2048.         if -f $relative_dir . '/install.sh';
  2049.  
  2050.     # If we have a configure header, require it.
  2051.     if ($config_header)
  2052.     {
  2053.         # FIXME: this restriction should be lifted.
  2054.         # FIXME: first see if it is even needed as-is.
  2055.         &am_conf_line_error ($config_header_line,
  2056.                  "argument to AC_CONFIG_HEADER contains \`/'\n")
  2057.         if ($config_header =~ /\//);
  2058.  
  2059.         &require_file_with_conf_line ($config_header_line,
  2060.                       $FOREIGN, $config_header);
  2061.  
  2062.         # Header defined and in this directory.
  2063.         if (-f 'acconfig.h')
  2064.         {
  2065.         $output_vars .= "ACCONFIG = acconfig.h\n";
  2066.         &push_dist_common ('acconfig.h');
  2067.         }
  2068.         if (-f $config_name . '.top')
  2069.         {
  2070.         $output_vars .= "CONFIG_TOP = ${config_name}.top\n";
  2071.         &push_dist_common ($config_name . '.top');
  2072.         }
  2073.         if (-f $config_name . '.bot')
  2074.         {
  2075.         $output_vars .= "CONFIG_BOT = ${config_name}.bot\n";
  2076.         &push_dist_common ($config_name . '.bot');
  2077.         }
  2078.  
  2079.         &require_file_with_conf_line ($config_header_line, $FOREIGN,
  2080.                       'stamp-h.in');
  2081.  
  2082.         $output_rules .= &file_contents ('remake-hdr');
  2083.         $output_vars .= "CONFIG_HEADER_IN = ${config_header}\n";
  2084.     }
  2085.  
  2086.     $top_reldir = '';
  2087.     }
  2088.  
  2089.     # Set location of mkinstalldirs.
  2090.     if ($config_aux_dir ne '.' && $config_aux_dir ne '')
  2091.     {
  2092.     $output_vars .= 'mkinstalldirs = ' . $config_aux_dir;
  2093.     }
  2094.     else
  2095.     {
  2096.     $output_vars .= 'mkinstalldirs = $(top_srcdir)';
  2097.     }
  2098.     $output_vars .= '/mkinstalldirs' . "\n";
  2099.  
  2100.     &am_line_error ('CONFIG_HEADER',
  2101.             "\`CONFIG_HEADER' is an anachronism; now determined from \`configure.in'")
  2102.     if &variable_defined ('CONFIG_HEADER');
  2103.  
  2104.     # Generate CONFIG_HEADER define, and define interally.
  2105.     $output_vars .= "CONFIG_HEADER = ${top_builddir}/${config_name}\n"
  2106.     if $config_name;
  2107.     $contents{'CONFIG_HEADER'} = "${top_builddir}/${config_name}"
  2108.     if $config_name;
  2109.  
  2110.     # Now look for other files in this directory which must be remade
  2111.     # by config.status, and generate rules for them.
  2112.     local (@actual_other_files) = ();
  2113.     local ($file, $local, $input);
  2114.     foreach $file (@other_input_files)
  2115.     {
  2116.     # Skip files not in this directory, any Makefile, and the
  2117.     # config header.  These last two must be handled specially.
  2118.     next unless &dirname ($file) eq $relative_dir;
  2119.     next if $file eq $top_builddir . '/' . $config_name;
  2120.     ($local = $file) =~ s/^.*\///;
  2121.     next if $local eq 'Makefile';
  2122.  
  2123.     if ($local =~ /^(.*):(.*)$/)
  2124.     {
  2125.         # This is the ":" syntax of AC_OUTPUT.
  2126.         $input = $2;
  2127.         $local = $1;
  2128.     }
  2129.     else
  2130.     {
  2131.         # Normal usage.
  2132.         $input = $local . '.in';
  2133.     }
  2134.     # FIXME: when using autoconf ":" syntax, should we set CONFIG_FILES
  2135.     # to $local:$input?
  2136.     $output_rules .= ($local . ': '
  2137.               . '$(top_builddir)/config.status ' . $input . "\n"
  2138.               . "\t"
  2139.               . 'cd $(top_builddir) && CONFIG_FILES='
  2140.               . ($relative_dir eq '.' ? '' : '$(subdir)/')
  2141.               . '$@ CONFIG_HEADERS= ./config.status'
  2142.               . "\n");
  2143.     push (@actual_other_files, $local);
  2144.  
  2145.     &require_file_with_conf_line ($ac_output_line, $FOREIGN,
  2146.                       $input);
  2147.     }
  2148.  
  2149.     # These files get removed by "make clean".
  2150.     &pretty_print ('CONFIG_CLEAN_FILES = ', '', @actual_other_files);
  2151. }
  2152.  
  2153. # Handle C headers.
  2154. sub handle_headers
  2155. {
  2156.     $dir_holds_headers = &am_install_var ('header', 'HEADERS', 'include',
  2157.                       'oldinclude', 'pkginclude',
  2158.                       'noinst', 'check');
  2159. }
  2160.  
  2161. sub handle_gettext
  2162. {
  2163.     return if ! $seen_gettext || $relative_dir ne '.';
  2164.  
  2165.     if (&variable_defined ('SUBDIRS'))
  2166.     {
  2167.     &am_line_error
  2168.         ('SUBDIRS',
  2169.          "ud_GNU_GETTEXT in configure.in but \`po' not in SUBDIRS")
  2170.         if $contents{'SUBDIRS'} !~ /\bpo\b/;
  2171.     &am_line_error
  2172.         ('SUBDIRS',
  2173.          "ud_GNU_GETTEXT in configure.in but \`intl' not in SUBDIRS")
  2174.         if $contents{'SUBDIRS'} !~ /\bintl\b/;
  2175.     }
  2176.  
  2177.     # Ensure that each language in ALL_LINGUAS has a .po file, and
  2178.     # each po file is mentioned in ALL_LINGUAS.
  2179.     if ($seen_linguas)
  2180.     {
  2181.     local (%linguas) = ();
  2182.     grep ($linguas{$_} = 1, split (' ', $all_linguas));
  2183.  
  2184.     foreach (<po/*.po>)
  2185.     {
  2186.         s/^po\///;
  2187.         s/\.po$//;
  2188.  
  2189.         &am_line_error ($all_linguas_line,
  2190.                 ("po/$_.po exists but \`$_' not in \`ALL_LINGUAS'"))
  2191.         if ! $linguas{$_};
  2192.     }
  2193.  
  2194.     foreach (keys %linguas)
  2195.     {
  2196.         &am_line_error ($all_linguas_line,
  2197.                 "$_ in \`ALL_LINGUAS' but po/$_.po does not exist")
  2198.         if ! -f "po/$_.po";
  2199.     }
  2200.     }
  2201.     else
  2202.     {
  2203.     &am_error ("ud_GNU_GETTEXT in configure.in but \`ALL_LINGUAS' not defined");
  2204.     }
  2205. }
  2206.  
  2207. # Handle footer elements.
  2208. sub handle_footer
  2209. {
  2210.     if ($contents{'SOURCES'})
  2211.     {
  2212.     &pretty_print ('SOURCES =', "",
  2213.                split (' ', $contents{'SOURCES'}));
  2214.     }
  2215.     if ($contents{'OBJECTS'})
  2216.     {
  2217.     &pretty_print ('OBJECTS =', "",
  2218.                split (' ', $contents{'OBJECTS'}));
  2219.     }
  2220.     if ($contents{'SOURCES'} || $contents{'OBJECTS'})
  2221.     {
  2222.     $output_vars .= "\n";
  2223.     }
  2224.  
  2225.     if (defined $contents{'SUFFIXES'})
  2226.     {
  2227.     # Push actual suffixes, and not $(SUFFIXES).  Some versions of
  2228.     # make do not like variable substitutions on the .SUFFIXES
  2229.     # line.
  2230.     push (@suffixes, split (' ', $contents{'SUFFIXES'}));
  2231.     }
  2232.  
  2233.     $output_trailer .= ".SUFFIXES:\n";
  2234.     if (@suffixes)
  2235.     {
  2236.     $output_trailer .= ".SUFFIXES: " . join (' ', @suffixes) . "\n";
  2237.     }
  2238.     $output_trailer .= &file_contents ('footer');
  2239. }
  2240.  
  2241. # Deal with installdirs target.
  2242. sub handle_installdirs
  2243. {
  2244.     # GNU Makefile standards recommend this.
  2245.     $output_rules .= ("installdirs:"
  2246.               . ($recursive_install
  2247.              ? " installdirs-recursive\n"
  2248.              : "\n"));
  2249.     push (@phony, 'installdirs');
  2250.     if (@installdirs)
  2251.     {
  2252.     &pretty_print_rule ("\t" . '$(mkinstalldirs) ', "\t\t",
  2253.                 @installdirs);
  2254.     }
  2255.     $output_rules .= "\n";
  2256. }
  2257.  
  2258. # There are several targets which need to be merged.  This is because
  2259. # their complete definition is compiled from many parts.  Note that we
  2260. # avoid double colon rules, otherwise we'd use them instead.
  2261. sub handle_merge_targets
  2262. {
  2263.     # There are a few install-related variables that you should not define.
  2264.     local ($var);
  2265.     foreach $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
  2266.     {
  2267.     if (&variable_defined ($var))
  2268.     {
  2269.         &am_line_error ($var, "\`$var' should not be defined");
  2270.     }
  2271.     }
  2272.  
  2273.     push (@all, 'Makefile');
  2274.     push (@all, $config_name)
  2275.     if $config_name && &dirname ($config_name) eq $relative_dir;
  2276.  
  2277.     &do_one_merge_target ('info', @info);
  2278.     if ($on_amiga) { &do_one_merge_target ('guide', @guide); }
  2279.     &do_one_merge_target ('dvi', @dvi);
  2280.  
  2281.     if (! &variable_defined ('SUBDIRS') || $relative_dir ne '.')
  2282.     {
  2283.     # 'check' must depend on 'all', but not at top level.
  2284.     # Ditto install.
  2285.     unshift (@check, 'all');
  2286.     unshift (@install, 'all');
  2287.     }
  2288.     &do_one_merge_target ('check', @check);
  2289.     &do_one_merge_target ('installcheck', @installcheck);
  2290.  
  2291.     # Handle the various install targets specially.  We do this so
  2292.     # that (eg) "make install-exec" will run "install-exec-recursive"
  2293.     # if required, but "make install" won't run it twice.  Step one is
  2294.     # to see if the user specified local versions of any of the
  2295.     # targets we handle.  "all" is treated as one of these since
  2296.     # "install" can run it.
  2297.     push (@install_exec, 'install-exec-local')
  2298.     if defined $contents{'install-exec-local'};
  2299.     push (@install_data, 'install-data-local')
  2300.     if defined $contents{'install-data-local'};
  2301.     push (@uninstall, 'uninstall-local')
  2302.     if defined $contents{'uninstall-local'};
  2303.     local ($utarg);
  2304.     foreach $utarg ('uninstall-data-local', 'uninstall-data-hook',
  2305.             'uninstall-exec-local', 'uninstall-exec-hook')
  2306.     {
  2307.     if (defined $contents{$utarg})
  2308.     {
  2309.         local ($x);
  2310.         ($x = $utarg) =~ s/(data|exec)-//;
  2311.         &am_line_error ($utarg, "use \`$x', not \`$utarg'");
  2312.     }
  2313.     }
  2314.     push (@all, 'all-local')
  2315.     if defined $contents{'all-local'};
  2316.  
  2317.     if (defined $contents{'install-local'})
  2318.     {
  2319.     &am_line_error ('install-local',
  2320.             "use \`install-data' or \`install-exec', not \`install'");
  2321.     }
  2322.  
  2323.     # Step two: if we are doing recursive makes, write out the
  2324.     # appropriate rules.
  2325.     local (@install);
  2326.     if ($recursive_install)
  2327.     {
  2328.     push (@install, 'install-recursive');
  2329.  
  2330.     if (@all)
  2331.     {
  2332.         local (@hackall) = ();
  2333.         if ($config_name && &dirname ($config_name) eq $relative_dir)
  2334.         {
  2335.  
  2336.         # This is kind of a hack, but I couldn't see a better
  2337.         # way to handle it.  In this particular case, we need
  2338.         # to make sure config.h is built before we recurse.
  2339.         # We can't do this by changing the order of
  2340.         # dependencies to the "all" because that breaks when
  2341.         # using parallel makes.  Instead we handle things
  2342.         # explicitly.
  2343.         $output_rules .= ('all-recursive-hack: $(CONFIG_HEADER)'
  2344.                   . "\n\t" . '$(MAKE) all-recursive'
  2345.                   . "\n\n");
  2346.         push (@hackall, 'all-recursive-hack');
  2347.         push (@phony, 'all-recursive-hack');
  2348.         }
  2349.         else
  2350.         {
  2351.         push (@hackall, 'all-recursive');
  2352.         }
  2353.  
  2354.         $output_rules .= ('all-am: '
  2355.                   . join (' ', @all)
  2356.                   . "\n\n");
  2357.         @all = @hackall;
  2358.         push (@all, 'all-am');
  2359.         push (@phony, 'all-am');
  2360.     }
  2361.     else
  2362.     {
  2363.         @all = ('all-recursive');
  2364.     }
  2365.     if (@install_exec)
  2366.     {
  2367.         $output_rules .= ('install-exec-am: '
  2368.                   . join (' ', @install_exec)
  2369.                   . "\n\n");
  2370.         @install_exec = ('install-exec-recursive', 'install-exec-am');
  2371.         push (@install, 'install-exec-am');
  2372.         push (@phony, 'install-exec-am');
  2373.     }
  2374.     else
  2375.     {
  2376.         @install_exec = ('install-exec-recursive');
  2377.     }
  2378.     if (@install_data)
  2379.     {
  2380.         $output_rules .= ('install-data-am: '
  2381.                   . join (' ', @install_data)
  2382.                   . "\n\n");
  2383.         @install_data = ('install-data-recursive', 'install-data-am');
  2384.         push (@install, 'install-data-am');
  2385.         push (@phony, 'install-data-am');
  2386.     }
  2387.     else
  2388.     {
  2389.         @install_data = ('install-data-recursive');
  2390.     }
  2391.     if (@uninstall)
  2392.     {
  2393.         $output_rules .= ('uninstall-am: '
  2394.                   . join (' ', @uninstall)
  2395.                   . "\n\n");
  2396.         @uninstall = ('uninstall-recursive', 'uninstall-am');
  2397.         push (@phony, 'uninstall-am');
  2398.     }
  2399.     else
  2400.     {
  2401.         @uninstall = ('uninstall-recursive');
  2402.     }
  2403.     }
  2404.  
  2405.     # Step three: print definitions users can use.  Code below knows
  2406.     # that install-exec is done before install-data, beware.
  2407.     $output_rules .= ("install-exec: "
  2408.               . join (' ', @install_exec)
  2409.               . "\n");
  2410.     $output_rules .= "\t\$(NORMAL_INSTALL)\n";
  2411.     if (defined $contents{'install-exec-hook'})
  2412.     {
  2413.     $output_rules .= "\t" . '$(MAKE) install-exec-hook' . "\n";
  2414.     }
  2415.     $output_rules .= "\n";
  2416.     push (@install, 'install-exec') if !$recursive_install;
  2417.     push (@phony, 'install-exec');
  2418.  
  2419.     $output_rules .= ("install-data: "
  2420.               . join (' ', @install_data)
  2421.               . "\n");
  2422.     $output_rules .= "\t\$(NORMAL_INSTALL)\n";
  2423.     if (defined $contents{'install-data-hook'})
  2424.     {
  2425.     $output_rules .= "\t" . '$(MAKE) install-data-hook' . "\n";
  2426.     }
  2427.     $output_rules .= "\n";
  2428.     push (@install, 'install-data') if !$recursive_install;
  2429.     push (@phony, 'install-data');
  2430.  
  2431.     # If no dependencies for 'install', add 'all'.  Why?  That way
  2432.     # "make install" at top level of distclean'd distribution won't
  2433.     # fail because stuff in 'lib' fails to build.
  2434.     if (! @install || (scalar (@install) == 2
  2435.                && $install[0] eq 'install-exec'
  2436.                && $install[1] eq 'install-data'))
  2437.     {
  2438.     push (@install, 'all');
  2439.     }
  2440.     $output_rules .= ('install: '
  2441.               . join (' ', @install)
  2442.               # Use "@:" as empty command so nothing prints.
  2443.               . "\n\t\@:"
  2444.               . "\n\n"
  2445.               . 'uninstall: '
  2446.               . join (' ', @uninstall)
  2447.               . "\n\n");
  2448.     push (@phony, 'install', 'uninstall');
  2449.  
  2450.     $output_rules .= ('all: '
  2451.               . join (' ', @all)
  2452.               . "\n\n");
  2453.     push (@phony, 'all');
  2454.  
  2455.     # Generate the new 'install-strip' target.
  2456.     $output_rules .= ("install-strip:\n\t"
  2457.               . '$(MAKE) INSTALL_PROGRAM=\'$(INSTALL_PROGRAM) -s\' install'
  2458.               . "\n");
  2459. }
  2460.  
  2461. # Helper for handle_merge_targets.
  2462. sub do_one_merge_target
  2463. {
  2464.     local ($name, @values) = @_;
  2465.  
  2466.     if (defined $contents{$name . '-local'})
  2467.     {
  2468.     # User defined local form of target.  So include it.
  2469.     push (@values, $name . '-local');
  2470.     push (@phony, $name . '-local');
  2471.     }
  2472.  
  2473.     $output_rules .= $name . ":";
  2474.     if (@values)
  2475.     {
  2476.     $output_rules .= ' ' . join (' ', @values);
  2477.     }
  2478.     $output_rules .= "\n\n";
  2479.     push (@phony, $name);
  2480. }
  2481.  
  2482. # Handle all 'clean' targets.
  2483. sub handle_clean
  2484. {
  2485.     push (@clean, 'generic');
  2486.     $output_rules .= &file_contents ('clean');
  2487.     &push_phony_cleaners ('generic');
  2488.  
  2489.     local ($target) = $recursive_install ? 'clean-am' : 'clean';
  2490.     &do_one_clean_target ($target, 'mostly', '', @clean);
  2491.     &do_one_clean_target ($target, '', 'mostly', @clean);
  2492.     &do_one_clean_target ($target, 'dist', '', @clean);
  2493.     &do_one_clean_target ($target, 'maintainer-', 'dist', @clean);
  2494.  
  2495.     push (@phony, 'clean', 'mostlyclean', 'distclean', 'maintainer-clean');
  2496.  
  2497.     local (@deps);
  2498.     if ($recursive_install)
  2499.     {
  2500.     @deps = ('am', 'recursive');
  2501.     &do_one_clean_target ('', 'mostly', '', @deps);
  2502.     &do_one_clean_target ('', '', '', @deps);
  2503.     &do_one_clean_target ('', 'dist', '', @deps);
  2504.     &do_one_clean_target ('', 'maintainer-', '', @deps);
  2505.     }
  2506. }
  2507.  
  2508. # Helper for handle_clean.
  2509. sub do_one_clean_target
  2510. {
  2511.     local ($target, $name, $last_name, @deps) = @_;
  2512.  
  2513.     # Special case: if target not passed, then don't generate
  2514.     # dependency on next "lower" clean target (eg no
  2515.     # clean<-mostlyclean derivation).  In this case the target is
  2516.     # implicitly known to be 'clean'.
  2517.     local ($flag) = $target;
  2518.     $target = 'clean' if ! $flag;
  2519.  
  2520.     grep (($_ = $name . 'clean-' . $_) && 0, @deps);
  2521.     if ($flag)
  2522.     {
  2523.     if ($last_name || $name ne 'mostly')
  2524.     {
  2525.         push (@deps, $last_name . $target . " ");
  2526.     }
  2527.     }
  2528.     # FIXME: not sure if I like the tabs here.
  2529.     &pretty_print_rule ($name . $target . ": ", "\t\t", @deps);
  2530.  
  2531.     # FIXME: shouldn't we really print these messages before running
  2532.     # the dependencies?
  2533.     if ($name . $target eq 'maintainer-clean')
  2534.     {
  2535.     # Print a special warning.
  2536.     $output_rules .=
  2537.         ("\t\@echo \"This command is intended for maintainers to use;\"\n"
  2538.          . "\t\@echo \"it deletes files that may require special "
  2539.          . "tools to rebuild.\"\n");
  2540.  
  2541.     $output_rules .= "\trm -f config.status\n"
  2542.         if $relative_dir eq '.';
  2543.     }
  2544.     elsif ($name . $target eq 'distclean')
  2545.     {
  2546.     $output_rules .= "\trm -f config.status\n";
  2547.     }
  2548.     $output_rules .= "\n";
  2549. }
  2550.  
  2551. # Handle .PHONY target.
  2552. sub handle_phony
  2553. {
  2554.     &pretty_print_rule ('.PHONY:', "", @phony);
  2555.     $output_rules .= "\n";
  2556. }
  2557.  
  2558. # Handle TESTS variable and other checks.
  2559. sub handle_tests
  2560. {
  2561.     if (defined $options{'dejagnu'})
  2562.     {
  2563.     push (@check, 'check-DEJAGNU');
  2564.     push (@phony, 'check-DEJAGNU');
  2565.     $output_rules .= &file_contents ('dejagnu') . "\n";
  2566.     # Note that in the rule we don't directly generate site.exp to
  2567.     # avoid the possibility of a corrupted site.exp if make is
  2568.     # interrupted.  Jim Meyering has some useful text on this
  2569.     # topic.
  2570.     $output_rules .= ("site.exp: Makefile\n"
  2571.               . "\t\@echo 'Making a new site.exp file...'\n"
  2572.               . "\t-\@rm -f site.bak\n"
  2573.               . "\t\@echo '## these variables are automatically generated by make ##' > \$\@-t\n"
  2574.               . "\t\@echo '# Do not edit here.  If you wish to override these values' >> \$\@-t\n"
  2575.               . "\t\@echo '# edit the last section' >> \$\@-t\n"
  2576.               . "\t\@echo 'set tool \$(DEJATOOL)' >> \$\@-t\n"
  2577.               . "\t\@echo 'set srcdir \$(srcdir)' >> \$\@-t\n"
  2578.               . "\t\@echo 'set objdir' \`pwd\` >> \$\@-t\n");
  2579.  
  2580.     # Extra stuff for AC_CANONICAL_*
  2581.     local (@whatlist) = ();
  2582.     if ($seen_canonical)
  2583.     {
  2584.         push (@whatlist, 'host')
  2585.     }
  2586.  
  2587.     # Extra stuff only for AC_CANONICAL_SYSTEM.
  2588.     if ($seen_canonical == $AC_CANONICAL_SYSTEM)
  2589.     {
  2590.         push (@whatlist, 'target', 'build');
  2591.     }
  2592.  
  2593.     local ($c1, $c2);
  2594.     foreach $c1 (@whatlist)
  2595.     {
  2596.         foreach $c2 ('alias', 'triplet')
  2597.         {
  2598.         $output_rules .= "\t\@echo 'set ${c1}_${c2} \$(${c1}_${c2})' >> \$\@-t\n";
  2599.         }
  2600.     }
  2601.  
  2602.     $output_rules .= ("\t\@echo '## All variables above are generated by configure. Do Not Edit ##' >> \$\@-t\n"
  2603.               . "\t-\@sed '1,/^## All variables above are.*##/ d' site.bak >> \$\@-t\n"
  2604.               . "\t-\@mv site.exp site.bak\n"
  2605.               . "\t\@mv \$\@-t site.exp\n");
  2606.     }
  2607.     else
  2608.     {
  2609.     local ($c);
  2610.     foreach $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
  2611.     {
  2612.         if (&variable_defined ($c))
  2613.         {
  2614.         &am_line_error ($c, "\`$c' defined but \`dejagnu' not in \`AUTOMAKE_OPTIONS'");
  2615.         }
  2616.     }
  2617.     }
  2618.  
  2619.     if (&variable_defined ('TESTS'))
  2620.     {
  2621.     push (@check, 'check-TESTS');
  2622.     push (@phony, 'check-TESTS');
  2623.     # FIXME: use $(SHELL) here?  That is what Ulrich suggests.
  2624.     # Maybe a new macro, $(TEST_SHELL), a la $(CONFIG_SHELL)?  For
  2625.     # now we just execute the file directly; this allows test
  2626.     # files which are compiled -- a possibly useful feature.
  2627.     $output_rules .= 'check-TESTS: $(TESTS)
  2628.     @failed=0; all=0; \\
  2629.     srcdir=$(srcdir); export srcdir; \\
  2630.     for tst in $(TESTS); do \\
  2631.       all=`expr $$all + 1`; \\
  2632.       if test -f $$tst; then dir=.; \\
  2633.       else dir="$(srcdir)"; fi; \\
  2634.       if $(TESTS_ENVIRONMENT) $$dir/$$tst; then \\
  2635.         echo "PASS: $$tst"; \\
  2636.       else \\
  2637.         failed=`expr $$failed + 1`; \\
  2638.         echo "FAIL: $$tst"; \\
  2639.       fi; \\
  2640.     done; \\
  2641.     if test "$$failed" -eq 0; then \\
  2642.       echo "========================"; \\
  2643.       echo "All $$all tests passed"; \\
  2644.       echo "========================"; \\
  2645.     else \\
  2646.       echo "$$failed of $$all tests failed"; \\
  2647.     fi
  2648. ';
  2649.     }
  2650. }
  2651.  
  2652. # Handle Emacs Lisp.
  2653. sub handle_emacs_lisp
  2654. {
  2655.     local (@elfiles) = &am_install_var ('lisp', 'LISP', 'lisp', 'noinst');
  2656.  
  2657.     if (@elfiles)
  2658.     {
  2659.     # Found some lisp.
  2660.     $output_vars .= "lispdir = \@lispdir\@\n";
  2661.     $output_rules .= (".el.elc:\n"
  2662.               . "\t\@echo 'WARNING: Warnings can be ignored. :-)'\n"
  2663.               . "\t\$(SHELL) \$(srcdir)/elisp-comp \$<\n");
  2664.     push (@suffixes, '.el', '.elc');
  2665.  
  2666.     # Generate .elc files.
  2667.     grep ($_ .= 'c', @elfiles);
  2668.     &pretty_print ('ELCFILES =', '', @elfiles);
  2669.  
  2670.     push (@clean, 'lisp');
  2671.     &push_phony_cleaners ('lisp');
  2672.  
  2673.     local ($varname);
  2674.     if (&variable_defined ('lisp_LISP'))
  2675.     {
  2676.         $varname = 'lisp_LISP';
  2677.         &am_error ("\`lisp_LISP' defined but \`AM_PATH_LISPDIR' not in \`configure.in'")
  2678.         if ! $seen_lispdir;
  2679.     }
  2680.     else
  2681.     {
  2682.         $varname = 'noinst_LISP';
  2683.     }
  2684.  
  2685.     &require_file_with_line ($varname, $FOREIGN, 'elisp-comp');
  2686.     }
  2687. }
  2688.  
  2689. ################################################################
  2690.  
  2691. # Scan configure.in for interesting things.
  2692. # FIXME: ensure VERSION, PACKAGE are set.
  2693. sub scan_configure
  2694. {
  2695.     open (CONFIGURE, 'configure.in')
  2696.     || die "automake: couldn't open \`configure.in': $!\n";
  2697.     print "automake: reading configure.in\n" if $verbose;
  2698.  
  2699.     # Reinitialize libsources here.  This isn't really necessary,
  2700.     # since we currently assume there is only one configure.in.  But
  2701.     # that won't always be the case.
  2702.     %libsources = ();
  2703.  
  2704.     local ($in_ac_output, @make_list) = 0;
  2705.     local ($libobj_iter);
  2706.     while (<CONFIGURE>)
  2707.     {
  2708.     # Remove comments from current line.
  2709.     s/\bdnl\b.*$//;
  2710.     s/\#.*$//;
  2711.  
  2712.     # Populate libobjs array.
  2713.     if (/AC_FUNC_ALLOCA/)
  2714.     {
  2715.         $libsources{'alloca.c'} = 1;
  2716.     }
  2717.     elsif (/AC_FUNC_GETLOADAVG/)
  2718.     {
  2719.         $libsources{'getloadavg.c'} = 1;
  2720.     }
  2721.     elsif (/AC_FUNC_MEMCMP/)
  2722.     {
  2723.         $libsources{'memcmp.c'} = 1;
  2724.     }
  2725.     elsif (/AC_STRUCT_ST_BLOCKS/)
  2726.     {
  2727.         $libsources{'fileblocks.c'} = 1;
  2728.     }
  2729.     elsif (/AM_FUNC_FNMATCH/)
  2730.     {
  2731.         $libsources{'fnmatch.c'} = 1;
  2732.     }
  2733.     elsif (/AC_REPLACE_FUNCS\s*\((.*)\)/)
  2734.     {
  2735.         foreach (split (' ', $1))
  2736.         {
  2737.         $libsources{$_ . '.c'} = 1;
  2738.         }
  2739.     }
  2740.     elsif (/A[CM]_REPLACE_GNU_GETOPT/)
  2741.     {
  2742.         $libsources{'getopt.c'} = 1;
  2743.         $libsources{'getopt1.c'} = 1;
  2744.     }
  2745.     elsif (/AM_FUNC_STRTOD/)
  2746.     {
  2747.         $libsources{'strtod.c'} = 1;
  2748.     }
  2749.     elsif (/AM_WITH_REGEX/)
  2750.     {
  2751.         $libsources{'rx.c'} = 1;
  2752.         $libsources{'rx.h'} = 1;
  2753.         $libsources{'regex.c'} = 1;
  2754.         $libsources{'regex.h'} = 1;
  2755.     }
  2756.     elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
  2757.            || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
  2758.     {
  2759.         foreach $libobj_iter (split (' ', $1))
  2760.         {
  2761.         if ($libobj_iter =~ /^(.*)\.o$/)
  2762.         {
  2763.             $libsources{$1 . '.c'} = 1;
  2764.         }
  2765.         }
  2766.     }
  2767.  
  2768.     if (/(fp_FUNC_FNMATCH|fp_PROG_INSTALL|fp_C_PROTOTYPES|jm_MAINTAINER_MODE)/)
  2769.     {
  2770.         &am_conf_line_error ($., "\`$1' is obsolete; use corresponding \`AM_' macro");
  2771.     }
  2772.  
  2773.     # Process the AC_OUTPUT macro.
  2774.     if (! $in_ac_output && s/AC_OUTPUT\s*\(\[?//)
  2775.     {
  2776.         $in_ac_output = 1;
  2777.         $ac_output_line = $.;
  2778.     }
  2779.     if ($in_ac_output)
  2780.     {
  2781.         $in_ac_output = 0 if s/[\]\),].*$//;
  2782.  
  2783.         # Look at potential Makefile.am's.
  2784.         foreach (split)
  2785.         {
  2786.         next if $_ eq "\\";
  2787.         if (-f $_ . '.am')
  2788.         {
  2789.             push (@make_list, $_);
  2790.         }
  2791.         else
  2792.         {
  2793.             push (@other_input_files, $_);
  2794.         }
  2795.         }
  2796.     }
  2797.  
  2798.     if (/AC_CONFIG_AUX_DIR\(([^)]+)\)/)
  2799.     {
  2800.         @config_aux_path = $1;
  2801.     }
  2802.  
  2803.     # Check for ansi2knr.
  2804.     $am_c_prototypes = 1 if /AM_C_PROTOTYPES/;
  2805.  
  2806.     # Check for NLS support.
  2807.     if (/ud_GNU_GETTEXT/)
  2808.     {
  2809.         $seen_gettext = 1;
  2810.         $ac_gettext_line = $.;
  2811.     }
  2812.  
  2813.         # Look for ALL_LINGUAS.
  2814.         if (/ALL_LINGUAS="(.*)"$/ || /ALL_LINGUAS=(.*)$/)
  2815.     {
  2816.         $seen_linguas = 1;
  2817.         $all_linguas = $1;
  2818.         $all_linguas_line = $.;
  2819.     }
  2820.  
  2821.     # Handle configuration headers.
  2822.     if (/AC_CONFIG_HEADER\s*\((.*)\)/)
  2823.     {
  2824.         $config_header_line = $.;
  2825.         $config_name = $1;
  2826.         if ($config_name =~ /^([^:]+):(.+)$/)
  2827.         {
  2828.         $config_name = $1;
  2829.         $config_header = $2;
  2830.         }
  2831.         else
  2832.         {
  2833.         $config_header = $config_name . '.in';
  2834.         }
  2835.     }
  2836.  
  2837.         # Handle AC_CANONICAL_*.  Always allow upgrading to
  2838.         # AC_CANONICAL_SYSTEM, but never downgrading.
  2839.     $seen_canonical = $AC_CANONICAL_HOST
  2840.         if ! $seen_canonical && /AC_CANONICAL_HOST/;
  2841.         $seen_canonical = $AC_CANONICAL_SYSTEM if /AC_CANONICAL_SYSTEM/;
  2842.  
  2843.     $seen_canonical = 1 if /AC_CHECK_TOOL/;
  2844.     $seen_path_xtra = 1 if /AC_PATH_XTRA/;
  2845.  
  2846.     # Sometimes it is desirable to explicitly set YACC.  For
  2847.     # instance some people don't want to use bison.
  2848.     $seen_prog_yacc = 1 if (/AC_PROG_YACC/
  2849.                 || /AC_SUBST\(YACC\)/
  2850.                 || /AC_(PATH|CHECK)_PROGS?\(YACC/);
  2851.  
  2852.         # This macro handles several different things.
  2853.         if (/AM_INIT_AUTOMAKE\([^,]*,([^)]+)\)/)
  2854.     {
  2855.         $seen_make_set = 1;
  2856.         $seen_package = 1;
  2857.         $seen_version = 1;
  2858.         $seen_arg_prog = 1;
  2859.         $seen_prog_install = 2;
  2860.         ($package_version = $1) =~ s/\s//;
  2861.         $package_version_line = $.;
  2862.     }
  2863.  
  2864.     # Some things required by Automake.
  2865.     $seen_make_set = 1 if /AC_PROG_MAKE_SET/;
  2866.     $seen_arg_prog = 1 if /AC_ARG_PROGRAM/;
  2867.     $seen_ranlib = 1 if /AC_PROG_RANLIB/;
  2868.         $seen_prog_cc = 1 if /AC_PROG_CC/;
  2869.         $seen_prog_cxx = 1 if /AC_PROG_CXX/;
  2870.         $seen_prog_lex = 1 if /AC_PROG_LEX/;
  2871.         $seen_decl_yytext = 1 if /AC_DECL_YYTEXT/;
  2872.         $seen_maint_mode = 1 if /AM_MAINTAINER_MODE/;
  2873.         $seen_package = 1 if /PACKAGE=/;
  2874.  
  2875.         if (/VERSION=(\S+)/)
  2876.     {
  2877.         $seen_version = 1;
  2878.         $package_version = $1;
  2879.         $package_version_line = $.;
  2880.     }
  2881.         elsif (/VERSION=/)
  2882.     {
  2883.         $seen_version = 1;
  2884.     }
  2885.  
  2886.         # Weird conditionals here because it is always allowed to
  2887.         # upgrade to AM_PROG_INSTALL but never to downgrade to
  2888.         # AC_PROG_INSTALL.
  2889.     $seen_prog_install = 1 if ! $seen_prog_install && /AC_PROG_INSTALL/;
  2890.     $seen_prog_install = 2 if /AM_PROG_INSTALL/;
  2891.  
  2892.         $seen_lispdir = 1 if /AM_PATH_LISPDIR/;
  2893.  
  2894.         if (/AM_PROG_LIBTOOL/)
  2895.     {
  2896.         $seen_libtool = 1;
  2897.         $seen_ranlib = 2;
  2898.         $libtool_line = $.;
  2899.     }
  2900.     }
  2901.  
  2902.     # Set input files if not specified by user.
  2903.     @input_files = @make_list if (! @input_files);
  2904.  
  2905.     close (CONFIGURE);
  2906.  
  2907.     &am_conf_error ("\`PACKAGE' not defined in configure.in")
  2908.         if ! $seen_package;
  2909.     &am_conf_error ("\`VERSION' not defined in configure.in")
  2910.         if ! $seen_version;
  2911.  
  2912.     # Look for some files we need.  Always check for these.  This
  2913.     # check must be done for every run, even those where we are only
  2914.     # looking at a subdir Makefile.  We must set relative_dir so that
  2915.     # the file-finding machinery works.
  2916.     local ($relative_dir) = '.';
  2917.     &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs');
  2918. }
  2919.  
  2920. ################################################################
  2921.  
  2922. # Do any extra checking for GNU standards.
  2923. sub check_gnu_standards
  2924. {
  2925.     if ($relative_dir eq '.')
  2926.     {
  2927.     # In top level (or only) directory.
  2928.     &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
  2929.                'AUTHORS', 'ChangeLog');
  2930.     }
  2931.  
  2932.     if ($strictness >= $GNU)
  2933.     {
  2934.     if (defined $options{'no-installman'})
  2935.     {
  2936.         &am_line_error ('AUTOMAKE_OPTIONS',
  2937.                 "option \`no-installman' disallowed by GNU standards");
  2938.     }
  2939.  
  2940.     if (defined $options{'no-installinfo'})
  2941.     {
  2942.         &am_line_error ('AUTOMAKE_OPTIONS',
  2943.                 "option \`no-installinfo' disallowed by GNU standards");
  2944.     }
  2945.     }
  2946. }
  2947.  
  2948. # Do any extra checking for GNITS standards.
  2949. sub check_gnits_standards
  2950. {
  2951.     if ($strictness >= $GNITS)
  2952.     {
  2953.     if (-f $relative_dir . '/COPYING.LIB')
  2954.     {
  2955.         &am_error ("\`${relative_dir}/COPYING.LIB' disallowed by Gnits standards");
  2956.     }
  2957.  
  2958.     if ($relative_dir eq '.')
  2959.     {
  2960.         if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
  2961.         {
  2962.         &am_conf_line_error ($package_version_line,
  2963.                      "version \`$package_version' doesn't follow Gnits standards");
  2964.         }
  2965.         elsif (defined $1 && -f 'README-alpha')
  2966.         {
  2967.         # This means we have an alpha release.  See
  2968.         # GNITS_VERSION_PATTERN for details.
  2969.         &require_file ($GNITS, 'README-alpha');
  2970.         }
  2971.     }
  2972.     }
  2973.  
  2974.     if ($relative_dir eq '.')
  2975.     {
  2976.     # In top level (or only) directory.
  2977.     &require_file ($GNITS, 'THANKS');
  2978.     }
  2979. }
  2980.  
  2981. ################################################################
  2982.  
  2983. # Pretty-print something.  HEAD is what should be printed at the
  2984. # beginning of the first line, FILL is what should be printed at the
  2985. # beginning of every subsequent line.
  2986. sub pretty_print_internal
  2987. {
  2988.     local ($head, $fill, @values) = @_;
  2989.  
  2990.     local ($column) = length ($head);
  2991.     local ($result) = $head;
  2992.  
  2993.     # Fill length is number of characters.  However, each Tab
  2994.     # character counts for eight.  So we count the number of Tabs and
  2995.     # multiply by 7.
  2996.     local ($fill_length) = length ($fill);
  2997.     $fill_length += 7 * ($fill =~ tr/\t/\t/d);
  2998.  
  2999.     local ($bol) = 0;
  3000.     foreach (@values)
  3001.     {
  3002.     # "71" because we also print a space.
  3003.     if ($column + length ($_) > 71)
  3004.     {
  3005.         $result .= " \\\n" . $fill;
  3006.         $column = $fill_length;
  3007.         $bol = 1;
  3008.     }
  3009.  
  3010.     $result .= ' ' unless ($bol);
  3011.     $result .= $_;
  3012.     $column += length ($_) + 1;
  3013.     $bol = 0;
  3014.     }
  3015.  
  3016.     $result .= "\n";
  3017.     return $result;
  3018. }
  3019.  
  3020. # Pretty-print something and append to output_vars.
  3021. sub pretty_print
  3022. {
  3023.     $output_vars .= &pretty_print_internal (@_);
  3024. }
  3025.  
  3026. # Pretty-print something and append to output_rules.
  3027. sub pretty_print_rule
  3028. {
  3029.     $output_rules .= &pretty_print_internal (@_);
  3030. }
  3031.  
  3032.  
  3033. ################################################################
  3034.  
  3035. # See if a variable exists.
  3036. sub variable_defined
  3037. {
  3038.     local ($var) = @_;
  3039.     if (defined $targets{$var})
  3040.     {
  3041.     &am_line_error ($var, "\`$var' is target; expected variable");
  3042.     }
  3043.     return (defined $contents{$var} && ! defined $targets{$var});
  3044. }
  3045.  
  3046. # Return contents of variable as list, split as whitespace.  This will
  3047. # recursively follow $(...) and ${...} inclusions.  It preserves @...@
  3048. # substitutions.  If PARENT is specified, it is the name of the
  3049. # including variable; this is only used for error reports.
  3050. sub variable_value_as_list
  3051. {
  3052.     local ($var, $parent) = @_;
  3053.     local (@result);
  3054.  
  3055.     if (defined $targets{$var})
  3056.     {
  3057.     &am_line_error ($var, "\`$var' is target; expected variable");
  3058.     }
  3059.     elsif (! defined $contents{$var})
  3060.     {
  3061.     &am_error ($parent, "variable \`$var' not defined");
  3062.     }
  3063.     else
  3064.     {
  3065.     foreach (split (' ', $contents{$var}))
  3066.     {
  3067.         # Handle variable substitutions.
  3068.         if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
  3069.         {
  3070.         push (@result, &variable_value_as_list ($1, $var));
  3071.         }
  3072.         else
  3073.         {
  3074.         push (@result, $_);
  3075.         }
  3076.     }
  3077.     }
  3078.  
  3079.     return @result;
  3080. }
  3081.  
  3082. # Read Makefile.am and set up %contents.  Simultaneously copy lines
  3083. # from Makefile.am into $output_trailer or $output_vars as
  3084. # appropriate.  NOTE we put rules in the trailer section.  We want
  3085. # user rules to come after our generated stuff.
  3086. sub read_am_file
  3087. {
  3088.     local ($amfile) = @_;
  3089.  
  3090.     # Compute relative location of the top object directory.
  3091.     local (@topdir) = ();
  3092.     foreach (split (/\//, $relative_dir))
  3093.     {
  3094.     next if $_ eq '.' || $_ eq '';
  3095.     if ($_ eq '..')
  3096.     {
  3097.         pop @topdir;
  3098.     }
  3099.     else
  3100.     {
  3101.         push (@topdir, '..');
  3102.     }
  3103.     }
  3104.     @topdir = ('.') if ! @topdir;
  3105.  
  3106.     $top_builddir = join ('/', @topdir);
  3107.     local ($build_rx, $header_vars);
  3108.     ($build_rx = $top_builddir) =~ s/(\W)/\\$1/g;
  3109.     if ($on_amiga)
  3110.     {
  3111.     $header_vars = &file_contents_with_transform 
  3112.     ('s/\@top_builddir\@/' . $build_rx . '/g', 'amiga-header-vars');
  3113.     }
  3114.     else
  3115.     {
  3116.     $header_vars = &file_contents_with_transform 
  3117.     ('s/\@top_builddir\@/' . $build_rx . '/g', 'header-vars');
  3118.     }
  3119.  
  3120.     # Generate some useful variables when AC_CANONICAL_* used.
  3121.     if ($seen_canonical)
  3122.     {
  3123.     $header_vars .= ('host_alias = @host_alias@' . "\n"
  3124.              . 'host_triplet = @host@' . "\n");
  3125.     if ($seen_canonical == $AC_CANONICAL_SYSTEM)
  3126.     {
  3127.         $header_vars .= ('build_alias = @build_alias@' . "\n"
  3128.                  . 'build_triplet = @build@' . "\n");
  3129.         $header_vars .= ('target_alias = @target_alias@' . "\n"
  3130.                  . 'target_triplet = @target@' . "\n");
  3131.     }
  3132.     }
  3133.  
  3134.     open (AM_FILE, $amfile) || die "automake: couldn't open \`$amfile': $!\n";
  3135.     print "automake: reading $amfile\n" if $verbose;
  3136.  
  3137.     $output_vars .= ("# $in_file_name generated automatically by automake "
  3138.              . $VERSION . " from $am_file_name\n");
  3139.  
  3140.     # Generate copyright for generated Makefile.in.
  3141.     $output_vars .= $gen_copyright;
  3142.  
  3143.     local ($saw_bk) = 0;
  3144.     local ($was_rule) = 0;
  3145.     local ($spacing) = '';
  3146.     local ($comment) = '';
  3147.     local ($last_var_name) = '';
  3148.     local ($blank) = 0;
  3149.  
  3150.     while (<AM_FILE>)
  3151.     {
  3152.     if (/$IGNORE_PATTERN/o)
  3153.     {
  3154.         # Merely delete comments beginning with two hashes.
  3155.     }
  3156.     elsif (/$WHITE_PATTERN/o)
  3157.     {
  3158.         # Stick a single white line before the incoming macro or rule.
  3159.         $spacing = "\n";
  3160.         $blank = 1;
  3161.     }
  3162.     elsif (/$COMMENT_PATTERN/o)
  3163.     {
  3164.         # Stick comments before the incoming macro or rule.  Make
  3165.         # sure a blank line preceeds first block of comments.
  3166.         $spacing = "\n" unless $blank;
  3167.         $blank = 1;
  3168.         $comment .= $spacing . $_;
  3169.         $spacing = '';
  3170.     }
  3171.     else
  3172.     {
  3173.         last;
  3174.     }
  3175.     }
  3176.  
  3177.     $output_vars .= $comment . "\n" . $header_vars;
  3178.     $comment = '';
  3179.     $spacing = "\n";
  3180.  
  3181.     local ($is_ok_macro);
  3182.     while ($_)
  3183.     {
  3184.     $_ .= "\n"
  3185.         unless substr ($_, -1, 1) eq "\n";
  3186.  
  3187.     $_ =~ s/\@(UN)?MAINT\@//g
  3188.         unless $seen_maint_mode;
  3189.  
  3190.     if (/$IGNORE_PATTERN/o)
  3191.     {
  3192.         # Merely delete comments beginning with two hashes.
  3193.     }
  3194.     elsif (/$WHITE_PATTERN/o)
  3195.     {
  3196.         # Stick a single white line before the incoming macro or rule.
  3197.         $spacing = "\n";
  3198.     }
  3199.     elsif (/$COMMENT_PATTERN/o)
  3200.     {
  3201.         # Stick comments before the incoming macro or rule.
  3202.         $comment .= $spacing . $_;
  3203.         $spacing = '';
  3204.     }
  3205.     elsif ($saw_bk)
  3206.     {
  3207.         if ($was_rule)
  3208.         {
  3209.         $output_trailer .= $_;
  3210.         $saw_bk = /\\$/;
  3211.         }
  3212.         else
  3213.         {
  3214.         $output_vars .= $_;
  3215.         $saw_bk = /\\$/;
  3216.         # Chop newline and backslash if this line is
  3217.         # continued.  FIXME: maybe ensure trailing whitespace
  3218.         # exists?
  3219.         chop if $saw_bk;
  3220.         chop if $saw_bk;
  3221.         $contents{$last_var_name} .= $_;
  3222.         }
  3223.     }
  3224.     elsif (/$RULE_PATTERN/o)
  3225.     {
  3226.         # warn "** Saw rule .$1.\n";
  3227.         # Found a rule.
  3228.         $was_rule = 1;
  3229.         # Value here doesn't matter; for targets we only note
  3230.         # existence.
  3231.         $contents{$1} = 1;
  3232.         $targets{$1} = 1;
  3233.         $content_lines{$1} = $.;
  3234.         $output_trailer .= $comment . $spacing . $_;
  3235.         $comment = $spacing = '';
  3236.         $saw_bk = /\\$/;
  3237.     }
  3238.     elsif (($is_ok_macro = /$MACRO_PATTERN/o)
  3239.            || /$BOGUS_MACRO_PATTERN/o)
  3240.     {
  3241.         # Found a macro definition.
  3242.         $was_rule = 0;
  3243.         $last_var_name = $1;
  3244.         if (substr ($2, -1) eq "\\")
  3245.         {
  3246.         $contents{$1} = substr ($2, 0, length ($2) - 1);
  3247.         }
  3248.         else
  3249.         {
  3250.         $contents{$1} = $2;
  3251.         }
  3252.         $content_lines{$1} = $.;
  3253.         $output_vars .= $comment . $spacing . $_;
  3254.         $comment = $spacing = '';
  3255.         $saw_bk = /\\$/;
  3256.  
  3257.         # Error if bogus.
  3258.         &am_line_error ($., "bad macro name \`$1'")
  3259.         if ! $is_ok_macro;
  3260.     }
  3261.     else
  3262.     {
  3263.         # This isn't an error; it is probably a continued rule.
  3264.         # In fact, this is what we assume.
  3265.         $was_rule = 1;
  3266.         $output_trailer .= $comment . $spacing . $_;
  3267.         $comment = $spacing = '';
  3268.         $saw_bk = /\\$/;
  3269.     }
  3270.  
  3271.     $_ = <AM_FILE>;
  3272.     }
  3273.  
  3274.     $output_trailer .= $comment;
  3275. }
  3276.  
  3277. ################################################################
  3278.  
  3279. sub initialize_global_constants
  3280. {
  3281.     # Values for AC_CANONICAL_*
  3282.     $AC_CANONICAL_HOST = 1;
  3283.     $AC_CANONICAL_SYSTEM = 2;
  3284.  
  3285.     # Associative array of standard directory names.  Entry is TRUE if
  3286.     # corresponding directory should be installed during
  3287.     # 'install-exec' phase.
  3288.     %exec_dir_p =
  3289.     ('bin', 1,
  3290.      'sbin', 1,
  3291.      'libexec', 1,
  3292.      'data', 0,
  3293.      'sysconf', 1,
  3294.      'localstate', 1,
  3295.      'lib', 1,
  3296.      'info', 0,
  3297.      'guide',0,
  3298.      'man', 0,
  3299.      'include', 0,
  3300.      'oldinclude', 0,
  3301.      'pkgdata', 0,
  3302.      'pkglib', 1,
  3303.      'pkginclude', 0
  3304.      );
  3305.  
  3306.     # Helper text for dealing with man pages.
  3307.     $install_man_format =
  3308.     '    sect=@SECTION@;                \\
  3309.     inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
  3310.     if test -f $(srcdir)/@MAN@; then file=$(srcdir)/@MAN@; \\
  3311.     else file=@MAN@; fi; \\
  3312.     $(INSTALL_DATA) $$file $(mandir)/man$$sect/$$inst
  3313. ';
  3314.  
  3315.     $uninstall_man_format =
  3316.     '    inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
  3317.     rm -f $(mandir)/man@SECTION@/$$inst
  3318. ';
  3319.  
  3320.     # Commonly found files we look for and automatically include in
  3321.     # DISTFILES.
  3322.     @common_files =
  3323.     (
  3324.      "README", "THANKS", "TODO", "NEWS", "COPYING", "COPYING.LIB",
  3325.      "INSTALL", "ABOUT-NLS", "ChangeLog", "configure", "configure.in",
  3326.      "config.guess", "config.sub", "AUTHORS", "BACKLOG", "ABOUT-GNU",
  3327.      "libversion.in", "mdate-sh", "mkinstalldirs", "install-sh",
  3328.      'texinfo.tex', "ansi2knr.c", "ansi2knr.1", 'elisp-comp',
  3329.      'interlock', 'ylwrap', 'acinclude.m4'
  3330.      );
  3331.  
  3332.     # Commonly used files we auto-include, but only sometimes.
  3333.     @common_sometimes =
  3334.     (
  3335.      "aclocal.m4", "acconfig.h", "config.h.top",
  3336.      "config.h.bot", "stamp-h.in", 'stamp-vti', 'libtool'
  3337.      );
  3338.  
  3339.     $USAGE = "\
  3340.   -a, --add-missing     add missing standard files to package
  3341.   --amdir=DIR           directory storing config files
  3342.   --build-dir=DIR       directory where build being done (for dependencies)
  3343.   --foreign             same as --strictness=foreign
  3344.   --gnits               same as --strictness=gnits
  3345.   --gnu                 same as --strictness=gnu
  3346.   --amiga               same as --strictness=amiga
  3347.   --help                print this help, then exit
  3348.   -i, --include-deps    include generated dependencies in Makefile.in
  3349.   --no-force            only update Makefile.in's that are out of date
  3350.   -o DIR, --output-dir=DIR
  3351.                         put generated Makefile.in's into DIR
  3352.   --srcdir-name=DIR     name used for srcdir (for dependencies)
  3353.   -s LEVEL, --strictness=LEVEL
  3354.                         set strictness level.  LEVEL is foreign, gnu, gnits
  3355.   -v, --verbose         verbosely list files processed
  3356.   --version             print version number, then exit\n";
  3357.  
  3358.     # Copyright on generated Makefile.ins.
  3359.     $gen_copyright = "\
  3360. # Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
  3361. # This Makefile.in is free software; the Free Software Foundation
  3362. # gives unlimited permission to copy, distribute and modify it.
  3363. ";
  3364. }
  3365.  
  3366. # (Re)-Initialize per-Makefile.am variables.
  3367. sub initialize_per_input
  3368. {
  3369.     # These two variables are used when generating each Makefile.in.
  3370.     # They hold the Makefile.in until it is ready to be printed.
  3371.     $output_rules = '';
  3372.     $output_vars = '';
  3373.     $output_trailer = '';
  3374.  
  3375.     # Suffixes found during a run.
  3376.     @suffixes = ();
  3377.  
  3378.     # This holds the contents of a Makefile.am, as parsed by
  3379.     # read_am_file.
  3380.     %contents = ();
  3381.  
  3382.     # This holds the names which are targets.  These also appear in
  3383.     # %contents.
  3384.     %targets = ();
  3385.  
  3386.     # This holds the line numbers at which various elements of
  3387.     # %contents are defined.
  3388.     %content_lines = ();
  3389.  
  3390.     # This holds the "relative directory" of the current Makefile.in.
  3391.     # Eg for src/Makefile.in, this is "src".
  3392.     $relative_dir = '';
  3393.  
  3394.     # This holds a list of files that are included in the
  3395.     # distribution.
  3396.     %dist_common = ();
  3397.  
  3398.     # List of dependencies for the obvious targets.
  3399.     @install_data = ();
  3400.     @install_exec = ();
  3401.     @uninstall = ();
  3402.     @installdirs = ();
  3403.  
  3404.     @info = ();
  3405.     if ($on_amiga) { @guide = (); }
  3406.     @dvi = ();
  3407.     @all = ();
  3408.     @check = ();
  3409.     @installcheck = ();
  3410.     @clean = ();
  3411.  
  3412.     @phony = ();
  3413.  
  3414.     # These are pretty obvious, too.  They are used to define the
  3415.     # SOURCES and OBJECTS variables.
  3416.     @sources = ();
  3417.     @objects = ();
  3418.  
  3419.     # TRUE if current directory holds any C source files.  (Actually
  3420.     # holds object extension, but this information is encapsulated in
  3421.     # the function get_object_extension).
  3422.     $dir_holds_sources = '';
  3423.  
  3424.     # TRUE if current directory holds any headers.
  3425.     $dir_holds_headers = 0;
  3426.  
  3427.     # TRUE if install targets should work recursively.
  3428.     $recursive_install = 0;
  3429.  
  3430.     # All .P files.
  3431.     %dep_files = ();
  3432.  
  3433.     # Strictness levels.
  3434.     $strictness = $default_strictness;
  3435.     $strictness_name = $default_strictness_name;
  3436.  
  3437.     # Options from AUTOMAKE_OPTIONS.
  3438.     %options = ();
  3439.  
  3440.     # Whether or not dependencies are handled.  Can be further changed
  3441.     # in handle_options.
  3442.     $use_dependencies = $cmdline_use_dependencies;
  3443.  
  3444.     # Per Makefile.am.
  3445.     $local_maint_charset = $maint_charset;
  3446.  
  3447.     # All yacc and lex source filenames for this directory.  Use
  3448.     # filenames instead of raw count so that multiple instances are
  3449.     # counted correctly (eg one yacc file can appear in multiple
  3450.     # programs without harm).
  3451.     %yacc_sources = ();
  3452.     %lex_sources = ();
  3453.  
  3454.     # C++ source extensions we've seen.
  3455.     %cxx_extensions = ();
  3456.  
  3457.     # TRUE if we've seen any non-C++ sources.
  3458.     $seen_c_source = 0;
  3459. }
  3460.  
  3461.  
  3462. ################################################################
  3463.  
  3464. # Return contents of a file from $am_dir, automatically skipping
  3465. # macros or rules which are already known.  Runs command on each line
  3466. # as it is read; this command can modify $_.
  3467. sub file_contents_with_transform
  3468. {
  3469.     local ($command, $basename) = @_;
  3470.     local ($file) = $am_dir . '/' . $basename . '.am';
  3471.  
  3472.     open (FC_FILE, $file)
  3473.     || die "automake: installation error: cannot open \`$file'\n";
  3474.     # Looks stupid?
  3475.     # print "automake: reading $file\n" if $verbose;
  3476.  
  3477.     local ($was_rule) = 0;
  3478.     local ($result_vars) = '';
  3479.     local ($result_rules) = '';
  3480.     local ($comment) = '';
  3481.     local ($spacing) = "\n";
  3482.     local ($skipping) = 0;
  3483.  
  3484.     while (<FC_FILE>)
  3485.     {
  3486.     $_ =~ s/\@(UN)?MAINT\@//g
  3487.         unless $seen_maint_mode;
  3488.  
  3489.     eval $command;
  3490.  
  3491.     if (/$IGNORE_PATTERN/o)
  3492.     {
  3493.         # Merely delete comments beginning with two hashes.
  3494.     }
  3495.     elsif (/$WHITE_PATTERN/o)
  3496.     {
  3497.         # Stick a single white line before the incoming macro or rule.
  3498.         $spacing = "\n";
  3499.     }
  3500.     elsif (/$COMMENT_PATTERN/o)
  3501.     {
  3502.         # Stick comments before the incoming macro or rule.
  3503.         $comment .= $spacing . $_;
  3504.         $spacing = '';
  3505.     }
  3506.     elsif ($saw_bk)
  3507.     {
  3508.         if ($was_rule)
  3509.         {
  3510.         $result_rules .= $_ if ! $skipping;
  3511.         }
  3512.         else
  3513.         {
  3514.         $result_vars .= $_ if ! $skipping;
  3515.         }
  3516.         $saw_bk = /\\$/;
  3517.     }
  3518.     elsif (/$RULE_PATTERN/o)
  3519.     {
  3520.         # warn "** Found rule .$1.\n";
  3521.         # Found a rule.
  3522.         $was_rule = 1;
  3523.         $skipping = defined $contents{$1};
  3524.         # warn "** Skip $skipping\n" if $skipping;
  3525.         $result_rules .= $comment . $spacing . $_ if ! $skipping;
  3526.         $comment = $spacing = '';
  3527.         $saw_bk = /\\$/;
  3528.     }
  3529.     elsif (/$MACRO_PATTERN/o)
  3530.     {
  3531.         # warn "** Found macro .$1.\n";
  3532.         # Found a variable reference.
  3533.         $was_rule = 0;
  3534.         $skipping = defined $contents{$1};
  3535.         # warn "** Skip $skipping\n" if $skipping;
  3536.         $result_vars .= $comment . $spacing . $_ if ! $skipping;
  3537.         $comment = $spacing = '';
  3538.         $saw_bk = /\\$/;
  3539.     }
  3540.     else
  3541.     {
  3542.         # This isn't an error; it is probably a continued rule.
  3543.         # In fact, this is what we assume.
  3544.         $was_rule = 1;
  3545.         $result_rules .= $comment . $spacing . $_ if ! $skipping;
  3546.         $comment = $spacing = '';
  3547.         $saw_bk = /\\$/;
  3548.     }
  3549.     }
  3550.  
  3551.     close (FC_FILE);
  3552.     return $result_vars . $result_rules . $comment;
  3553. }
  3554.  
  3555. # Like file_contents_with_transform, but no transform.
  3556. sub file_contents
  3557. {
  3558.     return &file_contents_with_transform ('', @_);
  3559. }
  3560.  
  3561. # Find all variable prefixes that are used for install directories.  A
  3562. # prefix `zar' qualifies iff:
  3563. # * `zardir' is a variable.
  3564. # * `zar_PRIMARY' is a variable.
  3565. sub am_primary_prefixes
  3566. {
  3567.     local ($primary, @prefixes) = @_;
  3568.  
  3569.     local (%valid, $varname);
  3570.     grep ($valid{$_} = 0, @prefixes);
  3571.     $valid{'EXTRA'} = 0;
  3572.     foreach $varname (keys %contents)
  3573.     {
  3574.     if ($varname =~ /^(.*)_$primary$/)
  3575.     {
  3576.         if (! defined $valid{$1} && ! &variable_defined ($1 . 'dir'))
  3577.         {
  3578.         &am_line_error ($varname, "invalid variable \"$varname\"");
  3579.         }
  3580.         else
  3581.         {
  3582.         # Ensure all extended prefixes are actually used.
  3583.         $valid{$1} = 1;
  3584.         }
  3585.     }
  3586.     }
  3587.  
  3588.     return %valid;
  3589. }
  3590.  
  3591. # Handle `where_HOW' variable magic.  Does all lookups, generates
  3592. # install code, and possibly generates code to define the primary
  3593. # variable.  The first argument is the name of the .am file to munge,
  3594. # the second argument is the primary variable (eg HEADERS), and all
  3595. # subsequent arguments are possible installation locations.  Returns
  3596. # list of all values of all _HOW targets.
  3597. #
  3598. # FIXME: this should be rewritten to be cleaner.  It should be broken
  3599. # up into multiple functions.
  3600. #
  3601. # Usage is: am_install_var (OPTION..., file, HOW, where...)
  3602. sub am_install_var
  3603. {
  3604.     local (@args) = @_;
  3605.  
  3606.     local ($do_all, $do_clean) = (1, 0);
  3607.     while (@args)
  3608.     {
  3609.     if ($args[0] eq '-clean')
  3610.     {
  3611.         $do_clean = 1;
  3612.     }
  3613.     elsif ($args[0] eq '-no-all')
  3614.     {
  3615.         $do_all = 0;
  3616.     }
  3617.     elsif ($args[0] !~ /^-/)
  3618.     {
  3619.         last;
  3620.     }
  3621.     shift (@args);
  3622.     }
  3623.     local ($file, $primary, @prefixes) = @args;
  3624.  
  3625.     local (@used) = ();
  3626.     local (@result) = ();
  3627.  
  3628.     # Now that configure substitutions are allowed in where_HOW
  3629.     # variables, it is an error to actually define the primary.
  3630.     &am_line_error ($primary, "\`$primary' is an anachronism")
  3631.     if &variable_defined ($primary);
  3632.  
  3633.  
  3634.     # Look for misspellings.  It is an error to have a variable ending
  3635.     # in a "reserved" suffix whose prefix is unknown, eg
  3636.     # "bni_PROGRAMS".  However, unusual prefixes are allowed if a
  3637.     # variable of the same name (with "dir" appended) exists.  For
  3638.     # instance, if the variable "zardir" is defined, then
  3639.     # "zar_PROGRAMS" becomes valid.  This is to provide a little extra
  3640.     # flexibility in those cases which need it.  Perhaps it should be
  3641.     # disallowed in the Gnits case?  The problem is, sometimes it is
  3642.     # useful to put things in a subdir of eg pkgdatadir, perhaps even
  3643.     # for Gnitsoids.
  3644.     local (%valid) = &am_primary_prefixes ($primary, @prefixes);
  3645.  
  3646.     local ($clean_file) = $file . '-clean';
  3647.     local ($one_name);
  3648.     local ($X);
  3649.     foreach $X (keys %valid)
  3650.     {
  3651.     $one_name = $X . '_' . $primary;
  3652.     if (&variable_defined ($one_name))
  3653.     {
  3654.         # Append actual contents of where_PRIMARY variable to
  3655.         # result.
  3656.         local ($rcurs);
  3657.         foreach $rcurs (&variable_value_as_list ($one_name))
  3658.         {
  3659.         # Skip configure substitutions.  Possibly bogus.
  3660.         next if $rcurs =~ /^\@.*\@$/;
  3661.         push (@result, $rcurs);
  3662.         }
  3663.  
  3664.         # "EXTRA" shouldn't be used when generating clean targets,
  3665.         # @all, or install targets.
  3666.         next if $X eq 'EXTRA';
  3667.  
  3668.         if ($do_clean)
  3669.         {
  3670.         $output_rules .=
  3671.             &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go',
  3672.                            $clean_file);
  3673.  
  3674.         push (@clean, $X . $primary);
  3675.         &push_phony_cleaners ($X . $primary);
  3676.         }
  3677.  
  3678.         if ($X eq 'check')
  3679.         {
  3680.         push (@check, '$(' . $one_name . ')');
  3681.         }
  3682.         else
  3683.         {
  3684.         push (@used, '$(' . $one_name . ')');
  3685.         }
  3686.         if ($X eq 'noinst' || $X eq 'check')
  3687.         {
  3688.         # Objects which don't get installed by default.
  3689.         next;
  3690.         }
  3691.  
  3692.         $output_rules .=
  3693.         &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go',
  3694.                            $file);
  3695.  
  3696.         push (@uninstall, 'uninstall-' . $X . $primary);
  3697.         push (@phony, 'uninstall-' . $X . $primary);
  3698.         push (@installdirs, '$(' . $X . 'dir)');
  3699.         if ($exec_dir_p{$X})
  3700.         {
  3701.         push (@install_exec, 'install-' . $X . $primary);
  3702.         push (@phony, 'install-' . $X . $primary);
  3703.         }
  3704.         else
  3705.         {
  3706.         push (@install_data, 'install-' . $X . $primary);
  3707.         push (@phony, 'install-' . $X . $primary);
  3708.         }
  3709.     }
  3710.     }
  3711.  
  3712.     if (@used)
  3713.     {
  3714.     # Define it.
  3715.     &pretty_print ($primary . ' =', '', @used);
  3716.     $output_vars .= "\n";
  3717.     }
  3718.  
  3719.     # Push here because PRIMARY might be configure time determined.
  3720.     push (@all, '$(' . $primary . ')')
  3721.     if $do_all && @used;
  3722.  
  3723.     return (@result);
  3724. }
  3725.  
  3726.  
  3727. ################################################################
  3728.  
  3729. # This variable is local to the "require file" set of functions.
  3730. @require_file_paths = ();
  3731.  
  3732. # Verify that the file must exist in the current directory.  Usage:
  3733. # require_file (isconfigure, line_number, strictness, file) strictness
  3734. # is the strictness level at which this file becomes required.  Must
  3735. # set require_file_paths before calling this function.
  3736. # require_file_paths is set to hold a single directory (the one in
  3737. # which the first file was found) before return.
  3738. sub require_file_internal
  3739. {
  3740.     local ($is_configure, $line, $mystrict, @files) = @_;
  3741.     local ($file, $fullfile);
  3742.     local ($found_it, $errfile, $errdir);
  3743.     local ($save_dir);
  3744.  
  3745.     foreach $file (@files)
  3746.     {
  3747.     $found_it = 0;
  3748.     foreach $dir (@require_file_paths)
  3749.     {
  3750.         if ($dir eq '.')
  3751.         {
  3752.         $fullfile = $relative_dir . "/" . $file;
  3753.         $errdir = $relative_dir unless $errdir;
  3754.         }
  3755.         else
  3756.         {
  3757.         $fullfile = $dir . "/" . $file;
  3758.         $errdir = $dir unless $errdir;
  3759.         }
  3760.  
  3761.         # Use different name for "error filename".  Otherwise on
  3762.         # an error the bad file will be reported as eg
  3763.         # `../../install-sh' when using the default
  3764.         # config_aux_path.
  3765.         $errfile = $errdir . '/' . $file;
  3766.  
  3767.         if (-f $fullfile)
  3768.         {
  3769.         $found_it = 1;
  3770.         # FIXME: Once again, special-case `.'.
  3771.         &push_dist_common ($file)
  3772.             if $dir eq $relative_dir || $dir eq '.';
  3773.         $save_dir = $dir;
  3774.         last;
  3775.         }
  3776.     }
  3777.  
  3778.     if ($found_it)
  3779.     {
  3780.         # Prune the path list.
  3781.         @require_file_paths = $save_dir;
  3782.     }
  3783.     else
  3784.     {
  3785.         if ($strictness >= $mystrict)
  3786.         {
  3787.         # Only install missing files according to our desired
  3788.         # strictness level.
  3789.         if ($add_missing && -f ($am_dir . '/' . $file))
  3790.         {
  3791.             # Install the missing file.  Symlink if we can, copy
  3792.             # if we must.
  3793.             if ($symlink_exists)
  3794.             {
  3795.             symlink ($am_dir . '/' . $file, $errfile);
  3796.             }
  3797.             else
  3798.             {
  3799.             system ('cp', $am_dir . '/' . $file, $errfile);
  3800.             }
  3801.  
  3802.             # FIXME: this is a hack.  Should have am_warn.
  3803.             local ($save) = $exit_status;
  3804.             if ($is_configure)
  3805.             {
  3806.             &am_conf_line_error
  3807.                 ($line,
  3808.                  "required file \"$errfile\" not found; installing");
  3809.             }
  3810.             else
  3811.             {
  3812.             &am_line_error
  3813.                 ($line,
  3814.                  "required file \"$errfile\" not found; installing");
  3815.             }
  3816.             $exit_status = $save;
  3817.         }
  3818.         else
  3819.         {
  3820.             # Only an error if strictness constraint violated.
  3821.             if ($is_configure)
  3822.             {
  3823.             &am_conf_line_error
  3824.                 ($line, "required file \"$errfile\" not found");
  3825.             }
  3826.             else
  3827.             {
  3828.             &am_line_error
  3829.                 ($line, "required file \"$errfile\" not found");
  3830.             }
  3831.         }
  3832.         }
  3833.     }
  3834.     }
  3835. }
  3836.  
  3837. # Like require_file_with_line, but error messages refer to
  3838. # configure.in, not the current Makefile.am.
  3839. sub require_file_with_conf_line
  3840. {
  3841.     @require_file_paths = '.';
  3842.     &require_file_internal (1, @_);
  3843. }
  3844.  
  3845. sub require_file_with_line
  3846. {
  3847.     @require_file_paths = '.';
  3848.     &require_file_internal (0, @_);
  3849. }
  3850.  
  3851. sub require_file
  3852. {
  3853.     @require_file_paths = '.';
  3854.     &require_file_internal (0, '', @_);
  3855. }
  3856.  
  3857. # Require a file that is also required by Autoconf.  Looks in
  3858. # configuration path, as specified by AC_CONFIG_AUX_DIR.
  3859. sub require_config_file
  3860. {
  3861.     @require_file_paths = @config_aux_path;
  3862.     &require_file_internal (0, '', @_);
  3863.     local ($dir) = $require_file_paths[0];
  3864.     @config_aux_path = @require_file_paths;
  3865.     if ($dir eq '.')
  3866.     {
  3867.     $config_aux_dir = '.';
  3868.     }
  3869.     else
  3870.     {
  3871.     $config_aux_dir = '$(top_srcdir)/' . $dir;
  3872.     }
  3873. }
  3874.  
  3875. # Assumes that the line number is in Makefile.am.
  3876. sub require_conf_file_with_line
  3877. {
  3878.     @require_file_paths = @config_aux_path;
  3879.     &require_file_internal (0, @_);
  3880.     local ($dir) = $require_file_paths[0];
  3881.     @config_aux_path = @require_file_paths;
  3882.     if ($dir eq '.')
  3883.     {
  3884.     $config_aux_dir = '.';
  3885.     }
  3886.     else
  3887.     {
  3888.     $config_aux_dir = '$(top_srcdir)/' . $dir;
  3889.     }
  3890. }
  3891.  
  3892. # Assumes that the line number is in Makefile.am.
  3893. sub require_conf_file_with_conf_line
  3894. {
  3895.     @require_file_paths = @config_aux_path;
  3896.     &require_file_internal (1, @_);
  3897.     local ($dir) = $require_file_paths[0];
  3898.     @config_aux_path = @require_file_paths;
  3899.     if ($dir eq '.')
  3900.     {
  3901.     $config_aux_dir = '.';
  3902.     }
  3903.     else
  3904.     {
  3905.     $config_aux_dir = '$(top_srcdir)/' . $dir;
  3906.     }
  3907. }
  3908.  
  3909. ################################################################
  3910.  
  3911. # Push a list of files onto dist_common.
  3912. sub push_dist_common
  3913. {
  3914.     local (@files) = @_;
  3915.     local ($file);
  3916.  
  3917.     foreach $file (@files)
  3918.     {
  3919.     $dist_common{$file} = 1;
  3920.     }
  3921. }
  3922.  
  3923. # Push a list of clean targets onto phony.
  3924. sub push_phony_cleaners
  3925. {
  3926.     local ($base) = @_;
  3927.     local ($target);
  3928.     foreach $target ('mostly', 'dist', '', 'maintainer-')
  3929.     {
  3930.     push (@phony, $target . 'clean-' . $base);
  3931.     }
  3932. }
  3933.  
  3934. # Set strictness.
  3935. sub set_strictness
  3936. {
  3937.     $strictness_name = $_[0];
  3938.     if ($strictness_name eq 'gnu')
  3939.     {
  3940.     $strictness = $GNU;
  3941.     }
  3942.     elsif ($strictness_name eq 'amiga')
  3943.     {
  3944.     $strictness = $AMIGA;
  3945.     }
  3946.     elsif ($strictness_name eq 'gnits')
  3947.     {
  3948.     $strictness = $GNITS;
  3949.     }
  3950.     elsif ($strictness_name eq 'foreign')
  3951.     {
  3952.     $strictness = $FOREIGN;
  3953.     }
  3954.     else
  3955.     {
  3956.     die "automake: level \`$strictness_name' not recognized\n";
  3957.     }
  3958. }
  3959.  
  3960.  
  3961. ################################################################
  3962.  
  3963. # Return directory name of file.
  3964. sub dirname
  3965. {
  3966.     local ($file) = @_;
  3967.     local ($sub);
  3968.  
  3969.     ($sub = $file) =~ s,/+[^/]+$,,g;
  3970.     $sub = '.' if $sub eq $file;
  3971.     return $sub;
  3972. }
  3973.  
  3974. ################################################################
  3975.  
  3976. # Print an error message and set exit status.
  3977. sub am_error
  3978. {
  3979.     warn "automake: ${am_file}.am: ", join (' ', @_), "\n";
  3980.     $exit_status = 1;
  3981. }
  3982.  
  3983. sub am_line_error
  3984. {
  3985.     local ($symbol, @args) = @_;
  3986.  
  3987.     if ($symbol)
  3988.     {
  3989.     # If SYMBOL not already a line number, look it up in Makefile.am.
  3990.     $symbol = $content_lines{$symbol} unless $symbol =~ /^\d+$/;
  3991.     $symbol .= ': ' if $symbol;
  3992.     warn "${am_file}.am:", $symbol, join (' ', @args), "\n";
  3993.     $exit_status = 1;
  3994.     }
  3995.     else
  3996.     {
  3997.     &am_error (@args);
  3998.     }
  3999. }
  4000.  
  4001. # Like am_error, but while scanning configure.in.
  4002. sub am_conf_error
  4003. {
  4004.     # FIXME: can run in subdirs.
  4005.     warn "automake: configure.in: ", join (' ', @_), "\n";
  4006.     $exit_status = 1;
  4007. }
  4008.  
  4009. # Error message with line number referring to configure.in.
  4010. sub am_conf_line_error
  4011. {
  4012.     local ($line, @args) = @_;
  4013.  
  4014.     if ($line)
  4015.     {
  4016.     warn "configure.in: $line: ", join (' ', @args), "\n";
  4017.     $exit_status = 1;
  4018.     }
  4019.     else
  4020.     {
  4021.     &am_conf_error (@args);
  4022.     }
  4023. }
  4024.  
  4025. # Tell user where our aclocal.m4 is, but only once.
  4026. sub keyed_aclocal_warning
  4027. {
  4028.     local ($key) = @_;
  4029.     warn "automake: macro \`$key' can be generated by \`aclocal'\n";
  4030. }
  4031.  
  4032. # Print usage information.
  4033. sub usage
  4034. {
  4035.     print "Usage: automake [OPTION] ... [Makefile]...\n";
  4036.     print $USAGE;
  4037.     print "\nFiles which are automatically distributed, if found:\n";
  4038.     $~ = "USAGE_FORMAT";
  4039.     local (@lcomm) = sort ((@common_files, @common_sometimes));
  4040.     local ($one, $two, $three, $four);
  4041.     while (@lcomm > 0)
  4042.     {
  4043.     $one = shift @lcomm;
  4044.     $two = @lcomm ? shift @lcomm : '';
  4045.     $three = @lcomm ? shift @lcomm : '';
  4046.     $four = @lcomm ? shift @lcomm : '';
  4047.     write;
  4048.     }
  4049.  
  4050.     print "\nReport bugs to <bug-gnu-utils\@prep.ai.mit.edu>\n";
  4051.  
  4052.     exit 0;
  4053. }
  4054.  
  4055. format USAGE_FORMAT =
  4056.   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
  4057.   $one,               $two,               $three,             $four
  4058. .
  4059.