Fixes
[automake.git] / automake.in
blob8d2b0d23c67c12cad1739420d9f9827a37a439ea
1 #!@PERL@
2 # -*- perl -*-
3 # @configure_input@
5 eval 'exec @PERL@ -S $0 ${1+"$@"}'
6     if $running_under_some_shell;
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 # Strictness level as set on command line.
54 $default_strictness = $GNU;
56 # Name of strictness level, as set on command line.
57 $default_strictness_name = 'gnu';
59 # This is TRUE if GNU make specific automatic dependency generation
60 # code should be included in generated Makefile.in.
61 $cmdline_use_dependencies = 1;
63 # TRUE if in verbose mode.
64 $verbose = 0;
66 # This holds our (eventual) exit status.  We don't actually exit until
67 # we have processed all input files.
68 $exit_status = 0;
70 # From the Perl manual.
71 $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
73 # TRUE if missing standard files should be installed.
74 $add_missing = 0;
76 # Files found by scanning configure.in for LIBOBJS.
77 %libsources = ();
79 # True if fp_C_PROTOTYPES appears in configure.in.
80 $fp_c_prototypes = 0;
82 # Names used in AC_CONFIG_HEADER call.  $config_name is the actual
83 # (first) argument.  $config_header is the '.in' file.  Ordinarily the
84 # second is derived from the first, but they can be different if the
85 # weird "NAME:FILE" syntax is used.
86 $config_name = '';
87 $config_header = '';
88 # Line number at which AC_CONFIG_HEADER appears in configure.in.
89 $config_header_line = 0;
91 # Relative location of top build directory.
92 $top_builddir = '';
94 # List of Makefile.am's to process.
95 @input_files = ();
97 # List of files in AC_OUTPUT without Makefile.am.
98 @other_input_files = ();
99 # Line number at which AC_OUTPUT seen.
100 $ac_output_line = 0;
102 # List of directories to search for configure-required files.  This
103 # can be set by AC_CONFIG_AUX_DIR.
104 @config_aux_path = ('.', '..', '../..');
105 $config_aux_dir = '';
107 # Whether AC_PROG_MAKE_SET has been seen in configure.in.
108 $seen_make_set = 0;
110 # Whether ud_GNU_GETTEXT has been seen in configure.in.
111 $seen_gettext = 0;
112 # Line number at which ud_GNU_GETTEXT seen.
113 $ac_gettext_line = 0;
115 # Whether ALL_LINGUAS has been seen.
116 $seen_linguas = '';
117 # The actual text.
118 $all_linguas = '';
119 # Line number at which it appears.
120 $all_linguas_line = 0;
122 # 1 if AC_PROG_INSTALL seen, 2 if fp_PROG_INSTALL seen.
123 $seen_prog_install = 0;
125 # 1 if any scripts installed, 0 otherwise.
126 $scripts_installed = 0;
128 # Whether AC_PATH_XTRA has been seen in configure.in.
129 $seen_path_xtra = 0;
131 # Whether YACC variable has been seen in configure.in.
132 $seen_prog_yacc = 0;
134 # TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM).  The presence of
135 # AC_CHECK_TOOL also sets this.
136 $seen_canonical = 0;
138 # TRUE if we've seen AC_PROG_RANLIB.
139 $seen_ranlib = 0;
141 # TRUE if we've seen AC_ARG_PROGRAM.
142 $seen_arg_prog = 0;
144 # TRUE if we've seen gm_PROG_LIBTOOL or AC_PROG_LIBTOOL.
145 $seen_libtool = 0;
146 $libtool_line = 0;
148 # TRUE if we've seen jm_MAINTAINER_MODE.
149 $seen_maint_mode = 0;
152 # Charsets used by maintainer and in distribution.  MAINT_CHARSET is
153 # handled in a funny way: if seen in the top-level Makefile.am, it is
154 # used for every directory which does not specify a different value.
155 # The rationale here is that some directories (eg gettext) might be
156 # distributions of other packages, and thus require their own charset
157 # info.  However, the DIST_CHARSET must be the same for the entire
158 # package; it can only be set at top-level.
159 # FIXME this yields bugs when rebuilding.  What to do?  Always
160 # read (and sometimes discard) top-level Makefile.am?
161 $maint_charset = '';
162 $dist_charset = 'utf8';         # recode doesn't support this yet.
164 # Name of input file ("Makefile.in") and output file ("Makefile.am").
165 # These have no directory components.
166 $am_file_name = '';
167 $in_file_name = '';
171 &initialize_global_constants;
173 # Parse command line.
174 &parse_arguments (@ARGV);
176 # Do configure.in scan only once.
177 &scan_configure;
179 die "automake: no \`Makefile.am' found or specified\n"
180     if ! @input_files;
182 # Now do all the work on each file.
183 foreach $am_file (@input_files)
185     # FIXME should support the AC_OUTPUT ":" syntax here.
186     if (! -f ($am_file . '.am'))
187     {
188         &am_error ('no such file');
189     }
190     else
191     {
192         &generate_makefile ($am_file);
193     }
196 if ($seen_prog_install <= $scripts_installed)
198     &am_conf_error (($scripts_installed ? 'fp_PROG_INSTALL' : 'AC_PROG_INSTALL')
199                     . " must be used in configure.in");
200     &keyed_aclocal_warning ('fp_PROG_INSTALL')
201         if $scripts_installed;
204 exit $exit_status;
207 ################################################################
209 # Parse command line.
210 sub parse_arguments
212     local (@arglist) = @_;
214     # Start off as gnu.
215     &set_strictness ('gnu');
217     while (@arglist)
218     {
219         if ($arglist[0] eq "--version")
220         {
221             print "Automake version $VERSION\n";
222             exit 0;
223         }
224         elsif ($arglist[0] eq "--help")
225         {
226             &usage;
227         }
228         elsif ($arglist[0] =~ /^--amdir=(.+)$/)
229         {
230             $am_dir = $1;
231         }
232         elsif ($arglist[0] eq '--amdir')
233         {
234             &require_argument (@arglist);
235             shift (@arglist);
236             $am_dir = $arglist[0];
237         }
238         elsif ($arglist[0] =~ /^--strictness=(.+)$/)
239         {
240             &set_strictness ($1);
241         }
242         elsif ($arglist[0] eq '--gnu')
243         {
244             &set_strictness ('gnu');
245         }
246         elsif ($arglist[0] eq '--gnits')
247         {
248             &set_strictness ('gnits');
249         }
250         elsif ($arglist[0] eq '--foreign')
251         {
252             &set_strictness ('foreign');
253         }
254         elsif ($arglist[0] eq '--strictness' || $arglist[0] eq '-s')
255         {
256             &require_argument (@arglist);
257             shift (@arglist);
258             &set_strictness ($arglist[0]);
259         }
260         elsif ($arglist[0] eq '--include-deps' || $arglist[0] eq '-i')
261         {
262             $cmdline_use_dependencies = 0;
263         }
264         elsif ($arglist[0] =~ /^--output-dir=(.*)$/)
265         {
266             # Set output directory.
267             $output_directory = $1;
268         }
269         elsif ($arglist[0] eq '--output-dir' || $arglist[0] eq '-o')
270         {
271             &require_argument (@arglist);
272             shift (@arglist);
273             $output_directory = $arglist[0];
274         }
275         elsif ($arglist[0] eq '--add-missing' || $arglist[0] eq '-a')
276         {
277             $add_missing = 1;
278         }
279         elsif ($arglist[0] eq '--verbose' || $arglist[0] eq '-v')
280         {
281             $verbose = 1;
282         }
283         elsif ($arglist[0] eq '--')
284         {
285             # Stop option processing.
286             shift (@arglist);
287             push (@input_files, @arglist);
288             last;
289         }
290         elsif ($arglist[0] =~ /^-/)
291         {
292             die "automake: unrecognized option -- \`$arglist[0]'\n";
293         }
294         else
295         {
296             push (@input_files, $arglist[0]);
297         }
299         shift (@arglist);
300     }
302     # Take global strictness from whatever we currently have set.
303     $default_strictness = $strictness;
304     $default_strictness_name = $strictness_name;
307 # Ensure argument exists, or die.
308 sub require_argument
310     local ($arg, @arglist) = @_;
311     die "automake: no argument given for option \`$arg'\n"
312         if ! @arglist;
315 ################################################################
317 # Generate a Makefile.in given the name of the corresponding Makefile.
318 sub generate_makefile
320     local ($makefile) = @_;
322     ($am_file_name = $makefile) =~ s/^.*\///;
323     $in_file_name = $am_file_name . '.in';
324     $am_file_name .= '.am';
326     print "automake: creating ", $makefile, ".in\n" if $verbose;
328     &initialize_per_input;
329     $relative_dir = &dirname ($makefile);
331     # At the toplevel directory, we might need config.guess, config.sub
332     # or libtool.
333     if ($relative_dir eq '.')
334     {
335         # libtool requires some files.
336         &require_conf_file_with_conf_line ($libtool_line, $FOREIGN,
337                                            'config.sub', 'config.guess',
338                                            'libtool') if $seen_libtool;
340         # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
341         # config.sub.
342         &require_config_file ($FOREIGN, 'config.guess', 'config.sub')
343             if $seen_canonical;
344     }
346     # We still need Makefile.in here, because sometimes the `dist'
347     # target doesn't re-run automake.
348     &push_dist_common ($in_file_name, $am_file_name);
349     push (@sources, '$(SOURCES)')
350         if &variable_defined ('SOURCES');
351     push (@objects, '$(OBJECTS)')
352         if &variable_defined ('OBJECTS');
354     # This is always the default target.  This gives us freedom to do
355     # things in whatever order is convenient.
356     $output_rules .= "default: all\n\n";
357     push (@phony, 'default');
359     &read_am_file ($makefile . '.am');
360     &handle_options;
362     # Check first, because we might modify some state.
363     &check_gnu_standards;
364     &check_gnits_standards;
366     &handle_configure;
367     &handle_gettext;
368     &handle_libraries;
369     &handle_programs;
370     &handle_scripts;
372     # Re-init SOURCES and OBJECTS.  FIXME other code shouldn't depend
373     # on this (but currently does).
374     $contents{'SOURCES'} = join (' ', @sources);
375     $contents{'OBJECTS'} = join (' ', @objects);
377     &handle_texinfo;
378     &handle_man_pages;
379     &handle_data;
380     &handle_headers;
381     &handle_subdirs;
382     &handle_tags;
383     &handle_dist;
384     &handle_dependencies;
385     &handle_tests;
386     &handle_footer;
387     &handle_merge_targets;
388     &handle_installdirs;
389     &handle_clean;
390     &handle_phony;
392     if (! -d ($output_directory . '/' . $relative_dir))
393     {
394         &mkdir ($output_directory . '/' . $relative_dir);
395     }
396     if (! open (GM_FILE, "> " . $output_directory . '/' . $makefile . ".in"))
397     {
398         warn "automake: ${am_file}.in: cannot open: $!\n";
399         $exit_status = 1;
400         return;
401     }
403     print GM_FILE $output_vars;
404     print GM_FILE $output_rules;
405     print GM_FILE $output_trailer;
407     close (GM_FILE);
410 ################################################################
412 # Handle AUTOMAKE_OPTIONS variable.
413 sub handle_options
415     return if ! &variable_defined ('AUTOMAKE_OPTIONS');
417     foreach (split (/\s+/, $contents{'AUTOMAKE_OPTIONS'}))
418     {
419         $options{$_} = 1;
420         if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
421         {
422             &set_strictness ($_);
423         }
424         elsif ($_ eq 'no-installman' || $_ eq 'ansi2knr' || $_ eq 'dist-shar')
425         {
426             # Explicitly recognize these.
427         }
428         elsif ($_ eq 'no-dependencies')
429         {
430             $use_dependencies = 0;
431         }
432         elsif (/[0-9]+\.?[0-9]+/)
433         {
434             # Got a version number.  Is the syntax too strict?
435             if ($VERSION < $_)
436             {
437                 &am_line_error ('AUTOMAKE_OPTIONS',
438                                 "require version $_, only have $VERSION");
439                 exit 1;
440             }
441         }
442         else
443         {
444             &am_line_error ('AUTOMAKE_OPTIONS',
445                             'option ', $_, 'not recognized');
446         }
447     }
450 # Return object extension.  Just once, put some code into the output.
451 sub get_object_extension
453     if (! $dir_holds_sources)
454     {
455         # Boilerplate.
456         local ($xform) = '';
457         if (&variable_defined ('CONFIG_HEADER'))
458         {
459             ($xform = &dirname ($contents{'CONFIG_HEADER'}))
460                 =~ s/(\W)/\\$1/g;
461             $xform = '-I' . $xform;
462         }
463         $xform = 's/\@CONFIG_INCLUDE_SPEC\@/' . $xform . '/go';
464         $output_vars .= &file_contents_with_transform ($xform,
465                                                        'compile-vars');
466         $output_rules .= &file_contents ('compile');
467         &push_phony_cleaners ('compile');
469         # If using X, include some extra variable definitions.  NOTE
470         # we don't want to force these into CFLAGS or anything,
471         # because not all programs will necessarily use X.
472         if ($seen_path_xtra)
473         {
474             $output_vars .= ("X_CFLAGS = \@X_CFLAGS\@\n"
475                              . "X_LIBS = \@X_LIBS\@\n"
476                              . "X_EXTRA_LIBS = \@X_EXTRA_LIBS\@\n"
477                              . "X_PRE_LIBS = \@X_PRE_LIBS\@\n");
478         }
480         # Check for automatic de-ANSI-fication.
481         $dir_holds_sources = '.o';
482         push (@suffixes, '.c', '.o');
483         push (@clean, 'compile');
485         if (defined $options{'ansi2knr'})
486         {
487             if (! $fp_c_prototypes)
488             {
489                 &am_line_error ('AUTOMAKE_OPTIONS',
490                                 "option \`ansi2knr' in use but \`fp_C_PROTOTYPES' not in configure.in");
491                 &keyed_aclocal_warning ('fp_C_PROTOTYPES');
492                 # Only give this error once.
493                 $fp_c_prototypes = 1;
494             }
496             $dir_holds_sources = '$o';
497             push (@suffixes, '._c', '._o');
499             &require_file_with_line ('AUTOMAKE_OPTIONS', $FOREIGN,
500                                      'ansi2knr.c', 'ansi2knr.1');
502             $output_vars .= &file_contents ('kr-vars');
503             $output_rules .= &file_contents ('compile-kr');
504             $output_rules .= &file_contents ('clean-kr');
506             push (@clean, 'kr');
507             &push_phony_cleaners ('kr');
508         }
509     }
510     return $dir_holds_sources;
513 # Handle SOURCE->OBJECT transform for one program or library.
514 sub handle_source_transform
516     # one_file is canonical name.  unxformed is given name.  obj is
517     # object extension.
518     local ($one_file, $unxformed, $obj) = @_;
519     local ($objpat) = $obj;
520     $objpat =~ s/(\W)/\\$1/g;
522     if (&variable_defined ($one_file . "_OBJECTS"))
523     {
524         &am_line_error ($one_file . '_OBJECTS',
525                         $one_file . '_OBJECTS', 'should not be defined');
526         # No point in continuing.
527         return;
528     }
530     local ($source_list);
531     local ($prefix);
532     foreach $prefix ('', 'EXTRA_')
533     {
534         $source_list = '';
535         if (&variable_defined ($prefix . $one_file . "_SOURCES"))
536         {
537             push (@sources, '$(' . $prefix . $one_file . "_SOURCES)");
538             push (@objects, '$(' . $prefix . $one_file . "_OBJECTS)")
539                 unless $prefix eq 'EXTRA_';
540             $source_list = $contents{$prefix . $one_file . "_SOURCES"};
541         }
542         elsif ($prefix eq '')
543         {
544             $output_vars .= ($one_file . "_SOURCES = " . $unxformed . ".c\n"
545                              . $one_file . "_OBJECTS = ". $unxformed
546                              . $obj . "\n");
547             push (@sources, $unxformed . '.c');
548             push (@objects, $unxformed . $obj);
549             $source_list = $unxformed . ".c ";
550         }
551         else
552         {
553             $output_vars .= "EXTRA_" . $one_file . "_SOURCES =\n";
554         }
556         if ($source_list)
557         {
558             # Turn sources into objects.
559             local (@files) = split (/\s+/, $source_list);
560             local (@result) = ();
561             foreach (@files)
562             {
563                 # Skip header files, including C++-ish ones.
564                 next if /\.[hH]$/;
565                 next if /\.hxx$/;
566                 # Skip things that look like macro references.
567                 next if /^\$\(.*\)$/;
568                 next if /^\$\{.*\}$/;
569                 # Skip things that look like configure substitutions.
570                 next if /^\@.*\@$/;
572                 # One wonders how this can happen.  But, apparently,
573                 # it can.  I believe it happens when nothing precedes
574                 # a backslash-newline on a line -- the \s+ regexp
575                 # doesn't match the newline.  Anyway, skip empty
576                 # strings.  See tests/depend.test for an example of
577                 # how to trigger this code.
578                 next if /^\s*$/;
580                 if (/^(.*)\.[yl]$/)
581                 {
582                     # Automatically include generated .c file in
583                     # distribution.
584                     &push_dist_common ($1 . '.c');
585                 }
587                 # Transform source files into .o files.
588                 s/\.cc$/$obj/g;
589                 s/\.cxx$/$obj/g;
590                 s/\.[cCmylfs]$/$obj/g;
591                 push (@result, $_)
592                     unless $prefix eq 'EXTRA_';
594                 # Transform .o or $o file into .P file (for automatic
595                 # dependency code).
596                 s/$objpat$/.P/g;
597                 $dep_files{'$(srcdir)/.deps/' . $_} = 1;
598             }
600             &pretty_print ($one_file . "_OBJECTS =", "", @result)
601                 unless $prefix eq 'EXTRA_';
602         }
603     }
605     if (&variable_defined ('CONFIG_HEADER'))
606     {
607         $output_rules .= ('$(' . $one_file . "_OBJECTS): "
608                           . $contents{'CONFIG_HEADER'} . "\n");
609     }
611     return @result;
614 # Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
615 sub handle_lib_objects
617     local ($var) = @_;
619     die "programming error in handle_lib_objects"
620         if ! &variable_defined ($var);
622     # We recognize certain things that are commonly put in LIBADD or
623     # LDADD.
624     local ($lsearch);
626     foreach $lsearch (split (/\s+/, $contents{$var}))
627     {
628         # Automatically handle @LIBOBJS@ and @ALLOCA@.  Basically this
629         # means adding entries to dep_files.
630         if ($lsearch eq '@LIBOBJS@')
631         {
632             local ($iter, $rewrite);
633             foreach $iter (keys %libsources)
634             {
635                 if ($iter ne 'alloca.c')
636                 {
637                     ($rewrite = $iter) =~ s/\.c$/.P/;
638                     $dep_files{'$(srcdir)/.deps/' . $rewrite} = 1;
639                     &require_file_with_line ($var, $FOREIGN, $iter);
640                 }
641             }
642         }
643         elsif ($lsearch eq '@ALLOCA@')
644         {
645             &am_line_error ($var,
646                             "\@ALLOCA\@ seen but \`AC_FUNC_ALLOCA' not in \`configure.in'")
647                 if ! defined $libsources{'alloca.c'};
648             $dep_files{'$(srcdir)/.deps/alloca.P'} = 1;
649             &require_file_with_line ($var, $FOREIGN, 'alloca.c');
650         }
651     }
654 # Handle C programs.
655 sub handle_programs
657     local (@proglist) = &am_install_var ('-clean',
658                                          'programs', 'PROGRAMS',
659                                          'bin', 'sbin', 'libexec', 'pkglib',
660                                          'noinst', 'check');
661     return if ! @proglist;
663     # If a program is installed, this is required.  We only want this
664     # error to appear once.
665     &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
666         unless $seen_arg_prog;
667     $seen_arg_prog = 1;
669     local ($obj) = &get_object_extension;
670     local ($one_file, $xname, $munge);
672     foreach $one_file (@proglist)
673     {
674         # Canonicalize names.
675         ($xname = $one_file) =~ tr/A-Za-z0-9_/_/c;
676         if ($xname ne $one_file)
677         {
678             local ($xt);
679             foreach $xt ('_LDADD', '_SOURCES', '_OBJECTS', '_DEPENDENCIES')
680             {
681                 &am_line_error ($one_file . $xt,
682                                 "invalid variable \`" . $one_file . $xt
683                                 . "'; should be \`" . $xname . $xt . "'")
684                     if &variable_defined ($one_file . $xt);
685             }
686         }
688         &handle_source_transform ($xname, $one_file, $obj);
690         if (&variable_defined ($xname . "_LDADD"))
691         {
692             &handle_lib_objects ($xname . '_LDADD');
693         }
694         else
695         {
696             # User didn't define prog_LDADD override.  So do it.
697             $output_vars .= $xname . '_LDADD = $(LDADD)' . "\n";
698         }
700         $output_rules .=
701             &file_contents_with_transform
702                 ('s/\@PROGRAM\@/' . $one_file . '/go;'
703                  . 's/\@XPROGRAM\@/' . $xname . '/go;',
704                  'program');
705     }
707     &handle_lib_objects ('LDADD')
708         if &variable_defined ('LDADD');
711 # Handle libraries.
712 sub handle_libraries
714     local (@liblist) = &am_install_var ('-no-all', '-clean',
715                                         'libraries', 'LIBRARIES',
716                                         'lib', 'pkglib', 'noinst', 'check');
717     return if ! @liblist;
719     if (! $seen_ranlib)
720     {
721         # FIXME need am_line_error here.  But we don't know which
722         # variable exists.  Must add a loop...  No.  Must have
723         # am_install_var return a hash.  Otherwise the user could add
724         # install directories that we'd never find.
725         &am_error ("library requires either \`AC_PROG_RANLIB' or `gm_PROG_LIBTOOL' in configure.in");
726         # Only get this error once.
727         $seen_ranlib = 1;
728     }
730     # Generate _LIBFILES variables.  Too bad we can't do this in
731     # am_install_var.
732     local ($onedir, $onelib);
733     local (@outlist);
734     foreach $onedir ('lib', 'pkglib', 'noinst', 'check')
735     {
736         if (&variable_defined ($onedir . '_LIBRARIES'))
737         {
738             @outlist = ();
739             foreach $onelib (split (/\s+/, $contents{$onedir . '_LIBRARIES'}))
740             {
741                 push (@outlist, 'lib' . $onelib . '.a');
742             }
743             &pretty_print ($onedir . '_LIBFILES =', "", @outlist);
744         }
745     }
746     push (@all, '$(LIBFILES)');
748     local ($obj) = &get_object_extension;
749     local ($munge);
750     foreach $onelib (@liblist)
751     {
752         if (&variable_defined ($onelib . '_LIBADD'))
753         {
754             &handle_lib_objects ($onelib . '_LIBADD');
755         }
756         else
757         {
758             # Generate support for conditional object inclusion in
759             # libraries.
760             $output_vars .= $onelib . "_LIBADD =\n";
761         }
763         &handle_source_transform ($onelib, $onelib, $obj);
765         $output_rules .=
766             &file_contents_with_transform ('s/\@LIBRARY\@/' . $onelib . '/go',
767                                            'library');
768     }
770     # Turn "foo" into "libfoo.a" and include macro definition.
771     grep (($_ = 'lib' . $_ . '.a') && 0, @liblist);
773     if (! &variable_defined ('LIBFILES'))
774     {
775         &pretty_print ('LIBFILES = ', "", @liblist);
776     }
778     if ($seen_libtool)
779     {
780         $output_vars .= ('AR = $(LIBTOOL) archive' . "\n"
781                          . 'RANLIB = $(LIBTOOL) ranlib' . "\n"
782                          . 'LCOMPILE = $(LIBTOOL) compile $(DEFS) $(INCLUDES)'
783                          . ' $(CPPFLAGS) $(CFLAGS)' . "\n");
784     }
785     else
786     {
787         $output_vars .= ('AR = ar' . "\n"
788                          . 'RANLIB = @RANLIB@' . "\n");
789     }
792 # Handle scripts.
793 sub handle_scripts
795     # NOTE we no longer automatically clean SCRIPTS, because it is
796     # useful to sometimes distribute scripts verbatim.  This happens
797     # eg in Automake itself.
798     local ($msi);
799     $msi = &am_install_var ('scripts', 'SCRIPTS',
800                             'bin', 'sbin', 'libexec', 'pkgdata',
801                             'noinst', 'check');
803     # We really only want a boolean value.
804     $scripts_installed = 1 if $msi;
806     if ($scripts_installed)
807     {
808         # If a program is installed, this is required.  We only want this
809         # error to appear once.
810         &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
811             unless $seen_arg_prog;
812         $seen_arg_prog = 1;
813     }
816 # Search a file for a "version.texi" Texinfo include.  Return the name
817 # of the include file if found, or the empty string if not.  A
818 # "version.texi" file is actually any file whose name matches
819 # "vers*.texi".
820 sub grep_for_vers_texi
822     local ($filename) = @_;
824     if (! open (TEXI, $filename))
825     {
826         &am_error ("couldn't open \`$filename': $!");
827         return '';
828     }
829     print "automake: reading $filename\n" if $verbose;
831     while (<TEXI>)
832     {
833         if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
834         {
835             # Found it.
836             close (TEXI);
837             return $1;
838         }
839     }
841     close (TEXI);
842     return '';
845 # Handle all Texinfo source.
846 sub handle_texinfo
848     &am_line_error ('TEXINFOS',
849                     "\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
850         if &variable_defined ('TEXINFOS');
851     return if (! &variable_defined ('info_TEXINFOS')
852                && ! &variable_defined ('html_TEXINFOS'));
854     local (@texis) = split (/\s+/, $contents{'info_TEXINFOS'});
856     local (@infos_list, @info_deps_list, @dvis_list, @texi_deps);
857     local ($infobase, $info_cursor);
858     local (%versions);
859     local ($done) = 0;
860     local ($vti);
861     local ($tc_cursor, @texi_cleans);
862     local ($canonical);
864     foreach $info_cursor (@texis)
865     {
866         ($infobase = $info_cursor) =~ s/\.texi$//;
868         # If 'version.texi' is referenced by input file, then include
869         # automatic versioning capability.
870         local ($vtexi)
871             = &grep_for_vers_texi ($relative_dir . "/" . $info_cursor);
872         if ($vtexi)
873         {
874             &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
875                 if (defined $versions{$vtexi});
876             $versions{$vtexi} = $info_cursor;
878             # We number the stamp-vti files.  This is doable since the
879             # actual names don't matter much.  We only number starting
880             # with the second one, so that the common case looks nice.
881             $vti = 'vti' . ($done ? $done : '');
882             &push_dist_common ($vtexi, 'stamp-' . $vti);
883             push (@clean, $vti);
885             # Only require once.
886             &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
887                                           'mdate-sh')
888                 if ! $done;
889             ++$done;
891             local ($conf_pat);
892             ($conf_pat = $config_aux_dir) =~ s/(\W)/\\$1/g;
893             $output_rules .=
894                 &file_contents_with_transform
895                     ('s/\@TEXI\@/' . $info_cursor . '/g; '
896                      . 's/\@VTI\@/' . $vti . '/g; '
897                      . 's/\@VTEXI\@/' . $vtexi . '/g;'
898                      . 's,\@MDDIR\@,' . $conf_pat . ',g;',
899                      'texi-version');
901             &push_phony_cleaners ($vti);
902         }
904         # If user specified file_TEXINFOS, then use that as explicit
905         # dependency list.
906         @texi_deps = ();
907         push (@texi_deps, $info_cursor);
908         push (@texi_deps, $vtexi) if $vtexi;
910         # Canonicalize name first.
911         ($canonical = $infobase) =~ tr/A-Za-z0-9_/_/c;
912         if (&variable_defined ($canonical . "_TEXINFOS"))
913         {
914             push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
915             &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
916         }
918         $output_rules .= ("\n" . $infobase . ".info: "
919                           . join (' ', @texi_deps) . "\n\n");
921         push (@infos_list, $infobase . '.info*');
922         push (@info_deps_list, $infobase . '.info');
923         push (@dvis_list, $infobase . '.dvi');
925         # Generate list of things to clean for this target.  We do
926         # this explicitly because otherwise too many things could be
927         # removed.  In particular the ".log" extension might
928         # reasonably be used in other contexts by the user.
929         foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns',
930                             'ky', 'log', 'pg', 'toc', 'tp', 'vr', 'op')
931         {
932             push (@texi_cleans, $infobase . '.' . $tc_cursor);
933         }
934     }
936     # Some boilerplate.
937     $output_vars .= &file_contents ('texinfos-vars');
938     $output_rules .= &file_contents ('texinfos');
939     push (@phony, 'install-info', 'uninstall-info');
941     # How to clean.
942     $output_rules .= "\nmostlyclean-info:\n";
943     &pretty_print_rule ("\trm -f", "\t  ", @texi_cleans);
944     $output_rules .= ("\nclean-info:\n\ndistclean-info:\n\n"
945                       . "maintainer-clean-info:\n\t"
946                       . 'rm -f $(INFOS)' . "\n");
947     &push_phony_cleaners ('info');
949     push (@suffixes, '.texi', '.info', '.dvi');
950     push (@uninstall, 'uninstall-info');
951     push (@clean, 'info');
952     push (@info, '$(INFO_DEPS)');
953     push (@dvi, '$(DVIS)');
954     push (@installdirs, '$(infodir)');
955     unshift (@install_data, 'install-info');
957     # Make sure documentation is made and installed first.  Use
958     # $(INFO_DEPS), not 'info', because otherwise recursive makes get
959     # run twice during "make all".
960     unshift (@all, '$(INFO_DEPS)');
962     $output_vars .= ("INFOS = " . join (' ', @infos_list) . "\n"
963                      . "INFO_DEPS = " . join (' ', @info_deps_list)  . "\n"
964                      . "DVIS = " . join (' ', @dvis_list) . "\n"
965                      # This next isn't strictly needed now -- the
966                      # places that look here could easily be changed
967                      # to look in info_TEXINFOS.  But this is probably
968                      # better, in case noinst_TEXINFOS is ever
969                      # supported.
970                      . "TEXINFOS = " . $contents{'info_TEXINFOS'} . "\n\n");
972     # Do some error checking.
973     &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex');
976 # Handle any man pages.
977 sub handle_man_pages
979     &am_line_error ('MANS', "\`MANS' is an anachronism; use \`man_MANS'")
980         if &variable_defined ('MANS');
981     return if ! &variable_defined ('man_MANS');
983     # We generate the manpage install code by hand to avoid the use of
984     # basename in the generated Makefile.
985     local (@mans) = split (/\s+/, $contents{'man_MANS'});
986     local (%sections, %inames, %secmap, %fullsecmap);
987     foreach (@mans)
988     {
989         # FIXME: statement without effect:
990         /^(.*)\.([0-9])([a-z]*)$/;
991         $sections{$2} = 1;
992         $inames{$1} = $_;
993         $secmap{$1} = $2;
994         $fullsecmap{$1} = $2 . $3;
995     }
997     # We don't really need this, but we use it in case we ever want to
998     # support noinst_MANS.
999     $output_vars .= "MANS = " . $contents{'man_MANS'} . "\n";
1001     # Generate list of install dirs.
1002     $output_rules .= "install-man: \$(MANS)\n";
1003     foreach (keys %sections)
1004     {
1005         push (@installdirs, '$(mandir)/man' . $_);
1006         $output_rules .= ("\t" . '$(mkinstalldirs) $(mandir)/man'
1007                           . $_ . "\n");
1008     }
1009     push (@phony, 'install-man');
1011     # Generate install target.
1012     local ($key);
1013     foreach $key (keys %inames)
1014     {
1015         $_ = $install_man_format;
1016         s/\@SECTION\@/$secmap{$key}/g;
1017         s/\@MAN\@/$inames{$key}/g;
1018         s/\@FULLSECT\@/$fullsecmap{$key}/g;
1019         s/\@MANBASE\@/$key/g;
1020         $output_rules .= $_;
1021     }
1022     $output_rules .= "\n";
1024     $output_rules .= "uninstall-man:\n";
1025     foreach $key (keys %inames)
1026     {
1027         $_ = $uninstall_man_format;
1028         s/\@SECTION\@/$secmap{$key}/g;
1029         s/\@MAN\@/$inames{$key}/g;
1030         s/\@FULLSECT\@/$fullsecmap{$key}/g;
1031         s/\@MANBASE\@/$key/g;
1032         $output_rules .= $_;
1033     }
1034     $output_rules .= "\n";
1035     push (@phony, 'uninstall-man');
1037     $output_vars .= &file_contents ('mans-vars');
1039     if (! defined $options{'no-installman'})
1040     {
1041         push (@install_data, 'install-man');
1042         push (@uninstall, 'uninstall-man');
1043         push (@all, '$(MANS)');
1044     }
1047 # Handle DATA variables.
1048 sub handle_data
1050     &am_install_var ('data', 'DATA', 'data', 'sysconf',
1051                      'sharedstate', 'localstate', 'pkgdata',
1052                      'noinst', 'check');
1055 # Handle TAGS.
1056 sub handle_tags
1058     local ($tagging) = 0;
1060     push (@phony, 'tags');
1061     if (&variable_defined ('SUBDIRS'))
1062     {
1063         $output_rules .= &file_contents ('tags');
1064         $tagging = 1;
1065     }
1066     elsif ($dir_holds_sources || &variable_defined ('ETAGS_ARGS'))
1067     {
1068         $output_rules .= &file_contents ('tags-subd');
1069         $tagging = 1;
1070     }
1072     if ($tagging)
1073     {
1074         $output_rules .= &file_contents ('tags-clean');
1075         push (@clean, 'tags');
1076         &push_phony_cleaners ('tags');
1077     }
1078     else
1079     {
1080         # Every Makefile must define some sort of TAGS rule.
1081         # Otherwise, it would be possible for a top-level "make TAGS"
1082         # to fail because some subdirectory failed.
1083         $output_rules .= "tags: TAGS\nTAGS:\n\n";
1084     }
1087 # Generate actual 'dist' (or dist-shar) rule.
1088 sub handle_dist_worker
1090     $output_rules .= 'distdir: $(DEP_DISTFILES)' . "\n";
1092     # Initialization; only at top level.
1093     if ($relative_dir eq '.')
1094     {
1095         if ($strictness >= $GNITS)
1096         {
1097             # For Gnits users, this is pretty handy.  Look at 15 lines
1098             # in case some explanatory text is desirable.
1099             $output_rules .= '  @if sed 15q $(srcdir)/NEWS | grep -e "$(VERSION)" > /dev/null; then :; else \\
1100           echo "NEWS not updated; not releasing" 1>&2; \\
1101           exit 1;                               \\
1102         fi
1104         }
1107         $output_rules .=
1108             # Create dist directory.
1109             '   rm -rf $(distdir)
1110         mkdir $(distdir)
1111         chmod 777 $(distdir)
1114         # Only run automake in `dist' target if --include-deps not
1115         # specified.  That way the recipient of a distribution can run
1116         # "make dist" and not need Automake.
1117         if ($cmdline_use_dependencies)
1118         {
1119             $output_rules .=
1120                 (
1121                  # We need an absolute path for --output-dir.  Thus the
1122                  # weirdness.
1123                  '      distdir=`cd $(distdir) && pwd` \\
1124           && cd $(srcdir) \\
1125           && automake --include-deps --output-dir=$$distdir --strictness='
1126                  # Set strictness of output.
1127                  . $strictness_name . "\n"
1128                  );
1129         }
1130     }
1132     # In loop, test for file existence because sometimes a file gets
1133     # included in DISTFILES twice.  For example this happens when a
1134     # single source file is used in building more than one program.
1135     # Also, there are situations in which "ln" can fail.  For instance
1136     # a file to distribute could actually be a cross-filesystem
1137     # symlink -- this can easily happen if "gettextize" was run on the
1138     # distribution.  Note that DISTFILES can contain a wildcard (for
1139     # info files, sigh), so we must use the echo trick.
1140     $output_rules .= '  @for file in `cd $(srcdir) && echo $(DISTFILES)`; do \\
1141           test -f $(distdir)/$$file \\
1142           || ln $(srcdir)/$$file $(distdir)/$$file 2> /dev/null \\
1143           || cp -p $(srcdir)/$$file $(distdir)/$$file; \\
1144         done
1147     # If we have SUBDIRS, create all dist subdirectories and do
1148     # recursive build.
1149     if (&variable_defined ('SUBDIRS'))
1150     {
1151         # Test for directory existence here because previous automake
1152         # invocation might have created some directories.  Note that
1153         # we explicitly set distdir for the subdir make; that lets us
1154         # mix-n-match many automake-using packages into one large
1155         # package, and have "dist" at the top level do the right
1156         # thing.
1157         $output_rules .= '      for subdir in $(SUBDIRS); do            \\
1158           test -d $(distdir)/$$subdir           \\
1159           || mkdir $(distdir)/$$subdir          \\
1160           || exit 1;                            \\
1161           chmod 777 $(distdir)/$$subdir;        \\
1162           (cd $$subdir && $(MAKE) distdir=../$(distdir)/$$subdir distdir) \\
1163             || exit 1; \\
1164         done
1166     }
1168     # If the target `dist-hook' exists, run it now.  This allows
1169     # users to do random weird things to the distribution before it is
1170     # packaged up.
1171     if (defined $contents{'dist-hook'})
1172     {
1173         $output_rules .= "\t\$(MAKE) dist-hook\n";
1174     }
1176     push (@phony, 'distdir');
1179 # Handle 'dist' target.
1180 sub handle_dist
1182     # Set up maint_charset.
1183     $local_maint_charset = $contents{'MAINT_CHARSET'}
1184         if &variable_defined ('MAINT_CHARSET');
1185     $maint_charset = $local_maint_charset
1186         if $relative_dir eq '.';
1188     if (&variable_defined ('DIST_CHARSET'))
1189     {
1190         &am_line_error ('DIST_CHARSET',
1191                         "DIST_CHARSET defined but no MAINT_CHARSET defined")
1192             if ! $local_maint_charset;
1193         if ($relative_dir eq '.')
1194         {
1195             $dist_charset = $contents{'DIST_CHARSET'}
1196         }
1197         else
1198         {
1199             &am_line_error ('DIST_CHARSET',
1200                             "DIST_CHARSET can only be defined at top level");
1201         }
1202     }
1204     # Look for common files that should be included in distribution.
1205     local ($cfile);
1206     foreach $cfile (@common_files)
1207     {
1208         if (-f ($relative_dir . "/" . $cfile))
1209         {
1210             &push_dist_common ($cfile);
1211         }
1212     }
1214     # Keys of %dist_common are names of files to distributed.  We put
1215     # README first because it then becomes easier to make a
1216     # Usenet-compliant shar file (in these, README must be first).
1217     # FIXME do more ordering of files here.
1218     local (@coms);
1219     if (defined $dist_common{'README'})
1220     {
1221         push (@coms, 'README');
1222         undef $dist_common{'README'};
1223     }
1224     push (@coms, sort keys %dist_common);
1226     &pretty_print ("DIST_COMMON =", "", @coms);
1227     $output_vars .= "\n";
1229     # Some boilerplate.
1230     $output_vars .= &file_contents ('dist-vars');
1232     # Put these things in rules section so it is easier for whoever
1233     # reads Makefile.in.
1234     if ($relative_dir eq '.')
1235     {
1236         $output_rules .= "\n" . 'distdir = $(PACKAGE)-$(VERSION)' . "\n";
1237     }
1238     else
1239     {
1240         $output_rules .= ("\nsubdir = " . $relative_dir . "\n"
1241                           . 'distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)'
1242                           . "\n");
1243     }
1245     # Generate 'dist' target, and maybe dist-shar.
1246     if ($relative_dir eq '.')
1247     {
1248         # Rule to check whether a distribution is viable.
1249         $output_rules .= '# This target untars the dist file and tries a VPATH configuration.  Then
1250 # it guarantees that the distribution is self-contained by making another
1251 # tarfile.
1252 distcheck: dist
1253         rm -rf $(distdir)
1254         $(TAR) zxf $(distdir).tar.gz
1255         mkdir $(distdir)/$(distdir)
1256         cd $(distdir)/$(distdir) \\
1257           && ../configure --srcdir=.. \\
1258           && $(MAKE) \\
1259           && $(MAKE) check \\
1260           && $(MAKE) dist
1261         rm -rf $(distdir)
1262         @echo "========================"; \\
1263         echo "$(distdir).tar.gz is ready for distribution"; \\
1264         echo "========================"
1267         $output_rules .= 'dist: distdir' . "\n\t";
1268         $output_rules .= 'chmod -R a+r $(distdir)' . "\n\t";
1269         $output_rules .= '$(TAR) chozf $(distdir).tar.gz $(distdir)';
1270         $output_rules .= "\n\t" . 'rm -rf $(distdir)' . "\n";
1272         if (defined $options{'dist-shar'})
1273         {
1274             $output_rules .= 'dist-shar: distdir' . "\n\t";
1275             $output_rules .= 'chmod -R a+r $(distdir)' . "\n\t";
1276             $output_rules .= 'shar $(distdir) | gzip > $(distdir).shar.gz';
1277             $output_rules .= "\n\t" . 'rm -rf $(distdir)' . "\n";
1278         }
1279     }
1281     # Generate distdir target.
1282     &handle_dist_worker;
1285 # Handle auto-dependency code.
1286 sub handle_dependencies
1288     if ($use_dependencies)
1289     {
1290         # Include GNU-make-specific auto-dep code.
1291         if ($dir_holds_sources)
1292         {
1293             &pretty_print ('DEP_FILES =', "", sort keys %dep_files);
1294             $output_rules .= &file_contents ('depend');
1295         }
1296     }
1297     else
1298     {
1299         # Include any auto-generated deps that are present.
1300         if (-d ($relative_dir . "/.deps") && -f ($relative_dir . "/.deps/.P"))
1301         {
1302             local ($depfile);
1303             local ($gpat) = $relative_dir . "/.deps/*.P";
1305             foreach $depfile (<${gpat}>)
1306             {
1307                 if (! open (DEP_FILE, $depfile))
1308                 {
1309                     &am_error ("couldn't open \`$depfile': $!");
1310                     next;
1311                 }
1312                 print "automake: reading $depfile\n" if $verbose;
1314                 # Slurp entire file.
1315                 $output_rules .= join ('', <DEP_FILE>);
1317                 close (DEP_FILE);
1318             }
1320             $output_rules .= "\n";
1321         }
1322     }
1325 # Handle subdirectories.
1326 sub handle_subdirs
1328     if (! &variable_defined ('SUBDIRS'))
1329     {
1330         &am_conf_error
1331             ("ud_GNU_GETTEXT in configure.in but SUBDIRS not defined")
1332                 if $seen_gettext && $relative_dir eq '.';
1333         return;
1334     }
1336     &require_file_with_conf_line ($ac_gettext_line, $FOREIGN, 'ABOUT-NLS')
1337         if $seen_gettext;
1339     return if ! &variable_defined ('SUBDIRS');
1341     # Make sure each directory mentioned in SUBDIRS actually exists.
1342     local ($dir);
1343     foreach $dir (split (/\s+/, $contents{'SUBDIRS'}))
1344     {
1345         # Skip directories substituted by configure.
1346         next if $dir =~ /^\@.*\@$/;
1347         &am_line_error ('SUBDIRS',
1348                         "required directory $relative_dir/$dir does not exist")
1349             if ! -d $relative_dir . '/' . $dir;
1350     }
1352     $output_rules .= &file_contents ('subdirs');
1354     # Push a bunch of phony targets.
1355     local ($phonies);
1356     foreach $phonies ('-data', '-exec', 'dirs')
1357     {
1358         push (@phony, 'install' . $phonies . '-recursive');
1359         push (@phony, 'uninstall' . $phonies . '-recursive');
1360     }
1361     foreach $phonies ('all', 'check', 'installcheck', 'info', 'dvi')
1362     {
1363         push (@phony, $phonies . '-recursive');
1364     }
1365     &push_phony_cleaners ('recursive');
1367     push (@check, "check-recursive");
1368     push (@installcheck, "installcheck-recursive");
1369     push (@info, "info-recursive");
1370     push (@dvi, "dvi-recursive");
1372     $recursive_install = 1;
1375 # Handle remaking and configure stuff.
1376 sub handle_configure
1378     # If SUBDIRS defined, require AC_PROG_MAKE_SET.
1379     &am_line_error ('SUBDIRS', "AC_PROG_MAKE_SET must be used in configure.in")
1380         if &variable_defined ('SUBDIRS') && ! $seen_make_set;
1382     # Look for some files we need.  Always check for these.
1383     &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs');
1385     local ($top_reldir);
1386     if ($relative_dir ne '.')
1387     {
1388         # In subdirectory.
1389         $output_rules .= &file_contents ('remake-subd');
1390         $top_reldir = '../';
1391     }
1392     else
1393     {
1394         if (-f 'aclocal.m4')
1395         {
1396             $output_vars .= "ACLOCAL = aclocal.m4\n";
1397             &push_dist_common ('aclocal.m4');
1398         }
1399         $output_rules .= &file_contents ('remake');
1401         &am_error
1402             ("\`install.sh' is an anachronism; use \`install-sh' instead")
1403                 if -f $relative_dir . '/install.sh';
1405         # If we have a configure header, require it.
1406         if ($config_header)
1407         {
1408             # FIXME this restriction should be lifted.
1409             # FIXME first see if it is even needed as-is.
1410             &am_conf_line_error ($config_header_line,
1411                                  "argument to AC_CONFIG_HEADER contains \`/'\n")
1412                 if ($config_header =~ /\//);
1414             &require_file_with_conf_line ($config_header_line,
1415                                           $FOREIGN, $config_header);
1417             # Header defined and in this directory.
1418             if (-f 'acconfig.h')
1419             {
1420                 $output_vars .= "ACCONFIG = acconfig.h\n";
1421                 &push_dist_common ('acconfig.h');
1422             }
1423             if (-f $config_name . '.top')
1424             {
1425                 $output_vars .= "CONFIG_TOP = ${config_name}.top\n";
1426                 &push_dist_common ($config_name . '.top');
1427             }
1428             if (-f $config_name . '.bot')
1429             {
1430                 $output_vars .= "CONFIG_BOT = ${config_name}.bot\n";
1431                 &push_dist_common ($config_name . '.bot');
1432             }
1434             &require_file_with_conf_line ($config_header_line, $FOREIGN,
1435                                           'stamp-h.in');
1437             $output_rules .= &file_contents ('remake-hdr');
1438             $output_vars .= "CONFIG_HEADER_IN = ${config_header}\n";
1439         }
1441         $top_reldir = '';
1442     }
1444     # Set location of mkinstalldirs.
1445     if ($config_aux_dir ne '.' && $config_aux_dir ne '')
1446     {
1447         $output_vars .= 'mkinstalldirs = ' . $config_aux_dir;
1448     }
1449     else
1450     {
1451         $output_vars .= 'mkinstalldirs = $(top_srcdir)';
1452     }
1453     $output_vars .= '/mkinstalldirs' . "\n";
1455     &am_line_error ('CONFIG_HEADER',
1456                     "\`CONFIG_HEADER' is an anachronism; now determined from \`configure.in'")
1457         if &variable_defined ('CONFIG_HEADER');
1459     # Generate CONFIG_HEADER define, and define interally.
1460     $output_vars .= "CONFIG_HEADER = ${top_builddir}/${config_name}\n"
1461         if $config_name;
1462     $contents{'CONFIG_HEADER'} = "${top_builddir}/${config_name}"
1463         if $config_name;
1465     # Now look for other files in this directory which must be remade
1466     # by config.status, and generate rules for them.
1467     local ($file, $local, $input);
1468     foreach $file (@other_input_files)
1469     {
1470         # Skip files not in this directory, any Makefile, and the
1471         # config header.  These last two must be handled specially.
1472         next unless &dirname ($file) eq $relative_dir;
1473         next if $file eq $top_builddir . '/' . $config_name;
1474         ($local = $file) =~ s/^.*\///;
1475         next if $local eq 'Makefile';
1477         if ($local =~ /^(.*):(.*)$/)
1478         {
1479             # This is the ":" syntax of AC_OUTPUT.
1480             $input = $2;
1481             $local = $1;
1482         }
1483         else
1484         {
1485             # Normal usage.
1486             $input = $local . '.in';
1487         }
1488         # FIXME when using autoconf ":" syntax, should we set CONFIG_FILES
1489         # to $local:$input?
1490         $output_rules .= ($local . ': '
1491                           . '$(top_builddir)/config.status ' . $input . "\n"
1492                           . "\t"
1493                           . 'cd $(top_builddir) && CONFIG_FILES='
1494                           . ($relative_dir eq '.' ? '' : '$(subdir)/')
1495                           . '$@ CONFIG_HEADERS= ./config.status'
1496                           . "\n");
1498         &require_file_with_conf_line ($ac_output_line, $FOREIGN,
1499                                       $local . '.in');
1500     }
1503 # Handle C headers.
1504 sub handle_headers
1506     &am_install_var ('header', 'HEADERS', 'include',
1507                      'oldinclude', 'pkginclude',
1508                      'noinst', 'check');
1511 sub handle_gettext
1513     return if ! $seen_gettext || $relative_dir ne '.';
1515     # As of 0.10.6, gettext still wants @INTLSUB@ and @POSUB@ in
1516     # SUBDIRS.  This is going to change in a future version.  So for
1517     # now we simply do no checking.
1518     if (0 && &variable_defined ('SUBDIRS'))
1519     {
1520         &am_line_error
1521             ('SUBDIRS',
1522              "ud_GNU_GETTEXT in configure.in but \`po' not in SUBDIRS")
1523                 if $contents{'SUBDIRS'} !~ /\bpo\b/;
1524         &am_line_error
1525             ('SUBDIRS',
1526              "ud_GNU_GETTEXT in configure.in but \`intl' not in SUBDIRS")
1527                 if $contents{'SUBDIRS'} !~ /\bintl\b/;
1528     }
1530     # Ensure that each language in ALL_LINGUAS has a .po file, and
1531     # each po file is mentioned in ALL_LINGUAS.
1532     if ($seen_linguas)
1533     {
1534         local (%linguas) = ();
1535         grep ($linguas{$_} = 1, split (/\s+/, $all_linguas));
1537         foreach (<po/*.po>)
1538         {
1539             s/^po\///;
1540             s/\.po$//;
1542             &am_line_error ($all_linguas_line,
1543                             ("po/$_.po exists but \`$_' not in \`ALL_LINGUAS'"))
1544                 if ! $linguas{$_};
1545         }
1547         foreach (keys %linguas)
1548         {
1549             &am_line_error ($all_linguas_line,
1550                             "$_ in \`ALL_LINGUAS' but po/$_.po does not exist")
1551                 if ! -f "po/$_.po";
1552         }
1553     }
1554     else
1555     {
1556         &am_error ("ud_GNU_GETTEXT in configure.in but \`ALL_LINGUAS' not defined");
1557     }
1560 # Handle footer elements.
1561 sub handle_footer
1563     if ($contents{'SOURCES'})
1564     {
1565         &pretty_print ('SOURCES =', "",
1566                        split (/\s+/, $contents{'SOURCES'}));
1567     }
1568     if ($contents{'OBJECTS'})
1569     {
1570         &pretty_print ('OBJECTS =', "",
1571                        split (/\s+/, $contents{'OBJECTS'}));
1572     }
1573     if ($contents{'SOURCES'} || $contents{'OBJECTS'})
1574     {
1575         $output_vars .= "\n";
1576     }
1578     if (defined $contents{'SUFFIXES'})
1579     {
1580         push (@suffixes, '$(SUFFIXES)');
1581     }
1583     $output_trailer .= ".SUFFIXES:\n";
1584     if (@suffixes)
1585     {
1586         $output_trailer .= ".SUFFIXES: " . join (' ', @suffixes) . "\n";
1587     }
1588     $output_trailer .= &file_contents ('footer');
1591 # Deal with installdirs target.
1592 sub handle_installdirs
1594     # GNU Makefile standards recommend this.
1595     $output_rules .= ("installdirs:"
1596                       . ($recursive_install
1597                          ? " installdirs-recursive\n"
1598                          : "\n"));
1599     push (@phony, 'installdirs');
1600     if (@installdirs)
1601     {
1602         &pretty_print_rule ("\t" . '$(mkinstalldirs) ', "\t\t",
1603                             @installdirs);
1604     }
1605     $output_rules .= "\n";
1608 # There are several targets which need to be merged.  This is because
1609 # their complete definition is compiled from many parts.  Note that we
1610 # avoid double colon rules, otherwise we'd use them instead.
1611 sub handle_merge_targets
1613     push (@all, 'Makefile');
1614     push (@all, $config_name)
1615         if $config_name && &dirname ($config_name) eq $relative_dir;
1617     &do_one_merge_target ('info', @info);
1618     &do_one_merge_target ('dvi', @dvi);
1620     if (! &variable_defined ('SUBDIRS') || $relative_dir ne '.')
1621     {
1622         # 'check' must depend on 'all', but not at top level.
1623         # Ditto install.
1624         unshift (@check, 'all');
1625         unshift (@install, 'all');
1626     }
1627     &do_one_merge_target ('check', @check);
1628     &do_one_merge_target ('installcheck', @installcheck);
1630     # Handle the various install targets specially.  We do this so
1631     # that (eg) "make install-exec" will run "install-exec-recursive"
1632     # if required, but "make install" won't run it twice.  Step one is
1633     # to see if the user specified local versions of any of the
1634     # targets we handle.  "all" is treated as one of these since
1635     # "install" can run it.
1636     push (@install_exec, 'install-exec-local')
1637         if defined $contents{'install-exec-local'};
1638     push (@install_data, 'install-data-local')
1639         if defined $contents{'install-data-local'};
1640     push (@uninstall, 'uninstall-local')
1641         if defined $contents{'uninstall-local'};
1642     push (@all, 'all-local')
1643         if defined $contents{'all-local'};
1645     if (defined $contents{'install-local'})
1646     {
1647         &am_line_error ('install-local',
1648                         "use \`install-data' or \`install-exec', not \`install'");
1649     }
1651     # Step two: if we are doing recursive makes, write out the
1652     # appropriate rules.
1653     local (@install);
1654     if ($recursive_install)
1655     {
1656         push (@install, 'install-recursive');
1658         if (@all)
1659         {
1660             local (@hackall) = ();
1661             if ($config_name && &dirname ($config_name) eq $relative_dir)
1662             {
1664                 # This is kind of a hack, but I couldn't see a better
1665                 # way to handle it.  In this particular case, we need
1666                 # to make sure config.h is built before we recurse.
1667                 # We can't do this by changing the order of
1668                 # dependencies to the "all" because that breaks when
1669                 # using parallel makes.  Instead we handle things
1670                 # explicitly.
1671                 $output_rules .= ('all-recursive-hack: $(CONFIG_HEADER)'
1672                                   . "\n\t" . '$(MAKE) all-recursive'
1673                                   . "\n\n");
1674                 push (@hackall, 'all-recursive-hack');
1675                 push (@phony, 'all-recursive-hack');
1676             }
1677             else
1678             {
1679                 push (@hackall, 'all-recursive');
1680             }
1682             $output_rules .= ('all-am: '
1683                               . join (' ', @all)
1684                               . "\n\n");
1685             @all = @hackall;
1686             push (@all, 'all-am');
1687             push (@phony, 'all-am');
1688         }
1689         else
1690         {
1691             @all = ('all-recursive');
1692         }
1693         if (@install_exec)
1694         {
1695             $output_rules .= ('install-exec-am: '
1696                               . join (' ', @install_exec)
1697                               . "\n\n");
1698             @install_exec = ('install-exec-recursive', 'install-exec-am');
1699             push (@install, 'install-exec-am');
1700             push (@phony, 'install-exec-am');
1701         }
1702         else
1703         {
1704             @install_exec = ('install-exec-recursive');
1705         }
1706         if (@install_data)
1707         {
1708             $output_rules .= ('install-data-am: '
1709                               . join (' ', @install_data)
1710                               . "\n\n");
1711             @install_data = ('install-data-recursive', 'install-data-am');
1712             push (@install, 'install-data-am');
1713             push (@phony, 'install-data-am');
1714         }
1715         else
1716         {
1717             @install_data = ('install-data-recursive');
1718         }
1719         if (@uninstall)
1720         {
1721             $output_rules .= ('uninstall-am: '
1722                               . join (' ', @uninstall)
1723                               . "\n\n");
1724             @uninstall = ('uninstall-recursive', 'uninstall-am');
1725             push (@phony, 'uninstall-am');
1726         }
1727         else
1728         {
1729             @uninstall = ('uninstall-recursive');
1730         }
1731     }
1733     # Step three: print definitions users can use.  Code below knows
1734     # that install-exec is done before install-data, beware.
1735     $output_rules .= ("install-exec: "
1736                       . join (' ', @install_exec)
1737                       . "\n");
1738     if (defined $contents{'install-exec-hook'})
1739     {
1740         $output_rules .= "\t" . '$(MAKE) install-exec-hook' . "\n";
1741     }
1742     $output_rules .= "\n";
1743     push (@install, 'install-exec') if !$recursive_install;
1744     push (@phony, 'install-exec');
1746     $output_rules .= ("install-data: "
1747                       . join (' ', @install_data)
1748                       . "\n");
1749     if (defined $contents{'install-data-hook'})
1750     {
1751         $output_rules .= "\t" . '$(MAKE) install-data-hook' . "\n";
1752     }
1753     $output_rules .= "\n";
1754     push (@install, 'install-data') if !$recursive_install;
1755     push (@phony, 'install-data');
1757     # If no dependencies for 'install', add 'all'.  Why?  That way
1758     # "make install" at top level of distclean'd distribution won't
1759     # fail because stuff in 'lib' fails to build.
1760     if (! @install || ($#install == 1
1761                        && $install[0] eq 'install-exec'
1762                        && $install[1] eq 'install-data'))
1763     {
1764         push (@install, 'all');
1765     }
1766     $output_rules .= ('install: '
1767                       . join (' ', @install)
1768                       # Use "@:" as empty command so nothing prints.
1769                       . "\n\t\@:"
1770                       . "\n\n"
1771                       . 'uninstall: '
1772                       . join (' ', @uninstall)
1773                       . "\n\n");
1774     push (@phony, 'install', 'uninstall');
1776     $output_rules .= ('all: '
1777                       . join (' ', @all)
1778                       . "\n\n");
1779     push (@phony, 'all');
1781     # Generate the new 'install-strip' target.
1782     $output_rules .= ("install-strip:\n\t"
1783                       . '$(MAKE) INSTALL_PROGRAM=\'$(INSTALL_PROGRAM) -s\' install'
1784                       . "\n");
1787 # Helper for handle_merge_targets.
1788 sub do_one_merge_target
1790     local ($name, @values) = @_;
1792     if (defined $contents{$name . '-local'})
1793     {
1794         # User defined local form of target.  So include it.
1795         push (@values, $name . '-local');
1796         push (@phony, $name . '-local');
1797     }
1799     $output_rules .= $name . ":";
1800     if (@values)
1801     {
1802         $output_rules .= ' ' . join (' ', @values);
1803     }
1804     $output_rules .= "\n\n";
1805     push (@phony, $name);
1808 # Handle all 'clean' targets.
1809 sub handle_clean
1811     push (@clean, 'generic');
1812     $output_rules .= &file_contents ('clean');
1813     &push_phony_cleaners ('generic');
1815     local ($target) = $recursive_install ? 'clean-am' : 'clean';
1816     &do_one_clean_target ($target, 'mostly', '', @clean);
1817     &do_one_clean_target ($target, '', 'mostly', @clean);
1818     &do_one_clean_target ($target, 'dist', '', @clean);
1819     &do_one_clean_target ($target, 'maintainer-', 'dist', @clean);
1821     push (@phony, 'clean', 'mostlyclean', 'distclean', 'maintainer-clean');
1823     local (@deps);
1824     if ($recursive_install)
1825     {
1826         @deps = ('am', 'recursive');
1827         &do_one_clean_target ('', 'mostly', '', @deps);
1828         &do_one_clean_target ('', '', '', @deps);
1829         &do_one_clean_target ('', 'dist', '', @deps);
1830         &do_one_clean_target ('', 'maintainer-', '', @deps);
1831     }
1834 # Helper for handle_clean.
1835 sub do_one_clean_target
1837     local ($target, $name, $last_name, @deps) = @_;
1839     # Special case: if target not passed, then don't generate
1840     # dependency on next "lower" clean target (eg no
1841     # clean<-mostlyclean derivation).  In this case the target is
1842     # implicitly known to be 'clean'.
1843     local ($flag) = $target;
1844     $target = 'clean' if ! $flag;
1846     grep (($_ = $name . 'clean-' . $_) && 0, @deps);
1847     if ($flag)
1848     {
1849         if ($last_name || $name ne 'mostly')
1850         {
1851             push (@deps, $last_name . $target . " ");
1852         }
1853     }
1854     # FIXME not sure if I like the tabs here.
1855     &pretty_print_rule ($name . $target . ": ", "\t\t", @deps);
1857     # FIXME shouldn't we really print these messages before running
1858     # the dependencies?
1859     if ($name . $target eq 'maintainer-clean')
1860     {
1861         # Print a special warning.
1862         $output_rules .=
1863             ("\t\@echo \"This command is intended for maintainers to use;\"\n"
1864              . "\t\@echo \"it deletes files that may require special "
1865              . "tools to rebuild.\"\n");
1867         $output_rules .= "\trm -f config.status\n"
1868             if $relative_dir eq '.';
1869     }
1870     elsif ($name . $target eq 'distclean')
1871     {
1872         $output_rules .= "\trm -f config.status\n";
1873     }
1874     $output_rules .= "\n";
1877 # Handle .PHONY target.
1878 sub handle_phony
1880     &pretty_print_rule ('.PHONY:', "", @phony);
1881     $output_rules .= "\n";
1884 # Handle TESTS variable.
1885 sub handle_tests
1887     return if ! &variable_defined ('TESTS');
1889     &push_dist_common (split (/\s+/, $contents{'TESTS'}));
1890     push (@check, 'check-TESTS');
1891     push (@phony, 'check-TESTS');
1892     # FIXME use $(SHELL) here?  That is what Ulrich suggests.  Maybe a
1893     # new macro, $(TEST_SHELL), a la $(CONFIG_SHELL)?  For now we just
1894     # execute the file directly; this allows test files which are
1895     # compiled -- a possibly useful feature.
1896     $output_rules .= 'check-TESTS: $(TESTS)
1897         @failed=0; all=0; \\
1898         srcdir=$(srcdir); export srcdir; \\
1899         for tst in $(TESTS); do \\
1900           all=`expr $$all + 1`; \\
1901           if test -f $$tst; then dir=.; \\
1902           else dir="$(srcdir)"; fi; \\
1903           if $$dir/$$tst; then \\
1904             echo "PASS: $$tst"; \\
1905           else \\
1906             failed=`expr $$failed + 1`; \\
1907             echo "FAIL: $$tst"; \\
1908           fi; \\
1909         done; \\
1910         if test "$$failed" -eq 0; then \\
1911           echo "========================"; \\
1912           echo "All $$all tests passed"; \\
1913           echo "========================"; \\
1914         else \\
1915           echo "$$failed of $$all tests failed"; \\
1916         fi
1920 ################################################################
1922 # Scan configure.in for interesting things.
1923 # FIXME ensure VERSION, PACKAGE are set.
1924 sub scan_configure
1926     open (CONFIGURE, 'configure.in')
1927         || die "automake: couldn't open \`configure.in': $!\n";
1928     print "automake: reading configure.in\n" if $verbose;
1930     # Reinitialize libsources here.  This isn't really necessary,
1931     # since we currently assume there is only one configure.in.  But
1932     # that won't always be the case.
1933     %libsources = ();
1935     local ($in_ac_output, @make_list) = 0;
1936     local ($libobj_iter);
1937     while (<CONFIGURE>)
1938     {
1939         # Remove comments from current line.
1940         s/\bdnl\b.*$//;
1941         s/\#.*$//;
1943         # Populate libobjs array.
1944         if (/AC_FUNC_ALLOCA/)
1945         {
1946             $libsources{'alloca.c'} = 1;
1947         }
1948         elsif (/AC_FUNC_GETLOADAVG/)
1949         {
1950             $libsources{'getloadavg.c'} = 1;
1951         }
1952         elsif (/AC_FUNC_MEMCMP/)
1953         {
1954             $libsources{'memcmp.c'} = 1;
1955         }
1956         elsif (/AC_STRUCT_ST_BLOCKS/)
1957         {
1958             $libsources{'fileblocks.c'} = 1;
1959         }
1960         elsif (/(AC|fp)_FUNC_FNMATCH/)
1961         {
1962             # AC_FUNC_FNMATCH is just wishful thinking at this point.
1963             $libsources{'fnmatch.c'} = 1;
1964         }
1965         elsif (/AC_REPLACE_FUNCS\s*\((.*)\)/)
1966         {
1967             foreach (split (/\s+/, $1))
1968             {
1969                 $libsources{$_ . '.c'} = 1;
1970             }
1971         }
1972         elsif (/AC_REPLACE_GNU_GETOPT/)
1973         {
1974             $libsources{'getopt.c'} = 1;
1975             $libsources{'getopt1.c'} = 1;
1976         }
1977         elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
1978                || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
1979         {
1980             foreach $libobj_iter (split (/\s+/, $1))
1981             {
1982                 if ($libobj_iter =~ /^(.*)\.o$/)
1983                 {
1984                     $libsources{$1 . '.c'} = 1;
1985                 }
1986             }
1987         }
1989         # Process the AC_OUTPUT macro.
1990         if (! $in_ac_output && s/AC_OUTPUT\s*\(\[?//)
1991         {
1992             $in_ac_output = 1;
1993             $ac_output_line = $.;
1994         }
1995         if ($in_ac_output)
1996         {
1997             $in_ac_output = 0 if s/[\]\),].*$//;
1999             # Look at potential Makefile.am's.
2000             foreach (split)
2001             {
2002                 next if $_ eq "\\";
2003                 if (-f $_ . '.am')
2004                 {
2005                     push (@make_list, $_);
2006                 }
2007                 else
2008                 {
2009                     push (@other_input_files, $_);
2010                 }
2011             }
2012         }
2014         if (/AC_CONFIG_AUX_DIR\(([^)]+)\)/)
2015         {
2016             @config_aux_path = $1;
2017         }
2019         # Check for ansi2knr.
2020         $fp_c_prototypes = 1 if /fp_C_PROTOTYPES/;
2022         # Check for NLS support.
2023         if (/ud_GNU_GETTEXT/)
2024         {
2025             $seen_gettext = 1;
2026             $ac_gettext_line = $.;
2027         }
2029         # Look for ALL_LINGUAS.
2030         if (/ALL_LINGUAS="(.*)"$/ || /ALL_LINGUAS=(.*)$/)
2031         {
2032             $seen_linguas = 1;
2033             $all_linguas = $1;
2034             $all_linguas_line = $.;
2035         }
2037         # Handle configuration headers.
2038         if (/AC_CONFIG_HEADER\s*\((.*)\)/)
2039         {
2040             $config_header_line = $.;
2041             $config_name = $1;
2042             if ($config_name =~ /^([^:]+):(.+)$/)
2043             {
2044                 $config_name = $1;
2045                 $config_header = $2;
2046             }
2047             else
2048             {
2049                 $config_header = $config_name . '.in';
2050             }
2051         }
2053         $seen_canonical = 1 if /AC_CANONICAL_(HOST|SYSTEM)/;
2054         $seen_canonical = 1 if /AC_CHECK_TOOL/;
2055         $seen_path_xtra = 1 if /AC_PATH_XTRA/;
2057         # Sometimes it is desirable to explicitly set YACC.  For
2058         # instance some people don't want to use bison.
2059         $seen_prog_yacc = 1 if (/AC_PROG_YACC/
2060                                 || /AC_SUBST\(YACC\)/
2061                                 || /AC_(PATH|CHECK)_PROGS?\(YACC/);
2063         # Some things required by Automake.
2064         $seen_make_set = 1 if /AC_PROG_MAKE_SET/;
2065         $seen_prog_install = 1 if ! $seen_prog_install && /AC_PROG_INSTALL/;
2066         $seen_prog_install = 2 if ! $seen_prog_install && /fp_PROG_INSTALL/;
2067         $seen_arg_prog = 1 if /AC_ARG_PROGRAM/;
2068         $seen_ranlib = 1 if /AC_PROG_RANLIB/;
2069         $seen_maint_mode = 1 if /jm_MAINTAINER_MODE/;
2071         if (/AC_PROG_LIBTOOL/ || /gm_PROG_LIBTOOL/)
2072         {
2073             $seen_libtool = 1;
2074             $seen_ranlib = 2;
2075             $libtool_line = $.;
2076         }
2077     }
2079     # Set input files if not specified by user.
2080     @input_files = @make_list if (! @input_files);
2082     close (CONFIGURE);
2085 ################################################################
2087 # Do any extra checking for GNU standards.
2088 sub check_gnu_standards
2090     if ($relative_dir eq '.')
2091     {
2092         # In top level (or only) directory.
2093         &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
2094                        'AUTHORS', 'ChangeLog');
2095     }
2098 # Do any extra checking for GNITS standards.
2099 sub check_gnits_standards
2101     if ($strictness >= $GNITS && -f $relative_dir . '/COPYING.LIB')
2102     {
2103         &am_error
2104             ("\`${relative_dir}/COPYING.LIB' disallowed by Gnits standards");
2105     }
2107     if ($relative_dir eq '.')
2108     {
2109         # In top level (or only) directory.
2110         &require_file ($GNITS, 'THANKS');
2111     }
2114 ################################################################
2116 # Pretty-print something.  HEAD is what should be printed at the
2117 # beginning of the first line, FILL is what should be printed at the
2118 # beginning of every subsequent line.
2119 sub pretty_print_internal
2121     local ($head, $fill, @values) = @_;
2123     local ($column) = length ($head);
2124     local ($result) = $head;
2126     # Fill length is number of characters.  However, each Tab
2127     # character counts for eight.  So we count the number of Tabs and
2128     # multiply by 7.
2129     local ($fill_length) = length ($fill);
2130     $fill_length += 7 * ($fill =~ tr/\t/\t/d);
2132     local ($bol) = 0;
2133     foreach (@values)
2134     {
2135         # "71" because we also print a space.
2136         if ($column + length ($_) > 71)
2137         {
2138             $result .= " \\\n" . $fill;
2139             $column = $fill_length;
2140             $bol = 1;
2141         }
2143         $result .= ' ' unless ($bol);
2144         $result .= $_;
2145         $column += length ($_) + 1;
2146         $bol = 0;
2147     }
2149     $result .= "\n";
2150     return $result;
2153 # Pretty-print something and append to output_vars.
2154 sub pretty_print
2156     $output_vars .= &pretty_print_internal (@_);
2159 # Pretty-print something and append to output_rules.
2160 sub pretty_print_rule
2162     $output_rules .= &pretty_print_internal (@_);
2166 ################################################################
2168 # See if a variable exists.
2169 sub variable_defined
2171     local ($var) = @_;
2172     if (defined $targets{$var})
2173     {
2174         &am_line_error ($var, "\`$var' is target; expected variable");
2175     }
2176     return (defined $contents{$var} && ! defined $targets{$var});
2179 # Read Makefile.am and set up %contents.  Simultaneously copy lines
2180 # from Makefile.am into $output_trailer or $output_vars as
2181 # appropriate.  NOTE we put rules in the trailer section.  We want
2182 # user rules to come after our generated stuff.
2183 sub read_am_file
2185     local ($amfile) = @_;
2187     # Compute relative location of the top object directory.
2188     local (@topdir) = ();
2189     foreach (split (/\//, $relative_dir))
2190     {
2191         next if $_ eq '.' || $_ eq '';
2192         if ($_ eq '..')
2193         {
2194             pop @topdir;
2195         }
2196         else
2197         {
2198             push (@topdir, '..');
2199         }
2200     }
2201     @topdir = ('.') if ! @topdir;
2203     $top_builddir = join ('/', @topdir);
2204     local ($build_rx);
2205     ($build_rx = $top_builddir) =~ s/(\W)/\\$1/g;
2206     local ($header_vars) =
2207         &file_contents_with_transform
2208             ('s/\@top_builddir\@/' . $build_rx . '/g',
2209              'header-vars');
2211     open (AM_FILE, $amfile) || die "automake: couldn't open \`$amfile': $!\n";
2212     print "automake: reading $amfile\n" if $verbose;
2214     $output_vars .= ("# $in_file_name generated automatically by automake "
2215                      . $VERSION . " from $am_file_name\n");
2217     # Generate copyright for generated Makefile.in.
2218     $output_vars .= $gen_copyright;
2220     local ($saw_bk) = 0;
2221     local ($was_rule) = 0;
2222     local ($spacing) = '';
2223     local ($comment) = '';
2224     local ($last_var_name) = '';
2225     local ($blank) = 0;
2227     while (<AM_FILE>)
2228     {
2229         if (/$IGNORE_PATTERN/o)
2230         {
2231             # Merely delete comments beginning with two hashes.
2232         }
2233         elsif (/$WHITE_PATTERN/o)
2234         {
2235             # Stick a single white line before the incoming macro or rule.
2236             $spacing = "\n";
2237             $blank = 1;
2238         }
2239         elsif (/$COMMENT_PATTERN/o)
2240         {
2241             # Stick comments before the incoming macro or rule.  Make
2242             # sure a blank line preceeds comments.
2243             $spacing = "\n" unless $blank;
2244             $comment .= $spacing . $_;
2245             $spacing = '';
2246         }
2247         else
2248         {
2249             last;
2250         }
2251     }
2253     $output_vars .= $comment . "\n" . $header_vars;
2254     $comment = '';
2255     $spacing = "\n";
2257     local ($is_ok_macro);
2258     while ($_)
2259     {
2260         $_ .= "\n"
2261             unless substr ($_, -1, 1) eq "\n";
2263         $_ =~ s/\@MAINT\@//g
2264             unless $seen_maint_mode;
2266         if (/$IGNORE_PATTERN/o)
2267         {
2268             # Merely delete comments beginning with two hashes.
2269         }
2270         elsif (/$WHITE_PATTERN/o)
2271         {
2272             # Stick a single white line before the incoming macro or rule.
2273             $spacing = "\n";
2274         }
2275         elsif (/$COMMENT_PATTERN/o)
2276         {
2277             # Stick comments before the incoming macro or rule.
2278             $comment .= $spacing . $_;
2279             $spacing = '';
2280         }
2281         elsif ($saw_bk)
2282         {
2283             if ($was_rule)
2284             {
2285                 $output_trailer .= $_;
2286                 $saw_bk = /\\$/;
2287             }
2288             else
2289             {
2290                 $output_vars .= $_;
2291                 $saw_bk = /\\$/;
2292                 # Chop newline and backslash if this line is
2293                 # continued.  FIXME maybe ensure trailing whitespace
2294                 # exists?
2295                 chop if $saw_bk;
2296                 chop if $saw_bk;
2297                 $contents{$last_var_name} .= $_;
2298             }
2299         }
2300         elsif (/$RULE_PATTERN/o)
2301         {
2302             # warn "** Saw rule .$1.\n";
2303             # Found a rule.
2304             $was_rule = 1;
2305             # Value here doesn't matter; for targets we only note
2306             # existence.
2307             $contents{$1} = 1;
2308             $targets{$1} = 1;
2309             $content_lines{$1} = $.;
2310             $output_trailer .= $comment . $spacing . $_;
2311             $comment = $spacing = '';
2312             $saw_bk = /\\$/;
2313         }
2314         elsif (($is_ok_macro = /$MACRO_PATTERN/o)
2315                || /$BOGUS_MACRO_PATTERN/o)
2316         {
2317             # Found a macro definition.
2318             $was_rule = 0;
2319             $last_var_name = $1;
2320             if (substr ($2, -1) eq "\\")
2321             {
2322                 $contents{$1} = substr ($2, 0, length ($2) - 1);
2323             }
2324             else
2325             {
2326                 $contents{$1} = $2;
2327             }
2328             $content_lines{$1} = $.;
2329             $output_vars .= $comment . $spacing . $_;
2330             $comment = $spacing = '';
2331             $saw_bk = /\\$/;
2333             # Error if bogus.
2334             &am_line_error ($., "bad macro name \`$1'")
2335                 if ! $is_ok_macro;
2336         }
2337         else
2338         {
2339             # This isn't an error; it is probably a continued rule.
2340             # In fact, this is what we assume.
2341             $was_rule = 1;
2342             $output_trailer .= $comment . $spacing . $_;
2343             $comment = $spacing = '';
2344             $saw_bk = /\\$/;
2345         }
2347         $_ = <AM_FILE>;
2348     }
2350     $output_trailer .= $comment;
2353 ################################################################
2355 sub initialize_global_constants
2357     # Associative array of standard directory names.  Entry is TRUE if
2358     # corresponding directory should be installed during
2359     # 'install-exec' phase.
2360     %exec_dir_p =
2361         ('bin', 1,
2362          'sbin', 1,
2363          'libexec', 1,
2364          'data', 0,
2365          'sysconf', 1,
2366          'localstate', 1,
2367          'lib', 1,
2368          'info', 0,
2369          'man', 0,
2370          'include', 0,
2371          'oldinclude', 0,
2372          'pkgdata', 0,
2373          'pkglib', 1,
2374          'pkginclude', 0
2375          );
2377     # Helper text for dealing with man pages.
2378     $install_man_format =
2379     '   @sect=@SECTION@;                                \\
2380         inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
2381         echo installing @MAN@ as $(mandir)/man$$sect/$$inst; \\
2382         $(INSTALL_DATA) $(srcdir)/@MAN@ $(mandir)/man$$sect/$$inst
2385     $uninstall_man_format =
2386     '   inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
2387         rm -f $(mandir)/man@SECTION@/$$inst
2390     # Commonly found files we look for and automatically include in
2391     # DISTFILES.
2392     @common_files =
2393         (
2394          "README", "THANKS", "TODO", "NEWS", "COPYING", "COPYING.LIB",
2395          "INSTALL", "ABOUT-NLS", "ChangeLog", "configure", "configure.in",
2396          "config.guess", "config.sub", "AUTHORS", "BACKLOG", "ABOUT-GNU",
2397          "libversion.in"
2398          );
2400     # Commonly used files we auto-include, but only sometimes.
2401     @common_sometimes =
2402         (
2403          "version.texi", "aclocal.m4", "acconfig.h", "config.h.top",
2404          "config.h.bot", "stamp-h.in", "mdate-sh", "ansi2knr.c",
2405          "ansi2knr.1", 'stamp-vti', "mkinstalldirs", "install-sh"
2406          );
2408     $USAGE = "\
2409   --amdir=DIR           directory storing config files
2410   --foreign             same as --strictness=foreign
2411   --gnits               same as --strictness=gnits
2412   --gnu                 same as --strictness=gnu
2413   --help                print this help, then exit
2414   -i, --include-deps    include generated dependencies in Makefile.in
2415   -a, --add-missing     add missing standard files to package
2416   -o DIR, --output-dir=DIR
2417                         put generated Makefile.in's into DIR
2418   -s LEVEL, --strictness=LEVEL
2419                         set strictness level.  LEVEL is foreign, gnu, gnits
2420   -v, --verbose         verbosely list files processed
2421   --version             print version number, then exit\n";
2423     # Copyright on generated Makefile.ins.
2424     $gen_copyright = "\
2425 # Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
2426 # This Makefile.in is free software; the Free Software Foundation
2427 # gives unlimited permission to copy, distribute and modify it.
2431 # (Re)-Initialize per-Makefile.am variables.
2432 sub initialize_per_input
2434     # These two variables are used when generating each Makefile.in.
2435     # They hold the Makefile.in until it is ready to be printed.
2436     $output_rules = '';
2437     $output_vars = '';
2438     $output_trailer = '';
2440     # Suffixes found during a run.
2441     @suffixes = ();
2443     # This holds the contents of a Makefile.am, as parsed by
2444     # read_am_file.
2445     %contents = ();
2447     # This holds the names which are targets.  These also appear in
2448     # %contents.
2449     %targets = ();
2451     # This holds the line numbers at which various elements of
2452     # %contents are defined.
2453     %content_lines = ();
2455     # This holds the "relative directory" of the current Makefile.in.
2456     # Eg for src/Makefile.in, this is "src".
2457     $relative_dir = '';
2459     # Directory where output files go.  Actually, output files are
2460     # relative to this directory.
2461     $output_directory = '.';
2463     # This holds a list of files that are included in the
2464     # distribution.
2465     %dist_common = ();
2467     # List of dependencies for the obvious targets.
2468     @install_data = ();
2469     @install_exec = ();
2470     @uninstall = ();
2471     @installdirs = ();
2473     @info = ();
2474     @dvi = ();
2475     @all = ();
2476     @check = ();
2477     @installcheck = ();
2478     @clean = ();
2480     @phony = ();
2482     # These are pretty obvious, too.  They are used to define the
2483     # SOURCES and OBJECTS variables.
2484     @sources = ();
2485     @objects = ();
2487     # TRUE if current directory holds any C source files.  (Actually
2488     # holds object extension, but this information is encapsulated in
2489     # the function get_object_extension).
2490     $dir_holds_sources = '';
2492     # TRUE if install targets should work recursively.
2493     $recursive_install = 0;
2495     # All .P files.
2496     %dep_files = ();
2498     # Strictness levels.
2499     $strictness = $default_strictness;
2500     $strictness_name = $default_strictness_name;
2502     # Options from AUTOMAKE_OPTIONS.
2503     %options = ();
2505     # Whether or not dependencies are handled.  Can be further changed
2506     # in handle_options.
2507     $use_dependencies = $cmdline_use_dependencies;
2509     # Per Makefile.am.
2510     $local_maint_charset = $maint_charset;
2514 ################################################################
2516 # Return contents of a file from $am_dir, automatically skipping
2517 # macros or rules which are already known.  Runs command on each line
2518 # as it is read; this command can modify $_.
2519 sub file_contents_with_transform
2521     local ($command, $basename) = @_;
2522     local ($file) = $am_dir . '/' . $basename . '.am';
2524     open (FC_FILE, $file)
2525         || die "automake: installation error: cannot open \`$file'\n";
2526     # Looks stupid?
2527     # print "automake: reading $file\n" if $verbose;
2529     local ($was_rule) = 0;
2530     local ($result_vars) = '';
2531     local ($result_rules) = '';
2532     local ($comment) = '';
2533     local ($spacing) = "\n";
2534     local ($skipping) = 0;
2536     while (<FC_FILE>)
2537     {
2538         $_ =~ s/\@MAINT\@//g
2539             unless $seen_maint_mode;
2541         eval $command;
2543         if (/$IGNORE_PATTERN/o)
2544         {
2545             # Merely delete comments beginning with two hashes.
2546         }
2547         elsif (/$WHITE_PATTERN/o)
2548         {
2549             # Stick a single white line before the incoming macro or rule.
2550             $spacing = "\n";
2551         }
2552         elsif (/$COMMENT_PATTERN/o)
2553         {
2554             # Stick comments before the incoming macro or rule.
2555             $comment .= $spacing . $_;
2556             $spacing = '';
2557         }
2558         elsif ($saw_bk)
2559         {
2560             if ($was_rule)
2561             {
2562                 $result_rules .= $_ if ! $skipping;
2563             }
2564             else
2565             {
2566                 $result_vars .= $_ if ! $skipping;
2567             }
2568             $saw_bk = /\\$/;
2569         }
2570         elsif (/$RULE_PATTERN/o)
2571         {
2572             # warn "** Found rule .$1.\n";
2573             # Found a rule.
2574             $was_rule = 1;
2575             $skipping = defined $contents{$1};
2576             # warn "** Skip $skipping\n" if $skipping;
2577             $result_rules .= $comment . $spacing . $_ if ! $skipping;
2578             $comment = $spacing = '';
2579             $saw_bk = /\\$/;
2580         }
2581         elsif (/$MACRO_PATTERN/o)
2582         {
2583             # warn "** Found macro .$1.\n";
2584             # Found a variable reference.
2585             $was_rule = 0;
2586             $skipping = defined $contents{$1};
2587             # warn "** Skip $skipping\n" if $skipping;
2588             $result_vars .= $comment . $spacing . $_ if ! $skipping;
2589             $comment = $spacing = '';
2590             $saw_bk = /\\$/;
2591         }
2592         else
2593         {
2594             # This isn't an error; it is probably a continued rule.
2595             # In fact, this is what we assume.
2596             $was_rule = 1;
2597             $result_rules .= $comment . $spacing . $_ if ! $skipping;
2598             $comment = $spacing = '';
2599             $saw_bk = /\\$/;
2600         }
2601     }
2603     close (FC_FILE);
2604     return $result_vars . $result_rules . $comment;
2607 # Like file_contents_with_transform, but no transform.
2608 sub file_contents
2610     return &file_contents_with_transform ('', @_);
2613 # Handle `where_HOW' variable magic.  Does all lookups, generates
2614 # install code, and possibly generates code to define the primary
2615 # variable.  The first argument is the name of the .am file to munge,
2616 # the second argument is the primary variable (eg HEADERS), and all
2617 # subsequent arguments are possible installation locations.  Returns
2618 # list of all values of all _HOW targets.
2620 # FIXME this should be rewritten to be cleaner.  It should be broken
2621 # up into multiple functions.
2623 # Usage is: am_install_var (OPTION..., file, HOW, where...)
2624 sub am_install_var
2626     local (@args) = @_;
2628     local ($do_all, $do_clean) = (1, 0);
2629     while (@args)
2630     {
2631         if ($args[0] eq '-clean')
2632         {
2633             $do_clean = 1;
2634         }
2635         elsif ($args[0] eq '-no-all')
2636         {
2637             $do_all = 0;
2638         }
2639         elsif ($args[0] !~ /^-/)
2640         {
2641             last;
2642         }
2643         shift (@args);
2644     }
2645     local ($file, $primary, @prefixes) = @args;
2647     local (@used) = ();
2648     local (@result) = ();
2650     # Now that configure substitutions are allowed in where_HOW
2651     # variables, it is an error to actually define the primary.
2652     &am_line_error ($primary, "\`$primary' is an anachronism")
2653         if &variable_defined ($primary);
2656     # Look for misspellings.  It is an error to have a variable ending
2657     # in a "reserved" suffix whose prefix is unknown, eg
2658     # "bni_PROGRAMS".  However, unusual prefixes are allowed if a
2659     # variable of the same name (with "dir" appended) exists.  For
2660     # instance, if the variable "zardir" is defined, then
2661     # "zar_PROGRAMS" becomes valid.  This is to provide a little extra
2662     # flexibility in those cases which need it.  Perhaps it should be
2663     # disallowed in the Gnits case?  The problem is, sometimes it is
2664     # useful to put things in a subdir of eg pkgdatadir, perhaps even
2665     # for Gnitsoids.
2666     local (%valid, $varname);
2667     grep ($valid{$_} = 0, @prefixes);
2668     $valid{'EXTRA'} = 0;
2669     foreach $varname (keys %contents)
2670     {
2671         if ($varname =~ /^(.*)_$primary$/)
2672         {
2673             if (! defined $valid{$1} && ! &variable_defined ($1 . 'dir'))
2674             {
2675                 &am_line_error ($varname, "invalid variable \"$varname\"");
2676             }
2677             else
2678             {
2679                 # Ensure all extended prefixes are actually used.
2680                 $valid{$1} = 1;
2681             }
2682         }
2683     }
2685     local ($clean_file) = $file . '-clean';
2686     local ($one_name);
2687     local ($X);
2688     foreach $X (keys %valid)
2689     {
2690         $one_name = $X . '_' . $primary;
2691         if (&variable_defined ($one_name))
2692         {
2693             # Append actual contents of where_PRIMARY variable to
2694             # result.
2695             local ($rcurs);
2696             foreach $rcurs (split (/\s+/, $contents{$one_name}))
2697             {
2698                 # Skip configure substitutions.  Possibly bogus.
2699                 next if $rcurs =~ /^\@.*\@$/;
2700                 push (@result, $rcurs);
2701             }
2703             # "EXTRA" shouldn't be used when generating clean targets,
2704             # @all, or install targets.
2705             next if $X eq 'EXTRA';
2707             if ($do_clean)
2708             {
2709                 $output_rules .=
2710                     &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go',
2711                                                    $clean_file);
2713                 push (@clean, $X . $primary);
2714                 &push_phony_cleaners ($X . $primary);
2715             }
2717             if ($X eq 'check')
2718             {
2719                 push (@check, '$(' . $one_name . ')');
2720             }
2721             else
2722             {
2723                 push (@used, '$(' . $one_name . ')');
2724             }
2725             if ($X eq 'noinst' || $X eq 'check')
2726             {
2727                 # Objects which don't get installed by default.
2728                 next;
2729             }
2731             $output_rules .=
2732                 &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go',
2733                                                $file);
2735             push (@uninstall, 'uninstall-' . $X . $primary);
2736             push (@phony, 'uninstall-' . $X . $primary);
2737             push (@installdirs, '$(' . $X . 'dir)');
2738             if ($exec_dir_p{$X})
2739             {
2740                 push (@install_exec, 'install-' . $X . $primary);
2741                 push (@phony, 'install-' . $X . $primary);
2742             }
2743             else
2744             {
2745                 push (@install_data, 'install-' . $X . $primary);
2746                 push (@phony, 'install-' . $X . $primary);
2747             }
2748         }
2749     }
2751     if (@used)
2752     {
2753         # Define it.
2754         &pretty_print ($primary . ' =', '', @used);
2755         $output_vars .= "\n";
2756     }
2758     # Push here because PRIMARY might be configure time determined.
2759     push (@all, '$(' . $primary . ')')
2760         if $do_all && @used;
2762     return (@result);
2766 ################################################################
2768 # This variable is local to the "require file" set of functions.
2769 @require_file_paths = ();
2771 # Verify that the file must exist in the current directory.  Usage:
2772 # require_file (isconfigure, line_number, strictness, file) strictness
2773 # is the strictness level at which this file becomes required.  Must
2774 # set require_file_paths before calling this function.
2775 # require_file_paths is set to hold a single directory (the one in
2776 # which the first file was found) before return.
2777 sub require_file_internal
2779     local ($is_configure, $line, $mystrict, @files) = @_;
2780     local ($file, $fullfile);
2781     local ($found_it, $errfile, $errdir);
2782     local ($save_dir);
2784     foreach $file (@files)
2785     {
2786         $found_it = 0;
2787         foreach $dir (@require_file_paths)
2788         {
2789             if ($dir eq '.')
2790             {
2791                 $fullfile = $relative_dir . "/" . $file;
2792                 $errdir = $relative_dir unless $errdir;
2793             }
2794             else
2795             {
2796                 $fullfile = $dir . "/" . $file;
2797                 $errdir = $dir unless $errdir;
2798             }
2800             # Use different name for "error filename".  Otherwise on
2801             # an error the bad file will be reported as eg
2802             # `../../install-sh' when using the default
2803             # config_aux_path.
2804             $errfile = $errdir . '/' . $file;
2806             if (-f $fullfile)
2807             {
2808                 $found_it = 1;
2809                 &push_dist_common ($file) if $dir eq $relative_dir;
2810                 $save_dir = $dir;
2811                 last;
2812             }
2813         }
2815         if ($found_it)
2816         {
2817             # Prune the path list.
2818             @require_file_paths = $save_dir;
2819         }
2820         else
2821         {
2822             if ($strictness >= $mystrict)
2823             {
2824                 # Only install missing files according to our desired
2825                 # strictness level.
2826                 if ($add_missing && -f ($am_dir . '/' . $file))
2827                 {
2828                     # Install the missing file.  Symlink if we can, copy
2829                     # if we must.
2830                     if ($symlink_exists)
2831                     {
2832                         symlink ($am_dir . '/' . $file, $errfile);
2833                     }
2834                     else
2835                     {
2836                         system ('cp', $am_dir . '/' . $file, $errfile);
2837                     }
2839                     # FIXME this is a hack.  Should have am_warn.
2840                     local ($save) = $exit_status;
2841                     if ($is_configure)
2842                     {
2843                         &am_conf_line_error
2844                             ($line,
2845                              "required file \"$errfile\" not found; installing");
2846                     }
2847                     else
2848                     {
2849                         &am_line_error
2850                             ($line,
2851                              "required file \"$errfile\" not found; installing");
2852                     }
2853                     $exit_status = $save;
2854                 }
2855                 else
2856                 {
2857                     # Only an error if strictness constraint violated.
2858                     if ($is_configure)
2859                     {
2860                         &am_conf_line_error
2861                             ($line, "required file \"$errfile\" not found");
2862                     }
2863                     else
2864                     {
2865                         &am_line_error
2866                             ($line, "required file \"$errfile\" not found");
2867                     }
2868                 }
2869             }
2870         }
2871     }
2874 # Like require_file_with_line, but error messages refer to
2875 # configure.in, not the current Makefile.am.
2876 sub require_file_with_conf_line
2878     @require_file_paths = '.';
2879     &require_file_internal (1, @_);
2882 sub require_file_with_line
2884     @require_file_paths = '.';
2885     &require_file_internal (0, @_);
2888 sub require_file
2890     @require_file_paths = '.';
2891     &require_file_internal (0, '', @_);
2894 # Require a file that is also required by Autoconf.  Looks in
2895 # configuration path, as specified by AC_CONFIG_AUX_DIR.
2896 sub require_config_file
2898     @require_file_paths = @config_aux_path;
2899     &require_file_internal (0, '', @_);
2900     local ($dir) = $require_file_paths[0];
2901     @config_aux_path = @require_file_paths;
2902     if ($dir eq '.')
2903     {
2904         $config_aux_dir = '.';
2905     }
2906     else
2907     {
2908         $config_aux_dir = '$(top_srcdir)/' . $dir;
2909     }
2912 # Assumes that the line number is in Makefile.am.
2913 sub require_conf_file_with_line
2915     @require_file_paths = @config_aux_path;
2916     &require_file_internal (0, @_);
2917     local ($dir) = $require_file_paths[0];
2918     @config_aux_path = @require_file_paths;
2919     if ($dir eq '.')
2920     {
2921         $config_aux_dir = '.';
2922     }
2923     else
2924     {
2925         $config_aux_dir = '$(top_srcdir)/' . $dir;
2926     }
2929 # Assumes that the line number is in Makefile.am.
2930 sub require_conf_file_with_conf_line
2932     @require_file_paths = @config_aux_path;
2933     &require_file_internal (1, @_);
2934     local ($dir) = $require_file_paths[0];
2935     @config_aux_path = @require_file_paths;
2936     if ($dir eq '.')
2937     {
2938         $config_aux_dir = '.';
2939     }
2940     else
2941     {
2942         $config_aux_dir = '$(top_srcdir)/' . $dir;
2943     }
2946 ################################################################
2948 # Push a list of files onto dist_common.
2949 sub push_dist_common
2951     local (@files) = @_;
2952     local ($file);
2954     foreach $file (@files)
2955     {
2956         $dist_common{$file} = 1;
2957     }
2960 # Push a list of clean targets onto phony.
2961 sub push_phony_cleaners
2963     local ($base) = @_;
2964     local ($target);
2965     foreach $target ('mostly', 'dist', '', 'maintainer-')
2966     {
2967         push (@phony, $target . 'clean-' . $base);
2968     }
2971 # Set strictness.
2972 sub set_strictness
2974     $strictness_name = $_[0];
2975     if ($strictness_name eq 'gnu')
2976     {
2977         $strictness = $GNU;
2978     }
2979     elsif ($strictness_name eq 'gnits')
2980     {
2981         $strictness = $GNITS;
2982     }
2983     elsif ($strictness_name eq 'foreign')
2984     {
2985         $strictness = $FOREIGN;
2986     }
2987     else
2988     {
2989         die "automake: level \`$strictness_name' not recognized\n";
2990     }
2994 ################################################################
2996 # Return directory name of file.
2997 sub dirname
2999     local ($file) = @_;
3000     local ($sub);
3002     ($sub = $file) =~ s,/+[^/]+$,,g;
3003     $sub = '.' if $sub eq $file;
3004     return $sub;
3007 # Make a directory.
3008 sub mkdir
3010     local ($dirname) = @_;
3011     system ("mkdir", $dirname);
3014 ################################################################
3016 # Print an error message and set exit status.
3017 sub am_error
3019     warn "automake: ${am_file}.am: ", join (' ', @_), "\n";
3020     $exit_status = 1;
3023 sub am_line_error
3025     local ($symbol, @args) = @_;
3027     if ($symbol)
3028     {
3029         # If SYMBOL not already a line number, look it up in Makefile.am.
3030         $symbol = $content_lines{$symbol} unless $symbol =~ /^\d+$/;
3031         $symbol .= ': ' if $symbol;
3032         warn "${am_file}.am:", $symbol, join (' ', @args), "\n";
3033         $exit_status = 1;
3034     }
3035     else
3036     {
3037         &am_error (@args);
3038     }
3041 # Like am_error, but while scanning configure.in.
3042 sub am_conf_error
3044     # FIXME can run in subdirs.
3045     warn "automake: configure.in: ", join (' ', @_), "\n";
3046     $exit_status = 1;
3049 # Error message with line number referring to configure.in.
3050 sub am_conf_line_error
3052     local ($line, @args) = @_;
3054     if ($line)
3055     {
3056         warn "configure.in: $line: ", join (' ', @args), "\n";
3057         $exit_status = 1;
3058     }
3059     else
3060     {
3061         &am_conf_error (@args);
3062     }
3065 # Tell user where our aclocal.m4 is, but only once.
3066 sub keyed_aclocal_warning
3068     local ($key) = @_;
3069     warn "automake: macro \`$key' can be found in ${am_dir}/aclocal.m4\n";
3072 # Print usage information.
3073 sub usage
3075     print "Usage: automake [OPTION] ... [Makefile]...\n";
3076     print $USAGE;
3077     print "\nFiles which are automatically distributed, if found:\n";
3078     $~ = "USAGE_FORMAT";
3079     local (@lcomm) = sort ((@common_files, @common_sometimes));
3080     local ($one, $two, $three, $four);
3081     while (@lcomm > 0)
3082     {
3083         $one = shift @lcomm;
3084         $two = @lcomm ? shift @lcomm : '';
3085         $three = @lcomm ? shift @lcomm : '';
3086         $four = @lcomm ? shift @lcomm : '';
3087         write;
3088     }
3090     exit 0;
3093 format USAGE_FORMAT =
3094   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
3095   $one,               $two,               $three,             $four