Nothing
[automake.git] / automake.in
blob6fa7e8db08e30f36a6bb3c7dcb9db300771db280
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) . "\n\n");
967         push (@infos_list, $infobase . '.info', '.info-[0-9]',
968               '.info-[0-9][0-9]');
969         push (@info_deps_list, $infobase . '.info');
970         push (@dvis_list, $infobase . '.dvi');
972         # Generate list of things to clean for this target.  We do
973         # this explicitly because otherwise too many things could be
974         # removed.  In particular the ".log" extension might
975         # reasonably be used in other contexts by the user.
976         foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns',
977                             'ky', 'log', 'pg', 'toc', 'tp', 'vr', 'op')
978         {
979             push (@texi_cleans, $infobase . '.' . $tc_cursor);
980         }
981     }
983     # Some boilerplate.
984     $output_vars .= &file_contents ('texinfos-vars');
985     $output_rules .= &file_contents ('texinfos');
986     push (@phony, 'install-info', 'uninstall-info');
988     # How to clean.
989     $output_rules .= "\nmostlyclean-info:\n";
990     &pretty_print_rule ("\trm -f", "\t  ", @texi_cleans);
991     $output_rules .= ("\nclean-info:\n\ndistclean-info:\n\n"
992                       . "maintainer-clean-info:\n\t"
993                       . 'rm -f $(INFOS)' . "\n");
994     &push_phony_cleaners ('info');
996     push (@suffixes, '.texi', '.info', '.dvi');
998     if (! defined $options{'no-installinfo'})
999     {
1000         push (@uninstall, 'uninstall-info');
1001         push (@installdirs, '$(infodir)');
1002         unshift (@install_data, 'install-info');
1004         # Make sure documentation is made and installed first.  Use
1005         # $(INFO_DEPS), not 'info', because otherwise recursive makes
1006         # get run twice during "make all".
1007         unshift (@all, '$(INFO_DEPS)');
1008     }
1009     push (@clean, 'info');
1010     push (@info, '$(INFO_DEPS)');
1011     push (@dvi, '$(DVIS)');
1013     $output_vars .= ("INFOS = " . join (' ', @infos_list) . "\n"
1014                      . "INFO_DEPS = " . join (' ', @info_deps_list)  . "\n"
1015                      . "DVIS = " . join (' ', @dvis_list) . "\n"
1016                      # This next isn't strictly needed now -- the
1017                      # places that look here could easily be changed
1018                      # to look in info_TEXINFOS.  But this is probably
1019                      # better, in case noinst_TEXINFOS is ever
1020                      # supported.
1021                      . "TEXINFOS = " . $contents{'info_TEXINFOS'} . "\n\n");
1023     # Do some error checking.
1024     &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex');
1027 # Handle any man pages.
1028 sub handle_man_pages
1030     &am_line_error ('MANS', "\`MANS' is an anachronism; use \`man_MANS'")
1031         if &variable_defined ('MANS');
1032     return if ! &variable_defined ('man_MANS');
1034     # We generate the manpage install code by hand to avoid the use of
1035     # basename in the generated Makefile.
1036     local (@mans) = split (' ', $contents{'man_MANS'});
1037     local (%sections, %inames, %secmap, %fullsecmap);
1038     foreach (@mans)
1039     {
1040         # FIXME: statement without effect:
1041         /^(.*)\.([0-9])([a-z]*)$/;
1042         $sections{$2} = 1;
1043         $inames{$1} = $_;
1044         $secmap{$1} = $2;
1045         $fullsecmap{$1} = $2 . $3;
1046     }
1048     # We don't really need this, but we use it in case we ever want to
1049     # support noinst_MANS.
1050     $output_vars .= "MANS = " . $contents{'man_MANS'} . "\n";
1052     # Generate list of install dirs.
1053     $output_rules .= "install-man: \$(MANS)\n";
1054     foreach (keys %sections)
1055     {
1056         push (@installdirs, '$(mandir)/man' . $_)
1057             unless defined $options{'no-installman'};
1058         $output_rules .= ("\t" . '$(mkinstalldirs) $(mandir)/man'
1059                           . $_ . "\n");
1060     }
1061     push (@phony, 'install-man');
1063     # Generate install target.
1064     local ($key);
1065     foreach $key (keys %inames)
1066     {
1067         $_ = $install_man_format;
1068         s/\@SECTION\@/$secmap{$key}/g;
1069         s/\@MAN\@/$inames{$key}/g;
1070         s/\@FULLSECT\@/$fullsecmap{$key}/g;
1071         s/\@MANBASE\@/$key/g;
1072         $output_rules .= $_;
1073     }
1074     $output_rules .= "\n";
1076     $output_rules .= "uninstall-man:\n";
1077     foreach $key (keys %inames)
1078     {
1079         $_ = $uninstall_man_format;
1080         s/\@SECTION\@/$secmap{$key}/g;
1081         s/\@MAN\@/$inames{$key}/g;
1082         s/\@FULLSECT\@/$fullsecmap{$key}/g;
1083         s/\@MANBASE\@/$key/g;
1084         $output_rules .= $_;
1085     }
1086     $output_rules .= "\n";
1087     push (@phony, 'uninstall-man');
1089     $output_vars .= &file_contents ('mans-vars');
1091     if (! defined $options{'no-installman'})
1092     {
1093         push (@install_data, 'install-man');
1094         push (@uninstall, 'uninstall-man');
1095         push (@all, '$(MANS)');
1096     }
1099 # Handle DATA variables.
1100 sub handle_data
1102     &am_install_var ('data', 'DATA', 'data', 'sysconf',
1103                      'sharedstate', 'localstate', 'pkgdata',
1104                      'noinst', 'check');
1107 # Handle TAGS.
1108 sub handle_tags
1110     local ($tagging) = 0;
1112     push (@phony, 'tags');
1113     if (&variable_defined ('SUBDIRS'))
1114     {
1115         $output_rules .= &file_contents ('tags');
1116         push (@phony, 'tags-recursive');
1117         $tagging = 1;
1118     }
1119     elsif ($dir_holds_sources || &variable_defined ('ETAGS_ARGS'))
1120     {
1121         $output_rules .= &file_contents ('tags-subd');
1122         $tagging = 1;
1123     }
1125     if ($tagging)
1126     {
1127         $output_rules .= &file_contents ('tags-clean');
1128         push (@clean, 'tags');
1129         &push_phony_cleaners ('tags');
1130     }
1131     else
1132     {
1133         # Every Makefile must define some sort of TAGS rule.
1134         # Otherwise, it would be possible for a top-level "make TAGS"
1135         # to fail because some subdirectory failed.
1136         $output_rules .= "tags: TAGS\nTAGS:\n\n";
1137     }
1140 # Worker for handle_dist.
1141 sub handle_dist_worker
1143     $output_rules .= 'distdir: $(DEP_DISTFILES)' . "\n";
1145     # Initialization; only at top level.
1146     if ($relative_dir eq '.')
1147     {
1148         if ($strictness >= $GNITS)
1149         {
1150             # For Gnits users, this is pretty handy.  Look at 15 lines
1151             # in case some explanatory text is desirable.
1152             $output_rules .= '  @if sed 15q $(srcdir)/NEWS | grep -e "$(VERSION)" > /dev/null; then :; else \\
1153           echo "NEWS not updated; not releasing" 1>&2; \\
1154           exit 1;                               \\
1155         fi
1157         }
1160         $output_rules .=
1161             # Create dist directory.
1162             '   rm -rf $(distdir)
1163         mkdir $(distdir)
1164         chmod 777 $(distdir)
1167         # Only run automake in `dist' target if --include-deps not
1168         # specified.  That way the recipient of a distribution can run
1169         # "make dist" and not need Automake.
1170         if ($cmdline_use_dependencies)
1171         {
1172             $output_rules .=
1173                 (
1174                  # We need an absolute path for --output-dir.  Thus the
1175                  # weirdness.
1176                  '      distdir=`cd $(distdir) && pwd` \\
1177           && cd $(srcdir) \\
1178           && automake --include-deps --output-dir=$$distdir --strictness='
1179                  # Set strictness of output.
1180                  . $strictness_name . "\n"
1181                  );
1182         }
1183     }
1185     # In loop, test for file existence because sometimes a file gets
1186     # included in DISTFILES twice.  For example this happens when a
1187     # single source file is used in building more than one program.
1188     # Also, there are situations in which "ln" can fail.  For instance
1189     # a file to distribute could actually be a cross-filesystem
1190     # symlink -- this can easily happen if "gettextize" was run on the
1191     # distribution.  Note that DISTFILES can contain a wildcard (for
1192     # info files, sigh), so we must use the echo trick.
1193     $output_rules .= '  @for file in `cd $(srcdir) && echo $(DISTFILES)`; do \\
1194           test -f $(distdir)/$$file \\
1195           || ln $(srcdir)/$$file $(distdir)/$$file 2> /dev/null \\
1196           || cp -p $(srcdir)/$$file $(distdir)/$$file; \\
1197         done
1200     # If we have SUBDIRS, create all dist subdirectories and do
1201     # recursive build.
1202     if (&variable_defined ('SUBDIRS'))
1203     {
1204         # Test for directory existence here because previous automake
1205         # invocation might have created some directories.  Note that
1206         # we explicitly set distdir for the subdir make; that lets us
1207         # mix-n-match many automake-using packages into one large
1208         # package, and have "dist" at the top level do the right
1209         # thing.
1210         $output_rules .= '      for subdir in $(SUBDIRS); do            \\
1211           test -d $(distdir)/$$subdir           \\
1212           || mkdir $(distdir)/$$subdir          \\
1213           || exit 1;                            \\
1214           chmod 777 $(distdir)/$$subdir;        \\
1215           (cd $$subdir && $(MAKE) distdir=../$(distdir)/$$subdir distdir) \\
1216             || exit 1; \\
1217         done
1219     }
1221     # If the target `dist-hook' exists, run it now.  This allows
1222     # users to do random weird things to the distribution before it is
1223     # packaged up.
1224     if (defined $contents{'dist-hook'})
1225     {
1226         $output_rules .= "\t\$(MAKE) dist-hook\n";
1227     }
1229     push (@phony, 'distdir');
1232 # Handle 'dist' target.
1233 sub handle_dist
1235     # Set up maint_charset.
1236     $local_maint_charset = $contents{'MAINT_CHARSET'}
1237         if &variable_defined ('MAINT_CHARSET');
1238     $maint_charset = $local_maint_charset
1239         if $relative_dir eq '.';
1241     if (&variable_defined ('DIST_CHARSET'))
1242     {
1243         &am_line_error ('DIST_CHARSET',
1244                         "DIST_CHARSET defined but no MAINT_CHARSET defined")
1245             if ! $local_maint_charset;
1246         if ($relative_dir eq '.')
1247         {
1248             $dist_charset = $contents{'DIST_CHARSET'}
1249         }
1250         else
1251         {
1252             &am_line_error ('DIST_CHARSET',
1253                             "DIST_CHARSET can only be defined at top level");
1254         }
1255     }
1257     # Look for common files that should be included in distribution.
1258     local ($cfile);
1259     foreach $cfile (@common_files)
1260     {
1261         if (-f ($relative_dir . "/" . $cfile))
1262         {
1263             &push_dist_common ($cfile);
1264         }
1265     }
1267     # Keys of %dist_common are names of files to distributed.  We put
1268     # README first because it then becomes easier to make a
1269     # Usenet-compliant shar file (in these, README must be first).
1270     # FIXME do more ordering of files here.
1271     local (@coms);
1272     if (defined $dist_common{'README'})
1273     {
1274         push (@coms, 'README');
1275         undef $dist_common{'README'};
1276     }
1277     push (@coms, sort keys %dist_common);
1279     &pretty_print ("DIST_COMMON =", "", @coms);
1280     $output_vars .= "\n";
1282     # Some boilerplate.
1283     $output_vars .= &file_contents ('dist-vars');
1285     # Put these things in rules section so it is easier for whoever
1286     # reads Makefile.in.
1287     if ($relative_dir eq '.')
1288     {
1289         $output_rules .= "\n" . 'distdir = $(PACKAGE)-$(VERSION)' . "\n";
1290     }
1291     else
1292     {
1293         $output_rules .= ("\nsubdir = " . $relative_dir . "\n"
1294                           . 'distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)'
1295                           . "\n");
1296     }
1298     # Generate 'dist' target, and maybe dist-shar / dist-zip.
1299     if ($relative_dir eq '.')
1300     {
1301         # Rule to check whether a distribution is viable.
1302         $output_rules .= ('# This target untars the dist file and tries a VPATH configuration.  Then
1303 # it guarantees that the distribution is self-contained by making another
1304 # tarfile.
1305 distcheck: dist
1306         rm -rf $(distdir)
1307         $(TAR) zxf $(distdir).tar.gz
1308         mkdir $(distdir)/=build
1309         mkdir $(distdir)/=inst
1310         dc_install_base=`cd $(distdir)/=inst && pwd`; \\
1311         cd $(distdir)/=build \\
1312           && ../configure '
1314                           . ($seen_gettext ? '--with-included-gettext ' : '')
1315                           . '--srcdir=.. --prefix=$$dc_install_base \\
1316           && $(MAKE) \\
1317           && $(MAKE) dvi \\
1318           && $(MAKE) check \\
1319           && $(MAKE) install \\
1320           && $(MAKE) installcheck \\
1321           && $(MAKE) dist
1322         rm -rf $(distdir)
1323         @echo "========================"; \\
1324         echo "$(distdir).tar.gz is ready for distribution"; \\
1325         echo "========================"
1328         $output_rules .= 'dist: distdir' . "\n\t";
1329         # Ignore return result from chmod, because it might give an
1330         # error if we chmod a symlink.
1331         $output_rules .= '-chmod -R a+r $(distdir)' . "\n\t";
1332         $output_rules .= '$(TAR) chozf $(distdir).tar.gz $(distdir)';
1333         $output_rules .= "\n\t" . 'rm -rf $(distdir)' . "\n";
1335         if (defined $options{'dist-shar'})
1336         {
1337             $output_rules .= 'dist-shar: distdir' . "\n\t";
1338             # Ignore return result from chmod, because it might give
1339             # an error if we chmod a symlink.
1340             $output_rules .= '-chmod -R a+r $(distdir)' . "\n\t";
1341             $output_rules .= 'shar $(distdir) | gzip > $(distdir).shar.gz';
1342             $output_rules .= "\n\t" . 'rm -rf $(distdir)' . "\n";
1343         }
1345         if (defined $options{'dist-zip'})
1346         {
1347             $output_rules .= 'dist-zip: distdir' . "\n\t";
1348             $output_rules .= 'chmod -R a+r $(distdir)' . "\n\t";
1349             $output_rules .= 'zip -rq $(distdir).zip $(distdir)';
1350             $output_rules .= "\n\t" . 'rm -rf $(distdir)' . "\n";
1351         }
1352     }
1354     # Generate distdir target.
1355     &handle_dist_worker;
1358 # Handle auto-dependency code.
1359 sub handle_dependencies
1361     if ($use_dependencies)
1362     {
1363         # Include GNU-make-specific auto-dep code.
1364         if ($dir_holds_sources)
1365         {
1366             &pretty_print ('DEP_FILES =', "", sort keys %dep_files);
1367             $output_rules .= &file_contents ('depend');
1368         }
1369     }
1370     else
1371     {
1372         # Include any auto-generated deps that are present.
1373         if (-d ($relative_dir . "/.deps") && -f ($relative_dir . "/.deps/.P"))
1374         {
1375             local ($depfile);
1376             local ($gpat) = $relative_dir . "/.deps/*.P";
1378             foreach $depfile (<${gpat}>)
1379             {
1380                 if (! open (DEP_FILE, $depfile))
1381                 {
1382                     &am_error ("couldn't open \`$depfile': $!");
1383                     next;
1384                 }
1385                 print "automake: reading $depfile\n" if $verbose;
1387                 # Slurp entire file.
1388                 $output_rules .= join ('', <DEP_FILE>);
1390                 close (DEP_FILE);
1391             }
1393             $output_rules .= "\n";
1394         }
1395     }
1398 # Handle subdirectories.
1399 sub handle_subdirs
1401     if (! &variable_defined ('SUBDIRS'))
1402     {
1403         &am_conf_error
1404             ("ud_GNU_GETTEXT in configure.in but SUBDIRS not defined")
1405                 if $seen_gettext && $relative_dir eq '.';
1406         return;
1407     }
1409     &require_file_with_conf_line ($ac_gettext_line, $FOREIGN, 'ABOUT-NLS')
1410         if $seen_gettext;
1412     return if ! &variable_defined ('SUBDIRS');
1414     # Make sure each directory mentioned in SUBDIRS actually exists.
1415     local ($dir);
1416     foreach $dir (split (' ', $contents{'SUBDIRS'}))
1417     {
1418         # Skip directories substituted by configure.
1419         next if $dir =~ /^\@.*\@$/;
1420         &am_line_error ('SUBDIRS',
1421                         "required directory $relative_dir/$dir does not exist")
1422             if ! -d $relative_dir . '/' . $dir;
1423     }
1425     $output_rules .= &file_contents ('subdirs');
1427     # Push a bunch of phony targets.
1428     local ($phonies);
1429     foreach $phonies ('-data', '-exec', 'dirs')
1430     {
1431         push (@phony, 'install' . $phonies . '-recursive');
1432         push (@phony, 'uninstall' . $phonies . '-recursive');
1433     }
1434     foreach $phonies ('all', 'check', 'installcheck', 'info', 'dvi')
1435     {
1436         push (@phony, $phonies . '-recursive');
1437     }
1438     &push_phony_cleaners ('recursive');
1440     push (@check, "check-recursive");
1441     push (@installcheck, "installcheck-recursive");
1442     push (@info, "info-recursive");
1443     push (@dvi, "dvi-recursive");
1445     $recursive_install = 1;
1448 # Handle remaking and configure stuff.
1449 sub handle_configure
1451     # If SUBDIRS defined, require AC_PROG_MAKE_SET.
1452     &am_line_error ('SUBDIRS', "AC_PROG_MAKE_SET must be used in configure.in")
1453         if &variable_defined ('SUBDIRS') && ! $seen_make_set;
1455     local ($top_reldir);
1456     if ($relative_dir ne '.')
1457     {
1458         # In subdirectory.
1459         $output_rules .= &file_contents ('remake-subd');
1460         $top_reldir = '../';
1461     }
1462     else
1463     {
1464         if (-f 'aclocal.m4')
1465         {
1466             $output_vars .= "ACLOCAL = aclocal.m4\n";
1467             &push_dist_common ('aclocal.m4');
1468         }
1469         $output_rules .= &file_contents_with_transform ('s/\@STRICTNESS\@/'
1470                                                         . $strictness_name
1471                                                         . '/g',
1472                                                         'remake');
1474         &am_error
1475             ("\`install.sh' is an anachronism; use \`install-sh' instead")
1476                 if -f $relative_dir . '/install.sh';
1478         # If we have a configure header, require it.
1479         if ($config_header)
1480         {
1481             # FIXME this restriction should be lifted.
1482             # FIXME first see if it is even needed as-is.
1483             &am_conf_line_error ($config_header_line,
1484                                  "argument to AC_CONFIG_HEADER contains \`/'\n")
1485                 if ($config_header =~ /\//);
1487             &require_file_with_conf_line ($config_header_line,
1488                                           $FOREIGN, $config_header);
1490             # Header defined and in this directory.
1491             if (-f 'acconfig.h')
1492             {
1493                 $output_vars .= "ACCONFIG = acconfig.h\n";
1494                 &push_dist_common ('acconfig.h');
1495             }
1496             if (-f $config_name . '.top')
1497             {
1498                 $output_vars .= "CONFIG_TOP = ${config_name}.top\n";
1499                 &push_dist_common ($config_name . '.top');
1500             }
1501             if (-f $config_name . '.bot')
1502             {
1503                 $output_vars .= "CONFIG_BOT = ${config_name}.bot\n";
1504                 &push_dist_common ($config_name . '.bot');
1505             }
1507             &require_file_with_conf_line ($config_header_line, $FOREIGN,
1508                                           'stamp-h.in');
1510             $output_rules .= &file_contents ('remake-hdr');
1511             $output_vars .= "CONFIG_HEADER_IN = ${config_header}\n";
1512         }
1514         $top_reldir = '';
1515     }
1517     # Set location of mkinstalldirs.
1518     if ($config_aux_dir ne '.' && $config_aux_dir ne '')
1519     {
1520         $output_vars .= 'mkinstalldirs = ' . $config_aux_dir;
1521     }
1522     else
1523     {
1524         $output_vars .= 'mkinstalldirs = $(top_srcdir)';
1525     }
1526     $output_vars .= '/mkinstalldirs' . "\n";
1528     &am_line_error ('CONFIG_HEADER',
1529                     "\`CONFIG_HEADER' is an anachronism; now determined from \`configure.in'")
1530         if &variable_defined ('CONFIG_HEADER');
1532     # Generate CONFIG_HEADER define, and define interally.
1533     $output_vars .= "CONFIG_HEADER = ${top_builddir}/${config_name}\n"
1534         if $config_name;
1535     $contents{'CONFIG_HEADER'} = "${top_builddir}/${config_name}"
1536         if $config_name;
1538     # Now look for other files in this directory which must be remade
1539     # by config.status, and generate rules for them.
1540     local ($file, $local, $input);
1541     foreach $file (@other_input_files)
1542     {
1543         # Skip files not in this directory, any Makefile, and the
1544         # config header.  These last two must be handled specially.
1545         next unless &dirname ($file) eq $relative_dir;
1546         next if $file eq $top_builddir . '/' . $config_name;
1547         ($local = $file) =~ s/^.*\///;
1548         next if $local eq 'Makefile';
1550         if ($local =~ /^(.*):(.*)$/)
1551         {
1552             # This is the ":" syntax of AC_OUTPUT.
1553             $input = $2;
1554             $local = $1;
1555         }
1556         else
1557         {
1558             # Normal usage.
1559             $input = $local . '.in';
1560         }
1561         # FIXME when using autoconf ":" syntax, should we set CONFIG_FILES
1562         # to $local:$input?
1563         $output_rules .= ($local . ': '
1564                           . '$(top_builddir)/config.status ' . $input . "\n"
1565                           . "\t"
1566                           . 'cd $(top_builddir) && CONFIG_FILES='
1567                           . ($relative_dir eq '.' ? '' : '$(subdir)/')
1568                           . '$@ CONFIG_HEADERS= ./config.status'
1569                           . "\n");
1571         &require_file_with_conf_line ($ac_output_line, $FOREIGN,
1572                                       $local . '.in');
1573     }
1576 # Handle C headers.
1577 sub handle_headers
1579     &am_install_var ('header', 'HEADERS', 'include',
1580                      'oldinclude', 'pkginclude',
1581                      'noinst', 'check');
1584 sub handle_gettext
1586     return if ! $seen_gettext || $relative_dir ne '.';
1588     if (&variable_defined ('SUBDIRS'))
1589     {
1590         &am_line_error
1591             ('SUBDIRS',
1592              "ud_GNU_GETTEXT in configure.in but \`po' not in SUBDIRS")
1593                 if $contents{'SUBDIRS'} !~ /\bpo\b/;
1594         &am_line_error
1595             ('SUBDIRS',
1596              "ud_GNU_GETTEXT in configure.in but \`intl' not in SUBDIRS")
1597                 if $contents{'SUBDIRS'} !~ /\bintl\b/;
1598     }
1600     # Ensure that each language in ALL_LINGUAS has a .po file, and
1601     # each po file is mentioned in ALL_LINGUAS.
1602     if ($seen_linguas)
1603     {
1604         local (%linguas) = ();
1605         grep ($linguas{$_} = 1, split (' ', $all_linguas));
1607         foreach (<po/*.po>)
1608         {
1609             s/^po\///;
1610             s/\.po$//;
1612             &am_line_error ($all_linguas_line,
1613                             ("po/$_.po exists but \`$_' not in \`ALL_LINGUAS'"))
1614                 if ! $linguas{$_};
1615         }
1617         foreach (keys %linguas)
1618         {
1619             &am_line_error ($all_linguas_line,
1620                             "$_ in \`ALL_LINGUAS' but po/$_.po does not exist")
1621                 if ! -f "po/$_.po";
1622         }
1623     }
1624     else
1625     {
1626         &am_error ("ud_GNU_GETTEXT in configure.in but \`ALL_LINGUAS' not defined");
1627     }
1630 # Handle footer elements.
1631 sub handle_footer
1633     if ($contents{'SOURCES'})
1634     {
1635         &pretty_print ('SOURCES =', "",
1636                        split (' ', $contents{'SOURCES'}));
1637     }
1638     if ($contents{'OBJECTS'})
1639     {
1640         &pretty_print ('OBJECTS =', "",
1641                        split (' ', $contents{'OBJECTS'}));
1642     }
1643     if ($contents{'SOURCES'} || $contents{'OBJECTS'})
1644     {
1645         $output_vars .= "\n";
1646     }
1648     if (defined $contents{'SUFFIXES'})
1649     {
1650         # Push actual suffixes, and not $(SUFFIXES).  Some versions of
1651         # make do not like variable substitutions on the .SUFFIXES
1652         # line.
1653         push (@suffixes, split (' ', $contents{'SUFFIXES'}));
1654     }
1656     $output_trailer .= ".SUFFIXES:\n";
1657     if (@suffixes)
1658     {
1659         $output_trailer .= ".SUFFIXES: " . join (' ', @suffixes) . "\n";
1660     }
1661     $output_trailer .= &file_contents ('footer');
1664 # Deal with installdirs target.
1665 sub handle_installdirs
1667     # GNU Makefile standards recommend this.
1668     $output_rules .= ("installdirs:"
1669                       . ($recursive_install
1670                          ? " installdirs-recursive\n"
1671                          : "\n"));
1672     push (@phony, 'installdirs');
1673     if (@installdirs)
1674     {
1675         &pretty_print_rule ("\t" . '$(mkinstalldirs) ', "\t\t",
1676                             @installdirs);
1677     }
1678     $output_rules .= "\n";
1681 # There are several targets which need to be merged.  This is because
1682 # their complete definition is compiled from many parts.  Note that we
1683 # avoid double colon rules, otherwise we'd use them instead.
1684 sub handle_merge_targets
1686     push (@all, 'Makefile');
1687     push (@all, $config_name)
1688         if $config_name && &dirname ($config_name) eq $relative_dir;
1690     &do_one_merge_target ('info', @info);
1691     &do_one_merge_target ('dvi', @dvi);
1693     if (! &variable_defined ('SUBDIRS') || $relative_dir ne '.')
1694     {
1695         # 'check' must depend on 'all', but not at top level.
1696         # Ditto install.
1697         unshift (@check, 'all');
1698         unshift (@install, 'all');
1699     }
1700     &do_one_merge_target ('check', @check);
1701     &do_one_merge_target ('installcheck', @installcheck);
1703     # Handle the various install targets specially.  We do this so
1704     # that (eg) "make install-exec" will run "install-exec-recursive"
1705     # if required, but "make install" won't run it twice.  Step one is
1706     # to see if the user specified local versions of any of the
1707     # targets we handle.  "all" is treated as one of these since
1708     # "install" can run it.
1709     push (@install_exec, 'install-exec-local')
1710         if defined $contents{'install-exec-local'};
1711     push (@install_data, 'install-data-local')
1712         if defined $contents{'install-data-local'};
1713     push (@uninstall, 'uninstall-local')
1714         if defined $contents{'uninstall-local'};
1715     push (@all, 'all-local')
1716         if defined $contents{'all-local'};
1718     if (defined $contents{'install-local'})
1719     {
1720         &am_line_error ('install-local',
1721                         "use \`install-data' or \`install-exec', not \`install'");
1722     }
1724     # Step two: if we are doing recursive makes, write out the
1725     # appropriate rules.
1726     local (@install);
1727     if ($recursive_install)
1728     {
1729         push (@install, 'install-recursive');
1731         if (@all)
1732         {
1733             local (@hackall) = ();
1734             if ($config_name && &dirname ($config_name) eq $relative_dir)
1735             {
1737                 # This is kind of a hack, but I couldn't see a better
1738                 # way to handle it.  In this particular case, we need
1739                 # to make sure config.h is built before we recurse.
1740                 # We can't do this by changing the order of
1741                 # dependencies to the "all" because that breaks when
1742                 # using parallel makes.  Instead we handle things
1743                 # explicitly.
1744                 $output_rules .= ('all-recursive-hack: $(CONFIG_HEADER)'
1745                                   . "\n\t" . '$(MAKE) all-recursive'
1746                                   . "\n\n");
1747                 push (@hackall, 'all-recursive-hack');
1748                 push (@phony, 'all-recursive-hack');
1749             }
1750             else
1751             {
1752                 push (@hackall, 'all-recursive');
1753             }
1755             $output_rules .= ('all-am: '
1756                               . join (' ', @all)
1757                               . "\n\n");
1758             @all = @hackall;
1759             push (@all, 'all-am');
1760             push (@phony, 'all-am');
1761         }
1762         else
1763         {
1764             @all = ('all-recursive');
1765         }
1766         if (@install_exec)
1767         {
1768             $output_rules .= ('install-exec-am: '
1769                               . join (' ', @install_exec)
1770                               . "\n\n");
1771             @install_exec = ('install-exec-recursive', 'install-exec-am');
1772             push (@install, 'install-exec-am');
1773             push (@phony, 'install-exec-am');
1774         }
1775         else
1776         {
1777             @install_exec = ('install-exec-recursive');
1778         }
1779         if (@install_data)
1780         {
1781             $output_rules .= ('install-data-am: '
1782                               . join (' ', @install_data)
1783                               . "\n\n");
1784             @install_data = ('install-data-recursive', 'install-data-am');
1785             push (@install, 'install-data-am');
1786             push (@phony, 'install-data-am');
1787         }
1788         else
1789         {
1790             @install_data = ('install-data-recursive');
1791         }
1792         if (@uninstall)
1793         {
1794             $output_rules .= ('uninstall-am: '
1795                               . join (' ', @uninstall)
1796                               . "\n\n");
1797             @uninstall = ('uninstall-recursive', 'uninstall-am');
1798             push (@phony, 'uninstall-am');
1799         }
1800         else
1801         {
1802             @uninstall = ('uninstall-recursive');
1803         }
1804     }
1806     # Step three: print definitions users can use.  Code below knows
1807     # that install-exec is done before install-data, beware.
1808     $output_rules .= ("install-exec: "
1809                       . join (' ', @install_exec)
1810                       . "\n");
1811     if (defined $contents{'install-exec-hook'})
1812     {
1813         $output_rules .= "\t" . '$(MAKE) install-exec-hook' . "\n";
1814     }
1815     $output_rules .= "\n";
1816     push (@install, 'install-exec') if !$recursive_install;
1817     push (@phony, 'install-exec');
1819     $output_rules .= ("install-data: "
1820                       . join (' ', @install_data)
1821                       . "\n");
1822     if (defined $contents{'install-data-hook'})
1823     {
1824         $output_rules .= "\t" . '$(MAKE) install-data-hook' . "\n";
1825     }
1826     $output_rules .= "\n";
1827     push (@install, 'install-data') if !$recursive_install;
1828     push (@phony, 'install-data');
1830     # If no dependencies for 'install', add 'all'.  Why?  That way
1831     # "make install" at top level of distclean'd distribution won't
1832     # fail because stuff in 'lib' fails to build.
1833     if (! @install || ($#install == 1
1834                        && $install[0] eq 'install-exec'
1835                        && $install[1] eq 'install-data'))
1836     {
1837         push (@install, 'all');
1838     }
1839     $output_rules .= ('install: '
1840                       . join (' ', @install)
1841                       # Use "@:" as empty command so nothing prints.
1842                       . "\n\t\@:"
1843                       . "\n\n"
1844                       . 'uninstall: '
1845                       . join (' ', @uninstall)
1846                       . "\n\n");
1847     push (@phony, 'install', 'uninstall');
1849     $output_rules .= ('all: '
1850                       . join (' ', @all)
1851                       . "\n\n");
1852     push (@phony, 'all');
1854     # Generate the new 'install-strip' target.
1855     $output_rules .= ("install-strip:\n\t"
1856                       . '$(MAKE) INSTALL_PROGRAM=\'$(INSTALL_PROGRAM) -s\' install'
1857                       . "\n");
1860 # Helper for handle_merge_targets.
1861 sub do_one_merge_target
1863     local ($name, @values) = @_;
1865     if (defined $contents{$name . '-local'})
1866     {
1867         # User defined local form of target.  So include it.
1868         push (@values, $name . '-local');
1869         push (@phony, $name . '-local');
1870     }
1872     $output_rules .= $name . ":";
1873     if (@values)
1874     {
1875         $output_rules .= ' ' . join (' ', @values);
1876     }
1877     $output_rules .= "\n\n";
1878     push (@phony, $name);
1881 # Handle all 'clean' targets.
1882 sub handle_clean
1884     push (@clean, 'generic');
1885     $output_rules .= &file_contents ('clean');
1886     &push_phony_cleaners ('generic');
1888     local ($target) = $recursive_install ? 'clean-am' : 'clean';
1889     &do_one_clean_target ($target, 'mostly', '', @clean);
1890     &do_one_clean_target ($target, '', 'mostly', @clean);
1891     &do_one_clean_target ($target, 'dist', '', @clean);
1892     &do_one_clean_target ($target, 'maintainer-', 'dist', @clean);
1894     push (@phony, 'clean', 'mostlyclean', 'distclean', 'maintainer-clean');
1896     local (@deps);
1897     if ($recursive_install)
1898     {
1899         @deps = ('am', 'recursive');
1900         &do_one_clean_target ('', 'mostly', '', @deps);
1901         &do_one_clean_target ('', '', '', @deps);
1902         &do_one_clean_target ('', 'dist', '', @deps);
1903         &do_one_clean_target ('', 'maintainer-', '', @deps);
1904     }
1907 # Helper for handle_clean.
1908 sub do_one_clean_target
1910     local ($target, $name, $last_name, @deps) = @_;
1912     # Special case: if target not passed, then don't generate
1913     # dependency on next "lower" clean target (eg no
1914     # clean<-mostlyclean derivation).  In this case the target is
1915     # implicitly known to be 'clean'.
1916     local ($flag) = $target;
1917     $target = 'clean' if ! $flag;
1919     grep (($_ = $name . 'clean-' . $_) && 0, @deps);
1920     if ($flag)
1921     {
1922         if ($last_name || $name ne 'mostly')
1923         {
1924             push (@deps, $last_name . $target . " ");
1925         }
1926     }
1927     # FIXME not sure if I like the tabs here.
1928     &pretty_print_rule ($name . $target . ": ", "\t\t", @deps);
1930     # FIXME shouldn't we really print these messages before running
1931     # the dependencies?
1932     if ($name . $target eq 'maintainer-clean')
1933     {
1934         # Print a special warning.
1935         $output_rules .=
1936             ("\t\@echo \"This command is intended for maintainers to use;\"\n"
1937              . "\t\@echo \"it deletes files that may require special "
1938              . "tools to rebuild.\"\n");
1940         $output_rules .= "\trm -f config.status\n"
1941             if $relative_dir eq '.';
1942     }
1943     elsif ($name . $target eq 'distclean')
1944     {
1945         $output_rules .= "\trm -f config.status\n";
1946     }
1947     $output_rules .= "\n";
1950 # Handle .PHONY target.
1951 sub handle_phony
1953     &pretty_print_rule ('.PHONY:', "", @phony);
1954     $output_rules .= "\n";
1957 # Handle TESTS variable and other checks.
1958 sub handle_tests
1960     if (defined $options{'dejagnu'})
1961     {
1962         push (@check, 'check-DEJAGNU');
1963         push (@phony, 'check-DEJAGNU');
1964         $output_rules .= &file_contents ('dejagnu') . "\n";
1965         # Note that in the rule we don't directly generate site.exp to
1966         # avoid the possibility of a corrupted site.exp if make is
1967         # interrupted.  Jim Meyering has some useful text on this
1968         # topic.
1969         $output_rules .= ("site.exp: Makefile\n"
1970                           . "\t\@echo 'Making a new site.exp file...'\n"
1971                           . "\t-\@rm -f site.bak\n"
1972                           . "\t\@echo '## these variables are automatically generated by make ##' > \$\@-t\n"
1973                           . "\t\@echo '# Do not edit here.  If you wish to override these values' >> \$\@-t\n"
1974                           . "\t\@echo '# edit the last section' >> \$\@-t\n"
1975                           . "\t\@echo 'set tool \$(DEJATOOL)' >> \$\@-t\n"
1976                           . "\t\@echo 'set srcdir \$(srcdir)' >> \$\@-t\n"
1977                           . "\t\@echo 'set objdir' \`pwd\` >> \$\@-t\n");
1979         # Extra stuff for AC_CANONICAL_*
1980         local (@whatlist) = ();
1981         if ($seen_canonical)
1982         {
1983             push (@whatlist, 'host')
1984         }
1986         # Extra stuff only for AC_CANONICAL_SYSTEM.
1987         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
1988         {
1989             push (@whatlist, 'target', 'build');
1990         }
1992         local ($c1, $c2);
1993         foreach $c1 (@whatlist)
1994         {
1995             foreach $c2 ('alias', 'triplet')
1996             {
1997                 $output_rules .= "\t\@echo 'set ${c1}_${c2} \$(${c1}_${c2})' >> \$\@-t\n";
1998             }
1999         }
2001         $output_rules .= ("\t\@echo '## All variables above are generated by configure. Do Not Edit ##' >> \$\@-t\n"
2002                           . "\t-\@sed '1,/^## All variables above are.*##/ d' site.bak >> \$\@-t\n"
2003                           . "\t-\@mv site.exp site.bak\n"
2004                           . "\t\@mv \$\@-t site.exp\n");
2005     }
2006     else
2007     {
2008         local ($c);
2009         foreach $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
2010         {
2011             if (&variable_defined ($c))
2012             {
2013                 &am_line_error ($c, "\`$c' defined but \`dejagnu' not in \`AUTOMAKE_OPTIONS'");
2014             }
2015         }
2016     }
2018     if (&variable_defined ('TESTS'))
2019     {
2020         push (@check, 'check-TESTS');
2021         push (@phony, 'check-TESTS');
2022         # FIXME use $(SHELL) here?  That is what Ulrich suggests.
2023         # Maybe a new macro, $(TEST_SHELL), a la $(CONFIG_SHELL)?  For
2024         # now we just execute the file directly; this allows test
2025         # files which are compiled -- a possibly useful feature.
2026         $output_rules .= 'check-TESTS: $(TESTS)
2027         @failed=0; all=0; \\
2028         srcdir=$(srcdir); export srcdir; \\
2029         for tst in $(TESTS); do \\
2030           all=`expr $$all + 1`; \\
2031           if test -f $$tst; then dir=.; \\
2032           else dir="$(srcdir)"; fi; \\
2033           if $(TESTS_ENVIRONMENT) $$dir/$$tst; then \\
2034             echo "PASS: $$tst"; \\
2035           else \\
2036             failed=`expr $$failed + 1`; \\
2037             echo "FAIL: $$tst"; \\
2038           fi; \\
2039         done; \\
2040         if test "$$failed" -eq 0; then \\
2041           echo "========================"; \\
2042           echo "All $$all tests passed"; \\
2043           echo "========================"; \\
2044         else \\
2045           echo "$$failed of $$all tests failed"; \\
2046         fi
2048     }
2051 # Handle Emacs Lisp.
2052 sub handle_emacs_lisp
2054     local (@elfiles) = &am_install_var ('lisp', 'LISP', 'lisp', 'noinst');
2056     if (@elfiles)
2057     {
2058         # Found some lisp.
2059         $output_vars .= "lispdir = \@lispdir\@\n";
2060         $output_rules .= (".el.elc:\n"
2061                           . "\t\@echo 'WARNING: Warnings can be ignored. :-)'\n"
2062                           . "\t\$(SHELL) \$(srcdir)/elisp-comp \$<\n");
2063         push (@suffixes, '.el', '.elc');
2065         # Generate .elc files.
2066         grep ($_ .= 'c', @elfiles);
2067         &pretty_print ('ELCFILES =', '', @elfiles);
2069         local ($varname);
2070         if (&variable_defined ('lisp_LISP'))
2071         {
2072             $varname = 'lisp_LISP';
2073             &am_error ("\`lisp_LISP' defined but \`ud_PATH_LISPDIR' not in \`configure.in'")
2074                 if ! $seen_lispdir;
2075         }
2076         else
2077         {
2078             $varname = 'noinst_LISP';
2079         }
2080         &require_file_with_line ($varname, $FOREIGN, 'elisp-comp');
2082     }
2085 ################################################################
2087 # Scan configure.in for interesting things.
2088 # FIXME ensure VERSION, PACKAGE are set.
2089 sub scan_configure
2091     open (CONFIGURE, 'configure.in')
2092         || die "automake: couldn't open \`configure.in': $!\n";
2093     print "automake: reading configure.in\n" if $verbose;
2095     # Reinitialize libsources here.  This isn't really necessary,
2096     # since we currently assume there is only one configure.in.  But
2097     # that won't always be the case.
2098     %libsources = ();
2100     local ($in_ac_output, @make_list) = 0;
2101     local ($libobj_iter);
2102     while (<CONFIGURE>)
2103     {
2104         # Remove comments from current line.
2105         s/\bdnl\b.*$//;
2106         s/\#.*$//;
2108         # Populate libobjs array.
2109         if (/AC_FUNC_ALLOCA/)
2110         {
2111             $libsources{'alloca.c'} = 1;
2112         }
2113         elsif (/AC_FUNC_GETLOADAVG/)
2114         {
2115             $libsources{'getloadavg.c'} = 1;
2116         }
2117         elsif (/AC_FUNC_MEMCMP/)
2118         {
2119             $libsources{'memcmp.c'} = 1;
2120         }
2121         elsif (/AC_STRUCT_ST_BLOCKS/)
2122         {
2123             $libsources{'fileblocks.c'} = 1;
2124         }
2125         elsif (/(AC|fp)_FUNC_FNMATCH/)
2126         {
2127             # AC_FUNC_FNMATCH is just wishful thinking at this point.
2128             $libsources{'fnmatch.c'} = 1;
2129         }
2130         elsif (/AC_REPLACE_FUNCS\s*\((.*)\)/)
2131         {
2132             foreach (split (' ', $1))
2133             {
2134                 $libsources{$_ . '.c'} = 1;
2135             }
2136         }
2137         elsif (/AC_REPLACE_GNU_GETOPT/)
2138         {
2139             $libsources{'getopt.c'} = 1;
2140             $libsources{'getopt1.c'} = 1;
2141         }
2142         elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
2143                || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
2144         {
2145             foreach $libobj_iter (split (' ', $1))
2146             {
2147                 if ($libobj_iter =~ /^(.*)\.o$/)
2148                 {
2149                     $libsources{$1 . '.c'} = 1;
2150                 }
2151             }
2152         }
2154         # Process the AC_OUTPUT macro.
2155         if (! $in_ac_output && s/AC_OUTPUT\s*\(\[?//)
2156         {
2157             $in_ac_output = 1;
2158             $ac_output_line = $.;
2159         }
2160         if ($in_ac_output)
2161         {
2162             $in_ac_output = 0 if s/[\]\),].*$//;
2164             # Look at potential Makefile.am's.
2165             foreach (split)
2166             {
2167                 next if $_ eq "\\";
2168                 if (-f $_ . '.am')
2169                 {
2170                     push (@make_list, $_);
2171                 }
2172                 else
2173                 {
2174                     push (@other_input_files, $_);
2175                 }
2176             }
2177         }
2179         if (/AC_CONFIG_AUX_DIR\(([^)]+)\)/)
2180         {
2181             @config_aux_path = $1;
2182         }
2184         # Check for ansi2knr.
2185         $fp_c_prototypes = 1 if /fp_C_PROTOTYPES/;
2187         # Check for NLS support.
2188         if (/ud_GNU_GETTEXT/)
2189         {
2190             $seen_gettext = 1;
2191             $ac_gettext_line = $.;
2192         }
2194         # Look for ALL_LINGUAS.
2195         if (/ALL_LINGUAS="(.*)"$/ || /ALL_LINGUAS=(.*)$/)
2196         {
2197             $seen_linguas = 1;
2198             $all_linguas = $1;
2199             $all_linguas_line = $.;
2200         }
2202         # Handle configuration headers.
2203         if (/AC_CONFIG_HEADER\s*\((.*)\)/)
2204         {
2205             $config_header_line = $.;
2206             $config_name = $1;
2207             if ($config_name =~ /^([^:]+):(.+)$/)
2208             {
2209                 $config_name = $1;
2210                 $config_header = $2;
2211             }
2212             else
2213             {
2214                 $config_header = $config_name . '.in';
2215             }
2216         }
2218         # Handle AC_CANONICAL_*.  Always allow upgrading to
2219         # AC_CANONICAL_SYSTEM, but never downgrading.
2220         $seen_canonical = $AC_CANONICAL_HOST
2221             if ! $seen_canonical && /AC_CANONICAL_HOST/;
2222         $seen_canonical = $AC_CANONICAL_SYSTEM if /AC_CANONICAL_SYSTEM/;
2224         $seen_canonical = 1 if /AC_CHECK_TOOL/;
2225         $seen_path_xtra = 1 if /AC_PATH_XTRA/;
2227         # Sometimes it is desirable to explicitly set YACC.  For
2228         # instance some people don't want to use bison.
2229         $seen_prog_yacc = 1 if (/AC_PROG_YACC/
2230                                 || /AC_SUBST\(YACC\)/
2231                                 || /AC_(PATH|CHECK)_PROGS?\(YACC/);
2233         # Some things required by Automake.
2234         $seen_make_set = 1 if /AC_PROG_MAKE_SET/;
2235         $seen_arg_prog = 1 if /AC_ARG_PROGRAM/;
2236         $seen_ranlib = 1 if /AC_PROG_RANLIB/;
2237         $seen_maint_mode = 1 if /jm_MAINTAINER_MODE/;
2238         $seen_package = 1 if /PACKAGE=/;
2239         $seen_version = 1 if /VERSION=/;
2241         # Weird conditionals here because it is always allowed to
2242         # upgrade to fp_PROG_INSTALL but never to downgrade to
2243         # AC_PROG_INSTALL.
2244         $seen_prog_install = 1 if ! $seen_prog_install && /AC_PROG_INSTALL/;
2245         $seen_prog_install = 2 if /fp_PROG_INSTALL/;
2247         $seen_lispdir = 1 if /ud_PATH_LISPDIR/;
2249         if (/AM_PROG_LIBTOOL/)
2250         {
2251             $seen_libtool = 1;
2252             $seen_ranlib = 2;
2253             $libtool_line = $.;
2254         }
2255     }
2257     # Set input files if not specified by user.
2258     @input_files = @make_list if (! @input_files);
2260     close (CONFIGURE);
2262     &am_conf_error ("\`PACKAGE' not defined in configure.in")
2263         if ! $seen_package;
2264     &am_conf_error ("\`VERSION' not defined in configure.in")
2265         if ! $seen_version;
2267     # Look for some files we need.  Always check for these.  This
2268     # check must be done for every run, even those where we are only
2269     # looking at a subdir Makefile.  We must set relative_dir so that
2270     # the file-finding machinery works.
2271     local ($relative_dir) = '.';
2272     &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs');
2275 ################################################################
2277 # Do any extra checking for GNU standards.
2278 sub check_gnu_standards
2280     if ($relative_dir eq '.')
2281     {
2282         # In top level (or only) directory.
2283         &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
2284                        'AUTHORS', 'ChangeLog');
2285     }
2288 # Do any extra checking for GNITS standards.
2289 sub check_gnits_standards
2291     if ($strictness >= $GNITS && -f $relative_dir . '/COPYING.LIB')
2292     {
2293         &am_error
2294             ("\`${relative_dir}/COPYING.LIB' disallowed by Gnits standards");
2295     }
2297     if ($relative_dir eq '.')
2298     {
2299         # In top level (or only) directory.
2300         &require_file ($GNITS, 'THANKS');
2301     }
2304 ################################################################
2306 # Pretty-print something.  HEAD is what should be printed at the
2307 # beginning of the first line, FILL is what should be printed at the
2308 # beginning of every subsequent line.
2309 sub pretty_print_internal
2311     local ($head, $fill, @values) = @_;
2313     local ($column) = length ($head);
2314     local ($result) = $head;
2316     # Fill length is number of characters.  However, each Tab
2317     # character counts for eight.  So we count the number of Tabs and
2318     # multiply by 7.
2319     local ($fill_length) = length ($fill);
2320     $fill_length += 7 * ($fill =~ tr/\t/\t/d);
2322     local ($bol) = 0;
2323     foreach (@values)
2324     {
2325         # "71" because we also print a space.
2326         if ($column + length ($_) > 71)
2327         {
2328             $result .= " \\\n" . $fill;
2329             $column = $fill_length;
2330             $bol = 1;
2331         }
2333         $result .= ' ' unless ($bol);
2334         $result .= $_;
2335         $column += length ($_) + 1;
2336         $bol = 0;
2337     }
2339     $result .= "\n";
2340     return $result;
2343 # Pretty-print something and append to output_vars.
2344 sub pretty_print
2346     $output_vars .= &pretty_print_internal (@_);
2349 # Pretty-print something and append to output_rules.
2350 sub pretty_print_rule
2352     $output_rules .= &pretty_print_internal (@_);
2356 ################################################################
2358 # See if a variable exists.
2359 sub variable_defined
2361     local ($var) = @_;
2362     if (defined $targets{$var})
2363     {
2364         &am_line_error ($var, "\`$var' is target; expected variable");
2365     }
2366     return (defined $contents{$var} && ! defined $targets{$var});
2369 # Read Makefile.am and set up %contents.  Simultaneously copy lines
2370 # from Makefile.am into $output_trailer or $output_vars as
2371 # appropriate.  NOTE we put rules in the trailer section.  We want
2372 # user rules to come after our generated stuff.
2373 sub read_am_file
2375     local ($amfile) = @_;
2377     # Compute relative location of the top object directory.
2378     local (@topdir) = ();
2379     foreach (split (/\//, $relative_dir))
2380     {
2381         next if $_ eq '.' || $_ eq '';
2382         if ($_ eq '..')
2383         {
2384             pop @topdir;
2385         }
2386         else
2387         {
2388             push (@topdir, '..');
2389         }
2390     }
2391     @topdir = ('.') if ! @topdir;
2393     $top_builddir = join ('/', @topdir);
2394     local ($build_rx);
2395     ($build_rx = $top_builddir) =~ s/(\W)/\\$1/g;
2396     local ($header_vars) =
2397         &file_contents_with_transform
2398             ('s/\@top_builddir\@/' . $build_rx . '/g',
2399              'header-vars');
2401     # Generate some useful variables when AC_CANONICAL_* used.
2402     if ($seen_canonical)
2403     {
2404         $header_vars .= ('host_alias = @host_alias@' . "\n"
2405                          . 'host_triplet = @host@' . "\n");
2406         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
2407         {
2408             $header_vars .= ('build_alias = @build_alias@' . "\n"
2409                              . 'build_triplet = @build@' . "\n");
2410             $header_vars .= ('target_alias = @target_alias@' . "\n"
2411                              . 'target_triplet = @target@' . "\n");
2412         }
2413     }
2415     open (AM_FILE, $amfile) || die "automake: couldn't open \`$amfile': $!\n";
2416     print "automake: reading $amfile\n" if $verbose;
2418     $output_vars .= ("# $in_file_name generated automatically by automake "
2419                      . $VERSION . " from $am_file_name\n");
2421     # Generate copyright for generated Makefile.in.
2422     $output_vars .= $gen_copyright;
2424     local ($saw_bk) = 0;
2425     local ($was_rule) = 0;
2426     local ($spacing) = '';
2427     local ($comment) = '';
2428     local ($last_var_name) = '';
2429     local ($blank) = 0;
2431     while (<AM_FILE>)
2432     {
2433         if (/$IGNORE_PATTERN/o)
2434         {
2435             # Merely delete comments beginning with two hashes.
2436         }
2437         elsif (/$WHITE_PATTERN/o)
2438         {
2439             # Stick a single white line before the incoming macro or rule.
2440             $spacing = "\n";
2441             $blank = 1;
2442         }
2443         elsif (/$COMMENT_PATTERN/o)
2444         {
2445             # Stick comments before the incoming macro or rule.  Make
2446             # sure a blank line preceeds comments.
2447             $spacing = "\n" unless $blank;
2448             $comment .= $spacing . $_;
2449             $spacing = '';
2450         }
2451         else
2452         {
2453             last;
2454         }
2455     }
2457     $output_vars .= $comment . "\n" . $header_vars;
2458     $comment = '';
2459     $spacing = "\n";
2461     local ($is_ok_macro);
2462     while ($_)
2463     {
2464         $_ .= "\n"
2465             unless substr ($_, -1, 1) eq "\n";
2467         $_ =~ s/\@MAINT\@//g
2468             unless $seen_maint_mode;
2470         if (/$IGNORE_PATTERN/o)
2471         {
2472             # Merely delete comments beginning with two hashes.
2473         }
2474         elsif (/$WHITE_PATTERN/o)
2475         {
2476             # Stick a single white line before the incoming macro or rule.
2477             $spacing = "\n";
2478         }
2479         elsif (/$COMMENT_PATTERN/o)
2480         {
2481             # Stick comments before the incoming macro or rule.
2482             $comment .= $spacing . $_;
2483             $spacing = '';
2484         }
2485         elsif ($saw_bk)
2486         {
2487             if ($was_rule)
2488             {
2489                 $output_trailer .= $_;
2490                 $saw_bk = /\\$/;
2491             }
2492             else
2493             {
2494                 $output_vars .= $_;
2495                 $saw_bk = /\\$/;
2496                 # Chop newline and backslash if this line is
2497                 # continued.  FIXME maybe ensure trailing whitespace
2498                 # exists?
2499                 chop if $saw_bk;
2500                 chop if $saw_bk;
2501                 $contents{$last_var_name} .= $_;
2502             }
2503         }
2504         elsif (/$RULE_PATTERN/o)
2505         {
2506             # warn "** Saw rule .$1.\n";
2507             # Found a rule.
2508             $was_rule = 1;
2509             # Value here doesn't matter; for targets we only note
2510             # existence.
2511             $contents{$1} = 1;
2512             $targets{$1} = 1;
2513             $content_lines{$1} = $.;
2514             $output_trailer .= $comment . $spacing . $_;
2515             $comment = $spacing = '';
2516             $saw_bk = /\\$/;
2517         }
2518         elsif (($is_ok_macro = /$MACRO_PATTERN/o)
2519                || /$BOGUS_MACRO_PATTERN/o)
2520         {
2521             # Found a macro definition.
2522             $was_rule = 0;
2523             $last_var_name = $1;
2524             if (substr ($2, -1) eq "\\")
2525             {
2526                 $contents{$1} = substr ($2, 0, length ($2) - 1);
2527             }
2528             else
2529             {
2530                 $contents{$1} = $2;
2531             }
2532             $content_lines{$1} = $.;
2533             $output_vars .= $comment . $spacing . $_;
2534             $comment = $spacing = '';
2535             $saw_bk = /\\$/;
2537             # Error if bogus.
2538             &am_line_error ($., "bad macro name \`$1'")
2539                 if ! $is_ok_macro;
2540         }
2541         else
2542         {
2543             # This isn't an error; it is probably a continued rule.
2544             # In fact, this is what we assume.
2545             $was_rule = 1;
2546             $output_trailer .= $comment . $spacing . $_;
2547             $comment = $spacing = '';
2548             $saw_bk = /\\$/;
2549         }
2551         $_ = <AM_FILE>;
2552     }
2554     $output_trailer .= $comment;
2557 ################################################################
2559 sub initialize_global_constants
2561     # Values for AC_CANONICAL_*
2562     $AC_CANONICAL_HOST = 1;
2563     $AC_CANONICAL_SYSTEM = 2;
2565     # Associative array of standard directory names.  Entry is TRUE if
2566     # corresponding directory should be installed during
2567     # 'install-exec' phase.
2568     %exec_dir_p =
2569         ('bin', 1,
2570          'sbin', 1,
2571          'libexec', 1,
2572          'data', 0,
2573          'sysconf', 1,
2574          'localstate', 1,
2575          'lib', 1,
2576          'info', 0,
2577          'man', 0,
2578          'include', 0,
2579          'oldinclude', 0,
2580          'pkgdata', 0,
2581          'pkglib', 1,
2582          'pkginclude', 0
2583          );
2585     # Helper text for dealing with man pages.
2586     $install_man_format =
2587     '   @sect=@SECTION@;                                \\
2588         inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
2589         echo installing @MAN@ as $(mandir)/man$$sect/$$inst; \\
2590         if test -f $(srcdir)/@MAN@; then file=$(srcdir)/@MAN@; \\
2591         else file=@MAN@; fi; \\
2592         $(INSTALL_DATA) $(srcdir)/@MAN@ $(mandir)/man$$sect/$$inst
2595     $uninstall_man_format =
2596     '   inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
2597         rm -f $(mandir)/man@SECTION@/$$inst
2600     # Commonly found files we look for and automatically include in
2601     # DISTFILES.
2602     @common_files =
2603         (
2604          "README", "THANKS", "TODO", "NEWS", "COPYING", "COPYING.LIB",
2605          "INSTALL", "ABOUT-NLS", "ChangeLog", "configure", "configure.in",
2606          "config.guess", "config.sub", "AUTHORS", "BACKLOG", "ABOUT-GNU",
2607          "libversion.in", "mdate-sh", "mkinstalldirs", "install-sh",
2608          'texinfo.tex', "ansi2knr.c", "ansi2knr.1"
2609          );
2611     # Commonly used files we auto-include, but only sometimes.
2612     @common_sometimes =
2613         (
2614          "aclocal.m4", "acconfig.h", "config.h.top",
2615          "config.h.bot", "stamp-h.in", 'stamp-vti', 'elisp-comp', 'libtool'
2616          );
2618     $USAGE = "\
2619   --amdir=DIR           directory storing config files
2620   --foreign             same as --strictness=foreign
2621   --gnits               same as --strictness=gnits
2622   --gnu                 same as --strictness=gnu
2623   --help                print this help, then exit
2624   -i, --include-deps    include generated dependencies in Makefile.in
2625   -a, --add-missing     add missing standard files to package
2626   --no-force            only update Makefile.in's that are out of date
2627   -o DIR, --output-dir=DIR
2628                         put generated Makefile.in's into DIR
2629   -s LEVEL, --strictness=LEVEL
2630                         set strictness level.  LEVEL is foreign, gnu, gnits
2631   -v, --verbose         verbosely list files processed
2632   --version             print version number, then exit\n";
2634     # Copyright on generated Makefile.ins.
2635     $gen_copyright = "\
2636 # Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
2637 # This Makefile.in is free software; the Free Software Foundation
2638 # gives unlimited permission to copy, distribute and modify it.
2642 # (Re)-Initialize per-Makefile.am variables.
2643 sub initialize_per_input
2645     # These two variables are used when generating each Makefile.in.
2646     # They hold the Makefile.in until it is ready to be printed.
2647     $output_rules = '';
2648     $output_vars = '';
2649     $output_trailer = '';
2651     # Suffixes found during a run.
2652     @suffixes = ();
2654     # This holds the contents of a Makefile.am, as parsed by
2655     # read_am_file.
2656     %contents = ();
2658     # This holds the names which are targets.  These also appear in
2659     # %contents.
2660     %targets = ();
2662     # This holds the line numbers at which various elements of
2663     # %contents are defined.
2664     %content_lines = ();
2666     # This holds the "relative directory" of the current Makefile.in.
2667     # Eg for src/Makefile.in, this is "src".
2668     $relative_dir = '';
2670     # This holds a list of files that are included in the
2671     # distribution.
2672     %dist_common = ();
2674     # List of dependencies for the obvious targets.
2675     @install_data = ();
2676     @install_exec = ();
2677     @uninstall = ();
2678     @installdirs = ();
2680     @info = ();
2681     @dvi = ();
2682     @all = ();
2683     @check = ();
2684     @installcheck = ();
2685     @clean = ();
2687     @phony = ();
2689     # These are pretty obvious, too.  They are used to define the
2690     # SOURCES and OBJECTS variables.
2691     @sources = ();
2692     @objects = ();
2694     # TRUE if current directory holds any C source files.  (Actually
2695     # holds object extension, but this information is encapsulated in
2696     # the function get_object_extension).
2697     $dir_holds_sources = '';
2699     # TRUE if install targets should work recursively.
2700     $recursive_install = 0;
2702     # All .P files.
2703     %dep_files = ();
2705     # Strictness levels.
2706     $strictness = $default_strictness;
2707     $strictness_name = $default_strictness_name;
2709     # Options from AUTOMAKE_OPTIONS.
2710     %options = ();
2712     # Whether or not dependencies are handled.  Can be further changed
2713     # in handle_options.
2714     $use_dependencies = $cmdline_use_dependencies;
2716     # Per Makefile.am.
2717     $local_maint_charset = $maint_charset;
2721 ################################################################
2723 # Return contents of a file from $am_dir, automatically skipping
2724 # macros or rules which are already known.  Runs command on each line
2725 # as it is read; this command can modify $_.
2726 sub file_contents_with_transform
2728     local ($command, $basename) = @_;
2729     local ($file) = $am_dir . '/' . $basename . '.am';
2731     open (FC_FILE, $file)
2732         || die "automake: installation error: cannot open \`$file'\n";
2733     # Looks stupid?
2734     # print "automake: reading $file\n" if $verbose;
2736     local ($was_rule) = 0;
2737     local ($result_vars) = '';
2738     local ($result_rules) = '';
2739     local ($comment) = '';
2740     local ($spacing) = "\n";
2741     local ($skipping) = 0;
2743     while (<FC_FILE>)
2744     {
2745         $_ =~ s/\@MAINT\@//g
2746             unless $seen_maint_mode;
2748         eval $command;
2750         if (/$IGNORE_PATTERN/o)
2751         {
2752             # Merely delete comments beginning with two hashes.
2753         }
2754         elsif (/$WHITE_PATTERN/o)
2755         {
2756             # Stick a single white line before the incoming macro or rule.
2757             $spacing = "\n";
2758         }
2759         elsif (/$COMMENT_PATTERN/o)
2760         {
2761             # Stick comments before the incoming macro or rule.
2762             $comment .= $spacing . $_;
2763             $spacing = '';
2764         }
2765         elsif ($saw_bk)
2766         {
2767             if ($was_rule)
2768             {
2769                 $result_rules .= $_ if ! $skipping;
2770             }
2771             else
2772             {
2773                 $result_vars .= $_ if ! $skipping;
2774             }
2775             $saw_bk = /\\$/;
2776         }
2777         elsif (/$RULE_PATTERN/o)
2778         {
2779             # warn "** Found rule .$1.\n";
2780             # Found a rule.
2781             $was_rule = 1;
2782             $skipping = defined $contents{$1};
2783             # warn "** Skip $skipping\n" if $skipping;
2784             $result_rules .= $comment . $spacing . $_ if ! $skipping;
2785             $comment = $spacing = '';
2786             $saw_bk = /\\$/;
2787         }
2788         elsif (/$MACRO_PATTERN/o)
2789         {
2790             # warn "** Found macro .$1.\n";
2791             # Found a variable reference.
2792             $was_rule = 0;
2793             $skipping = defined $contents{$1};
2794             # warn "** Skip $skipping\n" if $skipping;
2795             $result_vars .= $comment . $spacing . $_ if ! $skipping;
2796             $comment = $spacing = '';
2797             $saw_bk = /\\$/;
2798         }
2799         else
2800         {
2801             # This isn't an error; it is probably a continued rule.
2802             # In fact, this is what we assume.
2803             $was_rule = 1;
2804             $result_rules .= $comment . $spacing . $_ if ! $skipping;
2805             $comment = $spacing = '';
2806             $saw_bk = /\\$/;
2807         }
2808     }
2810     close (FC_FILE);
2811     return $result_vars . $result_rules . $comment;
2814 # Like file_contents_with_transform, but no transform.
2815 sub file_contents
2817     return &file_contents_with_transform ('', @_);
2820 # Handle `where_HOW' variable magic.  Does all lookups, generates
2821 # install code, and possibly generates code to define the primary
2822 # variable.  The first argument is the name of the .am file to munge,
2823 # the second argument is the primary variable (eg HEADERS), and all
2824 # subsequent arguments are possible installation locations.  Returns
2825 # list of all values of all _HOW targets.
2827 # FIXME this should be rewritten to be cleaner.  It should be broken
2828 # up into multiple functions.
2830 # Usage is: am_install_var (OPTION..., file, HOW, where...)
2831 sub am_install_var
2833     local (@args) = @_;
2835     local ($do_all, $do_clean) = (1, 0);
2836     while (@args)
2837     {
2838         if ($args[0] eq '-clean')
2839         {
2840             $do_clean = 1;
2841         }
2842         elsif ($args[0] eq '-no-all')
2843         {
2844             $do_all = 0;
2845         }
2846         elsif ($args[0] !~ /^-/)
2847         {
2848             last;
2849         }
2850         shift (@args);
2851     }
2852     local ($file, $primary, @prefixes) = @args;
2854     local (@used) = ();
2855     local (@result) = ();
2857     # Now that configure substitutions are allowed in where_HOW
2858     # variables, it is an error to actually define the primary.
2859     &am_line_error ($primary, "\`$primary' is an anachronism")
2860         if &variable_defined ($primary);
2863     # Look for misspellings.  It is an error to have a variable ending
2864     # in a "reserved" suffix whose prefix is unknown, eg
2865     # "bni_PROGRAMS".  However, unusual prefixes are allowed if a
2866     # variable of the same name (with "dir" appended) exists.  For
2867     # instance, if the variable "zardir" is defined, then
2868     # "zar_PROGRAMS" becomes valid.  This is to provide a little extra
2869     # flexibility in those cases which need it.  Perhaps it should be
2870     # disallowed in the Gnits case?  The problem is, sometimes it is
2871     # useful to put things in a subdir of eg pkgdatadir, perhaps even
2872     # for Gnitsoids.
2873     local (%valid, $varname);
2874     grep ($valid{$_} = 0, @prefixes);
2875     $valid{'EXTRA'} = 0;
2876     foreach $varname (keys %contents)
2877     {
2878         if ($varname =~ /^(.*)_$primary$/)
2879         {
2880             if (! defined $valid{$1} && ! &variable_defined ($1 . 'dir'))
2881             {
2882                 &am_line_error ($varname, "invalid variable \"$varname\"");
2883             }
2884             else
2885             {
2886                 # Ensure all extended prefixes are actually used.
2887                 $valid{$1} = 1;
2888             }
2889         }
2890     }
2892     local ($clean_file) = $file . '-clean';
2893     local ($one_name);
2894     local ($X);
2895     foreach $X (keys %valid)
2896     {
2897         $one_name = $X . '_' . $primary;
2898         if (&variable_defined ($one_name))
2899         {
2900             # Append actual contents of where_PRIMARY variable to
2901             # result.
2902             local ($rcurs);
2903             foreach $rcurs (split (' ', $contents{$one_name}))
2904             {
2905                 # Skip configure substitutions.  Possibly bogus.
2906                 next if $rcurs =~ /^\@.*\@$/;
2907                 push (@result, $rcurs);
2908             }
2910             # "EXTRA" shouldn't be used when generating clean targets,
2911             # @all, or install targets.
2912             next if $X eq 'EXTRA';
2914             if ($do_clean)
2915             {
2916                 $output_rules .=
2917                     &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go',
2918                                                    $clean_file);
2920                 push (@clean, $X . $primary);
2921                 &push_phony_cleaners ($X . $primary);
2922             }
2924             if ($X eq 'check')
2925             {
2926                 push (@check, '$(' . $one_name . ')');
2927             }
2928             else
2929             {
2930                 push (@used, '$(' . $one_name . ')');
2931             }
2932             if ($X eq 'noinst' || $X eq 'check')
2933             {
2934                 # Objects which don't get installed by default.
2935                 next;
2936             }
2938             $output_rules .=
2939                 &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go',
2940                                                $file);
2942             push (@uninstall, 'uninstall-' . $X . $primary);
2943             push (@phony, 'uninstall-' . $X . $primary);
2944             push (@installdirs, '$(' . $X . 'dir)');
2945             if ($exec_dir_p{$X})
2946             {
2947                 push (@install_exec, 'install-' . $X . $primary);
2948                 push (@phony, 'install-' . $X . $primary);
2949             }
2950             else
2951             {
2952                 push (@install_data, 'install-' . $X . $primary);
2953                 push (@phony, 'install-' . $X . $primary);
2954             }
2955         }
2956     }
2958     if (@used)
2959     {
2960         # Define it.
2961         &pretty_print ($primary . ' =', '', @used);
2962         $output_vars .= "\n";
2963     }
2965     # Push here because PRIMARY might be configure time determined.
2966     push (@all, '$(' . $primary . ')')
2967         if $do_all && @used;
2969     return (@result);
2973 ################################################################
2975 # This variable is local to the "require file" set of functions.
2976 @require_file_paths = ();
2978 # Verify that the file must exist in the current directory.  Usage:
2979 # require_file (isconfigure, line_number, strictness, file) strictness
2980 # is the strictness level at which this file becomes required.  Must
2981 # set require_file_paths before calling this function.
2982 # require_file_paths is set to hold a single directory (the one in
2983 # which the first file was found) before return.
2984 sub require_file_internal
2986     local ($is_configure, $line, $mystrict, @files) = @_;
2987     local ($file, $fullfile);
2988     local ($found_it, $errfile, $errdir);
2989     local ($save_dir);
2991     foreach $file (@files)
2992     {
2993         $found_it = 0;
2994         foreach $dir (@require_file_paths)
2995         {
2996             if ($dir eq '.')
2997             {
2998                 $fullfile = $relative_dir . "/" . $file;
2999                 $errdir = $relative_dir unless $errdir;
3000             }
3001             else
3002             {
3003                 $fullfile = $dir . "/" . $file;
3004                 $errdir = $dir unless $errdir;
3005             }
3007             # Use different name for "error filename".  Otherwise on
3008             # an error the bad file will be reported as eg
3009             # `../../install-sh' when using the default
3010             # config_aux_path.
3011             $errfile = $errdir . '/' . $file;
3013             if (-f $fullfile)
3014             {
3015                 $found_it = 1;
3016                 &push_dist_common ($file) if $dir eq $relative_dir;
3017                 $save_dir = $dir;
3018                 last;
3019             }
3020         }
3022         if ($found_it)
3023         {
3024             # Prune the path list.
3025             @require_file_paths = $save_dir;
3026         }
3027         else
3028         {
3029             if ($strictness >= $mystrict)
3030             {
3031                 # Only install missing files according to our desired
3032                 # strictness level.
3033                 if ($add_missing && -f ($am_dir . '/' . $file))
3034                 {
3035                     # Install the missing file.  Symlink if we can, copy
3036                     # if we must.
3037                     if ($symlink_exists)
3038                     {
3039                         symlink ($am_dir . '/' . $file, $errfile);
3040                     }
3041                     else
3042                     {
3043                         system ('cp', $am_dir . '/' . $file, $errfile);
3044                     }
3046                     # FIXME this is a hack.  Should have am_warn.
3047                     local ($save) = $exit_status;
3048                     if ($is_configure)
3049                     {
3050                         &am_conf_line_error
3051                             ($line,
3052                              "required file \"$errfile\" not found; installing");
3053                     }
3054                     else
3055                     {
3056                         &am_line_error
3057                             ($line,
3058                              "required file \"$errfile\" not found; installing");
3059                     }
3060                     $exit_status = $save;
3061                 }
3062                 else
3063                 {
3064                     # Only an error if strictness constraint violated.
3065                     if ($is_configure)
3066                     {
3067                         &am_conf_line_error
3068                             ($line, "required file \"$errfile\" not found");
3069                     }
3070                     else
3071                     {
3072                         &am_line_error
3073                             ($line, "required file \"$errfile\" not found");
3074                     }
3075                 }
3076             }
3077         }
3078     }
3081 # Like require_file_with_line, but error messages refer to
3082 # configure.in, not the current Makefile.am.
3083 sub require_file_with_conf_line
3085     @require_file_paths = '.';
3086     &require_file_internal (1, @_);
3089 sub require_file_with_line
3091     @require_file_paths = '.';
3092     &require_file_internal (0, @_);
3095 sub require_file
3097     @require_file_paths = '.';
3098     &require_file_internal (0, '', @_);
3101 # Require a file that is also required by Autoconf.  Looks in
3102 # configuration path, as specified by AC_CONFIG_AUX_DIR.
3103 sub require_config_file
3105     @require_file_paths = @config_aux_path;
3106     &require_file_internal (0, '', @_);
3107     local ($dir) = $require_file_paths[0];
3108     @config_aux_path = @require_file_paths;
3109     if ($dir eq '.')
3110     {
3111         $config_aux_dir = '.';
3112     }
3113     else
3114     {
3115         $config_aux_dir = '$(top_srcdir)/' . $dir;
3116     }
3119 # Assumes that the line number is in Makefile.am.
3120 sub require_conf_file_with_line
3122     @require_file_paths = @config_aux_path;
3123     &require_file_internal (0, @_);
3124     local ($dir) = $require_file_paths[0];
3125     @config_aux_path = @require_file_paths;
3126     if ($dir eq '.')
3127     {
3128         $config_aux_dir = '.';
3129     }
3130     else
3131     {
3132         $config_aux_dir = '$(top_srcdir)/' . $dir;
3133     }
3136 # Assumes that the line number is in Makefile.am.
3137 sub require_conf_file_with_conf_line
3139     @require_file_paths = @config_aux_path;
3140     &require_file_internal (1, @_);
3141     local ($dir) = $require_file_paths[0];
3142     @config_aux_path = @require_file_paths;
3143     if ($dir eq '.')
3144     {
3145         $config_aux_dir = '.';
3146     }
3147     else
3148     {
3149         $config_aux_dir = '$(top_srcdir)/' . $dir;
3150     }
3153 ################################################################
3155 # Push a list of files onto dist_common.
3156 sub push_dist_common
3158     local (@files) = @_;
3159     local ($file);
3161     foreach $file (@files)
3162     {
3163         $dist_common{$file} = 1;
3164     }
3167 # Push a list of clean targets onto phony.
3168 sub push_phony_cleaners
3170     local ($base) = @_;
3171     local ($target);
3172     foreach $target ('mostly', 'dist', '', 'maintainer-')
3173     {
3174         push (@phony, $target . 'clean-' . $base);
3175     }
3178 # Set strictness.
3179 sub set_strictness
3181     $strictness_name = $_[0];
3182     if ($strictness_name eq 'gnu')
3183     {
3184         $strictness = $GNU;
3185     }
3186     elsif ($strictness_name eq 'gnits')
3187     {
3188         $strictness = $GNITS;
3189     }
3190     elsif ($strictness_name eq 'foreign')
3191     {
3192         $strictness = $FOREIGN;
3193     }
3194     else
3195     {
3196         die "automake: level \`$strictness_name' not recognized\n";
3197     }
3201 ################################################################
3203 # Return directory name of file.
3204 sub dirname
3206     local ($file) = @_;
3207     local ($sub);
3209     ($sub = $file) =~ s,/+[^/]+$,,g;
3210     $sub = '.' if $sub eq $file;
3211     return $sub;
3214 # Make a directory.
3215 sub mkdir
3217     local ($dirname) = @_;
3218     system ("mkdir", $dirname);
3221 ################################################################
3223 # Print an error message and set exit status.
3224 sub am_error
3226     warn "automake: ${am_file}.am: ", join (' ', @_), "\n";
3227     $exit_status = 1;
3230 sub am_line_error
3232     local ($symbol, @args) = @_;
3234     if ($symbol)
3235     {
3236         # If SYMBOL not already a line number, look it up in Makefile.am.
3237         $symbol = $content_lines{$symbol} unless $symbol =~ /^\d+$/;
3238         $symbol .= ': ' if $symbol;
3239         warn "${am_file}.am:", $symbol, join (' ', @args), "\n";
3240         $exit_status = 1;
3241     }
3242     else
3243     {
3244         &am_error (@args);
3245     }
3248 # Like am_error, but while scanning configure.in.
3249 sub am_conf_error
3251     # FIXME can run in subdirs.
3252     warn "automake: configure.in: ", join (' ', @_), "\n";
3253     $exit_status = 1;
3256 # Error message with line number referring to configure.in.
3257 sub am_conf_line_error
3259     local ($line, @args) = @_;
3261     if ($line)
3262     {
3263         warn "configure.in: $line: ", join (' ', @args), "\n";
3264         $exit_status = 1;
3265     }
3266     else
3267     {
3268         &am_conf_error (@args);
3269     }
3272 # Tell user where our aclocal.m4 is, but only once.
3273 sub keyed_aclocal_warning
3275     local ($key) = @_;
3276     warn "automake: macro \`$key' can be found in ${am_dir}/aclocal.m4\n";
3279 # Print usage information.
3280 sub usage
3282     print "Usage: automake [OPTION] ... [Makefile]...\n";
3283     print $USAGE;
3284     print "\nFiles which are automatically distributed, if found:\n";
3285     $~ = "USAGE_FORMAT";
3286     local (@lcomm) = sort ((@common_files, @common_sometimes));
3287     local ($one, $two, $three, $four);
3288     while (@lcomm > 0)
3289     {
3290         $one = shift @lcomm;
3291         $two = @lcomm ? shift @lcomm : '';
3292         $three = @lcomm ? shift @lcomm : '';
3293         $four = @lcomm ? shift @lcomm : '';
3294         write;
3295     }
3297     exit 0;
3300 format USAGE_FORMAT =
3301   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
3302   $one,               $two,               $three,             $four