fortran fixlet
[automake.git] / automake.in
blob9b6cbb2bb985eee3bdf0a5832cc7576db967f320
1 #!@PERL@
2 # -*- perl -*-
3 # @configure_input@
5 eval 'exec @PERL@ -S $0 ${1+"$@"}'
6     if 0;
8 # automake - create Makefile.in from Makefile.am
9 # Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2, or (at your option)
14 # any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24 # 02111-1307, USA.
26 # Originally written by David Mackenzie <djm@gnu.ai.mit.edu>.
27 # Perl reimplementation by Tom Tromey <tromey@cygnus.com>.
30 # Parameters set by configure.  Not to be changed.  NOTE: assign
31 # VERSION as string so that eg version 0.30 will print correctly.
32 $VERSION = "@VERSION@";
33 $PACKAGE = "@PACKAGE@";
34 $prefix = "@prefix@";
35 $am_dir = "@datadir@/@PACKAGE@";
36 $TAR = "@TAR@";
38 # String constants.
39 $IGNORE_PATTERN = "^##([^#].*)?\$";
40 $WHITE_PATTERN = "^[ \t]*\$";
41 $COMMENT_PATTERN = "^#";
42 $RULE_PATTERN = "^([\$a-zA-Z_.][-.a-zA-Z0-9_(){}/\$]*) *:([^=].*|)\$";
43 $SUFFIX_RULE_PATTERN = "^\\.([a-zA-Z]+)\\.([a-zA-Z]+)\$";
44 $MACRO_PATTERN = "^([A-Za-z][A-Za-z0-9_]*)[ \t]*:?=[ \t]*(.*)\$";
45 $BOGUS_MACRO_PATTERN = "^([^ \t]*)[ \t]*:?=[ \t]*(.*)\$";
46 $GNITS_VERSION_PATTERN = "[0-9]+\\.[0-9]+([a-z]|\\.[0-9]+)?";
47 $IF_PATTERN = "^if[ \t]+\([A-Za-z][A-Za-z0-9_]*\)[ \t]*\(#.*\)?\$";
48 $ELSE_PATTERN = "^else[ \t]*\(#.*\)?\$";
49 $ENDIF_PATTERN = "^endif[ \t]*\(#.*\)?\$";
51 # Some regular expressions.  One reason to put them here is that it
52 # makes indentation work better in Emacs.
53 $AC_CONFIG_AUX_DIR_PATTERN = "AC_CONFIG_AUX_DIR\\(([^)]+)\\)";
54 $AM_INIT_AUTOMAKE_PATTERN = "AM_INIT_AUTOMAKE\\([^,]*,([^,)]+)[,)]";
55 $AM_PACKAGE_VERSION_PATTERN = "^\\s*\\[?([^]\\s]+)\\]?\\s*\$";
56 # Note that there is no AC_PATH_TOOL.  But we don't really care.
57 $AC_CHECK_PATTERN = "AC_(CHECK|PATH)_(PROG|PROGS|TOOL)\\(\\[?(\\w+)";
58 $AM_MISSING_PATTERN = "AM_MISSING_PROG\\(\\[?(\\w+)";
59 # Just check for alphanumeric in AC_SUBST.  If you do AC_SUBST(5),
60 # then too bad.
61 $AC_SUBST_PATTERN = "AC_SUBST\\(\\[?(\\w+)";
62 $AM_CONDITIONAL_PATTERN = "AM_CONDITIONAL\\((\\w+)";
64 # Constants to define the "strictness" level.
65 $FOREIGN = 0;
66 $GNU = 1;
67 $GNITS = 2;
71 # Variables global to entire run.
73 # TRUE if we should always generate Makefile.in.
74 $force_generation = 1;
76 # Strictness level as set on command line.
77 $default_strictness = $GNU;
79 # Name of strictness level, as set on command line.
80 $default_strictness_name = 'gnu';
82 # This is TRUE if GNU make specific automatic dependency generation
83 # code should be included in generated Makefile.in.
84 $cmdline_use_dependencies = 1;
86 # TRUE if in verbose mode.
87 $verbose = 0;
89 # This holds our (eventual) exit status.  We don't actually exit until
90 # we have processed all input files.
91 $exit_status = 0;
93 # From the Perl manual.
94 $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
96 # TRUE if missing standard files should be installed.
97 $add_missing = 0;
99 # Files found by scanning configure.in for LIBOBJS.
100 %libsources = ();
102 # True if AM_C_PROTOTYPES appears in configure.in.
103 $am_c_prototypes = 0;
105 # Names used in AC_CONFIG_HEADER call.  @config_fullnames holds the
106 # name which appears in AC_CONFIG_HEADER, colon and all.
107 # @config_names holds the file names.  @config_headers holds the '.in'
108 # files.  Ordinarily these are similar, but they can be different if
109 # the weird "NAME:FILE" syntax is used.
110 @config_fullnames = ();
111 @config_names = ();
112 @config_headers = ();
113 # Line number at which AC_CONFIG_HEADER appears in configure.in.
114 $config_header_line = 0;
116 # Directory where output files go.  Actually, output files are
117 # relative to this directory.
118 $output_directory = '.';
120 # Relative location of top build directory.
121 $top_builddir = '';
123 # Absolute location of top build directory.
124 $build_directory = '';
126 # Name of srcdir as given in build directory's Makefile.  For
127 # dependencies only.
128 $srcdir_name = '';
130 # List of Makefile.am's to process, and their corresponding outputs.
131 @input_files = ();
132 %output_files = ();
134 # List of files in AC_OUTPUT without Makefile.am, and their outputs.
135 @other_input_files = ();
136 # Line number at which AC_OUTPUT seen.
137 $ac_output_line = 0;
139 # List of directories to search for configure-required files.  This
140 # can be set by AC_CONFIG_AUX_DIR.
141 @config_aux_path = ('.', '..', '../..');
142 $config_aux_dir = '';
144 # Whether AC_PROG_MAKE_SET has been seen in configure.in.
145 $seen_make_set = 0;
147 # Whether AM_GNU_GETTEXT has been seen in configure.in.
148 $seen_gettext = 0;
149 # Line number at which AM_GNU_GETTEXT seen.
150 $ac_gettext_line = 0;
152 # Whether ALL_LINGUAS has been seen.
153 $seen_linguas = '';
154 # The actual text.
155 $all_linguas = '';
156 # Line number at which it appears.
157 $all_linguas_line = 0;
159 # 1 if AC_PROG_INSTALL seen, 2 if AM_PROG_INSTALL seen.
160 $seen_prog_install = 0;
162 # 1 if any scripts installed, 0 otherwise.
163 $scripts_installed = 0;
165 # Whether AC_PATH_XTRA has been seen in configure.in.
166 $seen_path_xtra = 0;
168 # TRUE if AC_DECL_YYTEXT was seen.
169 $seen_decl_yytext = 0;
171 # TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM).  The presence of
172 # AC_CHECK_TOOL also sets this.
173 $seen_canonical = 0;
175 # TRUE if we've seen AC_ARG_PROGRAM.
176 $seen_arg_prog = 0;
178 # TRUE if we've seen AM_PROG_LIBTOOL.
179 $seen_libtool = 0;
180 $libtool_line = 0;
182 # Files installed by libtoolize.
183 @libtoolize_files = ('ltconfig', 'ltmain.sh', 'config.guess', 'config.sub');
185 # TRUE if we've seen AM_MAINTAINER_MODE.
186 $seen_maint_mode = 0;
188 # TRUE if we've seen PACKAGE and VERSION.
189 $seen_package = 0;
190 $seen_version = 0;
192 # Actual version we've seen.
193 $package_version = '';
195 # Line number where we saw version definition.
196 $package_version_line = 0;
198 # TRUE if we've seen AM_PATH_LISPDIR.
199 $seen_lispdir = 0;
201 # TRUE if we've seen AM_EXEEXT.
202 $seen_exeext = 0;
204 # Hash table of discovered configure substitutions.  Keys are names,
205 # values are meaningless.
206 %configure_vars = ();
208 # Charsets used by maintainer and in distribution.  MAINT_CHARSET is
209 # handled in a funny way: if seen in the top-level Makefile.am, it is
210 # used for every directory which does not specify a different value.
211 # The rationale here is that some directories (eg gettext) might be
212 # distributions of other packages, and thus require their own charset
213 # info.  However, the DIST_CHARSET must be the same for the entire
214 # package; it can only be set at top-level.
215 # FIXME: this yields bugs when rebuilding.  What to do?  Always
216 # read (and sometimes discard) top-level Makefile.am?
217 $maint_charset = '';
218 $dist_charset = 'utf8';         # recode doesn't support this yet.
220 # Name of input file ("Makefile.in") and output file ("Makefile.am").
221 # These have no directory components.
222 $am_file_name = '';
223 $in_file_name = '';
225 # TRUE if --cygnus seen.
226 $cygnus_mode = 0;
228 # Keys of this hash are names of dependency files to ignore.
229 %omit_dependencies = ();
231 # Hash table of AM_CONDITIONAL variables seen in configure.
232 %configure_cond = ();
234 # Map from obsolete macros to hints for new macros.
235 # FIXME complete the list so that there are no `0' hints.
236 %obsolete_macros =
237     (
238      'AC_FEATURE_CTYPE', "use \`AC_HEADER_STDC'",
239      'AC_FEATURE_ERRNO', "add \`strerror' to \`AC_REPLACE_FUNCS(...)'",
240      'AC_FEATURE_EXIT', 0,
241      'AC_SYSTEM_HEADER', 0,
243      # Note that we do not handle this one, because it is still run
244      # from AM_CONFIG_HEADER.  So we deal with it specially in
245      # scan_configure.
246      # 'AC_CONFIG_HEADER', "use \`AM_CONFIG_HEADER'",
248      'fp_C_PROTOTYPES', "use \`AM_C_PROTOTYPES'",
249      'fp_PROG_CC_STDC', "use \`AM_PROG_CC_STDC'",
250      'fp_PROG_INSTALL', "use \`AM_PROG_INSTALL'",
251      'fp_WITH_DMALLOC', "use \`AM_WITH_DMALLOC'",
252      'fp_WITH_REGEX', "use \`AM_WITH_REGEX'",
253      'gm_PROG_LIBTOOL', "use \`AM_PROG_LIBTOOL'",
254      'jm_MAINTAINER_MODE', "use \`AM_MAINTAINER_MODE'",
255      'md_TYPE_PTRDIFF_T', "use \`AM_TYPE_PTRDIFF_T'",
256      'ud_PATH_LISPDIR', "use \`AM_PATH_LISPDIR'",
258      # Now part of autoconf proper, under a different name.
259      'AM_FUNC_FNMATCH', "use \`AC_FUNC_FNMATCH'",
260      'fp_FUNC_FNMATCH', "use \`AC_FUNC_FNMATCH'",
261      'AM_SANITY_CHECK_CC', "automatically done by \`AC_PROG_CC'",
263 # These aren't quite obsolete.
264 #      'md_PATH_PROG',
265      );
267 # Regexp to match the above macros.
268 $obsolete_rx = '(' . join ('|', keys %obsolete_macros) . ')';
272 &initialize_global_constants;
274 # Parse command line.
275 &parse_arguments (@ARGV);
277 # Do configure.in scan only once.
278 &scan_configure;
280 die "automake: no \`Makefile.am' found or specified\n"
281     if ! @input_files;
283 # Now do all the work on each file.
284 foreach $am_file (@input_files)
286     if (! -f ($am_file . '.am'))
287     {
288         &am_error ("\`" . $am_file . ".am' does not exist");
289     }
290     else
291     {
292         &generate_makefile ($output_files{$am_file}, $am_file);
293     }
296 if ($seen_prog_install <= $scripts_installed)
298     &am_conf_error (($scripts_installed ? 'AM_PROG_INSTALL' : 'AC_PROG_INSTALL')
299                     . " must be used in configure.in");
300     &keyed_aclocal_warning ('AM_PROG_INSTALL')
301         if $scripts_installed;
304 exit $exit_status;
307 ################################################################
309 # Parse command line.
310 sub parse_arguments
312     local (@arglist) = @_;
314     # Start off as gnu.
315     &set_strictness ('gnu');
317     while (@arglist)
318     {
319         if ($arglist[0] eq "--version")
320         {
321             print "automake (GNU $PACKAGE) $VERSION\n\n";
322             print "Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.\n";
323             print "This is free software; see the source for copying conditions.  There is NO\n";
324             print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n";
325             print "Written by Tom Tromey <tromey\@cygnus.com>\n";
327             exit 0;
328         }
329         elsif ($arglist[0] eq "--help")
330         {
331             &usage;
332         }
333         elsif ($arglist[0] =~ /^--amdir=(.+)$/)
334         {
335             $am_dir = $1;
336         }
337         elsif ($arglist[0] eq '--amdir')
338         {
339             &require_argument (@arglist);
340             shift (@arglist);
341             $am_dir = $arglist[0];
342         }
343         elsif ($arglist[0] =~ /^--build-dir=(.+)$/)
344         {
345             # Must end in /.
346             $build_directory = $1 . '/';
347         }
348         elsif ($arglist[0] eq '--build-dir')
349         {
350             &require_argument (@arglist);
351             shift (@arglist);
352             # Must end in /.
353             $build_directory = $arglist[0] . '/';
354         }
355         elsif ($arglist[0] =~ /^--srcdir-name=(.+)$/)
356         {
357             $srcdir_name = $1;
358         }
359         elsif ($arglist[0] eq '--srcdir-name')
360         {
361             &require_argument (@arglist);
362             shift (@arglist);
363             $srcdir_name = $arglist[0];
364         }
365         elsif ($arglist[0] eq '--gnu')
366         {
367             &set_strictness ('gnu');
368         }
369         elsif ($arglist[0] eq '--gnits')
370         {
371             &set_strictness ('gnits');
372         }
373         elsif ($arglist[0] eq '--cygnus')
374         {
375             $cygnus_mode = 1;
376         }
377         elsif ($arglist[0] eq '--foreign')
378         {
379             &set_strictness ('foreign');
380         }
381         elsif ($arglist[0] eq '--include-deps' || $arglist[0] eq '-i')
382         {
383             $cmdline_use_dependencies = 0;
384         }
385         elsif ($arglist[0] eq '--no-force')
386         {
387             $force_generation = 0;
388         }
389         elsif ($arglist[0] =~ /^--output-dir=(.*)$/)
390         {
391             # Set output directory.
392             $output_directory = $1;
393         }
394         elsif ($arglist[0] eq '--output-dir' || $arglist[0] eq '-o')
395         {
396             &require_argument (@arglist);
397             shift (@arglist);
398             $output_directory = $arglist[0];
399         }
400         elsif ($arglist[0] eq '--add-missing' || $arglist[0] eq '-a')
401         {
402             $add_missing = 1;
403         }
404         elsif ($arglist[0] eq '--verbose' || $arglist[0] eq '-v')
405         {
406             $verbose = 1;
407         }
408         elsif ($arglist[0] eq '--')
409         {
410             # Stop option processing.
411             shift (@arglist);
412             push (@input_files, @arglist);
413             last;
414         }
415         elsif ($arglist[0] =~ /^-/)
416         {
417             die "automake: unrecognized option -- \`$arglist[0]'\nTry \`automake --help' for more information.\n";
418         }
419         else
420         {
421             # Handle $local:$input syntax.  Note that we only examine
422             # the first ":" file to see if it is automake input; the
423             # rest are just taken verbatim.  We still keep all the
424             # files around for dependency checking, however.
425             local ($local, $input, @rest) = split (/:/, $arglist[0]);
426             if (! $input)
427             {
428                 $input = $local;
429             }
430             else
431             {
432                 # Strip .in; later on .am is tacked on.  That is how
433                 # the automake input file is found.  Maybe not the
434                 # best way, but it is easy to explain.  FIXME: should
435                 # be error if .in is missing.
436                 $input =~ s/\.in$//;
437             }
438             push (@input_files, $input);
439             $output_files{$input} = join (':', ($local, @rest));
440         }
442         shift (@arglist);
443     }
445     # Take global strictness from whatever we currently have set.
446     $default_strictness = $strictness;
447     $default_strictness_name = $strictness_name;
450 # Ensure argument exists, or die.
451 sub require_argument
453     local ($arg, @arglist) = @_;
454     die "automake: no argument given for option \`$arg'\n"
455         if ! @arglist;
458 ################################################################
460 # Generate a Makefile.in given the name of the corresponding Makefile and
461 # the name of the file output by config.status.
462 sub generate_makefile
464     local ($output, $makefile) = @_;
466     ($am_file_name = $makefile) =~ s/^.*\///;
467     $in_file_name = $am_file_name . '.in';
468     $am_file_name .= '.am';
470     # $OUTPUT is encoded.  If it contains a ":" then the first element
471     # is the real output file, and all remaining elements are input
472     # files.  We don't scan or otherwise deal with these input file,
473     # other than to mark them as dependencies.  See scan_configure for
474     # details.
475     local (@secondary_inputs);
476     ($output, @secondary_inputs) = split (/:/, $output);
478     &initialize_per_input;
479     $relative_dir = &dirname ($output);
480     $am_relative_dir = &dirname ($makefile);
482     # At the toplevel directory, we might need config.guess, config.sub
483     # or libtool scripts (ltconfig and ltmain.sh).
484     if ($relative_dir eq '.')
485     {
486         # libtool requires some files.
487         &require_conf_file_with_conf_line ($libtool_line, $FOREIGN,
488                                            @libtoolize_files)
489             if $seen_libtool;
491         # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
492         # config.sub.
493         &require_config_file ($FOREIGN, 'config.guess', 'config.sub')
494             if $seen_canonical;
495     }
497     # We still need Makefile.in here, because sometimes the `dist'
498     # target doesn't re-run automake.
499     if ($am_relative_dir eq $relative_dir)
500     {
501         # Only distribute the files if they are in the same subdir as
502         # the generated makefile.
503         &push_dist_common ($in_file_name, $am_file_name);
504     }
505     push (@sources, '$(SOURCES)')
506         if &variable_defined ('SOURCES');
507     push (@objects, '$(OBJECTS)')
508         if &variable_defined ('OBJECTS');
510     # This is always the default target.  This gives us freedom to do
511     # things in whatever order is convenient.  Note that we set up
512     # $output_header here so that we can insert some text just after
513     # the "default" target, but before any other targets.  In
514     # particular we want to support the .SUFFIX hack here; this is
515     # documented elsewhere.
516     $output_header = "default: all\n\n";
517     push (@phony, 'default');
519     &read_am_file ($makefile . '.am');
520     if (&handle_options)
521     {
522         # Fatal error.  Just return, so we can continue with next file.
523         return;
524     }
526     # Check first, because we might modify some state.
527     &check_cygnus;
528     &check_gnu_standards;
529     &check_gnits_standards;
531     &handle_configure ($output, $makefile, @secondary_inputs);
532     &handle_gettext;
533     &handle_libraries;
534     &handle_ltlibraries;
535     &handle_programs;
536     &handle_scripts;
538     &handle_built_sources;
540     # This must be run after all the sources are scanned.
541     &handle_yacc_lex_cxx;
543     # Re-init SOURCES and OBJECTS.  FIXME: other code shouldn't depend
544     # on this (but currently does).
545     $contents{'SOURCES'} = join (' ', @sources);
546     $contents{'OBJECTS'} = join (' ', @objects);
548     &handle_texinfo;
549     &handle_emacs_lisp;
550     &handle_man_pages;
551     &handle_data;
552     &handle_headers;
553     &handle_subdirs;
554     &handle_tags;
555     &handle_dist ($makefile);
556     &handle_dependencies;
557     &handle_tests;
558     &handle_footer;
559     &handle_merge_targets ($makefile);
560     &handle_installdirs;
561     &handle_clean;
562     &handle_phony;
564     &handle_minor_options;
565     &check_typos;
567     if (! -d ($output_directory . '/' . $am_relative_dir))
568     {
569         mkdir ($output_directory . '/' . $am_relative_dir, 0755);
570     }
572     local ($out_file) = $output_directory . '/' . $makefile . ".in";
573     if (! $force_generation && -e $out_file)
574     {
575         local ($am_time) = (stat ($makefile . '.am'))[9];
576         local ($in_time) = (stat ($out_file))[9];
577         # FIXME: should cache these times.
578         local ($conf_time) = (stat ('configure.in'))[9];
579         # FIXME: how to do unsigned comparison?
580         if ($am_time < $in_time || $am_time < $conf_time)
581         {
582             # No need to update.
583             return;
584         }
585         if (-f 'aclocal.m4')
586         {
587             local ($acl_time) = (stat _)[9];
588             return if ($am_time < $acl_time);
589         }
590     }
592     if (! open (GM_FILE, "> " . $out_file))
593     {
594         warn "automake: ${am_file}.in: cannot write: $!\n";
595         $exit_status = 1;
596         return;
597     }
598     print "automake: creating ", $makefile, ".in\n" if $verbose;
600     print GM_FILE $output_vars;
601     print GM_FILE $output_header;
602     print GM_FILE $output_rules;
603     print GM_FILE $output_trailer;
605     close (GM_FILE);
608 ################################################################
610 # Handle AUTOMAKE_OPTIONS variable.  Return 1 on error, 0 otherwise.
611 sub handle_options
613     if ($strictness == $GNITS)
614     {
615         $options{'readme-alpha'} = 1;
616         $options{'check-news'} = 1;
617     }
619     return 0 if ! &variable_defined ('AUTOMAKE_OPTIONS');
621     foreach (&variable_value_as_list ('AUTOMAKE_OPTIONS', ''))
622     {
623         $options{$_} = 1;
624         if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
625         {
626             &set_strictness ($_);
627         }
628         elsif (/ansi2knr/)
629         {
630             # An option like "../lib/ansi2knr" is allowed.  With no
631             # path prefix, we assume the required programs are in this
632             # directory.  We save the actual option for later.
633             $options{'ansi2knr'} = $_;
634         }
635         elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
636                || $_ eq 'dist-shar' || $_ eq 'dist-zip'
637                || $_ eq 'dist-tarZ' || $_ eq 'dejagnu'
638                || $_ eq 'no-texinfo.tex'
639                || $_ eq 'readme-alpha' || $_ eq 'check-news')
640         {
641             # Explicitly recognize these.
642         }
643         elsif ($_ eq 'no-dependencies')
644         {
645             $use_dependencies = 0;
646         }
647         elsif (/([0-9]+)\.([0-9]+)/)
648         {
649             # Got a version number.  Note that alpha releases count as
650             # the next higher release.  Note also that we assume there
651             # will be a maximum of 100 minor releases for any given
652             # major release.
653             local ($rmajor, $rminor) = ($1, $2);
654             if ($VERSION !~ /([0-9]+)\.([0-9]+)([a-z])?/)
655             {
656                 print STDERR
657                     "automake: programming error: version is incorrect\n";
658                 exit 1;
659             }
660             local ($tmajor, $tminor) = ($1, $2);
661             # Handle alpha versions.
662             ++$tminor if defined $3;
664             if ($rmajor > $tmajor || ($rmajor == $tmajor && $rminor > $tminor))
665             {
666                 &am_line_error ('AUTOMAKE_OPTIONS',
667                                 "require version $_, only have $VERSION");
668                 return 1;
669             }
670         }
671         else
672         {
673             &am_line_error ('AUTOMAKE_OPTIONS',
674                             'option ', $_, 'not recognized');
675         }
676     }
678     return 0;
681 # Return object extension.  Just once, put some code into the output.
682 # Argument is the name of the output file
683 sub get_object_extension
685     local ($out) = @_;
687     # Always set this.
688     $dir_holds_sources = 1;
690     # Maybe require libtool library object files.
691     local ($extension) = '.o';
692     $extension = '.lo' if ($out =~ /\.la$/);
694     if (! $included_generic_compile)
695     {
696         # Boilerplate.
697         local ($xform) = '';
698         if (&variable_defined ('CONFIG_HEADER'))
699         {
700             local ($one_hdr);
701             foreach $one_hdr (split (' ', &variable_value ('CONFIG_HEADER')))
702             {
703                 local ($var);
704                 ($var = &dirname ($one_hdr)) =~ s/(\W)/\\$1/g;
705                 $xform .= ' ' if $xform;
706                 $xform .= '-I' . $var;
707             }
708         }
709         $xform = 's/\@CONFIG_INCLUDE_SPEC\@/' . $xform . '/go;';
710         $output_vars .= &file_contents_with_transform ($xform,
711                                                        'comp-vars');
712         $output_rules .= &file_contents ('compile');
713         &push_phony_cleaners ('compile');
715         # If using X, include some extra variable definitions.  NOTE
716         # we don't want to force these into CFLAGS or anything,
717         # because not all programs will necessarily use X.
718         if ($seen_path_xtra)
719         {
720             local ($var);
721             foreach $var ('X_CFLAGS', 'X_LIBS', 'X_EXTRA_LIBS', 'X_PRE_LIBS')
722             {
723                 &define_configure_variable ($var);
724             }
725         }
727         push (@suffixes, '.c', '.o');
728         push (@clean, 'compile');
730         $included_generic_compile = 1;
731     }
733     if ($seen_libtool && ! $included_libtool_compile)
734     {
735         # Output the libtool compilation rules.
736         $output_rules .= &file_contents ('libtool');
737         &push_phony_cleaners ('libtool');
739         push (@suffixes, '.lo');
740         push (@clean, 'libtool');
742         $included_libtool_compile = 1;
743     }
745     # Check for automatic de-ANSI-fication.
746     if (defined $options{'ansi2knr'})
747     {
748         $extension = '$U' . $extension;
749         if (! $included_knr_compile)
750         {
751             if (! $am_c_prototypes)
752             {
753                 &am_line_error ('AUTOMAKE_OPTIONS',
754                                 "option \`ansi2knr' in use but \`AM_C_PROTOTYPES' not in configure.in");
755                 &keyed_aclocal_warning ('AM_C_PROTOTYPES');
756                 # Only give this error once.
757                 $am_c_prototypes = 1;
758             }
760             # Only require ansi2knr files if they should appear in
761             # this directory.
762             if ($options{'ansi2knr'} eq 'ansi2knr')
763             {
764                 &require_file_with_line ('AUTOMAKE_OPTIONS', $FOREIGN,
765                                          'ansi2knr.c', 'ansi2knr.1');
766                 $output_rules .= &file_contents ('kr-extra');
767                 push (@clean, 'krextra');
768                 &push_phony_cleaners ('krextra');
769             }
771             # Generate rules to build ansi2knr.  If it is in some
772             # other directory, then generate dependencies but have the
773             # rule just run elsewhere.
774             $output_rules .= ($options{'ansi2knr'} . ': '
775                               . $options{'ansi2knr'} . ".o\n");
776             if ($options{'ansi2knr'} eq 'ansi2knr')
777             {
778                 $output_rules .= ("\t\$(LINK) ansi2knr.o \$(LIBS)\n"
779                                   . "ansi2knr.o: \$(CONFIG_HEADER)\n\n");
780             }
781             else
782             {
783                 $output_rules .= ("\tcd " . &dirname ($options{'ansi2knr'})
784                                   . " && \$(MAKE) ansi2knr\n\n");
785             }
787             # Make sure ansi2knr can be found: if no path specified,
788             # specify "./".
789             if ($options{'ansi2knr'} eq 'ansi2knr')
790             {
791                 # Substitution from AM_C_PROTOTYPES.  This makes it be
792                 # built only when necessary.
793                 &define_configure_variable ('ANSI2KNR');
794                 # ansi2knr needs to be built before subdirs, so unshift it.
795                 unshift (@all, '$(ANSI2KNR)');
796             }
797             else
798             {
799                 # Found in another directory.
800                 &define_variable ("ANSI2KNR", $options{'ansi2knr'});
801             }
803             $output_rules .= &file_contents ('clean-kr');
805             push (@clean, 'kr');
806             &push_phony_cleaners ('kr');
808             $included_knr_compile = 1;
809         }
810     }
812     return $extension;
815 # Handle yacc and lex.
816 sub handle_yacc_lex_cxx
818     #
819     # First do yacc and lex.
820     #
822     local ($yacc_count) = scalar (keys %yacc_sources);
823     local ($lex_count) = scalar (keys %lex_sources);
825     if ($yacc_count)
826     {
827         local (%seen_suffix) = ();
828         foreach (keys %yacc_sources)
829         {
830             /(\..*)$/;
831             &output_yacc_build_rule ($1, $yacc_count > 1)
832                 if (! defined $seen_suffix{$1});
833             $seen_suffix{$1} = 1;
834         }
836         if (! defined $configure_vars{'YACC'})
837         {
838             &am_error ("yacc source seen but \`YACC' not defined in \`configure.in'");
839         }
840     }
841     if ($lex_count)
842     {
843         local (%seen_suffix) = ();
844         foreach (keys %lex_sources)
845         {
846             /(\..*)$/;
847             &output_lex_build_rule ($1, $lex_count > 1)
848                 if (! defined $seen_suffix{$1});
849             $seen_suffix{$1} = 1;
850         }
852         if (! defined $configure_vars{'LEX'})
853         {
854             &am_error ("lex source seen but \`LEX' not defined in \`configure.in'");
855         }
856         if (! $seen_decl_yytext)
857         {
858             &am_error ("lex source seen but \`AC_DECL_YYTEXT' not in \`configure.in'");
859         }
860     }
862     if ($yacc_count > 1 || $lex_count > 1)
863     {
864         # If there is more than one distinct yacc (resp lex) source
865         # file in a given directory, then the `ylwrap' program is
866         # required to allow parallel builds to work correctly.  FIXME:
867         # for now, no line number.
868         &require_config_file ($FOREIGN, 'ylwrap');
869         if ($config_aux_dir ne '.' && $config_aux_dir ne '')
870         {
871                 &define_variable ('YLWRAP', $config_aux_dir . "/ylwrap");
872         }
873         else
874         {
875                 &define_variable ('YLWRAP', '$(srcdir)/ylwrap');
876         }
877     }
879     #
880     # Handle libtool.
881     #
882     local ($ltcompile, $ltlink) = ('', '');
883     if ($seen_libtool)
884     {
885         &define_configure_variable ("LIBTOOL");
886         $ltcompile = '$(LIBTOOL) --mode=compile ';
887         $ltlink = '$(LIBTOOL) --mode=link ';
888     }
890     #
891     # Now handle C++.
892     #
893     local (@cxx_list) = keys %cxx_extensions;
894     local ($cxx_count) = scalar @cxx_list;
895     if ($cxx_count)
896     {
897         push (@suffixes, @cxx_list);
899         &define_configure_variable ("CXXFLAGS");
900         &define_variable ('CXXCOMPILE', '$(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)');
901         &define_variable ('LTCXXCOMPILE',
902                           $ltcompile . '$(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)')
903             if ($seen_libtool);
905         &define_variable ('CXXLINK', $ltlink . '$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@');
907         local ($ext);
908         foreach $ext (@cxx_list)
909         {
910             $output_rules .= ("$ext.o:\n"
911                               . "\t\$(CXXCOMPILE) -c \$<\n");
912             $output_rules .= ("$ext.lo:\n"
913                               . "\t\$(LTCXXCOMPILE) -c \$<\n")
914                 if ($seen_libtool);
915         }
917         if (! defined $configure_vars{'CXX'})
918         {
919             &am_error ("C++ source seen but \`CXX' not defined in \`configure.in'");
920         }
921     }
923     #
924     # Handle some ansi2knr cleanup.
925     #
926     if (defined $options{'ansi2knr'} && keys %de_ansi_files)
927     {
928         # Make all _.c files depend on their corresponding .c files.
929         local ($base, @objects);
930         foreach $base (sort (keys %de_ansi_files))
931         {
932             # Each _.c file must depend on ansi2knr; otherwise it
933             # might be used in a parallel build before it is built.
934             # We need to support files in the srcdir and in the build
935             # dir (because these files might be auto-generated.  But
936             # we can't use $< -- some makes only define $< during a
937             # suffix rule.
938             $output_rules .= ($base . "_.c: $base.c \$(ANSI2KNR)\n\t"
939                               . '$(ANSI2KNR) '
940                               . '`if test -f $(srcdir)/' . $base . '.c'
941                               . '; then echo $(srcdir)/' . $base . '.c'
942                               . '; else echo ' . $base . '.c; fi` '
943                               . $base . "_.c\n");
944             push (@objects, $base . '_.o');
945             push (@objects, $base . '_.lo') if $seen_libtool;
946         }
948         # Make all _.o (and _.lo) files depend on ansi2knr.
949         # Use a sneaky little hack to make it print nicely.
950         &pretty_print_rule ('', '', @objects, ':', '$(ANSI2KNR)');
951     }
953     #
954     # Last, handle some C cleanup.
955     #
956     if ($seen_c_source)
957     {
958         &define_configure_variable ('CFLAGS');
959         &define_variable ('COMPILE',
960                           '$(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)');
961         &define_variable ('LTCOMPILE',
962                           $ltcompile .
963                           '$(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)')
964             if ($seen_libtool);
965         &define_variable ('LINK', $ltlink . '$(CC) $(CFLAGS) $(LDFLAGS) -o $@');
967         if (! defined $configure_vars{'CC'})
968         {
969             &am_line_error ($seen_c_source,
970                             "C source seen but \`CC' not defined in \`configure.in'");
971         }
972     }
976 # Output a rule to build from a YACC source.  The output from YACC is
977 # compiled with C or C++, depending on the extension of the YACC file.
978 sub output_yacc_build_rule
980     local ($yacc_suffix, $use_ylwrap, $c_suffix) = @_;
982     local ($c_suffix, $suffix);
983     ($c_suffix = $yacc_suffix) =~ tr/y/c/;
984     push (@suffixes, $yacc_suffix, $c_suffix, '.h');
986     # Generate rule for c/c++ and header file.  Probably should only
987     # do header if `yacc -d' is run.  But how can we determine that?
988     foreach $suffix ($c_suffix, '.h')
989     {
990         $output_rules .= "$yacc_suffix$suffix:\n\t";
992         if ($use_ylwrap)
993         {
994             $output_rules .= ('$(SHELL) $(YLWRAP)'
995                               . ' "$(YACC)" $< y.tab.c $*' . $c_suffix
996                               . ' y.tab.h $*.h -- $(YACCFLAGS)');
997         }
998         else
999         {
1000             $output_rules .= ('$(YACC) $(YACCFLAGS) $< && mv y.tab.c $@' . "\n"
1001                               . "\tif test -f y.tab.h; then \\\n"
1002                               . "\tif cmp -s y.tab.h \$*.h; then rm -f y.tab.h; else mv y.tab.h \$*.h; fi; \\\n"
1003                           . "\telse :; fi");
1004         }
1005         $output_rules .= "\n";
1006     }
1009 sub output_lex_build_rule
1011     local ($lex_suffix, $use_ylwrap) = @_;
1012     local ($c_suffix);
1014     ($c_suffix = $lex_suffix) =~ tr/l/c/;
1015     push (@suffixes, $lex_suffix);
1016     &define_configure_variable ('LEX_OUTPUT_ROOT');
1017     &define_configure_variable ('LEXLIB');
1018     $output_rules .= "$lex_suffix$c_suffix:\n\t";
1020     if ($use_ylwrap)
1021     {
1022         # Is the $@ correct here?  If so, why not use it in the ylwrap
1023         # build rule for yacc above?
1024         $output_rules .= '$(SHELL) $(YLWRAP)'
1025             . ' "$(LEX)" $< $(LEX_OUTPUT_ROOT).c $@ -- $(LFLAGS)';
1026     }
1027     else
1028     {
1029         $output_rules .= '$(LEX) $(LFLAGS) $< && mv $(LEX_OUTPUT_ROOT).c $@';
1030     }
1031     $output_rules .= "\n";
1035 # Check to make sure a source defined in LIBOBJS is not explicitly
1036 # mentioned.  This is a separate function (as opposed to being inlined
1037 # in handle_source_transform) because it isn't always appropriate to
1038 # do this check.
1039 sub check_libobjs_sources
1041     local ($one_file, $unxformed) = @_;
1043     local ($prefix, $file, @files);
1044     foreach $prefix ('', 'EXTRA_')
1045     {
1046         if (&variable_defined ($prefix . $one_file . '_SOURCES'))
1047         {
1048             @files = &variable_value_as_list (($prefix
1049                                                . $one_file . '_SOURCES'),
1050                                               'all');
1051         }
1052         elsif ($prefix eq '')
1053         {
1054             @files = ($unxformed . '.c');
1055         }
1056         else
1057         {
1058             next;
1059         }
1061         foreach $file (@files)
1062         {
1063             if (defined $libsources{$file})
1064             {
1065                 &am_line_error ($prefix . $one_file . '_SOURCES',
1066                                 "automatically discovered file \`$file' should not be explicitly mentioned");
1067             }
1068         }
1069     }
1072 # Does much of the actual work for handle_source_transform.
1073 # Arguments are:
1074 #   list of source files to transform
1075 # Result is a list
1076 #   first element is name of linker to use (empty string for default linker)
1077 #   remaining elements are names of `.o's
1078 sub handle_single_transform_list
1080     local (@files) = @_;
1081     local ($linker) = '';
1082     local (@result) = ();
1083     local ($nonansi_obj) = $obj;
1084     $nonansi_obj =~ s/_//g;
1085     if (@files > 0)
1086     {
1087         # Turn sources into objects.
1088         foreach (@files)
1089         {
1090             # Skip header files, including C++-ish ones.  The list
1091             # of C++ header extensions comes from Emacs 19.32
1092             # etags.
1093             next if /\.[hH]$/;
1094             next if /\.hxx$/;
1095             next if /\.h\+\+$/;
1096             next if /\.hh$/;
1097             next if /\.hpp$/;
1098             # Skip things that look like configure substitutions.
1099             next if /^\@.*\@$/;
1101             # Include appropriate file for lex or yacc source in
1102             # distribution.  If the extension is the regular '.y' or
1103             # '.l', we assume C compilation, and the generated file
1104             # has exension .c.  Otherwise, we compile with C++, and
1105             # make the following association: (yy -> cc, y++ -> c++,
1106             # yxx -> cxx), similarly for .ll, etc.
1107             if (/^(.*)\.(y|yy|y\+\+|yxx)$/)
1108             {
1109                 # Yacc source.
1110                 local ($ext) = $2;
1111                 $ext =~ tr/y/c/;
1112                 &push_dist_common ("$1.$ext");
1113                 $yacc_sources{$_} = 1;
1114             }
1115             elsif (/^(.*)\.(l|ll|l\+\+|lxx)$/)
1116             {
1117                 # Lex source.
1118                 local ($ext) = $2;
1119                 $ext =~ tr/l/c/;
1120                 &push_dist_common ("$1.$ext");
1121                 $lex_sources{$_} = 1;
1122             }
1124             # Strip any directory prefix.
1125             $_ = &basename ($_);
1127             # Transform source files into .o files.  List of C++
1128             # extensions comes from Emacs 19.34 etags.
1129             if (s/\.(c\+\+|cc|cpp|cxx|C)$/$nonansi_obj/)
1130             {
1131                 $cxx_extensions{'.' . $1} = 1;
1132                 $linker = 'CXXLINK';
1133             }
1134             elsif (s/\.(yy|y\+\+|yxx|ll|l\+\+|lxx)$/$nonansi_obj/)
1135             {
1136                 # Compiling lex or yacc with C++
1137                 local ($ext) = $1;
1138                 $ext =~ tr/ly/cc/;
1139                 $cxx_extensions{".$ext"} = 1;
1140                 $linker = 'CXXLINK';
1141             }
1142             elsif (s/\.([Ff]|f90|for)$/$nonansi_obj/)
1143             {
1144                 # FORTRAN support.  FIXME: not finished.
1145             }
1146             elsif (s/\.[sS]$/$nonansi_obj/)
1147             {
1148                 # .s is assembly.  Just rewrite it.  FIXME: not finished.
1149             }
1150             elsif (defined ($options{'ansi2knr'}) && s/_\.[cly]$/_.c/)
1151             {
1152                 # FIXME include line number in error.
1153                 &am_error ("C source file \`$_' would be deleted by ansi2knr rules");
1154             }
1155             elsif (s/\.[cly]$//)
1156             {
1157                 # .c is C.  .l is lex.  .y is yacc.
1158   
1159                 # Note: first we rewrite (eg) foo.c to foo and push
1160                 # the file onto the list of deansified files.  Then we add
1161                 # $obj, which can either be `_.o', or simply `.o' if
1162                 # deansification is not required.
1163                 $de_ansi_files{$_} = 1;
1164                 $_ .= $obj;
1165                 $seen_c_source = 1;
1166             }
1167             elsif (/\.$source_suffix_pattern$/) 
1168             {
1169                 # We just rewrite it.  Maybe we should do more.
1170                 s//.$suffix_rules{$1}/;
1171             }
1172             else
1173             {
1174                 # No error message here.  Used to have one, but it was
1175                 # very unpopular.
1176                 next;
1177             }
1179             push (@result, $_);
1181             # Transform .o or $o file into .P file (for automatic
1182             # dependency code).
1183             s/$objpat$/.P/g;
1184             $dep_files{'.deps/' . $_} = 1;
1185         }
1186     }
1188     return ($linker, @result);
1191 # Handle SOURCE->OBJECT transform for one program or library.
1192 # Arguments are:
1193 #   canonical (transformed) name of object to build
1194 #   actual name of object to build
1195 #   object extension (ie either `.o' or `$o'.
1196 # Return result is name of linker variable that must be used.
1197 # Empty return means just use `LINK'.
1198 sub handle_source_transform
1200     # one_file is canonical name.  unxformed is given name.  obj is
1201     # object extension.
1202     local ($one_file, $unxformed, $obj) = @_;
1203     local ($objpat) = $obj;
1204     $objpat =~ s/(\W)/\\$1/g;
1205     # Handle explicit `.o' as well as whatever we're passed.
1206     $objpat = '(' . $objpat . "|\\.o)";
1208     local ($linker) = '';
1210     if (&variable_defined ($one_file . "_OBJECTS"))
1211     {
1212         &am_line_error ($one_file . '_OBJECTS',
1213                         $one_file . '_OBJECTS', 'should not be defined');
1214         # No point in continuing.
1215         return;
1216     }
1218     local (@files, @result, $prefix, $temp);
1219     foreach $prefix ('', 'EXTRA_')
1220     {
1221         @files = ();
1222         local ($var) = $prefix . $one_file . "_SOURCES";
1223         if (&variable_defined ($var))
1224         {
1225             push (@sources, '$(' . $prefix . $one_file . "_SOURCES)");
1226             push (@objects, '$(' . $prefix . $one_file . "_OBJECTS)")
1227                 unless $prefix eq 'EXTRA_';
1228             local (@conds) = &variable_conditions ($var);
1229             if (! @conds)
1230             {
1231                 @files = &variable_value_as_list ($var, '');
1232             }
1233             else
1234             {
1235                 local ($cond);
1236                 foreach $cond (@conds)
1237                 {
1238                     @files = &variable_value_as_list ($var, $cond);
1239                     ($temp, @result) = &handle_single_transform_list (@files);
1240                     $linker = $temp if $linker eq '';
1241                     &define_pretty_variable ($one_file . "_OBJECTS", $cond,
1242                                              @result)
1243                         unless $prefix eq 'EXTRA_';
1244                 }
1246                 next;
1247             }
1248         }
1249         elsif ($prefix eq '')
1250         {
1251             &define_variable ($one_file . "_SOURCES", $unxformed . ".c");
1252             push (@sources, $unxformed . '.c');
1253             push (@objects, $unxformed . $obj);
1254             push (@files, $unxformed . '.c');
1255         }
1257         ($temp, @result) = &handle_single_transform_list (@files);
1258         $linker = $temp if $linker eq '';
1259         &define_pretty_variable ($one_file . "_OBJECTS", '', @result)
1260             unless $prefix eq 'EXTRA_';
1261     }
1263     return $linker;
1266 # Handle the BUILT_SOURCES variable.
1267 sub handle_built_sources
1269     return unless &variable_defined ('BUILT_SOURCES');
1271     local (@sources) = &variable_value_as_list ('BUILT_SOURCES', 'all');
1272     local ($s);
1273     foreach $s (@sources)
1274     {
1275         if (/^\@.*\@$/)
1276         {
1277             # FIXME: is this really the right thing to do?
1278             &am_line_error ('BUILT_SOURCES',
1279                             "\`BUILT_SOURCES' should not contain a configure substitution");
1280             last;
1281         }
1282     }
1284     # We don't care about the return value of this function.  We just
1285     # want to make sure to update %dep_files with the contents of
1286     # BUILT_SOURCES.
1287     &handle_single_transform_list (@sources);
1290 # Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
1291 # Also, generate _DEPENDENCIES variable if appropriate.
1292 # Arguments are:
1293 #   transformed name of object being built, or empty string if no object
1294 #   name of _LDADD/_LIBADD-type variable to examine
1295 #   boolean (lex_seen) which is true if a lex source file was seen in this
1296 #     object.  valid only for LDADDs, not LIBADDs.  If set, LEXLIB
1297 #     must be in LDADD.
1298 # Returns 1 if LIBOBJS seen, 0 otherwise.
1299 sub handle_lib_objects
1301     local ($xname, $var, $lex_seen) = @_;
1302     local ($ret);
1304     die "automake: programming error 1 in handle_lib_objects\n"
1305         if ! &variable_defined ($var);
1307     die "automake: programming error 2 in handle_lib_objects\n"
1308         if $lex_seen && $var =~ /LIBADD/;
1310     local (@conds) = &variable_conditions ($var);
1311     if (! @conds)
1312     {
1313         $ret = &handle_lib_objects_cond ($xname, $var, $lex_seen, '');
1314     }
1315     else
1316     {
1317         local ($cond);
1318         $ret = 0;
1319         foreach $cond (@conds)
1320         {
1321             if (&handle_lib_objects_cond ($xname, $var, $lex_seen, $cond))
1322             {
1323                 $ret = 1;
1324             }
1325         }
1326     }
1328     return $ret;
1331 # Subroutine of handle_lib_objects: handle a particular condition.
1332 sub handle_lib_objects_cond
1334     local ($xname, $var, $lex_seen, $cond) = @_;
1336     # We recognize certain things that are commonly put in LIBADD or
1337     # LDADD.
1338     local ($lsearch);
1339     local (@dep_list) = ();
1341     # If no lex source seen, just assume this is ok.
1342     local ($lex_ok) = $lex_seen ? 0 : 1;
1344     local ($seen_libobjs) = 0;
1345     local ($flagvar) = 0;
1347     foreach $lsearch (&variable_value_as_list ($var, $cond))
1348     {
1349         # Skip -lfoo and -Ldir; these are explicitly allowed.
1350         next if $lsearch =~ /^-[lL]/;
1351         if (! $flagvar && $lsearch =~ /^-/)
1352         {
1353             if ($var =~ /^(.*)LDADD$/)
1354             {
1355                 &am_line_error ($var, "linker flags such as \`$lsearch' belong in \`${1}LDFLAGS");
1356             }
1357             else
1358             {
1359                 # Only get this error once.
1360                 $flagvar = 1;
1361                 &am_line_error ($var, "you cannot use linker flags such as \`$lsearch' in \`$var'");
1362             }
1363         }
1365         # Assume we have a file of some sort, and push it onto the
1366         # dependency list.  Autoconf substitutions are not pushed;
1367         # rarely is a new dependency substituted into (eg) foo_LDADD
1368         # -- but "bad things (eg -lX11) are routinely substituted.
1369         # Note that LIBOBJS and ALLOCA are exceptions to this rule,
1370         # and handled specially below.
1371         push (@dep_list, $lsearch)
1372             unless $lsearch =~ /^\@.*\@$/;
1374         # Automatically handle @LIBOBJS@ and @ALLOCA@.  Basically this
1375         # means adding entries to dep_files.
1376         if ($lsearch =~ /^\@(LT)?LIBOBJS\@$/)
1377         {
1378             push (@dep_list, $lsearch);
1379             $seen_libobjs = 1;
1380             if (! keys %libsources)
1381             {
1382                 &am_line_error ($var, "\@$1" . "LIBOBJS\@ seen but never set in \`configure.in'");
1383             }
1385             local ($iter, $rewrite);
1386             foreach $iter (keys %libsources)
1387             {
1388                 if ($iter =~ /\.[cly]$/)
1389                 {
1390                     $seen_c_source = $var;
1391                 }
1393                 if ($iter =~ /\.h$/)
1394                 {
1395                     &require_file_with_line ($var, $FOREIGN, $iter);
1396                 }
1397                 elsif ($iter ne 'alloca.c')
1398                 {
1399                     ($rewrite = $iter) =~ s/\.c$/.P/;
1400                     $dep_files{'.deps/' . $rewrite} = 1;
1401                     &require_file_with_line ($var, $FOREIGN, $iter);
1402                 }
1403             }
1404         }
1405         elsif ($lsearch =~ /^\@(LT)?ALLOCA\@$/)
1406         {
1407             push (@dep_list, $lsearch);
1408             &am_line_error ($var,
1409                             "\@$1" . "ALLOCA\@ seen but \`AC_FUNC_ALLOCA' not in \`configure.in'")
1410                 if ! defined $libsources{'alloca.c'};
1411             $dep_files{'.deps/alloca.P'} = 1;
1412             &require_file_with_line ($var, $FOREIGN, 'alloca.c');
1413             $seen_c_source = $var;
1414         }
1415         elsif ($lsearch eq '@LEXLIB@')
1416         {
1417             # FIXME: variable_value_as_list requires us to force
1418             # @LEXLIB@ here, where we'd really prefer $(LEXLIB).
1419             # Nasty -- this will have to wait until many cleanups are
1420             # made, I think.
1421             $lex_ok = 1;
1422         }
1423     }
1425     if (! $lex_ok)
1426     {
1427         &am_line_error ($var, 'lex source file used without @LEXLIB@');
1428     }
1430     if ($xname ne '' && ! &variable_defined ($xname . '_DEPENDENCIES', $cond))
1431     {
1432         &define_pretty_variable ($xname . '_DEPENDENCIES', $cond, @dep_list);
1433     }
1435     return $seen_libobjs;
1438 # Canonicalize a name, and check to make sure the non-canonical name
1439 # is never used.  Returns canonical name.  Arguments are name and a
1440 # list of suffixes to check for.
1441 sub check_canonical_spelling
1443     local ($name, @suffixes) = @_;
1444     local ($xname, $xt);
1446     ($xname = $name) =~ tr/A-Za-z0-9_/_/c;
1447     if ($xname ne $name)
1448     {
1449         local ($xt);
1450         foreach $xt (@suffixes)
1451         {
1452             &am_line_error ($name . $xt,
1453                             "invalid variable \`" . $name . $xt
1454                             . "'; should be \`" . $xname . $xt . "'")
1455                 if &variable_defined ($name . $xt);
1456         }
1457     }
1459     return $xname;
1462 # Handle C programs.
1463 sub handle_programs
1465     local (@proglist) = &am_install_var ('-clean',
1466                                          'progs', 'PROGRAMS',
1467                                          'bin', 'sbin', 'libexec', 'pkglib',
1468                                          'noinst', 'check');
1469     return if ! @proglist;
1471     # If a program is installed, this is required.  We only want this
1472     # error to appear once.
1473     &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
1474         unless $seen_arg_prog;
1475     $seen_arg_prog = 1;
1477     local ($one_file, $xname, $munge);
1479     local ($seen_libobjs) = 0;
1480     foreach $one_file (@proglist)
1481     {
1482         local ($obj) = &get_object_extension ($one_file);
1484         # Canonicalize names and check for misspellings.
1485         $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
1486                                             '_SOURCES', '_OBJECTS',
1487                                             '_DEPENDENCIES');
1489         # FIXME: Using a trick to figure out if any lex sources appear
1490         # in our program; should use some cleaner method.
1491         local ($lex_num) = scalar (keys %lex_sources);
1492         local ($linker) = &handle_source_transform ($xname, $one_file, $obj);
1493         local ($lex_file_seen) = (scalar (keys %lex_sources) > $lex_num);
1495         local ($xt) = '';
1496         if (&variable_defined ($xname . "_LDADD"))
1497         {
1498             if (&handle_lib_objects ($xname, $xname . '_LDADD',
1499                                      $lex_file_seen))
1500             {
1501                 $seen_libobjs = 1;
1502             }
1503             $lex_file_seen = 0;
1504             $xt = '_LDADD';
1505         }
1506         else
1507         {
1508             # User didn't define prog_LDADD override.  So do it.
1509             &define_variable ($xname . '_LDADD', '$(LDADD)');
1511             # This does a bit too much work.  But we need it to
1512             # generate _DEPENDENCIES when appropriate.
1513             if (&variable_defined ('LDADD'))
1514             {
1515                 if (&handle_lib_objects ($xname, 'LDADD', $lex_file_seen))
1516                 {
1517                     $seen_libobjs = 1;
1518                 }
1519                 $lex_file_seen = 0;
1520             }
1521             elsif (! &variable_defined ($xname . '_DEPENDENCIES'))
1522             {
1523                 &define_variable ($xname . '_DEPENDENCIES', '');
1524             }
1525             $xt = '_SOURCES'
1526         }
1528         if (&variable_defined ($xname . '_LIBADD'))
1529         {
1530             &am_line_error ($xname . '_LIBADD',
1531                             "use \`" . $xname . "_LDADD', not \`"
1532                             . $xname . "_LIBADD'");
1533         }
1535         if (! &variable_defined ($xname . '_LDFLAGS'))
1536         {
1537             # Define the prog_LDFLAGS variable.
1538             &define_variable ($xname . '_LDFLAGS', '');
1539         }
1541         if ($lex_file_seen)
1542         {
1543             &am_line_error ($xname . $xt,
1544                             'lex source file used without @LEXLIB@');
1545         }
1547         # Determine program to use for link.
1548         local ($xlink);
1549         if (&variable_defined ($xname . '_LINK'))
1550         {
1551             $xlink = $xname . '_LINK';
1552         }
1553         else
1554         {
1555             $xlink = $linker ? $linker : 'LINK';
1556         }
1558         local ($xexe);
1559         if ($seen_exeext && $one_file !~ /\./)
1560         {
1561             $xexe = 's/\@EXEEXT\@/\$(EXEEXT)/g;';
1562         }
1563         else
1564         {
1565             $xexe = 's/\@EXEEXT\@//g;';
1566         }
1568         $output_rules .=
1569             &file_contents_with_transform
1570                 ('s/\@PROGRAM\@/' . $one_file . '/go;'
1571                  . 's/\@XPROGRAM\@/' . $xname . '/go;'
1572                  . 's/\@XLINK\@/' . $xlink . '/go;'
1573                  . $xexe,
1574                  'program');
1575     }
1577     if (&variable_defined ('LDADD') && &handle_lib_objects ('', 'LDADD', 0))
1578     {
1579         $seen_libobjs = 1;
1580     }
1582     if ($seen_libobjs)
1583     {
1584         foreach $one_file (@proglist)
1585         {
1586             # Canonicalize names.
1587             ($xname = $one_file) =~ tr/A-Za-z0-9_/_/c;
1589             if (&variable_defined ($xname . '_LDADD'))
1590             {
1591                 &check_libobjs_sources ($xname, $xname . '_LDADD');
1592             }
1593             elsif (&variable_defined ('LDADD'))
1594             {
1595                 &check_libobjs_sources ($xname, 'LDADD');
1596             }
1597         }
1598     }
1602 # Handle libraries.
1603 sub handle_libraries
1605     local (@liblist) = &am_install_var ('-clean',
1606                                         'libs', 'LIBRARIES',
1607                                         'lib', 'pkglib', 'noinst', 'check');
1608     return if ! @liblist;
1610     local (%valid) = &am_primary_prefixes ('LIBRARIES', 'lib', 'pkglib',
1611                                            'noinst', 'check');
1612     if (! defined $configure_vars{'RANLIB'})
1613     {
1614         local ($key);
1615         foreach $key (keys %valid)
1616         {
1617             if (&variable_defined ($key . '_LIBRARIES'))
1618             {
1619                 &am_line_error ($key . '_LIBRARIES', "library used but \`RANLIB' not defined in \`configure.in'");
1620                 # Only get this error once.
1621                 $configure_vars{'RANLIB'} = 1;
1622                 last;
1623             }
1624         }
1625     }
1627     local ($onelib);
1628     local ($munge);
1629     local ($xlib);
1630     local ($seen_libobjs) = 0;
1631     foreach $onelib (@liblist)
1632     {
1633         # Check that the library fits the standard naming convention.
1634         if ($onelib !~ /^lib.*\.a$/)
1635         {
1636             # FIXME should put line number here.  That means mapping
1637             # from library name back to variable name.
1638             &am_error ("\`$onelib' is not a standard library name");
1639         }
1641         local ($obj) = &get_object_extension ($onelib);
1643         # Canonicalize names and check for misspellings.
1644         $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
1645                                            '_OBJECTS', '_DEPENDENCIES');
1647         if (&variable_defined ($xlib . '_LIBADD'))
1648         {
1649             if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
1650             {
1651                 $seen_libobjs = 1;
1652             }
1653         }
1654         else
1655         {
1656             # Generate support for conditional object inclusion in
1657             # libraries.
1658             &define_variable ($xlib . "_LIBADD", '');
1659         }
1661         if (&variable_defined ($xlib . '_LDADD'))
1662         {
1663             &am_line_error ($xlib . '_LDADD',
1664                             "use \`" . $xlib . "_LIBADD', not \`"
1665                             . $xlib . "_LDADD'");
1666         }
1668         &handle_source_transform ($xlib, $onelib, $obj);
1670         $output_rules .=
1671             &file_contents_with_transform ('s/\@LIBRARY\@/' . $onelib . '/go;'
1672                                            . 's/\@XLIBRARY\@/'
1673                                            . $xlib . '/go;',
1674                                            'library');
1675     }
1677     if ($seen_libobjs)
1678     {
1679         foreach $onelib (@liblist)
1680         {
1681             # Canonicalize names.
1682             ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
1683             if (&variable_defined ($xlib . '_LIBADD'))
1684             {
1685                 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
1686             }
1687         }
1688     }
1690     &define_variable ('AR', 'ar');
1691     &define_configure_variable ('RANLIB');
1694 # Handle shared libraries.
1695 sub handle_ltlibraries
1697     local (@liblist) = &am_install_var ('-clean',
1698                                         'ltlib', 'LTLIBRARIES',
1699                                         'lib', 'pkglib');
1700     return if ! @liblist;
1702     local (%instdirs);
1703     local (%valid) = &am_primary_prefixes ('LTLIBRARIES', 'lib', 'pkglib');
1705     local ($key);
1706     foreach $key (keys %valid)
1707     {
1708         if (&variable_defined ($key . '_LTLIBRARIES'))
1709         {
1710             if (!$seen_libtool)
1711             {
1712                 &am_line_error ($key . '_LTLIBRARIES', "library used but \`LIBTOOL' not defined in \`configure.in'");
1713                 # Only get this error once.
1714                 $configure_vars{'LIBTOOL'} = 1;
1715                 $seen_libtool = 1;
1716             }
1718             # Get the installation directory of each library.
1719             for (&variable_value_as_list ($key . '_LTLIBRARIES', 'all'))
1720             {
1721                 if ($instdirs{$_})
1722                 {
1723                     &am_error ("\`$_' is already going to be installed in \`$instdirs{$_}'");
1724                 }
1725                 else
1726                 {
1727                     $instdirs{$_} = $key;
1728                 }
1729             }
1730         }
1731     }
1733     local ($onelib);
1734     local ($munge);
1735     local ($xlib);
1736     local ($seen_libobjs) = 0;
1737     foreach $onelib (@liblist)
1738     {
1739         # Check that the library fits the standard naming convention.
1740         if ($onelib !~ /^lib.*\.la$/)
1741         {
1742             # FIXME this should only be a warning for foreign packages
1743             # FIXME should put line number here.  That means mapping
1744             # from library name back to variable name.
1745             &am_error ("\`$onelib' is not a standard libtool library name");
1746         }
1748         local ($obj) = &get_object_extension ($onelib);
1750         # Canonicalize names and check for misspellings.
1751         $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
1752                                            '_SOURCES', '_OBJECTS',
1753                                            '_DEPENDENCIES');
1755         if (! &variable_defined ($xlib . '_LDFLAGS'))
1756         {
1757             # Define the lib_LDFLAGS variable.
1758             &define_variable ($xlib . '_LDFLAGS', '');
1759         }
1761         if (&variable_defined ($xlib . '_LIBADD'))
1762         {
1763             if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
1764             {
1765                 $seen_libobjs = 1;
1766             }
1767         }
1768         else
1769         {
1770             # Generate support for conditional object inclusion in
1771             # libraries.
1772             &define_variable ($xlib . "_LIBADD", '');
1773         }
1775         if (&variable_defined ($xlib . '_LDADD'))
1776         {
1777             &am_line_error ($xlib . '_LDADD',
1778                             "use \`" . $xlib . "_LIBADD', not \`"
1779                             . $xlib . "_LDADD'");
1780         }
1782         local ($linker) = &handle_source_transform ($xlib, $onelib, $obj);
1784         # Determine program to use for link.
1785         local ($xlink);
1786         if (&variable_defined ($xlib . '_LINK'))
1787         {
1788             $xlink = $xlib . '_LINK';
1789         }
1790         else
1791         {
1792             $xlink = $linker ? $linker : 'LINK';
1793         }
1795         local ($rpath);
1796         if ($instdirs{$onelib} eq 'EXTRA')
1797         {
1798             # It's an EXTRA_ library, so we can't specify -rpath.
1799             # Yuck.
1800             $rpath = 's/\@RPATH\@//go;';
1801         }
1802         else
1803         {
1804             $rpath = ('s/\@RPATH\@/-rpath \$(' . $instdirs{$onelib}
1805                       . 'dir)/go;');
1806         }
1808         $output_rules .=
1809             &file_contents_with_transform ('s/\@LTLIBRARY\@/'
1810                                            . $onelib . '/go;'
1811                                            . 's/\@XLTLIBRARY\@/'
1812                                            . $xlib . '/go;'
1813                                            . $rpath
1814                                            . 's/\@XLINK\@/' . $xlink . '/go;',
1815                                            'ltlibrary');
1816     }
1818     if ($seen_libobjs)
1819     {
1820         foreach $onelib (@liblist)
1821         {
1822             # Canonicalize names.
1823             ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
1824             if (&variable_defined ($xlib . '_LIBADD'))
1825             {
1826                 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
1827             }
1828         }
1829     }
1832 # See if any _SOURCES variable were misspelled.  Also, make sure that
1833 # EXTRA_ variables don't contain configure substitutions.
1834 sub check_typos
1836     local ($varname, $primary);
1837     foreach $varname (keys %contents)
1838     {
1839         foreach $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
1840                           '_DEPENDENCIES')
1841         {
1842             if ($varname =~ /$primary$/ && ! $content_seen{$varname})
1843             {
1844                 &am_line_error ($varname,
1845                                 "invalid unused variable name: \`$varname'");
1846             }
1847         }
1848     }
1851 # Handle scripts.
1852 sub handle_scripts
1854     # NOTE we no longer automatically clean SCRIPTS, because it is
1855     # useful to sometimes distribute scripts verbatim.  This happens
1856     # eg in Automake itself.
1857     &am_install_var ('scripts', 'SCRIPTS',
1858                      'bin', 'sbin', 'libexec', 'pkgdata',
1859                      'noinst', 'check');
1861     # Set $scripts_installed if appropriate.  Make sure we only find
1862     # scripts which are actually installed -- this is why we can't
1863     # simply use the return value of am_install_var.
1864     local (%valid) = &am_primary_prefixes ('SCRIPTS', 'bin', 'sbin',
1865                                            'libexec', 'pkgdata',
1866                                            'noinst', 'check');
1867     local ($key);
1868     foreach $key (keys %valid)
1869     {
1870         if ($key ne 'noinst'
1871             && $key ne 'check'
1872             && &variable_defined ($key . '_SCRIPTS'))
1873         {
1874             $scripts_installed = 1;
1875             # push (@check_tests, 'check-' . $key . 'SCRIPTS');
1876         }
1877     }
1879     if ($scripts_installed)
1880     {
1881         # If a program is installed, this is required.  We only want this
1882         # error to appear once.
1883         &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
1884             unless $seen_arg_prog;
1885         $seen_arg_prog = 1;
1886     }
1889 # Search a file for a "version.texi" Texinfo include.  Return the name
1890 # of the include file if found, or the empty string if not.  A
1891 # "version.texi" file is actually any file whose name matches
1892 # "vers*.texi".
1893 sub scan_texinfo_file
1895     local ($filename) = @_;
1897     if (! open (TEXI, $filename))
1898     {
1899         &am_error ("couldn't open \`$filename': $!");
1900         return '';
1901     }
1902     print "automake: reading $filename\n" if $verbose;
1904     local ($vfile, $outfile);
1905     while (<TEXI>)
1906     {
1907         if (/^\@setfilename +(\S+)/)
1908         {
1909             $outfile = $1;
1910             last if ($vfile);
1911         }
1913         if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
1914         {
1915             # Found version.texi include.
1916             $vfile = $1;
1917             last if $outfile;
1918         }
1919     }
1921     close (TEXI);
1922     return ($outfile, $vfile);
1925 # Handle all Texinfo source.
1926 sub handle_texinfo
1928     &am_line_error ('TEXINFOS',
1929                     "\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
1930         if &variable_defined ('TEXINFOS');
1931     return if (! &variable_defined ('info_TEXINFOS')
1932                && ! &variable_defined ('html_TEXINFOS'));
1934     local (@texis) = &variable_value_as_list ('info_TEXINFOS', 'all');
1936     local (@info_deps_list, @dvis_list, @texi_deps);
1937     local ($infobase, $info_cursor);
1938     local (%versions);
1939     local ($done) = 0;
1940     local ($vti);
1941     local ($tc_cursor, @texi_cleans);
1942     local ($canonical);
1944     foreach $info_cursor (@texis)
1945     {
1946         ($infobase = $info_cursor) =~ s/\.texi(nfo)?$//;
1948         # If 'version.texi' is referenced by input file, then include
1949         # automatic versioning capability.
1950         local ($out_file, $vtexi) = &scan_texinfo_file ($relative_dir
1951                                                         . "/" . $info_cursor);
1953         if ($out_file eq '')
1954         {
1955             &am_error ("\`$info_cursor' missing \@setfilename");
1956             next;
1957         }
1959         if ($out_file =~ /\.(.+)$/ && $1 ne 'info')
1960         {
1961             # FIXME should report line number in input file.
1962             &am_error ("output of \`$info_cursor', \`$out_file', has unrecognized extension");
1963             next;
1964         }
1966         if ($vtexi)
1967         {
1968             &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
1969                 if (defined $versions{$vtexi});
1970             $versions{$vtexi} = $info_cursor;
1972             # We number the stamp-vti files.  This is doable since the
1973             # actual names don't matter much.  We only number starting
1974             # with the second one, so that the common case looks nice.
1975             $vti = 'vti' . ($done ? $done : '');
1976             &push_dist_common ($vtexi, 'stamp-' . $vti);
1977             push (@clean, $vti);
1979             # Only require once.
1980             &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
1981                                           'mdate-sh')
1982                 if ! $done;
1983             ++$done;
1985             local ($conf_pat);
1986             ($conf_pat = $config_aux_dir) =~ s/(\W)/\\$1/g;
1987             $output_rules .=
1988                 &file_contents_with_transform
1989                     ('s/\@TEXI\@/' . $info_cursor . '/g; '
1990                      . 's/\@VTI\@/' . $vti . '/g; '
1991                      . 's/\@VTEXI\@/' . $vtexi . '/g;'
1992                      . 's,\@MDDIR\@,' . $conf_pat . ',g;',
1993                      'texi-vers');
1995             &push_phony_cleaners ($vti);
1996         }
1998         # If user specified file_TEXINFOS, then use that as explicit
1999         # dependency list.
2000         @texi_deps = ();
2001         push (@texi_deps, $info_cursor);
2002         push (@texi_deps, $vtexi) if $vtexi;
2004         # Canonicalize name first.
2005         ($canonical = $infobase) =~ tr/A-Za-z0-9_/_/c;
2006         if (&variable_defined ($canonical . "_TEXINFOS"))
2007         {
2008             push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
2009             &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
2010         }
2012         $output_rules .= ("\n" . $out_file . ": "
2013                           . join (' ', @texi_deps)
2014                           . "\n" . $infobase . ".dvi: "
2015                           . join (' ', @texi_deps)
2016                           . "\n\n");
2018         push (@info_deps_list, $out_file);
2019         push (@dvis_list, $infobase . '.dvi');
2021         # Generate list of things to clean for this target.  We do
2022         # this explicitly because otherwise too many things could be
2023         # removed.  In particular the ".log" extension might
2024         # reasonably be used in other contexts by the user.
2025         foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns',
2026                             'ky', 'kys', 'ps', 'log', 'pg', 'toc', 'tp', 'tps',
2027                             'vr', 'vrs', 'op', 'tr', 'cv', 'cn')
2028         {
2029             push (@texi_cleans, $infobase . '.' . $tc_cursor);
2030         }
2031     }
2033     # Find these programs wherever they may lie.  Yes, this has
2034     # intimate knowledge of the structure of the texinfo distribution.
2035     &define_program_variable ('MAKEINFO', 'build', 'texinfo/makeinfo',
2036                               'makeinfo',
2037                               # Circumlocution to avoid accidental
2038                               # configure substitution.
2039                               '@MAKE' . 'INFO@');
2040     &define_program_variable ('TEXI2DVI', 'src', 'texinfo/util',
2041                               'texi2dvi');
2043     # Set transform for including texinfos.am.  First, handle --cygnus
2044     # stuff.
2045     local ($xform);
2046     if ($cygnus_mode)
2047     {
2048         $xform = 's/^NOTCYGNUS.*$//; s/^CYGNUS//;';
2049     }
2050     else
2051     {
2052         $xform = 's/^CYGNUS.*$//; s/^NOTCYGNUS//;';
2053     }
2055     # Handle location of texinfo.tex.
2056     local ($need_texi_file) = 0;
2057     if ($cygnus_mode)
2058     {
2059         &define_variable ('TEXINFO_TEX',
2060                           '$(top_srcdir)/../texinfo/texinfo.tex');
2061     }
2062     elsif ($config_aux_dir ne '.' && $config_aux_dir ne '')
2063     {
2064         &define_variable ('TEXINFO_TEX', $config_aux_dir . '/texinfo.tex');
2065     }
2066     elsif (! &variable_defined ('TEXINFO_TEX'))
2067     {
2068         &define_variable ('TEXINFO_TEX', '$(srcdir)/texinfo.tex');
2069     }
2070     else
2071     {
2072         $need_texi_file = 1;
2073     }
2074     local ($xxform) = &dirname (&variable_value ('TEXINFO_TEX'));
2075     $xxform =~ s/(\W)/\\$1/g;
2076     $xform .= ' s/\@TEXINFODIR\@/' . $xxform . '/g;';
2078     $output_rules .= &file_contents_with_transform ($xform, 'texinfos');
2079     push (@phony, 'install-info-am', 'uninstall-info');
2080     push (@dist_targets, 'dist-info');
2082     # How to clean.  The funny name is due to --cygnus influence; in
2083     # Cygnus mode, `clean-info' is a target that users can use.
2084     $output_rules .= "\nmostlyclean-aminfo:\n";
2085     &pretty_print_rule ("\t-rm -f", "\t  ", @texi_cleans);
2086     $output_rules .= ("\nclean-aminfo:\n\ndistclean-aminfo:\n\n"
2087                       . "maintainer-clean-aminfo:\n\t"
2088                       # Eww.  But how else can we find all the output
2089                       # files from makeinfo?
2090                       . 'for i in $(INFO_DEPS); do' . " \\\n"
2091                       . "\t" . '  rm -f $$i;' . " \\\n"
2092                       . "\t" . '  if test "`echo $$i-[0-9]*`" != "$$i-[0-9]*"; then' . " \\\n"
2093                       . "\t" . '    rm -f $$i-[0-9]*;' . " \\\n"
2094                       . "\t" . '  fi;' . " \\\n"
2095                       . "\tdone\n");
2096     &push_phony_cleaners ('aminfo');
2097     if ($cygnus_mode)
2098     {
2099         $output_rules .= "clean-info: mostlyclean-aminfo\n";
2100     }
2102     push (@suffixes, '.texi', '.texinfo', '.info', '.dvi', '.ps');
2104     if (! defined $options{'no-installinfo'})
2105     {
2106         push (@uninstall, 'uninstall-info');
2107         push (@installdirs, '$(infodir)');
2108         unshift (@install_data, 'install-info-am');
2110         # Make sure documentation is made and installed first.  Use
2111         # $(INFO_DEPS), not 'info', because otherwise recursive makes
2112         # get run twice during "make all".
2113         unshift (@all, '$(INFO_DEPS)');
2114     }
2115     push (@clean, 'aminfo');
2116     push (@info, '$(INFO_DEPS)');
2117     push (@dvi, '$(DVIS)');
2119     &define_variable ("INFO_DEPS", join (' ', @info_deps_list));
2120     &define_variable ("DVIS", join (' ', @dvis_list));
2121     # This next isn't strictly needed now -- the places that look here
2122     # could easily be changed to look in info_TEXINFOS.  But this is
2123     # probably better, in case noinst_TEXINFOS is ever supported.
2124     &define_variable ("TEXINFOS", &variable_value ('info_TEXINFOS'));
2126     # Do some error checking.  Note that this file is not required
2127     # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
2128     # up above.
2129     &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex')
2130         if $need_texi_file || ! defined $options{'no-texinfo.tex'};
2133 # Handle any man pages.
2134 sub handle_man_pages
2136     &am_line_error ('MANS', "\`MANS' is an anachronism; use \`man_MANS'")
2137         if &variable_defined ('MANS');
2138     return if ! &variable_defined ('man_MANS');
2140     # We generate the manpage install code by hand to avoid the use of
2141     # basename in the generated Makefile.
2142     local (@mans) = &variable_value_as_list ('man_MANS', 'all');
2143     local (%sections, %inames, %mbases, %secmap, %fullsecmap);
2144     local ($i) = 1;
2145     foreach (@mans)
2146     {
2147         # FIXME: statement without effect:
2148         /^(.*)\.([0-9])([a-z]*)$/;
2149         $sections{$2} = 1;
2150         $inames{$i} = $_;
2151         $mbases{$i} = $1;
2152         $secmap{$i} = $2;
2153         $fullsecmap{$i} = $2 . $3;
2154         $i++;
2155     }
2157     # We don't really need this, but we use it in case we ever want to
2158     # support noinst_MANS.
2159     &define_variable ("MANS", &variable_value ('man_MANS'));
2161     # Generate list of install dirs.
2162     $output_rules .= "install-man: \$(MANS)\n";
2163     $output_rules .= "\t\$(NORMAL_INSTALL)\n";
2164     # Sort keys so that output is deterministic.
2165     foreach (sort keys %sections)
2166     {
2167         push (@installdirs, '$(mandir)/man' . $_)
2168             unless defined $options{'no-installman'};
2169         $output_rules .= ("\t" . '$(mkinstalldirs) $(mandir)/man'
2170                           . $_ . "\n");
2171     }
2172     push (@phony, 'install-man');
2174     # Generate install target.
2175     local ($key);
2176     foreach $key (sort keys %inames)
2177     {
2178         $_ = $install_man_format;
2179         s/\@SECTION\@/$secmap{$key}/g;
2180         s/\@MAN\@/$inames{$key}/g;
2181         s/\@FULLSECT\@/$fullsecmap{$key}/g;
2182         s/\@MANBASE\@/$mbases{$key}/g;
2183         $output_rules .= $_;
2184     }
2185     $output_rules .= "\n";
2187     $output_rules .= "uninstall-man:\n\t\$(NORMAL_UNINSTALL)\n";
2188     foreach $key (sort keys %inames)
2189     {
2190         $_ = $uninstall_man_format;
2191         s/\@SECTION\@/$secmap{$key}/g;
2192         s/\@MAN\@/$inames{$key}/g;
2193         s/\@FULLSECT\@/$fullsecmap{$key}/g;
2194         s/\@MANBASE\@/$mbases{$key}/g;
2195         $output_rules .= $_;
2196     }
2197     $output_rules .= "\n";
2198     push (@phony, 'uninstall-man');
2200     $output_vars .= &file_contents ('mans-vars');
2202     if (! defined $options{'no-installman'})
2203     {
2204         push (@install_data, 'install-man');
2205         push (@uninstall, 'uninstall-man');
2206         push (@all, '$(MANS)');
2207     }
2210 # Handle DATA variables.
2211 sub handle_data
2213     &am_install_var ('data', 'DATA', 'data', 'sysconf',
2214                      'sharedstate', 'localstate', 'pkgdata',
2215                      'noinst', 'check');
2218 # Handle TAGS.
2219 sub handle_tags
2221     push (@phony, 'tags');
2222     local (@tag_deps) = ();
2223     if (&variable_defined ('SUBDIRS'))
2224     {
2225         $output_rules .= ("tags-recursive:\n"
2226                           . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
2227                           # Never fail here if a subdir fails; it
2228                           # isn't important.
2229                           . "\t  (cd \$\$subdir && \$(MAKE) tags); \\\n"
2230                           . "\tdone\n");
2231         push (@tag_deps, 'tags-recursive');
2232         push (@phony, 'tags-recursive');
2233     }
2235     if ($dir_holds_sources
2236         || $dir_holds_headers
2237         || &variable_defined ('ETAGS_ARGS')
2238         || @tag_deps)
2239     {
2240         local ($xform) = '';
2241         local ($one_hdr);
2242         foreach $one_hdr (@config_headers)
2243         {
2244             if ($relative_dir eq &dirname ($one_hdr))
2245             {
2246                 # The config header is in this directory.  So require it.
2247                 local ($var);
2248                 ($var = &basename ($one_hdr)) =~ s/(\W)/\\$1/g;
2249                 $xform .= ' ' if $xform;
2250                 $xform .= $var;
2251             }
2252         }
2253         $xform = ('s/\@CONFIG\@/' . $xform . '/;'
2254                   . 's/\@DIRS\@/' . join (' ', @tag_deps) . '/;');
2256         if (&variable_defined ('SUBDIRS'))
2257         {
2258             $xform .= 's/^SUBDIRS//;';
2259         }
2260         else
2261         {
2262             $xform .= 's/^SUBDIRS.*$//;';
2263         }
2265         $output_rules .= &file_contents_with_transform ($xform, 'tags');
2266         $output_rules .= &file_contents ('tags-clean');
2267         push (@clean, 'tags');
2268         &push_phony_cleaners ('tags');
2269         &examine_variable ('TAGS_DEPENDENCIES');
2270     }
2271     elsif (&variable_defined ('TAGS_DEPENDENCIES'))
2272     {
2273         &am_line_error ('TAGS_DEPENDENCIES',
2274                         "doesn't make sense to define \`TAGS_DEPENDENCIES' without sources or \`ETAGS_ARGS'");
2275     }
2276     else
2277     {
2278         # Every Makefile must define some sort of TAGS rule.
2279         # Otherwise, it would be possible for a top-level "make TAGS"
2280         # to fail because some subdirectory failed.
2281         $output_rules .= "tags: TAGS\nTAGS:\n\n";
2282     }
2285 # Worker for handle_dist.
2286 sub handle_dist_worker
2288     local ($makefile) = @_;
2290     $output_rules .= 'distdir: $(DISTFILES)' . "\n";
2292     # Initialization; only at top level.
2293     if ($relative_dir eq '.')
2294     {
2295         if (defined $options{'check-news'})
2296         {
2297             # For Gnits users, this is pretty handy.  Look at 15 lines
2298             # in case some explanatory text is desirable.
2299             $output_rules .= '  @if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" > /dev/null; then :; else \\
2300           echo "NEWS not updated; not releasing" 1>&2; \\
2301           exit 1; \\
2302         fi
2304         }
2307         # Create dist directory.
2308         $output_rules .= ("\t-rm -rf \$(distdir)\n"
2309                           . "\tmkdir \$(distdir)\n"
2310                           . "\t-chmod 777 \$(distdir)\n");
2311     }
2313     # Only run automake in `dist' target if --include-deps and
2314     # `no-dependencies' not specified.  That way the recipient of a
2315     # distribution can run "make dist" and not need Automake.  You
2316     # might be wondering why we run automake once for each directory
2317     # we distribute, instead of running it once at the top level.  The
2318     # answer is that we want to run automake after the dependencies
2319     # have been generated.  This occurs when "make" is run in the
2320     # subdir.  So automake must be run after make has updated the
2321     # Makefile, which means that it must run once per directory.
2322     if ($use_dependencies)
2323     {
2324         $output_rules .=
2325             (
2326              # There are several directories we need to know about
2327              # when rebuilding the Makefile.ins.  They are:
2328              #   here - The absolute path to our topmost build directory.
2329              #   top_distdir - The absolute path to the top of our dist
2330              #                 hierarchy.
2331              #   distdir - The path to our sub-part of the dist hierarchy.
2332              # If this directory is the topmost directory, we set
2333              # top_distdir from distdir; that lets us pass in distdir
2334              # from an enclosing package.
2335              "\t" . 'here=`cd $(top_builddir) && pwd`; ' . "\\\n"
2336              . "\t" . 'top_distdir=`cd $('
2337              . (($relative_dir eq '.') ? 'distdir' : 'top_distdir')
2338              . ') && pwd`; ' . "\\\n"
2339              . "\t" . 'distdir=`cd $(distdir) && pwd`; ' . "\\\n"
2340              . "\tcd \$(top_srcdir) \\\n"
2341              . "\t  && \$(AUTOMAKE) --include-deps --build-dir=\$\$here --srcdir-name=\$(top_srcdir) --output-dir=\$\$top_distdir "
2342              # Set strictness of output.
2343              . ($cygnus_mode ? '--cygnus' : ('--' . $strictness_name))
2344              . ($cmdline_use_dependencies ? '' : ' --include-deps')
2345              . " " . $makefile . "\n"
2346              );
2347     }
2349     # Scan EXTRA_DIST to see if we need to distribute anything from a
2350     # subdir.  If so, add it to the list.  I didn't want to do this
2351     # originally, but there were so many requests that I finally
2352     # relented.
2353     local (@dist_dirs);
2354     if (&variable_defined ('EXTRA_DIST'))
2355     {
2356         # FIXME: This should be fixed to work with conditionals.  That
2357         # will require only making the entries in @dist_dirs under the
2358         # appropriate condition.  This is meaningful if the nature of
2359         # the distribution should depend upon the configure options
2360         # used.
2361         foreach (&variable_value_as_list ('EXTRA_DIST', ''))
2362         {
2363             next if /^\@.*\@$/;
2364             next unless s,/+[^/]+$,,;
2365             push (@dist_dirs, $_)
2366                 unless $_ eq '.';
2367         }
2368     }
2369     if (@dist_dirs)
2370     {
2371         # Prepend $(distdir) to each directory given.  Doing it via a
2372         # hash lets us ensure that each directory is used only once.
2373         local (%dhash);
2374         grep ($dhash{'$(distdir)/' . $_} = 1, @dist_dirs);
2375         $output_rules .= "\t";
2376         &pretty_print_rule ('$(mkinstalldirs)', "\t   ", sort keys %dhash);
2377     }
2379     # In loop, test for file existence because sometimes a file gets
2380     # included in DISTFILES twice.  For example this happens when a
2381     # single source file is used in building more than one program.
2382     # Also, there are situations in which "ln" can fail.  For instance
2383     # a file to distribute could actually be a cross-filesystem
2384     # symlink -- this can easily happen if "gettextize" was run on the
2385     # distribution.
2386     $output_rules .= "\t\@for file in \$(DISTFILES); do \\\n";
2387     if ($cygnus_mode)
2388     {
2389         $output_rules .= "\t  if test -f \$\$file; then d=.; else d=\$(srcdir); fi; \\\n";
2390     }
2391     else
2392     {
2393         $output_rules .= "\t  d=\$(srcdir); \\\n";
2394     }
2395     $output_rules .= '    test -f $(distdir)/$$file \\
2396           || ln $$d/$$file $(distdir)/$$file 2> /dev/null \\
2397           || cp -p $$d/$$file $(distdir)/$$file; \\
2398         done
2401     # If we have SUBDIRS, create all dist subdirectories and do
2402     # recursive build.
2403     if (&variable_defined ('SUBDIRS'))
2404     {
2405         # If SUBDIRS is conditionally defined, then set DIST_SUBDIRS
2406         # to all possible directories, and use it.
2407         if (! &variable_conditions ('SUBDIRS'))
2408         {
2409             $dist_subdir_name = 'SUBDIRS';
2410         }
2411         else
2412         {
2413             $dist_subdir_name = 'DIST_SUBDIRS';
2414             if (! &variable_defined ('DIST_SUBDIRS'))
2415             {
2416                 &define_pretty_variable ('DIST_SUBDIRS', '',
2417                                          &variable_value_as_list ('SUBDIRS',
2418                                                                   'all'));
2419             }
2420         }
2422         # Test for directory existence here because previous automake
2423         # invocation might have created some directories.  Note that
2424         # we explicitly set distdir for the subdir make; that lets us
2425         # mix-n-match many automake-using packages into one large
2426         # package, and have "dist" at the top level do the right
2427         # thing.  If we're in the topmost directory, then we use
2428         # `distdir' instead of `top_distdir'; this lets us work
2429         # correctly with an enclosing package.
2430         $output_rules .= 
2431             ("\t" . 'for subdir in $(' . $dist_subdir_name . '); do ' . "\\\n"
2432              . "\t" . '  test -d $(distdir)/$$subdir ' . "\\\n"
2433              . "\t" . '  || mkdir $(distdir)/$$subdir ' . "\\\n"
2434              . "\t" . '  || exit 1; ' . "\\\n"
2435              . "\t" . '  chmod 777 $(distdir)/$$subdir; ' . "\\\n"
2436              . "\t" . '  (cd $$subdir && $(MAKE) top_distdir=../$('
2437              . (($relative_dir eq '.') ? 'distdir' : 'top_distdir')
2438              . ') distdir=../$(distdir)/$$subdir distdir) ' . "\\\n"
2439              . "\t" . '    || exit 1; ' . "\\\n"
2440              . "\tdone\n");
2441     }
2443     # If the target `dist-hook' exists, make sure it is run.  This
2444     # allows users to do random weird things to the distribution
2445     # before it is packaged up.
2446     push (@dist_targets, 'dist-hook') if defined $contents{'dist-hook'};
2448     local ($targ);
2449     foreach $targ (@dist_targets)
2450     {
2451         # We must explicitly set distdir and top_distdir for these
2452         # sub-makes.
2453         $output_rules .= "\t\$(MAKE) top_distdir=\"\$(top_distdir)\" distdir=\"\$(distdir)\" $targ\n";
2454     }
2456     push (@phony, 'distdir');
2459 # Handle 'dist' target.
2460 sub handle_dist
2462     local ($makefile) = @_;
2464     # Set up maint_charset.
2465     $local_maint_charset = &variable_value ('MAINT_CHARSET')
2466         if &variable_defined ('MAINT_CHARSET');
2467     $maint_charset = $local_maint_charset
2468         if $relative_dir eq '.';
2470     if (&variable_defined ('DIST_CHARSET'))
2471     {
2472         &am_line_error ('DIST_CHARSET',
2473                         "DIST_CHARSET defined but no MAINT_CHARSET defined")
2474             if ! $local_maint_charset;
2475         if ($relative_dir eq '.')
2476         {
2477             $dist_charset = &variable_value ('DIST_CHARSET')
2478         }
2479         else
2480         {
2481             &am_line_error ('DIST_CHARSET',
2482                             "DIST_CHARSET can only be defined at top level");
2483         }
2484     }
2486     # Look for common files that should be included in distribution.
2487     local ($cfile);
2488     foreach $cfile (@common_files)
2489     {
2490         if (-f ($relative_dir . "/" . $cfile))
2491         {
2492             &push_dist_common ($cfile);
2493         }
2494     }
2496     # Keys of %dist_common are names of files to distributed.  We put
2497     # README first because it then becomes easier to make a
2498     # Usenet-compliant shar file (in these, README must be first).
2499     # FIXME: do more ordering of files here.
2500     local (@coms);
2501     if (defined $dist_common{'README'})
2502     {
2503         push (@coms, 'README');
2504         delete $dist_common{'README'};
2505     }
2506     push (@coms, sort keys %dist_common);
2508     &define_pretty_variable ("DIST_COMMON", '', @coms);
2509     $output_vars .= "\n";
2511     # Some boilerplate.
2512     $output_vars .= &file_contents ('dist-vars') . "\n";
2513     &define_variable ('TAR', $TAR);
2514     &define_variable ('GZIP', '--best');
2516     # Put these things in rules section so it is easier for whoever
2517     # reads Makefile.in.
2518     if (! &variable_defined ('distdir'))
2519     {
2520         if ($relative_dir eq '.')
2521         {
2522             $output_rules .= "\n" . 'distdir = $(PACKAGE)-$(VERSION)' . "\n";
2523         }
2524         else
2525         {
2526             $output_rules .= ("\n"
2527                               . 'distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)'
2528                               . "\n");
2529         }
2530     }
2531     if ($relative_dir eq '.')
2532     {
2533         $output_rules .= "top_distdir = \$(distdir)\n\n";
2534     }
2535     else
2536     {
2537         $output_rules .= "\nsubdir = " . $relative_dir . "\n\n";
2538     }
2540     # Generate 'dist' target, and maybe dist-shar / dist-zip / dist-tarZ.
2541     if ($relative_dir eq '.')
2542     {
2543         # Rule to check whether a distribution is viable.
2544         $output_rules .= ('# This target untars the dist file and tries a VPATH configuration.  Then
2545 # it guarantees that the distribution is self-contained by making another
2546 # tarfile.
2547 distcheck: dist
2548         -rm -rf $(distdir)
2549         GZIP=$(GZIP) $(TAR) zxf $(distdir).tar.gz
2550         mkdir $(distdir)/=build
2551         mkdir $(distdir)/=inst
2552         dc_install_base=`cd $(distdir)/=inst && pwd`; \\'
2553                           . (defined $contents{'distcheck-hook'}
2554                              ? "\t\$(MAKE) distcheck-hook"
2555                              : '')
2556                           . '
2557         cd $(distdir)/=build \\
2558           && ../configure '
2560                           . ($seen_gettext ? '--with-included-gettext ' : '')
2561                           . '--srcdir=.. --prefix=$$dc_install_base \\
2562           && $(MAKE) \\
2563           && $(MAKE) dvi \\
2564           && $(MAKE) check \\
2565           && $(MAKE) install \\
2566           && $(MAKE) installcheck \\
2567           && $(MAKE) dist
2568         -rm -rf $(distdir)
2569         @echo "========================"; \\
2570         echo "$(distdir).tar.gz is ready for distribution"; \\
2571         echo "========================"
2574         local ($dist_all) = ('dist-all: distdir' . "\n"
2575                              . $dist_header);
2576         local ($curs);
2577         foreach $curs ('dist', 'dist-shar', 'dist-zip', 'dist-tarZ')
2578         {
2579             if (defined $options{$curs} || $curs eq 'dist')
2580             {
2581                 $output_rules .= ($curs . ': distdir' . "\n"
2582                                   . $dist_header
2583                                   . $dist{$curs}
2584                                   . $dist_trailer);
2585                 $dist_all .= $dist{$curs};
2586             }
2587         }
2588         $output_rules .= $dist_all . $dist_trailer;
2589     }
2591     # Generate distdir target.
2592     &handle_dist_worker ($makefile);
2595 # Scan a single dependency file and rewrite the dependencies as
2596 # appropriate.  Essentially this means:
2597 # * Clean out absolute dependencies which are not desirable.
2598 # * Rewrite other dependencies to be relative to $(top_srcdir).
2599 sub scan_dependency_file
2601     local ($depfile) = @_;
2603     if (! open (DEP_FILE, $depfile))
2604     {
2605         &am_error ("couldn't open \`$depfile': $!");
2606         return;
2607     }
2608     print "automake: reading $depfile\n" if $verbose;
2610     # Sometimes it is necessary to omit some dependencies.
2611     local (%omit) = %omit_dependencies;
2612     if (&variable_defined ('OMIT_DEPENDENCIES'))
2613     {
2614         # FIXME: Doesn't work with conditionals.  I'm not sure if this
2615         # matters.
2616         grep ($omit{$_} = 1,
2617               &variable_value_as_list ('OMIT_DEPENDENCIES', ''));
2618     }
2620     local ($first_line) = 1;
2621     local ($last_line) = 0;
2622     local ($target, @dependencies);
2623     local ($one_dep, $xform);
2624     local ($just_file);
2626     local ($srcdir_rx, $fixup_rx);
2627     ($fixup_rx = $srcdir_name . '/' . $relative_dir . '/')
2628         =~ s/(\W)/\\$1/g;
2629     ($srcdir_rx = $srcdir_name . '/') =~ s/(\W)/\\$1/g;
2631     local ($rewrite_builddir) = (($top_builddir eq '.')
2632                                  ? ''
2633                                  : $top_builddir . '/');
2635     while (<DEP_FILE>)
2636     {
2637         if ($last_line)
2638         {
2639             # If LAST_LINE set then we've already seen what we thought
2640             # was the last line.
2641             goto bad_format;
2642         }
2643         next if (/$WHITE_PATTERN/o);
2644         chop;
2645         if (! s/\\$//)
2646         {
2647             # No trailing "\" means this should be the last line.
2648             $last_line = 1;
2649         }
2651         if ($first_line)
2652         {
2653             if (! /^([^:]+:)(.+)$/)
2654             {
2655               bad_format:
2656                 &am_error ("\`$depfile' has incorrect format");
2657                 close (DEP_FILE);
2658                 return;
2659             }
2661             $_ = $2;
2662             # Make sure to strip the .P file from the target.
2663             ($target = $1) =~ s, *\.deps/[^.]+\.P,,;
2665             $first_line = 0;
2666         }
2668         foreach $one_dep (split (' ', $_))
2669         {
2670             ($just_file = $one_dep) =~ s,^.*/,,;
2671             next if defined $omit{$just_file};
2673             if ($one_dep =~ /^$fixup_rx/)
2674             {
2675                 # The dependency points to the current directory in
2676                 # some way.
2677                 ($xform = $one_dep) =~ s/^$fixup_rx//;
2678                 push (@dependencies, $xform);
2679             }
2680             elsif ($one_dep =~ /^$srcdir_rx/)
2681             {
2682                 # The dependency is in some other directory in the package.
2683                 ($xform = $one_dep) =~ s/^$srcdir_rx/$rewrite_builddir/;
2684                 push (@dependencies, $xform);
2685             }
2686             elsif ($one_dep =~ /^\//)
2687             {
2688                 # Absolute path; ignore.
2689             }
2690             else
2691             {
2692                 # Anything else is assumed to be correct.
2693                 push (@dependencies, $one_dep);
2694             }
2695         }
2696     }
2698     &pretty_print_rule ($target, "\t", @dependencies);
2700     close (DEP_FILE);
2703 # Handle auto-dependency code.
2704 sub handle_dependencies
2706     # Make sure this variable is always marked as used.
2707     &examine_variable ('OMIT_DEPENDENCIES');
2709     if ($use_dependencies)
2710     {
2711         # Include GNU-make-specific auto-dep code.  Don't include it
2712         # if DEP_FILES would be empty.
2713         if ($dir_holds_sources && keys %dep_files)
2714         {
2715             &define_pretty_variable ('DEP_FILES', '', sort keys %dep_files);
2716             $output_rules .= &file_contents ('depend');
2717             push (@clean, 'depend');
2718             &push_phony_cleaners ('depend');
2719             $output_rules .=
2720                 &file_contents_with_transform ('s/\@EXT\@/.c/g;'
2721                                                . 's/\@MKDEP\@/MKDEP/g;'
2722                                                . 's/^ONLYC//g;',
2723                                                'depend2');
2724             local ($ext);
2725             local ($need_cxx) = 0;
2726             foreach $ext (sort keys %cxx_extensions)
2727             {
2728                 $output_rules .=
2729                     &file_contents_with_transform ('s/\@EXT\@/' . $ext .'/g;'
2730                                                    . 's/\@MKDEP\@/CXXMKDEP/g;'
2731                                                    . 's/^ONLYC.*$//;',
2732                                                    'depend2');
2733                 $need_cxx = 1;
2734             }
2735             if ($need_cxx)
2736             {
2737                 &define_variable ('CXXMKDEP', '$(CXX) -M $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)');
2738             }
2739         }
2740     }
2741     elsif ($build_directory ne '')
2742     {
2743         # Include any auto-generated deps that are present.  Note that
2744         # $build_directory ends in a "/".
2745         if (-d ($build_directory . $relative_dir . "/.deps")
2746             && -f ($build_directory . $relative_dir . "/.deps/.P"))
2747         {
2748             local ($depfile);
2750             foreach $depfile (&my_glob ($build_directory
2751                                         . $relative_dir . "/.deps/*.P"))
2752             {
2753                 &scan_dependency_file ($depfile);
2754             }
2756             $output_rules .= "\n";
2757         }
2758     }
2761 # Handle subdirectories.
2762 sub handle_subdirs
2764     return if ! &variable_defined ('SUBDIRS');
2766     # Make sure each directory mentioned in SUBDIRS actually exists.
2767     local ($dir);
2768     foreach $dir (&variable_value_as_list ('SUBDIRS', 'all'))
2769     {
2770         # Skip directories substituted by configure.
2771         next if $dir =~ /^\@.*\@$/;
2773         if (! -d $am_relative_dir . '/' . $dir)
2774         {
2775             &am_line_error ('SUBDIRS',
2776                             "required directory $am_relative_dir/$dir does not exist");
2777             next;
2778         }
2780         &am_line_error ('SUBDIRS', "directory should not contain \`/'")
2781             if $dir =~ /\//;
2782     }
2784     local ($xform) = ('s/\@INSTALLINFO\@/' .
2785                       (defined $options{'no-installinfo'}
2786                        ? 'install-info-recursive'
2787                        : '')
2788                       . '/;');
2789     $output_rules .= &file_contents_with_transform ($xform, 'subdirs');
2791     # Push a bunch of phony targets.
2792     local ($phonies);
2793     foreach $phonies ('-data', '-exec', 'dirs')
2794     {
2795         push (@phony, 'install' . $phonies . '-recursive');
2796         push (@phony, 'uninstall' . $phonies . '-recursive');
2797     }
2798     foreach $phonies ('all', 'check', 'installcheck', 'info', 'dvi')
2799     {
2800         push (@phony, $phonies . '-recursive');
2801     }
2802     &push_phony_cleaners ('recursive');
2804     push (@check_tests, "check-recursive");
2805     push (@installcheck, "installcheck-recursive");
2806     push (@info, "info-recursive");
2807     push (@dvi, "dvi-recursive");
2809     $recursive_install = 1;
2812 # Handle aclocal.m4.
2813 sub handle_aclocal_m4
2815     local ($regen_aclocal) = 0;
2816     if (-f 'aclocal.m4')
2817     {
2818         &define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4');
2819         &push_dist_common ('aclocal.m4');
2821         if (open (ACLOCAL, '< aclocal.m4'))
2822         {
2823             local ($line);
2824             $line = <ACLOCAL>;
2825             close (ACLOCAL);
2827             if ($line =~ 'generated automatically by aclocal')
2828             {
2829                 $regen_aclocal = 1;
2830             }
2831         }
2832     }
2834     local ($acinclude) = 0;
2835     if (-f 'acinclude.m4')
2836     {
2837         $regen_aclocal = 1;
2838         $acinclude = 1;
2839     }
2841     # Note that it might be possible that aclocal.m4 doesn't exist but
2842     # should be auto-generated.  This case probably isn't very
2843     # important.
2844     if ($regen_aclocal)
2845     {
2846         local (@ac_deps) = (
2847                             ($seen_maint_mode ? "\@MAINT\@" : "") ,
2848                             "configure.in",
2849                             ($acinclude ? ' acinclude.m4' : '')
2850                             );
2852         # Scan all -I directories for m4 files.  These are our
2853         # dependencies.
2854         if (&variable_defined ('ACLOCAL_AMFLAGS'))
2855         {
2856             local ($amdir);
2857             foreach $amdir (&variable_value_as_list ('ACLOCAL_AMFLAGS', ''))
2858             {
2859                 if ($amdir =~ s/^-I//
2860                     && $amdir !~ /^\//
2861                     && -d $amdir)
2862                 {
2863                     push (@ac_deps, &my_glob ($am_dir . '/*.m4'));
2864                 }
2865             }
2866         }
2868         &pretty_print_rule ("\$(ACLOCAL_M4):", "\t\t", @ac_deps);
2870         $output_rules .=  ("\t"
2871                            . 'cd $(srcdir) && $(ACLOCAL)'
2872                            . (&variable_defined ('ACLOCAL_AMFLAGS')
2873                               ? ' $(ACLOCAL_AMFLAGS)' : '')
2874                            . "\n");
2875     }
2878 # Rewrite a list of input files into a form suitable to put on a
2879 # dependency list.  The idea is that if an input file has a directory
2880 # part the same as the current directory, then the directory part is
2881 # simply removed.  But if the directory part is different, then
2882 # $(top_srcdir) is prepended.  Among other things, this is used to
2883 # generate the dependency list for the output files generated by
2884 # AC_OUTPUT.  Consider what the dependencies should look like in this
2885 # case:
2886 #   AC_OUTPUT(src/out:src/in1:lib/in2)
2887 sub rewrite_inputs_into_dependencies
2889     local (@inputs) = @_;
2890     local ($single, @newinputs);
2892     foreach $single (@inputs)
2893     {
2894         if (&dirname ($single) eq $relative_dir)
2895         {
2896             push (@newinputs, &basename ($single));
2897         }
2898         else
2899         {
2900             push (@newinputs, '$(top_srcdir)/' . $single);
2901         }
2902     }
2904     return @newinputs;
2907 # Handle remaking and configure stuff.
2908 # We need the name of the input file, to do proper remaking rules.
2909 sub handle_configure
2911     local ($local, $input, @secondary_inputs) = @_;
2913     # If SUBDIRS defined, require AC_PROG_MAKE_SET.
2914     &am_line_error ('SUBDIRS', "AC_PROG_MAKE_SET must be used in configure.in")
2915         if &variable_defined ('SUBDIRS') && ! $seen_make_set;
2917     local ($top_reldir);
2919     local ($input_base) = &basename ($input);
2920     local ($local_base) = &basename ($local);
2922     local ($amfile) = $input_base . '.am';
2923     # We know we can always add '.in' because it really should be an
2924     # error if the .in was missing originally.
2925     local ($infile) = '$(srcdir)/' . $input_base . '.in';
2926     local ($colon_infile);
2927     if ($local ne $input)
2928     {
2929         $colon_infile = ':' . $input . '.in';
2930     }
2931     $colon_infile .= ':' . join (':', @secondary_inputs)
2932         if @secondary_inputs;
2934     local (@rewritten) = &rewrite_inputs_into_dependencies (@secondary_inputs);
2935     # This rule remakes the Makefile.in.  Note use of @MAINT@ forces
2936     # us to abandon pretty-printing.  Sigh.
2937     $output_rules .= ($infile
2938                       # NOTE perl 5.003 (with -w) gives a
2939                       # uninitialized value error on the next line.
2940                       # Don't know why.
2941                       . ': '
2942                       . ($seen_maint_mode ? '@MAINT@ ' : '')
2943                       . $amfile . ' '
2944                       . '$(top_srcdir)/configure.in $(ACLOCAL_M4) '
2945                       . join (' ', @rewritten) . "\n"
2946                       . "\tcd \$(top_srcdir) && \$(AUTOMAKE) "
2947                       . ($cygnus_mode ? '--cygnus' : ('--' . $strictness_name))
2948                       . ($cmdline_use_dependencies ? '' : ' --include-deps')
2949                       . ' ' . $input . $colon_infile . "\n\n");
2951     # This rule remakes the Makefile.
2952     $output_rules .= ($local_base
2953                       # NOTE: bogus uninit value error on next line;
2954                       # see comment above.
2955                       . ': '
2956                       . $infile . ' '
2957                       . '$(top_builddir)/config.status'
2958                       # NOTE: Makefile only depends on BUILT_SOURCES
2959                       # when dependencies are being computed.  This is
2960                       # a workaround for an obscure bug with
2961                       # AC_LINK_FILES.  Anyway, when dependencies are
2962                       # turned off, this shouldn't matter.
2963                       . ($use_dependencies ? ' $(BUILT_SOURCES)' : '')
2964                       . "\n"
2965                       . "\tcd \$(top_builddir) \\\n"
2966                       . "\t  && CONFIG_FILES="
2967                       . (($relative_dir eq '.') ? '$@' : '$(subdir)/$@')
2968                       . $colon_infile
2969                       . ' CONFIG_HEADERS= $(SHELL) ./config.status'
2970                       . "\n\n");
2972     if ($relative_dir ne '.')
2973     {
2974         # In subdirectory.
2975         $top_reldir = '../';
2976     }
2977     else
2978     {
2979         &handle_aclocal_m4;
2980         $output_rules .= &file_contents ('remake');
2981         &examine_variable ('CONFIGURE_DEPENDENCIES');
2982         $top_reldir = '';
2983     }
2985     # If we have a configure header, require it.
2986     local ($one_hdr);
2987     local (@local_fullnames) = @config_fullnames;
2988     local (@local_names) = @config_names;
2989     local ($hdr_index) = 0;
2990     local ($distclean_config) = '';
2991     foreach $one_hdr (@config_headers)
2992     {
2993         local ($one_fullname) = shift (@local_fullnames);
2994         local ($one_name) = shift (@local_names);
2995         $hdr_index += 1;
2996         if ($relative_dir eq &dirname ($one_hdr))
2997         {
2998             local ($ch_sans_dir) = &basename ($one_hdr);
2999             local ($cn_sans_dir) = &basename ($one_name);
3001             &require_file_with_conf_line ($config_header_line,
3002                                           $FOREIGN, $ch_sans_dir);
3004             # Header defined and in this directory.
3005             local (@files);
3006             if (-f $relative_dir . '/acconfig.h')
3007             {
3008                 push (@files, 'acconfig.h');
3009             }
3010             if (-f $one_name . '.top')
3011             {
3012                 push (@files, "${cn_sans_dir}.top");
3013             }
3014             if (-f $one_name . '.bot')
3015             {
3016                 push (@files, "${cn_sans_dir}.bot");
3017             }
3019             &push_dist_common (@files);
3021             local ($stamp_name) = 'stamp-h';
3022             $stamp_name .= "${hdr_index}" if scalar (@config_headers) > 1;
3024             local ($xform) = '';
3026             $xform = 's,\@FILES\@,' . join (' ', @files) . ',;';
3027             $xform .= 's,\@CONFIG_HEADER\@,' . "${cn_sans_dir}" . ',;';
3028             $xform .= 's,\@CONFIG_HEADER_IN\@,' . "${ch_sans_dir}" . ',;';
3029             $xform .= 's,\@CONFIG_HEADER_FULL\@,' . "${one_fullname}" . ',;';
3030             $xform .= 's,\@STAMP\@,' . "${stamp_name}" . ',;';
3032             $output_rules .= &file_contents_with_transform ($xform,
3033                                                             'remake-hdr');
3035             &touch ($relative_dir . "/${stamp_name}.in");
3036             &require_file_with_conf_line ($config_header_line, $FOREIGN,
3037                                           "${stamp_name}.in");
3039             $distclean_config .= ' ' if $distclean_config;
3040             $distclean_config .= $cn_sans_dir;
3041         }
3042     }
3044     if ($distclean_config)
3045     {
3046         $output_rules .= &file_contents_with_transform ('s,\@FILES\@,'
3047                                                         . $distclean_config
3048                                                         . ',;',
3049                                                         'clean-hdr');
3050         push (@clean, 'hdr');
3051         &push_phony_cleaners ('hdr');
3052     }
3054     # Set location of mkinstalldirs.
3055     if ($config_aux_dir ne '.' && $config_aux_dir ne '')
3056     {
3057         &define_variable ('mkinstalldirs', ('$(SHELL) ' . $config_aux_dir
3058                                             . '/mkinstalldirs'));
3059     }
3060     else
3061     {
3062         &define_variable ('mkinstalldirs',
3063                           '$(SHELL) $(top_srcdir)/mkinstalldirs');
3064     }
3066     &am_line_error ('CONFIG_HEADER',
3067                     "\`CONFIG_HEADER' is an anachronism; now determined from \`configure.in'")
3068         if &variable_defined ('CONFIG_HEADER');
3070     local ($one_name);
3071     local ($config_header) = '';
3072     foreach $one_name (@config_names)
3073     {
3074         # Generate CONFIG_HEADER define.
3075         local ($one_hdr);
3076         if ($relative_dir eq &dirname ($one_name))
3077         {
3078             $one_hdr = &basename ($one_name);
3079         }
3080         else
3081         {
3082             $one_hdr = "${top_builddir}/${one_name}";
3083         }
3085         $config_header .= ' ' if $config_header;
3086         $config_header .= $one_hdr;
3087     }
3088     if ($config_header)
3089     {
3090         &define_variable ("CONFIG_HEADER", $config_header);
3091     }
3093     # Now look for other files in this directory which must be remade
3094     # by config.status, and generate rules for them.
3095     local (@actual_other_files) = ();
3096     local ($file, $local);
3097     local (@inputs, @rewritten_inputs, $single);
3098     local ($need_rewritten);
3099     foreach $file (@other_input_files)
3100     {
3101         if ($file =~ /^(.*):(.*)$/)
3102         {
3103             # This is the ":" syntax of AC_OUTPUT.
3104             $file = $1;
3105             $local = &basename ($file);
3106             @inputs = split (':', $2);
3107             @rewritten_inputs = &rewrite_inputs_into_dependencies (@inputs);
3108             $need_rewritten = 1;
3109         }
3110         else
3111         {
3112             # Normal usage.
3113             $local = &basename ($file);
3114             @inputs = ($local . '.in');
3115             @rewritten_inputs =
3116                 &rewrite_inputs_into_dependencies ($file . '.in');
3117             $need_rewritten = 0;
3118         }
3120         # Skip files not in this directory.
3121         next unless &dirname ($file) eq $relative_dir;
3123         # Skip any file that is an automake input.
3124         next if -f $file . '.am';
3126         # Some users have been tempted to put `stamp-h' in the
3127         # AC_OUTPUT line.  This won't do the right thing, so we
3128         # explicitly fail here.
3129         if ($local eq 'stamp-h')
3130         {
3131             # FIXME: allow real filename.
3132             &am_conf_error ('configure.in', $ac_output_line,
3133                             'stamp-h should not appear in AC_OUTPUT');
3134             next;
3135         }
3137         $output_rules .= ($local . ': '
3138                           . '$(top_builddir)/config.status '
3139                           . join (' ', @rewritten_inputs) . "\n"
3140                           . "\t"
3141                           . 'cd $(top_builddir) && CONFIG_FILES='
3142                           . ($relative_dir eq '.' ? '' : '$(subdir)/')
3143                           . '$@' . ($need_rewritten
3144                                     ? (':' . join (':', @rewritten_inputs))
3145                                     : '')
3146                           . ' CONFIG_HEADERS= ./config.status'
3147                           . "\n");
3148         push (@actual_other_files, $local);
3150         # Require all input files.
3151         &require_file_with_conf_line ($ac_output_line, $FOREIGN,
3152                                       @inputs);
3153     }
3155     # These files get removed by "make clean".
3156     &define_pretty_variable ('CONFIG_CLEAN_FILES', '', @actual_other_files);
3159 # Handle C headers.
3160 sub handle_headers
3162     $dir_holds_headers = &am_install_var ('header', 'HEADERS', 'include',
3163                                           'oldinclude', 'pkginclude',
3164                                           'noinst', 'check');
3167 sub handle_gettext
3169     return if ! $seen_gettext || $relative_dir ne '.';
3171     if (! &variable_defined ('SUBDIRS'))
3172     {
3173         &am_conf_error
3174             ("AM_GNU_GETTEXT in configure.in but SUBDIRS not defined");
3175         return;
3176     }
3178     &require_file_with_conf_line ($ac_gettext_line, $FOREIGN, 'ABOUT-NLS')
3179         if $seen_gettext;
3181     if (&variable_defined ('SUBDIRS'))
3182     {
3183         &am_line_error
3184             ('SUBDIRS',
3185              "AM_GNU_GETTEXT in configure.in but \`po' not in SUBDIRS")
3186                 if $contents{'SUBDIRS'} !~ /\bpo\b/;
3187         &am_line_error
3188             ('SUBDIRS',
3189              "AM_GNU_GETTEXT in configure.in but \`intl' not in SUBDIRS")
3190                 if $contents{'SUBDIRS'} !~ /\bintl\b/;
3191     }
3193     # Ensure that each language in ALL_LINGUAS has a .po file, and
3194     # each po file is mentioned in ALL_LINGUAS.
3195     if ($seen_linguas)
3196     {
3197         local (%linguas) = ();
3198         grep ($linguas{$_} = 1, split (' ', $all_linguas));
3200         foreach (<po/*.po>)
3201         {
3202             s/^po\///;
3203             s/\.po$//;
3205             &am_line_error ($all_linguas_line,
3206                             ("po/$_.po exists but \`$_' not in \`ALL_LINGUAS'"))
3207                 if ! $linguas{$_};
3208         }
3210         foreach (keys %linguas)
3211         {
3212             &am_line_error ($all_linguas_line,
3213                             "$_ in \`ALL_LINGUAS' but po/$_.po does not exist")
3214                 if ! -f "po/$_.po";
3215         }
3216     }
3217     else
3218     {
3219         &am_error ("AM_GNU_GETTEXT in configure.in but \`ALL_LINGUAS' not defined");
3220     }
3223 # Handle footer elements.
3224 sub handle_footer
3226     if ($contents{'SOURCES'})
3227     {
3228         # NOTE don't use define_pretty_variable here, because
3229         # $contents{...} is already defined.
3230         $output_vars .= 'SOURCES = ' . $contents{'SOURCES'} . "\n";
3231     }
3232     if ($contents{'OBJECTS'})
3233     {
3234         # NOTE don't use define_pretty_variable here, because
3235         # $contents{...} is already defined.
3236         $output_vars .= 'OBJECTS = ' . $contents{'OBJECTS'} . "\n";
3237     }
3238     if ($contents{'SOURCES'} || $contents{'OBJECTS'})
3239     {
3240         $output_vars .= "\n";
3241     }
3243     if (&variable_defined ('SUFFIXES'))
3244     {
3245         # Push actual suffixes, and not $(SUFFIXES).  Some versions of
3246         # make do not like variable substitutions on the .SUFFIXES
3247         # line.
3248         push (@suffixes, &variable_value_as_list ('SUFFIXES', ''));
3249     }
3250     if (&target_defined ('.SUFFIXES'))
3251     {
3252         &am_line_error ('.SUFFIXES',
3253                         "use variable \`SUFFIXES', not target \`.SUFFIXES'");
3254     }
3256     # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
3257     # before .SUFFIXES.  So we make sure that .SUFFIXES appears before
3258     # anything else, by sticking it right after the default: target.
3259     $output_header .= ".SUFFIXES:\n";
3260     if (@suffixes)
3261     {
3263         # Make sure suffixes has unique elements.  Sort them to ensure
3264         # the output remains consistent.
3265         local (%suffixes);
3267         grep ($suffixes{$_} = 1, @suffixes);
3269         $output_header .= (".SUFFIXES: "
3270                            . join (' ', sort keys %suffixes)
3271                            . "\n");
3272     }
3273     $output_trailer .= &file_contents ('footer');
3276 # Deal with installdirs target.
3277 sub handle_installdirs
3279     # GNU Makefile standards recommend this.
3280     $output_rules .= ("installdirs:"
3281                       . ($recursive_install
3282                          ? " installdirs-recursive\n"
3283                          : "\n"));
3284     push (@phony, 'installdirs');
3285     if (@installdirs)
3286     {
3287         &pretty_print_rule ("\t" . '$(mkinstalldirs) ', "\t\t",
3288                             @installdirs);
3289     }
3290     $output_rules .= "\n";
3293 # There are several targets which need to be merged.  This is because
3294 # their complete definition is compiled from many parts.  Note that we
3295 # avoid double colon rules, otherwise we'd use them instead.
3296 sub handle_merge_targets
3298     local ($makefile) = @_;
3300     # There are a few install-related variables that you should not define.
3301     local ($var);
3302     foreach $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
3303     {
3304         if (&variable_defined ($var))
3305         {
3306             &am_line_error ($var, "\`$var' should not be defined");
3307         }
3308     }
3310     # Put this at the beginning for the sake of non-GNU makes.  This
3311     # is still wrong if these makes can run parallel jobs.  But it is
3312     # right enough.
3313     unshift (@all, &basename ($makefile));
3315     local ($one_name);
3316     foreach $one_name (@config_names)
3317     {
3318         push (@all, &basename ($one_name))
3319             if &dirname ($one_name) eq $relative_dir;
3320     }
3322     &do_one_merge_target ('info', @info);
3323     &do_one_merge_target ('dvi', @dvi);
3324     &do_check_merge_target;
3325     &do_one_merge_target ('installcheck', @installcheck);
3327     if (defined $options{'no-installinfo'})
3328     {
3329         # FIXME: this is kind of a hack; should find another way to
3330         # know that this is required.
3331         local (@dirs);
3332         if (grep ($_ eq 'install-info-am', @phony))
3333         {
3334             push (@dirs, 'install-info-am');
3335         }
3336         if (&variable_defined ('SUBDIRS'))
3337         {
3338             push (@dirs, 'install-info-recursive');
3339         }
3340         &do_one_merge_target ('install-info', @dirs);
3341     }
3343     # Handle the various install targets specially.  We do this so
3344     # that (eg) "make install-exec" will run "install-exec-recursive"
3345     # if required, but "make install" won't run it twice.  Step one is
3346     # to see if the user specified local versions of any of the
3347     # targets we handle.  "all" is treated as one of these since
3348     # "install" can run it.
3349     push (@install_exec, 'install-exec-local')
3350         if defined $contents{'install-exec-local'};
3351     push (@install_data, 'install-data-local')
3352         if defined $contents{'install-data-local'};
3353     push (@uninstall, 'uninstall-local')
3354         if defined $contents{'uninstall-local'};
3355     local ($utarg);
3356     foreach $utarg ('uninstall-data-local', 'uninstall-data-hook',
3357                     'uninstall-exec-local', 'uninstall-exec-hook')
3358     {
3359         if (defined $contents{$utarg})
3360         {
3361             local ($x);
3362             ($x = $utarg) =~ s/(data|exec)-//;
3363             &am_line_error ($utarg, "use \`$x', not \`$utarg'");
3364         }
3365     }
3366     push (@all, 'all-local')
3367         if defined $contents{'all-local'};
3369     if (defined $contents{'install-local'})
3370     {
3371         &am_line_error ('install-local',
3372                         "use \`install-data' or \`install-exec', not \`install'");
3373     }
3375     # Step two: if we are doing recursive makes, write out the
3376     # appropriate rules.
3377     local (@install);
3378     if ($recursive_install)
3379     {
3380         push (@install, 'install-recursive');
3382         if (@all)
3383         {
3384             local (@hackall) = ();
3385             local ($one_name);
3386             local ($local_headers) = '';
3387             foreach $one_name (@config_names)
3388             {
3389                 if (&dirname ($one_name) eq $relative_dir)
3390                 {
3391                     $local_headers .= ' ' if $local_headers;
3392                     $local_headers .= &basename ($one_name);
3393                 }
3394             }
3395             if ($local_headers)
3396             {
3398                 # This is kind of a hack, but I couldn't see a better
3399                 # way to handle it.  In this particular case, we need
3400                 # to make sure config.h is built before we recurse.
3401                 # We can't do this by changing the order of
3402                 # dependencies to the "all" because that breaks when
3403                 # using parallel makes.  Instead we handle things
3404                 # explicitly.
3405                 $output_rules .= ("all-recursive-am: ${local_headers}"
3406                                   . "\n\t" . '$(MAKE) all-recursive'
3407                                   . "\n\n");
3408                 push (@hackall, 'all-recursive-am');
3409                 push (@phony, 'all-recursive-am');
3410             }
3411             else
3412             {
3413                 push (@hackall, 'all-recursive');
3414             }
3416             $output_rules .= ('all-am: '
3417                               . join (' ', @all)
3418                               . "\n\n");
3419             @all = @hackall;
3420             push (@all, 'all-am');
3421             push (@phony, 'all-am');
3422         }
3423         else
3424         {
3425             @all = ('all-recursive');
3427             # Must always generate `all-am' target, so it can be
3428             # referred to elsewhere.
3429             $output_rules .= "all-am:\n";
3430         }
3431         if (@install_exec)
3432         {
3433             $output_rules .= ('install-exec-am: '
3434                               . join (' ', @install_exec)
3435                               . "\n\n");
3436             @install_exec = ('install-exec-recursive', 'install-exec-am');
3437             push (@install, 'install-exec-am');
3438             push (@phony, 'install-exec-am');
3439         }
3440         else
3441         {
3442             @install_exec = ('install-exec-recursive');
3443         }
3444         if (@install_data)
3445         {
3446             $output_rules .= ('install-data-am: '
3447                               . join (' ', @install_data)
3448                               . "\n\n");
3449             @install_data = ('install-data-recursive', 'install-data-am');
3450             push (@install, 'install-data-am');
3451             push (@phony, 'install-data-am');
3452         }
3453         else
3454         {
3455             @install_data = ('install-data-recursive');
3456         }
3457         if (@uninstall)
3458         {
3459             $output_rules .= ('uninstall-am: '
3460                               . join (' ', @uninstall)
3461                               . "\n\n");
3462             @uninstall = ('uninstall-recursive', 'uninstall-am');
3463             push (@phony, 'uninstall-am');
3464         }
3465         else
3466         {
3467             @uninstall = ('uninstall-recursive');
3468         }
3469     }
3471     # Step three: print definitions users can use.  Code below knows
3472     # that install-exec is done before install-data, beware.
3473     $output_rules .= ("install-exec: "
3474                       . join (' ', @install_exec)
3475                       . "\n");
3476     $output_rules .= "\t\@\$(NORMAL_INSTALL)\n";
3477     if (defined $contents{'install-exec-hook'})
3478     {
3479         $output_rules .= "\t" . '$(MAKE) install-exec-hook' . "\n";
3480     }
3481     $output_rules .= "\n";
3482     push (@install, 'install-exec') if !$recursive_install;
3483     push (@phony, 'install-exec');
3485     $output_rules .= ("install-data: "
3486                       . join (' ', @install_data)
3487                       . "\n");
3488     $output_rules .= "\t\@\$(NORMAL_INSTALL)\n";
3489     if (defined $contents{'install-data-hook'})
3490     {
3491         $output_rules .= "\t" . '$(MAKE) install-data-hook' . "\n";
3492     }
3493     $output_rules .= "\n";
3494     push (@install, 'install-data') if !$recursive_install;
3495     push (@phony, 'install-data');
3497     # If no dependencies for 'install', add 'all'.  Why?  That way
3498     # "make install" at top level of distclean'd distribution won't
3499     # fail because stuff in 'lib' fails to build.
3500     if (! @install || (scalar (@install) == 2
3501                        && $install[0] eq 'install-exec'
3502                        && $install[1] eq 'install-data'))
3503     {
3504         push (@install, 'all');
3505     }
3506     $output_rules .= ('install: '
3507                       . join (' ', @install)
3508                       # Use "@:" as empty command so nothing prints.
3509                       . "\n\t\@:"
3510                       . "\n\n"
3511                       . 'uninstall: '
3512                       . join (' ', @uninstall)
3513                       . "\n\n");
3514     push (@phony, 'install', 'uninstall');
3516     $output_rules .= ('all: '
3517                       . join (' ', @all)
3518                       . "\n\n");
3519     push (@phony, 'all');
3521     # Generate the new 'install-strip' target.  Must set
3522     # INSTALL_SCRIPT to avoid stripping scripts.
3523     $output_rules .= ("install-strip:\n\t"
3524                       . '$(MAKE) INSTALL_PROGRAM=\'$(INSTALL_PROGRAM) -s\' INSTALL_SCRIPT=\'$(INSTALL_PROGRAM)\' install'
3525                       . "\n");
3528 # Helper for handle_merge_targets.
3529 sub do_one_merge_target
3531     local ($name, @values) = @_;
3533     if (defined $contents{$name . '-local'})
3534     {
3535         # User defined local form of target.  So include it.
3536         push (@values, $name . '-local');
3537         push (@phony, $name . '-local');
3538     }
3540     &pretty_print_rule ($name . ":", "\t\t", @values);
3541     push (@phony, $name);
3544 # Handle check merge target specially.
3545 sub do_check_merge_target
3547     if (defined $contents{'check-local'})
3548     {
3549         # User defined local form of target.  So include it.
3550         push (@check_tests, 'check-local');
3551         push (@phony, 'check-local');
3552     }
3554     # In --cygnus mode, check doesn't depend on all.
3555     if (! $cygnus_mode)
3556     {
3557         if (! &variable_defined ('SUBDIRS'))
3558         {
3559             # 'check' must depend on `all', but not when doing
3560             # recursive build.
3561             unshift (@check, 'all');
3562         }
3563         else
3564         {
3565             # When subdirs are used, do the `all' build and then do
3566             # all the recursive stuff.  Actually use `all-am' because
3567             # it doesn't recurse; we rely on the check target in the
3568             # subdirs to do the required builds there.
3569             unshift (@check, 'all-am');
3570         }
3571     }
3573     # The check target must depend on the local equivalent of `all',
3574     # to ensure all the primary targets are built.  Also it must
3575     # depend on the test code named in @check.
3576     &pretty_print_rule ('check:', "\t\t", @check);
3578     # Now the check rules must explicitly run anything named in
3579     # @check_tests.  This is done via a separate make invocation to
3580     # avoid problems with parallel makes.  Every time I write code
3581     # like this I wonder: how could you invent a parallel make and not
3582     # provide any real synchronization facilities?
3583     &pretty_print_rule ("\t\$(MAKE)", "\t  ", @check_tests);
3586 # Handle all 'clean' targets.
3587 sub handle_clean
3589     push (@clean, 'generic');
3590     $output_rules .= &file_contents ('clean');
3591     &push_phony_cleaners ('generic');
3593     local ($target) = $recursive_install ? 'clean-am' : 'clean';
3594     &do_one_clean_target ($target, 'mostly', '', @clean);
3595     &do_one_clean_target ($target, '', 'mostly', @clean);
3596     &do_one_clean_target ($target, 'dist', '', @clean);
3597     &do_one_clean_target ($target, 'maintainer-', 'dist', @clean);
3599     push (@phony, 'clean', 'mostlyclean', 'distclean', 'maintainer-clean');
3601     local (@deps);
3602     if ($recursive_install)
3603     {
3604         # Do -recursive before -am.  If you aren't doing a parallel
3605         # make, this can be nicer.
3606         @deps = ('recursive', 'am');
3607         &do_one_clean_target ('', 'mostly', '', @deps);
3608         &do_one_clean_target ('', '', '', @deps);
3609         &do_one_clean_target ('', 'dist', '', @deps);
3610         &do_one_clean_target ('', 'maintainer-', '', @deps);
3611     }
3614 # Helper for handle_clean.
3615 sub do_one_clean_target
3617     local ($target, $name, $last_name, @deps) = @_;
3619     # Special case: if target not passed, then don't generate
3620     # dependency on next "lower" clean target (eg no
3621     # clean<-mostlyclean derivation).  In this case the target is
3622     # implicitly known to be 'clean'.
3623     local ($flag) = $target;
3624     $target = 'clean' if ! $flag;
3626     grep (($_ = $name . 'clean-' . $_) && 0, @deps);
3627     if ($flag)
3628     {
3629         if ($last_name || $name ne 'mostly')
3630         {
3631             push (@deps, $last_name . $target);
3632         }
3633     }
3635     # If a -local version of the rule is given, add it to the list.
3636     if (defined $contents{$name . $target . '-local'})
3637     {
3638         push (@deps, $name . $target . '-local');
3639     }
3641     # Print the target and the dependencies.
3642     &pretty_print_rule ($name . $target . ": ", "\t\t", @deps);
3644     # FIXME: shouldn't we really print these messages before running
3645     # the dependencies?
3646     if ($name . $target eq 'maintainer-clean')
3647     {
3648         # Print a special warning.
3649         $output_rules .=
3650             ("\t\@echo \"This command is intended for maintainers to use;\"\n"
3651              . "\t\@echo \"it deletes files that may require special "
3652              . "tools to rebuild.\"\n");
3654         $output_rules .= "\t-rm -f config.status\n"
3655             if $relative_dir eq '.';
3656     }
3657     elsif ($name . $target eq 'distclean')
3658     {
3659         $output_rules .= "\t-rm -f config.status\n";
3660         $output_rules .= "\t-rm -f libtool\n" if $seen_libtool;
3661     }
3662     $output_rules .= "\n";
3665 # Handle .PHONY target.
3666 sub handle_phony
3668     &pretty_print_rule ('.PHONY:', "", @phony);
3669     $output_rules .= "\n";
3672 # Handle TESTS variable and other checks.
3673 sub handle_tests
3675     if (defined $options{'dejagnu'})
3676     {
3677         push (@check_tests, 'check-DEJAGNU');
3678         push (@phony, 'check-DEJAGNU');
3680         local ($xform);
3681         if ($cygnus_mode)
3682         {
3683             $xform = 's/^CYGNUS//;';
3684         }
3685         else
3686         {
3687             $xform = 's/^CYGNUS.*$//;';
3688         }
3689         $output_rules .= &file_contents_with_transform ($xform, 'dejagnu');
3691         # In Cygnus mode, these are found in the build tree.
3692         # Otherwise they are looked for in $PATH.
3693         &define_program_variable ('EXPECT', 'build', 'expect', 'expect');
3694         &define_program_variable ('RUNTEST', 'src', 'dejagnu', 'runtest');
3696         # Note that in the rule we don't directly generate site.exp to
3697         # avoid the possibility of a corrupted site.exp if make is
3698         # interrupted.  Jim Meyering has some useful text on this
3699         # topic.
3700         $output_rules .= ("site.exp: Makefile\n"
3701                           . "\t\@echo 'Making a new site.exp file...'\n"
3702                           . "\t-\@rm -f site.bak\n"
3703                           . "\t\@echo '## these variables are automatically generated by make ##' > \$\@-t\n"
3704                           . "\t\@echo '# Do not edit here.  If you wish to override these values' >> \$\@-t\n"
3705                           . "\t\@echo '# edit the last section' >> \$\@-t\n"
3706                           . "\t\@echo 'set tool \$(DEJATOOL)' >> \$\@-t\n"
3707                           . "\t\@echo 'set srcdir \$(srcdir)' >> \$\@-t\n"
3708                           . "\t\@echo 'set objdir' \`pwd\` >> \$\@-t\n");
3710         # Extra stuff for AC_CANONICAL_*
3711         local (@whatlist) = ();
3712         if ($seen_canonical)
3713         {
3714             push (@whatlist, 'host')
3715         }
3717         # Extra stuff only for AC_CANONICAL_SYSTEM.
3718         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
3719         {
3720             push (@whatlist, 'target', 'build');
3721         }
3723         local ($c1, $c2);
3724         foreach $c1 (@whatlist)
3725         {
3726             foreach $c2 ('alias', 'triplet')
3727             {
3728                 $output_rules .= "\t\@echo 'set ${c1}_${c2} \$(${c1}_${c2})' >> \$\@-t\n";
3729             }
3730         }
3732         $output_rules .= ("\t\@echo '## All variables above are generated by configure. Do Not Edit ##' >> \$\@-t\n"
3733                           . "\t-\@sed '1,/^## All variables above are.*##/ d' site.bak >> \$\@-t\n"
3734                           . "\t-\@mv site.exp site.bak\n"
3735                           . "\t\@mv \$\@-t site.exp\n");
3736     }
3737     else
3738     {
3739         local ($c);
3740         foreach $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
3741         {
3742             if (&variable_defined ($c))
3743             {
3744                 &am_line_error ($c, "\`$c' defined but \`dejagnu' not in \`AUTOMAKE_OPTIONS'");
3745             }
3746         }
3747     }
3749     if (&variable_defined ('TESTS'))
3750     {
3751         push (@check_tests, 'check-TESTS');
3752         push (@phony, 'check-TESTS');
3754         $output_rules .= 'check-TESTS: $(TESTS)
3755         @failed=0; all=0; \\
3756         srcdir=$(srcdir); export srcdir; \\
3757         for tst in $(TESTS); do \\
3758           if test -f $$tst; then dir=.; \\
3759           else dir="$(srcdir)"; fi; \\
3760           if $(TESTS_ENVIRONMENT) $$dir/$$tst; then \\
3761             all=`expr $$all + 1`; \\
3762             echo "PASS: $$tst"; \\
3763           elif test $$? -ne 77; then \\
3764             all=`expr $$all + 1`; \\
3765             failed=`expr $$failed + 1`; \\
3766             echo "FAIL: $$tst"; \\
3767           fi; \\
3768         done; \\
3769         if test "$$failed" -eq 0; then \\
3770           banner="All $$all tests passed"; \\
3771         else \\
3772           banner="$$failed of $$all tests failed"; \\
3773         fi; \\
3774         dashes=`echo "$$banner" | sed s/./=/g`; \\
3775         echo "$$dashes"; \\
3776         echo "$$banner"; \\
3777         echo "$$dashes"; \\
3778         test "$$failed" -eq 0
3780     }
3783 # Handle Emacs Lisp.
3784 sub handle_emacs_lisp
3786     local (@elfiles) = &am_install_var ('lisp', 'LISP', 'lisp', 'noinst');
3788     if (@elfiles)
3789     {
3790         # Found some lisp.
3791         &define_configure_variable ('lispdir');
3792         &define_configure_variable ('EMACS');
3793         $output_rules .= (".el.elc:\n"
3794                           . "\t\@echo 'WARNING: Warnings can be ignored. :-)'\n"
3795                           . "\tif test \$(EMACS) != no; then \\\n"
3796                           . "\t  EMACS=\$(EMACS) \$(SHELL) \$(srcdir)/elisp-comp \$<; \\\n"
3797                           . "\tfi\n");
3798         push (@suffixes, '.el', '.elc');
3800         # Generate .elc files.
3801         grep ($_ .= 'c', @elfiles);
3802         &define_pretty_variable ('ELCFILES', '', @elfiles);
3804         $output_rules .= &file_contents ('lisp-clean');
3805         push (@clean, 'lisp');
3806         &push_phony_cleaners ('lisp');
3808         push (@all, '$(ELCFILES)');
3810         local ($varname);
3811         if (&variable_defined ('lisp_LISP'))
3812         {
3813             $varname = 'lisp_LISP';
3814             &am_error ("\`lisp_LISP' defined but \`AM_PATH_LISPDIR' not in \`configure.in'")
3815                 if ! $seen_lispdir;
3816         }
3817         else
3818         {
3819             $varname = 'noinst_LISP';
3820         }
3822         &require_file_with_line ($varname, $FOREIGN, 'elisp-comp');
3823     }
3826 # Handle some of the minor options.
3827 sub handle_minor_options
3829     if (defined $options{'readme-alpha'})
3830     {
3831         if ($relative_dir eq '.')
3832         {
3833             if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
3834             {
3835                 # FIXME: allow real filename.
3836                 &am_conf_line_error ('configure.in',
3837                                      $package_version_line,
3838                                      "version \`$package_version' doesn't follow Gnits standards");
3839             }
3840             elsif (defined $1 && -f 'README-alpha')
3841             {
3842                 # This means we have an alpha release.  See
3843                 # GNITS_VERSION_PATTERN for details.
3844                 &require_file ($FOREIGN, 'README-alpha');
3845             }
3846         }
3847     }
3850 ################################################################
3852 # Scan one file for interesting things.  Subroutine of scan_configure.
3853 sub scan_one_configure_file
3855     local ($filename) = @_;
3857     open (CONFIGURE, $filename)
3858         || die "automake: couldn't open \`$filename': $!\n";
3859     print "automake: reading $filename\n" if $verbose;
3861     while (<CONFIGURE>)
3862     {
3863         # Remove comments from current line.
3864         s/\bdnl\b.*$//;
3865         s/\#.*$//;
3867         # Skip macro definitions.  Otherwise we might be confused into
3868         # thinking that a macro that was only defined was actually
3869         # used.
3870         next if /AC_DEFUN/;
3872         # Populate libobjs array.
3873         if (/AC_FUNC_ALLOCA/)
3874         {
3875             $libsources{'alloca.c'} = 1;
3876         }
3877         elsif (/AC_FUNC_GETLOADAVG/)
3878         {
3879             $libsources{'getloadavg.c'} = 1;
3880         }
3881         elsif (/AC_FUNC_MEMCMP/)
3882         {
3883             $libsources{'memcmp.c'} = 1;
3884         }
3885         elsif (/AC_STRUCT_ST_BLOCKS/)
3886         {
3887             $libsources{'fileblocks.c'} = 1;
3888         }
3889         elsif (/A[CM]_REPLACE_GNU_GETOPT/)
3890         {
3891             $libsources{'getopt.c'} = 1;
3892             $libsources{'getopt1.c'} = 1;
3893         }
3894         elsif (/AM_FUNC_STRTOD/)
3895         {
3896             $libsources{'strtod.c'} = 1;
3897         }
3898         elsif (/AM_WITH_REGEX/)
3899         {
3900             $libsources{'rx.c'} = 1;
3901             $libsources{'rx.h'} = 1;
3902             $libsources{'regex.c'} = 1;
3903             $libsources{'regex.h'} = 1;
3904             $omit_dependencies{'rx.h'} = 1;
3905             $omit_dependencies{'regex.h'} = 1;
3906         }
3907         elsif (/AM_FUNC_MKTIME/)
3908         {
3909             $libsources{'mktime.c'} = 1;
3910         }
3911         elsif (/AM_FUNC_ERROR_AT_LINE/)
3912         {
3913             $libsources{'error.c'} = 1;
3914             $libsources{'error.h'} = 1;
3915         }
3916         elsif (/AM_FUNC_OBSTACK/)
3917         {
3918             $libsources{'obstack.c'} = 1;
3919             $libsources{'obstack.h'} = 1;
3920         }
3921         elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
3922                || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
3923         {
3924             foreach $libobj_iter (split (' ', $1))
3925             {
3926                 if ($libobj_iter =~ /^(.*)\.o$/)
3927                 {
3928                     $libsources{$1 . '.c'} = 1;
3929                 }
3930             }
3931         }
3933         if (! $in_ac_replace && s/AC_REPLACE_FUNCS\s*\(\[?//)
3934         {
3935             $in_ac_replace = 1;
3936         }
3937         if ($in_ac_replace)
3938         {
3939             $in_ac_replace = 0 if s/[\]\)].*$//;
3940             # Remove trailing backslash.
3941             s/\\$//;
3942             foreach (split)
3943             {
3944                 # Need to skip empty elements for Perl 4.
3945                 next if $_ eq '';
3946                 $libsources{$_ . '.c'} = 1;
3947             }
3948         }
3950         if (/$obsolete_rx/o)
3951         {
3952             local ($hint) = '';
3953             if ($obsolete_macros{$1})
3954             {
3955                 $hint = '; ' . $obsolete_macros{$1};
3956             }
3957             &am_conf_line_error ($filename, $., "\`$1' is obsolete$hint");
3958         }
3960         # Process the AC_OUTPUT macro.
3961         if (! $in_ac_output && s/AC_OUTPUT\s*\(\[?//)
3962         {
3963             $in_ac_output = 1;
3964             $ac_output_line = $.;
3965         }
3966         if ($in_ac_output)
3967         {
3968             local ($closing) = 0;
3969             if (s/[\]\),].*$//)
3970             {
3971                 $in_ac_output = 0;
3972                 $closing = 1;
3973             }
3975             # Look at potential Makefile.am's.
3976             foreach (split)
3977             {
3978                 next if $_ eq "\\";
3980                 # Handle $local:$input syntax.  Note that we ignore
3981                 # every input file past the first, though we keep
3982                 # those around for later.
3983                 local ($local, $input, @rest) = split (/:/);
3984                 if (! $input)
3985                 {
3986                     $input = $local;
3987                 }
3988                 else
3989                 {
3990                     # FIXME: should be error if .in is missing.
3991                     $input =~ s/\.in$//;
3992                 }
3994                 if (-f $input . '.am')
3995                 {
3996                     # We have a file that automake should generate.
3997                     push (@make_input_list, $input);
3998                     $make_list{$input} = join (':', ($local, @rest));
3999                 }
4000                 else
4001                 {
4002                     # We have a file that automake should cause to be
4003                     # rebuilt, but shouldn't generate itself.
4004                     push (@other_input_files, $_);
4005                 }
4006             }
4008             if ($closing && @make_input_list == 0 && @other_input_files == 0)
4009             {
4010                 &am_conf_line_error ($filename, $ac_output_line,
4011                                      "No files mentioned in \`AC_OUTPUT'");
4012                 exit 1;
4013             }
4014         }
4016         if (/$AC_CONFIG_AUX_DIR_PATTERN/o)
4017         {
4018             @config_aux_path = $1;
4019         }
4021         # Check for ansi2knr.
4022         $am_c_prototypes = 1 if /AM_C_PROTOTYPES/;
4024         # Check for exe extension stuff.
4025         if (/AM_EXEEXT/)
4026         {
4027             $seen_exeext = 1;
4028             $configure_vars{'EXEEXT'} = 1;
4029         }
4031         # Check for NLS support.
4032         if (/AM_GNU_GETTEXT/)
4033         {
4034             $seen_gettext = 1;
4035             $ac_gettext_line = $.;
4036             $omit_dependencies{'libintl.h'} = 1;
4037         }
4039         # Look for ALL_LINGUAS.
4040         if (/ALL_LINGUAS="(.*)"$/ || /ALL_LINGUAS=(.*)$/)
4041         {
4042             $seen_linguas = 1;
4043             $all_linguas = $1;
4044             $all_linguas_line = $.;
4045         }
4047         # Handle configuration headers.  A config header of `[$1]'
4048         # means we are actually scanning AM_CONFIG_HEADER from
4049         # aclocal.m4.
4050         if (/A([CM])_CONFIG_HEADER\s*\((.*)\)/
4051             && $2 ne '[$1]')
4052         {
4053             &am_conf_line_error
4054                 ($filename, $.,
4055                  "\`AC_CONFIG_HEADER' is obsolete; use \`AM_CONFIG_HEADER'")
4056                     if $1 eq 'C';
4058             $config_header_line = $.;
4059             local ($one_hdr);
4060             foreach $one_hdr (split (' ', $2))
4061             {
4062                 push (@config_fullnames, $one_hdr);
4063                 if ($one_hdr =~ /^([^:]+):(.+)$/)
4064                 {
4065                     push (@config_names, $1);
4066                     push (@config_headers, $2);
4067                 }
4068                 else
4069                 {
4070                     push (@config_names, $one_hdr);
4071                     push (@config_headers, $one_hdr . '.in');
4072                 }
4073             }
4074         }
4076         # Handle AC_CANONICAL_*.  Always allow upgrading to
4077         # AC_CANONICAL_SYSTEM, but never downgrading.
4078         $seen_canonical = $AC_CANONICAL_HOST
4079             if ! $seen_canonical
4080                 && (/AC_CANONICAL_HOST/ || /AC_CHECK_TOOL/);
4081         $seen_canonical = $AC_CANONICAL_SYSTEM if /AC_CANONICAL_SYSTEM/;
4083         $seen_path_xtra = 1 if /AC_PATH_XTRA/;
4085         # This macro handles several different things.
4086         if (/$AM_INIT_AUTOMAKE_PATTERN/o)
4087         {
4088             $seen_make_set = 1;
4089             $seen_package = 1;
4090             $seen_version = 1;
4091             $seen_arg_prog = 1;
4092             $seen_prog_install = 2;
4093             ($package_version = $1) =~ s/$AM_PACKAGE_VERSION_PATTERN/$1/o;
4094             $package_version_line = $.;
4095         }
4097         # This is like AM_INIT_AUTOMAKE, but doesn't actually set the
4098         # package and version number.  (This might change in the
4099         # future).  Yes, I'm not above hacking Automake so it works
4100         # well with other GNU tools -- that is actually the point.
4101         if (/AM_INIT_GUILE_MODULE/)
4102         {
4103             $seen_make_set = 1;
4104             $seen_package = 1;
4105             $seen_version = 1;
4106             $seen_arg_prog = 1;
4107             $seen_prog_install = 2;
4108             @config_aux_path = ('..');
4109         }
4111         # Some things required by Automake.
4112         $seen_make_set = 1 if /AC_PROG_MAKE_SET/;
4113         $seen_arg_prog = 1 if /AC_ARG_PROGRAM/;
4115         if (/AC_PROG_(YACC|RANLIB|CC|CXX|LEX|AWK|CPP|CXXCPP|LN_S)/)
4116         {
4117             $configure_vars{$1} = 1;
4118         }
4119         if (/$AC_CHECK_PATTERN/o)
4120         {
4121             $configure_vars{$3} = 1;
4122         }
4123         if (/$AM_MISSING_PATTERN/o
4124             && $1 ne 'ACLOCAL'
4125             && $1 ne 'AUTOCONF'
4126             && $1 ne 'AUTOMAKE'
4127             && $1 ne 'AUTOHEADER')
4128         {
4129             $configure_vars{$1} = 1;
4130         }
4132         # Explicitly avoid ANSI2KNR -- we AC_SUBST that in protos.m4,
4133         # but later define it elsewhere.  This is pretty hacky.  We
4134         # also explicitly avoid INSTALL_SCRIPT and some other
4135         # variables because they are defined in header-vars.am.
4136         # FIXME.
4137         if (/$AC_SUBST_PATTERN/o
4138             && $1 ne 'ANSI2KNR'
4139             && $1 ne 'INSTALL_SCRIPT')
4140         {
4141             $configure_vars{$1} = 1;
4142         }
4144         $seen_decl_yytext = 1 if /AC_DECL_YYTEXT/;
4145         $seen_maint_mode = 1 if /AM_MAINTAINER_MODE/;
4146         $seen_package = 1 if /PACKAGE=/;
4148         # Skip VERSION of [$2]; that is from AM_INIT_AUTOMAKE.
4149         if (/\bVERSION=(\S+)/ && $1 ne '[$2]')
4150         {
4151             $seen_version = 1;
4152             $package_version = $1;
4153             $package_version_line = $.;
4154         }
4155         elsif (/VERSION=/)
4156         {
4157             $seen_version = 1;
4158         }
4160         # Weird conditionals here because it is always allowed to
4161         # upgrade to AM_PROG_INSTALL but never to downgrade to
4162         # AC_PROG_INSTALL.
4163         $seen_prog_install = 1 if ! $seen_prog_install && /AC_PROG_INSTALL/;
4164         $seen_prog_install = 2 if /AM_PROG_INSTALL/;
4166         $seen_lispdir = 1 if /AM_PATH_LISPDIR/;
4168         if (/AM_PROG_LIBTOOL/)
4169         {
4170             $seen_libtool = 1;
4171             $libtool_line = $.;
4172             $configure_vars{'LIBTOOL'} = 1;
4173             $configure_vars{'RANLIB'} = 1;
4174             $configure_vars{'CC'} = 1;
4175             # AM_PROG_LIBTOOL runs AC_CANONICAL_HOST.  Make sure we
4176             # never downgrade (if we've seen AC_CANONICAL_SYSTEM).
4177             $seen_canonical = $AC_CANONICAL_HOST if ! $seen_canonical;
4178         }
4180         if (/$AM_CONDITIONAL_PATTERN/o)
4181         {
4182             $configure_cond{$1} = 1;
4183         }
4184     }
4186     close (CONFIGURE);
4189 # Scan configure.in and aclocal.m4 for interesting things.  We must
4190 # scan aclocal.m4 because there might be AC_SUBSTs and such there.
4191 sub scan_configure
4193     # Reinitialize libsources here.  This isn't really necessary,
4194     # since we currently assume there is only one configure.in.  But
4195     # that won't always be the case.
4196     %libsources = ();
4198     local ($in_ac_output, $in_ac_replace) = (0, 0);
4199     local (%make_list, @make_input_list);
4200     local ($libobj_iter);
4202     &scan_one_configure_file ('configure.in');
4203     &scan_one_configure_file ('aclocal.m4')
4204         if -f 'aclocal.m4';
4206     # Set input and output files if not specified by user.
4207     if (! @input_files)
4208     {
4209         @input_files = @make_input_list;
4210         %output_files = %make_list;
4211     }
4213     &am_conf_error ("\`PACKAGE' not defined in configure.in")
4214         if ! $seen_package;
4215     &am_conf_error ("\`VERSION' not defined in configure.in")
4216         if ! $seen_version;
4218     # Look for some files we need.  Always check for these.  This
4219     # check must be done for every run, even those where we are only
4220     # looking at a subdir Makefile.  We must set relative_dir so that
4221     # the file-finding machinery works.
4222     local ($relative_dir) = '.';
4223     &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs', 'missing');
4224     &am_error ("\`install.sh' is an anachronism; use \`install-sh' instead")
4225         if -f $config_aux_path[0] . '/install.sh';
4228 ################################################################
4230 # Set up for Cygnus mode.
4231 sub check_cygnus
4233     return unless $cygnus_mode;
4235     &set_strictness ('foreign');
4236     $options{'no-installinfo'} = 1;
4237     $options{'no-dependencies'} = 1;
4238     $use_dependencies = 0;
4240     if (! $seen_maint_mode)
4241     {
4242         &am_conf_error ("\`AM_MAINTAINER_MODE' required when --cygnus specified");
4243     }
4245     if (! $seen_exeext)
4246     {
4247         &am_conf_error ("\`AM_EXEEXT' required when --cygnus specified");
4248     }
4251 # Do any extra checking for GNU standards.
4252 sub check_gnu_standards
4254     if ($relative_dir eq '.')
4255     {
4256         # In top level (or only) directory.
4257         &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
4258                        'AUTHORS', 'ChangeLog');
4259     }
4261     if ($strictness >= $GNU)
4262     {
4263         if (defined $options{'no-installman'})
4264         {
4265             &am_line_error ('AUTOMAKE_OPTIONS',
4266                             "option \`no-installman' disallowed by GNU standards");
4267         }
4269         if (defined $options{'no-installinfo'})
4270         {
4271             &am_line_error ('AUTOMAKE_OPTIONS',
4272                             "option \`no-installinfo' disallowed by GNU standards");
4273         }
4274     }
4277 # Do any extra checking for GNITS standards.
4278 sub check_gnits_standards
4280     if ($strictness >= $GNITS)
4281     {
4282         if (-f $relative_dir . '/COPYING.LIB')
4283         {
4284             &am_error ("\`${relative_dir}/COPYING.LIB' disallowed by Gnits standards");
4285         }
4286     }
4288     if ($relative_dir eq '.')
4289     {
4290         # In top level (or only) directory.
4291         &require_file ($GNITS, 'THANKS');
4292     }
4295 ################################################################
4297 # Pretty-print something.  HEAD is what should be printed at the
4298 # beginning of the first line, FILL is what should be printed at the
4299 # beginning of every subsequent line.
4300 sub pretty_print_internal
4302     local ($head, $fill, @values) = @_;
4304     local ($column) = length ($head);
4305     local ($result) = $head;
4307     # Fill length is number of characters.  However, each Tab
4308     # character counts for eight.  So we count the number of Tabs and
4309     # multiply by 7.
4310     local ($fill_length) = length ($fill);
4311     $fill_length += 7 * ($fill =~ tr/\t/\t/d);
4313     local ($bol) = ($head eq '');
4314     foreach (@values)
4315     {
4316         # "71" because we also print a space.
4317         if ($column + length ($_) > 71)
4318         {
4319             $result .= " \\\n" . $fill;
4320             $column = $fill_length;
4321             $bol = 1;
4322         }
4324         $result .= ' ' unless ($bol);
4325         $result .= $_;
4326         $column += length ($_) + 1;
4327         $bol = 0;
4328     }
4330     $result .= "\n";
4331     return $result;
4334 # Pretty-print something and append to output_vars.
4335 sub pretty_print
4337     $output_vars .= &pretty_print_internal (@_);
4340 # Pretty-print something and append to output_rules.
4341 sub pretty_print_rule
4343     $output_rules .= &pretty_print_internal (@_);
4347 ################################################################
4349 # See if a target exists.
4350 sub target_defined
4352     local ($target) = @_;
4353     return defined $targets{$target};
4356 # See if two conditionals are the same.
4357 sub conditional_same
4359     local ($cond1, $cond2) = @_;
4361     return (&conditional_true_when ($cond1, $cond2)
4362             && &conditional_true_when ($cond2, $cond1));
4365 # See if a conditional is true.  Both arguments are conditional
4366 # strings.  This returns true if the first conditional is true when
4367 # the second conditional is true.
4368 sub conditional_true_when
4370     local ($cond, $when) = @_;
4372     # Check the easy case first.
4373     if ($cond eq $when)
4374     {
4375         return 1;
4376     }
4378     # Check each component of $cond, which looks @COND1@@COND2@.
4379     foreach $comp (split ('@', $cond))
4380     {
4381         # The way we split will give null strings between each
4382         # condition.
4383         next if ! $comp;
4385         if (index ($when, '@' . $comp . '@') == -1)
4386         {
4387             return 0;
4388         }
4389     }
4391     return 1;
4394 # Check for an ambiguous conditional.  This is called when a variable
4395 # or target is being defined conditionally.  If we already know about
4396 # a definition that is true under the same conditions, then we have an
4397 # ambiguity.
4398 sub check_ambiguous_conditional
4400     local ($var_name, $cond) = @_;
4401     local (@cond_vals) = split (' ', $conditional{$var_name});
4402     while (@cond_vals)
4403     {
4404         local ($vcond) = shift (@cond_vals);
4405         shift (@cond_vals);
4406         if (&conditional_true_when ($vcond, $cond)
4407             || &conditional_true_when ($cond, $vcond))
4408         {
4409             &am_line_error ($var_name,
4410                             "$var_name multiply defined in condition");
4411         }
4412     }
4415 # See if a variable exists.  The first argument is the variable name,
4416 # and the optional second argument is the condition which we should
4417 # check.  If no condition is given, we currently return true if the
4418 # variable is defined under any condition.
4419 sub variable_defined
4421     local ($var, $cond) = @_;
4422     if (defined $targets{$var})
4423     {
4424         &am_line_error ($var, "\`$var' is target; expected variable");
4425         return 0;
4426     }
4427     elsif (defined $contents{$var})
4428     {
4429         if ($cond && $conditional{$var})
4430         {
4431             # We have been asked to check for a particular condition,
4432             # and the variable is defined conditionally.  We need to
4433             # look through the conditions under which the variable is
4434             # defined, and see if any of them match the conditional we
4435             # have been asked to check.
4436             local (@cond_vars) = split (' ', $conditional{$var});
4437             while (@cond_vars)
4438             {
4439                 if (&conditional_same ($cond, shift (@cond_vars)))
4440                 {
4441                     # Even a conditional examination is good enough
4442                     # for us.  FIXME: really should maintain examined
4443                     # status on a per-condition basis.
4444                     $content_seen{$var} = 1;
4445                     return 1;
4446                 }
4447                 shift (@cond_vars);
4448             }
4450             # The variable is not defined for the given condition.
4451             return 0;
4452         }
4454         $content_seen{$var} = 1;
4455         return 1;
4456     }
4457     return 0;
4460 # Mark a variable as examined.
4461 sub examine_variable
4463     local ($var) = @_;
4464     &variable_defined ($var);
4467 # Quote a value in order to put it in $conditional.  We need to quote
4468 # spaces, and we need to handle null strings, so that we can later
4469 # retrieve values by splitting on space.
4470 sub quote_cond_val
4472     local ($val) = @_;
4473     $val =~ s/ /\001/g;
4474     $val = '\002' if $val eq '';
4475     return $val;
4478 # Unquote a value in $conditional.
4479 sub unquote_cond_val
4481     local ($val) = @_;
4482     $val =~ s/\001/ /g;
4483     $val = '' if $val eq '\002';
4484     return $val;
4487 # Return the set of conditions for which a variable is defined.
4489 # If the variable is not defined conditionally, and is not defined in
4490 # terms of any variables which are defined conditionally, then this
4491 # returns the empty list.
4493 # If the variable is defined conditionally, but is not defined in
4494 # terms of any variables which are defined conditionally, then this
4495 # returns the list of conditions for which the variable is defined.
4497 # If the variable is defined in terms of any variables which are
4498 # defined conditionally, then this returns a full set of permutations
4499 # of the subvariable conditions.  For example, if the variable is
4500 # defined in terms of a variable which is defined for @COND_TRUE@,
4501 # then this returns both @COND_TRUE@ and @COND_FALSE@.  This is
4502 # because we will need to define the variable under both conditions.
4504 sub variable_conditions
4506     local ($var) = @_;
4507     local (%uniqify);
4508     local ($cond);
4510     foreach $cond (&variable_conditions_sub ($var, '', ()))
4511     {
4512         $uniqify{$cond} = 1;
4513     }
4515     return keys %uniqify;
4518 # A subroutine of variable_conditions.  We only return conditions
4519 # which are true for all the conditions in @PARENT_CONDS.
4520 sub variable_conditions_sub
4522     local ($var, $parent, @parent_conds) = @_;
4523     local (@new_conds) = ();
4525     if (! $conditional{$var})
4526     {
4527         foreach (split (' ', $contents{$var}))
4528         {
4529             # If a comment seen, just leave.
4530             last if /^#/;
4532             # Handle variable substitutions.
4533             if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
4534             {
4535                 push (@new_conds,
4536                       &variable_conditions_sub ($1, $var, @parent_conds));
4537             }
4538         }
4540         return &variable_conditions_reduce (@new_conds);
4541     }
4543     local (@this_conds) = ();
4544     local (@condvals) = split (' ', $conditional{$var});
4545     while (@condvals)
4546     {
4547         local ($cond) = shift (@condvals);
4548         local ($val) = &unquote_cond_val (shift (@condvals));
4550         if (@parent_conds)
4551         {
4552             local ($ok) = 1;
4553             local ($parent_cond);
4554             foreach $parent_cond (@parent_conds)
4555             {
4556                 if (! &conditional_true_when ($parent_cond, $cond))
4557                 {
4558                     $ok = 0;
4559                     last;
4560                 }
4561             }
4563             next if ! $ok;
4564         }
4566         push (@this_conds, $cond);
4568         push (@parent_conds, $cond);
4569         local (@subvar_conds) = ();
4570         foreach (split (' ', $val))
4571         {
4572             # If a comment seen, just leave.
4573             last if /^#/;
4575             # Handle variable substitutions.
4576             if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
4577             {
4578                 push (@subvar_conds,
4579                       &variable_conditions_sub ($1, $var, @parent_conds));
4580             }
4581         }
4582         pop (@parent_conds);
4584         # If there are no conditional subvariables, then we want to
4585         # return this condition.  Otherwise, we want to return the
4586         # permutations of the subvariables.
4587         if (! @subvar_conds)
4588         {
4589             push (@new_conds, $cond);
4590         }
4591         else
4592         {
4593             push (@new_conds, &variable_conditions_reduce (@subvar_conds));
4594         }
4595     }
4597     return @new_conds
4598         if ! $parent;
4600     # If we are being called on behalf of another variable, we need to
4601     # return all possible permutations of the conditions.  We have
4602     # already handled everything in @this_conds along with their
4603     # subvariables.  We now need to add any permutations that are not
4604     # in @this_conds.
4605     local ($this_cond);
4606     foreach $this_cond (@this_conds)
4607     {
4608         local (@perms) =
4609             &variable_conditions_permutations (split('@', $this_cond));
4610         local ($perm);
4611         foreach $perm (@perms)
4612         {
4613             local ($scan);
4614             local ($ok) = 1;
4615             foreach $scan (@this_conds)
4616             {
4617                 if (&conditional_true_when ($perm, $scan)
4618                     || &conditional_true_when ($scan, $perm))
4619                 {
4620                     $ok = 0;
4621                     last;
4622                 }
4623             }
4624             next if ! $ok;
4626             if (@parent_conds)
4627             {
4628                 local ($ok) = 1;
4629                 local ($parent_cond);
4630                 foreach $parent_cond (@parent_conds)
4631                 {
4632                     if (! &conditional_true_when ($parent_cond, $perm))
4633                     {
4634                         $ok = 0;
4635                         last;
4636                     }
4637                 }
4639                 next if ! $ok;
4640             }
4642             # This permutation was not already handled, and is valid
4643             # for the parents.
4644             push (@new_conds, $perm);
4645         }
4646     }
4648     return @new_conds;
4651 # Subroutine for variable_conditions_sort
4652 sub variable_conditions_cmp
4654     local ($as) = $a;
4655     $as =~ s/[^@]//g;
4656     local ($bs) = $b;
4657     $bs =~ s/[^@]//g;
4658     return (length ($as) <=> length ($bs)
4659             || $a cmp $b);
4662 # Sort a list of conditionals so that only the exclusive ones are
4663 # retained.  For example, if both @COND1_TRUE@@COND2_TRUE@ and
4664 # @COND1_TRUE@ are in the list, discard the latter.
4665 sub variable_conditions_reduce
4667     local (@conds) = @_;
4668     local (@ret) = ();
4669     local ($cond);
4670     foreach $cond (sort variable_conditions_cmp @conds)
4671     {
4672         local ($ok) = 1;
4673         local ($scan);
4674         foreach $scan (@ret)
4675         {
4676             if (&conditional_true_when ($cond, $scan))
4677             {
4678                 $ok = 0;
4679                 last;
4680             }
4681         }
4682         next if ! $ok;
4683         push (@ret, $cond);
4684     }
4686     return @ret;
4689 # Return a list of permutations of a conditional string.
4690 sub variable_conditions_permutations
4692     local (@comps) = @_;
4693     return ()
4694         if ! @comps;
4695     local ($comp) = shift (@comps);
4696     return &variable_conditions_permutations (@comps)
4697         if $comp eq '';
4698     local ($neg) = $comp;
4699     $neg =~ s/TRUE$/TRUEO/;
4700     $neg =~ s/FALSE$/TRUE/;
4701     $neg =~ s/TRUEO$/FALSE/;
4702     local (@ret);
4703     local ($sub);
4704     foreach $sub (&variable_conditions_permutations (@comps))
4705     {
4706         push (@ret, '@' . $comp . '@' . $sub);
4707         push (@ret, '@' . $neg . '@' . $sub);
4708     }
4709     if (! @ret)
4710     {
4711         push (@ret, '@' . $comp . '@');
4712         push (@ret, '@' . $neg . '@');
4713     }
4714     return @ret;
4717 # Warn if a variable is conditionally defined.  This is called if we
4718 # are using the value of a variable.
4719 sub variable_conditionally_defined
4721     local ($var, $parent) = @_;
4722     if ($conditional{$var})
4723     {
4724         if ($parent)
4725         {
4726             &am_line_error ($parent,
4727                             "warning: automake does not support conditional definition of $var in $parent");
4728         }
4729         else
4730         {
4731             &am_line_error ($parent,
4732                             "warning: automake does not support $var being defined conditionally")
4733         }
4734     }
4737 # Get the value of a variable.  This just returns $contents, but warns
4738 # if the variable is conditionally defined.
4739 sub variable_value
4741     local ($var) = @_;
4742     &variable_conditionally_defined ($var);
4743     return $contents{$var};
4746 # Convert a variable value to a list, split as whitespace.  This will
4747 # recursively follow $(...) and ${...} inclusions.  It preserves @...@
4748 # substitutions.  If COND is 'all', then all values under all
4749 # conditions should be returned; if COND is a particular condition
4750 # (all conditions are surrounded by @...@) then only the value for
4751 # that condition should be returned; otherwise, warn if VAR is
4752 # conditionally defined.
4753 sub value_to_list
4755     local ($var, $val, $cond) = @_;
4756     local (@result);
4758     foreach (split (' ', $val))
4759     {
4760         # If a comment seen, just leave.
4761         last if /^#/;
4763         # Handle variable substitutions.
4764         if (/^\$\{([^}]*)\}$/ || /^\$\(([^)]*)\)$/)
4765         {
4766             local ($varname) = $1;
4768             # If the user uses a losing variable name, just ignore it.
4769             # This isn't ideal, but people have requested it.
4770             next if ($varname =~ /\@.*\@/);
4772             local ($from, $to);
4773             local (@temp_list);
4774             if ($varname =~ /^([^:]*):([^=]*)=(.*)$/)
4775             {
4776                 $varname = $1;
4777                 $to = $3;
4778                 ($from = $2) =~ s/(\W)/\\$1/g;
4779             }
4781             # Find the value.
4782             @temp_list = &variable_value_as_list ($1, $cond, $var);
4784             # Now rewrite the value if appropriate.
4785             if ($from)
4786             {
4787                 grep (s/$from$/$to/, @temp_list);
4788             }
4790             push (@result, @temp_list);
4791         }
4792         else
4793         {
4794             push (@result, $_);
4795         }
4796     }
4798     return @result;
4801 # Return contents of variable as list, split as whitespace.  This will
4802 # recursively follow $(...) and ${...} inclusions.  It preserves @...@
4803 # substitutions.  If COND is 'all', then all values under all
4804 # conditions should be returned; if COND is a particular condition
4805 # (all conditions are surrounded by @...@) then only the value for
4806 # that condition should be returned; otherwise, warn if VAR is
4807 # conditionally defined.  If PARENT is specified, it is the name of
4808 # the including variable; this is only used for error reports.
4809 sub variable_value_as_list
4811     local ($var, $cond, $parent) = @_;
4812     local (@result);
4814     if (defined $targets{$var})
4815     {
4816         &am_line_error ($var, "\`$var' is target; expected variable");
4817     }
4818     elsif (! defined $contents{$var})
4819     {
4820         &am_line_error ($parent, "variable \`$var' not defined");
4821     }
4822     elsif ($cond eq 'all' && $conditional{$var})
4823     {
4824         local (@condvals) = split (' ', $conditional{$var});
4825         while (@condvals)
4826         {
4827             shift (@condvals);
4828             local ($val) = &unquote_cond_val (shift (@condvals));
4829             push (@result, &value_to_list ($var, $val, $cond));
4830         }
4831     }
4832     elsif ($cond && $conditional{$var})
4833     {
4834         local (@condvals) = split (' ', $conditional{$var});
4835         local ($onceflag);
4836         while (@condvals)
4837         {
4838             local ($vcond) = shift (@condvals);
4839             local ($val) = &unquote_cond_val (shift (@condvals));
4840             if (&conditional_true_when ($vcond, $cond))
4841             {
4842                 # Warn if we have an ambiguity.  It's hard to know how
4843                 # to handle this case correctly.
4844                 &variable_conditionally_defined ($var, $parent)
4845                     if $onceflag;
4846                 $onceflag = 1;
4847                 push (@result, &value_to_list ($var, $val, $cond));
4848             }
4849         }
4850     }
4851     else
4852     {
4853         &variable_conditionally_defined ($var, $parent);
4854         $content_seen{$var} = 1;
4855         push (@result, &value_to_list ($var, $contents{$var}, $cond));
4856     }
4858     return @result;
4861 # Define a new variable, but only if not already defined.
4862 sub define_variable
4864     local ($var, $value) = @_;
4866     if (! defined $contents{$var})
4867     {
4868         $output_vars .= $var . ' = ' . $value . "\n";
4869         $contents{$var} = $value;
4870         $content_seen{$var} = 1;
4871     }
4874 # Like define_variable, but the value is a list, and the variable may
4875 # be defined conditionally.  The second argument is the conditional
4876 # under which the value should be defined; this should be the empty
4877 # string to define the variable unconditionally.  The third argument
4878 # is a list holding the values to use for the variable.  The value is
4879 # pretty printed in the output file.
4880 sub define_pretty_variable
4882     local ($var, $cond, @value) = @_;
4883     if (! defined $contents{$var}
4884         || ($cond && ! &variable_defined ($var, $cond)))
4885     {
4886         $contents{$var} = join (' ', @value);
4887         if ($cond)
4888         {
4889             if ($conditional{$var})
4890             {
4891                 $conditional{$var} .= ' ';
4892             }
4893             else
4894             {
4895                 $conditional{$var} = '';
4896             }
4897             $conditional{$var} .= ($cond
4898                                    . ' '
4899                                    . &quote_cond_val ($contents{$var}));
4900         }
4901         &pretty_print ($cond . $var . ' = ', $cond, @value);
4902         $content_seen{$var} = 1;
4903     }
4906 # Like define_variable, but define a variable to be the configure
4907 # substitution by the same name.
4908 sub define_configure_variable
4910     local ($var) = @_;
4911     local ($value) = '@' . $var . '@';
4912     &define_variable ($var, $value);
4915 # Define a variable that represents a program to run.  If in Cygnus
4916 # mode, the program is searched for in the build (or source) tree.
4917 # Otherwise no searching is done at all.  Arguments are:
4918 # * VAR      Name of variable to define
4919 # * WHATDIR  Either `src' or `build', depending on where program should
4920 #            be found.  (runtest is in srcdir!)
4921 # * SUBDIR   Subdir of top-level dir
4922 # * PROGRAM  Name of program
4923 # * OVERRIDE If specified, the name of the program to use when not in
4924 #            Cygnus mode.  Defaults to PROGRAM.
4925 sub define_program_variable
4927     local ($var, $whatdir, $subdir, $program, $override) = @_;
4929     if (! $override)
4930     {
4931         $override = $program;
4932     }
4934     if ($cygnus_mode)
4935     {
4936         local ($full) = ('$(top_' . $whatdir . 'dir)/../'
4937                          . $subdir . '/' . $program);
4938         &define_variable ($var, ('`if test -f ' . $full
4939                                  . '; then echo ' . $full . '; else echo '
4940                                  . $program . '; fi`'));
4941     }
4942     else
4943     {
4944         &define_variable ($var, $override);
4945     }
4949 ################################################################
4951 # Read Makefile.am and set up %contents.  Simultaneously copy lines
4952 # from Makefile.am into $output_trailer or $output_vars as
4953 # appropriate.  NOTE we put rules in the trailer section.  We want
4954 # user rules to come after our generated stuff.
4955 sub read_am_file
4957     local ($amfile) = @_;
4959     open (AM_FILE, $amfile) || die "automake: couldn't open \`$amfile': $!\n";
4960     print "automake: reading $amfile\n" if $verbose;
4962     $output_vars = ("# $in_file_name generated automatically by automake "
4963                     . $VERSION . " from $am_file_name\n");
4965     # Generate copyright for generated Makefile.in.
4966     $output_vars .= $gen_copyright;
4968     local ($saw_bk) = 0;
4969     local ($was_rule) = 0;
4970     local ($spacing) = '';
4971     local ($comment) = '';
4972     local ($last_var_name) = '';
4973     local ($blank) = 0;
4975     while (<AM_FILE>)
4976     {
4977         if (/$IGNORE_PATTERN/o)
4978         {
4979             # Merely delete comments beginning with two hashes.
4980         }
4981         elsif (/$WHITE_PATTERN/o)
4982         {
4983             # Stick a single white line before the incoming macro or rule.
4984             $spacing = "\n";
4985             $blank = 1;
4986         }
4987         elsif (/$COMMENT_PATTERN/o)
4988         {
4989             # Stick comments before the incoming macro or rule.  Make
4990             # sure a blank line preceeds first block of comments.
4991             $spacing = "\n" unless $blank;
4992             $blank = 1;
4993             $comment .= $spacing . $_;
4994             $spacing = '';
4995         }
4996         else
4997         {
4998             last;
4999         }
5000     }
5002     $output_vars .= $comment . "\n";
5003     $comment = '';
5004     $spacing = "\n";
5005     local ($am_vars) = '';
5007     local ($is_ok_macro);
5008     while ($_)
5009     {
5010         $_ .= "\n"
5011             unless substr ($_, -1, 1) eq "\n";
5013         $_ =~ s/\@MAINT\@//g
5014             unless $seen_maint_mode;
5016         if (/$IGNORE_PATTERN/o)
5017         {
5018             # Merely delete comments beginning with two hashes.
5019         }
5020         elsif (/$WHITE_PATTERN/o)
5021         {
5022             # Stick a single white line before the incoming macro or rule.
5023             $spacing = "\n";
5024         }
5025         elsif (/$COMMENT_PATTERN/o)
5026         {
5027             # Stick comments before the incoming macro or rule.
5028             $comment .= $spacing . $_;
5029             $spacing = '';
5030         }
5031         elsif ($saw_bk)
5032         {
5033             if ($was_rule)
5034             {
5035                 $output_trailer .= join ('', @conditional_stack) . $_;
5036                 $saw_bk = /\\$/;
5037             }
5038             else
5039             {
5040                 $am_vars .= join ('', @conditional_stack) . $_;
5041                 $saw_bk = /\\$/;
5042                 # Chop newline and backslash if this line is
5043                 # continued.  FIXME: maybe ensure trailing whitespace
5044                 # exists?
5045                 chop if $saw_bk;
5046                 chop if $saw_bk;
5047                 $contents{$last_var_name} .= $_;
5048                 if (@conditional_stack)
5049                 {
5050                     $conditional{$last_var_name} .= &quote_cond_val ($_);
5051                 }
5052             }
5053         }
5054         elsif (/$IF_PATTERN/o)
5055         {
5056             &am_line_error ($., "$1 does not appear in AM_CONDITIONAL")
5057                 if (! $configure_cond{$1});
5058             push (@conditional_stack, "\@" . $1 . "_TRUE\@");
5059         }
5060         elsif (/$ELSE_PATTERN/o)
5061         {
5062             if (! @conditional_stack)
5063             {
5064                 &am_line_error ($., "else without if");
5065             }
5066             elsif ($conditional_stack[$#conditional_stack] =~ /_FALSE\@$/)
5067             {
5068                 &am_line_error ($., "else after else");
5069             }
5070             else
5071             {
5072                 $conditional_stack[$#conditional_stack]
5073                     =~ s/_TRUE\@$/_FALSE\@/;
5074             }
5075         }
5076         elsif (/$ENDIF_PATTERN/o)
5077         {
5078             if (! @conditional_stack)
5079             {
5080                 &am_line_error ($., "endif without if");
5081             }
5082             else
5083             {
5084                 pop @conditional_stack;
5085             }
5086         }
5087         elsif (/$RULE_PATTERN/o)
5088         {
5089             # Found a rule.
5090             $was_rule = 1;
5091             if (defined $contents{$1}
5092                 && (@conditional_stack
5093                     ? ! defined $conditional{$1}
5094                     : defined $conditional{$1}))
5095             {
5096                 &am_line_error ($1,
5097                                 "$1 defined both conditionally and unconditionally");
5098             }
5099             # Value here doesn't matter; for targets we only note
5100             # existence.
5101             $contents{$1} = 1;
5102             $targets{$1} = 1;
5103             local ($cond_string) = join ('', @conditional_stack);
5104             if (@conditional_stack)
5105             {
5106                 if ($conditional{$1})
5107                 {
5108                     &check_ambiguous_conditional ($1, $cond_string);
5109                     $conditional{$1} .= ' ';
5110                 }
5111                 else
5112                 {
5113                     $conditional{$1} = '';
5114                 }
5115                 $conditional{$1} .= $cond_string . ' 1';
5116             }
5117             $content_lines{$1} = $.;
5118             $output_trailer .= $comment . $spacing . $cond_string . $_;
5119             $comment = $spacing = '';
5120             $saw_bk = /\\$/;
5122             # Check the rule for being a suffix rule. If so, store in
5123             # a hash.
5125             local ($source_suffix);
5126             local ($object_suffix);
5128             if (($source_suffix, $object_suffix) = ($1 =~ $SUFFIX_RULE_PATTERN)) 
5129             {
5130               $suffix_rules{$source_suffix} = $object_suffix;
5131               print "Sources ending in .$source_suffix become .$object_suffix\n" if $verbose;
5132               $source_suffix_pattern = "(" . join('|', keys %suffix_rules) . ")";
5133             }
5135             # FIXME: make sure both suffixes are in SUFFIXES? Or set
5136             # SUFFIXES from suffix_rules?
5137         }
5138         elsif (($is_ok_macro = /$MACRO_PATTERN/o)
5139                || /$BOGUS_MACRO_PATTERN/o)
5140         {
5141             # Found a macro definition.
5142             $was_rule = 0;
5143             $last_var_name = $1;
5144             if (defined $contents{$1}
5145                 && (@conditional_stack
5146                     ? ! defined $conditional{$1}
5147                     : defined $conditional{$1}))
5148             {
5149                 &am_line_error ($1,
5150                                 "$1 defined both conditionally and unconditionally");
5151             }
5152             if ($2 ne '' && substr ($2, -1) eq "\\")
5153             {
5154                 $contents{$last_var_name} = substr ($2, 0, length ($2) - 1);
5155             }
5156             else
5157             {
5158                 $contents{$last_var_name} = $2;
5159             }
5160             local ($cond_string) = join ('', @conditional_stack);
5161             if (@conditional_stack)
5162             {
5163                 if ($conditional{$last_var_name})
5164                 {
5165                     &check_ambiguous_conditional ($last_var_name,
5166                                                   $cond_string);
5167                     $conditional{$last_var_name} .= ' ';
5168                 }
5169                 else
5170                 {
5171                     $conditional{$last_var_name} = '';
5172                 }
5173                 local ($val) = $contents{$last_var_name};
5174                 $conditional{$last_var_name} .= ($cond_string
5175                                                  . ' '
5176                                                  . &quote_cond_val ($val));
5177             }
5178             $content_lines{$last_var_name} = $.;
5179             $am_vars .= $comment . $spacing . $cond_string . $_;
5180             $comment = $spacing = '';
5181             $saw_bk = /\\$/;
5183             # Error if bogus.
5184             &am_line_error ($., "bad macro name \`$last_var_name'")
5185                 if ! $is_ok_macro;
5186         }
5187         else
5188         {
5189             # This isn't an error; it is probably a continued rule.
5190             # In fact, this is what we assume.
5191             $was_rule = 1;
5192             $output_trailer .= ($comment . $spacing
5193                                 . join ('', @conditional_stack) . $_);
5194             $comment = $spacing = '';
5195             $saw_bk = /\\$/;
5196         }
5198         $_ = <AM_FILE>;
5199     }
5201     $output_trailer .= $comment;
5203     &am_error ("unterminated conditionals: " . join (' ', @conditional_stack))
5204         if (@conditional_stack);
5206     # Compute relative location of the top object directory.
5207     local (@topdir) = ();
5208     foreach (split (/\//, $relative_dir))
5209     {
5210         next if $_ eq '.' || $_ eq '';
5211         if ($_ eq '..')
5212         {
5213             pop @topdir;
5214         }
5215         else
5216         {
5217             push (@topdir, '..');
5218         }
5219     }
5220     @topdir = ('.') if ! @topdir;
5222     $top_builddir = join ('/', @topdir);
5223     local ($build_rx);
5224     ($build_rx = $top_builddir) =~ s/(\W)/\\$1/g;
5225     $output_vars .= &file_contents_with_transform
5226                         ('s/\@top_builddir\@/' . $build_rx . '/g;',
5227                          'header-vars');
5229     # Generate some useful variables when AC_CANONICAL_* used.  FIXME:
5230     # this should use generic %configure_vars method.
5231     if ($seen_canonical)
5232     {
5233         local ($curs, %vars);
5234         $vars{'host_alias'} = 'host_alias';
5235         $vars{'host_triplet'} = 'host';
5236         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
5237         {
5238             $vars{'build_alias'} = 'build_alias';
5239             $vars{'build_triplet'} = 'build';
5240             $vars{'target_alias'} = 'target_alias';
5241             $vars{'target_triplet'} = 'target';
5242         }
5243         foreach $curs (sort keys %vars)
5244         {
5245             $output_vars .= "$curs = \@$vars{$curs}\@\n";
5246             $contents{$curs} = "\@$vars{$curs}\@";
5247         }
5248     }
5250     local ($curs);
5251     foreach $curs (sort keys %configure_vars)
5252     {
5253         &define_configure_variable ($curs);
5254     }
5256     $output_vars .= $am_vars;
5259 ################################################################
5261 sub initialize_global_constants
5263     # Values for AC_CANONICAL_*
5264     $AC_CANONICAL_HOST = 1;
5265     $AC_CANONICAL_SYSTEM = 2;
5267     # Associative array of standard directory names.  Entry is TRUE if
5268     # corresponding directory should be installed during
5269     # 'install-exec' phase.
5270     %exec_dir_p =
5271         ('bin', 1,
5272          'sbin', 1,
5273          'libexec', 1,
5274          'data', 0,
5275          'sysconf', 1,
5276          'localstate', 1,
5277          'lib', 1,
5278          'info', 0,
5279          'man', 0,
5280          'include', 0,
5281          'oldinclude', 0,
5282          'pkgdata', 0,
5283          'pkglib', 1,
5284          'pkginclude', 0
5285          );
5287     # Helper text for dealing with man pages.
5288     $install_man_format =
5289     '   @sect=@SECTION@;                                \\
5290         inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
5291         if test -f $(srcdir)/@MAN@; then file=$(srcdir)/@MAN@; \\
5292         else file=@MAN@; fi; \\
5293         echo " $(INSTALL_DATA) $$file $(mandir)/man$$sect/$$inst"; \\
5294         $(INSTALL_DATA) $$file $(mandir)/man$$sect/$$inst
5297     $uninstall_man_format =
5298     '   inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
5299         -rm -f $(mandir)/man@SECTION@/$$inst
5302     # Commonly found files we look for and automatically include in
5303     # DISTFILES.
5304     @common_files =
5305         (
5306          "README", "THANKS", "TODO", "NEWS", "COPYING", "COPYING.LIB",
5307          "INSTALL", "ABOUT-NLS", "ChangeLog", "configure", "configure.in",
5308          "config.guess", "config.sub", "AUTHORS", "BACKLOG", "ABOUT-GNU",
5309          "libversion.in", "mdate-sh", "mkinstalldirs", "install-sh",
5310          'texinfo.tex', "ansi2knr.c", "ansi2knr.1", 'elisp-comp',
5311          'ylwrap', 'acinclude.m4', @libtoolize_files,
5312          'missing'
5313          );
5315     # Commonly used files we auto-include, but only sometimes.
5316     @common_sometimes =
5317         (
5318          "aclocal.m4", "acconfig.h", "config.h.top",
5319          "config.h.bot", "stamp-h.in", 'stamp-vti'
5320          );
5322     $USAGE = "\
5323   -a, --add-missing     add missing standard files to package
5324   --amdir=DIR           directory storing config files
5325   --build-dir=DIR       directory where build being done (for dependencies)
5326   --cygnus              assume program is part of Cygnus-style tree
5327   --foreign             set strictness to foreign
5328   --gnits               set strictness to gnits
5329   --gnu                 set strictness to gnu
5330   --help                print this help, then exit
5331   -i, --include-deps    include generated dependencies in Makefile.in
5332   --no-force            only update Makefile.in's that are out of date
5333   -o DIR, --output-dir=DIR
5334                         put generated Makefile.in's into DIR
5335   --srcdir-name=DIR     name used for srcdir (for dependencies)
5336   -v, --verbose         verbosely list files processed
5337   --version             print version number, then exit\n";
5339     # Copyright on generated Makefile.ins.
5340     $gen_copyright = "\
5341 # Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
5342 # This Makefile.in is free software; the Free Software Foundation
5343 # gives unlimited permission to copy and/or distribute it,
5344 # with or without modifications, as long as this notice is preserved.
5346 # This program is distributed in the hope that it will be useful,
5347 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
5348 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
5349 # PARTICULAR PURPOSE.
5352     # Ignore return result from chmod, because it might give an error
5353     # if we chmod a symlink.
5354     $dist_header = "\t" . '-chmod -R a+r $(distdir)' . "\n";
5355     $dist{'dist-tarZ'} = ("\t"
5356                      . '$(TAR) chf - $(distdir) | compress -c > $(distdir).tar.Z'
5357                      . "\n");
5358     $dist{'dist-shar'} = ("\t"
5359                      . 'shar $(distdir) | gzip > $(distdir).shar.gz'
5360                      . "\n");
5361     $dist{'dist-zip'} = "\t" . 'zip -rq $(distdir).zip $(distdir)' . "\n";
5362     $dist{'dist'} = "\t" .  'GZIP=$(GZIP) $(TAR) chozf $(distdir).tar.gz $(distdir)' . "\n";
5363     $dist_trailer = "\t" . '-rm -rf $(distdir)' . "\n";
5366 # (Re)-Initialize per-Makefile.am variables.
5367 sub initialize_per_input
5369     # These two variables are used when generating each Makefile.in.
5370     # They hold the Makefile.in until it is ready to be printed.
5371     $output_rules = '';
5372     $output_vars = '';
5373     $output_trailer = '';
5374     $output_header = '';
5376     # Suffixes found during a run.
5377     @suffixes = ();
5379     # This holds the contents of a Makefile.am, as parsed by
5380     # read_am_file.
5381     %contents = ();
5383     # This holds the names which are targets.  These also appear in
5384     # %contents.
5385     %targets = ();
5387     # For a variable or target which is defined conditionally, this
5388     # holds an array of the conditional values.  The array is composed
5389     # of pairs of condition strings (the variables which configure
5390     # will substitute) and values (the value of a target is
5391     # meaningless).  For an unconditional variable, this is empty.
5392     %conditional = ();
5394     # This holds the line numbers at which various elements of
5395     # %contents are defined.
5396     %content_lines = ();
5398     # This holds a 1 if a particular variable was examined.
5399     %content_seen = ();
5401     # This is the conditional stack.
5402     @conditional_stack = ();
5404     # This holds the "relative directory" of the current Makefile.in.
5405     # Eg for src/Makefile.in, this is "src".
5406     $relative_dir = '';
5408     # This holds a list of files that are included in the
5409     # distribution.
5410     %dist_common = ();
5412     # List of dependencies for the obvious targets.
5413     @install_data = ();
5414     @install_exec = ();
5415     @uninstall = ();
5416     @installdirs = ();
5418     @info = ();
5419     @dvi = ();
5420     @all = ();
5421     @check = ();
5422     @check_tests = ();
5423     @installcheck = ();
5424     @clean = ();
5426     @phony = ();
5428     # These are pretty obvious, too.  They are used to define the
5429     # SOURCES and OBJECTS variables.
5430     @sources = ();
5431     @objects = ();
5433     # TRUE if current directory holds any C source files.
5434     $dir_holds_sources = 0;
5436     # These variables track inclusion of various compile-related .am
5437     # files.  $included_generic_compile is TRUE if the basic code has
5438     # been included.  $included_knr_compile is TRUE if the ansi2knr
5439     # code has been included.  $included_libtool_compile is TRUE if
5440     # libtool support has been included.
5441     $included_generic_compile = 0;
5442     $included_knr_compile = 0;
5443     $included_libtool_compile = 0;
5445     # TRUE if current directory holds any headers.
5446     $dir_holds_headers = 0;
5448     # TRUE if install targets should work recursively.
5449     $recursive_install = 0;
5451     # All .P files.
5452     %dep_files = ();
5454     # Strictness levels.
5455     $strictness = $default_strictness;
5456     $strictness_name = $default_strictness_name;
5458     # Options from AUTOMAKE_OPTIONS.
5459     %options = ();
5461     # Whether or not dependencies are handled.  Can be further changed
5462     # in handle_options.
5463     $use_dependencies = $cmdline_use_dependencies;
5465     # Per Makefile.am.
5466     $local_maint_charset = $maint_charset;
5468     # All yacc and lex source filenames for this directory.  Use
5469     # filenames instead of raw count so that multiple instances are
5470     # counted correctly (eg one yacc file can appear in multiple
5471     # programs without harm).
5472     %yacc_sources = ();
5473     %lex_sources = ();
5475     # C++ source extensions we've seen.
5476     %cxx_extensions = ();
5478     # TRUE if we've seen any non-C++ sources.  This actually holds a
5479     # line number or the name of a symbol corresponding to a line
5480     # number where the C sources were seen.  If it is -1 then it means
5481     # we couldn't (easily) figure out which line of the Makefile.am
5482     # mentioned the sources.
5483     $seen_c_source = 0;
5485     # This is a list of all targets to run during "make dist".
5486     @dist_targets = ();
5488     # Keys in this hash are the basenames of files which must depend
5489     # on ansi2knr.
5490     %de_ansi_files = ();
5492     # This maps the source extension of a suffix rule to its
5493     # corresponding output extension.
5494     %suffix_rules = ();
5498 ################################################################
5500 # Return contents of a file from $am_dir, automatically skipping
5501 # macros or rules which are already known.  Runs command on each line
5502 # as it is read; this command can modify $_.
5503 sub file_contents_with_transform
5505     local ($command, $basename) = @_;
5506     local ($file) = $am_dir . '/' . $basename . '.am';
5508     if ($command ne '' && substr ($command, -1) ne ';')
5509     {
5510         die "automake: programming error in file_contents_with_transform\n";
5511     }
5513     open (FC_FILE, $file)
5514         || die "automake: installation error: cannot open \`$file'\n";
5515     # Looks stupid?
5516     # print "automake: reading $file\n" if $verbose;
5518     local ($was_rule) = 0;
5519     local ($result_vars) = '';
5520     local ($result_rules) = '';
5521     local ($comment) = '';
5522     local ($spacing) = "\n";
5523     local ($skipping) = 0;
5524     local ($had_chars);
5526     while (<FC_FILE>)
5527     {
5528         $_ =~ s/\@MAINT\@//g
5529             unless $seen_maint_mode;
5531         $had_chars = length ($_) && $_ ne "\n";
5532         eval $command;
5533         # If the transform caused all the characters to go away, then
5534         # ignore the line.  Why do this?  Because in Perl 4, a "next"
5535         # inside of an eval doesn't affect a loop outside the eval.
5536         # So we can't pass in a "transform" that uses next.  We used
5537         # to do this.  "Empty" also means consisting of a single
5538         # newline.
5539         next if $had_chars && ($_ eq '' || $_ eq "\n");
5541         if (/$IGNORE_PATTERN/o)
5542         {
5543             # Merely delete comments beginning with two hashes.
5544         }
5545         elsif (/$WHITE_PATTERN/o)
5546         {
5547             # Stick a single white line before the incoming macro or rule.
5548             $spacing = "\n";
5549         }
5550         elsif (/$COMMENT_PATTERN/o)
5551         {
5552             # Stick comments before the incoming macro or rule.
5553             $comment .= $spacing . $_;
5554             $spacing = '';
5555         }
5556         elsif ($saw_bk)
5557         {
5558             if ($was_rule)
5559             {
5560                 $result_rules .= $_ if ! $skipping;
5561             }
5562             else
5563             {
5564                 $result_vars .= $_ if ! $skipping;
5565             }
5566             $saw_bk = /\\$/;
5567         }
5568         elsif (/$RULE_PATTERN/o)
5569         {
5570             # Found a rule.
5571             $was_rule = 1;
5572             $skipping = defined $contents{$1};
5573             $result_rules .= $comment . $spacing . $_ if ! $skipping;
5574             $comment = $spacing = '';
5575             $saw_bk = /\\$/;
5576         }
5577         elsif (/$MACRO_PATTERN/o)
5578         {
5579             # Found a variable reference.
5580             $was_rule = 0;
5581             $skipping = defined $contents{$1};
5582             $result_vars .= $comment . $spacing . $_ if ! $skipping;
5583             $comment = $spacing = '';
5584             $saw_bk = /\\$/;
5585         }
5586         else
5587         {
5588             # This isn't an error; it is probably a continued rule.
5589             # In fact, this is what we assume.
5590             $was_rule = 1;
5591             $result_rules .= $comment . $spacing . $_ if ! $skipping;
5592             $comment = $spacing = '';
5593             $saw_bk = /\\$/;
5594         }
5595     }
5597     close (FC_FILE);
5598     return $result_vars . $result_rules . $comment;
5601 # Like file_contents_with_transform, but no transform.
5602 sub file_contents
5604     return &file_contents_with_transform ('', @_);
5607 # Find all variable prefixes that are used for install directories.  A
5608 # prefix `zar' qualifies iff:
5609 # * `zardir' is a variable.
5610 # * `zar_PRIMARY' is a variable.
5611 sub am_primary_prefixes
5613     local ($primary, @prefixes) = @_;
5615     local (%valid, $varname);
5616     grep ($valid{$_} = 0, @prefixes);
5617     $valid{'EXTRA'} = 0;
5618     foreach $varname (keys %contents)
5619     {
5620         if ($varname =~ /^(.*)_$primary$/)
5621         {
5622             if (! defined $valid{$1}
5623                 && ! &variable_defined ($1 . 'dir')
5624                 # Note that a configure variable is always legitimate.
5625                 # It is natural to name such variables after the
5626                 # primary, so we explicitly allow it.
5627                 && ! defined $configure_vars{$varname})
5628             {
5629                 &am_line_error ($varname, "invalid variable \`$varname'");
5630             }
5631             else
5632             {
5633                 # Ensure all extended prefixes are actually used.
5634                 $valid{$1} = 1;
5635             }
5636         }
5637     }
5639     return %valid;
5642 # Handle `where_HOW' variable magic.  Does all lookups, generates
5643 # install code, and possibly generates code to define the primary
5644 # variable.  The first argument is the name of the .am file to munge,
5645 # the second argument is the primary variable (eg HEADERS), and all
5646 # subsequent arguments are possible installation locations.  Returns
5647 # list of all values of all _HOW targets.
5649 # FIXME: this should be rewritten to be cleaner.  It should be broken
5650 # up into multiple functions.
5652 # Usage is: am_install_var (OPTION..., file, HOW, where...)
5653 sub am_install_var
5655     local (@args) = @_;
5657     local ($do_clean) = 0;
5659     local ($ltxform);
5660     if (defined $configure_vars{'LIBTOOL'})
5661     {
5662         # Transform '@LIBTOOL ...@' to '$(LIBTOOL) ...'
5663         $ltxform = 's/\@LIBTOOL([^\@]*)\@/\$(LIBTOOL) $1/;';
5664     }
5665     else
5666     {
5667         # Delete '@LIBTOOL ...@'
5668         $ltxform = 's/\@LIBTOOL([^\@]*)\@//;';
5669     }
5671     local ($cygxform);
5672     if (! $seen_exeext)
5673     {
5674         $cygxform = 's/\@EXEEXT\@//g;';
5675     }
5676     else
5677     {
5678         $cygxform = 's/\@EXEEXT\@/\$(EXEEXT)/g;';
5679     }
5681     while (@args)
5682     {
5683         if ($args[0] eq '-clean')
5684         {
5685             $do_clean = 1;
5686         }
5687         elsif ($args[0] !~ /^-/)
5688         {
5689             last;
5690         }
5691         shift (@args);
5692     }
5693     local ($file, $primary, @prefixes) = @args;
5695     local (@used) = ();
5696     local (@result) = ();
5698     # Now that configure substitutions are allowed in where_HOW
5699     # variables, it is an error to actually define the primary.
5700     &am_line_error ($primary, "\`$primary' is an anachronism")
5701         if &variable_defined ($primary);
5704     # Look for misspellings.  It is an error to have a variable ending
5705     # in a "reserved" suffix whose prefix is unknown, eg
5706     # "bni_PROGRAMS".  However, unusual prefixes are allowed if a
5707     # variable of the same name (with "dir" appended) exists.  For
5708     # instance, if the variable "zardir" is defined, then
5709     # "zar_PROGRAMS" becomes valid.  This is to provide a little extra
5710     # flexibility in those cases which need it.  Perhaps it should be
5711     # disallowed in the Gnits case?  The problem is, sometimes it is
5712     # useful to put things in a subdir of eg pkgdatadir, perhaps even
5713     # for Gnitsoids.
5714     local (%valid) = &am_primary_prefixes ($primary, @prefixes);
5716     # If a primary includes a configure substitution, then the EXTRA_
5717     # form is required.  Otherwise we can't properly do our job.
5718     local ($require_extra);
5719     local ($warned_about_extra) = 0;
5721     local ($clean_file) = $file . '-clean';
5722     local ($one_name);
5723     local ($X);
5724     foreach $X (sort keys %valid)
5725     {
5726         $one_name = $X . '_' . $primary;
5727         if (&variable_defined ($one_name))
5728         {
5729             # Append actual contents of where_PRIMARY variable to
5730             # result.
5731             local ($rcurs);
5732             foreach $rcurs (&variable_value_as_list ($one_name, 'all'))
5733             {
5734                 # Skip configure substitutions.  Possibly bogus.
5735                 if ($rcurs =~ /^\@.*\@$/)
5736                 {
5737                     if ($X eq 'EXTRA')
5738                     {
5739                         if (! $warned_about_extra)
5740                         {
5741                             $warned_about_extra = 1;
5742                             &am_line_error ($one_name,
5743                                             "\`$one_name' contains configure substitution, but shouldn't");
5744                         }
5745                     }
5746                     # Check here to make sure variables defined in
5747                     # configure.in do not imply that EXTRA_PRIMARY
5748                     # must be defined.
5749                     elsif (! defined $configure_vars{$one_name})
5750                     {
5751                         $require_extra = $one_name;
5752                     }
5754                     next;
5755                 }
5757                 push (@result, $rcurs);
5758             }
5760             # "EXTRA" shouldn't be used when generating clean targets,
5761             # all, or install targets.
5762             next if $X eq 'EXTRA';
5764             # A blatant hack: we rewrite each _PROGRAMS primary to
5765             # include EXEEXT when in Cygwin32 mode.
5766             if ($seen_exeext && $primary eq 'PROGRAMS')
5767             {
5768                 local (@conds) = &variable_conditions ($one_name);
5769                 local (@one_binlist);
5771                 # FIXME: this definitely loses aesthetically; it
5772                 # redefines $ONE_NAME.  Instead we should arrange for
5773                 # variable definitions to be output later, instead of
5774                 # at scan time.
5776                 if (! @conds)
5777                 {
5778                     @one_binlist = ();
5779                     foreach $rcurs (&variable_value_as_list ($one_name, ''))
5780                     {
5781                         if ($rcurs =~ /\./ || $rcurs =~ /^\@.*\@$/)
5782                         {
5783                             push (@one_binlist, $rcurs);
5784                         }
5785                         else
5786                         {
5787                             push (@one_binlist, $rcurs . '$(EXEEXT)');
5788                         }
5789                     }
5791                     delete $contents{$one_name};
5792                     &define_pretty_variable ($one_name, '', @one_binlist);
5793                 }
5794                 else
5795                 {
5796                     local ($cond);
5797                     local ($condvals) = '';
5798                     foreach $cond (@conds)
5799                     {
5800                         @one_binlist = ();
5801                         local (@condval) = &variable_value_as_list ($one_name,
5802                                                                     $cond);
5803                         foreach $rcurs (@condval)
5804                         {
5805                             if ($rcurs =~ /\./ || $rcurs =~ /^\@.*\@$/)
5806                             {
5807                                 push (@one_binlist, $rcurs);
5808                             }
5809                             else
5810                             {
5811                                 push (@one_binlist, $rcurs . '$(EXEEXT)');
5812                             }
5813                         }
5815                         push (@condvals, $cond);
5816                         push (@condvals, join (' ', @one_binlist));
5817                     }
5819                     delete $contents{$one_name};
5821                     while (@condvals)
5822                     {
5823                         $cond = shift (@condvals);
5824                         local (@val) = split (' ', shift (@condvals));
5825                         &define_pretty_variable ($one_name, $cond, @val);
5826                     }
5827                 }
5828             }
5830             if ($do_clean)
5831             {
5832                 $output_rules .=
5833                     &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go;'
5834                                                    . $cygxform,
5835                                                    $clean_file);
5837                 push (@clean, $X . $primary);
5838                 &push_phony_cleaners ($X . $primary);
5839             }
5841             if ($X eq 'check')
5842             {
5843                 push (@check, '$(' . $one_name . ')');
5844             }
5845             else
5846             {
5847                 push (@used, '$(' . $one_name . ')');
5848             }
5849             if ($X eq 'noinst' || $X eq 'check')
5850             {
5851                 # Objects which don't get installed by default.
5852                 next;
5853             }
5855             $output_rules .=
5856                 &file_contents_with_transform ('s/\@DIR\@/' . $X . '/g;'
5857                                                . $ltxform . $cygxform,
5858                                                $file);
5860             push (@uninstall, 'uninstall-' . $X . $primary);
5861             push (@phony, 'uninstall-' . $X . $primary);
5862             push (@installdirs, '$(' . $X . 'dir)');
5863             if (defined $exec_dir_p{$X} ? $exec_dir_p{$X} : ($X =~ /exec/))
5864             {
5865                 push (@install_exec, 'install-' . $X . $primary);
5866                 push (@phony, 'install-' . $X . $primary);
5867             }
5868             else
5869             {
5870                 push (@install_data, 'install-' . $X . $primary);
5871                 push (@phony, 'install-' . $X . $primary);
5872             }
5873         }
5874     }
5876     if (@used)
5877     {
5878         # Define it.
5879         &define_pretty_variable ($primary, '', @used);
5880         $output_vars .= "\n";
5881     }
5883     if ($require_extra && ! &variable_defined ('EXTRA_' . $primary))
5884     {
5885         &am_line_error ($require_extra,
5886                         "\`$require_extra' contains configure substitution, but \`EXTRA_$primary' not defined");
5887     }
5889     # Push here because PRIMARY might be configure time determined.
5890     push (@all, '$(' . $primary . ')')
5891         if @used;
5893     return (@result);
5897 ################################################################
5899 # This variable is local to the "require file" set of functions.
5900 @require_file_paths = ();
5902 # Verify that the file must exist in the current directory.  Usage:
5903 # require_file (isconfigure, line_number, strictness, file) strictness
5904 # is the strictness level at which this file becomes required.  Must
5905 # set require_file_paths before calling this function.
5906 # require_file_paths is set to hold a single directory (the one in
5907 # which the first file was found) before return.
5908 sub require_file_internal
5910     local ($is_configure, $line, $mystrict, @files) = @_;
5911     local ($file, $fullfile);
5912     local ($found_it, $errfile, $errdir);
5913     local ($save_dir);
5915     foreach $file (@files)
5916     {
5917         $found_it = 0;
5918         foreach $dir (@require_file_paths)
5919         {
5920             if ($dir eq '.')
5921             {
5922                 $fullfile = $relative_dir . "/" . $file;
5923                 $errdir = $relative_dir unless $errdir;
5924             }
5925             else
5926             {
5927                 $fullfile = $dir . "/" . $file;
5928                 $errdir = $dir unless $errdir;
5929             }
5931             # Use different name for "error filename".  Otherwise on
5932             # an error the bad file will be reported as eg
5933             # `../../install-sh' when using the default
5934             # config_aux_path.
5935             $errfile = $errdir . '/' . $file;
5937             if (-f $fullfile)
5938             {
5939                 $found_it = 1;
5940                 # FIXME: Once again, special-case `.'.
5941                 &push_dist_common ($file)
5942                     if $dir eq $relative_dir || $dir eq '.';
5943                 $save_dir = $dir;
5944                 last;
5945             }
5946         }
5948         if ($found_it)
5949         {
5950             # Prune the path list.
5951             @require_file_paths = $save_dir;
5952         }
5953         else
5954         {
5955             if ($strictness >= $mystrict)
5956             {
5957                 local ($trailer) = '';
5958                 local ($suppress) = 0;
5960                 # Only install missing files according to our desired
5961                 # strictness level.
5962                 local ($message) = "required file \`$errfile' not found";
5963                 if ($add_missing)
5964                 {
5965                     $suppress = 1;
5967                     # Maybe run libtoolize.
5968                     if ($seen_libtool
5969                         && grep ($_ eq $file, @libtoolize_files)
5970                         && system ('libtoolize', '--automake'))
5971                     {
5972                         $message = "installing \`$errfile'";
5973                         $suppress = 0;
5974                         $trailer = "; cannot run \`libtoolize': $!";
5975                     }
5976                     elsif (-f ($am_dir . '/' . $file))
5977                     {
5978                         # Install the missing file.  Symlink if we
5979                         # can, copy if we must.  Note: delete the file
5980                         # first, in case it is a dangling symlink.
5981                         $message = "installing \`$errfile'";
5982                         unlink ($errfile);
5983                         if ($symlink_exists)
5984                         {
5985                             if (! symlink ($am_dir . '/' . $file, $errfile))
5986                             {
5987                                 $suppress = 0;
5988                                 $trailer = "; error while making link: $!\n";
5989                             }
5990                         }
5991                         elsif (! system ('cp', $am_dir . '/' . $file, $errfile))
5992                         {
5993                             $suppress = 0;
5994                             $trailer = "\n    error while making link\n";
5995                         }
5996                     }
5997                 }
5999                 local ($save) = $exit_status;
6000                 if ($is_configure)
6001                 {
6002                     # FIXME: allow actual file to be specified.
6003                     &am_conf_line_error ('configure.in', $line,
6004                                          "$message$trailer");
6005                 }
6006                 else
6007                 {
6008                     &am_line_error ($line, "$message$trailer");
6009                 }
6010                 $exit_status = $save if $suppress;
6011             }
6012         }
6013     }
6016 # Like require_file_with_line, but error messages refer to
6017 # configure.in, not the current Makefile.am.
6018 sub require_file_with_conf_line
6020     @require_file_paths = '.';
6021     &require_file_internal (1, @_);
6024 sub require_file_with_line
6026     @require_file_paths = '.';
6027     &require_file_internal (0, @_);
6030 sub require_file
6032     @require_file_paths = '.';
6033     &require_file_internal (0, '', @_);
6036 # Require a file that is also required by Autoconf.  Looks in
6037 # configuration path, as specified by AC_CONFIG_AUX_DIR.
6038 sub require_config_file
6040     @require_file_paths = @config_aux_path;
6041     &require_file_internal (1, '', @_);
6042     local ($dir) = $require_file_paths[0];
6043     @config_aux_path = @require_file_paths;
6044     if ($dir eq '.')
6045     {
6046         $config_aux_dir = '.';
6047     }
6048     else
6049     {
6050         $config_aux_dir = '$(top_srcdir)/' . $dir;
6051     }
6054 # Assumes that the line number is in Makefile.am.
6055 sub require_conf_file_with_line
6057     @require_file_paths = @config_aux_path;
6058     &require_file_internal (0, @_);
6059     local ($dir) = $require_file_paths[0];
6060     @config_aux_path = @require_file_paths;
6061     if ($dir eq '.')
6062     {
6063         $config_aux_dir = '.';
6064     }
6065     else
6066     {
6067         $config_aux_dir = '$(top_srcdir)/' . $dir;
6068     }
6071 # Assumes that the line number is in Makefile.am.
6072 sub require_conf_file_with_conf_line
6074     @require_file_paths = @config_aux_path;
6075     &require_file_internal (1, @_);
6076     local ($dir) = $require_file_paths[0];
6077     @config_aux_path = @require_file_paths;
6078     if ($dir eq '.')
6079     {
6080         $config_aux_dir = '.';
6081     }
6082     else
6083     {
6084         $config_aux_dir = '$(top_srcdir)/' . $dir;
6085     }
6088 ################################################################
6090 # Push a list of files onto dist_common.
6091 sub push_dist_common
6093     local (@files) = @_;
6094     local ($file);
6096     foreach $file (@files)
6097     {
6098         $dist_common{$file} = 1;
6099     }
6102 # Push a list of clean targets onto phony.
6103 sub push_phony_cleaners
6105     local ($base) = @_;
6106     local ($target);
6107     foreach $target ('mostly', 'dist', '', 'maintainer-')
6108     {
6109         push (@phony, $target . 'clean-' . $base);
6110     }
6113 # Set strictness.
6114 sub set_strictness
6116     $strictness_name = $_[0];
6117     if ($strictness_name eq 'gnu')
6118     {
6119         $strictness = $GNU;
6120     }
6121     elsif ($strictness_name eq 'gnits')
6122     {
6123         $strictness = $GNITS;
6124     }
6125     elsif ($strictness_name eq 'foreign')
6126     {
6127         $strictness = $FOREIGN;
6128     }
6129     else
6130     {
6131         die "automake: level \`$strictness_name' not recognized\n";
6132     }
6136 ################################################################
6138 # Return directory name of file.
6139 sub dirname
6141     local ($file) = @_;
6142     local ($sub);
6144     ($sub = $file) =~ s,/+[^/]+$,,g;
6145     $sub = '.' if $sub eq $file;
6146     return $sub;
6149 # Return file name of a file.
6150 sub basename
6152     local ($file) = @_;
6153     local ($sub);
6155     ($sub = $file) =~s,^.*/+,,g;
6156     return $sub;
6159 # Touch a file.
6160 sub touch
6162     local ($file) = @_;
6164     open (TOUCH, ">> $file");
6165     close (TOUCH);
6168 # Glob something.  Do this to avoid indentation screwups everywhere we
6169 # want to glob.  Gross!
6170 sub my_glob
6172     local ($pat) = @_;
6173     return <${pat}>;
6176 ################################################################
6178 # Print an error message and set exit status.
6179 sub am_error
6181     warn "automake: ${am_file}.am: ", join (' ', @_), "\n";
6182     $exit_status = 1;
6185 sub am_line_error
6187     local ($symbol, @args) = @_;
6189     if ($symbol && "$symbol" ne '-1')
6190     {
6191         # If SYMBOL not already a line number, look it up in Makefile.am.
6192         if ($symbol =~ /^\d+$/)
6193         {
6194             $symbol .= ': ';
6195         }
6196         elsif (defined $content_lines{$symbol})
6197         {
6198             $symbol = $content_lines{$symbol} . ': ';
6199         }
6200         else
6201         {
6202             # A single space, to provide nice separation.
6203             $symbol = ' ';
6204         }
6205         warn "${am_file}.am:", $symbol, join (' ', @args), "\n";
6206         $exit_status = 1;
6207     }
6208     else
6209     {
6210         &am_error (@args);
6211     }
6214 # Like am_error, but while scanning configure.in.
6215 sub am_conf_error
6217     # FIXME: can run in subdirs.
6218     warn "automake: configure.in: ", join (' ', @_), "\n";
6219     $exit_status = 1;
6222 # Error message with line number referring to configure.in.
6223 sub am_conf_line_error
6225     local ($file, $line, @args) = @_;
6227     if ($line)
6228     {
6229         warn "$file: $line: ", join (' ', @args), "\n";
6230         $exit_status = 1;
6231     }
6232     else
6233     {
6234         &am_conf_error (@args);
6235     }
6238 # Tell user where our aclocal.m4 is, but only once.
6239 sub keyed_aclocal_warning
6241     local ($key) = @_;
6242     warn "automake: macro \`$key' can be generated by \`aclocal'\n";
6245 # Print usage information.
6246 sub usage
6248     print "Usage: automake [OPTION] ... [Makefile]...\n\n";
6249     print "Generate Makefile.in for autoconf from Makefile.am\n";
6250     print $USAGE;
6251     print "\nFiles which are automatically distributed, if found:\n";
6252     $~ = "USAGE_FORMAT";
6253     local (@lcomm) = sort ((@common_files, @common_sometimes));
6254     local ($one, $two, $three, $four);
6255     while (@lcomm > 0)
6256     {
6257         $one = shift @lcomm;
6258         $two = @lcomm ? shift @lcomm : '';
6259         $three = @lcomm ? shift @lcomm : '';
6260         $four = @lcomm ? shift @lcomm : '';
6261         write;
6262     }
6264     print "\nReport bugs to <automake-bugs\@gnu.ai.mit.edu>.\n";
6266     exit 0;
6269 format USAGE_FORMAT =
6270   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
6271   $one,               $two,               $three,             $four