Bug fix, plus test
[automake.git] / automake.in
blobee8ddb227637bd8115878fb2454333b493eb2ad5
1 #!@PERL@
2 # -*- perl -*-
3 # @configure_input@
5 eval 'exec /usr/local/bin/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]*(.*)\$";
44 # Constants to define the "strictness" level.
45 $NORMAL = 0;
46 $GNU = 1;
47 $GNITS = 2;
51 # Variables global to entire run.
53 # Strictness level as set on command line.
54 $default_strictness = $NORMAL;
56 # Name of strictness level, as set on command line.
57 $default_strictness_name = 'normal';
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 # This holds our (eventual) exit status.  We don't actually exit until
64 # we have processed all input files.
65 $exit_status = 0;
67 # From the Perl manual.
68 $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
70 # TRUE if missing standard files should be installed.
71 $install_missing = 0;
73 # Files found by scanning configure.in for LIBOBJS.
74 %libsources = ();
76 # True if fp_C_PROTOTYPES appears in configure.in.
77 $fp_c_prototypes = 0;
79 # Names used in AC_CONFIG_HEADER call.  $config_name is the actual
80 # (first) argument.  $config_header is the '.in' file.  Ordinarily the
81 # second is derived from the first, but they can be different if the
82 # weird "NAME:FILE" syntax is used.
83 $config_name = '';
84 $config_header = '';
86 # Relative location of top build directory.
87 $top_builddir = '';
89 # List of Makefile.am's to process.
90 @input_files = ();
92 # List of files in AC_OUTPUT without Makefile.am.
93 @other_input_files = ();
95 # Whether AC_PROG_MAKE_SET has been seen in configure.in.
96 $seen_make_set = 0;
98 # Whether ud_GNU_GETTEXT has been seen in configure.in.
99 $seen_gettext = 0;
101 # 1 if AC_PROG_INSTALL seen, 2 if fp_PROG_INSTALL seen.
102 $seen_prog_install = 0;
104 # 1 if any scripts installed, 0 otherwise.
105 $scripts_installed = 0;
107 # Whether AC_PATH_XTRA has been seen in configure.in
108 $seen_path_xtra = 0;
110 # Charsets used by maintainer and in distribution.  MAINT_CHARSET is
111 # handled in a funny way: if seen in the top-level Makefile.am, it is
112 # used for every directory which does not specify a different value.
113 # The rationale here is that some directories (eg gettext) might be
114 # distributions of other packages, and thus require their own charset
115 # info.  However, the DIST_CHARSET must be the same for the entire
116 # package; it can only be set at top-level.
117 # FIXME this yields bugs when rebuilding.  What to do?  Always
118 # read (and sometimes discard) top-level Makefile.am?
119 $maint_charset = '';
120 $dist_charset = 'utf8';         # recode doesn't support this yet.
124 &initialize_global_constants;
126 # Parse command line.
127 &parse_arguments (@ARGV);
129 # Do configure.in scan only once.
130 &scan_configure;
132 die "automake: no \`Makefile.am' found or specified\n"
133     if ! @input_files;
135 # Now do all the work on each file.
136 foreach $am_file (@input_files)
138     # FIXME should support the AC_OUTPUT ":" syntax here.
139     if (! -f ($am_file . '.am'))
140     {
141         &am_error ('no such file');
142     }
143     else
144     {
145         &generate_makefile ($am_file);
146     }
149 &am_conf_error (($scripts_installed ? 'fp_PROG_INSTALL' : 'AC_PROG_INSTALL')
150                 . " must be used in configure.in")
151     unless $seen_prog_install > $scripts_installed;
153 exit $exit_status;
156 ################################################################
158 # Parse command line.
159 sub parse_arguments
161     local (@arglist) = @_;
163     # Start off as normal.
164     &set_strictness ('normal');
166     while (@arglist)
167     {
168         if ($arglist[0] eq "--version")
169         {
170             print "Automake version $VERSION\n";
171             exit 0;
172         }
173         elsif ($arglist[0] eq "--help")
174         {
175             &usage;
176         }
177         elsif ($arglist[0] =~ /^--amdir=(.+)$/)
178         {
179             $am_dir = $1;
180         }
181         elsif ($arglist[0] eq '--amdir')
182         {
183             &require_argument (@arglist);
184             shift (@arglist);
185             $am_dir = $arglist[0];
186         }
187         elsif ($arglist[0] =~ /^--strictness=(.+)$/)
188         {
189             &set_strictness ($1);
190         }
191         elsif ($arglist[0] eq '--gnu')
192         {
193             &set_strictness ('gnu');
194         }
195         elsif ($arglist[0] eq '--gnits')
196         {
197             &set_strictness ('gnits');
198         }
199         elsif ($arglist[0] eq '--strictness')
200         {
201             &require_argument (@arglist);
202             shift (@arglist);
203             &set_strictness ($arglist[0]);
204         }
205         elsif ($arglist[0] eq '--include-deps')
206         {
207             $cmdline_use_dependencies = 0;
208         }
209         elsif ($arglist[0] =~ /^--output-dir=(.*)$/)
210         {
211             # Set output directory.
212             $output_directory = $1;
213         }
214         elsif ($arglist[0] eq '--output-dir')
215         {
216             &require_argument (@arglist);
217             shift (@arglist);
218             $output_directory = $arglist[0];
219         }
220         elsif ($arglist[0] eq '--install-missing')
221         {
222             $install_missing = 1;
223         }
224         elsif ($arglist[0] eq '--')
225         {
226             # Stop option processing.
227             shift (@arglist);
228             push (@input_files, @arglist);
229             last;
230         }
231         elsif ($arglist[0] =~ /^-/)
232         {
233             die "automake: unrecognized option -- \`$arglist[0]'\n";
234         }
235         else
236         {
237             push (@input_files, $arglist[0]);
238         }
240         shift (@arglist);
241     }
243     # Take global strictness from whatever we currently have set.
244     $default_strictness = $strictness;
245     $default_strictness_name = $strictness_name;
248 # Ensure argument exists, or die.
249 sub require_argument
251     local ($arg, @arglist) = @_;
252     die "automake: no argument given for option \`$arg'\n"
253         if ! @arglist;
256 ################################################################
258 # Generate a Makefile.in given the name of the corresponding Makefile.
259 sub generate_makefile
261     local ($makefile) = @_;
263     # print "creating ", $makefile, ".in\n";
265     &initialize_per_input;
266     $relative_dir = &dirname ($makefile);
267     # FIXME with new 'dist' target, don't need Makefile.in.  Probably
268     # should remove it here.
269     &push_dist_common ('Makefile.in', 'Makefile.am');
270     push (@sources, '$(SOURCES)') if defined $contents{'SOURCES'};
271     push (@objects, '$(OBJECTS)') if defined $contents{'OBJECTS'};
273     # This is always the default target.  This gives us freedom to do
274     # things in whatever order is convenient.
275     $output_rules .= "default: all\n\n";
276     push (@phony, 'default');
278     &read_am_file ($makefile . '.am');
279     &handle_options;
281     # Check first, because we might modify some state.
282     &check_gnu_standards;
283     &check_gnits_standards;
285     &handle_configure;
286     &handle_libraries;
287     &handle_programs;
288     &handle_scripts;
290     # Re-init SOURCES and OBJECTS.  FIXME other code shouldn't depend
291     # on this (but currently does).
292     $contents{'SOURCES'} = join (' ', @sources);
293     $contents{'OBJECTS'} = join (' ', @objects);
295     &handle_texinfo;
296     &handle_man_pages;
297     &handle_data;
298     &handle_headers;
299     &handle_subdirs;
300     &handle_tags;
301     &handle_dist;
302     &handle_dependencies;
303     &handle_footer;
304     &handle_merge_targets;
305     &handle_installdirs;
306     &handle_clean;
307     &handle_phony;
309     if (! -d ($output_directory . '/' . $relative_dir))
310     {
311         &mkdir ($output_directory . '/' . $relative_dir);
312     }
313     if (! open (GM_FILE, "> " . $output_directory . '/' . $makefile . ".in"))
314     {
315         warn "automake: ${am_file}.in: cannot open: $!\n";
316         $exit_status = 1;
317         return;
318     }
320     print GM_FILE $output_vars;
321     print GM_FILE $output_rules;
322     print GM_FILE $output_trailer;
324     close (GM_FILE);
327 ################################################################
329 # Handle AUTOMAKE_OPTIONS variable.
330 sub handle_options
332     return if ! defined $contents{'AUTOMAKE_OPTIONS'};
334     foreach (split (/\s+/, $contents{'AUTOMAKE_OPTIONS'}))
335     {
336         $options{$_} = 1;
337         if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'normal')
338         {
339             &set_strictness ($_);
340         }
341         elsif ($_ eq 'no-installman' || $_ eq 'ansi2knr' || $_ eq 'dist-shar')
342         {
343             # Explicitly recognize these.
344         }
345         elsif ($_ eq 'no-dependencies')
346         {
347             $use_dependencies = 0;
348         }
349         elsif (/[0-9]+\.?[0-9]+/)
350         {
351             # Got a version number.  Is the syntax too strict?
352             if ($VERSION < $_)
353             {
354                 &am_error ("require version $_, only have $VERSION");
355                 # FIXME -- what else to do?
356                 exit 1;
357             }
358         }
359         else
360         {
361             &am_error ('option ', $_, 'not recognized');
362         }
363     }
366 # Return object extension.  Just once, put some code into the output.
367 sub get_object_extension
369     if (! $dir_holds_sources)
370     {
371         # Boilerplate.
372         local ($xform) = '';
373         if (defined $contents{'CONFIG_HEADER'})
374         {
375             ($xform = &dirname ($contents{'CONFIG_HEADER'}))
376                 =~ s/(\W)/\\$1/g;
377             $xform = 's/\@CONFIG_INCLUDE_SPEC\@/-I' . $xform . '/go';
378         }
379         $output_vars .= &file_contents_with_transform ($xform,
380                                                        'compile-vars');
381         $output_rules .= &file_contents ('compile');
382         &push_phony_cleaners ('compile');
384         # If using X, include some extra variable definitions.  NOTE
385         # we don't want to force these into CFLAGS or anything,
386         # because not all programs will necessarily use X.
387         if ($seen_path_xtra)
388         {
389             $output_vars .= ("X_CFLAGS = \@X_CFLAGS\@\n"
390                              . "X_LIBS = \@X_LIBS\@\n"
391                              . "X_EXTRA_LIBS = \@X_EXTRA_LIBS\@\n"
392                              . "X_PRE_LIBS = \@X_PRE_LIBS\@\n");
393         }
395         # Check for automatic de-ANSI-fication.
396         $dir_holds_sources = '.o';
397         push (@suffixes, '.c', '.o');
398         push (@clean, 'compile');
400         if (defined $options{'ansi2knr'} || defined $contents{'@kr@'})
401         {
402             &am_error ("option \`ansi2knr' in use but \`fp_C_PROTOTYPES' not in configure.in")
403                 if ! $fp_c_prototypes;
405             $dir_holds_sources = '$o';
406             push (@suffixes, '._c', '._o');
408             &require_file ($NORMAL, 'ansi2knr.c', 'ansi2knr.1');
410             $output_vars .= &file_contents ('kr-vars');
411             $output_rules .= &file_contents ('compile-kr');
412             $output_rules .= &file_contents ('clean-kr');
414             push (@clean, 'kr');
415             &push_phony_cleaners ('kr');
416         }
417     }
418     return $dir_holds_sources;
421 # Handle SOURCE->OBJECT transform for one program or library.
422 sub handle_source_transform
424     local ($one_file, $obj) = @_;
425     local ($objpat) = $obj;
426     $objpat =~ s/(\W)/\\$1/g;
428     # Look for file_SOURCES and file_OBJECTS.
429     if (defined $contents{$one_file . "_SOURCES"})
430     {
431         if (! defined $contents{$one_file . "_OBJECTS"})
432         {
433             # Turn sources into objects.
434             local (@files) = split (/\s+/, $contents{$one_file . "_SOURCES"});
435             local (@result) = ();
436             foreach (@files)
437             {
438                 # Skip header files.
439                 next if /\.h$/;
440                 # Skip things that look like macro references.
441                 next if /^\$\(.*\)$/;
442                 next if /^\$\{.*\}$/;
444                 if (/^(.*)\.[yl]$/)
445                 {
446                     # Automatically include generated .c file in
447                     # distribution.
448                     &push_dist_common ($1 . '.c');
449                 }
451                 # Transform source files into .o files.
452                 s/\.cc$/$obj/g;
453                 s/\.[cCmylfs]$/$obj/g;
454                 push (@result, $_);
456                 # Transform .o or $o file into .P file (for automatic
457                 # dependency code).
458                 s/$objpat$/.P/g;
459                 $dep_files{'$(srcdir)/.deps/' . $_} = 1;
460             }
462             &pretty_print ($one_file . "_OBJECTS =", "    ", @result);
463         }
464         else
465         {
466             &am_error ($one_file . '_OBJECTS', 'should not be defined');
467         }
469         push (@sources, '$(' . $one_file . "_SOURCES)");
470         push (@objects, '$(' . $one_file . "_OBJECTS)");
471     }
472     else
473     {
474         $output_vars .= ($one_file . "_SOURCES = " . $one_file . ".c\n"
475                          . $one_file . "_OBJECTS = ". $one_file
476                          . $obj . "\n");
477         push (@sources, $one_file . '.c');
478         push (@objects, $one_file . $obj);
479         $dep_files{'$(srcdir)/.deps/' . $one_file . '.P'} = 1;
480     }
482     if (defined $contents{'CONFIG_HEADER'})
483     {
484         $output_rules .= ('$(' . $one_file . "_OBJECTS): "
485                           . $contents{'CONFIG_HEADER'} . "\n");
486     }
488     return @result;
491 # Handle C programs.
492 sub handle_programs
494     local (@proglist) = &am_install_var ('-clean',
495                                          'programs', 'PROGRAMS',
496                                          'bin', 'sbin', 'libexec', 'pkglib',
497                                          'noinst');
498     # FIXME error if PROGRAMS defined but no blah_PROGRAMS defined.
499     return if ! @proglist;
501     local ($obj) = &get_object_extension;
502     local ($one_file, $munge);
504     foreach $one_file (@proglist)
505     {
506         &handle_source_transform ($one_file, $obj);
508         if (! defined $contents{$one_file . "_LDADD"})
509         {
510             # User didn't define prog_LDADD override.  So do it.
511             $output_vars .= $one_file . '_LDADD = $(LDADD)' . "\n";
512         }
514         $output_rules .=
515             &file_contents_with_transform ('s/\@PROGRAM\@/' . $one_file
516                                            . '/go', 'program');
517     }
520 # Handle libraries.
521 sub handle_libraries
523     local (@liblist) = &am_install_var ('-no-all', '-clean',
524                                         'libraries', 'LIBRARIES',
525                                         'lib', 'pkglib', 'noinst');
526     # FIXME error if LIBRARIES defined but no blah_LIBRARIES defined.
527     return if ! @liblist;
529     # Generate _LIBFILES variables.  Too bad we can't do this in
530     # am_install_var.
531     local ($onedir, $onelib);
532     local (@outlist);
533     foreach $onedir ('lib', 'pkglib', 'noinst')
534     {
535         if (defined $contents{$onedir . '_LIBRARIES'})
536         {
537             @outlist = ();
538             foreach $onelib (split (/\s+/, $contents{$onedir . '_LIBRARIES'}))
539             {
540                 push (@outlist, 'lib' . $onelib . '.a');
541             }
542             &pretty_print ($onedir . '_LIBFILES =', "    ", @outlist);
543         }
544     }
545     push (@all, '$(LIBFILES)');
547     local ($obj) = &get_object_extension;
548     local ($munge);
549     foreach $onelib (@liblist)
550     {
551         if (defined $contents{$onelib . '_LIBADD'})
552         {
553             # We recognize certain things that are commonly put in
554             # LIBADD.
555             local ($lsearch);
557             foreach $lsearch (split (/\s+/, $contents{$onelib . '_LIBADD'}))
558             {
559                 # Automatically handle @LIBOBJS@ and @ALLOCA@.
560                 # Basically this means adding entries to dep_files.
561                 if ($lsearch eq '@LIBOBJS@')
562                 {
563                     local ($iter, $rewrite);
564                     foreach $iter (keys %libsources)
565                     {
566                         if ($iter ne 'alloca.c')
567                         {
568                             ($rewrite = $iter) =~ s/\.c$/.P/;
569                             $dep_files{'$(srcdir)/.deps/' . $rewrite} = 1;
570                             &require_file ($NORMAL, $iter);
571                         }
572                     }
573                 }
574                 elsif ($lsearch eq '@ALLOCA@')
575                 {
576                     &am_error ("\@ALLOCA\@ seen but \`AC_FUNC_ALLOCA' not in \`configure.in'")
577                         if ! defined $libsources{'alloca.c'};
578                     $dep_files{'$(srcdir)/.deps/alloca.P'} = 1;
579                     &require_file ($NORMAL, 'alloca.c');
580                 }
581             }
582         }
583         else
584         {
585             # Generate support for conditional object inclusion in
586             # libraries.
587             $output_vars .= $onelib . "_LIBADD =\n";
588         }
590         &handle_source_transform ($onelib, $obj);
592         $output_rules .=
593             &file_contents_with_transform ('s/\@LIBRARY\@/' . $onelib . '/go',
594                                            'library');
595     }
597     # Turn "foo" into "libfoo.a" and include macro definition.
598     grep (($_ = 'lib' . $_ . '.a') && 0, @liblist);
600     if (! defined $contents{'LIBFILES'})
601     {
602         &pretty_print ('LIBFILES = ', "    ", @liblist);
603     }
604     $output_vars .= &file_contents ('libraries-vars');
607 # Handle scripts.
608 sub handle_scripts
610     # FIXME can't determine if these scripts are really being
611     # installed or not.
612     $scripts_installed = &am_install_var ('-clean',
613                                           'scripts', 'SCRIPTS',
614                                           'bin', 'sbin', 'libexec', 'noinst');
617 # Search a file for a "version.texi" Texinfo include.  Return the name
618 # of the include file if found, or the empty string if not.  A
619 # "version.texi" file is actually any file whose name matches
620 # "vers*.texi".
621 sub grep_for_vers_texi
623     local ($filename) = @_;
625     if (! open (TEXI, $filename))
626     {
627         &am_error ("couldn't open \`$filename': $!");
628         return '';
629     }
631     while (<TEXI>)
632     {
633         if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
634         {
635             # Found it.
636             close (TEXI);
637             return $1;
638         }
639     }
641     close (TEXI);
642     return '';
645 # Handle all Texinfo source.
646 sub handle_texinfo
648     # FIXME can this really be right?  Might want to have configure
649     # determine list of texinfos.  Fix this when someone complains.
650     &am_error ("\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
651         if defined $contents{'TEXINFOS'};
652     return if (! defined $contents{'info_TEXINFOS'}
653                && ! defined $contents{'html_TEXINFOS'});
655     local (@texis) = split (/\s+/, $contents{'info_TEXINFOS'});
657     local (@infos_list, @info_deps_list, @dvis_list, @texi_deps);
658     local ($infobase, $info_cursor);
659     local (%versions);
660     local ($done) = 0;
661     local ($vti);
662     local ($tc_cursor, @texi_cleans);
664     foreach $info_cursor (@texis)
665     {
666         ($infobase = $info_cursor) =~ s/\.texi$//;
668         # If 'version.texi' is referenced by input file, then include
669         # automatic versioning capability.
670         local ($vtexi)
671             = &grep_for_vers_texi ($relative_dir . "/" . $info_cursor);
672         if ($vtexi)
673         {
674             &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
675                 if (defined $versions{$vtexi});
676             $versions{$vtexi} = $info_cursor;
678             # Got a hit.
679             push (@texis, $vtexi);
680             # We number the stamp-vti files.  This is doable since the
681             # actual names don't matter much.  We only number starting
682             # with the second one, so that the common case looks nice.
683             $vti = 'vti' . ($done ? $done : '');
684             &push_dist_common ($vtexi, 'stamp-' . $vti);
685             push (@clean, $vti);
687             $output_rules .=
688                 &file_contents_with_transform
689                     ('s/\@TEXI\@/' . $info_cursor . '/g; '
690                      . 's/\@VTI\@/' . $vti . '/g; '
691                      . 's/\@VTEXI\@/' . $vtexi . '/g',
692                      'texi-version');
694             &push_phony_cleaners ($vti);
696             # Only require once.
697             &require_file ($NORMAL, 'mdate-sh') if ! $done;
698             ++$done;
699         }
701         # If user specified file_TEXINFOS, then use that as explicit
702         # dependency list.
703         @texi_deps = ();
704         push (@texi_deps, $info_cursor, $vtexi);
705         if (defined $contents{$infobase . "_TEXINFOS"})
706         {
707             push (@texi_deps, "\$" . $infobase . '_TEXINFOS');
708             &push_dist_common ("\$" . $infobase . '_TEXINFOS');
709         }
711         $output_rules .= ("\n" . $infobase . ".info: "
712                           . join (' ', @texi_deps) . "\n\n");
714         push (@infos_list, $infobase . '.info*');
715         push (@info_deps_list, $infobase . '.info');
716         push (@dvis_list, $infobase . '.dvi');
718         # Generate list of things to clean for this target.  We do
719         # this explicitly because otherwise too many things could be
720         # removed.  In particular the ".log" extension might
721         # reasonably be used in other contexts by the user.
722         foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns',
723                             'ky', 'log', 'pg', 'toc', 'tp', 'vr', 'op')
724         {
725             push (@texi_cleans, $infobase . '.' . $tc_cursor);
726         }
727     }
729     # Some boilerplate.
730     $output_vars .= &file_contents ('texinfos-vars');
731     $output_rules .= &file_contents ('texinfos');
732     push (@phony, 'install-info', 'uninstall-info');
734     # How to clean.
735     $output_rules .= "\nmostlyclean-info:\n";
736     &pretty_print_rule ("\trm -f", "\t  ", @texi_cleans);
737     $output_rules .= ("\nclean-info:\n\ndistclean-info:\n\n"
738                       . "maintainer-clean-info:\n\t"
739                       . 'rm -f $(INFOS)' . "\n");
740     &push_phony_cleaners ('info');
742     push (@suffixes, '.texi', '.info', '.dvi');
743     push (@uninstall, 'uninstall-info');
744     push (@clean, 'info');
745     push (@info, '$(INFO_DEPS)');
746     push (@dvi, '$(DVIS)');
747     push (@installdirs, '$(infodir)');
748     unshift (@install_data, 'install-info');
750     # Make sure documentation is made and installed first.  Use
751     # $(INFO_DEPS), not 'info', because otherwise recursive makes get
752     # run twice during "make all".  FIXME add test case.
753     unshift (@all, '$(INFO_DEPS)');
755     $output_vars .= ("INFOS = " . join (' ', @infos_list) . "\n"
756                      . "INFO_DEPS = " . join (' ', @info_deps_list)  . "\n"
757                      . "DVIS = " . join (' ', @dvis_list) . "\n"
758                      # This next isn't strictly needed now -- the
759                      # places that look here could easily be changed
760                      # to look in info_TEXINFOS.  But this is probably
761                      # better, in case noinst_TEXINFOS is ever
762                      # supported.
763                      . "TEXINFOS = " . $contents{'info_TEXINFOS'} . "\n\n");
765     # Do some error checking.
766     &require_file ($NORMAL, 'texinfo.tex');
769 # Handle any man pages.
770 sub handle_man_pages
772     &am_error ("\`MANS' is an anachronism; use \`man_MANS'")
773         if defined $contents{'MANS'};
774     return if ! defined $contents{'man_MANS'};
776     # We generate the manpage install code by hand to avoid the use of
777     # basename in the generated Makefile.
778     local (@mans) = split (/\s+/, $contents{'man_MANS'});
779     local (%sections, %inames, %secmap, %fullsecmap);
780     foreach (@mans)
781     {
782         # FIXME: statement without effect:
783         /^(.*)\.([0-9])([a-z]*)$/;
784         $sections{$2} = 1;
785         $inames{$1} = $_;
786         $secmap{$1} = $2;
787         $fullsecmap{$1} = $2 . $3;
788     }
790     # We don't really need this, but we use it in case we ever want to
791     # support noinst_MANS.
792     $output_vars .= "MANS = " . $contents{'man_MANS'} . "\n";
794     # Generate list of install dirs.
795     $output_rules .= "install-man: \$(MANS)\n";
796     foreach (keys %sections)
797     {
798         push (@installdirs, '$(mandir)/man' . $_);
799         $output_rules .= ("\t" . '$(top_srcdir)/mkinstalldirs $(mandir)/man'
800                           . $_ . "\n");
801     }
802     push (@phony, 'install-man');
804     # Generate install target.
805     local ($key);
806     foreach $key (keys %inames)
807     {
808         $_ = $install_man_format;
809         s/\@SECTION\@/$secmap{$key}/g;
810         s/\@MAN\@/$inames{$key}/g;
811         s/\@FULLSECT\@/$fullsecmap{$key}/g;
812         s/\@MANBASE\@/$key/g;
813         $output_rules .= $_;
814     }
815     $output_rules .= "\n";
817     $output_rules .= "uninstall-man:\n";
818     foreach $key (keys %inames)
819     {
820         $_ = $uninstall_man_format;
821         s/\@SECTION\@/$secmap{$key}/g;
822         s/\@MAN\@/$inames{$key}/g;
823         s/\@FULLSECT\@/$fullsecmap{$key}/g;
824         s/\@MANBASE\@/$key/g;
825         $output_rules .= $_;
826     }
827     $output_rules .= "\n";
828     push (@phony, 'uninstall-man');
830     $output_vars .= &file_contents ('mans-vars');
832     if (! defined $options{'no-installman'})
833     {
834         push (@install_data, 'install-man');
835         push (@uninstall, 'uninstall-man');
836         push (@all, '$(MANS)');
837     }
840 # Handle DATA variables.
841 sub handle_data
843     &am_install_var ('data', 'DATA', 'data', 'sysconf',
844                      'sharedstate', 'localstate', 'pkgdata',
845                      'noinst');
848 # Handle TAGS.
849 sub handle_tags
851     local ($tagging) = 0;
853     push (@phony, 'tags');
854     if (defined $contents{'SUBDIRS'})
855     {
856         $output_rules .= &file_contents ('tags');
857         $tagging = 1;
858     }
859     elsif ($dir_holds_sources || defined $contents{'ETAGS_ARGS'})
860     {
861         $output_rules .= &file_contents ('tags-subd');
862         $tagging = 1;
863     }
865     if ($tagging)
866     {
867         $output_rules .= &file_contents ('tags-clean');
868         push (@clean, 'tags');
869         &push_phony_cleaners ('tags');
870     }
871     else
872     {
873         # Every Makefile must define some sort of TAGS rule.
874         # Otherwise, it would be possible for a top-level "make TAGS"
875         # to fail because some subdirectory failed.
876         $output_rules .= "tags: TAGS\nTAGS:\n\n";
877     }
880 # Generate actual 'dist' (or dist-shar) rule.
881 sub handle_dist_worker
883     local ($distshar) = @_;
884     local ($target) = $distshar ? 'dist-shar' : 'dist';
886     $output_rules .= $target . ': $(DEP_DISTFILES)' . "\n";
888     # Initialization; only at top level.
889     if ($relative_dir eq '.')
890     {
891         if ($strictness >= $GNITS)
892         {
893             # For Gnits users, this is pretty handy.  Look at 15 lines
894             # in case some explanatory text is desirable.
895             $output_rules .= '  @if sed 15q NEWS | grep -e "$(VERSION)" > /dev/null; then :; else \\
896           echo "NEWS not updated; not releasing" 1>&2; \\
897           exit 1;                               \\
898         fi
900         }
903         $output_rules .=
904             (
905              # Create dist directory.
906              '  rm -rf $(distdir)
907         mkdir $(distdir)
908         chmod 777 $(distdir)
910              # We need an absolute path for --output-dir.  Thus the
911              # weirdness.
912              . '        distdir=`cd $(distdir) && pwd` \\
913           && cd $(srcdir) \\
914           && automake --include-deps --output-dir=$$distdir --strictness='
915              # Set strictness of output.
916              . $strictness_name . "\n"
917              );
918     }
920     # In loop, test for file existence because sometimes a file gets
921     # included in DISTFILES twice.  For example this happens when a
922     # single source file is used in building more than one program.
923     # Also, there are situations in which "ln" can fail.  For instance
924     # a file to distribute could actually be a cross-filesystem
925     # symlink -- this can easily happen if "gettextize" was run on the
926     # distribution.  Note that DISTFILES can contain a wildcard (for
927     # info files, sigh), so we must use the echo trick.
929     $output_rules .= '  @for file in `cd $(srcdir) && echo $(DISTFILES)`; do \\
930           test -f $(distdir)/$$file \\
931           || ln $(srcdir)/$$file $(distdir)/$$file 2> /dev/null \\
932           || cp -p $(srcdir)/$$file $(distdir)/$$file; \\
933         done
936     # If we have SUBDIRS, create all dist subdirectories and do
937     # recursive build.
938     if (defined $contents{'SUBDIRS'})
939     {
940         # Test for directory existence here because previous automake
941         # invocation might have created some directories.
942         $output_rules .= '      for subdir in $(SUBDIRS); do            \\
943           test -d $(distdir)/$$subdir           \\
944           || mkdir $(distdir)/$$subdir          \\
945           || exit 1;                            \\
946           chmod 777 $(distdir)/$$subdir;        \\
947           (cd $$subdir && $(MAKE) dist) || exit 1; \\
948         done
950     }
952     # Make verbatim copies of some subdirectories if required.  This
953     # is a hack which might go away.
954     if (defined $contents{'DIST_SUBDIRS'})
955     {
956         $output_rules .= '      @for dir in $(DIST_SUBDIRS); do         \\
957           echo copying directory $$dir;         \\
958           tar chf - $$dir | (cd $(distdir) && tar xBpf -); \\
959         done
961     }
963     # Finalize.
964     if ($relative_dir eq '.')
965     {
966         $output_rules .= '      chmod -R a+r $(distdir)' . "\n\t";
967         if ($distshar)
968         {
969             $output_rules .= 'shar $(distdir) | gzip > $(distdir).shar.gz';
970         }
971         else
972         {
973             $output_rules .= 'tar chozf $(distdir).tar.gz $(distdir)';
974         }
975         $output_rules .= "\n\t" . 'rm -rf $(distdir)' . "\n";
976     }
978     push (@phony, $target);
981 # Handle 'dist' target.
982 sub handle_dist
984     # Set up maint_charset.
985     $local_maint_charset = $contents{'MAINT_CHARSET'}
986         if defined $contents{'MAINT_CHARSET'};
987     $maint_charset = $local_maint_charset
988         if $relative_dir eq '.';
990     if (defined $contents{'DIST_CHARSET'})
991     {
992         &am_error ("DIST_CHARSET defined but no MAINT_CHARSET defined")
993             if ! $local_maint_charset;
994         if ($relative_dir eq '.')
995         {
996             $dist_charset = $contents{'DIST_CHARSET'}
997         }
998         else
999         {
1000             &am_error ("DIST_CHARSET can only be defined at top level");
1001         }
1002     }
1004     # Look for common files that should be included in distribution.
1005     local ($cfile);
1006     foreach $cfile (@common_files)
1007     {
1008         if (-f ($relative_dir . "/" . $cfile))
1009         {
1010             &push_dist_common ($cfile);
1011         }
1012     }
1014     # Keys of %dist_common are names of files to distributed.  We put
1015     # README first because it then becomes easier to make a
1016     # Usenet-compliant shar file (in these, README must be first).
1017     # FIXME do more ordering of files here.
1018     local (@coms);
1019     if (defined $dist_common{'README'})
1020     {
1021         push (@coms, 'README');
1022         undef $dist_common{'README'};
1023     }
1024     push (@coms, sort keys %dist_common);
1026     &pretty_print ("DIST_COMMON =", "    ", @coms);
1027     $output_vars .= "\n";
1029     # Some boilerplate.
1030     $output_vars .= &file_contents ('dist-vars');
1032     # Put these things in rules section so it is easier for whoever
1033     # reads Makefile.in.
1034     if ($relative_dir eq '.')
1035     {
1036         $output_rules .= "\n" . 'distdir = $(PACKAGE)-$(VERSION)' . "\n";
1037     }
1038     else
1039     {
1040         $output_rules .= ("\nsubdir = " . $relative_dir . "\n"
1041                           . 'distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)'
1042                           . "\n");
1043     }
1045     # Generate 'dist' target, and maybe dist-shar.
1046     &handle_dist_worker (0);
1047     &handle_dist_worker (1) if defined $options{'dist-shar'};
1050 # Handle auto-dependency code.
1051 sub handle_dependencies
1053     if ($use_dependencies)
1054     {
1055         # Include GNU-make-specific auto-dep code.
1056         if ($dir_holds_sources)
1057         {
1058             &pretty_print ('DEP_FILES =', "    ", sort keys %dep_files);
1059             $output_rules .= &file_contents ('depend');
1060         }
1061     }
1062     else
1063     {
1064         # Include any auto-generated deps that are present.
1065         if (-d ($relative_dir . "/.deps") && -f ($relative_dir . "/.deps/.P"))
1066         {
1067             local ($depfile);
1068             local ($gpat) = $relative_dir . "/.deps/*.P";
1070             foreach $depfile (<${gpat}>)
1071             {
1072                 if (! open (DEP_FILE, $depfile))
1073                 {
1074                     &am_error ("couldn't open $depfile", $!);
1075                     next;
1076                 }
1078                 # Slurp entire file.
1079                 $output_rules .= join ('', <DEP_FILE>);
1081                 close (DEP_FILE);
1082             }
1084             $output_rules .= "\n";
1085         }
1086     }
1089 # Handle subdirectories.
1090 sub handle_subdirs
1092     if (! defined $contents{'SUBDIRS'})
1093     {
1094         &am_conf_error
1095             ("ud_GNU_GETTEXT in configure.in but SUBDIRS not defined")
1096                 if $seen_gettext && $relative_dir eq '.';
1097         return;
1098     }
1100     &am_conf_error
1101         ("ud_GNU_GETTEXT in configure.in but \`po' not in SUBDIRS")
1102             if $seen_gettext && $contents{'SUBDIRS'} !~ /\bpo\b/;
1103     &am_conf_error
1104         ("ud_GNU_GETTEXT in configure.in but \`intl' not in SUBDIRS")
1105             if $seen_gettext && $contents{'SUBDIRS'} !~ /\bintl\b/;
1107     &require_file ($NORMAL, 'ABOUT-NLS') if $seen_gettext;
1109     return if ! defined $contents{'SUBDIRS'};
1111     # Make sure each directory mentioned in SUBDIRS actually exists.
1112     local ($dir);
1113     foreach $dir (split (/\s+/, $contents{'SUBDIRS'}))
1114     {
1115         &am_error ("required directory $relative_dir/$dir does not exist")
1116             if ! -d $relative_dir . '/' . $dir;
1117     }
1119     $output_rules .= &file_contents ('subdirs');
1121     # Push a bunch of phony targets.
1122     local ($phonies);
1123     foreach $phonies ('-data', '-exec', 'dirs')
1124     {
1125         push (@phony, 'install' . $phonies . '-recursive');
1126         push (@phony, 'uninstall' . $phonies . '-recursive');
1127     }
1128     foreach $phonies ('all', 'check', 'installcheck', 'info', 'dvi')
1129     {
1130         push (@phony, $phonies . '-recursive');
1131     }
1132     &push_phony_cleaners ('recursive');
1134     push (@all, "all-recursive");
1135     push (@check, "check-recursive");
1136     push (@installcheck, "installcheck-recursive");
1137     push (@info, "info-recursive");
1138     push (@dvi, "dvi-recursive");
1140     $recursive_install = 1;
1143 # Handle remaking and configure stuff.
1144 sub handle_configure
1146     # If SUBDIRS defined, require AC_PROG_MAKE_SET.
1147     &am_error ("AC_PROG_MAKE_SET must be used in configure.in")
1148         if defined $contents{'SUBDIRS'} && ! $seen_make_set;
1150     local ($top_reldir);
1151     if ($relative_dir ne '.')
1152     {
1153         # In subdirectory.
1154         $output_rules .= &file_contents ('remake-subd');
1155         $top_reldir = '../';
1156     }
1157     else
1158     {
1159         if (-f 'aclocal.m4')
1160         {
1161             $output_vars .= "ACLOCAL = aclocal.m4\n";
1162             &push_dist_common ('aclocal.m4');
1163         }
1164         $output_rules .= &file_contents ('remake');
1166         # Look for some files we need.
1167         &require_file ($NORMAL, 'install-sh', 'mkinstalldirs');
1169         &am_error
1170             ("\`install.sh' is an anachronism; use \`install-sh' instead")
1171                 if -f $relative_dir . '/install.sh';
1173         # If we have a configure header, require it.
1174         if ($config_header)
1175         {
1176             # FIXME this restriction should be lifted.
1177             # FIXME first see if it is even needed as-is.
1178             &am_error ("argument to AC_CONFIG_HEADER contains \`/'\n")
1179                 if ($config_header =~ /\//);
1181             &require_file ($NORMAL, $config_header);
1183             # Header defined and in this directory.
1184             if (-f 'acconfig.h')
1185             {
1186                 $output_vars .= "ACCONFIG = acconfig.h\n";
1187                 &push_dist_common ('acconfig.h');
1188             }
1189             if (-f $config_name . '.top')
1190             {
1191                 $output_vars .= "CONFIG_TOP = ${config_name}.top\n";
1192                 &push_dist_common ($config_name . '.top');
1193             }
1194             if (-f $config_name . '.bot')
1195             {
1196                 $output_vars .= "CONFIG_BOT = ${config_name}.bot\n";
1197                 &push_dist_common ($config_name . '.bot');
1198             }
1200             &push_dist_common ('stamp-h.in');
1202             $output_rules .= &file_contents ('remake-hdr');
1203             $output_vars .= "CONFIG_HEADER_IN = ${config_header}\n";
1204         }
1206         $top_reldir = '';
1207     }
1209     &am_error ("\`CONFIG_HEADER' is an anachronism; now determined from \`configure.in'")
1210         if defined $contents{'CONFIG_HEADER'};
1212     # Generate CONFIG_HEADER define, and define interally.
1213     $output_vars .= "CONFIG_HEADER = ${top_builddir}/${config_name}\n"
1214         if $config_name;
1215     $contents{'CONFIG_HEADER'} = "${top_builddir}/${config_name}"
1216         if $config_name;
1218     # Now look for other files in this directory which must be remade
1219     # by config.status, and generate rules for them.
1220     local ($file, $local, $input);
1221     foreach $file (@other_input_files)
1222     {
1223         # Skip files not in this directory, any Makefile, and the
1224         # config header.  These last two must be handled specially.
1225         next unless &dirname ($file) eq $relative_dir;
1226         next if $file eq $top_builddir . '/' . $config_name;
1227         ($local = $file) =~ s/^.*\///;
1228         next if $local eq 'Makefile';
1230         if ($local =~ /^(.*):(.*)$/)
1231         {
1232             # This is the ":" syntax of AC_OUTPUT.
1233             $input = $2;
1234             $local = $1;
1235         }
1236         else
1237         {
1238             # Normal usage.
1239             $input = $local . '.in';
1240         }
1241         # FIXME when using autoconf ":" syntax, should we set CONFIG_FILES
1242         # to $local:$input?
1243         $output_rules .= ($local . ': '
1244                           . '$(top_builddir)/config.status ' . $input . "\n"
1245                           . "\t"
1246                           . 'cd $(top_srcdir) && CONFIG_FILES='
1247                           . ($relative_dir eq '.' ? '' : '$(subdir)/')
1248                           . '$@ CONFIG_HEADERS= ./config.status'
1249                           . "\n");
1250         &require_file ($NORMAL, $local . '.in');
1251     }
1254 # Handle C headers.
1255 sub handle_headers
1257     &am_install_var ('header', 'HEADERS', 'include',
1258                      'oldinclude', 'pkginclude',
1259                      'noinst');
1262 # Handle footer elements.
1263 sub handle_footer
1265     if ($contents{'SOURCES'})
1266     {
1267         &pretty_print ('SOURCES =', "    ",
1268                        split (/\s+/, $contents{'SOURCES'}));
1269     }
1270     if ($contents{'OBJECTS'})
1271     {
1272         &pretty_print ('OBJECTS =', "    ",
1273                        split (/\s+/, $contents{'OBJECTS'}));
1274     }
1275     if ($contents{'SOURCES'} || $contents{'OBJECTS'})
1276     {
1277         $output_vars .= "\n";
1278     }
1280     if (defined $contents{'SUFFIXES'})
1281     {
1282         push (@suffixes, '$(SUFFIXES)');
1283     }
1285     $output_trailer .= ".SUFFIXES:\n";
1286     if (@suffixes)
1287     {
1288         $output_trailer .= ".SUFFIXES: " . join (' ', @suffixes) . "\n";
1289     }
1290     $output_trailer .= &file_contents ('footer');
1293 # Deal with installdirs target.
1294 sub handle_installdirs
1296     # GNU Makefile standards recommend this.
1297     $output_rules .= ("installdirs:"
1298                       . ($recursive_install
1299                          ? " installdirs-recursive\n"
1300                          : "\n"));
1301     push (@phony, 'installdirs');
1302     if (@installdirs)
1303     {
1304         &pretty_print_rule ("\t\$(top_srcdir)/mkinstalldirs ", "\t\t",
1305                             @installdirs);
1306     }
1307     $output_rules .= "\n";
1310 # There are several targets which need to be merged.  This is because
1311 # their complete definition is compiled from many parts.  Note that we
1312 # avoid double colon rules, otherwise we'd use them instead.
1313 sub handle_merge_targets
1315     &do_one_merge_target ('all', @all);
1316     &do_one_merge_target ('info', @info);
1317     &do_one_merge_target ('dvi', @dvi);
1319     if (! defined $contents{'SUBDIRS'} || $relative_dir ne '.')
1320     {
1321         # 'check' must depend on 'all', but not at top level.
1322         unshift (@check, 'all');
1323     }
1324     &do_one_merge_target ('check', @check);
1325     &do_one_merge_target ('installcheck', @installcheck);
1327     # Handle the various install targets specially.  We do this so
1328     # that (eg) "make install-exec" will run "install-exec-recursive"
1329     # if required, but "make install" won't run it twice.  Step one is
1330     # to see if the user specified local versions of any of the
1331     # targets we handle.
1332     if (defined $contents{'install-exec-local'})
1333     {
1334         push (@install_exec, 'install-exec-local');
1335     }
1336     if (defined $contents{'install-data-local'})
1337     {
1338         push (@install_data, 'install-data-local');
1339     }
1340     if (defined $contents{'uninstall-local'})
1341     {
1342         push (@uninstall, 'uninstall-local');
1343     }
1345     if (defined $contents{'install-local'})
1346     {
1347         &am_error ("use \`install-data' or \`install-exec', not \`install'");
1348     }
1350     # Step two: if we are doing recursive makes, write out the
1351     # appropriate rules.
1352     local (@install);
1353     if ($recursive_install)
1354     {
1355         push (@install, 'install-recursive');
1356         push (@uninstall, 'uninstall-recursive');
1358         if (@install_exec)
1359         {
1360             $output_rules .= ('install-exec-am: '
1361                               . join (' ', @install_exec)
1362                               . "\n\n");
1363             @install_exec = ('install-exec-recursive', 'install-exec-am');
1364             push (@install, 'install-exec-am');
1365             push (@phony, 'install-exec-am');
1366         }
1367         if (@install_data)
1368         {
1369             $output_rules .= ('install-data-am: '
1370                               . join (' ', @install_data)
1371                               . "\n\n");
1372             @install_data = ('install-data-recursive', 'install-data-am');
1373             push (@install, 'install-data-am');
1374             push (@phony, 'install-data-am');
1375         }
1376         if (@uninstall)
1377         {
1378             $output_rules .= ('uninstall-am: '
1379                               . join (' ', @uninstall)
1380                               . "\n\n");
1381             @uninstall = ('uninstall-recursive', 'uninstall-am');
1382             push (@phony, 'uninstall-am');
1383         }
1384     }
1386     # Step three: print definitions users can use.
1387     $output_rules .= ("install-exec: "
1388                       . join (' ', @install_exec)
1389                       . "\n\n");
1390     push (@install, 'install-exec') if !$recursive_install;
1391     push (@phony, 'install-exec');
1393     $output_rules .= ("install-data: "
1394                       . join (' ', @install_data)
1395                       . "\n\n");
1396     push (@install, 'install-data') if !$recursive_install;
1397     push (@phony, 'install-data');
1399     # If no dependencies for 'install', add 'all'.  Why?  That way
1400     # "make install" at top level of distclean'd distribution won't
1401     # fail because stuff in 'lib' fails to build.
1402     push (@install, 'all') if ! @install;
1403     $output_rules .= ('install: '
1404                       . join (' ', @install)
1405                       # Use "@:" as empty command so nothing prints.
1406                       . "\n\t\@:"
1407                       . "\n\n"
1408                       . 'uninstall: '
1409                       . join (' ', @uninstall)
1410                       . "\n\n");
1411     push (@phony, 'install', 'uninstall');
1414 # Helper for handle_merge_targets.
1415 sub do_one_merge_target
1417     local ($name, @values) = @_;
1419     if (defined $contents{$name . '-local'})
1420     {
1421         # User defined local form of target.  So include it.
1422         push (@values, $name . '-local');
1423         push (@phony, $name . '-local');
1424     }
1426     $output_rules .= $name . ":";
1427     if (@values)
1428     {
1429         $output_rules .= ' ' . join (' ', @values);
1430     }
1431     $output_rules .= "\n\n";
1432     push (@phony, $name);
1435 # Handle all 'clean' targets.
1436 sub handle_clean
1438     push (@clean, 'generic');
1439     $output_rules .= &file_contents ('clean');
1440     &push_phony_cleaners ('generic');
1442     local ($target) = $recursive_install ? 'clean-am' : 'clean';
1443     &do_one_clean_target ($target, 'mostly', '', @clean);
1444     &do_one_clean_target ($target, '', 'mostly', @clean);
1445     &do_one_clean_target ($target, 'dist', '', @clean);
1446     &do_one_clean_target ($target, 'maintainer-', 'dist', @clean);
1448     push (@phony, 'clean', 'mostlyclean', 'distclean', 'maintainer-clean');
1450     local (@deps);
1451     if ($recursive_install)
1452     {
1453         @deps = ('am', 'recursive');
1454         &do_one_clean_target ('', 'mostly', '', @deps);
1455         &do_one_clean_target ('', '', '', @deps);
1456         &do_one_clean_target ('', 'dist', '', @deps);
1457         &do_one_clean_target ('', 'maintainer-', '', @deps);
1458     }
1461 # Helper for handle_clean.
1462 sub do_one_clean_target
1464     local ($target, $name, $last_name, @deps) = @_;
1466     # Special case: if target not passed, then don't generate
1467     # dependency on next "lower" clean target (eg no
1468     # clean<-mostlyclean derivation).  In this case the target is
1469     # implicitly known to be 'clean'.
1470     local ($flag) = $target;
1471     $target = 'clean' if ! $flag;
1473     grep (($_ = $name . 'clean-' . $_) && 0, @deps);
1474     if ($flag)
1475     {
1476         if ($last_name || $name ne 'mostly')
1477         {
1478             push (@deps, $last_name . $target . " ");
1479         }
1480     }
1481     # FIXME not sure if I like the tabs here.
1482     &pretty_print_rule ($name . $target . ": ", "\t\t", @deps);
1484     # FIXME shouldn't we really print these messages before running
1485     # the dependencies?
1486     if ($name . $target eq 'maintainer-clean')
1487     {
1488         # Print a special warning.
1489         $output_rules .=
1490             ("\t\@echo \"This command is intended for maintainers to use;\"\n"
1491              . "\t\@echo \"it deletes files that may require special "
1492              . "tools to rebuild.\"\n");
1494         $output_rules .= "\trm -f config.status\n"
1495             if $relative_dir eq '.';
1496     }
1497     elsif ($name . $target eq 'distclean')
1498     {
1499         $output_rules .= "\trm -f config.status\n";
1500     }
1501     $output_rules .= "\n";
1504 # Handle .PHONY target.
1505 sub handle_phony
1507     &pretty_print_rule ('.PHONY:', "    ", @phony);
1508     $output_rules .= "\n";
1511 ################################################################
1513 # Scan configure.in for interesting things.
1514 # FIXME ensure VERSION, PACKAGE are set.
1515 sub scan_configure
1517     open (CONFIGURE, 'configure.in')
1518         || die "automake: couldn't open configure.in: $!\n";
1520     # Reinitialize libsources here.  This isn't really necessary,
1521     # since we currently assume there is only one configure.in.  But
1522     # that won't always be the case.
1523     %libsources = ();
1525     local ($in_ac_output, @make_list) = 0;
1526     local ($seen_arg_prog) = 0;
1527     local ($seen_canonical) = 0;
1528     while (<CONFIGURE>)
1529     {
1530         # Remove comments from current line.
1531         s/\bdnl\b.*$//;
1532         s/\#.*$//;
1534         # Populate libobjs array.
1535         if (/AC_FUNC_ALLOCA/)
1536         {
1537             $libsources{'alloca.c'} = 1;
1538         }
1539         elsif (/AC_FUNC_GETLOADAVG/)
1540         {
1541             $libsources{'getloadavg.c'} = 1;
1542         }
1543         elsif (/AC_FUNC_MEMCMP/)
1544         {
1545             $libsources{'memcmp.c'} = 1;
1546         }
1547         elsif (/AC_STRUCT_ST_BLOCKS/)
1548         {
1549             $libsources{'fileblocks.c'} = 1;
1550         }
1551         elsif (/AC_REPLACE_FUNCS\s*\((.*)\)/)
1552         {
1553             foreach (split (/\s+/, $1))
1554             {
1555                 $libsources{$_ . '.c'} = 1;
1556             }
1557         }
1558         elsif (/LIBOBJS="(.*)\.o\s+\$LIBOBJS"/)
1559         {
1560             $libsources{$1 . '.c'} = 1;
1561         }
1562         elsif (/LIBOBJS="\$LIBOBJS\s+(.*)\.o"/)
1563         {
1564             $libsources{$1 . '.c'} = 1;
1565         }
1567         # Process the AC_OUTPUT macro.
1568         if (! $in_ac_output && s/AC_OUTPUT\s*\(\[?//)
1569         {
1570             $in_ac_output = 1;
1571         }
1572         if ($in_ac_output)
1573         {
1574             s/\].*$//;
1575             $in_ac_output = 0 if s/[\),].*$//;
1577             # Look at potential Makefile.am's.
1578             foreach (split)
1579             {
1580                 if (-f $_ . '.am')
1581                 {
1582                     push (@make_list, $_);
1583                 }
1584                 else
1585                 {
1586                     push (@other_input_files, $_);
1587                 }
1588             }
1589         }
1591         # Check for ansi2knr.
1592         $fp_c_prototypes = 1 if /fp_C_PROTOTYPES/;
1594         # Check for NLS support.
1595         if (/ud_GNU_GETTEXT/)
1596         {
1597             $seen_gettext = 1;
1598         }
1600         # Handle configuration headers.
1601         if (/AC_CONFIG_HEADER\s*\((.*)\)/)
1602         {
1603             $config_name = $1;
1604             if ($config_name =~ /^([^:]+):(.+)$/)
1605             {
1606                 $config_name = $1;
1607                 $config_header = $2;
1608             }
1609             else
1610             {
1611                 $config_header = $config_name . '.in';
1612             }
1613         }
1615         $seen_canonical = 1 if /AC_CANONICAL_(HOST|SYSTEM)/;
1616         $seen_path_xtra = 1 if /AC_PATH_XTRA/;
1618         # Some things required by Automake.  FIXME we only really
1619         # require fp_PROG_INSTALL if some scripts are installed.  And
1620         # we only really require AC_ARG_PROGRAM if any program is
1621         # installed.
1622         $seen_make_set = 1 if /AC_PROG_MAKE_SET/;
1623         $seen_prog_install = 1 if ! $seen_prog_install && /AC_PROG_INSTALL/;
1624         $seen_prog_install = 2 if ! $seen_prog_install && /fp_PROG_INSTALL/;
1625         $seen_arg_prog = 1 if /AC_ARG_PROGRAM/;
1626     }
1628     # Set input files if not specified by user.
1629     @input_files = @make_list if (! @input_files);
1631     # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
1632     # config.sub.
1633     &require_file ($NORMAL, 'config.guess', 'config.sub')
1634         if $seen_canonical;
1636     &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
1637         unless $seen_arg_prog;
1639     close (CONFIGURE);
1642 ################################################################
1644 # Do any extra checking for GNU standards.
1645 sub check_gnu_standards
1647     &require_file ($GNU, 'ChangeLog');
1649     if ($relative_dir eq '.')
1650     {
1651         # In top level (or only) directory.
1652         &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
1653                        'AUTHORS');
1654     }
1657 # Do any extra checking for GNITS standards.
1658 sub check_gnits_standards
1660     if ($strictness >= $GNITS && -f $relative_dir . '/COPYING.LIB')
1661     {
1662         &am_error
1663             ("\`${relative_dir}/COPYING.LIB' disallowed by Gnits standards");
1664     }
1666     if ($relative_dir eq '.')
1667     {
1668         # In top level (or only) directory.
1669         &require_file ($GNITS, 'THANKS');
1670     }
1673 ################################################################
1675 # Pretty-print something.  HEAD is what should be printed at the
1676 # beginning of the first line, FILL is what should be printed at the
1677 # beginning of every subsequent line.
1678 sub pretty_print_internal
1680     local ($head, $fill, @values) = @_;
1682     local ($column) = length ($head);
1683     local ($result) = $head;
1685     # Fill length is number of characters.  However, each Tab
1686     # character counts for eight.  So we count the number of Tabs and
1687     # multiply by 7.
1688     local ($fill_length) = length ($fill);
1689     $fill_length += 7 * ($fill =~ tr/\t/\t/d);
1691     local ($bol) = 0;
1692     foreach (@values)
1693     {
1694         # "71" because we also print a space.
1695         if ($column + length ($_) > 71)
1696         {
1697             $result .= " \\\n" . $fill;
1698             $column = $fill_length;
1699             $bol = 1;
1700         }
1702         $result .= ' ' unless ($bol);
1703         $result .= $_;
1704         $column += length ($_) + 1;
1705         $bol = 0;
1706     }
1708     $result .= "\n";
1709     return $result;
1712 # Pretty-print something and append to output_vars.
1713 sub pretty_print
1715     $output_vars .= &pretty_print_internal (@_);
1718 # Pretty-print something and append to output_rules.
1719 sub pretty_print_rule
1721     $output_rules .= &pretty_print_internal (@_);
1725 ################################################################
1727 # Read Makefile.am and set up %contents.  Simultaneously copy lines
1728 # from Makefile.am into $output_trailer or $output_vars as
1729 # appropriate.  NOTE we put rules in the trailer section.  We want
1730 # user rules to come after our generated stuff.
1731 sub read_am_file
1733     local ($amfile) = @_;
1735     # Compute relative location of the top object directory.
1736     local (@topdir) = ();
1737     foreach (split (/\//, $relative_dir))
1738     {
1739         next if $_ eq '.' || $_ eq '';
1740         if ($_ eq '..')
1741         {
1742             pop @topdir;
1743         }
1744         else
1745         {
1746             push (@topdir, '..');
1747         }
1748     }
1749     @topdir = ('.') if ! @topdir;
1751     $top_builddir = join ('/', @topdir);
1752     local ($build_rx);
1753     ($build_rx = $top_builddir) =~ s/(\W)/\\$1/g;
1754     local ($header_vars) =
1755         &file_contents_with_transform
1756             ('s/\@top_builddir\@/' . $build_rx . '/g',
1757              'header-vars');
1759     open (AM_FILE, $amfile) || die "automake: couldn't open $amfile: $!\n";
1761     $output_vars .= ("# Makefile.in generated automatically by automake "
1762                      . $VERSION . " from Makefile.am\n");
1764     # Generate copyright for generated Makefile.in.
1765     $output_vars .= $gen_copyright;
1767     local ($saw_bk) = 0;
1768     local ($was_rule) = 0;
1769     local ($spacing) = '';
1770     local ($comment) = '';
1771     local ($last_var_name) = '';
1773     while (<AM_FILE>)
1774     {
1775         if (/$IGNORE_PATTERN/o)
1776         {
1777             # Merely delete comments beginning with two hashes.
1778         }
1779         elsif (/$WHITE_PATTERN/o)
1780         {
1781             # Stick a single white line before the incoming macro or rule.
1782             $spacing = "\n";
1783         }
1784         elsif (/$COMMENT_PATTERN/o)
1785         {
1786             # Stick comments before the incoming macro or rule.
1787             $comment .= $spacing . $_;
1788             $spacing = '';
1789         }
1790         else
1791         {
1792             last;
1793         }
1794     }
1796     $output_vars .= $comment . "\n" . $header_vars;
1797     $comment = '';
1798     $spacing = "\n";
1800     while ($_)
1801     {
1802         if (/$IGNORE_PATTERN/o)
1803         {
1804             # Merely delete comments beginning with two hashes.
1805         }
1806         elsif (/$WHITE_PATTERN/o)
1807         {
1808             # Stick a single white line before the incoming macro or rule.
1809             $spacing = "\n";
1810         }
1811         elsif (/$COMMENT_PATTERN/o)
1812         {
1813             # Stick comments before the incoming macro or rule.
1814             $comment .= $spacing . $_;
1815             $spacing = '';
1816         }
1817         elsif ($saw_bk)
1818         {
1819             if ($was_rule)
1820             {
1821                 $output_trailer .= $_;
1822                 $saw_bk = /\\$/;
1823             }
1824             else
1825             {
1826                 $output_vars .= $_;
1827                 $saw_bk = /\\$/;
1828                 # Chop newline and backslash if this line is
1829                 # continued.  FIXME maybe ensure trailing whitespace
1830                 # exists?
1831                 chop if $saw_bk;
1832                 chop if $saw_bk;
1833                 $contents{$last_var_name} .= $_;
1834             }
1835         }
1836         elsif (/$RULE_PATTERN/o)
1837         {
1838             # warn "** Saw rule .$1.\n";
1839             # Found a rule.
1840             $was_rule = 1;
1841             # Value here doesn't matter; for targets we only note
1842             # existence.
1843             $contents{$1} = 1;
1844             $output_trailer .= $comment . $spacing . $_;
1845             $comment = $spacing = '';
1846             $saw_bk = /\\$/;
1847         }
1848         elsif (/$MACRO_PATTERN/o)
1849         {
1850             # warn "** Saw macro .$1.\n";
1851             # Found a macro definition.
1852             $was_rule = 0;
1853             $last_var_name = $1;
1854             if (substr ($2, -1) eq "\\")
1855             {
1856                 $contents{$1} = substr ($2, 0, length ($2) - 1);
1857             }
1858             else
1859             {
1860                 $contents{$1} = $2;
1861             }
1862             $output_vars .= $comment . $spacing . $_;
1863             $comment = $spacing = '';
1864             $saw_bk = /\\$/;
1865         }
1866         elsif ($_ eq "\@kr\@\n")
1867         {
1868             # Special case: this means we want automatic
1869             # de-ANSI-fication.  This is deprecated.  Remove in the
1870             # future.
1871             $contents{'@kr@'} = 1;
1872             &am_error ('`@kr@\' is deprecated; put `ansi2knr\' in AUTOMAKE_OPTIONS instead');
1873         }
1874         else
1875         {
1876             # This isn't an error; it is probably a continued rule.
1877             # In fact, this is what we assume.
1878             $was_rule = 1;
1879             $output_trailer .= $comment . $spacing . $_;
1880             $comment = $spacing = '';
1881             $saw_bk = /\\$/;
1882         }
1884         $_ = <AM_FILE>;
1885     }
1887     $output_trailer .= $comment;
1890 ################################################################
1892 sub initialize_global_constants
1894     # Associative array of standard directory names.  Entry is TRUE if
1895     # corresponding directory should be installed during
1896     # 'install-exec' phase.
1897     %exec_dir_p =
1898         ('bin', 1,
1899          'sbin', 1,
1900          'libexec', 1,
1901          'data', 0,
1902          'sysconf', 1,
1903          'localstate', 1,
1904          'lib', 1,
1905          'info', 0,
1906          'man', 0,
1907          'include', 0,
1908          'oldinclude', 0,
1909          'pkgdata', 0,
1910          'pkglib', 1,
1911          'pkginclude', 0
1912          );
1914     # Helper text for dealing with man pages.
1915     $install_man_format =
1916     '   @sect=@SECTION@;                                \\
1917         inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
1918         echo installing @MAN@ as $(mandir)/man$$sect/$$inst; \\
1919         $(INSTALL_DATA) $(srcdir)/@MAN@ $(mandir)/man$$sect/$$inst
1922     $uninstall_man_format =
1923     '   inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
1924         rm -f $(mandir)/man@SECTION@/$$inst
1927     # Commonly found files we look for and automatically include in
1928     # DISTFILES.
1929     @common_files =
1930         (
1931          "README", "THANKS", "TODO", "NEWS", "COPYING", "COPYING.LIB",
1932          "INSTALL", "ABOUT-NLS", "ChangeLog", "configure", "configure.in",
1933          "config.guess", "config.sub", "AUTHORS", "BACKLOG", "ABOUT-GNU"
1934          );
1936     # Commonly used files we auto-include, but only sometimes.
1937     @common_sometimes =
1938         (
1939          "version.texi", "aclocal.m4", "acconfig.h", "config.h.top",
1940          "config.h.bot", "stamp-h.in", "mdate-sh", "ansi2knr.c",
1941          "ansi2knr.1", 'stamp-vti', "mkinstalldirs", "install-sh"
1942          );
1944     $USAGE = "\
1945   --amdir=DIR           directory storing config files
1946   --gnits               same as --strictness=gnits
1947   --gnu                 same as --strictness=gnu
1948   --help                print this help, then exit
1949   --include-deps        include generated dependencies in Makefile.in
1950   --install-missing     install missing standard files
1951   --output-dir=DIR      put generated Makefile.in's into DIR
1952   --strictness=LEVEL    set strictness level.  LEVEL is normal, gnu, gnits
1953   --version             print version number, then exit\n";
1955     # Copyright on generated Makefile.ins.
1956     $gen_copyright = "\
1957 # Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
1958 # This Makefile.in is free software; the Free Software Foundation
1959 # gives unlimited permission to copy, distribute and modify it.
1963 # (Re)-Initialize per-Makefile.am variables.
1964 sub initialize_per_input
1966     # These two variables are used when generating each Makefile.in.
1967     # They hold the Makefile.in until it is ready to be printed.
1968     $output_rules = '';
1969     $output_vars = '';
1970     $output_trailer = '';
1972     # Suffixes found during a run.
1973     @suffixes = ();
1975     # This holds the contents of a Makefile.am, as parsed by
1976     # read_am_file.
1977     %contents = ();
1979     # This holds the "relative directory" of the current Makefile.in.
1980     # Eg for src/Makefile.in, this is "src".
1981     $relative_dir = '';
1983     # Directory where output files go.  Actually, output files are
1984     # relative to this directory.
1985     $output_directory = '.';
1987     # This holds a list of files that are included in the
1988     # distribution.
1989     %dist_common = ();
1991     # List of dependencies for the obvious targets.
1992     @install_data = ();
1993     @install_exec = ();
1994     @uninstall = ();
1995     @installdirs = ();
1997     @info = ();
1998     @dvi = ();
1999     @all = ();
2000     @check = ();
2001     @installcheck = ();
2002     @clean = ();
2004     @phony = ();
2006     # These are pretty obvious, too.  They are used to define the
2007     # SOURCES and OBJECTS variables.
2008     @sources = ();
2009     @objects = ();
2011     # TRUE if current directory holds any C source files.  (Actually
2012     # holds object extension, but this information is encapsulated in
2013     # the function get_object_extension).
2014     $dir_holds_sources = '';
2016     # TRUE if install targets should work recursively.
2017     $recursive_install = 0;
2019     # All .P files.
2020     %dep_files = ();
2022     # Strictness levels.
2023     $strictness = $default_strictness;
2024     $strictness_name = $default_strictness_name;
2026     # Options from AUTOMAKE_OPTIONS.
2027     %options = ();
2029     # Whether or not dependencies are handled.  Can be further changed
2030     # in handle_options.
2031     $use_dependencies = $cmdline_use_dependencies;
2033     # Per Makefile.am.
2034     $local_maint_charset = $maint_charset;
2038 ################################################################
2040 # Return contents of a file from $am_dir, automatically skipping
2041 # macros or rules which are already known.  Runs command on each line
2042 # as it is read; this command can modify $_.
2043 sub file_contents_with_transform
2045     local ($command, $basename) = @_;
2046     local ($file) = $am_dir . '/' . $basename . '.am';
2048     open (FC_FILE, $file)
2049         || die "automake: installation error: cannot open \`$file'\n";
2051     local ($was_rule) = 0;
2052     local ($result_vars) = '';
2053     local ($result_rules) = '';
2054     local ($comment) = '';
2055     local ($spacing) = "\n";
2056     local ($skipping) = 0;
2058     while (<FC_FILE>)
2059     {
2060         eval $command;
2062         if (/$IGNORE_PATTERN/o)
2063         {
2064             # Merely delete comments beginning with two hashes.
2065         }
2066         elsif (/$WHITE_PATTERN/o)
2067         {
2068             # Stick a single white line before the incoming macro or rule.
2069             $spacing = "\n";
2070         }
2071         elsif (/$COMMENT_PATTERN/o)
2072         {
2073             # Stick comments before the incoming macro or rule.
2074             $comment .= $spacing . $_;
2075             $spacing = '';
2076         }
2077         elsif ($saw_bk)
2078         {
2079             if ($was_rule)
2080             {
2081                 $result_rules .= $_ if ! $skipping;
2082             }
2083             else
2084             {
2085                 $result_vars .= $_ if ! $skipping;
2086             }
2087             $saw_bk = /\\$/;
2088         }
2089         elsif (/$RULE_PATTERN/o)
2090         {
2091             # warn "** Found rule .$1.\n";
2092             # Found a rule.
2093             $was_rule = 1;
2094             $skipping = defined $contents{$1};
2095             # warn "** Skip $skipping\n" if $skipping;
2096             $result_rules .= $comment . $spacing . $_ if ! $skipping;
2097             $comment = $spacing = '';
2098             $saw_bk = /\\$/;
2099         }
2100         elsif (/$MACRO_PATTERN/o)
2101         {
2102             # warn "** Found macro .$1.\n";
2103             # Found a variable reference.
2104             $was_rule = 0;
2105             $skipping = defined $contents{$1};
2106             # warn "** Skip $skipping\n" if $skipping;
2107             $result_vars .= $comment . $spacing . $_ if ! $skipping;
2108             $comment = $spacing = '';
2109             $saw_bk = /\\$/;
2110         }
2111         else
2112         {
2113             # This isn't an error; it is probably a continued rule.
2114             # In fact, this is what we assume.
2115             $was_rule = 1;
2116             $result_rules .= $comment . $spacing . $_ if ! $skipping;
2117             $comment = $spacing = '';
2118             $saw_bk = /\\$/;
2119         }
2120     }
2122     close (FC_FILE);
2123     return $result_vars . $result_rules . $comment;
2126 # Like file_contents_with_transform, but no transform.
2127 sub file_contents
2129     return &file_contents_with_transform ('', @_);
2132 # Handle `where_HOW' variable magic.  Does all lookups, generates
2133 # install code,and possibly generates code to define the primary
2134 # variable.  The first argument is the name of the .am file to munge,
2135 # the second argument is the primary variable (eg HEADERS), and all
2136 # subsequent arguments are possible installation locations.  Returns
2137 # list of all values of all _HOW targets.
2139 # FIXME this should be rewritten to be cleaner.  It should be broken
2140 # up into multiple functions.
2142 # Usage is: am_install_var (OPTION..., file, HOW, where...)
2143 sub am_install_var
2145     local (@args) = @_;
2147     local ($do_all, $do_clean) = (1, 0);
2148     while (@args)
2149     {
2150         if ($args[0] eq '-clean')
2151         {
2152             $do_clean = 1;
2153         }
2154         elsif ($args[0] eq '-no-all')
2155         {
2156             $do_all = 0;
2157         }
2158         elsif ($args[0] !~ /^-/)
2159         {
2160             last;
2161         }
2162         shift (@args);
2163     }
2164     local ($file, $primary, @prefixes) = @args;
2166     local (@used) = ();
2167     local (@result) = ();
2169     local ($clean_file) = $file . '-clean';
2170     local ($one_name);
2171     local ($X);
2172     foreach $X (@prefixes)
2173     {
2174         $one_name = $X . '_' . $primary;
2175         if (defined $contents{$one_name})
2176         {
2177             # Append actual contents to result.
2178             push (@result, split (/\s+/, $contents{$one_name}));
2180             if ($do_clean)
2181             {
2182                 $output_rules .=
2183                     &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go',
2184                                                    $clean_file);
2186                 push (@clean, $X . $primary);
2187                 &push_phony_cleaners ($X . $primary);
2188             }
2190             push (@used, '$(' . $one_name . ')');
2191             if ($X eq 'noinst')
2192             {
2193                 # Objects in noinst_FOO never get installed.
2194                 next;
2195             }
2197             $output_rules .=
2198                 &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go',
2199                                                $file);
2201             push (@uninstall, 'uninstall-' . $X . $primary);
2202             push (@phony, 'uninstall-' . $X . $primary);
2203             push (@installdirs, '$(' . $X . 'dir)');
2204             if ($exec_dir_p{$X})
2205             {
2206                 push (@install_exec, 'install-' . $X . $primary);
2207             }
2208             else
2209             {
2210                 push (@install_data, 'install-' . $X . $primary);
2211             }
2212         }
2213     }
2215     if (! defined $contents{$primary} && @used)
2216     {
2217         # Define it.
2218         &pretty_print ($primary . ' =', '', @used);
2219         $output_vars .= "\n";
2220     }
2222     # Push here because PRIMARY might be configure time determined.
2223     push (@all, '$(' . $primary . ')') if ($do_all && @used);
2225     # Look for misspellings.  It is an error to have a variable ending
2226     # in a "reserved" suffix whose prefix is unknown, eg
2227     # "bni_PROGRAMS".
2228     local (%valid, $varname);
2229     grep ($valid{$_} = 0, @prefixes);
2230     foreach $varname (keys %contents)
2231     {
2232         if ($varname =~ /^(.*)_$primary$/ && ! defined $valid{$1})
2233         {
2234             &am_error ("invalid variable \"$varname\"");
2235         }
2236     }
2238     return (@result);
2242 ################################################################
2244 # Verify that the file must exist in the current directory.
2245 # Usage: require_file (strictness, file)
2246 # strictness is the strictness level at which this file becomes
2247 # required.
2248 sub require_file
2250     local ($mystrict, @files) = @_;
2251     local ($file, $fullfile);
2253     foreach $file (@files)
2254     {
2255         $fullfile = $relative_dir . "/" . $file;
2257         if (-f $fullfile)
2258         {
2259             &push_dist_common ($file);
2260         }
2261         elsif ($strictness >= $mystrict)
2262         {
2263             # Only install missing files according to our desired
2264             # strictness level.
2265             if ($install_missing && -f ($am_dir . '/' . $file))
2266             {
2267                 # Install the missing file.  Symlink if we can, copy
2268                 # if we must.
2269                 if ($symlink_exists)
2270                 {
2271                     symlink ($am_dir . '/' . $file, $fullfile);
2272                 }
2273                 else
2274                 {
2275                     system ('cp', $am_dir . '/' . $file, $fullfile);
2276                 }
2277                 &am_error
2278                     ("required file \"$fullfile\" not found; installing");
2279             }
2280             else
2281             {
2282                 # Only an error if strictness constraint violated.
2283                 &am_error ("required file \"$fullfile\" not found");
2284             }
2285         }
2286     }
2289 # Push a list of files onto dist_common.
2290 sub push_dist_common
2292     local (@files) = @_;
2293     local ($file);
2295     foreach $file (@files)
2296     {
2297         $dist_common{$file} = 1;
2298     }
2301 # Push a list of clean targets onto phony.
2302 sub push_phony_cleaners
2304     local ($base) = @_;
2305     local ($target);
2306     foreach $target ('mostly', 'dist', '', 'maintainer-')
2307     {
2308         push (@phony, $target . 'clean-' . $base);
2309     }
2312 # Set strictness.
2313 sub set_strictness
2315     $strictness_name = $_[0];
2316     if ($strictness_name eq 'gnu')
2317     {
2318         $strictness = $GNU;
2319     }
2320     elsif ($strictness_name eq 'gnits')
2321     {
2322         $strictness = $GNITS;
2323     }
2324     elsif ($strictness_name eq 'normal')
2325     {
2326         $strictness = $NORMAL;
2327     }
2328     else
2329     {
2330         die "automake: level \`$strictness_name' not recognized\n";
2331     }
2335 ################################################################
2337 # Return directory name of file.
2338 sub dirname
2340     local ($file) = @_;
2341     local ($sub);
2343     ($sub = $file) =~ s,/+[^/]+$,,g;
2344     $sub = '.' if $sub eq $file;
2345     return $sub;
2348 # Make a directory.
2349 sub mkdir
2351     local ($dirname) = @_;
2352     system ("mkdir", $dirname);
2355 ################################################################
2357 # Print an error message and set exit status.
2358 sub am_error
2360     warn "automake: ${am_file}.am: ", join (' ', @_), "\n";
2361     $exit_status = 1;
2364 # The same, but while scanning configure.in.
2365 sub am_conf_error
2367     # FIXME can run in subdirs.
2368     warn "automake: configure.in: ", join (' ', @_), "\n";
2369     $exit_status = 1;
2372 # Print usage information.
2373 sub usage
2375     print "Usage: automake [OPTION] ... [Makefile]...\n";
2376     print $USAGE;
2377     print "\nFiles which are automatically distributed, if found:\n";
2378     $~ = "USAGE_FORMAT";
2379     local (@lcomm) = sort ((@common_files, @common_sometimes));
2380     local ($one, $two, $three, $four);
2381     while (@lcomm > 0)
2382     {
2383         $one = shift @lcomm;
2384         $two = @lcomm ? shift @lcomm : '';
2385         $three = @lcomm ? shift @lcomm : '';
2386         $four = @lcomm ? shift @lcomm : '';
2387         write;
2388     }
2390     exit 0;
2393 format USAGE_FORMAT =
2394   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
2395   $one,               $two,               $three,             $four