#!/usr/bin/perl
# -*- perl -*-
# Generated automatically from automake.in by configure.

eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
    if 0;

# automake - create Makefile.in from Makefile.am
# Copyright (C) 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.

# Originally written by David Mackenzie <djm@gnu.ai.mit.edu>.
# Perl reimplementation by Tom Tromey <tromey@cygnus.com>.


# Parameters set by configure.  Not to be changed.  NOTE: assign
# VERSION as string so that eg version 0.30 will print correctly.
$VERSION = "1.3";
$PACKAGE = "automake";
$prefix = "/usr";
$am_dir = "${prefix}/share/automake";
$TAR = "tar";

# String constants.
$IGNORE_PATTERN = "^##([^#].*)?\$";
$WHITE_PATTERN = "^[ \t]*\$";
$COMMENT_PATTERN = "^#";
$RULE_PATTERN = "^([\$a-zA-Z_.][-.a-zA-Z0-9_(){}/\$]*) *:([^=].*|)\$";
$SUFFIX_RULE_PATTERN = "^\\.([a-zA-Z]+)\\.([a-zA-Z]+)\$";
$MACRO_PATTERN = "^([A-Za-z][A-Za-z0-9_]*)[ \t]*:?=[ \t]*(.*)\$";
$BOGUS_MACRO_PATTERN = "^([^ \t]*)[ \t]*:?=[ \t]*(.*)\$";
$GNITS_VERSION_PATTERN = "[0-9]+\\.[0-9]+([a-z]|\\.[0-9]+)?";
$IF_PATTERN = "^if[ \t]+\([A-Za-z][A-Za-z0-9_]*\)[ \t]*\(#.*\)?\$";
$ELSE_PATTERN = "^else[ \t]*\(#.*\)?\$";
$ENDIF_PATTERN = "^endif[ \t]*\(#.*\)?\$";

# Some regular expressions.  One reason to put them here is that it
# makes indentation work better in Emacs.
$AC_CONFIG_AUX_DIR_PATTERN = "AC_CONFIG_AUX_DIR\\(([^)]+)\\)";
$AM_INIT_AUTOMAKE_PATTERN = "AM_INIT_AUTOMAKE\\([^,]*,([^,)]+)[,)]";
$AM_PACKAGE_VERSION_PATTERN = "^\\s*\\[?([^]\\s]+)\\]?\\s*\$";
# Note that there is no AC_PATH_TOOL.  But we don't really care.
$AC_CHECK_PATTERN = "AC_(CHECK|PATH)_(PROG|PROGS|TOOL)\\(\\[?(\\w+)";
$AM_MISSING_PATTERN = "AM_MISSING_PROG\\(\\[?(\\w+)";
# Just check for alphanumeric in AC_SUBST.  If you do AC_SUBST(5),
# then too bad.
$AC_SUBST_PATTERN = "AC_SUBST\\(\\[?(\\w+)";
$AM_CONDITIONAL_PATTERN = "AM_CONDITIONAL\\((\\w+)";

# Constants to define the "strictness" level.
$FOREIGN = 0;
$GNU = 1;
$GNITS = 2;



# Variables global to entire run.

# TRUE if we should always generate Makefile.in.
$force_generation = 1;

# Strictness level as set on command line.
$default_strictness = $GNU;

# Name of strictness level, as set on command line.
$default_strictness_name = 'gnu';

# This is TRUE if GNU make specific automatic dependency generation
# code should be included in generated Makefile.in.
$cmdline_use_dependencies = 1;

# This is the name of a dependency makefile bit (usually for inclusion in a
# SMakefile or similar); empty if not set.
$generate_deps = '';

# TRUE if in verbose mode.
$verbose = 0;

# This holds our (eventual) exit status.  We don't actually exit until
# we have processed all input files.
$exit_status = 0;

# From the Perl manual.
$symlink_exists = (eval 'symlink ("", "");', $@ eq '');

# TRUE if missing standard files should be installed.
$add_missing = 0;

# Files found by scanning configure.in for LIBOBJS.
%libsources = ();

# True if AM_C_PROTOTYPES appears in configure.in.
$am_c_prototypes = 0;

# Names used in AC_CONFIG_HEADER call.  @config_fullnames holds the
# name which appears in AC_CONFIG_HEADER, colon and all.
# @config_names holds the file names.  @config_headers holds the '.in'
# files.  Ordinarily these are similar, but they can be different if
# the weird "NAME:FILE" syntax is used.
@config_fullnames = ();
@config_names = ();
@config_headers = ();
# Line number at which AC_CONFIG_HEADER appears in configure.in.
$config_header_line = 0;

# Directory where output files go.  Actually, output files are
# relative to this directory.
$output_directory = '.';

# Relative location of top build directory.
$top_builddir = '';

# Absolute location of top build directory.
$build_directory = '';

# Name of srcdir as given in build directory's Makefile.  For
# dependencies only.
$srcdir_name = '';

# List of Makefile.am's to process, and their corresponding outputs.
@input_files = ();
%output_files = ();

# List of files in AC_OUTPUT without Makefile.am, and their outputs.
@other_input_files = ();
# Line number at which AC_OUTPUT seen.
$ac_output_line = 0;

# List of directories to search for configure-required files.  This
# can be set by AC_CONFIG_AUX_DIR.
@config_aux_path = ('.', '..', '../..');
$config_aux_dir = '';

# Whether AC_PROG_MAKE_SET has been seen in configure.in.
$seen_make_set = 0;

# Whether AM_GNU_GETTEXT has been seen in configure.in.
$seen_gettext = 0;
# Line number at which AM_GNU_GETTEXT seen.
$ac_gettext_line = 0;

# Whether ALL_LINGUAS has been seen.
$seen_linguas = '';
# The actual text.
$all_linguas = '';
# Line number at which it appears.
$all_linguas_line = 0;

# 1 if AC_PROG_INSTALL seen, 2 if AM_PROG_INSTALL seen.
$seen_prog_install = 0;

# 1 if any scripts installed, 0 otherwise.
$scripts_installed = 0;

# Whether AC_PATH_XTRA has been seen in configure.in.
$seen_path_xtra = 0;

# TRUE if AC_DECL_YYTEXT was seen.
$seen_decl_yytext = 0;

# TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM).  The presence of
# AC_CHECK_TOOL also sets this.
$seen_canonical = 0;

# TRUE if we've seen AC_ARG_PROGRAM.
$seen_arg_prog = 0;

# TRUE if we've seen AM_PROG_LIBTOOL.
$seen_libtool = 0;
$libtool_line = 0;

# Files installed by libtoolize.
@libtoolize_files = ('ltconfig', 'ltmain.sh', 'config.guess', 'config.sub');

# TRUE if we've seen AM_MAINTAINER_MODE.
$seen_maint_mode = 0;

# TRUE if we've seen PACKAGE and VERSION.
$seen_package = 0;
$seen_version = 0;

# Actual version we've seen.
$package_version = '';

# Line number where we saw version definition.
$package_version_line = 0;

# TRUE if we've seen AM_PATH_LISPDIR.
$seen_lispdir = 0;

# TRUE if we've seen AM_EXEEXT.
$seen_exeext = 0;

# Hash table of discovered configure substitutions.  Keys are names,
# values are meaningless.
%configure_vars = ();

# Charsets used by maintainer and in distribution.  MAINT_CHARSET is
# handled in a funny way: if seen in the top-level Makefile.am, it is
# used for every directory which does not specify a different value.
# The rationale here is that some directories (eg gettext) might be
# distributions of other packages, and thus require their own charset
# info.  However, the DIST_CHARSET must be the same for the entire
# package; it can only be set at top-level.
# FIXME: this yields bugs when rebuilding.  What to do?  Always
# read (and sometimes discard) top-level Makefile.am?
$maint_charset = '';
$dist_charset = 'utf8';		# recode doesn't support this yet.

# Name of input file ("Makefile.in") and output file ("Makefile.am").
# These have no directory components.
$am_file_name = '';
$in_file_name = '';

# TRUE if --cygnus seen.
$cygnus_mode = 0;

# Keys of this hash are names of dependency files to ignore.
%omit_dependencies = ();

# Hash table of AM_CONDITIONAL variables seen in configure.
%configure_cond = ();

# Map from obsolete macros to hints for new macros.
# FIXME complete the list so that there are no `0' hints.
%obsolete_macros =
    (
     'AC_FEATURE_CTYPE', "use \`AC_HEADER_STDC'",
     'AC_FEATURE_ERRNO', "add \`strerror' to \`AC_REPLACE_FUNCS(...)'",
     'AC_FEATURE_EXIT', 0,
     'AC_SYSTEM_HEADER', 0,

     # Note that we do not handle this one, because it is still run
     # from AM_CONFIG_HEADER.  So we deal with it specially in
     # scan_configure.
     # 'AC_CONFIG_HEADER', "use \`AM_CONFIG_HEADER'",

     'fp_C_PROTOTYPES', "use \`AM_C_PROTOTYPES'",
     'fp_PROG_CC_STDC', "use \`AM_PROG_CC_STDC'",
     'fp_PROG_INSTALL', "use \`AM_PROG_INSTALL'",
     'fp_WITH_DMALLOC', "use \`AM_WITH_DMALLOC'",
     'fp_WITH_REGEX', "use \`AM_WITH_REGEX'",
     'gm_PROG_LIBTOOL', "use \`AM_PROG_LIBTOOL'",
     'jm_MAINTAINER_MODE', "use \`AM_MAINTAINER_MODE'",
     'md_TYPE_PTRDIFF_T', "use \`AM_TYPE_PTRDIFF_T'",
     'ud_PATH_LISPDIR', "use \`AM_PATH_LISPDIR'",

     # Now part of autoconf proper, under a different name.
     'AM_FUNC_FNMATCH', "use \`AC_FUNC_FNMATCH'",
     'fp_FUNC_FNMATCH', "use \`AC_FUNC_FNMATCH'",
     'AM_SANITY_CHECK_CC', "automatically done by \`AC_PROG_CC'",

# These aren't quite obsolete.
#      'md_PATH_PROG',
     );

# Regexp to match the above macros.
$obsolete_rx = '(' . join ('|', keys %obsolete_macros) . ')';



&initialize_global_constants;

# Parse command line.
&parse_arguments (@ARGV);

# Do configure.in scan only once.
&scan_configure;

die "automake: no \`Makefile.am' found or specified\n"
    if ! @input_files;

# If --generate-deps was given, we don't do anything else
#
if ($generate_deps)
{
    die "automake: Must specify --include-deps (or -i) when generating\n"
      if ($use_dependencies);
    die "automake: Must provide --build-dir when generating\n"
      if (!$build_directory);
    die "automake: Must provide --srcdir-name when generating\n"
      if (!$srcdir_name);

    open(GDEP, ">$output_directory/.dep_segment")
      || die "automake: Could not open `$output_directory/.dep_segment': $!\n";

    &handle_dependencies;
    print GDEP $output_rules;

    close(GDEP);
    exit $exit_status;
}

# Now do all the work on each file.
foreach $am_file (@input_files)
{
    if (! -f ($am_file . '.am'))
    {
	&am_error ("\`" . $am_file . ".am' does not exist");
    }
    else
    {
 	&generate_makefile ($output_files{$am_file}, $am_file);
    }
}

if ($seen_prog_install <= $scripts_installed)
{
    &am_conf_error (($scripts_installed ? 'AM_PROG_INSTALL' : 'AC_PROG_INSTALL')
		    . " must be used in configure.in");
    &keyed_aclocal_warning ('AM_PROG_INSTALL')
	if $scripts_installed;
}

exit $exit_status;


################################################################

# Parse command line.
sub parse_arguments
{
    local (@arglist) = @_;

    # Start off as gnu.
    &set_strictness ('gnu');

    while (@arglist)
    {
	if ($arglist[0] eq "--version")
	{
	    print "automake (GNU $PACKAGE) $VERSION\n\n";
	    print "Copyright (C) 1998 Free Software Foundation, Inc.\n";
	    print "This is free software; see the source for copying conditions.  There is NO\n";
	    print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n";
	    print "Written by Tom Tromey <tromey\@cygnus.com>\n";

	    exit 0;
	}
	elsif ($arglist[0] eq "--help")
	{
	    &usage;
	}
	elsif ($arglist[0] =~ /^--amdir=(.+)$/)
	{
	    $am_dir = $1;
	}
	elsif ($arglist[0] eq '--amdir')
	{
	    &require_argument (@arglist);
	    shift (@arglist);
	    $am_dir = $arglist[0];
	}
	elsif ($arglist[0] =~ /^--build-dir=(.+)$/)
	{
	    # Must end in /.
	    $build_directory = $1 . '/';
	}
	elsif ($arglist[0] eq '--build-dir')
	{
	    &require_argument (@arglist);
	    shift (@arglist);
	    # Must end in /.
	    $build_directory = $arglist[0] . '/';
	}
	elsif ($arglist[0] =~ /^--srcdir-name=(.+)$/)
	{
	    $srcdir_name = $1;
	}
	elsif ($arglist[0] eq '--srcdir-name')
	{
	    &require_argument (@arglist);
	    shift (@arglist);
	    $srcdir_name = $arglist[0];
	}
	elsif ($arglist[0] eq '--gnu')
	{
	    &set_strictness ('gnu');
	}
	elsif ($arglist[0] eq '--gnits')
	{
	    &set_strictness ('gnits');
	}
	elsif ($arglist[0] eq '--cygnus')
	{
	    $cygnus_mode = 1;
	}
	elsif ($arglist[0] eq '--foreign')
	{
	    &set_strictness ('foreign');
	}
	elsif ($arglist[0] eq '--include-deps' || $arglist[0] eq '-i')
	{
	    $cmdline_use_dependencies = 0;
	}
	elsif ($arglist[0] eq '--generate-deps')
	{
	    $generate_deps = $1;
	}
	elsif ($arglist[0] eq '--no-force')
	{
	    $force_generation = 0;
	}
	elsif ($arglist[0] =~ /^--output-dir=(.*)$/)
	{
	    # Set output directory.
	    $output_directory = $1;
	}
	elsif ($arglist[0] eq '--output-dir' || $arglist[0] eq '-o')
	{
	    &require_argument (@arglist);
	    shift (@arglist);
	    $output_directory = $arglist[0];
	}
	elsif ($arglist[0] eq '--add-missing' || $arglist[0] eq '-a')
	{
	    $add_missing = 1;
	}
	elsif ($arglist[0] eq '--verbose' || $arglist[0] eq '-v')
	{
	    $verbose = 1;
	}
	elsif ($arglist[0] eq '--')
	{
	    # Stop option processing.
	    shift (@arglist);
	    push (@input_files, @arglist);
	    last;
	}
	elsif ($arglist[0] =~ /^-/)
	{
	    die "automake: unrecognized option -- \`$arglist[0]'\nTry \`automake --help' for more information.\n";
	}
	else
	{
	    # Handle $local:$input syntax.  Note that we only examine
	    # the first ":" file to see if it is automake input; the
	    # rest are just taken verbatim.  We still keep all the
	    # files around for dependency checking, however.
	    local ($local, $input, @rest) = split (/:/, $arglist[0]);
	    if (! $input)
	    {
		$input = $local;
	    }
	    else
	    {
		# Strip .in; later on .am is tacked on.  That is how
		# the automake input file is found.  Maybe not the
		# best way, but it is easy to explain.  FIXME: should
		# be error if .in is missing.
		$input =~ s/\.in$//;
	    }
	    push (@input_files, $input);
	    $output_files{$input} = join (':', ($local, @rest));
	}

	shift (@arglist);
    }

    # Take global strictness from whatever we currently have set.
    $default_strictness = $strictness;
    $default_strictness_name = $strictness_name;
}

# Ensure argument exists, or die.
sub require_argument
{
    local ($arg, @arglist) = @_;
    die "automake: no argument given for option \`$arg'\n"
	if ! @arglist;
}

################################################################

# Generate a Makefile.in given the name of the corresponding Makefile and
# the name of the file output by config.status.
sub generate_makefile
{
    local ($output, $makefile) = @_;

    ($am_file_name = $makefile) =~ s/^.*\///;
    $in_file_name = $am_file_name . '.in';
    $am_file_name .= '.am';

    # $OUTPUT is encoded.  If it contains a ":" then the first element
    # is the real output file, and all remaining elements are input
    # files.  We don't scan or otherwise deal with these input file,
    # other than to mark them as dependencies.  See scan_configure for
    # details.
    local (@secondary_inputs);
    ($output, @secondary_inputs) = split (/:/, $output);

    &initialize_per_input;
    $relative_dir = &dirname ($output);
    $am_relative_dir = &dirname ($makefile);

    # At the toplevel directory, we might need config.guess, config.sub
    # or libtool scripts (ltconfig and ltmain.sh).
    if ($relative_dir eq '.')
    {
 	# libtool requires some files.
 	&require_conf_file_with_conf_line ($libtool_line, $FOREIGN,
 					   @libtoolize_files)
	    if $seen_libtool;

        # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
        # config.sub.
        &require_config_file ($FOREIGN, 'config.guess', 'config.sub')
	    if $seen_canonical;
    }

    # We still need Makefile.in here, because sometimes the `dist'
    # target doesn't re-run automake.
    if ($am_relative_dir eq $relative_dir)
    {
	# Only distribute the files if they are in the same subdir as
	# the generated makefile.
	&push_dist_common ($in_file_name, $am_file_name);
    }
    push (@sources, '$(SOURCES)')
	if &variable_defined ('SOURCES');
    push (@objects, '$(OBJECTS)')
	if &variable_defined ('OBJECTS');

    &read_am_file ($makefile . '.am');
    if (&handle_options)
    {
	# Fatal error.  Just return, so we can continue with next file.
	return;
    }

    # Check first, because we might modify some state.
    &check_cygnus;
    &check_gnu_standards;
    &check_gnits_standards;

    &handle_configure ($output, $makefile, @secondary_inputs);
    &handle_gettext;
    &handle_libraries;
    &handle_ltlibraries;
    &handle_programs;
    &handle_scripts;

    &handle_built_sources;

    # This must be run after all the sources are scanned.
    &handle_yacc_lex_cxx;

    # Re-init SOURCES and OBJECTS.  FIXME: other code shouldn't depend
    # on this (but currently does).
    $contents{'SOURCES'} = join (' ', @sources);
    $contents{'OBJECTS'} = join (' ', @objects);

    &handle_texinfo;
    &handle_emacs_lisp;
    &handle_java;
    &handle_man_pages;
    &handle_data;
    &handle_headers;
    &handle_subdirs;
    &handle_tags;
    &handle_minor_options;
    &handle_dist ($makefile);
    &handle_dependencies;
    &handle_tests;
    &handle_footer;
    &handle_merge_targets ($output);
    &handle_installdirs;
    &handle_clean;
    &handle_phony;

    &check_typos;

    if (! -d ($output_directory . '/' . $am_relative_dir))
    {
	mkdir ($output_directory . '/' . $am_relative_dir, 0755);
    }

    local ($out_file) = $output_directory . '/' . $makefile . ".in";
    if (! $force_generation && -e $out_file)
    {
	local ($am_time) = (stat ($makefile . '.am'))[9];
	local ($in_time) = (stat ($out_file))[9];
	# FIXME: should cache these times.
	local ($conf_time) = (stat ('configure.in'))[9];
	# FIXME: how to do unsigned comparison?
	if ($am_time < $in_time || $am_time < $conf_time)
	{
	    # No need to update.
	    return;
	}
	if (-f 'aclocal.m4')
	{
	    local ($acl_time) = (stat _)[9];
	    return if ($am_time < $acl_time);
	}
    }

    if (! open (GM_FILE, "> " . $out_file))
    {
	warn "automake: ${am_file}.in: cannot write: $!\n";
	$exit_status = 1;
	return;
    }
    print "automake: creating ", $makefile, ".in\n" if $verbose;

    print GM_FILE $output_vars;
    # We make sure that `all:' is the first target.
    print GM_FILE $output_all;
    print GM_FILE $output_header;
    print GM_FILE $output_rules;
    print GM_FILE $output_trailer;

    close (GM_FILE);
}

################################################################

# Handle AUTOMAKE_OPTIONS variable.  Return 1 on error, 0 otherwise.
sub handle_options
{
    if (&variable_defined ('AUTOMAKE_OPTIONS'))
    {
	foreach (&variable_value_as_list ('AUTOMAKE_OPTIONS', ''))
	{
	    $options{$_} = 1;
	    if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
	    {
		&set_strictness ($_);
	    }
	    elsif ($_ eq 'cygnus')
	    {
		$cygnus_mode = 1;
	    }
	    elsif (/ansi2knr/)
	    {
		# An option like "../lib/ansi2knr" is allowed.  With
		# no path prefix, we assume the required programs are
		# in this directory.  We save the actual option for
		# later.
		$options{'ansi2knr'} = $_;
	    }
	    elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
		   || $_ eq 'dist-shar' || $_ eq 'dist-zip'
		   || $_ eq 'dist-tarZ' || $_ eq 'dejagnu'
		   || $_ eq 'no-texinfo.tex'
		   || $_ eq 'readme-alpha' || $_ eq 'check-news')
	    {
		# Explicitly recognize these.
	    }
	    elsif ($_ eq 'no-dependencies')
	    {
		$use_dependencies = 0;
	    }
	    elsif (/([0-9]+)\.([0-9]+)([a-z])?/)
	    {
		# Got a version number.

		local ($rmajor, $rminor, $ralpha) = ($1, $2, $3);

		if ($VERSION !~ /([0-9]+)\.([0-9]+)([a-z])?/)
		{
		    print STDERR
			"automake: programming error: version is incorrect\n";
		    exit 1;
		}
		local ($tmajor, $tminor, $talpha) = ($1, $2, $3);

		# 2.0 is better than 1.0.
		# 1.2 is better than 1.1.
		# 1.2a is better than 1.2.
		if ($rmajor > $tmajor
		    || ($rmajor == $tmajor && $rminor > $tminor)
		    || ($rminor == $tminor && $rminor == $tminor
			&& $ralpha gt $talpha))
		{
		    &am_line_error ('AUTOMAKE_OPTIONS',
				    "require version $_, only have $VERSION");
		    return 1;
		}
	    }
	    else
	    {
		&am_line_error ('AUTOMAKE_OPTIONS',
				"option \`" . $_ . "\' not recognized");
	    }
	}
    }

    if ($strictness == $GNITS)
    {
	$options{'readme-alpha'} = 1;
	$options{'check-news'} = 1;
    }

    return 0;
}

