5 eval "exec /usr/local/bin/perl -S $0 $*"
6 if $running_under_some_shell;
8 # automake - create Makefile.in from Makefile.am
9 # Copyright (C) 1994 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.
31 $VERSION = "@VERSION@";
33 $am_dir = "@datadir@/@PACKAGE@";
37 # This is TRUE if GNU make specific automatic dependency generation
38 # code should be included in generated Makefile.in.
39 $use_dependencies = 1;
41 # This holds our (eventual) exit status. We don't actually exit until
42 # we have processed all input files.
45 # These two variables are used when generating each Makefile.in. They
46 # hold the Makefile.in until it is ready to be printed.
51 # Suffixes found during a run.
54 # This holds the contents of a Makefile.am, as parsed by read_am_file.
57 # This holds the "relative directory" of the current Makefile.in. Eg
58 # for src/Makefile.in, this is "src".
61 # Directory where output files go. Actually, output files are
62 # relative to this directory.
63 $output_directory = '.';
65 # This holds a list of files that are included in the distribution.
68 # List of dependencies for the obvious targets.
81 # TRUE if current directory holds any C source files.
82 $dir_holds_sources = 0;
84 # TRUE if install targets should work recursively.
85 $recursive_install = 0;
92 @input_files = &parse_arguments (@ARGV);
94 # Now do all the work on each file.
95 foreach $am_file (@input_files)
97 if (! -f ($am_file . '.am'))
99 print STDERR "automake: $am_file" . ".am: no such file\n";
104 &generate_makefile ($am_file);
111 ################################################################
113 # Parse command line.
116 local (@arglist) = @_;
119 while ($#arglist >= 0)
121 if ($arglist[0] eq "--version")
123 print "Automake version $VERSION\n";
126 elsif ($arglist[0] eq "--help")
130 elsif ($arglist[0] =~ /^--amdir=(.+)$/)
134 elsif ($arglist[0] eq '--amdir')
139 "automake: no argument given for option \`$arglist[0]'\n";
143 $am_dir = $arglist[0];
145 elsif ($arglist[0] eq '--include-deps')
147 $use_dependencies = 0;
149 elsif ($arglist[0] =~ /^--output-dir=(.*)$/)
151 # Set output directory.
152 $output_directory = $1;
154 elsif ($arglist[0] eq '--output-dir')
159 "automake: no argument given for option \`$arglist[0]'\n";
163 $output_directory = $arglist[0];
165 elsif ($arglist[0] eq '--')
167 # Stop option processing.
169 push (@make_list, @arglist);
172 elsif ($arglist[0] =~ /^-/)
174 print STDERR "automake: unrecognized option -- \`$arglist[0]'\n";
179 push (@make_list, $arglist[0]);
187 # Look around for some files.
188 push (@make_list, 'Makefile') if -f 'Makefile.am';
190 foreach (<*/Makefile.am>)
193 push (@make_list, $_);
196 if ($#make_list >= 0)
198 print "automake: using ", join (' ', @make_list), "\n";
202 print STDERR "automake: no \"Makefile.am\" found or specified\n";
210 ################################################################
212 # Generate a Makefile.in given the name of the corresponding Makefile.
213 sub generate_makefile
215 local ($makefile) = @_;
217 print "creating ", $makefile, ".in\n";
219 $relative_dir = &dirname ($makefile);
222 $output_trailer = '';
225 # FIXME with new 'dist' target, don't need Makefile.in. Probably
226 # should remove it here.
227 @dist_common = ('Makefile.in', 'Makefile.am');
232 $dir_holds_sources = 0;
233 $recursive_install = 0;
241 # Generate header before reading .am file. The header must come
242 # before anything else, and read_am_file copies code into the
246 # This is always the default target. This gives us freedom to do
247 # things in whatever order is convenient.
248 $output_rules .= "default: all\n\n";
250 &read_am_file ($makefile . '.am');
253 local ($programs) = &am_variable ('PROGRAMS');
254 local ($libprograms) = &am_variable ('LIBPROGRAMS');
255 local ($libraries) = &am_variable ('LIBRARIES');
256 local ($scripts) = &am_variable ('SCRIPTS');
257 local ($libscripts) = &am_variable ('LIBSCRIPTS');
259 &handle_programs ($programs, $libprograms, $libraries);
260 &handle_scripts ($scripts, $libscripts);
261 &handle_libraries ($libraries);
270 &handle_dependencies;
272 &handle_merge_targets;
276 if (! -d ($output_directory . '/' . $relative_dir))
278 &mkdir ($output_directory . '/' . $relative_dir);
280 if (! open (GM_FILE, "> " . $output_directory . '/' . $makefile . ".in"))
282 print STDERR "automake: cannot open ", $makefile, ".in: ", $!, "\n";
287 print GM_FILE $output_vars;
288 print GM_FILE $output_rules;
289 print GM_FILE $output_trailer;
294 ################################################################
296 # Generate header of Makefile.in.
301 . "# Makefile.in generated automatically by automake "
303 . " from Makefile.am\n");
305 $output_vars = $output_vars . &file_contents ('header-vars');
308 # Handle C programs and libraries.
311 local ($programs, $libprograms, $libraries) = @_;
313 if (!$programs && !$libprograms && !$libraries)
318 $dir_holds_sources = 1;
321 $output_vars .= &file_contents ('compile-vars');
322 $output_rules .= &file_contents ('compile');
324 # Check for automatic de-ANSI-fication.
326 push (@suffixes, '.c', '.o');
327 push (@clean, 'compile');
329 if (defined $contents{'@kr@'})
332 push (@suffixes, '._c', '._o');
334 &require_file ('ansi2knr.c');
335 &require_file ('ansi2knr.1');
337 $output_vars .= &file_contents ('kr-vars');
338 $output_rules .= &file_contents ('compile-kr');
339 $output_rules .= &file_contents ('clean-kr');
344 local (@sources, @objects);
345 push (@sources, '${SOURCES}') if (defined $contents{'SOURCES'});
346 push (@objects, '${OBJECTS}') if (defined $contents{'OBJECTS'});
349 foreach $one_file (split (' ', ($programs . ' '
353 # Look for file_SOURCES and file_OBJECTS. FIXME file_OBJECTS
354 # should probably not be used(?)
355 if (defined $contents{$one_file . "_SOURCES"})
357 if (! defined $contents{$one_file . "_OBJECTS"})
359 # Turn sources into objects.
360 $_ = $contents{$one_file . "_SOURCES"};
362 # Ugh: Perl syntax vs Emacs.
363 local ($krc1, $krc2) = ('\.\$\{kr\}c', '\.\$\(kr\)c');
368 s/\.[cCmylfs]/$obj/g;
370 $output_vars .= $one_file . "_OBJECTS = " . $_ . "\n";
373 push (@sources, '${' . $one_file . "_SOURCES}");
374 push (@objects, '${' . $one_file . "_OBJECTS}");
378 $output_vars .= ($one_file . "_SOURCES = " . $one_file . ".c\n"
379 . $one_file . "_OBJECTS = ". $one_file
381 push (@sources, $one_file . '.c');
382 push (@objects, $one_file . $obj);
385 if (defined $contents{'CONFIG_HEADER'})
387 $output_rules .= ('$(' . $one_file . "_OBJECTS): "
388 . $contents{'CONFIG_HEADER'} . "\n");
392 $output_vars .= "\n";
394 # Re-init SOURCES and OBJECTS. FIXME other code shouldn't depend
396 $contents{'SOURCES'} = join (' ', @sources);
397 $contents{'OBJECTS'} = join (' ', @objects);
399 # Some boilerplate, and install rules.
402 $output_rules .= &file_contents ('programs');
403 push (@install_exec, "install-programs");
404 push (@uninstall, 'uninstall-programs');
405 push (@clean, 'programs');
406 push (@installdirs, '$(bindir)');
407 push (@all, '$(PROGRAMS)');
411 $output_rules .= &file_contents ('libprograms');
412 push (@install_exec, 'install-libprograms');
413 push (@uninstall, 'uninstall-libprograms');
414 push (@clean, 'libprograms');
415 push (@installdirs, '$(libexecdir)');
416 push (@all, '$(LIBPROGRAMS)');
420 if ($programs || $libprograms)
422 local ($fcont) = &file_contents ('program');
424 foreach $one_file (split (' ', $programs . ' ' . $libprograms))
426 if (! defined $contents{$one_file . "_LDADD"})
428 # User didn't define prog_LDADD override. So do it.
429 $output_vars .= $one_file . '_LDADD = ${LDADD}' . "\n";
432 ($munge = $fcont) =~ s/\@PROGRAM\@/$one_file/g;
433 $output_rules .= $munge;
441 local ($libraries) = @_;
443 return if (!$libraries);
445 local (@liblist) = split (' ', $libraries);
447 $output_rules .= &file_contents ('libraries');
448 local ($onefile) = &file_contents ('library');
449 local ($onelib, $munge);
450 foreach $onelib (@liblist)
452 if (! defined $contents{$onelib . '_LIBADD'})
454 # Generate support for conditional objection inclusion in
456 $output_vars .= $onelib . "_LIBADD =\n";
459 ($munge = $onefile) =~ s/\@LIBRARY\@/$onelib/g;
460 $output_rules .= $munge;
463 # Turn "foo" into "libfoo.a" and include macro definition.
464 grep (($_ = 'lib' . $_ . '.a') && 0, @liblist);
465 $output_vars .= ("LIBFILES = " . join (' ', @liblist) . "\n\n"
466 . &file_contents ('libraries-vars'));
468 push (@install_exec, 'install-libraries');
469 push (@uninstall, 'uninstall-libraries');
470 push (@clean, 'libraries');
471 push (@all, '$(LIBFILES)');
477 local ($scripts, $libscripts) = @_;
481 $output_rules .= &file_contents ('scripts');
482 push (@install_exec, 'install-scripts');
483 push (@uninstall, 'uninstall-scripts');
484 push (@clean, 'scripts');
485 push (@installdirs, '$(bindir)');
486 push (@all, '$(SCRIPTS)');
491 $output_rules .= &file_contents ('libscripts');
492 push (@install_exec, 'install-libscripts');
493 push (@uninstall, 'uninstall-libscripts');
494 push (@clean, 'libscripts');
495 push (@installdirs, '$(libexecdir');
496 push (@all, '$(LIBSCRIPTS)');
500 # Handle all Texinfo source.
503 local ($texis) = &am_variable ('TEXINFOS');
506 local (@texis) = split (' ', $texis);
509 print STDERR "automake: sorry, only one file allowed in \`TEXINFOS'\n";
515 ($infobase = $texis[0]) =~ s/\.texi$//;
517 # If 'version.texi' is referenced by input file, then include
518 # automatic versioning capability.
519 system ("grep version.texi " . $relative_dir . "/" . $texis[0]
520 . " > /dev/null 2>&1");
524 push (@texis, 'version.texi');
525 push (@dist_common, 'version.texi', 'stamp-vti');
526 push (@clean, 'vti');
529 ($tfile = &file_contents ('texi-version')) =~ s/\@TEXI\@/$texis[0]/g;
530 $output_rules = $output_rules . $tfile;
532 &require_file ('mdate-sh');
535 # If user specified file_TEXINFOS, then use that as explicit
537 if (defined $contents{$infobase . "_TEXINFOS"})
539 push (@texis, "\$" . $infobase . '_TEXINFOS');
540 push (@dist_common, "\$" . $infobase . '_TEXINFOS');
545 $output_rules = ($output_rules . $infobase . ".info: "
546 . join (' ', @texis) . "\n\n");
550 $output_vars = $output_vars . &file_contents ('texinfos-vars');
551 $output_rules = $output_rules . &file_contents ('texinfos');
553 push (@suffixes, '.texi', '.info', '.dvi');
554 push (@uninstall, 'uninstall-info');
555 push (@clean, 'info');
556 push (@info, '$(INFO_DEPS)');
557 push (@dvi, '$(DVIS)');
558 push (@installdirs, '$(infodir)');
559 # Make sure documentation is made and installed first.
560 unshift (@install_data, 'install-info');
561 unshift (@all, 'info');
563 $output_vars .= ("INFOS = " . $infobase . ".info*\n"
564 . "INFO_DEPS = " . $infobase . ".info\n"
565 . "DVIS = " . $infobase . ".dvi\n\n");
567 # Do some error checking.
568 &require_file ('texinfo.tex');
571 # Handle any man pages.
574 return if (! defined $contents{'MANS'});
576 # We generate the manpage install code by hand to avoid the use of
577 # basename in the generated Makefile.
578 local (@mans) = split (' ', $contents{'MANS'});
579 local (%sections, %inames, %secmap, %fullsecmap);
582 m/^(.*)\.([0-9])([a-z]*)$/;
586 $fullsecmap{$1} = $2 . $3;
589 # Generate list of install dirs.
590 $output_rules .= "install-man:\n";
591 foreach (keys %sections)
593 push (@installdirs, '$(mandir)/man' . $_);
594 $output_rules .= ("\t" . '$(top_srcdir)/mkinstalldirs $(mandir)/man'
598 # Generate install target.
600 foreach $key (keys %inames)
602 $_ = $install_man_format;
603 s/\@SECTION\@/$secmap{$key}/g;
604 s/\@MAN\@/$inames{$key}/g;
605 s/\@FULLSECT\@/$fullsecmap{$key}/g;
606 s/\@MANBASE\@/$key/g;
609 $output_rules .= "\n";
611 $output_rules .= "uninstall-man:\n";
612 foreach $key (keys %inames)
614 $_ = $uninstall_man_format;
615 s/\@SECTION\@/$secmap{$key}/g;
616 s/\@MAN\@/$inames{$key}/g;
617 s/\@FULLSECT\@/$fullsecmap{$key}/g;
618 s/\@MANBASE\@/$key/g;
621 $output_rules .= "\n";
623 $output_vars .= &file_contents ('mans-vars');
625 push (@install_data, 'install-man');
626 push (@uninstall, 'uninstall-man');
627 push (@all, '$(MANS)');
630 # Handle DATA and PACKAGEDATA.
633 if (defined $contents{'DATA'})
635 $output_rules .= &file_contents ('data');
636 push (@install_data, 'install-ddata');
637 push (@uninstall, 'uninstall-ddata');
638 push (@installdirs, '$(datadir)');
641 if (defined $contents{'PACKAGEDATA'})
643 $output_rules .= &file_contents ('packagedata');
644 push (@install_data, 'install-pdata');
645 push (@uninstall, 'uninstall-pdata');
646 push (@installdirs, '$(datadir)/$(PACKAGE)');
653 local ($tagging) = 0;
655 if (defined ($contents{'SUBDIRS'}))
657 $output_rules .= &file_contents ('tags');
660 elsif ($dir_holds_sources || defined ($contents{'ETAGS_ARGS'}))
662 $output_rules .= &file_contents ('tags-subd');
668 $output_rules .= &file_contents ('tags-clean');
669 push (@clean, 'tags');
673 # Every Makefile must define some sort of TAGS rule.
674 # Otherwise, it would be possible for a top-level "make TAGS"
675 # to fail because some subdirectory failed.
676 $output_rules .= "tags: TAGS\nTAGS:\n\n";
680 # Handle 'dist' target.
683 # Look for common files that should be included in distribution.
685 foreach $cfile (@common_files)
687 if (-f ($relative_dir . "/" . $cfile))
689 push (@dist_common, $cfile);
693 $output_vars .= "DIST_COMMON = " . join (' ', @dist_common) . "\n\n";
696 $output_vars .= &file_contents ('dist-vars');
697 if ($relative_dir ne '.')
700 $output_vars .= "subdir = " . $relative_dir . "\n\n";
701 $output_rules .= &file_contents ('dist-subd');
705 $output_rules .= &file_contents (defined ($contents{'SUBDIRS'})
711 # Handle auto-dependency code.
712 sub handle_dependencies
714 if ($use_dependencies)
716 # Include GNU-make-specific auto-dep code.
717 if ($dir_holds_sources)
719 $output_rules .= &file_contents ('depend');
724 # Include any auto-generated deps that are present.
725 if (-d ($relative_dir . "/.deps") && -f ($relative_dir . "/.deps/.P"))
728 local ($gpat) = $relative_dir . "/.deps/*.P";
730 foreach $depfile (<${gpat}>)
732 if (! open (DEP_FILE, $depfile))
734 print STDERR "automake: couldn't open $depfile: $!\n";
739 $output_rules .= join ('', <DEP_FILE>);
744 $output_rules .= "\n";
749 # Handle subdirectories.
752 return if (! defined ($contents{'SUBDIRS'}));
754 $output_rules .= &file_contents ('subdirs');
756 push (@all, "all-recursive");
757 push (@check, "check-recursive");
758 push (@installcheck, "installcheck-recursive");
759 push (@info, "info-recursive");
760 push (@dvi, "dvi-recursive");
762 $recursive_install = 1;
765 # Handle remaking and configure stuff.
768 if ($relative_dir ne '.')
771 $output_rules .= &file_contents ('remake-subd');
777 $output_vars .= "ACLOCAL = aclocal.m4\n";
778 push (@dist_common, 'aclocal.m4');
780 $output_rules .= &file_contents ('remake');
782 # Look for some files we need.
783 &require_file ('install-sh');
784 &require_file ('mkinstalldirs');
787 if (defined ($contents{'CONFIG_HEADER'})
788 && $contents{'CONFIG_HEADER'} !~ m,/,)
790 # Header defined and in this directory.
793 $output_vars .= "ACCONFIG = acconfig.h\n";
794 push (@dist_common, 'acconfig.h');
796 if (-f 'config.h.top')
798 $output_vars .= "CONFIG_TOP = config.h.top\n";
799 push (@dist_common, 'config.h.top');
801 if (-f 'config.h.bot')
803 $output_vars .= "CONFIG_BOT = config.h.bot\n";
804 push (@dist_common, 'config.h.bot');
807 push (@dist_common, 'stamp-h.in', $contents{'CONFIG_HEADER'} . '.in');
809 $output_rules .= &file_contents ('remake-hdr');
813 # Handle footer elements.
816 if ($contents{'SOURCES'})
818 $output_vars .= "SOURCES = " . $contents{'SOURCES'} . "\n";
820 if ($contents{'OBJECTS'})
822 $output_vars .= "OBJECTS = " . $contents{'OBJECTS'} . "\n";
824 if ($contents{'SOURCES'} || $contents{'OBJECTS'})
826 $output_vars .= "\n";
829 if (defined $contents{'SUFFIXES'})
831 push (@suffixes, '$(SUFFIXES)');
834 $output_trailer .= ".SUFFIXES:\n";
837 $output_trailer .= ".SUFFIXES: " . join (' ', @suffixes) . "\n";
839 $output_trailer .= "\n" . &file_contents ('footer');
842 # Deal with installdirs target.
843 sub handle_installdirs
845 # GNU Makefile standards recommend this. FIXME prettyprint rule
847 $output_rules .= ("installdirs:"
848 . ($recursive_install
849 ? " installdirs-recursive\n"
851 if ($#installdirs >= 0)
853 $output_rules .= ("\t\$(top_srcdir)/mkinstalldirs "
854 . join (' ', @installdirs)
857 $output_rules .= "\n";
860 # There are several targets which need to be merged. This is because
861 # their complete definition is compiled from many parts. Note that we
862 # avoid double colon rules, otherwise we'd use them instead.
863 sub handle_merge_targets
865 &do_one_merge_target ('all', @all);
866 &do_one_merge_target ('info', @info);
867 &do_one_merge_target ('dvi', @dvi);
868 &do_one_merge_target ('check', @check);
869 &do_one_merge_target ('installcheck', @installcheck);
871 # Handle the various install targets specially. We do this so
872 # that (eg) "make install-exec" will run "install-exec-recursive"
873 # if required, but "make install" won't run it twice. Step one is
874 # to see if the user specified local versions of any of the
876 if (defined $contents{'install-exec-local'})
878 push (@install_exec, 'install-exec-local');
880 if (defined $contents{'install-data-local'})
882 push (@install_data, 'install-data-local');
884 if (defined $contents{'uninstall-local'})
886 push (@uninstall, 'uninstall-local');
889 if (defined $contents{'install-local'})
891 print STDERR "automake: use \`install-data' or \`install-exec', not \`install'\n";
894 # Step two: if we are doing recursive makes, write out the
897 if ($recursive_install)
899 push (@install, 'install-recursive');
900 push (@uninstall, 'uninstall-recursive');
902 if ($#install_exec >= 0)
904 $output_rules .= ('install-exec-am: '
905 . join (' ', @install_exec)
907 @install_exec = ('install-exec-recursive', 'install-exec-am');
908 push (@install, 'install-exec-am');
910 if ($#install_data >= 0)
912 $output_rules .= ('install-data-am: '
913 . join (' ', @install_data)
915 @install_data = ('install-data-recursive', 'install-data-am');
916 push (@install, 'install-data-am');
918 if ($#uninstall >= 0)
920 $output_rules .= ('uninstall-am: '
921 . join (' ', @uninstall)
923 @uninstall = ('uninstall-recursive', 'uninstall-am');
927 # Step three: print definitions users can use.
928 if ($#install_exec >= 0)
930 $output_rules .= ("install-exec: "
931 . join (' ', @install_exec)
933 push (@install, 'install-exec') if (!$recursive_install);
935 if ($#install_data >= 0)
937 $output_rules .= ("install-data: "
938 . join (' ', @install_data)
940 push (@install, 'install-data') if (!$recursive_install);
943 $output_rules .= ('install: '
944 . join (' ', @install)
947 . join (' ', @uninstall)
951 # Helper for handle_merge_targets.
952 sub do_one_merge_target
954 local ($name, @values) = @_;
956 if (defined $contents{$name . '-local'})
958 # User defined local form of target. So include it.
959 push (@values, $name . '-local');
962 $output_rules .= $name . ": " . join (' ', @values) . "\n\n";
965 # Handle all 'clean' targets.
968 push (@clean, 'generic');
969 $output_rules .= &file_contents ('clean');
971 local ($target) = $recursive_install ? 'clean-am' : 'clean';
972 &do_one_clean_target ($target, 'mostly', '', @clean);
973 &do_one_clean_target ($target, '', 'mostly', @clean);
974 &do_one_clean_target ($target, 'dist', '', @clean);
975 &do_one_clean_target ($target, 'maintainer-', 'dist', @clean);
978 if ($recursive_install)
980 @deps = ('am', 'recursive');
981 &do_one_clean_target ('', 'mostly', '', @deps);
982 &do_one_clean_target ('', '', '', @deps);
983 &do_one_clean_target ('', 'dist', '', @deps);
984 &do_one_clean_target ('', 'maintainer-', '', @deps);
988 # Helper for handle_clean.
989 sub do_one_clean_target
991 local ($target, $name, $last_name, @deps) = @_;
993 # Special case: if target not passed, then don't generate
994 # dependency on next "lower" clean target (eg no
995 # clean<-mostlyclean derivation). In this case the target is
996 # implicitly known to be 'clean'.
997 local ($flag) = $target;
1003 $output_rules .= $name . $target . ": ";
1006 if ($last_name || $name ne 'mostly')
1008 $output_rules .= $last_name . $target . " ";
1012 $output_rules .= ($name . 'clean-' . join (' ' . $name . 'clean-', @deps)
1015 # FIXME shouldn't we really print these messages before running
1017 if ($name . $target eq 'maintainer-clean')
1019 # Print a special warning.
1021 ("\t\@echo \"This command is intended for maintainers to use;\"\n"
1022 . "\t\@echo \"it deletes files that may require special "
1023 . "tools to rebuild.\"\n");
1025 $output_rules .= "\n";
1028 ################################################################
1030 # Read Makefile.am and set up %contents. Simultaneously copy lines
1031 # from Makefile.am into $output_trailer or $output_vars as
1032 # appropriate. NOTE we put rules in the trailer section. We want
1033 # user rules to come after our generated stuff.
1036 local ($amfile) = @_;
1038 if (! open (AMFILE, $amfile))
1040 print STDERR "automake: couldn't open $amfile: $!\n";
1044 local ($saw_bk) = 0;
1045 local ($was_rule) = 0;
1046 local ($last_var_name) = '';
1056 $output_trailer .= $_ . "\n";
1060 $output_vars .= $_ . "\n";
1061 if (substr ($_, -1) eq "\\")
1063 $contents{$last_var_name} .= substr ($_, 0,
1068 $contents{$last_var_name} .= $_;
1072 elsif ($_ eq '@kr@')
1074 # Special case: this means we want automatic
1075 # de-ANSI-fication. FIXME think of a better way.
1076 $contents{'@kr@'} = 1;
1078 elsif (m/^ *([a-zA-Z_.][a-zA-Z0-9_.]*) *:/)
1082 # Value here doesn't matter; for targets we only note
1085 $output_trailer .= $_ . "\n";
1087 elsif (m/^ *([A-Za-z][A-Za-z0-9_]*)[ ]*=[ ]*(.*)$/)
1089 # Found a variable reference.
1091 $last_var_name = $1;
1092 if (substr ($2, -1) eq "\\")
1094 $contents{$1} = substr ($2, 0, length ($2) - 1);
1100 $output_vars .= $_ . "\n";
1104 # Special rule: if looking at a blank line, append it to
1105 # whatever we saw last.
1108 $output_trailer .= "\n";
1112 $output_vars .= "\n";
1117 # This isn't an error; it is probably a continued rule.
1118 # In fact, this is what we assume.
1119 $output_trailer .= $_ . "\n";
1122 $saw_bk = (substr ($_, -1) eq "\\");
1125 # Include some space after user code.
1126 $output_vars .= "\n";
1127 $output_trailer .= "\n";
1130 ################################################################
1132 # Initialize global variables.
1135 # Helper text for dealing with man pages.
1136 $install_man_format =
1137 ' sect=@SECTION@; \\
1138 inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
1139 echo installing @MAN@ as $(mandir)/man$$sect/$$inst; \\
1140 $(INSTALL_DATA) $(srcdir)/@MAN@ $(mandir)/man$$sect/$$inst; \\
1141 if test -d $(mandir)/cat$$sect; then \\
1142 echo formatting @MAN@ as $(mandir)/cat$$sect/$$inst; \\
1143 $(NROFF) -man $(srcdir)/@MAN@ > $(mandir)/cat$$sect/$$inst; \\
1149 $uninstall_man_format =
1150 ' inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
1151 rm -f $(mandir)/man@SECTION@/$$inst $(mandir)/cat@SECTION@/$$inst
1154 # Commonly found files we look for and automatically include in
1158 "THANKS", "TODO", "README", "NEWS", "COPYING", "COPYING.LIB",
1159 "INSTALL", "ABOUT-NLS", "ChangeLog", "configure", "configure.in",
1160 "config.guess", "config.sub"
1163 # Commonly used files we auto-include, but only sometimes.
1166 "version.texi", "aclocal.m4", "acconfig.h", "config.h.top",
1167 "config.h.bot", "stamp-h.in", "mdate-sh", "ansi2knr.c",
1168 "ansi2knr.1", 'stamp-vti', "mkinstalldirs", "install-sh"
1172 --amdir=DIR directory storing config files
1173 --help print this help, then exit
1174 --include-deps include generated dependencies in Makefile.in
1175 --output-dir=DIR put generated Makefile.in's into DIR
1176 --version print version number, then exit\n";
1180 ################################################################
1182 # Return contents of a file from $am_dir.
1185 local ($basename) = @_;
1186 local ($file) = $am_dir . '/' . $basename . '.am';
1188 if (! open (FC_FILE, $file))
1190 print STDERR "automake: installation error: cannot open \"$file\"\n";
1194 # Lines starting with "##" are comments for developer use only.
1195 # Maybe this is a bad idea?
1196 local ($result) = '';
1199 $result .= $_ unless ( m/^##/);
1205 # Return contents of some Makefile.am variable. Allow for AM_ style
1209 local ($varname) = @_;
1211 return (defined ($contents{'AM_' . $varname})
1212 ? $contents{'AM_' . $varname}
1213 : $contents{$varname});
1216 ################################################################
1218 # Verify that the file must exist in the current directory.
1222 local ($fullfile) = $relative_dir . "/" . $file;
1226 print STDERR "automake: required file \"$fullfile\" not found\n";
1231 push (@dist_common, $file);
1236 ################################################################
1238 # Return directory name of file.
1244 ($sub = $file) =~ s,/+[^/]+,,g;
1256 local ($dirname) = @_;
1257 system ("mkdir", $dirname);
1260 ################################################################
1262 # Print usage information.
1265 print "Usage: automake [OPTION] ... [Makefile]...\n";
1267 print "\nFiles which are automatically distributed, if found:\n";
1268 $~ = "USAGE_FORMAT";
1269 local (@lcomm) = sort ((@common_files, @common_sometimes));
1271 while ($#lcomm >= 0)
1273 $one = shift (@lcomm);
1274 $two = shift (@lcomm);
1281 format USAGE_FORMAT =
1282 @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<