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. (Actually holds
82 # object extension, but this information is encapsulated in the
83 # function get_object_extension).
84 $dir_holds_sources = '';
86 # TRUE if install targets should work recursively.
87 $recursive_install = 0;
94 @input_files = &parse_arguments (@ARGV);
96 # Now do all the work on each file.
97 foreach $am_file (@input_files)
99 if (! -f ($am_file . '.am'))
101 &am_error ('no such file');
105 &generate_makefile ($am_file);
112 ################################################################
114 # Parse command line.
117 local (@arglist) = @_;
120 while ($#arglist >= 0)
122 if ($arglist[0] eq "--version")
124 print "Automake version $VERSION\n";
127 elsif ($arglist[0] eq "--help")
131 elsif ($arglist[0] =~ /^--amdir=(.+)$/)
135 elsif ($arglist[0] eq '--amdir')
140 "automake: no argument given for option \`$arglist[0]'\n";
144 $am_dir = $arglist[0];
146 elsif ($arglist[0] eq '--include-deps')
148 $use_dependencies = 0;
150 elsif ($arglist[0] =~ /^--output-dir=(.*)$/)
152 # Set output directory.
153 $output_directory = $1;
155 elsif ($arglist[0] eq '--output-dir')
160 "automake: no argument given for option \`$arglist[0]'\n";
164 $output_directory = $arglist[0];
166 elsif ($arglist[0] eq '--')
168 # Stop option processing.
170 push (@make_list, @arglist);
173 elsif ($arglist[0] =~ /^-/)
175 print STDERR "automake: unrecognized option -- \`$arglist[0]'\n";
180 push (@make_list, $arglist[0]);
188 # Look around for some files.
189 push (@make_list, 'Makefile') if -f 'Makefile.am';
191 foreach (<*/Makefile.am>)
194 push (@make_list, $_);
197 if ($#make_list >= 0)
199 print "automake: using ", join (' ', @make_list), "\n";
203 print STDERR "automake: no \"Makefile.am\" found or specified\n";
211 ################################################################
213 # Generate a Makefile.in given the name of the corresponding Makefile.
214 sub generate_makefile
216 local ($makefile) = @_;
218 print "creating ", $makefile, ".in\n";
220 $relative_dir = &dirname ($makefile);
223 $output_trailer = '';
226 # FIXME with new 'dist' target, don't need Makefile.in. Probably
227 # should remove it here.
228 @dist_common = ('Makefile.in', 'Makefile.am');
233 $dir_holds_sources = '';
234 $recursive_install = 0;
242 # Generate header before reading .am file. The header must come
243 # before anything else, and read_am_file copies code into the
247 # This is always the default target. This gives us freedom to do
248 # things in whatever order is convenient.
249 $output_rules .= "default: all\n\n";
251 &read_am_file ($makefile . '.am');
254 local ($programs) = &am_variable ('PROGRAMS');
255 local ($libprograms) = &am_variable ('LIBPROGRAMS');
256 local ($libraries) = &am_variable ('LIBRARIES');
257 local ($scripts) = &am_variable ('SCRIPTS');
258 local ($libscripts) = &am_variable ('LIBSCRIPTS');
260 &handle_programs ($programs, $libprograms, $libraries);
261 &handle_scripts ($scripts, $libscripts);
262 &handle_libraries ($libraries);
272 &handle_dependencies;
274 &handle_merge_targets;
278 if (! -d ($output_directory . '/' . $relative_dir))
280 &mkdir ($output_directory . '/' . $relative_dir);
282 if (! open (GM_FILE, "> " . $output_directory . '/' . $makefile . ".in"))
284 &am_error ("cannot open:", $!);
288 print GM_FILE $output_vars;
289 print GM_FILE $output_rules;
290 print GM_FILE $output_trailer;
295 ################################################################
297 # Generate header of Makefile.in.
302 . "# Makefile.in generated automatically by automake "
304 . " from Makefile.am\n");
306 $output_vars = $output_vars . &file_contents ('header-vars');
309 # Return object extension. Just once, put some code into the output.
310 sub get_object_extension
312 if (! $dir_holds_sources)
316 $output_vars .= &file_contents ('compile-vars');
317 $output_rules .= &file_contents ('compile');
319 # Check for automatic de-ANSI-fication.
320 $dir_holds_sources = '.o';
321 push (@suffixes, '.c', '.o');
322 push (@clean, 'compile');
324 if (defined $contents{'@kr@'})
326 $dir_holds_sources = '.${kr}o';
327 push (@suffixes, '._c', '._o');
329 &require_file ('ansi2knr.c');
330 &require_file ('ansi2knr.1');
332 $output_vars .= &file_contents ('kr-vars');
333 $output_rules .= &file_contents ('compile-kr');
334 $output_rules .= &file_contents ('clean-kr');
339 return $dir_holds_sources;
342 # Handle SOURCE->OBJECT transform for one program or library.
343 sub handle_source_transform
345 local ($one_file, $obj) = @_;
347 # Look for file_SOURCES and file_OBJECTS.
348 local (@result) = ();
349 if (defined $contents{$one_file . "_SOURCES"})
351 if (! defined $contents{$one_file . "_OBJECTS"})
353 # Turn sources into objects.
354 $_ = $contents{$one_file . "_SOURCES"};
356 # Ugh: Perl syntax vs Emacs.
357 local ($krc1, $krc2) = ('\.\$\{kr\}c', '\.\$\(kr\)c');
362 s/\.[cCmylfs]/$obj/g;
364 $output_vars .= $one_file . "_OBJECTS = " . $_ . "\n";
368 &am_error ($one_file . '_OBJECTS', 'should not be defined');
371 @result = ('${' . $one_file . "_SOURCES}",
372 '${' . $one_file . "_OBJECTS}");
376 $output_vars .= ($one_file . "_SOURCES = " . $one_file . ".c\n"
377 . $one_file . "_OBJECTS = ". $one_file
379 @result = ($one_file . '.c',
383 if (defined $contents{'CONFIG_HEADER'})
385 $output_rules .= ('$(' . $one_file . "_OBJECTS): "
386 . $contents{'CONFIG_HEADER'} . "\n");
395 local ($programs, $libprograms, $libraries) = @_;
397 if (!$programs && !$libprograms && !$libraries)
403 local ($obj) = &get_object_extension;
405 local (@sources, @objects);
406 push (@sources, '${SOURCES}') if (defined $contents{'SOURCES'});
407 push (@objects, '${OBJECTS}') if (defined $contents{'OBJECTS'});
410 local ($sadd, $oadd);
411 foreach $one_file (split (' ', ($programs . ' '
415 ($sadd, $oadd) = &handle_source_transform ($one_file, $obj);
416 push (@sources, $sadd);
417 push (@objects, $oadd);
420 $output_vars .= "\n";
422 # Re-init SOURCES and OBJECTS. FIXME other code shouldn't depend
424 $contents{'SOURCES'} = join (' ', @sources);
425 $contents{'OBJECTS'} = join (' ', @objects);
427 # Some boilerplate, and install rules.
430 $output_rules .= &file_contents ('programs');
431 push (@install_exec, "install-programs");
432 push (@uninstall, 'uninstall-programs');
433 push (@clean, 'programs');
434 push (@installdirs, '$(bindir)');
435 push (@all, '$(PROGRAMS)');
439 $output_rules .= &file_contents ('libprograms');
440 push (@install_exec, 'install-libprograms');
441 push (@uninstall, 'uninstall-libprograms');
442 push (@clean, 'libprograms');
443 push (@installdirs, '$(libexecdir)');
444 push (@all, '$(LIBPROGRAMS)');
448 if ($programs || $libprograms)
450 local ($fcont) = &file_contents ('program');
452 foreach $one_file (split (' ', $programs . ' ' . $libprograms))
454 if (! defined $contents{$one_file . "_LDADD"})
456 # User didn't define prog_LDADD override. So do it.
457 $output_vars .= $one_file . '_LDADD = ${LDADD}' . "\n";
460 ($munge = $fcont) =~ s/\@PROGRAM\@/$one_file/g;
461 $output_rules .= $munge;
469 local ($libraries) = @_;
471 return if (!$libraries);
473 local (@liblist) = split (' ', $libraries);
475 $output_rules .= &file_contents ('libraries');
476 local ($onefile) = &file_contents ('library');
477 local ($onelib, $munge);
478 foreach $onelib (@liblist)
480 if (! defined $contents{$onelib . '_LIBADD'})
482 # Generate support for conditional object inclusion in
484 $output_vars .= $onelib . "_LIBADD =\n";
487 ($munge = $onefile) =~ s/\@LIBRARY\@/$onelib/g;
488 $output_rules .= $munge;
491 # Turn "foo" into "libfoo.a" and include macro definition.
492 grep (($_ = 'lib' . $_ . '.a') && 0, @liblist);
493 $output_vars .= ("LIBFILES = " . join (' ', @liblist) . "\n\n"
494 . &file_contents ('libraries-vars'));
496 push (@install_exec, 'install-libraries');
497 push (@uninstall, 'uninstall-libraries');
498 push (@clean, 'libraries');
499 push (@all, '$(LIBFILES)');
505 &am_install_var ('scripts', 'SCRIPTS', 'bin', 'sbin', 'libexec',
509 # Handle all Texinfo source.
512 local ($texis) = &am_variable ('TEXINFOS');
515 local (@texis) = split (' ', $texis);
518 &am_error ('sorry, only one file allowed in `TEXINFOS\'');
523 ($infobase = $texis[0]) =~ s/\.texi$//;
525 # If 'version.texi' is referenced by input file, then include
526 # automatic versioning capability.
527 system ("grep version.texi " . $relative_dir . "/" . $texis[0]
528 . " > /dev/null 2>&1");
532 push (@texis, 'version.texi');
533 push (@dist_common, 'version.texi', 'stamp-vti');
534 push (@clean, 'vti');
537 ($tfile = &file_contents ('texi-version')) =~ s/\@TEXI\@/$texis[0]/g;
538 $output_rules = $output_rules . $tfile;
540 &require_file ('mdate-sh');
543 # If user specified file_TEXINFOS, then use that as explicit
545 if (defined $contents{$infobase . "_TEXINFOS"})
547 push (@texis, "\$" . $infobase . '_TEXINFOS');
548 push (@dist_common, "\$" . $infobase . '_TEXINFOS');
553 $output_rules = ($output_rules . $infobase . ".info: "
554 . join (' ', @texis) . "\n\n");
558 $output_vars = $output_vars . &file_contents ('texinfos-vars');
559 $output_rules = $output_rules . &file_contents ('texinfos');
561 push (@suffixes, '.texi', '.info', '.dvi');
562 push (@uninstall, 'uninstall-info');
563 push (@clean, 'info');
564 push (@info, '$(INFO_DEPS)');
565 push (@dvi, '$(DVIS)');
566 push (@installdirs, '$(infodir)');
567 # Make sure documentation is made and installed first.
568 unshift (@install_data, 'install-info');
569 unshift (@all, 'info');
571 $output_vars .= ("INFOS = " . $infobase . ".info*\n"
572 . "INFO_DEPS = " . $infobase . ".info\n"
573 . "DVIS = " . $infobase . ".dvi\n\n");
575 # Do some error checking.
576 &require_file ('texinfo.tex');
579 # Handle any man pages.
582 return if (! defined $contents{'MANS'});
584 # We generate the manpage install code by hand to avoid the use of
585 # basename in the generated Makefile.
586 local (@mans) = split (' ', $contents{'MANS'});
587 local (%sections, %inames, %secmap, %fullsecmap);
590 m/^(.*)\.([0-9])([a-z]*)$/;
594 $fullsecmap{$1} = $2 . $3;
597 # Generate list of install dirs.
598 $output_rules .= "install-man:\n";
599 foreach (keys %sections)
601 push (@installdirs, '$(mandir)/man' . $_);
602 $output_rules .= ("\t" . '$(top_srcdir)/mkinstalldirs $(mandir)/man'
606 # Generate install target.
608 foreach $key (keys %inames)
610 $_ = $install_man_format;
611 s/\@SECTION\@/$secmap{$key}/g;
612 s/\@MAN\@/$inames{$key}/g;
613 s/\@FULLSECT\@/$fullsecmap{$key}/g;
614 s/\@MANBASE\@/$key/g;
617 $output_rules .= "\n";
619 $output_rules .= "uninstall-man:\n";
620 foreach $key (keys %inames)
622 $_ = $uninstall_man_format;
623 s/\@SECTION\@/$secmap{$key}/g;
624 s/\@MAN\@/$inames{$key}/g;
625 s/\@FULLSECT\@/$fullsecmap{$key}/g;
626 s/\@MANBASE\@/$key/g;
629 $output_rules .= "\n";
631 $output_vars .= &file_contents ('mans-vars');
633 push (@install_data, 'install-man');
634 push (@uninstall, 'uninstall-man');
635 push (@all, '$(MANS)');
638 # Handle DATA variables.
641 &am_install_var ('data', 'DATA', 'data', 'sysconf',
642 'sharedstate', 'localstate', 'pkgdata',
649 local ($tagging) = 0;
651 if (defined ($contents{'SUBDIRS'}))
653 $output_rules .= &file_contents ('tags');
656 elsif ($dir_holds_sources || defined ($contents{'ETAGS_ARGS'}))
658 $output_rules .= &file_contents ('tags-subd');
664 $output_rules .= &file_contents ('tags-clean');
665 push (@clean, 'tags');
669 # Every Makefile must define some sort of TAGS rule.
670 # Otherwise, it would be possible for a top-level "make TAGS"
671 # to fail because some subdirectory failed.
672 $output_rules .= "tags: TAGS\nTAGS:\n\n";
676 # Handle 'dist' target.
679 # Look for common files that should be included in distribution.
681 foreach $cfile (@common_files)
683 if (-f ($relative_dir . "/" . $cfile))
685 push (@dist_common, $cfile);
689 $output_vars .= "DIST_COMMON = " . join (' ', @dist_common) . "\n\n";
692 $output_vars .= &file_contents ('dist-vars');
693 if ($relative_dir ne '.')
696 $output_vars .= "subdir = " . $relative_dir . "\n\n";
697 $output_rules .= &file_contents ('dist-subd');
701 $output_rules .= &file_contents (defined ($contents{'SUBDIRS'})
707 # Handle auto-dependency code.
708 sub handle_dependencies
710 if ($use_dependencies)
712 # Include GNU-make-specific auto-dep code.
713 if ($dir_holds_sources)
715 $output_rules .= &file_contents ('depend');
720 # Include any auto-generated deps that are present.
721 if (-d ($relative_dir . "/.deps") && -f ($relative_dir . "/.deps/.P"))
724 local ($gpat) = $relative_dir . "/.deps/*.P";
726 foreach $depfile (<${gpat}>)
728 if (! open (DEP_FILE, $depfile))
730 &am_error ("couldn't open $depfile", $!);
735 $output_rules .= join ('', <DEP_FILE>);
740 $output_rules .= "\n";
745 # Handle subdirectories.
748 return if (! defined ($contents{'SUBDIRS'}));
750 $output_rules .= &file_contents ('subdirs');
752 push (@all, "all-recursive");
753 push (@check, "check-recursive");
754 push (@installcheck, "installcheck-recursive");
755 push (@info, "info-recursive");
756 push (@dvi, "dvi-recursive");
758 $recursive_install = 1;
761 # Handle remaking and configure stuff.
764 if ($relative_dir ne '.')
767 $output_rules .= &file_contents ('remake-subd');
773 $output_vars .= "ACLOCAL = aclocal.m4\n";
774 push (@dist_common, 'aclocal.m4');
776 $output_rules .= &file_contents ('remake');
778 # Look for some files we need.
779 &require_file ('install-sh');
780 &require_file ('mkinstalldirs');
783 if (defined ($contents{'CONFIG_HEADER'})
784 && $contents{'CONFIG_HEADER'} !~ m,/,)
786 # Header defined and in this directory.
789 $output_vars .= "ACCONFIG = acconfig.h\n";
790 push (@dist_common, 'acconfig.h');
792 if (-f 'config.h.top')
794 $output_vars .= "CONFIG_TOP = config.h.top\n";
795 push (@dist_common, 'config.h.top');
797 if (-f 'config.h.bot')
799 $output_vars .= "CONFIG_BOT = config.h.bot\n";
800 push (@dist_common, 'config.h.bot');
803 push (@dist_common, 'stamp-h.in', $contents{'CONFIG_HEADER'} . '.in');
805 $output_rules .= &file_contents ('remake-hdr');
812 &am_install_var ('data', 'HEADERS', 'include',
813 'oldinclude', 'pkginclude',
817 # Handle footer elements.
820 if ($contents{'SOURCES'})
822 $output_vars .= "SOURCES = " . $contents{'SOURCES'} . "\n";
824 if ($contents{'OBJECTS'})
826 $output_vars .= "OBJECTS = " . $contents{'OBJECTS'} . "\n";
828 if ($contents{'SOURCES'} || $contents{'OBJECTS'})
830 $output_vars .= "\n";
833 if (defined $contents{'SUFFIXES'})
835 push (@suffixes, '$(SUFFIXES)');
838 $output_trailer .= ".SUFFIXES:\n";
841 $output_trailer .= ".SUFFIXES: " . join (' ', @suffixes) . "\n";
843 $output_trailer .= "\n" . &file_contents ('footer');
846 # Deal with installdirs target.
847 sub handle_installdirs
849 # GNU Makefile standards recommend this. FIXME prettyprint rule
851 $output_rules .= ("installdirs:"
852 . ($recursive_install
853 ? " installdirs-recursive\n"
855 if ($#installdirs >= 0)
857 $output_rules .= ("\t\$(top_srcdir)/mkinstalldirs "
858 . join (' ', @installdirs)
861 $output_rules .= "\n";
864 # There are several targets which need to be merged. This is because
865 # their complete definition is compiled from many parts. Note that we
866 # avoid double colon rules, otherwise we'd use them instead.
867 sub handle_merge_targets
869 &do_one_merge_target ('all', @all);
870 &do_one_merge_target ('info', @info);
871 &do_one_merge_target ('dvi', @dvi);
872 &do_one_merge_target ('check', @check);
873 &do_one_merge_target ('installcheck', @installcheck);
875 # Handle the various install targets specially. We do this so
876 # that (eg) "make install-exec" will run "install-exec-recursive"
877 # if required, but "make install" won't run it twice. Step one is
878 # to see if the user specified local versions of any of the
880 if (defined $contents{'install-exec-local'})
882 push (@install_exec, 'install-exec-local');
884 if (defined $contents{'install-data-local'})
886 push (@install_data, 'install-data-local');
888 if (defined $contents{'uninstall-local'})
890 push (@uninstall, 'uninstall-local');
893 if (defined $contents{'install-local'})
895 &am_error ("use \`install-data' or \`install-exec', not \`install'");
898 # Step two: if we are doing recursive makes, write out the
901 if ($recursive_install)
903 push (@install, 'install-recursive');
904 push (@uninstall, 'uninstall-recursive');
906 if ($#install_exec >= 0)
908 $output_rules .= ('install-exec-am: '
909 . join (' ', @install_exec)
911 @install_exec = ('install-exec-recursive', 'install-exec-am');
912 push (@install, 'install-exec-am');
914 if ($#install_data >= 0)
916 $output_rules .= ('install-data-am: '
917 . join (' ', @install_data)
919 @install_data = ('install-data-recursive', 'install-data-am');
920 push (@install, 'install-data-am');
922 if ($#uninstall >= 0)
924 $output_rules .= ('uninstall-am: '
925 . join (' ', @uninstall)
927 @uninstall = ('uninstall-recursive', 'uninstall-am');
931 # Step three: print definitions users can use.
932 if ($#install_exec >= 0)
934 $output_rules .= ("install-exec: "
935 . join (' ', @install_exec)
937 push (@install, 'install-exec') if (!$recursive_install);
939 if ($#install_data >= 0)
941 $output_rules .= ("install-data: "
942 . join (' ', @install_data)
944 push (@install, 'install-data') if (!$recursive_install);
947 $output_rules .= ('install: '
948 . join (' ', @install)
951 . join (' ', @uninstall)
955 # Helper for handle_merge_targets.
956 sub do_one_merge_target
958 local ($name, @values) = @_;
960 if (defined $contents{$name . '-local'})
962 # User defined local form of target. So include it.
963 push (@values, $name . '-local');
966 $output_rules .= $name . ": " . join (' ', @values) . "\n\n";
969 # Handle all 'clean' targets.
972 push (@clean, 'generic');
973 $output_rules .= &file_contents ('clean');
975 local ($target) = $recursive_install ? 'clean-am' : 'clean';
976 &do_one_clean_target ($target, 'mostly', '', @clean);
977 &do_one_clean_target ($target, '', 'mostly', @clean);
978 &do_one_clean_target ($target, 'dist', '', @clean);
979 &do_one_clean_target ($target, 'maintainer-', 'dist', @clean);
982 if ($recursive_install)
984 @deps = ('am', 'recursive');
985 &do_one_clean_target ('', 'mostly', '', @deps);
986 &do_one_clean_target ('', '', '', @deps);
987 &do_one_clean_target ('', 'dist', '', @deps);
988 &do_one_clean_target ('', 'maintainer-', '', @deps);
992 # Helper for handle_clean.
993 sub do_one_clean_target
995 local ($target, $name, $last_name, @deps) = @_;
997 # Special case: if target not passed, then don't generate
998 # dependency on next "lower" clean target (eg no
999 # clean<-mostlyclean derivation). In this case the target is
1000 # implicitly known to be 'clean'.
1001 local ($flag) = $target;
1007 $output_rules .= $name . $target . ": ";
1010 if ($last_name || $name ne 'mostly')
1012 $output_rules .= $last_name . $target . " ";
1016 $output_rules .= ($name . 'clean-' . join (' ' . $name . 'clean-', @deps)
1019 # FIXME shouldn't we really print these messages before running
1021 if ($name . $target eq 'maintainer-clean')
1023 # Print a special warning.
1025 ("\t\@echo \"This command is intended for maintainers to use;\"\n"
1026 . "\t\@echo \"it deletes files that may require special "
1027 . "tools to rebuild.\"\n");
1029 $output_rules .= "\n";
1032 ################################################################
1034 # Read Makefile.am and set up %contents. Simultaneously copy lines
1035 # from Makefile.am into $output_trailer or $output_vars as
1036 # appropriate. NOTE we put rules in the trailer section. We want
1037 # user rules to come after our generated stuff.
1040 local ($amfile) = @_;
1042 if (! open (AMFILE, $amfile))
1044 print STDERR "automake: couldn't open $amfile: $!\n";
1048 local ($saw_bk) = 0;
1049 local ($was_rule) = 0;
1050 local ($last_var_name) = '';
1060 $output_trailer .= $_ . "\n";
1064 $output_vars .= $_ . "\n";
1065 if (substr ($_, -1) eq "\\")
1067 $contents{$last_var_name} .= substr ($_, 0,
1072 $contents{$last_var_name} .= $_;
1076 elsif ($_ eq '@kr@')
1078 # Special case: this means we want automatic
1079 # de-ANSI-fication. FIXME think of a better way.
1080 $contents{'@kr@'} = 1;
1082 elsif (m/^ *([a-zA-Z_.][a-zA-Z0-9_.]*) *:/)
1086 # Value here doesn't matter; for targets we only note
1089 $output_trailer .= $_ . "\n";
1091 elsif (m/^ *([A-Za-z][A-Za-z0-9_]*)[ ]*=[ ]*(.*)$/)
1093 # Found a variable reference.
1095 $last_var_name = $1;
1096 if (substr ($2, -1) eq "\\")
1098 $contents{$1} = substr ($2, 0, length ($2) - 1);
1104 $output_vars .= $_ . "\n";
1108 # Special rule: if looking at a blank line, append it to
1109 # whatever we saw last.
1112 $output_trailer .= "\n";
1116 $output_vars .= "\n";
1121 # This isn't an error; it is probably a continued rule.
1122 # In fact, this is what we assume.
1123 $output_trailer .= $_ . "\n";
1126 $saw_bk = (substr ($_, -1) eq "\\");
1129 # Include some space after user code.
1130 $output_vars .= "\n";
1131 $output_trailer .= "\n";
1134 ################################################################
1136 # Initialize global variables.
1139 # Associative array of standard directory names. Entry is TRUE if
1140 # corresponding directory should be installed during
1141 # 'install-exec' phase.
1159 # Helper text for dealing with man pages.
1160 $install_man_format =
1161 ' sect=@SECTION@; \\
1162 inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
1163 echo installing @MAN@ as $(mandir)/man$$sect/$$inst; \\
1164 $(INSTALL_DATA) $(srcdir)/@MAN@ $(mandir)/man$$sect/$$inst; \\
1165 if test -d $(mandir)/cat$$sect; then \\
1166 echo formatting @MAN@ as $(mandir)/cat$$sect/$$inst; \\
1167 $(NROFF) -man $(srcdir)/@MAN@ > $(mandir)/cat$$sect/$$inst; \\
1173 $uninstall_man_format =
1174 ' inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
1175 rm -f $(mandir)/man@SECTION@/$$inst $(mandir)/cat@SECTION@/$$inst
1178 # Commonly found files we look for and automatically include in
1182 "THANKS", "TODO", "README", "NEWS", "COPYING", "COPYING.LIB",
1183 "INSTALL", "ABOUT-NLS", "ChangeLog", "configure", "configure.in",
1184 "config.guess", "config.sub"
1187 # Commonly used files we auto-include, but only sometimes.
1190 "version.texi", "aclocal.m4", "acconfig.h", "config.h.top",
1191 "config.h.bot", "stamp-h.in", "mdate-sh", "ansi2knr.c",
1192 "ansi2knr.1", 'stamp-vti', "mkinstalldirs", "install-sh"
1196 --amdir=DIR directory storing config files
1197 --help print this help, then exit
1198 --include-deps include generated dependencies in Makefile.in
1199 --output-dir=DIR put generated Makefile.in's into DIR
1200 --version print version number, then exit\n";
1204 ################################################################
1206 # Return contents of a file from $am_dir.
1209 local ($basename) = @_;
1210 local ($file) = $am_dir . '/' . $basename . '.am';
1212 if (! open (FC_FILE, $file))
1214 print STDERR "automake: installation error: cannot open \"$file\"\n";
1218 # Lines starting with "##" are comments for developer use only.
1219 # Maybe this is a bad idea?
1220 local ($result) = '';
1223 $result .= $_ unless ( m/^##/);
1229 # Return contents of some Makefile.am variable. Allow for AM_ style
1233 local ($varname) = @_;
1235 return (defined ($contents{'AM_' . $varname})
1236 ? $contents{'AM_' . $varname}
1237 : $contents{$varname});
1240 # Handle `where_HOW' variable magic. Does all lookups, generates
1241 # install code,and possibly generates code to define the primary
1242 # variable. The first argument is the name of the .am file to munge,
1243 # the second argument is the primary variable (eg HEADERS), and all
1244 # subsequent arguments are possible installation locations. FIXME
1245 # should scan all defined variables and do some error checking to
1246 # avoid typos (eg 'bnidir_PROGRAMS' should give error). Returns TRUE
1247 # if any items were found, FALSE otherwise.
1250 local ($file, $primary, @prefixes) = @_;
1253 local ($contents) = &file_contents ($file);
1257 if (defined $contents{$_ . '_' . $primary})
1259 push (@used, '${' . $_ . '_' . $primary . '}');
1262 # Objects in noinst_FOO never get installed.
1266 ($munge = $contents) =~ s/\@DIR\@/$_/g;
1267 $output_rules .= $munge;
1269 push (@uninstall, 'uninstall-' . $_ . $primary);
1270 push (@installdirs, '${' . $_ . 'dir}');
1271 if ($exec_dir_p{$_})
1273 push (@install_exec, 'install-' . $_ . $primary);
1277 push (@install_data, 'install-' . $_ . $primary);
1282 if (! defined $contents{$primary} && $#used >= 0)
1285 $output_vars .= $primary . " = " . join (' ', @used) . "\n\n";
1288 return ($#used >= 0);
1292 ################################################################
1294 # Verify that the file must exist in the current directory.
1298 local ($fullfile) = $relative_dir . "/" . $file;
1302 &am_error ("required file \"$fullfile\" not found");
1306 push (@dist_common, $file);
1311 ################################################################
1313 # Return directory name of file.
1319 ($sub = $file) =~ s,/+[^/]+,,g;
1331 local ($dirname) = @_;
1332 system ("mkdir", $dirname);
1335 ################################################################
1337 # Print an error message and set exit status.
1340 print STDERR "automake: ${am_file}.am: ", join (' ', @_), "\n";
1344 # Print usage information.
1347 print "Usage: automake [OPTION] ... [Makefile]...\n";
1349 print "\nFiles which are automatically distributed, if found:\n";
1350 $~ = "USAGE_FORMAT";
1351 local (@lcomm) = sort ((@common_files, @common_sometimes));
1353 while ($#lcomm >= 0)
1355 $one = shift (@lcomm);
1356 $two = shift (@lcomm);
1363 format USAGE_FORMAT =
1364 @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<