# Return object extension.  Just once, put some code into the output.
# Argument is the name of the output file
sub get_object_extension
{
    local ($out) = @_;

    # Always set this.
    $dir_holds_sources = 1;

    # Maybe require libtool library object files.
    local ($extension) = '.o';
    $extension = '.lo' if ($out =~ /\.la$/);

    if (! $included_generic_compile)
    {
	# Boilerplate.
	local ($xform) = '';
	if (&variable_defined ('CONFIG_HEADER'))
	{
	    local ($one_hdr);
	    foreach $one_hdr (split (' ', &variable_value ('CONFIG_HEADER')))
	    {
		local ($var);
		($var = &dirname ($one_hdr)) =~ s/(\W)/\\$1/g;
		$xform .= ' ' if $xform;
		$xform .= '-I' . $var;
	    }
	}
	$xform = 's/\@CONFIG_INCLUDE_SPEC\@/' . $xform . '/go;';
	$output_vars .= &file_contents_with_transform ($xform,
						       'comp-vars');
	$output_rules .=
	    &file_contents_with_transform
		($use_dependencies ? 's/^NOTDEPEND.*$//;' : 's/^NOTDEPEND//;',
		 'compile');

	&push_phony_cleaners ('compile');

	# If using X, include some extra variable definitions.  NOTE
	# we don't want to force these into CFLAGS or anything,
	# because not all programs will necessarily use X.
	if ($seen_path_xtra)
	{
	    local ($var);
	    foreach $var ('X_CFLAGS', 'X_LIBS', 'X_EXTRA_LIBS', 'X_PRE_LIBS')
	    {
		&define_configure_variable ($var);
	    }
	}

	push (@suffixes, '.c', '.o', '.S', '.s');
	push (@clean, 'compile');

	$included_generic_compile = 1;
    }

    if ($seen_libtool && ! $included_libtool_compile)
    {
	# Output the libtool compilation rules.
	$output_rules .=
	    &file_contents_with_transform
		($use_dependencies ? 's/^NOTDEPEND.*$//;' : 's/^NOTDEPEND//;',
		 'libtool');

	&push_phony_cleaners ('libtool');

	push (@suffixes, '.lo');
	push (@clean, 'libtool');

	$included_libtool_compile = 1;
    }

    # Check for automatic de-ANSI-fication.
    if (defined $options{'ansi2knr'})
    {
	$extension = '$U' . $extension;
	if (! $included_knr_compile)
	{
	    if (! $am_c_prototypes)
	    {
		&am_line_error ('AUTOMAKE_OPTIONS',
				"option \`ansi2knr' in use but \`AM_C_PROTOTYPES' not in configure.in");
		&keyed_aclocal_warning ('AM_C_PROTOTYPES');
		# Only give this error once.
		$am_c_prototypes = 1;
	    }

	    # Only require ansi2knr files if they should appear in
	    # this directory.
	    if ($options{'ansi2knr'} eq 'ansi2knr')
	    {
		&require_file_with_line ('AUTOMAKE_OPTIONS', $FOREIGN,
					 'ansi2knr.c', 'ansi2knr.1');
		$output_rules .= &file_contents ('kr-extra');
		push (@clean, 'krextra');
		&push_phony_cleaners ('krextra');
	    }

	    # Generate rules to build ansi2knr.  If it is in some
	    # other directory, then generate dependencies but have the
	    # rule just run elsewhere.
	    $output_rules .= ($options{'ansi2knr'} . ': '
			      . $options{'ansi2knr'} . ".o\n");
	    if ($options{'ansi2knr'} eq 'ansi2knr')
	    {
		$output_rules .= ("\t\$(LINK) ansi2knr.o \$(LIBS)\n"
				  . "ansi2knr.o: \$(CONFIG_HEADER)\n\n");
	    }
	    else
	    {
		$output_rules .= ("\tcd " . &dirname ($options{'ansi2knr'})
				  . " && \$(MAKE) ansi2knr\n\n");
		# This is required for non-GNU makes.
	        $output_rules .= ($options{'ansi2knr'} . ".o:\n");
		$output_rules .= ("\tcd " . &dirname ($options{'ansi2knr'})
				  . " && \$(MAKE) ansi2knr.o\n\n");
	    }

	    # Make sure ansi2knr can be found: if no path specified,
	    # specify "./".
	    if ($options{'ansi2knr'} eq 'ansi2knr')
	    {
		# Substitution from AM_C_PROTOTYPES.  This makes it be
		# built only when necessary.
		&define_configure_variable ('ANSI2KNR');
		# ansi2knr needs to be built before subdirs, so unshift it.
		unshift (@all, '$(ANSI2KNR)');
	    }
	    else
	    {
		# Found in another directory.
		&define_variable ("ANSI2KNR", $options{'ansi2knr'});
	    }

	    $output_rules .= &file_contents ('clean-kr');

	    push (@clean, 'kr');
	    &push_phony_cleaners ('kr');

	    $included_knr_compile = 1;
	}
    }

    return $extension;
}

# Handle yacc and lex.
sub handle_yacc_lex_cxx
{
    #
    # First do yacc and lex.
    #

    local ($yacc_count) = scalar (keys %yacc_sources);
    local ($lex_count) = scalar (keys %lex_sources);

    if ($yacc_count)
    {
	local ($file, $base, $hname, $cname);
	local (%seen_suffix) = ();
	foreach $file (keys %yacc_sources)
	{
	    $file =~ /(\..*)$/;
	    &output_yacc_build_rule ($1, $yacc_count > 1)
		if (! defined $seen_suffix{$1});
	    $seen_suffix{$1} = 1;

	    # Now generate rule to make the header file.  This should
	    # only be generated if `yacc -d' specified.  But right now
	    # there is no way to determine that.  FIXME: the
	    # AM_FOOFLAGS idea would suffice here.
	    $file =~ /^(.*)\.(y|yy|y\+\+|yxx)$/;
	    $base = $1;
	    ($hname = $2) =~ tr/y/h/;
	    ($cname = $2) =~ tr/y/c/;
	    $output_rules .= "${base}.${hname}: ${base}.${cname}\n";
	}
	$output_rules .= "\n";

	if (! defined $configure_vars{'YACC'})
	{
	    &am_error ("yacc source seen but \`YACC' not defined in \`configure.in'");
	}
	if (&variable_defined ('YACCFLAGS'))
	{
	    &am_line_error ('YACCFLAGS',
			    "\`YACCFLAGS' obsolete; use \`YFLAGS' instead");
	}
    }
    if ($lex_count)
    {
	local (%seen_suffix) = ();
	foreach (keys %lex_sources)
	{
	    /(\..*)$/;
	    &output_lex_build_rule ($1, $lex_count > 1)
		if (! defined $seen_suffix{$1});
	    $seen_suffix{$1} = 1;
	}

	if (! defined $configure_vars{'LEX'})
	{
	    &am_error ("lex source seen but \`LEX' not defined in \`configure.in'");
	}
	if (! $seen_decl_yytext)
	{
	    &am_error ("lex source seen but \`AC_DECL_YYTEXT' not in \`configure.in'");
	}
    }

    if ($yacc_count > 1 || $lex_count > 1)
    {
	# If there is more than one distinct yacc (resp lex) source
	# file in a given directory, then the `ylwrap' program is
	# required to allow parallel builds to work correctly.  FIXME:
	# for now, no line number.
	&require_config_file ($FOREIGN, 'ylwrap');
	if ($config_aux_dir ne '.' && $config_aux_dir ne '')
	{
		&define_variable ('YLWRAP', $config_aux_dir . "/ylwrap");
	}
	else
	{
		&define_variable ('YLWRAP', '$(srcdir)/ylwrap');
	}
    }

    #
    # Handle libtool.
    #
    local ($ltcompile, $ltlink) = ('', '');
    if ($seen_libtool)
    {
	&define_configure_variable ("LIBTOOL");
	$ltcompile = '$(LIBTOOL) --mode=compile ';
	$ltlink = '$(LIBTOOL) --mode=link ';
    }

    #
    # Now handle C++.
    #
    local (@cxx_list) = keys %cxx_extensions;
    local ($cxx_count) = scalar @cxx_list;
    if ($cxx_count)
    {
	push (@suffixes, @cxx_list);

	&define_configure_variable ("CXXFLAGS");
	&define_variable ('CXXCOMPILE', '$(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)');
	&define_variable ('LTCXXCOMPILE',
			  $ltcompile . '$(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)')
	    if ($seen_libtool);

	&define_variable ('CXXLINK', $ltlink . '$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@');

	local ($ext);
	foreach $ext (@cxx_list)
	{
	    $output_rules .= ("$ext.o:\n"
			      . "\t\$(CXXCOMPILE) -c \$<\n");
	    $output_rules .= ("$ext.lo:\n"
			      . "\t\$(LTCXXCOMPILE) -c \$<\n")
		if ($seen_libtool);
	}

	if (! defined $configure_vars{'CXX'})
	{
	    &am_error ("C++ source seen but \`CXX' not defined in \`configure.in'");
	}
    }

    #
    # Handle some ansi2knr cleanup.
    #

    # Push all libobjs files onto de_ansi_files.  We actually only
    # push files which exist in the current directory, and which are
    # genuine source files.  This is moderately lame.  FIXME.
    local ($file);
    foreach $file (keys %libsources)
    {
	if ($file =~ /^(.*)\.[cly]$/ && -f "$relative_dir/$file")
	{
	    $de_ansi_files{$1} = 1;
	}
    }

    if (defined $options{'ansi2knr'} && keys %de_ansi_files)
    {
 	# Make all _.c files depend on their corresponding .c files.
 	local ($base, @objects);
 	foreach $base (sort (keys %de_ansi_files))
 	{
	    # Each _.c file must depend on ansi2knr; otherwise it
	    # might be used in a parallel build before it is built.
	    # We need to support files in the srcdir and in the build
	    # dir (because these files might be auto-generated.  But
	    # we can't use $< -- some makes only define $< during a
	    # suffix rule.
 	    $output_rules .= ($base . "_.c: $base.c \$(ANSI2KNR)\n\t"
			      . '$(CPP) $(DEFS) $(INCLUDES) $(CPPFLAGS) '
			      . '`if test -f $(srcdir)/' . $base . '.c'
			      . '; then echo $(srcdir)/' . $base . '.c'
			      . '; else echo ' . $base . '.c; fi` '
			      . '| $(ANSI2KNR) ' . $base . "_.c\n");
 	    push (@objects, $base . '_.o');
 	    push (@objects, $base . '_.lo') if $seen_libtool;
 	}

 	# Make all _.o (and _.lo) files depend on ansi2knr.
 	# Use a sneaky little hack to make it print nicely.
 	&pretty_print_rule ('', '', @objects, ':', '$(ANSI2KNR)');
    }

    #
    # Last, handle some C cleanup.
    #
    if ($seen_any_source)
    {
	&define_configure_variable ('CFLAGS');
	&define_variable ('COMPILE',
			  '$(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)');
	&define_variable ('LTCOMPILE',
			  $ltcompile .
			  '$(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)')
	    if ($seen_libtool);
	&define_variable ('LINK', $ltlink . '$(CC) $(CFLAGS) $(LDFLAGS) -o $@');
    }

    if ($seen_c_source && ! defined $configure_vars{'CC'})
    {
	&am_line_error ($seen_c_source,
			"C source seen but \`CC' not defined in \`configure.in'");
    }
}


# Output a rule to build from a YACC source.  The output from YACC is
# compiled with C or C++, depending on the extension of the YACC file.
sub output_yacc_build_rule
{
    local ($yacc_suffix, $use_ylwrap, $c_suffix) = @_;

    local ($suffix);
    ($suffix = $yacc_suffix) =~ tr/y/c/;
    push (@suffixes, $yacc_suffix, $suffix);

    # Generate rule for c/c++.
    $output_rules .= "$yacc_suffix$suffix:\n\t";

    if ($use_ylwrap)
    {
	$output_rules .= ('$(SHELL) $(YLWRAP)'
			  . ' "$(YACC)" $< y.tab.c $*' . $suffix
			  . ' y.tab.h $*.h -- $(YFLAGS)');
    }
    else
    {
	$output_rules .= ('$(YACC) $(YFLAGS) $< && mv y.tab.c $*'
			  . $suffix . "\n"
			  . "\tif test -f y.tab.h; then \\\n"
			  . "\tif cmp -s y.tab.h \$*.h; then rm -f y.tab.h; else mv y.tab.h \$*.h; fi; \\\n"
			  . "\telse :; fi");
    }
    $output_rules .= "\n";
}

sub output_lex_build_rule
{
    local ($lex_suffix, $use_ylwrap) = @_;
    local ($c_suffix);

    ($c_suffix = $lex_suffix) =~ tr/l/c/;
    push (@suffixes, $lex_suffix);
    &define_configure_variable ('LEX_OUTPUT_ROOT');
    &define_configure_variable ('LEXLIB');
    $output_rules .= "$lex_suffix$c_suffix:\n\t";

    if ($use_ylwrap)
    {
        # Is the $@ correct here?  If so, why not use it in the ylwrap
        # build rule for yacc above?
	$output_rules .= '$(SHELL) $(YLWRAP)'
	    . ' "$(LEX)" $< $(LEX_OUTPUT_ROOT).c $@ -- $(LFLAGS)';
    }
    else
    {
	$output_rules .= '$(LEX) $(LFLAGS) $< && mv $(LEX_OUTPUT_ROOT).c $@';
    }
    $output_rules .= "\n";
}


# Check to make sure a source defined in LIBOBJS is not explicitly
# mentioned.  This is a separate function (as opposed to being inlined
# in handle_source_transform) because it isn't always appropriate to
# do this check.
sub check_libobjs_sources
{
    local ($one_file, $unxformed) = @_;

    local ($prefix, $file, @files);
    foreach $prefix ('', 'EXTRA_')
    {
	if (&variable_defined ($prefix . $one_file . '_SOURCES'))
	{
	    @files = &variable_value_as_list (($prefix
					       . $one_file . '_SOURCES'),
					      'all');
	}
	elsif ($prefix eq '')
	{
	    @files = ($unxformed . '.c');
	}
	else
	{
	    next;
	}

	foreach $file (@files)
	{
	    if (defined $libsources{$file})
	    {
		&am_line_error ($prefix . $one_file . '_SOURCES',
				"automatically discovered file \`$file' should not be explicitly mentioned");
	    }
	}
    }
}

# Does much of the actual work for handle_source_transform.
# Arguments are:
#   pattern matching object extension (e.g., .o)
#   list of source files to transform
# Result is a list
#   first element is name of linker to use (empty string for default linker)
#   remaining elements are names of `.o's
sub handle_single_transform_list
{
    local ($objpat, @files) = @_;
    local ($linker) = '';
    local (@result) = ();
    local ($nonansi_obj) = $obj;
    $nonansi_obj =~ s/_//g;
    if (@files > 0)
    {
	# Turn sources into objects.
	foreach (@files)
	{
	    # Skip header files, including C++-ish ones.  The list
	    # of C++ header extensions comes from Emacs 19.32
	    # etags.
	    next if /\.[hH]$/;
	    next if /\.hxx$/;
	    next if /\.h\+\+$/;
	    next if /\.hh$/;
	    next if /\.hpp$/;
	    # Skip things that look like configure substitutions.
	    next if /^\@.*\@$/;

	    # Include appropriate file for lex or yacc source in
	    # distribution.  If the extension is the regular '.y' or
	    # '.l', we assume C compilation, and the generated file
	    # has exension .c.  Otherwise, we compile with C++, and
	    # make the following association: (yy -> cc, y++ -> c++,
	    # yxx -> cxx), similarly for .ll, etc.
	    if (/^(.*)\.(y|yy|y\+\+|yxx)$/)
	    {
		# Yacc source.
		local ($ext) = $2;
		$ext =~ tr/y/c/;
		&push_dist_common ("$1.$ext");
		$yacc_sources{$_} = 1;
	    }
	    elsif (/^(.*)\.(l|ll|l\+\+|lxx)$/)
	    {
		# Lex source.
		local ($ext) = $2;
		$ext =~ tr/l/c/;
		&push_dist_common ("$1.$ext");
		$lex_sources{$_} = 1;
	    }

	    # Strip any directory prefix.
	    $_ = &basename ($_);

	    local ($is_cxx) = 0;
	    # Transform source files into .o files.  List of C++
	    # extensions comes from Emacs 19.34 etags.
	    if (s/\.(c\+\+|cc|cpp|cxx|C)$/$nonansi_obj/)
	    {
		$cxx_extensions{'.' . $1} = 1;
		$linker = 'CXXLINK';
		$is_cxx = 1;
	    }
	    elsif (s/\.(yy|y\+\+|yxx|ll|l\+\+|lxx)$/$nonansi_obj/)
	    {
		# Compiling lex or yacc with C++
		local ($ext) = $1;
		$ext =~ tr/ly/cc/;
		$cxx_extensions{".$ext"} = 1;
		$linker = 'CXXLINK';
	    }
	    elsif (s/\.([Ff]|f90|for)$/$nonansi_obj/)
	    {
		# FORTRAN support.  FIXME: not finished.
	    }
	    elsif (s/\.[sS]$/$nonansi_obj/)
	    {
		# .s is assembly.  Just rewrite it.  FIXME: not finished.
	    }
 	    elsif (defined ($options{'ansi2knr'}) && s/_\.[cly]$/_.c/)
 	    {
 		# FIXME include line number in error.
 		&am_error ("C source file \`$_' would be deleted by ansi2knr rules");
 	    }
	    elsif (s/\.[cly]$//)
  	    {
  		# .c is C.  .l is lex.  .y is yacc.

 		# Note: first we rewrite (eg) foo.c to foo and push
 		# the file onto the list of deansified files.  Then we add
 		# $obj, which can either be `_.o', or simply `.o' if
 		# deansification is not required.
 		$de_ansi_files{$_} = 1;
 		$_ .= $obj;
  		$seen_c_source = 1;
	    }
 	    elsif (/\.$source_suffix_pattern$/) 
 	    {
		# We just rewrite it.  Maybe we should do more.
		s//.$suffix_rules{$1}/;
		$objpat = "\\." . $suffix_rules{$1};
 	    }
	    else
	    {
		# No error message here.  Used to have one, but it was
		# very unpopular.
		next;
	    }

	    $seen_any_source = 1 unless $is_cxx;
	    push (@result, $_);

	    # Transform .o or $o file into .P file (for automatic
	    # dependency code).
	    s/$objpat$/.P/g;
	    $dep_files{'.deps/' . $_} = 1;
	}
    }

    return ($linker, @result);
}

# Handle SOURCE->OBJECT transform for one program or library.
# Arguments are:
#   canonical (transformed) name of object to build
#   actual name of object to build
#   object extension (ie either `.o' or `$o'.
# Return result is name of linker variable that must be used.
# Empty return means just use `LINK'.
sub handle_source_transform
{
    # one_file is canonical name.  unxformed is given name.  obj is
    # object extension.
    local ($one_file, $unxformed, $obj) = @_;
    local ($objpat) = $obj;
    $objpat =~ s/(\W)/\\$1/g;
    # Handle explicit `.o' as well as whatever we're passed.
    $objpat = '(' . $objpat . "|\\.o)";

    local ($linker) = '';

    if (&variable_defined ($one_file . "_OBJECTS"))
    {
	&am_line_error ($one_file . '_OBJECTS',
			$one_file . '_OBJECTS', 'should not be defined');
	# No point in continuing.
	return;
    }

    local (@files, @result, $prefix, $temp);
    foreach $prefix ('', 'EXTRA_')
    {
	@files = ();
	local ($var) = $prefix . $one_file . "_SOURCES";
	if (&variable_defined ($var))
	{
	    push (@sources, '$(' . $prefix . $one_file . "_SOURCES)");
	    push (@objects, '$(' . $prefix . $one_file . "_OBJECTS)")
		unless $prefix eq 'EXTRA_';
	    local (@conds) = &variable_conditions ($var);
	    if (! @conds)
	    {
		@files = &variable_value_as_list ($var, '');
	    }
	    else
	    {
		local ($cond, $cond_var_name);
		local ($count) = 0;
		local (@namelist) = ();
		foreach $cond (@conds)
		{
		    @files = &variable_value_as_list ($var, $cond);
		    ($temp, @result) = &handle_single_transform_list ($objpat,
								      @files);
		    $linker = $temp if $linker eq '';

		    # We have to have a new name for each such
		    # variable.  Then we define the _OBJECTS variable
		    # as the union of all such variables.  Hopefully
		    # this is the Right Thing.
		    $cond_var_name = 'cond' . $count . $one_file . '_OBJECTS';
		    &define_pretty_variable ($cond_var_name, $cond, @result)
			unless $prefix eq 'EXTRA_';
		    push (@namelist, '$(' . $cond_var_name . ')');
		    ++$count;
		}

		&define_pretty_variable ($one_file . '_OBJECTS', '',
					 @namelist);

		next;
	    }
	}
	elsif ($prefix eq '')
	{
	    &define_variable ($one_file . "_SOURCES", $unxformed . ".c");
	    push (@sources, $unxformed . '.c');
	    push (@objects, $unxformed . $obj);
	    push (@files, $unxformed . '.c');
	}

	($temp, @result) = &handle_single_transform_list ($objpat, @files);
	$linker = $temp if $linker eq '';
	&define_pretty_variable ($one_file . "_OBJECTS", '', @result)
	    unless $prefix eq 'EXTRA_';
    }

    return $linker;
}

# Handle the BUILT_SOURCES variable.
sub handle_built_sources
{
    return unless &variable_defined ('BUILT_SOURCES');

    local (@sources) = &variable_value_as_list ('BUILT_SOURCES', 'all');
    local ($s);
    foreach $s (@sources)
    {
	if (/^\@.*\@$/)
	{
	    # FIXME: is this really the right thing to do?
	    &am_line_error ('BUILT_SOURCES',
			    "\`BUILT_SOURCES' should not contain a configure substitution");
	    last;
	}
    }

    # We don't care about the return value of this function.  We just
    # want to make sure to update %dep_files with the contents of
    # BUILT_SOURCES.
    &handle_single_transform_list ("\\.o", @sources);
}

# Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
# Also, generate _DEPENDENCIES variable if appropriate.
# Arguments are:
#   transformed name of object being built, or empty string if no object
#   name of _LDADD/_LIBADD-type variable to examine
#   boolean (lex_seen) which is true if a lex source file was seen in this
#     object.  valid only for LDADDs, not LIBADDs.
# Returns 1 if LIBOBJS seen, 0 otherwise.
sub handle_lib_objects
{
    local ($xname, $var, $lex_seen) = @_;
    local ($ret);

    die "automake: programming error 1 in handle_lib_objects\n"
	if ! &variable_defined ($var);

    die "automake: programming error 2 in handle_lib_objects\n"
	if $lex_seen && $var =~ /LIBADD/;

    local (@conds) = &variable_conditions ($var);
    if (! @conds)
    {
	$ret = &handle_lib_objects_cond ($xname, $var, $lex_seen, '');
    }
    else
    {
	local ($cond);
	$ret = 0;
	foreach $cond (@conds)
	{
	    if (&handle_lib_objects_cond ($xname, $var, $lex_seen, $cond))
	    {
		$ret = 1;
	    }
	}
    }

    return $ret;
}

# Subroutine of handle_lib_objects: handle a particular condition.
sub handle_lib_objects_cond
{
    local ($xname, $var, $lex_seen, $cond) = @_;

    # We recognize certain things that are commonly put in LIBADD or
    # LDADD.
    local ($lsearch);
    local (@dep_list) = ();

    local ($seen_libobjs) = 0;
    local ($flagvar) = 0;

    foreach $lsearch (&variable_value_as_list ($var, $cond))
    {
	# Skip -lfoo and -Ldir; these are explicitly allowed.
	next if $lsearch =~ /^-[lL]/;
	if (! $flagvar && $lsearch =~ /^-/)
	{
	    if ($var =~ /^(.*)LDADD$/)
	    {
		&am_line_error ($var, "linker flags such as \`$lsearch' belong in \`${1}LDFLAGS");
	    }
	    else
	    {
		# Only get this error once.
		$flagvar = 1;
		&am_line_error ($var, "you cannot use linker flags such as \`$lsearch' in \`$var'");
	    }
	}

	# Assume we have a file of some sort, and push it onto the
	# dependency list.  Autoconf substitutions are not pushed;
	# rarely is a new dependency substituted into (eg) foo_LDADD
	# -- but "bad things (eg -lX11) are routinely substituted.
	# Note that LIBOBJS and ALLOCA are exceptions to this rule,
	# and handled specially below.
	push (@dep_list, $lsearch)
	    unless $lsearch =~ /^\@.*\@$/;

	# Automatically handle @LIBOBJS@ and @ALLOCA@.  Basically this
	# means adding entries to dep_files.
	if ($lsearch =~ /^\@(LT)?LIBOBJS\@$/)
	{
	    push (@dep_list, $lsearch);
	    $seen_libobjs = 1;
	    if (! keys %libsources)
	    {
		&am_line_error ($var, "\@$1" . "LIBOBJS\@ seen but never set in \`configure.in'");
	    }

	    local ($iter, $rewrite);
	    foreach $iter (keys %libsources)
	    {
		if ($iter =~ /\.[cly]$/)
		{
		    $seen_c_source = $var;
		    $seen_any_source = 1;
		}

		if ($iter =~ /\.h$/)
		{
		    &require_file_with_line ($var, $FOREIGN, $iter);
		}
		elsif ($iter ne 'alloca.c')
		{
		    ($rewrite = $iter) =~ s/\.c$/.P/;
		    $dep_files{'.deps/' . $rewrite} = 1;
		    &require_file_with_line ($var, $FOREIGN, $iter);
		}
	    }
	}
	elsif ($lsearch =~ /^\@(LT)?ALLOCA\@$/)
	{
	    push (@dep_list, $lsearch);
	    &am_line_error ($var,
			    "\@$1" . "ALLOCA\@ seen but \`AC_FUNC_ALLOCA' not in \`configure.in'")
		if ! defined $libsources{'alloca.c'};
	    $dep_files{'.deps/alloca.P'} = 1;
	    &require_file_with_line ($var, $FOREIGN, 'alloca.c');
	    $seen_c_source = $var;
	    $seen_any_source = 1;
	}
    }

    if ($xname ne '' && ! &variable_defined ($xname . '_DEPENDENCIES', $cond))
    {
	&define_pretty_variable ($xname . '_DEPENDENCIES', $cond, @dep_list);
    }

    return $seen_libobjs;
}

# Canonicalize a name, and check to make sure the non-canonical name
# is never used.  Returns canonical name.  Arguments are name and a
# list of suffixes to check for.
sub check_canonical_spelling
{
    local ($name, @suffixes) = @_;
    local ($xname, $xt);

    ($xname = $name) =~ tr/A-Za-z0-9_/_/c;
    if ($xname ne $name)
    {
	local ($xt);
	foreach $xt (@suffixes)
	{
	    &am_line_error ($name . $xt,
			    "invalid variable \`" . $name . $xt
			    . "'; should be \`" . $xname . $xt . "'")
		if &variable_defined ($name . $xt);
	}
    }

    return $xname;
}

# Handle C programs.
sub handle_programs
{
    local (@proglist) = &am_install_var ('-clean',
					 'progs', 'PROGRAMS',
					 'bin', 'sbin', 'libexec', 'pkglib',
					 'noinst', 'check');
    return if ! @proglist;

    # If a program is installed, this is required.  We only want this
    # error to appear once.
    &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
	unless $seen_arg_prog;
    $seen_arg_prog = 1;

    local ($one_file, $xname, $munge);

    local ($seen_libobjs) = 0;
    foreach $one_file (@proglist)
    {
	local ($obj) = &get_object_extension ($one_file);

	# Canonicalize names and check for misspellings.
	$xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
					    '_SOURCES', '_OBJECTS',
					    '_DEPENDENCIES');

	# FIXME: Using a trick to figure out if any lex sources appear
	# in our program; should use some cleaner method.
	local ($lex_num) = scalar (keys %lex_sources);
	local ($linker) = &handle_source_transform ($xname, $one_file, $obj);
	local ($lex_file_seen) = (scalar (keys %lex_sources) > $lex_num);

	local ($xt) = '';
	if (&variable_defined ($xname . "_LDADD"))
	{
	    if (&handle_lib_objects ($xname, $xname . '_LDADD',
				     $lex_file_seen))
	    {
		$seen_libobjs = 1;
	    }
	    $lex_file_seen = 0;
	    $xt = '_LDADD';
	}
	else
	{
	    # User didn't define prog_LDADD override.  So do it.
	    &define_variable ($xname . '_LDADD', '$(LDADD)');

	    # This does a bit too much work.  But we need it to
	    # generate _DEPENDENCIES when appropriate.
	    if (&variable_defined ('LDADD'))
	    {
		if (&handle_lib_objects ($xname, 'LDADD', $lex_file_seen))
		{
		    $seen_libobjs = 1;
		}
		$lex_file_seen = 0;
	    }
	    elsif (! &variable_defined ($xname . '_DEPENDENCIES'))
	    {
		&define_variable ($xname . '_DEPENDENCIES', '');
	    }
	    $xt = '_SOURCES'
	}

	if (&variable_defined ($xname . '_LIBADD'))
	{
	    &am_line_error ($xname . '_LIBADD',
			    "use \`" . $xname . "_LDADD', not \`"
			    . $xname . "_LIBADD'");
	}

	if (! &variable_defined ($xname . '_LDFLAGS'))
	{
	    # Define the prog_LDFLAGS variable.
	    &define_variable ($xname . '_LDFLAGS', '');
	}

	# Determine program to use for link.
	local ($xlink);
	if (&variable_defined ($xname . '_LINK'))
	{
	    $xlink = $xname . '_LINK';
	}
	else
	{
	    $xlink = $linker ? $linker : 'LINK';
	}

	local ($xexe);
	if ($seen_exeext && $one_file !~ /\./)
	{
	    $xexe = 's/\@EXEEXT\@/\$(EXEEXT)/g;';
	}
	else
	{
	    $xexe = 's/\@EXEEXT\@//g;';
	}

	$output_rules .=
	    &file_contents_with_transform
		('s/\@PROGRAM\@/' . $one_file . '/go;'
		 . 's/\@XPROGRAM\@/' . $xname . '/go;'
		 . 's/\@XLINK\@/' . $xlink . '/go;'
		 . $xexe,
		 'program');
    }

    if (&variable_defined ('LDADD') && &handle_lib_objects ('', 'LDADD', 0))
    {
	$seen_libobjs = 1;
    }

    if ($seen_libobjs)
    {
	foreach $one_file (@proglist)
	{
	    # Canonicalize names.
	    ($xname = $one_file) =~ tr/A-Za-z0-9_/_/c;

	    if (&variable_defined ($xname . '_LDADD'))
	    {
		&check_libobjs_sources ($xname, $xname . '_LDADD');
	    }
	    elsif (&variable_defined ('LDADD'))
	    {
		&check_libobjs_sources ($xname, 'LDADD');
	    }
	}
    }
}


