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 '.';
1100 &require_file ($NORMAL, 'ABOUT-NLS') if $seen_gettext;
1102 return if ! defined $contents{'SUBDIRS'};
1104 # Make sure each directory mentioned in SUBDIRS actually exists.
1106 foreach $dir (split (/\s+/, $contents{'SUBDIRS'}))
1108 &am_error ("required directory $relative_dir/$dir does not exist")
1109 if ! -d $relative_dir . '/' . $dir;
1112 $output_rules .= &file_contents ('subdirs');
1114 # Push a bunch of phony targets.
1116 foreach $phonies ('-data', '-exec', 'dirs')
1118 push (@phony, 'install' . $phonies . '-recursive');
1119 push (@phony, 'uninstall' . $phonies . '-recursive');
1121 foreach $phonies ('all', 'check', 'installcheck', 'info', 'dvi')
1123 push (@phony, $phonies . '-recursive');
1125 &push_phony_cleaners ('recursive');
1127 push (@all, "all-recursive");
1128 push (@check, "check-recursive");
1129 push (@installcheck, "installcheck-recursive");
1130 push (@info, "info-recursive");
1131 push (@dvi, "dvi-recursive");
1133 $recursive_install = 1;
1136 # Handle remaking and configure stuff.
1137 sub handle_configure
1139 # If SUBDIRS defined, require AC_PROG_MAKE_SET.
1140 &am_error ("AC_PROG_MAKE_SET must be used in configure.in")
1141 if defined $contents{'SUBDIRS'} && ! $seen_make_set;
1143 local ($top_reldir);
1144 if ($relative_dir ne '.')
1147 $output_rules .= &file_contents ('remake-subd');
1148 $top_reldir = '../';
1152 if (-f 'aclocal.m4')
1154 $output_vars .= "ACLOCAL = aclocal.m4\n";
1155 &push_dist_common ('aclocal.m4');
1157 $output_rules .= &file_contents ('remake');
1159 # Look for some files we need.
1160 &require_file ($NORMAL, 'install-sh', 'mkinstalldirs');
1163 ("\`install.sh' is an anachronism; use \`install-sh' instead")
1164 if -f $relative_dir . '/install.sh';
1166 # If we have a configure header, require it.
1169 # FIXME this restriction should be lifted.
1170 # FIXME first see if it is even needed as-is.
1171 &am_error ("argument to AC_CONFIG_HEADER contains \`/'\n")
1172 if ($config_header =~ /\//);
1174 &require_file ($NORMAL, $config_header);
1176 # Header defined and in this directory.
1177 if (-f 'acconfig.h')
1179 $output_vars .= "ACCONFIG = acconfig.h\n";
1180 &push_dist_common ('acconfig.h');
1182 if (-f $config_name . '.top')
1184 $output_vars .= "CONFIG_TOP = ${config_name}.top\n";
1185 &push_dist_common ($config_name . '.top');
1187 if (-f $config_name . '.bot')
1189 $output_vars .= "CONFIG_BOT = ${config_name}.bot\n";
1190 &push_dist_common ($config_name . '.bot');
1193 &push_dist_common ('stamp-h.in');
1195 $output_rules .= &file_contents ('remake-hdr');
1196 $output_vars .= "CONFIG_HEADER_IN = ${config_header}\n";
1202 &am_error ("\`CONFIG_HEADER' is an anachronism; now determined from \`configure.in'")
1203 if defined $contents{'CONFIG_HEADER'};
1205 # Generate CONFIG_HEADER define, and define interally.
1206 $output_vars .= "CONFIG_HEADER = ${top_builddir}/${config_name}\n"
1208 $contents{'CONFIG_HEADER'} = "${top_builddir}/${config_name}"
1211 # Now look for other files in this directory which must be remade
1212 # by config.status, and generate rules for them.
1213 local ($file, $local, $input);
1214 foreach $file (@other_input_files)
1216 # Skip files not in this directory, any Makefile, and the
1217 # config header. These last two must be handled specially.
1218 next unless &dirname ($file) eq $relative_dir;
1219 next if $file eq $top_builddir . '/' . $config_name;
1220 ($local = $file) =~ s/^.*\///;
1221 next if $local eq 'Makefile';
1223 if ($local =~ /^(.*):(.*)$/)
1225 # This is the ":" syntax of AC_OUTPUT.
1232 $input = $local . '.in';
1234 # FIXME when using autoconf ":" syntax, should we set CONFIG_FILES
1236 $output_rules .= ($local . ': '
1237 . '$(top_builddir)/config.status ' . $input . "\n"
1239 . 'cd $(top_srcdir) && CONFIG_FILES='
1240 . ($relative_dir eq '.' ? '' : '$(subdir)/')
1241 . '$@ CONFIG_HEADERS= ./config.status'
1243 &require_file ($NORMAL, $local . '.in');
1250 &am_install_var ('header', 'HEADERS', 'include',
1251 'oldinclude', 'pkginclude',
1255 # Handle footer elements.
1258 if ($contents{'SOURCES'})
1260 &pretty_print ('SOURCES =', " ",
1261 split (/\s+/, $contents{'SOURCES'}));
1263 if ($contents{'OBJECTS'})
1265 &pretty_print ('OBJECTS =', " ",
1266 split (/\s+/, $contents{'OBJECTS'}));
1268 if ($contents{'SOURCES'} || $contents{'OBJECTS'})
1270 $output_vars .= "\n";
1273 if (defined $contents{'SUFFIXES'})
1275 push (@suffixes, '$(SUFFIXES)');
1278 $output_trailer .= ".SUFFIXES:\n";
1281 $output_trailer .= ".SUFFIXES: " . join (' ', @suffixes) . "\n";
1283 $output_trailer .= &file_contents ('footer');
1286 # Deal with installdirs target.
1287 sub handle_installdirs
1289 # GNU Makefile standards recommend this.
1290 $output_rules .= ("installdirs:"
1291 . ($recursive_install
1292 ? " installdirs-recursive\n"
1294 push (@phony, 'installdirs');
1297 &pretty_print_rule ("\t\$(top_srcdir)/mkinstalldirs ", "\t\t",
1300 $output_rules .= "\n";
1303 # There are several targets which need to be merged. This is because
1304 # their complete definition is compiled from many parts. Note that we
1305 # avoid double colon rules, otherwise we'd use them instead.
1306 sub handle_merge_targets
1308 &do_one_merge_target ('all', @all);
1309 &do_one_merge_target ('info', @info);
1310 &do_one_merge_target ('dvi', @dvi);
1312 if (! defined $contents{'SUBDIRS'} || $relative_dir ne '.')
1314 # 'check' must depend on 'all', but not at top level.
1315 unshift (@check, 'all');
1317 &do_one_merge_target ('check', @check);
1318 &do_one_merge_target ('installcheck', @installcheck);
1320 # Handle the various install targets specially. We do this so
1321 # that (eg) "make install-exec" will run "install-exec-recursive"
1322 # if required, but "make install" won't run it twice. Step one is
1323 # to see if the user specified local versions of any of the
1324 # targets we handle.
1325 if (defined $contents{'install-exec-local'})
1327 push (@install_exec, 'install-exec-local');
1329 if (defined $contents{'install-data-local'})
1331 push (@install_data, 'install-data-local');
1333 if (defined $contents{'uninstall-local'})
1335 push (@uninstall, 'uninstall-local');
1338 if (defined $contents{'install-local'})
1340 &am_error ("use \`install-data' or \`install-exec', not \`install'");
1343 # Step two: if we are doing recursive makes, write out the
1344 # appropriate rules.
1346 if ($recursive_install)
1348 push (@install, 'install-recursive');
1349 push (@uninstall, 'uninstall-recursive');
1353 $output_rules .= ('install-exec-am: '
1354 . join (' ', @install_exec)
1356 @install_exec = ('install-exec-recursive', 'install-exec-am');
1357 push (@install, 'install-exec-am');
1358 push (@phony, 'install-exec-am');
1362 $output_rules .= ('install-data-am: '
1363 . join (' ', @install_data)
1365 @install_data = ('install-data-recursive', 'install-data-am');
1366 push (@install, 'install-data-am');
1367 push (@phony, 'install-data-am');
1371 $output_rules .= ('uninstall-am: '
1372 . join (' ', @uninstall)
1374 @uninstall = ('uninstall-recursive', 'uninstall-am');
1375 push (@phony, 'uninstall-am');
1379 # Step three: print definitions users can use.
1380 $output_rules .= ("install-exec: "
1381 . join (' ', @install_exec)
1383 push (@install, 'install-exec') if !$recursive_install;
1384 push (@phony, 'install-exec');
1386 $output_rules .= ("install-data: "
1387 . join (' ', @install_data)
1389 push (@install, 'install-data') if !$recursive_install;
1390 push (@phony, 'install-data');
1392 # If no dependencies for 'install', add 'all'. Why? That way
1393 # "make install" at top level of distclean'd distribution won't
1394 # fail because stuff in 'lib' fails to build.
1395 push (@install, 'all') if ! @install;
1396 $output_rules .= ('install: '
1397 . join (' ', @install)
1398 # Use "@:" as empty command so nothing prints.
1402 . join (' ', @uninstall)
1404 push (@phony, 'install', 'uninstall');
1407 # Helper for handle_merge_targets.
1408 sub do_one_merge_target
1410 local ($name, @values) = @_;
1412 if (defined $contents{$name . '-local'})
1414 # User defined local form of target. So include it.
1415 push (@values, $name . '-local');
1416 push (@phony, $name . '-local');
1419 $output_rules .= $name . ":";
1422 $output_rules .= ' ' . join (' ', @values);
1424 $output_rules .= "\n\n";
1425 push (@phony, $name);
1428 # Handle all 'clean' targets.
1431 push (@clean, 'generic');
1432 $output_rules .= &file_contents ('clean');
1433 &push_phony_cleaners ('generic');
1435 local ($target) = $recursive_install ? 'clean-am' : 'clean';
1436 &do_one_clean_target ($target, 'mostly', '', @clean);
1437 &do_one_clean_target ($target, '', 'mostly', @clean);
1438 &do_one_clean_target ($target, 'dist', '', @clean);
1439 &do_one_clean_target ($target, 'maintainer-', 'dist', @clean);
1441 push (@phony, 'clean', 'mostlyclean', 'distclean', 'maintainer-clean');
1444 if ($recursive_install)
1446 @deps = ('am', 'recursive');
1447 &do_one_clean_target ('', 'mostly', '', @deps);
1448 &do_one_clean_target ('', '', '', @deps);
1449 &do_one_clean_target ('', 'dist', '', @deps);
1450 &do_one_clean_target ('', 'maintainer-', '', @deps);
1454 # Helper for handle_clean.
1455 sub do_one_clean_target
1457 local ($target, $name, $last_name, @deps) = @_;
1459 # Special case: if target not passed, then don't generate
1460 # dependency on next "lower" clean target (eg no
1461 # clean<-mostlyclean derivation). In this case the target is
1462 # implicitly known to be 'clean'.
1463 local ($flag) = $target;
1464 $target = 'clean' if ! $flag;
1466 grep (($_ = $name . 'clean-' . $_) && 0, @deps);
1469 if ($last_name || $name ne 'mostly')
1471 push (@deps, $last_name . $target . " ");
1474 # FIXME not sure if I like the tabs here.
1475 &pretty_print_rule ($name . $target . ": ", "\t\t", @deps);
1477 # FIXME shouldn't we really print these messages before running
1479 if ($name . $target eq 'maintainer-clean')
1481 # Print a special warning.
1483 ("\t\@echo \"This command is intended for maintainers to use;\"\n"
1484 . "\t\@echo \"it deletes files that may require special "
1485 . "tools to rebuild.\"\n");
1487 $output_rules .= "\trm -f config.status\n"
1488 if $relative_dir eq '.';
1490 elsif ($name . $target eq 'distclean')
1492 $output_rules .= "\trm -f config.status\n";
1494 $output_rules .= "\n";
1497 # Handle .PHONY target.
1500 &pretty_print_rule ('.PHONY:', " ", @phony);
1501 $output_rules .= "\n";
1504 ################################################################
1506 # Scan configure.in for interesting things.
1507 # FIXME ensure VERSION, PACKAGE are set.
1510 open (CONFIGURE, 'configure.in')
1511 || die "automake: couldn't open configure.in: $!\n";
1513 # Reinitialize libsources here. This isn't really necessary,
1514 # since we currently assume there is only one configure.in. But
1515 # that won't always be the case.
1518 local ($in_ac_output, @make_list) = 0;
1519 local ($seen_arg_prog) = 0;
1520 local ($seen_canonical) = 0;
1523 # Remove comments from current line.
1527 # Populate libobjs array.
1528 if (/AC_FUNC_ALLOCA/)
1530 $libsources{'alloca.c'} = 1;
1532 elsif (/AC_FUNC_GETLOADAVG/)
1534 $libsources{'getloadavg.c'} = 1;
1536 elsif (/AC_FUNC_MEMCMP/)
1538 $libsources{'memcmp.c'} = 1;
1540 elsif (/AC_STRUCT_ST_BLOCKS/)
1542 $libsources{'fileblocks.c'} = 1;
1544 elsif (/AC_REPLACE_FUNCS\s*\((.*)\)/)
1546 foreach (split (/\s+/, $1))
1548 $libsources{$_ . '.c'} = 1;
1551 elsif (/LIBOBJS="(.*)\.o\s+\$LIBOBJS"/)
1553 $libsources{$1 . '.c'} = 1;
1555 elsif (/LIBOBJS="\$LIBOBJS\s+(.*)\.o"/)
1557 $libsources{$1 . '.c'} = 1;
1560 # Process the AC_OUTPUT macro.
1561 if (! $in_ac_output && s/AC_OUTPUT\s*\(\[?//)
1568 $in_ac_output = 0 if s/[\),].*$//;
1570 # Look at potential Makefile.am's.
1576 push (@make_list, $_);
1580 push (@other_input_files, $_);
1585 # Check for ansi2knr.
1586 $fp_c_prototypes = 1 if /fp_C_PROTOTYPES/;
1588 # Check for NLS support.
1589 if (/ud_GNU_GETTEXT/)
1594 # Handle configuration headers.
1595 if (/AC_CONFIG_HEADER\s*\((.*)\)/)
1598 if ($config_name =~ /^([^:]+):(.+)$/)
1601 $config_header = $2;
1605 $config_header = $config_name . '.in';
1609 $seen_canonical = 1 if /AC_CANONICAL_(HOST|SYSTEM)/;
1610 $seen_path_xtra = 1 if /AC_PATH_XTRA/;
1612 # Some things required by Automake. FIXME we only really
1613 # require fp_PROG_INSTALL if some scripts are installed. And
1614 # we only really require AC_ARG_PROGRAM if any program is
1616 $seen_make_set = 1 if /AC_PROG_MAKE_SET/;
1617 $seen_prog_install = 1 if ! $seen_prog_install && /AC_PROG_INSTALL/;
1618 $seen_prog_install = 2 if ! $seen_prog_install && /fp_PROG_INSTALL/;
1619 $seen_arg_prog = 1 if /AC_ARG_PROGRAM/;
1622 # Set input files if not specified by user.
1623 @input_files = @make_list if (! @input_files);
1625 # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
1627 &require_file ($NORMAL, 'config.guess', 'config.sub')
1630 &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
1631 unless $seen_arg_prog;
1636 ################################################################
1638 # Do any extra checking for GNU standards.
1639 sub check_gnu_standards
1641 &require_file ($GNU, 'ChangeLog');
1643 if ($relative_dir eq '.')
1645 # In top level (or only) directory.
1646 &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
1651 # Do any extra checking for GNITS standards.
1652 sub check_gnits_standards
1654 if ($strictness >= $GNITS && -f $relative_dir . '/COPYING.LIB')
1657 ("\`${relative_dir}/COPYING.LIB' disallowed by Gnits standards");
1660 if ($relative_dir eq '.')
1662 # In top level (or only) directory.
1663 &require_file ($GNITS, 'THANKS');
1667 ################################################################
1669 # Pretty-print something. HEAD is what should be printed at the
1670 # beginning of the first line, FILL is what should be printed at the
1671 # beginning of every subsequent line.
1672 sub pretty_print_internal
1674 local ($head, $fill, @values) = @_;
1676 local ($column) = length ($head);
1677 local ($result) = $head;
1679 # Fill length is number of characters. However, each Tab
1680 # character counts for eight. So we count the number of Tabs and
1682 local ($fill_length) = length ($fill);
1683 $fill_length += 7 * ($fill =~ tr/\t/\t/d);
1688 # "71" because we also print a space.
1689 if ($column + length ($_) > 71)
1691 $result .= " \\\n" . $fill;
1692 $column = $fill_length;
1696 $result .= ' ' unless ($bol);
1698 $column += length ($_) + 1;
1706 # Pretty-print something and append to output_vars.
1709 $output_vars .= &pretty_print_internal (@_);
1712 # Pretty-print something and append to output_rules.
1713 sub pretty_print_rule
1715 $output_rules .= &pretty_print_internal (@_);
1719 ################################################################
1721 # Read Makefile.am and set up %contents. Simultaneously copy lines
1722 # from Makefile.am into $output_trailer or $output_vars as
1723 # appropriate. NOTE we put rules in the trailer section. We want
1724 # user rules to come after our generated stuff.
1727 local ($amfile) = @_;
1729 # Compute relative location of the top object directory.
1730 local (@topdir) = ();
1731 foreach (split (/\//, $relative_dir))
1733 next if $_ eq '.' || $_ eq '';
1740 push (@topdir, '..');
1743 @topdir = ('.') if ! @topdir;
1745 $top_builddir = join ('/', @topdir);
1747 ($build_rx = $top_builddir) =~ s/(\W)/\\$1/g;
1748 local ($header_vars) =
1749 &file_contents_with_transform
1750 ('s/\@top_builddir\@/' . $build_rx . '/g',
1753 open (AM_FILE, $amfile) || die "automake: couldn't open $amfile: $!\n";
1755 $output_vars .= ("# Makefile.in generated automatically by automake "
1756 . $VERSION . " from Makefile.am\n");
1758 # Generate copyright for generated Makefile.in.
1759 $output_vars .= $gen_copyright;
1761 local ($saw_bk) = 0;
1762 local ($was_rule) = 0;
1763 local ($spacing) = '';
1764 local ($comment) = '';
1765 local ($last_var_name) = '';
1769 if (/$IGNORE_PATTERN/o)
1771 # Merely delete comments beginning with two hashes.
1773 elsif (/$WHITE_PATTERN/o)
1775 # Stick a single white line before the incoming macro or rule.
1778 elsif (/$COMMENT_PATTERN/o)
1780 # Stick comments before the incoming macro or rule.
1781 $comment .= $spacing . $_;
1790 $output_vars .= $comment . "\n" . $header_vars;
1796 if (/$IGNORE_PATTERN/o)
1798 # Merely delete comments beginning with two hashes.
1800 elsif (/$WHITE_PATTERN/o)
1802 # Stick a single white line before the incoming macro or rule.
1805 elsif (/$COMMENT_PATTERN/o)
1807 # Stick comments before the incoming macro or rule.
1808 $comment .= $spacing . $_;
1815 $output_trailer .= $_;
1822 # Chop newline and backslash if this line is
1823 # continued. FIXME maybe ensure trailing whitespace
1827 $contents{$last_var_name} .= $_;
1830 elsif (/$RULE_PATTERN/o)
1832 # warn "** Saw rule .$1.\n";
1835 # Value here doesn't matter; for targets we only note
1838 $output_trailer .= $comment . $spacing . $_;
1839 $comment = $spacing = '';
1842 elsif (/$MACRO_PATTERN/o)
1844 # warn "** Saw macro .$1.\n";
1845 # Found a macro definition.
1847 $last_var_name = $1;
1848 if (substr ($2, -1) eq "\\")
1850 $contents{$1} = substr ($2, 0, length ($2) - 1);
1856 $output_vars .= $comment . $spacing . $_;
1857 $comment = $spacing = '';
1860 elsif ($_ eq "\@kr\@\n")
1862 # Special case: this means we want automatic
1863 # de-ANSI-fication. This is deprecated. Remove in the
1865 $contents{'@kr@'} = 1;
1866 &am_error ('`@kr@\' is deprecated; put `ansi2knr\' in AUTOMAKE_OPTIONS instead');
1870 # This isn't an error; it is probably a continued rule.
1871 # In fact, this is what we assume.
1873 $output_trailer .= $comment . $spacing . $_;
1874 $comment = $spacing = '';
1881 $output_trailer .= $comment;
1884 ################################################################
1886 sub initialize_global_constants
1888 # Associative array of standard directory names. Entry is TRUE if
1889 # corresponding directory should be installed during
1890 # 'install-exec' phase.
1908 # Helper text for dealing with man pages.
1909 $install_man_format =
1910 ' @sect=@SECTION@; \\
1911 inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
1912 echo installing @MAN@ as $(mandir)/man$$sect/$$inst; \\
1913 $(INSTALL_DATA) $(srcdir)/@MAN@ $(mandir)/man$$sect/$$inst
1916 $uninstall_man_format =
1917 ' inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
1918 rm -f $(mandir)/man@SECTION@/$$inst
1921 # Commonly found files we look for and automatically include in
1925 "README", "THANKS", "TODO", "NEWS", "COPYING", "COPYING.LIB",
1926 "INSTALL", "ABOUT-NLS", "ChangeLog", "configure", "configure.in",
1927 "config.guess", "config.sub", "AUTHORS", "BACKLOG", "ABOUT-GNU"
1930 # Commonly used files we auto-include, but only sometimes.
1933 "version.texi", "aclocal.m4", "acconfig.h", "config.h.top",
1934 "config.h.bot", "stamp-h.in", "mdate-sh", "ansi2knr.c",
1935 "ansi2knr.1", 'stamp-vti', "mkinstalldirs", "install-sh"
1939 --amdir=DIR directory storing config files
1940 --gnits same as --strictness=gnits
1941 --gnu same as --strictness=gnu
1942 --help print this help, then exit
1943 --include-deps include generated dependencies in Makefile.in
1944 --install-missing install missing standard files
1945 --output-dir=DIR put generated Makefile.in's into DIR
1946 --strictness=LEVEL set strictness level. LEVEL is normal, gnu, gnits
1947 --version print version number, then exit\n";
1949 # Copyright on generated Makefile.ins.
1951 # Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
1952 # This Makefile.in is free software; the Free Software Foundation
1953 # gives unlimited permission to copy, distribute and modify it.
1957 # (Re)-Initialize per-Makefile.am variables.
1958 sub initialize_per_input
1960 # These two variables are used when generating each Makefile.in.
1961 # They hold the Makefile.in until it is ready to be printed.
1964 $output_trailer = '';
1966 # Suffixes found during a run.
1969 # This holds the contents of a Makefile.am, as parsed by
1973 # This holds the "relative directory" of the current Makefile.in.
1974 # Eg for src/Makefile.in, this is "src".
1977 # Directory where output files go. Actually, output files are
1978 # relative to this directory.
1979 $output_directory = '.';
1981 # This holds a list of files that are included in the
1985 # List of dependencies for the obvious targets.
2000 # These are pretty obvious, too. They are used to define the
2001 # SOURCES and OBJECTS variables.
2005 # TRUE if current directory holds any C source files. (Actually
2006 # holds object extension, but this information is encapsulated in
2007 # the function get_object_extension).
2008 $dir_holds_sources = '';
2010 # TRUE if install targets should work recursively.
2011 $recursive_install = 0;
2016 # Strictness levels.
2017 $strictness = $default_strictness;
2018 $strictness_name = $default_strictness_name;
2020 # Options from AUTOMAKE_OPTIONS.
2023 # Whether or not dependencies are handled. Can be further changed
2024 # in handle_options.
2025 $use_dependencies = $cmdline_use_dependencies;
2028 $local_maint_charset = $maint_charset;
2032 ################################################################
2034 # Return contents of a file from $am_dir, automatically skipping
2035 # macros or rules which are already known. Runs command on each line
2036 # as it is read; this command can modify $_.
2037 sub file_contents_with_transform
2039 local ($command, $basename) = @_;
2040 local ($file) = $am_dir . '/' . $basename . '.am';
2042 open (FC_FILE, $file)
2043 || die "automake: installation error: cannot open \`$file'\n";
2045 local ($was_rule) = 0;
2046 local ($result_vars) = '';
2047 local ($result_rules) = '';
2048 local ($comment) = '';
2049 local ($spacing) = "\n";
2050 local ($skipping) = 0;
2056 if (/$IGNORE_PATTERN/o)
2058 # Merely delete comments beginning with two hashes.
2060 elsif (/$WHITE_PATTERN/o)
2062 # Stick a single white line before the incoming macro or rule.
2065 elsif (/$COMMENT_PATTERN/o)
2067 # Stick comments before the incoming macro or rule.
2068 $comment .= $spacing . $_;
2075 $result_rules .= $_ if ! $skipping;
2079 $result_vars .= $_ if ! $skipping;
2083 elsif (/$RULE_PATTERN/o)
2085 # warn "** Found rule .$1.\n";
2088 $skipping = defined $contents{$1};
2089 # warn "** Skip $skipping\n" if $skipping;
2090 $result_rules .= $comment . $spacing . $_ if ! $skipping;
2091 $comment = $spacing = '';
2094 elsif (/$MACRO_PATTERN/o)
2096 # warn "** Found macro .$1.\n";
2097 # Found a variable reference.
2099 $skipping = defined $contents{$1};
2100 # warn "** Skip $skipping\n" if $skipping;
2101 $result_vars .= $comment . $spacing . $_ if ! $skipping;
2102 $comment = $spacing = '';
2107 # This isn't an error; it is probably a continued rule.
2108 # In fact, this is what we assume.
2110 $result_rules .= $comment . $spacing . $_ if ! $skipping;
2111 $comment = $spacing = '';
2117 return $result_vars . $result_rules . $comment;
2120 # Like file_contents_with_transform, but no transform.
2123 return &file_contents_with_transform ('', @_);
2126 # Handle `where_HOW' variable magic. Does all lookups, generates
2127 # install code,and possibly generates code to define the primary
2128 # variable. The first argument is the name of the .am file to munge,
2129 # the second argument is the primary variable (eg HEADERS), and all
2130 # subsequent arguments are possible installation locations. Returns
2131 # list of all values of all _HOW targets.
2133 # FIXME this should be rewritten to be cleaner. It should be broken
2134 # up into multiple functions.
2136 # Usage is: am_install_var (OPTION..., file, HOW, where...)
2141 local ($do_all, $do_clean) = (1, 0);
2144 if ($args[0] eq '-clean')
2148 elsif ($args[0] eq '-no-all')
2152 elsif ($args[0] !~ /^-/)
2158 local ($file, $primary, @prefixes) = @args;
2161 local (@result) = ();
2163 local ($clean_file) = $file . '-clean';
2166 foreach $X (@prefixes)
2168 $one_name = $X . '_' . $primary;
2169 if (defined $contents{$one_name})
2171 # Append actual contents to result.
2172 push (@result, split (/\s+/, $contents{$one_name}));
2177 &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go',
2180 push (@clean, $X . $primary);
2181 &push_phony_cleaners ($X . $primary);
2184 push (@used, '$(' . $one_name . ')');
2187 # Objects in noinst_FOO never get installed.
2192 &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go',
2195 push (@uninstall, 'uninstall-' . $X . $primary);
2196 push (@phony, 'uninstall-' . $X . $primary);
2197 push (@installdirs, '$(' . $X . 'dir)');
2198 if ($exec_dir_p{$X})
2200 push (@install_exec, 'install-' . $X . $primary);
2204 push (@install_data, 'install-' . $X . $primary);
2209 if (! defined $contents{$primary} && @used)
2212 &pretty_print ($primary . ' =', '', @used);
2213 $output_vars .= "\n";
2216 # Push here because PRIMARY might be configure time determined.
2217 push (@all, '$(' . $primary . ')') if ($do_all && @used);
2219 # Look for misspellings. It is an error to have a variable ending
2220 # in a "reserved" suffix whose prefix is unknown, eg
2222 local (%valid, $varname);
2223 grep ($valid{$_} = 0, @prefixes);
2224 foreach $varname (keys %contents)
2226 if ($varname =~ /^(.*)_$primary$/ && ! defined $valid{$1})
2228 &am_error ("invalid variable \"$varname\"");
2236 ################################################################
2238 # Verify that the file must exist in the current directory.
2239 # Usage: require_file (strictness, file)
2240 # strictness is the strictness level at which this file becomes
2244 local ($mystrict, @files) = @_;
2245 local ($file, $fullfile);
2247 foreach $file (@files)
2249 $fullfile = $relative_dir . "/" . $file;
2253 &push_dist_common ($file);
2255 elsif ($strictness >= $mystrict)
2257 # Only install missing files according to our desired
2259 if ($install_missing && -f ($am_dir . '/' . $file))
2261 # Install the missing file. Symlink if we can, copy
2263 if ($symlink_exists)
2265 symlink ($am_dir . '/' . $file, $fullfile);
2269 system ('cp', $am_dir . '/' . $file, $fullfile);
2272 ("required file \"$fullfile\" not found; installing");
2276 # Only an error if strictness constraint violated.
2277 &am_error ("required file \"$fullfile\" not found");
2283 # Push a list of files onto dist_common.
2284 sub push_dist_common
2286 local (@files) = @_;
2289 foreach $file (@files)
2291 $dist_common{$file} = 1;
2295 # Push a list of clean targets onto phony.
2296 sub push_phony_cleaners
2300 foreach $target ('mostly', 'dist', '', 'maintainer-')
2302 push (@phony, $target . 'clean-' . $base);
2309 $strictness_name = $_[0];
2310 if ($strictness_name eq 'gnu')
2314 elsif ($strictness_name eq 'gnits')
2316 $strictness = $GNITS;
2318 elsif ($strictness_name eq 'normal')
2320 $strictness = $NORMAL;
2324 die "automake: level \`$strictness_name' not recognized\n";
2329 ################################################################
2331 # Return directory name of file.
2337 ($sub = $file) =~ s,/+[^/]+$,,g;
2338 $sub = '.' if $sub eq $file;
2345 local ($dirname) = @_;
2346 system ("mkdir", $dirname);
2349 ################################################################
2351 # Print an error message and set exit status.
2354 warn "automake: ${am_file}.am: ", join (' ', @_), "\n";
2358 # The same, but while scanning configure.in.
2361 # FIXME can run in subdirs.
2362 warn "automake: configure.in: ", join (' ', @_), "\n";
2366 # Print usage information.
2369 print "Usage: automake [OPTION] ... [Makefile]...\n";
2371 print "\nFiles which are automatically distributed, if found:\n";
2372 $~ = "USAGE_FORMAT";
2373 local (@lcomm) = sort ((@common_files, @common_sometimes));
2374 local ($one, $two, $three, $four);
2377 $one = shift @lcomm;
2378 $two = @lcomm ? shift @lcomm : '';
2379 $three = @lcomm ? shift @lcomm : '';
2380 $four = @lcomm ? shift @lcomm : '';
2387 format USAGE_FORMAT =
2388 @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<
2389 $one, $two, $three, $four