remake bugs reported by Phil Nelson
[automake.git] / automake.in
blob47c56f1472ee35b80c10f9a359c08f46c229c0ce
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 $MACRO_PATTERN = "^([A-Za-z][A-Za-z0-9_]*)[ \t]*:?=[ \t]*(.*)\$";
44 $BOGUS_MACRO_PATTERN = "^([^ \t]*)[ \t]*:?=[ \t]*(.*)\$";
45 $GNITS_VERSION_PATTERN = "[0-9]+\\.[0-9]+([a-z]|\\.[0-9]+)?";
47 # Some regular expressions.  One reason to put them here is that it
48 # makes indentation work better in Emacs.
49 $AC_CONFIG_AUX_DIR_PATTERN = "AC_CONFIG_AUX_DIR\\(([^)]+)\\)";
50 $AM_INIT_AUTOMAKE_PATTERN = "AM_INIT_AUTOMAKE\\([^,]*,([^,)]+)[,)]";
51 $AM_PACKAGE_VERSION_PATTERN = "^\\s*\\[?([^]\\s]+)\\]?\\s*\$";
52 # Note that there is no AC_PATH_TOOL.  But we don't really care.
53 $AC_CHECK_PATTERN = "AC_(CHECK|PATH)_(PROG|PROGS|TOOL)\\(\\[?(\\w+)";
54 $AM_MISSING_PATTERN = "AM_MISSING_PROG\\(\\[?(\\w+)";
55 # Just check for alphanumeric in AC_SUBST.  If you do AC_SUBST(5),
56 # then too bad.
57 $AC_SUBST_PATTERN = "AC_SUBST\\(\\[?(\\w+)";
59 # Constants to define the "strictness" level.
60 $FOREIGN = 0;
61 $GNU = 1;
62 $GNITS = 2;
66 # Variables global to entire run.
68 # TRUE if we should always generate Makefile.in.
69 $force_generation = 1;
71 # Strictness level as set on command line.
72 $default_strictness = $GNU;
74 # Name of strictness level, as set on command line.
75 $default_strictness_name = 'gnu';
77 # This is TRUE if GNU make specific automatic dependency generation
78 # code should be included in generated Makefile.in.
79 $cmdline_use_dependencies = 1;
81 # TRUE if in verbose mode.
82 $verbose = 0;
84 # This holds our (eventual) exit status.  We don't actually exit until
85 # we have processed all input files.
86 $exit_status = 0;
88 # From the Perl manual.
89 $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
91 # TRUE if missing standard files should be installed.
92 $add_missing = 0;
94 # Files found by scanning configure.in for LIBOBJS.
95 %libsources = ();
97 # True if AM_C_PROTOTYPES appears in configure.in.
98 $am_c_prototypes = 0;
100 # Names used in AC_CONFIG_HEADER call.  @config_fullnames holds the
101 # name which appears in AC_CONFIG_HEADER, colon and all.
102 # @config_names holds the file names.  @config_headers holds the '.in'
103 # files.  Ordinarily these are similar, but they can be different if
104 # the weird "NAME:FILE" syntax is used.
105 @config_fullnames = ();
106 @config_names = ();
107 @config_headers = ();
108 # Line number at which AC_CONFIG_HEADER appears in configure.in.
109 $config_header_line = 0;
111 # Directory where output files go.  Actually, output files are
112 # relative to this directory.
113 $output_directory = '.';
115 # Relative location of top build directory.
116 $top_builddir = '';
118 # Absolute location of top build directory.
119 $build_directory = '';
121 # Name of srcdir as given in build directory's Makefile.  For
122 # dependencies only.
123 $srcdir_name = '';
125 # List of Makefile.am's to process, and their corresponding outputs.
126 @input_files = ();
127 %output_files = ();
129 # List of files in AC_OUTPUT without Makefile.am, and their outputs.
130 @other_input_files = ();
131 # Line number at which AC_OUTPUT seen.
132 $ac_output_line = 0;
134 # List of directories to search for configure-required files.  This
135 # can be set by AC_CONFIG_AUX_DIR.
136 @config_aux_path = ('.', '..', '../..');
137 $config_aux_dir = '';
139 # Whether AC_PROG_MAKE_SET has been seen in configure.in.
140 $seen_make_set = 0;
142 # Whether AM_GNU_GETTEXT has been seen in configure.in.
143 $seen_gettext = 0;
144 # Line number at which AM_GNU_GETTEXT seen.
145 $ac_gettext_line = 0;
147 # Whether ALL_LINGUAS has been seen.
148 $seen_linguas = '';
149 # The actual text.
150 $all_linguas = '';
151 # Line number at which it appears.
152 $all_linguas_line = 0;
154 # 1 if AC_PROG_INSTALL seen, 2 if AM_PROG_INSTALL seen.
155 $seen_prog_install = 0;
157 # 1 if any scripts installed, 0 otherwise.
158 $scripts_installed = 0;
160 # Whether AC_PATH_XTRA has been seen in configure.in.
161 $seen_path_xtra = 0;
163 # TRUE if AC_DECL_YYTEXT was seen.
164 $seen_decl_yytext = 0;
166 # TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM).  The presence of
167 # AC_CHECK_TOOL also sets this.
168 $seen_canonical = 0;
170 # TRUE if we've seen AC_ARG_PROGRAM.
171 $seen_arg_prog = 0;
173 # TRUE if we've seen AM_PROG_LIBTOOL.
174 $seen_libtool = 0;
175 $libtool_line = 0;
177 # Files installed by libtoolize.
178 @libtoolize_files = ('ltconfig', 'ltmain.sh', 'config.guess', 'config.sub');
180 # TRUE if we've seen AM_MAINTAINER_MODE.
181 $seen_maint_mode = 0;
183 # TRUE if we've seen PACKAGE and VERSION.
184 $seen_package = 0;
185 $seen_version = 0;
187 # Actual version we've seen.
188 $package_version = '';
190 # Line number where we saw version definition.
191 $package_version_line = 0;
193 # TRUE if we've seen AM_PATH_LISPDIR.
194 $seen_lispdir = 0;
196 # TRUE if we've seen AM_CYGWIN32.
197 $seen_cygwin32 = 0;
199 # Hash table of discovered configure substitutions.  Keys are names,
200 # values are meaningless.
201 %configure_vars = ();
203 # Charsets used by maintainer and in distribution.  MAINT_CHARSET is
204 # handled in a funny way: if seen in the top-level Makefile.am, it is
205 # used for every directory which does not specify a different value.
206 # The rationale here is that some directories (eg gettext) might be
207 # distributions of other packages, and thus require their own charset
208 # info.  However, the DIST_CHARSET must be the same for the entire
209 # package; it can only be set at top-level.
210 # FIXME: this yields bugs when rebuilding.  What to do?  Always
211 # read (and sometimes discard) top-level Makefile.am?
212 $maint_charset = '';
213 $dist_charset = 'utf8';         # recode doesn't support this yet.
215 # Name of input file ("Makefile.in") and output file ("Makefile.am").
216 # These have no directory components.
217 $am_file_name = '';
218 $in_file_name = '';
220 # TRUE if --cygnus seen.
221 $cygnus_mode = 0;
223 # Keys of this hash are names of dependency files to ignore.
224 %omit_dependencies = ();
226 # Map from obsolete macros to hints for new macros.
227 # FIXME complete the list so that there are no `0' hints.
228 %obsolete_macros =
229     (
230      'AC_FEATURE_CTYPE', "use \`AC_HEADER_STDC'",
231      'AC_FEATURE_ERRNO', "add \`strerror' to \`AC_REPLACE_FUNCS(...)'",
232      'AC_FEATURE_EXIT', 0,
233      'AC_SYSTEM_HEADER', 0,
235      # Note that we do not handle this one, because it is still run
236      # from AM_CONFIG_HEADER.  So we deal with it specially in
237      # scan_configure.
238      # 'AC_CONFIG_HEADER', "use \`AM_CONFIG_HEADER'",
240      'fp_C_PROTOTYPES', "use \`AM_C_PROTOTYPES'",
241      'fp_PROG_CC_STDC', "use \`AM_PROG_CC_STDC'",
242      'fp_PROG_INSTALL', "use \`AM_PROG_INSTALL'",
243      'fp_WITH_DMALLOC', "use \`AM_WITH_DMALLOC'",
244      'fp_WITH_REGEX', "use \`AM_WITH_REGEX'",
245      'gm_PROG_LIBTOOL', "use \`AM_PROG_LIBTOOL'",
246      'jm_MAINTAINER_MODE', "use \`AM_MAINTAINER_MODE'",
247      'md_TYPE_PTRDIFF_T', "use \`AM_TYPE_PTRDIFF_T'",
248      'ud_PATH_LISPDIR', "use \`AM_PATH_LISPDIR'",
250      # Now part of autoconf proper, under a different name.
251      'AM_FUNC_FNMATCH', "use \`AC_FUNC_FNMATCH'",
252      'fp_FUNC_FNMATCH', "use \`AC_FUNC_FNMATCH'",
253      'AM_SANITY_CHECK_CC', "automatically done by \`AC_PROG_CC'",
255 # These aren't quite obsolete.
256 #      'md_PATH_PROG',
257      );
259 # Regexp to match the above macros.
260 $obsolete_rx = '(' . join ('|', keys %obsolete_macros) . ')';
264 &initialize_global_constants;
266 # Parse command line.
267 &parse_arguments (@ARGV);
269 # Do configure.in scan only once.
270 &scan_configure;
272 die "automake: no \`Makefile.am' found or specified\n"
273     if ! @input_files;
275 # Now do all the work on each file.
276 foreach $am_file (@input_files)
278     if (! -f ($am_file . '.am'))
279     {
280         &am_error ("\`" . $am_file . ".am' does not exist");
281     }
282     else
283     {
284         &generate_makefile ($output_files{$am_file}, $am_file);
285     }
288 if ($seen_prog_install <= $scripts_installed)
290     &am_conf_error (($scripts_installed ? 'AM_PROG_INSTALL' : 'AC_PROG_INSTALL')
291                     . " must be used in configure.in");
292     &keyed_aclocal_warning ('AM_PROG_INSTALL')
293         if $scripts_installed;
296 exit $exit_status;
299 ################################################################
301 # Parse command line.
302 sub parse_arguments
304     local (@arglist) = @_;
306     # Start off as gnu.
307     &set_strictness ('gnu');
309     while (@arglist)
310     {
311         if ($arglist[0] eq "--version")
312         {
313             print "automake (GNU $PACKAGE) $VERSION\n\n";
314             print "Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.\n";
315             print "This is free software; see the source for copying conditions.  There is NO\n";
316             print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n";
317             print "Written by Tom Tromey <tromey\@cygnus.com>\n";
319             exit 0;
320         }
321         elsif ($arglist[0] eq "--help")
322         {
323             &usage;
324         }
325         elsif ($arglist[0] =~ /^--amdir=(.+)$/)
326         {
327             $am_dir = $1;
328         }
329         elsif ($arglist[0] eq '--amdir')
330         {
331             &require_argument (@arglist);
332             shift (@arglist);
333             $am_dir = $arglist[0];
334         }
335         elsif ($arglist[0] =~ /^--build-dir=(.+)$/)
336         {
337             # Must end in /.
338             $build_directory = $1 . '/';
339         }
340         elsif ($arglist[0] eq '--build-dir')
341         {
342             &require_argument (@arglist);
343             shift (@arglist);
344             # Must end in /.
345             $build_directory = $arglist[0] . '/';
346         }
347         elsif ($arglist[0] =~ /^--srcdir-name=(.+)$/)
348         {
349             $srcdir_name = $1;
350         }
351         elsif ($arglist[0] eq '--srcdir-name')
352         {
353             &require_argument (@arglist);
354             shift (@arglist);
355             $srcdir_name = $arglist[0];
356         }
357         elsif ($arglist[0] eq '--gnu')
358         {
359             &set_strictness ('gnu');
360         }
361         elsif ($arglist[0] eq '--gnits')
362         {
363             &set_strictness ('gnits');
364         }
365         elsif ($arglist[0] eq '--cygnus')
366         {
367             $cygnus_mode = 1;
368         }
369         elsif ($arglist[0] eq '--foreign')
370         {
371             &set_strictness ('foreign');
372         }
373         elsif ($arglist[0] eq '--include-deps' || $arglist[0] eq '-i')
374         {
375             $cmdline_use_dependencies = 0;
376         }
377         elsif ($arglist[0] eq '--no-force')
378         {
379             $force_generation = 0;
380         }
381         elsif ($arglist[0] =~ /^--output-dir=(.*)$/)
382         {
383             # Set output directory.
384             $output_directory = $1;
385         }
386         elsif ($arglist[0] eq '--output-dir' || $arglist[0] eq '-o')
387         {
388             &require_argument (@arglist);
389             shift (@arglist);
390             $output_directory = $arglist[0];
391         }
392         elsif ($arglist[0] eq '--add-missing' || $arglist[0] eq '-a')
393         {
394             $add_missing = 1;
395         }
396         elsif ($arglist[0] eq '--verbose' || $arglist[0] eq '-v')
397         {
398             $verbose = 1;
399         }
400         elsif ($arglist[0] eq '--')
401         {
402             # Stop option processing.
403             shift (@arglist);
404             push (@input_files, @arglist);
405             last;
406         }
407         elsif ($arglist[0] =~ /^-/)
408         {
409             die "automake: unrecognized option -- \`$arglist[0]'\nTry \`automake --help' for more information.\n";
410         }
411         else
412         {
413             # Handle $local:$input syntax.  Note that we only examine
414             # the first ":" file to see if it is automake input; the
415             # rest are just taken verbatim.  We still keep all the
416             # files around for dependency checking, however.
417             local ($local, $input, @rest) = split (/:/, $arglist[0]);
418             if (! $input)
419             {
420                 $input = $local;
421             }
422             else
423             {
424                 # Strip .in; later on .am is tacked on.  That is how
425                 # the automake input file is found.  Maybe not the
426                 # best way, but it is easy to explain.  FIXME: should
427                 # be error if .in is missing.
428                 $input =~ s/\.in$//;
429             }
430             push (@input_files, $input);
431             $output_files{$input} = join (':', ($local, @rest));
432         }
434         shift (@arglist);
435     }
437     # Take global strictness from whatever we currently have set.
438     $default_strictness = $strictness;
439     $default_strictness_name = $strictness_name;
442 # Ensure argument exists, or die.
443 sub require_argument
445     local ($arg, @arglist) = @_;
446     die "automake: no argument given for option \`$arg'\n"
447         if ! @arglist;
450 ################################################################
452 # Generate a Makefile.in given the name of the corresponding Makefile and
453 # the name of the file output by config.status.
454 sub generate_makefile
456     local ($output, $makefile) = @_;
458     ($am_file_name = $makefile) =~ s/^.*\///;
459     $in_file_name = $am_file_name . '.in';
460     $am_file_name .= '.am';
462     # $OUTPUT is encoded.  If it contains a ":" then the first element
463     # is the real output file, and all remaining elements are input
464     # files.  We don't scan or otherwise deal with these input file,
465     # other than to mark them as dependencies.  See scan_configure for
466     # details.
467     local (@secondary_inputs);
468     ($output, @secondary_inputs) = split (/:/, $output);
470     &initialize_per_input;
471     $relative_dir = &dirname ($output);
472     $am_relative_dir = &dirname ($makefile);
474     # At the toplevel directory, we might need config.guess, config.sub
475     # or libtool scripts (ltconfig and ltmain.sh).
476     if ($relative_dir eq '.')
477     {
478         # libtool requires some files.
479         &require_conf_file_with_conf_line ($libtool_line, $FOREIGN,
480                                            @libtoolize_files)
481             if $seen_libtool;
483         # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
484         # config.sub.
485         &require_config_file ($FOREIGN, 'config.guess', 'config.sub')
486             if $seen_canonical;
487     }
489     # We still need Makefile.in here, because sometimes the `dist'
490     # target doesn't re-run automake.
491     if ($am_relative_dir eq $relative_dir)
492     {
493         # Only distribute the files if they are in the same subdir as
494         # the generated makefile.
495         &push_dist_common ($in_file_name, $am_file_name);
496     }
497     push (@sources, '$(SOURCES)')
498         if &variable_defined ('SOURCES');
499     push (@objects, '$(OBJECTS)')
500         if &variable_defined ('OBJECTS');
502     # This is always the default target.  This gives us freedom to do
503     # things in whatever order is convenient.  Note that we set up
504     # $output_header here so that we can insert some text just after
505     # the "default" target, but before any other targets.  In
506     # particular we want to support the .SUFFIX hack here; this is
507     # documented elsewhere.
508     $output_header = "default: all\n\n";
509     push (@phony, 'default');
511     &read_am_file ($makefile . '.am');
512     if (&handle_options)
513     {
514         # Fatal error.  Just return, so we can continue with next file.
515         return;
516     }
518     # Check first, because we might modify some state.
519     &check_cygnus;
520     &check_gnu_standards;
521     &check_gnits_standards;
523     &handle_configure ($output, $makefile, @secondary_inputs);
524     &handle_gettext;
525     &handle_libraries;
526     &handle_ltlibraries;
527     &handle_programs;
528     &handle_scripts;
530     &handle_built_sources;
532     # This must be run after all the sources are scanned.
533     &handle_yacc_lex_cxx;
535     # Re-init SOURCES and OBJECTS.  FIXME: other code shouldn't depend
536     # on this (but currently does).
537     $contents{'SOURCES'} = join (' ', @sources);
538     $contents{'OBJECTS'} = join (' ', @objects);
540     &handle_texinfo;
541     &handle_emacs_lisp;
542     &handle_man_pages;
543     &handle_data;
544     &handle_headers;
545     &handle_subdirs;
546     &handle_tags;
547     &handle_dist;
548     &handle_dependencies;
549     &handle_tests;
550     &handle_footer;
551     &handle_merge_targets ($makefile);
552     &handle_installdirs;
553     &handle_clean;
554     &handle_phony;
556     &check_typos;
558     if (! -d ($output_directory . '/' . $am_relative_dir))
559     {
560         mkdir ($output_directory . '/' . $am_relative_dir, 0755);
561     }
563     local ($out_file) = $output_directory . '/' . $makefile . ".in";
564     if (! $force_generation && -e $out_file)
565     {
566         local ($am_time) = (stat ($makefile . '.am'))[9];
567         local ($in_time) = (stat ($out_file))[9];
568         # FIXME: how to do unsigned comparison?
569         if ($am_time < $in_time)
570         {
571             # No need to update.
572             return;
573         }
574     }
576     if (! open (GM_FILE, "> " . $out_file))
577     {
578         warn "automake: ${am_file}.in: cannot open: $!\n";
579         $exit_status = 1;
580         return;
581     }
582     print "automake: creating ", $makefile, ".in\n" if $verbose;
584     print GM_FILE $output_vars;
585     print GM_FILE $output_header;
586     print GM_FILE $output_rules;
587     print GM_FILE $output_trailer;
589     close (GM_FILE);
592 ################################################################
594 # Handle AUTOMAKE_OPTIONS variable.  Return 1 on error, 0 otherwise.
595 sub handle_options
597     return 0 if ! &variable_defined ('AUTOMAKE_OPTIONS');
599     foreach (&variable_value_as_list ('AUTOMAKE_OPTIONS'))
600     {
601         $options{$_} = 1;
602         if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
603         {
604             &set_strictness ($_);
605         }
606         elsif (/ansi2knr/)
607         {
608             # An option like "../lib/ansi2knr" is allowed.  With no
609             # path prefix, we assume the required programs are in this
610             # directory.  We save the actual option for later.
611             $options{'ansi2knr'} = $_;
612         }
613         elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
614                || $_ eq 'dist-shar' || $_ eq 'dist-zip'
615                || $_ eq 'dist-tarZ' || $_ eq 'dejagnu'
616                || $_ eq 'no-texinfo.tex')
617         {
618             # Explicitly recognize these.
619         }
620         elsif ($_ eq 'no-dependencies')
621         {
622             $use_dependencies = 0;
623         }
624         elsif (/([0-9]+)\.([0-9]+)/)
625         {
626             # Got a version number.  Note that alpha releases count as
627             # the next higher release.  Note also that we assume there
628             # will be a maximum of 100 minor releases for any given
629             # major release.
630             local ($rmajor, $rminor) = ($1, $2);
631             if ($VERSION !~ /([0-9]+)\.([0-9]+)([a-z])?/)
632             {
633                 print STDERR
634                     "automake: programming error: version is incorrect\n";
635                 exit 1;
636             }
637             local ($tmajor, $tminor) = ($1, $2);
638             # Handle alpha versions.
639             ++$tminor if defined $3;
641             if ($rmajor > $tmajor || ($rmajor == $tmajor && $rminor > $tminor))
642             {
643                 &am_line_error ('AUTOMAKE_OPTIONS',
644                                 "require version $_, only have $VERSION");
645                 return 1;
646             }
647         }
648         else
649         {
650             &am_line_error ('AUTOMAKE_OPTIONS',
651                             'option ', $_, 'not recognized');
652         }
653     }
655     return 0;
658 # Return object extension.  Just once, put some code into the output.
659 # Argument is the name of the output file
660 sub get_object_extension
662     local ($out) = @_;
664     # Always set this.
665     $dir_holds_sources = 1;
667     # Maybe require libtool library object files.
668     local ($l, $extension) = ('', 'o');
669     $l = 'l' if ($out =~ /^lib.*\.la$/);
671     if (! $included_generic_compile)
672     {
673         # Boilerplate.
674         local ($xform) = '';
675         if (&variable_defined ('CONFIG_HEADER'))
676         {
677             local ($one_hdr);
678             foreach $one_hdr (split (' ', $contents{'CONFIG_HEADER'}))
679             {
680                 local ($var);
681                 ($var = &dirname ($one_hdr)) =~ s/(\W)/\\$1/g;
682                 $xform .= ' ' if $xform;
683                 $xform .= '-I' . $var;
684             }
685         }
686         $xform = 's/\@CONFIG_INCLUDE_SPEC\@/' . $xform . '/go;';
687         $output_vars .= &file_contents_with_transform ($xform,
688                                                        'comp-vars');
689         $output_rules .= &file_contents ('compile');
690         &push_phony_cleaners ('compile');
692         # If using X, include some extra variable definitions.  NOTE
693         # we don't want to force these into CFLAGS or anything,
694         # because not all programs will necessarily use X.
695         if ($seen_path_xtra)
696         {
697             local ($var);
698             foreach $var ('X_CFLAGS', 'X_LIBS', 'X_EXTRA_LIBS', 'X_PRE_LIBS')
699             {
700                 &define_configure_variable ($var);
701             }
702         }
704         push (@suffixes, '.c', '.o');
705         push (@clean, 'compile');
707         $included_generic_compile = 1;
708     }
710     if ($seen_libtool && ! $included_libtool_compile)
711     {
712         # Output the libtool compilation rules.
713         $output_rules .= &file_contents ('libtool');
714         &push_phony_cleaners ('libtool');
716         push (@suffixes, '.lo');
717         push (@clean, 'libtool');
719         $included_libtool_compile = 1;
720     }
722     # Check for automatic de-ANSI-fication.
723     if (defined $options{'ansi2knr'})
724     {
725         $extension = '$o';
726         if (! $included_knr_compile)
727         {
728             if (! $am_c_prototypes)
729             {
730                 &am_line_error ('AUTOMAKE_OPTIONS',
731                                 "option \`ansi2knr' in use but \`AM_C_PROTOTYPES' not in configure.in");
732                 &keyed_aclocal_warning ('AM_C_PROTOTYPES');
733                 # Only give this error once.
734                 $am_c_prototypes = 1;
735             }
737             push (@suffixes, '._c', '._o');
738             push (@suffixes, '.l_o') if $seen_libtool;
740             # Only require ansi2knr files if they should appear in
741             # this directory.
742             if ($options{'ansi2knr'} eq 'ansi2knr')
743             {
744                 &require_file_with_line ('AUTOMAKE_OPTIONS', $FOREIGN,
745                                          'ansi2knr.c', 'ansi2knr.1');
746                 $output_rules .= &file_contents ('kr-extra');
747                 push (@clean, 'krextra');
748                 &push_phony_cleaners ('krextra');
749             }
751             # Generate rules to build ansi2knr.  If it is in some
752             # other directory, then generate dependencies but have the
753             # rule just run elsewhere.
754             $output_rules .= ($options{'ansi2knr'} . ': '
755                               . $options{'ansi2knr'} . ".o\n");
756             if ($options{'ansi2knr'} eq 'ansi2knr')
757             {
758                 $output_rules .= ("\t\$(LINK) ansi2knr.o \$(LIBS)\n"
759                                   . "ansi2knr.o: \$(CONFIG_HEADER)\n\n");
760             }
761             else
762             {
763                 $output_rules .= ("\tcd " . &dirname ($options{'ansi2knr'})
764                                   . " && \$(MAKE) ansi2knr\n\n");
765             }
767             &define_variable ('o', "\@U\@o");
769             # Make sure ansi2knr can be found: if no path specified,
770             # specify "./".
771             if ($options{'ansi2knr'} eq 'ansi2knr')
772             {
773                 # Substitution from AM_C_PROTOTYPES.  This makes it be
774                 # built only when necessary.
775                 &define_configure_variable ('ANSI2KNR');
776                 # ansi2knr needs to be built before subdirs, so unshift it.
777                 unshift (@all, '$(ANSI2KNR)');
778             }
779             else
780             {
781                 # Found in another directory.
782                 &define_variable ("ANSI2KNR", &dirname ($options{'ansi2knr'}));
783             }
785             $output_rules .= &file_contents ('compile-kr');
786             $output_rules .= &file_contents ('clean-kr');
788             push (@clean, 'kr');
789             &push_phony_cleaners ('kr');
791             $included_knr_compile = 1;
792         }
793     }
795     return '.' . $l . $extension;
798 # Handle yacc and lex.
799 sub handle_yacc_lex_cxx
801     #
802     # First do yacc and lex.
803     #
805     local ($yacc_count) = scalar (keys %yacc_sources);
806     local ($lex_count) = scalar (keys %lex_sources);
808     if ($yacc_count)
809     {
810         local (%seen_suffix) = ();
811         foreach (keys %yacc_sources)
812         {
813             /(\..*)$/;
814             &output_yacc_build_rule ($1, $yacc_count > 1)
815                 if (! defined $seen_suffix{$1});
816             $seen_suffix{$1} = 1;
817         }
819         if (! defined $configure_vars{'YACC'})
820         {
821             &am_error ("yacc source seen but \`YACC' not defined in \`configure.in'");
822         }
823     }
824     if ($lex_count)
825     {
826         local (%seen_suffix) = ();
827         foreach (keys %lex_sources)
828         {
829             /(\..*)$/;
830             &output_lex_build_rule ($1, $lex_count > 1)
831                 if (! defined $seen_suffix{$1});
832             $seen_suffix{$1} = 1;
833         }
835         if (! defined $configure_vars{'LEX'})
836         {
837             &am_error ("lex source seen but \`LEX' not defined in \`configure.in'");
838         }
839         if (! $seen_decl_yytext)
840         {
841             &am_error ("lex source seen but \`AC_DECL_YYTEXT' not in \`configure.in'");
842         }
843     }
845     if ($yacc_count > 1 || $lex_count > 1)
846     {
847         # If there is more than one distinct yacc (resp lex) source
848         # file in a given directory, then the `interlock' program is
849         # required to allow parallel builds to work correctly.  FIXME:
850         # for now, no line number.
851         &require_config_file ($FOREIGN, 'interlock', 'ylwrap');
852         if ($config_aux_dir ne '.' && $config_aux_dir ne '')
853         {
854                 &define_variable ('INTERLOCK', $config_aux_dir . "/interlock");
855                 &define_variable ('YLWRAP', $config_aux_dir . "/ylwrap");
856         }
857         else
858         {
859                 &define_variable ('INTERLOCK', '$(srcdir)/interlock');
860                 &define_variable ('YLWRAP', '$(srcdir)/ylwrap');
861         }
862     }
864     #
865     # Handle libtool.
866     #
867     local ($ltcompile, $ltlink) = ('', '');
868     if ($seen_libtool)
869     {
870         &define_configure_variable ("LIBTOOL");
871         $ltcompile = '$(LIBTOOL) --mode=compile ';
872         $ltlink = '$(LIBTOOL) --mode=link ';
873     }
875     #
876     # Now handle C++.
877     #
878     local (@cxx_list) = keys %cxx_extensions;
879     local ($cxx_count) = scalar @cxx_list;
880     if ($cxx_count)
881     {
882         push (@suffixes, @cxx_list);
884         &define_configure_variable ("CXXFLAGS");
885         &define_variable ('CXXCOMPILE', '$(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)');
886         &define_variable ('LTCXXCOMPILE',
887                           $ltcompile . '$(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)')
888             if ($seen_libtool);
890         &define_variable ('CXXLINK', $ltlink . '$(CXX) $(LDFLAGS) -o $@');
892         local ($ext);
893         foreach $ext (@cxx_list)
894         {
895             $output_rules .= ("$ext.o:\n"
896                               . "\t\$(CXXCOMPILE) -c \$<\n");
897             $output_rules .= ("$ext.lo:\n"
898                               . "\t\$(LTCXXCOMPILE) -c \$<\n")
899                 if ($seen_libtool);
900         }
902         if (! defined $configure_vars{'CXX'})
903         {
904             &am_error ("C++ source seen but \`CXX' not defined in \`configure.in'");
905         }
906     }
908     #
909     # Handle some ansi2knr cleanup.
910     #
911     if (defined $options{'ansi2knr'} && keys %de_ansi_objects)
912     {
913         # Make all ._o files depend on ansi2knr.  Use a sneaky little
914         # hack to make it print nicely.
915         &pretty_print_rule ('', '', ((sort keys %de_ansi_objects),
916                                      ':', '$(ANSI2KNR)'));
917         # The ._c files also depend on ansi2knr.  We need both because
918         # some makes don't apply transitivity through implicit rules.
919         local (%de_ansi_sources, $x);
920         foreach $x (keys %de_ansi_objects)
921         {
922             $x =~ s/o$/c/;
923             $de_ansi_sources{$x} = 1;
924         }
925         &pretty_print_rule ('', '', ((sort keys %de_ansi_sources),
926                                      ':', '$(ANSI2KNR)'));
927     }
929     #
930     # Last, handle some C cleanup.
931     #
932     if ($seen_c_source)
933     {
934         &define_configure_variable ('CFLAGS');
935         &define_variable ('COMPILE',
936                           '$(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)');
937         &define_variable ('LTCOMPILE',
938                           $ltcompile .
939                           '$(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)')
940             if ($seen_libtool);
941         &define_variable ('LINK', $ltlink . '$(CC) $(LDFLAGS) -o $@');
943         if (! defined $configure_vars{'CC'})
944         {
945             &am_line_error ($seen_c_source,
946                             "C source seen but \`CC' not defined in \`configure.in'");
947         }
948     }
952 # Output a rule to build from a YACC source.  The output from YACC is
953 # compiled with C or C++, depending on the extension of the YACC file.
954 sub output_yacc_build_rule
956     local ($yacc_suffix, $use_interlock, $c_suffix) = @_;
958     local ($c_suffix, $suffix);
959     ($c_suffix = $yacc_suffix) =~ tr/y/c/;
960     push (@suffixes, $yacc_suffix, $c_suffix, '.h');
962     # Generate rule for c/c++ and header file.  Probably should only
963     # do header if `yacc -d' is run.
964     foreach $suffix ($c_suffix, '.h')
965     {
966         $output_rules .= "$yacc_suffix$suffix:\n\t";
968         if ($use_interlock)
969         {
970             $output_rules .= ('$(SHELL) $(INTERLOCK) =yacclockdir $(YLWRAP)'
971                               . ' "$(YACC)" y.tab.c $*' . $suffix
972                               . ' y.tab.h $*.h -- $(YFLAGS) $<');
973         }
974         else
975         {
976             $output_rules .= ('$(YACC) $(YFLAGS) $< && mv y.tab.c $@' . "\n"
977                               . "\tif test -f y.tab.h; then \\\n"
978                               . "\tif cmp -s y.tab.h \$*.h; then rm -f y.tab.h; else mv y.tab.h \$*.h; fi; \\\n"
979                           . "\telse :; fi");
980         }
981         $output_rules .= "\n";
982     }
985 sub output_lex_build_rule
987     local ($lex_suffix, $use_interlock) = @_;
988     local ($c_suffix);
990     ($c_suffix = $lex_suffix) =~ tr/l/c/;
991     push (@suffixes, $lex_suffix);
992     &define_configure_variable ('LEX_OUTPUT_ROOT');
993     &define_configure_variable ('LEXLIB');
994     $output_rules .= "$lex_suffix$c_suffix:\n\t";
996     if ($use_interlock)
997     {
998         # is the $@ correct here?  If so, why not use it in the
999         # interlock build rule for yacc above?
1000         $output_rules .= '$(SHELL) $(INTERLOCK) =lexlockdir $(YLWRAP)'
1001             . ' "$(LEX)" $(LEX_OUTPUT_ROOT).c $@ -- $(LFLAGS) $<';
1002     }
1003     else
1004     {
1005         $output_rules .= '$(LEX) $(LFLAGS) $< && mv $(LEX_OUTPUT_ROOT).c $@';
1006     }
1007     $output_rules .= "\n";
1011 # Check to make sure a source defined in LIBOBJS is not explicitly
1012 # mentioned.  This is a separate function (as opposed to being inlined
1013 # in handle_source_transform) because it isn't always appropriate to
1014 # do this check.
1015 sub check_libobjs_sources
1017     local ($one_file, $unxformed) = @_;
1019     local ($prefix, $file, @files);
1020     foreach $prefix ('', 'EXTRA_')
1021     {
1022         if (&variable_defined ($prefix . $one_file . '_SOURCES'))
1023         {
1024             @files = &variable_value_as_list ($prefix
1025                                               . $one_file . '_SOURCES');
1026         }
1027         elsif ($prefix eq '')
1028         {
1029             @files = ($unxformed . '.c');
1030         }
1031         else
1032         {
1033             next;
1034         }
1036         foreach $file (@files)
1037         {
1038             if (defined $libsources{$file})
1039             {
1040                 &am_line_error ($prefix . $one_file . '_SOURCES',
1041                                 "automatically discovered file \`$file' should not be explicitly mentioned");
1042             }
1043         }
1044     }
1047 # Does much of the actual work for handle_source_transform.
1048 # Arguments are:
1049 #   list of source files to transform
1050 # Result is a list
1051 #   first element is name of linker to use (empty string for default linker)
1052 #   remaining elements are names of `.o's
1053 sub handle_single_transform_list
1055     local (@files) = @_;
1056     local ($linker) = '';
1057     local (@result) = ();
1058     local ($nonansi_obj) = $obj;
1059     $nonansi_obj =~ s/_//g;
1060     if (length (@files))
1061     {
1062         # Turn sources into objects.
1063         foreach (@files)
1064         {
1065             # Skip header files, including C++-ish ones.  The list
1066             # of C++ header extensions comes from Emacs 19.32
1067             # etags.
1068             next if /\.[hH]$/;
1069             next if /\.hxx$/;
1070             next if /\.h\+\+$/;
1071             next if /\.hh$/;
1072             next if /\.hpp$/;
1073             # Skip things that look like configure substitutions.
1074             next if /^\@.*\@$/;
1076             # Include appropriate file for lex or yacc source in
1077             # distribution.  If the extension is the regular '.y' or
1078             # '.l', we assume C compilation, and the generated file
1079             # has exension .c.  Otherwise, we compile with C++, and
1080             # make the following association: (yy -> cc, y++ -> c++,
1081             # yxx -> cxx), similarly for .ll, etc.
1082             if (/^(.*)\.(y|yy|y\+\+|yxx)$/)
1083             {
1084                 # Yacc source.
1085                 local ($ext) = $2;
1086                 $ext =~ tr/y/c/;
1087                 &push_dist_common ("$1.$ext");
1088                 $yacc_sources{$_} = 1;
1089             }
1090             elsif (/^(.*)\.(l|ll|l\+\+|lxx)$/)
1091             {
1092                 # Lex source.
1093                 local ($ext) = $2;
1094                 $ext =~ tr/l/c/;
1095                 &push_dist_common ("$1.$ext");
1096                 $lex_sources{$_} = 1;
1097             }
1099             # Transform source files into .o files.  List of C++
1100             # extensions comes from Emacs 19.34 etags.
1101             if (s/\.(c\+\+|cc|cpp|cxx|C)$/$nonansi_obj/)
1102             {
1103                 $cxx_extensions{'.' . $1} = 1;
1104                 $linker = 'CXXLINK';
1105             }
1106             elsif (s/\.(yy|y\+\+|yxx|ll|l\+\+|lxx)$/$nonansi_obj/)
1107             {
1108                 # Compiling lex or yacc with C++
1109                 local ($ext) = $1;
1110                 $ext =~ tr/ly/cc/;
1111                 $cxx_extensions{".$ext"} = 1;
1112                 $linker = 'CXXLINK';
1113             }
1114             elsif (s/\.([Ff]\\|f90\\|for)$/$nonansi_obj/)
1115             {
1116                 # FORTRAN support.  FIXME: not finished.
1117             }
1118             elsif (s/\.[sS]$/$nonansi_obj/)
1119             {
1120                 # .s is assembly.  Just rewrite it.  FIXME: not finished.
1121             }
1122             elsif (s/\.[cly]$/._o/)
1123             {
1124                 # .c is C.  .l is lex.  .y is yacc.
1126                 # Note: first we rewrite (eg) foo.c to foo._o and push
1127                 # the file onto the list of objects that require
1128                 # ansi2knr.  Then we rewrite ._o to $obj; $obj can be
1129                 # simply `.o' if deansification is not really
1130                 # required.
1131                 $de_ansi_objects{$_} = 1;
1132                 s/\._o$/$obj/;
1133                 $seen_c_source = -1 unless $seen_c_source;
1134             }
1135             else
1136             {
1137                 # No error message here.  Used to have one, but it was
1138                 # very unpopular.
1139                 next;
1140             }
1142             push (@result, $_);
1144             # Transform .o or $o file into .P file (for automatic
1145             # dependency code).
1146             s/$objpat$/.P/g;
1147             $dep_files{'.deps/' . $_} = 1;
1148         }
1149     }
1151     return ($linker, @result);
1154 # Handle SOURCE->OBJECT transform for one program or library.
1155 # Arguments are:
1156 #   canonical (transformed) name of object to build
1157 #   actual name of object to build
1158 #   object extension (ie either `.o' or `$o'.
1159 # Return result is name of linker variable that must be used.
1160 # Empty return means just use `LINK'.
1161 sub handle_source_transform
1163     # one_file is canonical name.  unxformed is given name.  obj is
1164     # object extension.
1165     local ($one_file, $unxformed, $obj) = @_;
1166     local ($objpat) = $obj;
1167     $objpat =~ s/(\W)/\\$1/g;
1168     # Handle explicit `.o' as well as whatever we're passed.
1169     $objpat = '(' . $objpat . "|\\.o)";
1171     local ($linker) = '';
1173     if (&variable_defined ($one_file . "_OBJECTS"))
1174     {
1175         &am_line_error ($one_file . '_OBJECTS',
1176                         $one_file . '_OBJECTS', 'should not be defined');
1177         # No point in continuing.
1178         return;
1179     }
1181     local (@files, @result, $prefix, $temp);
1182     foreach $prefix ('', 'EXTRA_')
1183     {
1184         @files = ();
1185         if (&variable_defined ($prefix . $one_file . "_SOURCES"))
1186         {
1187             push (@sources, '$(' . $prefix . $one_file . "_SOURCES)");
1188             push (@objects, '$(' . $prefix . $one_file . "_OBJECTS)")
1189                 unless $prefix eq 'EXTRA_';
1190             @files = &variable_value_as_list ($prefix
1191                                               . $one_file . "_SOURCES");
1192         }
1193         elsif ($prefix eq '')
1194         {
1195             &define_variable ($one_file . "_SOURCES", $unxformed . ".c");
1196             push (@sources, $unxformed . '.c');
1197             push (@objects, $unxformed . $obj);
1198             push (@files, $unxformed . '.c');
1199         }
1201         ($temp, @result) = &handle_single_transform_list (@files);
1202         $linker = $temp if $linker eq '';
1203         &define_pretty_variable ($one_file . "_OBJECTS", @result)
1204             unless $prefix eq 'EXTRA_';
1205     }
1207     return $linker;
1210 # Handle the BUILT_SOURCES variable.
1211 sub handle_built_sources
1213     return unless &variable_defined ('BUILT_SOURCES');
1214     push (@all, '$(BUILT_SOURCES)');
1216     local (@sources) = &variable_value_as_list ('BUILT_SOURCES');
1217     local ($s);
1218     foreach $s (@sources)
1219     {
1220         if (/^\@.*\@$/)
1221         {
1222             # FIXME: is this really the right thing to do?
1223             &am_line_error ('BUILT_SOURCES', "\`BUILT_SOURCES' should not contain a configure substitution");
1224             last;
1225         }
1226     }
1228     # We don't care about the return value of this function.  We just
1229     # want to make sure to update %dep_files with the contents of
1230     # BUILT_SOURCES.
1231     &handle_single_transform_list (@sources);
1234 # Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
1235 # Also, generate _DEPENDENCIES variable if appropriate.
1236 # Arguments are:
1237 #   transformed name of object being built, or empty string if no object
1238 #   name of _LDADD/_LIBADD-type variable to examine
1239 #   boolean (lex_seen) which is true if a lex source file was seen in this
1240 #     object.  valid only for LDADDs, not LIBADDs.  If set, LEXLIB
1241 #     must be in LDADD.
1242 # Returns 1 if LIBOBJS seen, 0 otherwise.
1243 sub handle_lib_objects
1245     local ($xname, $var, $lex_seen) = @_;
1247     die "automake: programming error 1 in handle_lib_objects\n"
1248         if ! &variable_defined ($var);
1250     die "automake: programming error 2 in handle_lib_objects\n"
1251         if $lex_seen && $var =~ /LIBADD/;
1253     # We recognize certain things that are commonly put in LIBADD or
1254     # LDADD.
1255     local ($lsearch);
1256     local (@dep_list) = ();
1258     # If no lex source seen, just assume this is ok.
1259     local ($lex_ok) = $lex_seen ? 0 : 1;
1261     local ($seen_libobjs) = 0;
1262     local ($flagvar) = 0;
1264     foreach $lsearch (&variable_value_as_list ($var))
1265     {
1266         # Skip -lfoo and -Ldir; these are explicitly allowed.
1267         next if $lsearch =~ /^-[lL]/;
1268         if (! $flagvar && $lsearch =~ /^-/)
1269         {
1270             if ($var =~ /^(.*)LDADD$/)
1271             {
1272                 &am_line_error ($var, "linker flags such as \`$lsearch' belong in \`${1}LDFLAGS");
1273             }
1274             else
1275             {
1276                 # Only get this error once.
1277                 $flagvar = 1;
1278                 &am_line_error ($var, "you cannot use linker flags such as \`$lsearch' in \`$var'");
1279             }
1280         }
1282         # Assume we have a file of some sort, and push it onto the
1283         # dependency list.  Autoconf substitutions are not pushed;
1284         # rarely is a new dependency substituted into (eg) foo_LDADD
1285         # -- but "bad things (eg -lX11) are routinely substituted.
1286         # Note that LIBOBJS and ALLOCA are exceptions to this rule,
1287         # and handled specially below.
1288         push (@dep_list, $lsearch)
1289             unless $lsearch =~ /^\@.*\@$/;
1291         # Automatically handle @LIBOBJS@ and @ALLOCA@.  Basically this
1292         # means adding entries to dep_files.
1293         if ($lsearch =~ /^\@(LT)?LIBOBJS\@$/)
1294         {
1295             push (@dep_list, $lsearch);
1296             $seen_libobjs = 1;
1297             if (! keys %libsources)
1298             {
1299                 &am_line_error ($var, "\@$1" . "LIBOBJS\@ seen but never set in \`configure.in'");
1300             }
1302             local ($iter, $rewrite);
1303             foreach $iter (keys %libsources)
1304             {
1305                 if ($iter =~ /\.[cly]$/)
1306                 {
1307                     $seen_c_source = $var;
1308                 }
1310                 if ($iter =~ /\.h$/)
1311                 {
1312                     &require_file_with_line ($var, $FOREIGN, $iter);
1313                 }
1314                 elsif ($iter ne 'alloca.c')
1315                 {
1316                     ($rewrite = $iter) =~ s/\.c$/.P/;
1317                     $dep_files{'.deps/' . $rewrite} = 1;
1318                     &require_file_with_line ($var, $FOREIGN, $iter);
1319                 }
1320             }
1321         }
1322         elsif ($lsearch =~ /^\@(LT)?ALLOCA\@$/)
1323         {
1324             push (@dep_list, $lsearch);
1325             &am_line_error ($var,
1326                             "\@$1" . "ALLOCA\@ seen but \`AC_FUNC_ALLOCA' not in \`configure.in'")
1327                 if ! defined $libsources{'alloca.c'};
1328             $dep_files{'.deps/alloca.P'} = 1;
1329             &require_file_with_line ($var, $FOREIGN, 'alloca.c');
1330             $seen_c_source = $var;
1331         }
1332         elsif ($lsearch eq '@LEXLIB@')
1333         {
1334             # FIXME: variable_value_as_list requires us to force
1335             # @LEXLIB@ here, where we'd really prefer $(LEXLIB).
1336             # Nasty -- this will have to wait until many cleanups are
1337             # made, I think.
1338             $lex_ok = 1;
1339         }
1340     }
1342     if (! $lex_ok)
1343     {
1344         &am_line_error ($var, 'lex source file used without @LEXLIB@');
1345     }
1347     if ($xname ne '' && ! &variable_defined ($xname . '_DEPENDENCIES'))
1348     {
1349         &define_pretty_variable ($xname . '_DEPENDENCIES', @dep_list);
1350     }
1352     return $seen_libobjs;
1355 # Canonicalize a name, and check to make sure the non-canonical name
1356 # is never used.  Returns canonical name.  Arguments are name and a
1357 # list of suffixes to check for.
1358 sub check_canonical_spelling
1360     local ($name, @suffixes) = @_;
1361     local ($xname, $xt);
1363     ($xname = $name) =~ tr/A-Za-z0-9_/_/c;
1364     if ($xname ne $name)
1365     {
1366         local ($xt);
1367         foreach $xt (@suffixes)
1368         {
1369             &am_line_error ($name . $xt,
1370                             "invalid variable \`" . $name . $xt
1371                             . "'; should be \`" . $xname . $xt . "'")
1372                 if &variable_defined ($name . $xt);
1373         }
1374     }
1376     return $xname;
1379 # Handle C programs.
1380 sub handle_programs
1382     local (@proglist) = &am_install_var ('-clean',
1383                                          'progs', 'PROGRAMS',
1384                                          'bin', 'sbin', 'libexec', 'pkglib',
1385                                          'noinst', 'check');
1386     return if ! @proglist;
1388     # If a program is installed, this is required.  We only want this
1389     # error to appear once.
1390     &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
1391         unless $seen_arg_prog;
1392     $seen_arg_prog = 1;
1394     local ($one_file, $xname, $munge);
1396     local ($seen_libobjs) = 0;
1397     foreach $one_file (@proglist)
1398     {
1399         local ($obj) = &get_object_extension ($one_file);
1401         # Canonicalize names and check for misspellings.
1402         $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
1403                                             '_SOURCES', '_OBJECTS',
1404                                             '_DEPENDENCIES');
1406         # FIXME: Using a trick to figure out if any lex sources appear
1407         # in our program; should use some cleaner method.
1408         local ($lex_num) = scalar (keys %lex_sources);
1409         local ($linker) = &handle_source_transform ($xname, $one_file, $obj);
1410         local ($lex_file_seen) = (scalar (keys %lex_sources) > $lex_num);
1412         local ($xt) = '';
1413         if (&variable_defined ($xname . "_LDADD"))
1414         {
1415             if (&handle_lib_objects ($xname, $xname . '_LDADD',
1416                                      $lex_file_seen))
1417             {
1418                 $seen_libobjs = 1;
1419             }
1420             $lex_file_seen = 0;
1421             $xt = '_LDADD';
1422         }
1423         else
1424         {
1425             # User didn't define prog_LDADD override.  So do it.
1426             &define_variable ($xname . '_LDADD', '$(LDADD)');
1428             # This does a bit too much work.  But we need it to
1429             # generate _DEPENDENCIES when appropriate.
1430             if (&variable_defined ('LDADD'))
1431             {
1432                 if (&handle_lib_objects ($xname, 'LDADD', $lex_file_seen))
1433                 {
1434                     $seen_libobjs = 1;
1435                 }
1436                 $lex_file_seen = 0;
1437             }
1438             $xt = '_SOURCES'
1439         }
1441         if (&variable_defined ($xname . '_LIBADD'))
1442         {
1443             &am_line_error ($xname . '_LIBADD',
1444                             "use \`" . $xname . "_LDADD', not \`"
1445                             . $xname . "_LIBADD'");
1446         }
1448         if (! &variable_defined ($xname . '_LDFLAGS'))
1449         {
1450             # Define the prog_LDFLAGS variable.
1451             &define_variable ($xname . '_LDFLAGS', '');
1452         }
1454         if ($lex_file_seen)
1455         {
1456             &am_line_error ($xname . $xt,
1457                             'lex source file used without @LEXLIB@');
1458         }
1460         # Determine program to use for link.
1461         local ($xlink);
1462         if (&variable_defined ($xname . '_LINK'))
1463         {
1464             $xlink = $xname . '_LINK';
1465         }
1466         else
1467         {
1468             $xlink = $linker ? $linker : 'LINK';
1469         }
1471         local ($cygxform);
1472         if (! $seen_cygwin32)
1473         {
1474             $cygxform = 's/^CYGWIN.*$//; s/^NOTCYGWIN//;';
1475         }
1476         else
1477         {
1478             $cygxform = 's/^NOTCYGWIN.*$//; s/^CYGWIN//;';
1479         }
1481         $output_rules .=
1482             &file_contents_with_transform
1483                 ('s/\@PROGRAM\@/' . $one_file . '/go;'
1484                  . 's/\@XPROGRAM\@/' . $xname . '/go;'
1485                  . 's/\@XLINK\@/' . $xlink . '/go;'
1486                  . $cygxform,
1487                  'program');
1488     }
1490     if (&variable_defined ('LDADD') && &handle_lib_objects ('', 'LDADD', 0))
1491     {
1492         $seen_libobjs = 1;
1493     }
1495     if ($seen_libobjs)
1496     {
1497         foreach $one_file (@proglist)
1498         {
1499             # Canonicalize names.
1500             ($xname = $one_file) =~ tr/A-Za-z0-9_/_/c;
1502             if (&variable_defined ($xname . '_LDADD'))
1503             {
1504                 &check_libobjs_sources ($xname, $xname . '_LDADD');
1505             }
1506             elsif (&variable_defined ('LDADD'))
1507             {
1508                 &check_libobjs_sources ($xname, 'LDADD');
1509             }
1510         }
1511     }
1515 # Handle libraries.
1516 sub handle_libraries
1518     local (@liblist) = &am_install_var ('-clean',
1519                                         'libs', 'LIBRARIES',
1520                                         'lib', 'pkglib', 'noinst', 'check');
1521     return if ! @liblist;
1523     local (%valid) = &am_primary_prefixes ('LIBRARIES', 'lib', 'pkglib',
1524                                            'noinst', 'check');
1525     if (! defined $configure_vars{'RANLIB'})
1526     {
1527         local ($key);
1528         foreach $key (keys %valid)
1529         {
1530             if (&variable_defined ($key . '_LIBRARIES'))
1531             {
1532                 &am_line_error ($key . '_LIBRARIES', "library used but \`RANLIB' not defined in \`configure.in'");
1533                 # Only get this error once.
1534                 $configure_vars{'RANLIB'} = 1;
1535                 last;
1536             }
1537         }
1538     }
1540     local ($onelib);
1541     local ($munge);
1542     local ($xlib);
1543     local ($seen_libobjs) = 0;
1544     foreach $onelib (@liblist)
1545     {
1546         # Check that the library fits the standard naming convention.
1547         if ($onelib !~ /^lib.*\.a$/)
1548         {
1549             # FIXME this should only be a warning for foreign packages
1550             # FIXME should put line number here.  That means mapping
1551             # from library name back to variable name.
1552             &am_error ("\`$onelib' is not a standard library name");
1553         }
1555         local ($obj) = &get_object_extension ($onelib);
1557         # Canonicalize names and check for misspellings.
1558         $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
1559                                            '_OBJECTS', '_DEPENDENCIES');
1561         if (&variable_defined ($xlib . '_LIBADD'))
1562         {
1563             if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
1564             {
1565                 $seen_libobjs = 1;
1566             }
1567         }
1568         else
1569         {
1570             # Generate support for conditional object inclusion in
1571             # libraries.
1572             &define_variable ($xlib . "_LIBADD", '');
1573         }
1575         if (&variable_defined ($xlib . '_LDADD'))
1576         {
1577             &am_line_error ($xlib . '_LDADD',
1578                             "use \`" . $xlib . "_LIBADD', not \`"
1579                             . $xlib . "_LDADD'");
1580         }
1582         &handle_source_transform ($xlib, $onelib, $obj);
1584         $output_rules .=
1585             &file_contents_with_transform ('s/\@LIBRARY\@/' . $onelib . '/go;'
1586                                            . 's/\@XLIBRARY\@/'
1587                                            . $xlib . '/go;',
1588                                            'library');
1589     }
1591     if ($seen_libobjs)
1592     {
1593         foreach $onelib (@liblist)
1594         {
1595             # Canonicalize names.
1596             ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
1597             if (&variable_defined ($xlib . '_LIBADD'))
1598             {
1599                 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
1600             }
1601         }
1602     }
1604     &define_variable ('AR', 'ar');
1605     &define_configure_variable ('RANLIB');
1608 # Handle shared libraries.
1609 sub handle_ltlibraries
1611     local (@liblist) = &am_install_var ('-clean',
1612                                         'ltlib', 'LTLIBRARIES',
1613                                         'lib', 'pkglib');
1614     return if ! @liblist;
1616     local (%instdirs);
1617     local (%valid) = &am_primary_prefixes ('LTLIBRARIES', 'lib', 'pkglib');
1619     local ($key);
1620     foreach $key (keys %valid)
1621     {
1622         if (&variable_defined ($key . '_LTLIBRARIES'))
1623         {
1624             if (!$seen_libtool)
1625             {
1626                 &am_line_error ($key . '_LTLIBRARIES', "library used but \`LIBTOOL' not defined in \`configure.in'");
1627                 # Only get this error once.
1628                 $configure_vars{'LIBTOOL'} = 1;
1629                 $seen_libtool = 1;
1630             }
1632             # Get the installation directory of each library.
1633             for (&variable_value_as_list ($key . '_LTLIBRARIES'))
1634             {
1635                 if ($instdirs{$_})
1636                 {
1637                     &am_error ("\`$_' is already going to be installed in \`$instdirs{$_}'");
1638                 }
1639                 else
1640                 {
1641                     $instdirs{$_} = $key;
1642                 }
1643             }
1644         }
1645     }
1647     local ($onelib);
1648     local ($munge);
1649     local ($xlib);
1650     local ($seen_libobjs) = 0;
1651     foreach $onelib (@liblist)
1652     {
1653         # Check that the library fits the standard naming convention.
1654         if ($onelib !~ /^lib.*\.la$/)
1655         {
1656             # FIXME this should only be a warning for foreign packages
1657             # FIXME should put line number here.  That means mapping
1658             # from library name back to variable name.
1659             &am_error ("\`$onelib' is not a standard libtool library name");
1660         }
1662         local ($obj) = &get_object_extension ($onelib);
1664         # Canonicalize names and check for misspellings.
1665         $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
1666                                            '_SOURCES', '_OBJECTS',
1667                                            '_DEPENDENCIES');
1669         if (! &variable_defined ($xlib . '_LDFLAGS'))
1670         {
1671             # Define the lib_LDFLAGS variable.
1672             &define_variable ($xlib . '_LDFLAGS', '');
1673         }
1675         if (&variable_defined ($xlib . '_LIBADD'))
1676         {
1677             if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
1678             {
1679                 $seen_libobjs = 1;
1680             }
1681         }
1682         else
1683         {
1684             # Generate support for conditional object inclusion in
1685             # libraries.
1686             &define_variable ($xlib . "_LIBADD", '');
1687         }
1689         if (&variable_defined ($xlib . '_LDADD'))
1690         {
1691             &am_line_error ($xlib . '_LDADD',
1692                             "use \`" . $xlib . "_LIBADD', not \`"
1693                             . $xlib . "_LDADD'");
1694         }
1696         local ($linker) = &handle_source_transform ($xlib, $onelib, $obj);
1698         # Determine program to use for link.
1699         local ($xlink);
1700         if (&variable_defined ($xlib . '_LINK'))
1701         {
1702             $xlink = $xlib . '_LINK';
1703         }
1704         else
1705         {
1706             $xlink = $linker ? $linker : 'LINK';
1707         }
1709         local ($rpath);
1710         if ($instdirs{$onelib} eq 'EXTRA')
1711         {
1712             # It's an EXTRA_ library, so we can't specify -rpath.
1713             # Yuck.
1714             $rpath = 's/\@RPATH\@//go;';
1715         }
1716         else
1717         {
1718             $rpath = ('s/\@RPATH\@/-rpath \$(' . $instdirs{$onelib}
1719                       . 'dir)/go;');
1720         }
1722         $output_rules .=
1723             &file_contents_with_transform ('s/\@LTLIBRARY\@/'
1724                                            . $onelib . '/go;'
1725                                            . 's/\@XLTLIBRARY\@/'
1726                                            . $xlib . '/go;'
1727                                            . $rpath
1728                                            . 's/\@XLINK\@/' . $xlink . '/go;',
1729                                            'ltlibrary');
1730     }
1732     if ($seen_libobjs)
1733     {
1734         foreach $onelib (@liblist)
1735         {
1736             # Canonicalize names.
1737             ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
1738             if (&variable_defined ($xlib . '_LIBADD'))
1739             {
1740                 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
1741             }
1742         }
1743     }
1746 # See if any _SOURCES variable were misspelled.  Also, make sure that
1747 # EXTRA_ variables don't contain configure substitutions.
1748 sub check_typos
1750     local ($varname, $primary);
1751     foreach $varname (keys %contents)
1752     {
1753         foreach $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS', '_DEPENDENCIES')
1754         {
1755             if ($varname =~ /$primary$/ && ! $content_seen{$varname})
1756             {
1757                 &am_line_error ($varname,
1758                                 "invalid unused variable name: \`$varname'");
1759             }
1760         }
1761     }
1764 # Handle scripts.
1765 sub handle_scripts
1767     # NOTE we no longer automatically clean SCRIPTS, because it is
1768     # useful to sometimes distribute scripts verbatim.  This happens
1769     # eg in Automake itself.
1770     &am_install_var ('scripts', 'SCRIPTS',
1771                      'bin', 'sbin', 'libexec', 'pkgdata',
1772                      'noinst', 'check');
1774     # Set $scripts_installed if appropriate.  Make sure we only find
1775     # scripts which are actually installed -- this is why we can't
1776     # simply use the return value of am_install_var.
1777     local (%valid) = &am_primary_prefixes ('SCRIPTS', 'bin', 'sbin',
1778                                            'libexec', 'pkgdata',
1779                                            'noinst', 'check');
1780     local ($key);
1781     foreach $key (keys %valid)
1782     {
1783         if ($key ne 'noinst'
1784             && $key ne 'check'
1785             && &variable_defined ($key . '_SCRIPTS'))
1786         {
1787             $scripts_installed = 1;
1788             # push (@check_tests, 'check-' . $key . 'SCRIPTS');
1789         }
1790     }
1792     if ($scripts_installed)
1793     {
1794         # If a program is installed, this is required.  We only want this
1795         # error to appear once.
1796         &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
1797             unless $seen_arg_prog;
1798         $seen_arg_prog = 1;
1799     }
1802 # Search a file for a "version.texi" Texinfo include.  Return the name
1803 # of the include file if found, or the empty string if not.  A
1804 # "version.texi" file is actually any file whose name matches
1805 # "vers*.texi".
1806 sub scan_texinfo_file
1808     local ($filename) = @_;
1810     if (! open (TEXI, $filename))
1811     {
1812         &am_error ("couldn't open \`$filename': $!");
1813         return '';
1814     }
1815     print "automake: reading $filename\n" if $verbose;
1817     local ($vfile, $outfile);
1818     while (<TEXI>)
1819     {
1820         if (/^\@setfilename +(\S+)/)
1821         {
1822             $outfile = $1;
1823             last if ($vfile);
1824         }
1826         if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
1827         {
1828             # Found version.texi include.
1829             $vfile = $1;
1830             last if $outfile;
1831         }
1832     }
1834     close (TEXI);
1835     return ($outfile, $vfile);
1838 # Handle all Texinfo source.
1839 sub handle_texinfo
1841     &am_line_error ('TEXINFOS',
1842                     "\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
1843         if &variable_defined ('TEXINFOS');
1844     return if (! &variable_defined ('info_TEXINFOS')
1845                && ! &variable_defined ('html_TEXINFOS'));
1847     local (@texis) = &variable_value_as_list ('info_TEXINFOS');
1849     local (@info_deps_list, @dvis_list, @texi_deps);
1850     local ($infobase, $info_cursor);
1851     local (%versions);
1852     local ($done) = 0;
1853     local ($vti);
1854     local ($tc_cursor, @texi_cleans);
1855     local ($canonical);
1857     foreach $info_cursor (@texis)
1858     {
1859         ($infobase = $info_cursor) =~ s/\.texi(nfo)?$//;
1861         # If 'version.texi' is referenced by input file, then include
1862         # automatic versioning capability.
1863         local ($out_file, $vtexi) = &scan_texinfo_file ($relative_dir
1864                                                         . "/" . $info_cursor);
1866         if ($out_file eq '')
1867         {
1868             &am_error ("\`$info_cursor' missing \@setfilename");
1869             next;
1870         }
1872         if ($out_file =~ /\.(.+)$/ && $1 ne 'info')
1873         {
1874             # FIXME should report line number in input file.
1875             &am_error ("output of \`$info_cursor', \`$out_file', has unrecognized extension");
1876             next;
1877         }
1879         if ($vtexi)
1880         {
1881             &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
1882                 if (defined $versions{$vtexi});
1883             $versions{$vtexi} = $info_cursor;
1885             # We number the stamp-vti files.  This is doable since the
1886             # actual names don't matter much.  We only number starting
1887             # with the second one, so that the common case looks nice.
1888             $vti = 'vti' . ($done ? $done : '');
1889             &push_dist_common ($vtexi, 'stamp-' . $vti);
1890             push (@clean, $vti);
1892             # Only require once.
1893             &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
1894                                           'mdate-sh')
1895                 if ! $done;
1896             ++$done;
1898             local ($conf_pat);
1899             ($conf_pat = $config_aux_dir) =~ s/(\W)/\\$1/g;
1900             $output_rules .=
1901                 &file_contents_with_transform
1902                     ('s/\@TEXI\@/' . $info_cursor . '/g; '
1903                      . 's/\@VTI\@/' . $vti . '/g; '
1904                      . 's/\@VTEXI\@/' . $vtexi . '/g;'
1905                      . 's,\@MDDIR\@,' . $conf_pat . ',g;',
1906                      'texi-vers');
1908             &push_phony_cleaners ($vti);
1909         }
1911         # If user specified file_TEXINFOS, then use that as explicit
1912         # dependency list.
1913         @texi_deps = ();
1914         push (@texi_deps, $info_cursor);
1915         push (@texi_deps, $vtexi) if $vtexi;
1917         # Canonicalize name first.
1918         ($canonical = $infobase) =~ tr/A-Za-z0-9_/_/c;
1919         if (&variable_defined ($canonical . "_TEXINFOS"))
1920         {
1921             push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
1922             &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
1923         }
1925         $output_rules .= ("\n" . $out_file . ": "
1926                           . join (' ', @texi_deps)
1927                           . "\n" . $infobase . ".dvi: "
1928                           . join (' ', @texi_deps)
1929                           . "\n\n");
1931         push (@info_deps_list, $out_file);
1932         push (@dvis_list, $infobase . '.dvi');
1934         # Generate list of things to clean for this target.  We do
1935         # this explicitly because otherwise too many things could be
1936         # removed.  In particular the ".log" extension might
1937         # reasonably be used in other contexts by the user.
1938         foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns',
1939                             'ky', 'log', 'pg', 'toc', 'tp', 'tps',
1940                             'vr', 'vrs', 'op', 'tr', 'cv')
1941         {
1942             push (@texi_cleans, $infobase . '.' . $tc_cursor);
1943         }
1944     }
1946     # Find these programs wherever they may lie.  Yes, this has
1947     # intimate knowledge of the structure of the texinfo distribution.
1948     &define_program_variable ('MAKEINFO', 'build', 'texinfo/makeinfo',
1949                               'makeinfo',
1950                               # Circumlocution to avoid accidental
1951                               # configure substitution.
1952                               '@MAKE' . 'INFO@');
1953     &define_program_variable ('TEXI2DVI', 'src', 'texinfo/util',
1954                               'texi2dvi');
1956     # Set transform for including texinfos.am.  First, handle --cygnus
1957     # stuff.
1958     local ($xform);
1959     if ($cygnus_mode)
1960     {
1961         $xform = 's/^NOTCYGNUS.*$//; s/^CYGNUS//;';
1962     }
1963     else
1964     {
1965         $xform = 's/^CYGNUS.*$//; s/^NOTCYGNUS//;';
1966     }
1968     # Handle location of texinfo.tex.
1969     if ($cygnus_mode)
1970     {
1971         &define_variable ('TEXINFO_TEX',
1972                           '$(top_srcdir)/../texinfo/texinfo.tex');
1973     }
1974     elsif (! &variable_defined ('TEXINFO_TEX'))
1975     {
1976         &define_variable ('TEXINFO_TEX', '$(srcdir)/texinfo.tex');
1977     }
1978     local ($xxform) = &dirname ($contents{'TEXINFO_TEX'});
1979     $xxform =~ s/(\W)/\\$1/g;
1980     $xform .= ' s/\@TEXINFODIR\@/' . $xxform . '/g;';
1982     $output_rules .= &file_contents_with_transform ($xform, 'texinfos');
1983     push (@phony, 'install-info-am', 'uninstall-info');
1984     push (@dist_targets, 'dist-info');
1986     # How to clean.  The funny name is due to --cygnus influence; in
1987     # Cygnus mode, `clean-info' is a target that users can use.
1988     $output_rules .= "\nmostlyclean-aminfo:\n";
1989     &pretty_print_rule ("\trm -f", "\t  ", @texi_cleans);
1990     $output_rules .= ("\nclean-aminfo:\n\ndistclean-aminfo:\n\n"
1991                       . "maintainer-clean-aminfo:\n\t"
1992                       . 'for i in $(INFO_DEPS); do rm -f `eval echo $$i*`; done'
1993                       . "\n");
1994     &push_phony_cleaners ('aminfo');
1995     if ($cygnus_mode)
1996     {
1997         $output_rules .= "clean-info: mostlyclean-aminfo\n";
1998     }
2000     push (@suffixes, '.texi', '.texinfo', '.info', '.dvi', '.ps');
2002     if (! defined $options{'no-installinfo'})
2003     {
2004         push (@uninstall, 'uninstall-info');
2005         push (@installdirs, '$(infodir)');
2006         unshift (@install_data, 'install-info-am');
2008         # Make sure documentation is made and installed first.  Use
2009         # $(INFO_DEPS), not 'info', because otherwise recursive makes
2010         # get run twice during "make all".
2011         unshift (@all, '$(INFO_DEPS)');
2012     }
2013     push (@clean, 'info');
2014     push (@info, '$(INFO_DEPS)');
2015     push (@dvi, '$(DVIS)');
2017     &define_variable ("INFO_DEPS", join (' ', @info_deps_list));
2018     &define_variable ("DVIS", join (' ', @dvis_list));
2019     # This next isn't strictly needed now -- the places that look here
2020     # could easily be changed to look in info_TEXINFOS.  But this is
2021     # probably better, in case noinst_TEXINFOS is ever supported.
2022     &define_variable ("TEXINFOS", $contents{'info_TEXINFOS'});
2024     # Do some error checking.  Note that this file is not required
2025     # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
2026     # up above.
2027     &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex')
2028         unless (defined $options{'no-texinfo.tex'}
2029                 || &variable_defined ('TEXINFO_TEX'));
2032 # Handle any man pages.
2033 sub handle_man_pages
2035     &am_line_error ('MANS', "\`MANS' is an anachronism; use \`man_MANS'")
2036         if &variable_defined ('MANS');
2037     return if ! &variable_defined ('man_MANS');
2039     # We generate the manpage install code by hand to avoid the use of
2040     # basename in the generated Makefile.
2041     local (@mans) = &variable_value_as_list ('man_MANS');
2042     local (%sections, %inames, %mbases, %secmap, %fullsecmap);
2043     local ($i) = 1;
2044     foreach (@mans)
2045     {
2046         # FIXME: statement without effect:
2047         /^(.*)\.([0-9])([a-z]*)$/;
2048         $sections{$2} = 1;
2049         $inames{$i} = $_;
2050         $mbases{$i} = $1;
2051         $secmap{$i} = $2;
2052         $fullsecmap{$i} = $2 . $3;
2053         $i++;
2054     }
2056     # We don't really need this, but we use it in case we ever want to
2057     # support noinst_MANS.
2058     &define_variable ("MANS", $contents{'man_MANS'});
2060     # Generate list of install dirs.
2061     $output_rules .= "install-man: \$(MANS)\n";
2062     $output_rules .= "\t\$(NORMAL_INSTALL)\n";
2063     # Sort keys so that output is deterministic.
2064     foreach (sort keys %sections)
2065     {
2066         push (@installdirs, '$(mandir)/man' . $_)
2067             unless defined $options{'no-installman'};
2068         $output_rules .= ("\t" . '$(mkinstalldirs) $(mandir)/man'
2069                           . $_ . "\n");
2070     }
2071     push (@phony, 'install-man');
2073     # Generate install target.
2074     local ($key);
2075     foreach $key (sort keys %inames)
2076     {
2077         $_ = $install_man_format;
2078         s/\@SECTION\@/$secmap{$key}/g;
2079         s/\@MAN\@/$inames{$key}/g;
2080         s/\@FULLSECT\@/$fullsecmap{$key}/g;
2081         s/\@MANBASE\@/$mbases{$key}/g;
2082         $output_rules .= $_;
2083     }
2084     $output_rules .= "\n";
2086     $output_rules .= "uninstall-man:\n\t\$(NORMAL_UNINSTALL)\n";
2087     foreach $key (sort keys %inames)
2088     {
2089         $_ = $uninstall_man_format;
2090         s/\@SECTION\@/$secmap{$key}/g;
2091         s/\@MAN\@/$inames{$key}/g;
2092         s/\@FULLSECT\@/$fullsecmap{$key}/g;
2093         s/\@MANBASE\@/$mbases{$key}/g;
2094         $output_rules .= $_;
2095     }
2096     $output_rules .= "\n";
2097     push (@phony, 'uninstall-man');
2099     $output_vars .= &file_contents ('mans-vars');
2101     if (! defined $options{'no-installman'})
2102     {
2103         push (@install_data, 'install-man');
2104         push (@uninstall, 'uninstall-man');
2105         push (@all, '$(MANS)');
2106     }
2109 # Handle DATA variables.
2110 sub handle_data
2112     &am_install_var ('data', 'DATA', 'data', 'sysconf',
2113                      'sharedstate', 'localstate', 'pkgdata',
2114                      'noinst', 'check');
2117 # Handle TAGS.
2118 sub handle_tags
2120     push (@phony, 'tags');
2121     local (@tag_deps) = ();
2122     if (&variable_defined ('SUBDIRS'))
2123     {
2124         $output_rules .= ("tags-recursive:\n"
2125                           . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
2126                           # Never fail here if a subdir fails; it
2127                           # isn't important.
2128                           . "\t  (cd \$\$subdir && \$(MAKE) tags); \\\n"
2129                           . "\tdone\n");
2130         push (@tag_deps, 'tags-recursive');
2131         push (@phony, 'tags-recursive');
2132     }
2134     if ($dir_holds_sources
2135         || $dir_holds_headers
2136         || &variable_defined ('ETAGS_ARGS')
2137         || @tag_deps)
2138     {
2139         local ($xform) = '';
2140         local ($one_hdr);
2141         foreach $one_hdr (@config_headers)
2142         {
2143             if ($relative_dir eq &dirname ($one_hdr))
2144             {
2145                 # The config header is in this directory.  So require it.
2146                 local ($var);
2147                 ($var = &basename ($one_hdr)) =~ s/(\W)/\\$1/g;
2148                 $xform .= ' ' if $xform;
2149                 $xform .= $var;
2150             }
2151         }
2152         $xform = ('s/\@CONFIG\@/' . $xform . '/;'
2153                   . 's/\@DIRS\@/' . join (' ', @tag_deps) . '/;');
2155         if (&variable_defined ('SUBDIRS'))
2156         {
2157             $xform .= 's/^SUBDIRS//;';
2158         }
2159         else
2160         {
2161             $xform .= 's/^SUBDIRS.*$//;';
2162         }
2164         $output_rules .= &file_contents_with_transform ($xform, 'tags');
2165         $output_rules .= &file_contents ('tags-clean');
2166         push (@clean, 'tags');
2167         &push_phony_cleaners ('tags');
2168         &examine_variable ('TAGS_DEPENDENCIES');
2169     }
2170     elsif (&variable_defined ('TAGS_DEPENDENCIES'))
2171     {
2172         &am_line_error ('TAGS_DEPENDENCIES',
2173                         "doesn't make sense to define \`TAGS_DEPENDENCIES' without sources or \`ETAGS_ARGS'");
2174     }
2175     else
2176     {
2177         # Every Makefile must define some sort of TAGS rule.
2178         # Otherwise, it would be possible for a top-level "make TAGS"
2179         # to fail because some subdirectory failed.
2180         $output_rules .= "tags: TAGS\nTAGS:\n\n";
2181     }
2184 # Worker for handle_dist.
2185 sub handle_dist_worker
2187     $output_rules .= 'distdir: $(DISTFILES)' . "\n";
2189     # Initialization; only at top level.
2190     if ($relative_dir eq '.')
2191     {
2192         if ($strictness >= $GNITS)
2193         {
2194             # For Gnits users, this is pretty handy.  Look at 15 lines
2195             # in case some explanatory text is desirable.
2196             $output_rules .= '  @if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" > /dev/null; then :; else \\
2197           echo "NEWS not updated; not releasing" 1>&2; \\
2198           exit 1; \\
2199         fi
2201         }
2204         $output_rules .=
2205             # Create dist directory.
2206             '   rm -rf $(distdir)
2207         mkdir $(distdir)
2208         -chmod 755 $(distdir)
2211         # Only run automake in `dist' target if --include-deps and
2212         # `no-dependencies' not specified.  That way the recipient of
2213         # a distribution can run "make dist" and not need Automake.
2214         if ($use_dependencies)
2215         {
2216             $output_rules .=
2217                 (
2218                  # We need an absolute path for --output-dir.  Thus the
2219                  # weirdness.
2220                  '      here=`pwd`; distdir=`cd $(distdir) && pwd` \\
2221           && cd $(srcdir) \\
2222           && $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(srcdir) --output-dir=$$distdir '
2223                  # Set strictness of output.
2224                  . ($cygnus_mode ? '--cygnus' : ('--' . $strictness_name))
2225                  . "\n"
2226                  );
2227         }
2228     }
2230     # Scan EXTRA_DIST to see if we need to distribute anything from a
2231     # subdir.  If so, add it to the list.  I didn't want to do this
2232     # originally, but there were so many requests that I finally
2233     # relented.
2234     local (@dist_dirs);
2235     if (&variable_defined ('EXTRA_DIST'))
2236     {
2237         foreach (&variable_value_as_list ('EXTRA_DIST'))
2238         {
2239             next if /^\@.*\@$/;
2240             next unless s,/+[^/]+$,,;
2241             push (@dist_dirs, $_)
2242                 unless $_ eq '.';
2243         }
2244     }
2245     if (@dist_dirs)
2246     {
2247         # Prepend $(distdir) to each directory given.  Doing it via a
2248         # hash lets us ensure that each directory is used only once.
2249         local (%dhash);
2250         grep ($dhash{'$(distdir)/' . $_} = 1, @dist_dirs);
2251         $output_rules .= "\t";
2252         &pretty_print_rule ('$(mkinstalldirs)', "\t   ", sort keys %dhash);
2253     }
2255     # In loop, test for file existence because sometimes a file gets
2256     # included in DISTFILES twice.  For example this happens when a
2257     # single source file is used in building more than one program.
2258     # Also, there are situations in which "ln" can fail.  For instance
2259     # a file to distribute could actually be a cross-filesystem
2260     # symlink -- this can easily happen if "gettextize" was run on the
2261     # distribution.
2262     $output_rules .= "\t\@for file in \$(DISTFILES); do \\\n";
2263     if ($cygnus_mode)
2264     {
2265         $output_rules .= "\t  if test -f \$\$file; then d=.; else d=\$(srcdir); fi; \\\n";
2266     }
2267     else
2268     {
2269         $output_rules .= "\t  d=\$(srcdir); \\\n";
2270     }
2271     $output_rules .= '    test -f $(distdir)/$$file \\
2272           || ln $$d/$$file $(distdir)/$$file 2> /dev/null \\
2273           || cp -p $$d/$$file $(distdir)/$$file; \\
2274         done
2277     # If we have SUBDIRS, create all dist subdirectories and do
2278     # recursive build.
2279     if (&variable_defined ('SUBDIRS'))
2280     {
2281         # Test for directory existence here because previous automake
2282         # invocation might have created some directories.  Note that
2283         # we explicitly set distdir for the subdir make; that lets us
2284         # mix-n-match many automake-using packages into one large
2285         # package, and have "dist" at the top level do the right
2286         # thing.
2287         $output_rules .= '      for subdir in $(SUBDIRS); do            \\
2288           test -d $(distdir)/$$subdir           \\
2289           || mkdir $(distdir)/$$subdir          \\
2290           || exit 1;                            \\
2291           chmod 755 $(distdir)/$$subdir;        \\
2292           (cd $$subdir && $(MAKE) distdir=../$(distdir)/$$subdir distdir) \\
2293             || exit 1; \\
2294         done
2296     }
2298     # If the target `dist-hook' exists, make sure it is run.  This
2299     # allows users to do random weird things to the distribution
2300     # before it is packaged up.
2301     push (@dist_targets, 'dist-hook') if defined $contents{'dist-hook'};
2303     local ($targ);
2304     foreach $targ (@dist_targets)
2305     {
2306         # We must explicitly set distdir for these sub-makes.
2307         $output_rules .= "\t\$(MAKE) distdir=\"\$(distdir)\" $targ\n";
2308     }
2310     push (@phony, 'distdir');
2313 # Handle 'dist' target.
2314 sub handle_dist
2316     # Set up maint_charset.
2317     $local_maint_charset = $contents{'MAINT_CHARSET'}
2318         if &variable_defined ('MAINT_CHARSET');
2319     $maint_charset = $local_maint_charset
2320         if $relative_dir eq '.';
2322     if (&variable_defined ('DIST_CHARSET'))
2323     {
2324         &am_line_error ('DIST_CHARSET',
2325                         "DIST_CHARSET defined but no MAINT_CHARSET defined")
2326             if ! $local_maint_charset;
2327         if ($relative_dir eq '.')
2328         {
2329             $dist_charset = $contents{'DIST_CHARSET'}
2330         }
2331         else
2332         {
2333             &am_line_error ('DIST_CHARSET',
2334                             "DIST_CHARSET can only be defined at top level");
2335         }
2336     }
2338     # Look for common files that should be included in distribution.
2339     local ($cfile);
2340     foreach $cfile (@common_files)
2341     {
2342         if (-f ($relative_dir . "/" . $cfile))
2343         {
2344             &push_dist_common ($cfile);
2345         }
2346     }
2348     # Keys of %dist_common are names of files to distributed.  We put
2349     # README first because it then becomes easier to make a
2350     # Usenet-compliant shar file (in these, README must be first).
2351     # FIXME: do more ordering of files here.
2352     local (@coms);
2353     if (defined $dist_common{'README'})
2354     {
2355         push (@coms, 'README');
2356         delete $dist_common{'README'};
2357     }
2358     push (@coms, sort keys %dist_common);
2360     &define_pretty_variable ("DIST_COMMON", @coms);
2361     $output_vars .= "\n";
2363     # Some boilerplate.
2364     $output_vars .= &file_contents ('dist-vars') . "\n";
2365     &define_variable ('TAR', $TAR);
2366     &define_variable ('GZIP', '--best');
2368     # Put these things in rules section so it is easier for whoever
2369     # reads Makefile.in.
2370     if (! &variable_defined ('distdir'))
2371     {
2372         if ($relative_dir eq '.')
2373         {
2374             $output_rules .= "\n" . 'distdir = $(PACKAGE)-$(VERSION)' . "\n";
2375         }
2376         else
2377         {
2378             $output_rules .= ("\n"
2379                               . 'distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)'
2380                               . "\n");
2381         }
2382     }
2383     if ($relative_dir ne '.')
2384     {
2385         $output_rules .= "\nsubdir = " . $relative_dir . "\n";
2386     }
2388     # Generate 'dist' target, and maybe dist-shar / dist-zip / dist-tarZ.
2389     if ($relative_dir eq '.')
2390     {
2391         # Rule to check whether a distribution is viable.
2392         $output_rules .= ('# This target untars the dist file and tries a VPATH configuration.  Then
2393 # it guarantees that the distribution is self-contained by making another
2394 # tarfile.
2395 distcheck: dist
2396         rm -rf $(distdir)
2397         GZIP=$(GZIP) $(TAR) zxf $(distdir).tar.gz
2398         mkdir $(distdir)/=build
2399         mkdir $(distdir)/=inst
2400         dc_install_base=`cd $(distdir)/=inst && pwd`; \\'
2401                           . (defined $contents{'distcheck-hook'}
2402                              ? "\t\$(MAKE) distcheck-hook"
2403                              : '')
2404                           . '
2405         cd $(distdir)/=build \\
2406           && ../configure '
2408                           . ($seen_gettext ? '--with-included-gettext ' : '')
2409                           . '--srcdir=.. --prefix=$$dc_install_base \\
2410           && $(MAKE) \\
2411           && $(MAKE) dvi \\
2412           && $(MAKE) check \\
2413           && $(MAKE) install \\
2414           && $(MAKE) installcheck \\
2415           && $(MAKE) dist
2416         rm -rf $(distdir)
2417         @echo "========================"; \\
2418         echo "$(distdir).tar.gz is ready for distribution"; \\
2419         echo "========================"
2422         local ($dist_all) = ('dist-all: distdir' . "\n"
2423                              . $dist_header);
2424         local ($curs);
2425         foreach $curs ('dist', 'dist-shar', 'dist-zip', 'dist-tarZ')
2426         {
2427             if (defined $options{$curs} || $curs eq 'dist')
2428             {
2429                 $output_rules .= ($curs . ': distdir' . "\n"
2430                                   . $dist_header
2431                                   . $dist{$curs}
2432                                   . $dist_trailer);
2433                 $dist_all .= $dist{$curs};
2434             }
2435         }
2436         $output_rules .= $dist_all . $dist_trailer;
2437     }
2439     # Generate distdir target.
2440     &handle_dist_worker;
2443 # Scan a single dependency file and rewrite the dependencies as
2444 # appropriate.  Essentially this means:
2445 # * Clean out absolute dependencies which are not desirable.
2446 # * Rewrite other dependencies to be relative to $(top_srcdir).
2447 sub scan_dependency_file
2449     local ($depfile) = @_;
2451     if (! open (DEP_FILE, $depfile))
2452     {
2453         &am_error ("couldn't open \`$depfile': $!");
2454         return;
2455     }
2456     print "automake: reading $depfile\n" if $verbose;
2458     # Sometimes it is necessary to omit some dependencies.
2459     local (%omit) = %omit_dependencies;
2460     if (&variable_defined ('OMIT_DEPENDENCIES'))
2461     {
2462         grep ($omit{$_} = 1, &variable_value_as_list ('OMIT_DEPENDENCIES'));
2463     }
2465     local ($first_line) = 1;
2466     local ($last_line) = 0;
2467     local ($target, @dependencies);
2468     local ($one_dep, $xform);
2469     local ($just_file);
2471     local ($srcdir_rx, $fixup_rx);
2472     # If the top srcdir is absolute, then the current directory is
2473     # just relative_dir.  But if the top srcdir is relative, then we
2474     # need to add some dots first.  The same holds when matching
2475     # srcdir directly.
2476     if ($srcdir_name =~ /^\//)
2477     {
2478         ($fixup_rx = $srcdir_name . '/' . $relative_dir . '/')
2479             =~ s/(\W)/\\$1/g;
2480         ($srcdir_rx = $srcdir_name . '/') =~ s/(\W)/\\$1/g;
2481     }
2482     else
2483     {
2484         ($fixup_rx = ($srcdir_name . '/' . $top_builddir . '/'
2485                       . $relative_dir . '/')) =~ s/(\W)/\\$1/g;
2486         $srcdir_rx = $srcdir_name . '/';
2487         # Don't append a spurious "." to the regex.
2488         $srcdir_rx .= $top_builddir
2489             unless $top_builddir eq '.';
2490         $srcdir_rx =~ s/(\W)/\\$1/g;
2491     }
2493     local ($rewrite_builddir) = (($top_builddir eq '.')
2494                                  ? ''
2495                                  : $top_builddir . '/');
2497     while (<DEP_FILE>)
2498     {
2499         if ($last_line)
2500         {
2501             # If LAST_LINE set then we've already seen what we thought
2502             # was the last line.
2503             goto bad_format;
2504         }
2505         next if (/$WHITE_PATTERN/o);
2506         chop;
2507         if (! s/\\$//)
2508         {
2509             # No trailing "\" means this should be the last line.
2510             $last_line = 1;
2511         }
2513         if ($first_line)
2514         {
2515             if (! /^([^:]+:)(.+)$/)
2516             {
2517               bad_format:
2518                 &am_error ("\`$depfile' has incorrect format");
2519                 close (DEP_FILE);
2520                 return;
2521             }
2523             $_ = $2;
2524             # Make sure to strip the .P file from the target.
2525             ($target = $1) =~ s, *\.deps/[^.]+\.P,,;
2527             $first_line = 0;
2528         }
2530         foreach $one_dep (split (' ', $_))
2531         {
2532             if ($one_dep =~ /^$fixup_rx/)
2533             {
2534                 # The dependency points to the current directory in
2535                 # some way.
2536                 ($xform = $one_dep) =~ s/^$fixup_rx//;
2537                 push (@dependencies, $xform);
2538             }
2539             elsif ($one_dep =~ /^$srcdir_rx/)
2540             {
2541                 # The dependency is in some other directory in the package.
2542                 ($xform = $one_dep) =~ s/^$srcdir_rx/$rewrite_builddir/;
2543                 push (@dependencies, $xform);
2544             }
2545             elsif ($one_dep =~ /^\//)
2546             {
2547                 # Absolute path; ignore.
2548             }
2549             else
2550             {
2551                 # Anything else is assumed to be correct.  But first
2552                 # make sure it is not on our list of dependencies to
2553                 # omit.
2554                 ($just_file = $one_dep) =~ s,^.*/,,;
2555                 push (@dependencies, $one_dep)
2556                     if ! defined $omit{$just_file};
2557             }
2558         }
2559     }
2561     &pretty_print_rule ($target, "\t", @dependencies);
2563     close (DEP_FILE);
2566 # Handle auto-dependency code.
2567 sub handle_dependencies
2569     if ($use_dependencies)
2570     {
2571         # Include GNU-make-specific auto-dep code.
2572         if ($dir_holds_sources)
2573         {
2574             &define_pretty_variable ('DEP_FILES', sort keys %dep_files);
2575             $output_rules .= &file_contents ('depend');
2576             push (@clean, 'depend');
2577             &push_phony_cleaners ('depend');
2578             $output_rules .=
2579                 &file_contents_with_transform ('s/\@EXT\@/.c/g;'
2580                                                . 's/\@MKDEP\@/MKDEP/g;'
2581                                                . 's/^ONLYC//g;',
2582                                                'depend2');
2583             local ($ext);
2584             local ($need_cxx) = 0;
2585             foreach $ext (sort keys %cxx_extensions)
2586             {
2587                 $output_rules .=
2588                     &file_contents_with_transform ('s/\@EXT\@/' . $ext .'/g;'
2589                                                    . 's/\@MKDEP\@/CXXMKDEP/g;'
2590                                                    . 's/^ONLYC.*$//;',
2591                                                    'depend2');
2592                 $need_cxx = 1;
2593             }
2594             if ($need_cxx)
2595             {
2596                 &define_variable ('CXXMKDEP', '$(CXX) -M $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)');
2597             }
2598         }
2599     }
2600     elsif ($build_directory ne '')
2601     {
2602         # Include any auto-generated deps that are present.  Note that
2603         # $build_directory ends in a "/".
2604         if (-d ($build_directory . $relative_dir . "/.deps")
2605             && -f ($build_directory . $relative_dir . "/.deps/.P"))
2606         {
2607             local ($depfile);
2609             foreach $depfile (&my_glob ($build_directory
2610                                         . $relative_dir . "/.deps/*.P"))
2611             {
2612                 &scan_dependency_file ($depfile);
2613             }
2615             $output_rules .= "\n";
2616         }
2617     }
2620 # Handle subdirectories.
2621 sub handle_subdirs
2623     return if ! &variable_defined ('SUBDIRS');
2625     # Make sure each directory mentioned in SUBDIRS actually exists.
2626     local ($dir);
2627     foreach $dir (&variable_value_as_list ('SUBDIRS'))
2628     {
2629         # Skip directories substituted by configure.
2630         next if $dir =~ /^\@.*\@$/;
2632         if (! -d $am_relative_dir . '/' . $dir)
2633         {
2634             &am_line_error ('SUBDIRS',
2635                             "required directory $am_relative_dir/$dir does not exist");
2636             next;
2637         }
2639         &am_line_error ('SUBDIRS', "directory should not contain \`/'")
2640             if $dir =~ /\//;
2641     }
2643     local ($xform) = ('s/\@INSTALLINFO\@/' .
2644                       (defined $options{'no-installinfo'}
2645                        ? 'install-info-recursive'
2646                        : '')
2647                       . '/;');
2648     $output_rules .= &file_contents_with_transform ($xform, 'subdirs');
2650     # Push a bunch of phony targets.
2651     local ($phonies);
2652     foreach $phonies ('-data', '-exec', 'dirs')
2653     {
2654         push (@phony, 'install' . $phonies . '-recursive');
2655         push (@phony, 'uninstall' . $phonies . '-recursive');
2656     }
2657     foreach $phonies ('all', 'check', 'installcheck', 'info', 'dvi')
2658     {
2659         push (@phony, $phonies . '-recursive');
2660     }
2661     &push_phony_cleaners ('recursive');
2663     push (@check_tests, "check-recursive");
2664     push (@installcheck, "installcheck-recursive");
2665     push (@info, "info-recursive");
2666     push (@dvi, "dvi-recursive");
2668     $recursive_install = 1;
2671 # Handle aclocal.m4.
2672 sub handle_aclocal_m4
2674     local ($regen_aclocal) = 0;
2675     if (-f 'aclocal.m4')
2676     {
2677         &define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4');
2678         &push_dist_common ('aclocal.m4');
2680         if (open (ACLOCAL, '< aclocal.m4'))
2681         {
2682             local ($line);
2683             $line = <ACLOCAL>;
2684             close (ACLOCAL);
2686             if ($line =~ 'generated automatically by aclocal')
2687             {
2688                 $regen_aclocal = 1;
2689             }
2690         }
2691     }
2693     local ($acinclude) = 0;
2694     if (-f 'acinclude.m4')
2695     {
2696         $regen_aclocal = 1;
2697         $acinclude = 1;
2698     }
2700     # Note that it might be possible that aclocal.m4 doesn't exist but
2701     # should be auto-generated.  This case probably isn't very
2702     # important.
2703     if ($regen_aclocal)
2704     {
2705         local (@ac_deps) = (
2706                             ($seen_maint_mode ? "\@MAINT\@" : "") ,
2707                             "configure.in",
2708                             ($acinclude ? ' acinclude.m4' : '')
2709                             );
2711         # Scan all -I directories for m4 files.  These are our
2712         # dependencies.
2713         if (&variable_defined ('ACLOCAL_AMFLAGS'))
2714         {
2715             local ($amdir);
2716             foreach $amdir (&variable_value_as_list ('ACLOCAL_AMFLAGS'))
2717             {
2718                 if ($amdir =~ s/^-I//
2719                     && $amdir !~ /^\//
2720                     && -d $amdir)
2721                 {
2722                     push (@ac_deps, &my_glob ($am_dir . '/*.m4'));
2723                 }
2724             }
2725         }
2727         &pretty_print_rule ("\$(ACLOCAL_M4):", "\t\t", @ac_deps);
2729         $output_rules .=  ("\t"
2730                            . 'cd $(srcdir) && $(ACLOCAL)'
2731                            . (&variable_defined ('ACLOCAL_AMFLAGS')
2732                               ? ' $(ACLOCAL_AMFLAGS)' : '')
2733                            . "\n");
2734     }
2737 # Rewrite a list of input files into a form suitable to put on a
2738 # dependency list.  The idea is that if an input file has a directory
2739 # part the same as the current directory, then the directory part is
2740 # simply removed.  But if the directory part is different, then
2741 # $(top_srcdir) is prepended.  Among other things, this is used to
2742 # generate the dependency list for the output files generated by
2743 # AC_OUTPUT.  Consider what the dependencies should look like in this
2744 # case:
2745 #   AC_OUTPUT(src/out:src/in1:lib/in2)
2746 sub rewrite_inputs_into_dependencies
2748     local (@inputs) = @_;
2749     local ($single, @newinputs);
2751     foreach $single (@inputs)
2752     {
2753         if (&dirname ($single) eq $relative_dir)
2754         {
2755             push (@newinputs, &basename ($single));
2756         }
2757         else
2758         {
2759             push (@newinputs, '$(top_srcdir)/' . $single);
2760         }
2761     }
2763     return @newinputs;
2766 # Handle remaking and configure stuff.
2767 # We need the name of the input file, to do proper remaking rules.
2768 sub handle_configure
2770     local ($local, $input, @secondary_inputs) = @_;
2772     # If SUBDIRS defined, require AC_PROG_MAKE_SET.
2773     &am_line_error ('SUBDIRS', "AC_PROG_MAKE_SET must be used in configure.in")
2774         if &variable_defined ('SUBDIRS') && ! $seen_make_set;
2776     local ($top_reldir);
2778     local ($input_base) = &basename ($input);
2779     local ($local_base) = &basename ($local);
2781     local ($amfile) = $input_base . '.am';
2782     # We know we can always add '.in' because it really should be an
2783     # error if the .in was missing originally.
2784     local ($infile) = '$(srcdir)/' . $input_base . '.in';
2785     local ($colon_infile);
2786     if ($local ne $input)
2787     {
2788         $colon_infile = ':' . $input . '.in';
2789     }
2790     $colon_infile .= ':' . join (':', @secondary_inputs)
2791         if @secondary_inputs;
2793     local (@rewritten) = &rewrite_inputs_into_dependencies (@secondary_inputs);
2794     # This rule remakes the Makefile.in.  Note use of @MAINT@ forces
2795     # us to abandon pretty-printing.  Sigh.
2796     $output_rules .= ($infile
2797                       # NOTE perl 5.003 (with -w) gives a
2798                       # uninitialized value error on the next line.
2799                       # Don't know why.
2800                       . ': '
2801                       . ($seen_maint_mode ? '@MAINT@ ' : '')
2802                       . $amfile . ' '
2803                       . '$(top_srcdir)/configure.in $(ACLOCAL_M4) '
2804                       . join (' ', @rewritten) . "\n"
2805                       . "\tcd \$(top_srcdir) && \$(AUTOMAKE) "
2806                       . ($cygnus_mode ? '--cygnus' : ('--' . $strictness_name))
2807                       . ' ' . $input . $colon_infile . "\n\n");
2809     # This rule remakes the Makefile.
2810     $output_rules .= ($local_base
2811                       # NOTE: bogus uninit value error on next line;
2812                       # see comment above.
2813                       . ': '
2814                       . $infile . ' '
2815                       . '$(top_builddir)/config.status $(BUILT_SOURCES)'
2816                       . "\n"
2817                       . "\tcd \$(top_builddir) \\\n"
2818                       . "\t  && CONFIG_FILES="
2819                       . (($relative_dir eq '.') ? '$@' : '$(subdir)/$@')
2820                       . $colon_infile
2821                       . ' CONFIG_HEADERS= $(SHELL) ./config.status'
2822                       . "\n\n");
2824     if ($relative_dir ne '.')
2825     {
2826         # In subdirectory.
2827         $top_reldir = '../';
2828     }
2829     else
2830     {
2831         &handle_aclocal_m4;
2832         $output_rules .= &file_contents ('remake');
2833         &examine_variable ('CONFIGURE_DEPENDENCIES');
2834         $top_reldir = '';
2835     }
2837     # If we have a configure header, require it.
2838     local ($one_hdr);
2839     local (@local_fullnames) = @config_fullnames;
2840     local (@local_names) = @config_names;
2841     local ($hdr_index) = 0;
2842     local ($distclean_config) = '';
2843     foreach $one_hdr (@config_headers)
2844     {
2845         local ($one_fullname) = shift (@local_fullnames);
2846         local ($one_name) = shift (@local_names);
2847         $hdr_index += 1;
2848         if ($relative_dir eq &dirname ($one_hdr))
2849         {
2850             local ($ch_sans_dir) = &basename ($one_hdr);
2851             local ($cn_sans_dir) = &basename ($one_name);
2853             &require_file_with_conf_line ($config_header_line,
2854                                           $FOREIGN, $ch_sans_dir);
2856             # Header defined and in this directory.
2857             local (@files);
2858             if (-f $relative_dir . '/acconfig.h')
2859             {
2860                 push (@files, 'acconfig.h');
2861             }
2862             if (-f $one_name . '.top')
2863             {
2864                 push (@files, "${cn_sans_dir}.top");
2865             }
2866             if (-f $one_name . '.bot')
2867             {
2868                 push (@files, "${cn_sans_dir}.bot");
2869             }
2871             &push_dist_common (@files);
2873             local ($stamp_name) = 'stamp-h';
2874             $stamp_name .= "${hdr_index}" if scalar (@config_headers) > 1;
2876             local ($xform) = '';
2878             $xform = 's/\@FILES\@/' . join (' ', @files) . '/;';
2879             $xform .= 's/\@CONFIG_HEADER\@/' . "${cn_sans_dir}" . '/;';
2880             $xform .= 's/\@CONFIG_HEADER_IN\@/' . "${ch_sans_dir}" . '/;';
2881             $xform .= 's/\@CONFIG_HEADER_FULL\@/' . "${one_fullname}" . '/;';
2882             $xform .= 's/\@STAMP\@/' . "${stamp_name}" . '/;';
2884             $output_rules .= &file_contents_with_transform ($xform,
2885                                                             'remake-hdr');
2887             &touch ($relative_dir . "/${stamp_name}.in");
2888             &require_file_with_conf_line ($config_header_line, $FOREIGN,
2889                                           "${stamp_name}.in");
2891             $distclean_config .= ' ' if $distclean_config;
2892             $distclean_config .= $cn_sans_dir;
2893         }
2894     }
2896     if ($distclean_config)
2897     {
2898         $output_rules .= &file_contents_with_transform ('s/\@FILES\@/'
2899                                                         . $distclean_config
2900                                                         . '/;',
2901                                                         'clean-hdr');
2902         push (@clean, 'hdr');
2903         &push_phony_cleaners ('hdr');
2904     }
2906     # Set location of mkinstalldirs.
2907     if ($config_aux_dir ne '.' && $config_aux_dir ne '')
2908     {
2909         &define_variable ('mkinstalldirs', ('$(SHELL) ' . $config_aux_dir
2910                                             . '/mkinstalldirs'));
2911     }
2912     else
2913     {
2914         &define_variable ('mkinstalldirs',
2915                           '$(SHELL) $(top_srcdir)/mkinstalldirs');
2916     }
2918     &am_line_error ('CONFIG_HEADER',
2919                     "\`CONFIG_HEADER' is an anachronism; now determined from \`configure.in'")
2920         if &variable_defined ('CONFIG_HEADER');
2922     local ($one_name);
2923     local ($config_header) = '';
2924     foreach $one_name (@config_names)
2925     {
2926         # Generate CONFIG_HEADER define.
2927         local ($one_hdr);
2928         if ($relative_dir eq &dirname ($one_name))
2929         {
2930             $one_hdr = &basename ($one_name);
2931         }
2932         else
2933         {
2934             $one_hdr = "${top_builddir}/${one_name}";
2935         }
2937         $config_header .= ' ' if $config_header;
2938         $config_header .= $one_hdr;
2939     }
2940     if ($config_header)
2941     {
2942         &define_variable ("CONFIG_HEADER", $config_header);
2943     }
2945     # Now look for other files in this directory which must be remade
2946     # by config.status, and generate rules for them.
2947     local (@actual_other_files) = ();
2948     local ($file, $local);
2949     local (@inputs, @rewritten_inputs, $single);
2950     foreach $file (@other_input_files)
2951     {
2952         if ($file =~ /^(.*):(.*)$/)
2953         {
2954             # This is the ":" syntax of AC_OUTPUT.
2955             $file = $1;
2956             $local = &basename ($file);
2957             @inputs = split (':', $2);
2958             @rewritten_inputs = &rewrite_inputs_into_dependencies (@inputs);
2959         }
2960         else
2961         {
2962             # Normal usage.
2963             $local = &basename ($file);
2964             @inputs = ($local . '.in');
2965             @rewritten_inputs =
2966                 &rewrite_inputs_into_dependencies ($file . '.in');
2967         }
2969         # Skip files not in this directory.
2970         next unless &dirname ($file) eq $relative_dir;
2972         # Skip any file that is an automake input.
2973         next if -f $file . '.am';
2975         # Some users have been tempted to put `stamp-h' in the
2976         # AC_OUTPUT line.  This won't do the right thing, so we
2977         # explicitly fail here.
2978         if ($local eq 'stamp-h')
2979         {
2980             # FIXME: allow real filename.
2981             &am_conf_error ('configure.in', $ac_output_line,
2982                             'stamp-h should not appear in AC_OUTPUT');
2983             next;
2984         }
2986         $output_rules .= ($local . ': '
2987                           . '$(top_builddir)/config.status '
2988                           . join (' ', @rewritten_inputs) . "\n"
2989                           . "\t"
2990                           . 'cd $(top_builddir) && CONFIG_FILES='
2991                           . ($relative_dir eq '.' ? '' : '$(subdir)/')
2992                           . '$@' . (length (@rewritten_inputs) > 1
2993                                     ? (':' . join (':', @rewritten_inputs))
2994                                     : '')
2995                           . ' CONFIG_HEADERS= ./config.status'
2996                           . "\n");
2997         push (@actual_other_files, $local);
2999         # Require all input files.
3000         &require_file_with_conf_line ($ac_output_line, $FOREIGN,
3001                                       @inputs);
3002     }
3004     # These files get removed by "make clean".
3005     &define_pretty_variable ('CONFIG_CLEAN_FILES', @actual_other_files);
3008 # Handle C headers.
3009 sub handle_headers
3011     $dir_holds_headers = &am_install_var ('header', 'HEADERS', 'include',
3012                                           'oldinclude', 'pkginclude',
3013                                           'noinst', 'check');
3016 sub handle_gettext
3018     return if ! $seen_gettext || $relative_dir ne '.';
3020     if (! &variable_defined ('SUBDIRS'))
3021     {
3022         &am_conf_error
3023             ("AM_GNU_GETTEXT in configure.in but SUBDIRS not defined");
3024         return;
3025     }
3027     &require_file_with_conf_line ($ac_gettext_line, $FOREIGN, 'ABOUT-NLS')
3028         if $seen_gettext;
3030     if (&variable_defined ('SUBDIRS'))
3031     {
3032         &am_line_error
3033             ('SUBDIRS',
3034              "AM_GNU_GETTEXT in configure.in but \`po' not in SUBDIRS")
3035                 if $contents{'SUBDIRS'} !~ /\bpo\b/;
3036         &am_line_error
3037             ('SUBDIRS',
3038              "AM_GNU_GETTEXT in configure.in but \`intl' not in SUBDIRS")
3039                 if $contents{'SUBDIRS'} !~ /\bintl\b/;
3040     }
3042     # Ensure that each language in ALL_LINGUAS has a .po file, and
3043     # each po file is mentioned in ALL_LINGUAS.
3044     if ($seen_linguas)
3045     {
3046         local (%linguas) = ();
3047         grep ($linguas{$_} = 1, split (' ', $all_linguas));
3049         foreach (<po/*.po>)
3050         {
3051             s/^po\///;
3052             s/\.po$//;
3054             &am_line_error ($all_linguas_line,
3055                             ("po/$_.po exists but \`$_' not in \`ALL_LINGUAS'"))
3056                 if ! $linguas{$_};
3057         }
3059         foreach (keys %linguas)
3060         {
3061             &am_line_error ($all_linguas_line,
3062                             "$_ in \`ALL_LINGUAS' but po/$_.po does not exist")
3063                 if ! -f "po/$_.po";
3064         }
3065     }
3066     else
3067     {
3068         &am_error ("AM_GNU_GETTEXT in configure.in but \`ALL_LINGUAS' not defined");
3069     }
3072 # Handle footer elements.
3073 sub handle_footer
3075     if ($contents{'SOURCES'})
3076     {
3077         # NOTE don't use define_pretty_variable here, because
3078         # $contents{...} is already defined.
3079         $output_vars .= 'SOURCES = ' . $contents{'SOURCES'} . "\n";
3080     }
3081     if ($contents{'OBJECTS'})
3082     {
3083         # NOTE don't use define_pretty_variable here, because
3084         # $contents{...} is already defined.
3085         $output_vars .= 'OBJECTS = ' . $contents{'OBJECTS'} . "\n";
3086     }
3087     if ($contents{'SOURCES'} || $contents{'OBJECTS'})
3088     {
3089         $output_vars .= "\n";
3090     }
3092     if (&variable_defined ('SUFFIXES'))
3093     {
3094         # Push actual suffixes, and not $(SUFFIXES).  Some versions of
3095         # make do not like variable substitutions on the .SUFFIXES
3096         # line.
3097         push (@suffixes, &variable_value_as_list ('SUFFIXES'));
3098     }
3099     if (&target_defined ('.SUFFIXES'))
3100     {
3101         &am_line_error ('.SUFFIXES',
3102                         "use variable \`SUFFIXES', not target \`.SUFFIXES'");
3103     }
3105     # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
3106     # before .SUFFIXES.  So we make sure that .SUFFIXES appears before
3107     # anything else, by sticking it right after the default: target.
3108     $output_header .= ".SUFFIXES:\n";
3109     if (@suffixes)
3110     {
3112         # Make sure suffixes has unique elements.  Sort them to ensure
3113         # the output remains consistent.
3114         local (%suffixes);
3116         grep ($suffixes{$_} = 1, @suffixes);
3118         $output_header .= (".SUFFIXES: "
3119                            . join (' ', sort keys %suffixes)
3120                            . "\n");
3121     }
3122     $output_trailer .= &file_contents ('footer');
3125 # Deal with installdirs target.
3126 sub handle_installdirs
3128     # GNU Makefile standards recommend this.
3129     $output_rules .= ("installdirs:"
3130                       . ($recursive_install
3131                          ? " installdirs-recursive\n"
3132                          : "\n"));
3133     push (@phony, 'installdirs');
3134     if (@installdirs)
3135     {
3136         &pretty_print_rule ("\t" . '$(mkinstalldirs) ', "\t\t",
3137                             @installdirs);
3138     }
3139     $output_rules .= "\n";
3142 # There are several targets which need to be merged.  This is because
3143 # their complete definition is compiled from many parts.  Note that we
3144 # avoid double colon rules, otherwise we'd use them instead.
3145 sub handle_merge_targets
3147     local ($makefile) = @_;
3149     # There are a few install-related variables that you should not define.
3150     local ($var);
3151     foreach $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
3152     {
3153         if (&variable_defined ($var))
3154         {
3155             &am_line_error ($var, "\`$var' should not be defined");
3156         }
3157     }
3159     # Put this at the beginning for the sake of non-GNU makes.  This
3160     # is still wrong if these makes can run parallel jobs.  But it is
3161     # right enough.
3162     unshift (@all, &basename ($makefile));
3164     local ($one_name);
3165     foreach $one_name (@config_names)
3166     {
3167         push (@all, &basename ($one_name))
3168             if &dirname ($one_name) eq $relative_dir;
3169     }
3171     &do_one_merge_target ('info', @info);
3172     &do_one_merge_target ('dvi', @dvi);
3173     &do_check_merge_target;
3174     &do_one_merge_target ('installcheck', @installcheck);
3176     if (defined $options{'no-installinfo'})
3177     {
3178         # FIXME: this is kind of a hack; should find another way to
3179         # know that this is required.
3180         local (@dirs);
3181         if (grep ($_ eq 'install-info-am', @phony))
3182         {
3183             push (@dirs, 'install-info-am');
3184         }
3185         if (&variable_defined ('SUBDIRS'))
3186         {
3187             push (@dirs, 'install-info-recursive');
3188         }
3189         &do_one_merge_target ('install-info', @dirs);
3190     }
3192     # Handle the various install targets specially.  We do this so
3193     # that (eg) "make install-exec" will run "install-exec-recursive"
3194     # if required, but "make install" won't run it twice.  Step one is
3195     # to see if the user specified local versions of any of the
3196     # targets we handle.  "all" is treated as one of these since
3197     # "install" can run it.
3198     push (@install_exec, 'install-exec-local')
3199         if defined $contents{'install-exec-local'};
3200     push (@install_data, 'install-data-local')
3201         if defined $contents{'install-data-local'};
3202     push (@uninstall, 'uninstall-local')
3203         if defined $contents{'uninstall-local'};
3204     local ($utarg);
3205     foreach $utarg ('uninstall-data-local', 'uninstall-data-hook',
3206                     'uninstall-exec-local', 'uninstall-exec-hook')
3207     {
3208         if (defined $contents{$utarg})
3209         {
3210             local ($x);
3211             ($x = $utarg) =~ s/(data|exec)-//;
3212             &am_line_error ($utarg, "use \`$x', not \`$utarg'");
3213         }
3214     }
3215     push (@all, 'all-local')
3216         if defined $contents{'all-local'};
3218     if (defined $contents{'install-local'})
3219     {
3220         &am_line_error ('install-local',
3221                         "use \`install-data' or \`install-exec', not \`install'");
3222     }
3224     # Step two: if we are doing recursive makes, write out the
3225     # appropriate rules.
3226     local (@install);
3227     if ($recursive_install)
3228     {
3229         push (@install, 'install-recursive');
3231         if (@all)
3232         {
3233             local (@hackall) = ();
3234             local ($one_name);
3235             local ($local_headers) = '';
3236             foreach $one_name (@config_names)
3237             {
3238                 if (&dirname ($one_name) eq $relative_dir)
3239                 {
3240                     $local_headers .= ' ' if $local_headers;
3241                     $local_headers .= &basename ($one_name);
3242                 }
3243             }
3244             if ($local_headers)
3245             {
3247                 # This is kind of a hack, but I couldn't see a better
3248                 # way to handle it.  In this particular case, we need
3249                 # to make sure config.h is built before we recurse.
3250                 # We can't do this by changing the order of
3251                 # dependencies to the "all" because that breaks when
3252                 # using parallel makes.  Instead we handle things
3253                 # explicitly.
3254                 $output_rules .= ("all-recursive-am: ${local_headers}"
3255                                   . "\n\t" . '$(MAKE) all-recursive'
3256                                   . "\n\n");
3257                 push (@hackall, 'all-recursive-am');
3258                 push (@phony, 'all-recursive-am');
3259             }
3260             else
3261             {
3262                 push (@hackall, 'all-recursive');
3263             }
3265             $output_rules .= ('all-am: '
3266                               . join (' ', @all)
3267                               . "\n\n");
3268             @all = @hackall;
3269             push (@all, 'all-am');
3270             push (@phony, 'all-am');
3271         }
3272         else
3273         {
3274             @all = ('all-recursive');
3276             # Must always generate `all-am' target, so it can be
3277             # referred to elsewhere.
3278             $output_rules .= "all-am:\n";
3279         }
3280         if (@install_exec)
3281         {
3282             $output_rules .= ('install-exec-am: '
3283                               . join (' ', @install_exec)
3284                               . "\n\n");
3285             @install_exec = ('install-exec-recursive', 'install-exec-am');
3286             push (@install, 'install-exec-am');
3287             push (@phony, 'install-exec-am');
3288         }
3289         else
3290         {
3291             @install_exec = ('install-exec-recursive');
3292         }
3293         if (@install_data)
3294         {
3295             $output_rules .= ('install-data-am: '
3296                               . join (' ', @install_data)
3297                               . "\n\n");
3298             @install_data = ('install-data-recursive', 'install-data-am');
3299             push (@install, 'install-data-am');
3300             push (@phony, 'install-data-am');
3301         }
3302         else
3303         {
3304             @install_data = ('install-data-recursive');
3305         }
3306         if (@uninstall)
3307         {
3308             $output_rules .= ('uninstall-am: '
3309                               . join (' ', @uninstall)
3310                               . "\n\n");
3311             @uninstall = ('uninstall-recursive', 'uninstall-am');
3312             push (@phony, 'uninstall-am');
3313         }
3314         else
3315         {
3316             @uninstall = ('uninstall-recursive');
3317         }
3318     }
3320     # Step three: print definitions users can use.  Code below knows
3321     # that install-exec is done before install-data, beware.
3322     $output_rules .= ("install-exec: "
3323                       . join (' ', @install_exec)
3324                       . "\n");
3325     $output_rules .= "\t\@\$(NORMAL_INSTALL)\n";
3326     if (defined $contents{'install-exec-hook'})
3327     {
3328         $output_rules .= "\t" . '$(MAKE) install-exec-hook' . "\n";
3329     }
3330     $output_rules .= "\n";
3331     push (@install, 'install-exec') if !$recursive_install;
3332     push (@phony, 'install-exec');
3334     $output_rules .= ("install-data: "
3335                       . join (' ', @install_data)
3336                       . "\n");
3337     $output_rules .= "\t\@\$(NORMAL_INSTALL)\n";
3338     if (defined $contents{'install-data-hook'})
3339     {
3340         $output_rules .= "\t" . '$(MAKE) install-data-hook' . "\n";
3341     }
3342     $output_rules .= "\n";
3343     push (@install, 'install-data') if !$recursive_install;
3344     push (@phony, 'install-data');
3346     # If no dependencies for 'install', add 'all'.  Why?  That way
3347     # "make install" at top level of distclean'd distribution won't
3348     # fail because stuff in 'lib' fails to build.
3349     if (! @install || (scalar (@install) == 2
3350                        && $install[0] eq 'install-exec'
3351                        && $install[1] eq 'install-data'))
3352     {
3353         push (@install, 'all');
3354     }
3355     $output_rules .= ('install: '
3356                       . join (' ', @install)
3357                       # Use "@:" as empty command so nothing prints.
3358                       . "\n\t\@:"
3359                       . "\n\n"
3360                       . 'uninstall: '
3361                       . join (' ', @uninstall)
3362                       . "\n\n");
3363     push (@phony, 'install', 'uninstall');
3365     $output_rules .= ('all: '
3366                       . join (' ', @all)
3367                       . "\n\n");
3368     push (@phony, 'all');
3370     # Generate the new 'install-strip' target.
3371     $output_rules .= ("install-strip:\n\t"
3372                       . '$(MAKE) INSTALL_PROGRAM=\'$(INSTALL_PROGRAM) -s\' install'
3373                       . "\n");
3376 # Helper for handle_merge_targets.
3377 sub do_one_merge_target
3379     local ($name, @values) = @_;
3381     if (defined $contents{$name . '-local'})
3382     {
3383         # User defined local form of target.  So include it.
3384         push (@values, $name . '-local');
3385         push (@phony, $name . '-local');
3386     }
3388     &pretty_print_rule ($name . ":", "\t\t", @values);
3389     push (@phony, $name);
3392 # Handle check merge target specially.
3393 sub do_check_merge_target
3395     if (defined $contents{'check-local'})
3396     {
3397         # User defined local form of target.  So include it.
3398         push (@check_tests, 'check-local');
3399         push (@phony, 'check-local');
3400     }
3402     if (! &variable_defined ('SUBDIRS'))
3403     {
3404         # 'check' must depend on `all', but not when doing recursive
3405         # build.
3406         unshift (@check, 'all');
3407     }
3408     else
3409     {
3410         # When subdirs are used, do the `all' build and then do all
3411         # the recursive stuff.  Actually use `all-am' because it
3412         # doesn't recurse; we rely on the check target in the subdirs
3413         # to do the required builds there.
3414         unshift (@check, 'all-am');
3415     }
3417     # The check target must depend on the local equivalent of `all',
3418     # to ensure all the primary targets are built.  Also it must
3419     # depend on the test code named in @check.
3420     &pretty_print_rule ('check:', "\t\t", @check);
3422     # Now the check rules must explicitly run anything named in
3423     # @check_tests.  This is done via a separate make invocation to
3424     # avoid problems with parallel makes.  Every time I write code
3425     # like this I wonder: how could you invent a parallel make and not
3426     # provide any real synchronization facilities?
3427     &pretty_print_rule ("\t\$(MAKE)", "\t  ", @check_tests);
3430 # Handle all 'clean' targets.
3431 sub handle_clean
3433     push (@clean, 'generic');
3434     $output_rules .= &file_contents ('clean');
3435     &push_phony_cleaners ('generic');
3437     local ($target) = $recursive_install ? 'clean-am' : 'clean';
3438     &do_one_clean_target ($target, 'mostly', '', @clean);
3439     &do_one_clean_target ($target, '', 'mostly', @clean);
3440     &do_one_clean_target ($target, 'dist', '', @clean);
3441     &do_one_clean_target ($target, 'maintainer-', 'dist', @clean);
3443     push (@phony, 'clean', 'mostlyclean', 'distclean', 'maintainer-clean');
3445     local (@deps);
3446     if ($recursive_install)
3447     {
3448         # Do -recursive before -am.  If you aren't doing a parallel
3449         # make, this can be nicer.
3450         @deps = ('recursive', 'am');
3451         &do_one_clean_target ('', 'mostly', '', @deps);
3452         &do_one_clean_target ('', '', '', @deps);
3453         &do_one_clean_target ('', 'dist', '', @deps);
3454         &do_one_clean_target ('', 'maintainer-', '', @deps);
3455     }
3458 # Helper for handle_clean.
3459 sub do_one_clean_target
3461     local ($target, $name, $last_name, @deps) = @_;
3463     # Special case: if target not passed, then don't generate
3464     # dependency on next "lower" clean target (eg no
3465     # clean<-mostlyclean derivation).  In this case the target is
3466     # implicitly known to be 'clean'.
3467     local ($flag) = $target;
3468     $target = 'clean' if ! $flag;
3470     grep (($_ = $name . 'clean-' . $_) && 0, @deps);
3471     if ($flag)
3472     {
3473         if ($last_name || $name ne 'mostly')
3474         {
3475             push (@deps, $last_name . $target);
3476         }
3477     }
3479     # If a -local version of the rule is given, add it to the list.
3480     if (defined $contents{$name . $target . '-local'})
3481     {
3482         push (@deps, $name . $target . '-local');
3483     }
3485     # Print the target and the dependencies.
3486     &pretty_print_rule ($name . $target . ": ", "\t\t", @deps);
3488     # FIXME: shouldn't we really print these messages before running
3489     # the dependencies?
3490     if ($name . $target eq 'maintainer-clean')
3491     {
3492         # Print a special warning.
3493         $output_rules .=
3494             ("\t\@echo \"This command is intended for maintainers to use;\"\n"
3495              . "\t\@echo \"it deletes files that may require special "
3496              . "tools to rebuild.\"\n");
3498         $output_rules .= "\trm -f config.status\n"
3499             if $relative_dir eq '.';
3500     }
3501     elsif ($name . $target eq 'distclean')
3502     {
3503         $output_rules .= "\trm -f config.status\n";
3504         $output_rules .= "\trm -f libtool\n" if $seen_libtool;
3505     }
3506     $output_rules .= "\n";
3509 # Handle .PHONY target.
3510 sub handle_phony
3512     &pretty_print_rule ('.PHONY:', "", @phony);
3513     $output_rules .= "\n";
3516 # Handle TESTS variable and other checks.
3517 sub handle_tests
3519     if (defined $options{'dejagnu'})
3520     {
3521         push (@check_tests, 'check-DEJAGNU');
3522         push (@phony, 'check-DEJAGNU');
3524         local ($xform);
3525         if ($cygnus_mode)
3526         {
3527             $xform = 's/^CYGNUS//;';
3528         }
3529         else
3530         {
3531             $xform = 's/^CYGNUS.*$//;';
3532         }
3533         $output_rules .= &file_contents_with_transform ($xform, 'dejagnu');
3535         # In Cygnus mode, these are found in the build tree.
3536         # Otherwise they are looked for in $PATH.
3537         &define_program_variable ('EXPECT', 'build', 'expect', 'expect');
3538         &define_program_variable ('RUNTEST', 'src', 'dejagnu', 'runtest');
3540         # Note that in the rule we don't directly generate site.exp to
3541         # avoid the possibility of a corrupted site.exp if make is
3542         # interrupted.  Jim Meyering has some useful text on this
3543         # topic.
3544         $output_rules .= ("site.exp: Makefile\n"
3545                           . "\t\@echo 'Making a new site.exp file...'\n"
3546                           . "\t-\@rm -f site.bak\n"
3547                           . "\t\@echo '## these variables are automatically generated by make ##' > \$\@-t\n"
3548                           . "\t\@echo '# Do not edit here.  If you wish to override these values' >> \$\@-t\n"
3549                           . "\t\@echo '# edit the last section' >> \$\@-t\n"
3550                           . "\t\@echo 'set tool \$(DEJATOOL)' >> \$\@-t\n"
3551                           . "\t\@echo 'set srcdir \$(srcdir)' >> \$\@-t\n"
3552                           . "\t\@echo 'set objdir' \`pwd\` >> \$\@-t\n");
3554         # Extra stuff for AC_CANONICAL_*
3555         local (@whatlist) = ();
3556         if ($seen_canonical)
3557         {
3558             push (@whatlist, 'host')
3559         }
3561         # Extra stuff only for AC_CANONICAL_SYSTEM.
3562         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
3563         {
3564             push (@whatlist, 'target', 'build');
3565         }
3567         local ($c1, $c2);
3568         foreach $c1 (@whatlist)
3569         {
3570             foreach $c2 ('alias', 'triplet')
3571             {
3572                 $output_rules .= "\t\@echo 'set ${c1}_${c2} \$(${c1}_${c2})' >> \$\@-t\n";
3573             }
3574         }
3576         $output_rules .= ("\t\@echo '## All variables above are generated by configure. Do Not Edit ##' >> \$\@-t\n"
3577                           . "\t-\@sed '1,/^## All variables above are.*##/ d' site.bak >> \$\@-t\n"
3578                           . "\t-\@mv site.exp site.bak\n"
3579                           . "\t\@mv \$\@-t site.exp\n");
3580     }
3581     else
3582     {
3583         local ($c);
3584         foreach $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
3585         {
3586             if (&variable_defined ($c))
3587             {
3588                 &am_line_error ($c, "\`$c' defined but \`dejagnu' not in \`AUTOMAKE_OPTIONS'");
3589             }
3590         }
3591     }
3593     if (&variable_defined ('TESTS'))
3594     {
3595         push (@check_tests, 'check-TESTS');
3596         push (@phony, 'check-TESTS');
3598         $output_rules .= 'check-TESTS: $(TESTS)
3599         @failed=0; all=0; \\
3600         srcdir=$(srcdir); export srcdir; \\
3601         for tst in $(TESTS); do \\
3602           all=`expr $$all + 1`; \\
3603           if test -f $$tst; then dir=.; \\
3604           else dir="$(srcdir)"; fi; \\
3605           if $(TESTS_ENVIRONMENT) $$dir/$$tst; then \\
3606             echo "PASS: $$tst"; \\
3607           else \\
3608             failed=`expr $$failed + 1`; \\
3609             echo "FAIL: $$tst"; \\
3610           fi; \\
3611         done; \\
3612         if test "$$failed" -eq 0; then \\
3613           echo "========================"; \\
3614           echo "All $$all tests passed"; \\
3615           echo "========================"; \\
3616         else \\
3617           echo "$$failed of $$all tests failed"; \\
3618           exit 1; \\
3619         fi
3621     }
3624 # Handle Emacs Lisp.
3625 sub handle_emacs_lisp
3627     local (@elfiles) = &am_install_var ('lisp', 'LISP', 'lisp', 'noinst');
3629     if (@elfiles)
3630     {
3631         # Found some lisp.
3632         &define_configure_variable ('lispdir');
3633         &define_configure_variable ('EMACS');
3634         $output_rules .= (".el.elc:\n"
3635                           . "\t\@echo 'WARNING: Warnings can be ignored. :-)'\n"
3636                           . "\tif test \$(EMACS) != no; then \\\n"
3637                           . "\t  EMACS=\$(EMACS) \$(SHELL) \$(srcdir)/elisp-comp \$<; \\\n"
3638                           . "\tfi\n");
3639         push (@suffixes, '.el', '.elc');
3641         # Generate .elc files.
3642         grep ($_ .= 'c', @elfiles);
3643         &define_pretty_variable ('ELCFILES', @elfiles);
3645         push (@clean, 'lisp');
3646         &push_phony_cleaners ('lisp');
3648         push (@all, '$(ELCFILES)');
3650         local ($varname);
3651         if (&variable_defined ('lisp_LISP'))
3652         {
3653             $varname = 'lisp_LISP';
3654             &am_error ("\`lisp_LISP' defined but \`AM_PATH_LISPDIR' not in \`configure.in'")
3655                 if ! $seen_lispdir;
3656         }
3657         else
3658         {
3659             $varname = 'noinst_LISP';
3660         }
3662         &require_file_with_line ($varname, $FOREIGN, 'elisp-comp');
3663     }
3666 ################################################################
3668 # Scan one file for interesting things.  Subroutine of scan_configure.
3669 sub scan_one_configure_file
3671     local ($filename) = @_;
3673     open (CONFIGURE, $filename)
3674         || die "automake: couldn't open \`$filename': $!\n";
3675     print "automake: reading $filename\n" if $verbose;
3677     while (<CONFIGURE>)
3678     {
3679         # Remove comments from current line.
3680         s/\bdnl\b.*$//;
3681         s/\#.*$//;
3683         # Skip macro definitions.  Otherwise we might be confused into
3684         # thinking that a macro that was only defined was actually
3685         # used.
3686         next if /AC_DEFUN/;
3688         # Populate libobjs array.
3689         if (/AC_FUNC_ALLOCA/)
3690         {
3691             $libsources{'alloca.c'} = 1;
3692         }
3693         elsif (/AC_FUNC_GETLOADAVG/)
3694         {
3695             $libsources{'getloadavg.c'} = 1;
3696         }
3697         elsif (/AC_FUNC_MEMCMP/)
3698         {
3699             $libsources{'memcmp.c'} = 1;
3700         }
3701         elsif (/AC_STRUCT_ST_BLOCKS/)
3702         {
3703             $libsources{'fileblocks.c'} = 1;
3704         }
3705         elsif (/A[CM]_REPLACE_GNU_GETOPT/)
3706         {
3707             $libsources{'getopt.c'} = 1;
3708             $libsources{'getopt1.c'} = 1;
3709         }
3710         elsif (/AM_FUNC_STRTOD/)
3711         {
3712             $libsources{'strtod.c'} = 1;
3713         }
3714         elsif (/AM_WITH_REGEX/)
3715         {
3716             $libsources{'rx.c'} = 1;
3717             $libsources{'rx.h'} = 1;
3718             $libsources{'regex.c'} = 1;
3719             $libsources{'regex.h'} = 1;
3720             $omit_dependencies{'rx.h'} = 1;
3721             $omit_dependencies{'regex.h'} = 1;
3722         }
3723         elsif (/AM_FUNC_MKTIME/)
3724         {
3725             $libsources{'mktime.c'} = 1;
3726         }
3727         elsif (/AM_FUNC_ERROR_AT_LINE/)
3728         {
3729             $libsources{'error.c'} = 1;
3730             $libsources{'error.h'} = 1;
3731         }
3732         elsif (/AM_FUNC_OBSTACK/)
3733         {
3734             $libsources{'obstack.c'} = 1;
3735             $libsources{'obstack.h'} = 1;
3736         }
3737         elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
3738                || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
3739         {
3740             foreach $libobj_iter (split (' ', $1))
3741             {
3742                 if ($libobj_iter =~ /^(.*)\.o$/)
3743                 {
3744                     $libsources{$1 . '.c'} = 1;
3745                 }
3746             }
3747         }
3749         if (! $in_ac_replace && s/AC_REPLACE_FUNCS\s*\(\[?//)
3750         {
3751             $in_ac_replace = 1;
3752         }
3753         if ($in_ac_replace)
3754         {
3755             $in_ac_replace = 0 if s/[\]\)].*$//;
3756             # Remove trailing backslash.
3757             s/\\$//;
3758             foreach (split)
3759             {
3760                 # Need to skip empty elements for Perl 4.
3761                 next if $_ eq '';
3762                 $libsources{$_ . '.c'} = 1;
3763             }
3764         }
3766         if (/$obsolete_rx/o)
3767         {
3768             local ($hint) = '';
3769             if ($obsolete_macros{$1})
3770             {
3771                 $hint = '; ' . $obsolete_macros{$1};
3772             }
3773             &am_conf_line_error ($filename, $., "\`$1' is obsolete$hint");
3774         }
3776         # Process the AC_OUTPUT macro.
3777         if (! $in_ac_output && s/AC_OUTPUT\s*\(\[?//)
3778         {
3779             $in_ac_output = 1;
3780             $ac_output_line = $.;
3781         }
3782         if ($in_ac_output)
3783         {
3784             $in_ac_output = 0 if s/[\]\),].*$//;
3786             # Look at potential Makefile.am's.
3787             foreach (split)
3788             {
3789                 next if $_ eq "\\";
3791                 # Handle $local:$input syntax.  Note that we ignore
3792                 # every input file past the first, though we keep
3793                 # those around for later.
3794                 local ($local, $input, @rest) = split (/:/);
3795                 if (! $input)
3796                 {
3797                     $input = $local;
3798                 }
3799                 else
3800                 {
3801                     # FIXME: should be error if .in is missing.
3802                     $input =~ s/\.in$//;
3803                 }
3805                 if (-f $input . '.am')
3806                 {
3807                     # We have a file that automake should generate.
3808                     push (@make_input_list, $input);
3809                     $make_list{$input} = join (':', ($local, @rest));
3810                 }
3811                 else
3812                 {
3813                     # We have a file that automake should cause to be
3814                     # rebuilt, but shouldn't generate itself.
3815                     push (@other_input_files, $_);
3816                 }
3817             }
3818         }
3820         if (/$AC_CONFIG_AUX_DIR_PATTERN/o)
3821         {
3822             @config_aux_path = $1;
3823         }
3825         # Check for ansi2knr.
3826         $am_c_prototypes = 1 if /AM_C_PROTOTYPES/;
3828         # Check for Cygwin32.
3829         if (/AM_CYGWIN32/)
3830         {
3831             $seen_cygwin32 = 1;
3832             $configure_vars{'EXEEXT'} = 1;
3833         }
3835         # Check for NLS support.
3836         if (/AM_GNU_GETTEXT/)
3837         {
3838             $seen_gettext = 1;
3839             $ac_gettext_line = $.;
3840             $omit_dependencies{'libintl.h'} = 1;
3841         }
3843         # Look for ALL_LINGUAS.
3844         if (/ALL_LINGUAS="(.*)"$/ || /ALL_LINGUAS=(.*)$/)
3845         {
3846             $seen_linguas = 1;
3847             $all_linguas = $1;
3848             $all_linguas_line = $.;
3849         }
3851         # Handle configuration headers.  A config header of `[$1]'
3852         # means we are actually scanning AM_CONFIG_HEADER from
3853         # aclocal.m4.
3854         if (/A([CM])_CONFIG_HEADER\s*\((.*)\)/
3855             && $2 ne '[$1]')
3856         {
3857             &am_conf_line_error
3858                 ($filename, $.,
3859                  "\`AC_CONFIG_HEADER' is obsolete; use \`AM_CONFIG_HEADER'")
3860                     if $1 eq 'C';
3862             $config_header_line = $.;
3863             local ($one_hdr);
3864             foreach $one_hdr (split (' ', $2))
3865             {
3866                 push (@config_fullnames, $one_hdr);
3867                 if ($one_hdr =~ /^([^:]+):(.+)$/)
3868                 {
3869                     push (@config_names, $1);
3870                     push (@config_headers, $2);
3871                 }
3872                 else
3873                 {
3874                     push (@config_names, $one_hdr);
3875                     push (@config_headers, $one_hdr . '.in');
3876                 }
3877             }
3878         }
3880         # Handle AC_CANONICAL_*.  Always allow upgrading to
3881         # AC_CANONICAL_SYSTEM, but never downgrading.
3882         $seen_canonical = $AC_CANONICAL_HOST
3883             if ! $seen_canonical
3884                 && (/AC_CANONICAL_HOST/ || /AC_CHECK_TOOL/);
3885         $seen_canonical = $AC_CANONICAL_SYSTEM if /AC_CANONICAL_SYSTEM/;
3887         $seen_path_xtra = 1 if /AC_PATH_XTRA/;
3889         # This macro handles several different things.
3890         if (/$AM_INIT_AUTOMAKE_PATTERN/o)
3891         {
3892             $seen_make_set = 1;
3893             $seen_package = 1;
3894             $seen_version = 1;
3895             $seen_arg_prog = 1;
3896             $seen_prog_install = 2;
3897             ($package_version = $1) =~ s/$AM_PACKAGE_VERSION_PATTERN/$1/o;
3898             $package_version_line = $.;
3899         }
3901         # This is like AM_INIT_AUTOMAKE, but doesn't actually set the
3902         # package and version number.  (This might change in the
3903         # future).  Yes, I'm not above hacking Automake so it works
3904         # well with other GNU tools -- that is actually the point.
3905         if (/AM_INIT_GUILE_MODULE/)
3906         {
3907             $seen_make_set = 1;
3908             $seen_package = 1;
3909             $seen_version = 1;
3910             $seen_arg_prog = 1;
3911             $seen_prog_install = 2;
3912             @config_aux_path = ('..');
3913         }
3915         # Some things required by Automake.
3916         $seen_make_set = 1 if /AC_PROG_MAKE_SET/;
3917         $seen_arg_prog = 1 if /AC_ARG_PROGRAM/;
3919         if (/AC_PROG_(YACC|RANLIB|CC|CXX|LEX|AWK|CPP|CXXCPP|LN_S)/)
3920         {
3921             $configure_vars{$1} = 1;
3922         }
3923         if (/$AC_CHECK_PATTERN/o)
3924         {
3925             $configure_vars{$3} = 1;
3926         }
3927         if (/$AM_MISSING_PATTERN/o)
3928         {
3929             $configure_vars{$1} = 1;
3930         }
3932         # Explicitly avoid ANSI2KNR -- we AC_SUBST that in protos.m4,
3933         # but later define it elsewhere.  This is pretty hacky.  We
3934         # also explicitly avoid INSTALL_SCRIPT because it is defined
3935         # in header-vars.am.  FIXME.
3936         if (/$AC_SUBST_PATTERN/o
3937             && $1 ne 'ANSI2KNR'
3938             && $1 ne 'INSTALL_SCRIPT')
3939         {
3940             $configure_vars{$1} = 1;
3941         }
3943         $seen_decl_yytext = 1 if /AC_DECL_YYTEXT/;
3944         $seen_maint_mode = 1 if /AM_MAINTAINER_MODE/;
3945         $seen_package = 1 if /PACKAGE=/;
3947         # Skip VERSION of [$2]; that is from AM_INIT_AUTOMAKE.
3948         if (/\bVERSION=(\S+)/ && $1 ne '[$2]')
3949         {
3950             $seen_version = 1;
3951             $package_version = $1;
3952             $package_version_line = $.;
3953         }
3954         elsif (/VERSION=/)
3955         {
3956             $seen_version = 1;
3957         }
3959         # Weird conditionals here because it is always allowed to
3960         # upgrade to AM_PROG_INSTALL but never to downgrade to
3961         # AC_PROG_INSTALL.
3962         $seen_prog_install = 1 if ! $seen_prog_install && /AC_PROG_INSTALL/;
3963         $seen_prog_install = 2 if /AM_PROG_INSTALL/;
3965         $seen_lispdir = 1 if /AM_PATH_LISPDIR/;
3967         if (/AM_PROG_LIBTOOL/)
3968         {
3969             $seen_libtool = 1;
3970             $libtool_line = $.;
3971             $configure_vars{'LIBTOOL'} = 1;
3972             $configure_vars{'RANLIB'} = 1;
3973             $configure_vars{'CC'} = 1;
3974             # AM_PROG_LIBTOOL runs AC_CANONICAL_HOST.  Make sure we
3975             # never downgrade (if we've seen AC_CANONICAL_SYSTEM).
3976             $seen_canonical = $AC_CANONICAL_HOST if ! $seen_canonical;
3977         }
3978     }
3980     close (CONFIGURE);
3983 # Scan configure.in and aclocal.m4 for interesting things.  We must
3984 # scan aclocal.m4 because there might be AC_SUBSTs and such there.
3985 sub scan_configure
3987     # Reinitialize libsources here.  This isn't really necessary,
3988     # since we currently assume there is only one configure.in.  But
3989     # that won't always be the case.
3990     %libsources = ();
3992     local ($in_ac_output, $in_ac_replace) = (0, 0);
3993     local (%make_list, @make_input_list);
3994     local ($libobj_iter);
3996     &scan_one_configure_file ('configure.in');
3997     &scan_one_configure_file ('aclocal.m4')
3998         if -f 'aclocal.m4';
4000     # Set input and output files if not specified by user.
4001     if (! @input_files)
4002     {
4003         @input_files = @make_input_list;
4004         %output_files = %make_list;
4005     }
4007     &am_conf_error ("\`PACKAGE' not defined in configure.in")
4008         if ! $seen_package;
4009     &am_conf_error ("\`VERSION' not defined in configure.in")
4010         if ! $seen_version;
4012     # Look for some files we need.  Always check for these.  This
4013     # check must be done for every run, even those where we are only
4014     # looking at a subdir Makefile.  We must set relative_dir so that
4015     # the file-finding machinery works.
4016     local ($relative_dir) = '.';
4017     &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs', 'missing');
4018     &am_error ("\`install.sh' is an anachronism; use \`install-sh' instead")
4019         if -f $config_aux_path[0] . '/install.sh';
4022 ################################################################
4024 # Set up for Cygnus mode.
4025 sub check_cygnus
4027     return unless $cygnus_mode;
4029     &set_strictness ('foreign');
4030     $options{'no-installinfo'} = 1;
4031     $options{'no-dependencies'} = 1;
4032     $use_dependencies = 0;
4034     if (! $seen_maint_mode)
4035     {
4036         &am_conf_error ("\`AM_MAINTAINER_MODE' required when --cygnus specified");
4037     }
4039     if (! $seen_cygwin32)
4040     {
4041         &am_conf_error ("\`AM_CYGWIN32' required when --cygnus specified");
4042     }
4045 # Do any extra checking for GNU standards.
4046 sub check_gnu_standards
4048     if ($relative_dir eq '.')
4049     {
4050         # In top level (or only) directory.
4051         &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
4052                        'AUTHORS', 'ChangeLog');
4053     }
4055     if ($strictness >= $GNU)
4056     {
4057         if (defined $options{'no-installman'})
4058         {
4059             &am_line_error ('AUTOMAKE_OPTIONS',
4060                             "option \`no-installman' disallowed by GNU standards");
4061         }
4063         if (defined $options{'no-installinfo'})
4064         {
4065             &am_line_error ('AUTOMAKE_OPTIONS',
4066                             "option \`no-installinfo' disallowed by GNU standards");
4067         }
4068     }
4071 # Do any extra checking for GNITS standards.
4072 sub check_gnits_standards
4074     if ($strictness >= $GNITS)
4075     {
4076         if (-f $relative_dir . '/COPYING.LIB')
4077         {
4078             &am_error ("\`${relative_dir}/COPYING.LIB' disallowed by Gnits standards");
4079         }
4081         if ($relative_dir eq '.')
4082         {
4083             if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
4084             {
4085                 # FIXME: allow real filename.
4086                 &am_conf_line_error ('configure.in',
4087                                      $package_version_line,
4088                                      "version \`$package_version' doesn't follow Gnits standards");
4089             }
4090             elsif (defined $1 && -f 'README-alpha')
4091             {
4092                 # This means we have an alpha release.  See
4093                 # GNITS_VERSION_PATTERN for details.
4094                 &require_file ($GNITS, 'README-alpha');
4095             }
4096         }
4097     }
4099     if ($relative_dir eq '.')
4100     {
4101         # In top level (or only) directory.
4102         &require_file ($GNITS, 'THANKS');
4103     }
4106 ################################################################
4108 # Pretty-print something.  HEAD is what should be printed at the
4109 # beginning of the first line, FILL is what should be printed at the
4110 # beginning of every subsequent line.
4111 sub pretty_print_internal
4113     local ($head, $fill, @values) = @_;
4115     local ($column) = length ($head);
4116     local ($result) = $head;
4118     # Fill length is number of characters.  However, each Tab
4119     # character counts for eight.  So we count the number of Tabs and
4120     # multiply by 7.
4121     local ($fill_length) = length ($fill);
4122     $fill_length += 7 * ($fill =~ tr/\t/\t/d);
4124     local ($bol) = ($head eq '');
4125     foreach (@values)
4126     {
4127         # "71" because we also print a space.
4128         if ($column + length ($_) > 71)
4129         {
4130             $result .= " \\\n" . $fill;
4131             $column = $fill_length;
4132             $bol = 1;
4133         }
4135         $result .= ' ' unless ($bol);
4136         $result .= $_;
4137         $column += length ($_) + 1;
4138         $bol = 0;
4139     }
4141     $result .= "\n";
4142     return $result;
4145 # Pretty-print something and append to output_vars.
4146 sub pretty_print
4148     $output_vars .= &pretty_print_internal (@_);
4151 # Pretty-print something and append to output_rules.
4152 sub pretty_print_rule
4154     $output_rules .= &pretty_print_internal (@_);
4158 ################################################################
4160 # See if a target exists.
4161 sub target_defined
4163     local ($target) = @_;
4164     return defined $targets{$target};
4167 # See if a variable exists.
4168 sub variable_defined
4170     local ($var) = @_;
4171     if (defined $targets{$var})
4172     {
4173         &am_line_error ($var, "\`$var' is target; expected variable");
4174         return 0;
4175     }
4176     elsif (defined $contents{$var})
4177     {
4178         $content_seen{$var} = 1;
4179         return 1;
4180     }
4181     return 0;
4184 # Mark a variable as examined.
4185 sub examine_variable
4187     local ($var) = @_;
4188     &variable_defined ($var);
4191 # Return contents of variable as list, split as whitespace.  This will
4192 # recursively follow $(...) and ${...} inclusions.  It preserves @...@
4193 # substitutions.  If PARENT is specified, it is the name of the
4194 # including variable; this is only used for error reports.
4195 sub variable_value_as_list
4197     local ($var, $parent) = @_;
4198     local (@result);
4200     if (defined $targets{$var})
4201     {
4202         &am_line_error ($var, "\`$var' is target; expected variable");
4203     }
4204     elsif (! defined $contents{$var})
4205     {
4206         &am_line_error ($parent, "variable \`$var' not defined");
4207     }
4208     else
4209     {
4210         local (@temp_list);
4211         $content_seen{$var} = 1;
4212         foreach (split (' ', $contents{$var}))
4213         {
4214             # If a comment seen, just leave.
4215             last if /^#/;
4217             # Handle variable substitutions.
4218             if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
4219             {
4220                 local ($varname) = $1;
4221                 local ($from, $to);
4222                 if ($varname =~ /^([^:]*):([^=]*)=(.*)$/)
4223                 {
4224                     $varname = $1;
4225                     $to = $3;
4226                     ($from = $2) =~ s/(\W)/\\$1/g;
4227                 }
4229                 # Find the value.
4230                 @temp_list = &variable_value_as_list ($1, $var);
4232                 # Now rewrite the value if appropriate.
4233                 if ($from)
4234                 {
4235                     grep (s/$from$/$to/, @temp_list);
4236                 }
4238                 push (@result, @temp_list);
4239             }
4240             else
4241             {
4242                 push (@result, $_);
4243             }
4244         }
4245     }
4247     return @result;
4250 # Define a new variable, but only if not already defined.
4251 sub define_variable
4253     local ($var, $value) = @_;
4255     if (! defined $contents{$var})
4256     {
4257         $output_vars .= $var . ' = ' . $value . "\n";
4258         $contents{$var} = $value;
4259         $content_seen{$var} = 1;
4260     }
4263 # Like define_variable, but second arg is a list, and is
4264 # pretty-printed.
4265 sub define_pretty_variable
4267     local ($var, @value) = @_;
4268     if (! defined $contents{$var})
4269     {
4270         $contents{$var} = join (' ', @value);
4271         &pretty_print ($var . ' = ', '', @value);
4272         $content_seen{$var} = 1;
4273     }
4276 # Like define_variable, but define a variable to be the configure
4277 # substitution by the same name.
4278 sub define_configure_variable
4280     local ($var) = @_;
4281     local ($value) = '@' . $var . '@';
4282     &define_variable ($var, $value);
4285 # Define a variable that represents a program to run.  If in Cygnus
4286 # mode, the program is searched for in the build (or source) tree.
4287 # Otherwise no searching is done at all.  Arguments are:
4288 # * VAR      Name of variable to define
4289 # * WHATDIR  Either `src' or `build', depending on where program should
4290 #            be found.  (runtest is in srcdir!)
4291 # * SUBDIR   Subdir of top-level dir
4292 # * PROGRAM  Name of program
4293 # * OVERRIDE If specified, the name of the program to use when not in
4294 #            Cygnus mode.  Defaults to PROGRAM.
4295 sub define_program_variable
4297     local ($var, $whatdir, $subdir, $program, $override) = @_;
4299     if (! $override)
4300     {
4301         $override = $program;
4302     }
4304     if ($cygnus_mode)
4305     {
4306         local ($full) = ('$(top_' . $whatdir . 'dir)/../'
4307                          . $subdir . '/' . $program);
4308         &define_variable ($var, ('`if test -f ' . $full
4309                                  . '; then echo ' . $full . '; else echo '
4310                                  . $program . '; fi`'));
4311     }
4312     else
4313     {
4314         &define_variable ($var, $override);
4315     }
4319 ################################################################
4321 # Read Makefile.am and set up %contents.  Simultaneously copy lines
4322 # from Makefile.am into $output_trailer or $output_vars as
4323 # appropriate.  NOTE we put rules in the trailer section.  We want
4324 # user rules to come after our generated stuff.
4325 sub read_am_file
4327     local ($amfile) = @_;
4329     open (AM_FILE, $amfile) || die "automake: couldn't open \`$amfile': $!\n";
4330     print "automake: reading $amfile\n" if $verbose;
4332     $output_vars = ("# $in_file_name generated automatically by automake "
4333                     . $VERSION . " from $am_file_name\n");
4335     # Generate copyright for generated Makefile.in.
4336     $output_vars .= $gen_copyright;
4338     local ($saw_bk) = 0;
4339     local ($was_rule) = 0;
4340     local ($spacing) = '';
4341     local ($comment) = '';
4342     local ($last_var_name) = '';
4343     local ($blank) = 0;
4345     while (<AM_FILE>)
4346     {
4347         if (/$IGNORE_PATTERN/o)
4348         {
4349             # Merely delete comments beginning with two hashes.
4350         }
4351         elsif (/$WHITE_PATTERN/o)
4352         {
4353             # Stick a single white line before the incoming macro or rule.
4354             $spacing = "\n";
4355             $blank = 1;
4356         }
4357         elsif (/$COMMENT_PATTERN/o)
4358         {
4359             # Stick comments before the incoming macro or rule.  Make
4360             # sure a blank line preceeds first block of comments.
4361             $spacing = "\n" unless $blank;
4362             $blank = 1;
4363             $comment .= $spacing . $_;
4364             $spacing = '';
4365         }
4366         else
4367         {
4368             last;
4369         }
4370     }
4372     $output_vars .= $comment . "\n";
4373     $comment = '';
4374     $spacing = "\n";
4375     local ($am_vars) = '';
4377     local ($is_ok_macro);
4378     while ($_)
4379     {
4380         $_ .= "\n"
4381             unless substr ($_, -1, 1) eq "\n";
4383         $_ =~ s/\@MAINT\@//g
4384             unless $seen_maint_mode;
4386         if (/$IGNORE_PATTERN/o)
4387         {
4388             # Merely delete comments beginning with two hashes.
4389         }
4390         elsif (/$WHITE_PATTERN/o)
4391         {
4392             # Stick a single white line before the incoming macro or rule.
4393             $spacing = "\n";
4394         }
4395         elsif (/$COMMENT_PATTERN/o)
4396         {
4397             # Stick comments before the incoming macro or rule.
4398             $comment .= $spacing . $_;
4399             $spacing = '';
4400         }
4401         elsif ($saw_bk)
4402         {
4403             if ($was_rule)
4404             {
4405                 $output_trailer .= $_;
4406                 $saw_bk = /\\$/;
4407             }
4408             else
4409             {
4410                 $am_vars .= $_;
4411                 $saw_bk = /\\$/;
4412                 # Chop newline and backslash if this line is
4413                 # continued.  FIXME: maybe ensure trailing whitespace
4414                 # exists?
4415                 chop if $saw_bk;
4416                 chop if $saw_bk;
4417                 $contents{$last_var_name} .= $_;
4418             }
4419         }
4420         elsif (/$RULE_PATTERN/o)
4421         {
4422             # warn "** Saw rule .$1.\n";
4423             # Found a rule.
4424             $was_rule = 1;
4425             # Value here doesn't matter; for targets we only note
4426             # existence.
4427             $contents{$1} = 1;
4428             $targets{$1} = 1;
4429             $content_lines{$1} = $.;
4430             $output_trailer .= $comment . $spacing . $_;
4431             $comment = $spacing = '';
4432             $saw_bk = /\\$/;
4433         }
4434         elsif (($is_ok_macro = /$MACRO_PATTERN/o)
4435                || /$BOGUS_MACRO_PATTERN/o)
4436         {
4437             # Found a macro definition.
4438             $was_rule = 0;
4439             $last_var_name = $1;
4440             if ($2 ne '' && substr ($2, -1) eq "\\")
4441             {
4442                 $contents{$1} = substr ($2, 0, length ($2) - 1);
4443             }
4444             else
4445             {
4446                 $contents{$1} = $2;
4447             }
4448             $content_lines{$1} = $.;
4449             $am_vars .= $comment . $spacing . $_;
4450             $comment = $spacing = '';
4451             $saw_bk = /\\$/;
4453             # Error if bogus.
4454             &am_line_error ($., "bad macro name \`$1'")
4455                 if ! $is_ok_macro;
4456         }
4457         else
4458         {
4459             # This isn't an error; it is probably a continued rule.
4460             # In fact, this is what we assume.
4461             $was_rule = 1;
4462             $output_trailer .= $comment . $spacing . $_;
4463             $comment = $spacing = '';
4464             $saw_bk = /\\$/;
4465         }
4467         $_ = <AM_FILE>;
4468     }
4470     $output_trailer .= $comment;
4472     # Compute relative location of the top object directory.
4473     local (@topdir) = ();
4474     foreach (split (/\//, $relative_dir))
4475     {
4476         next if $_ eq '.' || $_ eq '';
4477         if ($_ eq '..')
4478         {
4479             pop @topdir;
4480         }
4481         else
4482         {
4483             push (@topdir, '..');
4484         }
4485     }
4486     @topdir = ('.') if ! @topdir;
4488     $top_builddir = join ('/', @topdir);
4489     local ($build_rx);
4490     ($build_rx = $top_builddir) =~ s/(\W)/\\$1/g;
4491     $output_vars .= &file_contents_with_transform
4492                         ('s/\@top_builddir\@/' . $build_rx . '/g;',
4493                          'header-vars');
4495     # Generate some useful variables when AC_CANONICAL_* used.  FIXME:
4496     # this should use generic %configure_vars method.
4497     if ($seen_canonical)
4498     {
4499         local ($curs, %vars);
4500         $vars{'host_alias'} = 'host_alias';
4501         $vars{'host_triplet'} = 'host';
4502         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
4503         {
4504             $vars{'build_alias'} = 'build_alias';
4505             $vars{'build_triplet'} = 'build';
4506             $vars{'target_alias'} = 'target_alias';
4507             $vars{'target_triplet'} = 'target';
4508         }
4509         foreach $curs (sort keys %vars)
4510         {
4511             $output_vars .= "$curs = \@$vars{$curs}\@\n";
4512             $contents{$curs} = "\@$vars{$curs}\@";
4513         }
4514     }
4516     local ($curs);
4517     foreach $curs (sort keys %configure_vars)
4518     {
4519         &define_configure_variable ($curs);
4520     }
4522     $output_vars .= $am_vars;
4525 ################################################################
4527 sub initialize_global_constants
4529     # Values for AC_CANONICAL_*
4530     $AC_CANONICAL_HOST = 1;
4531     $AC_CANONICAL_SYSTEM = 2;
4533     # Associative array of standard directory names.  Entry is TRUE if
4534     # corresponding directory should be installed during
4535     # 'install-exec' phase.
4536     %exec_dir_p =
4537         ('bin', 1,
4538          'sbin', 1,
4539          'libexec', 1,
4540          'data', 0,
4541          'sysconf', 1,
4542          'localstate', 1,
4543          'lib', 1,
4544          'info', 0,
4545          'man', 0,
4546          'include', 0,
4547          'oldinclude', 0,
4548          'pkgdata', 0,
4549          'pkglib', 1,
4550          'pkginclude', 0
4551          );
4553     # Helper text for dealing with man pages.
4554     $install_man_format =
4555     '   @sect=@SECTION@;                                \\
4556         inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
4557         if test -f $(srcdir)/@MAN@; then file=$(srcdir)/@MAN@; \\
4558         else file=@MAN@; fi; \\
4559         echo " $(INSTALL_DATA) $$file $(mandir)/man$$sect/$$inst"; \\
4560         $(INSTALL_DATA) $$file $(mandir)/man$$sect/$$inst
4563     $uninstall_man_format =
4564     '   inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
4565         rm -f $(mandir)/man@SECTION@/$$inst
4568     # Commonly found files we look for and automatically include in
4569     # DISTFILES.
4570     @common_files =
4571         (
4572          "README", "THANKS", "TODO", "NEWS", "COPYING", "COPYING.LIB",
4573          "INSTALL", "ABOUT-NLS", "ChangeLog", "configure", "configure.in",
4574          "config.guess", "config.sub", "AUTHORS", "BACKLOG", "ABOUT-GNU",
4575          "libversion.in", "mdate-sh", "mkinstalldirs", "install-sh",
4576          'texinfo.tex', "ansi2knr.c", "ansi2knr.1", 'elisp-comp',
4577          'interlock', 'ylwrap', 'acinclude.m4', @libtoolize_files,
4578          'missing'
4579          );
4581     # Commonly used files we auto-include, but only sometimes.
4582     @common_sometimes =
4583         (
4584          "aclocal.m4", "acconfig.h", "config.h.top",
4585          "config.h.bot", "stamp-h.in", 'stamp-vti'
4586          );
4588     $USAGE = "\
4589   -a, --add-missing     add missing standard files to package
4590   --amdir=DIR           directory storing config files
4591   --build-dir=DIR       directory where build being done (for dependencies)
4592   --cygnus              assume program is part of Cygnus-style tree
4593   --foreign             set strictness to foreign
4594   --gnits               set strictness to gnits
4595   --gnu                 set strictness to gnu
4596   --help                print this help, then exit
4597   -i, --include-deps    include generated dependencies in Makefile.in
4598   --no-force            only update Makefile.in's that are out of date
4599   -o DIR, --output-dir=DIR
4600                         put generated Makefile.in's into DIR
4601   --srcdir-name=DIR     name used for srcdir (for dependencies)
4602   -v, --verbose         verbosely list files processed
4603   --version             print version number, then exit\n";
4605     # Copyright on generated Makefile.ins.
4606     $gen_copyright = "\
4607 # Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
4608 # This Makefile.in is free software; the Free Software Foundation
4609 # gives unlimited permission to copy, distribute and modify it.
4612     # Ignore return result from chmod, because it might give an error
4613     # if we chmod a symlink.
4614     $dist_header = "\t" . '-chmod -R a+r $(distdir)' . "\n";
4615     $dist{'tarZ'} = ("\t"
4616                      . '$(TAR) chf - $(distdir) | compress -c > $(distdir).tar.Z'
4617                      . "\n");
4618     $dist{'shar'} = ("\t"
4619                      . 'shar $(distdir) | gzip > $(distdir).shar.gz'
4620                      . "\n");
4621     $dist{'zip'} = "\t" . 'zip -rq $(distdir).zip $(distdir)' . "\n";
4622     $dist{'dist'} = "\t" .  'GZIP=$(GZIP) $(TAR) chozf $(distdir).tar.gz $(distdir)' . "\n";
4623     $dist_trailer = "\t" . 'rm -rf $(distdir)' . "\n";
4626 # (Re)-Initialize per-Makefile.am variables.
4627 sub initialize_per_input
4629     # These two variables are used when generating each Makefile.in.
4630     # They hold the Makefile.in until it is ready to be printed.
4631     $output_rules = '';
4632     $output_vars = '';
4633     $output_trailer = '';
4634     $output_header = '';
4636     # Suffixes found during a run.
4637     @suffixes = ();
4639     # This holds the contents of a Makefile.am, as parsed by
4640     # read_am_file.
4641     %contents = ();
4643     # This holds the names which are targets.  These also appear in
4644     # %contents.
4645     %targets = ();
4647     # This holds the line numbers at which various elements of
4648     # %contents are defined.
4649     %content_lines = ();
4651     # This holds a 1 if a particular variable was examined.
4652     %content_seen = ();
4654     # This holds the "relative directory" of the current Makefile.in.
4655     # Eg for src/Makefile.in, this is "src".
4656     $relative_dir = '';
4658     # This holds a list of files that are included in the
4659     # distribution.
4660     %dist_common = ();
4662     # List of dependencies for the obvious targets.
4663     @install_data = ();
4664     @install_exec = ();
4665     @uninstall = ();
4666     @installdirs = ();
4668     @info = ();
4669     @dvi = ();
4670     @all = ();
4671     @check = ();
4672     @check_tests = ();
4673     @installcheck = ();
4674     @clean = ();
4676     @phony = ();
4678     # These are pretty obvious, too.  They are used to define the
4679     # SOURCES and OBJECTS variables.
4680     @sources = ();
4681     @objects = ();
4683     # TRUE if current directory holds any C source files.
4684     $dir_holds_sources = 0;
4686     # These variables track inclusion of various compile-related .am
4687     # files.  $included_generic_compile is TRUE if the basic code has
4688     # been included.  $included_knr_compile is TRUE if the ansi2knr
4689     # code has been included.  $included_libtool_compile is TRUE if
4690     # libtool support has been included.
4691     $included_generic_compile = 0;
4692     $included_knr_compile = 0;
4693     $included_libtool_compile = 0;
4695     # TRUE if current directory holds any headers.
4696     $dir_holds_headers = 0;
4698     # TRUE if install targets should work recursively.
4699     $recursive_install = 0;
4701     # All .P files.
4702     %dep_files = ();
4704     # Strictness levels.
4705     $strictness = $default_strictness;
4706     $strictness_name = $default_strictness_name;
4708     # Options from AUTOMAKE_OPTIONS.
4709     %options = ();
4711     # Whether or not dependencies are handled.  Can be further changed
4712     # in handle_options.
4713     $use_dependencies = $cmdline_use_dependencies;
4715     # Per Makefile.am.
4716     $local_maint_charset = $maint_charset;
4718     # All yacc and lex source filenames for this directory.  Use
4719     # filenames instead of raw count so that multiple instances are
4720     # counted correctly (eg one yacc file can appear in multiple
4721     # programs without harm).
4722     %yacc_sources = ();
4723     %lex_sources = ();
4725     # C++ source extensions we've seen.
4726     %cxx_extensions = ();
4728     # TRUE if we've seen any non-C++ sources.  This actually holds a
4729     # line number or the name of a symbol corresponding to a line
4730     # number where the C sources were seen.  If it is -1 then it means
4731     # we couldn't (easily) figure out which line of the Makefile.am
4732     # mentioned the sources.
4733     $seen_c_source = 0;
4735     # This is a list of all targets to run during "make dist".
4736     @dist_targets = ();
4738     # Keys in this hash are the names of ._o files which must depend
4739     # on ansi2knr.  Ugh.
4740     %de_ansi_objects = ();
4744 ################################################################
4746 # Return contents of a file from $am_dir, automatically skipping
4747 # macros or rules which are already known.  Runs command on each line
4748 # as it is read; this command can modify $_.
4749 sub file_contents_with_transform
4751     local ($command, $basename) = @_;
4752     local ($file) = $am_dir . '/' . $basename . '.am';
4754     if ($command ne '' && substr ($command, -1) ne ';')
4755     {
4756         die "automake: programming error in file_contents_with_transform\n";
4757     }
4759     open (FC_FILE, $file)
4760         || die "automake: installation error: cannot open \`$file'\n";
4761     # Looks stupid?
4762     # print "automake: reading $file\n" if $verbose;
4764     local ($was_rule) = 0;
4765     local ($result_vars) = '';
4766     local ($result_rules) = '';
4767     local ($comment) = '';
4768     local ($spacing) = "\n";
4769     local ($skipping) = 0;
4770     local ($had_chars);
4772     while (<FC_FILE>)
4773     {
4774         $_ =~ s/\@MAINT\@//g
4775             unless $seen_maint_mode;
4777         $had_chars = length ($_) && $_ ne "\n";
4778         eval $command;
4779         # If the transform caused all the characters to go away, then
4780         # ignore the line.  Why do this?  Because in Perl 4, a "next"
4781         # inside of an eval doesn't affect a loop outside the eval.
4782         # So we can't pass in a "transform" that uses next.  We used
4783         # to do this.  "Empty" also means consisting of a single
4784         # newline.
4785         next if $had_chars && ($_ eq '' || $_ eq "\n");
4787         if (/$IGNORE_PATTERN/o)
4788         {
4789             # Merely delete comments beginning with two hashes.
4790         }
4791         elsif (/$WHITE_PATTERN/o)
4792         {
4793             # Stick a single white line before the incoming macro or rule.
4794             $spacing = "\n";
4795         }
4796         elsif (/$COMMENT_PATTERN/o)
4797         {
4798             # Stick comments before the incoming macro or rule.
4799             $comment .= $spacing . $_;
4800             $spacing = '';
4801         }
4802         elsif ($saw_bk)
4803         {
4804             if ($was_rule)
4805             {
4806                 $result_rules .= $_ if ! $skipping;
4807             }
4808             else
4809             {
4810                 $result_vars .= $_ if ! $skipping;
4811             }
4812             $saw_bk = /\\$/;
4813         }
4814         elsif (/$RULE_PATTERN/o)
4815         {
4816             # warn "** Found rule .$1.\n";
4817             # Found a rule.
4818             $was_rule = 1;
4819             $skipping = defined $contents{$1};
4820             # warn "** Skip $skipping\n" if $skipping;
4821             $result_rules .= $comment . $spacing . $_ if ! $skipping;
4822             $comment = $spacing = '';
4823             $saw_bk = /\\$/;
4824         }
4825         elsif (/$MACRO_PATTERN/o)
4826         {
4827             # warn "** Found macro .$1.\n";
4828             # Found a variable reference.
4829             $was_rule = 0;
4830             $skipping = defined $contents{$1};
4831             # warn "** Skip $skipping\n" if $skipping;
4832             $result_vars .= $comment . $spacing . $_ if ! $skipping;
4833             $comment = $spacing = '';
4834             $saw_bk = /\\$/;
4835         }
4836         else
4837         {
4838             # This isn't an error; it is probably a continued rule.
4839             # In fact, this is what we assume.
4840             $was_rule = 1;
4841             $result_rules .= $comment . $spacing . $_ if ! $skipping;
4842             $comment = $spacing = '';
4843             $saw_bk = /\\$/;
4844         }
4845     }
4847     close (FC_FILE);
4848     return $result_vars . $result_rules . $comment;
4851 # Like file_contents_with_transform, but no transform.
4852 sub file_contents
4854     return &file_contents_with_transform ('', @_);
4857 # Find all variable prefixes that are used for install directories.  A
4858 # prefix `zar' qualifies iff:
4859 # * `zardir' is a variable.
4860 # * `zar_PRIMARY' is a variable.
4861 sub am_primary_prefixes
4863     local ($primary, @prefixes) = @_;
4865     local (%valid, $varname);
4866     grep ($valid{$_} = 0, @prefixes);
4867     $valid{'EXTRA'} = 0;
4868     foreach $varname (keys %contents)
4869     {
4870         if ($varname =~ /^(.*)_$primary$/)
4871         {
4872             if (! defined $valid{$1}
4873                 && ! &variable_defined ($1 . 'dir')
4874                 # Note that a configure variable is always legitimate.
4875                 # It is natural to name such variables after the
4876                 # primary, so we explicitly allow it.
4877                 && ! defined $configure_vars{$varname})
4878             {
4879                 &am_line_error ($varname, "invalid variable \"$varname\"");
4880             }
4881             else
4882             {
4883                 # Ensure all extended prefixes are actually used.
4884                 $valid{$1} = 1;
4885             }
4886         }
4887     }
4889     return %valid;
4892 # Handle `where_HOW' variable magic.  Does all lookups, generates
4893 # install code, and possibly generates code to define the primary
4894 # variable.  The first argument is the name of the .am file to munge,
4895 # the second argument is the primary variable (eg HEADERS), and all
4896 # subsequent arguments are possible installation locations.  Returns
4897 # list of all values of all _HOW targets.
4899 # FIXME: this should be rewritten to be cleaner.  It should be broken
4900 # up into multiple functions.
4902 # Usage is: am_install_var (OPTION..., file, HOW, where...)
4903 sub am_install_var
4905     local (@args) = @_;
4907     local ($do_clean) = 0;
4909     local ($ltxform);
4910     if (defined $configure_vars{'LIBTOOL'})
4911     {
4912         # Transform '@LIBTOOL ...@' to '$(LIBTOOL) ...'
4913         $ltxform = 's/\@LIBTOOL([^\@]*)\@/\$(LIBTOOL) $1/;';
4914     }
4915     else
4916     {
4917         # Delete '@LIBTOOL ...@'
4918         $ltxform = 's/\@LIBTOOL([^\@]*)\@//;';
4919     }
4921     local ($cygxform);
4922     if (! $seen_cygwin32)
4923     {
4924         $cygxform = 's/\@EXEEXT\@//g; s/^NOTCYGWIN//; s/^CYGWIN.*$//;';
4925     }
4926     else
4927     {
4928         $cygxform = 's/\@EXEEXT\@/\$(EXEEXT)/g; s/^CYGWIN//; s/^NOTCYGWIN.*$//;';
4929     }
4931     while (@args)
4932     {
4933         if ($args[0] eq '-clean')
4934         {
4935             $do_clean = 1;
4936         }
4937         elsif ($args[0] !~ /^-/)
4938         {
4939             last;
4940         }
4941         shift (@args);
4942     }
4943     local ($file, $primary, @prefixes) = @args;
4945     local (@used) = ();
4946     local (@result) = ();
4948     # Now that configure substitutions are allowed in where_HOW
4949     # variables, it is an error to actually define the primary.
4950     &am_line_error ($primary, "\`$primary' is an anachronism")
4951         if &variable_defined ($primary);
4954     # Look for misspellings.  It is an error to have a variable ending
4955     # in a "reserved" suffix whose prefix is unknown, eg
4956     # "bni_PROGRAMS".  However, unusual prefixes are allowed if a
4957     # variable of the same name (with "dir" appended) exists.  For
4958     # instance, if the variable "zardir" is defined, then
4959     # "zar_PROGRAMS" becomes valid.  This is to provide a little extra
4960     # flexibility in those cases which need it.  Perhaps it should be
4961     # disallowed in the Gnits case?  The problem is, sometimes it is
4962     # useful to put things in a subdir of eg pkgdatadir, perhaps even
4963     # for Gnitsoids.
4964     local (%valid) = &am_primary_prefixes ($primary, @prefixes);
4966     # If a primary includes a configure substitution, then the EXTRA_
4967     # form is required.  Otherwise we can't properly do our job.
4968     local ($require_extra);
4969     local ($warned_about_extra) = 0;
4971     local ($clean_file) = $file . '-clean';
4972     local ($one_name);
4973     local ($X);
4974     foreach $X (sort keys %valid)
4975     {
4976         $one_name = $X . '_' . $primary;
4977         if (&variable_defined ($one_name))
4978         {
4979             # Append actual contents of where_PRIMARY variable to
4980             # result.
4981             local ($rcurs);
4982             foreach $rcurs (&variable_value_as_list ($one_name))
4983             {
4984                 # Skip configure substitutions.  Possibly bogus.
4985                 if ($rcurs =~ /^\@.*\@$/)
4986                 {
4987                     if ($X eq 'EXTRA')
4988                     {
4989                         if (! $warned_about_extra)
4990                         {
4991                             $warned_about_extra = 1;
4992                             &am_line_error ($one_name,
4993                                             "\`$one_name' contains configure substitution, but shouldn't");
4994                         }
4995                     }
4996                     # Check here to make sure variables defined in
4997                     # configure.in do not imply that EXTRA_PRIMARY
4998                     # must be defined.
4999                     elsif (! defined $configure_vars{$one_name})
5000                     {
5001                         $require_extra = $one_name;
5002                     }
5003                     next;
5004                 }
5005                 push (@result, $rcurs);
5006             }
5008             # "EXTRA" shouldn't be used when generating clean targets,
5009             # @all, or install targets.
5010             next if $X eq 'EXTRA';
5012             if ($do_clean)
5013             {
5014                 $output_rules .=
5015                     &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go;'
5016                                                    . $cygxform,
5017                                                    $clean_file);
5019                 push (@clean, $X . $primary);
5020                 &push_phony_cleaners ($X . $primary);
5021             }
5023             if ($X eq 'check')
5024             {
5025                 push (@check, '$(' . $one_name . ')');
5026             }
5027             else
5028             {
5029                 push (@used, '$(' . $one_name . ')');
5030             }
5031             if ($X eq 'noinst' || $X eq 'check')
5032             {
5033                 # Objects which don't get installed by default.
5034                 next;
5035             }
5037             $output_rules .=
5038                 &file_contents_with_transform ('s/\@DIR\@/' . $X . '/g;'
5039                                                . $ltxform . $cygxform,
5040                                                $file);
5042             push (@uninstall, 'uninstall-' . $X . $primary);
5043             push (@phony, 'uninstall-' . $X . $primary);
5044             push (@installdirs, '$(' . $X . 'dir)');
5045             if (defined $exec_dir_p{$X} ? $exec_dir_p{$X} : ($X =~ /exec/))
5046             {
5047                 push (@install_exec, 'install-' . $X . $primary);
5048                 push (@phony, 'install-' . $X . $primary);
5049             }
5050             else
5051             {
5052                 push (@install_data, 'install-' . $X . $primary);
5053                 push (@phony, 'install-' . $X . $primary);
5054             }
5055         }
5056     }
5058     if (@used)
5059     {
5060         # Define it.
5061         &define_pretty_variable ($primary, @used);
5062         $output_vars .= "\n";
5063     }
5065     if ($require_extra && ! &variable_defined ('EXTRA_' . $primary))
5066     {
5067         &am_line_error ($require_extra,
5068                         "\`$require_extra' contains configure substitution, but \`EXTRA_$primary' not defined");
5069     }
5071     # Push here because PRIMARY might be configure time determined.
5072     push (@all, '$(' . $primary . ')')
5073         if @used;
5075     return (@result);
5079 ################################################################
5081 # This variable is local to the "require file" set of functions.
5082 @require_file_paths = ();
5084 # Verify that the file must exist in the current directory.  Usage:
5085 # require_file (isconfigure, line_number, strictness, file) strictness
5086 # is the strictness level at which this file becomes required.  Must
5087 # set require_file_paths before calling this function.
5088 # require_file_paths is set to hold a single directory (the one in
5089 # which the first file was found) before return.
5090 sub require_file_internal
5092     local ($is_configure, $line, $mystrict, @files) = @_;
5093     local ($file, $fullfile);
5094     local ($found_it, $errfile, $errdir);
5095     local ($save_dir);
5097     foreach $file (@files)
5098     {
5099         $found_it = 0;
5100         foreach $dir (@require_file_paths)
5101         {
5102             if ($dir eq '.')
5103             {
5104                 $fullfile = $relative_dir . "/" . $file;
5105                 $errdir = $relative_dir unless $errdir;
5106             }
5107             else
5108             {
5109                 $fullfile = $dir . "/" . $file;
5110                 $errdir = $dir unless $errdir;
5111             }
5113             # Use different name for "error filename".  Otherwise on
5114             # an error the bad file will be reported as eg
5115             # `../../install-sh' when using the default
5116             # config_aux_path.
5117             $errfile = $errdir . '/' . $file;
5119             if (-f $fullfile)
5120             {
5121                 $found_it = 1;
5122                 # FIXME: Once again, special-case `.'.
5123                 &push_dist_common ($file)
5124                     if $dir eq $relative_dir || $dir eq '.';
5125                 $save_dir = $dir;
5126                 last;
5127             }
5128         }
5130         if ($found_it)
5131         {
5132             # Prune the path list.
5133             @require_file_paths = $save_dir;
5134         }
5135         else
5136         {
5137             if ($strictness >= $mystrict)
5138             {
5139                 local ($trailer) = '';
5140                 local ($suppress) = 0;
5142                 # Only install missing files according to our desired
5143                 # strictness level.
5144                 if ($add_missing)
5145                 {
5146                     $trailer = "; installing";
5147                     $suppress = 1;
5149                     # Maybe run libtoolize.
5150                     if ($seen_libtool
5151                         && grep ($_ eq $file, @libtoolize_files)
5152                         && system ('libtoolize', '--automake'))
5153                     {
5154                         $suppress = 0;
5155                         $trailer .= "; cannot run \`libtoolize': $!";
5156                     }
5157                     elsif (-f ($am_dir . '/' . $file))
5158                     {
5159                         # Install the missing file.  Symlink if we
5160                         # can, copy if we must.  Note: delete the file
5161                         # first, in case it is a dangling symlink.
5162                         unlink ($errfile);
5163                         if ($symlink_exists)
5164                         {
5165                             if (! symlink ($am_dir . '/' . $file, $errfile))
5166                             {
5167                                 $suppress = 0;
5168                                 $trailer .= "; error while making link: $!\n";
5169                             }
5170                         }
5171                         elsif (! system ('cp', $am_dir . '/' . $file, $errfile))
5172                         {
5173                             $suppress = 0;
5174                             $trailer .= "\n    error while making link\n";
5175                         }
5176                     }
5177                 }
5179                 local ($save) = $exit_status;
5180                 if ($is_configure)
5181                 {
5182                     # FIXME: allow actual file to be specified.
5183                     &am_conf_line_error
5184                         ('configure.in', $line,
5185                          "required file \"$errfile\" not found$trailer");
5186                 }
5187                 else
5188                 {
5189                     &am_line_error
5190                         ($line,
5191                          "required file \"$errfile\" not found$trailer");
5192                 }
5193                 $exit_status = $save if $suppress;
5194             }
5195         }
5196     }
5199 # Like require_file_with_line, but error messages refer to
5200 # configure.in, not the current Makefile.am.
5201 sub require_file_with_conf_line
5203     @require_file_paths = '.';
5204     &require_file_internal (1, @_);
5207 sub require_file_with_line
5209     @require_file_paths = '.';
5210     &require_file_internal (0, @_);
5213 sub require_file
5215     @require_file_paths = '.';
5216     &require_file_internal (0, '', @_);
5219 # Require a file that is also required by Autoconf.  Looks in
5220 # configuration path, as specified by AC_CONFIG_AUX_DIR.
5221 sub require_config_file
5223     @require_file_paths = @config_aux_path;
5224     &require_file_internal (1, '', @_);
5225     local ($dir) = $require_file_paths[0];
5226     @config_aux_path = @require_file_paths;
5227     if ($dir eq '.')
5228     {
5229         $config_aux_dir = '.';
5230     }
5231     else
5232     {
5233         $config_aux_dir = '$(top_srcdir)/' . $dir;
5234     }
5237 # Assumes that the line number is in Makefile.am.
5238 sub require_conf_file_with_line
5240     @require_file_paths = @config_aux_path;
5241     &require_file_internal (0, @_);
5242     local ($dir) = $require_file_paths[0];
5243     @config_aux_path = @require_file_paths;
5244     if ($dir eq '.')
5245     {
5246         $config_aux_dir = '.';
5247     }
5248     else
5249     {
5250         $config_aux_dir = '$(top_srcdir)/' . $dir;
5251     }
5254 # Assumes that the line number is in Makefile.am.
5255 sub require_conf_file_with_conf_line
5257     @require_file_paths = @config_aux_path;
5258     &require_file_internal (1, @_);
5259     local ($dir) = $require_file_paths[0];
5260     @config_aux_path = @require_file_paths;
5261     if ($dir eq '.')
5262     {
5263         $config_aux_dir = '.';
5264     }
5265     else
5266     {
5267         $config_aux_dir = '$(top_srcdir)/' . $dir;
5268     }
5271 ################################################################
5273 # Push a list of files onto dist_common.
5274 sub push_dist_common
5276     local (@files) = @_;
5277     local ($file);
5279     foreach $file (@files)
5280     {
5281         $dist_common{$file} = 1;
5282     }
5285 # Push a list of clean targets onto phony.
5286 sub push_phony_cleaners
5288     local ($base) = @_;
5289     local ($target);
5290     foreach $target ('mostly', 'dist', '', 'maintainer-')
5291     {
5292         push (@phony, $target . 'clean-' . $base);
5293     }
5296 # Set strictness.
5297 sub set_strictness
5299     $strictness_name = $_[0];
5300     if ($strictness_name eq 'gnu')
5301     {
5302         $strictness = $GNU;
5303     }
5304     elsif ($strictness_name eq 'gnits')
5305     {
5306         $strictness = $GNITS;
5307     }
5308     elsif ($strictness_name eq 'foreign')
5309     {
5310         $strictness = $FOREIGN;
5311     }
5312     else
5313     {
5314         die "automake: level \`$strictness_name' not recognized\n";
5315     }
5319 ################################################################
5321 # Return directory name of file.
5322 sub dirname
5324     local ($file) = @_;
5325     local ($sub);
5327     ($sub = $file) =~ s,/+[^/]+$,,g;
5328     $sub = '.' if $sub eq $file;
5329     return $sub;
5332 # Return file name of a file.
5333 sub basename
5335     local ($file) = @_;
5336     local ($sub);
5338     ($sub = $file) =~s,^.*/+,,g;
5339     return $sub;
5342 # Touch a file.
5343 sub touch
5345     local ($file) = @_;
5347     open (TOUCH, ">> $file");
5348     close (TOUCH);
5351 # Glob something.  Do this to avoid indentation screwups everywhere we
5352 # want to glob.  Gross!
5353 sub my_glob
5355     local ($pat) = @_;
5356     return <${pat}>;
5359 ################################################################
5361 # Print an error message and set exit status.
5362 sub am_error
5364     warn "automake: ${am_file}.am: ", join (' ', @_), "\n";
5365     $exit_status = 1;
5368 sub am_line_error
5370     local ($symbol, @args) = @_;
5372     if ($symbol && "$symbol" ne '-1')
5373     {
5374         # If SYMBOL not already a line number, look it up in Makefile.am.
5375         if ($symbol =~ /^\d+$/)
5376         {
5377             $symbol .= ': ';
5378         }
5379         elsif (defined $content_lines{$symbol})
5380         {
5381             $symbol = $content_lines{$symbol} . ': ';
5382         }
5383         else
5384         {
5385             # A single space, to provide nice separation.
5386             $symbol = ' ';
5387         }
5388         warn "${am_file}.am:", $symbol, join (' ', @args), "\n";
5389         $exit_status = 1;
5390     }
5391     else
5392     {
5393         &am_error (@args);
5394     }
5397 # Like am_error, but while scanning configure.in.
5398 sub am_conf_error
5400     # FIXME: can run in subdirs.
5401     warn "automake: configure.in: ", join (' ', @_), "\n";
5402     $exit_status = 1;
5405 # Error message with line number referring to configure.in.
5406 sub am_conf_line_error
5408     local ($file, $line, @args) = @_;
5410     if ($line)
5411     {
5412         warn "$file: $line: ", join (' ', @args), "\n";
5413         $exit_status = 1;
5414     }
5415     else
5416     {
5417         &am_conf_error (@args);
5418     }
5421 # Tell user where our aclocal.m4 is, but only once.
5422 sub keyed_aclocal_warning
5424     local ($key) = @_;
5425     warn "automake: macro \`$key' can be generated by \`aclocal'\n";
5428 # Print usage information.
5429 sub usage
5431     print "Usage: automake [OPTION] ... [Makefile]...\n";
5432     print $USAGE;
5433     print "\nFiles which are automatically distributed, if found:\n";
5434     $~ = "USAGE_FORMAT";
5435     local (@lcomm) = sort ((@common_files, @common_sometimes));
5436     local ($one, $two, $three, $four);
5437     while (@lcomm > 0)
5438     {
5439         $one = shift @lcomm;
5440         $two = @lcomm ? shift @lcomm : '';
5441         $three = @lcomm ? shift @lcomm : '';
5442         $four = @lcomm ? shift @lcomm : '';
5443         write;
5444     }
5446     print "\nReport bugs to <automake-bugs\@gnu.ai.mit.edu>\n";
5448     exit 0;
5451 format USAGE_FORMAT =
5452   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
5453   $one,               $two,               $three,             $four