# Handle libraries.
sub handle_libraries
{
    local (@liblist) = &am_install_var ('-clean',
					'libs', 'LIBRARIES',
					'lib', 'pkglib', 'noinst', 'check');
    return if ! @liblist;

    local (%valid) = &am_primary_prefixes ('LIBRARIES', 'lib', 'pkglib',
					   'noinst', 'check');
    if (! defined $configure_vars{'RANLIB'})
    {
	local ($key);
	foreach $key (keys %valid)
	{
	    if (&variable_defined ($key . '_LIBRARIES'))
	    {
		&am_line_error ($key . '_LIBRARIES', "library used but \`RANLIB' not defined in \`configure.in'");
		# Only get this error once.
		$configure_vars{'RANLIB'} = 1;
		last;
	    }
	}
    }

    local ($onelib);
    local ($munge);
    local ($xlib);
    local ($seen_libobjs) = 0;
    foreach $onelib (@liblist)
    {
	# Check that the library fits the standard naming convention.
	if ($onelib !~ /^lib.*\.a$/)
	{
	    # FIXME should put line number here.  That means mapping
	    # from library name back to variable name.
	    &am_error ("\`$onelib' is not a standard library name");
	}

	local ($obj) = &get_object_extension ($onelib);

	# Canonicalize names and check for misspellings.
	$xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
					   '_OBJECTS', '_DEPENDENCIES');

	if (&variable_defined ($xlib . '_LIBADD'))
	{
	    if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
	    {
		$seen_libobjs = 1;
	    }
	}
	else
	{
	    # Generate support for conditional object inclusion in
	    # libraries.
	    &define_variable ($xlib . "_LIBADD", '');
	}

	if (&variable_defined ($xlib . '_LDADD'))
	{
	    &am_line_error ($xlib . '_LDADD',
			    "use \`" . $xlib . "_LIBADD', not \`"
			    . $xlib . "_LDADD'");
	}

	# Make sure we at look at this.
	&examine_variable ($xlib . '_DEPENDENCIES');

	&handle_source_transform ($xlib, $onelib, $obj);

	$output_rules .=
	    &file_contents_with_transform ('s/\@LIBRARY\@/' . $onelib . '/go;'
					   . 's/\@XLIBRARY\@/'
					   . $xlib . '/go;',
					   'library');
    }

    if ($seen_libobjs)
    {
	foreach $onelib (@liblist)
	{
	    # Canonicalize names.
	    ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
	    if (&variable_defined ($xlib . '_LIBADD'))
	    {
		&check_libobjs_sources ($xlib, $xlib . '_LIBADD');
	    }
	}
    }

    &define_variable ('AR', 'ar');
    &define_configure_variable ('RANLIB');
}

# Handle shared libraries.
sub handle_ltlibraries
{
    local (@liblist) = &am_install_var ('-clean',
					'ltlib', 'LTLIBRARIES',
					'lib', 'pkglib');
    return if ! @liblist;

    local (%instdirs);
    local (%valid) = &am_primary_prefixes ('LTLIBRARIES', 'lib', 'pkglib');

    local ($key);
    foreach $key (keys %valid)
    {
	if (&variable_defined ($key . '_LTLIBRARIES'))
	{
	    if (!$seen_libtool)
	    {
		&am_line_error ($key . '_LTLIBRARIES', "library used but \`LIBTOOL' not defined in \`configure.in'");
		# Only get this error once.
		$configure_vars{'LIBTOOL'} = 1;
		$seen_libtool = 1;
	    }

	    # Get the installation directory of each library.
	    for (&variable_value_as_list ($key . '_LTLIBRARIES', 'all'))
	    {
		if ($instdirs{$_})
		{
		    &am_error ("\`$_' is already going to be installed in \`$instdirs{$_}'");
		}
		else
		{
		    $instdirs{$_} = $key;
		}
	    }
	}
    }

    local ($onelib);
    local ($munge);
    local ($xlib);
    local ($seen_libobjs) = 0;
    foreach $onelib (@liblist)
    {
	# Check that the library fits the standard naming convention.
	if ($onelib !~ /^lib.*\.la$/)
	{
	    # FIXME this should only be a warning for foreign packages
	    # FIXME should put line number here.  That means mapping
	    # from library name back to variable name.
	    &am_error ("\`$onelib' is not a standard libtool library name");
	}

	local ($obj) = &get_object_extension ($onelib);

	# Canonicalize names and check for misspellings.
	$xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
					   '_SOURCES', '_OBJECTS',
					   '_DEPENDENCIES');

	if (! &variable_defined ($xlib . '_LDFLAGS'))
	{
	    # Define the lib_LDFLAGS variable.
	    &define_variable ($xlib . '_LDFLAGS', '');
	}

	if (&variable_defined ($xlib . '_LIBADD'))
	{
	    if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
	    {
		$seen_libobjs = 1;
	    }
	}
	else
	{
	    # Generate support for conditional object inclusion in
	    # libraries.
	    &define_variable ($xlib . "_LIBADD", '');
	}

	if (&variable_defined ($xlib . '_LDADD'))
	{
	    &am_line_error ($xlib . '_LDADD',
			    "use \`" . $xlib . "_LIBADD', not \`"
			    . $xlib . "_LDADD'");
	}

	# Make sure we at look at this.
	&examine_variable ($xlib . '_DEPENDENCIES');

	local ($linker) = &handle_source_transform ($xlib, $onelib, $obj);

	# Determine program to use for link.
	local ($xlink);
	if (&variable_defined ($xlib . '_LINK'))
	{
	    $xlink = $xlib . '_LINK';
	}
	else
	{
	    $xlink = $linker ? $linker : 'LINK';
	}

	local ($rpath);
	if ($instdirs{$onelib} eq 'EXTRA')
	{
	    # It's an EXTRA_ library, so we can't specify -rpath.
	    # Yuck.
	    $rpath = 's/\@RPATH\@//go;';
	}
	else
	{
	    $rpath = ('s/\@RPATH\@/-rpath \$(' . $instdirs{$onelib}
		      . 'dir)/go;');
	}

	$output_rules .=
	    &file_contents_with_transform ('s/\@LTLIBRARY\@/'
					   . $onelib . '/go;'
					   . 's/\@XLTLIBRARY\@/'
					   . $xlib . '/go;'
					   . $rpath
					   . 's/\@XLINK\@/' . $xlink . '/go;',
					   'ltlibrary');
    }

    if ($seen_libobjs)
    {
	foreach $onelib (@liblist)
	{
	    # Canonicalize names.
	    ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
	    if (&variable_defined ($xlib . '_LIBADD'))
	    {
		&check_libobjs_sources ($xlib, $xlib . '_LIBADD');
	    }
	}
    }
}

# See if any _SOURCES variable were misspelled.  Also, make sure that
# EXTRA_ variables don't contain configure substitutions.
sub check_typos
{
    local ($varname, $primary);
    foreach $varname (keys %contents)
    {
	foreach $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
			  '_DEPENDENCIES')
	{
	    if ($varname =~ /$primary$/ && ! $content_seen{$varname})
	    {
		&am_line_error ($varname,
				"invalid unused variable name: \`$varname'");
	    }
	}
    }
}

# Handle scripts.
sub handle_scripts
{
    # NOTE we no longer automatically clean SCRIPTS, because it is
    # useful to sometimes distribute scripts verbatim.  This happens
    # eg in Automake itself.
    &am_install_var ('scripts', 'SCRIPTS',
		     'bin', 'sbin', 'libexec', 'pkgdata',
		     'noinst', 'check');

    # Set $scripts_installed if appropriate.  Make sure we only find
    # scripts which are actually installed -- this is why we can't
    # simply use the return value of am_install_var.
    local (%valid) = &am_primary_prefixes ('SCRIPTS', 'bin', 'sbin',
					   'libexec', 'pkgdata',
					   'noinst', 'check');
    local ($key);
    foreach $key (keys %valid)
    {
	if ($key ne 'noinst'
	    && $key ne 'check'
	    && &variable_defined ($key . '_SCRIPTS'))
	{
	    $scripts_installed = 1;
	    # push (@check_tests, 'check-' . $key . 'SCRIPTS');
	}
    }

    if ($scripts_installed)
    {
	# If a program is installed, this is required.  We only want this
	# error to appear once.
	&am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
	    unless $seen_arg_prog;
	$seen_arg_prog = 1;
    }
}

# Search a file for a "version.texi" Texinfo include.  Return the name
# of the include file if found, or the empty string if not.  A
# "version.texi" file is actually any file whose name matches
# "vers*.texi".
sub scan_texinfo_file
{
    local ($filename) = @_;

    if (! open (TEXI, $filename))
    {
	&am_error ("couldn't open \`$filename': $!");
	return '';
    }
    print "automake: reading $filename\n" if $verbose;

    local ($vfile, $outfile);
    while (<TEXI>)
    {
	if (/^\@setfilename +(\S+)/)
	{
	    $outfile = $1;
	    last if ($vfile);
	}

	if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
	{
	    # Found version.texi include.
	    $vfile = $1;
	    last if $outfile;
	}
    }

    close (TEXI);
    return ($outfile, $vfile);
}

# Handle all Texinfo source.
sub handle_texinfo
{
    &am_line_error ('TEXINFOS',
		    "\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
	if &variable_defined ('TEXINFOS');
    return if (! &variable_defined ('info_TEXINFOS')
	       && ! &variable_defined ('html_TEXINFOS'));

    local (@texis) = &variable_value_as_list ('info_TEXINFOS', 'all');

    local (@info_deps_list, @dvis_list, @texi_deps);
    local ($infobase, $info_cursor);
    local (%versions);
    local ($done) = 0;
    local ($vti);
    local ($tc_cursor, @texi_cleans);
    local ($canonical);

    foreach $info_cursor (@texis)
    {
	# FIXME: This is mildly hacky, since it recognizes "txinfo".
	# I don't feel like making it right.
	($infobase = $info_cursor) =~ s/\.te?xi(nfo)?$//;

	# If 'version.texi' is referenced by input file, then include
	# automatic versioning capability.
	local ($out_file, $vtexi) = &scan_texinfo_file ($relative_dir
							. "/" . $info_cursor);

	if ($out_file eq '')
	{
	    &am_error ("\`$info_cursor' missing \@setfilename");
	    next;
	}

	if ($out_file =~ /\.(.+)$/ && $1 ne 'info')
	{
	    # FIXME should report line number in input file.
	    &am_error ("output of \`$info_cursor', \`$out_file', has unrecognized extension");
	    next;
	}

	if ($vtexi)
	{
	    &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
		if (defined $versions{$vtexi});
	    $versions{$vtexi} = $info_cursor;

	    # We number the stamp-vti files.  This is doable since the
	    # actual names don't matter much.  We only number starting
	    # with the second one, so that the common case looks nice.
	    $vti = 'vti' . ($done ? $done : '');
	    &push_dist_common ($vtexi, 'stamp-' . $vti);
	    push (@clean, $vti);

	    # Only require once.
	    &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
					  'mdate-sh')
		if ! $done;
	    ++$done;

	    local ($conf_pat);
	    ($conf_pat = $config_aux_dir) =~ s/(\W)/\\$1/g;
	    $output_rules .=
		&file_contents_with_transform
		    ('s/\@TEXI\@/' . $info_cursor . '/g; '
		     . 's/\@VTI\@/' . $vti . '/g; '
		     . 's/\@VTEXI\@/' . $vtexi . '/g;'
		     . 's,\@MDDIR\@,' . $conf_pat . ',g;',
		     'texi-vers');

	    &push_phony_cleaners ($vti);
	}

	# If user specified file_TEXINFOS, then use that as explicit
	# dependency list.
	@texi_deps = ();
	push (@texi_deps, $info_cursor);
	push (@texi_deps, $vtexi) if $vtexi;

	# Canonicalize name first.
	($canonical = $infobase) =~ tr/A-Za-z0-9_/_/c;
	if (&variable_defined ($canonical . "_TEXINFOS"))
	{
	    push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
	    &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
	}

	$output_rules .= ("\n" . $out_file . ": "
			  . join (' ', @texi_deps)
			  . "\n" . $infobase . ".dvi: "
			  . join (' ', @texi_deps)
			  . "\n\n");

	push (@info_deps_list, $out_file);
	push (@dvis_list, $infobase . '.dvi');

	# Generate list of things to clean for this target.  We do
	# this explicitly because otherwise too many things could be
	# removed.  In particular the ".log" extension might
	# reasonably be used in other contexts by the user.
	foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns',
			    'ky', 'kys', 'ps', 'log', 'pg', 'toc', 'tp', 'tps',
			    'vr', 'vrs', 'op', 'tr', 'cv', 'cn')
	{
	    push (@texi_cleans, $infobase . '.' . $tc_cursor);
	}
    }

    # Find these programs wherever they may lie.  Yes, this has
    # intimate knowledge of the structure of the texinfo distribution.
    &define_program_variable ('MAKEINFO', 'build', 'texinfo/makeinfo',
			      'makeinfo',
			      # Circumlocution to avoid accidental
			      # configure substitution.
			      '@MAKE' . 'INFO@');
    &define_program_variable ('TEXI2DVI', 'src', 'texinfo/util',
			      'texi2dvi');

    # Set transform for including texinfos.am.  First, handle --cygnus
    # stuff.
    local ($xform);
    if ($cygnus_mode)
    {
	$xform = 's/^NOTCYGNUS.*$//; s/^CYGNUS//;';
    }
    else
    {
	$xform = 's/^CYGNUS.*$//; s/^NOTCYGNUS//;';
    }

    # Handle location of texinfo.tex.
    local ($need_texi_file) = 0;
    if ($cygnus_mode)
    {
	&define_variable ('TEXINFO_TEX',
			  '$(top_srcdir)/../texinfo/texinfo.tex');
    }
    elsif ($config_aux_dir ne '.' && $config_aux_dir ne '')
    {
	&define_variable ('TEXINFO_TEX', $config_aux_dir . '/texinfo.tex');
    }
    elsif (! &variable_defined ('TEXINFO_TEX'))
    {
	&define_variable ('TEXINFO_TEX', '$(srcdir)/texinfo.tex');
    }
    else
    {
	$need_texi_file = 1;
    }
    local ($xxform) = &dirname (&variable_value ('TEXINFO_TEX'));
    $xxform =~ s/(\W)/\\$1/g;
    $xform .= ' s/\@TEXINFODIR\@/' . $xxform . '/g;';

    $output_rules .= &file_contents_with_transform ($xform, 'texinfos');
    push (@phony, 'install-info-am', 'uninstall-info');
    push (@dist_targets, 'dist-info');

    # How to clean.  The funny name is due to --cygnus influence; in
    # Cygnus mode, `clean-info' is a target that users can use.
    $output_rules .= "\nmostlyclean-aminfo:\n";
    &pretty_print_rule ("\t-rm -f", "\t  ", @texi_cleans);
    $output_rules .= ("\nclean-aminfo:\n\ndistclean-aminfo:\n\n"
		      . "maintainer-clean-aminfo:\n\t"
		      # Eww.  But how else can we find all the output
		      # files from makeinfo?
		      . 'for i in $(INFO_DEPS); do' . " \\\n"
		      . "\t" . '  rm -f $$i;' . " \\\n"
		      . "\t" . '  if test "`echo $$i-[0-9]*`" != "$$i-[0-9]*"; then' . " \\\n"
		      . "\t" . '    rm -f $$i-[0-9]*;' . " \\\n"
		      . "\t" . '  fi;' . " \\\n"
		      . "\tdone\n");
    &push_phony_cleaners ('aminfo');
    if ($cygnus_mode)
    {
	$output_rules .= "clean-info: mostlyclean-aminfo\n";
    }

    push (@suffixes, '.texi', '.texinfo', '.txi', '.info', '.dvi', '.ps');

    if (! defined $options{'no-installinfo'})
    {
	push (@uninstall, 'uninstall-info');
	push (@installdirs, '$(DESTDIR)$(infodir)');
	unshift (@install_data, 'install-info-am');

	# Make sure documentation is made and installed first.  Use
	# $(INFO_DEPS), not 'info', because otherwise recursive makes
	# get run twice during "make all".
	unshift (@all, '$(INFO_DEPS)');
    }
    push (@clean, 'aminfo');
    push (@info, '$(INFO_DEPS)');
    push (@dvi, '$(DVIS)');

    &define_variable ("INFO_DEPS", join (' ', @info_deps_list));
    &define_variable ("DVIS", join (' ', @dvis_list));
    # This next isn't strictly needed now -- the places that look here
    # could easily be changed to look in info_TEXINFOS.  But this is
    # probably better, in case noinst_TEXINFOS is ever supported.
    &define_variable ("TEXINFOS", &variable_value ('info_TEXINFOS'));

    # Do some error checking.  Note that this file is not required
    # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
    # up above.
    &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex')
	if $need_texi_file && ! defined $options{'no-texinfo.tex'};
}

# Handle any man pages.
sub handle_man_pages
{
    &am_line_error ('MANS', "\`MANS' is an anachronism; use \`man_MANS'")
	if &variable_defined ('MANS');
    return if ! &variable_defined ('man_MANS');

    # Find all the sections in use.  We do this by first looking for
    # "standard" sections, and then looking for any additional
    # sections used in man_MANS.
    local ($sect, %sections, %vlist);
    # Add more sections as needed.
    foreach $sect ('0'..'9', 'n', 'l')
    {
	if (&variable_defined ('man' . $sect . '_MANS'))
	{
	    $sections{$sect} = 1;
	    $vlist{'$(man' . $sect . '_MANS)'} = 1;
	}
    }

    if (&variable_defined ('man_MANS'))
    {
	$vlist{'$(man_MANS)'} = 1;
	foreach (&variable_value_as_list ('man_MANS', 'all'))
	{
	    # A page like `foo.1c' goes into man1dir.
	    if (/\.([0-9a-z])([a-z]*)$/)
	    {
		$sections{$1} = 1;
	    }
	}
    }


    # Now for each section, generate an install and unintall rule.
    # Sort sections so output is deterministic.
    local (@namelist);
    foreach $sect (sort keys %sections)
    {
	&define_variable ('man' . $sect . 'dir', '$(mandir)/man' . $sect);
	push (@installdirs, '$(DESTDIR)$(mandir)/man' . $sect)
	    unless defined $options{'no-installman'};
	$output_rules .= &file_contents_with_transform ('s/\@SECTION\@/'
							. $sect . '/g;',
							'mans');
	push (@phony, 'install-man' . $sect, 'uninstall-man' . $sect);
	push (@namelist, 'install-man' . $sect);
    }

    # We don't really need this, but we use it in case we ever want to
    # support noinst_MANS.
    &define_variable ("MANS", join (' ', sort keys %vlist));

    # Generate list of install dirs.
    $output_rules .= ("install-man: \$(MANS)\n"
		      . "\t\@\$(NORMAL_INSTALL)\n");
    &pretty_print_rule ("\t\$(MAKE)", "\t ", @namelist);
    push (@phony, 'install-man');

    $output_rules .= "uninstall-man:\n\t\@\$(NORMAL_UNINSTALL)\n";
    grep ($_ = 'un' . $_, @namelist);
    &pretty_print_rule ("\t\$(MAKE)", "\t ", @namelist);
    push (@phony, 'uninstall-man');

    $output_vars .= &file_contents ('mans-vars');

    if (! defined $options{'no-installman'})
    {
	push (@install_data, 'install-man');
	push (@uninstall, 'uninstall-man');
	push (@all, '$(MANS)');
    }
}

