Bug fix
[automake.git] / automake.in
blobd9ae2ce80d19acf3892bdb2d19fbb564447881f3
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 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@drip.colorado.edu>.
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 $prefix = "@prefix@";
34 $am_dir = "@datadir@/@PACKAGE@";
36 # String constants.
37 $IGNORE_PATTERN = "^##([^#].*)?\$";
38 $WHITE_PATTERN = "^[ \t]*\$";
39 $COMMENT_PATTERN = "^#";
40 $RULE_PATTERN = "^([\$a-zA-Z_.][-.a-zA-Z0-9_(){}/]*) *:";
41 $MACRO_PATTERN = "^([A-Za-z][A-Za-z0-9_]*)[ \t]*=[ \t]*(.*)\$";
42 $BOGUS_MACRO_PATTERN = "^([^ \t]*)[ \t]*=[ \t]*(.*)\$";
44 # Constants to define the "strictness" level.
45 $FOREIGN = 0;
46 $GNU = 1;
47 $GNITS = 2;
51 # Variables global to entire run.
53 # TRUE if we should always generate Makefile.in.
54 $force_generation = 1;
56 # Strictness level as set on command line.
57 $default_strictness = $GNU;
59 # Name of strictness level, as set on command line.
60 $default_strictness_name = 'gnu';
62 # This is TRUE if GNU make specific automatic dependency generation
63 # code should be included in generated Makefile.in.
64 $cmdline_use_dependencies = 1;
66 # TRUE if in verbose mode.
67 $verbose = 0;
69 # This holds our (eventual) exit status.  We don't actually exit until
70 # we have processed all input files.
71 $exit_status = 0;
73 # From the Perl manual.
74 $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
76 # TRUE if missing standard files should be installed.
77 $add_missing = 0;
79 # Files found by scanning configure.in for LIBOBJS.
80 %libsources = ();
82 # True if fp_C_PROTOTYPES appears in configure.in.
83 $fp_c_prototypes = 0;
85 # Names used in AC_CONFIG_HEADER call.  $config_name is the actual
86 # (first) argument.  $config_header is the '.in' file.  Ordinarily the
87 # second is derived from the first, but they can be different if the
88 # weird "NAME:FILE" syntax is used.
89 $config_name = '';
90 $config_header = '';
91 # Line number at which AC_CONFIG_HEADER appears in configure.in.
92 $config_header_line = 0;
94 # Directory where output files go.  Actually, output files are
95 # relative to this directory.
96 $output_directory = '.';
98 # Relative location of top build directory.
99 $top_builddir = '';
101 # List of Makefile.am's to process.
102 @input_files = ();
104 # List of files in AC_OUTPUT without Makefile.am.
105 @other_input_files = ();
106 # Line number at which AC_OUTPUT seen.
107 $ac_output_line = 0;
109 # List of directories to search for configure-required files.  This
110 # can be set by AC_CONFIG_AUX_DIR.
111 @config_aux_path = ('.', '..', '../..');
112 $config_aux_dir = '';
114 # Whether AC_PROG_MAKE_SET has been seen in configure.in.
115 $seen_make_set = 0;
117 # Whether ud_GNU_GETTEXT has been seen in configure.in.
118 $seen_gettext = 0;
119 # Line number at which ud_GNU_GETTEXT seen.
120 $ac_gettext_line = 0;
122 # Whether ALL_LINGUAS has been seen.
123 $seen_linguas = '';
124 # The actual text.
125 $all_linguas = '';
126 # Line number at which it appears.
127 $all_linguas_line = 0;
129 # 1 if AC_PROG_INSTALL seen, 2 if fp_PROG_INSTALL seen.
130 $seen_prog_install = 0;
132 # 1 if any scripts installed, 0 otherwise.
133 $scripts_installed = 0;
135 # Whether AC_PATH_XTRA has been seen in configure.in.
136 $seen_path_xtra = 0;
138 # Whether YACC variable has been seen in configure.in.
139 $seen_prog_yacc = 0;
141 # TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM).  The presence of
142 # AC_CHECK_TOOL also sets this.
143 $seen_canonical = 0;
145 # TRUE if we've seen AC_PROG_RANLIB.
146 $seen_ranlib = 0;
148 # TRUE if we've seen AC_ARG_PROGRAM.
149 $seen_arg_prog = 0;
151 # TRUE if we've seen AM_PROG_LIBTOOL.
152 $seen_libtool = 0;
153 $libtool_line = 0;
155 # TRUE if we've seen jm_MAINTAINER_MODE.
156 $seen_maint_mode = 0;
158 # TRUE if we've seen PACKAGE and VERSION.
159 $seen_package = 0;
160 $seen_version = 0;
162 # TRUE if we've seen ud_PATH_LISPDIR.
163 $seen_lispdir = 0;
166 # Charsets used by maintainer and in distribution.  MAINT_CHARSET is
167 # handled in a funny way: if seen in the top-level Makefile.am, it is
168 # used for every directory which does not specify a different value.
169 # The rationale here is that some directories (eg gettext) might be
170 # distributions of other packages, and thus require their own charset
171 # info.  However, the DIST_CHARSET must be the same for the entire
172 # package; it can only be set at top-level.
173 # FIXME this yields bugs when rebuilding.  What to do?  Always
174 # read (and sometimes discard) top-level Makefile.am?
175 $maint_charset = '';
176 $dist_charset = 'utf8';         # recode doesn't support this yet.
178 # Name of input file ("Makefile.in") and output file ("Makefile.am").
179 # These have no directory components.
180 $am_file_name = '';
181 $in_file_name = '';
185 &initialize_global_constants;
187 # Parse command line.
188 &parse_arguments (@ARGV);
190 # Do configure.in scan only once.
191 &scan_configure;
193 die "automake: no \`Makefile.am' found or specified\n"
194     if ! @input_files;
196 # Now do all the work on each file.
197 foreach $am_file (@input_files)
199     # FIXME should support the AC_OUTPUT ":" syntax here.
200     if (! -f ($am_file . '.am'))
201     {
202         &am_error ('no such file');
203     }
204     else
205     {
206         &generate_makefile ($am_file);
207     }
210 if ($seen_prog_install <= $scripts_installed)
212     &am_conf_error (($scripts_installed ? 'fp_PROG_INSTALL' : 'AC_PROG_INSTALL')
213                     . " must be used in configure.in");
214     &keyed_aclocal_warning ('fp_PROG_INSTALL')
215         if $scripts_installed;
218 exit $exit_status;
221 ################################################################
223 # Parse command line.
224 sub parse_arguments
226     local (@arglist) = @_;
228     # Start off as gnu.
229     &set_strictness ('gnu');
231     while (@arglist)
232     {
233         if ($arglist[0] eq "--version")
234         {
235             print "Automake version $VERSION\n";
236             exit 0;
237         }
238         elsif ($arglist[0] eq "--help")
239         {
240             &usage;
241         }
242         elsif ($arglist[0] =~ /^--amdir=(.+)$/)
243         {
244             $am_dir = $1;
245         }
246         elsif ($arglist[0] eq '--amdir')
247         {
248             &require_argument (@arglist);
249             shift (@arglist);
250             $am_dir = $arglist[0];
251         }
252         elsif ($arglist[0] =~ /^--strictness=(.+)$/)
253         {
254             &set_strictness ($1);
255         }
256         elsif ($arglist[0] eq '--gnu')
257         {
258             &set_strictness ('gnu');
259         }
260         elsif ($arglist[0] eq '--gnits')
261         {
262             &set_strictness ('gnits');
263         }
264         elsif ($arglist[0] eq '--foreign')
265         {
266             &set_strictness ('foreign');
267         }
268         elsif ($arglist[0] eq '--strictness' || $arglist[0] eq '-s')
269         {
270             &require_argument (@arglist);
271             shift (@arglist);
272             &set_strictness ($arglist[0]);
273         }
274         elsif ($arglist[0] eq '--include-deps' || $arglist[0] eq '-i')
275         {
276             $cmdline_use_dependencies = 0;
277         }
278         elsif ($arglist[0] eq '--no-force')
279         {
280             $force_generation = 0;
281         }
282         elsif ($arglist[0] =~ /^--output-dir=(.*)$/)
283         {
284             # Set output directory.
285             $output_directory = $1;
286         }
287         elsif ($arglist[0] eq '--output-dir' || $arglist[0] eq '-o')
288         {
289             &require_argument (@arglist);
290             shift (@arglist);
291             $output_directory = $arglist[0];
292         }
293         elsif ($arglist[0] eq '--add-missing' || $arglist[0] eq '-a')
294         {
295             $add_missing = 1;
296         }
297         elsif ($arglist[0] eq '--verbose' || $arglist[0] eq '-v')
298         {
299             $verbose = 1;
300         }
301         elsif ($arglist[0] eq '--')
302         {
303             # Stop option processing.
304             shift (@arglist);
305             push (@input_files, @arglist);
306             last;
307         }
308         elsif ($arglist[0] =~ /^-/)
309         {
310             die "automake: unrecognized option -- \`$arglist[0]'\n";
311         }
312         else
313         {
314             push (@input_files, $arglist[0]);
315         }
317         shift (@arglist);
318     }
320     # Take global strictness from whatever we currently have set.
321     $default_strictness = $strictness;
322     $default_strictness_name = $strictness_name;
325 # Ensure argument exists, or die.
326 sub require_argument
328     local ($arg, @arglist) = @_;
329     die "automake: no argument given for option \`$arg'\n"
330         if ! @arglist;
333 ################################################################
335 # Generate a Makefile.in given the name of the corresponding Makefile.
336 sub generate_makefile
338     local ($makefile) = @_;
340     ($am_file_name = $makefile) =~ s/^.*\///;
341     $in_file_name = $am_file_name . '.in';
342     $am_file_name .= '.am';
344     &initialize_per_input;
345     $relative_dir = &dirname ($makefile);
347     # At the toplevel directory, we might need config.guess, config.sub
348     # or libtool.
349     if ($relative_dir eq '.')
350     {
351         # libtool requires some files.
352         &require_conf_file_with_conf_line ($libtool_line, $FOREIGN,
353                                            'config.sub', 'config.guess',
354                                            'libtool') if $seen_libtool;
356         # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
357         # config.sub.
358         &require_config_file ($FOREIGN, 'config.guess', 'config.sub')
359             if $seen_canonical;
360     }
362     # We still need Makefile.in here, because sometimes the `dist'
363     # target doesn't re-run automake.
364     &push_dist_common ($in_file_name, $am_file_name);
365     push (@sources, '$(SOURCES)')
366         if &variable_defined ('SOURCES');
367     push (@objects, '$(OBJECTS)')
368         if &variable_defined ('OBJECTS');
370     # This is always the default target.  This gives us freedom to do
371     # things in whatever order is convenient.
372     $output_rules .= "default: all\n\n";
373     push (@phony, 'default');
375     &read_am_file ($makefile . '.am');
376     &handle_options;
378     # Check first, because we might modify some state.
379     &check_gnu_standards;
380     &check_gnits_standards;
382     &handle_configure;
383     &handle_gettext;
384     &handle_libraries;
385     &handle_programs;
386     &handle_scripts;
388     # Re-init SOURCES and OBJECTS.  FIXME other code shouldn't depend
389     # on this (but currently does).
390     $contents{'SOURCES'} = join (' ', @sources);
391     $contents{'OBJECTS'} = join (' ', @objects);
393     &handle_texinfo;
394     &handle_emacs_lisp;
395     &handle_man_pages;
396     &handle_data;
397     &handle_headers;
398     &handle_subdirs;
399     &handle_tags;
400     &handle_dist;
401     &handle_dependencies;
402     &handle_tests;
403     &handle_footer;
404     &handle_merge_targets;
405     &handle_installdirs;
406     &handle_clean;
407     &handle_phony;
409     if (! -d ($output_directory . '/' . $relative_dir))
410     {
411         &mkdir ($output_directory . '/' . $relative_dir);
412     }
414     local ($out_file) = $output_directory . '/' . $makefile . ".in";
415     if (! $force_generation && -e $out_file)
416     {
417         local ($am_time) = (stat ($makefile . '.am'))[9];
418         local ($in_time) = (stat ($out_file))[9];
419         # FIXME how to do unsigned comparison?
420         if ($am_time < $in_time)
421         {
422             # No need to update.
423             return;
424         }
425     }
427     if (! open (GM_FILE, "> " . $out_file))
428     {
429         warn "automake: ${am_file}.in: cannot open: $!\n";
430         $exit_status = 1;
431         return;
432     }
433     print "automake: creating ", $makefile, ".in\n" if $verbose;
435     print GM_FILE $output_vars;
436     print GM_FILE $output_rules;
437     print GM_FILE $output_trailer;
439     close (GM_FILE);
442 ################################################################
444 # Handle AUTOMAKE_OPTIONS variable.
445 sub handle_options
447     return if ! &variable_defined ('AUTOMAKE_OPTIONS');
449     foreach (split (' ', $contents{'AUTOMAKE_OPTIONS'}))
450     {
451         $options{$_} = 1;
452         if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
453         {
454             &set_strictness ($_);
455         }
456         elsif ($_ eq 'no-installman' || $_ eq 'ansi2knr'
457                || $_ eq 'dist-shar' || $_ eq 'dist-zip'
458                || $_ eq 'dejagnu' || $_ eq 'no-installinfo')
459         {
460             # Explicitly recognize these.
461         }
462         elsif ($_ eq 'no-dependencies')
463         {
464             $use_dependencies = 0;
465         }
466         elsif (/[0-9]+\.?[0-9]+/)
467         {
468             # Got a version number.  Is the syntax too strict?
469             local ($num_version);
470             ($num_version = $VERSION) =~ tr/0-9//cd;
471             if ($num_version < $_)
472             {
473                 &am_line_error ('AUTOMAKE_OPTIONS',
474                                 "require version $_, only have $VERSION");
475                 exit 1;
476             }
477         }
478         else
479         {
480             &am_line_error ('AUTOMAKE_OPTIONS',
481                             'option ', $_, 'not recognized');
482         }
483     }
486 # Return object extension.  Just once, put some code into the output.
487 sub get_object_extension
489     if (! $dir_holds_sources)
490     {
491         # Boilerplate.
492         local ($xform) = '';
493         if (&variable_defined ('CONFIG_HEADER'))
494         {
495             ($xform = &dirname ($contents{'CONFIG_HEADER'}))
496                 =~ s/(\W)/\\$1/g;
497             $xform = '-I' . $xform;
498         }
499         $xform = 's/\@CONFIG_INCLUDE_SPEC\@/' . $xform . '/go';
500         $output_vars .= &file_contents_with_transform ($xform,
501                                                        'compile-vars');
502         $output_rules .= &file_contents ('compile');
503         &push_phony_cleaners ('compile');
505         # If using X, include some extra variable definitions.  NOTE
506         # we don't want to force these into CFLAGS or anything,
507         # because not all programs will necessarily use X.
508         if ($seen_path_xtra)
509         {
510             $output_vars .= ("X_CFLAGS = \@X_CFLAGS\@\n"
511                              . "X_LIBS = \@X_LIBS\@\n"
512                              . "X_EXTRA_LIBS = \@X_EXTRA_LIBS\@\n"
513                              . "X_PRE_LIBS = \@X_PRE_LIBS\@\n");
514         }
516         # Check for automatic de-ANSI-fication.
517         $dir_holds_sources = '.o';
518         push (@suffixes, '.c', '.o');
519         push (@clean, 'compile');
521         if (defined $options{'ansi2knr'})
522         {
523             if (! $fp_c_prototypes)
524             {
525                 &am_line_error ('AUTOMAKE_OPTIONS',
526                                 "option \`ansi2knr' in use but \`fp_C_PROTOTYPES' not in configure.in");
527                 &keyed_aclocal_warning ('fp_C_PROTOTYPES');
528                 # Only give this error once.
529                 $fp_c_prototypes = 1;
530             }
532             $dir_holds_sources = '$o';
533             push (@suffixes, '._c', '._o');
535             &require_file_with_line ('AUTOMAKE_OPTIONS', $FOREIGN,
536                                      'ansi2knr.c', 'ansi2knr.1');
538             $output_vars .= &file_contents ('kr-vars');
539             $output_rules .= &file_contents ('compile-kr');
540             $output_rules .= &file_contents ('clean-kr');
542             push (@clean, 'kr');
543             &push_phony_cleaners ('kr');
544         }
545     }
546     return $dir_holds_sources;
549 # Handle SOURCE->OBJECT transform for one program or library.
550 sub handle_source_transform
552     # one_file is canonical name.  unxformed is given name.  obj is
553     # object extension.
554     local ($one_file, $unxformed, $obj) = @_;
555     local ($objpat) = $obj;
556     $objpat =~ s/(\W)/\\$1/g;
558     if (&variable_defined ($one_file . "_OBJECTS"))
559     {
560         &am_line_error ($one_file . '_OBJECTS',
561                         $one_file . '_OBJECTS', 'should not be defined');
562         # No point in continuing.
563         return;
564     }
566     local ($source_list);
567     local ($prefix);
568     foreach $prefix ('', 'EXTRA_')
569     {
570         $source_list = '';
571         if (&variable_defined ($prefix . $one_file . "_SOURCES"))
572         {
573             push (@sources, '$(' . $prefix . $one_file . "_SOURCES)");
574             push (@objects, '$(' . $prefix . $one_file . "_OBJECTS)")
575                 unless $prefix eq 'EXTRA_';
576             $source_list = $contents{$prefix . $one_file . "_SOURCES"};
577         }
578         elsif ($prefix eq '')
579         {
580             $output_vars .= $one_file . "_SOURCES = " . $unxformed . ".c\n";
581             push (@sources, $unxformed . '.c');
582             push (@objects, $unxformed . $obj);
583             $source_list = $unxformed . ".c ";
584         }
585         else
586         {
587             $output_vars .= "EXTRA_" . $one_file . "_SOURCES =\n";
588         }
590         if ($source_list)
591         {
592             # Turn sources into objects.
593             local (@files) = split (' ', $source_list);
594             local (@result) = ();
595             foreach (@files)
596             {
597                 # Skip header files, including C++-ish ones.
598                 next if /\.[hH]$/;
599                 next if /\.hxx$/;
600                 # Skip things that look like macro references.
601                 next if /^\$\(.*\)$/;
602                 next if /^\$\{.*\}$/;
603                 # Skip things that look like configure substitutions.
604                 next if /^\@.*\@$/;
606                 # Include .c file for lex or yacc source in distribution.
607                 if (/^(.*)\.[yl]$/)
608                 {
609                     # Yacc source.
610                     &push_dist_common ($1 . '.c');
611                     if (! defined $targets{$1 . '.c'})
612                     {
613                         # Generate a target.
614                         $output_rules .= ($1 . '.c: ' . $_ . "\n"
615                                           . "\t"
616                                           . 'cd $(srcdir) && $(YACC) $(YFLAGS) $< && mv y.tab.c '
617                                           . $1 . '.c' . "\n");
618                     }
619                 }
620                 elsif (/^(.*)\.l$/)
621                 {
622                     # Lex source.
623                     &push_dist_common ($1 . '.c');
624                     if (! defined $targets{$1 . '.c'})
625                     {
626                         $output_rules .= ($1 . '.c: ' . $_ . "\n"
627                                           . "\t"
628                                           . 'cd $(srcdir) && $(LEX) $(LFLAGS) $< && mv lex.yy.c '
629                                           . $1 . '.c' . "\n");
630                     }
631                 }
633                 # Transform source files into .o files.
634                 s/\.cc$/$obj/g;
635                 s/\.cxx$/$obj/g;
636                 s/\.[cCmylfs]$/$obj/g;
637                 push (@result, $_)
638                     unless $prefix eq 'EXTRA_';
640                 # Transform .o or $o file into .P file (for automatic
641                 # dependency code).
642                 s/$objpat$/.P/g;
643                 $dep_files{'$(srcdir)/.deps/' . $_} = 1;
644             }
646             &pretty_print ($one_file . "_OBJECTS =", "", @result)
647                 unless $prefix eq 'EXTRA_';
648         }
649     }
651     if (&variable_defined ('CONFIG_HEADER'))
652     {
653         $output_rules .= ('$(' . $one_file . "_OBJECTS): "
654                           . $contents{'CONFIG_HEADER'} . "\n");
655     }
657     return @result;
660 # Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
661 sub handle_lib_objects
663     local ($var) = @_;
665     die "programming error in handle_lib_objects"
666         if ! &variable_defined ($var);
668     # We recognize certain things that are commonly put in LIBADD or
669     # LDADD.
670     local ($lsearch);
672     foreach $lsearch (split (' ', $contents{$var}))
673     {
674         # Automatically handle @LIBOBJS@ and @ALLOCA@.  Basically this
675         # means adding entries to dep_files.
676         if ($lsearch eq '@LIBOBJS@')
677         {
678             local ($iter, $rewrite);
679             foreach $iter (keys %libsources)
680             {
681                 if ($iter ne 'alloca.c')
682                 {
683                     ($rewrite = $iter) =~ s/\.c$/.P/;
684                     $dep_files{'$(srcdir)/.deps/' . $rewrite} = 1;
685                     &require_file_with_line ($var, $FOREIGN, $iter);
686                 }
687             }
688         }
689         elsif ($lsearch eq '@ALLOCA@')
690         {
691             &am_line_error ($var,
692                             "\@ALLOCA\@ seen but \`AC_FUNC_ALLOCA' not in \`configure.in'")
693                 if ! defined $libsources{'alloca.c'};
694             $dep_files{'$(srcdir)/.deps/alloca.P'} = 1;
695             &require_file_with_line ($var, $FOREIGN, 'alloca.c');
696         }
697     }
700 # Handle C programs.
701 sub handle_programs
703     local (@proglist) = &am_install_var ('-clean',
704                                          'programs', 'PROGRAMS',
705                                          'bin', 'sbin', 'libexec', 'pkglib',
706                                          'noinst', 'check');
707     return if ! @proglist;
709     # If a program is installed, this is required.  We only want this
710     # error to appear once.
711     &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
712         unless $seen_arg_prog;
713     $seen_arg_prog = 1;
715     local ($obj) = &get_object_extension;
716     local ($one_file, $xname, $munge);
718     foreach $one_file (@proglist)
719     {
720         # Canonicalize names.
721         ($xname = $one_file) =~ tr/A-Za-z0-9_/_/c;
722         if ($xname ne $one_file)
723         {
724             local ($xt);
725             foreach $xt ('_LDADD', '_SOURCES', '_OBJECTS', '_DEPENDENCIES')
726             {
727                 &am_line_error ($one_file . $xt,
728                                 "invalid variable \`" . $one_file . $xt
729                                 . "'; should be \`" . $xname . $xt . "'")
730                     if &variable_defined ($one_file . $xt);
731             }
732         }
734         &handle_source_transform ($xname, $one_file, $obj);
736         if (&variable_defined ($xname . "_LDADD"))
737         {
738             &handle_lib_objects ($xname . '_LDADD');
739         }
740         else
741         {
742             # User didn't define prog_LDADD override.  So do it.
743             $output_vars .= $xname . '_LDADD = $(LDADD)' . "\n";
744         }
746         $output_rules .=
747             &file_contents_with_transform
748                 ('s/\@PROGRAM\@/' . $one_file . '/go;'
749                  . 's/\@XPROGRAM\@/' . $xname . '/go;',
750                  'program');
751     }
753     &handle_lib_objects ('LDADD')
754         if &variable_defined ('LDADD');
757 # Handle libraries.
758 sub handle_libraries
760     local (@liblist) = &am_install_var ('-no-all', '-clean',
761                                         'libraries', 'LIBRARIES',
762                                         'lib', 'pkglib', 'noinst', 'check');
763     return if ! @liblist;
765     if (! $seen_ranlib)
766     {
767         # FIXME need am_line_error here.  But we don't know which
768         # variable exists.  Must add a loop...  No.  Must have
769         # am_install_var return a hash.  Otherwise the user could add
770         # install directories that we'd never find.
771         &am_error ("library requires either \`AC_PROG_RANLIB' or `AM_PROG_LIBTOOL' in configure.in");
772         # Only get this error once.
773         $seen_ranlib = 1;
774     }
776     # Generate _LIBFILES variables.  Too bad we can't do this in
777     # am_install_var.
778     local ($onedir, $onelib);
779     local (@outlist);
780     foreach $onedir ('lib', 'pkglib', 'noinst', 'check')
781     {
782         if (&variable_defined ($onedir . '_LIBRARIES'))
783         {
784             @outlist = ();
785             foreach $onelib (split (' ', $contents{$onedir . '_LIBRARIES'}))
786             {
787                 push (@outlist, 'lib' . $onelib . '.a');
788             }
789             &pretty_print ($onedir . '_LIBFILES =', "", @outlist);
790         }
791     }
792     push (@all, '$(LIBFILES)');
794     local ($obj) = &get_object_extension;
795     local ($munge);
796     foreach $onelib (@liblist)
797     {
798         if (&variable_defined ($onelib . '_LIBADD'))
799         {
800             &handle_lib_objects ($onelib . '_LIBADD');
801         }
802         else
803         {
804             # Generate support for conditional object inclusion in
805             # libraries.
806             $output_vars .= $onelib . "_LIBADD =\n";
807         }
809         &handle_source_transform ($onelib, $onelib, $obj);
811         $output_rules .=
812             &file_contents_with_transform ('s/\@LIBRARY\@/' . $onelib . '/go',
813                                            'library');
814     }
816     # Turn "foo" into "libfoo.a" and include macro definition.
817     grep (($_ = 'lib' . $_ . '.a') && 0, @liblist);
819     if (! &variable_defined ('LIBFILES'))
820     {
821         &pretty_print ('LIBFILES = ', "", @liblist);
822     }
824     if ($seen_libtool)
825     {
826         $output_vars .= ('AR = $(LIBTOOL) archive' . "\n"
827                          . 'RANLIB = $(LIBTOOL) ranlib' . "\n"
828                          . 'LCOMPILE = $(LIBTOOL) compile $(DEFS) $(INCLUDES)'
829                          . ' $(CPPFLAGS) $(CFLAGS)' . "\n");
830     }
831     else
832     {
833         $output_vars .= ('AR = ar' . "\n"
834                          . 'RANLIB = @RANLIB@' . "\n");
835     }
838 # Handle scripts.
839 sub handle_scripts
841     # NOTE we no longer automatically clean SCRIPTS, because it is
842     # useful to sometimes distribute scripts verbatim.  This happens
843     # eg in Automake itself.
844     local ($msi);
845     $msi = &am_install_var ('scripts', 'SCRIPTS',
846                             'bin', 'sbin', 'libexec', 'pkgdata',
847                             'noinst', 'check');
849     # We really only want a boolean value.
850     $scripts_installed = 1 if $msi;
852     if ($scripts_installed)
853     {
854         # If a program is installed, this is required.  We only want this
855         # error to appear once.
856         &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
857             unless $seen_arg_prog;
858         $seen_arg_prog = 1;
859     }
862 # Search a file for a "version.texi" Texinfo include.  Return the name
863 # of the include file if found, or the empty string if not.  A
864 # "version.texi" file is actually any file whose name matches
865 # "vers*.texi".
866 sub grep_for_vers_texi
868     local ($filename) = @_;
870     if (! open (TEXI, $filename))
871     {
872         &am_error ("couldn't open \`$filename': $!");
873         return '';
874     }
875     print "automake: reading $filename\n" if $verbose;
877     while (<TEXI>)
878     {
879         if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
880         {
881             # Found it.
882             close (TEXI);
883             return $1;
884         }
885     }
887     close (TEXI);
888     return '';
891 # Handle all Texinfo source.
892 sub handle_texinfo
894     &am_line_error ('TEXINFOS',
895                     "\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
896         if &variable_defined ('TEXINFOS');
897     return if (! &variable_defined ('info_TEXINFOS')
898                && ! &variable_defined ('html_TEXINFOS'));
900     local (@texis) = split (' ', $contents{'info_TEXINFOS'});
902     local (@infos_list, @info_deps_list, @dvis_list, @texi_deps);
903     local ($infobase, $info_cursor);
904     local (%versions);
905     local ($done) = 0;
906     local ($vti);
907     local ($tc_cursor, @texi_cleans);
908     local ($canonical);
910     foreach $info_cursor (@texis)
911     {
912         ($infobase = $info_cursor) =~ s/\.texi$//;
914         # If 'version.texi' is referenced by input file, then include
915         # automatic versioning capability.
916         local ($vtexi)
917             = &grep_for_vers_texi ($relative_dir . "/" . $info_cursor);
918         if ($vtexi)
919         {
920             &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
921                 if (defined $versions{$vtexi});
922             $versions{$vtexi} = $info_cursor;
924             # We number the stamp-vti files.  This is doable since the
925             # actual names don't matter much.  We only number starting
926             # with the second one, so that the common case looks nice.
927             $vti = 'vti' . ($done ? $done : '');
928             &push_dist_common ($vtexi, 'stamp-' . $vti);
929             push (@clean, $vti);
931             # Only require once.
932             &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
933                                           'mdate-sh')
934                 if ! $done;
935             ++$done;
937             local ($conf_pat);
938             ($conf_pat = $config_aux_dir) =~ s/(\W)/\\$1/g;
939             $output_rules .=
940                 &file_contents_with_transform
941                     ('s/\@TEXI\@/' . $info_cursor . '/g; '
942                      . 's/\@VTI\@/' . $vti . '/g; '
943                      . 's/\@VTEXI\@/' . $vtexi . '/g;'
944                      . 's,\@MDDIR\@,' . $conf_pat . ',g;',
945                      'texi-version');
947             &push_phony_cleaners ($vti);
948         }
950         # If user specified file_TEXINFOS, then use that as explicit
951         # dependency list.
952         @texi_deps = ();
953         push (@texi_deps, $info_cursor);
954         push (@texi_deps, $vtexi) if $vtexi;
956         # Canonicalize name first.
957         ($canonical = $infobase) =~ tr/A-Za-z0-9_/_/c;
958         if (&variable_defined ($canonical . "_TEXINFOS"))
959         {
960             push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
961             &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
962         }
964         $output_rules .= ("\n" . $infobase . ".info: "
965                           . join (' ', @texi_deps)
966                           . "\n" . $infobase . ".dvi: "
967                           . join (' ', @texi_deps)
968                           . "\n\n");
970         push (@infos_list, $infobase . '.info', '.info-[0-9]',
971               '.info-[0-9][0-9]');
972         push (@info_deps_list, $infobase . '.info');
973         push (@dvis_list, $infobase . '.dvi');
975         # Generate list of things to clean for this target.  We do
976         # this explicitly because otherwise too many things could be
977         # removed.  In particular the ".log" extension might
978         # reasonably be used in other contexts by the user.
979         foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns',
980                             'ky', 'log', 'pg', 'toc', 'tp', 'vr', 'op')
981         {
982             push (@texi_cleans, $infobase . '.' . $tc_cursor);
983         }
984     }
986     # Some boilerplate.
987     $output_vars .= &file_contents ('texinfos-vars');
988     $output_rules .= &file_contents ('texinfos');
989     push (@phony, 'install-info', 'uninstall-info');
991     # How to clean.
992     $output_rules .= "\nmostlyclean-info:\n";
993     &pretty_print_rule ("\trm -f", "\t  ", @texi_cleans);
994     $output_rules .= ("\nclean-info:\n\ndistclean-info:\n\n"
995                       . "maintainer-clean-info:\n\t"
996                       . 'rm -f $(INFOS)' . "\n");
997     &push_phony_cleaners ('info');
999     push (@suffixes, '.texi', '.info', '.dvi');
1001     if (! defined $options{'no-installinfo'})
1002     {
1003         push (@uninstall, 'uninstall-info');
1004         push (@installdirs, '$(infodir)');
1005         unshift (@install_data, 'install-info');
1007         # Make sure documentation is made and installed first.  Use
1008         # $(INFO_DEPS), not 'info', because otherwise recursive makes
1009         # get run twice during "make all".
1010         unshift (@all, '$(INFO_DEPS)');
1011     }
1012     push (@clean, 'info');
1013     push (@info, '$(INFO_DEPS)');
1014     push (@dvi, '$(DVIS)');
1016     $output_vars .= ("INFOS = " . join (' ', @infos_list) . "\n"
1017                      . "INFO_DEPS = " . join (' ', @info_deps_list)  . "\n"
1018                      . "DVIS = " . join (' ', @dvis_list) . "\n"
1019                      # This next isn't strictly needed now -- the
1020                      # places that look here could easily be changed
1021                      # to look in info_TEXINFOS.  But this is probably
1022                      # better, in case noinst_TEXINFOS is ever
1023                      # supported.
1024                      . "TEXINFOS = " . $contents{'info_TEXINFOS'} . "\n\n");
1026     # Do some error checking.
1027     &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex');
1030 # Handle any man pages.
1031 sub handle_man_pages
1033     &am_line_error ('MANS', "\`MANS' is an anachronism; use \`man_MANS'")
1034         if &variable_defined ('MANS');
1035     return if ! &variable_defined ('man_MANS');
1037     # We generate the manpage install code by hand to avoid the use of
1038     # basename in the generated Makefile.
1039     local (@mans) = split (' ', $contents{'man_MANS'});
1040     local (%sections, %inames, %secmap, %fullsecmap);
1041     foreach (@mans)
1042     {
1043         # FIXME: statement without effect:
1044         /^(.*)\.([0-9])([a-z]*)$/;
1045         $sections{$2} = 1;
1046         $inames{$1} = $_;
1047         $secmap{$1} = $2;
1048         $fullsecmap{$1} = $2 . $3;
1049     }
1051     # We don't really need this, but we use it in case we ever want to
1052     # support noinst_MANS.
1053     $output_vars .= "MANS = " . $contents{'man_MANS'} . "\n";
1055     # Generate list of install dirs.
1056     $output_rules .= "install-man: \$(MANS)\n";
1057     foreach (keys %sections)
1058     {
1059         push (@installdirs, '$(mandir)/man' . $_)
1060             unless defined $options{'no-installman'};
1061         $output_rules .= ("\t" . '$(mkinstalldirs) $(mandir)/man'
1062                           . $_ . "\n");
1063     }
1064     push (@phony, 'install-man');
1066     # Generate install target.
1067     local ($key);
1068     foreach $key (keys %inames)
1069     {
1070         $_ = $install_man_format;
1071         s/\@SECTION\@/$secmap{$key}/g;
1072         s/\@MAN\@/$inames{$key}/g;
1073         s/\@FULLSECT\@/$fullsecmap{$key}/g;
1074         s/\@MANBASE\@/$key/g;
1075         $output_rules .= $_;
1076     }
1077     $output_rules .= "\n";
1079     $output_rules .= "uninstall-man:\n";
1080     foreach $key (keys %inames)
1081     {
1082         $_ = $uninstall_man_format;
1083         s/\@SECTION\@/$secmap{$key}/g;
1084         s/\@MAN\@/$inames{$key}/g;
1085         s/\@FULLSECT\@/$fullsecmap{$key}/g;
1086         s/\@MANBASE\@/$key/g;
1087         $output_rules .= $_;
1088     }
1089     $output_rules .= "\n";
1090     push (@phony, 'uninstall-man');
1092     $output_vars .= &file_contents ('mans-vars');
1094     if (! defined $options{'no-installman'})
1095     {
1096         push (@install_data, 'install-man');
1097         push (@uninstall, 'uninstall-man');
1098         push (@all, '$(MANS)');
1099     }
1102 # Handle DATA variables.
1103 sub handle_data
1105     &am_install_var ('data', 'DATA', 'data', 'sysconf',
1106                      'sharedstate', 'localstate', 'pkgdata',
1107                      'noinst', 'check');
1110 # Handle TAGS.
1111 sub handle_tags
1113     local ($tagging) = 0;
1115     push (@phony, 'tags');
1116     if (&variable_defined ('SUBDIRS'))
1117     {
1118         $output_rules .= &file_contents ('tags');
1119         push (@phony, 'tags-recursive');
1120         $tagging = 1;
1121     }
1122     elsif ($dir_holds_sources || &variable_defined ('ETAGS_ARGS'))
1123     {
1124         $output_rules .= &file_contents ('tags-subd');
1125         $tagging = 1;
1126     }
1128     if ($tagging)
1129     {
1130         $output_rules .= &file_contents ('tags-clean');
1131         push (@clean, 'tags');
1132         &push_phony_cleaners ('tags');
1133     }
1134     else
1135     {
1136         # Every Makefile must define some sort of TAGS rule.
1137         # Otherwise, it would be possible for a top-level "make TAGS"
1138         # to fail because some subdirectory failed.
1139         $output_rules .= "tags: TAGS\nTAGS:\n\n";
1140     }
1143 # Worker for handle_dist.
1144 sub handle_dist_worker
1146     $output_rules .= 'distdir: $(DEP_DISTFILES)' . "\n";
1148     # Initialization; only at top level.
1149     if ($relative_dir eq '.')
1150     {
1151         if ($strictness >= $GNITS)
1152         {
1153             # For Gnits users, this is pretty handy.  Look at 15 lines
1154             # in case some explanatory text is desirable.
1155             $output_rules .= '  @if sed 15q $(srcdir)/NEWS | grep -e "$(VERSION)" > /dev/null; then :; else \\
1156           echo "NEWS not updated; not releasing" 1>&2; \\
1157           exit 1;                               \\
1158         fi
1160         }
1163         $output_rules .=
1164             # Create dist directory.
1165             '   rm -rf $(distdir)
1166         mkdir $(distdir)
1167         chmod 777 $(distdir)
1170         # Only run automake in `dist' target if --include-deps not
1171         # specified.  That way the recipient of a distribution can run
1172         # "make dist" and not need Automake.
1173         if ($cmdline_use_dependencies)
1174         {
1175             $output_rules .=
1176                 (
1177                  # We need an absolute path for --output-dir.  Thus the
1178                  # weirdness.
1179                  '      distdir=`cd $(distdir) && pwd` \\
1180           && cd $(srcdir) \\
1181           && automake --include-deps --output-dir=$$distdir --strictness='
1182                  # Set strictness of output.
1183                  . $strictness_name . "\n"
1184                  );
1185         }
1186     }
1188     # In loop, test for file existence because sometimes a file gets
1189     # included in DISTFILES twice.  For example this happens when a
1190     # single source file is used in building more than one program.
1191     # Also, there are situations in which "ln" can fail.  For instance
1192     # a file to distribute could actually be a cross-filesystem
1193     # symlink -- this can easily happen if "gettextize" was run on the
1194     # distribution.  Note that DISTFILES can contain a wildcard (for
1195     # info files, sigh), so we must use the echo trick.
1196     $output_rules .= '  @for file in `cd $(srcdir) && echo $(DISTFILES)`; do \\
1197           test -f $(distdir)/$$file \\
1198           || ln $(srcdir)/$$file $(distdir)/$$file 2> /dev/null \\
1199           || cp -p $(srcdir)/$$file $(distdir)/$$file; \\
1200         done
1203     # If we have SUBDIRS, create all dist subdirectories and do
1204     # recursive build.
1205     if (&variable_defined ('SUBDIRS'))
1206     {
1207         # Test for directory existence here because previous automake
1208         # invocation might have created some directories.  Note that
1209         # we explicitly set distdir for the subdir make; that lets us
1210         # mix-n-match many automake-using packages into one large
1211         # package, and have "dist" at the top level do the right
1212         # thing.
1213         $output_rules .= '      for subdir in $(SUBDIRS); do            \\
1214           test -d $(distdir)/$$subdir           \\
1215           || mkdir $(distdir)/$$subdir          \\
1216           || exit 1;                            \\
1217           chmod 777 $(distdir)/$$subdir;        \\
1218           (cd $$subdir && $(MAKE) distdir=../$(distdir)/$$subdir distdir) \\
1219             || exit 1; \\
1220         done
1222     }
1224     # If the target `dist-hook' exists, run it now.  This allows
1225     # users to do random weird things to the distribution before it is
1226     # packaged up.
1227     if (defined $contents{'dist-hook'})
1228     {
1229         $output_rules .= "\t\$(MAKE) dist-hook\n";
1230     }
1232     push (@phony, 'distdir');
1235 # Handle 'dist' target.
1236 sub handle_dist
1238     # Set up maint_charset.
1239     $local_maint_charset = $contents{'MAINT_CHARSET'}
1240         if &variable_defined ('MAINT_CHARSET');
1241     $maint_charset = $local_maint_charset
1242         if $relative_dir eq '.';
1244     if (&variable_defined ('DIST_CHARSET'))
1245     {
1246         &am_line_error ('DIST_CHARSET',
1247                         "DIST_CHARSET defined but no MAINT_CHARSET defined")
1248             if ! $local_maint_charset;
1249         if ($relative_dir eq '.')
1250         {
1251             $dist_charset = $contents{'DIST_CHARSET'}
1252         }
1253         else
1254         {
1255             &am_line_error ('DIST_CHARSET',
1256                             "DIST_CHARSET can only be defined at top level");
1257         }
1258     }
1260     # Look for common files that should be included in distribution.
1261     local ($cfile);
1262     foreach $cfile (@common_files)
1263     {
1264         if (-f ($relative_dir . "/" . $cfile))
1265         {
1266             &push_dist_common ($cfile);
1267         }
1268     }
1270     # Keys of %dist_common are names of files to distributed.  We put
1271     # README first because it then becomes easier to make a
1272     # Usenet-compliant shar file (in these, README must be first).
1273     # FIXME do more ordering of files here.
1274     local (@coms);
1275     if (defined $dist_common{'README'})
1276     {
1277         push (@coms, 'README');
1278         undef $dist_common{'README'};
1279     }
1280     push (@coms, sort keys %dist_common);
1282     &pretty_print ("DIST_COMMON =", "", @coms);
1283     $output_vars .= "\n";
1285     # Some boilerplate.
1286     $output_vars .= &file_contents ('dist-vars');
1288     # Put these things in rules section so it is easier for whoever
1289     # reads Makefile.in.
1290     if ($relative_dir eq '.')
1291     {
1292         $output_rules .= "\n" . 'distdir = $(PACKAGE)-$(VERSION)' . "\n";
1293     }
1294     else
1295     {
1296         $output_rules .= ("\nsubdir = " . $relative_dir . "\n"
1297                           . 'distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)'
1298                           . "\n");
1299     }
1301     # Generate 'dist' target, and maybe dist-shar / dist-zip.
1302     if ($relative_dir eq '.')
1303     {
1304         # Rule to check whether a distribution is viable.
1305         $output_rules .= ('# This target untars the dist file and tries a VPATH configuration.  Then
1306 # it guarantees that the distribution is self-contained by making another
1307 # tarfile.
1308 distcheck: dist
1309         rm -rf $(distdir)
1310         $(TAR) zxf $(distdir).tar.gz
1311         mkdir $(distdir)/=build
1312         mkdir $(distdir)/=inst
1313         dc_install_base=`cd $(distdir)/=inst && pwd`; \\
1314         cd $(distdir)/=build \\
1315           && ../configure '
1317                           . ($seen_gettext ? '--with-included-gettext ' : '')
1318                           . '--srcdir=.. --prefix=$$dc_install_base \\
1319           && $(MAKE) \\
1320           && $(MAKE) dvi \\
1321           && $(MAKE) check \\
1322           && $(MAKE) install \\
1323           && $(MAKE) installcheck \\
1324           && $(MAKE) dist
1325         rm -rf $(distdir)
1326         @echo "========================"; \\
1327         echo "$(distdir).tar.gz is ready for distribution"; \\
1328         echo "========================"
1331         $output_rules .= 'dist: distdir' . "\n\t";
1332         # Ignore return result from chmod, because it might give an
1333         # error if we chmod a symlink.
1334         $output_rules .= '-chmod -R a+r $(distdir)' . "\n\t";
1335         $output_rules .= '$(TAR) chozf $(distdir).tar.gz $(distdir)';
1336         $output_rules .= "\n\t" . 'rm -rf $(distdir)' . "\n";
1338         if (defined $options{'dist-shar'})
1339         {
1340             $output_rules .= 'dist-shar: distdir' . "\n\t";
1341             # Ignore return result from chmod, because it might give
1342             # an error if we chmod a symlink.
1343             $output_rules .= '-chmod -R a+r $(distdir)' . "\n\t";
1344             $output_rules .= 'shar $(distdir) | gzip > $(distdir).shar.gz';
1345             $output_rules .= "\n\t" . 'rm -rf $(distdir)' . "\n";
1346         }
1348         if (defined $options{'dist-zip'})
1349         {
1350             $output_rules .= 'dist-zip: distdir' . "\n\t";
1351             $output_rules .= 'chmod -R a+r $(distdir)' . "\n\t";
1352             $output_rules .= 'zip -rq $(distdir).zip $(distdir)';
1353             $output_rules .= "\n\t" . 'rm -rf $(distdir)' . "\n";
1354         }
1355     }
1357     # Generate distdir target.
1358     &handle_dist_worker;
1361 # Handle auto-dependency code.
1362 sub handle_dependencies
1364     if ($use_dependencies)
1365     {
1366         # Include GNU-make-specific auto-dep code.
1367         if ($dir_holds_sources)
1368         {
1369             &pretty_print ('DEP_FILES =', "", sort keys %dep_files);
1370             $output_rules .= &file_contents ('depend');
1371         }
1372     }
1373     else
1374     {
1375         # Include any auto-generated deps that are present.
1376         if (-d ($relative_dir . "/.deps") && -f ($relative_dir . "/.deps/.P"))
1377         {
1378             local ($depfile);
1379             local ($gpat) = $relative_dir . "/.deps/*.P";
1381             foreach $depfile (<${gpat}>)
1382             {
1383                 if (! open (DEP_FILE, $depfile))
1384                 {
1385                     &am_error ("couldn't open \`$depfile': $!");
1386                     next;
1387                 }
1388                 print "automake: reading $depfile\n" if $verbose;
1390                 # Slurp entire file.
1391                 $output_rules .= join ('', <DEP_FILE>);
1393                 close (DEP_FILE);
1394             }
1396             $output_rules .= "\n";
1397         }
1398     }
1401 # Handle subdirectories.
1402 sub handle_subdirs
1404     if (! &variable_defined ('SUBDIRS'))
1405     {
1406         &am_conf_error
1407             ("ud_GNU_GETTEXT in configure.in but SUBDIRS not defined")
1408                 if $seen_gettext && $relative_dir eq '.';
1409         return;
1410     }
1412     &require_file_with_conf_line ($ac_gettext_line, $FOREIGN, 'ABOUT-NLS')
1413         if $seen_gettext;
1415     return if ! &variable_defined ('SUBDIRS');
1417     # Make sure each directory mentioned in SUBDIRS actually exists.
1418     local ($dir);
1419     foreach $dir (split (' ', $contents{'SUBDIRS'}))
1420     {
1421         # Skip directories substituted by configure.
1422         next if $dir =~ /^\@.*\@$/;
1423         &am_line_error ('SUBDIRS',
1424                         "required directory $relative_dir/$dir does not exist")
1425             if ! -d $relative_dir . '/' . $dir;
1426     }
1428     $output_rules .= &file_contents ('subdirs');
1430     # Push a bunch of phony targets.
1431     local ($phonies);
1432     foreach $phonies ('-data', '-exec', 'dirs')
1433     {
1434         push (@phony, 'install' . $phonies . '-recursive');
1435         push (@phony, 'uninstall' . $phonies . '-recursive');
1436     }
1437     foreach $phonies ('all', 'check', 'installcheck', 'info', 'dvi')
1438     {
1439         push (@phony, $phonies . '-recursive');
1440     }
1441     &push_phony_cleaners ('recursive');
1443     push (@check, "check-recursive");
1444     push (@installcheck, "installcheck-recursive");
1445     push (@info, "info-recursive");
1446     push (@dvi, "dvi-recursive");
1448     $recursive_install = 1;
1451 # Handle remaking and configure stuff.
1452 sub handle_configure
1454     # If SUBDIRS defined, require AC_PROG_MAKE_SET.
1455     &am_line_error ('SUBDIRS', "AC_PROG_MAKE_SET must be used in configure.in")
1456         if &variable_defined ('SUBDIRS') && ! $seen_make_set;
1458     local ($top_reldir);
1459     if ($relative_dir ne '.')
1460     {
1461         # In subdirectory.
1462         $output_rules .= &file_contents ('remake-subd');
1463         $top_reldir = '../';
1464     }
1465     else
1466     {
1467         if (-f 'aclocal.m4')
1468         {
1469             $output_vars .= "ACLOCAL = aclocal.m4\n";
1470             &push_dist_common ('aclocal.m4');
1471         }
1472         $output_rules .= &file_contents_with_transform ('s/\@STRICTNESS\@/'
1473                                                         . $strictness_name
1474                                                         . '/g',
1475                                                         'remake');
1477         &am_error
1478             ("\`install.sh' is an anachronism; use \`install-sh' instead")
1479                 if -f $relative_dir . '/install.sh';
1481         # If we have a configure header, require it.
1482         if ($config_header)
1483         {
1484             # FIXME this restriction should be lifted.
1485             # FIXME first see if it is even needed as-is.
1486             &am_conf_line_error ($config_header_line,
1487                                  "argument to AC_CONFIG_HEADER contains \`/'\n")
1488                 if ($config_header =~ /\//);
1490             &require_file_with_conf_line ($config_header_line,
1491                                           $FOREIGN, $config_header);
1493             # Header defined and in this directory.
1494             if (-f 'acconfig.h')
1495             {
1496                 $output_vars .= "ACCONFIG = acconfig.h\n";
1497                 &push_dist_common ('acconfig.h');
1498             }
1499             if (-f $config_name . '.top')
1500             {
1501                 $output_vars .= "CONFIG_TOP = ${config_name}.top\n";
1502                 &push_dist_common ($config_name . '.top');
1503             }
1504             if (-f $config_name . '.bot')
1505             {
1506                 $output_vars .= "CONFIG_BOT = ${config_name}.bot\n";
1507                 &push_dist_common ($config_name . '.bot');
1508             }
1510             &require_file_with_conf_line ($config_header_line, $FOREIGN,
1511                                           'stamp-h.in');
1513             $output_rules .= &file_contents ('remake-hdr');
1514             $output_vars .= "CONFIG_HEADER_IN = ${config_header}\n";
1515         }
1517         $top_reldir = '';
1518     }
1520     # Set location of mkinstalldirs.
1521     if ($config_aux_dir ne '.' && $config_aux_dir ne '')
1522     {
1523         $output_vars .= 'mkinstalldirs = ' . $config_aux_dir;
1524     }
1525     else
1526     {
1527         $output_vars .= 'mkinstalldirs = $(top_srcdir)';
1528     }
1529     $output_vars .= '/mkinstalldirs' . "\n";
1531     &am_line_error ('CONFIG_HEADER',
1532                     "\`CONFIG_HEADER' is an anachronism; now determined from \`configure.in'")
1533         if &variable_defined ('CONFIG_HEADER');
1535     # Generate CONFIG_HEADER define, and define interally.
1536     $output_vars .= "CONFIG_HEADER = ${top_builddir}/${config_name}\n"
1537         if $config_name;
1538     $contents{'CONFIG_HEADER'} = "${top_builddir}/${config_name}"
1539         if $config_name;
1541     # Now look for other files in this directory which must be remade
1542     # by config.status, and generate rules for them.
1543     local ($file, $local, $input);
1544     foreach $file (@other_input_files)
1545     {
1546         # Skip files not in this directory, any Makefile, and the
1547         # config header.  These last two must be handled specially.
1548         next unless &dirname ($file) eq $relative_dir;
1549         next if $file eq $top_builddir . '/' . $config_name;
1550         ($local = $file) =~ s/^.*\///;
1551         next if $local eq 'Makefile';
1553         if ($local =~ /^(.*):(.*)$/)
1554         {
1555             # This is the ":" syntax of AC_OUTPUT.
1556             $input = $2;
1557             $local = $1;
1558         }
1559         else
1560         {
1561             # Normal usage.
1562             $input = $local . '.in';
1563         }
1564         # FIXME when using autoconf ":" syntax, should we set CONFIG_FILES
1565         # to $local:$input?
1566         $output_rules .= ($local . ': '
1567                           . '$(top_builddir)/config.status ' . $input . "\n"
1568                           . "\t"
1569                           . 'cd $(top_builddir) && CONFIG_FILES='
1570                           . ($relative_dir eq '.' ? '' : '$(subdir)/')
1571                           . '$@ CONFIG_HEADERS= ./config.status'
1572                           . "\n");
1574         &require_file_with_conf_line ($ac_output_line, $FOREIGN,
1575                                       $input);
1576     }
1579 # Handle C headers.
1580 sub handle_headers
1582     &am_install_var ('header', 'HEADERS', 'include',
1583                      'oldinclude', 'pkginclude',
1584                      'noinst', 'check');
1587 sub handle_gettext
1589     return if ! $seen_gettext || $relative_dir ne '.';
1591     if (&variable_defined ('SUBDIRS'))
1592     {
1593         &am_line_error
1594             ('SUBDIRS',
1595              "ud_GNU_GETTEXT in configure.in but \`po' not in SUBDIRS")
1596                 if $contents{'SUBDIRS'} !~ /\bpo\b/;
1597         &am_line_error
1598             ('SUBDIRS',
1599              "ud_GNU_GETTEXT in configure.in but \`intl' not in SUBDIRS")
1600                 if $contents{'SUBDIRS'} !~ /\bintl\b/;
1601     }
1603     # Ensure that each language in ALL_LINGUAS has a .po file, and
1604     # each po file is mentioned in ALL_LINGUAS.
1605     if ($seen_linguas)
1606     {
1607         local (%linguas) = ();
1608         grep ($linguas{$_} = 1, split (' ', $all_linguas));
1610         foreach (<po/*.po>)
1611         {
1612             s/^po\///;
1613             s/\.po$//;
1615             &am_line_error ($all_linguas_line,
1616                             ("po/$_.po exists but \`$_' not in \`ALL_LINGUAS'"))
1617                 if ! $linguas{$_};
1618         }
1620         foreach (keys %linguas)
1621         {
1622             &am_line_error ($all_linguas_line,
1623                             "$_ in \`ALL_LINGUAS' but po/$_.po does not exist")
1624                 if ! -f "po/$_.po";
1625         }
1626     }
1627     else
1628     {
1629         &am_error ("ud_GNU_GETTEXT in configure.in but \`ALL_LINGUAS' not defined");
1630     }
1633 # Handle footer elements.
1634 sub handle_footer
1636     if ($contents{'SOURCES'})
1637     {
1638         &pretty_print ('SOURCES =', "",
1639                        split (' ', $contents{'SOURCES'}));
1640     }
1641     if ($contents{'OBJECTS'})
1642     {
1643         &pretty_print ('OBJECTS =', "",
1644                        split (' ', $contents{'OBJECTS'}));
1645     }
1646     if ($contents{'SOURCES'} || $contents{'OBJECTS'})
1647     {
1648         $output_vars .= "\n";
1649     }
1651     if (defined $contents{'SUFFIXES'})
1652     {
1653         # Push actual suffixes, and not $(SUFFIXES).  Some versions of
1654         # make do not like variable substitutions on the .SUFFIXES
1655         # line.
1656         push (@suffixes, split (' ', $contents{'SUFFIXES'}));
1657     }
1659     $output_trailer .= ".SUFFIXES:\n";
1660     if (@suffixes)
1661     {
1662         $output_trailer .= ".SUFFIXES: " . join (' ', @suffixes) . "\n";
1663     }
1664     $output_trailer .= &file_contents ('footer');
1667 # Deal with installdirs target.
1668 sub handle_installdirs
1670     # GNU Makefile standards recommend this.
1671     $output_rules .= ("installdirs:"
1672                       . ($recursive_install
1673                          ? " installdirs-recursive\n"
1674                          : "\n"));
1675     push (@phony, 'installdirs');
1676     if (@installdirs)
1677     {
1678         &pretty_print_rule ("\t" . '$(mkinstalldirs) ', "\t\t",
1679                             @installdirs);
1680     }
1681     $output_rules .= "\n";
1684 # There are several targets which need to be merged.  This is because
1685 # their complete definition is compiled from many parts.  Note that we
1686 # avoid double colon rules, otherwise we'd use them instead.
1687 sub handle_merge_targets
1689     push (@all, 'Makefile');
1690     push (@all, $config_name)
1691         if $config_name && &dirname ($config_name) eq $relative_dir;
1693     &do_one_merge_target ('info', @info);
1694     &do_one_merge_target ('dvi', @dvi);
1696     if (! &variable_defined ('SUBDIRS') || $relative_dir ne '.')
1697     {
1698         # 'check' must depend on 'all', but not at top level.
1699         # Ditto install.
1700         unshift (@check, 'all');
1701         unshift (@install, 'all');
1702     }
1703     &do_one_merge_target ('check', @check);
1704     &do_one_merge_target ('installcheck', @installcheck);
1706     # Handle the various install targets specially.  We do this so
1707     # that (eg) "make install-exec" will run "install-exec-recursive"
1708     # if required, but "make install" won't run it twice.  Step one is
1709     # to see if the user specified local versions of any of the
1710     # targets we handle.  "all" is treated as one of these since
1711     # "install" can run it.
1712     push (@install_exec, 'install-exec-local')
1713         if defined $contents{'install-exec-local'};
1714     push (@install_data, 'install-data-local')
1715         if defined $contents{'install-data-local'};
1716     push (@uninstall, 'uninstall-local')
1717         if defined $contents{'uninstall-local'};
1718     push (@all, 'all-local')
1719         if defined $contents{'all-local'};
1721     if (defined $contents{'install-local'})
1722     {
1723         &am_line_error ('install-local',
1724                         "use \`install-data' or \`install-exec', not \`install'");
1725     }
1727     # Step two: if we are doing recursive makes, write out the
1728     # appropriate rules.
1729     local (@install);
1730     if ($recursive_install)
1731     {
1732         push (@install, 'install-recursive');
1734         if (@all)
1735         {
1736             local (@hackall) = ();
1737             if ($config_name && &dirname ($config_name) eq $relative_dir)
1738             {
1740                 # This is kind of a hack, but I couldn't see a better
1741                 # way to handle it.  In this particular case, we need
1742                 # to make sure config.h is built before we recurse.
1743                 # We can't do this by changing the order of
1744                 # dependencies to the "all" because that breaks when
1745                 # using parallel makes.  Instead we handle things
1746                 # explicitly.
1747                 $output_rules .= ('all-recursive-hack: $(CONFIG_HEADER)'
1748                                   . "\n\t" . '$(MAKE) all-recursive'
1749                                   . "\n\n");
1750                 push (@hackall, 'all-recursive-hack');
1751                 push (@phony, 'all-recursive-hack');
1752             }
1753             else
1754             {
1755                 push (@hackall, 'all-recursive');
1756             }
1758             $output_rules .= ('all-am: '
1759                               . join (' ', @all)
1760                               . "\n\n");
1761             @all = @hackall;
1762             push (@all, 'all-am');
1763             push (@phony, 'all-am');
1764         }
1765         else
1766         {
1767             @all = ('all-recursive');
1768         }
1769         if (@install_exec)
1770         {
1771             $output_rules .= ('install-exec-am: '
1772                               . join (' ', @install_exec)
1773                               . "\n\n");
1774             @install_exec = ('install-exec-recursive', 'install-exec-am');
1775             push (@install, 'install-exec-am');
1776             push (@phony, 'install-exec-am');
1777         }
1778         else
1779         {
1780             @install_exec = ('install-exec-recursive');
1781         }
1782         if (@install_data)
1783         {
1784             $output_rules .= ('install-data-am: '
1785                               . join (' ', @install_data)
1786                               . "\n\n");
1787             @install_data = ('install-data-recursive', 'install-data-am');
1788             push (@install, 'install-data-am');
1789             push (@phony, 'install-data-am');
1790         }
1791         else
1792         {
1793             @install_data = ('install-data-recursive');
1794         }
1795         if (@uninstall)
1796         {
1797             $output_rules .= ('uninstall-am: '
1798                               . join (' ', @uninstall)
1799                               . "\n\n");
1800             @uninstall = ('uninstall-recursive', 'uninstall-am');
1801             push (@phony, 'uninstall-am');
1802         }
1803         else
1804         {
1805             @uninstall = ('uninstall-recursive');
1806         }
1807     }
1809     # Step three: print definitions users can use.  Code below knows
1810     # that install-exec is done before install-data, beware.
1811     $output_rules .= ("install-exec: "
1812                       . join (' ', @install_exec)
1813                       . "\n");
1814     if (defined $contents{'install-exec-hook'})
1815     {
1816         $output_rules .= "\t" . '$(MAKE) install-exec-hook' . "\n";
1817     }
1818     $output_rules .= "\n";
1819     push (@install, 'install-exec') if !$recursive_install;
1820     push (@phony, 'install-exec');
1822     $output_rules .= ("install-data: "
1823                       . join (' ', @install_data)
1824                       . "\n");
1825     if (defined $contents{'install-data-hook'})
1826     {
1827         $output_rules .= "\t" . '$(MAKE) install-data-hook' . "\n";
1828     }
1829     $output_rules .= "\n";
1830     push (@install, 'install-data') if !$recursive_install;
1831     push (@phony, 'install-data');
1833     # If no dependencies for 'install', add 'all'.  Why?  That way
1834     # "make install" at top level of distclean'd distribution won't
1835     # fail because stuff in 'lib' fails to build.
1836     if (! @install || ($#install == 1
1837                        && $install[0] eq 'install-exec'
1838                        && $install[1] eq 'install-data'))
1839     {
1840         push (@install, 'all');
1841     }
1842     $output_rules .= ('install: '
1843                       . join (' ', @install)
1844                       # Use "@:" as empty command so nothing prints.
1845                       . "\n\t\@:"
1846                       . "\n\n"
1847                       . 'uninstall: '
1848                       . join (' ', @uninstall)
1849                       . "\n\n");
1850     push (@phony, 'install', 'uninstall');
1852     $output_rules .= ('all: '
1853                       . join (' ', @all)
1854                       . "\n\n");
1855     push (@phony, 'all');
1857     # Generate the new 'install-strip' target.
1858     $output_rules .= ("install-strip:\n\t"
1859                       . '$(MAKE) INSTALL_PROGRAM=\'$(INSTALL_PROGRAM) -s\' install'
1860                       . "\n");
1863 # Helper for handle_merge_targets.
1864 sub do_one_merge_target
1866     local ($name, @values) = @_;
1868     if (defined $contents{$name . '-local'})
1869     {
1870         # User defined local form of target.  So include it.
1871         push (@values, $name . '-local');
1872         push (@phony, $name . '-local');
1873     }
1875     $output_rules .= $name . ":";
1876     if (@values)
1877     {
1878         $output_rules .= ' ' . join (' ', @values);
1879     }
1880     $output_rules .= "\n\n";
1881     push (@phony, $name);
1884 # Handle all 'clean' targets.
1885 sub handle_clean
1887     push (@clean, 'generic');
1888     $output_rules .= &file_contents ('clean');
1889     &push_phony_cleaners ('generic');
1891     local ($target) = $recursive_install ? 'clean-am' : 'clean';
1892     &do_one_clean_target ($target, 'mostly', '', @clean);
1893     &do_one_clean_target ($target, '', 'mostly', @clean);
1894     &do_one_clean_target ($target, 'dist', '', @clean);
1895     &do_one_clean_target ($target, 'maintainer-', 'dist', @clean);
1897     push (@phony, 'clean', 'mostlyclean', 'distclean', 'maintainer-clean');
1899     local (@deps);
1900     if ($recursive_install)
1901     {
1902         @deps = ('am', 'recursive');
1903         &do_one_clean_target ('', 'mostly', '', @deps);
1904         &do_one_clean_target ('', '', '', @deps);
1905         &do_one_clean_target ('', 'dist', '', @deps);
1906         &do_one_clean_target ('', 'maintainer-', '', @deps);
1907     }
1910 # Helper for handle_clean.
1911 sub do_one_clean_target
1913     local ($target, $name, $last_name, @deps) = @_;
1915     # Special case: if target not passed, then don't generate
1916     # dependency on next "lower" clean target (eg no
1917     # clean<-mostlyclean derivation).  In this case the target is
1918     # implicitly known to be 'clean'.
1919     local ($flag) = $target;
1920     $target = 'clean' if ! $flag;
1922     grep (($_ = $name . 'clean-' . $_) && 0, @deps);
1923     if ($flag)
1924     {
1925         if ($last_name || $name ne 'mostly')
1926         {
1927             push (@deps, $last_name . $target . " ");
1928         }
1929     }
1930     # FIXME not sure if I like the tabs here.
1931     &pretty_print_rule ($name . $target . ": ", "\t\t", @deps);
1933     # FIXME shouldn't we really print these messages before running
1934     # the dependencies?
1935     if ($name . $target eq 'maintainer-clean')
1936     {
1937         # Print a special warning.
1938         $output_rules .=
1939             ("\t\@echo \"This command is intended for maintainers to use;\"\n"
1940              . "\t\@echo \"it deletes files that may require special "
1941              . "tools to rebuild.\"\n");
1943         $output_rules .= "\trm -f config.status\n"
1944             if $relative_dir eq '.';
1945     }
1946     elsif ($name . $target eq 'distclean')
1947     {
1948         $output_rules .= "\trm -f config.status\n";
1949     }
1950     $output_rules .= "\n";
1953 # Handle .PHONY target.
1954 sub handle_phony
1956     &pretty_print_rule ('.PHONY:', "", @phony);
1957     $output_rules .= "\n";
1960 # Handle TESTS variable and other checks.
1961 sub handle_tests
1963     if (defined $options{'dejagnu'})
1964     {
1965         push (@check, 'check-DEJAGNU');
1966         push (@phony, 'check-DEJAGNU');
1967         $output_rules .= &file_contents ('dejagnu') . "\n";
1968         # Note that in the rule we don't directly generate site.exp to
1969         # avoid the possibility of a corrupted site.exp if make is
1970         # interrupted.  Jim Meyering has some useful text on this
1971         # topic.
1972         $output_rules .= ("site.exp: Makefile\n"
1973                           . "\t\@echo 'Making a new site.exp file...'\n"
1974                           . "\t-\@rm -f site.bak\n"
1975                           . "\t\@echo '## these variables are automatically generated by make ##' > \$\@-t\n"
1976                           . "\t\@echo '# Do not edit here.  If you wish to override these values' >> \$\@-t\n"
1977                           . "\t\@echo '# edit the last section' >> \$\@-t\n"
1978                           . "\t\@echo 'set tool \$(DEJATOOL)' >> \$\@-t\n"
1979                           . "\t\@echo 'set srcdir \$(srcdir)' >> \$\@-t\n"
1980                           . "\t\@echo 'set objdir' \`pwd\` >> \$\@-t\n");
1982         # Extra stuff for AC_CANONICAL_*
1983         local (@whatlist) = ();
1984         if ($seen_canonical)
1985         {
1986             push (@whatlist, 'host')
1987         }
1989         # Extra stuff only for AC_CANONICAL_SYSTEM.
1990         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
1991         {
1992             push (@whatlist, 'target', 'build');
1993         }
1995         local ($c1, $c2);
1996         foreach $c1 (@whatlist)
1997         {
1998             foreach $c2 ('alias', 'triplet')
1999             {
2000                 $output_rules .= "\t\@echo 'set ${c1}_${c2} \$(${c1}_${c2})' >> \$\@-t\n";
2001             }
2002         }
2004         $output_rules .= ("\t\@echo '## All variables above are generated by configure. Do Not Edit ##' >> \$\@-t\n"
2005                           . "\t-\@sed '1,/^## All variables above are.*##/ d' site.bak >> \$\@-t\n"
2006                           . "\t-\@mv site.exp site.bak\n"
2007                           . "\t\@mv \$\@-t site.exp\n");
2008     }
2009     else
2010     {
2011         local ($c);
2012         foreach $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
2013         {
2014             if (&variable_defined ($c))
2015             {
2016                 &am_line_error ($c, "\`$c' defined but \`dejagnu' not in \`AUTOMAKE_OPTIONS'");
2017             }
2018         }
2019     }
2021     if (&variable_defined ('TESTS'))
2022     {
2023         push (@check, 'check-TESTS');
2024         push (@phony, 'check-TESTS');
2025         # FIXME use $(SHELL) here?  That is what Ulrich suggests.
2026         # Maybe a new macro, $(TEST_SHELL), a la $(CONFIG_SHELL)?  For
2027         # now we just execute the file directly; this allows test
2028         # files which are compiled -- a possibly useful feature.
2029         $output_rules .= 'check-TESTS: $(TESTS)
2030         @failed=0; all=0; \\
2031         srcdir=$(srcdir); export srcdir; \\
2032         for tst in $(TESTS); do \\
2033           all=`expr $$all + 1`; \\
2034           if test -f $$tst; then dir=.; \\
2035           else dir="$(srcdir)"; fi; \\
2036           if $(TESTS_ENVIRONMENT) $$dir/$$tst; then \\
2037             echo "PASS: $$tst"; \\
2038           else \\
2039             failed=`expr $$failed + 1`; \\
2040             echo "FAIL: $$tst"; \\
2041           fi; \\
2042         done; \\
2043         if test "$$failed" -eq 0; then \\
2044           echo "========================"; \\
2045           echo "All $$all tests passed"; \\
2046           echo "========================"; \\
2047         else \\
2048           echo "$$failed of $$all tests failed"; \\
2049         fi
2051     }
2054 # Handle Emacs Lisp.
2055 sub handle_emacs_lisp
2057     local (@elfiles) = &am_install_var ('lisp', 'LISP', 'lisp', 'noinst');
2059     if (@elfiles)
2060     {
2061         # Found some lisp.
2062         $output_vars .= "lispdir = \@lispdir\@\n";
2063         $output_rules .= (".el.elc:\n"
2064                           . "\t\@echo 'WARNING: Warnings can be ignored. :-)'\n"
2065                           . "\t\$(SHELL) \$(srcdir)/elisp-comp \$<\n");
2066         push (@suffixes, '.el', '.elc');
2068         # Generate .elc files.
2069         grep ($_ .= 'c', @elfiles);
2070         &pretty_print ('ELCFILES =', '', @elfiles);
2072         local ($varname);
2073         if (&variable_defined ('lisp_LISP'))
2074         {
2075             $varname = 'lisp_LISP';
2076             &am_error ("\`lisp_LISP' defined but \`ud_PATH_LISPDIR' not in \`configure.in'")
2077                 if ! $seen_lispdir;
2078         }
2079         else
2080         {
2081             $varname = 'noinst_LISP';
2082         }
2083         &require_file_with_line ($varname, $FOREIGN, 'elisp-comp');
2085     }
2088 ################################################################
2090 # Scan configure.in for interesting things.
2091 # FIXME ensure VERSION, PACKAGE are set.
2092 sub scan_configure
2094     open (CONFIGURE, 'configure.in')
2095         || die "automake: couldn't open \`configure.in': $!\n";
2096     print "automake: reading configure.in\n" if $verbose;
2098     # Reinitialize libsources here.  This isn't really necessary,
2099     # since we currently assume there is only one configure.in.  But
2100     # that won't always be the case.
2101     %libsources = ();
2103     local ($in_ac_output, @make_list) = 0;
2104     local ($libobj_iter);
2105     while (<CONFIGURE>)
2106     {
2107         # Remove comments from current line.
2108         s/\bdnl\b.*$//;
2109         s/\#.*$//;
2111         # Populate libobjs array.
2112         if (/AC_FUNC_ALLOCA/)
2113         {
2114             $libsources{'alloca.c'} = 1;
2115         }
2116         elsif (/AC_FUNC_GETLOADAVG/)
2117         {
2118             $libsources{'getloadavg.c'} = 1;
2119         }
2120         elsif (/AC_FUNC_MEMCMP/)
2121         {
2122             $libsources{'memcmp.c'} = 1;
2123         }
2124         elsif (/AC_STRUCT_ST_BLOCKS/)
2125         {
2126             $libsources{'fileblocks.c'} = 1;
2127         }
2128         elsif (/(AC|fp)_FUNC_FNMATCH/)
2129         {
2130             # AC_FUNC_FNMATCH is just wishful thinking at this point.
2131             $libsources{'fnmatch.c'} = 1;
2132         }
2133         elsif (/AC_REPLACE_FUNCS\s*\((.*)\)/)
2134         {
2135             foreach (split (' ', $1))
2136             {
2137                 $libsources{$_ . '.c'} = 1;
2138             }
2139         }
2140         elsif (/AC_REPLACE_GNU_GETOPT/)
2141         {
2142             $libsources{'getopt.c'} = 1;
2143             $libsources{'getopt1.c'} = 1;
2144         }
2145         elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
2146                || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
2147         {
2148             foreach $libobj_iter (split (' ', $1))
2149             {
2150                 if ($libobj_iter =~ /^(.*)\.o$/)
2151                 {
2152                     $libsources{$1 . '.c'} = 1;
2153                 }
2154             }
2155         }
2157         # Process the AC_OUTPUT macro.
2158         if (! $in_ac_output && s/AC_OUTPUT\s*\(\[?//)
2159         {
2160             $in_ac_output = 1;
2161             $ac_output_line = $.;
2162         }
2163         if ($in_ac_output)
2164         {
2165             $in_ac_output = 0 if s/[\]\),].*$//;
2167             # Look at potential Makefile.am's.
2168             foreach (split)
2169             {
2170                 next if $_ eq "\\";
2171                 if (-f $_ . '.am')
2172                 {
2173                     push (@make_list, $_);
2174                 }
2175                 else
2176                 {
2177                     push (@other_input_files, $_);
2178                 }
2179             }
2180         }
2182         if (/AC_CONFIG_AUX_DIR\(([^)]+)\)/)
2183         {
2184             @config_aux_path = $1;
2185         }
2187         # Check for ansi2knr.
2188         $fp_c_prototypes = 1 if /fp_C_PROTOTYPES/;
2190         # Check for NLS support.
2191         if (/ud_GNU_GETTEXT/)
2192         {
2193             $seen_gettext = 1;
2194             $ac_gettext_line = $.;
2195         }
2197         # Look for ALL_LINGUAS.
2198         if (/ALL_LINGUAS="(.*)"$/ || /ALL_LINGUAS=(.*)$/)
2199         {
2200             $seen_linguas = 1;
2201             $all_linguas = $1;
2202             $all_linguas_line = $.;
2203         }
2205         # Handle configuration headers.
2206         if (/AC_CONFIG_HEADER\s*\((.*)\)/)
2207         {
2208             $config_header_line = $.;
2209             $config_name = $1;
2210             if ($config_name =~ /^([^:]+):(.+)$/)
2211             {
2212                 $config_name = $1;
2213                 $config_header = $2;
2214             }
2215             else
2216             {
2217                 $config_header = $config_name . '.in';
2218             }
2219         }
2221         # Handle AC_CANONICAL_*.  Always allow upgrading to
2222         # AC_CANONICAL_SYSTEM, but never downgrading.
2223         $seen_canonical = $AC_CANONICAL_HOST
2224             if ! $seen_canonical && /AC_CANONICAL_HOST/;
2225         $seen_canonical = $AC_CANONICAL_SYSTEM if /AC_CANONICAL_SYSTEM/;
2227         $seen_canonical = 1 if /AC_CHECK_TOOL/;
2228         $seen_path_xtra = 1 if /AC_PATH_XTRA/;
2230         # Sometimes it is desirable to explicitly set YACC.  For
2231         # instance some people don't want to use bison.
2232         $seen_prog_yacc = 1 if (/AC_PROG_YACC/
2233                                 || /AC_SUBST\(YACC\)/
2234                                 || /AC_(PATH|CHECK)_PROGS?\(YACC/);
2236         # Some things required by Automake.
2237         $seen_make_set = 1 if /AC_PROG_MAKE_SET/;
2238         $seen_arg_prog = 1 if /AC_ARG_PROGRAM/;
2239         $seen_ranlib = 1 if /AC_PROG_RANLIB/;
2240         $seen_maint_mode = 1 if /jm_MAINTAINER_MODE/;
2241         $seen_package = 1 if /PACKAGE=/;
2242         $seen_version = 1 if /VERSION=/;
2244         # Weird conditionals here because it is always allowed to
2245         # upgrade to fp_PROG_INSTALL but never to downgrade to
2246         # AC_PROG_INSTALL.
2247         $seen_prog_install = 1 if ! $seen_prog_install && /AC_PROG_INSTALL/;
2248         $seen_prog_install = 2 if /fp_PROG_INSTALL/;
2250         $seen_lispdir = 1 if /ud_PATH_LISPDIR/;
2252         if (/AM_PROG_LIBTOOL/)
2253         {
2254             $seen_libtool = 1;
2255             $seen_ranlib = 2;
2256             $libtool_line = $.;
2257         }
2258     }
2260     # Set input files if not specified by user.
2261     @input_files = @make_list if (! @input_files);
2263     close (CONFIGURE);
2265     &am_conf_error ("\`PACKAGE' not defined in configure.in")
2266         if ! $seen_package;
2267     &am_conf_error ("\`VERSION' not defined in configure.in")
2268         if ! $seen_version;
2270     # Look for some files we need.  Always check for these.  This
2271     # check must be done for every run, even those where we are only
2272     # looking at a subdir Makefile.  We must set relative_dir so that
2273     # the file-finding machinery works.
2274     local ($relative_dir) = '.';
2275     &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs');
2278 ################################################################
2280 # Do any extra checking for GNU standards.
2281 sub check_gnu_standards
2283     if ($relative_dir eq '.')
2284     {
2285         # In top level (or only) directory.
2286         &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
2287                        'AUTHORS', 'ChangeLog');
2288     }
2291 # Do any extra checking for GNITS standards.
2292 sub check_gnits_standards
2294     if ($strictness >= $GNITS && -f $relative_dir . '/COPYING.LIB')
2295     {
2296         &am_error
2297             ("\`${relative_dir}/COPYING.LIB' disallowed by Gnits standards");
2298     }
2300     if ($relative_dir eq '.')
2301     {
2302         # In top level (or only) directory.
2303         &require_file ($GNITS, 'THANKS');
2304     }
2307 ################################################################
2309 # Pretty-print something.  HEAD is what should be printed at the
2310 # beginning of the first line, FILL is what should be printed at the
2311 # beginning of every subsequent line.
2312 sub pretty_print_internal
2314     local ($head, $fill, @values) = @_;
2316     local ($column) = length ($head);
2317     local ($result) = $head;
2319     # Fill length is number of characters.  However, each Tab
2320     # character counts for eight.  So we count the number of Tabs and
2321     # multiply by 7.
2322     local ($fill_length) = length ($fill);
2323     $fill_length += 7 * ($fill =~ tr/\t/\t/d);
2325     local ($bol) = 0;
2326     foreach (@values)
2327     {
2328         # "71" because we also print a space.
2329         if ($column + length ($_) > 71)
2330         {
2331             $result .= " \\\n" . $fill;
2332             $column = $fill_length;
2333             $bol = 1;
2334         }
2336         $result .= ' ' unless ($bol);
2337         $result .= $_;
2338         $column += length ($_) + 1;
2339         $bol = 0;
2340     }
2342     $result .= "\n";
2343     return $result;
2346 # Pretty-print something and append to output_vars.
2347 sub pretty_print
2349     $output_vars .= &pretty_print_internal (@_);
2352 # Pretty-print something and append to output_rules.
2353 sub pretty_print_rule
2355     $output_rules .= &pretty_print_internal (@_);
2359 ################################################################
2361 # See if a variable exists.
2362 sub variable_defined
2364     local ($var) = @_;
2365     if (defined $targets{$var})
2366     {
2367         &am_line_error ($var, "\`$var' is target; expected variable");
2368     }
2369     return (defined $contents{$var} && ! defined $targets{$var});
2372 # Read Makefile.am and set up %contents.  Simultaneously copy lines
2373 # from Makefile.am into $output_trailer or $output_vars as
2374 # appropriate.  NOTE we put rules in the trailer section.  We want
2375 # user rules to come after our generated stuff.
2376 sub read_am_file
2378     local ($amfile) = @_;
2380     # Compute relative location of the top object directory.
2381     local (@topdir) = ();
2382     foreach (split (/\//, $relative_dir))
2383     {
2384         next if $_ eq '.' || $_ eq '';
2385         if ($_ eq '..')
2386         {
2387             pop @topdir;
2388         }
2389         else
2390         {
2391             push (@topdir, '..');
2392         }
2393     }
2394     @topdir = ('.') if ! @topdir;
2396     $top_builddir = join ('/', @topdir);
2397     local ($build_rx);
2398     ($build_rx = $top_builddir) =~ s/(\W)/\\$1/g;
2399     local ($header_vars) =
2400         &file_contents_with_transform
2401             ('s/\@top_builddir\@/' . $build_rx . '/g',
2402              'header-vars');
2404     # Generate some useful variables when AC_CANONICAL_* used.
2405     if ($seen_canonical)
2406     {
2407         $header_vars .= ('host_alias = @host_alias@' . "\n"
2408                          . 'host_triplet = @host@' . "\n");
2409         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
2410         {
2411             $header_vars .= ('build_alias = @build_alias@' . "\n"
2412                              . 'build_triplet = @build@' . "\n");
2413             $header_vars .= ('target_alias = @target_alias@' . "\n"
2414                              . 'target_triplet = @target@' . "\n");
2415         }
2416     }
2418     open (AM_FILE, $amfile) || die "automake: couldn't open \`$amfile': $!\n";
2419     print "automake: reading $amfile\n" if $verbose;
2421     $output_vars .= ("# $in_file_name generated automatically by automake "
2422                      . $VERSION . " from $am_file_name\n");
2424     # Generate copyright for generated Makefile.in.
2425     $output_vars .= $gen_copyright;
2427     local ($saw_bk) = 0;
2428     local ($was_rule) = 0;
2429     local ($spacing) = '';
2430     local ($comment) = '';
2431     local ($last_var_name) = '';
2432     local ($blank) = 0;
2434     while (<AM_FILE>)
2435     {
2436         if (/$IGNORE_PATTERN/o)
2437         {
2438             # Merely delete comments beginning with two hashes.
2439         }
2440         elsif (/$WHITE_PATTERN/o)
2441         {
2442             # Stick a single white line before the incoming macro or rule.
2443             $spacing = "\n";
2444             $blank = 1;
2445         }
2446         elsif (/$COMMENT_PATTERN/o)
2447         {
2448             # Stick comments before the incoming macro or rule.  Make
2449             # sure a blank line preceeds comments.
2450             $spacing = "\n" unless $blank;
2451             $comment .= $spacing . $_;
2452             $spacing = '';
2453         }
2454         else
2455         {
2456             last;
2457         }
2458     }
2460     $output_vars .= $comment . "\n" . $header_vars;
2461     $comment = '';
2462     $spacing = "\n";
2464     local ($is_ok_macro);
2465     while ($_)
2466     {
2467         $_ .= "\n"
2468             unless substr ($_, -1, 1) eq "\n";
2470         $_ =~ s/\@MAINT\@//g
2471             unless $seen_maint_mode;
2473         if (/$IGNORE_PATTERN/o)
2474         {
2475             # Merely delete comments beginning with two hashes.
2476         }
2477         elsif (/$WHITE_PATTERN/o)
2478         {
2479             # Stick a single white line before the incoming macro or rule.
2480             $spacing = "\n";
2481         }
2482         elsif (/$COMMENT_PATTERN/o)
2483         {
2484             # Stick comments before the incoming macro or rule.
2485             $comment .= $spacing . $_;
2486             $spacing = '';
2487         }
2488         elsif ($saw_bk)
2489         {
2490             if ($was_rule)
2491             {
2492                 $output_trailer .= $_;
2493                 $saw_bk = /\\$/;
2494             }
2495             else
2496             {
2497                 $output_vars .= $_;
2498                 $saw_bk = /\\$/;
2499                 # Chop newline and backslash if this line is
2500                 # continued.  FIXME maybe ensure trailing whitespace
2501                 # exists?
2502                 chop if $saw_bk;
2503                 chop if $saw_bk;
2504                 $contents{$last_var_name} .= $_;
2505             }
2506         }
2507         elsif (/$RULE_PATTERN/o)
2508         {
2509             # warn "** Saw rule .$1.\n";
2510             # Found a rule.
2511             $was_rule = 1;
2512             # Value here doesn't matter; for targets we only note
2513             # existence.
2514             $contents{$1} = 1;
2515             $targets{$1} = 1;
2516             $content_lines{$1} = $.;
2517             $output_trailer .= $comment . $spacing . $_;
2518             $comment = $spacing = '';
2519             $saw_bk = /\\$/;
2520         }
2521         elsif (($is_ok_macro = /$MACRO_PATTERN/o)
2522                || /$BOGUS_MACRO_PATTERN/o)
2523         {
2524             # Found a macro definition.
2525             $was_rule = 0;
2526             $last_var_name = $1;
2527             if (substr ($2, -1) eq "\\")
2528             {
2529                 $contents{$1} = substr ($2, 0, length ($2) - 1);
2530             }
2531             else
2532             {
2533                 $contents{$1} = $2;
2534             }
2535             $content_lines{$1} = $.;
2536             $output_vars .= $comment . $spacing . $_;
2537             $comment = $spacing = '';
2538             $saw_bk = /\\$/;
2540             # Error if bogus.
2541             &am_line_error ($., "bad macro name \`$1'")
2542                 if ! $is_ok_macro;
2543         }
2544         else
2545         {
2546             # This isn't an error; it is probably a continued rule.
2547             # In fact, this is what we assume.
2548             $was_rule = 1;
2549             $output_trailer .= $comment . $spacing . $_;
2550             $comment = $spacing = '';
2551             $saw_bk = /\\$/;
2552         }
2554         $_ = <AM_FILE>;
2555     }
2557     $output_trailer .= $comment;
2560 ################################################################
2562 sub initialize_global_constants
2564     # Values for AC_CANONICAL_*
2565     $AC_CANONICAL_HOST = 1;
2566     $AC_CANONICAL_SYSTEM = 2;
2568     # Associative array of standard directory names.  Entry is TRUE if
2569     # corresponding directory should be installed during
2570     # 'install-exec' phase.
2571     %exec_dir_p =
2572         ('bin', 1,
2573          'sbin', 1,
2574          'libexec', 1,
2575          'data', 0,
2576          'sysconf', 1,
2577          'localstate', 1,
2578          'lib', 1,
2579          'info', 0,
2580          'man', 0,
2581          'include', 0,
2582          'oldinclude', 0,
2583          'pkgdata', 0,
2584          'pkglib', 1,
2585          'pkginclude', 0
2586          );
2588     # Helper text for dealing with man pages.
2589     $install_man_format =
2590     '   @sect=@SECTION@;                                \\
2591         inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
2592         echo installing @MAN@ as $(mandir)/man$$sect/$$inst; \\
2593         if test -f $(srcdir)/@MAN@; then file=$(srcdir)/@MAN@; \\
2594         else file=@MAN@; fi; \\
2595         $(INSTALL_DATA) $(srcdir)/@MAN@ $(mandir)/man$$sect/$$inst
2598     $uninstall_man_format =
2599     '   inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
2600         rm -f $(mandir)/man@SECTION@/$$inst
2603     # Commonly found files we look for and automatically include in
2604     # DISTFILES.
2605     @common_files =
2606         (
2607          "README", "THANKS", "TODO", "NEWS", "COPYING", "COPYING.LIB",
2608          "INSTALL", "ABOUT-NLS", "ChangeLog", "configure", "configure.in",
2609          "config.guess", "config.sub", "AUTHORS", "BACKLOG", "ABOUT-GNU",
2610          "libversion.in", "mdate-sh", "mkinstalldirs", "install-sh",
2611          'texinfo.tex', "ansi2knr.c", "ansi2knr.1"
2612          );
2614     # Commonly used files we auto-include, but only sometimes.
2615     @common_sometimes =
2616         (
2617          "aclocal.m4", "acconfig.h", "config.h.top",
2618          "config.h.bot", "stamp-h.in", 'stamp-vti', 'elisp-comp', 'libtool'
2619          );
2621     $USAGE = "\
2622   --amdir=DIR           directory storing config files
2623   --foreign             same as --strictness=foreign
2624   --gnits               same as --strictness=gnits
2625   --gnu                 same as --strictness=gnu
2626   --help                print this help, then exit
2627   -i, --include-deps    include generated dependencies in Makefile.in
2628   -a, --add-missing     add missing standard files to package
2629   --no-force            only update Makefile.in's that are out of date
2630   -o DIR, --output-dir=DIR
2631                         put generated Makefile.in's into DIR
2632   -s LEVEL, --strictness=LEVEL
2633                         set strictness level.  LEVEL is foreign, gnu, gnits
2634   -v, --verbose         verbosely list files processed
2635   --version             print version number, then exit\n";
2637     # Copyright on generated Makefile.ins.
2638     $gen_copyright = "\
2639 # Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
2640 # This Makefile.in is free software; the Free Software Foundation
2641 # gives unlimited permission to copy, distribute and modify it.
2645 # (Re)-Initialize per-Makefile.am variables.
2646 sub initialize_per_input
2648     # These two variables are used when generating each Makefile.in.
2649     # They hold the Makefile.in until it is ready to be printed.
2650     $output_rules = '';
2651     $output_vars = '';
2652     $output_trailer = '';
2654     # Suffixes found during a run.
2655     @suffixes = ();
2657     # This holds the contents of a Makefile.am, as parsed by
2658     # read_am_file.
2659     %contents = ();
2661     # This holds the names which are targets.  These also appear in
2662     # %contents.
2663     %targets = ();
2665     # This holds the line numbers at which various elements of
2666     # %contents are defined.
2667     %content_lines = ();
2669     # This holds the "relative directory" of the current Makefile.in.
2670     # Eg for src/Makefile.in, this is "src".
2671     $relative_dir = '';
2673     # This holds a list of files that are included in the
2674     # distribution.
2675     %dist_common = ();
2677     # List of dependencies for the obvious targets.
2678     @install_data = ();
2679     @install_exec = ();
2680     @uninstall = ();
2681     @installdirs = ();
2683     @info = ();
2684     @dvi = ();
2685     @all = ();
2686     @check = ();
2687     @installcheck = ();
2688     @clean = ();
2690     @phony = ();
2692     # These are pretty obvious, too.  They are used to define the
2693     # SOURCES and OBJECTS variables.
2694     @sources = ();
2695     @objects = ();
2697     # TRUE if current directory holds any C source files.  (Actually
2698     # holds object extension, but this information is encapsulated in
2699     # the function get_object_extension).
2700     $dir_holds_sources = '';
2702     # TRUE if install targets should work recursively.
2703     $recursive_install = 0;
2705     # All .P files.
2706     %dep_files = ();
2708     # Strictness levels.
2709     $strictness = $default_strictness;
2710     $strictness_name = $default_strictness_name;
2712     # Options from AUTOMAKE_OPTIONS.
2713     %options = ();
2715     # Whether or not dependencies are handled.  Can be further changed
2716     # in handle_options.
2717     $use_dependencies = $cmdline_use_dependencies;
2719     # Per Makefile.am.
2720     $local_maint_charset = $maint_charset;
2724 ################################################################
2726 # Return contents of a file from $am_dir, automatically skipping
2727 # macros or rules which are already known.  Runs command on each line
2728 # as it is read; this command can modify $_.
2729 sub file_contents_with_transform
2731     local ($command, $basename) = @_;
2732     local ($file) = $am_dir . '/' . $basename . '.am';
2734     open (FC_FILE, $file)
2735         || die "automake: installation error: cannot open \`$file'\n";
2736     # Looks stupid?
2737     # print "automake: reading $file\n" if $verbose;
2739     local ($was_rule) = 0;
2740     local ($result_vars) = '';
2741     local ($result_rules) = '';
2742     local ($comment) = '';
2743     local ($spacing) = "\n";
2744     local ($skipping) = 0;
2746     while (<FC_FILE>)
2747     {
2748         $_ =~ s/\@MAINT\@//g
2749             unless $seen_maint_mode;
2751         eval $command;
2753         if (/$IGNORE_PATTERN/o)
2754         {
2755             # Merely delete comments beginning with two hashes.
2756         }
2757         elsif (/$WHITE_PATTERN/o)
2758         {
2759             # Stick a single white line before the incoming macro or rule.
2760             $spacing = "\n";
2761         }
2762         elsif (/$COMMENT_PATTERN/o)
2763         {
2764             # Stick comments before the incoming macro or rule.
2765             $comment .= $spacing . $_;
2766             $spacing = '';
2767         }
2768         elsif ($saw_bk)
2769         {
2770             if ($was_rule)
2771             {
2772                 $result_rules .= $_ if ! $skipping;
2773             }
2774             else
2775             {
2776                 $result_vars .= $_ if ! $skipping;
2777             }
2778             $saw_bk = /\\$/;
2779         }
2780         elsif (/$RULE_PATTERN/o)
2781         {
2782             # warn "** Found rule .$1.\n";
2783             # Found a rule.
2784             $was_rule = 1;
2785             $skipping = defined $contents{$1};
2786             # warn "** Skip $skipping\n" if $skipping;
2787             $result_rules .= $comment . $spacing . $_ if ! $skipping;
2788             $comment = $spacing = '';
2789             $saw_bk = /\\$/;
2790         }
2791         elsif (/$MACRO_PATTERN/o)
2792         {
2793             # warn "** Found macro .$1.\n";
2794             # Found a variable reference.
2795             $was_rule = 0;
2796             $skipping = defined $contents{$1};
2797             # warn "** Skip $skipping\n" if $skipping;
2798             $result_vars .= $comment . $spacing . $_ if ! $skipping;
2799             $comment = $spacing = '';
2800             $saw_bk = /\\$/;
2801         }
2802         else
2803         {
2804             # This isn't an error; it is probably a continued rule.
2805             # In fact, this is what we assume.
2806             $was_rule = 1;
2807             $result_rules .= $comment . $spacing . $_ if ! $skipping;
2808             $comment = $spacing = '';
2809             $saw_bk = /\\$/;
2810         }
2811     }
2813     close (FC_FILE);
2814     return $result_vars . $result_rules . $comment;
2817 # Like file_contents_with_transform, but no transform.
2818 sub file_contents
2820     return &file_contents_with_transform ('', @_);
2823 # Handle `where_HOW' variable magic.  Does all lookups, generates
2824 # install code, and possibly generates code to define the primary
2825 # variable.  The first argument is the name of the .am file to munge,
2826 # the second argument is the primary variable (eg HEADERS), and all
2827 # subsequent arguments are possible installation locations.  Returns
2828 # list of all values of all _HOW targets.
2830 # FIXME this should be rewritten to be cleaner.  It should be broken
2831 # up into multiple functions.
2833 # Usage is: am_install_var (OPTION..., file, HOW, where...)
2834 sub am_install_var
2836     local (@args) = @_;
2838     local ($do_all, $do_clean) = (1, 0);
2839     while (@args)
2840     {
2841         if ($args[0] eq '-clean')
2842         {
2843             $do_clean = 1;
2844         }
2845         elsif ($args[0] eq '-no-all')
2846         {
2847             $do_all = 0;
2848         }
2849         elsif ($args[0] !~ /^-/)
2850         {
2851             last;
2852         }
2853         shift (@args);
2854     }
2855     local ($file, $primary, @prefixes) = @args;
2857     local (@used) = ();
2858     local (@result) = ();
2860     # Now that configure substitutions are allowed in where_HOW
2861     # variables, it is an error to actually define the primary.
2862     &am_line_error ($primary, "\`$primary' is an anachronism")
2863         if &variable_defined ($primary);
2866     # Look for misspellings.  It is an error to have a variable ending
2867     # in a "reserved" suffix whose prefix is unknown, eg
2868     # "bni_PROGRAMS".  However, unusual prefixes are allowed if a
2869     # variable of the same name (with "dir" appended) exists.  For
2870     # instance, if the variable "zardir" is defined, then
2871     # "zar_PROGRAMS" becomes valid.  This is to provide a little extra
2872     # flexibility in those cases which need it.  Perhaps it should be
2873     # disallowed in the Gnits case?  The problem is, sometimes it is
2874     # useful to put things in a subdir of eg pkgdatadir, perhaps even
2875     # for Gnitsoids.
2876     local (%valid, $varname);
2877     grep ($valid{$_} = 0, @prefixes);
2878     $valid{'EXTRA'} = 0;
2879     foreach $varname (keys %contents)
2880     {
2881         if ($varname =~ /^(.*)_$primary$/)
2882         {
2883             if (! defined $valid{$1} && ! &variable_defined ($1 . 'dir'))
2884             {
2885                 &am_line_error ($varname, "invalid variable \"$varname\"");
2886             }
2887             else
2888             {
2889                 # Ensure all extended prefixes are actually used.
2890                 $valid{$1} = 1;
2891             }
2892         }
2893     }
2895     local ($clean_file) = $file . '-clean';
2896     local ($one_name);
2897     local ($X);
2898     foreach $X (keys %valid)
2899     {
2900         $one_name = $X . '_' . $primary;
2901         if (&variable_defined ($one_name))
2902         {
2903             # Append actual contents of where_PRIMARY variable to
2904             # result.
2905             local ($rcurs);
2906             foreach $rcurs (split (' ', $contents{$one_name}))
2907             {
2908                 # Skip configure substitutions.  Possibly bogus.
2909                 next if $rcurs =~ /^\@.*\@$/;
2910                 push (@result, $rcurs);
2911             }
2913             # "EXTRA" shouldn't be used when generating clean targets,
2914             # @all, or install targets.
2915             next if $X eq 'EXTRA';
2917             if ($do_clean)
2918             {
2919                 $output_rules .=
2920                     &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go',
2921                                                    $clean_file);
2923                 push (@clean, $X . $primary);
2924                 &push_phony_cleaners ($X . $primary);
2925             }
2927             if ($X eq 'check')
2928             {
2929                 push (@check, '$(' . $one_name . ')');
2930             }
2931             else
2932             {
2933                 push (@used, '$(' . $one_name . ')');
2934             }
2935             if ($X eq 'noinst' || $X eq 'check')
2936             {
2937                 # Objects which don't get installed by default.
2938                 next;
2939             }
2941             $output_rules .=
2942                 &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go',
2943                                                $file);
2945             push (@uninstall, 'uninstall-' . $X . $primary);
2946             push (@phony, 'uninstall-' . $X . $primary);
2947             push (@installdirs, '$(' . $X . 'dir)');
2948             if ($exec_dir_p{$X})
2949             {
2950                 push (@install_exec, 'install-' . $X . $primary);
2951                 push (@phony, 'install-' . $X . $primary);
2952             }
2953             else
2954             {
2955                 push (@install_data, 'install-' . $X . $primary);
2956                 push (@phony, 'install-' . $X . $primary);
2957             }
2958         }
2959     }
2961     if (@used)
2962     {
2963         # Define it.
2964         &pretty_print ($primary . ' =', '', @used);
2965         $output_vars .= "\n";
2966     }
2968     # Push here because PRIMARY might be configure time determined.
2969     push (@all, '$(' . $primary . ')')
2970         if $do_all && @used;
2972     return (@result);
2976 ################################################################
2978 # This variable is local to the "require file" set of functions.
2979 @require_file_paths = ();
2981 # Verify that the file must exist in the current directory.  Usage:
2982 # require_file (isconfigure, line_number, strictness, file) strictness
2983 # is the strictness level at which this file becomes required.  Must
2984 # set require_file_paths before calling this function.
2985 # require_file_paths is set to hold a single directory (the one in
2986 # which the first file was found) before return.
2987 sub require_file_internal
2989     local ($is_configure, $line, $mystrict, @files) = @_;
2990     local ($file, $fullfile);
2991     local ($found_it, $errfile, $errdir);
2992     local ($save_dir);
2994     foreach $file (@files)
2995     {
2996         $found_it = 0;
2997         foreach $dir (@require_file_paths)
2998         {
2999             if ($dir eq '.')
3000             {
3001                 $fullfile = $relative_dir . "/" . $file;
3002                 $errdir = $relative_dir unless $errdir;
3003             }
3004             else
3005             {
3006                 $fullfile = $dir . "/" . $file;
3007                 $errdir = $dir unless $errdir;
3008             }
3010             # Use different name for "error filename".  Otherwise on
3011             # an error the bad file will be reported as eg
3012             # `../../install-sh' when using the default
3013             # config_aux_path.
3014             $errfile = $errdir . '/' . $file;
3016             if (-f $fullfile)
3017             {
3018                 $found_it = 1;
3019                 &push_dist_common ($file) if $dir eq $relative_dir;
3020                 $save_dir = $dir;
3021                 last;
3022             }
3023         }
3025         if ($found_it)
3026         {
3027             # Prune the path list.
3028             @require_file_paths = $save_dir;
3029         }
3030         else
3031         {
3032             if ($strictness >= $mystrict)
3033             {
3034                 # Only install missing files according to our desired
3035                 # strictness level.
3036                 if ($add_missing && -f ($am_dir . '/' . $file))
3037                 {
3038                     # Install the missing file.  Symlink if we can, copy
3039                     # if we must.
3040                     if ($symlink_exists)
3041                     {
3042                         symlink ($am_dir . '/' . $file, $errfile);
3043                     }
3044                     else
3045                     {
3046                         system ('cp', $am_dir . '/' . $file, $errfile);
3047                     }
3049                     # FIXME this is a hack.  Should have am_warn.
3050                     local ($save) = $exit_status;
3051                     if ($is_configure)
3052                     {
3053                         &am_conf_line_error
3054                             ($line,
3055                              "required file \"$errfile\" not found; installing");
3056                     }
3057                     else
3058                     {
3059                         &am_line_error
3060                             ($line,
3061                              "required file \"$errfile\" not found; installing");
3062                     }
3063                     $exit_status = $save;
3064                 }
3065                 else
3066                 {
3067                     # Only an error if strictness constraint violated.
3068                     if ($is_configure)
3069                     {
3070                         &am_conf_line_error
3071                             ($line, "required file \"$errfile\" not found");
3072                     }
3073                     else
3074                     {
3075                         &am_line_error
3076                             ($line, "required file \"$errfile\" not found");
3077                     }
3078                 }
3079             }
3080         }
3081     }
3084 # Like require_file_with_line, but error messages refer to
3085 # configure.in, not the current Makefile.am.
3086 sub require_file_with_conf_line
3088     @require_file_paths = '.';
3089     &require_file_internal (1, @_);
3092 sub require_file_with_line
3094     @require_file_paths = '.';
3095     &require_file_internal (0, @_);
3098 sub require_file
3100     @require_file_paths = '.';
3101     &require_file_internal (0, '', @_);
3104 # Require a file that is also required by Autoconf.  Looks in
3105 # configuration path, as specified by AC_CONFIG_AUX_DIR.
3106 sub require_config_file
3108     @require_file_paths = @config_aux_path;
3109     &require_file_internal (0, '', @_);
3110     local ($dir) = $require_file_paths[0];
3111     @config_aux_path = @require_file_paths;
3112     if ($dir eq '.')
3113     {
3114         $config_aux_dir = '.';
3115     }
3116     else
3117     {
3118         $config_aux_dir = '$(top_srcdir)/' . $dir;
3119     }
3122 # Assumes that the line number is in Makefile.am.
3123 sub require_conf_file_with_line
3125     @require_file_paths = @config_aux_path;
3126     &require_file_internal (0, @_);
3127     local ($dir) = $require_file_paths[0];
3128     @config_aux_path = @require_file_paths;
3129     if ($dir eq '.')
3130     {
3131         $config_aux_dir = '.';
3132     }
3133     else
3134     {
3135         $config_aux_dir = '$(top_srcdir)/' . $dir;
3136     }
3139 # Assumes that the line number is in Makefile.am.
3140 sub require_conf_file_with_conf_line
3142     @require_file_paths = @config_aux_path;
3143     &require_file_internal (1, @_);
3144     local ($dir) = $require_file_paths[0];
3145     @config_aux_path = @require_file_paths;
3146     if ($dir eq '.')
3147     {
3148         $config_aux_dir = '.';
3149     }
3150     else
3151     {
3152         $config_aux_dir = '$(top_srcdir)/' . $dir;
3153     }
3156 ################################################################
3158 # Push a list of files onto dist_common.
3159 sub push_dist_common
3161     local (@files) = @_;
3162     local ($file);
3164     foreach $file (@files)
3165     {
3166         $dist_common{$file} = 1;
3167     }
3170 # Push a list of clean targets onto phony.
3171 sub push_phony_cleaners
3173     local ($base) = @_;
3174     local ($target);
3175     foreach $target ('mostly', 'dist', '', 'maintainer-')
3176     {
3177         push (@phony, $target . 'clean-' . $base);
3178     }
3181 # Set strictness.
3182 sub set_strictness
3184     $strictness_name = $_[0];
3185     if ($strictness_name eq 'gnu')
3186     {
3187         $strictness = $GNU;
3188     }
3189     elsif ($strictness_name eq 'gnits')
3190     {
3191         $strictness = $GNITS;
3192     }
3193     elsif ($strictness_name eq 'foreign')
3194     {
3195         $strictness = $FOREIGN;
3196     }
3197     else
3198     {
3199         die "automake: level \`$strictness_name' not recognized\n";
3200     }
3204 ################################################################
3206 # Return directory name of file.
3207 sub dirname
3209     local ($file) = @_;
3210     local ($sub);
3212     ($sub = $file) =~ s,/+[^/]+$,,g;
3213     $sub = '.' if $sub eq $file;
3214     return $sub;
3217 # Make a directory.
3218 sub mkdir
3220     local ($dirname) = @_;
3221     system ("mkdir", $dirname);
3224 ################################################################
3226 # Print an error message and set exit status.
3227 sub am_error
3229     warn "automake: ${am_file}.am: ", join (' ', @_), "\n";
3230     $exit_status = 1;
3233 sub am_line_error
3235     local ($symbol, @args) = @_;
3237     if ($symbol)
3238     {
3239         # If SYMBOL not already a line number, look it up in Makefile.am.
3240         $symbol = $content_lines{$symbol} unless $symbol =~ /^\d+$/;
3241         $symbol .= ': ' if $symbol;
3242         warn "${am_file}.am:", $symbol, join (' ', @args), "\n";
3243         $exit_status = 1;
3244     }
3245     else
3246     {
3247         &am_error (@args);
3248     }
3251 # Like am_error, but while scanning configure.in.
3252 sub am_conf_error
3254     # FIXME can run in subdirs.
3255     warn "automake: configure.in: ", join (' ', @_), "\n";
3256     $exit_status = 1;
3259 # Error message with line number referring to configure.in.
3260 sub am_conf_line_error
3262     local ($line, @args) = @_;
3264     if ($line)
3265     {
3266         warn "configure.in: $line: ", join (' ', @args), "\n";
3267         $exit_status = 1;
3268     }
3269     else
3270     {
3271         &am_conf_error (@args);
3272     }
3275 # Tell user where our aclocal.m4 is, but only once.
3276 sub keyed_aclocal_warning
3278     local ($key) = @_;
3279     warn "automake: macro \`$key' can be found in ${am_dir}/aclocal.m4\n";
3282 # Print usage information.
3283 sub usage
3285     print "Usage: automake [OPTION] ... [Makefile]...\n";
3286     print $USAGE;
3287     print "\nFiles which are automatically distributed, if found:\n";
3288     $~ = "USAGE_FORMAT";
3289     local (@lcomm) = sort ((@common_files, @common_sometimes));
3290     local ($one, $two, $three, $four);
3291     while (@lcomm > 0)
3292     {
3293         $one = shift @lcomm;
3294         $two = @lcomm ? shift @lcomm : '';
3295         $three = @lcomm ? shift @lcomm : '';
3296         $four = @lcomm ? shift @lcomm : '';
3297         write;
3298     }
3300     exit 0;
3303 format USAGE_FORMAT =
3304   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
3305   $one,               $two,               $three,             $four