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 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 # Constants to define the "strictness" level.
44 # Variables global to entire run.
47 $strictness = $NORMAL;
49 # This is TRUE if GNU make specific automatic dependency generation
50 # code should be included in generated Makefile.in.
51 $use_dependencies = 1;
53 # This holds our (eventual) exit status. We don't actually exit until
54 # we have processed all input files.
57 # From the Perl manual.
58 $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
60 # TRUE if missing standard files should be installed.
65 &initialize_global_constants;
68 @input_files = &parse_arguments (@ARGV);
70 # Now do all the work on each file.
71 foreach $am_file (@input_files)
73 if (! -f ($am_file . '.am'))
75 &am_error ('no such file');
79 &generate_makefile ($am_file);
86 ################################################################
91 local (@arglist) = @_;
94 while ($#arglist >= 0)
96 if ($arglist[0] eq "--version")
98 print "Automake version $VERSION\n";
101 elsif ($arglist[0] eq "--help")
105 elsif ($arglist[0] =~ /^--amdir=(.+)$/)
109 elsif ($arglist[0] eq '--amdir')
111 &require_argument (@arglist);
113 $am_dir = $arglist[0];
115 elsif ($arglist[0] =~ /^--strictness=(.+)$/)
117 &set_strictness ($1);
119 elsif ($arglist[0] eq '--strictness')
121 &require_argument (@arglist);
123 &set_strictness ($arglist[0]);
125 elsif ($arglist[0] eq '--include-deps')
127 $use_dependencies = 0;
129 elsif ($arglist[0] =~ /^--output-dir=(.*)$/)
131 # Set output directory.
132 $output_directory = $1;
134 elsif ($arglist[0] eq '--output-dir')
136 &require_argument (@arglist);
138 $output_directory = $arglist[0];
140 elsif ($arglist[0] eq '--install-missing')
142 $install_missing = 1;
144 elsif ($arglist[0] eq '--')
146 # Stop option processing.
148 push (@make_list, @arglist);
151 elsif ($arglist[0] =~ /^-/)
153 print STDERR "automake: unrecognized option -- \`$arglist[0]'\n";
158 push (@make_list, $arglist[0]);
166 # Look around for some files.
167 push (@make_list, 'Makefile') if -f 'Makefile.am';
169 foreach (<*/Makefile.am>)
172 push (@make_list, $_);
175 if ($#make_list >= 0)
177 print "automake: using ", join (' ', @make_list), "\n";
181 print STDERR "automake: no \"Makefile.am\" found or specified\n";
189 # Ensure argument exists, or die.
192 local ($arg, @arglist) = @_;
195 print STDERR "automake: no argument given for option \`$arg'\n";
200 ################################################################
202 # Generate a Makefile.in given the name of the corresponding Makefile.
203 sub generate_makefile
205 local ($makefile) = @_;
207 print "creating ", $makefile, ".in\n";
209 &initialize_per_input;
210 $relative_dir = &dirname ($makefile);
211 # FIXME with new 'dist' target, don't need Makefile.in. Probably
212 # should remove it here.
213 &push_dist_common ('Makefile.in', 'Makefile.am');
214 push (@sources, '$(SOURCES)') if (defined $contents{'SOURCES'});
215 push (@objects, '$(OBJECTS)') if (defined $contents{'OBJECTS'});
217 # Generate header before reading .am file. The header must come
218 # before anything else, and read_am_file copies code into the
222 # This is always the default target. This gives us freedom to do
223 # things in whatever order is convenient.
224 $output_rules .= "default: all\n\n";
226 &read_am_file ($makefile . '.am');
228 # Check first, because we might modify some state.
229 &check_gnu_standards;
230 &check_gnits_standards;
236 # Re-init SOURCES and OBJECTS. FIXME other code shouldn't depend
237 # on this (but currently does).
238 $contents{'SOURCES'} = join (' ', @sources);
239 $contents{'OBJECTS'} = join (' ', @objects);
249 &handle_dependencies;
251 &handle_merge_targets;
255 if (! -d ($output_directory . '/' . $relative_dir))
257 &mkdir ($output_directory . '/' . $relative_dir);
259 if (! open (GM_FILE, "> " . $output_directory . '/' . $makefile . ".in"))
261 &am_error ("cannot open:", $!);
265 print GM_FILE $output_vars;
266 print GM_FILE $output_rules;
267 print GM_FILE $output_trailer;
272 ################################################################
274 # Generate header of Makefile.in.
279 . "# Makefile.in generated automatically by automake "
281 . " from Makefile.am\n");
283 $output_vars = $output_vars . &file_contents ('header-vars');
286 # Return object extension. Just once, put some code into the output.
287 sub get_object_extension
289 if (! $dir_holds_sources)
293 $output_vars .= &file_contents ('compile-vars');
294 $output_rules .= &file_contents ('compile');
296 # Check for automatic de-ANSI-fication.
297 $dir_holds_sources = '.o';
298 push (@suffixes, '.c', '.o');
299 push (@clean, 'compile');
301 if (defined $contents{'@kr@'})
303 $dir_holds_sources = '.$(kr)o';
304 push (@suffixes, '._c', '._o');
306 &require_file ($NORMAL, 'ansi2knr.c');
307 &require_file ($NORMAL, 'ansi2knr.1');
309 $output_vars .= &file_contents ('kr-vars');
310 $output_rules .= &file_contents ('compile-kr');
311 $output_rules .= &file_contents ('clean-kr');
316 return $dir_holds_sources;
319 # Handle SOURCE->OBJECT transform for one program or library.
320 sub handle_source_transform
322 local ($one_file, $obj) = @_;
324 # Look for file_SOURCES and file_OBJECTS.
325 if (defined $contents{$one_file . "_SOURCES"})
327 if (! defined $contents{$one_file . "_OBJECTS"})
329 # Turn sources into objects.
330 local (@files) = split (/\s+/, $contents{$one_file . "_SOURCES"});
331 # Ugh: Perl syntax vs Emacs.
332 local ($krc1, $krc2) = ('\.\$\{kr\}c', '\.\$\(kr\)c');
333 local (@result) = ();
338 # Automatically include generated .c file in
340 &push_dist_common ($1 . '.c');
343 # Transform source files into .o files.
347 s/\.[cCmylfs]$/$obj/g;
352 $output_vars .= ($one_file . "_OBJECTS = " . join (' ', @result)
357 &am_error ($one_file . '_OBJECTS', 'should not be defined');
360 push (@sources, '$(' . $one_file . "_SOURCES)");
361 push (@objects, '$(' . $one_file . "_OBJECTS)");
365 $output_vars .= ($one_file . "_SOURCES = " . $one_file . ".c\n"
366 . $one_file . "_OBJECTS = ". $one_file
368 push (@sources, $one_file . '.c');
369 push (@objects, $one_file . $obj);
372 if (defined $contents{'CONFIG_HEADER'})
374 $output_rules .= ('$(' . $one_file . "_OBJECTS): "
375 . $contents{'CONFIG_HEADER'} . "\n");
384 local (@proglist) = &am_install_var ('-clean',
385 'programs', 'PROGRAMS',
386 'bin', 'sbin', 'libexec', 'noinst');
387 # FIXME error if PROGRAMS defined but no blah_PROGRAMS defined.
388 return if ($#proglist < 0);
390 local ($obj) = &get_object_extension;
391 local ($one_file, $munge);
392 local ($fcont) = &file_contents ('program');
393 foreach $one_file (@proglist)
395 &handle_source_transform ($one_file, $obj);
397 if (! defined $contents{$one_file . "_LDADD"})
399 # User didn't define prog_LDADD override. So do it.
400 $output_vars .= $one_file . '_LDADD = $(LDADD)' . "\n";
403 ($munge = $fcont) =~ s/\@PROGRAM\@/$one_file/g;
404 $output_rules .= $munge;
411 local (@liblist) = &am_install_var ('-no-all', '-clean',
412 'libraries', 'LIBRARIES',
413 'lib', 'pkglib', 'noinst');
414 # FIXME error if LIBRARIES defined but no blah_LIBRARIES defined.
415 return if ($#liblist < 0);
417 # Generate _LIBFILES variables. Too bad we can't do this in
419 local ($onedir, $onelib);
421 foreach $onedir ('lib', 'pkglib', 'noinst')
423 if (defined $contents{$onedir . '_LIBRARIES'})
426 foreach $onelib (split (/\s+/, $contents{$onedir . '_LIBRARIES'}))
428 push (@outlist, 'lib' . $onelib . '.a');
430 $output_vars .= ($onedir . '_LIBFILES = '
431 . join (' ', @outlist) . "\n");
434 push (@all, '$(LIBFILES)');
436 local ($obj) = &get_object_extension;
437 local ($template) = &file_contents ('library');
439 foreach $onelib (@liblist)
441 if (! defined $contents{$onelib . '_LIBADD'})
443 # Generate support for conditional object inclusion in
445 $output_vars .= $onelib . "_LIBADD =\n";
448 &handle_source_transform ($onelib, $obj);
450 ($munge = $template) =~ s/\@LIBRARY\@/$onelib/g;
451 $output_rules .= $munge;
454 # Turn "foo" into "libfoo.a" and include macro definition.
455 grep (($_ = 'lib' . $_ . '.a') && 0, @liblist);
457 if (! defined $contents{'LIBFILES'})
459 $output_vars .= 'LIBFILES = ' . join (' ', @liblist) . "\n";
461 $output_vars .= &file_contents ('libraries-vars');
467 &am_install_var ('-clean',
468 'scripts', 'SCRIPTS',
469 'bin', 'sbin', 'libexec', 'noinst');
472 # Handle all Texinfo source.
475 local ($texis) = &am_variable ('TEXINFOS');
478 local (@texis) = split (/\s+/, $texis);
481 &am_error ('sorry, only one file allowed in `TEXINFOS\'');
486 ($infobase = $texis[0]) =~ s/\.texi$//;
488 # If 'version.texi' is referenced by input file, then include
489 # automatic versioning capability.
490 system ("grep version.texi " . $relative_dir . "/" . $texis[0]
491 . " > /dev/null 2>&1");
495 push (@texis, 'version.texi');
496 &push_dist_common ('version.texi', 'stamp-vti');
497 push (@clean, 'vti');
500 ($tfile = &file_contents ('texi-version')) =~ s/\@TEXI\@/$texis[0]/g;
501 $output_rules = $output_rules . $tfile;
503 &require_file ($NORMAL, 'mdate-sh');
506 # If user specified file_TEXINFOS, then use that as explicit
508 if (defined $contents{$infobase . "_TEXINFOS"})
510 push (@texis, "\$" . $infobase . '_TEXINFOS');
511 &push_dist_common ("\$" . $infobase . '_TEXINFOS');
516 $output_rules = ($output_rules . $infobase . ".info: "
517 . join (' ', @texis) . "\n\n");
521 $output_vars = $output_vars . &file_contents ('texinfos-vars');
522 $output_rules = $output_rules . &file_contents ('texinfos');
525 local ($crules) = &file_contents ('texi-clean');
526 $crules =~ s/\@TEXI\@/$infobase/g;
527 $output_rules .= $crules;
529 push (@suffixes, '.texi', '.info', '.dvi');
530 push (@uninstall, 'uninstall-info');
531 push (@clean, 'info');
532 push (@info, '$(INFO_DEPS)');
533 push (@dvi, '$(DVIS)');
534 push (@installdirs, '$(infodir)');
535 # Make sure documentation is made and installed first.
536 unshift (@install_data, 'install-info');
537 unshift (@all, 'info');
539 $output_vars .= ("INFOS = " . $infobase . ".info*\n"
540 . "INFO_DEPS = " . $infobase . ".info\n"
541 . "DVIS = " . $infobase . ".dvi\n\n");
543 # Do some error checking.
544 &require_file ($NORMAL, 'texinfo.tex');
547 # Handle any man pages.
550 return if (! defined $contents{'MANS'});
552 # We generate the manpage install code by hand to avoid the use of
553 # basename in the generated Makefile.
554 local (@mans) = split (/\s+/, $contents{'MANS'});
555 local (%sections, %inames, %secmap, %fullsecmap);
558 m/^(.*)\.([0-9])([a-z]*)$/;
562 $fullsecmap{$1} = $2 . $3;
565 # Generate list of install dirs.
566 $output_rules .= "install-man:\n";
567 foreach (keys %sections)
569 push (@installdirs, '$(mandir)/man' . $_);
570 $output_rules .= ("\t" . '$(top_srcdir)/mkinstalldirs $(mandir)/man'
574 # Generate install target.
576 foreach $key (keys %inames)
578 $_ = $install_man_format;
579 s/\@SECTION\@/$secmap{$key}/g;
580 s/\@MAN\@/$inames{$key}/g;
581 s/\@FULLSECT\@/$fullsecmap{$key}/g;
582 s/\@MANBASE\@/$key/g;
585 $output_rules .= "\n";
587 $output_rules .= "uninstall-man:\n";
588 foreach $key (keys %inames)
590 $_ = $uninstall_man_format;
591 s/\@SECTION\@/$secmap{$key}/g;
592 s/\@MAN\@/$inames{$key}/g;
593 s/\@FULLSECT\@/$fullsecmap{$key}/g;
594 s/\@MANBASE\@/$key/g;
597 $output_rules .= "\n";
599 $output_vars .= &file_contents ('mans-vars');
601 push (@install_data, 'install-man');
602 push (@uninstall, 'uninstall-man');
603 push (@all, '$(MANS)');
606 # Handle DATA variables.
609 &am_install_var ('data', 'DATA', 'data', 'sysconf',
610 'sharedstate', 'localstate', 'pkgdata',
617 local ($tagging) = 0;
619 if (defined ($contents{'SUBDIRS'}))
621 $output_rules .= &file_contents ('tags');
624 elsif ($dir_holds_sources || defined ($contents{'ETAGS_ARGS'}))
626 $output_rules .= &file_contents ('tags-subd');
632 $output_rules .= &file_contents ('tags-clean');
633 push (@clean, 'tags');
637 # Every Makefile must define some sort of TAGS rule.
638 # Otherwise, it would be possible for a top-level "make TAGS"
639 # to fail because some subdirectory failed.
640 $output_rules .= "tags: TAGS\nTAGS:\n\n";
644 # Handle 'dist' target.
647 # Look for common files that should be included in distribution.
649 foreach $cfile (@common_files)
651 if (-f ($relative_dir . "/" . $cfile))
653 &push_dist_common ($cfile);
657 $output_vars .= ("DIST_COMMON = " . join (' ', keys (%dist_common))
661 $output_vars .= &file_contents ('dist-vars');
662 if ($relative_dir ne '.')
665 $output_vars .= "subdir = " . $relative_dir . "\n\n";
666 $output_rules .= &file_contents ('dist-subd');
670 $output_rules .= &file_contents (defined ($contents{'SUBDIRS'})
676 # Handle auto-dependency code.
677 sub handle_dependencies
679 if ($use_dependencies)
681 # Include GNU-make-specific auto-dep code.
682 if ($dir_holds_sources)
684 $output_rules .= &file_contents ('depend');
689 # Include any auto-generated deps that are present.
690 if (-d ($relative_dir . "/.deps") && -f ($relative_dir . "/.deps/.P"))
693 local ($gpat) = $relative_dir . "/.deps/*.P";
695 foreach $depfile (<${gpat}>)
697 if (! open (DEP_FILE, $depfile))
699 &am_error ("couldn't open $depfile", $!);
704 $output_rules .= join ('', <DEP_FILE>);
709 $output_rules .= "\n";
714 # Handle subdirectories.
717 return if (! defined ($contents{'SUBDIRS'}));
719 $output_rules .= &file_contents ('subdirs');
721 push (@all, "all-recursive");
722 push (@check, "check-recursive");
723 push (@installcheck, "installcheck-recursive");
724 push (@info, "info-recursive");
725 push (@dvi, "dvi-recursive");
727 $recursive_install = 1;
730 # Handle remaking and configure stuff.
733 if ($relative_dir ne '.')
736 $output_rules .= &file_contents ('remake-subd');
740 &require_file ($NORMAL, 'configure.in');
741 # FIXME require 'configure'? What if autoconf hasn't been run
744 if (defined $contents{'SUBDIRS'})
746 # We required AC_PROG_MAKE_SET.
747 system ("grep AC_PROG_MAKE_SET configure.in > /dev/null 2>&1");
751 &am_error ("AC_PROG_MAKE_SET must be used in configure.in");
757 $output_vars .= "ACLOCAL = aclocal.m4\n";
758 &push_dist_common ('aclocal.m4');
760 $output_rules .= &file_contents ('remake');
762 # Look for some files we need.
763 &require_file ($NORMAL, 'install-sh');
764 &require_file ($NORMAL, 'mkinstalldirs');
767 if (defined ($contents{'CONFIG_HEADER'})
768 && $contents{'CONFIG_HEADER'} !~ m,/,)
770 # Header defined and in this directory.
773 $output_vars .= "ACCONFIG = acconfig.h\n";
774 &push_dist_common ('acconfig.h');
776 if (-f 'config.h.top')
778 $output_vars .= "CONFIG_TOP = config.h.top\n";
779 &push_dist_common ('config.h.top');
781 if (-f 'config.h.bot')
783 $output_vars .= "CONFIG_BOT = config.h.bot\n";
784 &push_dist_common ('config.h.bot');
787 &push_dist_common ('stamp-h.in', $contents{'CONFIG_HEADER'} . '.in');
789 $output_rules .= &file_contents ('remake-hdr');
796 &am_install_var ('data', 'HEADERS', 'include',
797 'oldinclude', 'pkginclude',
801 # Handle footer elements.
804 if ($contents{'SOURCES'})
806 $output_vars .= "SOURCES = " . $contents{'SOURCES'} . "\n";
808 if ($contents{'OBJECTS'})
810 $output_vars .= "OBJECTS = " . $contents{'OBJECTS'} . "\n";
812 if ($contents{'SOURCES'} || $contents{'OBJECTS'})
814 $output_vars .= "\n";
817 if (defined $contents{'SUFFIXES'})
819 push (@suffixes, '$(SUFFIXES)');
822 $output_trailer .= ".SUFFIXES:\n";
825 $output_trailer .= ".SUFFIXES: " . join (' ', @suffixes) . "\n";
827 $output_trailer .= "\n" . &file_contents ('footer');
830 # Deal with installdirs target.
831 sub handle_installdirs
833 # GNU Makefile standards recommend this. FIXME prettyprint rule
835 $output_rules .= ("installdirs:"
836 . ($recursive_install
837 ? " installdirs-recursive\n"
839 if ($#installdirs >= 0)
841 $output_rules .= ("\t\$(top_srcdir)/mkinstalldirs "
842 . join (' ', @installdirs)
845 $output_rules .= "\n";
848 # There are several targets which need to be merged. This is because
849 # their complete definition is compiled from many parts. Note that we
850 # avoid double colon rules, otherwise we'd use them instead.
851 sub handle_merge_targets
853 &do_one_merge_target ('all', @all);
854 &do_one_merge_target ('info', @info);
855 &do_one_merge_target ('dvi', @dvi);
856 &do_one_merge_target ('check', @check);
857 &do_one_merge_target ('installcheck', @installcheck);
859 # Handle the various install targets specially. We do this so
860 # that (eg) "make install-exec" will run "install-exec-recursive"
861 # if required, but "make install" won't run it twice. Step one is
862 # to see if the user specified local versions of any of the
864 if (defined $contents{'install-exec-local'})
866 push (@install_exec, 'install-exec-local');
868 if (defined $contents{'install-data-local'})
870 push (@install_data, 'install-data-local');
872 if (defined $contents{'uninstall-local'})
874 push (@uninstall, 'uninstall-local');
877 if (defined $contents{'install-local'})
879 &am_error ("use \`install-data' or \`install-exec', not \`install'");
882 # Step two: if we are doing recursive makes, write out the
885 if ($recursive_install)
887 push (@install, 'install-recursive');
888 push (@uninstall, 'uninstall-recursive');
890 if ($#install_exec >= 0)
892 $output_rules .= ('install-exec-am: '
893 . join (' ', @install_exec)
895 @install_exec = ('install-exec-recursive', 'install-exec-am');
896 push (@install, 'install-exec-am');
898 if ($#install_data >= 0)
900 $output_rules .= ('install-data-am: '
901 . join (' ', @install_data)
903 @install_data = ('install-data-recursive', 'install-data-am');
904 push (@install, 'install-data-am');
906 if ($#uninstall >= 0)
908 $output_rules .= ('uninstall-am: '
909 . join (' ', @uninstall)
911 @uninstall = ('uninstall-recursive', 'uninstall-am');
915 # Step three: print definitions users can use.
916 if ($#install_exec >= 0)
918 $output_rules .= ("install-exec: "
919 . join (' ', @install_exec)
921 push (@install, 'install-exec') if (!$recursive_install);
923 if ($#install_data >= 0)
925 $output_rules .= ("install-data: "
926 . join (' ', @install_data)
928 push (@install, 'install-data') if (!$recursive_install);
931 $output_rules .= ('install: '
932 . join (' ', @install)
935 . join (' ', @uninstall)
939 # Helper for handle_merge_targets.
940 sub do_one_merge_target
942 local ($name, @values) = @_;
944 if (defined $contents{$name . '-local'})
946 # User defined local form of target. So include it.
947 push (@values, $name . '-local');
950 $output_rules .= $name . ": " . join (' ', @values) . "\n\n";
953 # Handle all 'clean' targets.
956 push (@clean, 'generic');
957 $output_rules .= &file_contents ('clean');
959 local ($target) = $recursive_install ? 'clean-am' : 'clean';
960 &do_one_clean_target ($target, 'mostly', '', @clean);
961 &do_one_clean_target ($target, '', 'mostly', @clean);
962 &do_one_clean_target ($target, 'dist', '', @clean);
963 &do_one_clean_target ($target, 'maintainer-', 'dist', @clean);
966 if ($recursive_install)
968 @deps = ('am', 'recursive');
969 &do_one_clean_target ('', 'mostly', '', @deps);
970 &do_one_clean_target ('', '', '', @deps);
971 &do_one_clean_target ('', 'dist', '', @deps);
972 &do_one_clean_target ('', 'maintainer-', '', @deps);
976 # Helper for handle_clean.
977 sub do_one_clean_target
979 local ($target, $name, $last_name, @deps) = @_;
981 # Special case: if target not passed, then don't generate
982 # dependency on next "lower" clean target (eg no
983 # clean<-mostlyclean derivation). In this case the target is
984 # implicitly known to be 'clean'.
985 local ($flag) = $target;
991 $output_rules .= $name . $target . ": ";
994 if ($last_name || $name ne 'mostly')
996 $output_rules .= $last_name . $target . " ";
1000 $output_rules .= ($name . 'clean-' . join (' ' . $name . 'clean-', @deps)
1003 # FIXME shouldn't we really print these messages before running
1005 if ($name . $target eq 'maintainer-clean')
1007 # Print a special warning.
1009 ("\t\@echo \"This command is intended for maintainers to use;\"\n"
1010 . "\t\@echo \"it deletes files that may require special "
1011 . "tools to rebuild.\"\n");
1013 elsif ($name . $target eq 'distclean'
1014 || $name . $target eq 'maintainer-clean')
1016 $output_rules .= "\trm -f config.status\n";
1018 $output_rules .= "\n";
1021 ################################################################
1023 # Do any extra checking for GNU standards.
1024 sub check_gnu_standards
1026 &require_file ($GNU, 'ChangeLog');
1028 if ($relative_dir eq '.')
1030 # In top level (or only) directory.
1031 &require_file ($GNU, 'INSTALL', 'NEWS', 'README');
1035 # Do any extra checking for GNITS standards.
1036 sub check_gnits_standards
1040 ################################################################
1042 # Read Makefile.am and set up %contents. Simultaneously copy lines
1043 # from Makefile.am into $output_trailer or $output_vars as
1044 # appropriate. NOTE we put rules in the trailer section. We want
1045 # user rules to come after our generated stuff.
1048 local ($amfile) = @_;
1050 if (! open (AMFILE, $amfile))
1052 print STDERR "automake: couldn't open $amfile: $!\n";
1056 local ($saw_bk) = 0;
1057 local ($was_rule) = 0;
1058 local ($last_var_name) = '';
1068 $output_trailer .= $_ . "\n";
1072 $output_vars .= $_ . "\n";
1073 if (substr ($_, -1) eq "\\")
1075 $contents{$last_var_name} .= substr ($_, 0,
1080 $contents{$last_var_name} .= $_;
1084 elsif ($_ eq '@kr@')
1086 # Special case: this means we want automatic
1087 # de-ANSI-fication. FIXME think of a better way.
1088 $contents{'@kr@'} = 1;
1090 elsif (m/^ *([a-zA-Z_.][-.a-zA-Z0-9_.]*) *:/)
1094 # Value here doesn't matter; for targets we only note
1097 $output_trailer .= $_ . "\n";
1099 elsif (m/^ *([A-Za-z][A-Za-z0-9_]*)[ \t]*=[ \t]*(.*)$/)
1101 # Found a variable reference.
1103 $last_var_name = $1;
1104 if (substr ($2, -1) eq "\\")
1106 $contents{$1} = substr ($2, 0, length ($2) - 1);
1112 $output_vars .= $_ . "\n";
1116 # Special rule: if looking at a blank line, append it to
1117 # whatever we saw last.
1120 $output_trailer .= "\n";
1124 $output_vars .= "\n";
1129 # This isn't an error; it is probably a continued rule.
1130 # In fact, this is what we assume.
1131 $output_trailer .= $_ . "\n";
1134 $saw_bk = (substr ($_, -1) eq "\\");
1137 # Include some space after user code.
1138 $output_vars .= "\n";
1139 $output_trailer .= "\n";
1142 ################################################################
1144 sub initialize_global_constants
1146 # Associative array of standard directory names. Entry is TRUE if
1147 # corresponding directory should be installed during
1148 # 'install-exec' phase.
1166 # Helper text for dealing with man pages.
1167 $install_man_format =
1168 ' sect=@SECTION@; \\
1169 inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
1170 echo installing @MAN@ as $(mandir)/man$$sect/$$inst; \\
1171 $(INSTALL_DATA) $(srcdir)/@MAN@ $(mandir)/man$$sect/$$inst; \\
1172 if test -d $(mandir)/cat$$sect; then \\
1173 echo formatting @MAN@ as $(mandir)/cat$$sect/$$inst; \\
1174 $(NROFF) -man $(srcdir)/@MAN@ > $(mandir)/cat$$sect/$$inst; \\
1180 $uninstall_man_format =
1181 ' inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
1182 rm -f $(mandir)/man@SECTION@/$$inst $(mandir)/cat@SECTION@/$$inst
1185 # Commonly found files we look for and automatically include in
1189 "THANKS", "TODO", "README", "NEWS", "COPYING", "COPYING.LIB",
1190 "INSTALL", "ABOUT-NLS", "ChangeLog", "configure", "configure.in",
1191 "config.guess", "config.sub"
1194 # Commonly used files we auto-include, but only sometimes.
1197 "version.texi", "aclocal.m4", "acconfig.h", "config.h.top",
1198 "config.h.bot", "stamp-h.in", "mdate-sh", "ansi2knr.c",
1199 "ansi2knr.1", 'stamp-vti', "mkinstalldirs", "install-sh"
1203 --amdir=DIR directory storing config files
1204 --help print this help, then exit
1205 --include-deps include generated dependencies in Makefile.in
1206 --install-missing install missing standard files
1207 --output-dir=DIR put generated Makefile.in's into DIR
1208 --strictness=LEVEL set strictness level. LEVEL is normal, gnu, gnits
1209 --version print version number, then exit\n";
1212 # (Re)-Initialize per-Makefile.am variables.
1213 sub initialize_per_input
1215 # These two variables are used when generating each Makefile.in.
1216 # They hold the Makefile.in until it is ready to be printed.
1219 $output_trailer = '';
1221 # Suffixes found during a run.
1224 # This holds the contents of a Makefile.am, as parsed by
1228 # This holds the "relative directory" of the current Makefile.in.
1229 # Eg for src/Makefile.in, this is "src".
1232 # Directory where output files go. Actually, output files are
1233 # relative to this directory.
1234 $output_directory = '.';
1236 # This holds a list of files that are included in the
1240 # List of dependencies for the obvious targets.
1253 # These are pretty obvious, too. They are used to define the
1254 # SOURCES and OBJECTS variables.
1258 # TRUE if current directory holds any C source files. (Actually
1259 # holds object extension, but this information is encapsulated in
1260 # the function get_object_extension).
1261 $dir_holds_sources = '';
1263 # TRUE if install targets should work recursively.
1264 $recursive_install = 0;
1268 ################################################################
1270 # Return contents of a file from $am_dir.
1273 local ($basename) = @_;
1274 local ($file) = $am_dir . '/' . $basename . '.am';
1276 if (! open (FC_FILE, $file))
1278 print STDERR "automake: installation error: cannot open \"$file\"\n";
1282 # Lines starting with "##" are comments for developer use only.
1283 local ($result) = '';
1286 $result .= $_ unless ( m/^##/);
1292 # Return contents of some Makefile.am variable. Allow for AM_ style
1296 local ($varname) = @_;
1298 return (defined ($contents{'AM_' . $varname})
1299 ? $contents{'AM_' . $varname}
1300 : $contents{$varname});
1303 # Handle `where_HOW' variable magic. Does all lookups, generates
1304 # install code,and possibly generates code to define the primary
1305 # variable. The first argument is the name of the .am file to munge,
1306 # the second argument is the primary variable (eg HEADERS), and all
1307 # subsequent arguments are possible installation locations. FIXME
1308 # should scan all defined variables and do some error checking to
1309 # avoid typos (eg 'bni_PROGRAMS' should give error). Returns list of
1310 # all values of all _HOW targets.
1312 # FIXME this should be rewritten to be cleaner. It should be broken
1313 # up into multiple functions.
1315 # Usage is: am_install_var (OPTION..., file, HOW, where...)
1320 local ($do_all, $do_clean) = (1, 0);
1323 if ($args[0] eq '-clean')
1327 elsif ($args[0] eq '-no-all')
1331 elsif ($args[0] !~ /^-/)
1337 local ($file, $primary, @prefixes) = @args;
1340 local (@result) = ();
1342 local ($template) = &file_contents ($file);
1343 local ($clean_templ) = &file_contents ($file . '-clean');
1348 $one_name = $_ . '_' . $primary;
1349 if (defined $contents{$one_name})
1351 # Append actual contents to result.
1352 push (@result, split (/\s+/, $contents{$one_name}));
1356 ($munge = $clean_templ) =~ s/\@DIR\@/$_/g;
1357 $output_rules .= $munge;
1358 push (@clean, $_ . $primary);
1361 push (@used, '$(' . $one_name . ')');
1364 # Objects in noinst_FOO never get installed.
1368 ($munge = $template) =~ s/\@DIR\@/$_/g;
1369 $output_rules .= $munge;
1371 push (@uninstall, 'uninstall-' . $_ . $primary);
1372 push (@installdirs, '$(' . $_ . 'dir)');
1373 if ($exec_dir_p{$_})
1375 push (@install_exec, 'install-' . $_ . $primary);
1379 push (@install_data, 'install-' . $_ . $primary);
1384 if (! defined $contents{$primary} && $#used >= 0)
1387 $output_vars .= $primary . " = " . join (' ', @used) . "\n\n";
1390 # Push here because PRIMARY might be configure time determined.
1391 push (@all, '$(' . $primary . ')') if ($do_all && $#used >= 0);
1393 # Look for misspellings. It is an error to have a variable ending
1394 # in a "reserved" suffix whose prefix is unknown, eg
1396 local (%valid, $varname);
1397 grep ($valid{$_} = 0, @prefixes);
1398 foreach $varname (keys %contents)
1400 if ($varname =~ /^(.*)_$primary$/ && ! defined $valid{$1})
1402 &am_error ("invalid variable \"$varname\"");
1410 ################################################################
1412 # Verify that the file must exist in the current directory.
1413 # Usage: require_file (strictness, file)
1414 # strictness is the strictness level at which this file becomes
1418 local ($mystrict, $file) = @_;
1419 local ($fullfile) = $relative_dir . "/" . $file;
1423 &push_dist_common ($file);
1425 elsif ($install_missing && -f ($am_dir . '/' . $file))
1427 # Install the missing file. Symlink if we can, copy if we must.
1428 if ($symlink_exists)
1430 symlink ($am_dir . '/' . $file, $fullfile);
1434 system ('cp', $am_dir . '/' . $file, $fullfile);
1436 &am_error ("required file \"$fullfile\" not found; installing");
1438 elsif ($strictness >= $mystrict)
1440 # Only an error if strictness constraint violated.
1441 &am_error ("required file \"$fullfile\" not found");
1445 # Push a list of files onto dist_common.
1446 sub push_dist_common
1448 local (@files) = @_;
1451 foreach $file (@files)
1453 $dist_common{$file} = 1;
1466 elsif ($name eq 'gnits')
1468 $strictness = $GNITS;
1470 elsif ($name eq 'normal')
1472 $strictness = $NORMAL;
1476 print STDERR "automake: level \`$name' not recognized\n";
1482 ################################################################
1484 # Return directory name of file.
1490 ($sub = $file) =~ s,/+[^/]+,,g;
1502 local ($dirname) = @_;
1503 system ("mkdir", $dirname);
1506 ################################################################
1508 # Print an error message and set exit status.
1511 print STDERR "automake: ${am_file}.am: ", join (' ', @_), "\n";
1515 # Print usage information.
1518 print "Usage: automake [OPTION] ... [Makefile]...\n";
1520 print "\nFiles which are automatically distributed, if found:\n";
1521 $~ = "USAGE_FORMAT";
1522 local (@lcomm) = sort ((@common_files, @common_sometimes));
1524 while ($#lcomm >= 0)
1526 $one = shift (@lcomm);
1527 $two = shift (@lcomm);
1534 format USAGE_FORMAT =
1535 @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<