# Handle DATA variables.
sub handle_data
{
    &am_install_var ('data', 'DATA', 'data', 'sysconf',
		     'sharedstate', 'localstate', 'pkgdata',
		     'noinst', 'check');
}

# Handle TAGS.
sub handle_tags
{
    push (@phony, 'tags');
    local (@tag_deps) = ();
    if (&variable_defined ('SUBDIRS'))
    {
	$output_rules .= ("tags-recursive:\n"
			  . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
			  # Never fail here if a subdir fails; it
			  # isn't important.
			  . "\t  (cd \$\$subdir && \$(MAKE) tags); \\\n"
			  . "\tdone\n");
	push (@tag_deps, 'tags-recursive');
	push (@phony, 'tags-recursive');
    }

    if ($dir_holds_sources
	|| $dir_holds_headers
	|| &variable_defined ('ETAGS_ARGS')
	|| @tag_deps)
    {
	local ($xform) = '';
	local ($one_hdr);
	foreach $one_hdr (@config_headers)
	{
	    if ($relative_dir eq &dirname ($one_hdr))
	    {
		# The config header is in this directory.  So require it.
		local ($var);
		($var = &basename ($one_hdr)) =~ s/(\W)/\\$1/g;
		$xform .= ' ' if $xform;
		$xform .= $var;
	    }
	}
	$xform = ('s/\@CONFIG\@/' . $xform . '/;'
		  . 's/\@DIRS\@/' . join (' ', @tag_deps) . '/;');

	if (&variable_defined ('SUBDIRS'))
	{
	    $xform .= 's/^SUBDIRS//;';
	}
	else
	{
	    $xform .= 's/^SUBDIRS.*$//;';
	}

	$output_rules .= &file_contents_with_transform ($xform, 'tags');
	$output_rules .= &file_contents ('tags-clean');
	push (@clean, 'tags');
	&push_phony_cleaners ('tags');
	&examine_variable ('TAGS_DEPENDENCIES');
    }
    elsif (&variable_defined ('TAGS_DEPENDENCIES'))
    {
	&am_line_error ('TAGS_DEPENDENCIES',
			"doesn't make sense to define \`TAGS_DEPENDENCIES' without sources or \`ETAGS_ARGS'");
    }
    else
    {
	# Every Makefile must define some sort of TAGS rule.
	# Otherwise, it would be possible for a top-level "make TAGS"
	# to fail because some subdirectory failed.
	$output_rules .= "tags: TAGS\nTAGS:\n\n";
    }
}

# Worker for handle_dist.
sub handle_dist_worker
{
    local ($makefile) = @_;

    $output_rules .= 'distdir: $(DISTFILES)' . "\n";

    # Initialization; only at top level.
    if ($relative_dir eq '.')
    {
	if (defined $options{'check-news'})
	{
	    # For Gnits users, this is pretty handy.  Look at 15 lines
	    # in case some explanatory text is desirable.
	    $output_rules .= '	@if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" > /dev/null; then :; else \\
	  echo "NEWS not updated; not releasing" 1>&2; \\
	  exit 1; \\
	fi
';
	}


	# Create dist directory.
	$output_rules .= ("\t-rm -rf \$(distdir)\n"
			  . "\tmkdir \$(distdir)\n"
			  . "\t-chmod 777 \$(distdir)\n");
    }

    # Only run automake in `dist' target if --include-deps and
    # `no-dependencies' not specified.  That way the recipient of a
    # distribution can run "make dist" and not need Automake.  You
    # might be wondering why we run automake once for each directory
    # we distribute, instead of running it once at the top level.  The
    # answer is that we want to run automake after the dependencies
    # have been generated
    elsxlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
					   '_SOURCES', '_OBJECTS',
					   '_DEPENDENCIES');

	if (! &variable_defined ($xlib . '_LDFLAGS'))
	{
	    # Define the lib_LDFLAGS variable.
	    &define_variable ($xlib . '_LDFLAGS', '');
	}

	if (&variable_defined ($xlib . '_LIBADD'))
	{
	    if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
	    {
		$seen_libobjs = 1;
	    }
	}
	else
	{
	    # Generate support for conditional object inclusion in
	    # libraries.
	    &define_variable ($xlib . "_LIBADD", '');
	}

	if (&variable_defined ($xlib . '_LDADD'))
	{
	    &am_line_error ($xlib . '_LDADD',
			    "use \`" . $xlib . "_LIBADD', not \`"
			    . $xlib . "_LDADD'");
	}

	# Make sure we at look at this.
	&examine_variable ($xlib . '_DEPENDENCIES');

	local ($linker) = &handle_source_transform ($xlib, $onelib, $obj);

	# Determine program to use for link.
	local ($xlink);
	if (&variable_defined ($xlib . '_LINK'))
	{
	    $xlink = $xlib . '_LINK';
	}
	else
	{
	    $xlink = $linker ? $linker : 'LINK';
	}

	local ($rpath);
	if ($instdirs{$onelib} eq 'EXTRA')
	{
	    # It's an EXTRA_ library, so we can't specify -rpath.
	    # Yuck.
	    $rpath = 's/\@RPATH\@//go;';
	}
	else
	{
	    $rpath = ('s/\@RPATH\@/-rpath \$(' . $instdirs{$onelib}
		      . 'dir)/go;');
	}

	$output_rules .=
	    &file_contents_with_transform ('s/\@LTLIBRARY\@/'
					   . $onelib . '/go;'
					   . 's/\@XLTLIBRARY\@/'
					   . $xlib . '/go;'
					   . $rpath
					   . 's/\@XLINK\@/' . $xlink . '/go;',
					   'ltlibrary');
    }

    if ($seen_libobjs)
    {
	foreach $onelib (@liblist)
	{
	    # Canonicalize names.
	    ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
	    if (&variable_defined ($xlib . '_LIBADD'))
	    {
		&check_libobjs_sources ($xlib, $xlib . '_LIBADD');
	    }
	}
    }
}

# See if any _SOURCES variable were misspelled.  Also, make sure that
# EXTRA_ variables don't contain configure substitutions.
sub check_typos
{
    local ($varname, $primary);
    foreach $varname (keys %contents)
    {
	foreach $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
			  '_DEPENDENCIES')
	{
	    if ($varname =~ /$primary$/ && ! $content_seen{$varname})
	    {
		&am_line_error ($varname,
				"invalid unused variable name: \`$varname'");
	    }
	}
    }
}

# Handle scripts.
sub handle_scripts
{
    # NOTE we no longer automatically clean SCRIPTS, because it is
    # useful to sometimes distribute scripts verbatim.  This happens
    # eg in Automake itself.
    &am_install_var ('scripts', 'SCRIPTS',
		     'bin', 'sbin', 'libexec', 'pkgdata',
		     'noinst', 'check');

    # Set $scripts_installed if appropriate.  Make sure we only find
    # scripts which are actually installed -- this is why we can't
    # simply use the return value of am_install_var.
    local (%valid) = &am_primary_prefixes ('SCRIPTS', 'bin', 'sbin',
					   'libexec', 'pkgdata',
					   'noinst', 'check');
    local ($key);
    foreach $key (keys %valid)
    {
	if ($key ne 'noinst'
	    && $key ne 'check'
	    && &variable_defined ($key . '_SCRIPTS'))
	{
	    $scripts_installed = 1;
	    # push (@check_tests, 'check-' . $key . 'SCRIPTS');
	}
    }

    if ($scripts_installed)
    {
	# If a program is installed, this is required.  We only want this
	# error to appear once.
	&am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
	    unless $seen_arg_prog;
	$seen_arg_prog = 1;
    }
}

# Search a file for a "version.texi" Texinfo include.  Return the name
# of the include file if found, or the empty string if not.  A
# "version.texi" file is actually any file whose name matches
# "vers*.texi".
sub scan_texinfo_file
{
    local ($filename) = @_;

    if (! open (TEXI, $filename))
    {
	&am_error ("couldn't open \`$filename': $!");
	return '';
    }
    print "automake: reading $filename\n" if $verbose;

    local ($vfile, $outfile);
    while (<TEXI>)
    {
	if (/^\@setfilename +(\S+)/)
	{
	    $outfile = $1;
	    last if ($vfile);
	}

	if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
	{
	    # Found version.texi include.
	    $vfile = $1;
	    last if $outfile;
	}
    }

    close (TEXI);
    return ($outfile, $vfile);
}

# Handle all Texinfo source.
sub handle_texinfo
{
    &am_line_error ('TEXINFOS',
		    "\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
	if &variable_defined ('TEXINFOS');
    return if (! &variable_defined ('info_TEXINFOS')
	       && ! &variable_defined ('html_TEXINFOS'));

    local (@texis) = &variable_value_as_list ('info_TEXINFOS', 'all');

    local (@info_deps_list, @dvis_list, @texi_deps);
    local ($infobase, $info_cursor);
    local (%versions);
    local ($done) = 0;
    local ($vti);
    local ($tc_cursor, @texi_cleans);
    local ($canonical);

    foreach $info_cursor (@texis)
    {
	# FIXME: This is mildly hacky, since it recognizes "txinfo".
	# I don't feel like making it right.
	($infobase = $info_cursor) =~ s/\.te?xi(nfo)?$//;

	# If 'version.texi' is referenced by input file, then include
	# automatic versioning capability.
	local ($out_file, $vtexi) = &scan_texinfo_file ($relative_dir
							. "/" . $info_cursor);

	if ($out_file eq '')
	{
	    &am_error ("\`$info_cursor' missing \@setfilename");
	    next;
	}

	if ($out_file =~ /\.(.+)$/ && $1 ne 'info')
	{
	    # FIXME should report line number in input file.
	    &am_error ("output of \`$info_cursor', \`$out_file', has unrecognized extension");
	    next;
	}

	if ($vtexi)
	{
	    &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
		if (defined $versions{$vtexi});
	    $versions{$vtexi} = $info_cursor;

	    # We number the stamp-vti files.  This is doable since the
	    # actual names don't matter much.  We only number starting
	    # with the second one, so that the common case looks nice.
	    $vti = 'vti' . ($done ? $done : '');
	    &push_dist_common ($vtexi, 'stamp-' . $vti);
	    push (@clean, $vti);

	    # Only require once.
	    &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
					  'mdate-sh')
		if ! $done;
	    ++$done;

	    local ($conf_pat);
	    ($conf_pat = $config_aux_dir) =~ s/(\W)/\\$1/g;
	    $output_rules .=
		&file_contents_with_transform
		    ('s/\@TEXI\@/' . $info_cursor . '/g; '
		     . 's/\@VTI\@/' . $vti . '/g; '
		     . 's/\@VTEXI\@/' . $vtexi . '/g;'
		     . 's,\@MDDIR\@,' . $conf_pat . ',g;',
		     'texi-vers');

	    &push_phony_cleaners ($vti);
	}

	# If user specified file_TEXINFOS, then use that as explicit
	# dependency list.
	@texi_deps = ();
	push (@texi_deps, $info_cursor);
	push (@texi_deps, $vtexi) if $vtexi;

	# Canonicalize name first.
	($canonical = $infobase) =~ tr/A-Za-z0-9_/_/c;
	if (&variable_defined ($canonical . "_TEXINFOS"))
	{
	    push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
	    &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
	}

	$output_rules .= ("\n" . $out_file . ": "
			  . join (' ', @texi_deps)
			  . "\n" . $infobase . ".dvi: "
			  . join (' ', @texi_deps)
			  . "\n\n");

	push (@info_deps_list, $out_file);
	push (@dvis_list, $infobase . '.dvi');

	# Generate list of things to clean for this target.  We do
	# this explicitly because otherwise too many things could be
	# removed.  In particular the ".log" extension might
	# reasonably be used in other contexts by the user.
	foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns',
			    'ky', 'kys', 'ps', 'log', 'pg', 'toc', 'tp', 'tps',
			    'vr', 'vrs', 'op', 'tr', 'cv', 'cn')
	{
	    push (@texi_cleans, $infobase . '.' . $tc_cursor);
	}
    }

    # Find these programs wherever they may lie.  Yes, this has
    # intimate knowledge of the structure of the texinfo distribution.
    &define_program_variable ('MAKEINFO', 'build', 'texinfo/makeinfo',
			      'makeinfo',
			      # Circumlocution to avoid accidental
			      # configure substitution.
			      '@MAKE' . 'INFO@');
    &define_program_variable ('TEXI2DVI', 'src', 'texinfo/util',
			      'texi2dvi');

    # Set transform for including texinfos.am.  First, handle --cygnus
    # stuff.
    local ($xform);
    if ($cygnus_mode)
    {
	$xform = 's/^NOTCYGNUS.*$//; s/^CYGNUS//;';
    }
    else
    {
	$xform = 's/^CYGNUS.*$//; s/^NOTCYGNUS//;';
    }

    # Handle location of texinfo.tex.
    local ($need_texi_file) = 0;
    if ($cygnus_mode)
    {
	&define_variable ('TEXINFO_TEX',
			  '$(top_srcdir)/../texinfo/texinfo.tex');
    }
    elsif ($config_aux_dir ne '.' && $config_aux_dir ne '')
    {
	&define_variable ('TEXINFO_TEX', $config_aux_dir . '/texinfo.tex');
    }
    elsif (! &variable_defined ('TEXINFO_TEX'))
    {
	&define_variable ('TEXINFO_TEX', '$(srcdir)/texinfo.tex');
    }
    else
    {
	$need_texi_file = 1;
    }
    local ($xxform) = &dirname (&variable_value ('TEXINFO_TEX'));
    $xxform =~ s/(\W)/\\$1/g;
    $xform .= ' s/\@TEXINFODIR\@/' . $xxform . '/g;';

    $output_rules .= &file_contents_with_transform ($xform, 'texinfos');
    push (@phony, 'install-info-am', 'uninstall-info');
    push (@dist_targets, 'dist-info');

    # How to clean.  The funny name is due to --cygnus influence; in
    # Cygnus mode, `clean-info' is a target that users can use.
    $output_rules .= "\nmostlyclean-aminfo:\n";
    &pretty_print_rule ("\t-rm -f", "\t  ", @texi_cleans);
    $output_rules .= ("\nclean-aminfo:\n\ndistclean-aminfo:\n\n"
		      . "maintainer-clean-aminfo:\n\t"
		      # Eww.  But how else can we find all the output
		      # files from makeinfo?
		      . 'for i in $(INFO_DEPS); do' . " \\\n"
		      . "\t" . '  rm -f $$i;' . " \\\n"
		      . "\t" . '  if test "`echo $$i-[0-9]*`" != "$$i-[0-9]*"; then' . " \\\n"
		      . "\t" . '    rm -f $$i-[0-9]*;' . " \\\n"
		      . "\t" . '  fi;' . " \\\n"
		      . "\tdone\n");
    &push_phony_cleaners ('aminfo');
    if ($cygnus_mode)
    {
	$output_rules .= "clean-info: mostlyclean-aminfo\n";
    }

    push (@suffixes, '.texi', '.texinfo', '.txi', '.info', '.dvi', '.ps');

    if (! defined $options{'no-installinfo'})
    {
	push (@uninstall, 'uninstall-info');
	push (@installdirs, '$(DESTDIR)$(infodir)');
	unshift (@install_data, 'install-info-am');

	# Make sure documentation is made and installed first.  Use
	# $(INFO_DEPS), not 'info', because otherwise recursive makes
	# get run twice during "make all".
	unshift (@all, '$(INFO_DEPS)');
    }
    push (@clean, 'aminfo');
    push (@info, '$(INFO_DEPS)');
    push (@dvi, '$(DVIS)');

    &define_variable ("INFO_DEPS", join (' ', @info_deps_list));
    &define_variable ("DVIS", join (' ', @dvis_list));
    # This next isn't strictly needed now -- the places that look here
    # could easily be changed to look in info_TEXINFOS.  But this is
    # probably better, in case noinst_TEXINFOS is ever supported.
    &define_variable ("TEXINFOS", &variable_value ('info_TEXINFOS'));

    # Do some error checking.  Note that this file is not required
    # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
    # up above.
    &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex')
	if $need_texi_file && ! defined $options{'no-texinfo.tex'};
}

# Handle any man pages.
sub handle_man_pages
{
    &am_line_error ('MANS', "\`MANS' is an anachronism; use \`man_MANS'")
	if &variable_defined ('MANS');
    return if ! &variable_defined ('man_MANS');

    # Find all the sections in use.  We do this by first looking for
    # "standard" sections, and then looking for any additional
    # sections used in man_MANS.
    local ($sect, %sections, %vlist);
    # Add more sections as needed.
    foreach $sect ('0'..'9', 'n', 'l')
    {
	if (&variable_defined ('man' . $sect . '_MANS'))
	{
	    $sections{$sect} = 1;
	    $vlist{'$(man' . $sect . '_MANS)'} = 1;
	}
    }

    if (&variable_defined ('man_MANS'))
    {
	$vlist{'$(man_MANS)'} = 1;
	foreach (&variable_value_as_list ('man_MANS', 'all'))
	{
	    # A page like `foo.1c' goes into man1dir.
	    if (/\.([0-9a-z])([a-z]*)$/)
	    {
		$sections{$1} = 1;
	    }
	}
    }


    # Now for each section, generate an install and unintall rule.
    # Sort sections so output is deterministic.
    local (@namelist);
    foreach $sect (sort keys %sections)
    {
	&define_variable ('man' . $sect . 'dir', '$(mandir)/man' . $sect);
	push (@installdirs, '$(DESTDIR)$(mandir)/man' . $sect)
	    unless defined $options{'no-installman'};
	$output_rules .= &file_contents_with_transform ('s/\@SECTION\@/'
							. $sect . '/g;',
							'mans');
	push (@phony, 'install-man' . $sect, 'uninstall-man' . $sect);
	push (@namelist, 'install-man' . $sect);
    }

    # We don't really need this, but we use it in case we ever want to
    # support noinst_MANS.
    &define_variable ("MANS", join (' ', sort keys %vlist));

    # Generate list of install dirs.
    $output_rules .= ("install-man: \$(MANS)\n"
		      . "\t\@\$(NORMAL_INSTALL)\n");
    &pretty_print_rule ("\t\$(MAKE)", "\t ", @namelist);
    push (@phony, 'install-man');

    $output_rules .= "uninstall-man:\n\t\@\$(NORMAL_UNINSTALL)\n";
    grep ($_ = 'un' . $_, @namelist);
    &pretty_print_rule ("\t\$(MAKE)", "\t ", @namelist);
    push (@phony, 'uninstall-man');

    $output_vars .= &file_contents ('mans-vars');

    if (! defined $options{'no-installman'})
    {
	push (@install_data, 'install-man');
	push (@uninstall, 'uninstall-man');
	push (@all, '$(MANS)');
    }
}

# Handle DATA variables.
sub handle_data
{
    &am_install_var ('data', 'DATA', 'data', 'sysconf',
		     'sharedstate', 'localstate', 'pkgdata',
		     'noinst', 'check');
}

# Handle TAGS.
sub handle_tags
{
    push (@phony, 'tags');
    local (@tag_deps) = ();
    if (&variable_defined ('SUBDIRS'))
    {
	$output_rules .= ("tags-recursive:\n"
			  . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
			  # Never fail here if a subdir fails; it
			  # isn't important.
			  . "\t  (cd \$\$subdir && \$(MAKE) tags); \\\n"
			  . "\tdone\n");
	push (@tag_deps, 'tags-recursive');
	push (@phony, 'tags-recursive');
    }

    if ($dir_holds_sources
	|| $dir_holds_headers
	|| &variable_defined ('ETAGS_ARGS')
	|| @tag_deps)
    {
	local ($xform) = '';
	local ($one_hdr);
	foreach $one_hdr (@config_headers)
	{
	    if ($relative_dir eq &dirname ($one_hdr))
	    {
		# The config header is in this directory.  So require it.
		local ($var);
		($var = &basename ($one_hdr)) =~ s/(\W)/\\$1/g;
		$xform .= ' ' if $xform;
		$xform .= $var;
	    }
	}
	$xform = ('s/\@CONFIG\@/' . $xform . '/;'
		  . 's/\@DIRS\@/' . join (' ', @tag_deps) . '/;');

	if (&variable_defined ('SUBDIRS'))
	{
	    $xform .= 's/^SUBDIRS//;';
	}
	else
	{
	    $xform .= 's/^SUBDIRS.*$//;';
	}

	$output_rules .= &file_contents_with_transform ($xform, 'tags');
	$output_rules .= &file_contents ('tags-clean');
	push (@clean, 'tags');
	&push_phony_cleaners ('tags');
	&examine_variable ('TAGS_DEPENDENCIES');
    }
    elsif (&variable_defined ('TAGS_DEPENDENCIES'))
    {
	&am_line_error ('TAGS_DEPENDENCIES',
			"doesn't make sense to define \`TAGS_DEPENDENCIES' without sources or \`ETAGS_ARGS'");
    }
    else
    {
	# Every Makefile must define some sort of TAGS rule.
	# Otherwise, it would be possible for a top-level "make TAGS"
	# to fail because some subdirectory failed.
	$output_rules .= "tags: TAGS\nTAGS:\n\n";
    }
}

# Worker for handle_dist.
sub handle_dist_worker
{
    local ($makefile) = @_;

    $output_rules .= 'distdir: $(DISTFILES)' . "\n";

    # Initialization; only at top level.
    if ($relative_dir eq '.')
    {
	if (defined $options{'check-news'})
	{
	    # For Gnits users, this is pretty handy.  Look at 15 lines
	    # in case some explanatory text is desirable.
	    $output_rules .= '	@if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" > /dev/null; then :; else \\
	  echo "NEWS not updated; not releasing" 1>&2; \\
	  exit 1; \\
	fi
';
	}


	# Create dist directory.
	$output_rules .= ("\t-rm -rf \$(distdir)\n"
			  . "\tmkdir \$(distdir)\n"
			  . "\t-chmod 777 \$(distdir)\n");
    }

    # Only run automake in `dist' target if --include-deps and
    # `no-dependencies' not specified.  That way the recipient of a
    # distribution can run "make dist" and not need Automake.  You
    # might be wondering why we run automake once for each directory
    # we distribute, instead of running it once at the top level.  The
    # answer is that we want to run automake after the dependencies
    # have been generated
    elsxlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
					   '_SOURCES', '_OBJECTS',
					   '_DEPENDENCIES');

	if (! &variable_defined ($xlib . '_LDFLAGS'))
	{
	    # Define the lib_LDFLAGS variable.
	    &define_variable ($xlib . '_LDFLAGS', '');
	}

	if (&variable_defined ($xlib . '_LIBADD'))
	{
	    if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
	    {
		$seen_libobjs = 1;
	    }
	}
	else
	{
	    # Generate support for conditional object inclusion in
	    # libraries.
	    &define_variable ($xlib . "_LIBADD", '');
	}

	if (&variable_defined ($xlib . '_LDADD'))
	{
	    &am_line_error ($xlib . '_LDADD',
			    "use \`" . $xlib . "_LIBADD', not \`"
			    . $xlib . "_LDADD'");
	}

	# Make sure we at look at this.
	&examine_variable ($xlib . '_DEPENDENCIES');

	local ($linker) = &handle_source_transform ($xlib, $onelib, $obj);

	# Determine program to use for link.
	local ($xlink);
	if (&variable_defined ($xlib . '_LINK'))
	{
	    $xlink = $xlib . '_LINK';
	}
	else
	{
	    $xlink = $linker ? $linker : 'LINK';
	}

	local ($rpath);
	if ($instdirs{$onelib} eq 'EXTRA')
	{
	    # It's an EXTRA_ library, so we can't specify -rpath.
	    # Yuck.
	    $rpath = 's/\@RPATH\@//go;';
	}
	else
	{
	    $rpath = ('s/\@RPATH\@/-rpath \$(' . $instdirs{$onelib}
		      . 'dir)/go;');
	}

	$output_rules .=
	    &file_contents_with_transform ('s/\@LTLIBRARY\@/'
					   . $onelib . '/go;'
					   . 's/\@XLTLIBRARY\@/'
					   . $xlib . '/go;'
					   . $rpath
					   . 's/\@XLINK\@/' . $xlink . '/go;',
					   'ltlibrary');
    }

    if ($seen_libobjs)
    {
	foreach $onelib (@liblist)
	{
	    # Canonicalize names.
	    ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
	    if (&variable_defined ($xlib . '_LIBADD'))
	    {
		&check_libobjs_sources ($xlib, $xlib . '_LIBADD');
	    }
	}
    }
}

