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)
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
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@";
34 $am_dir = "@datadir@/@PACKAGE@";
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.
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.
66 # This holds our (eventual) exit status. We don't actually exit until
67 # we have processed all input files.
70 # From the Perl manual.
71 $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
73 # TRUE if missing standard files should be installed.
76 # Files found by scanning configure.in for LIBOBJS.
79 # True if fp_C_PROTOTYPES appears in configure.in.
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.
88 # Line number at which AC_CONFIG_HEADER appears in configure.in.
89 $config_header_line = 0;
91 # Relative location of top build directory.
94 # List of Makefile.am's to process.
97 # List of files in AC_OUTPUT without Makefile.am.
98 @other_input_files = ();
100 # Whether AC_PROG_MAKE_SET has been seen in configure.in.
103 # Whether ud_GNU_GETTEXT has been seen in configure.in.
106 # 1 if AC_PROG_INSTALL seen, 2 if fp_PROG_INSTALL seen.
107 $seen_prog_install = 0;
109 # 1 if any scripts installed, 0 otherwise.
110 $scripts_installed = 0;
112 # Whether AC_PATH_XTRA has been seen in configure.in.
115 # Whether YACC variable has been seen in configure.in.
118 # TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM). The presence of
119 # AC_CHECK_TOOL also sets this.
122 # TRUE if we've seen AC_PROG_RANLIB.
125 # Charsets used by maintainer and in distribution. MAINT_CHARSET is
126 # handled in a funny way: if seen in the top-level Makefile.am, it is
127 # used for every directory which does not specify a different value.
128 # The rationale here is that some directories (eg gettext) might be
129 # distributions of other packages, and thus require their own charset
130 # info. However, the DIST_CHARSET must be the same for the entire
131 # package; it can only be set at top-level.
132 # FIXME this yields bugs when rebuilding. What to do? Always
133 # read (and sometimes discard) top-level Makefile.am?
135 $dist_charset = 'utf8'; # recode doesn't support this yet.
139 &initialize_global_constants;
141 # Parse command line.
142 &parse_arguments (@ARGV);
144 # Do configure.in scan only once.
147 die "automake: no \`Makefile.am' found or specified\n"
150 # Now do all the work on each file.
151 foreach $am_file (@input_files)
153 # FIXME should support the AC_OUTPUT ":" syntax here.
154 if (! -f ($am_file . '.am'))
156 &am_error ('no such file');
160 &generate_makefile ($am_file);
164 if ($seen_prog_install <= $scripts_installed)
166 &am_conf_error (($scripts_installed ? 'fp_PROG_INSTALL' : 'AC_PROG_INSTALL')
167 . " must be used in configure.in");
168 &keyed_aclocal_warning ('fp_PROG_INSTALL')
169 if $scripts_installed;
175 ################################################################
177 # Parse command line.
180 local (@arglist) = @_;
182 # Start off as normal.
183 &set_strictness ('normal');
187 if ($arglist[0] eq "--version")
189 print "Automake version $VERSION\n";
192 elsif ($arglist[0] eq "--help")
196 elsif ($arglist[0] =~ /^--amdir=(.+)$/)
200 elsif ($arglist[0] eq '--amdir')
202 &require_argument (@arglist);
204 $am_dir = $arglist[0];
206 elsif ($arglist[0] =~ /^--strictness=(.+)$/)
208 &set_strictness ($1);
210 elsif ($arglist[0] eq '--gnu')
212 &set_strictness ('gnu');
214 elsif ($arglist[0] eq '--gnits')
216 &set_strictness ('gnits');
218 elsif ($arglist[0] eq '--strictness')
220 &require_argument (@arglist);
222 &set_strictness ($arglist[0]);
224 elsif ($arglist[0] eq '--include-deps')
226 $cmdline_use_dependencies = 0;
228 elsif ($arglist[0] =~ /^--output-dir=(.*)$/)
230 # Set output directory.
231 $output_directory = $1;
233 elsif ($arglist[0] eq '--output-dir')
235 &require_argument (@arglist);
237 $output_directory = $arglist[0];
239 elsif ($arglist[0] eq '--install-missing')
241 $install_missing = 1;
243 elsif ($arglist[0] eq '--verbose')
247 elsif ($arglist[0] eq '--')
249 # Stop option processing.
251 push (@input_files, @arglist);
254 elsif ($arglist[0] =~ /^-/)
256 die "automake: unrecognized option -- \`$arglist[0]'\n";
260 push (@input_files, $arglist[0]);
266 # Take global strictness from whatever we currently have set.
267 $default_strictness = $strictness;
268 $default_strictness_name = $strictness_name;
271 # Ensure argument exists, or die.
274 local ($arg, @arglist) = @_;
275 die "automake: no argument given for option \`$arg'\n"
279 ################################################################
281 # Generate a Makefile.in given the name of the corresponding Makefile.
282 sub generate_makefile
284 local ($makefile) = @_;
286 print "automake: creating ", $makefile, ".in\n" if $verbose;
288 &initialize_per_input;
289 $relative_dir = &dirname ($makefile);
291 # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
293 &require_file ($NORMAL, 'config.guess', 'config.sub')
294 if $relative_dir eq '.' && $seen_canonical;
296 # FIXME with new 'dist' target, don't need Makefile.in. Probably
297 # should remove it here.
298 &push_dist_common ('Makefile.in', 'Makefile.am');
299 push (@sources, '$(SOURCES)') if defined $contents{'SOURCES'};
300 push (@objects, '$(OBJECTS)') if defined $contents{'OBJECTS'};
302 # This is always the default target. This gives us freedom to do
303 # things in whatever order is convenient.
304 $output_rules .= "default: all\n\n";
305 push (@phony, 'default');
307 &read_am_file ($makefile . '.am');
310 # Check first, because we might modify some state.
311 &check_gnu_standards;
312 &check_gnits_standards;
319 # Re-init SOURCES and OBJECTS. FIXME other code shouldn't depend
320 # on this (but currently does).
321 $contents{'SOURCES'} = join (' ', @sources);
322 $contents{'OBJECTS'} = join (' ', @objects);
331 &handle_dependencies;
334 &handle_merge_targets;
339 if (! -d ($output_directory . '/' . $relative_dir))
341 &mkdir ($output_directory . '/' . $relative_dir);
343 if (! open (GM_FILE, "> " . $output_directory . '/' . $makefile . ".in"))
345 warn "automake: ${am_file}.in: cannot open: $!\n";
350 print GM_FILE $output_vars;
351 print GM_FILE $output_rules;
352 print GM_FILE $output_trailer;
357 ################################################################
359 # Handle AUTOMAKE_OPTIONS variable.
362 return if ! defined $contents{'AUTOMAKE_OPTIONS'};
364 foreach (split (/\s+/, $contents{'AUTOMAKE_OPTIONS'}))
367 if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'normal')
369 &set_strictness ($_);
371 elsif ($_ eq 'no-installman' || $_ eq 'ansi2knr' || $_ eq 'dist-shar')
373 # Explicitly recognize these.
375 elsif ($_ eq 'no-dependencies')
377 $use_dependencies = 0;
379 elsif (/[0-9]+\.?[0-9]+/)
381 # Got a version number. Is the syntax too strict?
384 &am_line_error ('AUTOMAKE_OPTIONS',
385 "require version $_, only have $VERSION");
386 # FIXME -- what else to do?
392 &am_line_error ('AUTOMAKE_OPTIONS',
393 'option ', $_, 'not recognized');
398 # Return object extension. Just once, put some code into the output.
399 sub get_object_extension
401 if (! $dir_holds_sources)
405 if (defined $contents{'CONFIG_HEADER'})
407 ($xform = &dirname ($contents{'CONFIG_HEADER'}))
409 $xform = 's/\@CONFIG_INCLUDE_SPEC\@/-I' . $xform . '/go';
411 $output_vars .= &file_contents_with_transform ($xform,
413 $output_rules .= &file_contents ('compile');
414 &push_phony_cleaners ('compile');
416 # If using X, include some extra variable definitions. NOTE
417 # we don't want to force these into CFLAGS or anything,
418 # because not all programs will necessarily use X.
421 $output_vars .= ("X_CFLAGS = \@X_CFLAGS\@\n"
422 . "X_LIBS = \@X_LIBS\@\n"
423 . "X_EXTRA_LIBS = \@X_EXTRA_LIBS\@\n"
424 . "X_PRE_LIBS = \@X_PRE_LIBS\@\n");
427 # Check for automatic de-ANSI-fication.
428 $dir_holds_sources = '.o';
429 push (@suffixes, '.c', '.o');
430 push (@clean, 'compile');
432 if (defined $options{'ansi2knr'})
434 if (! $fp_c_prototypes)
436 &am_line_error ('AUTOMAKE_OPTIONS',
437 "option \`ansi2knr' in use but \`fp_C_PROTOTYPES' not in configure.in");
438 &keyed_aclocal_warning ('fp_C_PROTOTYPES');
439 # Only give this error once.
440 $fp_c_prototypes = 1;
443 $dir_holds_sources = '$o';
444 push (@suffixes, '._c', '._o');
446 &require_file ($NORMAL, 'ansi2knr.c', 'ansi2knr.1');
448 $output_vars .= &file_contents ('kr-vars');
449 $output_rules .= &file_contents ('compile-kr');
450 $output_rules .= &file_contents ('clean-kr');
453 &push_phony_cleaners ('kr');
456 return $dir_holds_sources;
459 # Handle SOURCE->OBJECT transform for one program or library.
460 sub handle_source_transform
462 local ($one_file, $obj) = @_;
463 local ($objpat) = $obj;
464 $objpat =~ s/(\W)/\\$1/g;
466 # Look for file_SOURCES and file_OBJECTS.
467 if (defined $contents{$one_file . "_SOURCES"})
469 if (! defined $contents{$one_file . "_OBJECTS"})
471 # Turn sources into objects.
472 local (@files) = split (/\s+/, $contents{$one_file . "_SOURCES"});
473 local (@result) = ();
476 # Skip header files, including C++-ish ones.
479 # Skip things that look like macro references.
480 next if /^\$\(.*\)$/;
481 next if /^\$\{.*\}$/;
485 # Automatically include generated .c file in
487 &push_dist_common ($1 . '.c');
490 # Transform source files into .o files.
493 s/\.[cCmylfs]$/$obj/g;
496 # Transform .o or $o file into .P file (for automatic
499 $dep_files{'$(srcdir)/.deps/' . $_} = 1;
502 &pretty_print ($one_file . "_OBJECTS =", "", @result);
506 &am_line_error ($one_file . '_OBJECTS',
507 $one_file . '_OBJECTS', 'should not be defined');
510 push (@sources, '$(' . $one_file . "_SOURCES)");
511 push (@objects, '$(' . $one_file . "_OBJECTS)");
515 $output_vars .= ($one_file . "_SOURCES = " . $one_file . ".c\n"
516 . $one_file . "_OBJECTS = ". $one_file
518 push (@sources, $one_file . '.c');
519 push (@objects, $one_file . $obj);
520 $dep_files{'$(srcdir)/.deps/' . $one_file . '.P'} = 1;
523 if (defined $contents{'CONFIG_HEADER'})
525 $output_rules .= ('$(' . $one_file . "_OBJECTS): "
526 . $contents{'CONFIG_HEADER'} . "\n");
535 local (@proglist) = &am_install_var ('-clean',
536 'programs', 'PROGRAMS',
537 'bin', 'sbin', 'libexec', 'pkglib',
539 return if ! @proglist;
541 local ($obj) = &get_object_extension;
542 local ($one_file, $munge);
544 foreach $one_file (@proglist)
546 &handle_source_transform ($one_file, $obj);
548 if (! defined $contents{$one_file . "_LDADD"})
550 # User didn't define prog_LDADD override. So do it.
551 $output_vars .= $one_file . '_LDADD = $(LDADD)' . "\n";
555 &file_contents_with_transform ('s/\@PROGRAM\@/' . $one_file
563 local (@liblist) = &am_install_var ('-no-all', '-clean',
564 'libraries', 'LIBRARIES',
565 'lib', 'pkglib', 'noinst');
566 return if ! @liblist;
570 # FIXME need am_line_error here. But we don't know which
571 # variable exists. Must add a loop...
572 &am_error ("building a library but \`AC_PROG_RANLIB' not in configure.in");
573 # Only get this error once.
577 # Generate _LIBFILES variables. Too bad we can't do this in
579 local ($onedir, $onelib);
581 foreach $onedir ('lib', 'pkglib', 'noinst')
583 if (defined $contents{$onedir . '_LIBRARIES'})
586 foreach $onelib (split (/\s+/, $contents{$onedir . '_LIBRARIES'}))
588 push (@outlist, 'lib' . $onelib . '.a');
590 &pretty_print ($onedir . '_LIBFILES =', "", @outlist);
593 push (@all, '$(LIBFILES)');
595 local ($obj) = &get_object_extension;
597 foreach $onelib (@liblist)
599 if (defined $contents{$onelib . '_LIBADD'})
601 # We recognize certain things that are commonly put in
605 foreach $lsearch (split (/\s+/, $contents{$onelib . '_LIBADD'}))
607 # Automatically handle @LIBOBJS@ and @ALLOCA@.
608 # Basically this means adding entries to dep_files.
609 if ($lsearch eq '@LIBOBJS@')
611 local ($iter, $rewrite);
612 foreach $iter (keys %libsources)
614 if ($iter ne 'alloca.c')
616 ($rewrite = $iter) =~ s/\.c$/.P/;
617 $dep_files{'$(srcdir)/.deps/' . $rewrite} = 1;
618 &require_file ($NORMAL, $iter);
622 elsif ($lsearch eq '@ALLOCA@')
624 &am_line_error ($onelib . '_LIBADD',
625 "\@ALLOCA\@ seen but \`AC_FUNC_ALLOCA' not in \`configure.in'")
626 if ! defined $libsources{'alloca.c'};
627 $dep_files{'$(srcdir)/.deps/alloca.P'} = 1;
628 &require_file ($NORMAL, 'alloca.c');
634 # Generate support for conditional object inclusion in
636 $output_vars .= $onelib . "_LIBADD =\n";
639 &handle_source_transform ($onelib, $obj);
642 &file_contents_with_transform ('s/\@LIBRARY\@/' . $onelib . '/go',
646 # Turn "foo" into "libfoo.a" and include macro definition.
647 grep (($_ = 'lib' . $_ . '.a') && 0, @liblist);
649 if (! defined $contents{'LIBFILES'})
651 &pretty_print ('LIBFILES = ', "", @liblist);
653 $output_vars .= &file_contents ('libraries-vars');
659 # NOTE we no longer automatically clean SCRIPTS, because it is
660 # useful to sometimes distribute scripts verbatim. This happens
661 # eg in Automake itself.
662 $scripts_installed = &am_install_var ('scripts', 'SCRIPTS',
663 'bin', 'sbin', 'libexec', 'pkgdata',
666 # We really only want a boolean value.
667 $scripts_installed = 1 if $scripts_installed;
670 # Search a file for a "version.texi" Texinfo include. Return the name
671 # of the include file if found, or the empty string if not. A
672 # "version.texi" file is actually any file whose name matches
674 sub grep_for_vers_texi
676 local ($filename) = @_;
678 if (! open (TEXI, $filename))
680 &am_error ("couldn't open \`$filename': $!");
683 print "automake: reading $filename\n" if $verbose;
687 if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
699 # Handle all Texinfo source.
702 # FIXME can this really be right? Might want to have configure
703 # determine list of texinfos. Fix this when someone complains.
704 &am_line_error ('TEXINFOS',
705 "\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
706 if defined $contents{'TEXINFOS'};
707 return if (! defined $contents{'info_TEXINFOS'}
708 && ! defined $contents{'html_TEXINFOS'});
710 local (@texis) = split (/\s+/, $contents{'info_TEXINFOS'});
712 local (@infos_list, @info_deps_list, @dvis_list, @texi_deps);
713 local ($infobase, $info_cursor);
717 local ($tc_cursor, @texi_cleans);
719 foreach $info_cursor (@texis)
721 ($infobase = $info_cursor) =~ s/\.texi$//;
723 # If 'version.texi' is referenced by input file, then include
724 # automatic versioning capability.
726 = &grep_for_vers_texi ($relative_dir . "/" . $info_cursor);
729 &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
730 if (defined $versions{$vtexi});
731 $versions{$vtexi} = $info_cursor;
734 push (@texis, $vtexi);
735 # We number the stamp-vti files. This is doable since the
736 # actual names don't matter much. We only number starting
737 # with the second one, so that the common case looks nice.
738 $vti = 'vti' . ($done ? $done : '');
739 &push_dist_common ($vtexi, 'stamp-' . $vti);
743 &file_contents_with_transform
744 ('s/\@TEXI\@/' . $info_cursor . '/g; '
745 . 's/\@VTI\@/' . $vti . '/g; '
746 . 's/\@VTEXI\@/' . $vtexi . '/g',
749 &push_phony_cleaners ($vti);
752 &require_file ($NORMAL, 'mdate-sh') if ! $done;
756 # If user specified file_TEXINFOS, then use that as explicit
759 push (@texi_deps, $info_cursor, $vtexi);
760 if (defined $contents{$infobase . "_TEXINFOS"})
762 push (@texi_deps, "\$" . $infobase . '_TEXINFOS');
763 &push_dist_common ("\$" . $infobase . '_TEXINFOS');
766 $output_rules .= ("\n" . $infobase . ".info: "
767 . join (' ', @texi_deps) . "\n\n");
769 push (@infos_list, $infobase . '.info*');
770 push (@info_deps_list, $infobase . '.info');
771 push (@dvis_list, $infobase . '.dvi');
773 # Generate list of things to clean for this target. We do
774 # this explicitly because otherwise too many things could be
775 # removed. In particular the ".log" extension might
776 # reasonably be used in other contexts by the user.
777 foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns',
778 'ky', 'log', 'pg', 'toc', 'tp', 'vr', 'op')
780 push (@texi_cleans, $infobase . '.' . $tc_cursor);
785 $output_vars .= &file_contents ('texinfos-vars');
786 $output_rules .= &file_contents ('texinfos');
787 push (@phony, 'install-info', 'uninstall-info');
790 $output_rules .= "\nmostlyclean-info:\n";
791 &pretty_print_rule ("\trm -f", "\t ", @texi_cleans);
792 $output_rules .= ("\nclean-info:\n\ndistclean-info:\n\n"
793 . "maintainer-clean-info:\n\t"
794 . 'rm -f $(INFOS)' . "\n");
795 &push_phony_cleaners ('info');
797 push (@suffixes, '.texi', '.info', '.dvi');
798 push (@uninstall, 'uninstall-info');
799 push (@clean, 'info');
800 push (@info, '$(INFO_DEPS)');
801 push (@dvi, '$(DVIS)');
802 push (@installdirs, '$(infodir)');
803 unshift (@install_data, 'install-info');
805 # Make sure documentation is made and installed first. Use
806 # $(INFO_DEPS), not 'info', because otherwise recursive makes get
807 # run twice during "make all". FIXME add test case.
808 unshift (@all, '$(INFO_DEPS)');
810 $output_vars .= ("INFOS = " . join (' ', @infos_list) . "\n"
811 . "INFO_DEPS = " . join (' ', @info_deps_list) . "\n"
812 . "DVIS = " . join (' ', @dvis_list) . "\n"
813 # This next isn't strictly needed now -- the
814 # places that look here could easily be changed
815 # to look in info_TEXINFOS. But this is probably
816 # better, in case noinst_TEXINFOS is ever
818 . "TEXINFOS = " . $contents{'info_TEXINFOS'} . "\n\n");
820 # Do some error checking.
821 &require_file ($NORMAL, 'texinfo.tex');
824 # Handle any man pages.
827 &am_line_error ('MANS', "\`MANS' is an anachronism; use \`man_MANS'")
828 if defined $contents{'MANS'};
829 return if ! defined $contents{'man_MANS'};
831 # We generate the manpage install code by hand to avoid the use of
832 # basename in the generated Makefile.
833 local (@mans) = split (/\s+/, $contents{'man_MANS'});
834 local (%sections, %inames, %secmap, %fullsecmap);
837 # FIXME: statement without effect:
838 /^(.*)\.([0-9])([a-z]*)$/;
842 $fullsecmap{$1} = $2 . $3;
845 # We don't really need this, but we use it in case we ever want to
846 # support noinst_MANS.
847 $output_vars .= "MANS = " . $contents{'man_MANS'} . "\n";
849 # Generate list of install dirs.
850 $output_rules .= "install-man: \$(MANS)\n";
851 foreach (keys %sections)
853 push (@installdirs, '$(mandir)/man' . $_);
854 $output_rules .= ("\t" . '$(top_srcdir)/mkinstalldirs $(mandir)/man'
857 push (@phony, 'install-man');
859 # Generate install target.
861 foreach $key (keys %inames)
863 $_ = $install_man_format;
864 s/\@SECTION\@/$secmap{$key}/g;
865 s/\@MAN\@/$inames{$key}/g;
866 s/\@FULLSECT\@/$fullsecmap{$key}/g;
867 s/\@MANBASE\@/$key/g;
870 $output_rules .= "\n";
872 $output_rules .= "uninstall-man:\n";
873 foreach $key (keys %inames)
875 $_ = $uninstall_man_format;
876 s/\@SECTION\@/$secmap{$key}/g;
877 s/\@MAN\@/$inames{$key}/g;
878 s/\@FULLSECT\@/$fullsecmap{$key}/g;
879 s/\@MANBASE\@/$key/g;
882 $output_rules .= "\n";
883 push (@phony, 'uninstall-man');
885 $output_vars .= &file_contents ('mans-vars');
887 if (! defined $options{'no-installman'})
889 push (@install_data, 'install-man');
890 push (@uninstall, 'uninstall-man');
891 push (@all, '$(MANS)');
895 # Handle DATA variables.
898 &am_install_var ('data', 'DATA', 'data', 'sysconf',
899 'sharedstate', 'localstate', 'pkgdata',
906 local ($tagging) = 0;
908 push (@phony, 'tags');
909 if (defined $contents{'SUBDIRS'})
911 $output_rules .= &file_contents ('tags');
914 elsif ($dir_holds_sources || defined $contents{'ETAGS_ARGS'})
916 $output_rules .= &file_contents ('tags-subd');
922 $output_rules .= &file_contents ('tags-clean');
923 push (@clean, 'tags');
924 &push_phony_cleaners ('tags');
928 # Every Makefile must define some sort of TAGS rule.
929 # Otherwise, it would be possible for a top-level "make TAGS"
930 # to fail because some subdirectory failed.
931 $output_rules .= "tags: TAGS\nTAGS:\n\n";
935 # Generate actual 'dist' (or dist-shar) rule.
936 sub handle_dist_worker
938 local ($distshar) = @_;
939 local ($target) = $distshar ? 'dist-shar' : 'dist';
941 $output_rules .= $target . ': $(DEP_DISTFILES)' . "\n";
943 # Initialization; only at top level.
944 if ($relative_dir eq '.')
946 if ($strictness >= $GNITS)
948 # For Gnits users, this is pretty handy. Look at 15 lines
949 # in case some explanatory text is desirable.
950 $output_rules .= ' @if sed 15q NEWS | grep -e "$(VERSION)" > /dev/null; then :; else \\
951 echo "NEWS not updated; not releasing" 1>&2; \\
960 # Create dist directory.
965 # We need an absolute path for --output-dir. Thus the
967 . ' distdir=`cd $(distdir) && pwd` \\
969 && automake --include-deps --output-dir=$$distdir --strictness='
970 # Set strictness of output.
971 . $strictness_name . "\n"
975 # In loop, test for file existence because sometimes a file gets
976 # included in DISTFILES twice. For example this happens when a
977 # single source file is used in building more than one program.
978 # Also, there are situations in which "ln" can fail. For instance
979 # a file to distribute could actually be a cross-filesystem
980 # symlink -- this can easily happen if "gettextize" was run on the
981 # distribution. Note that DISTFILES can contain a wildcard (for
982 # info files, sigh), so we must use the echo trick.
984 $output_rules .= ' @for file in `cd $(srcdir) && echo $(DISTFILES)`; do \\
985 test -f $(distdir)/$$file \\
986 || ln $(srcdir)/$$file $(distdir)/$$file 2> /dev/null \\
987 || cp -p $(srcdir)/$$file $(distdir)/$$file; \\
991 # If we have SUBDIRS, create all dist subdirectories and do
993 if (defined $contents{'SUBDIRS'})
995 # Test for directory existence here because previous automake
996 # invocation might have created some directories.
997 $output_rules .= ' for subdir in $(SUBDIRS); do \\
998 test -d $(distdir)/$$subdir \\
999 || mkdir $(distdir)/$$subdir \\
1001 chmod 777 $(distdir)/$$subdir; \\
1002 (cd $$subdir && $(MAKE) dist) || exit 1; \\
1007 # Make verbatim copies of some subdirectories if required. This
1008 # is a hack which might go away.
1009 if (defined $contents{'DIST_SUBDIRS'})
1011 $output_rules .= ' @for dir in $(DIST_SUBDIRS); do \\
1012 echo copying directory $$dir; \\
1013 tar chf - $$dir | (cd $(distdir) && tar xBpf -); \\
1019 if ($relative_dir eq '.')
1021 $output_rules .= ' chmod -R a+r $(distdir)' . "\n\t";
1024 $output_rules .= 'shar $(distdir) | gzip > $(distdir).shar.gz';
1028 $output_rules .= 'tar chozf $(distdir).tar.gz $(distdir)';
1030 $output_rules .= "\n\t" . 'rm -rf $(distdir)' . "\n";
1033 push (@phony, $target);
1036 # Handle 'dist' target.
1039 # Set up maint_charset.
1040 $local_maint_charset = $contents{'MAINT_CHARSET'}
1041 if defined $contents{'MAINT_CHARSET'};
1042 $maint_charset = $local_maint_charset
1043 if $relative_dir eq '.';
1045 if (defined $contents{'DIST_CHARSET'})
1047 &am_line_error ('DIST_CHARSET',
1048 "DIST_CHARSET defined but no MAINT_CHARSET defined")
1049 if ! $local_maint_charset;
1050 if ($relative_dir eq '.')
1052 $dist_charset = $contents{'DIST_CHARSET'}
1056 &am_line_error ('DIST_CHARSET',
1057 "DIST_CHARSET can only be defined at top level");
1061 # Look for common files that should be included in distribution.
1063 foreach $cfile (@common_files)
1065 if (-f ($relative_dir . "/" . $cfile))
1067 &push_dist_common ($cfile);
1071 # Keys of %dist_common are names of files to distributed. We put
1072 # README first because it then becomes easier to make a
1073 # Usenet-compliant shar file (in these, README must be first).
1074 # FIXME do more ordering of files here.
1076 if (defined $dist_common{'README'})
1078 push (@coms, 'README');
1079 undef $dist_common{'README'};
1081 push (@coms, sort keys %dist_common);
1083 &pretty_print ("DIST_COMMON =", "", @coms);
1084 $output_vars .= "\n";
1087 $output_vars .= &file_contents ('dist-vars');
1089 # Put these things in rules section so it is easier for whoever
1090 # reads Makefile.in.
1091 if ($relative_dir eq '.')
1093 $output_rules .= "\n" . 'distdir = $(PACKAGE)-$(VERSION)' . "\n";
1097 $output_rules .= ("\nsubdir = " . $relative_dir . "\n"
1098 . 'distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)'
1102 # Generate 'dist' target, and maybe dist-shar.
1103 &handle_dist_worker (0);
1104 &handle_dist_worker (1) if defined $options{'dist-shar'};
1107 # Handle auto-dependency code.
1108 sub handle_dependencies
1110 if ($use_dependencies)
1112 # Include GNU-make-specific auto-dep code.
1113 if ($dir_holds_sources)
1115 &pretty_print ('DEP_FILES =', "", sort keys %dep_files);
1116 $output_rules .= &file_contents ('depend');
1121 # Include any auto-generated deps that are present.
1122 if (-d ($relative_dir . "/.deps") && -f ($relative_dir . "/.deps/.P"))
1125 local ($gpat) = $relative_dir . "/.deps/*.P";
1127 foreach $depfile (<${gpat}>)
1129 if (! open (DEP_FILE, $depfile))
1131 &am_error ("couldn't open $depfile", $!);
1134 print "automake: reading $depfile\n" if $verbose;
1136 # Slurp entire file.
1137 $output_rules .= join ('', <DEP_FILE>);
1142 $output_rules .= "\n";
1147 # Handle subdirectories.
1150 if (! defined $contents{'SUBDIRS'})
1153 ("ud_GNU_GETTEXT in configure.in but SUBDIRS not defined")
1154 if $seen_gettext && $relative_dir eq '.';
1162 "ud_GNU_GETTEXT in configure.in but \`po' not in SUBDIRS")
1163 if $contents{'SUBDIRS'} !~ /\bpo\b/;
1166 "ud_GNU_GETTEXT in configure.in but \`intl' not in SUBDIRS")
1167 if $contents{'SUBDIRS'} !~ /\bintl\b/;
1170 &require_file ($NORMAL, 'ABOUT-NLS') if $seen_gettext;
1172 return if ! defined $contents{'SUBDIRS'};
1174 # Make sure each directory mentioned in SUBDIRS actually exists.
1176 foreach $dir (split (/\s+/, $contents{'SUBDIRS'}))
1178 # Skip directories substituted by configure.
1179 next if $dir =~ /^\@.*\@$/;
1180 &am_line_error ('SUBDIRS',
1181 "required directory $relative_dir/$dir does not exist")
1182 if ! -d $relative_dir . '/' . $dir;
1185 $output_rules .= &file_contents ('subdirs');
1187 # Push a bunch of phony targets.
1189 foreach $phonies ('-data', '-exec', 'dirs')
1191 push (@phony, 'install' . $phonies . '-recursive');
1192 push (@phony, 'uninstall' . $phonies . '-recursive');
1194 foreach $phonies ('all', 'check', 'installcheck', 'info', 'dvi')
1196 push (@phony, $phonies . '-recursive');
1198 &push_phony_cleaners ('recursive');
1200 push (@check, "check-recursive");
1201 push (@installcheck, "installcheck-recursive");
1202 push (@info, "info-recursive");
1203 push (@dvi, "dvi-recursive");
1205 $recursive_install = 1;
1208 # Handle remaking and configure stuff.
1209 sub handle_configure
1211 # If SUBDIRS defined, require AC_PROG_MAKE_SET.
1212 &am_line_error ('SUBDIRS', "AC_PROG_MAKE_SET must be used in configure.in")
1213 if defined $contents{'SUBDIRS'} && ! $seen_make_set;
1215 local ($top_reldir);
1216 if ($relative_dir ne '.')
1219 $output_rules .= &file_contents ('remake-subd');
1220 $top_reldir = '../';
1224 if (-f 'aclocal.m4')
1226 $output_vars .= "ACLOCAL = aclocal.m4\n";
1227 &push_dist_common ('aclocal.m4');
1229 $output_rules .= &file_contents ('remake');
1231 # Look for some files we need.
1232 &require_file ($NORMAL, 'install-sh', 'mkinstalldirs');
1235 ("\`install.sh' is an anachronism; use \`install-sh' instead")
1236 if -f $relative_dir . '/install.sh';
1238 # If we have a configure header, require it.
1241 # FIXME this restriction should be lifted.
1242 # FIXME first see if it is even needed as-is.
1243 &am_line_error ($config_header_line,
1244 "argument to AC_CONFIG_HEADER contains \`/'\n")
1245 if ($config_header =~ /\//);
1247 &require_file ($NORMAL, $config_header);
1249 # Header defined and in this directory.
1250 if (-f 'acconfig.h')
1252 $output_vars .= "ACCONFIG = acconfig.h\n";
1253 &push_dist_common ('acconfig.h');
1255 if (-f $config_name . '.top')
1257 $output_vars .= "CONFIG_TOP = ${config_name}.top\n";
1258 &push_dist_common ($config_name . '.top');
1260 if (-f $config_name . '.bot')
1262 $output_vars .= "CONFIG_BOT = ${config_name}.bot\n";
1263 &push_dist_common ($config_name . '.bot');
1266 &push_dist_common ('stamp-h.in');
1268 $output_rules .= &file_contents ('remake-hdr');
1269 $output_vars .= "CONFIG_HEADER_IN = ${config_header}\n";
1275 &am_line_error ('CONFIG_HEADER',
1276 "\`CONFIG_HEADER' is an anachronism; now determined from \`configure.in'")
1277 if defined $contents{'CONFIG_HEADER'};
1279 # Generate CONFIG_HEADER define, and define interally.
1280 $output_vars .= "CONFIG_HEADER = ${top_builddir}/${config_name}\n"
1282 $contents{'CONFIG_HEADER'} = "${top_builddir}/${config_name}"
1285 # Now look for other files in this directory which must be remade
1286 # by config.status, and generate rules for them.
1287 local ($file, $local, $input);
1288 foreach $file (@other_input_files)
1290 # Skip files not in this directory, any Makefile, and the
1291 # config header. These last two must be handled specially.
1292 next unless &dirname ($file) eq $relative_dir;
1293 next if $file eq $top_builddir . '/' . $config_name;
1294 ($local = $file) =~ s/^.*\///;
1295 next if $local eq 'Makefile';
1297 if ($local =~ /^(.*):(.*)$/)
1299 # This is the ":" syntax of AC_OUTPUT.
1306 $input = $local . '.in';
1308 # FIXME when using autoconf ":" syntax, should we set CONFIG_FILES
1310 $output_rules .= ($local . ': '
1311 . '$(top_builddir)/config.status ' . $input . "\n"
1313 . 'cd $(top_builddir) && CONFIG_FILES='
1314 . ($relative_dir eq '.' ? '' : '$(subdir)/')
1315 . '$@ CONFIG_HEADERS= ./config.status'
1317 &require_file ($NORMAL, $local . '.in');
1324 &am_install_var ('header', 'HEADERS', 'include',
1325 'oldinclude', 'pkginclude',
1329 # Handle footer elements.
1332 if ($contents{'SOURCES'})
1334 &pretty_print ('SOURCES =', "",
1335 split (/\s+/, $contents{'SOURCES'}));
1337 if ($contents{'OBJECTS'})
1339 &pretty_print ('OBJECTS =', "",
1340 split (/\s+/, $contents{'OBJECTS'}));
1342 if ($contents{'SOURCES'} || $contents{'OBJECTS'})
1344 $output_vars .= "\n";
1347 if (defined $contents{'SUFFIXES'})
1349 push (@suffixes, '$(SUFFIXES)');
1352 $output_trailer .= ".SUFFIXES:\n";
1355 $output_trailer .= ".SUFFIXES: " . join (' ', @suffixes) . "\n";
1357 $output_trailer .= &file_contents ('footer');
1360 # Deal with installdirs target.
1361 sub handle_installdirs
1363 # GNU Makefile standards recommend this.
1364 $output_rules .= ("installdirs:"
1365 . ($recursive_install
1366 ? " installdirs-recursive\n"
1368 push (@phony, 'installdirs');
1371 &pretty_print_rule ("\t\$(top_srcdir)/mkinstalldirs ", "\t\t",
1374 $output_rules .= "\n";
1377 # There are several targets which need to be merged. This is because
1378 # their complete definition is compiled from many parts. Note that we
1379 # avoid double colon rules, otherwise we'd use them instead.
1380 sub handle_merge_targets
1382 push (@all, 'Makefile');
1383 push (@all, $config_name)
1384 if $config_name && &dirname ($config_name) eq $relative_dir;
1386 &do_one_merge_target ('info', @info);
1387 &do_one_merge_target ('dvi', @dvi);
1389 if (! defined $contents{'SUBDIRS'} || $relative_dir ne '.')
1391 # 'check' must depend on 'all', but not at top level.
1393 unshift (@check, 'all');
1394 unshift (@install, 'all');
1396 &do_one_merge_target ('check', @check);
1397 &do_one_merge_target ('installcheck', @installcheck);
1399 # Handle the various install targets specially. We do this so
1400 # that (eg) "make install-exec" will run "install-exec-recursive"
1401 # if required, but "make install" won't run it twice. Step one is
1402 # to see if the user specified local versions of any of the
1403 # targets we handle. "all" is treated as one of these since
1404 # "install" can run it.
1405 push (@install_exec, 'install-exec-local')
1406 if defined $contents{'install-exec-local'};
1407 push (@install_data, 'install-data-local')
1408 if defined $contents{'install-data-local'};
1409 push (@uninstall, 'uninstall-local')
1410 if defined $contents{'uninstall-local'};
1411 push (@all, 'all-local')
1412 if defined $contents{'all-local'};
1414 if (defined $contents{'install-local'})
1416 &am_line_error ('install-local',
1417 "use \`install-data' or \`install-exec', not \`install'");
1420 # Step two: if we are doing recursive makes, write out the
1421 # appropriate rules.
1423 if ($recursive_install)
1425 push (@install, 'install-recursive');
1429 $output_rules .= ('all-am: '
1432 @all = ('all-recursive', 'all-am');
1433 push (@phony, 'all-am');
1437 @all = ('all-recursive');
1441 $output_rules .= ('install-exec-am: '
1442 . join (' ', @install_exec)
1444 @install_exec = ('install-exec-recursive', 'install-exec-am');
1445 push (@install, 'install-exec-am');
1446 push (@phony, 'install-exec-am');
1450 @install_exec = ('install-exec-recursive');
1454 $output_rules .= ('install-data-am: '
1455 . join (' ', @install_data)
1457 @install_data = ('install-data-recursive', 'install-data-am');
1458 push (@install, 'install-data-am');
1459 push (@phony, 'install-data-am');
1463 @install_data = ('install-data-recursive');
1467 $output_rules .= ('uninstall-am: '
1468 . join (' ', @uninstall)
1470 @uninstall = ('uninstall-recursive', 'uninstall-am');
1471 push (@phony, 'uninstall-am');
1475 @uninstall = ('uninstall-recursive');
1479 # Step three: print definitions users can use.
1480 $output_rules .= ("install-exec: "
1481 . join (' ', @install_exec)
1483 push (@install, 'install-exec') if !$recursive_install;
1484 push (@phony, 'install-exec');
1486 $output_rules .= ("install-data: "
1487 . join (' ', @install_data)
1489 push (@install, 'install-data') if !$recursive_install;
1490 push (@phony, 'install-data');
1492 # If no dependencies for 'install', add 'all'. Why? That way
1493 # "make install" at top level of distclean'd distribution won't
1494 # fail because stuff in 'lib' fails to build.
1495 push (@install, 'all') if ! @install;
1496 $output_rules .= ('install: '
1497 . join (' ', @install)
1498 # Use "@:" as empty command so nothing prints.
1502 . join (' ', @uninstall)
1504 push (@phony, 'install', 'uninstall');
1506 $output_rules .= ('all: '
1509 push (@phony, 'all');
1512 # Helper for handle_merge_targets.
1513 sub do_one_merge_target
1515 local ($name, @values) = @_;
1517 if (defined $contents{$name . '-local'})
1519 # User defined local form of target. So include it.
1520 push (@values, $name . '-local');
1521 push (@phony, $name . '-local');
1524 $output_rules .= $name . ":";
1527 $output_rules .= ' ' . join (' ', @values);
1529 $output_rules .= "\n\n";
1530 push (@phony, $name);
1533 # Handle all 'clean' targets.
1536 push (@clean, 'generic');
1537 $output_rules .= &file_contents ('clean');
1538 &push_phony_cleaners ('generic');
1540 local ($target) = $recursive_install ? 'clean-am' : 'clean';
1541 &do_one_clean_target ($target, 'mostly', '', @clean);
1542 &do_one_clean_target ($target, '', 'mostly', @clean);
1543 &do_one_clean_target ($target, 'dist', '', @clean);
1544 &do_one_clean_target ($target, 'maintainer-', 'dist', @clean);
1546 push (@phony, 'clean', 'mostlyclean', 'distclean', 'maintainer-clean');
1549 if ($recursive_install)
1551 @deps = ('am', 'recursive');
1552 &do_one_clean_target ('', 'mostly', '', @deps);
1553 &do_one_clean_target ('', '', '', @deps);
1554 &do_one_clean_target ('', 'dist', '', @deps);
1555 &do_one_clean_target ('', 'maintainer-', '', @deps);
1559 # Helper for handle_clean.
1560 sub do_one_clean_target
1562 local ($target, $name, $last_name, @deps) = @_;
1564 # Special case: if target not passed, then don't generate
1565 # dependency on next "lower" clean target (eg no
1566 # clean<-mostlyclean derivation). In this case the target is
1567 # implicitly known to be 'clean'.
1568 local ($flag) = $target;
1569 $target = 'clean' if ! $flag;
1571 grep (($_ = $name . 'clean-' . $_) && 0, @deps);
1574 if ($last_name || $name ne 'mostly')
1576 push (@deps, $last_name . $target . " ");
1579 # FIXME not sure if I like the tabs here.
1580 &pretty_print_rule ($name . $target . ": ", "\t\t", @deps);
1582 # FIXME shouldn't we really print these messages before running
1584 if ($name . $target eq 'maintainer-clean')
1586 # Print a special warning.
1588 ("\t\@echo \"This command is intended for maintainers to use;\"\n"
1589 . "\t\@echo \"it deletes files that may require special "
1590 . "tools to rebuild.\"\n");
1592 $output_rules .= "\trm -f config.status\n"
1593 if $relative_dir eq '.';
1595 elsif ($name . $target eq 'distclean')
1597 $output_rules .= "\trm -f config.status\n";
1599 $output_rules .= "\n";
1602 # Handle .PHONY target.
1605 &pretty_print_rule ('.PHONY:', "", @phony);
1606 $output_rules .= "\n";
1609 # Handle TESTS variable.
1612 return if ! defined $contents{'TESTS'};
1614 &push_dist_common (split (/\s+/, $contents{'TESTS'}));
1615 push (@check, 'check-TESTS');
1616 # FIXME use $(SHELL) here? That is what Ulrich suggests. Maybe a
1617 # new macro, $(TEST_SHELL), a la $(CONFIG_SHELL)? For now we just
1618 # execute the file directly; this allows test files which are
1619 # compiled -- a possibly useful feature.
1620 $output_rules .= 'check-TESTS:
1621 @failed=0; all=0; \\
1622 srcdir=$(srcdir); export srcdir; \\
1623 for tst in $(TESTS); do \\
1624 all=`expr $$all + 1`; \\
1625 if test -f $$tst; then dir=.; \\
1626 else dir="$(srcdir)"; fi; \\
1627 if $$dir/$$tst; then \\
1628 echo "PASS: $$tst"; \\
1630 failed=`expr $$failed + 1`; \\
1631 echo "FAIL: $$tst"; \\
1634 if test "$$failed" -eq 0; then \\
1635 echo "========================"; \\
1636 echo "All $$all tests passed"; \\
1637 echo "========================"; \\
1639 echo "$$failed of $$all tests failed"; \\
1644 ################################################################
1646 # Scan configure.in for interesting things.
1647 # FIXME ensure VERSION, PACKAGE are set.
1650 open (CONFIGURE, 'configure.in')
1651 || die "automake: couldn't open configure.in: $!\n";
1652 print "automake: reading configure.in\n" if $verbose;
1654 # Reinitialize libsources here. This isn't really necessary,
1655 # since we currently assume there is only one configure.in. But
1656 # that won't always be the case.
1659 local ($in_ac_output, @make_list) = 0;
1660 local ($seen_arg_prog) = 0;
1661 local ($libobj_iter);
1664 # Remove comments from current line.
1668 # Populate libobjs array.
1669 if (/AC_FUNC_ALLOCA/)
1671 $libsources{'alloca.c'} = 1;
1673 elsif (/AC_FUNC_GETLOADAVG/)
1675 $libsources{'getloadavg.c'} = 1;
1677 elsif (/AC_FUNC_MEMCMP/)
1679 $libsources{'memcmp.c'} = 1;
1681 elsif (/AC_STRUCT_ST_BLOCKS/)
1683 $libsources{'fileblocks.c'} = 1;
1685 elsif (/(AC|fp)_FUNC_FNMATCH/)
1687 # AC_FUNC_FNMATCH is just wishful thinking at this point.
1688 $libsources{'fnmatch.c'} = 1;
1690 elsif (/AC_REPLACE_FUNCS\s*\((.*)\)/)
1692 foreach (split (/\s+/, $1))
1694 $libsources{$_ . '.c'} = 1;
1697 elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
1698 || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
1700 foreach $libobj_iter (split (/\s+/, $1))
1702 if ($libobj_iter =~ /^(.*)\.o$/)
1704 $libsources{$1 . '.c'} = 1;
1709 # Process the AC_OUTPUT macro.
1710 if (! $in_ac_output && s/AC_OUTPUT\s*\(\[?//)
1716 $in_ac_output = 0 if s/[\]\),].*$//;
1718 # Look at potential Makefile.am's.
1724 push (@make_list, $_);
1728 push (@other_input_files, $_);
1733 # Check for ansi2knr.
1734 $fp_c_prototypes = 1 if /fp_C_PROTOTYPES/;
1736 # Check for NLS support.
1737 if (/ud_GNU_GETTEXT/)
1742 # Handle configuration headers.
1743 if (/AC_CONFIG_HEADER\s*\((.*)\)/)
1745 $config_header_line = $.;
1747 if ($config_name =~ /^([^:]+):(.+)$/)
1750 $config_header = $2;
1754 $config_header = $config_name . '.in';
1758 $seen_canonical = 1 if /AC_CANONICAL_(HOST|SYSTEM)/;
1759 $seen_canonical = 1 if /AC_CHECK_TOOL/;
1760 $seen_path_xtra = 1 if /AC_PATH_XTRA/;
1762 # Sometimes it is desirable to explicitly set YACC. For
1763 # instance some people don't want to use bison.
1764 $seen_prog_yacc = 1 if (/AC_PROG_YACC/
1765 || /AC_SUBST\(YACC\)/
1766 || /AC_(PATH|CHECK)_PROGS?\(YACC/);
1768 # Some things required by Automake. FIXME We only really
1769 # require AC_ARG_PROGRAM if any program is installed.
1770 $seen_make_set = 1 if /AC_PROG_MAKE_SET/;
1771 $seen_prog_install = 1 if ! $seen_prog_install && /AC_PROG_INSTALL/;
1772 $seen_prog_install = 2 if ! $seen_prog_install && /fp_PROG_INSTALL/;
1773 $seen_arg_prog = 1 if /AC_ARG_PROGRAM/;
1774 $seen_ranlib = 1 if /AC_PROG_RANLIB/;
1777 # Set input files if not specified by user.
1778 @input_files = @make_list if (! @input_files);
1780 &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
1781 unless $seen_arg_prog;
1786 ################################################################
1788 # Do any extra checking for GNU standards.
1789 sub check_gnu_standards
1791 &require_file ($GNU, 'ChangeLog');
1793 if ($relative_dir eq '.')
1795 # In top level (or only) directory.
1796 &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
1801 # Do any extra checking for GNITS standards.
1802 sub check_gnits_standards
1804 if ($strictness >= $GNITS && -f $relative_dir . '/COPYING.LIB')
1807 ("\`${relative_dir}/COPYING.LIB' disallowed by Gnits standards");
1810 if ($relative_dir eq '.')
1812 # In top level (or only) directory.
1813 &require_file ($GNITS, 'THANKS');
1817 ################################################################
1819 # Pretty-print something. HEAD is what should be printed at the
1820 # beginning of the first line, FILL is what should be printed at the
1821 # beginning of every subsequent line.
1822 sub pretty_print_internal
1824 local ($head, $fill, @values) = @_;
1826 local ($column) = length ($head);
1827 local ($result) = $head;
1829 # Fill length is number of characters. However, each Tab
1830 # character counts for eight. So we count the number of Tabs and
1832 local ($fill_length) = length ($fill);
1833 $fill_length += 7 * ($fill =~ tr/\t/\t/d);
1838 # "71" because we also print a space.
1839 if ($column + length ($_) > 71)
1841 $result .= " \\\n" . $fill;
1842 $column = $fill_length;
1846 $result .= ' ' unless ($bol);
1848 $column += length ($_) + 1;
1856 # Pretty-print something and append to output_vars.
1859 $output_vars .= &pretty_print_internal (@_);
1862 # Pretty-print something and append to output_rules.
1863 sub pretty_print_rule
1865 $output_rules .= &pretty_print_internal (@_);
1869 ################################################################
1871 # Read Makefile.am and set up %contents. Simultaneously copy lines
1872 # from Makefile.am into $output_trailer or $output_vars as
1873 # appropriate. NOTE we put rules in the trailer section. We want
1874 # user rules to come after our generated stuff.
1877 local ($amfile) = @_;
1879 # Compute relative location of the top object directory.
1880 local (@topdir) = ();
1881 foreach (split (/\//, $relative_dir))
1883 next if $_ eq '.' || $_ eq '';
1890 push (@topdir, '..');
1893 @topdir = ('.') if ! @topdir;
1895 $top_builddir = join ('/', @topdir);
1897 ($build_rx = $top_builddir) =~ s/(\W)/\\$1/g;
1898 local ($header_vars) =
1899 &file_contents_with_transform
1900 ('s/\@top_builddir\@/' . $build_rx . '/g',
1903 open (AM_FILE, $amfile) || die "automake: couldn't open $amfile: $!\n";
1904 print "automake: reading $amfile\n" if $verbose;
1906 $output_vars .= ("# Makefile.in generated automatically by automake "
1907 . $VERSION . " from Makefile.am\n");
1909 # Generate copyright for generated Makefile.in.
1910 $output_vars .= $gen_copyright;
1912 local ($saw_bk) = 0;
1913 local ($was_rule) = 0;
1914 local ($spacing) = '';
1915 local ($comment) = '';
1916 local ($last_var_name) = '';
1920 if (/$IGNORE_PATTERN/o)
1922 # Merely delete comments beginning with two hashes.
1924 elsif (/$WHITE_PATTERN/o)
1926 # Stick a single white line before the incoming macro or rule.
1929 elsif (/$COMMENT_PATTERN/o)
1931 # Stick comments before the incoming macro or rule.
1932 $comment .= $spacing . $_;
1941 $output_vars .= $comment . "\n" . $header_vars;
1947 if (/$IGNORE_PATTERN/o)
1949 # Merely delete comments beginning with two hashes.
1951 elsif (/$WHITE_PATTERN/o)
1953 # Stick a single white line before the incoming macro or rule.
1956 elsif (/$COMMENT_PATTERN/o)
1958 # Stick comments before the incoming macro or rule.
1959 $comment .= $spacing . $_;
1966 $output_trailer .= $_;
1973 # Chop newline and backslash if this line is
1974 # continued. FIXME maybe ensure trailing whitespace
1978 $contents{$last_var_name} .= $_;
1981 elsif (/$RULE_PATTERN/o)
1983 # warn "** Saw rule .$1.\n";
1986 # Value here doesn't matter; for targets we only note
1989 $content_lines{$1} = $.;
1990 $output_trailer .= $comment . $spacing . $_;
1991 $comment = $spacing = '';
1994 elsif (/$MACRO_PATTERN/o)
1996 # warn "** Saw macro .$1.\n";
1997 # Found a macro definition.
1999 $last_var_name = $1;
2000 if (substr ($2, -1) eq "\\")
2002 $contents{$1} = substr ($2, 0, length ($2) - 1);
2008 $content_lines{$1} = $.;
2009 $output_vars .= $comment . $spacing . $_;
2010 $comment = $spacing = '';
2015 # This isn't an error; it is probably a continued rule.
2016 # In fact, this is what we assume.
2018 $output_trailer .= $comment . $spacing . $_;
2019 $comment = $spacing = '';
2026 $output_trailer .= $comment;
2029 ################################################################
2031 sub initialize_global_constants
2033 # Associative array of standard directory names. Entry is TRUE if
2034 # corresponding directory should be installed during
2035 # 'install-exec' phase.
2053 # Helper text for dealing with man pages.
2054 $install_man_format =
2055 ' @sect=@SECTION@; \\
2056 inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
2057 echo installing @MAN@ as $(mandir)/man$$sect/$$inst; \\
2058 $(INSTALL_DATA) $(srcdir)/@MAN@ $(mandir)/man$$sect/$$inst
2061 $uninstall_man_format =
2062 ' inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
2063 rm -f $(mandir)/man@SECTION@/$$inst
2066 # Commonly found files we look for and automatically include in
2070 "README", "THANKS", "TODO", "NEWS", "COPYING", "COPYING.LIB",
2071 "INSTALL", "ABOUT-NLS", "ChangeLog", "configure", "configure.in",
2072 "config.guess", "config.sub", "AUTHORS", "BACKLOG", "ABOUT-GNU"
2075 # Commonly used files we auto-include, but only sometimes.
2078 "version.texi", "aclocal.m4", "acconfig.h", "config.h.top",
2079 "config.h.bot", "stamp-h.in", "mdate-sh", "ansi2knr.c",
2080 "ansi2knr.1", 'stamp-vti', "mkinstalldirs", "install-sh"
2084 --amdir=DIR directory storing config files
2085 --gnits same as --strictness=gnits
2086 --gnu same as --strictness=gnu
2087 --help print this help, then exit
2088 --include-deps include generated dependencies in Makefile.in
2089 --install-missing install missing standard files
2090 --output-dir=DIR put generated Makefile.in's into DIR
2091 --strictness=LEVEL set strictness level. LEVEL is normal, gnu, gnits
2092 --verbose verbosely list files processed
2093 --version print version number, then exit\n";
2095 # Copyright on generated Makefile.ins.
2097 # Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
2098 # This Makefile.in is free software; the Free Software Foundation
2099 # gives unlimited permission to copy, distribute and modify it.
2103 # (Re)-Initialize per-Makefile.am variables.
2104 sub initialize_per_input
2106 # These two variables are used when generating each Makefile.in.
2107 # They hold the Makefile.in until it is ready to be printed.
2110 $output_trailer = '';
2112 # Suffixes found during a run.
2115 # This holds the contents of a Makefile.am, as parsed by
2119 # This holds the line numbers at which various elements of
2120 # %contents are defined.
2121 %content_lines = ();
2123 # This holds the "relative directory" of the current Makefile.in.
2124 # Eg for src/Makefile.in, this is "src".
2127 # Directory where output files go. Actually, output files are
2128 # relative to this directory.
2129 $output_directory = '.';
2131 # This holds a list of files that are included in the
2135 # List of dependencies for the obvious targets.
2150 # These are pretty obvious, too. They are used to define the
2151 # SOURCES and OBJECTS variables.
2155 # TRUE if current directory holds any C source files. (Actually
2156 # holds object extension, but this information is encapsulated in
2157 # the function get_object_extension).
2158 $dir_holds_sources = '';
2160 # TRUE if install targets should work recursively.
2161 $recursive_install = 0;
2166 # Strictness levels.
2167 $strictness = $default_strictness;
2168 $strictness_name = $default_strictness_name;
2170 # Options from AUTOMAKE_OPTIONS.
2173 # Whether or not dependencies are handled. Can be further changed
2174 # in handle_options.
2175 $use_dependencies = $cmdline_use_dependencies;
2178 $local_maint_charset = $maint_charset;
2182 ################################################################
2184 # Return contents of a file from $am_dir, automatically skipping
2185 # macros or rules which are already known. Runs command on each line
2186 # as it is read; this command can modify $_.
2187 sub file_contents_with_transform
2189 local ($command, $basename) = @_;
2190 local ($file) = $am_dir . '/' . $basename . '.am';
2192 open (FC_FILE, $file)
2193 || die "automake: installation error: cannot open \`$file'\n";
2195 # print "automake: reading $file\n" if $verbose;
2197 local ($was_rule) = 0;
2198 local ($result_vars) = '';
2199 local ($result_rules) = '';
2200 local ($comment) = '';
2201 local ($spacing) = "\n";
2202 local ($skipping) = 0;
2208 if (/$IGNORE_PATTERN/o)
2210 # Merely delete comments beginning with two hashes.
2212 elsif (/$WHITE_PATTERN/o)
2214 # Stick a single white line before the incoming macro or rule.
2217 elsif (/$COMMENT_PATTERN/o)
2219 # Stick comments before the incoming macro or rule.
2220 $comment .= $spacing . $_;
2227 $result_rules .= $_ if ! $skipping;
2231 $result_vars .= $_ if ! $skipping;
2235 elsif (/$RULE_PATTERN/o)
2237 # warn "** Found rule .$1.\n";
2240 $skipping = defined $contents{$1};
2241 # warn "** Skip $skipping\n" if $skipping;
2242 $result_rules .= $comment . $spacing . $_ if ! $skipping;
2243 $comment = $spacing = '';
2246 elsif (/$MACRO_PATTERN/o)
2248 # warn "** Found macro .$1.\n";
2249 # Found a variable reference.
2251 $skipping = defined $contents{$1};
2252 # warn "** Skip $skipping\n" if $skipping;
2253 $result_vars .= $comment . $spacing . $_ if ! $skipping;
2254 $comment = $spacing = '';
2259 # This isn't an error; it is probably a continued rule.
2260 # In fact, this is what we assume.
2262 $result_rules .= $comment . $spacing . $_ if ! $skipping;
2263 $comment = $spacing = '';
2269 return $result_vars . $result_rules . $comment;
2272 # Like file_contents_with_transform, but no transform.
2275 return &file_contents_with_transform ('', @_);
2278 # Handle `where_HOW' variable magic. Does all lookups, generates
2279 # install code,and possibly generates code to define the primary
2280 # variable. The first argument is the name of the .am file to munge,
2281 # the second argument is the primary variable (eg HEADERS), and all
2282 # subsequent arguments are possible installation locations. Returns
2283 # list of all values of all _HOW targets.
2285 # FIXME this should be rewritten to be cleaner. It should be broken
2286 # up into multiple functions.
2288 # Usage is: am_install_var (OPTION..., file, HOW, where...)
2293 local ($do_all, $do_clean) = (1, 0);
2296 if ($args[0] eq '-clean')
2300 elsif ($args[0] eq '-no-all')
2304 elsif ($args[0] !~ /^-/)
2310 local ($file, $primary, @prefixes) = @args;
2313 local (@result) = ();
2315 # Now that configure substitutions are allowed in where_HOW
2316 # variables, it is an error to actually define the primary.
2317 &am_line_error ($primary, "\`$primary' is an anachronism")
2318 if defined $contents{$primary};
2320 local ($clean_file) = $file . '-clean';
2323 foreach $X (@prefixes)
2325 $one_name = $X . '_' . $primary;
2326 if (defined $contents{$one_name})
2328 # Append actual contents to result. Skip elements that
2329 # look like configure substitutions.
2330 push (@result, grep (! /^\@.*\@$/,
2331 split (/\s+/, $contents{$one_name})));
2336 &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go',
2339 push (@clean, $X . $primary);
2340 &push_phony_cleaners ($X . $primary);
2343 push (@used, '$(' . $one_name . ')');
2346 # Objects in noinst_FOO never get installed.
2351 &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go',
2354 push (@uninstall, 'uninstall-' . $X . $primary);
2355 push (@phony, 'uninstall-' . $X . $primary);
2356 push (@installdirs, '$(' . $X . 'dir)');
2357 if ($exec_dir_p{$X})
2359 push (@install_exec, 'install-' . $X . $primary);
2360 push (@phony, 'install-' . $X . $primary);
2364 push (@install_data, 'install-' . $X . $primary);
2365 push (@phony, 'install-' . $X . $primary);
2373 &pretty_print ($primary . ' =', '', @used);
2374 $output_vars .= "\n";
2377 # Push here because PRIMARY might be configure time determined.
2378 push (@all, '$(' . $primary . ')')
2379 if $do_all && @used;
2381 # Look for misspellings. It is an error to have a variable ending
2382 # in a "reserved" suffix whose prefix is unknown, eg
2384 local (%valid, $varname);
2385 grep ($valid{$_} = 0, @prefixes);
2386 $valid{'EXTRA'} = 0;
2387 foreach $varname (keys %contents)
2389 if ($varname =~ /^(.*)_$primary$/ && ! defined $valid{$1})
2391 &am_line_error ($varname, "invalid variable \"$varname\"");
2395 push (@result, split (/\s+/, $contents{'EXTRA_' . $primary}))
2396 if defined $contents{'EXTRA_' . $primary};
2402 ################################################################
2404 # Verify that the file must exist in the current directory.
2405 # Usage: require_file (strictness, file)
2406 # strictness is the strictness level at which this file becomes
2410 local ($mystrict, @files) = @_;
2411 local ($file, $fullfile);
2413 foreach $file (@files)
2415 $fullfile = $relative_dir . "/" . $file;
2419 &push_dist_common ($file);
2421 elsif ($strictness >= $mystrict)
2423 # Only install missing files according to our desired
2425 if ($install_missing && -f ($am_dir . '/' . $file))
2427 # Install the missing file. Symlink if we can, copy
2429 if ($symlink_exists)
2431 symlink ($am_dir . '/' . $file, $fullfile);
2435 system ('cp', $am_dir . '/' . $file, $fullfile);
2438 # FIXME this is a hack. Should have am_warn.
2439 local ($save) = $exit_status;
2441 ("required file \"$fullfile\" not found; installing");
2442 $exit_status = $save;
2446 # Only an error if strictness constraint violated.
2447 &am_error ("required file \"$fullfile\" not found");
2453 # Push a list of files onto dist_common.
2454 sub push_dist_common
2456 local (@files) = @_;
2459 foreach $file (@files)
2461 $dist_common{$file} = 1;
2465 # Push a list of clean targets onto phony.
2466 sub push_phony_cleaners
2470 foreach $target ('mostly', 'dist', '', 'maintainer-')
2472 push (@phony, $target . 'clean-' . $base);
2479 $strictness_name = $_[0];
2480 if ($strictness_name eq 'gnu')
2484 elsif ($strictness_name eq 'gnits')
2486 $strictness = $GNITS;
2488 elsif ($strictness_name eq 'normal')
2490 $strictness = $NORMAL;
2494 die "automake: level \`$strictness_name' not recognized\n";
2499 ################################################################
2501 # Return directory name of file.
2507 ($sub = $file) =~ s,/+[^/]+$,,g;
2508 $sub = '.' if $sub eq $file;
2515 local ($dirname) = @_;
2516 system ("mkdir", $dirname);
2519 ################################################################
2521 # Print an error message and set exit status.
2524 warn "automake: ${am_file}.am: ", join (' ', @_), "\n";
2530 local ($symbol, @args) = @_;
2532 # If SYMBOL not already a line number, look it up in Makefile.am.
2533 $symbol = $content_lines{$symbol} unless $symbol =~ /^\d+$/;
2534 warn "${am_file}.am:", $symbol, ": ", join (' ', @args),
2539 # The same, but while scanning configure.in.
2542 # FIXME can run in subdirs.
2543 warn "automake: configure.in: ", join (' ', @_), "\n";
2547 # Tell user where our aclocal.m4 is, but only once.
2548 sub keyed_aclocal_warning
2551 warn "automake: macro \`$key' can be found in ${am_dir}/aclocal.m4\n";
2554 # Print usage information.
2557 print "Usage: automake [OPTION] ... [Makefile]...\n";
2559 print "\nFiles which are automatically distributed, if found:\n";
2560 $~ = "USAGE_FORMAT";
2561 local (@lcomm) = sort ((@common_files, @common_sometimes));
2562 local ($one, $two, $three, $four);
2565 $one = shift @lcomm;
2566 $two = @lcomm ? shift @lcomm : '';
2567 $three = @lcomm ? shift @lcomm : '';
2568 $four = @lcomm ? shift @lcomm : '';
2575 format USAGE_FORMAT =
2576 @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<
2577 $one, $two, $three, $four