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)
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 = $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.
67 # From the Perl manual.
68 $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
70 # TRUE if missing standard files should be installed.
73 # Files found by scanning configure.in for LIBOBJS.
76 # True if fp_C_PROTOTYPES appears in configure.in.
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.
86 # Relative location of top build directory.
89 # List of Makefile.am's to process.
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.
98 # Whether ud_GNU_GETTEXT has been seen in configure.in.
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
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?
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.
132 die "automake: no \`Makefile.am' found or specified\n"
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'))
141 &am_error ('no such file');
145 &generate_makefile ($am_file);
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;
156 ################################################################
158 # Parse command line.
161 local (@arglist) = @_;
163 # Start off as normal.
164 &set_strictness ('normal');
168 if ($arglist[0] eq "--version")
170 print "Automake version $VERSION\n";
173 elsif ($arglist[0] eq "--help")
177 elsif ($arglist[0] =~ /^--amdir=(.+)$/)
181 elsif ($arglist[0] eq '--amdir')
183 &require_argument (@arglist);
185 $am_dir = $arglist[0];
187 elsif ($arglist[0] =~ /^--strictness=(.+)$/)
189 &set_strictness ($1);
191 elsif ($arglist[0] eq '--gnu')
193 &set_strictness ('gnu');
195 elsif ($arglist[0] eq '--gnits')
197 &set_strictness ('gnits');
199 elsif ($arglist[0] eq '--strictness')
201 &require_argument (@arglist);
203 &set_strictness ($arglist[0]);
205 elsif ($arglist[0] eq '--include-deps')
207 $cmdline_use_dependencies = 0;
209 elsif ($arglist[0] =~ /^--output-dir=(.*)$/)
211 # Set output directory.
212 $output_directory = $1;
214 elsif ($arglist[0] eq '--output-dir')
216 &require_argument (@arglist);
218 $output_directory = $arglist[0];
220 elsif ($arglist[0] eq '--install-missing')
222 $install_missing = 1;
224 elsif ($arglist[0] eq '--')
226 # Stop option processing.
228 push (@input_files, @arglist);
231 elsif ($arglist[0] =~ /^-/)
233 die "automake: unrecognized option -- \`$arglist[0]'\n";
237 push (@input_files, $arglist[0]);
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.
251 local ($arg, @arglist) = @_;
252 die "automake: no argument given for option \`$arg'\n"
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');
281 # Check first, because we might modify some state.
282 &check_gnu_standards;
283 &check_gnits_standards;
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);
302 &handle_dependencies;
304 &handle_merge_targets;
309 if (! -d ($output_directory . '/' . $relative_dir))
311 &mkdir ($output_directory . '/' . $relative_dir);
313 if (! open (GM_FILE, "> " . $output_directory . '/' . $makefile . ".in"))
315 warn "automake: ${am_file}.in: cannot open: $!\n";
320 print GM_FILE $output_vars;
321 print GM_FILE $output_rules;
322 print GM_FILE $output_trailer;
327 ################################################################
329 # Handle AUTOMAKE_OPTIONS variable.
332 return if ! defined $contents{'AUTOMAKE_OPTIONS'};
334 foreach (split (/\s+/, $contents{'AUTOMAKE_OPTIONS'}))
337 if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'normal')
339 &set_strictness ($_);
341 elsif ($_ eq 'no-installman' || $_ eq 'ansi2knr' || $_ eq 'dist-shar')
343 # Explicitly recognize these.
345 elsif ($_ eq 'no-dependencies')
347 $use_dependencies = 0;
349 elsif (/[0-9]+\.?[0-9]+/)
351 # Got a version number. Is the syntax too strict?
354 &am_error ("require version $_, only have $VERSION");
355 # FIXME -- what else to do?
361 &am_error ('option ', $_, 'not recognized');
366 # Return object extension. Just once, put some code into the output.
367 sub get_object_extension
369 if (! $dir_holds_sources)
373 if (defined $contents{'CONFIG_HEADER'})
375 ($xform = &dirname ($contents{'CONFIG_HEADER'}))
377 $xform = 's/\@CONFIG_INCLUDE_SPEC\@/-I' . $xform . '/go';
379 $output_vars .= &file_contents_with_transform ($xform,
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.
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");
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@'})
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');
415 &push_phony_cleaners ('kr');
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"})
431 if (! defined $contents{$one_file . "_OBJECTS"})
433 # Turn sources into objects.
434 local (@files) = split (/\s+/, $contents{$one_file . "_SOURCES"});
435 local (@result) = ();
440 # Skip things that look like macro references.
441 next if /^\$\(.*\)$/;
442 next if /^\$\{.*\}$/;
446 # Automatically include generated .c file in
448 &push_dist_common ($1 . '.c');
451 # Transform source files into .o files.
453 s/\.[cCmylfs]$/$obj/g;
456 # Transform .o or $o file into .P file (for automatic
459 $dep_files{'$(srcdir)/.deps/' . $_} = 1;
462 &pretty_print ($one_file . "_OBJECTS =", " ", @result);
466 &am_error ($one_file . '_OBJECTS', 'should not be defined');
469 push (@sources, '$(' . $one_file . "_SOURCES)");
470 push (@objects, '$(' . $one_file . "_OBJECTS)");
474 $output_vars .= ($one_file . "_SOURCES = " . $one_file . ".c\n"
475 . $one_file . "_OBJECTS = ". $one_file
477 push (@sources, $one_file . '.c');
478 push (@objects, $one_file . $obj);
479 $dep_files{'$(srcdir)/.deps/' . $one_file . '.P'} = 1;
482 if (defined $contents{'CONFIG_HEADER'})
484 $output_rules .= ('$(' . $one_file . "_OBJECTS): "
485 . $contents{'CONFIG_HEADER'} . "\n");
494 local (@proglist) = &am_install_var ('-clean',
495 'programs', 'PROGRAMS',
496 'bin', 'sbin', 'libexec', 'pkglib',
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)
506 &handle_source_transform ($one_file, $obj);
508 if (! defined $contents{$one_file . "_LDADD"})
510 # User didn't define prog_LDADD override. So do it.
511 $output_vars .= $one_file . '_LDADD = $(LDADD)' . "\n";
515 &file_contents_with_transform ('s/\@PROGRAM\@/' . $one_file
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
531 local ($onedir, $onelib);
533 foreach $onedir ('lib', 'pkglib', 'noinst')
535 if (defined $contents{$onedir . '_LIBRARIES'})
538 foreach $onelib (split (/\s+/, $contents{$onedir . '_LIBRARIES'}))
540 push (@outlist, 'lib' . $onelib . '.a');
542 &pretty_print ($onedir . '_LIBFILES =', " ", @outlist);
545 push (@all, '$(LIBFILES)');
547 local ($obj) = &get_object_extension;
549 foreach $onelib (@liblist)
551 if (defined $contents{$onelib . '_LIBADD'})
553 # We recognize certain things that are commonly put in
557 foreach $lsearch (split (/\s+/, $contents{$onelib . '_LIBADD'}))
559 # Automatically handle @LIBOBJS@ and @ALLOCA@.
560 # Basically this means adding entries to dep_files.
561 if ($lsearch eq '@LIBOBJS@')
563 local ($iter, $rewrite);
564 foreach $iter (keys %libsources)
566 if ($iter ne 'alloca.c')
568 ($rewrite = $iter) =~ s/\.c$/.P/;
569 $dep_files{'$(srcdir)/.deps/' . $rewrite} = 1;
570 &require_file ($NORMAL, $iter);
574 elsif ($lsearch eq '@ALLOCA@')
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');
585 # Generate support for conditional object inclusion in
587 $output_vars .= $onelib . "_LIBADD =\n";
590 &handle_source_transform ($onelib, $obj);
593 &file_contents_with_transform ('s/\@LIBRARY\@/' . $onelib . '/go',
597 # Turn "foo" into "libfoo.a" and include macro definition.
598 grep (($_ = 'lib' . $_ . '.a') && 0, @liblist);
600 if (! defined $contents{'LIBFILES'})
602 &pretty_print ('LIBFILES = ', " ", @liblist);
604 $output_vars .= &file_contents ('libraries-vars');
610 # FIXME can't determine if these scripts are really being
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
621 sub grep_for_vers_texi
623 local ($filename) = @_;
625 if (! open (TEXI, $filename))
627 &am_error ("couldn't open \`$filename': $!");
633 if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
645 # Handle all Texinfo source.
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);
662 local ($tc_cursor, @texi_cleans);
664 foreach $info_cursor (@texis)
666 ($infobase = $info_cursor) =~ s/\.texi$//;
668 # If 'version.texi' is referenced by input file, then include
669 # automatic versioning capability.
671 = &grep_for_vers_texi ($relative_dir . "/" . $info_cursor);
674 &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
675 if (defined $versions{$vtexi});
676 $versions{$vtexi} = $info_cursor;
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);
688 &file_contents_with_transform
689 ('s/\@TEXI\@/' . $info_cursor . '/g; '
690 . 's/\@VTI\@/' . $vti . '/g; '
691 . 's/\@VTEXI\@/' . $vtexi . '/g',
694 &push_phony_cleaners ($vti);
697 &require_file ($NORMAL, 'mdate-sh') if ! $done;
701 # If user specified file_TEXINFOS, then use that as explicit
704 push (@texi_deps, $info_cursor, $vtexi);
705 if (defined $contents{$infobase . "_TEXINFOS"})
707 push (@texi_deps, "\$" . $infobase . '_TEXINFOS');
708 &push_dist_common ("\$" . $infobase . '_TEXINFOS');
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')
725 push (@texi_cleans, $infobase . '.' . $tc_cursor);
730 $output_vars .= &file_contents ('texinfos-vars');
731 $output_rules .= &file_contents ('texinfos');
732 push (@phony, 'install-info', 'uninstall-info');
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
763 . "TEXINFOS = " . $contents{'info_TEXINFOS'} . "\n\n");
765 # Do some error checking.
766 &require_file ($NORMAL, 'texinfo.tex');
769 # Handle any 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);
782 # FIXME: statement without effect:
783 /^(.*)\.([0-9])([a-z]*)$/;
787 $fullsecmap{$1} = $2 . $3;
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)
798 push (@installdirs, '$(mandir)/man' . $_);
799 $output_rules .= ("\t" . '$(top_srcdir)/mkinstalldirs $(mandir)/man'
802 push (@phony, 'install-man');
804 # Generate install target.
806 foreach $key (keys %inames)
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;
815 $output_rules .= "\n";
817 $output_rules .= "uninstall-man:\n";
818 foreach $key (keys %inames)
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;
827 $output_rules .= "\n";
828 push (@phony, 'uninstall-man');
830 $output_vars .= &file_contents ('mans-vars');
832 if (! defined $options{'no-installman'})
834 push (@install_data, 'install-man');
835 push (@uninstall, 'uninstall-man');
836 push (@all, '$(MANS)');
840 # Handle DATA variables.
843 &am_install_var ('data', 'DATA', 'data', 'sysconf',
844 'sharedstate', 'localstate', 'pkgdata',
851 local ($tagging) = 0;
853 push (@phony, 'tags');
854 if (defined $contents{'SUBDIRS'})
856 $output_rules .= &file_contents ('tags');
859 elsif ($dir_holds_sources || defined $contents{'ETAGS_ARGS'})
861 $output_rules .= &file_contents ('tags-subd');
867 $output_rules .= &file_contents ('tags-clean');
868 push (@clean, 'tags');
869 &push_phony_cleaners ('tags');
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";
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 '.')
891 if ($strictness >= $GNITS)
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; \\
905 # Create dist directory.
910 # We need an absolute path for --output-dir. Thus the
912 . ' distdir=`cd $(distdir) && pwd` \\
914 && automake --include-deps --output-dir=$$distdir --strictness='
915 # Set strictness of output.
916 . $strictness_name . "\n"
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; \\
936 # If we have SUBDIRS, create all dist subdirectories and do
938 if (defined $contents{'SUBDIRS'})
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 \\
946 chmod 777 $(distdir)/$$subdir; \\
947 (cd $$subdir && $(MAKE) dist) || exit 1; \\
952 # Make verbatim copies of some subdirectories if required. This
953 # is a hack which might go away.
954 if (defined $contents{'DIST_SUBDIRS'})
956 $output_rules .= ' @for dir in $(DIST_SUBDIRS); do \\
957 echo copying directory $$dir; \\
958 tar chf - $$dir | (cd $(distdir) && tar xBpf -); \\
964 if ($relative_dir eq '.')
966 $output_rules .= ' chmod -R a+r $(distdir)' . "\n\t";
969 $output_rules .= 'shar $(distdir) | gzip > $(distdir).shar.gz';
973 $output_rules .= 'tar chozf $(distdir).tar.gz $(distdir)';
975 $output_rules .= "\n\t" . 'rm -rf $(distdir)' . "\n";
978 push (@phony, $target);
981 # Handle 'dist' target.
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'})
992 &am_error ("DIST_CHARSET defined but no MAINT_CHARSET defined")
993 if ! $local_maint_charset;
994 if ($relative_dir eq '.')
996 $dist_charset = $contents{'DIST_CHARSET'}
1000 &am_error ("DIST_CHARSET can only be defined at top level");
1004 # Look for common files that should be included in distribution.
1006 foreach $cfile (@common_files)
1008 if (-f ($relative_dir . "/" . $cfile))
1010 &push_dist_common ($cfile);
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.
1019 if (defined $dist_common{'README'})
1021 push (@coms, 'README');
1022 undef $dist_common{'README'};
1024 push (@coms, sort keys %dist_common);
1026 &pretty_print ("DIST_COMMON =", " ", @coms);
1027 $output_vars .= "\n";
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 '.')
1036 $output_rules .= "\n" . 'distdir = $(PACKAGE)-$(VERSION)' . "\n";
1040 $output_rules .= ("\nsubdir = " . $relative_dir . "\n"
1041 . 'distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)'
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)
1055 # Include GNU-make-specific auto-dep code.
1056 if ($dir_holds_sources)
1058 &pretty_print ('DEP_FILES =', " ", sort keys %dep_files);
1059 $output_rules .= &file_contents ('depend');
1064 # Include any auto-generated deps that are present.
1065 if (-d ($relative_dir . "/.deps") && -f ($relative_dir . "/.deps/.P"))
1068 local ($gpat) = $relative_dir . "/.deps/*.P";
1070 foreach $depfile (<${gpat}>)
1072 if (! open (DEP_FILE, $depfile))
1074 &am_error ("couldn't open $depfile", $!);
1078 # Slurp entire file.
1079 $output_rules .= join ('', <DEP_FILE>);
1084 $output_rules .= "\n";
1089 # Handle subdirectories.
1092 if (! defined $contents{'SUBDIRS'})
1095 ("ud_GNU_GETTEXT in configure.in but SUBDIRS not defined")
1096 if $seen_gettext && $relative_dir eq '.';
1101 ("ud_GNU_GETTEXT in configure.in but \`po' not in SUBDIRS")
1102 if $seen_gettext && $contents{'SUBDIRS'} !~ /\bpo\b/;
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.
1113 foreach $dir (split (/\s+/, $contents{'SUBDIRS'}))
1115 &am_error ("required directory $relative_dir/$dir does not exist")
1116 if ! -d $relative_dir . '/' . $dir;
1119 $output_rules .= &file_contents ('subdirs');
1121 # Push a bunch of phony targets.
1123 foreach $phonies ('-data', '-exec', 'dirs')
1125 push (@phony, 'install' . $phonies . '-recursive');
1126 push (@phony, 'uninstall' . $phonies . '-recursive');
1128 foreach $phonies ('all', 'check', 'installcheck', 'info', 'dvi')
1130 push (@phony, $phonies . '-recursive');
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 '.')
1154 $output_rules .= &file_contents ('remake-subd');
1155 $top_reldir = '../';
1159 if (-f 'aclocal.m4')
1161 $output_vars .= "ACLOCAL = aclocal.m4\n";
1162 &push_dist_common ('aclocal.m4');
1164 $output_rules .= &file_contents ('remake');
1166 # Look for some files we need.
1167 &require_file ($NORMAL, 'install-sh', 'mkinstalldirs');
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.
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')
1186 $output_vars .= "ACCONFIG = acconfig.h\n";
1187 &push_dist_common ('acconfig.h');
1189 if (-f $config_name . '.top')
1191 $output_vars .= "CONFIG_TOP = ${config_name}.top\n";
1192 &push_dist_common ($config_name . '.top');
1194 if (-f $config_name . '.bot')
1196 $output_vars .= "CONFIG_BOT = ${config_name}.bot\n";
1197 &push_dist_common ($config_name . '.bot');
1200 &push_dist_common ('stamp-h.in');
1202 $output_rules .= &file_contents ('remake-hdr');
1203 $output_vars .= "CONFIG_HEADER_IN = ${config_header}\n";
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"
1215 $contents{'CONFIG_HEADER'} = "${top_builddir}/${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)
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 =~ /^(.*):(.*)$/)
1232 # This is the ":" syntax of AC_OUTPUT.
1239 $input = $local . '.in';
1241 # FIXME when using autoconf ":" syntax, should we set CONFIG_FILES
1243 $output_rules .= ($local . ': '
1244 . '$(top_builddir)/config.status ' . $input . "\n"
1246 . 'cd $(top_srcdir) && CONFIG_FILES='
1247 . ($relative_dir eq '.' ? '' : '$(subdir)/')
1248 . '$@ CONFIG_HEADERS= ./config.status'
1250 &require_file ($NORMAL, $local . '.in');
1257 &am_install_var ('header', 'HEADERS', 'include',
1258 'oldinclude', 'pkginclude',
1262 # Handle footer elements.
1265 if ($contents{'SOURCES'})
1267 &pretty_print ('SOURCES =', " ",
1268 split (/\s+/, $contents{'SOURCES'}));
1270 if ($contents{'OBJECTS'})
1272 &pretty_print ('OBJECTS =', " ",
1273 split (/\s+/, $contents{'OBJECTS'}));
1275 if ($contents{'SOURCES'} || $contents{'OBJECTS'})
1277 $output_vars .= "\n";
1280 if (defined $contents{'SUFFIXES'})
1282 push (@suffixes, '$(SUFFIXES)');
1285 $output_trailer .= ".SUFFIXES:\n";
1288 $output_trailer .= ".SUFFIXES: " . join (' ', @suffixes) . "\n";
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"
1301 push (@phony, 'installdirs');
1304 &pretty_print_rule ("\t\$(top_srcdir)/mkinstalldirs ", "\t\t",
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 '.')
1321 # 'check' must depend on 'all', but not at top level.
1322 unshift (@check, 'all');
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'})
1334 push (@install_exec, 'install-exec-local');
1336 if (defined $contents{'install-data-local'})
1338 push (@install_data, 'install-data-local');
1340 if (defined $contents{'uninstall-local'})
1342 push (@uninstall, 'uninstall-local');
1345 if (defined $contents{'install-local'})
1347 &am_error ("use \`install-data' or \`install-exec', not \`install'");
1350 # Step two: if we are doing recursive makes, write out the
1351 # appropriate rules.
1353 if ($recursive_install)
1355 push (@install, 'install-recursive');
1356 push (@uninstall, 'uninstall-recursive');
1360 $output_rules .= ('install-exec-am: '
1361 . join (' ', @install_exec)
1363 @install_exec = ('install-exec-recursive', 'install-exec-am');
1364 push (@install, 'install-exec-am');
1365 push (@phony, 'install-exec-am');
1369 $output_rules .= ('install-data-am: '
1370 . join (' ', @install_data)
1372 @install_data = ('install-data-recursive', 'install-data-am');
1373 push (@install, 'install-data-am');
1374 push (@phony, 'install-data-am');
1378 $output_rules .= ('uninstall-am: '
1379 . join (' ', @uninstall)
1381 @uninstall = ('uninstall-recursive', 'uninstall-am');
1382 push (@phony, 'uninstall-am');
1386 # Step three: print definitions users can use.
1387 $output_rules .= ("install-exec: "
1388 . join (' ', @install_exec)
1390 push (@install, 'install-exec') if !$recursive_install;
1391 push (@phony, 'install-exec');
1393 $output_rules .= ("install-data: "
1394 . join (' ', @install_data)
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.
1409 . join (' ', @uninstall)
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'})
1421 # User defined local form of target. So include it.
1422 push (@values, $name . '-local');
1423 push (@phony, $name . '-local');
1426 $output_rules .= $name . ":";
1429 $output_rules .= ' ' . join (' ', @values);
1431 $output_rules .= "\n\n";
1432 push (@phony, $name);
1435 # Handle all 'clean' targets.
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');
1451 if ($recursive_install)
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);
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);
1476 if ($last_name || $name ne 'mostly')
1478 push (@deps, $last_name . $target . " ");
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
1486 if ($name . $target eq 'maintainer-clean')
1488 # Print a special warning.
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 '.';
1497 elsif ($name . $target eq 'distclean')
1499 $output_rules .= "\trm -f config.status\n";
1501 $output_rules .= "\n";
1504 # Handle .PHONY target.
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.
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.
1525 local ($in_ac_output, @make_list) = 0;
1526 local ($seen_arg_prog) = 0;
1527 local ($seen_canonical) = 0;
1530 # Remove comments from current line.
1534 # Populate libobjs array.
1535 if (/AC_FUNC_ALLOCA/)
1537 $libsources{'alloca.c'} = 1;
1539 elsif (/AC_FUNC_GETLOADAVG/)
1541 $libsources{'getloadavg.c'} = 1;
1543 elsif (/AC_FUNC_MEMCMP/)
1545 $libsources{'memcmp.c'} = 1;
1547 elsif (/AC_STRUCT_ST_BLOCKS/)
1549 $libsources{'fileblocks.c'} = 1;
1551 elsif (/AC_REPLACE_FUNCS\s*\((.*)\)/)
1553 foreach (split (/\s+/, $1))
1555 $libsources{$_ . '.c'} = 1;
1558 elsif (/LIBOBJS="(.*)\.o\s+\$LIBOBJS"/)
1560 $libsources{$1 . '.c'} = 1;
1562 elsif (/LIBOBJS="\$LIBOBJS\s+(.*)\.o"/)
1564 $libsources{$1 . '.c'} = 1;
1567 # Process the AC_OUTPUT macro.
1568 if (! $in_ac_output && s/AC_OUTPUT\s*\(\[?//)
1575 $in_ac_output = 0 if s/[\),].*$//;
1577 # Look at potential Makefile.am's.
1582 push (@make_list, $_);
1586 push (@other_input_files, $_);
1591 # Check for ansi2knr.
1592 $fp_c_prototypes = 1 if /fp_C_PROTOTYPES/;
1594 # Check for NLS support.
1595 if (/ud_GNU_GETTEXT/)
1600 # Handle configuration headers.
1601 if (/AC_CONFIG_HEADER\s*\((.*)\)/)
1604 if ($config_name =~ /^([^:]+):(.+)$/)
1607 $config_header = $2;
1611 $config_header = $config_name . '.in';
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
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/;
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
1633 &require_file ($NORMAL, 'config.guess', 'config.sub')
1636 &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
1637 unless $seen_arg_prog;
1642 ################################################################
1644 # Do any extra checking for GNU standards.
1645 sub check_gnu_standards
1647 &require_file ($GNU, 'ChangeLog');
1649 if ($relative_dir eq '.')
1651 # In top level (or only) directory.
1652 &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
1657 # Do any extra checking for GNITS standards.
1658 sub check_gnits_standards
1660 if ($strictness >= $GNITS && -f $relative_dir . '/COPYING.LIB')
1663 ("\`${relative_dir}/COPYING.LIB' disallowed by Gnits standards");
1666 if ($relative_dir eq '.')
1668 # In top level (or only) directory.
1669 &require_file ($GNITS, 'THANKS');
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
1688 local ($fill_length) = length ($fill);
1689 $fill_length += 7 * ($fill =~ tr/\t/\t/d);
1694 # "71" because we also print a space.
1695 if ($column + length ($_) > 71)
1697 $result .= " \\\n" . $fill;
1698 $column = $fill_length;
1702 $result .= ' ' unless ($bol);
1704 $column += length ($_) + 1;
1712 # Pretty-print something and append to output_vars.
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.
1733 local ($amfile) = @_;
1735 # Compute relative location of the top object directory.
1736 local (@topdir) = ();
1737 foreach (split (/\//, $relative_dir))
1739 next if $_ eq '.' || $_ eq '';
1746 push (@topdir, '..');
1749 @topdir = ('.') if ! @topdir;
1751 $top_builddir = join ('/', @topdir);
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',
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) = '';
1775 if (/$IGNORE_PATTERN/o)
1777 # Merely delete comments beginning with two hashes.
1779 elsif (/$WHITE_PATTERN/o)
1781 # Stick a single white line before the incoming macro or rule.
1784 elsif (/$COMMENT_PATTERN/o)
1786 # Stick comments before the incoming macro or rule.
1787 $comment .= $spacing . $_;
1796 $output_vars .= $comment . "\n" . $header_vars;
1802 if (/$IGNORE_PATTERN/o)
1804 # Merely delete comments beginning with two hashes.
1806 elsif (/$WHITE_PATTERN/o)
1808 # Stick a single white line before the incoming macro or rule.
1811 elsif (/$COMMENT_PATTERN/o)
1813 # Stick comments before the incoming macro or rule.
1814 $comment .= $spacing . $_;
1821 $output_trailer .= $_;
1828 # Chop newline and backslash if this line is
1829 # continued. FIXME maybe ensure trailing whitespace
1833 $contents{$last_var_name} .= $_;
1836 elsif (/$RULE_PATTERN/o)
1838 # warn "** Saw rule .$1.\n";
1841 # Value here doesn't matter; for targets we only note
1844 $output_trailer .= $comment . $spacing . $_;
1845 $comment = $spacing = '';
1848 elsif (/$MACRO_PATTERN/o)
1850 # warn "** Saw macro .$1.\n";
1851 # Found a macro definition.
1853 $last_var_name = $1;
1854 if (substr ($2, -1) eq "\\")
1856 $contents{$1} = substr ($2, 0, length ($2) - 1);
1862 $output_vars .= $comment . $spacing . $_;
1863 $comment = $spacing = '';
1866 elsif ($_ eq "\@kr\@\n")
1868 # Special case: this means we want automatic
1869 # de-ANSI-fication. This is deprecated. Remove in the
1871 $contents{'@kr@'} = 1;
1872 &am_error ('`@kr@\' is deprecated; put `ansi2knr\' in AUTOMAKE_OPTIONS instead');
1876 # This isn't an error; it is probably a continued rule.
1877 # In fact, this is what we assume.
1879 $output_trailer .= $comment . $spacing . $_;
1880 $comment = $spacing = '';
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.
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
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"
1936 # Commonly used files we auto-include, but only sometimes.
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"
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.
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.
1970 $output_trailer = '';
1972 # Suffixes found during a run.
1975 # This holds the contents of a Makefile.am, as parsed by
1979 # This holds the "relative directory" of the current Makefile.in.
1980 # Eg for src/Makefile.in, this is "src".
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
1991 # List of dependencies for the obvious targets.
2006 # These are pretty obvious, too. They are used to define the
2007 # SOURCES and OBJECTS variables.
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;
2022 # Strictness levels.
2023 $strictness = $default_strictness;
2024 $strictness_name = $default_strictness_name;
2026 # Options from AUTOMAKE_OPTIONS.
2029 # Whether or not dependencies are handled. Can be further changed
2030 # in handle_options.
2031 $use_dependencies = $cmdline_use_dependencies;
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;
2062 if (/$IGNORE_PATTERN/o)
2064 # Merely delete comments beginning with two hashes.
2066 elsif (/$WHITE_PATTERN/o)
2068 # Stick a single white line before the incoming macro or rule.
2071 elsif (/$COMMENT_PATTERN/o)
2073 # Stick comments before the incoming macro or rule.
2074 $comment .= $spacing . $_;
2081 $result_rules .= $_ if ! $skipping;
2085 $result_vars .= $_ if ! $skipping;
2089 elsif (/$RULE_PATTERN/o)
2091 # warn "** Found rule .$1.\n";
2094 $skipping = defined $contents{$1};
2095 # warn "** Skip $skipping\n" if $skipping;
2096 $result_rules .= $comment . $spacing . $_ if ! $skipping;
2097 $comment = $spacing = '';
2100 elsif (/$MACRO_PATTERN/o)
2102 # warn "** Found macro .$1.\n";
2103 # Found a variable reference.
2105 $skipping = defined $contents{$1};
2106 # warn "** Skip $skipping\n" if $skipping;
2107 $result_vars .= $comment . $spacing . $_ if ! $skipping;
2108 $comment = $spacing = '';
2113 # This isn't an error; it is probably a continued rule.
2114 # In fact, this is what we assume.
2116 $result_rules .= $comment . $spacing . $_ if ! $skipping;
2117 $comment = $spacing = '';
2123 return $result_vars . $result_rules . $comment;
2126 # Like file_contents_with_transform, but no transform.
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...)
2147 local ($do_all, $do_clean) = (1, 0);
2150 if ($args[0] eq '-clean')
2154 elsif ($args[0] eq '-no-all')
2158 elsif ($args[0] !~ /^-/)
2164 local ($file, $primary, @prefixes) = @args;
2167 local (@result) = ();
2169 local ($clean_file) = $file . '-clean';
2172 foreach $X (@prefixes)
2174 $one_name = $X . '_' . $primary;
2175 if (defined $contents{$one_name})
2177 # Append actual contents to result.
2178 push (@result, split (/\s+/, $contents{$one_name}));
2183 &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go',
2186 push (@clean, $X . $primary);
2187 &push_phony_cleaners ($X . $primary);
2190 push (@used, '$(' . $one_name . ')');
2193 # Objects in noinst_FOO never get installed.
2198 &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go',
2201 push (@uninstall, 'uninstall-' . $X . $primary);
2202 push (@phony, 'uninstall-' . $X . $primary);
2203 push (@installdirs, '$(' . $X . 'dir)');
2204 if ($exec_dir_p{$X})
2206 push (@install_exec, 'install-' . $X . $primary);
2210 push (@install_data, 'install-' . $X . $primary);
2215 if (! defined $contents{$primary} && @used)
2218 &pretty_print ($primary . ' =', '', @used);
2219 $output_vars .= "\n";
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
2228 local (%valid, $varname);
2229 grep ($valid{$_} = 0, @prefixes);
2230 foreach $varname (keys %contents)
2232 if ($varname =~ /^(.*)_$primary$/ && ! defined $valid{$1})
2234 &am_error ("invalid variable \"$varname\"");
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
2250 local ($mystrict, @files) = @_;
2251 local ($file, $fullfile);
2253 foreach $file (@files)
2255 $fullfile = $relative_dir . "/" . $file;
2259 &push_dist_common ($file);
2261 elsif ($strictness >= $mystrict)
2263 # Only install missing files according to our desired
2265 if ($install_missing && -f ($am_dir . '/' . $file))
2267 # Install the missing file. Symlink if we can, copy
2269 if ($symlink_exists)
2271 symlink ($am_dir . '/' . $file, $fullfile);
2275 system ('cp', $am_dir . '/' . $file, $fullfile);
2278 ("required file \"$fullfile\" not found; installing");
2282 # Only an error if strictness constraint violated.
2283 &am_error ("required file \"$fullfile\" not found");
2289 # Push a list of files onto dist_common.
2290 sub push_dist_common
2292 local (@files) = @_;
2295 foreach $file (@files)
2297 $dist_common{$file} = 1;
2301 # Push a list of clean targets onto phony.
2302 sub push_phony_cleaners
2306 foreach $target ('mostly', 'dist', '', 'maintainer-')
2308 push (@phony, $target . 'clean-' . $base);
2315 $strictness_name = $_[0];
2316 if ($strictness_name eq 'gnu')
2320 elsif ($strictness_name eq 'gnits')
2322 $strictness = $GNITS;
2324 elsif ($strictness_name eq 'normal')
2326 $strictness = $NORMAL;
2330 die "automake: level \`$strictness_name' not recognized\n";
2335 ################################################################
2337 # Return directory name of file.
2343 ($sub = $file) =~ s,/+[^/]+$,,g;
2344 $sub = '.' if $sub eq $file;
2351 local ($dirname) = @_;
2352 system ("mkdir", $dirname);
2355 ################################################################
2357 # Print an error message and set exit status.
2360 warn "automake: ${am_file}.am: ", join (' ', @_), "\n";
2364 # The same, but while scanning configure.in.
2367 # FIXME can run in subdirs.
2368 warn "automake: configure.in: ", join (' ', @_), "\n";
2372 # Print usage information.
2375 print "Usage: automake [OPTION] ... [Makefile]...\n";
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);
2383 $one = shift @lcomm;
2384 $two = @lcomm ? shift @lcomm : '';
2385 $three = @lcomm ? shift @lcomm : '';
2386 $four = @lcomm ? shift @lcomm : '';
2393 format USAGE_FORMAT =
2394 @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<
2395 $one, $two, $three, $four