# See if any _SOURCES variable were misspelled.  Also, make sure that
# EXTRA_ variables don't contain configure substitutions.
sub check_typos
{
    local ($varname, $primary);
    foreach $varname (keys %contents)
    {
	foreach $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
			  '_DEPENDENCIES')
	{
	    if ($varname =~ /$primary$/ && ! $content_seen{$varname})
	    {
		&am_line_error ($varname,
				"invalid unused variable name: \`$varname'");
	    }
	}
    }
}

# Handle scripts.
sub handle_scripts
{
    # NOTE we no longer automatically clean SCRIPTS, because it is
    # useful to sometimes distribute scripts verbatim.  This happens
    # eg in Automake itself.
    &am_install_var ('scripts', 'SCRIPTS',
		     'bin', 'sbin', 'libexec', 'pkgdata',
		     'noinst', 'check');

    # Set $scripts_installed if appropriate.  Make sure we only find
    # scripts which are actually installed -- this is why we can't
    # simply use the return value of am_install_var.
    local (%valid) = &am_primary_prefixes ('SCRIPTS', 'bin', 'sbin',
					   'libexec', 'pkgdata',
					   'noinst', 'check');
    local ($key);
    foreach $key (keys %valid)
    {
	if ($key ne 'noinst'
	    && $key ne 'check'
	    && &variable_defined ($key . '_SCRIPTS'))
	{
	    $scripts_installed = 1;
	    # push (@check_tests, 'check-' . $key . 'SCRIPTS');
	}
    }

    if ($scripts_installed)
    {
	# If a program is installed, this is required.  We only want this
	# error to appear once.
	&am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
	    unless $seen_arg_prog;
	$seen_arg_prog = 1;
    }
}

# Search a file for a "version.texi" Texinfo include.  Return the name
# of the include file if found, or the empty string if not.  A
# "version.texi" file is actually any file whose name matches
# "vers*.texi".
sub scan_texinfo_file
{
    local ($filename) = @_;

    if (! open (TEXI, $filename))
    {
	&am_error ("couldn't open \`$filename': $!");
	return '';
    }
    print "automake: reading $filename\n" if $verbose;

    local ($vfile, $outfile);
    while (<TEXI>)
    {
	if (/^\@setfilename +(\S+)/)
	{
	    $outfile = $1;
	    last if ($vfile);
	}

	if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
	{
	    # Found version.texi include.
	    $vfile = $1;
	    last if $outfile;
	}
    }

    close (TEXI);
    return ($outfile, $vfile);
}

# Handle all Texinfo source.
sub handle_texinfo
{
    &am_line_error ('TEXINFOS',
		    "\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
	if &variable_defined ('TEXINFOS');
    return if (! &variable_defined ('info_TEXINFOS')
	       && ! &variable_defined ('html_TEXINFOS'));

    local (@texis) = &variable_value_as_list ('info_TEXINFOS', 'all');

    local (@info_deps_list, @dvis_list, @texi_deps);
    local ($infobase, $info_cursor);
    local (%versions);
    local ($done) = 0;
    local ($vti);
    local ($tc_cursor, @texi_cleans);
    local ($canonical);

    foreach $info_cursor (@texis)
    {
	# FIXME: This is mildly hacky, since it recognizes "txinfo".
	# I don't feel like making it right.
	($infobase = $info_cursor) =~ s/\.te?xi(nfo)?$//;

	# If 'version.texi' is referenced by input file, then include
	# automatic versioning capability.
	local ($out_file, $vtexi) = &scan_texinfo_file ($relative_dir
							. "/" . $info_cursor);

	if ($out_file eq '')
	{
	    &am_error ("\`$info_cursor' missing \@setfilename");
	    next;
	}

	if ($out_file =~ /\.(.+)$/ && $1 ne 'info')
	{
	    # FIXME should report line number in input file.
	    &am_error ("output of \`$info_cursor', \`$out_file', has unrecognized extension");
	    next;
	}

	if ($vtexi)
	{
	    &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
		if (defined $versions{$vtexi});
	    $versions{$vtexi} = $info_cursor;

	    # We number the stamp-vti files.  This is doable since the
	    # actual names don't matter much.  We only number starting
	    # with the second one, so that the common case looks nice.
	    $vti = 'vti' . ($done ? $done : '');
	    &push_dist_common ($vtexi, 'stamp-' . $vti);
	    push (@clean, $vti);

	    # Only require once.
	    &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
					  'mdate-sh')
		if ! $done;
	    ++$done;

	    local ($conf_pat);
	    ($conf_pat = $config_aux_dir) =~ s/(\W)/\\$1/g;
	    $output_rules .=
		&file_contents_with_transform
		    ('s/\@TEXI\@/' . $info_cursor . '/g; '
		     . 's/\@VTI\@/' . $vti . '/g; '
		     . 's/\@VTEXI\@/' . $vtexi . '/g;'
		     . 's,\@MDDIR\@,' . $conf_pat . ',g;',
		     'texi-vers');

	    &push_phony_cleaners ($vti);
	}

	# If user specified file_TEXINFOS, then use that as explicit
	# dependency list.
	@texi_deps = ();
	push (@texi_deps, $info_cursor);
	push (@texi_deps, $vtexi) if $vtexi;

	# Canonicalize name first.
	($canonical = $infobase) =~ tr/A-Za-z0-9_/_/c;
	if (&variable_defined ($canonical . "_TEXINFOS"))
	{
	    push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
	    &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
	}

	$output_rules .= ("\n" . $out_file . ": "
			  . join (' ', @texi_deps)
			  . "\n" . $infobase . ".dvi: "
			  . join (' ', @texi_deps)
			  . "\n\n");

	push (@info_deps_list, $out_file);
	push (@dvis_list, $infobase . '.dvi');

	# Generate list of things to clean for this target.  We do
	# this explicitly because otherwise too many things could be
	# removed.  In particular the ".log" extension might
	# reasonably be used in other contexts by the user.
	foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns',
			    'ky', 'kys', 'ps', 'log', 'pg', 'toc', 'tp', 'tps',
			    'vr', 'vrs', 'op', 'tr', 'cv', 'cn')
	{
	    push (@texi_cleans, $infobase . '.' . $tc_cursor);
	}
    }

    # Find these programs wherever they may lie.  Yes, this has
    # intimate knowledge of the structure of the texinfo distribution.
    &define_program_variable ('MAKEINFO', 'build', 'texinfo/makeinfo',
			      'makeinfo',
			      # Circumlocution to avoid accidental
			      # configure substitution.
			      '@MAKE' . 'INFO@');
    &define_program_variable ('TEXI2DVI', 'src', 'texinfo/util',
			      'texi2dvi');

    # Set transform for including texinfos.am.  First, handle --cygnus
    # stuff.
    local ($xform);
    if ($cygnus_mode)
    {
	$xform = 's/^NOTCYGNUS.*$//; s/^CYGNUS//;';
    }
    else
    {
	$xform = 's/^CYGNUS.*$//; s/^NOTCYGNUS//;';
    }

    # Handle location of texinfo.tex.
    local ($need_texi_file) = 0;
    if ($cygnus_mode)
    {
	&define_variable ('TEXINFO_TEX',
			  '$(top_srcdir)/../texinfo/texinfo.tex');
    }
    elsif ($config_aux_dir ne '.' && $config_aux_dir ne '')
    {
	&define_variable ('TEXINFO_TEX', $config_aux_dir . '/texinfo.tex');
    }
    elsif (! &variable_defined ('TEXINFO_TEX'))
    {
	&define_variable ('TEXINFO_TEX', '$(srcdir)/texinfo.tex');
    }
    else
    {
	$need_texi_file = 1;
    }
    local ($xxform) = &dirname (&variable_value ('TEXINFO_TEX'));
    $xxform =~ s/(\W)/\\$1/g;
    $xform .= ' s/\@TEXINFODIR\@/' . $xxform . '/g;';

    $output_rules .= &file_contents_with_transform ($xform, 'texinfos');
    push (@phony, 'install-info-am', 'uninstall-info');
    push (@dist_targets, 'dist-info');

    # How to clean.  The funny name is due to --cygnus influence; in
    # Cygnus mode, `clean-info' is a target that users can use.
    $output_rules .= "\nmostlyclean-aminfo:\n";
    &pretty_print_rule ("\t-rm -f", "\t  ", @texi_cleans);
    $output_rules .= ("\nclean-aminfo:\n\ndistclean-aminfo:\n\n"
		      . "maintainer-clean-aminfo:\n\t"
		      # Eww.  But how else can we find all the output
		      # files from makeinfo?
		      . 'for i in $(INFO_DEPS); do' . " \\\n"
		      . "\t" . '  rm -f $$i;' . " \\\n"
		      . "\t" . '  if test "`echo $$i-[0-9]*`" != "$$i-[0-9]*"; then' . " \\\n"
		      . "\t" . '    rm -f $$i-[0-9]*;' . " \\\n"
		      . "\t" . '  fi;' . " \\\n"
		      . "\tdone\n");
    &push_phony_cleaners ('aminfo');
    if ($cygnus_mode)
    {
	$output_rules .= "clean-info: mostlyclean-aminfo\n";
    }

    push (@suffixes, '.texi', '.texinfo', '.txi', '.info', '.dvi', '.ps');

    if (! defined $options{'no-installinfo'})
    {
	push (@uninstall, 'uninstall-info');
	push (@installdirs, '$(DESTDIR)$(infodir)');
	unshift (@install_data, 'install-info-am');

	# Make sure documentation is made and installed first.  Use
	# $(INFO_DEPS), not 'info', because otherwise recursive makes
	# get run twice during "make all".
	unshift (@all, '$(INFO_DEPS)');
    }
    push (@clean, 'aminfo');
    push (@info, '$(INFO_DEPS)');
    push (@dvi, '$(DVIS)');

    &define_variable ("INFO_DEPS", join (' ', @info_deps_list));
    &define_variable ("DVIS", join (' ', @dvis_list));
    # This next isn't strictly needed now -- the places that look here
    # could easily be changed to look in info_TEXINFOS.  But this is
    # probably better, in case noinst_TEXINFOS is ever supported.
    &define_variable ("TEXINFOS", &variable_value ('info_TEXINFOS'));

    # Do some error checking.  Note that this file is not required
    # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
    # up above.
    &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex')
	if $need_texi_file && ! defined $options{'no-texinfo.tex'};
}

# Handle any man pages.
sub handle_man_pages
{
    &am_line_error ('MANS', "\`MANS' is an anachronism; use \`man_MANS'")
	if &variable_defined ('MANS');
    return if ! &variable_defined ('man_MANS');

    # Find all the sections in use.  We do this by first looking for
    # "standard" sections, and then looking for any additional
    # sections used in man_MANS.
    local ($sect, %sections, %vlist);
    # Add more sections as needed.
    foreach $sect ('0'..'9', 'n', 'l')
    {
	if (&variable_defined ('man' . $sect . '_MANS'))
	{
	    $sections{$sect} = 1;
	    $vlist{'$(man' . $sect . '_MANS)'} = 1;
	}
    }

    if (&variable_defined ('man_MANS'))
    {
	$vlist{'$(man_MANS)'} = 1;
	foreach (&variable_value_as_list ('man_MANS', 'all'))
	{
	    # A page like `foo.1c' goes into man1dir.
	    if (/\.([0-9a-z])([a-z]*)$/)
	    {
		$sections{$1} = 1;
	    }
	}
    }


    # Now for each section, generate an install and unintall rule.
    # Sort sections so output is deterministic.
    local (@namelist);
    foreach $sect (sort keys %sections)
    {
	&define_variable ('man' . $sect . 'dir', '$(mandir)/man' . $sect);
	push (@installdirs, '$(DESTDIR)$(mandir)/man' . $sect)
	    unless defined $options{'no-installman'};
	$output_rules .= &file_contents_with_transform ('s/\@SECTION\@/'
							. $sect . '/g;',
							'mans');
	push (@phony, 'install-man' . $sect, 'uninstall-man' . $sect);
	push (@namelist, 'install-man' . $sect);
    }

    # We don't really need this, but we use it in case we ever want to
    # support noinst_MANS.
    &define_variable ("MANS", join (' ', sort keys %vlist));

    # Generate list of install dirs.
    $output_rules .= ("install-man: \$(MANS)\n"
		      . "\t\@\$(NORMAL_INSTALL)\n");
    &pretty_print_rule ("\t\$(MAKE)", "\t ", @namelist);
    push (@phony, 'install-man');

    $output_rules .= "uninstall-man:\n\t\@\$(NORMAL_UNINSTALL)\n";
    grep ($_ = 'un' . $_, @namelist);
    &pretty_print_rule ("\t\$(MAKE)", "\t ", @namelist);
    push (@phony, 'uninstall-man');

    $output_vars .= &file_contents ('mans-vars');

    if (! defined $options{'no-installman'})
    {
	push (@install_data, 'install-man');
	push (@uninstall, 'uninstall-man');
	push (@all, '$(MANS)');
    }
}

# Handle DATA variables.
sub handle_data
{
    &am_install_var ('data', 'DATA', 'data', 'sysconf',
		     'sharedstate', 'localstate', 'pkgdata',
		     'noinst', 'check');
}

# Handle TAGS.
sub handle_tags
{
    push (@phony, 'tags');
    local (@tag_deps) = ();
    if (&variable_defined ('SUBDIRS'))
    {
	$output_rules .= ("tags-recursive:\n"
			  . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
			  # Never fail here if a subdir fails; it
			  # isn't important.
			  . "\t  (cd \$\$subdir && \$(MAKE) tags); \\\n"
			  . "\tdone\n");
	push (@tag_deps, 'tags-recursive');
	push (@phony, 'tags-recursive');
    }

    if ($dir_holds_sources
	|| $dir_holds_headers
	|| &variable_defined ('ETAGS_ARGS')
	|| @tag_deps)
    {
	local ($xform) = '';
	local ($one_hdr);
	foreach $one_hdr (@config_headers)
	{
	    if ($relative_dir eq &dirname ($one_hdr))
	    {
		# The config header is in this directory.  So require it.
		local ($var);
		($var = &basename ($one_hdr)) =~ s/(\W)/\\$1/g;
		$xform .= ' ' if $xform;
		$xform .= $var;
	    }
	}
	$xform = ('s/\@CONFIG\@/' . $xform . '/;'
		  . 's/\@DIRS\@/' . join (' ', @tag_deps) . '/;');

	if (&variable_defined ('SUBDIRS'))
	{
	    $xform .= 's/^SUBDIRS//;';
	}
	else
	{
	    $xform .= 's/^SUBDIRS.*$//;';
	}

	$output_rules .= &file_contents_with_transform ($xform, 'tags');
	$output_rules .= &file_contents ('tags-clean');
	push (@clean, 'tags');
	&push_phony_cleaners ('tags');
	&examine_variable ('TAGS_DEPENDENCIES');
    }
    elsif (&variable_defined ('TAGS_DEPENDENCIES'))
    {
	&am_line_error ('TAGS_DEPENDENCIES',
			"doesn't make sense to define \`TAGS_DEPENDENCIES' without sources or \`ETAGS_ARGS'");
    }
    else
    {
	# Every Makefile must define some sort of TAGS rule.
	# Otherwise, it would be possible for a top-level "make TAGS"
	# to fail because some subdirectory failed.
	$output_rules .= "tags: TAGS\nTAGS:\n\n";
    }
}

# Worker for handle_dist.
sub handle_dist_worker
{
    local ($makefile) = @_;

    $output_rules .= 'distdir: $(DISTFILES)' . "\n";

    # Initialization; only at top level.
    if ($relative_dir eq '.')
    {
	if (defined $options{'check-news'})
	{
	    # For Gnits users, this is pretty handy.  Look at 15 lines
	    # in case some explanatory text is desirable.
	    $output_rules .= '	@if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" > /dev/null; then :; else \\
	  echo "NEWS not updated; not releasing" 1>&2; \\
	  exit 1; \\
	fi
';
	}


	# Create dist directory.
	$output_rules .= ("\t-rm -rf \$(distdir)\n"
			  . "\tmkdir \$(distdir)\n"
			  . "\t-chmod 777 \$(distdir)\n");
    }

    # Only run automake in `dist' target if --include-deps and
    # `no-dependencies' not specified.  That way the recipient of a
    # distribution can run "make dist" and not need Automake.  You
    # might be wondering why we run automake once for each directory
    # we distribute, instead of running it once at the top level.  The
    # answer is that we want to run automake after the dependencies
    # have been generated
    elsxlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
					   '_SOURCES', '_OBJECTS',
					   '_DEPENDENCIES');

	if (! &variable_defined ($xlib . '_LDFLAGS'))
	{
	    # Define the lib_LDFLAGS variable.
	    &define_variable ($xlib . '_LDFLAGS', '');
	}

	if (&variable_defined ($xlib . '_LIBADD'))
	{
	    if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
	    {
		$seen_libobjs = 1;
	    }
	}
	else
	{
	    # Generate support for conditional object inclusion in
	    # libraries.
	    &define_variable ($xlib . "_LIBADD", '');
	}

	if (&variable_defined ($xlib . '_LDADD'))
	{
	    &am_line_error ($xlib . '_LDADD',
			    "use \`" . $xlib . "_LIBADD', not \`"
			    . $xlib . "_LDADD'");
	}

	# Make sure we at look at this.
	&examine_variable ($xlib . '_DEPENDENCIES');

	local ($linker) = &handle_source_transform ($xlib, $onelib, $obj);

	# Determine program to use for link.
	local ($xlink);
	if (&variable_defined ($xlib . '_LINK'))
	{
	    $xlink = $xlib . '_LINK';
	}
	else
	{
	    $xlink = $linker ? $linker : 'LINK';
	}

	local ($rpath);
	if ($instdirs{$onelib} eq 'EXTRA')
	{
	    # It's an EXTRA_ library, so we can't specify -rpath.
	    # Yuck.
	    $rpath = 's/\@RPATH\@//go;';
	}
	else
	{
	    $rpath = ('s/\@RPATH\@/-rpath \$(' . $instdirs{$onelib}
		      . 'dir)/go;');
	}

	$output_rules .=
	    &file_contents_with_transform ('s/\@LTLIBRARY\@/'
					   . $onelib . '/go;'
					   . 's/\@XLTLIBRARY\@/'
					   . $xlib . '/go;'
					   . $rpath
					   . 's/\@XLINK\@/' . $xlink . '/go;',
					   'ltlibrary');
    }

    if ($seen_libobjs)
    {
	foreach $onelib (@liblist)
	{
	    # Canonicalize names.
	    ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
	    if (&variable_defined ($xlib . '_LIBADD'))
	    {
		&check_libobjs_sources ($xlib, $xlib . '_LIBADD');
	    }
	}
    }
}

# See if any _SOURCES variable were misspelled.  Also, make sure that
# EXTRA_ variables don't contain configure substitutions.
sub check_typos
{
    local ($varname, $primary);
    foreach $varname (keys %contents)
    {
	foreach $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
			  '_DEPENDENCIES')
	{
	    if ($varname =~ /$primary$/ && ! $content_seen{$varname})
	    {
		&am_line_error ($varname,
				"invalid unused variable name: \`$varname'");
	    }
	}
    }
}

# Handle scripts.
sub handle_scripts
{
    # NOTE we no longer automatically clean SCRIPTS, because it is
    # useful to sometimes distribute scripts verbatim.  This happens
    # eg in Automake itself.
    &am_install_var ('scripts', 'SCRIPTS',
		     'bin', 'sbin', 'libexec', 'pkgdata',
		     'noinst', 'check');

    # Set $scripts_installed if appropriate.  Make sure we only find
    # scripts which are actually installed -- this is why we can't
    # simply use the return value of am_install_var.
    local (%valid) = &am_primary_prefixes ('SCRIPTS', 'bin', 'sbin',
					   'libexec', 'pkgdata',
					   'noinst', 'check');
    local ($key);
    foreach $key (keys %valid)
    {
	if ($key ne 'noinst'
	    && $key ne 'check'
	    && &variable_defined ($key . '_SCRIPTS'))
	{
	    $scripts_installed = 1;
	    # push (@check_tests, 'check-' . $key . 'SCRIPTS');
	}
    }

    if ($scripts_installed)
    {
	# If a program is installed, this is required.  We only want this
	# error to appear once.
	&am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
	    unless $seen_arg_prog;
	$seen_arg_prog = 1;
    }
}

# Search a file for a "version.texi" Texinfo include.  Return the name
# of the include file if found, or the empty string if not.  A
# "version.texi" file is actually any file whose name matches
# "vers*.texi".
sub scan_texinfo_file
{
    local ($filename) = @_;

    if (! open (TEXI, $filename))
    {
	&am_error ("couldn't open \`$filename': $!");
	return '';
    }
    print "automake: reading $filename\n" if $verbose;

    local ($vfile, $outfile);
    while (<TEXI>)
    {
	if (/^\@setfilename +(\S+)/)
	{
	    $outfile = $1;
	    last if ($vfile);
	}

	if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
	{
	    # Found version.texi include.
	    $vfile = $1;
	    last if $outfile;
	}
    }

    close (TEXI);
    return ($outfile, $vfile);
}

