"Fossies" - the Fresh Open Source Software Archive

Member "automake-1.16.3/bin/automake.in" (19 Nov 2020, 259422 Bytes) of package /linux/misc/automake-1.16.3.tar.xz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "automake.in": 1.16.2_vs_1.16.3.

    1 #!@PERL@
    2 # automake - create Makefile.in from Makefile.am            -*- perl -*-
    3 # @configure_input@
    4 # Copyright (C) 1994-2020 Free Software Foundation, Inc.
    5 
    6 # This program is free software; you can redistribute it and/or modify
    7 # it under the terms of the GNU General Public License as published by
    8 # the Free Software Foundation; either version 2, or (at your option)
    9 # any later version.
   10 
   11 # This program is distributed in the hope that it will be useful,
   12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
   13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14 # GNU General Public License for more details.
   15 
   16 # You should have received a copy of the GNU General Public License
   17 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
   18 
   19 # Originally written by David Mackenzie <djm@gnu.ai.mit.edu>.
   20 # Perl reimplementation by Tom Tromey <tromey@redhat.com>, and
   21 # Alexandre Duret-Lutz <adl@gnu.org>.
   22 
   23 package Automake;
   24 
   25 use 5.006;
   26 use strict;
   27 use warnings FATAL => 'all';
   28 
   29 BEGIN
   30 {
   31   unshift (@INC, '@datadir@/@PACKAGE@-@APIVERSION@')
   32     unless $ENV{AUTOMAKE_UNINSTALLED};
   33 
   34   # Override SHELL.  This is required on DJGPP so that system() uses
   35   # bash, not COMMAND.COM which doesn't quote arguments properly.
   36   # Other systems aren't expected to use $SHELL when Automake
   37   # runs, but it should be safe to drop the "if DJGPP" guard if
   38   # it turns up other systems need the same thing.  After all,
   39   # if SHELL is used, ./configure's SHELL is always better than
   40   # the user's SHELL (which may be something like tcsh).
   41   $ENV{'SHELL'} = '@SHELL@' if exists $ENV{'DJDIR'};
   42 }
   43 
   44 use Carp;
   45 use File::Basename;
   46 use File::Spec;
   47 
   48 use Automake::Config;
   49 BEGIN
   50 {
   51   if ($perl_threads)
   52     {
   53       require threads;
   54       import threads;
   55       require Thread::Queue;
   56       import Thread::Queue;
   57     }
   58 }
   59 use Automake::General;
   60 use Automake::XFile;
   61 use Automake::Channels;
   62 use Automake::ChannelDefs;
   63 use Automake::Configure_ac;
   64 use Automake::FileUtils;
   65 use Automake::Location;
   66 use Automake::Condition qw/TRUE FALSE/;
   67 use Automake::DisjConditions;
   68 use Automake::Options;
   69 use Automake::Variable;
   70 use Automake::VarDef;
   71 use Automake::Rule;
   72 use Automake::RuleDef;
   73 use Automake::Wrap 'makefile_wrap';
   74 use Automake::Language;
   75 
   76 ## ----------------------- ##
   77 ## Subroutine prototypes.  ##
   78 ## ----------------------- ##
   79 
   80 sub append_exeext (&$);
   81 sub check_gnits_standards ();
   82 sub check_gnu_standards ();
   83 sub check_trailing_slash ($\$);
   84 sub check_typos ();
   85 sub define_files_variable ($\@$$);
   86 sub define_standard_variables ();
   87 sub define_verbose_libtool ();
   88 sub define_verbose_texinfo ();
   89 sub do_check_merge_target ();
   90 sub get_number_of_threads ();
   91 sub handle_compile ();
   92 sub handle_data ();
   93 sub handle_dist ();
   94 sub handle_emacs_lisp ();
   95 sub handle_factored_dependencies ();
   96 sub handle_footer ();
   97 sub handle_gettext ();
   98 sub handle_headers ();
   99 sub handle_install ();
  100 sub handle_java ();
  101 sub handle_languages ();
  102 sub handle_libraries ();
  103 sub handle_libtool ();
  104 sub handle_ltlibraries ();
  105 sub handle_makefiles_serial ();
  106 sub handle_man_pages ();
  107 sub handle_minor_options ();
  108 sub handle_options ();
  109 sub handle_programs ();
  110 sub handle_python ();
  111 sub handle_scripts ();
  112 sub handle_silent ();
  113 sub handle_subdirs ();
  114 sub handle_tags ();
  115 sub handle_targets ();
  116 sub handle_tests ();
  117 sub handle_tests_dejagnu ();
  118 sub handle_texinfo ();
  119 sub handle_user_recursion ();
  120 sub initialize_per_input ();
  121 sub lang_lex_finish ();
  122 sub lang_sub_obj ();
  123 sub lang_vala_finish ();
  124 sub lang_yacc_finish ();
  125 sub locate_aux_dir ();
  126 sub parse_arguments ();
  127 sub scan_aclocal_m4 ();
  128 sub scan_autoconf_files ();
  129 sub silent_flag ();
  130 sub transform ($\%);
  131 sub transform_token ($\%$);
  132 sub usage ();
  133 sub version ();
  134 sub yacc_lex_finish_helper ();
  135 
  136 ## ----------- ##
  137 ## Constants.  ##
  138 ## ----------- ##
  139 
  140 # Some regular expressions.  One reason to put them here is that it
  141 # makes indentation work better in Emacs.
  142 
  143 # Writing singled-quoted-$-terminated regexes is a pain because
  144 # perl-mode thinks of $' as the ${'} variable (instead of a $ followed
  145 # by a closing quote.  Letting perl-mode think the quote is not closed
  146 # leads to all sort of misindentations.  On the other hand, defining
  147 # regexes as double-quoted strings is far less readable.  So usually
  148 # we will write:
  149 #
  150 #  $REGEX = '^regex_value' . "\$";
  151 
  152 my $IGNORE_PATTERN = '^\s*##([^#\n].*)?\n';
  153 my $WHITE_PATTERN = '^\s*' . "\$";
  154 my $COMMENT_PATTERN = '^#';
  155 my $TARGET_PATTERN='[$a-zA-Z0-9_.@%][-.a-zA-Z0-9_(){}/$+@%]*';
  156 # A rule has three parts: a list of targets, a list of dependencies,
  157 # and optionally actions.
  158 my $RULE_PATTERN =
  159   "^($TARGET_PATTERN(?:(?:\\\\\n|\\s)+$TARGET_PATTERN)*) *:([^=].*|)\$";
  160 
  161 # Only recognize leading spaces, not leading tabs.  If we recognize
  162 # leading tabs here then we need to make the reader smarter, because
  163 # otherwise it will think rules like 'foo=bar; \' are errors.
  164 my $ASSIGNMENT_PATTERN = '^ *([^ \t=:+]*)\s*([:+]?)=\s*(.*)' . "\$";
  165 # This pattern recognizes a Gnits version id and sets $1 if the
  166 # release is an alpha release.  We also allow a suffix which can be
  167 # used to extend the version number with a "fork" identifier.
  168 my $GNITS_VERSION_PATTERN = '\d+\.\d+([a-z]|\.\d+)?(-[A-Za-z0-9]+)?';
  169 
  170 my $IF_PATTERN = '^if\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*)\s*(?:#.*)?' . "\$";
  171 my $ELSE_PATTERN =
  172   '^else(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?' . "\$";
  173 my $ENDIF_PATTERN =
  174   '^endif(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?' . "\$";
  175 my $PATH_PATTERN = '(\w|[+/.-])+';
  176 # This will pass through anything not of the prescribed form.
  177 my $INCLUDE_PATTERN = ('^include\s+'
  178 		       . '((\$\(top_srcdir\)/' . $PATH_PATTERN . ')'
  179 		       . '|(\$\(srcdir\)/' . $PATH_PATTERN . ')'
  180 		       . '|([^/\$]' . $PATH_PATTERN . '))\s*(#.*)?' . "\$");
  181 
  182 # Directories installed during 'install-exec' phase.
  183 my $EXEC_DIR_PATTERN =
  184   '^(?:bin|sbin|libexec|sysconf|localstate|lib|pkglib|.*exec.*)' . "\$";
  185 
  186 # Values for AC_CANONICAL_*
  187 use constant AC_CANONICAL_BUILD  => 1;
  188 use constant AC_CANONICAL_HOST   => 2;
  189 use constant AC_CANONICAL_TARGET => 3;
  190 
  191 # Values indicating when something should be cleaned.
  192 use constant MOSTLY_CLEAN     => 0;
  193 use constant CLEAN            => 1;
  194 use constant DIST_CLEAN       => 2;
  195 use constant MAINTAINER_CLEAN => 3;
  196 
  197 # Libtool files.
  198 my @libtool_files = qw(ltmain.sh config.guess config.sub);
  199 # ltconfig appears here for compatibility with old versions of libtool.
  200 my @libtool_sometimes = qw(ltconfig ltcf-c.sh ltcf-cxx.sh ltcf-gcj.sh);
  201 
  202 # Commonly found files we look for and automatically include in
  203 # DISTFILES.
  204 my @common_files =
  205     (qw(ABOUT-GNU ABOUT-NLS AUTHORS BACKLOG COPYING COPYING.DOC COPYING.LIB
  206 	COPYING.LESSER ChangeLog INSTALL NEWS README THANKS TODO
  207 	ar-lib compile config.guess config.rpath
  208 	config.sub depcomp install-sh libversion.in mdate-sh
  209 	missing mkinstalldirs py-compile texinfo.tex ylwrap),
  210      @libtool_files, @libtool_sometimes);
  211 
  212 # Commonly used files we auto-include, but only sometimes.  This list
  213 # is used for the --help output only.
  214 my @common_sometimes =
  215   qw(aclocal.m4 acconfig.h config.h.top config.h.bot configure
  216      configure.ac configure.in stamp-vti);
  217 
  218 # Standard directories from the GNU Coding Standards, and additional
  219 # pkg* directories from Automake.  Stored in a hash for fast member check.
  220 my %standard_prefix =
  221     map { $_ => 1 } (qw(bin data dataroot doc dvi exec html include info
  222 			lib libexec lisp locale localstate man man1 man2
  223 			man3 man4 man5 man6 man7 man8 man9 oldinclude pdf
  224 			pkgdata pkginclude pkglib pkglibexec ps sbin
  225 			sharedstate sysconf));
  226 
  227 # Copyright on generated Makefile.ins.
  228 my $gen_copyright = "\
  229 # Copyright (C) 1994-$RELEASE_YEAR Free Software Foundation, Inc.
  230 
  231 # This Makefile.in is free software; the Free Software Foundation
  232 # gives unlimited permission to copy and/or distribute it,
  233 # with or without modifications, as long as this notice is preserved.
  234 
  235 # This program is distributed in the hope that it will be useful,
  236 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
  237 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  238 # PARTICULAR PURPOSE.
  239 ";
  240 
  241 # These constants are returned by the lang_*_rewrite functions.
  242 # LANG_SUBDIR means that the resulting object file should be in a
  243 # subdir if the source file is.  In this case the file name cannot
  244 # have '..' components.
  245 use constant LANG_IGNORE  => 0;
  246 use constant LANG_PROCESS => 1;
  247 use constant LANG_SUBDIR  => 2;
  248 
  249 # These are used when keeping track of whether an object can be built
  250 # by two different paths.
  251 use constant COMPILE_LIBTOOL  => 1;
  252 use constant COMPILE_ORDINARY => 2;
  253 
  254 # We can't always associate a location to a variable or a rule,
  255 # when it's defined by Automake.  We use INTERNAL in this case.
  256 use constant INTERNAL => new Automake::Location;
  257 
  258 # Serialization keys for message queues.
  259 use constant QUEUE_MESSAGE   => "msg";
  260 use constant QUEUE_CONF_FILE => "conf file";
  261 use constant QUEUE_LOCATION  => "location";
  262 use constant QUEUE_STRING    => "string";
  263 
  264 ## ---------------------------------- ##
  265 ## Variables related to the options.  ##
  266 ## ---------------------------------- ##
  267 
  268 # TRUE if we should always generate Makefile.in.
  269 my $force_generation = 1;
  270 
  271 # From the Perl manual.
  272 my $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
  273 
  274 # TRUE if missing standard files should be installed.
  275 my $add_missing = 0;
  276 
  277 # TRUE if we should copy missing files; otherwise symlink if possible.
  278 my $copy_missing = 0;
  279 
  280 # TRUE if we should always update files that we know about.
  281 my $force_missing = 0;
  282 
  283 
  284 ## ---------------------------------------- ##
  285 ## Variables filled during files scanning.  ##
  286 ## ---------------------------------------- ##
  287 
  288 # Name of the configure.ac file.
  289 my $configure_ac;
  290 
  291 # Files found by scanning configure.ac for LIBOBJS.
  292 my %libsources = ();
  293 
  294 # Names used in AC_CONFIG_HEADERS call.
  295 my @config_headers = ();
  296 
  297 # Names used in AC_CONFIG_LINKS call.
  298 my @config_links = ();
  299 
  300 # List of Makefile.am's to process, and their corresponding outputs.
  301 my @input_files = ();
  302 my %output_files = ();
  303 
  304 # Complete list of Makefile.am's that exist.
  305 my @configure_input_files = ();
  306 
  307 # List of files in AC_CONFIG_FILES/AC_OUTPUT without Makefile.am's,
  308 # and their outputs.
  309 my @other_input_files = ();
  310 # Where each AC_CONFIG_FILES/AC_OUTPUT/AC_CONFIG_LINK/AC_CONFIG_HEADERS
  311 # appears.  The keys are the files created by these macros.
  312 my %ac_config_files_location = ();
  313 # The condition under which AC_CONFIG_FOOS appears.
  314 my %ac_config_files_condition = ();
  315 
  316 # Directory to search for configure-required files.  This
  317 # will be computed by locate_aux_dir() and can be set using
  318 # AC_CONFIG_AUX_DIR in configure.ac.
  319 # $CONFIG_AUX_DIR is the 'raw' directory, valid only in the source-tree.
  320 my $config_aux_dir = '';
  321 my $config_aux_dir_set_in_configure_ac = 0;
  322 # $AM_CONFIG_AUX_DIR is prefixed with $(top_srcdir), so it can be used
  323 # in Makefiles.
  324 my $am_config_aux_dir = '';
  325 
  326 # Directory to search for AC_LIBSOURCE files, as set by AC_CONFIG_LIBOBJ_DIR
  327 # in configure.ac.
  328 my $config_libobj_dir = '';
  329 
  330 # Whether AM_GNU_GETTEXT has been seen in configure.ac.
  331 my $seen_gettext = 0;
  332 # Whether AM_GNU_GETTEXT([external]) is used.
  333 my $seen_gettext_external = 0;
  334 # Where AM_GNU_GETTEXT appears.
  335 my $ac_gettext_location;
  336 # Whether AM_GNU_GETTEXT_INTL_SUBDIR has been seen.
  337 my $seen_gettext_intl = 0;
  338 
  339 # The arguments of the AM_EXTRA_RECURSIVE_TARGETS call (if any).
  340 my @extra_recursive_targets = ();
  341 
  342 # Lists of tags supported by Libtool.
  343 my %libtool_tags = ();
  344 # 1 if Libtool uses LT_SUPPORTED_TAG.  If it does, then it also
  345 # uses AC_REQUIRE_AUX_FILE.
  346 my $libtool_new_api = 0;
  347 
  348 # Most important AC_CANONICAL_* macro seen so far.
  349 my $seen_canonical = 0;
  350 
  351 # Where AM_MAINTAINER_MODE appears.
  352 my $seen_maint_mode;
  353 
  354 # Actual version we've seen.
  355 my $package_version = '';
  356 
  357 # Where version is defined.
  358 my $package_version_location;
  359 
  360 # TRUE if we've seen AM_PROG_AR
  361 my $seen_ar = 0;
  362 
  363 # Location of AC_REQUIRE_AUX_FILE calls, indexed by their argument.
  364 my %required_aux_file = ();
  365 
  366 # Where AM_INIT_AUTOMAKE is called.
  367 my $seen_init_automake = 0;
  368 
  369 # TRUE if we've seen AM_AUTOMAKE_VERSION.
  370 my $seen_automake_version = 0;
  371 
  372 # Hash table of discovered configure substitutions.  Keys are names,
  373 # values are 'FILE:LINE' strings which are used by error message
  374 # generation.
  375 my %configure_vars = ();
  376 
  377 # Ignored configure substitutions (i.e., variables not to be output in
  378 # Makefile.in)
  379 my %ignored_configure_vars = ();
  380 
  381 # Files included by $configure_ac.
  382 my @configure_deps = ();
  383 
  384 # Greatest timestamp of configure's dependencies.
  385 my $configure_deps_greatest_timestamp = 0;
  386 
  387 # Hash table of AM_CONDITIONAL variables seen in configure.
  388 my %configure_cond = ();
  389 
  390 # This maps extensions onto language names.
  391 my %extension_map = ();
  392 
  393 # List of the DIST_COMMON files we discovered while reading
  394 # configure.ac.
  395 my @configure_dist_common = ();
  396 
  397 # This maps languages names onto objects.
  398 my %languages = ();
  399 # Maps each linker variable onto a language object.
  400 my %link_languages = ();
  401 
  402 # maps extensions to needed source flags.
  403 my %sourceflags = ();
  404 
  405 # List of targets we must always output.
  406 # FIXME: Complete, and remove falsely required targets.
  407 my %required_targets =
  408   (
  409    'all'          => 1,
  410    'dvi'	  => 1,
  411    'pdf'	  => 1,
  412    'ps'		  => 1,
  413    'info'	  => 1,
  414    'install-info' => 1,
  415    'install'      => 1,
  416    'install-data' => 1,
  417    'install-exec' => 1,
  418    'uninstall'    => 1,
  419 
  420    # FIXME: Not required, temporary hacks.
  421    # Well, actually they are sort of required: the -recursive
  422    # targets will run them anyway...
  423    'html-am'         => 1,
  424    'dvi-am'          => 1,
  425    'pdf-am'          => 1,
  426    'ps-am'           => 1,
  427    'info-am'         => 1,
  428    'install-data-am' => 1,
  429    'install-exec-am' => 1,
  430    'install-html-am' => 1,
  431    'install-dvi-am'  => 1,
  432    'install-pdf-am'  => 1,
  433    'install-ps-am'   => 1,
  434    'install-info-am' => 1,
  435    'installcheck-am' => 1,
  436    'uninstall-am'    => 1,
  437    'tags-am'         => 1,
  438    'ctags-am'        => 1,
  439    'cscopelist-am'   => 1,
  440    'install-man'     => 1,
  441   );
  442 
  443 # Queue to push require_conf_file requirements to.
  444 my $required_conf_file_queue;
  445 
  446 # The name of the Makefile currently being processed.
  447 my $am_file = 'BUG';
  448 
  449 ################################################################
  450 
  451 ## ------------------------------------------ ##
  452 ## Variables reset by &initialize_per_input.  ##
  453 ## ------------------------------------------ ##
  454 
  455 # Relative dir of the output makefile.
  456 my $relative_dir;
  457 
  458 # Greatest timestamp of the output's dependencies (excluding
  459 # configure's dependencies).
  460 my $output_deps_greatest_timestamp;
  461 
  462 # These variables are used when generating each Makefile.in.
  463 # They hold the Makefile.in until it is ready to be printed.
  464 my $output_vars;
  465 my $output_all;
  466 my $output_header;
  467 my $output_rules;
  468 my $output_trailer;
  469 
  470 # This is the conditional stack, updated on if/else/endif, and
  471 # used to build Condition objects.
  472 my @cond_stack;
  473 
  474 # This holds the set of included files.
  475 my @include_stack;
  476 
  477 # List of dependencies for the obvious targets.
  478 my @all;
  479 my @check;
  480 my @check_tests;
  481 
  482 # Keys in this hash table are files to delete.  The associated
  483 # value tells when this should happen (MOSTLY_CLEAN, DIST_CLEAN, etc.)
  484 my %clean_files;
  485 
  486 # Keys in this hash table are object files or other files in
  487 # subdirectories which need to be removed.  This only holds files
  488 # which are created by compilations.  The value in the hash indicates
  489 # when the file should be removed.
  490 my %compile_clean_files;
  491 
  492 # Keys in this hash table are directories where we expect to build a
  493 # libtool object.  We use this information to decide what directories
  494 # to delete.
  495 my %libtool_clean_directories;
  496 
  497 # Value of $(SOURCES), used by tags.am.
  498 my @sources;
  499 # Sources which go in the distribution.
  500 my @dist_sources;
  501 
  502 # This hash maps object file names onto their corresponding source
  503 # file names.  This is used to ensure that each object is created
  504 # by a single source file.
  505 my %object_map;
  506 
  507 # This hash maps object file names onto an integer value representing
  508 # whether this object has been built via ordinary compilation or
  509 # libtool compilation (the COMPILE_* constants).
  510 my %object_compilation_map;
  511 
  512 
  513 # This keeps track of the directories for which we've already
  514 # created dirstamp code.  Keys are directories, values are stamp files.
  515 # Several keys can share the same stamp files if they are equivalent
  516 # (as are './/foo' and 'foo').
  517 my %directory_map;
  518 
  519 # All .P files.
  520 my %dep_files;
  521 
  522 # This is a list of all targets to run during "make dist".
  523 my @dist_targets;
  524 
  525 # List of all programs, libraries and ltlibraries as returned
  526 # by am_install_var
  527 my @proglist;
  528 my @liblist;
  529 my @ltliblist;
  530 # Blacklist of targets (as canonical base name) for which object file names
  531 # may not be automatically shortened
  532 my @dup_shortnames;
  533 
  534 # Keep track of all programs declared in this Makefile, without
  535 # $(EXEEXT).  @substitutions@ are not listed.
  536 my %known_programs;
  537 my %known_libraries;
  538 
  539 # This keeps track of which extensions we've seen (that we care
  540 # about).
  541 my %extension_seen;
  542 
  543 # This is random scratch space for the language finish functions.
  544 # Don't randomly overwrite it; examine other uses of keys first.
  545 my %language_scratch;
  546 
  547 # We keep track of which objects need special (per-executable)
  548 # handling on a per-language basis.
  549 my %lang_specific_files;
  550 
  551 # List of distributed files to be put in DIST_COMMON.
  552 my @dist_common;
  553 
  554 # This is set when 'handle_dist' has finished.  Once this happens,
  555 # we should no longer push on dist_common.
  556 my $handle_dist_run;
  557 
  558 # Used to store a set of linkers needed to generate the sources currently
  559 # under consideration.
  560 my %linkers_used;
  561 
  562 # True if we need 'LINK' defined.  This is a hack.
  563 my $need_link;
  564 
  565 # Does the generated Makefile have to build some compiled object
  566 # (for binary programs, or plain or libtool libraries)?
  567 my $must_handle_compiled_objects;
  568 
  569 # Record each file processed by make_paragraphs.
  570 my %transformed_files;
  571 
  572 ################################################################
  573 
  574 ## ---------------------------------------------- ##
  575 ## Variables not reset by &initialize_per_input.  ##
  576 ## ---------------------------------------------- ##
  577 
  578 # Cache each file processed by make_paragraphs.
  579 # (This is different from %transformed_files because
  580 # %transformed_files is reset for each file while %am_file_cache
  581 # it global to the run.)
  582 my %am_file_cache;
  583 
  584 ################################################################
  585 
  586 # var_SUFFIXES_trigger ($TYPE, $VALUE)
  587 # ------------------------------------
  588 # This is called by Automake::Variable::define() when SUFFIXES
  589 # is defined ($TYPE eq '') or appended ($TYPE eq '+').
  590 # The work here needs to be performed as a side-effect of the
  591 # macro_define() call because SUFFIXES definitions impact
  592 # on $KNOWN_EXTENSIONS_PATTERN which is used used when parsing
  593 # the input am file.
  594 sub var_SUFFIXES_trigger
  595 {
  596     my ($type, $value) = @_;
  597     accept_extensions (split (' ', $value));
  598 }
  599 Automake::Variable::hook ('SUFFIXES', \&var_SUFFIXES_trigger);
  600 
  601 ################################################################
  602 
  603 
  604 # initialize_per_input ()
  605 # -----------------------
  606 # (Re)-Initialize per-Makefile.am variables.
  607 sub initialize_per_input ()
  608 {
  609     reset_local_duplicates ();
  610 
  611     $relative_dir = undef;
  612 
  613     $output_deps_greatest_timestamp = 0;
  614 
  615     $output_vars = '';
  616     $output_all = '';
  617     $output_header = '';
  618     $output_rules = '';
  619     $output_trailer = '';
  620 
  621     Automake::Options::reset;
  622     Automake::Variable::reset;
  623     Automake::Rule::reset;
  624 
  625     @cond_stack = ();
  626 
  627     @include_stack = ();
  628 
  629     @all = ();
  630     @check = ();
  631     @check_tests = ();
  632 
  633     %clean_files = ();
  634     %compile_clean_files = ();
  635 
  636     # We always include '.'.  This isn't strictly correct.
  637     %libtool_clean_directories = ('.' => 1);
  638 
  639     @sources = ();
  640     @dist_sources = ();
  641 
  642     %object_map = ();
  643     %object_compilation_map = ();
  644 
  645     %directory_map = ();
  646 
  647     %dep_files = ();
  648 
  649     @dist_targets = ();
  650 
  651     @dist_common = ();
  652     $handle_dist_run = 0;
  653 
  654     @proglist = ();
  655     @liblist = ();
  656     @ltliblist = ();
  657     @dup_shortnames = ();
  658 
  659     %known_programs = ();
  660     %known_libraries = ();
  661 
  662     %extension_seen = ();
  663 
  664     %language_scratch = ();
  665 
  666     %lang_specific_files = ();
  667 
  668     $need_link = 0;
  669 
  670     $must_handle_compiled_objects = 0;
  671 
  672     %transformed_files = ();
  673 }
  674 
  675 
  676 ################################################################
  677 
  678 # Initialize our list of languages that are internally supported.
  679 
  680 my @cpplike_flags =
  681   qw{
  682     $(DEFS)
  683     $(DEFAULT_INCLUDES)
  684     $(INCLUDES)
  685     $(AM_CPPFLAGS)
  686     $(CPPFLAGS)
  687   };
  688 
  689 # C.
  690 register_language ('name' => 'c',
  691 		   'Name' => 'C',
  692 		   'config_vars' => ['CC'],
  693 		   'autodep' => '',
  694 		   'flags' => ['CFLAGS', 'CPPFLAGS'],
  695 		   'ccer' => 'CC',
  696 		   'compiler' => 'COMPILE',
  697 		   'compile' => "\$(CC) @cpplike_flags \$(AM_CFLAGS) \$(CFLAGS)",
  698 		   'lder' => 'CCLD',
  699 		   'ld' => '$(CC)',
  700 		   'linker' => 'LINK',
  701 		   'link' => '$(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
  702 		   'compile_flag' => '-c',
  703 		   'output_flag' => '-o',
  704 		   'libtool_tag' => 'CC',
  705 		   'extensions' => ['.c']);
  706 
  707 # C++.
  708 register_language ('name' => 'cxx',
  709 		   'Name' => 'C++',
  710 		   'config_vars' => ['CXX'],
  711 		   'linker' => 'CXXLINK',
  712 		   'link' => '$(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
  713 		   'autodep' => 'CXX',
  714 		   'flags' => ['CXXFLAGS', 'CPPFLAGS'],
  715 		   'compile' => "\$(CXX) @cpplike_flags \$(AM_CXXFLAGS) \$(CXXFLAGS)",
  716 		   'ccer' => 'CXX',
  717 		   'compiler' => 'CXXCOMPILE',
  718 		   'compile_flag' => '-c',
  719 		   'output_flag' => '-o',
  720 		   'libtool_tag' => 'CXX',
  721 		   'lder' => 'CXXLD',
  722 		   'ld' => '$(CXX)',
  723 		   'pure' => 1,
  724 		   'extensions' => ['.c++', '.cc', '.cpp', '.cxx', '.C']);
  725 
  726 # Objective C.
  727 register_language ('name' => 'objc',
  728 		   'Name' => 'Objective C',
  729 		   'config_vars' => ['OBJC'],
  730 		   'linker' => 'OBJCLINK',
  731 		   'link' => '$(OBJCLD) $(AM_OBJCFLAGS) $(OBJCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
  732 		   'autodep' => 'OBJC',
  733 		   'flags' => ['OBJCFLAGS', 'CPPFLAGS'],
  734 		   'compile' => "\$(OBJC) @cpplike_flags \$(AM_OBJCFLAGS) \$(OBJCFLAGS)",
  735 		   'ccer' => 'OBJC',
  736 		   'compiler' => 'OBJCCOMPILE',
  737 		   'compile_flag' => '-c',
  738 		   'output_flag' => '-o',
  739 		   'lder' => 'OBJCLD',
  740 		   'ld' => '$(OBJC)',
  741 		   'pure' => 1,
  742 		   'extensions' => ['.m']);
  743 
  744 # Objective C++.
  745 register_language ('name' => 'objcxx',
  746 		   'Name' => 'Objective C++',
  747 		   'config_vars' => ['OBJCXX'],
  748 		   'linker' => 'OBJCXXLINK',
  749 		   'link' => '$(OBJCXXLD) $(AM_OBJCXXFLAGS) $(OBJCXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
  750 		   'autodep' => 'OBJCXX',
  751 		   'flags' => ['OBJCXXFLAGS', 'CPPFLAGS'],
  752 		   'compile' => "\$(OBJCXX) @cpplike_flags \$(AM_OBJCXXFLAGS) \$(OBJCXXFLAGS)",
  753 		   'ccer' => 'OBJCXX',
  754 		   'compiler' => 'OBJCXXCOMPILE',
  755 		   'compile_flag' => '-c',
  756 		   'output_flag' => '-o',
  757 		   'lder' => 'OBJCXXLD',
  758 		   'ld' => '$(OBJCXX)',
  759 		   'pure' => 1,
  760 		   'extensions' => ['.mm']);
  761 
  762 # Unified Parallel C.
  763 register_language ('name' => 'upc',
  764 		   'Name' => 'Unified Parallel C',
  765 		   'config_vars' => ['UPC'],
  766 		   'linker' => 'UPCLINK',
  767 		   'link' => '$(UPCLD) $(AM_UPCFLAGS) $(UPCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
  768 		   'autodep' => 'UPC',
  769 		   'flags' => ['UPCFLAGS', 'CPPFLAGS'],
  770 		   'compile' => "\$(UPC) @cpplike_flags \$(AM_UPCFLAGS) \$(UPCFLAGS)",
  771 		   'ccer' => 'UPC',
  772 		   'compiler' => 'UPCCOMPILE',
  773 		   'compile_flag' => '-c',
  774 		   'output_flag' => '-o',
  775 		   'lder' => 'UPCLD',
  776 		   'ld' => '$(UPC)',
  777 		   'pure' => 1,
  778 		   'extensions' => ['.upc']);
  779 
  780 # Headers.
  781 register_language ('name' => 'header',
  782 		   'Name' => 'Header',
  783 		   'extensions' => ['.h', '.H', '.hxx', '.h++', '.hh',
  784 				    '.hpp', '.inc'],
  785 		   # No output.
  786 		   'output_extensions' => sub { return () },
  787 		   # Nothing to do.
  788 		   '_finish' => sub { });
  789 
  790 # Vala
  791 register_language ('name' => 'vala',
  792 		   'Name' => 'Vala',
  793 		   'config_vars' => ['VALAC'],
  794 		   'flags' => [],
  795 		   'compile' => '$(VALAC) $(AM_VALAFLAGS) $(VALAFLAGS)',
  796 		   'ccer' => 'VALAC',
  797 		   'compiler' => 'VALACOMPILE',
  798 		   'extensions' => ['.vala'],
  799 		   'output_extensions' => sub { (my $ext = $_[0]) =~ s/vala$/c/;
  800 						return ($ext,) },
  801 		   'rule_file' => 'vala',
  802 		   '_finish' => \&lang_vala_finish,
  803 		   '_target_hook' => \&lang_vala_target_hook,
  804 		   'nodist_specific' => 1);
  805 
  806 # Yacc (C & C++).
  807 register_language ('name' => 'yacc',
  808 		   'Name' => 'Yacc',
  809 		   'config_vars' => ['YACC'],
  810 		   'flags' => ['YFLAGS'],
  811 		   'compile' => '$(YACC) $(AM_YFLAGS) $(YFLAGS)',
  812 		   'ccer' => 'YACC',
  813 		   'compiler' => 'YACCCOMPILE',
  814 		   'extensions' => ['.y'],
  815 		   'output_extensions' => sub { (my $ext = $_[0]) =~ tr/y/c/;
  816 						return ($ext,) },
  817 		   'rule_file' => 'yacc',
  818 		   '_finish' => \&lang_yacc_finish,
  819 		   '_target_hook' => \&lang_yacc_target_hook,
  820 		   'nodist_specific' => 1);
  821 register_language ('name' => 'yaccxx',
  822 		   'Name' => 'Yacc (C++)',
  823 		   'config_vars' => ['YACC'],
  824 		   'rule_file' => 'yacc',
  825 		   'flags' => ['YFLAGS'],
  826 		   'ccer' => 'YACC',
  827 		   'compiler' => 'YACCCOMPILE',
  828 		   'compile' => '$(YACC) $(AM_YFLAGS) $(YFLAGS)',
  829 		   'extensions' => ['.y++', '.yy', '.yxx', '.ypp'],
  830 		   'output_extensions' => sub { (my $ext = $_[0]) =~ tr/y/c/;
  831 						return ($ext,) },
  832 		   '_finish' => \&lang_yacc_finish,
  833 		   '_target_hook' => \&lang_yacc_target_hook,
  834 		   'nodist_specific' => 1);
  835 
  836 # Lex (C & C++).
  837 register_language ('name' => 'lex',
  838 		   'Name' => 'Lex',
  839 		   'config_vars' => ['LEX'],
  840 		   'rule_file' => 'lex',
  841 		   'flags' => ['LFLAGS'],
  842 		   'compile' => '$(LEX) $(AM_LFLAGS) $(LFLAGS)',
  843 		   'ccer' => 'LEX',
  844 		   'compiler' => 'LEXCOMPILE',
  845 		   'extensions' => ['.l'],
  846 		   'output_extensions' => sub { (my $ext = $_[0]) =~ tr/l/c/;
  847 						return ($ext,) },
  848 		   '_finish' => \&lang_lex_finish,
  849 		   '_target_hook' => \&lang_lex_target_hook,
  850 		   'nodist_specific' => 1);
  851 register_language ('name' => 'lexxx',
  852 		   'Name' => 'Lex (C++)',
  853 		   'config_vars' => ['LEX'],
  854 		   'rule_file' => 'lex',
  855 		   'flags' => ['LFLAGS'],
  856 		   'compile' => '$(LEX) $(AM_LFLAGS) $(LFLAGS)',
  857 		   'ccer' => 'LEX',
  858 		   'compiler' => 'LEXCOMPILE',
  859 		   'extensions' => ['.l++', '.ll', '.lxx', '.lpp'],
  860 		   'output_extensions' => sub { (my $ext = $_[0]) =~ tr/l/c/;
  861 						return ($ext,) },
  862 		   '_finish' => \&lang_lex_finish,
  863 		   '_target_hook' => \&lang_lex_target_hook,
  864 		   'nodist_specific' => 1);
  865 
  866 # Assembler.
  867 register_language ('name' => 'asm',
  868 		   'Name' => 'Assembler',
  869 		   'config_vars' => ['CCAS', 'CCASFLAGS'],
  870 
  871 		   'flags' => ['CCASFLAGS'],
  872 		   # Users can set AM_CCASFLAGS to include DEFS, INCLUDES,
  873 		   # or anything else required.  They can also set CCAS.
  874 		   # Or simply use Preprocessed Assembler.
  875 		   'compile' => '$(CCAS) $(AM_CCASFLAGS) $(CCASFLAGS)',
  876 		   'ccer' => 'CCAS',
  877 		   'compiler' => 'CCASCOMPILE',
  878 		   'compile_flag' => '-c',
  879 		   'output_flag' => '-o',
  880 		   'extensions' => ['.s']);
  881 
  882 # Preprocessed Assembler.
  883 register_language ('name' => 'cppasm',
  884 		   'Name' => 'Preprocessed Assembler',
  885 		   'config_vars' => ['CCAS', 'CCASFLAGS'],
  886 
  887 		   'autodep' => 'CCAS',
  888 		   'flags' => ['CCASFLAGS', 'CPPFLAGS'],
  889 		   'compile' => "\$(CCAS) @cpplike_flags \$(AM_CCASFLAGS) \$(CCASFLAGS)",
  890 		   'ccer' => 'CPPAS',
  891 		   'compiler' => 'CPPASCOMPILE',
  892                    'libtool_tag' => 'CC',
  893 		   'compile_flag' => '-c',
  894 		   'output_flag' => '-o',
  895 		   'extensions' => ['.S', '.sx']);
  896 
  897 # Fortran 77
  898 register_language ('name' => 'f77',
  899 		   'Name' => 'Fortran 77',
  900 		   'config_vars' => ['F77'],
  901 		   'linker' => 'F77LINK',
  902 		   'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
  903 		   'flags' => ['FFLAGS'],
  904 		   'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS)',
  905 		   'ccer' => 'F77',
  906 		   'compiler' => 'F77COMPILE',
  907 		   'compile_flag' => '-c',
  908 		   'output_flag' => '-o',
  909 		   'libtool_tag' => 'F77',
  910 		   'lder' => 'F77LD',
  911 		   'ld' => '$(F77)',
  912 		   'pure' => 1,
  913 		   'extensions' => ['.f', '.for']);
  914 
  915 # Fortran
  916 register_language ('name' => 'fc',
  917 		   'Name' => 'Fortran',
  918 		   'config_vars' => ['FC'],
  919 		   'linker' => 'FCLINK',
  920 		   'link' => '$(FCLD) $(AM_FCFLAGS) $(FCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
  921 		   'flags' => ['FCFLAGS'],
  922 		   'compile' => '$(FC) $(AM_FCFLAGS) $(FCFLAGS)',
  923 		   'ccer' => 'FC',
  924 		   'compiler' => 'FCCOMPILE',
  925 		   'compile_flag' => '-c',
  926 		   'output_flag' => '-o',
  927 		   'libtool_tag' => 'FC',
  928 		   'lder' => 'FCLD',
  929 		   'ld' => '$(FC)',
  930 		   'pure' => 1,
  931 		   'extensions' => ['.f90', '.f95', '.f03', '.f08']);
  932 
  933 # Preprocessed Fortran
  934 register_language ('name' => 'ppfc',
  935 		   'Name' => 'Preprocessed Fortran',
  936 		   'config_vars' => ['FC'],
  937 		   'linker' => 'FCLINK',
  938 		   'link' => '$(FCLD) $(AM_FCFLAGS) $(FCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
  939 		   'lder' => 'FCLD',
  940 		   'ld' => '$(FC)',
  941 		   'flags' => ['FCFLAGS', 'CPPFLAGS'],
  942 		   'ccer' => 'PPFC',
  943 		   'compiler' => 'PPFCCOMPILE',
  944 		   'compile' => "\$(FC) @cpplike_flags \$(AM_FCFLAGS) \$(FCFLAGS)",
  945 		   'compile_flag' => '-c',
  946 		   'output_flag' => '-o',
  947 		   'libtool_tag' => 'FC',
  948 		   'pure' => 1,
  949 		   'extensions' => ['.F90','.F95', '.F03', '.F08']);
  950 
  951 # Preprocessed Fortran 77
  952 #
  953 # The current support for preprocessing Fortran 77 just involves
  954 # passing "$(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS)
  955 # $(CPPFLAGS)" as additional flags to the Fortran 77 compiler, since
  956 # this is how GNU Make does it; see the "GNU Make Manual, Edition 0.51
  957 # for 'make' Version 3.76 Beta" (specifically, from info file
  958 # '(make)Catalogue of Rules').
  959 #
  960 # A better approach would be to write an Autoconf test
  961 # (i.e. AC_PROG_FPP) for a Fortran 77 preprocessor, because not all
  962 # Fortran 77 compilers know how to do preprocessing.  The Autoconf
  963 # macro AC_PROG_FPP should test the Fortran 77 compiler first for
  964 # preprocessing capabilities, and then fall back on cpp (if cpp were
  965 # available).
  966 register_language ('name' => 'ppf77',
  967 		   'Name' => 'Preprocessed Fortran 77',
  968 		   'config_vars' => ['F77'],
  969 		   'linker' => 'F77LINK',
  970 		   'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
  971 		   'lder' => 'F77LD',
  972 		   'ld' => '$(F77)',
  973 		   'flags' => ['FFLAGS', 'CPPFLAGS'],
  974 		   'ccer' => 'PPF77',
  975 		   'compiler' => 'PPF77COMPILE',
  976 		   'compile' => "\$(F77) @cpplike_flags \$(AM_FFLAGS) \$(FFLAGS)",
  977 		   'compile_flag' => '-c',
  978 		   'output_flag' => '-o',
  979 		   'libtool_tag' => 'F77',
  980 		   'pure' => 1,
  981 		   'extensions' => ['.F']);
  982 
  983 # Ratfor.
  984 register_language ('name' => 'ratfor',
  985 		   'Name' => 'Ratfor',
  986 		   'config_vars' => ['F77'],
  987 		   'linker' => 'F77LINK',
  988 		   'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
  989 		   'lder' => 'F77LD',
  990 		   'ld' => '$(F77)',
  991 		   'flags' => ['RFLAGS', 'FFLAGS'],
  992 		   # FIXME also FFLAGS.
  993 		   'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)',
  994 		   'ccer' => 'F77',
  995 		   'compiler' => 'RCOMPILE',
  996 		   'compile_flag' => '-c',
  997 		   'output_flag' => '-o',
  998 		   'libtool_tag' => 'F77',
  999 		   'pure' => 1,
 1000 		   'extensions' => ['.r']);
 1001 
 1002 # Java via gcj.
 1003 register_language ('name' => 'java',
 1004 		   'Name' => 'Java',
 1005 		   'config_vars' => ['GCJ'],
 1006 		   'linker' => 'GCJLINK',
 1007 		   'link' => '$(GCJLD) $(AM_GCJFLAGS) $(GCJFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
 1008 		   'autodep' => 'GCJ',
 1009 		   'flags' => ['GCJFLAGS'],
 1010 		   'compile' => '$(GCJ) $(AM_GCJFLAGS) $(GCJFLAGS)',
 1011 		   'ccer' => 'GCJ',
 1012 		   'compiler' => 'GCJCOMPILE',
 1013 		   'compile_flag' => '-c',
 1014 		   'output_flag' => '-o',
 1015 		   'libtool_tag' => 'GCJ',
 1016 		   'lder' => 'GCJLD',
 1017 		   'ld' => '$(GCJ)',
 1018 		   'pure' => 1,
 1019 		   'extensions' => ['.java', '.class', '.zip', '.jar']);
 1020 
 1021 ################################################################
 1022 
 1023 # Error reporting functions.
 1024 
 1025 # err_am ($MESSAGE, [%OPTIONS])
 1026 # -----------------------------
 1027 # Uncategorized errors about the current Makefile.am.
 1028 sub err_am
 1029 {
 1030   msg_am ('error', @_);
 1031 }
 1032 
 1033 # err_ac ($MESSAGE, [%OPTIONS])
 1034 # -----------------------------
 1035 # Uncategorized errors about configure.ac.
 1036 sub err_ac
 1037 {
 1038   msg_ac ('error', @_);
 1039 }
 1040 
 1041 # msg_am ($CHANNEL, $MESSAGE, [%OPTIONS])
 1042 # ---------------------------------------
 1043 # Messages about about the current Makefile.am.
 1044 sub msg_am
 1045 {
 1046   my ($channel, $msg, %opts) = @_;
 1047   msg $channel, "${am_file}.am", $msg, %opts;
 1048 }
 1049 
 1050 # msg_ac ($CHANNEL, $MESSAGE, [%OPTIONS])
 1051 # ---------------------------------------
 1052 # Messages about about configure.ac.
 1053 sub msg_ac
 1054 {
 1055   my ($channel, $msg, %opts) = @_;
 1056   msg $channel, $configure_ac, $msg, %opts;
 1057 }
 1058 
 1059 ################################################################
 1060 
 1061 # subst ($TEXT)
 1062 # -------------
 1063 # Return a configure-style substitution using the indicated text.
 1064 # We do this to avoid having the substitutions directly in automake.in;
 1065 # when we do that they are sometimes removed and this causes confusion
 1066 # and bugs.
 1067 sub subst
 1068 {
 1069     my ($text) = @_;
 1070     return '@' . $text . '@';
 1071 }
 1072 
 1073 ################################################################
 1074 
 1075 
 1076 # $BACKPATH
 1077 # backname ($RELDIR)
 1078 # -------------------
 1079 # If I "cd $RELDIR", then to come back, I should "cd $BACKPATH".
 1080 # For instance 'src/foo' => '../..'.
 1081 # Works with non strictly increasing paths, i.e., 'src/../lib' => '..'.
 1082 sub backname
 1083 {
 1084     my ($file) = @_;
 1085     my @res;
 1086     foreach (split (/\//, $file))
 1087     {
 1088 	next if $_ eq '.' || $_ eq '';
 1089 	if ($_ eq '..')
 1090 	{
 1091 	    pop @res
 1092 	      or prog_error ("trying to reverse path '$file' pointing outside tree");
 1093 	}
 1094 	else
 1095 	{
 1096 	    push (@res, '..');
 1097 	}
 1098     }
 1099     return join ('/', @res) || '.';
 1100 }
 1101 
 1102 ################################################################
 1103 
 1104 # Silent rules handling functions.
 1105 
 1106 # verbose_var (NAME)
 1107 # ------------------
 1108 # The public variable stem used to implement silent rules.
 1109 sub verbose_var
 1110 {
 1111     my ($name) = @_;
 1112     return 'AM_V_' . $name;
 1113 }
 1114 
 1115 # verbose_private_var (NAME)
 1116 # --------------------------
 1117 # The naming policy for the private variables for silent rules.
 1118 sub verbose_private_var
 1119 {
 1120     my ($name) = @_;
 1121     return 'am__v_' . $name;
 1122 }
 1123 
 1124 # define_verbose_var (NAME, VAL-IF-SILENT, [VAL-IF-VERBOSE])
 1125 # ----------------------------------------------------------
 1126 # For  silent rules, setup VAR and dispatcher, to expand to
 1127 # VAL-IF-SILENT if silent, to VAL-IF-VERBOSE (defaulting to
 1128 # empty) if not.
 1129 sub define_verbose_var
 1130 {
 1131     my ($name, $silent_val, $verbose_val) = @_;
 1132     $verbose_val = '' unless defined $verbose_val;
 1133     my $var = verbose_var ($name);
 1134     my $pvar = verbose_private_var ($name);
 1135     my $silent_var = $pvar . '_0';
 1136     my $verbose_var = $pvar . '_1';
 1137     # For typical 'make's, 'configure' replaces AM_V (inside @@) with $(V)
 1138     # and AM_DEFAULT_V (inside @@) with $(AM_DEFAULT_VERBOSITY).
 1139     # For strict POSIX 2008 'make's, it replaces them with 0 or 1 instead.
 1140     # See AM_SILENT_RULES in m4/silent.m4.
 1141     define_variable ($var, '$(' . $pvar . '_@'.'AM_V'.'@)', INTERNAL);
 1142     define_variable ($pvar . '_', '$(' . $pvar . '_@'.'AM_DEFAULT_V'.'@)',
 1143                      INTERNAL);
 1144     Automake::Variable::define ($silent_var, VAR_AUTOMAKE, '', TRUE,
 1145                                 $silent_val, '', INTERNAL, VAR_ASIS)
 1146       if (! vardef ($silent_var, TRUE));
 1147     Automake::Variable::define ($verbose_var, VAR_AUTOMAKE, '', TRUE,
 1148                                 $verbose_val, '', INTERNAL, VAR_ASIS)
 1149       if (! vardef ($verbose_var, TRUE));
 1150 }
 1151 
 1152 # verbose_flag (NAME)
 1153 # -------------------
 1154 # Contents of '%VERBOSE%' variable to expand before rule command.
 1155 sub verbose_flag
 1156 {
 1157     my ($name) = @_;
 1158     return '$(' . verbose_var ($name) . ')';
 1159 }
 1160 
 1161 sub verbose_nodep_flag
 1162 {
 1163     my ($name) = @_;
 1164     return '$(' . verbose_var ($name) . subst ('am__nodep') . ')';
 1165 }
 1166 
 1167 # silent_flag
 1168 # -----------
 1169 # Contents of %SILENT%: variable to expand to '@' when silent.
 1170 sub silent_flag ()
 1171 {
 1172     return verbose_flag ('at');
 1173 }
 1174 
 1175 # define_verbose_tagvar (NAME)
 1176 # ----------------------------
 1177 # Engage the needed silent rules machinery for tag NAME.
 1178 sub define_verbose_tagvar
 1179 {
 1180     my ($name) = @_;
 1181     define_verbose_var ($name, '@echo "  '. $name . ' ' x (8 - length ($name)) . '" $@;');
 1182 }
 1183 
 1184 # Engage the needed silent rules machinery for assorted texinfo commands.
 1185 sub define_verbose_texinfo ()
 1186 {
 1187   my @tagvars = ('DVIPS', 'MAKEINFO', 'INFOHTML', 'TEXI2DVI', 'TEXI2PDF');
 1188   foreach my $tag (@tagvars)
 1189     {
 1190       define_verbose_tagvar($tag);
 1191     }
 1192   define_verbose_var('texinfo', '-q');
 1193   define_verbose_var('texidevnull', '> /dev/null');
 1194 }
 1195 
 1196 # Engage the needed silent rules machinery for 'libtool --silent'.
 1197 sub define_verbose_libtool ()
 1198 {
 1199     define_verbose_var ('lt', '--silent');
 1200     return verbose_flag ('lt');
 1201 }
 1202 
 1203 sub handle_silent ()
 1204 {
 1205     # Define "$(AM_V_P)", expanding to a shell conditional that can be
 1206     # used in make recipes to determine whether we are being run in
 1207     # silent mode or not.  The choice of the name derives from the LISP
 1208     # convention of appending the letter 'P' to denote a predicate (see
 1209     # also "the '-P' convention" in the Jargon File); we do so for lack
 1210     # of a better convention.
 1211     define_verbose_var ('P', 'false', ':');
 1212     # *Always* provide the user with '$(AM_V_GEN)', unconditionally.
 1213     define_verbose_tagvar ('GEN');
 1214     define_verbose_var ('at', '@');
 1215 }
 1216 
 1217 
 1218 ################################################################
 1219 
 1220 
 1221 # Handle AUTOMAKE_OPTIONS variable.  Return 0 on error, 1 otherwise.
 1222 sub handle_options ()
 1223 {
 1224   my $var = var ('AUTOMAKE_OPTIONS');
 1225   if ($var)
 1226     {
 1227       if ($var->has_conditional_contents)
 1228 	{
 1229 	  msg_var ('unsupported', $var,
 1230 		   "'AUTOMAKE_OPTIONS' cannot have conditional contents");
 1231 	}
 1232       my @options = map { { option => $_->[1], where => $_->[0] } }
 1233 			$var->value_as_list_recursive (cond_filter => TRUE,
 1234 						       location => 1);
 1235       return 0 unless process_option_list (@options);
 1236     }
 1237 
 1238   if ($strictness == GNITS)
 1239     {
 1240       set_option ('readme-alpha', INTERNAL);
 1241       set_option ('std-options', INTERNAL);
 1242       set_option ('check-news', INTERNAL);
 1243     }
 1244 
 1245   return 1;
 1246 }
 1247 
 1248 # shadow_unconditionally ($varname, $where)
 1249 # -----------------------------------------
 1250 # Return a $(variable) that contains all possible values
 1251 # $varname can take.
 1252 # If the VAR wasn't defined conditionally, return $(VAR).
 1253 # Otherwise we create an am__VAR_DIST variable which contains
 1254 # all possible values, and return $(am__VAR_DIST).
 1255 sub shadow_unconditionally
 1256 {
 1257   my ($varname, $where) = @_;
 1258   my $var = var $varname;
 1259   if ($var->has_conditional_contents)
 1260     {
 1261       $varname = "am__${varname}_DIST";
 1262       my @files = uniq ($var->value_as_list_recursive);
 1263       define_pretty_variable ($varname, TRUE, $where, @files);
 1264     }
 1265   return "\$($varname)"
 1266 }
 1267 
 1268 # check_user_variables (@LIST)
 1269 # ----------------------------
 1270 # Make sure each variable VAR in @LIST does not exist, suggest using AM_VAR
 1271 # otherwise.
 1272 sub check_user_variables
 1273 {
 1274   my @dont_override = @_;
 1275   foreach my $flag (@dont_override)
 1276     {
 1277       my $var = var $flag;
 1278       if ($var)
 1279 	{
 1280 	  for my $cond ($var->conditions->conds)
 1281 	    {
 1282 	      if ($var->rdef ($cond)->owner == VAR_MAKEFILE)
 1283 		{
 1284 		  msg_cond_var ('gnu', $cond, $flag,
 1285 				"'$flag' is a user variable, "
 1286 				. "you should not override it;\n"
 1287 				. "use 'AM_$flag' instead");
 1288 		}
 1289 	    }
 1290 	}
 1291     }
 1292 }
 1293 
 1294 # Call finish function for each language that was used.
 1295 sub handle_languages ()
 1296 {
 1297     if (! option 'no-dependencies')
 1298       {
 1299         # Include auto-dep code.  Don't include it if DEP_FILES would
 1300         # be empty.
 1301         if (keys %extension_seen && keys %dep_files)
 1302           {
 1303             my @dep_files = sort keys %dep_files;
 1304             # Set location of depcomp.
 1305             define_variable ('depcomp',
 1306                              "\$(SHELL) $am_config_aux_dir/depcomp",
 1307                              INTERNAL);
 1308             define_variable ('am__maybe_remake_depfiles', 'depfiles', INTERNAL);
 1309             define_variable ('am__depfiles_remade', "@dep_files", INTERNAL);
 1310             $output_rules .= "\n";
 1311             my @dist_rms;
 1312             foreach my $depfile (@dep_files)
 1313               {
 1314                 push @dist_rms, "\t-rm -f $depfile";
 1315                 # Generate each 'include' directive individually.  Several
 1316                 # make implementations (IRIX 6, Solaris 10, FreeBSD 8) will
 1317                 # fail to properly include several files resulting from a
 1318                 # variable expansion. Just Generating many separate includes
 1319                 # seems thus safest.
 1320                 $output_rules .= subst ('AMDEP_TRUE') .
 1321                                  subst ('am__include') .
 1322                                  " " .
 1323                                  subst('am__quote') .
 1324                                  $depfile .
 1325                                  subst('am__quote') .
 1326                                  " " .
 1327                                  "# am--include-marker\n";
 1328               }
 1329 
 1330             require_conf_file ("$am_file.am", FOREIGN, 'depcomp');
 1331 
 1332             $output_rules .= file_contents (
 1333                 'depend', new Automake::Location,
 1334                 'DISTRMS' => join ("\n", @dist_rms));
 1335           }
 1336       }
 1337     else
 1338       {
 1339         define_variable ('depcomp', '', INTERNAL);
 1340         define_variable ('am__maybe_remake_depfiles', '', INTERNAL);
 1341       }
 1342 
 1343     my %done;
 1344 
 1345     # Is the C linker needed?
 1346     my $needs_c = 0;
 1347     foreach my $ext (sort keys %extension_seen)
 1348     {
 1349 	next unless $extension_map{$ext};
 1350 
 1351 	my $lang = $languages{$extension_map{$ext}};
 1352 
 1353 	my $rule_file = $lang->rule_file || 'depend2';
 1354 
 1355 	# Get information on $LANG.
 1356 	my $pfx = $lang->autodep;
 1357 	my $fpfx = ($pfx eq '') ? 'CC' : $pfx;
 1358 
 1359 	my ($AMDEP, $FASTDEP) =
 1360 	  (option 'no-dependencies' || $lang->autodep eq 'no')
 1361 	  ? ('FALSE', 'FALSE') : ('AMDEP', "am__fastdep$fpfx");
 1362 
 1363 	my $verbose = verbose_flag ($lang->ccer || 'GEN');
 1364 	my $verbose_nodep = ($AMDEP eq 'FALSE')
 1365 	  ? $verbose : verbose_nodep_flag ($lang->ccer || 'GEN');
 1366 	my $silent = silent_flag ();
 1367 
 1368 	my %transform = ('EXT'     => $ext,
 1369 			 'PFX'     => $pfx,
 1370 			 'FPFX'    => $fpfx,
 1371 			 'AMDEP'   => $AMDEP,
 1372 			 'FASTDEP' => $FASTDEP,
 1373 			 '-c'      => $lang->compile_flag || '',
 1374 			 # These are not used, but they need to be defined
 1375 			 # so transform() do not complain.
 1376 			 SUBDIROBJ     => 0,
 1377 			 'DERIVED-EXT' => 'BUG',
 1378 			 DIST_SOURCE   => 1,
 1379 			 VERBOSE   => $verbose,
 1380 			 'VERBOSE-NODEP' => $verbose_nodep,
 1381 			 SILENT    => $silent,
 1382 			);
 1383 
 1384 	# Generate the appropriate rules for this extension.
 1385 	if (((! option 'no-dependencies') && $lang->autodep ne 'no')
 1386 	    || defined $lang->compile)
 1387 	{
 1388 	    # Compute a possible derived extension.
 1389 	    # This is not used by depend2.am.
 1390 	    my $der_ext = ($lang->output_extensions->($ext))[0];
 1391 
 1392 	    # When we output an inference rule like '.c.o:' we
 1393 	    # have two cases to consider: either subdir-objects
 1394 	    # is used, or it is not.
 1395 	    #
 1396 	    # In the latter case the rule is used to build objects
 1397 	    # in the current directory, and dependencies always
 1398 	    # go into './$(DEPDIR)/'.  We can hard-code this value.
 1399 	    #
 1400 	    # In the former case the rule can be used to build
 1401 	    # objects in sub-directories too.  Dependencies should
 1402 	    # go into the appropriate sub-directories, e.g.,
 1403 	    # 'sub/$(DEPDIR)/'.  The value of this directory
 1404 	    # needs to be computed on-the-fly.
 1405 	    #
 1406 	    # DEPBASE holds the name of this directory, plus the
 1407 	    # basename part of the object file (extensions Po, TPo,
 1408 	    # Plo, TPlo will be added later as appropriate).  It is
 1409 	    # either hardcoded, or a shell variable ('$depbase') that
 1410 	    # will be computed by the rule.
 1411 	    my $depbase =
 1412 	      option ('subdir-objects') ? '$$depbase' : '$(DEPDIR)/$*';
 1413 	    $output_rules .=
 1414 	      file_contents ($rule_file,
 1415 			     new Automake::Location,
 1416 			     %transform,
 1417 			     GENERIC   => 1,
 1418 
 1419 			     'DERIVED-EXT' => $der_ext,
 1420 
 1421 			     DEPBASE   => $depbase,
 1422 			     BASE      => '$*',
 1423 			     SOURCE    => '$<',
 1424 			     SOURCEFLAG => $sourceflags{$ext} || '',
 1425 			     OBJ       => '$@',
 1426 			     OBJOBJ    => '$@',
 1427 			     LTOBJ     => '$@',
 1428 
 1429 			     COMPILE   => '$(' . $lang->compiler . ')',
 1430 			     LTCOMPILE => '$(LT' . $lang->compiler . ')',
 1431 			     -o        => $lang->output_flag,
 1432 			     SUBDIROBJ => !! option 'subdir-objects');
 1433 	}
 1434 
 1435 	# Now include code for each specially handled object with this
 1436 	# language.
 1437 	my %seen_files = ();
 1438 	foreach my $file (@{$lang_specific_files{$lang->name}})
 1439 	{
 1440 	    my ($derived, $source, $obj, $myext, $srcext, %file_transform) = @$file;
 1441 
 1442 	    # We might see a given object twice, for instance if it is
 1443 	    # used under different conditions.
 1444 	    next if defined $seen_files{$obj};
 1445 	    $seen_files{$obj} = 1;
 1446 
 1447 	    prog_error ("found " . $lang->name .
 1448 			" in handle_languages, but compiler not defined")
 1449 	      unless defined $lang->compile;
 1450 
 1451 	    my $obj_compile = $lang->compile;
 1452 
 1453 	    # Rewrite each occurrence of 'AM_$flag' in the compile
 1454 	    # rule into '${derived}_$flag' if it exists.
 1455 	    for my $flag (@{$lang->flags})
 1456 	      {
 1457 		my $val = "${derived}_$flag";
 1458 		$obj_compile =~ s/\(AM_$flag\)/\($val\)/
 1459 		  if set_seen ($val);
 1460 	      }
 1461 
 1462 	    my $libtool_tag = '';
 1463 	    if ($lang->libtool_tag && exists $libtool_tags{$lang->libtool_tag})
 1464 	      {
 1465 		$libtool_tag = '--tag=' . $lang->libtool_tag . ' '
 1466 	      }
 1467 
 1468 	    my $ptltflags = "${derived}_LIBTOOLFLAGS";
 1469 	    $ptltflags = 'AM_LIBTOOLFLAGS' unless set_seen $ptltflags;
 1470 
 1471 	    my $ltverbose = define_verbose_libtool ();
 1472 	    my $obj_ltcompile =
 1473 	      "\$(LIBTOOL) $ltverbose $libtool_tag\$($ptltflags) \$(LIBTOOLFLAGS) "
 1474 	      . "--mode=compile $obj_compile";
 1475 
 1476 	    # We _need_ '-o' for per object rules.
 1477 	    my $output_flag = $lang->output_flag || '-o';
 1478 
 1479 	    my $depbase = dirname ($obj);
 1480 	    $depbase = ''
 1481 		if $depbase eq '.';
 1482 	    $depbase .= '/'
 1483 		unless $depbase eq '';
 1484 	    $depbase .= '$(DEPDIR)/' . basename ($obj);
 1485 
 1486 	    $output_rules .=
 1487 	      file_contents ($rule_file,
 1488 			     new Automake::Location,
 1489 			     %transform,
 1490 			     GENERIC   => 0,
 1491 
 1492 			     DEPBASE   => $depbase,
 1493 			     BASE      => $obj,
 1494 			     SOURCE    => $source,
 1495 			     SOURCEFLAG => $sourceflags{$srcext} || '',
 1496 			     # Use $myext and not '.o' here, in case
 1497 			     # we are actually building a new source
 1498 			     # file -- e.g. via yacc.
 1499 			     OBJ       => "$obj$myext",
 1500 			     OBJOBJ    => "$obj.obj",
 1501 			     LTOBJ     => "$obj.lo",
 1502 
 1503 			     VERBOSE   => $verbose,
 1504 			     'VERBOSE-NODEP'  => $verbose_nodep,
 1505 			     SILENT    => $silent,
 1506 			     COMPILE   => $obj_compile,
 1507 			     LTCOMPILE => $obj_ltcompile,
 1508 			     -o        => $output_flag,
 1509 			     %file_transform);
 1510 	}
 1511 
 1512 	# The rest of the loop is done once per language.
 1513 	next if defined $done{$lang};
 1514 	$done{$lang} = 1;
 1515 
 1516 	# Load the language dependent Makefile chunks.
 1517 	my %lang = map { uc ($_) => 0 } keys %languages;
 1518 	$lang{uc ($lang->name)} = 1;
 1519 	$output_rules .= file_contents ('lang-compile',
 1520 					new Automake::Location,
 1521 					%transform, %lang);
 1522 
 1523 	# If the source to a program consists entirely of code from a
 1524 	# 'pure' language, for instance C++ or Fortran 77, then we
 1525 	# don't need the C compiler code.  However if we run into
 1526 	# something unusual then we do generate the C code.  There are
 1527 	# probably corner cases here that do not work properly.
 1528 	# People linking Java code to Fortran code deserve pain.
 1529 	$needs_c ||= ! $lang->pure;
 1530 
 1531 	define_compiler_variable ($lang)
 1532 	  if ($lang->compile);
 1533 
 1534 	define_linker_variable ($lang)
 1535 	  if ($lang->link);
 1536 
 1537 	require_variables ("$am_file.am", $lang->Name . " source seen",
 1538 			   TRUE, @{$lang->config_vars});
 1539 
 1540 	# Call the finisher.
 1541 	$lang->finish;
 1542 
 1543 	# Flags listed in '->flags' are user variables (per GNU Standards),
 1544 	# they should not be overridden in the Makefile...
 1545 	my @dont_override = @{$lang->flags};
 1546 	# ... and so is LDFLAGS.
 1547 	push @dont_override, 'LDFLAGS' if $lang->link;
 1548 
 1549 	check_user_variables @dont_override;
 1550     }
 1551 
 1552     # If the project is entirely C++ or entirely Fortran 77 (i.e., 1
 1553     # suffix rule was learned), don't bother with the C stuff.  But if
 1554     # anything else creeps in, then use it.
 1555     my @languages_seen = map { $languages{$extension_map{$_}}->name }
 1556                              (keys %extension_seen);
 1557     @languages_seen = uniq (@languages_seen);
 1558     $needs_c = 1 if @languages_seen > 1;
 1559     if ($need_link || $needs_c)
 1560       {
 1561 	define_compiler_variable ($languages{'c'})
 1562 	  unless defined $done{$languages{'c'}};
 1563 	define_linker_variable ($languages{'c'});
 1564       }
 1565 }
 1566 
 1567 
 1568 # append_exeext { PREDICATE } $MACRO
 1569 # ----------------------------------
 1570 # Append $(EXEEXT) to each filename in $F appearing in the Makefile
 1571 # variable $MACRO if &PREDICATE($F) is true.  @substitutions@ are
 1572 # ignored.
 1573 #
 1574 # This is typically used on all filenames of *_PROGRAMS, and filenames
 1575 # of TESTS that are programs.
 1576 sub append_exeext (&$)
 1577 {
 1578   my ($pred, $macro) = @_;
 1579 
 1580   transform_variable_recursively
 1581     ($macro, $macro, 'am__EXEEXT', 0, INTERNAL,
 1582      sub {
 1583        my ($subvar, $val, $cond, $full_cond) = @_;
 1584        # Append $(EXEEXT) unless the user did it already, or it's a
 1585        # @substitution@.
 1586        $val .= '$(EXEEXT)'
 1587 	 if $val !~ /(?:\$\(EXEEXT\)$|^[@]\w+[@]$)/ && &$pred ($val);
 1588        return $val;
 1589      });
 1590 }
 1591 
 1592 
 1593 # Check to make sure a source defined in LIBOBJS is not explicitly
 1594 # mentioned.  This is a separate function (as opposed to being inlined
 1595 # in handle_source_transform) because it isn't always appropriate to
 1596 # do this check.
 1597 sub check_libobjs_sources
 1598 {
 1599   my ($one_file, $unxformed) = @_;
 1600 
 1601   foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
 1602 		      'dist_EXTRA_', 'nodist_EXTRA_')
 1603     {
 1604       my @files;
 1605       my $varname = $prefix . $one_file . '_SOURCES';
 1606       my $var = var ($varname);
 1607       if ($var)
 1608 	{
 1609 	  @files = $var->value_as_list_recursive;
 1610 	}
 1611       elsif ($prefix eq '')
 1612 	{
 1613 	  @files = ($unxformed . '.c');
 1614 	}
 1615       else
 1616 	{
 1617 	  next;
 1618 	}
 1619 
 1620       foreach my $file (@files)
 1621 	{
 1622 	  err_var ($prefix . $one_file . '_SOURCES',
 1623 		   "automatically discovered file '$file' should not" .
 1624 		   " be explicitly mentioned")
 1625 	    if defined $libsources{$file};
 1626 	}
 1627     }
 1628 }
 1629 
 1630 
 1631 # @OBJECTS
 1632 # handle_single_transform ($VAR, $TOPPARENT, $DERIVED, $OBJ, $FILE, %TRANSFORM)
 1633 # -----------------------------------------------------------------------------
 1634 # Does much of the actual work for handle_source_transform.
 1635 # Arguments are:
 1636 #   $VAR is the name of the variable that the source filenames come from
 1637 #   $TOPPARENT is the name of the _SOURCES variable which is being processed
 1638 #   $DERIVED is the name of resulting executable or library
 1639 #   $OBJ is the object extension (e.g., '.lo')
 1640 #   $FILE the source file to transform
 1641 #   %TRANSFORM contains extras arguments to pass to file_contents
 1642 #     when producing explicit rules
 1643 # Result is a list of the names of objects
 1644 # %linkers_used will be updated with any linkers needed
 1645 sub handle_single_transform
 1646 {
 1647     my ($var, $topparent, $derived, $obj, $_file, %transform) = @_;
 1648     my @files = ($_file);
 1649     my @result = ();
 1650 
 1651     # Turn sources into objects.  We use a while loop like this
 1652     # because we might add to @files in the loop.
 1653     while (scalar @files > 0)
 1654     {
 1655 	$_ = shift @files;
 1656 
 1657 	# Configure substitutions in _SOURCES variables are errors.
 1658 	if (/^\@.*\@$/)
 1659 	{
 1660 	  my $parent_msg = '';
 1661 	  $parent_msg = "\nand is referred to from '$topparent'"
 1662 	    if $topparent ne $var->name;
 1663 	  err_var ($var,
 1664 		   "'" . $var->name . "' includes configure substitution '$_'"
 1665 		   . $parent_msg . ";\nconfigure " .
 1666 		   "substitutions are not allowed in _SOURCES variables");
 1667 	  next;
 1668 	}
 1669 
 1670 	# If the source file is in a subdirectory then the '.o' is put
 1671 	# into the current directory, unless the subdir-objects option
 1672 	# is in effect.
 1673 
 1674 	# Split file name into base and extension.
 1675 	next if ! /^(?:(.*)\/)?([^\/]*)($KNOWN_EXTENSIONS_PATTERN)$/;
 1676 	my $full = $_;
 1677 	my $directory = $1 || '';
 1678 	my $base = $2;
 1679 	my $extension = $3;
 1680 
 1681 	# We must generate a rule for the object if it requires its own flags.
 1682 	my $renamed = 0;
 1683 	my ($linker, $object);
 1684 
 1685         # This records whether we've seen a derived source file (e.g., yacc
 1686         # or lex output).
 1687         my $derived_source;
 1688 
 1689 	# This holds the 'aggregate context' of the file we are
 1690 	# currently examining.  If the file is compiled with
 1691 	# per-object flags, then it will be the name of the object.
 1692 	# Otherwise it will be 'AM'.  This is used by the target hook
 1693 	# language function.
 1694 	my $aggregate = 'AM';
 1695 
 1696 	$extension = derive_suffix ($extension, $obj);
 1697 	my $lang;
 1698 	if ($extension_map{$extension} &&
 1699 	    ($lang = $languages{$extension_map{$extension}}))
 1700 	{
 1701 	    # Found the language, so see what it says.
 1702 	    saw_extension ($extension);
 1703 
 1704 	    # Do we have per-executable flags for this executable?
 1705 	    my $have_per_exec_flags = 0;
 1706 	    my @peflags = @{$lang->flags};
 1707 	    push @peflags, 'LIBTOOLFLAGS' if $obj eq '.lo';
 1708 	    foreach my $flag (@peflags)
 1709 	      {
 1710 		if (set_seen ("${derived}_$flag"))
 1711 		  {
 1712 		    $have_per_exec_flags = 1;
 1713 		    last;
 1714 		  }
 1715 	      }
 1716 
 1717 	    # Note: computed subr call.  The language rewrite function
 1718 	    # should return one of the LANG_* constants.  It could
 1719 	    # also return a list whose first value is such a constant
 1720 	    # and whose second value is a new source extension which
 1721 	    # should be applied.  This means this particular language
 1722 	    # generates another source file which we must then process
 1723 	    # further.
 1724 	    my $subr = \&{'lang_' . $lang->name . '_rewrite'};
 1725 	    defined &$subr or $subr = \&lang_sub_obj;
 1726 	    my ($r, $source_extension)
 1727 		= &$subr ($directory, $base, $extension,
 1728 			  $obj, $have_per_exec_flags, $var);
 1729 	    # Skip this entry if we were asked not to process it.
 1730 	    next if $r == LANG_IGNORE;
 1731 
 1732 	    # Now extract linker and other info.
 1733 	    $linker = $lang->linker;
 1734 
 1735             my $this_obj_ext;
 1736             if (defined $source_extension)
 1737               {
 1738                 $this_obj_ext = $source_extension;
 1739                 $derived_source = 1;
 1740               }
 1741             else
 1742               {
 1743                 $this_obj_ext = $obj;
 1744                 $derived_source = 0;
 1745                 # Don't ever place built object files in $(srcdir),
 1746                 # even when sources are specified explicitly as (say)
 1747                 # '$(srcdir)/foo.c' or '$(top_srcdir)/foo.c'.
 1748                 # See automake bug#13928.
 1749                 my @d = split '/', $directory;
 1750                 if (@d > 0 && option 'subdir-objects')
 1751                   {
 1752                     my $d = $d[0];
 1753                     if ($d eq '$(srcdir)' or $d eq '${srcdir}')
 1754                       {
 1755                         shift @d;
 1756                       }
 1757                     elsif ($d eq '$(top_srcdir)' or $d eq '${top_srcdir}')
 1758                       {
 1759                         $d[0] = '$(top_builddir)';
 1760                       }
 1761                     $directory = join '/', @d;
 1762                   }
 1763               }
 1764             $object = $base . $this_obj_ext;
 1765 
 1766 	    if ($have_per_exec_flags)
 1767 	    {
 1768 		# We have a per-executable flag in effect for this
 1769 		# object.  In this case we rewrite the object's
 1770 		# name to ensure it is unique.
 1771 
 1772                 # We choose the name 'DERIVED_OBJECT' to ensure (1) uniqueness,
 1773                 # and (2) continuity between invocations.  However, this will
 1774                 # result in a name that is too long for losing systems, in some
 1775                 # situations.  So we attempt to shorten automatically under
 1776                 # subdir-objects, and provide _SHORTNAME to override as a last
 1777                 # resort.  If subdir-object is in effect, it's usually
 1778                 # unnecessary to use the complete 'DERIVED_OBJECT' (that is
 1779                 # often the result from %canon_reldir%/%C% usage) since objects
 1780                 # are placed next to their source file.  Generally, this means
 1781                 # it is already unique within that directory (see below for an
 1782                 # exception).  Thus, we try to avoid unnecessarily long file
 1783                 # names by stripping the directory components of
 1784                 # 'DERIVED_OBJECT'.  This allows avoiding explicit _SHORTNAME
 1785                 # usage in many cases.  EXCEPTION: If two (or more) targets in
 1786                 # different directories but with the same base name (after
 1787                 # canonicalization), using target-specific FLAGS, link the same
 1788                 # object, then this logic clashes.  Thus, we don't strip if
 1789                 # this is detected.
 1790                 my $dname = $derived;
 1791                 if ($directory ne ''
 1792                     && option 'subdir-objects'
 1793                     && none { $dname =~ /$_[0]$/ } @dup_shortnames)
 1794                   {
 1795                     # At this point, we don't clear information about what
 1796                     # parts of $derived are truly file name components.  We can
 1797                     # determine that by comparing against the canonicalization
 1798                     # of $directory.
 1799                     my $dir = $directory . "/";
 1800                     my $cdir = canonicalize ($dir);
 1801                     my $dir_len = length ($dir);
 1802                     # Make sure we only strip full file name components.  This
 1803                     # is done by repeatedly trying to find cdir at the
 1804                     # beginning.  Each iteration removes one file name
 1805                     # component from the end of cdir.
 1806                     while ($dir_len > 0 && index ($derived, $cdir) != 0)
 1807                       {
 1808                         # Eventually $dir_len becomes 0.
 1809                         $dir_len = rindex ($dir, "/", $dir_len - 2) + 1;
 1810                         $cdir = substr ($cdir, 0, $dir_len);
 1811                       }
 1812                     $dname = substr ($derived, $dir_len);
 1813                   }
 1814 		my $var = var ($derived . '_SHORTNAME');
 1815 		if ($var)
 1816 		{
 1817 		    # FIXME: should use the same Condition as
 1818 		    # the _SOURCES variable.  But this is really
 1819 		    # silly overkill -- nobody should have
 1820 		    # conditional shortnames.
 1821 		    $dname = $var->variable_value;
 1822 		}
 1823 		$object = $dname . '-' . $object;
 1824 
 1825 		prog_error ($lang->name . " flags defined without compiler")
 1826 		  if ! defined $lang->compile;
 1827 
 1828 		$renamed = 1;
 1829 	    }
 1830 
 1831 	    # If rewrite said it was ok, put the object into a subdir.
 1832 	    if ($directory ne '')
 1833 	    {
 1834               if ($r == LANG_SUBDIR)
 1835                 {
 1836                   $object = $directory . '/' . $object;
 1837                 }
 1838               else
 1839                 {
 1840                   # Since the next major version of automake (2.0) will
 1841                   # make the behaviour so far only activated with the
 1842                   # 'subdir-object' option mandatory, it's better if we
 1843                   # start warning users not using that option.
 1844                   # As suggested by Peter Johansson, we strive to avoid
 1845                   # the warning when it would be irrelevant, i.e., if
 1846                   # all source files sit in "current" directory.
 1847                   msg_var 'unsupported', $var,
 1848                           "source file '$full' is in a subdirectory,"
 1849                           . "\nbut option 'subdir-objects' is disabled";
 1850                   msg 'unsupported', INTERNAL, <<'EOF', uniq_scope => US_GLOBAL;
 1851 possible forward-incompatibility.
 1852 At least a source file is in a subdirectory, but the 'subdir-objects'
 1853 automake option hasn't been enabled.  For now, the corresponding output
 1854 object file(s) will be placed in the top-level directory.  However,
 1855 this behaviour will change in future Automake versions: they will
 1856 unconditionally cause object files to be placed in the same subdirectory
 1857 of the corresponding sources.
 1858 You are advised to start using 'subdir-objects' option throughout your
 1859 project, to avoid future incompatibilities.
 1860 EOF
 1861                 }
 1862 	    }
 1863 
 1864 	    # If the object file has been renamed (because per-target
 1865 	    # flags are used) we cannot compile the file with an
 1866 	    # inference rule: we need an explicit rule.
 1867 	    #
 1868 	    # If the source is in a subdirectory and the object is in
 1869 	    # the current directory, we also need an explicit rule.
 1870 	    #
 1871 	    # If both source and object files are in a subdirectory
 1872 	    # (this happens when the subdir-objects option is used),
 1873 	    # then the inference will work.
 1874 	    #
 1875 	    # The latter case deserves a historical note.  When the
 1876 	    # subdir-objects option was added on 1999-04-11 it was
 1877 	    # thought that inferences rules would work for
 1878 	    # subdirectory objects too.  Later, on 1999-11-22,
 1879 	    # automake was changed to output explicit rules even for
 1880 	    # subdir-objects.  Nobody remembers why, but this occurred
 1881 	    # soon after the merge of the user-dep-gen-branch so it
 1882 	    # might be related.  In late 2003 people complained about
 1883 	    # the size of the generated Makefile.ins (libgcj, with
 1884 	    # 2200+ subdir objects was reported to have a 9MB
 1885 	    # Makefile), so we now rely on inference rules again.
 1886 	    # Maybe we'll run across the same issue as in the past,
 1887 	    # but at least this time we can document it.  However since
 1888 	    # dependency tracking has evolved it is possible that
 1889 	    # our old problem no longer exists.
 1890 	    # Using inference rules for subdir-objects has been tested
 1891 	    # with GNU make, Solaris make, Ultrix make, BSD make,
 1892 	    # HP-UX make, and OSF1 make successfully.
 1893 	    if ($renamed
 1894 		|| ($directory ne '' && ! option 'subdir-objects')
 1895 		# We must also use specific rules for a nodist_ source
 1896 		# if its language requests it.
 1897 		|| ($lang->nodist_specific && ! $transform{'DIST_SOURCE'}))
 1898 	    {
 1899 		my $obj_sans_ext = substr ($object, 0,
 1900 					   - length ($this_obj_ext));
 1901 		my $full_ansi;
 1902 		if ($directory ne '')
 1903 	          {
 1904 			$full_ansi = $directory . '/' . $base . $extension;
 1905 	          }
 1906 		else
 1907 	          {
 1908 			$full_ansi = $base . $extension;
 1909 	          }
 1910 
 1911 		my @specifics = ($full_ansi, $obj_sans_ext,
 1912 				 # Only use $this_obj_ext in the derived
 1913 				 # source case because in the other case we
 1914 				 # *don't* want $(OBJEXT) to appear here.
 1915 				 ($derived_source ? $this_obj_ext : '.o'),
 1916 				 $extension);
 1917 
 1918 		# If we renamed the object then we want to use the
 1919 		# per-executable flag name.  But if this is simply a
 1920 		# subdir build then we still want to use the AM_ flag
 1921 		# name.
 1922 		if ($renamed)
 1923 		  {
 1924 		    unshift @specifics, $derived;
 1925 		    $aggregate = $derived;
 1926 		  }
 1927 		else
 1928 		  {
 1929 		    unshift @specifics, 'AM';
 1930 		  }
 1931 
 1932 		# Each item on this list is a reference to a list consisting
 1933 		# of four values followed by additional transform flags for
 1934 		# file_contents.  The four values are the derived flag prefix
 1935 		# (e.g. for 'foo_CFLAGS', it is 'foo'), the name of the
 1936 		# source file, the base name of the output file, and
 1937 		# the extension for the object file.
 1938 		push (@{$lang_specific_files{$lang->name}},
 1939 		      [@specifics, %transform]);
 1940 	    }
 1941 	}
 1942 	elsif ($extension eq $obj)
 1943 	{
 1944 	    # This is probably the result of a direct suffix rule.
 1945 	    # In this case we just accept the rewrite.
 1946 	    $object = "$base$extension";
 1947 	    $object = "$directory/$object" if $directory ne '';
 1948 	    $linker = '';
 1949 	}
 1950 	else
 1951 	{
 1952 	    # No error message here.  Used to have one, but it was
 1953 	    # very unpopular.
 1954 	    # FIXME: we could potentially do more processing here,
 1955 	    # perhaps treating the new extension as though it were a
 1956 	    # new source extension (as above).  This would require
 1957 	    # more restructuring than is appropriate right now.
 1958 	    next;
 1959 	}
 1960 
 1961 	err_am "object '$object' created by '$full' and '$object_map{$object}'"
 1962 	  if (defined $object_map{$object}
 1963 	      && $object_map{$object} ne $full);
 1964 
 1965 	my $comp_val = (($object =~ /\.lo$/)
 1966 			? COMPILE_LIBTOOL : COMPILE_ORDINARY);
 1967 	(my $comp_obj = $object) =~ s/\.lo$/.\$(OBJEXT)/;
 1968 	if (defined $object_compilation_map{$comp_obj}
 1969 	    && $object_compilation_map{$comp_obj} != 0
 1970 	    # Only see the error once.
 1971 	    && ($object_compilation_map{$comp_obj}
 1972 		!= (COMPILE_LIBTOOL | COMPILE_ORDINARY))
 1973 	    && $object_compilation_map{$comp_obj} != $comp_val)
 1974 	  {
 1975 	    err_am "object '$comp_obj' created both with libtool and without";
 1976 	  }
 1977 	$object_compilation_map{$comp_obj} |= $comp_val;
 1978 
 1979 	if (defined $lang)
 1980 	{
 1981 	    # Let the language do some special magic if required.
 1982 	    $lang->target_hook ($aggregate, $object, $full, %transform);
 1983 	}
 1984 
 1985 	if ($derived_source)
 1986 	  {
 1987 	    prog_error ($lang->name . " has automatic dependency tracking")
 1988 	      if $lang->autodep ne 'no';
 1989 	    # Make sure this new source file is handled next.  That will
 1990 	    # make it appear to be at the right place in the list.
 1991 	    unshift (@files, $object);
 1992 	    # Distribute derived sources unless the source they are
 1993 	    # derived from is not.
 1994 	    push_dist_common ($object)
 1995 	      unless ($topparent =~ /^(?:nobase_)?nodist_/);
 1996 	    next;
 1997 	  }
 1998 
 1999 	$linkers_used{$linker} = 1;
 2000 
 2001 	push (@result, $object);
 2002 
 2003 	if (! defined $object_map{$object})
 2004 	{
 2005 	    my @dep_list = ();
 2006 	    $object_map{$object} = $full;
 2007 
 2008 	    # If resulting object is in subdir, we need to make
 2009 	    # sure the subdir exists at build time.
 2010 	    if ($object =~ /\//)
 2011 	    {
 2012 		# FIXME: check that $DIRECTORY is somewhere in the
 2013 		# project
 2014 
 2015 		# For Java, the way we're handling it right now, a
 2016 		# '..' component doesn't make sense.
 2017 		if ($lang && $lang->name eq 'java' && $object =~ /(\/|^)\.\.\//)
 2018 		  {
 2019 		    err_am "'$full' should not contain a '..' component";
 2020 		  }
 2021 
 2022                 # Make sure *all* objects files in the subdirectory are
 2023                 # removed by "make mostlyclean".  Not only this is more
 2024                 # efficient than listing the object files to be removed
 2025                 # individually (which would cause an 'rm' invocation for
 2026                 # each of them -- very inefficient, see bug#10697), it
 2027                 # would also leave stale object files in the subdirectory
 2028                 # whenever a source file there is removed or renamed.
 2029                 $compile_clean_files{"$directory/*.\$(OBJEXT)"} = MOSTLY_CLEAN;
 2030                 if ($object =~ /\.lo$/)
 2031                   {
 2032                     # If we have a libtool object, then we also must remove
 2033                     # any '.lo' objects in its same subdirectory.
 2034                     $compile_clean_files{"$directory/*.lo"} = MOSTLY_CLEAN;
 2035                     # Remember to cleanup .libs/ in this directory.
 2036                     $libtool_clean_directories{$directory} = 1;
 2037                   }
 2038 
 2039 		push (@dep_list, require_build_directory ($directory));
 2040 
 2041 		# If we're generating dependencies, we also want
 2042 		# to make sure that the appropriate subdir of the
 2043 		# .deps directory is created.
 2044 		push (@dep_list,
 2045 		      require_build_directory ($directory . '/$(DEPDIR)'))
 2046 		  unless option 'no-dependencies';
 2047 	    }
 2048 
 2049 	    pretty_print_rule ($object . ':', "\t", @dep_list)
 2050 		if scalar @dep_list > 0;
 2051 	}
 2052 
 2053 	# Transform .o or $o file into .P file (for automatic
 2054 	# dependency code).
 2055         # Properly flatten multiple adjacent slashes, as Solaris 10 make
 2056         # might fail over them in an include statement.
 2057         # Leading double slashes may be special, as per Posix, so deal
 2058         # with them carefully.
 2059         if ($lang && $lang->autodep ne 'no')
 2060         {
 2061             my $depfile = $object;
 2062             $depfile =~ s/\.([^.]*)$/.P$1/;
 2063             $depfile =~ s/\$\(OBJEXT\)$/o/;
 2064             my $maybe_extra_leading_slash = '';
 2065             $maybe_extra_leading_slash = '/' if $depfile =~ m,^//[^/],;
 2066             $depfile =~ s,/+,/,g;
 2067             my $basename = basename ($depfile);
 2068             # This might make $dirname empty, but we account for that below.
 2069             (my $dirname = dirname ($depfile)) =~ s/\/*$//;
 2070             $dirname = $maybe_extra_leading_slash . $dirname;
 2071             $dep_files{$dirname . '/$(DEPDIR)/' . $basename} = 1;
 2072         }
 2073     }
 2074 
 2075     return @result;
 2076 }
 2077 
 2078 
 2079 # $LINKER
 2080 # define_objects_from_sources ($VAR, $OBJVAR, $NODEFINE, $ONE_FILE,
 2081 #                              $OBJ, $PARENT, $TOPPARENT, $WHERE, %TRANSFORM)
 2082 # ---------------------------------------------------------------------------
 2083 # Define an _OBJECTS variable for a _SOURCES variable (or subvariable)
 2084 #
 2085 # Arguments are:
 2086 #   $VAR is the name of the _SOURCES variable
 2087 #   $OBJVAR is the name of the _OBJECTS variable if known (otherwise
 2088 #     it will be generated and returned).
 2089 #   $NODEFINE is a boolean: if true, $OBJVAR will not be defined (but
 2090 #     work done to determine the linker will be).
 2091 #   $ONE_FILE is the canonical (transformed) name of object to build
 2092 #   $OBJ is the object extension (i.e. either '.o' or '.lo').
 2093 #   $TOPPARENT is the _SOURCES variable being processed.
 2094 #   $WHERE context into which this definition is done
 2095 #   %TRANSFORM extra arguments to pass to file_contents when producing
 2096 #     rules
 2097 #
 2098 # Result is a pair ($LINKER, $OBJVAR):
 2099 #    $LINKER is a boolean, true if a linker is needed to deal with the objects
 2100 sub define_objects_from_sources
 2101 {
 2102   my ($var, $objvar, $nodefine, $one_file,
 2103       $obj, $topparent, $where, %transform) = @_;
 2104 
 2105   my $needlinker = "";
 2106 
 2107   transform_variable_recursively
 2108     ($var, $objvar, 'am__objects', $nodefine, $where,
 2109      # The transform code to run on each filename.
 2110      sub {
 2111        my ($subvar, $val, $cond, $full_cond) = @_;
 2112        my @trans = handle_single_transform ($subvar, $topparent,
 2113 					    $one_file, $obj, $val,
 2114 					    %transform);
 2115        $needlinker = "true" if @trans;
 2116        return @trans;
 2117      });
 2118 
 2119   return $needlinker;
 2120 }
 2121 
 2122 
 2123 # handle_source_transform ($CANON_TARGET, $TARGET, $OBJEXT, $WHERE, %TRANSFORM)
 2124 # -----------------------------------------------------------------------------
 2125 # Handle SOURCE->OBJECT transform for one program or library.
 2126 # Arguments are:
 2127 #   canonical (transformed) name of target to build
 2128 #   actual target of object to build
 2129 #   object extension (i.e., either '.o' or '$o')
 2130 #   location of the source variable
 2131 #   extra arguments to pass to file_contents when producing rules
 2132 # Return the name of the linker variable that must be used.
 2133 # Empty return means just use 'LINK'.
 2134 sub handle_source_transform
 2135 {
 2136     # one_file is canonical name.  unxformed is given name.  obj is
 2137     # object extension.
 2138     my ($one_file, $unxformed, $obj, $where, %transform) = @_;
 2139 
 2140     my $linker = '';
 2141 
 2142     # No point in continuing if _OBJECTS is defined.
 2143     return if reject_var ($one_file . '_OBJECTS',
 2144 			  $one_file . '_OBJECTS should not be defined');
 2145 
 2146     my %used_pfx = ();
 2147     my $needlinker;
 2148     %linkers_used = ();
 2149     foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
 2150 			'dist_EXTRA_', 'nodist_EXTRA_')
 2151     {
 2152 	my $varname = $prefix . $one_file . "_SOURCES";
 2153 	my $var = var $varname;
 2154 	next unless $var;
 2155 
 2156 	# We are going to define _OBJECTS variables using the prefix.
 2157 	# Then we glom them all together.  So we can't use the null
 2158 	# prefix here as we need it later.
 2159 	my $xpfx = ($prefix eq '') ? 'am_' : $prefix;
 2160 
 2161 	# Keep track of which prefixes we saw.
 2162 	$used_pfx{$xpfx} = 1
 2163 	  unless $prefix =~ /EXTRA_/;
 2164 
 2165 	push @sources, "\$($varname)";
 2166 	push @dist_sources, shadow_unconditionally ($varname, $where)
 2167 	  unless (option ('no-dist') || $prefix =~ /^nodist_/);
 2168 
 2169 	$needlinker |=
 2170 	    define_objects_from_sources ($varname,
 2171 					 $xpfx . $one_file . '_OBJECTS',
 2172 					 !!($prefix =~ /EXTRA_/),
 2173 					 $one_file, $obj, $varname, $where,
 2174 					 DIST_SOURCE => ($prefix !~ /^nodist_/),
 2175 					 %transform);
 2176     }
 2177     if ($needlinker)
 2178     {
 2179 	$linker ||= resolve_linker (%linkers_used);
 2180     }
 2181 
 2182     my @keys = sort keys %used_pfx;
 2183     if (scalar @keys == 0)
 2184     {
 2185 	# The default source for libfoo.la is libfoo.c, but for
 2186 	# backward compatibility we first look at libfoo_la.c,
 2187 	# if no default source suffix is given.
 2188 	my $old_default_source = "$one_file.c";
 2189 	my $ext_var = var ('AM_DEFAULT_SOURCE_EXT');
 2190 	my $default_source_ext = $ext_var ? variable_value ($ext_var) : '.c';
 2191 	msg_var ('unsupported', $ext_var, $ext_var->name . " can assume at most one value")
 2192 	  if $default_source_ext =~ /[\t ]/;
 2193 	(my $default_source = $unxformed) =~ s,(\.[^./\\]*)?$,$default_source_ext,;
 2194 	# TODO: Remove this backward-compatibility hack in Automake 2.0.
 2195 	if ($old_default_source ne $default_source
 2196 	    && !$ext_var
 2197 	    && (rule $old_default_source
 2198 		|| rule '$(srcdir)/' . $old_default_source
 2199 		|| rule '${srcdir}/' . $old_default_source
 2200 		|| -f $old_default_source))
 2201 	  {
 2202 	    my $loc = $where->clone;
 2203 	    $loc->pop_context;
 2204 	    msg ('obsolete', $loc,
 2205 		 "the default source for '$unxformed' has been changed "
 2206 		 . "to '$default_source'.\n(Using '$old_default_source' for "
 2207 		 . "backward compatibility.)");
 2208 	    $default_source = $old_default_source;
 2209 	  }
 2210 	# If a rule exists to build this source with a $(srcdir)
 2211 	# prefix, use that prefix in our variables too.  This is for
 2212 	# the sake of BSD Make.
 2213 	if (rule '$(srcdir)/' . $default_source
 2214 	    || rule '${srcdir}/' . $default_source)
 2215 	  {
 2216 	    $default_source = '$(srcdir)/' . $default_source;
 2217 	  }
 2218 
 2219 	define_variable ($one_file . "_SOURCES", $default_source, $where);
 2220 	push (@sources, $default_source);
 2221 	push (@dist_sources, $default_source);
 2222 
 2223 	%linkers_used = ();
 2224 	my (@result) =
 2225 	  handle_single_transform ($one_file . '_SOURCES',
 2226 				   $one_file . '_SOURCES',
 2227 				   $one_file, $obj,
 2228 				   $default_source, %transform);
 2229 	$linker ||= resolve_linker (%linkers_used);
 2230 	define_pretty_variable ($one_file . '_OBJECTS', TRUE, $where, @result);
 2231     }
 2232     else
 2233     {
 2234 	@keys = map { '$(' . $_ . $one_file . '_OBJECTS)' } @keys;
 2235 	define_pretty_variable ($one_file . '_OBJECTS', TRUE, $where, @keys);
 2236     }
 2237 
 2238     # If we want to use 'LINK' we must make sure it is defined.
 2239     if ($linker eq '')
 2240     {
 2241 	$need_link = 1;
 2242     }
 2243 
 2244     return $linker;
 2245 }
 2246 
 2247 
 2248 # handle_lib_objects ($XNAME, $VAR)
 2249 # ---------------------------------
 2250 # Special-case ALLOCA and LIBOBJS substitutions in _LDADD or _LIBADD variables.
 2251 # Also, generate _DEPENDENCIES variable if appropriate.
 2252 # Arguments are:
 2253 #   transformed name of object being built, or empty string if no object
 2254 #   name of _LDADD/_LIBADD-type variable to examine
 2255 # Returns 1 if LIBOBJS seen, 0 otherwise.
 2256 sub handle_lib_objects
 2257 {
 2258   my ($xname, $varname) = @_;
 2259 
 2260   my $var = var ($varname);
 2261   prog_error "'$varname' undefined"
 2262     unless $var;
 2263   prog_error "unexpected variable name '$varname'"
 2264     unless $varname =~ /^(.*)(?:LIB|LD)ADD$/;
 2265   my $prefix = $1 || 'AM_';
 2266 
 2267   my $seen_libobjs = 0;
 2268   my $flagvar = 0;
 2269 
 2270   transform_variable_recursively
 2271     ($varname, $xname . '_DEPENDENCIES', 'am__DEPENDENCIES',
 2272      ! $xname, INTERNAL,
 2273      # Transformation function, run on each filename.
 2274      sub {
 2275        my ($subvar, $val, $cond, $full_cond) = @_;
 2276 
 2277        if ($val =~ /^-/)
 2278 	 {
 2279 	   # Skip -lfoo and -Ldir silently; these are explicitly allowed.
 2280 	   if ($val !~ /^-[lL]/ &&
 2281 	       # Skip -dlopen and -dlpreopen; these are explicitly allowed
 2282 	       # for Libtool libraries or programs.  (Actually we are a bit
 2283 	       # lax here since this code also applies to non-libtool
 2284 	       # libraries or programs, for which -dlopen and -dlopreopen
 2285 	       # are pure nonsense.  Diagnosing this doesn't seem very
 2286 	       # important: the developer will quickly get complaints from
 2287 	       # the linker.)
 2288 	       $val !~ /^-dl(?:pre)?open$/ &&
 2289 	       # Only get this error once.
 2290 	       ! $flagvar)
 2291 	     {
 2292 	       $flagvar = 1;
 2293 	       # FIXME: should display a stack of nested variables
 2294 	       # as context when $var != $subvar.
 2295 	       err_var ($var, "linker flags such as '$val' belong in "
 2296 			. "'${prefix}LDFLAGS'");
 2297 	     }
 2298 	   return ();
 2299 	 }
 2300        elsif ($val !~ /^\@.*\@$/)
 2301 	 {
 2302 	   # Assume we have a file of some sort, and output it into the
 2303 	   # dependency variable.  Autoconf substitutions are not output;
 2304 	   # rarely is a new dependency substituted into e.g. foo_LDADD
 2305 	   # -- but bad things (e.g. -lX11) are routinely substituted.
 2306 	   # Note that LIBOBJS and ALLOCA are exceptions to this rule,
 2307 	   # and handled specially below.
 2308 	   return $val;
 2309 	 }
 2310        elsif ($val =~ /^\@(LT)?LIBOBJS\@$/)
 2311 	 {
 2312 	   handle_LIBOBJS ($subvar, $cond, $1);
 2313 	   $seen_libobjs = 1;
 2314 	   return $val;
 2315 	 }
 2316        elsif ($val =~ /^\@(LT)?ALLOCA\@$/)
 2317 	 {
 2318 	   handle_ALLOCA ($subvar, $cond, $1);
 2319 	   return $val;
 2320 	 }
 2321        else
 2322 	 {
 2323 	   return ();
 2324 	 }
 2325      });
 2326 
 2327   return $seen_libobjs;
 2328 }
 2329 
 2330 # handle_LIBOBJS_or_ALLOCA ($VAR, $BASE)
 2331 # --------------------------------------
 2332 # Definitions common to LIBOBJS and ALLOCA.
 2333 # VAR should be one of LIBOBJS, LTLIBOBJS, ALLOCA, or LTALLOCA.
 2334 # BASE should be one base file name from AC_LIBSOURCE, or alloca.
 2335 sub handle_LIBOBJS_or_ALLOCA
 2336 {
 2337   my ($var, $base) = @_;
 2338 
 2339   my $dir = '';
 2340 
 2341   # If LIBOBJS files must be built in another directory we have
 2342   # to define LIBOBJDIR and ensure the files get cleaned.
 2343   # Otherwise LIBOBJDIR can be left undefined, and the cleaning
 2344   # is achieved by 'rm -f *.$(OBJEXT)' in compile.am.
 2345   if ($config_libobj_dir
 2346       && $relative_dir ne $config_libobj_dir)
 2347     {
 2348       if (option 'subdir-objects')
 2349 	{
 2350 	  # In the top-level Makefile we do not use $(top_builddir), because
 2351 	  # we are already there, and since the targets are built without
 2352 	  # a $(top_builddir), it helps BSD Make to match them with
 2353 	  # dependencies.
 2354 	  $dir = "$config_libobj_dir/"
 2355 	    if $config_libobj_dir ne '.';
 2356 	  $dir = backname ($relative_dir) . "/$dir"
 2357 	    if $relative_dir ne '.';
 2358 	  define_variable ('LIBOBJDIR', "$dir", INTERNAL);
 2359 	  if ($dir && !defined $clean_files{"$dir$base.\$(OBJEXT)"})
 2360 	    {
 2361 	      my $dirstamp = require_build_directory ($dir);
 2362 	      $output_rules .= "$dir$base.\$(OBJEXT): $dirstamp\n";
 2363 	      $output_rules .= "$dir$base.lo: $dirstamp\n"
 2364 		if ($var =~ /^LT/);
 2365 	    }
 2366 	  # libtool might create .$(OBJEXT) as a side-effect of using
 2367 	  # LTLIBOBJS or LTALLOCA.
 2368 	  $clean_files{"$dir$base.\$(OBJEXT)"} = MOSTLY_CLEAN;
 2369 	  $clean_files{"$dir$base.lo"} = MOSTLY_CLEAN
 2370 	    if ($var =~ /^LT/);
 2371 	}
 2372       else
 2373 	{
 2374 	  error ("'\$($var)' cannot be used outside '$config_libobj_dir' if"
 2375 		 . " 'subdir-objects' is not set");
 2376 	}
 2377     }
 2378 
 2379   return $dir;
 2380 }
 2381 
 2382 sub handle_LIBOBJS
 2383 {
 2384   my ($var, $cond, $lt) = @_;
 2385   my $myobjext = $lt ? 'lo' : 'o';
 2386   $lt ||= '';
 2387 
 2388   $var->requires_variables ("\@${lt}LIBOBJS\@ used", $lt . 'LIBOBJS')
 2389     if ! keys %libsources;
 2390 
 2391   foreach my $iter (keys %libsources)
 2392     {
 2393       my $dir = '';
 2394       if ($iter =~ /^(.*)(\.[cly])$/)
 2395 	{
 2396 	  saw_extension ($2);
 2397 	  saw_extension ('.c');
 2398 	  $dir = handle_LIBOBJS_or_ALLOCA ("${lt}LIBOBJS", $1);
 2399 	}
 2400 
 2401       if ($iter =~ /\.h$/)
 2402 	{
 2403 	  require_libsource_with_macro ($cond, $var, FOREIGN, $iter);
 2404 	}
 2405       elsif ($iter ne 'alloca.c')
 2406 	{
 2407 	  my $rewrite = $iter;
 2408 	  $rewrite =~ s/\.c$/.P$myobjext/;
 2409 	  $dep_files{$dir . '$(DEPDIR)/' . $rewrite} = 1;
 2410 	  $rewrite = "^" . quotemeta ($iter) . "\$";
 2411 	  # Only require the file if it is not a built source.
 2412 	  my $bs = var ('BUILT_SOURCES');
 2413 	  if (! $bs || ! grep (/$rewrite/, $bs->value_as_list_recursive))
 2414 	    {
 2415 	      require_libsource_with_macro ($cond, $var, FOREIGN, $iter);
 2416 	    }
 2417 	}
 2418     }
 2419 }
 2420 
 2421 sub handle_ALLOCA
 2422 {
 2423   my ($var, $cond, $lt) = @_;
 2424   my $myobjext = $lt ? 'lo' : 'o';
 2425   $lt ||= '';
 2426   my $dir = handle_LIBOBJS_or_ALLOCA ("${lt}ALLOCA", "alloca");
 2427 
 2428   $dir eq '' and $dir = './';
 2429   $var->requires_variables ("\@${lt}ALLOCA\@ used", $lt . 'ALLOCA');
 2430   $dep_files{$dir . '$(DEPDIR)/alloca.P' . $myobjext} = 1;
 2431   require_libsource_with_macro ($cond, $var, FOREIGN, 'alloca.c');
 2432   saw_extension ('.c');
 2433 }
 2434 
 2435 # Canonicalize the input parameter.
 2436 sub canonicalize
 2437 {
 2438     my ($string) = @_;
 2439     $string =~ tr/A-Za-z0-9_\@/_/c;
 2440     return $string;
 2441 }
 2442 
 2443 # Canonicalize a name, and check to make sure the non-canonical name
 2444 # is never used.  Returns canonical name.  Arguments are name and a
 2445 # list of suffixes to check for.
 2446 sub check_canonical_spelling
 2447 {
 2448   my ($name, @suffixes) = @_;
 2449 
 2450   my $xname = canonicalize ($name);
 2451   if ($xname ne $name)
 2452     {
 2453       foreach my $xt (@suffixes)
 2454 	{
 2455 	  reject_var ("$name$xt", "use '$xname$xt', not '$name$xt'");
 2456 	}
 2457     }
 2458 
 2459   return $xname;
 2460 }
 2461 
 2462 # Set up the compile suite.
 2463 sub handle_compile ()
 2464 {
 2465    return if ! $must_handle_compiled_objects;
 2466 
 2467     # Boilerplate.
 2468     my $default_includes = '';
 2469     if (! option 'nostdinc')
 2470       {
 2471 	my @incs = ('-I.', subst ('am__isrc'));
 2472 
 2473 	my $var = var 'CONFIG_HEADER';
 2474 	if ($var)
 2475 	  {
 2476 	    foreach my $hdr (split (' ', $var->variable_value))
 2477 	      {
 2478 		push @incs, '-I' . dirname ($hdr);
 2479 	      }
 2480 	  }
 2481 	# We want '-I. -I$(srcdir)', but the latter -I is redundant
 2482 	# and unaesthetic in non-VPATH builds.  We use `-I.@am__isrc@`
 2483 	# instead.  It will be replaced by '-I.' or '-I. -I$(srcdir)'.
 2484 	# Items in CONFIG_HEADER are never in $(srcdir) so it is safe
 2485 	# to just put @am__isrc@ right after '-I.', without a space.
 2486 	($default_includes = ' ' . uniq (@incs)) =~ s/ @/@/;
 2487       }
 2488 
 2489     my (@mostly_rms, @dist_rms);
 2490     foreach my $item (sort keys %compile_clean_files)
 2491     {
 2492 	if ($compile_clean_files{$item} == MOSTLY_CLEAN)
 2493 	{
 2494 	    push (@mostly_rms, "\t-rm -f $item");
 2495 	}
 2496 	elsif ($compile_clean_files{$item} == DIST_CLEAN)
 2497 	{
 2498 	    push (@dist_rms, "\t-rm -f $item");
 2499 	}
 2500 	else
 2501 	{
 2502 	  prog_error 'invalid entry in %compile_clean_files';
 2503 	}
 2504     }
 2505 
 2506     my ($coms, $vars, $rules) =
 2507       file_contents_internal (1, "$libdir/am/compile.am",
 2508 			      new Automake::Location,
 2509 			      'DEFAULT_INCLUDES' => $default_includes,
 2510 			      'MOSTLYRMS' => join ("\n", @mostly_rms),
 2511 			      'DISTRMS' => join ("\n", @dist_rms));
 2512     $output_vars .= $vars;
 2513     $output_rules .= "$coms$rules";
 2514 }
 2515 
 2516 # Handle libtool rules.
 2517 sub handle_libtool ()
 2518 {
 2519   return unless var ('LIBTOOL');
 2520 
 2521   # Libtool requires some files, but only at top level.
 2522   # (Starting with Libtool 2.0 we do not have to bother.  These
 2523   # requirements are done with AC_REQUIRE_AUX_FILE.)
 2524   require_conf_file_with_macro (TRUE, 'LIBTOOL', FOREIGN, @libtool_files)
 2525     if $relative_dir eq '.' && ! $libtool_new_api;
 2526 
 2527   my @libtool_rms;
 2528   foreach my $item (sort keys %libtool_clean_directories)
 2529     {
 2530       my $dir = ($item eq '.') ? '' : "$item/";
 2531       # .libs is for Unix, _libs for DOS.
 2532       push (@libtool_rms, "\t-rm -rf ${dir}.libs ${dir}_libs");
 2533     }
 2534 
 2535   check_user_variables 'LIBTOOLFLAGS';
 2536 
 2537   # Output the libtool compilation rules.
 2538   $output_rules .= file_contents ('libtool',
 2539 				  new Automake::Location,
 2540 				   LTRMS => join ("\n", @libtool_rms));
 2541 }
 2542 
 2543 # Check for duplicate targets
 2544 sub handle_targets ()
 2545 {
 2546   my %seen = ();
 2547   my @dups = ();
 2548   @proglist = am_install_var ('progs', 'PROGRAMS',
 2549                               'bin', 'sbin', 'libexec', 'pkglibexec',
 2550                               'noinst', 'check');
 2551   @liblist = am_install_var ('libs', 'LIBRARIES',
 2552                              'lib', 'pkglib', 'noinst', 'check');
 2553   @ltliblist = am_install_var ('ltlib', 'LTLIBRARIES',
 2554 			       'noinst', 'lib', 'pkglib', 'check');
 2555 
 2556   # Record duplications that may arise after canonicalization of the
 2557   # base names, in order to prevent object file clashes in the presence
 2558   # of target-specific *FLAGS
 2559   my @targetlist = (@proglist, @liblist, @ltliblist);
 2560   foreach my $pair (@targetlist)
 2561     {
 2562       my $base = canonicalize (basename (@$pair[1]));
 2563       push (@dup_shortnames, $base) if ($seen{$base});
 2564       $seen{$base} = $base;
 2565     }
 2566 }
 2567 
 2568 sub handle_programs ()
 2569 {
 2570   return if ! @proglist;
 2571   $must_handle_compiled_objects = 1;
 2572 
 2573   my $seen_global_libobjs =
 2574     var ('LDADD') && handle_lib_objects ('', 'LDADD');
 2575 
 2576   foreach my $pair (@proglist)
 2577     {
 2578       my ($where, $one_file) = @$pair;
 2579 
 2580       my $seen_libobjs = 0;
 2581       my $obj = '.$(OBJEXT)';
 2582 
 2583       $known_programs{$one_file} = $where;
 2584 
 2585       # Canonicalize names and check for misspellings.
 2586       my $xname = check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
 2587                                             '_SOURCES', '_OBJECTS',
 2588                                             '_DEPENDENCIES');
 2589 
 2590       $where->push_context ("while processing program '$one_file'");
 2591       $where->set (INTERNAL->get);
 2592 
 2593       my $linker = handle_source_transform ($xname, $one_file, $obj, $where,
 2594                                             NONLIBTOOL => 1, LIBTOOL => 0);
 2595 
 2596       if (var ($xname . "_LDADD"))
 2597 	{
 2598 	  $seen_libobjs = handle_lib_objects ($xname, $xname . '_LDADD');
 2599 	}
 2600       else
 2601 	{
 2602 	  # User didn't define prog_LDADD override.  So do it.
 2603 	  define_variable ($xname . '_LDADD', '$(LDADD)', $where);
 2604 
 2605 	  # This does a bit too much work.  But we need it to
 2606 	  # generate _DEPENDENCIES when appropriate.
 2607 	  if (var ('LDADD'))
 2608 	    {
 2609 	      $seen_libobjs = handle_lib_objects ($xname, 'LDADD');
 2610 	    }
 2611 	}
 2612 
 2613       reject_var ($xname . '_LIBADD',
 2614 		  "use '${xname}_LDADD', not '${xname}_LIBADD'");
 2615 
 2616       set_seen ($xname . '_DEPENDENCIES');
 2617       set_seen ('EXTRA_' . $xname . '_DEPENDENCIES');
 2618       set_seen ($xname . '_LDFLAGS');
 2619 
 2620       # Determine program to use for link.
 2621       my($xlink, $vlink) = define_per_target_linker_variable ($linker, $xname);
 2622       $vlink = verbose_flag ($vlink || 'GEN');
 2623 
 2624       # If the resulting program lies in a subdirectory,
 2625       # ensure that the directory exists before we need it.
 2626       my $dirstamp = require_build_directory_maybe ($one_file);
 2627 
 2628       $libtool_clean_directories{dirname ($one_file)} = 1;
 2629 
 2630       $output_rules .= file_contents ('program',
 2631                                       $where,
 2632                                       PROGRAM  => $one_file,
 2633                                       XPROGRAM => $xname,
 2634                                       XLINK    => $xlink,
 2635                                       VERBOSE  => $vlink,
 2636                                       DIRSTAMP => $dirstamp,
 2637                                       EXEEXT   => '$(EXEEXT)');
 2638 
 2639       if ($seen_libobjs || $seen_global_libobjs)
 2640 	{
 2641 	  if (var ($xname . '_LDADD'))
 2642 	    {
 2643 	      check_libobjs_sources ($xname, $xname . '_LDADD');
 2644 	    }
 2645 	  elsif (var ('LDADD'))
 2646 	    {
 2647 	      check_libobjs_sources ($xname, 'LDADD');
 2648 	    }
 2649 	}
 2650     }
 2651 }
 2652 
 2653 
 2654 sub handle_libraries ()
 2655 {
 2656   return if ! @liblist;
 2657   $must_handle_compiled_objects = 1;
 2658 
 2659   my @prefix = am_primary_prefixes ('LIBRARIES', 0, 'lib', 'pkglib',
 2660 				    'noinst', 'check');
 2661 
 2662   if (@prefix)
 2663     {
 2664       my $var = rvar ($prefix[0] . '_LIBRARIES');
 2665       $var->requires_variables ('library used', 'RANLIB');
 2666     }
 2667 
 2668   define_variable ('AR', 'ar', INTERNAL);
 2669   define_variable ('ARFLAGS', 'cru', INTERNAL);
 2670   define_verbose_tagvar ('AR');
 2671 
 2672   foreach my $pair (@liblist)
 2673     {
 2674       my ($where, $onelib) = @$pair;
 2675 
 2676       my $seen_libobjs = 0;
 2677       # Check that the library fits the standard naming convention.
 2678       my $bn = basename ($onelib);
 2679       if ($bn !~ /^lib.*\.a$/)
 2680 	{
 2681 	  $bn =~ s/^(?:lib)?(.*?)(?:\.[^.]*)?$/lib$1.a/;
 2682 	  my $suggestion = dirname ($onelib) . "/$bn";
 2683 	  $suggestion =~ s|^\./||g;
 2684 	  msg ('error-gnu/warn', $where,
 2685 	       "'$onelib' is not a standard library name\n"
 2686 	       . "did you mean '$suggestion'?")
 2687 	}
 2688 
 2689       ($known_libraries{$onelib} = $bn) =~ s/\.a$//;
 2690 
 2691       $where->push_context ("while processing library '$onelib'");
 2692       $where->set (INTERNAL->get);
 2693 
 2694       my $obj = '.$(OBJEXT)';
 2695 
 2696       # Canonicalize names and check for misspellings.
 2697       my $xlib = check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
 2698                                            '_OBJECTS', '_DEPENDENCIES',
 2699                                            '_AR');
 2700 
 2701       if (! var ($xlib . '_AR'))
 2702 	{
 2703 	  define_variable ($xlib . '_AR', '$(AR) $(ARFLAGS)', $where);
 2704 	}
 2705 
 2706       # Generate support for conditional object inclusion in
 2707       # libraries.
 2708       if (var ($xlib . '_LIBADD'))
 2709 	{
 2710 	  if (handle_lib_objects ($xlib, $xlib . '_LIBADD'))
 2711 	    {
 2712 	      $seen_libobjs = 1;
 2713 	    }
 2714 	}
 2715       else
 2716 	{
 2717 	  define_variable ($xlib . "_LIBADD", '', $where);
 2718 	}
 2719 
 2720       reject_var ($xlib . '_LDADD',
 2721 		  "use '${xlib}_LIBADD', not '${xlib}_LDADD'");
 2722 
 2723       # Make sure we at look at this.
 2724       set_seen ($xlib . '_DEPENDENCIES');
 2725       set_seen ('EXTRA_' . $xlib . '_DEPENDENCIES');
 2726 
 2727       handle_source_transform ($xlib, $onelib, $obj, $where,
 2728                                NONLIBTOOL => 1, LIBTOOL => 0);
 2729 
 2730       # If the resulting library lies in a subdirectory,
 2731       # make sure this directory will exist.
 2732       my $dirstamp = require_build_directory_maybe ($onelib);
 2733       my $verbose = verbose_flag ('AR');
 2734       my $silent = silent_flag ();
 2735 
 2736       $output_rules .= file_contents ('library',
 2737                                        $where,
 2738                                        VERBOSE  => $verbose,
 2739                                        SILENT   => $silent,
 2740                                        LIBRARY  => $onelib,
 2741                                        XLIBRARY => $xlib,
 2742                                        DIRSTAMP => $dirstamp);
 2743 
 2744       if ($seen_libobjs)
 2745 	{
 2746 	  if (var ($xlib . '_LIBADD'))
 2747 	    {
 2748 	      check_libobjs_sources ($xlib, $xlib . '_LIBADD');
 2749 	    }
 2750 	}
 2751 
 2752       if (! $seen_ar)
 2753 	{
 2754 	  msg ('extra-portability', $where,
 2755 	       "'$onelib': linking libraries using a non-POSIX\n"
 2756 	       . "archiver requires 'AM_PROG_AR' in '$configure_ac'")
 2757 	}
 2758     }
 2759 }
 2760 
 2761 
 2762 sub handle_ltlibraries ()
 2763 {
 2764   return if ! @ltliblist;
 2765   $must_handle_compiled_objects = 1;
 2766 
 2767   my @prefix = am_primary_prefixes ('LTLIBRARIES', 0, 'lib', 'pkglib',
 2768 				    'noinst', 'check');
 2769 
 2770   if (@prefix)
 2771     {
 2772       my $var = rvar ($prefix[0] . '_LTLIBRARIES');
 2773       $var->requires_variables ('Libtool library used', 'LIBTOOL');
 2774     }
 2775 
 2776   my %instdirs = ();
 2777   my %instsubdirs = ();
 2778   my %instconds = ();
 2779   my %liblocations = ();	# Location (in Makefile.am) of each library.
 2780 
 2781   foreach my $key (@prefix)
 2782     {
 2783       # Get the installation directory of each library.
 2784       my $dir = $key;
 2785       my $strip_subdir = 1;
 2786       if ($dir =~ /^nobase_/)
 2787         {
 2788 	  $dir =~ s/^nobase_//;
 2789 	  $strip_subdir = 0;
 2790 	}
 2791       my $var = rvar ($key . '_LTLIBRARIES');
 2792 
 2793       # We reject libraries which are installed in several places
 2794       # in the same condition, because we can only specify one
 2795       # '-rpath' option.
 2796       $var->traverse_recursively
 2797 	(sub
 2798 	 {
 2799 	   my ($var, $val, $cond, $full_cond) = @_;
 2800 	   my $hcond = $full_cond->human;
 2801 	   my $where = $var->rdef ($cond)->location;
 2802 	   my $ldir = '';
 2803 	   $ldir = '/' . dirname ($val)
 2804 	     if (!$strip_subdir);
 2805 	   # A library cannot be installed in different directories
 2806 	   # in overlapping conditions.
 2807 	   if (exists $instconds{$val})
 2808 	     {
 2809 	       my ($msg, $acond) =
 2810 		 $instconds{$val}->ambiguous_p ($val, $full_cond);
 2811 
 2812 	       if ($msg)
 2813 		 {
 2814 		   error ($where, $msg, partial => 1);
 2815 		   my $dirtxt = "installed " . ($strip_subdir ? "in" : "below") . " '$dir'";
 2816 		   $dirtxt = "built for '$dir'"
 2817 		     if $dir eq 'EXTRA' || $dir eq 'noinst' || $dir eq 'check';
 2818 		   my $dircond =
 2819 		     $full_cond->true ? "" : " in condition $hcond";
 2820 
 2821 		   error ($where, "'$val' should be $dirtxt$dircond ...",
 2822 			  partial => 1);
 2823 
 2824 		   my $hacond = $acond->human;
 2825 		   my $adir = $instdirs{$val}{$acond};
 2826 		   my $adirtxt = "installed in '$adir'";
 2827 		   $adirtxt = "built for '$adir'"
 2828 		     if ($adir eq 'EXTRA' || $adir eq 'noinst'
 2829 			 || $adir eq 'check');
 2830 		   my $adircond = $acond->true ? "" : " in condition $hacond";
 2831 
 2832 		   my $onlyone = ($dir ne $adir) ?
 2833 		     ("\nLibtool libraries can be built for only one "
 2834 		      . "destination") : "";
 2835 
 2836 		   error ($liblocations{$val}{$acond},
 2837 			  "... and should also be $adirtxt$adircond.$onlyone");
 2838 		   return;
 2839 		 }
 2840 	     }
 2841 	   else
 2842 	     {
 2843 	       $instconds{$val} = new Automake::DisjConditions;
 2844 	     }
 2845 	   $instdirs{$val}{$full_cond} = $dir;
 2846 	   $instsubdirs{$val}{$full_cond} = $ldir;
 2847 	   $liblocations{$val}{$full_cond} = $where;
 2848 	   $instconds{$val} = $instconds{$val}->merge ($full_cond);
 2849 	 },
 2850 	 sub
 2851 	 {
 2852 	   return ();
 2853 	 },
 2854 	 skip_ac_subst => 1);
 2855     }
 2856 
 2857   foreach my $pair (@ltliblist)
 2858     {
 2859       my ($where, $onelib) = @$pair;
 2860 
 2861       my $seen_libobjs = 0;
 2862       my $obj = '.lo';
 2863 
 2864       # Canonicalize names and check for misspellings.
 2865       my $xlib = check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
 2866                                            '_SOURCES', '_OBJECTS',
 2867                                            '_DEPENDENCIES');
 2868 
 2869       # Check that the library fits the standard naming convention.
 2870       my $libname_rx = '^lib.*\.la';
 2871       my $ldvar = var ("${xlib}_LDFLAGS") || var ('AM_LDFLAGS');
 2872       my $ldvar2 = var ('LDFLAGS');
 2873       if (($ldvar && grep (/-module/, $ldvar->value_as_list_recursive))
 2874 	  || ($ldvar2 && grep (/-module/, $ldvar2->value_as_list_recursive)))
 2875 	{
 2876 	  # Relax name checking for libtool modules.
 2877 	  $libname_rx = '\.la';
 2878 	}
 2879 
 2880       my $bn = basename ($onelib);
 2881       if ($bn !~ /$libname_rx$/)
 2882 	{
 2883 	  my $type = 'library';
 2884 	  if ($libname_rx eq '\.la')
 2885 	    {
 2886 	      $bn =~ s/^(lib|)(.*?)(?:\.[^.]*)?$/$1$2.la/;
 2887 	      $type = 'module';
 2888 	    }
 2889 	  else
 2890 	    {
 2891 	      $bn =~ s/^(?:lib)?(.*?)(?:\.[^.]*)?$/lib$1.la/;
 2892 	    }
 2893 	  my $suggestion = dirname ($onelib) . "/$bn";
 2894 	  $suggestion =~ s|^\./||g;
 2895 	  msg ('error-gnu/warn', $where,
 2896 	       "'$onelib' is not a standard libtool $type name\n"
 2897 	       . "did you mean '$suggestion'?")
 2898 	}
 2899 
 2900       ($known_libraries{$onelib} = $bn) =~ s/\.la$//;
 2901 
 2902       $where->push_context ("while processing Libtool library '$onelib'");
 2903       $where->set (INTERNAL->get);
 2904 
 2905       # Make sure we look at these.
 2906       set_seen ($xlib . '_LDFLAGS');
 2907       set_seen ($xlib . '_DEPENDENCIES');
 2908       set_seen ('EXTRA_' . $xlib . '_DEPENDENCIES');
 2909 
 2910       # Generate support for conditional object inclusion in
 2911       # libraries.
 2912       if (var ($xlib . '_LIBADD'))
 2913 	{
 2914 	  if (handle_lib_objects ($xlib, $xlib . '_LIBADD'))
 2915 	    {
 2916 	      $seen_libobjs = 1;
 2917 	    }
 2918 	}
 2919       else
 2920 	{
 2921 	  define_variable ($xlib . "_LIBADD", '', $where);
 2922 	}
 2923 
 2924       reject_var ("${xlib}_LDADD",
 2925 		  "use '${xlib}_LIBADD', not '${xlib}_LDADD'");
 2926 
 2927 
 2928       my $linker = handle_source_transform ($xlib, $onelib, $obj, $where,
 2929                                             NONLIBTOOL => 0, LIBTOOL => 1);
 2930 
 2931       # Determine program to use for link.
 2932       my($xlink, $vlink) = define_per_target_linker_variable ($linker, $xlib);
 2933       $vlink = verbose_flag ($vlink || 'GEN');
 2934 
 2935       my $rpathvar = "am_${xlib}_rpath";
 2936       my $rpath = "\$($rpathvar)";
 2937       foreach my $rcond ($instconds{$onelib}->conds)
 2938 	{
 2939 	  my $val;
 2940 	  if ($instdirs{$onelib}{$rcond} eq 'EXTRA'
 2941 	      || $instdirs{$onelib}{$rcond} eq 'noinst'
 2942 	      || $instdirs{$onelib}{$rcond} eq 'check')
 2943 	    {
 2944 	      # It's an EXTRA_ library, so we can't specify -rpath,
 2945 	      # because we don't know where the library will end up.
 2946 	      # The user probably knows, but generally speaking automake
 2947 	      # doesn't -- and in fact configure could decide
 2948 	      # dynamically between two different locations.
 2949 	      $val = '';
 2950 	    }
 2951 	  else
 2952 	    {
 2953 	      $val = ('-rpath $(' . $instdirs{$onelib}{$rcond} . 'dir)');
 2954 	      $val .= $instsubdirs{$onelib}{$rcond}
 2955 	        if defined $instsubdirs{$onelib}{$rcond};
 2956 	    }
 2957 	  if ($rcond->true)
 2958 	    {
 2959 	      # If $rcond is true there is only one condition and
 2960 	      # there is no point defining an helper variable.
 2961 	      $rpath = $val;
 2962 	    }
 2963 	  else
 2964 	    {
 2965 	      define_pretty_variable ($rpathvar, $rcond, INTERNAL, $val);
 2966 	    }
 2967 	}
 2968 
 2969       # If the resulting library lies in a subdirectory,
 2970       # make sure this directory will exist.
 2971       my $dirstamp = require_build_directory_maybe ($onelib);
 2972 
 2973       # Remember to cleanup .libs/ in this directory.
 2974       my $dirname = dirname $onelib;
 2975       $libtool_clean_directories{$dirname} = 1;
 2976 
 2977       $output_rules .= file_contents ('ltlibrary',
 2978                                       $where,
 2979                                       LTLIBRARY  => $onelib,
 2980                                       XLTLIBRARY => $xlib,
 2981                                       RPATH      => $rpath,
 2982                                       XLINK      => $xlink,
 2983                                       VERBOSE    => $vlink,
 2984                                       DIRSTAMP   => $dirstamp);
 2985       if ($seen_libobjs)
 2986 	{
 2987 	  if (var ($xlib . '_LIBADD'))
 2988 	    {
 2989 	      check_libobjs_sources ($xlib, $xlib . '_LIBADD');
 2990 	    }
 2991 	}
 2992 
 2993       if (! $seen_ar)
 2994 	{
 2995 	  msg ('extra-portability', $where,
 2996 	       "'$onelib': linking libtool libraries using a non-POSIX\n"
 2997 	       . "archiver requires 'AM_PROG_AR' in '$configure_ac'")
 2998 	}
 2999     }
 3000 }
 3001 
 3002 # See if any _SOURCES variable were misspelled.
 3003 sub check_typos ()
 3004 {
 3005   # It is ok if the user sets this particular variable.
 3006   set_seen 'AM_LDFLAGS';
 3007 
 3008   foreach my $primary ('SOURCES', 'LIBADD', 'LDADD', 'LDFLAGS', 'DEPENDENCIES')
 3009     {
 3010       foreach my $var (variables $primary)
 3011 	{
 3012 	  my $varname = $var->name;
 3013 	  # A configure variable is always legitimate.
 3014 	  next if exists $configure_vars{$varname};
 3015 
 3016 	  for my $cond ($var->conditions->conds)
 3017 	    {
 3018 	      $varname =~ /^(?:EXTRA_)?(?:nobase_)?(?:dist_|nodist_)?(.*)_[[:alnum:]]+$/;
 3019 	      msg_var ('syntax', $var, "variable '$varname' is defined but no"
 3020 		       . " program or\nlibrary has '$1' as canonical name"
 3021 		       . " (possible typo)")
 3022 		unless $var->rdef ($cond)->seen;
 3023 	    }
 3024 	}
 3025     }
 3026 }
 3027 
 3028 
 3029 sub handle_scripts ()
 3030 {
 3031     # NOTE we no longer automatically clean SCRIPTS, because it is
 3032     # useful to sometimes distribute scripts verbatim.  This happens
 3033     # e.g. in Automake itself.
 3034     am_install_var ('-candist', 'scripts', 'SCRIPTS',
 3035                     'bin', 'sbin', 'libexec', 'pkglibexec', 'pkgdata',
 3036                     'noinst', 'check');
 3037 }
 3038 
 3039 
 3040 ## ------------------------ ##
 3041 ## Handling Texinfo files.  ##
 3042 ## ------------------------ ##
 3043 
 3044 # ($OUTFILE, $VFILE)
 3045 # scan_texinfo_file ($FILENAME)
 3046 # -----------------------------
 3047 # $OUTFILE     - name of the info file produced by $FILENAME.
 3048 # $VFILE       - name of the version.texi file used (undef if none).
 3049 sub scan_texinfo_file
 3050 {
 3051   my ($filename) = @_;
 3052 
 3053   my $texi = new Automake::XFile "< $filename";
 3054   verb "reading $filename";
 3055 
 3056   my ($outfile, $vfile);
 3057   while ($_ = $texi->getline)
 3058     {
 3059       if (/^\@setfilename +(\S+)/)
 3060 	{
 3061 	  # Honor only the first @setfilename.  (It's possible to have
 3062 	  # more occurrences later if the manual shows examples of how
 3063 	  # to use @setfilename...)
 3064 	  next if $outfile;
 3065 
 3066 	  $outfile = $1;
 3067 	  if (index ($outfile, '.') < 0)
 3068 	    {
 3069 	      msg 'obsolete', "$filename:$.",
 3070 	          "use of suffix-less info files is discouraged"
 3071 	    }
 3072 	  elsif ($outfile !~ /\.info$/)
 3073 	    {
 3074 	      error ("$filename:$.",
 3075 		     "output '$outfile' has unrecognized extension");
 3076 	      return;
 3077 	    }
 3078 	}
 3079       # A "version.texi" file is actually any file whose name matches
 3080       # "vers*.texi".
 3081       elsif (/^\@include\s+(vers[^.]*\.texi)\s*$/)
 3082 	{
 3083 	  $vfile = $1;
 3084 	}
 3085     }
 3086 
 3087   if (! $outfile)
 3088     {
 3089       # Replace a .texi extension with .info
 3090       $outfile = basename($filename);
 3091       $outfile =~ s/\.[^.]+$//;
 3092       $outfile .= '.info';
 3093     }
 3094 
 3095   return ($outfile, $vfile);
 3096 }
 3097 
 3098 
 3099 # ($DIRSTAMP, @CLEAN_FILES)
 3100 # output_texinfo_build_rules ($SOURCE, $DEST, $INSRC, @DEPENDENCIES)
 3101 # ------------------------------------------------------------------
 3102 # SOURCE - the source Texinfo file
 3103 # DEST - the destination Info file
 3104 # INSRC - whether DEST should be built in the source tree
 3105 # DEPENDENCIES - known dependencies
 3106 sub output_texinfo_build_rules
 3107 {
 3108   my ($source, $dest, $insrc, @deps) = @_;
 3109 
 3110   # Split 'a.texi' into 'a' and '.texi'.
 3111   my ($spfx, $ssfx) = ($source =~ /^(.*?)(\.[^.]*)?$/);
 3112   my ($dpfx, $dsfx) = ($dest =~ /^(.*?)(\.[^.]*)?$/);
 3113 
 3114   $ssfx ||= "";
 3115   $dsfx ||= "";
 3116 
 3117   # We can output two kinds of rules: the "generic" rules use Make
 3118   # suffix rules and are appropriate when $source and $dest do not lie
 3119   # in a sub-directory; the "specific" rules are needed in the other
 3120   # case.
 3121   #
 3122   # The former are output only once (this is not really apparent here,
 3123   # but just remember that some logic deeper in Automake will not
 3124   # output the same rule twice); while the later need to be output for
 3125   # each Texinfo source.
 3126   my $generic;
 3127   my $makeinfoflags;
 3128   my $sdir = dirname $source;
 3129   if ($sdir eq '.' && dirname ($dest) eq '.')
 3130     {
 3131       $generic = 1;
 3132       $makeinfoflags = '-I $(srcdir)';
 3133     }
 3134   else
 3135     {
 3136       $generic = 0;
 3137       $makeinfoflags = "-I $sdir -I \$(srcdir)/$sdir";
 3138     }
 3139 
 3140   # A directory can contain two kinds of info files: some built in the
 3141   # source tree, and some built in the build tree.  The rules are
 3142   # different in each case.  However we cannot output two different
 3143   # set of generic rules.  Because in-source builds are more usual, we
 3144   # use generic rules in this case and fall back to "specific" rules
 3145   # for build-dir builds.  (It should not be a problem to invert this
 3146   # if needed.)
 3147   $generic = 0 unless $insrc;
 3148 
 3149   # We cannot use a suffix rule to build info files with an empty
 3150   # extension.  Otherwise we would output a single suffix inference
 3151   # rule, with separate dependencies, as in
 3152   #
 3153   #    .texi:
 3154   #             $(MAKEINFO) ...
 3155   #    foo.info: foo.texi
 3156   #
 3157   # which confuse Solaris make.  (See the Autoconf manual for
 3158   # details.)  Therefore we use a specific rule in this case.  This
 3159   # applies to info files only (dvi and pdf files always have an
 3160   # extension).
 3161   my $generic_info = ($generic && $dsfx) ? 1 : 0;
 3162 
 3163   # If the resulting file lies in a subdirectory,
 3164   # make sure this directory will exist.
 3165   my $dirstamp = require_build_directory_maybe ($dest);
 3166 
 3167   my $dipfx = ($insrc ? '$(srcdir)/' : '') . $dpfx;
 3168 
 3169   $output_rules .= file_contents ('texibuild',
 3170 				  new Automake::Location,
 3171                                   AM_V_MAKEINFO    => verbose_flag('MAKEINFO'),
 3172                                   AM_V_TEXI2DVI    => verbose_flag('TEXI2DVI'),
 3173                                   AM_V_TEXI2PDF    => verbose_flag('TEXI2PDF'),
 3174 				  DEPS             => "@deps",
 3175 				  DEST_PREFIX      => $dpfx,
 3176 				  DEST_INFO_PREFIX => $dipfx,
 3177 				  DEST_SUFFIX      => $dsfx,
 3178 				  DIRSTAMP         => $dirstamp,
 3179 				  GENERIC          => $generic,
 3180 				  GENERIC_INFO     => $generic_info,
 3181 				  INSRC		   => $insrc,
 3182 				  MAKEINFOFLAGS    => $makeinfoflags,
 3183                                   SILENT           => silent_flag(),
 3184 				  SOURCE           => ($generic
 3185 						       ? '$<' : $source),
 3186 				  SOURCE_INFO      => ($generic_info
 3187 						       ? '$<' : $source),
 3188 				  SOURCE_REAL      => $source,
 3189 				  SOURCE_SUFFIX    => $ssfx,
 3190                                   TEXIQUIET        => verbose_flag('texinfo'),
 3191                                   TEXIDEVNULL      => verbose_flag('texidevnull'),
 3192 				  );
 3193   return ($dirstamp, "$dpfx.dvi", "$dpfx.pdf", "$dpfx.ps", "$dpfx.html");
 3194 }
 3195 
 3196 
 3197 # ($MOSTLYCLEAN, $TEXICLEAN, $MAINTCLEAN)
 3198 # handle_texinfo_helper ($info_texinfos)
 3199 # --------------------------------------
 3200 # Handle all Texinfo source; helper for 'handle_texinfo'.
 3201 sub handle_texinfo_helper
 3202 {
 3203   my ($info_texinfos) = @_;
 3204   my (@infobase, @info_deps_list, @texi_deps);
 3205   my %versions;
 3206   my $done = 0;
 3207   my (@mostly_cleans, @texi_cleans, @maint_cleans) = ('', '', '');
 3208 
 3209   # Build a regex matching user-cleaned files.
 3210   my $d = var 'DISTCLEANFILES';
 3211   my $c = var 'CLEANFILES';
 3212   my @f = ();
 3213   push @f, $d->value_as_list_recursive (inner_expand => 1) if $d;
 3214   push @f, $c->value_as_list_recursive (inner_expand => 1) if $c;
 3215   @f = map { s|[^A-Za-z_0-9*\[\]\-]|\\$&|g; s|\*|[^/]*|g; $_; } @f;
 3216   my $user_cleaned_files = '^(?:' . join ('|', @f) . ')$';
 3217 
 3218   foreach my $texi
 3219       ($info_texinfos->value_as_list_recursive (inner_expand => 1))
 3220     {
 3221       my $infobase = $texi;
 3222       if ($infobase =~ s/\.texi$//)
 3223         {
 3224           1; # Nothing more to do.
 3225         }
 3226       elsif ($infobase =~ s/\.(txi|texinfo)$//)
 3227         {
 3228 	  msg_var 'obsolete', $info_texinfos,
 3229 	          "suffix '.$1' for Texinfo files is discouraged;" .
 3230                   " use '.texi' instead";
 3231         }
 3232       else
 3233 	{
 3234 	  # FIXME: report line number.
 3235 	  err_am "texinfo file '$texi' has unrecognized extension";
 3236 	  next;
 3237 	}
 3238 
 3239       push @infobase, $infobase;
 3240 
 3241       # If 'version.texi' is referenced by input file, then include
 3242       # automatic versioning capability.
 3243       my ($out_file, $vtexi) =
 3244 	scan_texinfo_file ("$relative_dir/$texi")
 3245 	or next;
 3246       # Directory of auxiliary files and build by-products used by texi2dvi
 3247       # and texi2pdf.
 3248       push @mostly_cleans, "$infobase.t2d";
 3249       push @mostly_cleans, "$infobase.t2p";
 3250 
 3251       # If the Texinfo source is in a subdirectory, create the
 3252       # resulting info in this subdirectory.  If it is in the current
 3253       # directory, try hard to not prefix "./" because it breaks the
 3254       # generic rules.
 3255       my $outdir = dirname ($texi) . '/';
 3256       $outdir = "" if $outdir eq './';
 3257       $out_file =  $outdir . $out_file;
 3258 
 3259       # Until Automake 1.6.3, .info files were built in the
 3260       # source tree.  This was an obstacle to the support of
 3261       # non-distributed .info files, and non-distributed .texi
 3262       # files.
 3263       #
 3264       # * Non-distributed .texi files is important in some packages
 3265       #   where .texi files are built at make time, probably using
 3266       #   other binaries built in the package itself, maybe using
 3267       #   tools or information found on the build host.  Because
 3268       #   these files are not distributed they are always rebuilt
 3269       #   at make time; they should therefore not lie in the source
 3270       #   directory.  One plan was to support this using
 3271       #   nodist_info_TEXINFOS or something similar.  (Doing this
 3272       #   requires some sanity checks.  For instance Automake should
 3273       #   not allow:
 3274       #      dist_info_TEXINFOS = foo.texi
 3275       #      nodist_foo_TEXINFOS = included.texi
 3276       #   because a distributed file should never depend on a
 3277       #   non-distributed file.)
 3278       #
 3279       # * If .texi files are not distributed, then .info files should
 3280       #   not be distributed either.  There are also cases where one
 3281       #   wants to distribute .texi files, but does not want to
 3282       #   distribute the .info files.  For instance the Texinfo package
 3283       #   distributes the tool used to build these files; it would
 3284       #   be a waste of space to distribute them.  It's not clear
 3285       #   which syntax we should use to indicate that .info files should
 3286       #   not be distributed.  Akim Demaille suggested that eventually
 3287       #   we switch to a new syntax:
 3288       #   |  Maybe we should take some inspiration from what's already
 3289       #   |  done in the rest of Automake.  Maybe there is too much
 3290       #   |  syntactic sugar here, and you want
 3291       #   |     nodist_INFO = bar.info
 3292       #   |     dist_bar_info_SOURCES = bar.texi
 3293       #   |     bar_texi_DEPENDENCIES = foo.texi
 3294       #   |  with a bit of magic to have bar.info represent the whole
 3295       #   |  bar*info set.  That's a lot more verbose that the current
 3296       #   |  situation, but it is # not new, hence the user has less
 3297       #   |  to learn.
 3298       #	  |
 3299       #   |  But there is still too much room for meaningless specs:
 3300       #   |     nodist_INFO = bar.info
 3301       #   |     dist_bar_info_SOURCES = bar.texi
 3302       #   |     dist_PS = bar.ps something-written-by-hand.ps
 3303       #   |     nodist_bar_ps_SOURCES = bar.texi
 3304       #   |     bar_texi_DEPENDENCIES = foo.texi
 3305       #   |  here bar.texi is dist_ in line 2, and nodist_ in 4.
 3306       #
 3307       # Back to the point, it should be clear that in order to support
 3308       # non-distributed .info files, we need to build them in the
 3309       # build tree, not in the source tree (non-distributed .texi
 3310       # files are less of a problem, because we do not output build
 3311       # rules for them).  In Automake 1.7 .info build rules have been
 3312       # largely cleaned up so that .info files get always build in the
 3313       # build tree, even when distributed.  The idea was that
 3314       #   (1) if during a VPATH build the .info file was found to be
 3315       #       absent or out-of-date (in the source tree or in the
 3316       #       build tree), Make would rebuild it in the build tree.
 3317       #       If an up-to-date source-tree of the .info file existed,
 3318       #       make would not rebuild it in the build tree.
 3319       #   (2) having two copies of .info files, one in the source tree
 3320       #       and one (newer) in the build tree is not a problem
 3321       #       because 'make dist' always pick files in the build tree
 3322       #       first.
 3323       # However it turned out the be a bad idea for several reasons:
 3324       #   * Tru64, OpenBSD, and FreeBSD (not NetBSD) Make do not behave
 3325       #     like GNU Make on point (1) above.  These implementations
 3326       #     of Make would always rebuild .info files in the build
 3327       #     tree, even if such files were up to date in the source
 3328       #     tree.  Consequently, it was impossible to perform a VPATH
 3329       #     build of a package containing Texinfo files using these
 3330       #     Make implementations.
 3331       #     (Refer to the Autoconf Manual, section "Limitation of
 3332       #     Make", paragraph "VPATH", item "target lookup", for
 3333       #     an account of the differences between these
 3334       #     implementations.)
 3335       #   * The GNU Coding Standards require these files to be built
 3336       #     in the source-tree (when they are distributed, that is).
 3337       #   * Keeping a fresher copy of distributed files in the
 3338       #     build tree can be annoying during development because
 3339       #     - if the files is kept under CVS, you really want it
 3340       #       to be updated in the source tree
 3341       #     - it is confusing that 'make distclean' does not erase
 3342       #       all files in the build tree.
 3343       #
 3344       # Consequently, starting with Automake 1.8, .info files are
 3345       # built in the source tree again.  Because we still plan to
 3346       # support non-distributed .info files at some point, we
 3347       # have a single variable ($INSRC) that controls whether
 3348       # the current .info file must be built in the source tree
 3349       # or in the build tree.  Actually this variable is switched
 3350       # off in two cases:
 3351       #  (1) For '.info' files that appear to be cleaned; this is for
 3352       #      backward compatibility with package such as Texinfo,
 3353       #      which do things like
 3354       #        info_TEXINFOS = texinfo.txi info-stnd.texi info.texi
 3355       #        DISTCLEANFILES = texinfo texinfo-* info*.info*
 3356       #        # Do not create info files for distribution.
 3357       #        dist-info:
 3358       #      in order not to distribute .info files.
 3359       #  (2) When the undocumented option 'info-in-builddir' is given.
 3360       #      This is done to allow the developers of GCC, GDB, GNU
 3361       #      binutils and the GNU bfd library to force the '.info' files
 3362       #      to be generated in the builddir rather than the srcdir, as
 3363       #      was once done when the (now removed) 'cygnus' option was
 3364       #      given.  See automake bug#11034 for more discussion.
 3365       my $insrc = 1;
 3366       my $soutdir = '$(srcdir)/' . $outdir;
 3367 
 3368       if (option 'info-in-builddir')
 3369         {
 3370           $insrc = 0;
 3371         }
 3372       elsif ($out_file =~ $user_cleaned_files)
 3373         {
 3374           $insrc = 0;
 3375           msg 'obsolete', "$am_file.am", <<EOF;
 3376 Oops!
 3377     It appears this file (or files included by it) are triggering
 3378     an undocumented, soon-to-be-removed automake hack.
 3379     Future automake versions will no longer place in the builddir
 3380     (rather than in the srcdir) the generated '.info' files that
 3381     appear to be cleaned, by e.g. being listed in CLEANFILES or
 3382     DISTCLEANFILES.
 3383     If you want your '.info' files to be placed in the builddir
 3384     rather than in the srcdir, you have to use the shiny new
 3385     'info-in-builddir' automake option.
 3386 EOF
 3387         }
 3388 
 3389       $outdir = $soutdir if $insrc;
 3390 
 3391       # If user specified file_TEXINFOS, then use that as explicit
 3392       # dependency list.
 3393       @texi_deps = ();
 3394       push (@texi_deps, "${soutdir}${vtexi}") if $vtexi;
 3395 
 3396       my $canonical = canonicalize ($infobase);
 3397       if (var ($canonical . "_TEXINFOS"))
 3398 	{
 3399 	  push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
 3400 	  push_dist_common ('$(' . $canonical . '_TEXINFOS)');
 3401 	}
 3402 
 3403       my ($dirstamp, @cfiles) =
 3404 	output_texinfo_build_rules ($texi, $out_file, $insrc, @texi_deps);
 3405       push (@texi_cleans, @cfiles);
 3406 
 3407       push (@info_deps_list, $out_file);
 3408 
 3409       # If a vers*.texi file is needed, emit the rule.
 3410       if ($vtexi)
 3411 	{
 3412 	  err_am ("'$vtexi', included in '$texi', "
 3413 		  . "also included in '$versions{$vtexi}'")
 3414 	    if defined $versions{$vtexi};
 3415 	  $versions{$vtexi} = $texi;
 3416 
 3417 	  # We number the stamp-vti files.  This is doable since the
 3418 	  # actual names don't matter much.  We only number starting
 3419 	  # with the second one, so that the common case looks nice.
 3420 	  my $vti = ($done ? $done : 'vti');
 3421 	  ++$done;
 3422 
 3423 	  # This is ugly, but it is our historical practice.
 3424 	  if ($config_aux_dir_set_in_configure_ac)
 3425 	    {
 3426 	      require_conf_file_with_macro (TRUE, 'info_TEXINFOS', FOREIGN,
 3427 					    'mdate-sh');
 3428 	    }
 3429 	  else
 3430 	    {
 3431 	      require_file_with_macro (TRUE, 'info_TEXINFOS',
 3432 				       FOREIGN, 'mdate-sh');
 3433 	    }
 3434 
 3435 	  my $conf_dir;
 3436 	  if ($config_aux_dir_set_in_configure_ac)
 3437 	    {
 3438 	      $conf_dir = "$am_config_aux_dir/";
 3439 	    }
 3440 	  else
 3441 	    {
 3442 	      $conf_dir = '$(srcdir)/';
 3443 	    }
 3444 	  $output_rules .= file_contents ('texi-vers',
 3445 					  new Automake::Location,
 3446 					  TEXI     => $texi,
 3447 					  VTI      => $vti,
 3448 					  STAMPVTI => "${soutdir}stamp-$vti",
 3449 					  VTEXI    => "$soutdir$vtexi",
 3450 					  MDDIR    => $conf_dir,
 3451 					  DIRSTAMP => $dirstamp);
 3452 	}
 3453     }
 3454 
 3455   # Handle location of texinfo.tex.
 3456   my $need_texi_file = 0;
 3457   my $texinfodir;
 3458   if (var ('TEXINFO_TEX'))
 3459     {
 3460       # The user defined TEXINFO_TEX so assume he knows what he is
 3461       # doing.
 3462       $texinfodir = ('$(srcdir)/'
 3463 		     . dirname (variable_value ('TEXINFO_TEX')));
 3464     }
 3465   elsif ($config_aux_dir_set_in_configure_ac)
 3466     {
 3467       $texinfodir = $am_config_aux_dir;
 3468       define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex", INTERNAL);
 3469       $need_texi_file = 2; # so that we require_conf_file later
 3470     }
 3471   else
 3472     {
 3473       $texinfodir = '$(srcdir)';
 3474       $need_texi_file = 1;
 3475     }
 3476   define_variable ('am__TEXINFO_TEX_DIR', $texinfodir, INTERNAL);
 3477 
 3478   push (@dist_targets, 'dist-info');
 3479 
 3480   if (! option 'no-installinfo')
 3481     {
 3482       # Make sure documentation is made and installed first.  Use
 3483       # $(INFO_DEPS), not 'info', because otherwise recursive makes
 3484       # get run twice during "make all".
 3485       unshift (@all, '$(INFO_DEPS)');
 3486     }
 3487 
 3488   define_files_variable ("DVIS", @infobase, 'dvi', INTERNAL);
 3489   define_files_variable ("PDFS", @infobase, 'pdf', INTERNAL);
 3490   define_files_variable ("PSS", @infobase, 'ps', INTERNAL);
 3491   define_files_variable ("HTMLS", @infobase, 'html', INTERNAL);
 3492 
 3493   # This next isn't strictly needed now -- the places that look here
 3494   # could easily be changed to look in info_TEXINFOS.  But this is
 3495   # probably better, in case noinst_TEXINFOS is ever supported.
 3496   define_variable ("TEXINFOS", variable_value ('info_TEXINFOS'), INTERNAL);
 3497 
 3498   # Do some error checking.  Note that this file is not required
 3499   # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
 3500   # up above.
 3501   if ($need_texi_file && ! option 'no-texinfo.tex')
 3502     {
 3503       if ($need_texi_file > 1)
 3504 	{
 3505 	  require_conf_file_with_macro (TRUE, 'info_TEXINFOS', FOREIGN,
 3506 					'texinfo.tex');
 3507 	}
 3508       else
 3509 	{
 3510 	  require_file_with_macro (TRUE, 'info_TEXINFOS', FOREIGN,
 3511 				   'texinfo.tex');
 3512 	}
 3513     }
 3514 
 3515   return (makefile_wrap ("", "\t  ", @mostly_cleans),
 3516 	  makefile_wrap ("", "\t  ", @texi_cleans),
 3517 	  makefile_wrap ("", "\t  ", @maint_cleans));
 3518 }
 3519 
 3520 
 3521 sub handle_texinfo ()
 3522 {
 3523   reject_var 'TEXINFOS', "'TEXINFOS' is an anachronism; use 'info_TEXINFOS'";
 3524   # FIXME: I think this is an obsolete future feature name.
 3525   reject_var 'html_TEXINFOS', "HTML generation not yet supported";
 3526 
 3527   my $info_texinfos = var ('info_TEXINFOS');
 3528   my ($mostlyclean, $clean, $maintclean) = ('', '', '');
 3529   if ($info_texinfos)
 3530     {
 3531       define_verbose_texinfo;
 3532       ($mostlyclean, $clean, $maintclean) = handle_texinfo_helper ($info_texinfos);
 3533       chomp $mostlyclean;
 3534       chomp $clean;
 3535       chomp $maintclean;
 3536     }
 3537 
 3538   $output_rules .=  file_contents ('texinfos',
 3539 				   new Automake::Location,
 3540                                    AM_V_DVIPS    => verbose_flag('DVIPS'),
 3541 				   MOSTLYCLEAN   => $mostlyclean,
 3542 				   TEXICLEAN     => $clean,
 3543 				   MAINTCLEAN    => $maintclean,
 3544 				   'LOCAL-TEXIS' => !!$info_texinfos,
 3545                                    TEXIQUIET     => verbose_flag('texinfo'));
 3546 }
 3547 
 3548 
 3549 sub handle_man_pages ()
 3550 {
 3551   reject_var 'MANS', "'MANS' is an anachronism; use 'man_MANS'";
 3552 
 3553   # Find all the sections in use.  We do this by first looking for
 3554   # "standard" sections, and then looking for any additional
 3555   # sections used in man_MANS.
 3556   my (%sections, %notrans_sections, %trans_sections,
 3557       %notrans_vars, %trans_vars, %notrans_sect_vars, %trans_sect_vars);
 3558   # We handle nodist_ for uniformity.  man pages aren't distributed
 3559   # by default so it isn't actually very important.
 3560   foreach my $npfx ('', 'notrans_')
 3561     {
 3562       foreach my $pfx ('', 'dist_', 'nodist_')
 3563 	{
 3564 	  # Add more sections as needed.
 3565 	  foreach my $section ('0'..'9', 'n', 'l')
 3566 	    {
 3567 	      my $varname = $npfx . $pfx . 'man' . $section . '_MANS';
 3568 	      if (var ($varname))
 3569 		{
 3570 		  $sections{$section} = 1;
 3571 		  $varname = '$(' . $varname . ')';
 3572 		  if ($npfx eq 'notrans_')
 3573 		    {
 3574 		      $notrans_sections{$section} = 1;
 3575 		      $notrans_sect_vars{$varname} = 1;
 3576 		    }
 3577 		  else
 3578 		    {
 3579 		      $trans_sections{$section} = 1;
 3580 		      $trans_sect_vars{$varname} = 1;
 3581 		    }
 3582 
 3583 		  push_dist_common ($varname)
 3584 		    if $pfx eq 'dist_';
 3585 		}
 3586 	    }
 3587 
 3588 	  my $varname = $npfx . $pfx . 'man_MANS';
 3589 	  my $var = var ($varname);
 3590 	  if ($var)
 3591 	    {
 3592 	      foreach ($var->value_as_list_recursive)
 3593 		{
 3594 		  # A page like 'foo.1c' goes into man1dir.
 3595 		  if (/\.([0-9a-z])([a-z]*)$/)
 3596 		    {
 3597 		      $sections{$1} = 1;
 3598 		      if ($npfx eq 'notrans_')
 3599 			{
 3600 			  $notrans_sections{$1} = 1;
 3601 			}
 3602 		      else
 3603 			{
 3604 			  $trans_sections{$1} = 1;
 3605 			}
 3606 		    }
 3607 		}
 3608 
 3609 	      $varname = '$(' . $varname . ')';
 3610 	      if ($npfx eq 'notrans_')
 3611 		{
 3612 		  $notrans_vars{$varname} = 1;
 3613 		}
 3614 	      else
 3615 		{
 3616 		  $trans_vars{$varname} = 1;
 3617 		}
 3618 	      push_dist_common ($varname)
 3619 		if $pfx eq 'dist_';
 3620 	    }
 3621 	}
 3622     }
 3623 
 3624   return unless %sections;
 3625 
 3626   my @unsorted_deps;
 3627 
 3628   # Build section independent variables.
 3629   my $have_notrans = %notrans_vars;
 3630   my @notrans_list = sort keys %notrans_vars;
 3631   my $have_trans = %trans_vars;
 3632   my @trans_list = sort keys %trans_vars;
 3633 
 3634   # Now for each section, generate an install and uninstall rule.
 3635   # Sort sections so output is deterministic.
 3636   foreach my $section (sort keys %sections)
 3637     {
 3638       # Build section dependent variables.
 3639       my $notrans_mans = $have_notrans || exists $notrans_sections{$section};
 3640       my $trans_mans = $have_trans || exists $trans_sections{$section};
 3641       my (%notrans_this_sect, %trans_this_sect);
 3642       my $expr = 'man' . $section . '_MANS';
 3643       foreach my $varname (keys %notrans_sect_vars)
 3644 	{
 3645 	  if ($varname =~ /$expr/)
 3646 	    {
 3647 	      $notrans_this_sect{$varname} = 1;
 3648 	    }
 3649 	}
 3650       foreach my $varname (keys %trans_sect_vars)
 3651 	{
 3652 	  if ($varname =~ /$expr/)
 3653 	    {
 3654 	      $trans_this_sect{$varname} = 1;
 3655 	    }
 3656 	}
 3657       my @notrans_sect_list = sort keys %notrans_this_sect;
 3658       my @trans_sect_list = sort keys %trans_this_sect;
 3659       @unsorted_deps = (keys %notrans_vars, keys %trans_vars,
 3660                         keys %notrans_this_sect, keys %trans_this_sect);
 3661       my @deps = sort @unsorted_deps;
 3662       $output_rules .= file_contents ('mans',
 3663                                       new Automake::Location,
 3664                                       SECTION           => $section,
 3665                                       DEPS              => "@deps",
 3666                                       NOTRANS_MANS      => $notrans_mans,
 3667                                       NOTRANS_SECT_LIST => "@notrans_sect_list",
 3668                                       HAVE_NOTRANS      => $have_notrans,
 3669                                       NOTRANS_LIST      => "@notrans_list",
 3670                                       TRANS_MANS        => $trans_mans,
 3671                                       TRANS_SECT_LIST   => "@trans_sect_list",
 3672                                       HAVE_TRANS        => $have_trans,
 3673                                       TRANS_LIST        => "@trans_list");
 3674     }
 3675 
 3676   @unsorted_deps  = (keys %notrans_vars, keys %trans_vars,
 3677                      keys %notrans_sect_vars, keys %trans_sect_vars);
 3678   my @mans = sort @unsorted_deps;
 3679   $output_vars .= file_contents ('mans-vars',
 3680 				 new Automake::Location,
 3681 				 MANS => "@mans");
 3682 
 3683   push (@all, '$(MANS)')
 3684     unless option 'no-installman';
 3685 }
 3686 
 3687 
 3688 sub handle_data ()
 3689 {
 3690     am_install_var ('-noextra', '-candist', 'data', 'DATA',
 3691                     'data', 'dataroot', 'doc', 'dvi', 'html', 'pdf',
 3692                     'ps', 'sysconf', 'sharedstate', 'localstate',
 3693                     'pkgdata', 'lisp', 'noinst', 'check');
 3694 }
 3695 
 3696 
 3697 sub handle_tags ()
 3698 {
 3699     my @config;
 3700     foreach my $spec (@config_headers)
 3701       {
 3702         my ($out, @ins) = split_config_file_spec ($spec);
 3703 	foreach my $in (@ins)
 3704 	  {
 3705             # If the config header source is in this directory,
 3706 	    # require it.
 3707 	    push @config, basename ($in)
 3708               if $relative_dir eq dirname ($in);
 3709 	   }
 3710       }
 3711 
 3712     define_variable ('am__tagged_files',
 3713                      '$(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)'
 3714                      . " @config", INTERNAL);
 3715 
 3716     if (rvar('am__tagged_files')->value_as_list_recursive
 3717           || var ('ETAGS_ARGS') || var ('SUBDIRS'))
 3718       {
 3719 	$output_rules .= file_contents ('tags', new Automake::Location);
 3720 	set_seen 'TAGS_DEPENDENCIES';
 3721       }
 3722     else
 3723       {
 3724         reject_var ('TAGS_DEPENDENCIES',
 3725 		    "it doesn't make sense to define 'TAGS_DEPENDENCIES'"
 3726 		    . " without\nsources or 'ETAGS_ARGS'");
 3727 	# Every Makefile must define some sort of TAGS rule.
 3728 	# Otherwise, it would be possible for a top-level "make TAGS"
 3729 	# to fail because some subdirectory failed.  Ditto ctags and
 3730         # cscope.
 3731         $output_rules .=
 3732           "tags TAGS:\n\n" .
 3733           "ctags CTAGS:\n\n" .
 3734           "cscope cscopelist:\n\n";
 3735       }
 3736 }
 3737 
 3738 
 3739 # user_phony_rule ($NAME)
 3740 # -----------------------
 3741 # Return false if rule $NAME does not exist.  Otherwise,
 3742 # declare it as phony, complete its definition (in case it is
 3743 # conditional), and return its Automake::Rule instance.
 3744 sub user_phony_rule
 3745 {
 3746   my ($name) = @_;
 3747   my $rule = rule $name;
 3748   if ($rule)
 3749     {
 3750       depend ('.PHONY', $name);
 3751       # Define $NAME in all condition where it is not already defined,
 3752       # so that it is always OK to depend on $NAME.
 3753       for my $c ($rule->not_always_defined_in_cond (TRUE)->conds)
 3754 	{
 3755 	  Automake::Rule::define ($name, 'internal', RULE_AUTOMAKE,
 3756 				  $c, INTERNAL);
 3757 	  $output_rules .= $c->subst_string . "$name:\n";
 3758 	}
 3759     }
 3760   return $rule;
 3761 }
 3762 
 3763 
 3764 # Handle 'dist' target.
 3765 sub handle_dist ()
 3766 {
 3767   # Substitutions for distdir.am
 3768   my %transform;
 3769 
 3770   # Define DIST_SUBDIRS.  This must always be done, regardless of the
 3771   # no-dist setting: target like 'distclean' or 'maintainer-clean' use it.
 3772   my $subdirs = var ('SUBDIRS');
 3773   if ($subdirs)
 3774     {
 3775       # If SUBDIRS is conditionally defined, then set DIST_SUBDIRS
 3776       # to all possible directories, and use it.  If DIST_SUBDIRS is
 3777       # defined, just use it.
 3778 
 3779       # Note that we check DIST_SUBDIRS first on purpose, so that
 3780       # we don't call has_conditional_contents for now reason.
 3781       # (In the past one project used so many conditional subdirectories
 3782       # that calling has_conditional_contents on SUBDIRS caused
 3783       # automake to grow to 150Mb -- this should not happen with
 3784       # the current implementation of has_conditional_contents,
 3785       # but it's more efficient to avoid the call anyway.)
 3786       if (var ('DIST_SUBDIRS'))
 3787 	{
 3788 	}
 3789       elsif ($subdirs->has_conditional_contents)
 3790 	{
 3791 	  define_pretty_variable
 3792 	    ('DIST_SUBDIRS', TRUE, INTERNAL,
 3793 	     uniq ($subdirs->value_as_list_recursive));
 3794 	}
 3795       else
 3796 	{
 3797 	  # We always define this because that is what 'distclean'
 3798 	  # wants.
 3799 	  define_pretty_variable ('DIST_SUBDIRS', TRUE, INTERNAL,
 3800 				  '$(SUBDIRS)');
 3801 	}
 3802     }
 3803 
 3804   # The remaining definitions are only required when a dist target is used.
 3805   return if option 'no-dist';
 3806 
 3807   # At least one of the archive formats must be enabled.
 3808   if ($relative_dir eq '.')
 3809     {
 3810       my $archive_defined = option 'no-dist-gzip' ? 0 : 1;
 3811       $archive_defined ||=
 3812 	grep { option "dist-$_" } qw(shar zip tarZ bzip2 lzip xz zstd);
 3813       error (option 'no-dist-gzip',
 3814 	     "no-dist-gzip specified but no dist-* specified,\n"
 3815 	     . "at least one archive format must be enabled")
 3816 	unless $archive_defined;
 3817     }
 3818 
 3819   # Look for common files that should be included in distribution.
 3820   # If the aux dir is set, and it does not have a Makefile.am, then
 3821   # we check for these files there as well.
 3822   my $check_aux = 0;
 3823   if ($relative_dir eq '.'
 3824       && $config_aux_dir_set_in_configure_ac)
 3825     {
 3826       if (! is_make_dir ($config_aux_dir))
 3827 	{
 3828 	  $check_aux = 1;
 3829 	}
 3830     }
 3831   foreach my $cfile (@common_files)
 3832     {
 3833       if (dir_has_case_matching_file ($relative_dir, $cfile)
 3834 	  # The file might be absent, but if it can be built it's ok.
 3835 	  || rule $cfile)
 3836 	{
 3837 	  push_dist_common ($cfile);
 3838 	}
 3839 
 3840       # Don't use 'elsif' here because a file might meaningfully
 3841       # appear in both directories.
 3842       if ($check_aux && dir_has_case_matching_file ($config_aux_dir, $cfile))
 3843 	{
 3844 	  push_dist_common ("$config_aux_dir/$cfile")
 3845 	}
 3846     }
 3847 
 3848   # We might copy elements from @configure_dist_common to
 3849   # @dist_common if we think we need to.  If the file appears in our
 3850   # directory, we would have discovered it already, so we don't
 3851   # check that.  But if the file is in a subdir without a Makefile,
 3852   # we want to distribute it here if we are doing '.'.  Ugly!
 3853   # Also, in some corner cases, it's possible that the following code
 3854   # will cause the same file to appear in the $(DIST_COMMON) variables
 3855   # of two distinct Makefiles; but this is not a problem, since the
 3856   # 'distdir' target in 'lib/am/distdir.am' can deal with the same
 3857   # file being distributed multiple times.
 3858   # See also automake bug#9651.
 3859   if ($relative_dir eq '.')
 3860     {
 3861       foreach my $file (@configure_dist_common)
 3862 	{
 3863 	  my $dir = dirname ($file);
 3864 	  push_dist_common ($file)
 3865 	    if ($dir eq '.' || ! is_make_dir ($dir));
 3866 	}
 3867       @configure_dist_common = ();
 3868     }
 3869 
 3870   # $(am__DIST_COMMON): files to be distributed automatically.  Will be
 3871   # appended to $(DIST_COMMON) in the generated Makefile.
 3872   # Use 'sort' so that the expansion of $(DIST_COMMON) in the generated
 3873   # Makefile is deterministic, in face of m4 and/or perl randomizations
 3874   # (see automake bug#17908).
 3875   define_pretty_variable ('am__DIST_COMMON', TRUE, INTERNAL,
 3876                           uniq (sort @dist_common));
 3877 
 3878   # Now that we've processed @dist_common, disallow further attempts
 3879   # to modify it.
 3880   $handle_dist_run = 1;
 3881 
 3882   $transform{'DISTCHECK-HOOK'} = !! rule 'distcheck-hook';
 3883   $transform{'GETTEXT'} = $seen_gettext && !$seen_gettext_external;
 3884 
 3885   # If the target 'dist-hook' exists, make sure it is run.  This
 3886   # allows users to do random weird things to the distribution
 3887   # before it is packaged up.
 3888   push (@dist_targets, 'dist-hook')
 3889     if user_phony_rule 'dist-hook';
 3890   $transform{'DIST-TARGETS'} = join (' ', @dist_targets);
 3891 
 3892   my $flm = option ('filename-length-max');
 3893   my $filename_filter = $flm ? '.' x $flm->[1] : '';
 3894 
 3895   $output_rules .= file_contents ('distdir',
 3896 				  new Automake::Location,
 3897 				  %transform,
 3898 				  FILENAME_FILTER => $filename_filter);
 3899 }
 3900 
 3901 
 3902 # check_directory ($NAME, $WHERE [, $RELATIVE_DIR = "."])
 3903 # -------------------------------------------------------
 3904 # Ensure $NAME is a directory (in $RELATIVE_DIR), and that it uses a sane
 3905 # name.  Use $WHERE as a location in the diagnostic, if any.
 3906 sub check_directory
 3907 {
 3908   my ($dir, $where, $reldir) = @_;
 3909   $reldir = '.' unless defined $reldir;
 3910 
 3911   error $where, "required directory $reldir/$dir does not exist"
 3912     unless -d "$reldir/$dir";
 3913 
 3914   # If an 'obj/' directory exists, BSD make will enter it before
 3915   # reading 'Makefile'.  Hence the 'Makefile' in the current directory
 3916   # will not be read.
 3917   #
 3918   #  % cat Makefile
 3919   #  all:
 3920   #          echo Hello
 3921   #  % cat obj/Makefile
 3922   #  all:
 3923   #          echo World
 3924   #  % make      # GNU make
 3925   #  echo Hello
 3926   #  Hello
 3927   #  % pmake     # BSD make
 3928   #  echo World
 3929   #  World
 3930   msg ('portability', $where,
 3931        "naming a subdirectory 'obj' causes troubles with BSD make")
 3932     if $dir eq 'obj';
 3933 
 3934   # 'aux' is probably the most important of the following forbidden name,
 3935   # since it's tempting to use it as an AC_CONFIG_AUX_DIR.
 3936   msg ('portability', $where,
 3937        "name '$dir' is reserved on W32 and DOS platforms")
 3938     if grep (/^\Q$dir\E$/i, qw/aux lpt1 lpt2 lpt3 com1 com2 com3 com4 con prn/);
 3939 }
 3940 
 3941 # check_directories_in_var ($VARIABLE)
 3942 # ------------------------------------
 3943 # Recursively check all items in variables $VARIABLE as directories
 3944 sub check_directories_in_var
 3945 {
 3946   my ($var) = @_;
 3947   $var->traverse_recursively
 3948     (sub
 3949      {
 3950        my ($var, $val, $cond, $full_cond) = @_;
 3951        check_directory ($val, $var->rdef ($cond)->location, $relative_dir);
 3952        return ();
 3953      },
 3954      undef,
 3955      skip_ac_subst => 1);
 3956 }
 3957 
 3958 
 3959 sub handle_subdirs ()
 3960 {
 3961   my $subdirs = var ('SUBDIRS');
 3962   return
 3963     unless $subdirs;
 3964 
 3965   check_directories_in_var $subdirs;
 3966 
 3967   my $dsubdirs = var ('DIST_SUBDIRS');
 3968   check_directories_in_var $dsubdirs
 3969     if $dsubdirs;
 3970 
 3971   $output_rules .= file_contents ('subdirs', new Automake::Location);
 3972   rvar ('RECURSIVE_TARGETS')->rdef (TRUE)->{'pretty'} = VAR_SORTED; # Gross!
 3973 }
 3974 
 3975 
 3976 # ($REGEN, @DEPENDENCIES)
 3977 # scan_aclocal_m4
 3978 # ---------------
 3979 # If aclocal.m4 creation is automated, return the list of its dependencies.
 3980 sub scan_aclocal_m4 ()
 3981 {
 3982   my $regen_aclocal = 0;
 3983 
 3984   set_seen 'CONFIG_STATUS_DEPENDENCIES';
 3985   set_seen 'CONFIGURE_DEPENDENCIES';
 3986 
 3987   if (-f 'aclocal.m4')
 3988     {
 3989       define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4', INTERNAL);
 3990 
 3991       my $aclocal = new Automake::XFile "< aclocal.m4";
 3992       my $line = $aclocal->getline;
 3993       $regen_aclocal = $line =~ 'generated automatically by aclocal';
 3994     }
 3995 
 3996   my @ac_deps = ();
 3997 
 3998   if (set_seen ('ACLOCAL_M4_SOURCES'))
 3999     {
 4000       push (@ac_deps, '$(ACLOCAL_M4_SOURCES)');
 4001       msg_var ('obsolete', 'ACLOCAL_M4_SOURCES',
 4002 	       "'ACLOCAL_M4_SOURCES' is obsolete.\n"
 4003 	       . "It should be safe to simply remove it");
 4004     }
 4005 
 4006   # Note that it might be possible that aclocal.m4 doesn't exist but
 4007   # should be auto-generated.  This case probably isn't very
 4008   # important.
 4009 
 4010   return ($regen_aclocal, @ac_deps);
 4011 }
 4012 
 4013 
 4014 # Helper function for 'substitute_ac_subst_variables'.
 4015 sub substitute_ac_subst_variables_worker
 4016 {
 4017   my ($token) = @_;
 4018   return "\@$token\@" if var $token;
 4019   return "\${$token\}";
 4020 }
 4021 
 4022 # substitute_ac_subst_variables ($TEXT)
 4023 # -------------------------------------
 4024 # Replace any occurrence of ${FOO} in $TEXT by @FOO@ if FOO is an AC_SUBST
 4025 # variable.
 4026 sub substitute_ac_subst_variables
 4027 {
 4028   my ($text) = @_;
 4029   $text =~ s/\$[{]([^ \t=:+{}]+)}/substitute_ac_subst_variables_worker ($1)/ge;
 4030   return $text;
 4031 }
 4032 
 4033 # @DEPENDENCIES
 4034 # prepend_srcdir (@INPUTS)
 4035 # ------------------------
 4036 # Prepend $(srcdir) or $(top_srcdir) to all @INPUTS.  The idea is that
 4037 # if an input file has a directory part the same as the current
 4038 # directory, then the directory part is simply replaced by $(srcdir).
 4039 # But if the directory part is different, then $(top_srcdir) is
 4040 # prepended.
 4041 sub prepend_srcdir
 4042 {
 4043   my (@inputs) = @_;
 4044   my @newinputs;
 4045 
 4046   foreach my $single (@inputs)
 4047     {
 4048       if (dirname ($single) eq $relative_dir)
 4049 	{
 4050 	  push (@newinputs, '$(srcdir)/' . basename ($single));
 4051 	}
 4052       else
 4053 	{
 4054 	  push (@newinputs, '$(top_srcdir)/' . $single);
 4055 	}
 4056     }
 4057   return @newinputs;
 4058 }
 4059 
 4060 # @DEPENDENCIES
 4061 # rewrite_inputs_into_dependencies ($OUTPUT, @INPUTS)
 4062 # ---------------------------------------------------
 4063 # Compute a list of dependencies appropriate for the rebuild
 4064 # rule of
 4065 #   AC_CONFIG_FILES($OUTPUT:$INPUT[0]:$INPUTS[1]:...)
 4066 # Also distribute $INPUTs which are not built by another AC_CONFIG_FOOs.
 4067 sub rewrite_inputs_into_dependencies
 4068 {
 4069   my ($file, @inputs) = @_;
 4070   my @res = ();
 4071 
 4072   for my $i (@inputs)
 4073     {
 4074       # We cannot create dependencies on shell variables.
 4075       next if (substitute_ac_subst_variables $i) =~ /\$/;
 4076 
 4077       if (exists $ac_config_files_location{$i} && $i ne $file)
 4078 	{
 4079 	  my $di = dirname $i;
 4080 	  if ($di eq $relative_dir)
 4081 	    {
 4082 	      $i = basename $i;
 4083 	    }
 4084 	  # In the top-level Makefile we do not use $(top_builddir), because
 4085 	  # we are already there, and since the targets are built without
 4086 	  # a $(top_builddir), it helps BSD Make to match them with
 4087 	  # dependencies.
 4088 	  elsif ($relative_dir ne '.')
 4089 	    {
 4090 	      $i = '$(top_builddir)/' . $i;
 4091 	    }
 4092 	}
 4093       else
 4094 	{
 4095 	  msg ('error', $ac_config_files_location{$file},
 4096 	       "required file '$i' not found")
 4097 	    unless $i =~ /\$/ || exists $output_files{$i} || -f $i;
 4098 	  ($i) = prepend_srcdir ($i);
 4099 	  push_dist_common ($i);
 4100 	}
 4101       push @res, $i;
 4102     }
 4103   return @res;
 4104 }
 4105 
 4106 
 4107 
 4108 # handle_configure ($MAKEFILE_AM, $MAKEFILE_IN, $MAKEFILE, @INPUTS)
 4109 # -----------------------------------------------------------------
 4110 # Handle remaking and configure stuff.
 4111 # We need the name of the input file, to do proper remaking rules.
 4112 sub handle_configure
 4113 {
 4114   my ($makefile_am, $makefile_in, $makefile, @inputs) = @_;
 4115 
 4116   prog_error 'empty @inputs'
 4117     unless @inputs;
 4118 
 4119   my ($rel_makefile_am, $rel_makefile_in) = prepend_srcdir ($makefile_am,
 4120 							    $makefile_in);
 4121   my $rel_makefile = basename $makefile;
 4122 
 4123   my $colon_infile = ':' . join (':', @inputs);
 4124   $colon_infile = '' if $colon_infile eq ":$makefile.in";
 4125   my @rewritten = rewrite_inputs_into_dependencies ($makefile, @inputs);
 4126   my ($regen_aclocal_m4, @aclocal_m4_deps) = scan_aclocal_m4;
 4127   define_pretty_variable ('am__aclocal_m4_deps', TRUE, INTERNAL,
 4128 			  @configure_deps, @aclocal_m4_deps,
 4129 			  '$(top_srcdir)/' . $configure_ac);
 4130   my @configuredeps = ('$(am__aclocal_m4_deps)', '$(CONFIGURE_DEPENDENCIES)');
 4131   push @configuredeps, '$(ACLOCAL_M4)' if -f 'aclocal.m4';
 4132   define_pretty_variable ('am__configure_deps', TRUE, INTERNAL,
 4133 			  @configuredeps);
 4134 
 4135   my $automake_options = '--' . $strictness_name .
 4136 			 (global_option 'no-dependencies' ? ' --ignore-deps' : '');
 4137 
 4138   $output_rules .= file_contents
 4139     ('configure',
 4140      new Automake::Location,
 4141      MAKEFILE              => $rel_makefile,
 4142      'MAKEFILE-DEPS'       => "@rewritten",
 4143      'CONFIG-MAKEFILE'     => ($relative_dir eq '.') ? '$@' : '$(subdir)/$@',
 4144      'MAKEFILE-IN'         => $rel_makefile_in,
 4145      'HAVE-MAKEFILE-IN-DEPS' => (@include_stack > 0),
 4146      'MAKEFILE-IN-DEPS'    => "@include_stack",
 4147      'MAKEFILE-AM'         => $rel_makefile_am,
 4148      'AUTOMAKE-OPTIONS'    => $automake_options,
 4149      'MAKEFILE-AM-SOURCES' => "$makefile$colon_infile",
 4150      'REGEN-ACLOCAL-M4'    => $regen_aclocal_m4,
 4151      VERBOSE               => verbose_flag ('GEN'));
 4152 
 4153   if ($relative_dir eq '.')
 4154     {
 4155       push_dist_common ('acconfig.h')
 4156 	if -f 'acconfig.h';
 4157     }
 4158 
 4159   # If we have a configure header, require it.
 4160   my $hdr_index = 0;
 4161   my @distclean_config;
 4162   foreach my $spec (@config_headers)
 4163     {
 4164       $hdr_index += 1;
 4165       # $CONFIG_H_PATH: config.h from top level.
 4166       my ($config_h_path, @ins) = split_config_file_spec ($spec);
 4167       my $config_h_dir = dirname ($config_h_path);
 4168 
 4169       # If the header is in the current directory we want to build
 4170       # the header here.  Otherwise, if we're at the topmost
 4171       # directory and the header's directory doesn't have a
 4172       # Makefile, then we also want to build the header.
 4173       if ($relative_dir eq $config_h_dir
 4174 	  || ($relative_dir eq '.' && ! is_make_dir ($config_h_dir)))
 4175 	{
 4176 	  my ($cn_sans_dir, $stamp_dir);
 4177 	  if ($relative_dir eq $config_h_dir)
 4178 	    {
 4179 	      $cn_sans_dir = basename ($config_h_path);
 4180 	      $stamp_dir = '';
 4181 	    }
 4182 	  else
 4183 	    {
 4184 	      $cn_sans_dir = $config_h_path;
 4185 	      if ($config_h_dir eq '.')
 4186 		{
 4187 		  $stamp_dir = '';
 4188 		}
 4189 	      else
 4190 		{
 4191 		  $stamp_dir = $config_h_dir . '/';
 4192 		}
 4193 	    }
 4194 
 4195 	  # This will also distribute all inputs.
 4196 	  @ins = rewrite_inputs_into_dependencies ($config_h_path, @ins);
 4197 
 4198 	  # Cannot define rebuild rules for filenames with shell variables.
 4199 	  next if (substitute_ac_subst_variables $config_h_path) =~ /\$/;
 4200 
 4201 	  # Header defined in this directory.
 4202 	  my @files;
 4203 	  if (-f $config_h_path . '.top')
 4204 	    {
 4205 	      push (@files, "$cn_sans_dir.top");
 4206 	    }
 4207 	  if (-f $config_h_path . '.bot')
 4208 	    {
 4209 	      push (@files, "$cn_sans_dir.bot");
 4210 	    }
 4211 
 4212 	  push_dist_common (@files);
 4213 
 4214 	  # For now, acconfig.h can only appear in the top srcdir.
 4215 	  if (-f 'acconfig.h')
 4216 	    {
 4217 	      push (@files, '$(top_srcdir)/acconfig.h');
 4218 	    }
 4219 
 4220 	  my $stamp = "${stamp_dir}stamp-h${hdr_index}";
 4221 	  $output_rules .=
 4222 	    file_contents ('remake-hdr',
 4223 			   new Automake::Location,
 4224 			   FILES            => "@files",
 4225 			   'FIRST-HDR'      => ($hdr_index == 1),
 4226 			   CONFIG_H         => $cn_sans_dir,
 4227 			   CONFIG_HIN       => $ins[0],
 4228 			   CONFIG_H_DEPS    => "@ins",
 4229 			   CONFIG_H_PATH    => $config_h_path,
 4230 			   STAMP            => "$stamp");
 4231 
 4232 	  push @distclean_config, $cn_sans_dir, $stamp;
 4233 	}
 4234     }
 4235 
 4236   $output_rules .= file_contents ('clean-hdr',
 4237 				  new Automake::Location,
 4238 				  FILES => "@distclean_config")
 4239     if @distclean_config;
 4240 
 4241   # Distribute and define mkinstalldirs only if it is already present
 4242   # in the package, for backward compatibility (some people may still
 4243   # use $(mkinstalldirs)).
 4244   # TODO: start warning about this in Automake 1.14, and have
 4245   # TODO: Automake 2.0 drop it (and the mkinstalldirs script
 4246   # TODO: as well).
 4247   my $mkidpath = "$config_aux_dir/mkinstalldirs";
 4248   if (-f $mkidpath)
 4249     {
 4250       # Use require_file so that any existing script gets updated
 4251       # by --force-missing.
 4252       require_conf_file ($mkidpath, FOREIGN, 'mkinstalldirs');
 4253       define_variable ('mkinstalldirs',
 4254 		       "\$(SHELL) $am_config_aux_dir/mkinstalldirs", INTERNAL);
 4255     }
 4256   else
 4257     {
 4258       # Use $(install_sh), not $(MKDIR_P) because the latter requires
 4259       # at least one argument, and $(mkinstalldirs) used to work
 4260       # even without arguments (e.g. $(mkinstalldirs) $(conditional_dir)).
 4261       # Also, $(MKDIR_P) uses the umask for any intermediate directories
 4262       # created, whereas we want them to be created with umask 022
 4263       # so that they are mode 755.
 4264       define_variable ('mkinstalldirs', '$(install_sh) -d', INTERNAL);
 4265     }
 4266 
 4267   reject_var ('CONFIG_HEADER',
 4268 	      "'CONFIG_HEADER' is an anachronism; now determined "
 4269 	      . "automatically\nfrom '$configure_ac'");
 4270 
 4271   my @config_h;
 4272   foreach my $spec (@config_headers)
 4273     {
 4274       my ($out, @ins) = split_config_file_spec ($spec);
 4275       # Generate CONFIG_HEADER define.
 4276       if ($relative_dir eq dirname ($out))
 4277 	{
 4278 	  push @config_h, basename ($out);
 4279 	}
 4280       else
 4281 	{
 4282 	  push @config_h, "\$(top_builddir)/$out";
 4283 	}
 4284     }
 4285   define_variable ("CONFIG_HEADER", "@config_h", INTERNAL)
 4286     if @config_h;
 4287 
 4288   # Now look for other files in this directory which must be remade
 4289   # by config.status, and generate rules for them.
 4290   my @actual_other_files = ();
 4291   # These get cleaned only in a VPATH build.
 4292   my @actual_other_vpath_files = ();
 4293   foreach my $lfile (@other_input_files)
 4294     {
 4295       my $file;
 4296       my @inputs;
 4297       if ($lfile =~ /^([^:]*):(.*)$/)
 4298 	{
 4299 	  # This is the ":" syntax of AC_OUTPUT.
 4300 	  $file = $1;
 4301 	  @inputs = split (':', $2);
 4302 	}
 4303       else
 4304 	{
 4305 	  # Normal usage.
 4306 	  $file = $lfile;
 4307 	  @inputs = $file . '.in';
 4308 	}
 4309 
 4310       # Automake files should not be stored in here, but in %MAKE_LIST.
 4311       prog_error ("$lfile in \@other_input_files\n"
 4312 		  . "\@other_input_files = (@other_input_files)")
 4313 	if -f $file . '.am';
 4314 
 4315       my $local = basename ($file);
 4316 
 4317       # We skip files that aren't in this directory.  However, if
 4318       # the file's directory does not have a Makefile, and we are
 4319       # currently doing '.', then we create a rule to rebuild the
 4320       # file in the subdir.
 4321       my $fd = dirname ($file);
 4322       if ($fd ne $relative_dir)
 4323 	{
 4324 	  if ($relative_dir eq '.' && ! is_make_dir ($fd))
 4325 	    {
 4326 	      $local = $file;
 4327 	    }
 4328 	  else
 4329 	    {
 4330 	      next;
 4331 	    }
 4332 	}
 4333 
 4334       my @rewritten_inputs = rewrite_inputs_into_dependencies ($file, @inputs);
 4335 
 4336       # Cannot output rules for shell variables.
 4337       next if (substitute_ac_subst_variables $local) =~ /\$/;
 4338 
 4339       my $condstr = '';
 4340       my $cond = $ac_config_files_condition{$lfile};
 4341       if (defined $cond)
 4342         {
 4343 	  $condstr = $cond->subst_string;
 4344 	  Automake::Rule::define ($local, $configure_ac, RULE_AUTOMAKE, $cond,
 4345 				  $ac_config_files_location{$file});
 4346         }
 4347       $output_rules .= ($condstr . $local . ': '
 4348 			. '$(top_builddir)/config.status '
 4349 			. "@rewritten_inputs\n"
 4350 			. $condstr . "\t"
 4351 			. 'cd $(top_builddir) && '
 4352 			. '$(SHELL) ./config.status '
 4353 			. ($relative_dir eq '.' ? '' : '$(subdir)/')
 4354 			. '$@'
 4355 			. "\n");
 4356       push (@actual_other_files, $local);
 4357     }
 4358 
 4359   # For links we should clean destinations and distribute sources.
 4360   foreach my $spec (@config_links)
 4361     {
 4362       my ($link, $file) = split /:/, $spec;
 4363       # Some people do AC_CONFIG_LINKS($computed).  We only handle
 4364       # the DEST:SRC form.
 4365       next unless $file;
 4366       my $where = $ac_config_files_location{$link};
 4367 
 4368       # Skip destinations that contain shell variables.
 4369       if ((substitute_ac_subst_variables $link) !~ /\$/)
 4370 	{
 4371 	  # We skip links that aren't in this directory.  However, if
 4372 	  # the link's directory does not have a Makefile, and we are
 4373 	  # currently doing '.', then we add the link to CONFIG_CLEAN_FILES
 4374 	  # in '.'s Makefile.in.
 4375 	  my $local = basename ($link);
 4376 	  my $fd = dirname ($link);
 4377 	  if ($fd ne $relative_dir)
 4378 	    {
 4379 	      if ($relative_dir eq '.' && ! is_make_dir ($fd))
 4380 		{
 4381 		  $local = $link;
 4382 		}
 4383 	      else
 4384 		{
 4385 		  $local = undef;
 4386 		}
 4387 	    }
 4388 	  if ($file ne $link)
 4389 	    {
 4390 	      push @actual_other_files, $local if $local;
 4391 	    }
 4392 	  else
 4393 	    {
 4394 	      push @actual_other_vpath_files, $local if $local;
 4395 	    }
 4396 	}
 4397 
 4398       # Do not process sources that contain shell variables.
 4399       if ((substitute_ac_subst_variables $file) !~ /\$/)
 4400 	{
 4401 	  my $fd = dirname ($file);
 4402 
 4403 	  # We distribute files that are in this directory.
 4404 	  # At the top-level ('.') we also distribute files whose
 4405 	  # directory does not have a Makefile.
 4406 	  if (($fd eq $relative_dir)
 4407 	      || ($relative_dir eq '.' && ! is_make_dir ($fd)))
 4408 	    {
 4409 	      # The following will distribute $file as a side-effect when
 4410 	      # it is appropriate (i.e., when $file is not already an output).
 4411 	      # We do not need the result, just the side-effect.
 4412 	      rewrite_inputs_into_dependencies ($link, $file);
 4413 	    }
 4414 	}
 4415     }
 4416 
 4417   # These files get removed by "make distclean".
 4418   define_pretty_variable ('CONFIG_CLEAN_FILES', TRUE, INTERNAL,
 4419 			  @actual_other_files);
 4420   define_pretty_variable ('CONFIG_CLEAN_VPATH_FILES', TRUE, INTERNAL,
 4421 			  @actual_other_vpath_files);
 4422 }
 4423 
 4424 sub handle_headers ()
 4425 {
 4426     my @r = am_install_var ('-defaultdist', 'header', 'HEADERS', 'include',
 4427 			    'oldinclude', 'pkginclude',
 4428 			    'noinst', 'check');
 4429     foreach (@r)
 4430     {
 4431       next unless $_->[1] =~ /\..*$/;
 4432       saw_extension ($&);
 4433     }
 4434 }
 4435 
 4436 sub handle_gettext ()
 4437 {
 4438   return if ! $seen_gettext || $relative_dir ne '.';
 4439 
 4440   my $subdirs = var 'SUBDIRS';
 4441 
 4442   if (! $subdirs)
 4443     {
 4444       err_ac "AM_GNU_GETTEXT used but SUBDIRS not defined";
 4445       return;
 4446     }
 4447 
 4448   # Perform some sanity checks to help users get the right setup.
 4449   # We disable these tests when po/ doesn't exist in order not to disallow
 4450   # unusual gettext setups.
 4451   #
 4452   # Bruno Haible:
 4453   # | The idea is:
 4454   # |
 4455   # |  1) If a package doesn't have a directory po/ at top level, it
 4456   # |     will likely have multiple po/ directories in subpackages.
 4457   # |
 4458   # |  2) It is useful to warn for the absence of intl/ if AM_GNU_GETTEXT
 4459   # |     is used without 'external'. It is also useful to warn for the
 4460   # |     presence of intl/ if AM_GNU_GETTEXT([external]) is used. Both
 4461   # |     warnings apply only to the usual layout of packages, therefore
 4462   # |     they should both be disabled if no po/ directory is found at
 4463   # |     top level.
 4464 
 4465   if (-d 'po')
 4466     {
 4467       my @subdirs = $subdirs->value_as_list_recursive;
 4468 
 4469       msg_var ('syntax', $subdirs,
 4470 	       "AM_GNU_GETTEXT used but 'po' not in SUBDIRS")
 4471 	if ! grep ($_ eq 'po', @subdirs);
 4472 
 4473       # intl/ is not required when AM_GNU_GETTEXT is called with the
 4474       # 'external' option and AM_GNU_GETTEXT_INTL_SUBDIR is not called.
 4475       msg_var ('syntax', $subdirs,
 4476 	       "AM_GNU_GETTEXT used but 'intl' not in SUBDIRS")
 4477 	if (! ($seen_gettext_external && ! $seen_gettext_intl)
 4478 	    && ! grep ($_ eq 'intl', @subdirs));
 4479 
 4480       # intl/ should not be used with AM_GNU_GETTEXT([external]), except
 4481       # if AM_GNU_GETTEXT_INTL_SUBDIR is called.
 4482       msg_var ('syntax', $subdirs,
 4483 	       "'intl' should not be in SUBDIRS when "
 4484 	       . "AM_GNU_GETTEXT([external]) is used")
 4485 	if ($seen_gettext_external && ! $seen_gettext_intl
 4486 	    && grep ($_ eq 'intl', @subdirs));
 4487     }
 4488 
 4489   require_file ($ac_gettext_location, GNU, 'ABOUT-NLS');
 4490 }
 4491 
 4492 # Emit makefile footer.
 4493 sub handle_footer ()
 4494 {
 4495     reject_rule ('.SUFFIXES',
 4496 		 "use variable 'SUFFIXES', not target '.SUFFIXES'");
 4497 
 4498     # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
 4499     # before .SUFFIXES.  So we make sure that .SUFFIXES appears before
 4500     # anything else, by sticking it right after the default: target.
 4501     $output_header .= ".SUFFIXES:\n";
 4502     my $suffixes = var 'SUFFIXES';
 4503     my @suffixes = Automake::Rule::suffixes;
 4504     if (@suffixes || $suffixes)
 4505     {
 4506 	# Make sure SUFFIXES has unique elements.  Sort them to ensure
 4507 	# the output remains consistent.  However, $(SUFFIXES) is
 4508 	# always at the start of the list, unsorted.  This is done
 4509 	# because make will choose rules depending on the ordering of
 4510 	# suffixes, and this lets the user have some control.  Push
 4511 	# actual suffixes, and not $(SUFFIXES).  Some versions of make
 4512 	# do not like variable substitutions on the .SUFFIXES line.
 4513 	my @user_suffixes = ($suffixes
 4514 			     ? $suffixes->value_as_list_recursive : ());
 4515 
 4516 	my %suffixes = map { $_ => 1 } @suffixes;
 4517 	delete @suffixes{@user_suffixes};
 4518 
 4519 	$output_header .= (".SUFFIXES: "
 4520 			   . join (' ', @user_suffixes, sort keys %suffixes)
 4521 			   . "\n");
 4522     }
 4523 
 4524     $output_trailer .= file_contents ('footer', new Automake::Location);
 4525 }
 4526 
 4527 
 4528 # Generate 'make install' rules.
 4529 sub handle_install ()
 4530 {
 4531   $output_rules .= file_contents
 4532     ('install',
 4533      new Automake::Location,
 4534      maybe_BUILT_SOURCES => (set_seen ('BUILT_SOURCES')
 4535 			     ? (" \$(BUILT_SOURCES)\n"
 4536 				. "\t\$(MAKE) \$(AM_MAKEFLAGS)")
 4537 			     : ''),
 4538      'installdirs-local' => (user_phony_rule ('installdirs-local')
 4539 			     ? ' installdirs-local' : ''),
 4540      am__installdirs => variable_value ('am__installdirs') || '');
 4541 }
 4542 
 4543 
 4544 # handle_all ($MAKEFILE)
 4545 #-----------------------
 4546 # Deal with 'all' and 'all-am'.
 4547 sub handle_all
 4548 {
 4549     my ($makefile) = @_;
 4550 
 4551     # Output 'all-am'.
 4552 
 4553     # Put this at the beginning for the sake of non-GNU makes.  This
 4554     # is still wrong if these makes can run parallel jobs.  But it is
 4555     # right enough.
 4556     unshift (@all, basename ($makefile));
 4557 
 4558     foreach my $spec (@config_headers)
 4559       {
 4560 	my ($out, @ins) = split_config_file_spec ($spec);
 4561 	push (@all, basename ($out))
 4562 	  if dirname ($out) eq $relative_dir;
 4563       }
 4564 
 4565     # Install 'all' hooks.
 4566     push (@all, "all-local")
 4567       if user_phony_rule "all-local";
 4568 
 4569     pretty_print_rule ("all-am:", "\t\t", @all);
 4570     depend ('.PHONY', 'all-am', 'all');
 4571 
 4572 
 4573     # Output 'all'.
 4574 
 4575     my @local_headers = ();
 4576     push @local_headers, '$(BUILT_SOURCES)'
 4577       if var ('BUILT_SOURCES');
 4578     foreach my $spec (@config_headers)
 4579       {
 4580 	my ($out, @ins) = split_config_file_spec ($spec);
 4581 	push @local_headers, basename ($out)
 4582 	  if dirname ($out) eq $relative_dir;
 4583       }
 4584 
 4585     if (@local_headers)
 4586       {
 4587 	# We need to make sure config.h is built before we recurse.
 4588 	# We also want to make sure that built sources are built
 4589 	# before any ordinary 'all' targets are run.  We can't do this
 4590 	# by changing the order of dependencies to the "all" because
 4591 	# that breaks when using parallel makes.  Instead we handle
 4592 	# things explicitly.
 4593 	$output_all .= ("all: @local_headers"
 4594 			. "\n\t"
 4595 			. '$(MAKE) $(AM_MAKEFLAGS) '
 4596 			. (var ('SUBDIRS') ? 'all-recursive' : 'all-am')
 4597 			. "\n\n");
 4598         depend ('.MAKE', 'all');
 4599       }
 4600     else
 4601       {
 4602 	$output_all .= "all: " . (var ('SUBDIRS')
 4603 				  ? 'all-recursive' : 'all-am') . "\n\n";
 4604       }
 4605 }
 4606 
 4607 # Generate helper targets for user-defined recursive targets, where needed.
 4608 sub handle_user_recursion ()
 4609 {
 4610   return unless @extra_recursive_targets;
 4611 
 4612   define_pretty_variable ('am__extra_recursive_targets', TRUE, INTERNAL,
 4613                           map { "$_-recursive" } @extra_recursive_targets);
 4614   my $aux = var ('SUBDIRS') ? 'recursive' : 'am';
 4615   foreach my $target (@extra_recursive_targets)
 4616     {
 4617       # This allows the default target's rules to be overridden in
 4618       # Makefile.am.
 4619       user_phony_rule ($target);
 4620       depend ("$target", "$target-$aux");
 4621       depend ("$target-am", "$target-local");
 4622       # Every user-defined recursive target 'foo' *must* have a valid
 4623       # associated 'foo-local' rule; we define it as an empty rule by
 4624       # default, so that the user can transparently extend it in his
 4625       # own Makefile.am.
 4626       pretty_print_rule ("$target-local:", '', '');
 4627       # $target-recursive might as well be undefined, so do not add
 4628       # it here; it's taken care of in subdirs.am anyway.
 4629       depend (".PHONY", "$target-am", "$target-local");
 4630     }
 4631 }
 4632 
 4633 
 4634 # Handle check merge target specially.
 4635 sub do_check_merge_target ()
 4636 {
 4637   # Include user-defined local form of target.
 4638   push @check_tests, 'check-local'
 4639     if user_phony_rule 'check-local';
 4640 
 4641   # The check target must depend on the local equivalent of
 4642   # 'all', to ensure all the primary targets are built.  Then it
 4643   # must build the local check rules.
 4644   $output_rules .= "check-am: all-am\n";
 4645   if (@check)
 4646     {
 4647       pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ", @check);
 4648       depend ('.MAKE', 'check-am');
 4649     }
 4650 
 4651   if (@check_tests)
 4652     {
 4653       pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
 4654 			 @check_tests);
 4655       depend ('.MAKE', 'check-am');
 4656     }
 4657 
 4658   depend '.PHONY', 'check', 'check-am';
 4659   # Handle recursion.  We have to honor BUILT_SOURCES like for 'all:'.
 4660   $output_rules .= ("check: "
 4661 		    . (var ('BUILT_SOURCES')
 4662 		       ? "\$(BUILT_SOURCES)\n\t\$(MAKE) \$(AM_MAKEFLAGS) "
 4663 		       : '')
 4664 		    . (var ('SUBDIRS') ? 'check-recursive' : 'check-am')
 4665 		    . "\n");
 4666   depend ('.MAKE', 'check')
 4667     if var ('BUILT_SOURCES');
 4668 }
 4669 
 4670 # Handle all 'clean' targets.
 4671 sub handle_clean
 4672 {
 4673   my ($makefile) = @_;
 4674 
 4675   # Clean the files listed in user variables if they exist.
 4676   $clean_files{'$(MOSTLYCLEANFILES)'} = MOSTLY_CLEAN
 4677     if var ('MOSTLYCLEANFILES');
 4678   $clean_files{'$(CLEANFILES)'} = CLEAN
 4679     if var ('CLEANFILES');
 4680   $clean_files{'$(DISTCLEANFILES)'} = DIST_CLEAN
 4681     if var ('DISTCLEANFILES');
 4682   $clean_files{'$(MAINTAINERCLEANFILES)'} = MAINTAINER_CLEAN
 4683     if var ('MAINTAINERCLEANFILES');
 4684 
 4685   # Built sources are automatically removed by maintainer-clean.
 4686   $clean_files{'$(BUILT_SOURCES)'} = MAINTAINER_CLEAN
 4687     if var ('BUILT_SOURCES');
 4688 
 4689   # Compute a list of "rm"s to run for each target.
 4690   my %rms = (MOSTLY_CLEAN, [],
 4691 	     CLEAN, [],
 4692 	     DIST_CLEAN, [],
 4693 	     MAINTAINER_CLEAN, []);
 4694 
 4695   foreach my $file (keys %clean_files)
 4696     {
 4697       my $when = $clean_files{$file};
 4698       prog_error 'invalid entry in %clean_files'
 4699 	unless exists $rms{$when};
 4700 
 4701       my $rm = "rm -f $file";
 4702       # If file is a variable, make sure when don't call 'rm -f' without args.
 4703       $rm ="test -z \"$file\" || $rm"
 4704 	if ($file =~ /^\s*\$(\(.*\)|\{.*\})\s*$/);
 4705 
 4706       push @{$rms{$when}}, "\t-$rm\n";
 4707     }
 4708 
 4709   $output_rules .= file_contents
 4710     ('clean',
 4711      new Automake::Location,
 4712      MOSTLYCLEAN_RMS      => join ('', sort @{$rms{&MOSTLY_CLEAN}}),
 4713      CLEAN_RMS            => join ('', sort @{$rms{&CLEAN}}),
 4714      DISTCLEAN_RMS        => join ('', sort @{$rms{&DIST_CLEAN}}),
 4715      MAINTAINER_CLEAN_RMS => join ('', sort @{$rms{&MAINTAINER_CLEAN}}),
 4716      MAKEFILE             => basename $makefile,
 4717      );
 4718 }
 4719 
 4720 
 4721 # Subroutine for handle_factored_dependencies() to let '.PHONY' and
 4722 # other '.TARGETS' be last.  This is meant to be used as a comparison
 4723 # subroutine passed to the sort built-int.
 4724 sub target_cmp
 4725 {
 4726   return 0 if $a eq $b;
 4727 
 4728   my $a1 = substr ($a, 0, 1);
 4729   my $b1 = substr ($b, 0, 1);
 4730   if ($a1 ne $b1)
 4731     {
 4732       return -1 if $b1 eq '.';
 4733       return 1 if $a1 eq '.';
 4734     }
 4735   return $a cmp $b;
 4736 }
 4737 
 4738 
 4739 # Handle everything related to gathered targets.
 4740 sub handle_factored_dependencies ()
 4741 {
 4742   # Reject bad hooks.
 4743   foreach my $utarg ('uninstall-data-local', 'uninstall-data-hook',
 4744 		     'uninstall-exec-local', 'uninstall-exec-hook',
 4745 		     'uninstall-dvi-local',
 4746 		     'uninstall-html-local',
 4747 		     'uninstall-info-local',
 4748 		     'uninstall-pdf-local',
 4749 		     'uninstall-ps-local')
 4750     {
 4751       my $x = $utarg;
 4752       $x =~ s/-.*-/-/;
 4753       reject_rule ($utarg, "use '$x', not '$utarg'");
 4754     }
 4755 
 4756   reject_rule ('install-local',
 4757 	       "use 'install-data-local' or 'install-exec-local', "
 4758 	       . "not 'install-local'");
 4759 
 4760   reject_rule ('install-hook',
 4761 	       "use 'install-data-hook' or 'install-exec-hook', "
 4762 	       . "not 'install-hook'");
 4763 
 4764   # Install the -local hooks.
 4765   foreach (keys %dependencies)
 4766     {
 4767       # Hooks are installed on the -am targets.
 4768       s/-am$// or next;
 4769       depend ("$_-am", "$_-local")
 4770 	if user_phony_rule "$_-local";
 4771     }
 4772 
 4773   # Install the -hook hooks.
 4774   # FIXME: Why not be as liberal as we are with -local hooks?
 4775   foreach ('install-exec', 'install-data', 'uninstall')
 4776     {
 4777       if (user_phony_rule "$_-hook")
 4778 	{
 4779 	  depend ('.MAKE', "$_-am");
 4780 	  register_action("$_-am",
 4781 			  ("\t\@\$(NORMAL_INSTALL)\n"
 4782 			   . "\t\$(MAKE) \$(AM_MAKEFLAGS) $_-hook"));
 4783 	}
 4784     }
 4785 
 4786   # All the required targets are phony.
 4787   depend ('.PHONY', keys %required_targets);
 4788 
 4789   # Actually output gathered targets.
 4790   foreach (sort target_cmp keys %dependencies)
 4791     {
 4792       # If there is nothing about this guy, skip it.
 4793       next
 4794 	unless (@{$dependencies{$_}}
 4795 		|| $actions{$_}
 4796 		|| $required_targets{$_});
 4797 
 4798       # Define gathered targets in undefined conditions.
 4799       # FIXME: Right now we must handle .PHONY as an exception,
 4800       # because people write things like
 4801       #    .PHONY: myphonytarget
 4802       # to append dependencies.  This would not work if Automake
 4803       # refrained from defining its own .PHONY target as it does
 4804       # with other overridden targets.
 4805       # Likewise for '.MAKE' and '.PRECIOUS'.
 4806       my @undefined_conds = (TRUE,);
 4807       if ($_ ne '.PHONY' && $_ ne '.MAKE' && $_ ne '.PRECIOUS')
 4808 	{
 4809 	  @undefined_conds =
 4810 	    Automake::Rule::define ($_, 'internal',
 4811 				    RULE_AUTOMAKE, TRUE, INTERNAL);
 4812 	}
 4813       my @uniq_deps = uniq (sort @{$dependencies{$_}});
 4814       foreach my $cond (@undefined_conds)
 4815 	{
 4816 	  my $condstr = $cond->subst_string;
 4817 	  pretty_print_rule ("$condstr$_:", "$condstr\t", @uniq_deps);
 4818 	  $output_rules .= $actions{$_} if defined $actions{$_};
 4819 	  $output_rules .= "\n";
 4820 	}
 4821     }
 4822 }
 4823 
 4824 
 4825 sub handle_tests_dejagnu ()
 4826 {
 4827     push (@check_tests, 'check-DEJAGNU');
 4828     $output_rules .= file_contents ('dejagnu', new Automake::Location);
 4829 }
 4830 
 4831 # handle_per_suffix_test ($TEST_SUFFIX, [%TRANSFORM])
 4832 #----------------------------------------------------
 4833 sub handle_per_suffix_test
 4834 {
 4835   my ($test_suffix, %transform) = @_;
 4836   my ($pfx, $generic, $am_exeext);
 4837   if ($test_suffix eq '')
 4838     {
 4839       $pfx = '';
 4840       $generic = 0;
 4841       $am_exeext = 'FALSE';
 4842     }
 4843   else
 4844     {
 4845       prog_error ("test suffix '$test_suffix' lacks leading dot")
 4846         unless $test_suffix =~ m/^\.(.*)/;
 4847       $pfx = uc ($1) . '_';
 4848       $generic = 1;
 4849       $am_exeext = exists $configure_vars{'EXEEXT'} ? 'am__EXEEXT'
 4850                                                     : 'FALSE';
 4851     }
 4852   # The "test driver" program, deputed to handle tests protocol used by
 4853   # test scripts.  By default, it's assumed that no protocol is used, so
 4854   # we fall back to the old behaviour, implemented by the 'test-driver'
 4855   # auxiliary script.
 4856   if (! var "${pfx}LOG_DRIVER")
 4857     {
 4858       require_conf_file ("parallel-tests", FOREIGN, 'test-driver');
 4859       define_variable ("${pfx}LOG_DRIVER",
 4860                        "\$(SHELL) $am_config_aux_dir/test-driver",
 4861                        INTERNAL);
 4862     }
 4863   my $driver = '$(' . $pfx . 'LOG_DRIVER)';
 4864   my $driver_flags = '$(AM_' . $pfx . 'LOG_DRIVER_FLAGS)'
 4865                        . ' $(' . $pfx . 'LOG_DRIVER_FLAGS)';
 4866   my $compile = "${pfx}LOG_COMPILE";
 4867   define_variable ($compile,
 4868                    '$(' . $pfx . 'LOG_COMPILER)'
 4869                       . ' $(AM_' .  $pfx . 'LOG_FLAGS)'
 4870                       . ' $(' . $pfx . 'LOG_FLAGS)',
 4871                      INTERNAL);
 4872   $output_rules .= file_contents ('check2', new Automake::Location,
 4873                                    GENERIC => $generic,
 4874                                    DRIVER => $driver,
 4875                                    DRIVER_FLAGS => $driver_flags,
 4876                                    COMPILE => '$(' . $compile . ')',
 4877                                    EXT => $test_suffix,
 4878                                    am__EXEEXT => $am_exeext,
 4879                                    %transform);
 4880 }
 4881 
 4882 # is_valid_test_extension ($EXT)
 4883 # ------------------------------
 4884 # Return true if $EXT can appear in $(TEST_EXTENSIONS), return false
 4885 # otherwise.
 4886 sub is_valid_test_extension
 4887 {
 4888   my $ext = shift;
 4889   return 1
 4890     if ($ext =~ /^\.[a-zA-Z_][a-zA-Z0-9_]*$/);
 4891   return 1
 4892     if (exists $configure_vars{'EXEEXT'} && $ext eq subst ('EXEEXT'));
 4893   return 0;
 4894 }
 4895 
 4896 
 4897 sub handle_tests ()
 4898 {
 4899   if (option 'dejagnu')
 4900     {
 4901       handle_tests_dejagnu;
 4902     }
 4903   else
 4904     {
 4905       foreach my $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
 4906 	{
 4907 	  reject_var ($c, "'$c' defined but 'dejagnu' not in "
 4908 		      . "'AUTOMAKE_OPTIONS'");
 4909 	}
 4910     }
 4911 
 4912   if (var ('TESTS'))
 4913     {
 4914       push (@check_tests, 'check-TESTS');
 4915       my $check_deps = "@check";
 4916       $output_rules .= file_contents ('check', new Automake::Location,
 4917                                       SERIAL_TESTS => !! option 'serial-tests',
 4918                                       CHECK_DEPS => $check_deps);
 4919 
 4920       # Tests that are known programs should have $(EXEEXT) appended.
 4921       # For matching purposes, we need to adjust XFAIL_TESTS as well.
 4922       append_exeext { exists $known_programs{$_[0]} } 'TESTS';
 4923       append_exeext { exists $known_programs{$_[0]} } 'XFAIL_TESTS'
 4924 	if (var ('XFAIL_TESTS'));
 4925 
 4926       if (! option 'serial-tests')
 4927         {
 4928 	  define_variable ('TEST_SUITE_LOG', 'test-suite.log', INTERNAL);
 4929 	  my $suff = '.test';
 4930 	  my $at_exeext = '';
 4931 	  my $handle_exeext = exists $configure_vars{'EXEEXT'};
 4932 	  if ($handle_exeext)
 4933 	    {
 4934 	      $at_exeext = subst ('EXEEXT');
 4935 	      $suff = $at_exeext  . ' ' . $suff;
 4936 	    }
 4937           if (! var 'TEST_EXTENSIONS')
 4938             {
 4939 	      define_variable ('TEST_EXTENSIONS', $suff, INTERNAL);
 4940             }
 4941           my $var = var 'TEST_EXTENSIONS';
 4942           # Currently, we are not able to deal with conditional contents
 4943           # in TEST_EXTENSIONS.
 4944           if ($var->has_conditional_contents)
 4945            {
 4946 	     msg_var 'unsupported', $var,
 4947                      "'TEST_EXTENSIONS' cannot have conditional contents";
 4948            }
 4949 	  my @test_suffixes = $var->value_as_list_recursive;
 4950           if ((my @invalid_test_suffixes =
 4951                   grep { !is_valid_test_extension $_ } @test_suffixes) > 0)
 4952             {
 4953               error $var->rdef (TRUE)->location,
 4954                     "invalid test extensions: @invalid_test_suffixes";
 4955             }
 4956           @test_suffixes = grep { is_valid_test_extension $_ } @test_suffixes;
 4957 	  if ($handle_exeext)
 4958 	    {
 4959 	      unshift (@test_suffixes, $at_exeext)
 4960 	        unless @test_suffixes && $test_suffixes[0] eq $at_exeext;
 4961 	    }
 4962 	  unshift (@test_suffixes, '');
 4963 
 4964 	  transform_variable_recursively
 4965 	    ('TESTS', 'TEST_LOGS', 'am__testlogs', 1, INTERNAL,
 4966 	      sub {
 4967 	        my ($subvar, $val, $cond, $full_cond) = @_;
 4968 		my $obj = $val;
 4969 		return $obj
 4970 		  if $val =~ /^\@.*\@$/;
 4971 		$obj =~ s/\$\(EXEEXT\)$//o;
 4972 
 4973 		if ($val =~ /(\$\((top_)?srcdir\))\//o)
 4974 		  {
 4975 		    msg ('error', $subvar->rdef ($cond)->location,
 4976 			 "using '$1' in TESTS is currently broken: '$val'");
 4977 		  }
 4978 
 4979 		foreach my $test_suffix (@test_suffixes)
 4980 		  {
 4981 		    next
 4982 		      if $test_suffix eq $at_exeext || $test_suffix eq '';
 4983 		    return substr ($obj, 0, length ($obj) - length ($test_suffix)) . '.log'
 4984 		      if substr ($obj, - length ($test_suffix)) eq $test_suffix;
 4985 		  }
 4986 		my $base = $obj;
 4987 		$obj .= '.log';
 4988                 handle_per_suffix_test ('',
 4989                                         OBJ => $obj,
 4990                                         BASE => $base,
 4991                                         SOURCE => $val);
 4992 	        return $obj;
 4993 	      });
 4994 
 4995 	  my $nhelper=1;
 4996 	  my $prev = 'TESTS';
 4997 	  my $post = '';
 4998 	  my $last_suffix = $test_suffixes[$#test_suffixes];
 4999 	  my $cur = '';
 5000 	  foreach my $test_suffix (@test_suffixes)
 5001 	    {
 5002 	      if ($test_suffix eq $last_suffix)
 5003 	        {
 5004 		  $cur = 'TEST_LOGS';
 5005 		}
 5006 	      else
 5007 	        {
 5008 		  $cur = 'am__test_logs' . $nhelper;
 5009 		}
 5010 	      define_variable ($cur,
 5011 		'$(' . $prev . ':' . $test_suffix . $post . '=.log)', INTERNAL);
 5012 	      $post = '.log';
 5013 	      $prev = $cur;
 5014 	      $nhelper++;
 5015 	      if ($test_suffix ne $at_exeext && $test_suffix ne '')
 5016 	        {
 5017                   handle_per_suffix_test ($test_suffix,
 5018                                           OBJ => '',
 5019                                           BASE => '$*',
 5020                                           SOURCE => '$<');
 5021 	        }
 5022 	    }
 5023 	  $clean_files{'$(TEST_LOGS)'} = MOSTLY_CLEAN;
 5024 	  $clean_files{'$(TEST_LOGS:.log=.trs)'} = MOSTLY_CLEAN;
 5025 	  $clean_files{'$(TEST_SUITE_LOG)'} = MOSTLY_CLEAN;
 5026 	}
 5027     }
 5028 }
 5029 
 5030 sub handle_emacs_lisp ()
 5031 {
 5032   my @elfiles = am_install_var ('-candist', 'lisp', 'LISP',
 5033                                 'lisp', 'noinst');
 5034 
 5035   return if ! @elfiles;
 5036 
 5037   define_pretty_variable ('am__ELFILES', TRUE, INTERNAL,
 5038 			  map { $_->[1] } @elfiles);
 5039   define_pretty_variable ('am__ELCFILES', TRUE, INTERNAL,
 5040 			  '$(am__ELFILES:.el=.elc)');
 5041   # This one can be overridden by users.
 5042   define_pretty_variable ('ELCFILES', TRUE, INTERNAL, '$(LISP:.el=.elc)');
 5043 
 5044   push @all, '$(ELCFILES)';
 5045 
 5046   require_variables ($elfiles[0][0], "Emacs Lisp sources seen", TRUE,
 5047 		     'EMACS', 'lispdir');
 5048 }
 5049 
 5050 sub handle_python ()
 5051 {
 5052   my @pyfiles = am_install_var ('-defaultdist', 'python', 'PYTHON',
 5053                                 'noinst');
 5054   return if ! @pyfiles;
 5055 
 5056   require_variables ($pyfiles[0][0], "Python sources seen", TRUE, 'PYTHON');
 5057   require_conf_file ($pyfiles[0][0], FOREIGN, 'py-compile');
 5058   define_variable ('py_compile', "$am_config_aux_dir/py-compile", INTERNAL);
 5059 }
 5060 
 5061 sub handle_java ()
 5062 {
 5063     my @sourcelist = am_install_var ('-candist',
 5064                                      'java', 'JAVA',
 5065                                      'noinst', 'check');
 5066     return if ! @sourcelist;
 5067 
 5068     my @prefixes = am_primary_prefixes ('JAVA', 1,
 5069 				        'noinst', 'check');
 5070 
 5071     my $dir;
 5072     my @java_sources = ();
 5073     foreach my $prefix (@prefixes)
 5074       {
 5075         (my $curs = $prefix) =~ s/^(?:nobase_)?(?:dist_|nodist_)?//;
 5076 
 5077 	next
 5078 	  if $curs eq 'EXTRA';
 5079 
 5080         push @java_sources, '$(' . $prefix . '_JAVA' . ')';
 5081 
 5082 	if (defined $dir)
 5083 	  {
 5084 	    err_var "${curs}_JAVA", "multiple _JAVA primaries in use"
 5085 	     unless $curs eq $dir;
 5086 	  }
 5087 
 5088 	$dir = $curs;
 5089       }
 5090 
 5091     define_pretty_variable ('am__java_sources', TRUE, INTERNAL,
 5092                             "@java_sources");
 5093 
 5094     if ($dir eq 'check')
 5095       {
 5096         push (@check, "class$dir.stamp");
 5097       }
 5098     else
 5099       {
 5100         push (@all, "class$dir.stamp");
 5101       }
 5102 }
 5103 
 5104 
 5105 sub handle_minor_options ()
 5106 {
 5107   if (option 'readme-alpha')
 5108     {
 5109       if ($relative_dir eq '.')
 5110 	{
 5111 	  if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
 5112 	    {
 5113 	      msg ('error-gnits', $package_version_location,
 5114 		   "version '$package_version' doesn't follow " .
 5115 		   "Gnits standards");
 5116 	    }
 5117 	  if (defined $1 && -f 'README-alpha')
 5118 	    {
 5119 	      # This means we have an alpha release.  See
 5120 	      # GNITS_VERSION_PATTERN for details.
 5121 	      push_dist_common ('README-alpha');
 5122 	    }
 5123 	}
 5124     }
 5125 }
 5126 
 5127 ################################################################
 5128 
 5129 # ($OUTPUT, @INPUTS)
 5130 # split_config_file_spec ($SPEC)
 5131 # ------------------------------
 5132 # Decode the Autoconf syntax for config files (files, headers, links
 5133 # etc.).
 5134 sub split_config_file_spec
 5135 {
 5136   my ($spec) = @_;
 5137   my ($output, @inputs) = split (/:/, $spec);
 5138 
 5139   push @inputs, "$output.in"
 5140     unless @inputs;
 5141 
 5142   return ($output, @inputs);
 5143 }
 5144 
 5145 # $input
 5146 # locate_am (@POSSIBLE_SOURCES)
 5147 # -----------------------------
 5148 # AC_CONFIG_FILES allow specifications such as Makefile:top.in:mid.in:bot.in
 5149 # This functions returns the first *.in file for which a *.am exists.
 5150 # It returns undef otherwise.
 5151 sub locate_am
 5152 {
 5153   my (@rest) = @_;
 5154   my $input;
 5155   foreach my $file (@rest)
 5156     {
 5157       if (($file =~ /^(.*)\.in$/) && -f "$1.am")
 5158 	{
 5159 	  $input = $file;
 5160 	  last;
 5161 	}
 5162     }
 5163   return $input;
 5164 }
 5165 
 5166 my %make_list;
 5167 
 5168 # scan_autoconf_config_files ($WHERE, $CONFIG-FILES)
 5169 # --------------------------------------------------
 5170 # Study $CONFIG-FILES which is the first argument to AC_CONFIG_FILES
 5171 # (or AC_OUTPUT).
 5172 sub scan_autoconf_config_files
 5173 {
 5174   my ($where, $config_files) = @_;
 5175 
 5176   # Look at potential Makefile.am's.
 5177   foreach (split ' ', $config_files)
 5178     {
 5179       # Must skip empty string for Perl 4.
 5180       next if $_ eq "\\" || $_ eq '';
 5181 
 5182       # Handle $local:$input syntax.
 5183       my ($local, @rest) = split (/:/);
 5184       @rest = ("$local.in",) unless @rest;
 5185       # Keep in sync with test 'conffile-leading-dot.sh'.
 5186       msg ('unsupported', $where,
 5187            "omit leading './' from config file names such as '$local';"
 5188            . "\nremake rules might be subtly broken otherwise")
 5189         if ($local =~ /^\.\//);
 5190       my $input = locate_am @rest;
 5191       if ($input)
 5192 	{
 5193 	  # We have a file that automake should generate.
 5194 	  $make_list{$input} = join (':', ($local, @rest));
 5195 	}
 5196       else
 5197 	{
 5198 	  # We have a file that automake should cause to be
 5199 	  # rebuilt, but shouldn't generate itself.
 5200 	  push (@other_input_files, $_);
 5201 	}
 5202       $ac_config_files_location{$local} = $where;
 5203       $ac_config_files_condition{$local} =
 5204         new Automake::Condition (@cond_stack)
 5205           if (@cond_stack);
 5206     }
 5207 }
 5208 
 5209 
 5210 sub scan_autoconf_traces
 5211 {
 5212   my ($filename) = @_;
 5213 
 5214   # Macros to trace, with their minimal number of arguments.
 5215   #
 5216   # IMPORTANT: If you add a macro here, you should also add this macro
 5217   # =========  to Automake-preselection in autoconf/lib/autom4te.in.
 5218   my %traced = (
 5219 		AC_CANONICAL_BUILD => 0,
 5220 		AC_CANONICAL_HOST => 0,
 5221 		AC_CANONICAL_TARGET => 0,
 5222 		AC_CONFIG_AUX_DIR => 1,
 5223 		AC_CONFIG_FILES => 1,
 5224 		AC_CONFIG_HEADERS => 1,
 5225 		AC_CONFIG_LIBOBJ_DIR => 1,
 5226 		AC_CONFIG_LINKS => 1,
 5227 		AC_FC_SRCEXT => 1,
 5228 		AC_INIT => 0,
 5229 		AC_LIBSOURCE => 1,
 5230 		AC_REQUIRE_AUX_FILE => 1,
 5231 		AC_SUBST_TRACE => 1,
 5232 		AM_AUTOMAKE_VERSION => 1,
 5233                 AM_PROG_MKDIR_P => 0,
 5234 		AM_CONDITIONAL => 2,
 5235 		AM_EXTRA_RECURSIVE_TARGETS => 1,
 5236 		AM_GNU_GETTEXT => 0,
 5237 		AM_GNU_GETTEXT_INTL_SUBDIR => 0,
 5238 		AM_INIT_AUTOMAKE => 0,
 5239 		AM_MAINTAINER_MODE => 0,
 5240 		AM_PROG_AR => 0,
 5241 		_AM_SUBST_NOTMAKE => 1,
 5242 		_AM_COND_IF => 1,
 5243 		_AM_COND_ELSE => 1,
 5244 		_AM_COND_ENDIF => 1,
 5245 		LT_SUPPORTED_TAG => 1,
 5246 		_LT_AC_TAGCONFIG => 0,
 5247 		m4_include => 1,
 5248 		m4_sinclude => 1,
 5249 		sinclude => 1,
 5250 	      );
 5251 
 5252   # Suppress all warnings from this invocation of autoconf.
 5253   # The user is presumably about to run autoconf themselves
 5254   # and will see its warnings then.
 5255   local $ENV{WARNINGS} = 'none';
 5256 
 5257   my $traces = ($ENV{AUTOCONF} || '@am_AUTOCONF@') . " ";
 5258 
 5259   # Use a separator unlikely to be used, not ':', the default, which
 5260   # has a precise meaning for AC_CONFIG_FILES and so on.
 5261   $traces .= join (' ',
 5262 		   map { "--trace=$_" . ':\$f:\$l::\$d::\$n::\${::}%' }
 5263 		   (keys %traced));
 5264 
 5265   verb "running WARNINGS=$ENV{WARNINGS} $traces";
 5266   my $tracefh = new Automake::XFile ("$traces $filename |");
 5267 
 5268   @cond_stack = ();
 5269   my $where;
 5270 
 5271   while ($_ = $tracefh->getline)
 5272     {
 5273       chomp;
 5274       my ($here, $depth, @args) = split (/::/);
 5275       $where = new Automake::Location $here;
 5276       my $macro = $args[0];
 5277 
 5278       prog_error ("unrequested trace '$macro'")
 5279 	unless exists $traced{$macro};
 5280 
 5281       # Skip and diagnose malformed calls.
 5282       if ($#args < $traced{$macro})
 5283 	{
 5284 	  msg ('syntax', $where, "not enough arguments for $macro");
 5285 	  next;
 5286 	}
 5287 
 5288       # Alphabetical ordering please.
 5289       if ($macro eq 'AC_CANONICAL_BUILD')
 5290 	{
 5291 	  if ($seen_canonical <= AC_CANONICAL_BUILD)
 5292 	    {
 5293 	      $seen_canonical = AC_CANONICAL_BUILD;
 5294 	    }
 5295 	}
 5296       elsif ($macro eq 'AC_CANONICAL_HOST')
 5297 	{
 5298 	  if ($seen_canonical <= AC_CANONICAL_HOST)
 5299 	    {
 5300 	      $seen_canonical = AC_CANONICAL_HOST;
 5301 	    }
 5302 	}
 5303       elsif ($macro eq 'AC_CANONICAL_TARGET')
 5304 	{
 5305 	  $seen_canonical = AC_CANONICAL_TARGET;
 5306 	}
 5307       elsif ($macro eq 'AC_CONFIG_AUX_DIR')
 5308 	{
 5309 	  if ($seen_init_automake)
 5310 	    {
 5311 	      error ($where, "AC_CONFIG_AUX_DIR must be called before "
 5312 		     . "AM_INIT_AUTOMAKE ...", partial => 1);
 5313 	      error ($seen_init_automake, "... AM_INIT_AUTOMAKE called here");
 5314 	    }
 5315 	  $config_aux_dir = $args[1];
 5316 	  $config_aux_dir_set_in_configure_ac = 1;
 5317 	  check_directory ($config_aux_dir, $where);
 5318 	}
 5319       elsif ($macro eq 'AC_CONFIG_FILES')
 5320 	{
 5321 	  # Look at potential Makefile.am's.
 5322 	  scan_autoconf_config_files ($where, $args[1]);
 5323 	}
 5324       elsif ($macro eq 'AC_CONFIG_HEADERS')
 5325 	{
 5326 	  foreach my $spec (split (' ', $args[1]))
 5327 	    {
 5328 	      my ($dest, @src) = split (':', $spec);
 5329 	      $ac_config_files_location{$dest} = $where;
 5330 	      push @config_headers, $spec;
 5331 	    }
 5332 	}
 5333       elsif ($macro eq 'AC_CONFIG_LIBOBJ_DIR')
 5334 	{
 5335 	  $config_libobj_dir = $args[1];
 5336 	  check_directory ($config_libobj_dir, $where);
 5337 	}
 5338       elsif ($macro eq 'AC_CONFIG_LINKS')
 5339 	{
 5340 	  foreach my $spec (split (' ', $args[1]))
 5341 	    {
 5342 	      my ($dest, $src) = split (':', $spec);
 5343 	      $ac_config_files_location{$dest} = $where;
 5344 	      push @config_links, $spec;
 5345 	    }
 5346 	}
 5347       elsif ($macro eq 'AC_FC_SRCEXT')
 5348 	{
 5349 	  my $suffix = $args[1];
 5350 	  # These flags are used as %SOURCEFLAG% in depend2.am,
 5351 	  # where the trailing space is important.
 5352 	  $sourceflags{'.' . $suffix} = '$(FCFLAGS_' . $suffix . ') '
 5353 	    if ($suffix eq 'f90' || $suffix eq 'f95' || $suffix eq 'f03' || $suffix eq 'f08');
 5354 	}
 5355       elsif ($macro eq 'AC_INIT')
 5356 	{
 5357 	  if (defined $args[2])
 5358 	    {
 5359 	      $package_version = $args[2];
 5360 	      $package_version_location = $where;
 5361 	    }
 5362 	}
 5363       elsif ($macro eq 'AC_LIBSOURCE')
 5364 	{
 5365 	  $libsources{$args[1]} = $here;
 5366 	}
 5367       elsif ($macro eq 'AC_REQUIRE_AUX_FILE')
 5368 	{
 5369 	  # Only remember the first time a file is required.
 5370 	  $required_aux_file{$args[1]} = $where
 5371 	    unless exists $required_aux_file{$args[1]};
 5372 	}
 5373       elsif ($macro eq 'AC_SUBST_TRACE')
 5374 	{
 5375 	  # Just check for alphanumeric in AC_SUBST_TRACE.  If you do
 5376 	  # AC_SUBST(5), then too bad.
 5377 	  $configure_vars{$args[1]} = $where
 5378 	    if $args[1] =~ /^\w+$/;
 5379 	}
 5380       elsif ($macro eq 'AM_AUTOMAKE_VERSION')
 5381 	{
 5382 	  error ($where,
 5383 		 "version mismatch.  This is Automake $VERSION,\n" .
 5384 		 "but the definition used by this AM_INIT_AUTOMAKE\n" .
 5385 		 "comes from Automake $args[1].  You should recreate\n" .
 5386 		 "aclocal.m4 with aclocal and run automake again.\n",
 5387 		 # $? = 63 is used to indicate version mismatch to missing.
 5388 		 exit_code => 63)
 5389 	    if $VERSION ne $args[1];
 5390 
 5391 	  $seen_automake_version = 1;
 5392 	}
 5393       elsif ($macro eq 'AM_PROG_MKDIR_P')
 5394 	{
 5395 	  msg 'obsolete', $where, <<'EOF';
 5396 The 'AM_PROG_MKDIR_P' macro is deprecated, and its use is discouraged.
 5397 You should use the Autoconf-provided 'AC_PROG_MKDIR_P' macro instead,
 5398 and use '$(MKDIR_P)' instead of '$(mkdir_p)'in your Makefile.am files.
 5399 EOF
 5400 	}
 5401       elsif ($macro eq 'AM_CONDITIONAL')
 5402 	{
 5403 	  $configure_cond{$args[1]} = $where;
 5404 	}
 5405       elsif ($macro eq 'AM_EXTRA_RECURSIVE_TARGETS')
 5406 	{
 5407           # Empty leading/trailing fields might be produced by split,
 5408           # hence the grep is really needed.
 5409           push @extra_recursive_targets,
 5410                grep (/./, (split /\s+/, $args[1]));
 5411 	}
 5412       elsif ($macro eq 'AM_GNU_GETTEXT')
 5413 	{
 5414 	  $seen_gettext = $where;
 5415 	  $ac_gettext_location = $where;
 5416 	  $seen_gettext_external = grep ($_ eq 'external', @args);
 5417 	}
 5418       elsif ($macro eq 'AM_GNU_GETTEXT_INTL_SUBDIR')
 5419 	{
 5420 	  $seen_gettext_intl = $where;
 5421 	}
 5422       elsif ($macro eq 'AM_INIT_AUTOMAKE')
 5423 	{
 5424 	  $seen_init_automake = $where;
 5425 	  if (defined $args[2])
 5426 	    {
 5427               msg 'obsolete', $where, <<'EOF';
 5428 AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated.  For more info, see:
 5429 https://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocation
 5430 EOF
 5431 	      $package_version = $args[2];
 5432 	      $package_version_location = $where;
 5433 	    }
 5434 	  elsif (defined $args[1])
 5435 	    {
 5436 	      my @opts = split (' ', $args[1]);
 5437 	      @opts = map { { option => $_, where => $where } } @opts;
 5438 	      exit $exit_code unless process_global_option_list (@opts);
 5439 	    }
 5440 	}
 5441       elsif ($macro eq 'AM_MAINTAINER_MODE')
 5442 	{
 5443 	  $seen_maint_mode = $where;
 5444 	}
 5445       elsif ($macro eq 'AM_PROG_AR')
 5446 	{
 5447 	  $seen_ar = $where;
 5448 	}
 5449       elsif ($macro eq '_AM_COND_IF')
 5450         {
 5451 	  cond_stack_if ('', $args[1], $where);
 5452 	  error ($where, "missing m4 quoting, macro depth $depth")
 5453 	    if ($depth != 1);
 5454 	}
 5455       elsif ($macro eq '_AM_COND_ELSE')
 5456         {
 5457 	  cond_stack_else ('!', $args[1], $where);
 5458 	  error ($where, "missing m4 quoting, macro depth $depth")
 5459 	    if ($depth != 1);
 5460 	}
 5461       elsif ($macro eq '_AM_COND_ENDIF')
 5462         {
 5463 	  cond_stack_endif (undef, undef, $where);
 5464 	  error ($where, "missing m4 quoting, macro depth $depth")
 5465 	    if ($depth != 1);
 5466 	}
 5467       elsif ($macro eq '_AM_SUBST_NOTMAKE')
 5468 	{
 5469 	  $ignored_configure_vars{$args[1]} = $where;
 5470 	}
 5471       elsif ($macro eq 'm4_include'
 5472 	     || $macro eq 'm4_sinclude'
 5473 	     || $macro eq 'sinclude')
 5474 	{
 5475 	  # Skip missing 'sinclude'd files.
 5476 	  next if $macro ne 'm4_include' && ! -f $args[1];
 5477 
 5478 	  # Some modified versions of Autoconf don't use
 5479 	  # frozen files.  Consequently it's possible that we see all
 5480 	  # m4_include's performed during Autoconf's startup.
 5481 	  # Obviously we don't want to distribute Autoconf's files
 5482 	  # so we skip absolute filenames here.
 5483 	  push @configure_deps, '$(top_srcdir)/' . $args[1]
 5484 	    unless $here =~ m,^(?:\w:)?[\\/],;
 5485 	  # Keep track of the greatest timestamp.
 5486 	  if (-e $args[1])
 5487 	    {
 5488 	      my $mtime = mtime $args[1];
 5489 	      $configure_deps_greatest_timestamp = $mtime
 5490 		if $mtime > $configure_deps_greatest_timestamp;
 5491 	    }
 5492 	}
 5493       elsif ($macro eq 'LT_SUPPORTED_TAG')
 5494 	{
 5495 	  $libtool_tags{$args[1]} = 1;
 5496 	  $libtool_new_api = 1;
 5497 	}
 5498       elsif ($macro eq '_LT_AC_TAGCONFIG')
 5499 	{
 5500 	  # _LT_AC_TAGCONFIG is an old macro present in Libtool 1.5.
 5501 	  # We use it to detect whether tags are supported.  Our
 5502 	  # preferred interface is LT_SUPPORTED_TAG, but it was
 5503 	  # introduced in Libtool 1.6.
 5504 	  if (0 == keys %libtool_tags)
 5505 	    {
 5506 	      # Hardcode the tags supported by Libtool 1.5.
 5507 	      %libtool_tags = (CC => 1, CXX => 1, GCJ => 1, F77 => 1);
 5508 	    }
 5509 	}
 5510     }
 5511 
 5512   error ($where, "condition stack not properly closed")
 5513     if (@cond_stack);
 5514 
 5515   $tracefh->close;
 5516 }
 5517 
 5518 
 5519 # Check whether we use 'configure.ac' or 'configure.in'.
 5520 # Scan it (and possibly 'aclocal.m4') for interesting things.
 5521 # We must scan aclocal.m4 because there might be AC_SUBSTs and such there.
 5522 sub scan_autoconf_files ()
 5523 {
 5524   # Reinitialize libsources here.  This isn't really necessary,
 5525   # since we currently assume there is only one configure.ac.  But
 5526   # that won't always be the case.
 5527   %libsources = ();
 5528 
 5529   # Keep track of the youngest configure dependency.
 5530   $configure_deps_greatest_timestamp = mtime $configure_ac;
 5531   if (-e 'aclocal.m4')
 5532     {
 5533       my $mtime = mtime 'aclocal.m4';
 5534       $configure_deps_greatest_timestamp = $mtime
 5535 	if $mtime > $configure_deps_greatest_timestamp;
 5536     }
 5537 
 5538   scan_autoconf_traces ($configure_ac);
 5539 
 5540   @configure_input_files = sort keys %make_list;
 5541   # Set input and output files if not specified by user.
 5542   if (! @input_files)
 5543     {
 5544       @input_files = @configure_input_files;
 5545       %output_files = %make_list;
 5546     }
 5547 
 5548 
 5549   if (! $seen_init_automake)
 5550     {
 5551       err_ac ("no proper invocation of AM_INIT_AUTOMAKE was found.\nYou "
 5552 	      . "should verify that $configure_ac invokes AM_INIT_AUTOMAKE,"
 5553 	      . "\nthat aclocal.m4 is present in the top-level directory,\n"
 5554 	      . "and that aclocal.m4 was recently regenerated "
 5555 	      . "(using aclocal)");
 5556     }
 5557   else
 5558     {
 5559       if (! $seen_automake_version)
 5560 	{
 5561 	  if (-f 'aclocal.m4')
 5562 	    {
 5563 	      error ($seen_init_automake,
 5564 		     "your implementation of AM_INIT_AUTOMAKE comes from " .
 5565 		     "an\nold Automake version.  You should recreate " .
 5566 		     "aclocal.m4\nwith aclocal and run automake again",
 5567 		     # $? = 63 is used to indicate version mismatch to missing.
 5568 		     exit_code => 63);
 5569 	    }
 5570 	  else
 5571 	    {
 5572 	      error ($seen_init_automake,
 5573 		     "no proper implementation of AM_INIT_AUTOMAKE was " .
 5574 		     "found,\nprobably because aclocal.m4 is missing.\n" .
 5575 		     "You should run aclocal to create this file, then\n" .
 5576 		     "run automake again");
 5577 	    }
 5578 	}
 5579     }
 5580 
 5581   locate_aux_dir ();
 5582 
 5583   # Look for some files we need.  Always check for these.  This
 5584   # check must be done for every run, even those where we are only
 5585   # looking at a subdir Makefile.  We must set relative_dir for
 5586   # push_required_file to work.
 5587   # Sort the files for stable verbose output.
 5588   $relative_dir = '.';
 5589   foreach my $file (sort keys %required_aux_file)
 5590     {
 5591       require_conf_file ($required_aux_file{$file}->get, FOREIGN, $file)
 5592     }
 5593   err_am "'install.sh' is an anachronism; use 'install-sh' instead"
 5594     if -f $config_aux_dir . '/install.sh';
 5595 
 5596   # Preserve dist_common for later.
 5597   @configure_dist_common = @dist_common;
 5598 }
 5599 
 5600 ################################################################
 5601 
 5602 # Do any extra checking for GNU standards.
 5603 sub check_gnu_standards ()
 5604 {
 5605   if ($relative_dir eq '.')
 5606     {
 5607       # In top level (or only) directory.
 5608       require_file ("$am_file.am", GNU,
 5609 		    qw/INSTALL NEWS README AUTHORS ChangeLog/);
 5610 
 5611       # Accept one of these three licenses; default to COPYING.
 5612       # Make sure we do not overwrite an existing license.
 5613       my $license;
 5614       foreach (qw /COPYING COPYING.LIB COPYING.LESSER/)
 5615 	{
 5616 	  if (-f $_)
 5617 	    {
 5618 	      $license = $_;
 5619 	      last;
 5620 	    }
 5621 	}
 5622       require_file ("$am_file.am", GNU, 'COPYING')
 5623 	unless $license;
 5624     }
 5625 
 5626   for my $opt ('no-installman', 'no-installinfo')
 5627     {
 5628       msg ('error-gnu', option $opt,
 5629 	   "option '$opt' disallowed by GNU standards")
 5630 	if option $opt;
 5631     }
 5632 }
 5633 
 5634 # Do any extra checking for GNITS standards.
 5635 sub check_gnits_standards ()
 5636 {
 5637   if ($relative_dir eq '.')
 5638     {
 5639       # In top level (or only) directory.
 5640       require_file ("$am_file.am", GNITS, 'THANKS');
 5641     }
 5642 }
 5643 
 5644 ################################################################
 5645 #
 5646 # Functions to handle files of each language.
 5647 
 5648 # Each 'lang_X_rewrite($DIRECTORY, $BASE, $EXT)' function follows a
 5649 # simple formula: Return value is LANG_SUBDIR if the resulting object
 5650 # file should be in a subdir if the source file is, LANG_PROCESS if
 5651 # file is to be dealt with, LANG_IGNORE otherwise.
 5652 
 5653 # Much of the actual processing is handled in
 5654 # handle_single_transform.  These functions exist so that
 5655 # auxiliary information can be recorded for a later cleanup pass.
 5656 # Note that the calls to these functions are computed, so don't bother
 5657 # searching for their precise names in the source.
 5658 
 5659 # This is just a convenience function that can be used to determine
 5660 # when a subdir object should be used.
 5661 sub lang_sub_obj ()
 5662 {
 5663     return option 'subdir-objects' ? LANG_SUBDIR : LANG_PROCESS;
 5664 }
 5665 
 5666 # Rewrite a single header file.
 5667 sub lang_header_rewrite
 5668 {
 5669     # Header files are simply ignored.
 5670     return LANG_IGNORE;
 5671 }
 5672 
 5673 # Rewrite a single Vala source file.
 5674 sub lang_vala_rewrite
 5675 {
 5676     my ($directory, $base, $ext) = @_;
 5677 
 5678     (my $newext = $ext) =~ s/vala$/c/;
 5679     return (LANG_SUBDIR, $newext);
 5680 }
 5681 
 5682 # Rewrite a single yacc/yacc++ file.
 5683 sub lang_yacc_rewrite
 5684 {
 5685     my ($directory, $base, $ext) = @_;
 5686 
 5687     my $r = lang_sub_obj;
 5688     (my $newext = $ext) =~ tr/y/c/;
 5689     return ($r, $newext);
 5690 }
 5691 sub lang_yaccxx_rewrite { lang_yacc_rewrite (@_); };
 5692 
 5693 # Rewrite a single lex/lex++ file.
 5694 sub lang_lex_rewrite
 5695 {
 5696     my ($directory, $base, $ext) = @_;
 5697 
 5698     my $r = lang_sub_obj;
 5699     (my $newext = $ext) =~ tr/l/c/;
 5700     return ($r, $newext);
 5701 }
 5702 sub lang_lexxx_rewrite { lang_lex_rewrite (@_); };
 5703 
 5704 # Rewrite a single Java file.
 5705 sub lang_java_rewrite
 5706 {
 5707     return LANG_SUBDIR;
 5708 }
 5709 
 5710 # The lang_X_finish functions are called after all source file
 5711 # processing is done.  Each should handle defining rules for the
 5712 # language, etc.  A finish function is only called if a source file of
 5713 # the appropriate type has been seen.
 5714 
 5715 sub lang_vala_finish_target
 5716 {
 5717   my ($self, $name) = @_;
 5718 
 5719   my $derived = canonicalize ($name);
 5720   my $var = var "${derived}_SOURCES";
 5721   return unless $var;
 5722 
 5723   my @vala_sources = grep { /\.(vala|vapi)$/ } ($var->value_as_list_recursive);
 5724 
 5725   # For automake bug#11229.
 5726   return unless @vala_sources;
 5727 
 5728   foreach my $vala_file (@vala_sources)
 5729     {
 5730       my $c_file = $vala_file;
 5731       if ($c_file =~ s/(.*)\.vala$/$1.c/)
 5732         {
 5733           my $built_c_file = "\$(builddir)/$c_file";
 5734           my $built_dir = dirname $built_c_file;
 5735           my $base_c_file = basename $c_file;
 5736           $output_rules .= "$built_c_file: \$(builddir)/${derived}_vala.stamp\n"
 5737             . "\t\@if test ! -f \$@ && test \$(srcdir) != \$(builddir) && test -n \"\$\$(find -L \$(srcdir)/$c_file -prune -newer \$(srcdir)/$vala_file)\"; then cp -p \$(srcdir)/$c_file $built_c_file; fi\n"
 5738             . "\t\@if test -f \$@; then :; else rm -f \$(builddir)/${derived}_vala.stamp; fi\n"
 5739             . "\t\@if test -f \$@; then :; else \\\n"
 5740             . "\t  \$(MAKE) \$(AM_MAKEFLAGS) \$(builddir)/${derived}_vala.stamp; \\\n"
 5741             . "\t  if test $built_dir != .; then mv $base_c_file $built_dir/; fi \\\n"
 5742             . "\tfi\n";
 5743 	  $clean_files{$built_c_file} = DIST_CLEAN;
 5744 	  $clean_files{"\$(srcdir)/$c_file"} = MAINTAINER_CLEAN;
 5745         }
 5746     }
 5747 
 5748   # Add rebuild rules for generated header and vapi files
 5749   my $flags = var ($derived . '_VALAFLAGS');
 5750   if ($flags)
 5751     {
 5752       my $lastflag = '';
 5753       foreach my $flag ($flags->value_as_list_recursive)
 5754 	{
 5755 	  if (grep (/^$lastflag$/, ('-H', '-h', '--header', '--internal-header',
 5756 	                            '--vapi', '--internal-vapi', '--gir')))
 5757 	    {
 5758 	      my $headerfile = "\$(builddir)/$flag";
 5759 	      $output_rules .= "$headerfile: \$(builddir)/${derived}_vala.stamp\n"
 5760 		. "\t\@if test -f \$@; then :; else rm -f \$(builddir)/${derived}_vala.stamp; fi\n"
 5761 		. "\t\@if test -f \$@; then :; else \\\n"
 5762 		. "\t  \$(MAKE) \$(AM_MAKEFLAGS) \$(builddir)/${derived}_vala.stamp; \\\n"
 5763 		. "\tfi\n";
 5764 
 5765 	      # valac is not used when building from dist tarballs
 5766 	      # distribute the generated files
 5767 	      push_dist_common ($headerfile);
 5768 	      $clean_files{$headerfile} = MAINTAINER_CLEAN;
 5769 	    }
 5770 	  if (grep (/$lastflag/, ('--library')))
 5771 	    {
 5772 	      my $headerfile = "\$(builddir)/$flag";
 5773 	      $output_rules .= "$headerfile.vapi: \$(builddir)/${derived}_vala.stamp\n"
 5774 		. "\t\@if test -f \$@; then :; else rm -f \$(builddir)/${derived}_vala.stamp; fi\n"
 5775 		. "\t\@if test -f \$@; then :; else \\\n"
 5776 		. "\t  \$(MAKE) \$(AM_MAKEFLAGS) \$(builddir)/${derived}_vala.stamp; \\\n"
 5777 		. "\tfi\n";
 5778 
 5779 	      # valac is not used when building from dist tarballs
 5780 	      # distribute the generated files
 5781 	      my $vapi = "$headerfile.vapi";
 5782 	      push_dist_common ($vapi);
 5783 	      $clean_files{$headerfile.'.vapi'} = MAINTAINER_CLEAN;
 5784 	    }
 5785 	  $lastflag = $flag;
 5786 	}
 5787     }
 5788 
 5789   my $compile = $self->compile;
 5790 
 5791   # Rewrite each occurrence of 'AM_VALAFLAGS' in the compile
 5792   # rule into '${derived}_VALAFLAGS' if it exists.
 5793   my $val = "${derived}_VALAFLAGS";
 5794   $compile =~ s/\(AM_VALAFLAGS\)/\($val\)/
 5795     if set_seen ($val);
 5796 
 5797   # VALAFLAGS is a user variable (per GNU Standards),
 5798   # it should not be overridden in the Makefile...
 5799   check_user_variables 'VALAFLAGS';
 5800 
 5801   my $dirname = dirname ($name);
 5802 
 5803   # Only generate C code, do not run C compiler
 5804   $compile .= " -C";
 5805 
 5806   my $verbose = verbose_flag ('VALAC');
 5807   my $silent = silent_flag ();
 5808   my $stampfile = "\$(builddir)/${derived}_vala.stamp";
 5809 
 5810   $output_rules .=
 5811     "\$(builddir)/${derived}_vala.stamp: @vala_sources\n".
 5812 # Since the C files generated from the vala sources depend on the
 5813 # ${derived}_vala.stamp file, we must ensure its timestamp is older than
 5814 # those of the C files generated by the valac invocation below (this is
 5815 # especially important on systems with sub-second timestamp resolution).
 5816 # Thus we need to create the stamp file *before* invoking valac, and to
 5817 # move it to its final location only after valac has been invoked.
 5818     "\t${silent}rm -f \$\@ && echo stamp > \$\@-t\n".
 5819     "\t${verbose}$compile \$^\n".
 5820     "\t${silent}mv -f \$\@-t \$\@\n";
 5821 
 5822   push_dist_common ($stampfile);
 5823 
 5824   $clean_files{$stampfile} = MAINTAINER_CLEAN;
 5825 }
 5826 
 5827 # Add output rules to invoke valac and create stamp file as a witness
 5828 # to handle multiple outputs. This function is called after all source
 5829 # file processing is done.
 5830 sub lang_vala_finish ()
 5831 {
 5832   my ($self) = @_;
 5833 
 5834   foreach my $prog (keys %known_programs)
 5835     {
 5836       lang_vala_finish_target ($self, $prog);
 5837     }
 5838 
 5839   while (my ($name) = each %known_libraries)
 5840     {
 5841       lang_vala_finish_target ($self, $name);
 5842     }
 5843 }
 5844 
 5845 # The built .c files should be cleaned only on maintainer-clean
 5846 # as the .c files are distributed. This function is called for each
 5847 # .vala source file.
 5848 sub lang_vala_target_hook
 5849 {
 5850   my ($self, $aggregate, $output, $input, %transform) = @_;
 5851 
 5852   $clean_files{$output} = MAINTAINER_CLEAN;
 5853 }
 5854 
 5855 # This is a yacc helper which is called whenever we have decided to
 5856 # compile a yacc file.
 5857 sub lang_yacc_target_hook
 5858 {
 5859     my ($self, $aggregate, $output, $input, %transform) = @_;
 5860 
 5861     # If some relevant *YFLAGS variable contains the '-d' flag, we'll
 5862     # have to to generate special code.
 5863     my $yflags_contains_minus_d = 0;
 5864 
 5865     foreach my $pfx ("", "${aggregate}_")
 5866       {
 5867 	my $yflagsvar = var ("${pfx}YFLAGS");
 5868 	next unless $yflagsvar;
 5869 	# We cannot work reliably with conditionally-defined YFLAGS.
 5870 	if ($yflagsvar->has_conditional_contents)
 5871 	  {
 5872 	    msg_var ('unsupported', $yflagsvar,
 5873 	             "'${pfx}YFLAGS' cannot have conditional contents");
 5874 	  }
 5875 	else
 5876 	  {
 5877 	    $yflags_contains_minus_d = 1
 5878 	      if grep (/^-d$/, $yflagsvar->value_as_list_recursive);
 5879 	  }
 5880       }
 5881 
 5882     if ($yflags_contains_minus_d)
 5883       {
 5884 	# Found a '-d' that applies to the compilation of this file.
 5885 	# Add a dependency for the generated header file, and arrange
 5886 	# for that file to be included in the distribution.
 5887 
 5888 	# The extension of the output file (e.g., '.c' or '.cxx').
 5889 	# We'll need it to compute the name of the generated header file.
 5890 	(my $output_ext = basename ($output)) =~ s/.*(\.[^.]+)$/$1/;
 5891 
 5892 	# We know that a yacc input should be turned into either a C or
 5893 	# C++ output file.  We depend on this fact (here and in yacc.am),
 5894 	# so check that it really holds.
 5895 	my $lang = $languages{$extension_map{$output_ext}};
 5896 	prog_error "invalid output name '$output' for yacc file '$input'"
 5897 	  if (!$lang || ($lang->name ne 'c' && $lang->name ne 'cxx'));
 5898 
 5899 	(my $header_ext = $output_ext) =~ s/c/h/g;
 5900         # Quote $output_ext in the regexp, so that dots in it are taken
 5901         # as literal dots, not as metacharacters.
 5902 	(my $header = $output) =~ s/\Q$output_ext\E$/$header_ext/;
 5903 
 5904 	foreach my $cond (Automake::Rule::define (${header}, 'internal',
 5905 						  RULE_AUTOMAKE, TRUE,
 5906 						  INTERNAL))
 5907 	  {
 5908 	    my $condstr = $cond->subst_string;
 5909 	    $output_rules .=
 5910 	      "$condstr${header}: $output\n"
 5911 	      # Recover from removal of $header
 5912 	      . "$condstr\t\@if test ! -f \$@; then rm -f $output; else :; fi\n"
 5913 	      . "$condstr\t\@if test ! -f \$@; then \$(MAKE) \$(AM_MAKEFLAGS) $output; else :; fi\n";
 5914 	  }
 5915 	# Distribute the generated file, unless its .y source was
 5916 	# listed in a nodist_ variable.  (handle_source_transform()
 5917 	# will set DIST_SOURCE.)
 5918 	push_dist_common ($header)
 5919 	  if $transform{'DIST_SOURCE'};
 5920 
 5921 	# The GNU rules say that yacc/lex output files should be removed
 5922 	# by maintainer-clean.  However, if the files are not distributed,
 5923 	# then we want to remove them with "make clean"; otherwise,
 5924 	# "make distcheck" will fail.
 5925 	$clean_files{$header} = $transform{'DIST_SOURCE'} ? MAINTAINER_CLEAN : CLEAN;
 5926       }
 5927     # See the comment above for $HEADER.
 5928     $clean_files{$output} = $transform{'DIST_SOURCE'} ? MAINTAINER_CLEAN : CLEAN;
 5929 }
 5930 
 5931 # This is a lex helper which is called whenever we have decided to
 5932 # compile a lex file.
 5933 sub lang_lex_target_hook
 5934 {
 5935     my ($self, $aggregate, $output, $input, %transform) = @_;
 5936     # The GNU rules say that yacc/lex output files should be removed
 5937     # by maintainer-clean.  However, if the files are not distributed,
 5938     # then we want to remove them with "make clean"; otherwise,
 5939     # "make distcheck" will fail.
 5940     $clean_files{$output} = $transform{'DIST_SOURCE'} ? MAINTAINER_CLEAN : CLEAN;
 5941 }
 5942 
 5943 # This is a helper for both lex and yacc.
 5944 sub yacc_lex_finish_helper ()
 5945 {
 5946   return if defined $language_scratch{'lex-yacc-done'};
 5947   $language_scratch{'lex-yacc-done'} = 1;
 5948 
 5949   # FIXME: for now, no line number.
 5950   require_conf_file ($configure_ac, FOREIGN, 'ylwrap');
 5951   define_variable ('YLWRAP', "$am_config_aux_dir/ylwrap", INTERNAL);
 5952 }
 5953 
 5954 sub lang_yacc_finish ()
 5955 {
 5956   return if defined $language_scratch{'yacc-done'};
 5957   $language_scratch{'yacc-done'} = 1;
 5958 
 5959   reject_var 'YACCFLAGS', "'YACCFLAGS' obsolete; use 'YFLAGS' instead";
 5960 
 5961   yacc_lex_finish_helper;
 5962 }
 5963 
 5964 
 5965 sub lang_lex_finish ()
 5966 {
 5967   return if defined $language_scratch{'lex-done'};
 5968   $language_scratch{'lex-done'} = 1;
 5969 
 5970   yacc_lex_finish_helper;
 5971 }
 5972 
 5973 
 5974 # Given a hash table of linker names, pick the name that has the most
 5975 # precedence.  This is lame, but something has to have global
 5976 # knowledge in order to eliminate the conflict.  Add more linkers as
 5977 # required.
 5978 sub resolve_linker
 5979 {
 5980     my (%linkers) = @_;
 5981 
 5982     foreach my $l (qw(GCJLINK OBJCXXLINK CXXLINK F77LINK FCLINK OBJCLINK UPCLINK))
 5983     {
 5984 	return $l if defined $linkers{$l};
 5985     }
 5986     return 'LINK';
 5987 }
 5988 
 5989 # Called to indicate that an extension was used.
 5990 sub saw_extension
 5991 {
 5992     my ($ext) = @_;
 5993     $extension_seen{$ext} = 1;
 5994 }
 5995 
 5996 # register_language (%ATTRIBUTE)
 5997 # ------------------------------
 5998 # Register a single language.
 5999 # Each %ATTRIBUTE is of the form ATTRIBUTE => VALUE.
 6000 sub register_language
 6001 {
 6002   my (%option) = @_;
 6003 
 6004   # Set the defaults.
 6005   $option{'autodep'} = 'no'
 6006     unless defined $option{'autodep'};
 6007   $option{'linker'} = ''
 6008     unless defined $option{'linker'};
 6009   $option{'flags'} = []
 6010     unless defined $option{'flags'};
 6011   $option{'output_extensions'} = sub { return ( '.$(OBJEXT)', '.lo' ) }
 6012     unless defined $option{'output_extensions'};
 6013   $option{'nodist_specific'} = 0
 6014     unless defined $option{'nodist_specific'};
 6015 
 6016   my $lang = new Automake::Language (%option);
 6017 
 6018   # Fill indexes.
 6019   $extension_map{$_} = $lang->name foreach @{$lang->extensions};
 6020   $languages{$lang->name} = $lang;
 6021   my $link = $lang->linker;
 6022   if ($link)
 6023     {
 6024       if (exists $link_languages{$link})
 6025 	{
 6026 	  prog_error ("'$link' has different definitions in "
 6027 		      . $lang->name . " and " . $link_languages{$link}->name)
 6028 	    if $lang->link ne $link_languages{$link}->link;
 6029 	}
 6030       else
 6031 	{
 6032 	  $link_languages{$link} = $lang;
 6033 	}
 6034     }
 6035 
 6036   # Update the pattern of known extensions.
 6037   accept_extensions (@{$lang->extensions});
 6038 
 6039   # Update the suffix rules map.
 6040   foreach my $suffix (@{$lang->extensions})
 6041     {
 6042       foreach my $dest ($lang->output_extensions->($suffix))
 6043 	{
 6044 	  register_suffix_rule (INTERNAL, $suffix, $dest);
 6045 	}
 6046     }
 6047 }
 6048 
 6049 # derive_suffix ($EXT, $OBJ)
 6050 # --------------------------
 6051 # This function is used to find a path from a user-specified suffix $EXT
 6052 # to $OBJ or to some other suffix we recognize internally, e.g. 'cc'.
 6053 sub derive_suffix
 6054 {
 6055   my ($source_ext, $obj) = @_;
 6056 
 6057   while (!$extension_map{$source_ext} && $source_ext ne $obj)
 6058     {
 6059       my $new_source_ext = next_in_suffix_chain ($source_ext, $obj);
 6060       last if not defined $new_source_ext;
 6061       $source_ext = $new_source_ext;
 6062     }
 6063 
 6064   return $source_ext;
 6065 }
 6066 
 6067 
 6068 # Pretty-print something and append to '$output_rules'.
 6069 sub pretty_print_rule
 6070 {
 6071     $output_rules .= makefile_wrap (shift, shift, @_);
 6072 }
 6073 
 6074 
 6075 ################################################################
 6076 
 6077 
 6078 ## -------------------------------- ##
 6079 ## Handling the conditional stack.  ##
 6080 ## -------------------------------- ##
 6081 
 6082 
 6083 # $STRING
 6084 # make_conditional_string ($NEGATE, $COND)
 6085 # ----------------------------------------
 6086 sub make_conditional_string
 6087 {
 6088   my ($negate, $cond) = @_;
 6089   $cond = "${cond}_TRUE"
 6090     unless $cond =~ /^TRUE|FALSE$/;
 6091   $cond = Automake::Condition::conditional_negate ($cond)
 6092     if $negate;
 6093   return $cond;
 6094 }
 6095 
 6096 
 6097 my %_am_macro_for_cond =
 6098   (
 6099   AMDEP => "one of the compiler tests\n"
 6100 	   . "    AC_PROG_CC, AC_PROG_CXX, AC_PROG_OBJC, AC_PROG_OBJCXX,\n"
 6101 	   . "    AM_PROG_AS, AM_PROG_GCJ, AM_PROG_UPC",
 6102   am__fastdepCC => 'AC_PROG_CC',
 6103   am__fastdepCCAS => 'AM_PROG_AS',
 6104   am__fastdepCXX => 'AC_PROG_CXX',
 6105   am__fastdepGCJ => 'AM_PROG_GCJ',
 6106   am__fastdepOBJC => 'AC_PROG_OBJC',
 6107   am__fastdepOBJCXX => 'AC_PROG_OBJCXX',
 6108   am__fastdepUPC => 'AM_PROG_UPC'
 6109   );
 6110 
 6111 # $COND
 6112 # cond_stack_if ($NEGATE, $COND, $WHERE)
 6113 # --------------------------------------
 6114 sub cond_stack_if
 6115 {
 6116   my ($negate, $cond, $where) = @_;
 6117 
 6118   if (! $configure_cond{$cond} && $cond !~ /^TRUE|FALSE$/)
 6119     {
 6120       my $text = "$cond does not appear in AM_CONDITIONAL";
 6121       my $scope = US_LOCAL;
 6122       if (exists $_am_macro_for_cond{$cond})
 6123 	{
 6124 	  my $mac = $_am_macro_for_cond{$cond};
 6125 	  $text .= "\n  The usual way to define '$cond' is to add ";
 6126 	  $text .= ($mac =~ / /) ? $mac : "'$mac'";
 6127 	  $text .= "\n  to '$configure_ac' and run 'aclocal' and 'autoconf' again";
 6128 	  # These warnings appear in Automake files (depend2.am),
 6129 	  # so there is no need to display them more than once:
 6130 	  $scope = US_GLOBAL;
 6131 	}
 6132       error $where, $text, uniq_scope => $scope;
 6133     }
 6134 
 6135   push (@cond_stack, make_conditional_string ($negate, $cond));
 6136 
 6137   return new Automake::Condition (@cond_stack);
 6138 }
 6139 
 6140 
 6141 # $COND
 6142 # cond_stack_else ($NEGATE, $COND, $WHERE)
 6143 # ----------------------------------------
 6144 sub cond_stack_else
 6145 {
 6146   my ($negate, $cond, $where) = @_;
 6147 
 6148   if (! @cond_stack)
 6149     {
 6150       error $where, "else without if";
 6151       return FALSE;
 6152     }
 6153 
 6154   $cond_stack[$#cond_stack] =
 6155     Automake::Condition::conditional_negate ($cond_stack[$#cond_stack]);
 6156 
 6157   # If $COND is given, check against it.
 6158   if (defined $cond)
 6159     {
 6160       $cond = make_conditional_string ($negate, $cond);
 6161 
 6162       error ($where, "else reminder ($negate$cond) incompatible with "
 6163 	     . "current conditional: $cond_stack[$#cond_stack]")
 6164 	if $cond_stack[$#cond_stack] ne $cond;
 6165     }
 6166 
 6167   return new Automake::Condition (@cond_stack);
 6168 }
 6169 
 6170 
 6171 # $COND
 6172 # cond_stack_endif ($NEGATE, $COND, $WHERE)
 6173 # -----------------------------------------
 6174 sub cond_stack_endif
 6175 {
 6176   my ($negate, $cond, $where) = @_;
 6177   my $old_cond;
 6178 
 6179   if (! @cond_stack)
 6180     {
 6181       error $where, "endif without if";
 6182       return TRUE;
 6183     }
 6184 
 6185   # If $COND is given, check against it.
 6186   if (defined $cond)
 6187     {
 6188       $cond = make_conditional_string ($negate, $cond);
 6189 
 6190       error ($where, "endif reminder ($negate$cond) incompatible with "
 6191 	     . "current conditional: $cond_stack[$#cond_stack]")
 6192 	if $cond_stack[$#cond_stack] ne $cond;
 6193     }
 6194 
 6195   pop @cond_stack;
 6196 
 6197   return new Automake::Condition (@cond_stack);
 6198 }
 6199 
 6200 
 6201 
 6202 
 6203 
 6204 ## ------------------------ ##
 6205 ## Handling the variables.  ##
 6206 ## ------------------------ ##
 6207 
 6208 
 6209 # define_pretty_variable ($VAR, $COND, $WHERE, @VALUE)
 6210 # ----------------------------------------------------
 6211 # Like define_variable, but the value is a list, and the variable may
 6212 # be defined conditionally.  The second argument is the condition
 6213 # under which the value should be defined; this should be the empty
 6214 # string to define the variable unconditionally.  The third argument
 6215 # is a list holding the values to use for the variable.  The value is
 6216 # pretty printed in the output file.
 6217 sub define_pretty_variable
 6218 {
 6219     my ($var, $cond, $where, @value) = @_;
 6220 
 6221     if (! vardef ($var, $cond))
 6222     {
 6223 	Automake::Variable::define ($var, VAR_AUTOMAKE, '', $cond, "@value",
 6224 				    '', $where, VAR_PRETTY);
 6225 	rvar ($var)->rdef ($cond)->set_seen;
 6226     }
 6227 }
 6228 
 6229 
 6230 # define_variable ($VAR, $VALUE, $WHERE)
 6231 # --------------------------------------
 6232 # Define a new Automake Makefile variable VAR to VALUE, but only if
 6233 # not already defined.
 6234 sub define_variable
 6235 {
 6236     my ($var, $value, $where) = @_;
 6237     define_pretty_variable ($var, TRUE, $where, $value);
 6238 }
 6239 
 6240 
 6241 # define_files_variable ($VAR, \@BASENAME, $EXTENSION, $WHERE)
 6242 # ------------------------------------------------------------
 6243 # Define the $VAR which content is the list of file names composed of
 6244 # a @BASENAME and the $EXTENSION.
 6245 sub define_files_variable ($\@$$)
 6246 {
 6247   my ($var, $basename, $extension, $where) = @_;
 6248   define_variable ($var,
 6249 		   join (' ', map { "$_.$extension" } @$basename),
 6250 		   $where);
 6251 }
 6252 
 6253 
 6254 # Like define_variable, but define a variable to be the configure
 6255 # substitution by the same name.
 6256 sub define_configure_variable
 6257 {
 6258   my ($var) = @_;
 6259   # Some variables we do not want to output.  For instance it
 6260   # would be a bad idea to output `U = @U@` when `@U@` can be
 6261   # substituted as `\`.
 6262   my $pretty = exists $ignored_configure_vars{$var} ? VAR_SILENT : VAR_ASIS;
 6263   Automake::Variable::define ($var, VAR_CONFIGURE, '', TRUE, subst ($var),
 6264 			      '', $configure_vars{$var}, $pretty);
 6265 }
 6266 
 6267 
 6268 # define_compiler_variable ($LANG)
 6269 # --------------------------------
 6270 # Define a compiler variable.  We also handle defining the 'LT'
 6271 # version of the command when using libtool.
 6272 sub define_compiler_variable
 6273 {
 6274     my ($lang) = @_;
 6275 
 6276     my ($var, $value) = ($lang->compiler, $lang->compile);
 6277     my $libtool_tag = '';
 6278     $libtool_tag = '--tag=' . $lang->libtool_tag . ' '
 6279       if $lang->libtool_tag && exists $libtool_tags{$lang->libtool_tag};
 6280     define_variable ($var, $value, INTERNAL);
 6281     if (var ('LIBTOOL'))
 6282       {
 6283 	my $verbose = define_verbose_libtool ();
 6284 	define_variable ("LT$var",
 6285                          "\$(LIBTOOL) $verbose $libtool_tag\$(AM_LIBTOOLFLAGS)"
 6286                          . " \$(LIBTOOLFLAGS) --mode=compile $value",
 6287                          INTERNAL);
 6288       }
 6289     define_verbose_tagvar ($lang->ccer || 'GEN');
 6290 }
 6291 
 6292 
 6293 sub define_linker_variable
 6294 {
 6295     my ($lang) = @_;
 6296 
 6297     my $libtool_tag = '';
 6298     $libtool_tag = '--tag=' . $lang->libtool_tag . ' '
 6299       if $lang->libtool_tag && exists $libtool_tags{$lang->libtool_tag};
 6300     # CCLD = $(CC).
 6301     define_variable ($lang->lder, $lang->ld, INTERNAL);
 6302     # CCLINK = $(CCLD) blah blah...
 6303     my $link = '';
 6304     if (var ('LIBTOOL'))
 6305       {
 6306 	my $verbose = define_verbose_libtool ();
 6307 	$link = "\$(LIBTOOL) $verbose $libtool_tag\$(AM_LIBTOOLFLAGS) "
 6308 		. "\$(LIBTOOLFLAGS) --mode=link ";
 6309       }
 6310     define_variable ($lang->linker, $link . $lang->link, INTERNAL);
 6311     define_variable ($lang->compiler, $lang, INTERNAL);
 6312     define_verbose_tagvar ($lang->lder || 'GEN');
 6313 }
 6314 
 6315 sub define_per_target_linker_variable
 6316 {
 6317   my ($linker, $target) = @_;
 6318 
 6319   # If the user wrote a custom link command, we don't define ours.
 6320   return "${target}_LINK"
 6321     if set_seen "${target}_LINK";
 6322 
 6323   my $xlink = $linker ? $linker : 'LINK';
 6324 
 6325   my $lang = $link_languages{$xlink};
 6326   prog_error "Unknown language for linker variable '$xlink'"
 6327     unless $lang;
 6328 
 6329   my $link_command = $lang->link;
 6330   if (var 'LIBTOOL')
 6331     {
 6332       my $libtool_tag = '';
 6333       $libtool_tag = '--tag=' . $lang->libtool_tag . ' '
 6334 	if $lang->libtool_tag && exists $libtool_tags{$lang->libtool_tag};
 6335 
 6336       my $verbose = define_verbose_libtool ();
 6337       $link_command =
 6338 	"\$(LIBTOOL) $verbose $libtool_tag\$(AM_LIBTOOLFLAGS) \$(LIBTOOLFLAGS) "
 6339 	. "--mode=link " . $link_command;
 6340     }
 6341 
 6342   # Rewrite each occurrence of 'AM_$flag' in the link
 6343   # command into '${derived}_$flag' if it exists.
 6344   my $orig_command = $link_command;
 6345   my @flags = (@{$lang->flags}, 'LDFLAGS');
 6346   push @flags, 'LIBTOOLFLAGS' if var 'LIBTOOL';
 6347   for my $flag (@flags)
 6348     {
 6349       my $val = "${target}_$flag";
 6350       $link_command =~ s/\(AM_$flag\)/\($val\)/
 6351 	if set_seen ($val);
 6352     }
 6353 
 6354   # If the computed command is the same as the generic command, use
 6355   # the command linker variable.
 6356   return ($lang->linker, $lang->lder)
 6357     if $link_command eq $orig_command;
 6358 
 6359   define_variable ("${target}_LINK", $link_command, INTERNAL);
 6360   return ("${target}_LINK", $lang->lder);
 6361 }
 6362 
 6363 ################################################################
 6364 
 6365 # check_trailing_slash ($WHERE, $LINE)
 6366 # ------------------------------------
 6367 # Return 1 iff $LINE ends with a slash.
 6368 # Might modify $LINE.
 6369 sub check_trailing_slash ($\$)
 6370 {
 6371   my ($where, $line) = @_;
 6372 
 6373   # Ignore '##' lines.
 6374   return 0 if $$line =~ /$IGNORE_PATTERN/o;
 6375 
 6376   # Catch and fix a common error.
 6377   msg "syntax", $where, "whitespace following trailing backslash"
 6378     if $$line =~ s/\\\s+\n$/\\\n/;
 6379 
 6380   return $$line =~ /\\$/;
 6381 }
 6382 
 6383 
 6384 # read_am_file ($AMFILE, $WHERE, $RELDIR)
 6385 # ---------------------------------------
 6386 # Read $AMFILE file name which is located in $RELDIR, and set up
 6387 # global variables resetted by '&generate_makefile'.  Simultaneously
 6388 # copy lines from $AMFILE into '$output_trailer', or define variables
 6389 # as appropriate.
 6390 #
 6391 # NOTE: We put rules in the trailer section.  We want user rules to
 6392 # come after our generated stuff.
 6393 sub read_am_file
 6394 {
 6395     my ($amfile, $where, $reldir) = @_;
 6396     my $canon_reldir = &canonicalize ($reldir);
 6397 
 6398     my $am_file = new Automake::XFile ("< $amfile");
 6399     verb "reading $amfile";
 6400 
 6401     # Keep track of the youngest output dependency.
 6402     my $mtime = mtime $amfile;
 6403     $output_deps_greatest_timestamp = $mtime
 6404       if $mtime > $output_deps_greatest_timestamp;
 6405 
 6406     my $spacing = '';
 6407     my $comment = '';
 6408     my $blank = 0;
 6409     my $saw_bk = 0;
 6410     my $var_look = VAR_ASIS;
 6411 
 6412     use constant IN_VAR_DEF => 0;
 6413     use constant IN_RULE_DEF => 1;
 6414     use constant IN_COMMENT => 2;
 6415     my $prev_state = IN_RULE_DEF;
 6416 
 6417     while ($_ = $am_file->getline)
 6418     {
 6419 	$where->set ("$amfile:$.");
 6420 	if (/$IGNORE_PATTERN/o)
 6421 	{
 6422 	    # Merely delete comments beginning with two hashes.
 6423 	}
 6424 	elsif (/$WHITE_PATTERN/o)
 6425 	{
 6426 	    error $where, "blank line following trailing backslash"
 6427 	      if $saw_bk;
 6428 	    # Stick a single white line before the incoming macro or rule.
 6429 	    $spacing = "\n";
 6430 	    $blank = 1;
 6431 	    # Flush all comments seen so far.
 6432 	    if ($comment ne '')
 6433 	    {
 6434 		$output_vars .= $comment;
 6435 		$comment = '';
 6436 	    }
 6437 	}
 6438 	elsif (/$COMMENT_PATTERN/o)
 6439 	{
 6440 	    # Stick comments before the incoming macro or rule.  Make
 6441 	    # sure a blank line precedes the first block of comments.
 6442 	    $spacing = "\n" unless $blank;
 6443 	    $blank = 1;
 6444 	    $comment .= $spacing . $_;
 6445 	    $spacing = '';
 6446 	    $prev_state = IN_COMMENT;
 6447 	}
 6448 	else
 6449 	{
 6450 	    last;
 6451 	}
 6452 	$saw_bk = check_trailing_slash ($where, $_);
 6453     }
 6454 
 6455     # We save the conditional stack on entry, and then check to make
 6456     # sure it is the same on exit.  This lets us conditionally include
 6457     # other files.
 6458     my @saved_cond_stack = @cond_stack;
 6459     my $cond = new Automake::Condition (@cond_stack);
 6460 
 6461     my $last_var_name = '';
 6462     my $last_var_type = '';
 6463     my $last_var_value = '';
 6464     my $last_where;
 6465     # FIXME: shouldn't use $_ in this loop; it is too big.
 6466     while ($_)
 6467     {
 6468 	$where->set ("$amfile:$.");
 6469 
 6470 	# Make sure the line is \n-terminated.
 6471 	chomp;
 6472 	$_ .= "\n";
 6473 
 6474 	# Don't look at MAINTAINER_MODE_TRUE here.  That shouldn't be
 6475 	# used by users.  @MAINT@ is an anachronism now.
 6476 	$_ =~ s/\@MAINT\@//g
 6477 	    unless $seen_maint_mode;
 6478 
 6479 	my $new_saw_bk = check_trailing_slash ($where, $_);
 6480 
 6481 	if ($reldir eq '.')
 6482 	  {
 6483 	    # If present, eat the following '_' or '/', converting
 6484 	    # "%reldir%/foo" and "%canon_reldir%_foo" into plain "foo"
 6485 	    # when $reldir is '.'.
 6486 	    $_ =~ s,%(D|reldir)%/,,g;
 6487 	    $_ =~ s,%(C|canon_reldir)%_,,g;
 6488 	  }
 6489 	$_ =~ s/%(D|reldir)%/${reldir}/g;
 6490 	$_ =~ s/%(C|canon_reldir)%/${canon_reldir}/g;
 6491 
 6492 	if (/$IGNORE_PATTERN/o)
 6493 	{
 6494 	    # Merely delete comments beginning with two hashes.
 6495 
 6496 	    # Keep any backslash from the previous line.
 6497 	    $new_saw_bk = $saw_bk;
 6498 	}
 6499 	elsif (/$WHITE_PATTERN/o)
 6500 	{
 6501 	    # Stick a single white line before the incoming macro or rule.
 6502 	    $spacing = "\n";
 6503 	    error $where, "blank line following trailing backslash"
 6504 	      if $saw_bk;
 6505 	}
 6506 	elsif (/$COMMENT_PATTERN/o)
 6507 	{
 6508 	    error $where, "comment following trailing backslash"
 6509 	      if $saw_bk && $prev_state != IN_COMMENT;
 6510 
 6511 	    # Stick comments before the incoming macro or rule.
 6512 	    $comment .= $spacing . $_;
 6513 	    $spacing = '';
 6514 	    $prev_state = IN_COMMENT;
 6515 	}
 6516 	elsif ($saw_bk)
 6517 	{
 6518 	    if ($prev_state == IN_RULE_DEF)
 6519 	    {
 6520 	      my $cond = new Automake::Condition @cond_stack;
 6521 	      $output_trailer .= $cond->subst_string;
 6522 	      $output_trailer .= $_;
 6523 	    }
 6524 	    elsif ($prev_state == IN_COMMENT)
 6525 	    {
 6526 		# If the line doesn't start with a '#', add it.
 6527 		# We do this because a continued comment like
 6528 		#   # A = foo \
 6529 		#         bar \
 6530 		#         baz
 6531 		# is not portable.  BSD make doesn't honor
 6532 		# escaped newlines in comments.
 6533 		s/^#?/#/;
 6534 		$comment .= $spacing . $_;
 6535 	    }
 6536 	    else # $prev_state == IN_VAR_DEF
 6537 	    {
 6538 	      $last_var_value .= ' '
 6539 		unless $last_var_value =~ /\s$/;
 6540 	      $last_var_value .= $_;
 6541 
 6542 	      if (!/\\$/)
 6543 		{
 6544 		  Automake::Variable::define ($last_var_name, VAR_MAKEFILE,
 6545 					      $last_var_type, $cond,
 6546 					      $last_var_value, $comment,
 6547 					      $last_where, VAR_ASIS)
 6548 		    if $cond != FALSE;
 6549 		  $comment = $spacing = '';
 6550 		}
 6551 	    }
 6552 	}
 6553 
 6554 	elsif (/$IF_PATTERN/o)
 6555 	  {
 6556 	    $cond = cond_stack_if ($1, $2, $where);
 6557 	  }
 6558 	elsif (/$ELSE_PATTERN/o)
 6559 	  {
 6560 	    $cond = cond_stack_else ($1, $2, $where);
 6561 	  }
 6562 	elsif (/$ENDIF_PATTERN/o)
 6563 	  {
 6564 	    $cond = cond_stack_endif ($1, $2, $where);
 6565 	  }
 6566 
 6567 	elsif (/$RULE_PATTERN/o)
 6568 	{
 6569 	    # Found a rule.
 6570 	    $prev_state = IN_RULE_DEF;
 6571 
 6572 	    # For now we have to output all definitions of user rules
 6573 	    # and can't diagnose duplicates (see the comment in
 6574 	    # Automake::Rule::define). So we go on and ignore the return value.
 6575 	    Automake::Rule::define ($1, $amfile, RULE_USER, $cond, $where);
 6576 
 6577 	    check_variable_expansions ($_, $where);
 6578 
 6579 	    $output_trailer .= $comment . $spacing;
 6580 	    my $cond = new Automake::Condition @cond_stack;
 6581 	    $output_trailer .= $cond->subst_string;
 6582 	    $output_trailer .= $_;
 6583 	    $comment = $spacing = '';
 6584 	}
 6585 	elsif (/$ASSIGNMENT_PATTERN/o)
 6586 	{
 6587 	    # Found a macro definition.
 6588 	    $prev_state = IN_VAR_DEF;
 6589 	    $last_var_name = $1;
 6590 	    $last_var_type = $2;
 6591 	    $last_var_value = $3;
 6592 	    $last_where = $where->clone;
 6593 	    if ($3 ne '' && substr ($3, -1) eq "\\")
 6594 	      {
 6595 		# We preserve the '\' because otherwise the long lines
 6596 		# that are generated will be truncated by broken
 6597 		# 'sed's.
 6598 		$last_var_value = $3 . "\n";
 6599 	      }
 6600 	    # Normally we try to output variable definitions in the
 6601 	    # same format they were input.  However, POSIX compliant
 6602 	    # systems are not required to support lines longer than
 6603 	    # 2048 bytes (most notably, some sed implementation are
 6604 	    # limited to 4000 bytes, and sed is used by config.status
 6605 	    # to rewrite Makefile.in into Makefile).  Moreover nobody
 6606 	    # would really write such long lines by hand since it is
 6607 	    # hardly maintainable.  So if a line is longer that 1000
 6608 	    # bytes (an arbitrary limit), assume it has been
 6609 	    # automatically generated by some tools, and flatten the
 6610 	    # variable definition.  Otherwise, keep the variable as it
 6611 	    # as been input.
 6612 	    $var_look = VAR_PRETTY if length ($last_var_value) >= 1000;
 6613 
 6614 	    if (!/\\$/)
 6615 	      {
 6616 		Automake::Variable::define ($last_var_name, VAR_MAKEFILE,
 6617 					    $last_var_type, $cond,
 6618 					    $last_var_value, $comment,
 6619 					    $last_where, $var_look)
 6620 		  if $cond != FALSE;
 6621 		$comment = $spacing = '';
 6622 		$var_look = VAR_ASIS;
 6623 	      }
 6624 	}
 6625 	elsif (/$INCLUDE_PATTERN/o)
 6626 	{
 6627 	    my $path = $1;
 6628 
 6629 	    if ($path =~ s/^\$\(top_srcdir\)\///)
 6630 	      {
 6631 		push (@include_stack, "\$\(top_srcdir\)/$path");
 6632 		# Distribute any included file.
 6633 
 6634 		# Always use the $(top_srcdir) prefix in DIST_COMMON,
 6635 		# otherwise OSF make will implicitly copy the included
 6636 		# file in the build tree during "make distdir" to satisfy
 6637 		# the dependency.
 6638 		# (subdir-am-cond.sh and subdir-ac-cond.sh will fail)
 6639 		push_dist_common ("\$\(top_srcdir\)/$path");
 6640 	      }
 6641 	    else
 6642 	      {
 6643 		$path =~ s/\$\(srcdir\)\///;
 6644 		push (@include_stack, "\$\(srcdir\)/$path");
 6645 		# Always use the $(srcdir) prefix in DIST_COMMON,
 6646 		# otherwise OSF make will implicitly copy the included
 6647 		# file in the build tree during "make distdir" to satisfy
 6648 		# the dependency.
 6649 		# (subdir-am-cond.sh and subdir-ac-cond.sh will fail)
 6650 		push_dist_common ("\$\(srcdir\)/$path");
 6651 		$path = $relative_dir . "/" . $path if $relative_dir ne '.';
 6652 	      }
 6653 	    my $new_reldir = File::Spec->abs2rel ($path, $relative_dir);
 6654 	    $new_reldir = '.' if $new_reldir !~ s,/[^/]*$,,;
 6655 	    $where->push_context ("'$path' included from here");
 6656 	    read_am_file ($path, $where, $new_reldir);
 6657 	    $where->pop_context;
 6658 	}
 6659 	else
 6660 	{
 6661 	    # This isn't an error; it is probably a continued rule.
 6662 	    # In fact, this is what we assume.
 6663 	    $prev_state = IN_RULE_DEF;
 6664 	    check_variable_expansions ($_, $where);
 6665 	    $output_trailer .= $comment . $spacing;
 6666 	    my $cond = new Automake::Condition @cond_stack;
 6667 	    $output_trailer .= $cond->subst_string;
 6668 	    $output_trailer .= $_;
 6669 	    $comment = $spacing = '';
 6670 	    error $where, "'#' comment at start of rule is unportable"
 6671 	      if $_ =~ /^\t\s*\#/;
 6672 	}
 6673 
 6674 	$saw_bk = $new_saw_bk;
 6675 	$_ = $am_file->getline;
 6676     }
 6677 
 6678     $output_trailer .= $comment;
 6679 
 6680     error ($where, "trailing backslash on last line")
 6681       if $saw_bk;
 6682 
 6683     error ($where, (@cond_stack ? "unterminated conditionals: @cond_stack"
 6684 		    : "too many conditionals closed in include file"))
 6685       if "@saved_cond_stack" ne "@cond_stack";
 6686 }
 6687 
 6688 
 6689 # A helper for read_main_am_file which initializes configure variables
 6690 # and variables from header-vars.am.
 6691 sub define_standard_variables ()
 6692 {
 6693   my $saved_output_vars = $output_vars;
 6694   my ($comments, undef, $rules) =
 6695     file_contents_internal (1, "$libdir/am/header-vars.am",
 6696 			    new Automake::Location);
 6697 
 6698   foreach my $var (sort keys %configure_vars)
 6699     {
 6700       define_configure_variable ($var);
 6701     }
 6702 
 6703   $output_vars .= $comments . $rules;
 6704 }
 6705 
 6706 
 6707 # read_main_am_file ($MAKEFILE_AM, $MAKEFILE_IN)
 6708 # ----------------------------------------------
 6709 sub read_main_am_file
 6710 {
 6711     my ($amfile, $infile) = @_;
 6712 
 6713     # This supports the strange variable tricks we are about to play.
 6714     prog_error ("variable defined before read_main_am_file\n" . variables_dump ())
 6715       if (scalar (variables) > 0);
 6716 
 6717     # Generate copyright header for generated Makefile.in.
 6718     # We do discard the output of predefined variables, handled below.
 6719     $output_vars = ("# " . basename ($infile) . " generated by automake "
 6720 		   . $VERSION . " from " . basename ($amfile) . ".\n");
 6721     $output_vars .= '# ' . subst ('configure_input') . "\n";
 6722     $output_vars .= $gen_copyright;
 6723 
 6724     # We want to predefine as many variables as possible.  This lets
 6725     # the user set them with '+=' in Makefile.am.
 6726     define_standard_variables;
 6727 
 6728     # Read user file, which might override some of our values.
 6729     read_am_file ($amfile, new Automake::Location, '.');
 6730 }
 6731 
 6732 
 6733 
 6734 ################################################################
 6735 
 6736 # $STRING
 6737 # flatten ($ORIGINAL_STRING)
 6738 # --------------------------
 6739 sub flatten
 6740 {
 6741   $_ = shift;
 6742 
 6743   s/\\\n//somg;
 6744   s/\s+/ /g;
 6745   s/^ //;
 6746   s/ $//;
 6747 
 6748   return $_;
 6749 }
 6750 
 6751 
 6752 # transform_token ($TOKEN, \%PAIRS, $KEY)
 6753 # ---------------------------------------
 6754 # Return the value associated to $KEY in %PAIRS, as used on $TOKEN
 6755 # (which should be ?KEY? or any of the special %% requests)..
 6756 sub transform_token ($\%$)
 6757 {
 6758   my ($token, $transform, $key) = @_;
 6759   my $res = $transform->{$key};
 6760   prog_error "Unknown key '$key' in '$token'" unless defined $res;
 6761   return $res;
 6762 }
 6763 
 6764 
 6765 # transform ($TOKEN, \%PAIRS)
 6766 # ---------------------------
 6767 # If ($TOKEN, $VAL) is in %PAIRS:
 6768 #   - replaces %KEY% with $VAL,
 6769 #   - enables/disables ?KEY? and ?!KEY?,
 6770 #   - replaces %?KEY% with TRUE or FALSE.
 6771 sub transform ($\%)
 6772 {
 6773   my ($token, $transform) = @_;
 6774 
 6775   # %KEY%.
 6776   # Must be before the following pattern to exclude the case
 6777   # when there is neither IFTRUE nor IFFALSE.
 6778   if ($token =~ /^%([\w\-]+)%$/)
 6779     {
 6780       return transform_token ($token, %$transform, $1);
 6781     }
 6782   # %?KEY%.
 6783   elsif ($token =~ /^%\?([\w\-]+)%$/)
 6784     {
 6785       return transform_token ($token, %$transform, $1) ? 'TRUE' : 'FALSE';
 6786     }
 6787   # ?KEY? and ?!KEY?.
 6788   elsif ($token =~ /^ \? (!?) ([\w\-]+) \? $/x)
 6789     {
 6790       my $neg = ($1 eq '!') ? 1 : 0;
 6791       my $val = transform_token ($token, %$transform, $2);
 6792       return (!!$val == $neg) ? '##%' : '';
 6793     }
 6794   else
 6795     {
 6796       prog_error "Unknown request format: $token";
 6797     }
 6798 }
 6799 
 6800 # $TEXT
 6801 # preprocess_file ($MAKEFILE, [%TRANSFORM])
 6802 # -----------------------------------------
 6803 # Load a $MAKEFILE, apply the %TRANSFORM, and return the result.
 6804 # No extra parsing or post-processing is done (i.e., recognition of
 6805 # rules declaration or of make variables definitions).
 6806 sub preprocess_file
 6807 {
 6808   my ($file, %transform) = @_;
 6809 
 6810   # Complete %transform with global options.
 6811   # Note that %transform goes last, so it overrides global options.
 6812   %transform = ( 'MAINTAINER-MODE'
 6813 		 => $seen_maint_mode ? subst ('MAINTAINER_MODE_TRUE') : '',
 6814 
 6815 		 'XZ'          => !! option 'dist-xz',
 6816 		 'LZIP'        => !! option 'dist-lzip',
 6817 		 'BZIP2'       => !! option 'dist-bzip2',
 6818 		 'COMPRESS'    => !! option 'dist-tarZ',
 6819 		 'GZIP'        =>  ! option 'no-dist-gzip',
 6820 		 'SHAR'        => !! option 'dist-shar',
 6821 		 'ZIP'         => !! option 'dist-zip',
 6822 		 'ZSTD'        => !! option 'dist-zstd',
 6823 
 6824 		 'INSTALL-INFO' =>  ! option 'no-installinfo',
 6825 		 'INSTALL-MAN'  =>  ! option 'no-installman',
 6826 		 'CK-NEWS'      => !! option 'check-news',
 6827 
 6828 		 'SUBDIRS'      => !! var ('SUBDIRS'),
 6829 		 'TOPDIR_P'     => $relative_dir eq '.',
 6830 
 6831 		 'BUILD'    => ($seen_canonical >= AC_CANONICAL_BUILD),
 6832 		 'HOST'     => ($seen_canonical >= AC_CANONICAL_HOST),
 6833 		 'TARGET'   => ($seen_canonical >= AC_CANONICAL_TARGET),
 6834 
 6835 		 'LIBTOOL'      => !! var ('LIBTOOL'),
 6836 		 'NONLIBTOOL'   => 1,
 6837 		%transform);
 6838 
 6839   if (! defined ($_ = $am_file_cache{$file}))
 6840     {
 6841       verb "reading $file";
 6842       # Swallow the whole file.
 6843       my $fc_file = new Automake::XFile "< $file";
 6844       my $saved_dollar_slash = $/;
 6845       undef $/;
 6846       $_ = $fc_file->getline;
 6847       $/ = $saved_dollar_slash;
 6848       $fc_file->close;
 6849       # Remove ##-comments.
 6850       # Besides we don't need more than two consecutive new-lines.
 6851       s/(?:$IGNORE_PATTERN|(?<=\n\n)\n+)//gom;
 6852       # Remember the contents of the just-read file.
 6853       $am_file_cache{$file} = $_;
 6854     }
 6855 
 6856   # Substitute Automake template tokens.
 6857   s/(?: % \?? [\w\-]+ %
 6858       | \? !? [\w\-]+ \?
 6859     )/transform($&, %transform)/gex;
 6860   # transform() may have added some ##%-comments to strip.
 6861   # (we use '##%' instead of '##' so we can distinguish ##%##%##% from
 6862   # ####### and do not remove the latter.)
 6863   s/^[ \t]*(?:##%)+.*\n//gm;
 6864 
 6865   return $_;
 6866 }
 6867 
 6868 
 6869 # @PARAGRAPHS
 6870 # make_paragraphs ($MAKEFILE, [%TRANSFORM])
 6871 # -----------------------------------------
 6872 # Load a $MAKEFILE, apply the %TRANSFORM, and return it as a list of
 6873 # paragraphs.
 6874 sub make_paragraphs
 6875 {
 6876   my ($file, %transform) = @_;
 6877   $transform{FIRST} = !$transformed_files{$file};
 6878   $transformed_files{$file} = 1;
 6879 
 6880   my @lines = split /(?<!\\)\n/, preprocess_file ($file, %transform);
 6881   my @res;
 6882 
 6883   while (defined ($_ = shift @lines))
 6884     {
 6885       my $paragraph = $_;
 6886       # If we are a rule, eat as long as we start with a tab.
 6887       if (/$RULE_PATTERN/smo)
 6888 	{
 6889 	  while (defined ($_ = shift @lines) && $_ =~ /^\t/)
 6890 	    {
 6891 	      $paragraph .= "\n$_";
 6892 	    }
 6893 	  unshift (@lines, $_);
 6894 	}
 6895 
 6896       # If we are a comments, eat as much comments as you can.
 6897       elsif (/$COMMENT_PATTERN/smo)
 6898 	{
 6899 	  while (defined ($_ = shift @lines)
 6900 		 && $_ =~ /$COMMENT_PATTERN/smo)
 6901 	    {
 6902 	      $paragraph .= "\n$_";
 6903 	    }
 6904 	  unshift (@lines, $_);
 6905 	}
 6906 
 6907       push @res, $paragraph;
 6908     }
 6909 
 6910   return @res;
 6911 }
 6912 
 6913 
 6914 
 6915 # ($COMMENT, $VARIABLES, $RULES)
 6916 # file_contents_internal ($IS_AM, $FILE, $WHERE, [%TRANSFORM])
 6917 # ------------------------------------------------------------
 6918 # Return contents of a file from $libdir/am, automatically skipping
 6919 # macros or rules which are already known. $IS_AM iff the caller is
 6920 # reading an Automake file (as opposed to the user's Makefile.am).
 6921 sub file_contents_internal
 6922 {
 6923     my ($is_am, $file, $where, %transform) = @_;
 6924 
 6925     $where->set ($file);
 6926 
 6927     my $result_vars = '';
 6928     my $result_rules = '';
 6929     my $comment = '';
 6930     my $spacing = '';
 6931 
 6932     # The following flags are used to track rules spanning across
 6933     # multiple paragraphs.
 6934     my $is_rule = 0;		# 1 if we are processing a rule.
 6935     my $discard_rule = 0;	# 1 if the current rule should not be output.
 6936 
 6937     # We save the conditional stack on entry, and then check to make
 6938     # sure it is the same on exit.  This lets us conditionally include
 6939     # other files.
 6940     my @saved_cond_stack = @cond_stack;
 6941     my $cond = new Automake::Condition (@cond_stack);
 6942 
 6943     foreach (make_paragraphs ($file, %transform))
 6944     {
 6945 	# FIXME: no line number available.
 6946 	$where->set ($file);
 6947 
 6948 	# Sanity checks.
 6949 	error $where, "blank line following trailing backslash:\n$_"
 6950 	  if /\\$/;
 6951 	error $where, "comment following trailing backslash:\n$_"
 6952 	  if /\\#/;
 6953 
 6954 	if (/^$/)
 6955 	{
 6956 	    $is_rule = 0;
 6957 	    # Stick empty line before the incoming macro or rule.
 6958 	    $spacing = "\n";
 6959 	}
 6960 	elsif (/$COMMENT_PATTERN/mso)
 6961 	{
 6962 	    $is_rule = 0;
 6963 	    # Stick comments before the incoming macro or rule.
 6964 	    $comment = "$_\n";
 6965 	}
 6966 
 6967 	# Handle inclusion of other files.
 6968 	elsif (/$INCLUDE_PATTERN/o)
 6969 	{
 6970 	    if ($cond != FALSE)
 6971 	      {
 6972 		my $file = ($is_am ? "$libdir/am/" : '') . $1;
 6973 		$where->push_context ("'$file' included from here");
 6974 		# N-ary '.=' fails.
 6975 		my ($com, $vars, $rules)
 6976 		  = file_contents_internal ($is_am, $file, $where, %transform);
 6977 		$where->pop_context;
 6978 		$comment .= $com;
 6979 		$result_vars .= $vars;
 6980 		$result_rules .= $rules;
 6981 	      }
 6982 	}
 6983 
 6984 	# Handling the conditionals.
 6985 	elsif (/$IF_PATTERN/o)
 6986 	  {
 6987 	    $cond = cond_stack_if ($1, $2, $file);
 6988 	  }
 6989 	elsif (/$ELSE_PATTERN/o)
 6990 	  {
 6991 	    $cond = cond_stack_else ($1, $2, $file);
 6992 	  }
 6993 	elsif (/$ENDIF_PATTERN/o)
 6994 	  {
 6995 	    $cond = cond_stack_endif ($1, $2, $file);
 6996 	  }
 6997 
 6998 	# Handling rules.
 6999 	elsif (/$RULE_PATTERN/mso)
 7000 	{
 7001 	  $is_rule = 1;
 7002 	  $discard_rule = 0;
 7003 	  # Separate relationship from optional actions: the first
 7004 	  # `new-line tab" not preceded by backslash (continuation
 7005 	  # line).
 7006 	  my $paragraph = $_;
 7007 	  /^(.*?)(?:(?<!\\)\n(\t.*))?$/s;
 7008 	  my ($relationship, $actions) = ($1, $2 || '');
 7009 
 7010 	  # Separate targets from dependencies: the first colon.
 7011 	  $relationship =~ /^([^:]+\S+) *: *(.*)$/som;
 7012 	  my ($targets, $dependencies) = ($1, $2);
 7013 	  # Remove the escaped new lines.
 7014 	  # I don't know why, but I have to use a tmp $flat_deps.
 7015 	  my $flat_deps = flatten ($dependencies);
 7016 	  my @deps = split (' ', $flat_deps);
 7017 
 7018 	  foreach (split (' ', $targets))
 7019 	    {
 7020 	      # FIXME: 1. We are not robust to people defining several targets
 7021 	      # at once, only some of them being in %dependencies.  The
 7022 	      # actions from the targets in %dependencies are usually generated
 7023 	      # from the content of %actions, but if some targets in $targets
 7024 	      # are not in %dependencies the ELSE branch will output
 7025 	      # a rule for all $targets (i.e. the targets which are both
 7026 	      # in %dependencies and $targets will have two rules).
 7027 
 7028 	      # FIXME: 2. The logic here is not able to output a
 7029 	      # multi-paragraph rule several time (e.g. for each condition
 7030 	      # it is defined for) because it only knows the first paragraph.
 7031 
 7032 	      # FIXME: 3. We are not robust to people defining a subset
 7033 	      # of a previously defined "multiple-target" rule.  E.g.
 7034 	      # 'foo:' after 'foo bar:'.
 7035 
 7036 	      # Output only if not in FALSE.
 7037 	      if (defined $dependencies{$_} && $cond != FALSE)
 7038 		{
 7039 		  depend ($_, @deps);
 7040 		  register_action ($_, $actions);
 7041 		}
 7042 	      else
 7043 		{
 7044 		  # Free-lance dependency.  Output the rule for all the
 7045 		  # targets instead of one by one.
 7046 		  my @undefined_conds =
 7047 		    Automake::Rule::define ($targets, $file,
 7048 					    $is_am ? RULE_AUTOMAKE : RULE_USER,
 7049 					    $cond, $where);
 7050 		  for my $undefined_cond (@undefined_conds)
 7051 		    {
 7052 		      my $condparagraph = $paragraph;
 7053 		      $condparagraph =~ s/^/$undefined_cond->subst_string/gme;
 7054 		      $result_rules .= "$spacing$comment$condparagraph\n";
 7055 		    }
 7056 		  if (scalar @undefined_conds == 0)
 7057 		    {
 7058 		      # Remember to discard next paragraphs
 7059 		      # if they belong to this rule.
 7060 		      # (but see also FIXME: #2 above.)
 7061 		      $discard_rule = 1;
 7062 		    }
 7063 		  $comment = $spacing = '';
 7064 		  last;
 7065 		}
 7066 	    }
 7067 	}
 7068 
 7069 	elsif (/$ASSIGNMENT_PATTERN/mso)
 7070 	{
 7071 	    my ($var, $type, $val) = ($1, $2, $3);
 7072 	    error $where, "variable '$var' with trailing backslash"
 7073 	      if /\\$/;
 7074 
 7075 	    $is_rule = 0;
 7076 
 7077 	    Automake::Variable::define ($var,
 7078 					$is_am ? VAR_AUTOMAKE : VAR_MAKEFILE,
 7079 					$type, $cond, $val, $comment, $where,
 7080 					VAR_ASIS)
 7081 	      if $cond != FALSE;
 7082 
 7083 	    $comment = $spacing = '';
 7084 	}
 7085 	else
 7086 	{
 7087 	    # This isn't an error; it is probably some tokens which
 7088 	    # configure is supposed to replace, such as '@SET-MAKE@',
 7089 	    # or some part of a rule cut by an if/endif.
 7090 	    if (! $cond->false && ! ($is_rule && $discard_rule))
 7091 	      {
 7092 		s/^/$cond->subst_string/gme;
 7093 		$result_rules .= "$spacing$comment$_\n";
 7094 	      }
 7095 	    $comment = $spacing = '';
 7096 	}
 7097     }
 7098 
 7099     error ($where, @cond_stack ?
 7100 	   "unterminated conditionals: @cond_stack" :
 7101 	   "too many conditionals closed in include file")
 7102       if "@saved_cond_stack" ne "@cond_stack";
 7103 
 7104     return ($comment, $result_vars, $result_rules);
 7105 }
 7106 
 7107 
 7108 # $CONTENTS
 7109 # file_contents ($BASENAME, $WHERE, [%TRANSFORM])
 7110 # -----------------------------------------------
 7111 # Return contents of a file from $libdir/am, automatically skipping
 7112 # macros or rules which are already known.
 7113 sub file_contents
 7114 {
 7115     my ($basename, $where, %transform) = @_;
 7116     my ($comments, $variables, $rules) =
 7117       file_contents_internal (1, "$libdir/am/$basename.am", $where,
 7118 			      %transform);
 7119     return "$comments$variables$rules";
 7120 }
 7121 
 7122 
 7123 # @PREFIX
 7124 # am_primary_prefixes ($PRIMARY, $CAN_DIST, @PREFIXES)
 7125 # ----------------------------------------------------
 7126 # Find all variable prefixes that are used for install directories.  A
 7127 # prefix 'zar' qualifies iff:
 7128 #
 7129 # * 'zardir' is a variable.
 7130 # * 'zar_PRIMARY' is a variable.
 7131 #
 7132 # As a side effect, it looks for misspellings.  It is an error to have
 7133 # a variable ending in a "reserved" suffix whose prefix is unknown, e.g.
 7134 # "bni_PROGRAMS".  However, unusual prefixes are allowed if a variable
 7135 # of the same name (with "dir" appended) exists.  For instance, if the
 7136 # variable "zardir" is defined, then "zar_PROGRAMS" becomes valid.
 7137 # This is to provide a little extra flexibility in those cases which
 7138 # need it.
 7139 sub am_primary_prefixes
 7140 {
 7141   my ($primary, $can_dist, @prefixes) = @_;
 7142 
 7143   local $_;
 7144   my %valid = map { $_ => 0 } @prefixes;
 7145   $valid{'EXTRA'} = 0;
 7146   foreach my $var (variables $primary)
 7147     {
 7148       # Automake is allowed to define variables that look like primaries
 7149       # but which aren't.  E.g. INSTALL_sh_DATA.
 7150       # Autoconf can also define variables like INSTALL_DATA, so
 7151       # ignore all configure variables (at least those which are not
 7152       # redefined in Makefile.am).
 7153       # FIXME: We should make sure that these variables are not
 7154       # conditionally defined (or else adjust the condition below).
 7155       my $def = $var->def (TRUE);
 7156       next if $def && $def->owner != VAR_MAKEFILE;
 7157 
 7158       my $varname = $var->name;
 7159 
 7160       if ($varname =~ /^(nobase_)?(dist_|nodist_)?(.*)_[[:alnum:]]+$/)
 7161 	{
 7162 	  my ($base, $dist, $X) = ($1 || '', $2 || '', $3 || '');
 7163 	  if ($dist ne '' && ! $can_dist)
 7164 	    {
 7165 	      err_var ($var,
 7166 		       "invalid variable '$varname': 'dist' is forbidden");
 7167 	    }
 7168 	  # Standard directories must be explicitly allowed.
 7169 	  elsif (! defined $valid{$X} && exists $standard_prefix{$X})
 7170 	    {
 7171 	      err_var ($var,
 7172 		       "'${X}dir' is not a legitimate directory " .
 7173 		       "for '$primary'");
 7174 	    }
 7175 	  # A not explicitly valid directory is allowed if Xdir is defined.
 7176 	  elsif (! defined $valid{$X} &&
 7177 		 $var->requires_variables ("'$varname' is used", "${X}dir"))
 7178 	    {
 7179 	      # Nothing to do.  Any error message has been output
 7180 	      # by $var->requires_variables.
 7181 	    }
 7182 	  else
 7183 	    {
 7184 	      # Ensure all extended prefixes are actually used.
 7185 	      $valid{"$base$dist$X"} = 1;
 7186 	    }
 7187 	}
 7188       else
 7189 	{
 7190 	  prog_error "unexpected variable name: $varname";
 7191 	}
 7192     }
 7193 
 7194   # Return only those which are actually defined.
 7195   return sort grep { var ($_ . '_' . $primary) } keys %valid;
 7196 }
 7197 
 7198 
 7199 # am_install_var (-OPTION..., file, HOW, where...)
 7200 # ------------------------------------------------
 7201 #
 7202 # Handle 'where_HOW' variable magic.  Does all lookups, generates
 7203 # install code, and possibly generates code to define the primary
 7204 # variable.  The first argument is the name of the .am file to munge,
 7205 # the second argument is the primary variable (e.g. HEADERS), and all
 7206 # subsequent arguments are possible installation locations.
 7207 #
 7208 # Returns list of [$location, $value] pairs, where
 7209 # $value's are the values in all where_HOW variable, and $location
 7210 # there associated location (the place here their parent variables were
 7211 # defined).
 7212 #
 7213 # FIXME: this should be rewritten to be cleaner.  It should be broken
 7214 # up into multiple functions.
 7215 #
 7216 sub am_install_var
 7217 {
 7218   my (@args) = @_;
 7219 
 7220   my $do_require = 1;
 7221   my $can_dist = 0;
 7222   my $default_dist = 0;
 7223   while (@args)
 7224     {
 7225       if ($args[0] eq '-noextra')
 7226 	{
 7227 	  $do_require = 0;
 7228 	}
 7229       elsif ($args[0] eq '-candist')
 7230 	{
 7231 	  $can_dist = 1;
 7232 	}
 7233       elsif ($args[0] eq '-defaultdist')
 7234 	{
 7235 	  $default_dist = 1;
 7236 	  $can_dist = 1;
 7237 	}
 7238       elsif ($args[0] !~ /^-/)
 7239 	{
 7240 	  last;
 7241 	}
 7242       shift (@args);
 7243     }
 7244 
 7245   my ($file, $primary, @prefix) = @args;
 7246 
 7247   # Now that configure substitutions are allowed in where_HOW
 7248   # variables, it is an error to actually define the primary.  We
 7249   # allow 'JAVA', as it is customarily used to mean the Java
 7250   # interpreter.  This is but one of several Java hacks.  Similarly,
 7251   # 'PYTHON' is customarily used to mean the Python interpreter.
 7252   reject_var $primary, "'$primary' is an anachronism"
 7253     unless $primary eq 'JAVA' || $primary eq 'PYTHON';
 7254 
 7255   # Get the prefixes which are valid and actually used.
 7256   @prefix = am_primary_prefixes ($primary, $can_dist, @prefix);
 7257 
 7258   # If a primary includes a configure substitution, then the EXTRA_
 7259   # form is required.  Otherwise we can't properly do our job.
 7260   my $require_extra;
 7261 
 7262   my @used = ();
 7263   my @result = ();
 7264 
 7265   foreach my $X (@prefix)
 7266     {
 7267       my $nodir_name = $X;
 7268       my $one_name = $X . '_' . $primary;
 7269       my $one_var = var $one_name;
 7270 
 7271       my $strip_subdir = 1;
 7272       # If subdir prefix should be preserved, do so.
 7273       if ($nodir_name =~ /^nobase_/)
 7274 	{
 7275 	  $strip_subdir = 0;
 7276 	  $nodir_name =~ s/^nobase_//;
 7277 	}
 7278 
 7279       # If files should be distributed, do so.
 7280       my $dist_p = 0;
 7281       if ($can_dist)
 7282 	{
 7283 	  $dist_p = (($default_dist && $nodir_name !~ /^nodist_/)
 7284 		     || (! $default_dist && $nodir_name =~ /^dist_/));
 7285 	  $nodir_name =~ s/^(dist|nodist)_//;
 7286 	}
 7287 
 7288 
 7289       # Use the location of the currently processed variable.
 7290       # We are not processing a particular condition, so pick the first
 7291       # available.
 7292       my $tmpcond = $one_var->conditions->one_cond;
 7293       my $where = $one_var->rdef ($tmpcond)->location->clone;
 7294 
 7295       # Append actual contents of where_PRIMARY variable to
 7296       # @result, skipping @substitutions@.
 7297       foreach my $locvals ($one_var->value_as_list_recursive (location => 1))
 7298 	{
 7299 	  my ($loc, $value) = @$locvals;
 7300 	  # Skip configure substitutions.
 7301 	  if ($value =~ /^\@.*\@$/)
 7302 	    {
 7303 	      if ($nodir_name eq 'EXTRA')
 7304 		{
 7305 		  error ($where,
 7306 			 "'$one_name' contains configure substitution, "
 7307 			 . "but shouldn't");
 7308 		}
 7309 	      # Check here to make sure variables defined in
 7310 	      # configure.ac do not imply that EXTRA_PRIMARY
 7311 	      # must be defined.
 7312 	      elsif (! defined $configure_vars{$one_name})
 7313 		{
 7314 		  $require_extra = $one_name
 7315 		    if $do_require;
 7316 		}
 7317 	    }
 7318 	  else
 7319 	    {
 7320 	      # Strip any $(EXEEXT) suffix the user might have added,
 7321               # or this will confuse handle_source_transform() and
 7322               # check_canonical_spelling().
 7323 	      # We'll add $(EXEEXT) back later anyway.
 7324 	      # Do it here rather than in handle_programs so the
 7325               # uniquifying at the end of this function works.
 7326 	      ${$locvals}[1] =~ s/\$\(EXEEXT\)$//
 7327 	        if $primary eq 'PROGRAMS';
 7328 
 7329 	      push (@result, $locvals);
 7330 	    }
 7331 	}
 7332       # A blatant hack: we rewrite each _PROGRAMS primary to include
 7333       # EXEEXT.
 7334       append_exeext { 1 } $one_name
 7335 	if $primary eq 'PROGRAMS';
 7336       # "EXTRA" shouldn't be used when generating clean targets,
 7337       # all, or install targets.  We used to warn if EXTRA_FOO was
 7338       # defined uselessly, but this was annoying.
 7339       next
 7340 	if $nodir_name eq 'EXTRA';
 7341 
 7342       if ($nodir_name eq 'check')
 7343 	{
 7344 	  push (@check, '$(' . $one_name . ')');
 7345 	}
 7346       else
 7347 	{
 7348 	  push (@used, '$(' . $one_name . ')');
 7349 	}
 7350 
 7351       # Is this to be installed?
 7352       my $install_p = $nodir_name ne 'noinst' && $nodir_name ne 'check';
 7353 
 7354       # If so, with install-exec? (or install-data?).
 7355       my $exec_p = ($nodir_name =~ /$EXEC_DIR_PATTERN/o);
 7356 
 7357       my $check_options_p = $install_p && !! option 'std-options';
 7358 
 7359       # Use the location of the currently processed variable as context.
 7360       $where->push_context ("while processing '$one_name'");
 7361 
 7362       # The variable containing all files to distribute.
 7363       my $distvar = "\$($one_name)";
 7364       $distvar = shadow_unconditionally ($one_name, $where)
 7365 	if ($dist_p && $one_var->has_conditional_contents);
 7366 
 7367       # Singular form of $PRIMARY.
 7368       (my $one_primary = $primary) =~ s/S$//;
 7369       $output_rules .= file_contents ($file, $where,
 7370                                       PRIMARY     => $primary,
 7371                                       ONE_PRIMARY => $one_primary,
 7372                                       DIR         => $X,
 7373                                       NDIR        => $nodir_name,
 7374                                       BASE        => $strip_subdir,
 7375                                       EXEC        => $exec_p,
 7376                                       INSTALL     => $install_p,
 7377                                       DIST        => $dist_p,
 7378                                       DISTVAR     => $distvar,
 7379                                       'CK-OPTS'   => $check_options_p);
 7380     }
 7381 
 7382   # The JAVA variable is used as the name of the Java interpreter.
 7383   # The PYTHON variable is used as the name of the Python interpreter.
 7384   if (@used && $primary ne 'JAVA' && $primary ne 'PYTHON')
 7385     {
 7386       # Define it.
 7387       define_pretty_variable ($primary, TRUE, INTERNAL, @used);
 7388       $output_vars .= "\n";
 7389     }
 7390 
 7391   err_var ($require_extra,
 7392 	   "'$require_extra' contains configure substitution,\n"
 7393 	   . "but 'EXTRA_$primary' not defined")
 7394     if ($require_extra && ! var ('EXTRA_' . $primary));
 7395 
 7396   # Push here because PRIMARY might be configure time determined.
 7397   push (@all, '$(' . $primary . ')')
 7398     if @used && $primary ne 'JAVA' && $primary ne 'PYTHON';
 7399 
 7400   # Make the result unique.  This lets the user use conditionals in
 7401   # a natural way, but still lets us program lazily -- we don't have
 7402   # to worry about handling a particular object more than once.
 7403   # We will keep only one location per object.
 7404   my %result = ();
 7405   for my $pair (@result)
 7406     {
 7407       my ($loc, $val) = @$pair;
 7408       $result{$val} = $loc;
 7409     }
 7410   my @l = sort keys %result;
 7411   return map { [$result{$_}->clone, $_] } @l;
 7412 }
 7413 
 7414 
 7415 ################################################################
 7416 
 7417 # Each key in this hash is the name of a directory holding a
 7418 # Makefile.in.  These variables are local to 'is_make_dir'.
 7419 my %make_dirs = ();
 7420 my $make_dirs_set = 0;
 7421 
 7422 # is_make_dir ($DIRECTORY)
 7423 # ------------------------
 7424 sub is_make_dir
 7425 {
 7426     my ($dir) = @_;
 7427     if (! $make_dirs_set)
 7428     {
 7429 	foreach my $iter (@configure_input_files)
 7430 	{
 7431 	    $make_dirs{dirname ($iter)} = 1;
 7432 	}
 7433 	# We also want to notice Makefile.in's.
 7434 	foreach my $iter (@other_input_files)
 7435 	{
 7436 	    if ($iter =~ /Makefile\.in$/)
 7437 	    {
 7438 		$make_dirs{dirname ($iter)} = 1;
 7439 	    }
 7440 	}
 7441 	$make_dirs_set = 1;
 7442     }
 7443     return defined $make_dirs{$dir};
 7444 }
 7445 
 7446 ################################################################
 7447 
 7448 # Find the aux dir.  This should match the algorithm used by
 7449 # ./configure. (See the Autoconf documentation for for
 7450 # AC_CONFIG_AUX_DIR.)
 7451 sub locate_aux_dir ()
 7452 {
 7453   if (! $config_aux_dir_set_in_configure_ac)
 7454     {
 7455       # The default auxiliary directory is the first
 7456       # of ., .., or ../.. that contains install-sh.
 7457       # Assume . if install-sh doesn't exist yet.
 7458       for my $dir (qw (. .. ../..))
 7459 	{
 7460 	  if (-f "$dir/install-sh")
 7461 	    {
 7462 	      $config_aux_dir = $dir;
 7463 	      last;
 7464 	    }
 7465 	}
 7466       $config_aux_dir = '.' unless $config_aux_dir;
 7467     }
 7468   # Avoid unsightly '/.'s.
 7469   $am_config_aux_dir =
 7470     '$(top_srcdir)' . ($config_aux_dir eq '.' ? "" : "/$config_aux_dir");
 7471   $am_config_aux_dir =~ s,/*$,,;
 7472 }
 7473 
 7474 
 7475 # push_required_file ($DIR, $FILE, $FULLFILE)
 7476 # -------------------------------------------
 7477 # Push the given file onto DIST_COMMON.
 7478 sub push_required_file
 7479 {
 7480   my ($dir, $file, $fullfile) = @_;
 7481 
 7482   # If the file to be distributed is in the same directory of the
 7483   # currently processed Makefile.am, then we want to distribute it
 7484   # from this same Makefile.am.
 7485   if ($dir eq $relative_dir)
 7486     {
 7487       push_dist_common ($file);
 7488     }
 7489   # This is needed to allow a construct in a non-top-level Makefile.am
 7490   # to require a file in the build-aux directory (see at least the test
 7491   # script 'test-driver-is-distributed.sh').  This is related to the
 7492   # automake bug#9546.  Note that the use of $config_aux_dir instead
 7493   # of $am_config_aux_dir here is deliberate and necessary.
 7494   elsif ($dir eq $config_aux_dir)
 7495     {
 7496       push_dist_common ("$am_config_aux_dir/$file");
 7497     }
 7498   # FIXME: another spacial case, for AC_LIBOBJ/AC_LIBSOURCE support.
 7499   # We probably need some refactoring of this function and its callers,
 7500   # to have a more explicit and systematic handling of all the special
 7501   # cases; but, since there are only two of them, this is low-priority
 7502   # ATM.
 7503   elsif ($config_libobj_dir && $dir eq $config_libobj_dir)
 7504     {
 7505       # Avoid unsightly '/.'s.
 7506       my $am_config_libobj_dir =
 7507         '$(top_srcdir)' .
 7508         ($config_libobj_dir eq '.' ? "" : "/$config_libobj_dir");
 7509       $am_config_libobj_dir =~ s|/*$||;
 7510       push_dist_common ("$am_config_libobj_dir/$file");
 7511     }
 7512   elsif ($relative_dir eq '.' && ! is_make_dir ($dir))
 7513     {
 7514       # If we are doing the topmost directory, and the file is in a
 7515       # subdir which does not have a Makefile, then we distribute it
 7516       # here.
 7517 
 7518       # If a required file is above the source tree, it is important
 7519       # to prefix it with '$(srcdir)' so that no VPATH search is
 7520       # performed.  Otherwise problems occur with Make implementations
 7521       # that rewrite and simplify rules whose dependencies are found in a
 7522       # VPATH location.  Here is an example with OSF1/Tru64 Make.
 7523       #
 7524       #   % cat Makefile
 7525       #   VPATH = sub
 7526       #   distdir: ../a
 7527       #	          echo ../a
 7528       #   % ls
 7529       #   Makefile a
 7530       #   % make
 7531       #   echo a
 7532       #   a
 7533       #
 7534       # Dependency '../a' was found in 'sub/../a', but this make
 7535       # implementation simplified it as 'a'.  (Note that the sub/
 7536       # directory does not even exist.)
 7537       #
 7538       # This kind of VPATH rewriting seems hard to cancel.  The
 7539       # distdir.am hack against VPATH rewriting works only when no
 7540       # simplification is done, i.e., for dependencies which are in
 7541       # subdirectories, not in enclosing directories.  Hence, in
 7542       # the latter case we use a full path to make sure no VPATH
 7543       # search occurs.
 7544       $fullfile = '$(srcdir)/' . $fullfile
 7545 	if $dir =~ m,^\.\.(?:$|/),;
 7546 
 7547       push_dist_common ($fullfile);
 7548     }
 7549   else
 7550     {
 7551       prog_error "a Makefile in relative directory $relative_dir " .
 7552                  "can't add files in directory $dir to DIST_COMMON";
 7553     }
 7554 }
 7555 
 7556 
 7557 # If a file name appears as a key in this hash, then it has already
 7558 # been checked for.  This allows us not to report the same error more
 7559 # than once.
 7560 my %required_file_not_found = ();
 7561 
 7562 # required_file_check_or_copy ($WHERE, $DIRECTORY, $FILE)
 7563 # -------------------------------------------------------
 7564 # Verify that the file must exist in $DIRECTORY, or install it.
 7565 sub required_file_check_or_copy
 7566 {
 7567   my ($where, $dir, $file) = @_;
 7568 
 7569   my $fullfile = "$dir/$file";
 7570   my $found_it = 0;
 7571   my $dangling_sym = 0;
 7572 
 7573   if (-l $fullfile && ! -f $fullfile)
 7574     {
 7575       $dangling_sym = 1;
 7576     }
 7577   elsif (dir_has_case_matching_file ($dir, $file))
 7578     {
 7579       $found_it = 1;
 7580     }
 7581 
 7582   # '--force-missing' only has an effect if '--add-missing' is
 7583   # specified.
 7584   return
 7585     if $found_it && (! $add_missing || ! $force_missing);
 7586 
 7587   # If we've already looked for it, we're done.  You might wonder why we
 7588   # don't do this before searching for the file.  If we do that, then
 7589   # something like AC_OUTPUT([subdir/foo foo]) will fail to put 'foo.in'
 7590   # into $(DIST_COMMON).
 7591   if (! $found_it)
 7592     {
 7593       return if defined $required_file_not_found{$fullfile};
 7594       $required_file_not_found{$fullfile} = 1;
 7595     }
 7596   if ($dangling_sym && $add_missing)
 7597     {
 7598       unlink ($fullfile);
 7599     }
 7600 
 7601   my $trailer = '';
 7602   my $trailer2 = '';
 7603   my $suppress = 0;
 7604 
 7605   # Only install missing files according to our desired
 7606   # strictness level.
 7607   my $message = "required file '$fullfile' not found";
 7608   if ($add_missing)
 7609     {
 7610       if (-f "$libdir/$file")
 7611         {
 7612           $suppress = 1;
 7613 
 7614           # Install the missing file.  Symlink if we
 7615           # can, copy if we must.  Note: delete the file
 7616           # first, in case it is a dangling symlink.
 7617           $message = "installing '$fullfile'";
 7618 
 7619           # The license file should not be volatile.
 7620           if ($file eq "COPYING")
 7621             {
 7622               $message .= " using GNU General Public License v3 file";
 7623               $trailer2 = "\n    Consider adding the COPYING file"
 7624                         . " to the version control system"
 7625                         . "\n    for your code, to avoid questions"
 7626                         . " about which license your project uses";
 7627             }
 7628 
 7629           # Windows Perl will hang if we try to delete a
 7630           # file that doesn't exist.
 7631           unlink ($fullfile) if -f $fullfile;
 7632           if ($symlink_exists && ! $copy_missing)
 7633             {
 7634               if (! symlink ("$libdir/$file", $fullfile)
 7635                   || ! -e $fullfile)
 7636                 {
 7637                   $suppress = 0;
 7638                   $trailer = "; error while making link: $!";
 7639                 }
 7640             }
 7641           elsif (system ('cp', "$libdir/$file", $fullfile))
 7642             {
 7643               $suppress = 0;
 7644               $trailer = "\n    error while copying";
 7645             }
 7646           set_dir_cache_file ($dir, $file);
 7647         }
 7648     }
 7649   else
 7650     {
 7651       $trailer = "\n  'automake --add-missing' can install '$file'"
 7652         if -f "$libdir/$file";
 7653     }
 7654 
 7655   # If --force-missing was specified, and we have
 7656   # actually found the file, then do nothing.
 7657   return
 7658     if $found_it && $force_missing;
 7659 
 7660   # If we couldn't install the file, but it is a target in
 7661   # the Makefile, don't print anything.  This allows files
 7662   # like README, AUTHORS, or THANKS to be generated.
 7663   return
 7664     if !$suppress && rule $file;
 7665 
 7666   msg ($suppress ? 'note' : 'error', $where, "$message$trailer$trailer2");
 7667 }
 7668 
 7669 
 7670 # require_file_internal ($WHERE, $MYSTRICT, $DIRECTORY, $QUEUE, @FILES)
 7671 # ---------------------------------------------------------------------
 7672 # Verify that the file must exist in $DIRECTORY, or install it.
 7673 # $MYSTRICT is the strictness level at which this file becomes required.
 7674 # Worker threads may queue up the action to be serialized by the master,
 7675 # if $QUEUE is true
 7676 sub require_file_internal
 7677 {
 7678   my ($where, $mystrict, $dir, $queue, @files) = @_;
 7679 
 7680   return
 7681     unless $strictness >= $mystrict;
 7682 
 7683   foreach my $file (@files)
 7684     {
 7685       push_required_file ($dir, $file, "$dir/$file");
 7686       if ($queue)
 7687         {
 7688           queue_required_file_check_or_copy ($required_conf_file_queue,
 7689                                              QUEUE_CONF_FILE, $relative_dir,
 7690                                              $where, $mystrict, @files);
 7691         }
 7692       else
 7693         {
 7694           required_file_check_or_copy ($where, $dir, $file);
 7695         }
 7696     }
 7697 }
 7698 
 7699 # require_file ($WHERE, $MYSTRICT, @FILES)
 7700 # ----------------------------------------
 7701 sub require_file
 7702 {
 7703     my ($where, $mystrict, @files) = @_;
 7704     require_file_internal ($where, $mystrict, $relative_dir, 0, @files);
 7705 }
 7706 
 7707 # require_file_with_macro ($COND, $MACRO, $MYSTRICT, @FILES)
 7708 # ----------------------------------------------------------
 7709 sub require_file_with_macro
 7710 {
 7711     my ($cond, $macro, $mystrict, @files) = @_;
 7712     $macro = rvar ($macro) unless ref $macro;
 7713     require_file ($macro->rdef ($cond)->location, $mystrict, @files);
 7714 }
 7715 
 7716 # require_libsource_with_macro ($COND, $MACRO, $MYSTRICT, @FILES)
 7717 # ---------------------------------------------------------------
 7718 # Require an AC_LIBSOURCEd file.  If AC_CONFIG_LIBOBJ_DIR was called, it
 7719 # must be in that directory.  Otherwise expect it in the current directory.
 7720 sub require_libsource_with_macro
 7721 {
 7722     my ($cond, $macro, $mystrict, @files) = @_;
 7723     $macro = rvar ($macro) unless ref $macro;
 7724     if ($config_libobj_dir)
 7725       {
 7726 	require_file_internal ($macro->rdef ($cond)->location, $mystrict,
 7727 			       $config_libobj_dir, 0, @files);
 7728       }
 7729     else
 7730       {
 7731 	require_file ($macro->rdef ($cond)->location, $mystrict, @files);
 7732       }
 7733 }
 7734 
 7735 # queue_required_file_check_or_copy ($QUEUE, $KEY, $DIR, $WHERE,
 7736 #                                    $MYSTRICT, @FILES)
 7737 # --------------------------------------------------------------
 7738 sub queue_required_file_check_or_copy
 7739 {
 7740     my ($queue, $key, $dir, $where, $mystrict, @files) = @_;
 7741     my @serial_loc;
 7742     if (ref $where)
 7743       {
 7744         @serial_loc = (QUEUE_LOCATION, $where->serialize ());
 7745       }
 7746     else
 7747       {
 7748         @serial_loc = (QUEUE_STRING, $where);
 7749       }
 7750     $queue->enqueue ($key, $dir, @serial_loc, $mystrict, 0 + @files, @files);
 7751 }
 7752 
 7753 # require_queued_file_check_or_copy ($QUEUE)
 7754 # ------------------------------------------
 7755 sub require_queued_file_check_or_copy
 7756 {
 7757     my ($queue) = @_;
 7758     my $where;
 7759     my $dir = $queue->dequeue ();
 7760     my $loc_key = $queue->dequeue ();
 7761     if ($loc_key eq QUEUE_LOCATION)
 7762       {
 7763 	$where = Automake::Location::deserialize ($queue);
 7764       }
 7765     elsif ($loc_key eq QUEUE_STRING)
 7766       {
 7767 	$where = $queue->dequeue ();
 7768       }
 7769     else
 7770       {
 7771 	prog_error "unexpected key $loc_key";
 7772       }
 7773     my $mystrict = $queue->dequeue ();
 7774     my $nfiles = $queue->dequeue ();
 7775     my @files;
 7776     push @files, $queue->dequeue ()
 7777       foreach (1 .. $nfiles);
 7778     return
 7779       unless $strictness >= $mystrict;
 7780     foreach my $file (@files)
 7781       {
 7782         required_file_check_or_copy ($where, $config_aux_dir, $file);
 7783       }
 7784 }
 7785 
 7786 # require_conf_file ($WHERE, $MYSTRICT, @FILES)
 7787 # ---------------------------------------------
 7788 # Looks in configuration path, as specified by AC_CONFIG_AUX_DIR.
 7789 sub require_conf_file
 7790 {
 7791     my ($where, $mystrict, @files) = @_;
 7792     my $queue = defined $required_conf_file_queue ? 1 : 0;
 7793     require_file_internal ($where, $mystrict, $config_aux_dir,
 7794                            $queue, @files);
 7795 }
 7796 
 7797 
 7798 # require_conf_file_with_macro ($COND, $MACRO, $MYSTRICT, @FILES)
 7799 # ---------------------------------------------------------------
 7800 sub require_conf_file_with_macro
 7801 {
 7802     my ($cond, $macro, $mystrict, @files) = @_;
 7803     require_conf_file (rvar ($macro)->rdef ($cond)->location,
 7804 		       $mystrict, @files);
 7805 }
 7806 
 7807 ################################################################
 7808 
 7809 # require_build_directory ($DIRECTORY)
 7810 # ------------------------------------
 7811 # Emit rules to create $DIRECTORY if needed, and return
 7812 # the file that any target requiring this directory should be made
 7813 # dependent upon.
 7814 # We don't want to emit the rule twice, and want to reuse it
 7815 # for directories with equivalent names (e.g., 'foo/bar' and './foo//bar').
 7816 sub require_build_directory
 7817 {
 7818   my $directory = shift;
 7819 
 7820   return $directory_map{$directory} if exists $directory_map{$directory};
 7821 
 7822   my $cdir = File::Spec->canonpath ($directory);
 7823 
 7824   if (exists $directory_map{$cdir})
 7825     {
 7826       my $stamp = $directory_map{$cdir};
 7827       $directory_map{$directory} = $stamp;
 7828       return $stamp;
 7829     }
 7830 
 7831   my $dirstamp = "$cdir/\$(am__dirstamp)";
 7832 
 7833   $directory_map{$directory} = $dirstamp;
 7834   $directory_map{$cdir} = $dirstamp;
 7835 
 7836   # Set a variable for the dirstamp basename.
 7837   define_pretty_variable ('am__dirstamp', TRUE, INTERNAL,
 7838 			  '$(am__leading_dot)dirstamp');
 7839 
 7840   # Directory must be removed by 'make distclean'.
 7841   $clean_files{$dirstamp} = DIST_CLEAN;
 7842 
 7843   $output_rules .= ("$dirstamp:\n"
 7844 		    . "\t\@\$(MKDIR_P) $directory\n"
 7845 		    . "\t\@: > $dirstamp\n");
 7846 
 7847   return $dirstamp;
 7848 }
 7849 
 7850 # require_build_directory_maybe ($FILE)
 7851 # -------------------------------------
 7852 # If $FILE lies in a subdirectory, emit a rule to create this
 7853 # directory and return the file that $FILE should be made
 7854 # dependent upon.  Otherwise, just return the empty string.
 7855 sub require_build_directory_maybe
 7856 {
 7857     my $file = shift;
 7858     my $directory = dirname ($file);
 7859 
 7860     if ($directory ne '.')
 7861     {
 7862 	return require_build_directory ($directory);
 7863     }
 7864     else
 7865     {
 7866 	return '';
 7867     }
 7868 }
 7869 
 7870 ################################################################
 7871 
 7872 # Push a list of files onto '@dist_common'.
 7873 sub push_dist_common
 7874 {
 7875   prog_error "push_dist_common run after handle_dist"
 7876     if $handle_dist_run;
 7877   push @dist_common, @_;
 7878 }
 7879 
 7880 
 7881 ################################################################
 7882 
 7883 # generate_makefile ($MAKEFILE_AM, $MAKEFILE_IN)
 7884 # ----------------------------------------------
 7885 # Generate a Makefile.in given the name of the corresponding Makefile and
 7886 # the name of the file output by config.status.
 7887 sub generate_makefile
 7888 {
 7889   my ($makefile_am, $makefile_in) = @_;
 7890 
 7891   # Reset all the Makefile.am related variables.
 7892   initialize_per_input;
 7893 
 7894   # AUTOMAKE_OPTIONS can contains -W flags to disable or enable
 7895   # warnings for this file.  So hold any warning issued before
 7896   # we have processed AUTOMAKE_OPTIONS.
 7897   buffer_messages ('warning');
 7898 
 7899   # $OUTPUT is encoded.  If it contains a ":" then the first element
 7900   # is the real output file, and all remaining elements are input
 7901   # files.  We don't scan or otherwise deal with these input files,
 7902   # other than to mark them as dependencies.  See the subroutine
 7903   # 'scan_autoconf_files' for details.
 7904   my ($makefile, @inputs) = split (/:/, $output_files{$makefile_in});
 7905 
 7906   $relative_dir = dirname ($makefile);
 7907 
 7908   read_main_am_file ($makefile_am, $makefile_in);
 7909   if (not handle_options)
 7910     {
 7911       # Process buffered warnings.
 7912       flush_messages;
 7913       # Fatal error.  Just return, so we can continue with next file.
 7914       return;
 7915     }
 7916   # Process buffered warnings.
 7917   flush_messages;
 7918 
 7919   # There are a few install-related variables that you should not define.
 7920   foreach my $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
 7921     {
 7922       my $v = var $var;
 7923       if ($v)
 7924 	{
 7925 	  my $def = $v->def (TRUE);
 7926 	  prog_error "$var not defined in condition TRUE"
 7927 	    unless $def;
 7928 	  reject_var $var, "'$var' should not be defined"
 7929 	    if $def->owner != VAR_AUTOMAKE;
 7930 	}
 7931     }
 7932 
 7933   # Catch some obsolete variables.
 7934   msg_var ('obsolete', 'INCLUDES',
 7935 	   "'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')")
 7936     if var ('INCLUDES');
 7937 
 7938   # Must do this after reading .am file.
 7939   define_variable ('subdir', $relative_dir, INTERNAL);
 7940 
 7941   # If DIST_SUBDIRS is defined, make sure SUBDIRS is, so that
 7942   # recursive rules are enabled.
 7943   define_pretty_variable ('SUBDIRS', TRUE, INTERNAL, '')
 7944     if var 'DIST_SUBDIRS' && ! var 'SUBDIRS';
 7945 
 7946   # Check first, because we might modify some state.
 7947   check_gnu_standards;
 7948   check_gnits_standards;
 7949 
 7950   handle_configure ($makefile_am, $makefile_in, $makefile, @inputs);
 7951   handle_gettext;
 7952 
 7953   handle_targets;
 7954   handle_libraries;
 7955   handle_ltlibraries;
 7956   handle_programs;
 7957   handle_scripts;
 7958 
 7959   handle_silent;
 7960 
 7961   # These must be run after all the sources are scanned.  They use
 7962   # variables defined by handle_libraries(), handle_ltlibraries(),
 7963   # or handle_programs().
 7964   handle_compile;
 7965   handle_languages;
 7966   handle_libtool;
 7967 
 7968   # Variables used by distdir.am and tags.am.
 7969   define_pretty_variable ('SOURCES', TRUE, INTERNAL, @sources);
 7970   if (! option 'no-dist')
 7971     {
 7972       define_pretty_variable ('DIST_SOURCES', TRUE, INTERNAL, @dist_sources);
 7973     }
 7974 
 7975   handle_texinfo;
 7976   handle_emacs_lisp;
 7977   handle_python;
 7978   handle_java;
 7979   handle_man_pages;
 7980   handle_data;
 7981   handle_headers;
 7982   handle_subdirs;
 7983   handle_user_recursion;
 7984   handle_tags;
 7985   handle_minor_options;
 7986   # Must come after handle_programs so that %known_programs is up-to-date.
 7987   handle_tests;
 7988 
 7989   # This must come after most other rules.
 7990   handle_dist;
 7991 
 7992   handle_footer;
 7993   do_check_merge_target;
 7994   handle_all ($makefile);
 7995 
 7996   # FIXME: Gross!
 7997   if (var ('lib_LTLIBRARIES') && var ('bin_PROGRAMS'))
 7998     {
 7999       $output_rules .= "install-binPROGRAMS: install-libLTLIBRARIES\n\n";
 8000     }
 8001   if (var ('nobase_lib_LTLIBRARIES') && var ('bin_PROGRAMS'))
 8002     {
 8003       $output_rules .= "install-binPROGRAMS: install-nobase_libLTLIBRARIES\n\n";
 8004     }
 8005 
 8006   handle_install;
 8007   handle_clean ($makefile);
 8008   handle_factored_dependencies;
 8009 
 8010   # Comes last, because all the above procedures may have
 8011   # defined or overridden variables.
 8012   $output_vars .= output_variables;
 8013 
 8014   check_typos;
 8015 
 8016   if ($exit_code != 0)
 8017     {
 8018       verb "not writing $makefile_in because of earlier errors";
 8019       return;
 8020     }
 8021 
 8022   my $am_relative_dir = dirname ($makefile_am);
 8023   mkdir ($am_relative_dir, 0755) if ! -d $am_relative_dir;
 8024 
 8025   # We make sure that 'all:' is the first target.
 8026   my $output =
 8027     "$output_vars$output_all$output_header$output_rules$output_trailer";
 8028 
 8029   # Decide whether we must update the output file or not.
 8030   # We have to update in the following situations.
 8031   #  * $force_generation is set.
 8032   #  * any of the output dependencies is younger than the output
 8033   #  * the contents of the output is different (this can happen
 8034   #    if the project has been populated with a file listed in
 8035   #    @common_files since the last run).
 8036   # Output's dependencies are split in two sets:
 8037   #  * dependencies which are also configure dependencies
 8038   #    These do not change between each Makefile.am
 8039   #  * other dependencies, specific to the Makefile.am being processed
 8040   #    (such as the Makefile.am itself, or any Makefile fragment
 8041   #    it includes).
 8042   my $timestamp = mtime $makefile_in;
 8043   if (! $force_generation
 8044       && $configure_deps_greatest_timestamp < $timestamp
 8045       && $output_deps_greatest_timestamp < $timestamp
 8046       && $output eq contents ($makefile_in))
 8047     {
 8048       verb "$makefile_in unchanged";
 8049       # No need to update.
 8050       return;
 8051     }
 8052 
 8053   if (-e $makefile_in)
 8054     {
 8055       unlink ($makefile_in)
 8056 	or fatal "cannot remove $makefile_in: $!";
 8057     }
 8058 
 8059   my $gm_file = new Automake::XFile "> $makefile_in";
 8060   verb "creating $makefile_in";
 8061   print $gm_file $output;
 8062 }
 8063 
 8064 
 8065 ################################################################
 8066 
 8067 
 8068 # Helper function for usage().
 8069 sub print_autodist_files
 8070 {
 8071   my @lcomm = uniq (sort @_);
 8072 
 8073   my @four;
 8074   format USAGE_FORMAT =
 8075   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
 8076   $four[0],           $four[1],           $four[2],           $four[3]
 8077 .
 8078   local $~ = "USAGE_FORMAT";
 8079 
 8080   my $cols = 4;
 8081   my $rows = int(@lcomm / $cols);
 8082   my $rest = @lcomm % $cols;
 8083 
 8084   if ($rest)
 8085     {
 8086       $rows++;
 8087     }
 8088   else
 8089     {
 8090       $rest = $cols;
 8091     }
 8092 
 8093   for (my $y = 0; $y < $rows; $y++)
 8094     {
 8095       @four = ("", "", "", "");
 8096       for (my $x = 0; $x < $cols; $x++)
 8097         {
 8098           last if $y + 1 == $rows && $x == $rest;
 8099 
 8100           my $idx = (($x > $rest)
 8101                ?  ($rows * $rest + ($rows - 1) * ($x - $rest))
 8102                : ($rows * $x));
 8103 
 8104           $idx += $y;
 8105           $four[$x] = $lcomm[$idx];
 8106         }
 8107       write;
 8108     }
 8109 }
 8110 
 8111 
 8112 sub usage ()
 8113 {
 8114     print "Usage: $0 [OPTION]... [Makefile]...
 8115 
 8116 Generate Makefile.in for configure from Makefile.am.
 8117 
 8118 Operation modes:
 8119       --help               print this help, then exit
 8120       --version            print version number, then exit
 8121   -v, --verbose            verbosely list files processed
 8122       --no-force           only update Makefile.in's that are out of date
 8123   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY
 8124 
 8125 Dependency tracking:
 8126   -i, --ignore-deps      disable dependency tracking code
 8127       --include-deps     enable dependency tracking code
 8128 
 8129 Flavors:
 8130       --foreign          set strictness to foreign
 8131       --gnits            set strictness to gnits
 8132       --gnu              set strictness to gnu
 8133 
 8134 Library files:
 8135   -a, --add-missing      add missing standard files to package
 8136       --libdir=DIR       set directory storing library files
 8137       --print-libdir     print directory storing library files
 8138   -c, --copy             with -a, copy missing files (default is symlink)
 8139   -f, --force-missing    force update of standard files
 8140 
 8141 ";
 8142     print Automake::ChannelDefs::usage (), "\n";
 8143 
 8144     print "\nFiles automatically distributed if found " .
 8145           "(always):\n";
 8146     print_autodist_files @common_files;
 8147     print "\nFiles automatically distributed if found " .
 8148           "(under certain conditions):\n";
 8149     print_autodist_files @common_sometimes;
 8150 
 8151     print '
 8152 Report bugs to <@PACKAGE_BUGREPORT@>.
 8153 GNU Automake home page: <@PACKAGE_URL@>.
 8154 General help using GNU software: <https://www.gnu.org/gethelp/>.
 8155 ';
 8156 
 8157     # --help always returns 0 per GNU standards.
 8158     exit 0;
 8159 }
 8160 
 8161 
 8162 sub version ()
 8163 {
 8164   print <<EOF;
 8165 automake (GNU $PACKAGE) $VERSION
 8166 Copyright (C) $RELEASE_YEAR Free Software Foundation, Inc.
 8167 License GPLv2+: GNU GPL version 2 or later <https://gnu.org/licenses/gpl-2.0.html>
 8168 This is free software: you are free to change and redistribute it.
 8169 There is NO WARRANTY, to the extent permitted by law.
 8170 
 8171 Written by Tom Tromey <tromey\@redhat.com>
 8172        and Alexandre Duret-Lutz <adl\@gnu.org>.
 8173 EOF
 8174   # --version always returns 0 per GNU standards.
 8175   exit 0;
 8176 }
 8177 
 8178 ################################################################
 8179 
 8180 # Parse command line.
 8181 sub parse_arguments ()
 8182 {
 8183   my $strict = 'gnu';
 8184   my $ignore_deps = 0;
 8185   my @warnings = ();
 8186 
 8187   my %cli_options =
 8188     (
 8189      'version' => \&version,
 8190      'help'    => \&usage,
 8191      'libdir=s'	=> \$libdir,
 8192      'print-libdir'     => sub { print "$libdir\n"; exit 0; },
 8193      'gnu'		=> sub { $strict = 'gnu'; },
 8194      'gnits'		=> sub { $strict = 'gnits'; },
 8195      'foreign'		=> sub { $strict = 'foreign'; },
 8196      'include-deps'	=> sub { $ignore_deps = 0; },
 8197      'i|ignore-deps'	=> sub { $ignore_deps = 1; },
 8198      'no-force'	=> sub { $force_generation = 0; },
 8199      'f|force-missing'  => \$force_missing,
 8200      'a|add-missing'	=> \$add_missing,
 8201      'c|copy'		=> \$copy_missing,
 8202      'v|verbose'	=> sub { setup_channel 'verb', silent => 0; },
 8203      'W|warnings=s'     => \@warnings,
 8204      );
 8205 
 8206   use Automake::Getopt ();
 8207   Automake::Getopt::parse_options %cli_options;
 8208 
 8209   set_strictness ($strict);
 8210   my $cli_where = new Automake::Location;
 8211   set_global_option ('no-dependencies', $cli_where) if $ignore_deps;
 8212   parse_warnings @warnings;
 8213 
 8214   return unless @ARGV;
 8215 
 8216   my $errspec = 0;
 8217   foreach my $arg (@ARGV)
 8218     {
 8219       fatal ("empty argument\nTry '$0 --help' for more information")
 8220 	if ($arg eq '');
 8221 
 8222       # Handle $local:$input syntax.
 8223       my ($local, @rest) = split (/:/, $arg);
 8224       @rest = ("$local.in",) unless @rest;
 8225       my $input = locate_am @rest;
 8226       if ($input)
 8227 	{
 8228 	  push @input_files, $input;
 8229 	  $output_files{$input} = join (':', ($local, @rest));
 8230 	}
 8231       else
 8232 	{
 8233 	  error "no Automake input file found for '$arg'";
 8234 	  $errspec = 1;
 8235 	}
 8236     }
 8237   fatal "no input file found among supplied arguments"
 8238     if $errspec && ! @input_files;
 8239 }
 8240 
 8241 
 8242 # handle_makefile ($MAKEFILE)
 8243 # ---------------------------
 8244 sub handle_makefile
 8245 {
 8246   my ($file) =  @_;
 8247   ($am_file = $file) =~ s/\.in$//;
 8248   if (! -f ($am_file . '.am'))
 8249     {
 8250       error "'$am_file.am' does not exist";
 8251     }
 8252   else
 8253     {
 8254       # Any warning setting now local to this Makefile.am.
 8255       dup_channel_setup;
 8256 
 8257       generate_makefile ($am_file . '.am', $file);
 8258 
 8259       # Back out any warning setting.
 8260       drop_channel_setup;
 8261     }
 8262 }
 8263 
 8264 # Deal with all makefiles, without threads.
 8265 sub handle_makefiles_serial ()
 8266 {
 8267   foreach my $file (@input_files)
 8268     {
 8269       handle_makefile ($file);
 8270     }
 8271 }
 8272 
 8273 # Logic for deciding how many worker threads to use.
 8274 sub get_number_of_threads ()
 8275 {
 8276   my $nthreads = $ENV{'AUTOMAKE_JOBS'} || 0;
 8277 
 8278   $nthreads = 0
 8279     unless $nthreads =~ /^[0-9]+$/;
 8280 
 8281   # It doesn't make sense to use more threads than makefiles,
 8282   my $max_threads = @input_files;
 8283 
 8284   if ($nthreads > $max_threads)
 8285     {
 8286       $nthreads = $max_threads;
 8287     }
 8288   return $nthreads;
 8289 }
 8290 
 8291 # handle_makefiles_threaded ($NTHREADS)
 8292 # -------------------------------------
 8293 # Deal with all makefiles, using threads.  The general strategy is to
 8294 # spawn NTHREADS worker threads, dispatch makefiles to them, and let the
 8295 # worker threads push back everything that needs serialization:
 8296 # * warning and (normal) error messages, for stable stderr output
 8297 #   order and content (avoiding duplicates, for example),
 8298 # * races when installing aux files (and respective messages),
 8299 # * races when collecting aux files for distribution.
 8300 #
 8301 # The latter requires that the makefile that deals with the aux dir
 8302 # files be handled last, done by the master thread.
 8303 sub handle_makefiles_threaded
 8304 {
 8305   my ($nthreads) = @_;
 8306 
 8307   # The file queue distributes all makefiles, the message queues
 8308   # collect all serializations needed for respective files.
 8309   my $file_queue = Thread::Queue->new;
 8310   my %msg_queues;
 8311   foreach my $file (@input_files)
 8312     {
 8313       $msg_queues{$file} = Thread::Queue->new;
 8314     }
 8315 
 8316   verb "spawning $nthreads worker threads";
 8317   my @threads = (1 .. $nthreads);
 8318   foreach my $t (@threads)
 8319     {
 8320       $t = threads->new (sub
 8321 	{
 8322 	  while (my $file = $file_queue->dequeue)
 8323 	    {
 8324 	      verb "handling $file";
 8325 	      my $queue = $msg_queues{$file};
 8326 	      setup_channel_queue ($queue, QUEUE_MESSAGE);
 8327 	      $required_conf_file_queue = $queue;
 8328 	      handle_makefile ($file);
 8329 	      $queue->enqueue (undef);
 8330 	      setup_channel_queue (undef, undef);
 8331 	      $required_conf_file_queue = undef;
 8332 	    }
 8333 	  return $exit_code;
 8334 	});
 8335     }
 8336 
 8337   # Queue all makefiles.
 8338   verb "queuing " . @input_files . " input files";
 8339   $file_queue->enqueue (@input_files, (undef) x @threads);
 8340 
 8341   # Collect and process serializations.
 8342   foreach my $file (@input_files)
 8343     {
 8344       verb "dequeuing messages for " . $file;
 8345       reset_local_duplicates ();
 8346       my $queue = $msg_queues{$file};
 8347       while (my $key = $queue->dequeue)
 8348 	{
 8349 	  if ($key eq QUEUE_MESSAGE)
 8350 	    {
 8351 	      pop_channel_queue ($queue);
 8352 	    }
 8353 	  elsif ($key eq QUEUE_CONF_FILE)
 8354 	    {
 8355 	      require_queued_file_check_or_copy ($queue);
 8356 	    }
 8357 	  else
 8358 	    {
 8359 	      prog_error "unexpected key $key";
 8360 	    }
 8361 	}
 8362     }
 8363 
 8364   foreach my $t (@threads)
 8365     {
 8366       my @exit_thread = $t->join;
 8367       $exit_code = $exit_thread[0]
 8368 	if ($exit_thread[0] > $exit_code);
 8369     }
 8370 }
 8371 
 8372 ################################################################
 8373 
 8374 # Parse the WARNINGS environment variable.
 8375 parse_WARNINGS;
 8376 
 8377 # Parse command line.
 8378 parse_arguments;
 8379 
 8380 $configure_ac = require_configure_ac;
 8381 
 8382 # Do configure.ac scan only once.
 8383 scan_autoconf_files;
 8384 
 8385 if (! @input_files)
 8386   {
 8387     my $msg = '';
 8388     $msg = "\nDid you forget AC_CONFIG_FILES([Makefile]) in $configure_ac?"
 8389       if -f 'Makefile.am';
 8390     fatal ("no 'Makefile.am' found for any configure output$msg");
 8391   }
 8392 
 8393 my $nthreads = get_number_of_threads ();
 8394 
 8395 if ($perl_threads && $nthreads >= 1)
 8396   {
 8397     handle_makefiles_threaded ($nthreads);
 8398   }
 8399 else
 8400   {
 8401     handle_makefiles_serial ();
 8402   }
 8403 
 8404 exit $exit_code;