# Handle all Texinfo source.
sub handle_texinfo
{
    &am_line_error ('TEXINFOS',
		    "\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
	if &variable_defined ('TEXINFOS');
    return if (! &variable_defined ('info_TEXINFOS')
	       && ! &variable_defined ('html_TEXINFOS'));

    local (@texis) = &variable_value_as_list ('info_TEXINFOS', 'all');

    local (@info_deps_list, @dvis_list, @texi_deps);
    local ($infobase, $info_cursor);
    local (%versions);
    local ($done) = 0;
    local ($vti);
    local ($tc_cursor, @texi_cleans);
    local ($canonical);

    foreach $info_cursor (@texis)
    {
	# FIXME: This is mildly hacky, since it recognizes "txinfo".
	# I don't feel like making it right.
	($infobase = $info_cursor) =~ s/\.te?xi(nfo)?$//;

	# If 'version.texi' is referenced by input file, then include
	# automatic versioning capability.
	local ($out_file, $vtexi) = &scan_texinfo_file ($relative_dir
							. "/" . $info_cursor);

	if ($out_file eq '')
	{
	    &am_error ("\`$info_cursor' missing \@setfilename");
	    next;
	}

	if ($out_file =~ /\.(.+)$/ && $1 ne 'info')
	{
	    # FIXME should report line number in input file.
	    &am_error ("output of \`$info_cursor', \`$out_file', has unrecognized extension");
	    next;
	}

	if ($vtexi)
	{
	    &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
		if (defined $versions{$vtexi});
	    $versions{$vtexi} = $info_cursor;

	    # We number the stamp-vti files.  This is doable since the
	    # actual names don't matter much.  We only number starting
	    # with the second one, so that the common case looks nice.
	    $vti = 'vti' . ($done ? $done : '');
	    &push_dist_common ($vtexi, 'stamp-' . $vti);
	    push (@clean, $vti);

	    # Only require once.
	    &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
					  'mdate-sh')
		if ! $done;
	    ++$done;

	    local ($conf_pat);
	    ($conf_pat = $config_aux_dir) =~ s/(\W)/\\$1/g;
	    $output_rules .=
		&file_contents_with_transform
		    ('s/\@TEXI\@/' . $info_cursor . '/g; '
		     . 's/\@VTI\@/' . $vti . '/g; '
		     . 's/\@VTEXI\@/' . $vtexi . '/g;'
		     . 's,\@MDDIR\@,' . $conf_pat . ',g;',
		     'texi-vers');

	    &push_phony_cleaners ($vti);
	}

	# If user specified file_TEXINFOS, then use that as explicit
	# dependency list.
	@texi_deps = ();
	push (@texi_deps, $info_cursor);
	push (@texi_deps, $vtexi) if $vtexi;

	# Canonicalize name first.
	($canonical = $infobase) =~ tr/A-Za-z0-9_/_/c;
	if (&variable_defined ($canonical . "_TEXINFOS"))
	{
	    push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
	    &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
	}

	$output_rules .= ("\n" . $out_file . ": "
			  . join (' ', @texi_deps)
			  . "\n" . $infobase . ".dvi: "
			  . join (' ', @texi_deps)
			  . "\n\n");

	push (@info_deps_list, $out_file);
	push (@dvis_list, $infobase . '.dvi');

	# Generate list of things to clean for this target.  We do
	# this explicitly because otherwise too many things could be
	# removed.  In particular the ".log" extension might
	# reasonably be used in other contexts by the user.
	foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns',
			    'ky', 'kys', 'ps', 'log', 'pg', 'toc', 'tp', 'tps',
			    'vr', 'vrs', 'op', 'tr', 'cv', 'cn')
	{
	    push (@texi_cleans, $infobase . '.' . $tc_cursor);
	}
    }

    # Find these programs wherever they may lie.  Yes, this has
    # intimate knowledge of the structure of the texinfo distribution.
    &define_program_variable ('MAKEINFO', 'build', 'texinfo/makeinfo',
			      'makeinfo',
			      # Circumlocution to avoid accidental
			      # configure substitution.
			      '@MAKE' . 'INFO@');
    &define_program_variable ('TEXI2DVI', 'src', 'texinfo/util',
			      'texi2dvi');

    # Set transform for including texinfos.am.  First, handle --cygnus
    # stuff.
    local ($xform);
    if ($cygnus_mode)
    {
	$xform = 's/^NOTCYGNUS.*$//; s/^CYGNUS//;';
    }
    else
    {
	$xform = 's/^CYGNUS.*$//; s/^NOTCYGNUS//;';
    }

    # Handle location of texinfo.tex.
    local ($need_texi_file) = 0;
    if ($cygnus_mode)
    {
	&define_variable ('TEXINFO_TEX',
			  '$(top_srcdir)/../texinfo/texinfo.tex');
    }
    elsif ($config_aux_dir ne '.' && $config_aux_dir ne '')
    {
	&define_variable ('TEXINFO_TEX', $config_aux_dir . '/texinfo.tex');
    }
    elsif (! &variable_defined ('TEXINFO_TEX'))
    {
	&define_variable ('TEXINFO_TEX', '$(srcdir)/texinfo.tex');
    }
    else
    {
	$need_texi_file = 1;
    }
    local ($xxform) = &dirname (&variable_value ('TEXINFO_TEX'));
    $xxform =~ s/(\W)/\\$1/g;
    $xform .= ' s/\@TEXINFODIR\@/' . $xxform . '/g;';

    $output_rules .= &file_contents_with_transform ($xform, 'texinfos');
    push (@phony, 'install-info-am', 'uninstall-info');
    push (@dist_targets, 'dist-info');

    # How to clean.  The funny name is due to --cygnus influence; in
    # Cygnus mode, `clean-info' is a target that users can use.
    $output_rules .= "\nmostlyclean-aminfo:\n";
    &pretty_print_rule ("\t-rm -f", "\t  ", @texi_cleans);
    $output_rules .= ("\nclean-aminfo:\n\ndistclean-aminfo:\n\n"
		      . "maintainer-clean-aminfo:\n\t"
		      # Eww.  But how else can we find all the output
		      # files from makeinfo?
		      . 'for i in $(INFO_DEPS); do' . " \\\n"
		      . "\t" . '  rm -f $$i;' . " \\\n"
		      . "\t" . '  if test "`echo $$i-[0-9]*`" != "$$i-[0-9]*"; then' . " \\\n"
		      . "\t" . '    rm -f $$i-[0-9]*;' . " \\\n"
		      . "\t" . '  fi;' . " \\\n"
		      . "\tdone\n");
    &push_phony_cleaners ('aminfo');
    if ($cygnus_mode)
    {
	$output_rules .= "clean-info: mostlyclean-aminfo\n";
    }

    push (@suffixes, '.texi', '.texinfo', '.txi', '.info', '.dvi', '.ps');

    if (! defined $options{'no-installinfo'})
    {
	push (@uninstall, 'uninstall-info');
	push (@installdirs, '$(DESTDIR)$(infodir)');
	unshift (@install_data, 'install-info-am');

	# Make sure documentation is made and installed first.  Use
	# $(INFO_DEPS), not 'info', because otherwise recursive makes
	# get run twice during "make all".
	unshift (@all, '$(INFO_DEPS)');
    }
    push (@clean, 'aminfo');
    push (@info, '$(INFO_DEPS)');
    push (@dvi, '$(DVIS)');

    &define_variable ("INFO_DEPS", join (' ', @info_deps_list));
    &define_variable ("DVIS", join (' ', @dvis_list));
    # This next isn't strictly needed now -- the places that look here
    # could easily be changed to look in info_TEXINFOS.  But this is
    # probably better, in case noinst_TEXINFOS is ever supported.
    &define_variable ("TEXINFOS", &variable_value ('info_TEXINFOS'));

    # Do some error checking.  Note that this file is not required
    # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
    # up above.
    &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex')
	if $need_texi_file && ! defined $options{'no-texinfo.tex'};
}

# Handle any man pages.
sub handle_man_pages
{
    &am_line_error ('MANS', "\`MANS' is an anachronism; use \`man_MANS'")
	if &variable_defined ('MANS');
    return if ! &variable_defined ('man_MANS');

    # Find all the sections in use.  We do this by first looking for
    # "standard" sections, and then looking for any additional
    # sections used in man_MANS.
    local ($sect, %sections, %vlist);
    # Add more sections as needed.
    foreach $sect ('0'..'9', 'n', 'l')
    {
	if (&variable_defined ('man' . $sect . '_MANS'))
	{
	    $sections{$sect} = 1;
	    $vlist{'$(man' . $sect . '_MANS)'} = 1;
	}
    }

    if (&variable_defined ('man_MANS'))
    {
	$vlist{'$(man_MANS)'} = 1;
	foreach (&variable_value_as_list ('man_MANS', 'all'))
	{
	    # A page like `foo.1c' goes into man1dir.
	    if (/\.([0-9a-z])([a-z]*)$/)
	    {
		$sections{$1} = 1;
	    }
	}
    }


    # Now for each section, generate an install and unintall rule.
    # Sort sections so output is deterministic.
    local (@namelist);
    foreach $sect (sort keys %sections)
    {
	&define_variable ('man' . $sect . 'dir', '$(mandir)/man' . $sect);
	push (@installdirs, '$(DESTDIR)$(mandir)/man' . $sect)
	    unless defined $options{'no-installman'};
	$output_rules .= &file_contents_with_transform ('s/\@SECTION\@/'
							. $sect . '/g;',
							'mans');
	push (@phony, 'install-man' . $sect, 'uninstall-man' . $sect);
	push (@namelist, 'install-man' . $sect);
    }

    # We don't really need this, but we use it in case we ever want to
    # support noinst_MANS.
    &define_variable ("MANS", join (' ', sort keys %vlist));

    # Generate list of install dirs.
    $output_rules .= ("install-man: \$(MANS)\n"
		      . "\t\@\$(NORMAL_INSTALL)\n");
    &pretty_print_rule ("\t\$(MAKE)", "\t ", @namelist);
    push (@phony, 'install-man');

    $output_rules .= "uninstall-man:\n\t\@\$(NORMAL_UNINSTALL)\n";
    grep ($_ = 'un' . $_, @namelist);
    &pretty_print_rule ("\t\$(MAKE)", "\t ", @namelist);
    push (@phony, 'uninstall-man');

    $output_vars .= &file_contents ('mans-vars');

    if (! defined $options{'no-installman'})
    {
	push (@install_data, 'install-man');
	push (@uninstall, 'uninstall-man');
	push (@all, '$(MANS)');
    }
}

# Handle DATA variables.
sub handle_data
{
    &am_install_var ('data', 'DATA', 'data', 'sysconf',
		     'sharedstate', 'localstate', 'pkgdata',
		     'noinst', 'check');
}

# Handle TAGS.
sub handle_tags
{
    push (@phony, 'tags');
    local (@tag_deps) = ();
    if (&variable_defined ('SUBDIRS'))
    {
	$output_rules .= ("tags-recursive:\n"
			  . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
			  # Never fail here if a subdir fails; it
			  # isn't important.
			  . "\t  (cd \$\$subdir && \$(MAKE) tags); \\\n"
			  . "\tdone\n");
	push (@tag_deps, 'tags-recursive');
	push (@phony, 'tags-recursive');
    }

    if ($dir_holds_sources
	|| $dir_holds_headers
	|| &variable_defined ('ETAGS_ARGS')
	|| @tag_deps)
    {
	local ($xform) = '';
	local ($one_hdr);
	foreach $one_hdr (@config_headers)
	{
	    if ($relative_dir eq &dirname ($one_hdr))
	    {
		# The config header is in this directory.  So require it.
		local ($var);
		($var = &basename ($one_hdr)) =~ s/(\W)/\\$1/g;
		$xform .= ' ' if $xform;
		$xform .= $var;
	    }
	}
	$xform = ('s/\@CONFIG\@/' . $xform . '/;'
		  . 's/\@DIRS\@/' . join (' ', @tag_deps) . '/;');

	if (&variable_defined ('SUBDIRS'))
	{
	    $xform .= 's/^SUBDIRS//;';
	}
	else
	{
	    $xform .= 's/^SUBDIRS.*$//;';
	}

	$output_rules .= &file_contents_with_transform ($xform, 'tags');
	$output_rules .= &file_contents ('tags-clean');
	push (@clean, 'tags');
	&push_phony_cleaners ('tags');
	&examine_variable ('TAGS_DEPENDENCIES');
    }
    elsif (&variable_defined ('TAGS_DEPENDENCIES'))
    {
	&am_line_error ('TAGS_DEPENDENCIES',
			"doesn't make sense to define \`TAGS_DEPENDENCIES' without sources or \`ETAGS_ARGS'");
    }
    else
    {
	# Every Makefile must define some sort of TAGS rule.
	# Otherwise, it would be possible for a top-level "make TAGS"
	# to fail because some subdirectory failed.
	$output_rules .= "tags: TAGS\nTAGS:\n\n";
    }
}

# Worker for handle_dist.
sub handle_dist_worker
{
    local ($makefile) = @_;

    $output_rules .= 'distdir: $(DISTFILES)' . "\n";

    # Initialization; only at top level.
    if ($relative_dir eq '.')
    {
	if (defined $options{'check-news'})
	{
	    # For Gnits users, this is pretty handy.  Look at 15 lines
	    # in case some explanatory text is desirable.
	    $output_rules .= '	@if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" > /dev/null; then :; else \\
	  echo "NEWS not updated; not releasing" 1>&2; \\
	  exit 1; \\
	fi
';
	}


	# Create dist directory.
	$output_rules .= ("\t-rm -rf \$(distdir)\n"
			  . "\tmkdir \$(distdir)\n"
			  . "\t-chmod 777 \$(distdir)\n");
    }

    # Only run automake in `dist' target if --include-deps and
    # `no-dependencies' not specified.  That way the recipient of a
    # distribution can run "make dist" and not need Automake.  You
    # might be wondering why we run automake once for each directory
    # we distribute, instead of running it once at the top level.  The
    # answer is that we want to run automake after the dependencies
    # have been generated
    elsxlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
					   '_SOURCES', '_OBJECTS',
					   '_DEPENDENCIES');

	if (! &variable_defined ($xlib . '_LDFLAGS'))
	{
	    # Define the lib_LDFLAGS variable.
	    &define_variable ($xlib . '_LDFLAGS', '');
	}

	if (&variable_defined ($xlib . '_LIBADD'))
	{
	    if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
	    {
		$seen_libobjs = 1;
	    }
	}
	else
	{
	    # Generate support for conditional object inclusion in
	    # libraries.
	    &define_variable ($xlib . "_LIBADD", '');
	}

	if (&variable_defined ($xlib . '_LDADD'))
	{
	    &am_line_error ($xlib . '_LDADD',
			    "use \`" . $xlib . "_LIBADD', not \`"
			    . $xlib . "_LDADD'");
	}

	# Make sure we at look at this.
	&examine_variable ($xlib . '_DEPENDENCIES');

	local ($linker) = &handle_source_transform ($xlib, $onelib, $obj);

	# Determine program to use for link.
	local ($xlink);
	if (&variable_defined ($xlib . '_LINK'))
	{
	    $xlink = $xlib . '_LINK';
	}
	else
	{
	    $xlink = $linker ? $linker : 'LINK';
	}

	local ($rpath);
	if ($instdirs{$onelib} eq 'EXTRA')
	{
	    # It's an EXTRA_ library, so we can't specify -rpath.
	    # Yuck.
	    $rpath = 's/\@RPATH\@//go;';
	}
	else
	{
	    $rpath = ('s/\@RPATH\@/-rpath \$(' . $instdirs{$onelib}
		      . 'dir)/go;');
	}

	$output_rules .=
	    &file_contents_with_transform ('s/\@LTLIBRARY\@/'
					   . $onelib . '/go;'
					   . 's/\@XLTLIBRARY\@/'
					   . $xlib . '/go;'
					   . $rpath
					   . 's/\@XLINK\@/' . $xlink . '/go;',
					   'ltlibrary');
    }

    if ($seen_libobjs)
    {
	foreach $onelib (@liblist)
	{
	    # Canonicalize names.
	    ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
	    if (&variable_defined ($xlib . '_LIBADD'))
	    {
		&check_libobjs_sources ($xlib, $xlib . '_LIBADD');
	    }
	}
    }
}

# See if any _SOURCES variable were misspelled.  Also, make sure that
# EXTRA_ variables don't contain configure substitutions.
sub check_typos
{
    local ($varname, $primary);
    foreach $varname (keys %contents)
    {
	foreach $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
			  '_DEPENDENCIES')
	{
	    if ($varname =~ /$primary$/ && ! $content_seen{$varname})
	    {
		&am_line_error ($varname,
				"invalid unused variable name: \`$varname'");
	    }
	}
    }
}

# Handle scripts.
sub handle_scripts
{
    # NOTE we no longer automatically clean SCRIPTS, because it is
    # useful to sometimes distribute scripts verbatim.  This happens
    # eg in Automake itself.
    &am_install_var ('scripts', 'SCRIPTS',
		     'bin', 'sbin', 'libexec', 'pkgdata',
		     'noinst', 'check');

    # Set $scripts_installed if appropriate.  Make sure we only find
    # scripts which are actually installed -- this is why we can't
    # simply use the return value of am_install_var.
    local (%valid) = &am_primary_prefixes ('SCRIPTS', 'bin', 'sbin',
					   'libexec', 'pkgdata',
					   'noinst', 'check');
    local ($key);
    foreach $key (keys %valid)
    {
	if ($key ne 'noinst'
	    && $key ne 'check'
	    && &variable_defined ($key . '_SCRIPTS'))
	{
	    $scripts_installed = 1;
	    # push (@check_tests, 'check-' . $key . 'SCRIPTS');
	}
    }

    if ($scripts_installed)
    {
	# If a program is installed, this is required.  We only want this
	# error to appear once.
	&am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
	    unless $seen_arg_prog;
	$seen_arg_prog = 1;
    }
}

# Search a file for a "version.texi" Texinfo include.  Return the name
# of the include file if found, or the empty string if not.  A
# "version.texi" file is actually any file whose name matches
# "vers*.texi".
sub scan_texinfo_file
{
    local ($filename) = @_;

    if (! open (TEXI, $filename))
    {
	&am_error ("couldn't open \`$filename': $!");
	return '';
    }
    print "automake: reading $filename\n" if $verbose;

    local ($vfile, $outfile);
    while (<TEXI>)
    {
	if (/^\@setfilename +(\S+)/)
	{
	    $outfile = $1;
	    last if ($vfile);
	}

	if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
	{
	    # Found version.texi include.
	    $vfile = $1;
	    last if $outfile;
	}
    }

    close (TEXI);
    return ($outfile, $vfile);
}

# Handle all Texinfo source.
sub handle_texinfo
{
    &am_line_error ('TEXINFOS',
		    "\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
	if &variable_defined ('TEXINFOS');
    return if (! &variable_defined ('info_TEXINFOS')
	       && ! &variable_defined ('html_TEXINFOS'));

    local (@texis) = &variable_value_as_list ('info_TEXINFOS', 'all');

    local (@info_deps_list, @dvis_list, @texi_deps);
    local ($infobase, $info_cursor);
    local (%versions);
    local ($done) = 0;
    local ($vti);
    local ($tc_cursor, @texi_cleans);
    local ($canonical);

    foreach $info_cursor (@texis)
    {
	# FIXME: This is mildly hacky, since it recognizes "txinfo".
	# I don't feel like making it right.
	($infobase = $info_cursor) =~ s/\.te?xi(nfo)?$//;

	# If 'version.texi' is referenced by input file, then include
	# automatic versioning capability.
	local ($out_file, $vtexi) = &scan_texinfo_file ($relative_dir
							. "/" . $info_cursor);

	if ($out_file eq '')
	{
	    &am_error ("\`$info_cursor' missing \@setfilename");
	    next;
	}

	if ($out_file =~ /\.(.+)$/ && $1 ne 'info')
	{
	    # FIXME should report line number in input file.
	    &am_error ("output of \`$info_cursor', \`$out_file', has unrecognized extension");
	    next;
	}

	if ($vtexi)
	{
	    &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
		if (defined $versions{$vtexi});
	    $versions{$vtexi} = $info_cursor;

	    # We number the stamp-vti files.  This is doable since the
	    # actual names don't matter much.  We only number starting
	    # with the second one, so that the common case looks nice.
	    $vti = 'vti' . ($done ? $done : '');
	    &push_dist_common ($vtexi, 'stamp-' . $vti);
	    push (@clean, $vti);

	    # Only require once.
	    &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
					  'mdate-sh')
		if ! $done;
	    ++$done;

	    local ($conf_pat);
	    ($conf_pat = $config_aux_dir) =~ s/(\W)/\\$1/g;
	    $output_rules .=
		&file_contents_with_transform
		    ('s/\@TEXI\@/' . $info_cursor . '/g; '
		     . 's/\@VTI\@/' . $vti . '/g; '
		     . 's/\@VTEXI\@/' . $vtexi . '/g;'
		     . 's,\@MDDIR\@,' . $conf_pat . ',g;',
		     'texi-vers');

	    &push_phony_cleaners ($vti);
	}

	# If user specified file_TEXINFOS, then use that as explicit
	# dependency list.
	@texi_deps = ();
	push (@texi_deps, $info_cursor);
	push (@texi_deps, $vtexi) if $vtexi;

	# Canonicalize name first.
	($canonical = $infobase) =~ tr/A-Za-z0-9_/_/c;
	if (&variable_defined ($canonical . "_TEXINFOS"))
	{
	    push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
	    &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
	}

	$output_rules .= ("\n" . $out_file . ": "
			  . join (' ', @texi_deps)
			  . "\n" . $infobase . ".dvi: "
			  . join (' ', @texi_deps)
			  . "\n\n");

	push (@info_deps_list, $out_file);
	push (@dvis_list, $infobase . '.dvi');

	# Generate list of things to clean for this target.  We do
	# this explicitly because otherwise too many things could be
	# removed.  In particular the ".log" extension might
	# reasonably be used in other contexts by the user.
	foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns',
			    'ky', 'kys', 'ps', 'log', 'pg', 'toc', 'tp', 'tps',
			    'vr', 'vrs', 'op', 'tr', 'cv', 'cn')
	{
	    push (@texi_cleans, $infobase . '.' . $tc_cursor);
	}
    }

    # Find these programs wherever they may lie.  Yes, this has
    # intimate knowledge of the structure of the texinfo distribution.
    &define_program_variable ('MAKEINFO', 'build', 'texinfo/makeinfo',
			      'makeinfo',
			      # Circumlocution to avoid accidental
			      # configure substitution.
			      '@MAKE' . 'INFO@');
    &define_program_variable ('TEXI2DVI', 'src', 'texinfo/util',
			      'texi2dvi');

    # Set transform for including texinfos.am.  First, handle --cygnus
    # stuff.
    local ($xform);
    if ($cygnus_mode)
    {
	$xform = 's/^NOTCYGNUS.*$//; s/^CYGNUS//;';
    }
    else
    {
	$xform = 's/^CYGNUS.*$//; s/^NOTCYGNUS//;';
    }

    # Handle location of texinfo.tex.
    local ($need_texi_file) = 0;
    if ($cygnus_mode)
    {
	&define_variable ('TEXINFO_TEX',
			  '$(top_srcdir)/../texinfo/texinfo.tex');
    }
    elsif ($config_aux_dir ne '.' && $config_aux_dir ne '')
    {
	&define_variable ('TEXINFO_TEX', $config_aux_dir . '/texinfo.tex');
    }
    elsif (! &variable_defined ('TEXINFO_TEX'))
    {
	&define_variable ('TEXINFO_TEX', '$(srcdir)/texinfo.tex');
    }
    else
    {
	$need_texi_file = 1;
    }
    local ($xxform) = &dirname (&variable_value ('TEXINFO_TEX'));
    $xxform =~ s/(\W)/\\$1/g;
    $xform .= ' s/\@TEXINFODIR\@/' . $xxform . '/g;';

    $output_rules .= &file_contents_with_transform ($xform, 'texinfos');
    push (@phony, 'install-info-am', 'uninstall-info');
    push (@dist_targets, 'dist-info');

    # How to clean.  The funny name is due to --cygnus influence; in
    # Cygnus mode, `clean-info' is a target that users can use.
    $output_rules .= "\nmostlyclean-aminfo:\n";
    &pretty_print_rule ("\t-rm -f", "\t  ", @texi_cleans);
    $output_rules .= ("\nclean-aminfo:\n\ndistclean-aminfo:\n\n"
		      . "maintainer-clean-aminfo:\n\t"
		      # Eww.  But how else can we find all the output
		      # files from makeinfo?
		      . 'for i in $(INFO_DEPS); do' . " \\\n"
		      . "\t" . '  rm -f $$i;' . " \\\n"
		      . "\t" . '  if test "`echo $$i-[0-9]*`" != "$$i-[0-9]*"; then' . " \\\n"
		      . "\t" . '    rm -f $$i-[0-9]*;' . " \\\n"
		      . "\t" . '  fi;' . " \\\n"
		      . "\tdone\n");
    &push_phony_cleaners ('aminfo');
    if ($cygnus_mode)
    {
	$output_rules .= "clean-info: mostlyclean-aminfo\n";
    }

    push (@suffixes, '.texi', '.texinfo', '.txi', '.info', '.dvi', '.ps');

    if (! defined $options{'no-installinfo'})
    {
	push (@uninstall, 'uninstall-info');
	push (@installdirs, '$(DESTDIR)$(infodir)');
	unshift (@install_data, 'install-info-am');

	# Make sure documentation is made and installed first.  Use
	# $(INFO_DEPS), not 'info', because otherwise recursive makes
	# get run twice during "make all".
	unshift (@all, '$(INFO_DEPS)');
    }
    push (@clean, 'aminfo');
    push (@info, '$(INFO_DEPS)');
    push (@dvi, '$(DVIS)');

    &define_variable ("INFO_DEPS", join (' ', @info_deps_list));
    &define_variable ("DVIS", join (' ', @dvis_list));
    # This next isn't strictly needed now -- the places that look here
    # could easily be changed to look in info_TEXINFOS.  But this is
    # probably better, in case noinst_TEXINFOS is ever supported.
    &define_variable ("TEXINFOS", &variable_value ('info_TEXINFOS'));

    # Do some error checking.  Note that this file is not required
    # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
    # up above.
    &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex')
	if $need_texi_file && ! defined $options{'no-texinfo.tex'};
}

# Handle any man pages.
sub handle_man_pages
{
    &am_line_error ('MANS', "\`MANS' is an anachronism; use \`man_MANS'")
	if &variable_defined ('MANS');
    return if ! &variable_defined ('man_MANS');

    # Find all the sections in use.  We do this by first looking for
    # "standard" sections, and then looking for any additional
    # sections used in man_MANS.
    local ($sect, %sections, %vlist);
    # Add more sections as needed.
    foreach $sect ('0'..'9', 'n', 'l')
    {
	if (&variable_defined ('man' . $sect . '_MANS'))
	{
	    $sections{$sect} = 1;
	    $vlist{'$(man' . $sect . '_MANS)'} = 1;
	}
    }

    if (&variable_defined ('man_MANS'))
    {
	$vlist{'$(man_MANS)'} = 1;
	foreach (&variable_value_as_list ('man_MANS', 'all'))
	{
	    # A page like `foo.1c' goes into man1dir.
	    if (/\.([0-9a-z])([a-z]*)$/)
	    {
		$sections{$1} = 1;
	    }
	}
    }


    # Now for each section, generate an install and unintall rule.
    # Sort sections so output is deterministic.
    local (@namelist);
    foreach $sect (sort keys %sections)
    {
	&define_variable ('man' . $sect . 'dir', '$(mandir)/man' . $sect);
	push (@installdirs, '$(DESTDIR)$(mandir)/man' . $sect)
	    unless defined $options{'no-installman'};
	$output_rules .= &file_contents_with_transform ('s/\@SECTION\@/'
							. $sect . '/g;',
							'mans');
	push (@phony, 'install-man' . $sect, 'uninstall-man' . $sect);
	push (@namelist, 'install-man' . $sect);
    }

    # We don't really need this, but we use it in case we ever want to
    # support noinst_MANS.
    &define_variable ("MANS", join (' ', sort keys %vlist));

    # Generate list of install dirs.
    $output_rules .= ("install-man: \$(MANS)\n"
		      . "\t\@\$(NORMAL_INSTALL)\n");
    &pretty_print_rule ("\t\$(MAKE)", "\t ", @namelist);
    push (@phony, 'install-man');

    $output_rules .= "uninstall-man:\n\t\@\$(NORMAL_UNINSTALL)\n";
    grep ($_ = 'un' . $_, @namelist);
    &pretty_print_rule ("\t\$(MAKE)", "\t ", @namelist);
    push (@phony, 'uninstall-man');

    $output_vars .= &file_contents ('mans-vars');

    if (! defined $options{'no-installman'})
    {
	push (@install_data, 'install-man');
	push (@uninstall, 'uninstall-man');
	push (@all, '$(MANS)');
    }
}

# Handle DATA variables.
sub handle_data
{
    &am_install_var ('data', 'DATA', 'data', 'sysconf',
		     'sharedstate', 'localstate', 'pkgdata',
		     'noinst', 'check');
}

# Handle TAGS.
sub handle_tags
{
    push (@phony, 'tags');
    local (@tag_deps) = ();
    if (&variable_defined ('SUBDIRS'))
    {
	$output_rules .= ("tags-recursive:\n"
			  . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
			  # Never fail here if a subdir fails; it
			  # isn't important.
			  . "\t  (cd \$\$subdir && \$(MAKE) tags); \\\n"
			  . "\tdone\n");
	push (@tag_deps, 'tags-recursive');
	push (@phony, 'tags-recursive');
    }

    if ($dir_holds_sources
	|| $dir_holds_headers
	|| &variable_defined ('ETAGS_ARGS')
	|| @tag_deps)
    {
	local ($xform) = '';
	local ($one_hdr);
	foreach $one_hdr (@config_headers)
	{
	    if ($relative_dir eq &dirname ($one_hdr))
	    {
		# The config header is in this directory.  So require it.
		local ($var);
		($var = &basename ($one_hdr)) =~ s/(\W)/\\$1/g;
		$xform .= ' ' if $xform;
		$xform .= $var;
	    }
	}
	$xform = ('s/\@CONFIG\@/' . $xform . '/;'
		  . 's/\@DIRS\@/' . join (' ', @tag_deps) . '/;');

	if (&variable_defined ('SUBDIRS'))
	{
	    $xform .= 's/^SUBDIRS//;';
	}
	else
	{
	    $xform .= 's/^SUBDIRS.*$//;';
	}

	$output_rules .= &file_contents_with_transform ($xform, 'tags');
	$output_rules .= &file_contents ('tags-clean');
	push (@clean, 'tags');
	&push_phony_cleaners ('tags');
	&examine_variable ('TAGS_DEPENDENCIES');
    }
    elsif (&variable_defined ('TAGS_DEPENDENCIES'))
    {
	&am_line_error ('TAGS_DEPENDENCIES',
			"doesn't make sense to define \`TAGS_DEPENDENCIES' without sources or \`ETAGS_ARGS'");
    }
    else
    {
	# Every Makefile must define some sort of TAGS rule.
	# Otherwise, it would be possible for a top-level "make TAGS"
	# to fail because some subdirectory failed.
	$output_rules .= "tags: TAGS\nTAGS:\n\n";
    }
}

# Worker for handle_dist.
sub handle_dist_worker
{
    local ($makefile) = @_;

    $output_rules .= 'distdir: $(DISTFILES)' . "\n";

    # Initialization; only at top level.
    if ($relative_dir eq '.')
    {
	if (defined $options{'check-news'})
	{
	    # For Gnits users, this is pretty handy.  Look at 15 lines
	    # in case some explanatory text is desirable.
	    $output_rules .= '	@if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" > /dev/null; then :; else \\
	  echo "NEWS not updated; not releasing" 1>&2; \\
	  exit 1; \\
	fi
';
	}


	# Create dist directory.
	$output_rules .= ("\t-rm -rf \$(distdir)\n"
			  . "\tmkdir \$(distdir)\n"
			  . "\t-chmod 777 \$(distdir)\n");
    }

    # Only run automake in `dist' target if --include-deps and
    # `no-dependencies' not specified.  That way the recipient of a
    # distribution can run "make dist" and not need Automake.  You
    # might be wondering why we run automake once for each directory
    # we distribute, instead of running it once at the top level.  The
    # answer is that we want to run automake after the dependencies
    # have been generated
    elsxlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
					   '_SOURCES', '_OBJECTS',
					   '_DEPENDENCIES');

	if (! &variable_defined ($xlib . '_LDFLAGS'))
	{
	    # Define the lib_LDFLAGS variable.
	    &define_variable ($xlib . '_LDFLAGS', '');
	}

	if (&variable_defined ($xlib . '_LIBADD'))
	{
	    if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
	    {
		$seen_libobjs = 1;
	    }
	}
	else
	{
	    # Generate support for conditional object inclusion in
	    # libraries.
	    &define_variable ($xlib . "_LIBADD", '');
	}

	if (&variable_defined ($xlib . '_LDADD'))
	{
	    &am_line_error ($xlib . '_LDADD',
			    "use \`" . $xlib . "_LIBADD', not \`"
			    . $xlib . "_LDADD'");
	}

	# Make sure we at look at this.
	&examine_variable ($xlib . '_DEPENDENCIES');

	local ($linker) = &handle_source_transform ($xlib, $onelib, $obj);

	# Determine program to use for link.
	local ($xlink);
	if (&variable_defined ($xlib . '_LINK'))
	{
	    $xlink = $xlib . '_LINK';
	}
	else
	{
	    $xlink = $linker ? $linker : 'LINK';
	}

	local ($rpath);
	if ($instdirs{$onelib} eq 'EXTRA')
	{
	    # It's an EXTRA_ library, so we can't specify -rpath.
	    # Yuck.
	    $rpath = 's/\@RPATH\@//go;';
	}
	else
	{
	    $rpath = ('s/\@RPATH\@/-rpath \$(' . $instdirs{$onelib}
		      . 'dir)/go;');
	}

	$output_rules .=
	    &file_contents_with_transform ('s/\@LTLIBRARY\@/'
					   . $onelib . '/go;'
					   . 's/\@XLTLIBRARY\@/'
					   . $xlib . '/go;'
					   . $rpath
					   . 's/\@XLINK\@/' . $xlink . '/go;',
					   'ltlibrary');
    }

    if ($seen_libobjs)
    {
	foreach $onelib (@liblist)
	{
	    # Canonicalize names.
	    ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
	    if (&variable_defined ($xlib . '_LIBADD'))
	    {
		&check_libobjs_sources ($xlib, $xlib . '_LIBADD');
	    }
	}
    }
}

# See if any _SOURCES variable were misspelled.  Also, make sure that
# EXTRA_ variables don't contain configure substitutions.
sub check_typos
{
    local ($varname, $primary);
    foreach $varname (keys %contents)
    {
	foreach $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
			  '_DEPENDENCIES')
	{
	    if ($varname =~ /$primary$/ && ! $content_seen{$varname})
	    {
		&am_line_error ($varname,
				"invalid unused variable name: \`$varname'");
	    }
	}
    }
}

# Handle scripts.
sub handle_scripts
{
    # NOTE we no longer automatically clean SCRIPTS, because it is
    # useful to sometimes distribute scripts verbatim.  This happens
    # eg in Automake itself.
    &am_install_var ('scripts', 'SCRIPTS',
		     'bin', 'sbin', 'libexec', 'pkgdata',
		     'noinst', 'check');

    # Set $scripts_installed if appropriate.  Make sure we only find
    # scripts which are actually installed -- this is why we can't
    # simply use the return value of am_install_var.
    local (%valid) = &am_primary_prefixes ('SCRIPTS', 'bin', 'sbin',
					   'libexec', 'pkgdata',
					   'noinst', 'check');
    local ($key);
    foreach $key (keys %valid)
    {
	if ($key ne 'noinst'
	    && $key ne 'check'
	    && &variable_defined ($key . '_SCRIPTS'))
	{
	    $scripts_installed = 1;
	    # push (@check_tests, 'check-' . $key . 'SCRIPTS');
	}
    }

    if ($scripts_installed)
    {
	# If a program is installed, this is required.  We only want this
	# error to appear once.
	&am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
	    unless $seen_arg_prog;
	$seen_arg_prog = 1;
    }
}

# Search a file for a "version.texi" Texinfo include.  Return the name
# of the include file if found, or the empty string if not.  A
# "version.texi" file is actually any file whose name matches
# "vers*.texi".
sub scan_texinfo_file
{
    local ($filename) = @_;

    if (! open (TEXI, $filename))
    {
	&am_error ("couldn't open \`$filename': $!");
	return '';
    }
    print "automake: reading $filename\n" if $verbose;

    local ($vfile, $outfile);
    while (<TEXI>)
    {
	if (/^\@setfilename +(\S+)/)
	{
	    $outfile = $1;
	    last if ($vfile);
	}

	if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
	{
	    # Found version.texi include.
	    $vfile = $1;
	    last if $outfile;
	}
    }

    close (TEXI);
    return ($outfile, $vfile);
}

# Handle all Texinfo source.
sub handle_texinfo
{
    &am_line_error ('TEXINFOS',
		    "\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
	if &variable_defined ('TEXINFOS');
    return if (! &variable_defined ('info_TEXINFOS')
	       && ! &variable_defined ('html_TEXINFOS'));

    local (@texis) = &variable_value_as_list ('info_TEXINFOS', 'all');

    local (@info_deps_list, @dvis_list, @texi_deps);
    local ($infobase, $info_cursor);
    local (%versions);
    local ($done) = 0;
    local ($vti);
    local ($tc_cursor, @texi_cleans);
    local ($canonical);

    foreach $info_cursor (@texis)
    {
	# FIXME: This is mildly hacky, since it recognizes "txinfo".
	# I don't feel like making it right.
	($infobase = $info_cursor) =~ s/\.te?xi(nfo)?$//;

	# If 'version.texi' is referenced by input file, then include
	# automatic versioning capability.
	local ($out_file, $vtexi) = &scan_texinfo_file ($relative_dir
							. "/" . $info_cursor);

	if ($out_file eq '')
	{
	    &am_error ("\`$info_cursor' missing \@setfilename");
	    next;
	}

	if ($out_file =~ /\.(.+)$/ && $1 ne 'info')
	{
	    # FIXME should report line number in input file.
	    &am_error ("output of \`$info_cursor', \`$out_file', has unrecognized extension");
	    next;
	}

	if ($vtexi)
	{
	    &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
		if (defined $versions{$vtexi});
	    $versions{$vtexi} = $info_cursor;

	    # We number the stamp-vti files.  This is doable since the
	    # actual names don't matter much.  We only number starting
	    # with the second one, so that the common case looks nice.
	    $vti = 'vti' . ($done ? $done : '');
	    &push_dist_common ($vtexi, 'stamp-' . $vti);
	    push (@clean, $vti);

	    # Only require once.
	    &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
					  'mdate-sh')
		if ! $done;
	    ++$done;

	    local ($conf_pat);
	    ($conf_pat = $config_aux_dir) =~ s/(\W)/\\$1/g;
	    $output_rules .=
		&file_contents_with_transform
		    ('s/\@TEXI\@/' . $info_cursor . '/g; '
		     . 's/\@VTI\@/' . $vti . '/g; '
		     . 's/\@VTEXI\@/' . $vtexi . '/g;'
		     . 's,\@MDDIR\@,' . $conf_pat . ',g;',
		     'texi-vers');

	    &push_phony_cleaners ($vti);
	}

	# If user specified file_TEXINFOS, then use that as explicit
	# dependency list.
	@texi_deps = ();
	push (@texi_deps, $info_cursor);
	push (@texi_deps, $vtexi) if $vtexi;

	# Canonicalize name first.
	($canonical = $infobase) =~ tr/A-Za-z0-9_/_/c;
	if (&variable_defined ($canonical . "_TEXINFOS"))
	{
	    push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
	    &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
	}

	$output_rules .= ("\n" . $out_file . ": "
			  . join (' ', @texi_deps)
			  . "\n" . $infobase . ".dvi: "
			  . join (' ', @texi_deps)
			  . "\n\n");

	push (@info_deps_list, $out_file);
	push (@dvis_list, $infobase . '.dvi');

	# Generate list of things to clean for this target.  We do
	# this explicitly because otherwise too many things could be
	# removed.  In particular the ".log" extension might
	# reasonably be used in other contexts by the user.
	foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns',
			    'ky', 'kys', 'ps', 'log', 'pg', 'toc', 'tp', 'tps',
			    'vr', 'vrs', 'op', 'tr', 'cv', 'cn')
	{
	    push (@texi_cleans, $infobase . '.' . $tc_cursor);
	}
    }

    # Find these programs wherever they may lie.  Yes, this has
    # intimate knowledge of the structure of the texinfo distribution.
    &define_program_variable ('MAKEINFO', 'build', 'texinfo/makeinfo',
			      'makeinfo',
			      # Circumlocution to avoid accidental
			      # configure substitution.
			      '@MAKE' . 'INFO@');
    &define_program_variable ('TEXI2DVI', 'src', 'texinfo/util',
			      'texi2dvi');

    # Set transform for including texinfos.am.  First, handle --cygnus
    # stuff.
    local ($xform);
    if ($cygnus_mode)
    {
	$xform = 's/^NOTCYGNUS.*$//; s/^CYGNUS//;';
    }
    else
    {
	$xform = 's/^CYGNUS.*$//; s/^NOTCYGNUS//;';
    }

    # Handle location of texinfo.tex.
    local ($need_texi_file) = 0;
    if ($cygnus_mode)
    {
	&define_variable ('TEXINFO_TEX',
			  '$(top_srcdir)/../texinfo/texinfo.tex');
    }
    elsif ($config_aux_dir ne '.' && $config_aux_dir ne '')
    {
	&define_variable ('TEXINFO_TEX', $config_aux_dir . '/texinfo.tex');
    }
    elsif (! &variable_defined ('TEXINFO_TEX'))
    {
	&define_variable ('TEXINFO_TEX', '$(srcdir)/texinfo.tex');
    }
    else
    {
	$need_texi_file = 1;
    }
    local ($xxform) = &dirname (&variable_value ('TEXINFO_TEX'));
    $xxform =~ s/(\W)/\\$1/g;
    $xform .= ' s/\@TEXINFODIR\@/' . $xxform . '/g;';

    $output_rules .= &file_contents_with_transform ($xform, 'texinfos');
    push (@phony, 'install-info-am', 'uninstall-info');
    push (@dist_targets, 'dist-info');

    # How to clean.  The funny name is due to --cygnus influence; in
    # Cygnus mode, `clean-info' is a target that users can use.
    $output_rules .= "\nmostlyclean-aminfo:\n";
    &pretty_print_rule ("\t-rm -f", "\t  ", @texi_cleans);
    $output_rules .= ("\nclean-aminfo:\n\ndistclean-aminfo:\n\n"
		      . "maintainer-clean-aminfo:\n\t"
		      # Eww.  But how else can we find all the output
		      # files from makeinfo?
		      . 'for i in $(INFO_DEPS); do' . " \\\n"
		      . "\t" . '  rm -f $$i;' . " \\\n"
		      . "\t" . '  if test "`echo $$i-[0-9]*`" != "$$i-[0-9]*"; then' . " \\\n"
		      . "\t" . '    rm -f $$i-[0-9]*;' . " \\\n"
		      . "\t" . '  fi;' . " \\\n"
		      . "\tdone\n");
    &push_phony_cleaners ('aminfo');
    if ($cygnus_mode)
    {
	$output_rules .= "clean-info: mostlyclean-aminfo\n";
    }

    push (@suffixes, '.texi', '.texinfo', '.txi', '.info', '.dvi', '.ps');

    if (! defined $options{'no-installinfo'})
    {
	push (@uninstall, 'uninstall-info');
	push (@installdirs, '$(DESTDIR)$(infodir)');
	unshift (@install_data, 'install-info-am');

	# Make sure documentation is made and installed first.  Use
	# $(INFO_DEPS), not 'info', because otherwise recursive makes
	# get run twice during "make all".
	unshift (@all, '$(INFO_DEPS)');
    }
    push (@clean, 'aminfo');
    push (@info, '$(INFO_DEPS)');
    push (@dvi, '$(DVIS)');

    &define_variable ("INFO_DEPS", join (' ', @info_deps_list));
    &define_variable ("DVIS", join (' ', @dvis_list));
    # This next isn't strictly needed now -- the places that look here
    # could easily be changed to look in info_TEXINFOS.  But this is
    # probably better, in case noinst_TEXINFOS is ever supported.
    &define_variable ("TEXINFOS", &variable_value ('info_TEXINFOS'));

    # Do some error checking.  Note that this file is not required
    # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
    # up above.
    &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex')
	if $need_texi_file && ! defined $options{'no-texinfo.tex'};
}

# Handle any man pages.
sub handle_man_pages
{
    &am_line_error ('MANS', "\`MANS' is an anachronism; use \`man_MANS'")
	if &variable_defined ('MANS');
    return if ! &variable_defined ('man_MANS');

    # Find all the sections in use.  We do this by first looking for
    # "standard" sections, and then looking for any additional
    # sections used in man_MANS.
    local ($sect, %sections, %vlist);
    # Add more sections as needed.
    foreach $sect ('0'..'9', 'n', 'l')
    {
	if (&variable_defined ('man' . $sect . '_MANS'))
	{
	    $sections{$sect} = 1;
	    $vlist{'$(man' . $sect . '_MANS)'} = 1;
	}
    }

    if (&variable_defined ('man_MANS'))
    {
	$vlist{'$(man_MANS)'} = 1;
	foreach (&variable_value_as_list ('man_MANS', 'all'))
	{
	    # A page like `foo.1c' goes into man1dir.
	    if (/\.([0-9a-z])([a-z]*)$/)
	    {
		$sections{$1} = 1;
	    }
	}
    }


    # Now for each section, generate an install and unintall rule.
    # Sort sections so output is deterministic.
    local (@namelist);
    foreach $sect (sort keys %sections)
    {
	&define_variable ('man' . $sect . 'dir', '$(mandir)/man' . $sect);
	push (@installdirs, '$(DESTDIR)$(mandir)/man' . $sect)
	    unless defined $options{'no-installman'};
	$output_rules .= &file_contents_with_transform ('s/\@SECTION\@/'
							. $sect . '/g;',
							'mans');
	push (@phony, 'install-man' . $sect, 'uninstall-man' . $sect);
	push (@namelist, 'install-man' . $sect);
    }

    # We don't really need this, but we use it in case we ever want to
    # support noinst_MANS.
    &define_variable ("MANS", join (' ', sort keys %vlist));

    # Generate list of install dirs.
    $output_rules .= ("install-man: \$(MANS)\n"
		      . "\t\@\$(NORMAL_INSTALL)\n");
    &pretty_print_rule ("\t\$(MAKE)", "\t ", @namelist);
    push (@phony, 'install-man');

    $output_rules .= "uninstall-man:\n\t\@\$(NORMAL_UNINSTALL)\n";
    grep ($_ = 'un' . $_, @namelist);
    &pretty_print_rule ("\t\$(MAKE)", "\t ", @namelist);
    push (@phony, 'uninstall-man');

    $output_vars .= &file_contents ('mans-vars');

    if (! defined $options{'no-installman'})
    {
	push (@install_data, 'install-man');
	push (@uninstall, 'uninstall-man');
	push (@all, '$(MANS)');
    }
}

# Handle DATA variables.
sub handle_data
{
    &am_install_var ('data', 'DATA', 'data', 'sysconf',
		     'sharedstate', 'localstate', 'pkgdata',
		     'noinst', 'check');
}

# Handle TAGS.
sub handle_tags
{
    push (@phony, 'tags');
    local (@tag_deps) = ();
    if (&variable_defined ('SUBDIRS'))
    {
	$output_rules .= ("tags-recursive:\n"
			  . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
			  # Never fail here if a subdir fails; it
			  # isn't important.
			  . "\t  (cd \$\$subdir && \$(MAKE) tags); \\\n"
			  . "\tdone\n");
	push (@tag_deps, 'tags-recursive');
	push (@phony, 'tags-recursive');
    }

    if ($dir_holds_sources
	|| $dir_holds_headers
	|| &variable_defined ('ETAGS_ARGS')
	|| @tag_deps)
    {
	local ($xform) = '';
	local ($one_hdr);
	foreach $one_hdr (@config_headers)
	{
	    if ($relative_dir eq &dirname ($one_hdr))
	    {
		# The config header is in this directory.  So require it.
		local ($var);
		($var = &basename ($one_hdr)) =~ s/(\W)/\\$1/g;
		$xform .= ' ' if $xform;
		$xform .= $var;
	    }
	}
	$xform = ('s/\@CONFIG\@/' . $xform . '/;'
		  . 's/\@DIRS\@/' . join (' ', @tag_deps) . '/;');

	if (&variable_defined ('SUBDIRS'))
	{
	    $xform .= 's/^SUBDIRS//;';
	}
	else
	{
	    $xform .= 's/^SUBDIRS.*$//;';
	}

	$output_rules .= &file_contents_with_transform ($xform, 'tags');
	$output_rules .= &file_contents ('tags-clean');
	push (@clean, 'tags');
	&push_phony_cleaners ('tags');
	&examine_variable ('TAGS_DEPENDENCIES');
    }
    elsif (&variable_defined ('TAGS_DEPENDENCIES'))
    {
	&am_line_error ('TAGS_DEPENDENCIES',
			"doesn't make sense to define \`TAGS_DEPENDENCIES' without sources or \`ETAGS_ARGS'");
    }
    else
    {
	# Every Makefile must define some sort of TAGS rule.
	# Otherwise, it would be possible for a top-level "make TAGS"
	# to fail because some subdirectory failed.
	$output_rules .= "tags: TAGS\nTAGS:\n\n";
    }
}

# Worker for handle_dist.
sub handle_dist_worker
{
    local ($makefile) = @_;

    $output_rules .= 'distdir: $(DISTFILES)' . "\n";

    # Initialization; only at top level.
    if ($relative_dir eq '.')
    {
	if (defined $options{'check-news'})
	{
	    # For Gnits users, this is pretty handy.  Look at 15 lines
	    # in case some explanatory text is desirable.
	    $output_rules .= '	@if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" > /dev/null; then :; else \\
	  echo "NEWS not updated; not releasing" 1>&2; \\
	  exit 1; \\
	fi
';
	}


	# Create dist directory.
	$output_rules .= ("\t-rm -rf \$(distdir)\n"
			  . "\tmkdir \$(distdir)\n"
			  . "\t-chmod 777 \$(distdir)\n");
    }

    # Only run automake in `dist' target if --include-deps and
    # `no-dependencies' not specified.  That way the recipient of a
    # distribution can run "make dist" and not need Automake.  You
    # might be wondering why we run automake once for each directory
    # we distribute, instead of running it once at the top level.  The
    # answer is that we want to run automake after the dependencies
    # have been generated
    elsxlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
					   '_SOURCES', '_OBJECTS',
					   '_DEPENDENCIES');

	if (! &variable_defined ($xlib . '_LDFLAGS'))
	{
	    # Define the lib_LDFLAGS variable.
	    &define_variable ($xlib . '_LDFLAGS', '');
	}

	if (&variable_defined ($xlib . '_LIBADD'))
	{
	    if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
	    {
		$seen_libobjs = 1;
	    }
	}
	else
	{
	    # Generate support for conditional object inclusion in
	    # libraries.
	    &define_variable ($xlib . "_LIBADD", '');
	}

	if (&variable_defined ($xlib . '_LDADD'))
	{
	    &am_line_error ($xlib . '_LDADD',
			    "use \`" . $xlib . "_LIBADD', not \`"
			    . $xlib . "_LDADD'");
	}

	# Make sure we at look at this.
	&examine_variable ($xlib . '_DEPENDENCIES');

	local ($linker) = &handle_source_transform ($xlib, $onelib, $obj);

	# Determine program to use for link.
	local ($xlink);
	if (&variable_defined ($xlib . '_LINK'))
	{
	    $xlink = $xlib . '_LINK';
	}
	else
	{
	    $xlink = $linker ? $linker : 'LINK';
	}

	local ($rpath);
	if ($instdirs{$onelib} eq 'EXTRA')
	{
	    # It's an EXTRA_ library, so we can't specify -rpath.
	    # Yuck.
	    $rpath = 's/\@RPATH\@//go;';
	}
	else
	{
	    $rpath = ('s/\@RPATH\@/-rpath \$(' . $instdirs{$onelib}
		      . 'dir)/go;');
	}

	$output_rules .=
	    &file_contents_with_transform ('s/\@LTLIBRARY\@/'
					   . $onelib . '/go;'
					   . 's/\@XLTLIBRARY\@/'
					   . $xlib . '/go;'
					   . $rpath
					   . 's/\@XLINK\@/' . $xlink . '/go;',
					   'ltlibrary');
    }

    if ($seen_libobjs)
    {
	foreach $onelib (@liblist)
	{
	    # Canonicalize names.
	    ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
	    if (&variable_defined ($xlib . '_LIBADD'))
	    {
		&check_libobjs_sources ($xlib, $xlib . '_LIBADD');
	    }
	}
    }
}

# See if any _SOURCES variable were misspelled.  Also, make sure that
# EXTRA_ variables don't contain configure substitutions.
sub check_typos
{
    local ($varname, $primary);
    foreach $varname (keys %contents)
    {
	foreach $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
			  '_DEPENDENCIES')
	{
	    if ($varname =~ /$primary$/ && ! $content_seen{$varname})
	    {
		&am_line_error ($varname,
				"invalid unused variable name: \`$varname'");
	    }
	}
    }
}

# Handle scripts.
sub handle_scripts
{
    # NOTE we no longer automatically clean SCRIPTS, because it is
    # useful to sometimes distribute scripts verbatim.  This happens
    # eg in Automake itself.
    &am_install_var ('scripts', 'SCRIPTS',
		     'bin', 'sbin', 'libexec', 'pkgdata',
		     'noinst', 'check');

    # Set $scripts_installed if appropriate.  Make sure we only find
    # scripts which are actually installed -- this is why we can't
    # simply use the return value of am_install_var.
    local (%valid) = &am_primary_prefixes ('SCRIPTS', 'bin', 'sbin',
					   'libexec', 'pkgdata',
					   'noinst', 'check');
    local ($key);
    foreach $key (keys %valid)
    {
	if ($key ne 'noinst'
	    && $key ne 'check'
	    && &variable_defined ($key . '_SCRIPTS'))
	{
	    $scripts_installed = 1;
	    # push (@check_tests, 'check-' . $key . 'SCRIPTS');
	}
    }

    if ($scripts_installed)
    {
	# If a program is installed, this is required.  We only want this
	# error to appear once.
	&am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
	    unless $seen_arg_prog;
	$seen_arg_prog = 1;
    }
}

# Search a file for a "version.texi" Texinfo include.  Return the name
# of the include file if found, or the empty string if not.  A
# "version.texi" file is actually any file whose name matches
# "vers*.texi".
sub scan_texinfo_file
{
    local ($filename) = @_;

    if (! open (TEXI, $filename))
    {
	&am_error ("couldn't open \`$filename': $!");
	return '';
    }
    print "automake: reading $filename\n" if $verbose;

    local ($vfile, $outfile);
    while (<TEXI>)
    {
	if (/^\@setfilename +(\S+)/)
	{
	    $outfile = $1;
	    last if ($vfile);
	}

	if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
	{
	    # Found version.texi include.
	    $vfile = $1;
	    last if $outfile;
	}
    }

    close (TEXI);
    return ($outfile, $vfile);
}

# Handle all Texinfo source.
sub handle_texinfo
{
    &am_line_error ('TEXINFOS',
		    "\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
	if &variable_defined ('TEXINFOS');
    return if (! &variable_defined ('info_TEXINFOS')
	       && ! &variable_defined ('html_TEXINFOS'));

    local (@texis) = &variable_value_as_list ('info_TEXINFOS', 'all');

    local (@info_deps_list, @dvis_list, @texi_deps);
    local ($infobase, $info_cursor);
    local (%versions);
    local ($done) = 0;
    local ($vti);
    local ($tc_cursor, @texi_cleans);
    local ($canonical);

    foreach $info_cursor (@texis)
    {
	# FIXME: This is mildly hacky, since it recognizes "txinfo".
	# I don't feel like making it right.
	($infobase = $info_cursor) =~ s/\.te?xi(nfo)?$//;

	# If 'version.texi' is referenced by input file, then include
	# automatic versioning capability.
	local ($out_file, $vtexi) = &scan_texinfo_file ($relative_dir
							. "/" . $info_cursor);

	if ($out_file eq '')
	{
	    &am_error ("\`$info_cursor' missing \@setfilename");
	    next;
	}

	if ($out_file =~ /\.(.+)$/ && $1 ne 'info')
	{
	    # FIXME should report line number in input file.
	    &am_error ("output of \`$info_cursor', \`$out_file', has unrecognized extension");
	    next;
	}

	if ($vtexi)
	{
	    &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
		if (defined $versions{$vtexi});
	    $versions{$vtexi} = $info_cursor;

	    # We number the stamp-vti files.  This is doable since the
	    # actual names don't matter much.  We only number starting
	    # with the second one, so that the common case looks nice.
	    $vti = 'vti' . ($done ? $done : '');
	    &push_dist_common ($vtexi, 'stamp-' . $vti);
	    push (@clean, $vti);

	    # Only require once.
	    &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
					  'mdate-sh')
		if ! $done;
	    ++$done;

	    local ($conf_pat);
	    ($conf_pat = $config_aux_dir) =~ s/(\W)/\\$1/g;
	    $output_rules .=
		&file_contents_with_transform
		    ('s/\@TEXI\@/' . $info_cursor . '/g; '
		     . 's/\@VTI\@/' . $vti . '/g; '
		     . 's/\@VTEXI\@/' . $vtexi . '/g;'
		     . 's,\@MDDIR\@,' . $conf_pat . ',g;',
		     'texi-vers');

	    &push_phony_cleaners ($vti);
	}

	# If user specified file_TEXINFOS, then use that as explicit
	# dependency list.
	@texi_deps = ();
	push (@texi_deps, $info_cursor);
	push (@texi_deps, $vtexi) if $vtexi;

	# Canonicalize name first.
	($canonical = $infobase) =~ tr/A-Za-z0-9_/_/c;
	if (&variable_defined ($canonical . "_TEXINFOS"))
	{
	    push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
	    &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
	}

	$output_rules .= ("\n" . $out_file . ": "
			  . join (' ', @texi_deps)
			  . "\n" . $infobase . ".dvi: "
			  . join (' ', @texi_deps)
			  . "\n\n");

	push (@info_deps_list, $out_file);
	push (@dvis_list, $infobase . '.dvi');

	# Generate list of things to clean for this target.  We do
	# this explicitly because otherwise too many things could be
	# removed.  In particular the ".log" extension might
	# reasonably be used in other contexts by the user.
	foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns',
			    'ky', 'kys', 'ps', 'log', 'pg', 'toc', 'tp', 'tps',
			    'vr', 'vrs', 'op', 'tr', 'cv', 'cn')
	{
	    push (@texi_cleans, $infobase . '.' . $tc_cursor);
	}
    }

    # Find these programs wherever they may lie.  Yes, this has
    # intimate knowledge of the structure of the texinfo distribution.
    &define_program_variable ('MAKEINFO', 'build', 'texinfo/makeinfo',
			      'makeinfo',
			      # Circumlocution to avoid accidental
			      # configure substitution.
			      '@MAKE' . 'INFO@');
    &define_program_variable ('TEXI2DVI', 'src', 'texinfo/util',
			      'texi2dvi');

    # Set transform for including texinfos.am.  First, handle --cygnus
    # stuff.
    local ($xform);
    if ($cygnus_mode)
    {
	$xform = 's/^NOTCYGNUS.*$//; s/^CYGNUS//;';
    }
    else
    {
	$xform = 's/^CYGNUS.*$//; s/^NOTCYGNUS//;';
    }

    # Handle location of texinfo.tex.
    local ($need_texi_file) = 0;
    if ($cygnus_mode)
    {
	&define_variable ('TEXINFO_TEX',
			  '$(top_srcdir)/../texinfo/texinfo.tex');
    }
    elsif ($config_aux_dir ne '.' && $config_aux_dir ne '')
    {
	&define_variable ('TEXINFO_TEX', $config_aux_dir . '/texinfo.tex');
    }
    elsif (! &variable_defined ('TEXINFO_TEX'))
    {
	&define_variable ('TEXINFO_TEX', '$(srcdir)/texinfo.tex');
    }
    else
    {
	$need_texi_file = 1;
    }
    local ($xxform) = &dirname (&variable_value ('TEXINFO_TEX'));
    $xxform =~ s/(\W)/\\$1/g;
    $xform .= ' s/\@TEXINFODIR\@/' . $xxform . '/g;';

    $output_rules .= &file_contents_with_transform ($xform, 'texinfos');
    push (@phony, 'install-info-am', 'uninstall-info');
    push (@dist_targets, 'dist-info');

    # How to clean.  The funny name is due to --cygnus influence; in
    # Cygnus mode, `clean-info' is a target that users can use.
    $output_rules .= "\nmostlyclean-aminfo:\n";
    &pretty_print_rule ("\t-rm -f", "\t  ", @texi_cleans);
    $output_rules .= ("\nclean-aminfo:\n\ndistclean-aminfo:\n\n"
		      . "maintainer-clean-aminfo:\n\t"
		      # Eww.  But how else can we find all the output
		      # files from makeinfo?
		      . 'for i in $(INFO_DEPS); do' . " \\\n"
		      . "\t" . '  rm -f $$i;' . " \\\n"
		      . "\t" . '  if test "`echo $$i-[0-9]*`" != "$$i-[0-9]*"; then' . " \\\n"
		      . "\t" . '    rm -f $$i-[0-9]*;' . " \\\n"
		      . "\t" . '  fi;' . " \\\n"
		      . "\tdone\n");
    &push_phony_cleaners ('aminfo');
    if ($cygnus_mode)
    {
	$output_rules .= "clean-info: mostlyclean-aminfo\n";
    }

    push (@suffixes, '.texi', '.texinfo', '.txi', '.info', '.dvi', '.ps');

    if (! defined $options{'no-installinfo'})
    {
	push (@uninstall, 'uninstall-info');
	push (@installdirs, '$(DESTDIR)$(infodir)');
	unshift (@install_data, 'install-info-am');

	# Make sure documentation is made and installed first.  Use
	# $(INFO_DEPS), not 'info', because otherwise recursive makes
	# get run twice during "make all".
	unshift (@all, '$(INFO_DEPS)');
    }
    push (@clean, 'aminfo');
    push (@info, '$(INFO_DEPS)');
    push (@dvi, '$(DVIS)');

    &define_variable ("INFO_DEPS", join (' ', @info_deps_list));
    &define_variable ("DVIS", join (' ', @dvis_list));
    # This next isn't strictly needed now -- the places that look here
    # could easily be changed to look in info_TEXINFOS.  But this is
    # probably better, in case noinst_TEXINFOS is ever supported.
    &define_variable ("TEXINFOS", &variable_value ('info_TEXINFOS'));

    # Do some error checking.  Note that this file is not required
    # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
    # up above.
    &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex')
	if $need_texi_file && ! defined $options{'no-texinfo.tex'};
}

# Handle any man pages.
sub handle_man_pages
{
    &am_line_error ('MANS', "\`MANS' is an anachronism; use \`man_MANS'")
	if &variable_defined ('MANS');
    return if ! &variable_defined ('man_MANS');

    # Find all the sections in use.  We do this by first looking for
    # "standard" sections, and then looking for any additional
    # sections used in man_MANS.
    local ($sect, %sections, %vlist);
    # Add more sections as needed.
    foreach $sect ('0'..'9', 'n', 'l')
    {
	if (&variable_defined ('man' . $sect . '_MANS'))
	{
	    $sections{$sect} = 1;
	    $vlist{'$(man' . $sect . '_MANS)'} = 1;
	}
    }

    if (&variable_defined ('man_MANS'))
    {
	$vlist{'$(man_MANS)'} = 1;
	foreach (&variable_value_as_list ('man_MANS', 'all'))
	{
	    # A page like `foo.1c' goes into man1dir.
	    if (/\.([0-9a-z])([a-z]*)$/)
	    {
		$sections{$1} = 1;
	    }
	}
    }


    # Now for each section, generate an install and unintall rule.
    # Sort sections so output is deterministic.
    local (@namelist);
    foreach $sect (sort keys %sections)
    {
	&define_variable ('man' . $sect . 'dir', '$(mandir)/man' . $sect);
	push (@installdirs, '$(DESTDIR)$(mandir)/man' . $sect)
	    unless defined $options{'no-installman'};
	$output_rules .= &file_contents_with_transform ('s/\@SECTION\@/'
							. $sect . '/g;',
							'mans');
	push (@phony, 'install-man' . $sect, 'uninstall-man' . $sect);
	push (@namelist, 'install-man' . $sect);
    }

    # We don't really need this, but we use it in case we ever want to
    # support noinst_MANS.
    &define_variable ("MANS", join (' ', sort keys %vlist));

    # Generate list of install dirs.
    $output_rules .= ("install-man: \$(MANS)\n"
		      . "\t\@\$(NORMAL_INSTALL)\n");
    &pretty_print_rule ("\t\$(MAKE)", "\t ", @namelist);
    push (@phony, 'install-man');

    $output_rules .= "uninstall-man:\n\t\@\$(NORMAL_UNINSTALL)\n";
    grep ($_ = 'un' . $_, @namelist);
    &pretty_print_rule ("\t\$(MAKE)", "\t ", @namelist);
    push (@phony, 'uninstall-man');

    $output_vars .= &file_contents ('mans-vars');

    if (! defined $options{'no-installman'})
    {
	push (@install_data, 'install-man');
	push (@uninstall, 'uninstall-man');
	push (@all, '$(MANS)');
    }
}

# Handle DATA variables.
sub handle_data
{
    &am_install_var ('data', 'DATA', 'data', 'sysconf',
		     'sharedstate', 'localstate', 'pkgdata',
		     'noinst', 'check');
}

# Handle TAGS.
sub handle_tags
{
    push (@phony, 'tags');
    local (@tag_deps) = ();
    if (&variable_defined ('SUBDIRS'))
    {
	$output_rules .= ("tags-recursive:\n"
			  . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
			  # Never fail here if a subdir fails; it
			  # isn't important.
			  . "\t  (cd \$\$subdir && \$(MAKE) tags); \\\n"
			  . "\tdone\n");
	push (@tag_deps, 'tags-recursive');
	push (@phony, 'tags-recursive');
    }

    if ($dir_holds_sources
	|| $dir_holds_headers
	|| &variable_defined ('ETAGS_ARGS')
	|| @tag_deps)
    {
	local ($xform) = '';
	local ($one_hdr);
	foreach $one_hdr (@config_headers)
	{
	    if ($relative_dir eq &dirname ($one_hdr))
	    {
		# The config header is in this directory.  So require it.
		local ($var);
		($var = &basename ($one_hdr)) =~ s/(\W)/\\$1/g;
		$xform .= ' ' if $xform;
		$xform .= $var;
	    }
	}
	$xform = ('s/\@CONFIG\@/' . $xform . '/;'
		  . 's/\@DIRS\@/' . join (' ', @tag_deps) . '/;');

	if (&variable_defined ('SUBDIRS'))
	{
	    $xform .= 's/^SUBDIRS//;';
	}
	else
	{
	    $xform .= 's/^SUBDIRS.*$//;';
	}

	$output_rules .= &file_contents_with_transform ($xform, 'tags');
	$output_rules .= &file_contents ('tags-clean');
	push (@clean, 'tags');
	&push_phony_cleaners ('tags');
	&examine_variable ('TAGS_DEPENDENCIES');
    }
    elsif (&variable_defined ('TAGS_DEPENDENCIES'))
    {
	&am_line_error ('TAGS_DEPENDENCIES',
			"doesn't make sense to define \`TAGS_DEPENDENCIES' without sources or \`ETAGS_ARGS'");
    }
    else
    {
	# Every Makefile must define some sort of TAGS rule.
	# Otherwise, it would be possible for a top-level "make TAGS"
	# to fail because some subdirectory failed.
	$output_rules .= "tags: TAGS\nTAGS:\n\n";
    }
}

# Worker for handle_dist.
sub handle_dist_worker
{
    local ($makefile) = @_;

    $output_rules .= 'distdir: $(DISTFILES)' . "\n";

    # Initialization; only at top level.
    if ($relative_dir eq '.')
    {
	if (defined $options{'check-news'})
	{
	    # For Gnits users, this is pretty handy.  Look at 15 lines
	    # in case some explanatory text is desirable.
	    $output_rules .= '	@if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" > /dev/null; then :; else \\
	  echo "NEWS not updated; not releasing" 1>&2; \\
	  exit 1; \\
	fi
';
	}


	# Create dist directory.
	$output_rules .= ("\t-rm -rf \$(distdir)\n"
			  . "\tmkdir \$(distdir)\n"
			  . "\t-chmod 777 \$(distdir)\n");
    }

    # Only run automake in `dist' target if --include-deps and
    # `no-dependencies' not specified.  That way the recipient of a
    # distribution can run "make dist" and not need Automake.  You
    # might be wondering why we run automake once for each directory
    # we distribute, instead of running it once at the top level.  The
    # answer is that we want to run automake after the dependencies
    # have been generated
    elsxlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
					   '_SOURCES', '_OBJECTS',
					   '_DEPENDENCIES');

	if (! &variable_defined ($xlib . '_LDFLAGS'))
	{
	    # Define the lib_LDFLAGS variable.
	    &define_variable ($xlib . '_LDFLAGS', '');
	}

	if (&variable_defined ($xlib . '_LIBADD'))
	{
	    if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
	    {
		$seen_libobjs = 1;
	    }
	}
	else
	{
	    # Generate support for conditional object inclusion in
	    # libraries.
	    &define_variable ($xlib . "_LIBADD", '');
	}

	if (&variable_defined ($xlib . '_LDADD'))
	{
	    &am_line_error ($xlib . '_LDADD',
			    "use \`" . $xlib . "_LIBADD', not \`"
			    . $xlib . "_LDADD'");
	}

	# Make sure we at look at this.
	&examine_variable ($xlib . '_DEPENDENCIES');

	local ($linker) = &handle_source_transform ($xlib, $onelib, $obj);

	# Determine program to use for link.
	local ($xlink);
	if (&variable_defined ($xlib . '_LINK'))
	{
	    $xlink = $xlib . '_LINK';
	}
	else
	{
	    $xlink = $linker ? $linker : 'LINK';
	}

	local ($rpath);
	if ($instdirs{$onelib} eq 'EXTRA')
	{
	    # It's an EXTRA_ library, so we can't specify -rpath.
	    # Yuck.
	    $rpath = 's/\@RPATH\@//go;';
	}
	else
	{
	    $rpath = ('s/\@RPATH\@/-rpath \$(' . $instdirs{$onelib}
		      . 'dir)/go;');
	}

	$output_rules .=
	    &file_contents_with_transform ('s/\@LTLIBRARY\@/'
					   . $onelib . '/go;'
					   . 's/\@XLTLIBRARY\@/'
					   . $xlib . '/go;'
					   . $rpath
					   . 's/\@XLINK\@/' . $xlink . '/go;',
					   'ltlibrary');
    }

    if ($seen_libobjs)
    {
	foreach $onelib (@liblist)
	{
	    # Canonicalize names.
	    ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
	    if (&variable_defined ($xlib . '_LIBADD'))
	    {
		&check_libobjs_sources ($xlib, $xlib . '_LIBADD');
	    }
	}
    }
}

# See if any _SOURCES variable were misspelled.  Also, make sure that
# EXTRA_ variables don't contain configure substitutions.
sub check_typos
{
    local ($varname, $primary);
    foreach $varname (keys %contents)
    {
	foreach $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
			  '_DEPENDENCIES')
	{
	    if ($varname =~ /$primary$/ && ! $content_seen{$varname})
	    {
		&am_line_error ($varname,
				"invalid unused variable name: \`$varname'");
	    }
	}
    }
}

# Handle scripts.
sub handle_scripts
{
    # NOTE we no longer automatically clean SCRIPTS, because it is
    # useful to sometimes distribute scripts verbatim.  This happens
    # eg in Automake itself.
    &am_install_var ('scripts', 'SCRIPTS',
		     'bin', 'sbin', 'libexec', 'pkgdata',
		     'noinst', 'check');

    # Set $scripts_installed if appropriate.  Make sure we only find
    # scripts which are actually installed -- this is why we can't
    # simply use the return value of am_install_var.
    local (%valid) = &am_primary_prefixes ('SCRIPTS', 'bin', 'sbin',
					   'libexec', 'pkgdata',
					   'noinst', 'check');
    local ($key);
    foreach $key (keys %valid)
    {
	if ($key ne 'noinst'
	    && $key ne 'check'
	    && &variable_defined ($key . '_SCRIPTS'))
	{
	    $scripts_installed = 1;
	    # push (@check_tests, 'check-' . $key . 'SCRIPTS');
	}
    }

    if ($scripts_installed)
    {
	# If a program is installed, this is required.  We only want this
	# error to appear once.
	&am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
	    unless $seen_arg_prog;
	$seen_arg_prog = 1;
    }
}

# Search a file for a "version.texi" Texinfo include.  Return the name
# of the include file if found, or the empty string if not.  A
# "version.texi" file is actually any file whose name matches
# "vers*.texi".
sub scan_texinfo_file
{
    local ($filename) = @_;

    if (! open (TEXI, $filename))
    {
	&am_error ("couldn't open \`$filename': $!");
	return '';
    }
    print "automake: reading $filename\n" if $verbose;

    local ($vfile, $outfile);
    while (<TEXI>)
    {
	if (/^\@setfilename +(\S+)/)
	{
	    $outfile = $1;
	    last if ($vfile);
	}

	if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
	{
	    # Found version.texi include.
	    $vfile = $1;
	    last if $outfile;
	}
    }

    close (TEXI);
    return ($outfile, $vfile);
}

# Handle all Texinfo source.
sub handle_texinfo
{
    &am_line_error ('TEXINFOS',
		    "\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
	if &variable_defined ('TEXINFOS');
    return if (! &variable_defined ('info_TEXINFOS')
	       && ! &variable_defined ('html_TEXINFOS'));

    local (@texis) = &variable_value_as_list ('info_TEXINFOS', 'all');

    local (@info_deps_list, @dvis_list, @texi_deps);
    local ($infobase, $info_cursor);
    local (%versions);
    local ($done) = 0;
    local ($vti);
    local ($tc_cursor, @texi_cleans);
    local ($canonical);

    foreach $info_cursor (@texis)
    {
	# FIXME: This is mildly hacky, since it recognizes "txinfo".
	# I don't feel like making it right.
	($infobase = $info_cursor) =~ s/\.te?xi(nfo)?$//;

	# If 'version.texi' is referenced by input file, then include
	# automatic versioning capability.
	local ($out_file, $vtexi) = &scan_texinfo_file ($relative_dir
							. "/" . $info_cursor);

	if ($out_file eq '')
	{
	    &am_error ("\`$info_cursor' missing                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     