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.
31 $VERSION = "@VERSION@";
33 $am_dir = "@datadir@/@PACKAGE@";
36 $IGNORE_PATTERN = "^##([^#].*)?\$";
37 $WHITE_PATTERN = "^[ \t]*\$";
38 $COMMENT_PATTERN = "^#";
39 $RULE_PATTERN = "^([a-zA-Z_.][-.a-zA-Z0-9_.]*) *:";
40 $MACRO_PATTERN = "^([A-Za-z][A-Za-z0-9_]*)[ \t]*=[ \t]*(.*)\$";
43 # Constants to define the "strictness" level.
50 # Variables global to entire run.
53 $strictness = $NORMAL;
55 # Name of strictness level.
56 $strictness_name = 'normal';
58 # This is TRUE if GNU make specific automatic dependency generation
59 # code should be included in generated Makefile.in.
60 $use_dependencies = 1;
62 # This holds our (eventual) exit status. We don't actually exit until
63 # we have processed all input files.
66 # From the Perl manual.
67 $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
69 # TRUE if missing standard files should be installed.
74 &initialize_global_constants;
77 @input_files = &parse_arguments (@ARGV);
79 # Now do all the work on each file.
80 foreach $am_file (@input_files)
82 if (! -f ($am_file . '.am'))
84 &am_error ('no such file');
88 &generate_makefile ($am_file);
95 ################################################################
100 local (@arglist) = @_;
105 if ($arglist[0] eq "--version")
107 print "Automake version $VERSION\n";
110 elsif ($arglist[0] eq "--help")
114 elsif ($arglist[0] =~ /^--amdir=(.+)$/)
118 elsif ($arglist[0] eq '--amdir')
120 &require_argument (@arglist);
122 $am_dir = $arglist[0];
124 elsif ($arglist[0] =~ /^--strictness=(.+)$/)
126 &set_strictness ($1);
128 elsif ($arglist[0] eq '--gnu')
130 &set_strictness ('gnu');
132 elsif ($arglist[0] eq '--gnits')
134 &set_strictness ('gnits');
136 elsif ($arglist[0] eq '--strictness')
138 &require_argument (@arglist);
140 &set_strictness ($arglist[0]);
142 elsif ($arglist[0] eq '--include-deps')
144 $use_dependencies = 0;
146 elsif ($arglist[0] =~ /^--output-dir=(.*)$/)
148 # Set output directory.
149 $output_directory = $1;
151 elsif ($arglist[0] eq '--output-dir')
153 &require_argument (@arglist);
155 $output_directory = $arglist[0];
157 elsif ($arglist[0] eq '--install-missing')
159 $install_missing = 1;
161 elsif ($arglist[0] eq '--')
163 # Stop option processing.
165 push (@make_list, @arglist);
168 elsif ($arglist[0] =~ /^-/)
170 die "automake: unrecognized option -- \`$arglist[0]'\n";
174 push (@make_list, $arglist[0]);
182 # Look around for some files.
183 push (@make_list, 'Makefile') if -f 'Makefile.am';
185 foreach (<*/Makefile.am>)
188 push (@make_list, $_);
191 die "automake: no \"Makefile.am\" found or specified\n"
198 # Ensure argument exists, or die.
201 local ($arg, @arglist) = @_;
202 die "automake: no argument given for option \`$arg'\n"
206 ################################################################
208 # Generate a Makefile.in given the name of the corresponding Makefile.
209 sub generate_makefile
211 local ($makefile) = @_;
213 print "creating ", $makefile, ".in\n";
215 &initialize_per_input;
216 $relative_dir = &dirname ($makefile);
217 # FIXME with new 'dist' target, don't need Makefile.in. Probably
218 # should remove it here.
219 &push_dist_common ('Makefile.in', 'Makefile.am');
220 push (@sources, '$(SOURCES)') if defined $contents{'SOURCES'};
221 push (@objects, '$(OBJECTS)') if defined $contents{'OBJECTS'};
223 # This is always the default target. This gives us freedom to do
224 # things in whatever order is convenient.
225 $output_rules .= "default: all\n\n";
226 push (@phony, 'default');
228 &read_am_file ($makefile . '.am');
230 # Check first, because we might modify some state.
231 &check_gnu_standards;
232 &check_gnits_standards;
238 # Re-init SOURCES and OBJECTS. FIXME other code shouldn't depend
239 # on this (but currently does).
240 $contents{'SOURCES'} = join (' ', @sources);
241 $contents{'OBJECTS'} = join (' ', @objects);
251 &handle_dependencies;
253 &handle_merge_targets;
258 if (! -d ($output_directory . '/' . $relative_dir))
260 &mkdir ($output_directory . '/' . $relative_dir);
262 if (! open (GM_FILE, "> " . $output_directory . '/' . $makefile . ".in"))
264 warn "automake: ${am_file}.in: cannot open: $!\n";
269 print GM_FILE $output_vars;
270 print GM_FILE $output_rules;
271 print GM_FILE $output_trailer;
276 ################################################################
278 # Return object extension. Just once, put some code into the output.
279 sub get_object_extension
281 if (! $dir_holds_sources)
285 $output_vars .= &file_contents ('compile-vars');
286 $output_rules .= &file_contents ('compile');
287 &push_phony_cleaners ('compile');
289 # Check for automatic de-ANSI-fication.
290 $dir_holds_sources = '.o';
291 push (@suffixes, '.c', '.o');
292 push (@clean, 'compile');
294 if (defined $contents{'@kr@'})
296 $dir_holds_sources = '.$(kr)o';
297 push (@suffixes, '._c', '._o');
299 &require_file ($NORMAL, 'ansi2knr.c', 'ansi2knr.1');
301 $output_vars .= &file_contents ('kr-vars');
302 $output_rules .= &file_contents ('compile-kr');
303 $output_rules .= &file_contents ('clean-kr');
306 &push_phony_cleaners ('kr');
309 return $dir_holds_sources;
312 # Handle SOURCE->OBJECT transform for one program or library.
313 sub handle_source_transform
315 local ($one_file, $obj) = @_;
317 # Look for file_SOURCES and file_OBJECTS.
318 if (defined $contents{$one_file . "_SOURCES"})
320 if (! defined $contents{$one_file . "_OBJECTS"})
322 # Turn sources into objects.
323 local (@files) = split (/\s+/, $contents{$one_file . "_SOURCES"});
324 # Ugh: Perl syntax vs Emacs.
325 local ($krc1, $krc2) = ('\.\$\{kr\}c', '\.\$\(kr\)c');
326 local (@result) = ();
331 # Automatically include generated .c file in
333 &push_dist_common ($1 . '.c');
336 # Transform source files into .o files.
340 s/\.[cCmylfs]$/$obj/g;
345 &pretty_print ($one_file . "_OBJECTS =", '', @result);
349 &am_error ($one_file . '_OBJECTS', 'should not be defined');
352 push (@sources, '$(' . $one_file . "_SOURCES)");
353 push (@objects, '$(' . $one_file . "_OBJECTS)");
357 $output_vars .= ($one_file . "_SOURCES = " . $one_file . ".c\n"
358 . $one_file . "_OBJECTS = ". $one_file
360 push (@sources, $one_file . '.c');
361 push (@objects, $one_file . $obj);
364 if (defined $contents{'CONFIG_HEADER'})
366 $output_rules .= ('$(' . $one_file . "_OBJECTS): "
367 . $contents{'CONFIG_HEADER'} . "\n");
376 local (@proglist) = &am_install_var ('-clean',
377 'programs', 'PROGRAMS',
378 'bin', 'sbin', 'libexec', 'noinst');
379 # FIXME error if PROGRAMS defined but no blah_PROGRAMS defined.
380 return if ! @proglist;
382 local ($obj) = &get_object_extension;
383 local ($one_file, $munge);
385 foreach $one_file (@proglist)
387 &handle_source_transform ($one_file, $obj);
389 if (! defined $contents{$one_file . "_LDADD"})
391 # User didn't define prog_LDADD override. So do it.
392 $output_vars .= $one_file . '_LDADD = $(LDADD)' . "\n";
396 &file_contents_with_transform ('s/\@PROGRAM\@/' . $one_file
404 local (@liblist) = &am_install_var ('-no-all', '-clean',
405 'libraries', 'LIBRARIES',
406 'lib', 'pkglib', 'noinst');
407 # FIXME error if LIBRARIES defined but no blah_LIBRARIES defined.
408 return if ! @liblist;
410 # Generate _LIBFILES variables. Too bad we can't do this in
412 local ($onedir, $onelib);
414 foreach $onedir ('lib', 'pkglib', 'noinst')
416 if (defined $contents{$onedir . '_LIBRARIES'})
419 foreach $onelib (split (/\s+/, $contents{$onedir . '_LIBRARIES'}))
421 push (@outlist, 'lib' . $onelib . '.a');
423 &pretty_print ($onedir . '_LIBFILES =', '', @outlist);
426 push (@all, '$(LIBFILES)');
428 local ($obj) = &get_object_extension;
430 foreach $onelib (@liblist)
432 if (! defined $contents{$onelib . '_LIBADD'})
434 # Generate support for conditional object inclusion in
436 $output_vars .= $onelib . "_LIBADD =\n";
439 &handle_source_transform ($onelib, $obj);
442 &file_contents_with_transform ('s/\@LIBRARY\@/' . $onelib . '/go',
446 # Turn "foo" into "libfoo.a" and include macro definition.
447 grep (($_ = 'lib' . $_ . '.a') && 0, @liblist);
449 if (! defined $contents{'LIBFILES'})
451 &pretty_print ('LIBFILES = ', '', @liblist);
453 $output_vars .= &file_contents ('libraries-vars');
459 &am_install_var ('-clean',
460 'scripts', 'SCRIPTS',
461 'bin', 'sbin', 'libexec', 'noinst');
464 # Handle all Texinfo source.
467 local ($texis) = &am_variable ('TEXINFOS');
470 local (@texis) = split (/\s+/, $texis);
473 &am_error ('sorry, only one file allowed in `TEXINFOS\'');
478 ($infobase = $texis[0]) =~ s/\.texi$//;
480 # If 'version.texi' is referenced by input file, then include
481 # automatic versioning capability.
482 system ("grep version.texi " . $relative_dir . "/" . $texis[0]
483 . " > /dev/null 2>&1");
487 push (@texis, 'version.texi');
488 &push_dist_common ('version.texi', 'stamp-vti');
489 push (@clean, 'vti');
492 &file_contents_with_transform ('s/\@TEXI\@/' . $texis[0] . '/go',
494 &push_phony_cleaners ('vti');
496 &require_file ($NORMAL, 'mdate-sh');
499 # If user specified file_TEXINFOS, then use that as explicit
501 if (defined $contents{$infobase . "_TEXINFOS"})
503 push (@texis, "\$" . $infobase . '_TEXINFOS');
504 &push_dist_common ("\$" . $infobase . '_TEXINFOS');
509 $output_rules .= ($infobase . ".info: "
510 . join (' ', @texis) . "\n\n");
514 $output_vars .= &file_contents ('texinfos-vars');
515 $output_rules .= &file_contents ('texinfos');
516 push (@phony, 'install-info', 'uninstall-info');
520 &file_contents_with_transform ('s/\@TEXI\@/' . $infobase . '/go',
522 &push_phony_cleaners ('info');
524 push (@suffixes, '.texi', '.info', '.dvi');
525 push (@uninstall, 'uninstall-info');
526 push (@clean, 'info');
527 push (@info, '$(INFO_DEPS)');
528 push (@dvi, '$(DVIS)');
529 push (@installdirs, '$(infodir)');
530 # Make sure documentation is made and installed first.
531 unshift (@install_data, 'install-info');
532 unshift (@all, 'info');
534 $output_vars .= ("INFOS = " . $infobase . ".info*\n"
535 . "INFO_DEPS = " . $infobase . ".info\n"
536 . "DVIS = " . $infobase . ".dvi\n\n");
538 # Do some error checking.
539 &require_file ($NORMAL, 'texinfo.tex');
542 # Handle any man pages.
545 return if ! defined $contents{'MANS'};
547 # We generate the manpage install code by hand to avoid the use of
548 # basename in the generated Makefile.
549 local (@mans) = split (/\s+/, $contents{'MANS'});
550 local (%sections, %inames, %secmap, %fullsecmap);
553 # FIXME: statement without effect:
554 /^(.*)\.([0-9])([a-z]*)$/;
558 $fullsecmap{$1} = $2 . $3;
561 # Generate list of install dirs.
562 $output_rules .= "install-man:\n";
563 foreach (keys %sections)
565 push (@installdirs, '$(mandir)/man' . $_);
566 $output_rules .= ("\t" . '$(top_srcdir)/mkinstalldirs $(mandir)/man'
569 push (@phony, 'install-man');
571 # Generate install target.
573 foreach $key (keys %inames)
575 $_ = $install_man_format;
576 s/\@SECTION\@/$secmap{$key}/g;
577 s/\@MAN\@/$inames{$key}/g;
578 s/\@FULLSECT\@/$fullsecmap{$key}/g;
579 s/\@MANBASE\@/$key/g;
582 $output_rules .= "\n";
584 $output_rules .= "uninstall-man:\n";
585 foreach $key (keys %inames)
587 $_ = $uninstall_man_format;
588 s/\@SECTION\@/$secmap{$key}/g;
589 s/\@MAN\@/$inames{$key}/g;
590 s/\@FULLSECT\@/$fullsecmap{$key}/g;
591 s/\@MANBASE\@/$key/g;
594 $output_rules .= "\n";
595 push (@phony, 'uninstall-man');
597 $output_vars .= &file_contents ('mans-vars');
599 push (@install_data, 'install-man');
600 push (@uninstall, 'uninstall-man');
601 push (@all, '$(MANS)');
604 # Handle DATA variables.
607 &am_install_var ('data', 'DATA', 'data', 'sysconf',
608 'sharedstate', 'localstate', 'pkgdata',
615 local ($tagging) = 0;
617 push (@phony, 'tags');
618 if (defined $contents{'SUBDIRS'})
620 $output_rules .= &file_contents ('tags');
623 elsif ($dir_holds_sources || defined $contents{'ETAGS_ARGS'})
625 $output_rules .= &file_contents ('tags-subd');
632 $output_rules .= &file_contents ('tags-clean');
633 push (@clean, 'tags');
634 &push_phony_cleaners ('tags');
638 # Every Makefile must define some sort of TAGS rule.
639 # Otherwise, it would be possible for a top-level "make TAGS"
640 # to fail because some subdirectory failed.
641 $output_rules .= "tags: TAGS\nTAGS:\n\n";
645 # Handle 'dist' target.
648 # Look for common files that should be included in distribution.
650 foreach $cfile (@common_files)
652 if (-f ($relative_dir . "/" . $cfile))
654 &push_dist_common ($cfile);
658 # Keys of %dist_common are names of files to distributed. We put
659 # README first because it then becomes easier to make a
660 # Usenet-compliant shar file (in these, README must be first).
661 # FIXME do more ordering of files here.
663 if (defined $dist_common{'README'})
665 push (@coms, 'README');
666 undef $dist_common{'README'};
668 push (@coms, keys %dist_common);
670 &pretty_print ("DIST_COMMON =", '', @coms);
671 $output_vars .= "\n";
674 $output_vars .= &file_contents ('dist-vars');
676 # Initialization; only at top level.
677 if ($relative_dir eq '.')
683 distdir = $(PACKAGE)-$(VERSION)
686 # Create dist directory.
687 . ' rm -rf $(distdir)
690 # We need an absolute path for --output-dir. Thus the
692 . ' distdir=`cd $(distdir) && pwd` \\
694 && automake --include-deps --output-dir=$$distdir --strictness='
695 # Set strictness of output.
696 . $strictness_name . "\n"
704 "\nsubdir = " . $relative_dir . "\n"
705 . 'distdir = $(PACKAGE)-$(VERSION)/$(subdir)
711 # In loop, test for file existence because sometimes a file gets
712 # included in DISTFILES twice. For example this happens when a
713 # single source file is used in building more than one program.
714 # Also, there are situations in which "ln" can fail. For instance
715 # a file to distribute could actually be a cross-filesystem
716 # symlink -- this can easily happen if "gettextize" was run on the
718 $output_rules .= ' @for file in $(DISTFILES); do \\
719 test -f $(distdir)/$$file \\
720 || ln $(srcdir)/$$file $(distdir)/$$file \\
721 || cp -p $(srcdir)/$$file $(distdir)/$$file; \\
725 # If top level, create all dist subdirectories and do recursive
727 if ($relative_dir eq '.')
729 # Test for directory existence here because previous automake
730 # invocation might have created some directories.
731 $output_rules .= ' for subdir in $(SUBDIRS); do \\
732 test -d $(distdir)/$$subdir \\
733 || mkdir $(distdir)/$$subdir \\
735 chmod 777 $(distdir)/$$subdir; \\
736 (cd $$subdir && $(MAKE) $@) || exit 1; \\
741 # Make verbatim copies of some subdirectories if required. This
742 # is a hack which might go away.
743 if (defined $contents{'DIST_SUBDIRS'})
745 $output_rules .= ' @for dir in $(DIST_SUBDIRS); do \\
746 echo copying directory $$dir; \\
747 tar -chf - $$dir | (cd $(distdir) && tar -xBpf -); \\
753 if ($relative_dir eq '.')
755 $output_rules .= ' chmod -R a+r $(distdir)
756 tar -chozf $(distdir).tar.gz $(distdir)
761 push (@phony, 'dist');
764 # Handle auto-dependency code.
765 sub handle_dependencies
767 if ($use_dependencies)
769 # Include GNU-make-specific auto-dep code.
770 if ($dir_holds_sources)
772 $output_rules .= &file_contents ('depend');
777 # Include any auto-generated deps that are present.
778 if (-d ($relative_dir . "/.deps") && -f ($relative_dir . "/.deps/.P"))
781 local ($gpat) = $relative_dir . "/.deps/*.P";
783 foreach $depfile (<${gpat}>)
785 if (! open (DEP_FILE, $depfile))
787 &am_error ("couldn't open $depfile", $!);
792 $output_rules .= join ('', <DEP_FILE>);
797 $output_rules .= "\n";
802 # Handle subdirectories.
805 return if ! defined $contents{'SUBDIRS'};
807 $output_rules .= &file_contents ('subdirs');
809 # Push a bunch of phony targets.
811 foreach $phonies ('-data', '-exec', 'dirs')
813 push (@phony, 'install' . $phonies . '-recursive');
814 push (@phony, 'uninstall' . $phonies . '-recursive');
816 foreach $phonies ('all', 'check', 'installcheck', 'info', 'dvi')
818 push (@phony, $phonies . '-recursive');
820 &push_phony_cleaners ('recursive');
822 push (@all, "all-recursive");
823 push (@check, "check-recursive");
824 push (@installcheck, "installcheck-recursive");
825 push (@info, "info-recursive");
826 push (@dvi, "dvi-recursive");
828 $recursive_install = 1;
831 # Handle remaking and configure stuff.
834 if ($relative_dir ne '.')
837 $output_rules .= &file_contents ('remake-subd');
841 &require_file ($NORMAL, 'configure.in');
842 # FIXME require 'configure'? What if autoconf hasn't been run
845 if (defined $contents{'SUBDIRS'})
847 # We required AC_PROG_MAKE_SET.
848 system ("grep AC_PROG_MAKE_SET configure.in > /dev/null 2>&1");
852 &am_error ("AC_PROG_MAKE_SET must be used in configure.in");
858 $output_vars .= "ACLOCAL = aclocal.m4\n";
859 &push_dist_common ('aclocal.m4');
861 $output_rules .= &file_contents ('remake');
863 # Look for some files we need.
864 &require_file ($NORMAL, 'install-sh', 'mkinstalldirs');
867 if (defined $contents{'CONFIG_HEADER'}
868 && $contents{'CONFIG_HEADER'} !~ /\//)
870 # Header defined and in this directory.
873 $output_vars .= "ACCONFIG = acconfig.h\n";
874 &push_dist_common ('acconfig.h');
876 if (-f 'config.h.top')
878 $output_vars .= "CONFIG_TOP = config.h.top\n";
879 &push_dist_common ('config.h.top');
881 if (-f 'config.h.bot')
883 $output_vars .= "CONFIG_BOT = config.h.bot\n";
884 &push_dist_common ('config.h.bot');
887 &push_dist_common ('stamp-h.in', $contents{'CONFIG_HEADER'} . '.in');
889 $output_rules .= &file_contents ('remake-hdr');
896 &am_install_var ('data', 'HEADERS', 'include',
897 'oldinclude', 'pkginclude',
901 # Handle footer elements.
904 if ($contents{'SOURCES'})
906 &pretty_print ('SOURCES =', '', split (/\s+/, $contents{'SOURCES'}));
908 if ($contents{'OBJECTS'})
910 &pretty_print ('OBJECTS =', '', split (/\s+/, $contents{'OBJECTS'}));
912 if ($contents{'SOURCES'} || $contents{'OBJECTS'})
914 $output_vars .= "\n";
917 if (defined $contents{'SUFFIXES'})
919 push (@suffixes, '$(SUFFIXES)');
922 $output_trailer .= ".SUFFIXES:\n";
925 $output_trailer .= ".SUFFIXES: " . join (' ', @suffixes) . "\n";
927 $output_trailer .= &file_contents ('footer');
930 # Deal with installdirs target.
931 sub handle_installdirs
933 # GNU Makefile standards recommend this.
934 $output_rules .= ("installdirs:"
935 . ($recursive_install
936 ? " installdirs-recursive\n"
938 push (@phony, 'installdirs');
941 &pretty_print_rule ("\t\$(top_srcdir)/mkinstalldirs ", "\t\t",
944 $output_rules .= "\n";
947 # There are several targets which need to be merged. This is because
948 # their complete definition is compiled from many parts. Note that we
949 # avoid double colon rules, otherwise we'd use them instead.
950 sub handle_merge_targets
952 &do_one_merge_target ('all', @all);
953 &do_one_merge_target ('info', @info);
954 &do_one_merge_target ('dvi', @dvi);
956 if (! defined $contents{'SUBDIRS'} || $relative_dir ne '.')
958 # 'check' must depend on 'all', but not at top level.
959 push (@check, 'all');
961 &do_one_merge_target ('check', @check);
962 &do_one_merge_target ('installcheck', @installcheck);
964 # Handle the various install targets specially. We do this so
965 # that (eg) "make install-exec" will run "install-exec-recursive"
966 # if required, but "make install" won't run it twice. Step one is
967 # to see if the user specified local versions of any of the
969 if (defined $contents{'install-exec-local'})
971 push (@install_exec, 'install-exec-local');
973 if (defined $contents{'install-data-local'})
975 push (@install_data, 'install-data-local');
977 if (defined $contents{'uninstall-local'})
979 push (@uninstall, 'uninstall-local');
982 if (defined $contents{'install-local'})
984 &am_error ("use \`install-data' or \`install-exec', not \`install'");
987 # Step two: if we are doing recursive makes, write out the
990 if ($recursive_install)
992 push (@install, 'install-recursive');
993 push (@uninstall, 'uninstall-recursive');
997 $output_rules .= ('install-exec-am: '
998 . join (' ', @install_exec)
1000 @install_exec = ('install-exec-recursive', 'install-exec-am');
1001 push (@install, 'install-exec-am');
1002 push (@phony, 'install-exec-am');
1006 $output_rules .= ('install-data-am: '
1007 . join (' ', @install_data)
1009 @install_data = ('install-data-recursive', 'install-data-am');
1010 push (@install, 'install-data-am');
1011 push (@phony, 'install-data-am');
1015 $output_rules .= ('uninstall-am: '
1016 . join (' ', @uninstall)
1018 @uninstall = ('uninstall-recursive', 'uninstall-am');
1019 push (@phony, 'uninstall-am');
1023 # Step three: print definitions users can use.
1026 $output_rules .= ("install-exec: "
1027 . join (' ', @install_exec)
1029 push (@install, 'install-exec') if !$recursive_install;
1030 push (@phony, 'install-exec');
1034 $output_rules .= ("install-data: "
1035 . join (' ', @install_data)
1037 push (@install, 'install-data') if !$recursive_install;
1038 push (@phony, 'install-data');
1041 # If no dependencies for 'install', add 'all'. Why? That way
1042 # "make install" at top level of distclean'd distribution won't
1043 # fail because stuff in 'lib' fails to build.
1044 push (@install, 'all') if ! @install;
1045 $output_rules .= ('install: '
1046 . join (' ', @install)
1047 # Use "@:" as empty command so nothing prints.
1051 . join (' ', @uninstall)
1053 push (@phony, 'install', 'uninstall');
1056 # Helper for handle_merge_targets.
1057 sub do_one_merge_target
1059 local ($name, @values) = @_;
1061 if (defined $contents{$name . '-local'})
1063 # User defined local form of target. So include it.
1064 push (@values, $name . '-local');
1065 push (@phony, $name . '-local');
1068 $output_rules .= $name . ":";
1071 $output_rules .= ' ' . join (' ', @values);
1073 $output_rules .= "\n\n";
1074 push (@phony, $name);
1077 # Handle all 'clean' targets.
1080 push (@clean, 'generic');
1081 $output_rules .= &file_contents ('clean');
1082 &push_phony_cleaners ('generic');
1084 local ($target) = $recursive_install ? 'clean-am' : 'clean';
1085 &do_one_clean_target ($target, 'mostly', '', @clean);
1086 &do_one_clean_target ($target, '', 'mostly', @clean);
1087 &do_one_clean_target ($target, 'dist', '', @clean);
1088 &do_one_clean_target ($target, 'maintainer-', 'dist', @clean);
1090 push (@phony, 'clean', 'mostlyclean', 'distclean', 'maintainer-clean');
1093 if ($recursive_install)
1095 @deps = ('am', 'recursive');
1096 &do_one_clean_target ('', 'mostly', '', @deps);
1097 &do_one_clean_target ('', '', '', @deps);
1098 &do_one_clean_target ('', 'dist', '', @deps);
1099 &do_one_clean_target ('', 'maintainer-', '', @deps);
1103 # Helper for handle_clean.
1104 sub do_one_clean_target
1106 local ($target, $name, $last_name, @deps) = @_;
1108 # Special case: if target not passed, then don't generate
1109 # dependency on next "lower" clean target (eg no
1110 # clean<-mostlyclean derivation). In this case the target is
1111 # implicitly known to be 'clean'.
1112 local ($flag) = $target;
1113 $target = 'clean' if ! $flag;
1115 grep (($_ = $name . 'clean-' . $_) && 0, @deps);
1118 if ($last_name || $name ne 'mostly')
1120 push (@deps, $last_name . $target . " ");
1123 &pretty_print_rule ($name . $target . ": ", '', @deps);
1125 # FIXME shouldn't we really print these messages before running
1127 if ($name . $target eq 'maintainer-clean')
1129 # Print a special warning.
1131 ("\t\@echo \"This command is intended for maintainers to use;\"\n"
1132 . "\t\@echo \"it deletes files that may require special "
1133 . "tools to rebuild.\"\n"
1134 . "\trm -f config.status\n");
1136 elsif ($name . $target eq 'distclean')
1138 $output_rules .= "\trm -f config.status\n";
1140 $output_rules .= "\n";
1143 # Handle .PHONY target.
1146 &pretty_print_rule ('.PHONY:', '', @phony);
1147 $output_rules .= "\n";
1150 ################################################################
1152 # Do any extra checking for GNU standards.
1153 sub check_gnu_standards
1155 &require_file ($GNU, 'ChangeLog');
1157 if ($relative_dir eq '.')
1159 # In top level (or only) directory.
1160 &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
1165 # Do any extra checking for GNITS standards.
1166 sub check_gnits_standards
1168 if ($strictness >= $GNITS && -f $relative_dir . '/COPYING.LIB')
1171 ("\`${relative_dir}/COPYING.LIB' disallowed by Gnits standards");
1174 if ($relative_dir eq '.')
1176 # In top level (or only) directory.
1177 &require_file ($GNITS, 'THANKS');
1181 ################################################################
1183 # Pretty-print something. HEAD is what should be printed at the
1184 # beginning of the first line, FILL is what should be printed at the
1185 # beginning of every subsequent line.
1186 sub pretty_print_internal
1188 local ($head, $fill, @values) = @_;
1190 local ($column) = length ($head);
1191 local ($result) = $head;
1196 # "71" because we also print a space.
1197 if ($column + length ($_) > 71)
1199 $result .= " \\\n" . $fill;
1200 $column = length ($fill);
1204 $result .= ' ' unless ($bol);
1206 $column += length ($_) + 1;
1214 # Pretty-print something and append to output_vars.
1217 $output_vars .= &pretty_print_internal (@_);
1220 # Pretty-print something and append to output_rules.
1221 sub pretty_print_rule
1223 $output_rules .= &pretty_print_internal (@_);
1227 ################################################################
1229 # Read Makefile.am and set up %contents. Simultaneously copy lines
1230 # from Makefile.am into $output_trailer or $output_vars as
1231 # appropriate. NOTE we put rules in the trailer section. We want
1232 # user rules to come after our generated stuff.
1235 local ($amfile) = @_;
1237 local ($header_vars) = &file_contents ('header-vars');
1239 open (AM_FILE, $amfile) || die "automake: couldn't open $amfile: $!\n";
1241 $output_vars .= ("# Makefile.in generated automatically by automake "
1242 . $VERSION . " from Makefile.am\n");
1244 # Generate copyright for generated Makefile.in.
1245 $output_vars .= $gen_copyright;
1247 local ($saw_bk) = 0;
1248 local ($was_rule) = 0;
1249 local ($spacing) = '';
1250 local ($comment) = '';
1251 local ($last_var_name) = '';
1255 if (/$IGNORE_PATTERN/o)
1257 # Merely delete comments beginning with two hashes.
1259 elsif (/$WHITE_PATTERN/o)
1261 # Stick a single white line before the incoming macro or rule.
1264 elsif (/$COMMENT_PATTERN/o)
1266 # Stick comments before the incoming macro or rule.
1267 $comment .= $spacing . $_;
1276 $output_vars .= $comment . "\n" . $header_vars;
1282 if (/$IGNORE_PATTERN/o)
1284 # Merely delete comments beginning with two hashes.
1286 elsif (/$WHITE_PATTERN/o)
1288 # Stick a single white line before the incoming macro or rule.
1291 elsif (/$COMMENT_PATTERN/o)
1293 # Stick comments before the incoming macro or rule.
1294 $comment .= $spacing . $_;
1301 $output_trailer .= $_;
1308 # Chop newline and backslash if this line is
1309 # continued. FIXME maybe ensure trailing whitespace
1313 $contents{$last_var_name} .= $_;
1316 elsif (/$RULE_PATTERN/o)
1318 # warn "** Saw rule .$1.\n";
1321 # Value here doesn't matter; for targets we only note
1324 $output_trailer .= $comment . $spacing . $_;
1325 $comment = $spacing = '';
1328 elsif (/$MACRO_PATTERN/o)
1330 # warn "** Saw macro .$1.\n";
1331 # Found a macro definition.
1333 $last_var_name = $1;
1334 if (substr ($2, -1) eq "\\")
1336 $contents{$1} = substr ($2, 0, length ($2) - 1);
1342 $output_vars .= $comment . $spacing . $_;
1343 $comment = $spacing = '';
1346 elsif ($_ eq "\@kr\@\n")
1348 # Special case: this means we want automatic
1349 # de-ANSI-fication. FIXME think of a better way.
1350 $contents{'@kr@'} = 1;
1354 # This isn't an error; it is probably a continued rule.
1355 # In fact, this is what we assume.
1357 $output_trailer .= $comment . $spacing . $_;
1358 $comment = $spacing = '';
1365 $output_trailer .= $comment;
1368 ################################################################
1370 sub initialize_global_constants
1372 # Associative array of standard directory names. Entry is TRUE if
1373 # corresponding directory should be installed during
1374 # 'install-exec' phase.
1392 # Helper text for dealing with man pages.
1393 $install_man_format =
1394 ' @sect=@SECTION@; \\
1395 inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
1396 echo installing @MAN@ as $(mandir)/man$$sect/$$inst; \\
1397 $(INSTALL_DATA) $(srcdir)/@MAN@ $(mandir)/man$$sect/$$inst
1400 $uninstall_man_format =
1401 ' inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
1402 rm -f $(mandir)/man@SECTION@/$$inst
1405 # Commonly found files we look for and automatically include in
1409 "README", "THANKS", "TODO", "NEWS", "COPYING", "COPYING.LIB",
1410 "INSTALL", "ABOUT-NLS", "ChangeLog", "configure", "configure.in",
1411 "config.guess", "config.sub", "AUTHORS", "BACKLOG", "ABOUT-GNU"
1414 # Commonly used files we auto-include, but only sometimes.
1417 "version.texi", "aclocal.m4", "acconfig.h", "config.h.top",
1418 "config.h.bot", "stamp-h.in", "mdate-sh", "ansi2knr.c",
1419 "ansi2knr.1", 'stamp-vti', "mkinstalldirs", "install-sh"
1423 --amdir=DIR directory storing config files
1424 --gnits same as --strictness=gnits
1425 --gnu same as --strictness=gnu
1426 --help print this help, then exit
1427 --include-deps include generated dependencies in Makefile.in
1428 --install-missing install missing standard files
1429 --output-dir=DIR put generated Makefile.in's into DIR
1430 --strictness=LEVEL set strictness level. LEVEL is normal, gnu, gnits
1431 --version print version number, then exit\n";
1433 # Copyright on generated Makefile.ins.
1435 # Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
1436 # This Makefile.in is free software; the Free Software Foundation
1437 # gives unlimited permission to copy, distribute and modify it.
1441 # (Re)-Initialize per-Makefile.am variables.
1442 sub initialize_per_input
1444 # These two variables are used when generating each Makefile.in.
1445 # They hold the Makefile.in until it is ready to be printed.
1448 $output_trailer = '';
1450 # Suffixes found during a run.
1453 # This holds the contents of a Makefile.am, as parsed by
1457 # This holds the "relative directory" of the current Makefile.in.
1458 # Eg for src/Makefile.in, this is "src".
1461 # Directory where output files go. Actually, output files are
1462 # relative to this directory.
1463 $output_directory = '.';
1465 # This holds a list of files that are included in the
1469 # List of dependencies for the obvious targets.
1484 # These are pretty obvious, too. They are used to define the
1485 # SOURCES and OBJECTS variables.
1489 # TRUE if current directory holds any C source files. (Actually
1490 # holds object extension, but this information is encapsulated in
1491 # the function get_object_extension).
1492 $dir_holds_sources = '';
1494 # TRUE if install targets should work recursively.
1495 $recursive_install = 0;
1499 ################################################################
1501 # Return contents of a file from $am_dir, automatically skipping
1502 # macros or rules which are already known. Runs command on each line
1503 # as it is read; this command can modify $_.
1504 sub file_contents_with_transform
1506 local ($command, $basename) = @_;
1507 local ($file) = $am_dir . '/' . $basename . '.am';
1509 open (FC_FILE, $file)
1510 || die "automake: installation error: cannot open \"$file\"\n";
1512 local ($was_rule) = 0;
1513 local ($result_vars) = '';
1514 local ($result_rules) = '';
1515 local ($comment) = '';
1516 local ($spacing) = "\n";
1517 local ($skipping) = 0;
1523 if (/$IGNORE_PATTERN/o)
1525 # Merely delete comments beginning with two hashes.
1527 elsif (/$WHITE_PATTERN/o)
1529 # Stick a single white line before the incoming macro or rule.
1532 elsif (/$COMMENT_PATTERN/o)
1534 # Stick comments before the incoming macro or rule.
1535 $comment .= $spacing . $_;
1542 $result_rules .= $_ if ! $skipping;
1546 $result_vars .= $_ if ! $skipping;
1550 elsif (/$RULE_PATTERN/o)
1552 # warn "** Found rule .$1.\n";
1555 $skipping = defined $contents{$1};
1556 # warn "** Skip $skipping\n" if $skipping;
1557 $result_rules .= $comment . $spacing . $_ if ! $skipping;
1558 $comment = $spacing = '';
1561 elsif (/$MACRO_PATTERN/o)
1563 # warn "** Found macro .$1.\n";
1564 # Found a variable reference.
1566 $skipping = defined $contents{$1};
1567 # warn "** Skip $skipping\n" if $skipping;
1568 $result_vars .= $comment . $spacing . $_ if ! $skipping;
1569 $comment = $spacing = '';
1574 # This isn't an error; it is probably a continued rule.
1575 # In fact, this is what we assume.
1577 $result_rules .= $comment . $spacing . $_ if ! $skipping;
1578 $comment = $spacing = '';
1584 return $result_vars . $result_rules . $comment;
1587 # Like file_contents_with_transform, but no transform.
1590 return &file_contents_with_transform ('', @_);
1593 # Return contents of some Makefile.am variable. Allow for AM_ style
1597 local ($varname) = @_;
1599 return (defined $contents{'AM_' . $varname}
1600 ? $contents{'AM_' . $varname}
1601 : $contents{$varname});
1604 # Handle `where_HOW' variable magic. Does all lookups, generates
1605 # install code,and possibly generates code to define the primary
1606 # variable. The first argument is the name of the .am file to munge,
1607 # the second argument is the primary variable (eg HEADERS), and all
1608 # subsequent arguments are possible installation locations. Returns
1609 # list of all values of all _HOW targets.
1611 # FIXME this should be rewritten to be cleaner. It should be broken
1612 # up into multiple functions.
1614 # Usage is: am_install_var (OPTION..., file, HOW, where...)
1619 local ($do_all, $do_clean) = (1, 0);
1622 if ($args[0] eq '-clean')
1626 elsif ($args[0] eq '-no-all')
1630 elsif ($args[0] !~ /^-/)
1636 local ($file, $primary, @prefixes) = @args;
1639 local (@result) = ();
1641 local ($clean_file) = $file . '-clean';
1644 foreach $X (@prefixes)
1646 $one_name = $X . '_' . $primary;
1647 if (defined $contents{$one_name})
1649 # Append actual contents to result.
1650 push (@result, split (/\s+/, $contents{$one_name}));
1655 &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go',
1658 push (@clean, $X . $primary);
1659 &push_phony_cleaners ($X . $primary);
1662 push (@used, '$(' . $one_name . ')');
1665 # Objects in noinst_FOO never get installed.
1670 &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go',
1673 push (@uninstall, 'uninstall-' . $X . $primary);
1674 push (@phony, 'uninstall-' . $X . $primary);
1675 push (@installdirs, '$(' . $X . 'dir)');
1676 if ($exec_dir_p{$X})
1678 push (@install_exec, 'install-' . $X . $primary);
1682 push (@install_data, 'install-' . $X . $primary);
1687 if (! defined $contents{$primary} && @used)
1690 &pretty_print ($primary . ' =', '', @used);
1691 $output_vars .= "\n";
1694 # Push here because PRIMARY might be configure time determined.
1695 push (@all, '$(' . $primary . ')') if ($do_all && @used);
1697 # Look for misspellings. It is an error to have a variable ending
1698 # in a "reserved" suffix whose prefix is unknown, eg
1700 local (%valid, $varname);
1701 grep ($valid{$_} = 0, @prefixes);
1702 foreach $varname (keys %contents)
1704 if ($varname =~ /^(.*)_$primary$/o && ! defined $valid{$1})
1706 &am_error ("invalid variable \"$varname\"");
1714 ################################################################
1716 # Verify that the file must exist in the current directory.
1717 # Usage: require_file (strictness, file)
1718 # strictness is the strictness level at which this file becomes
1722 local ($mystrict, @files) = @_;
1723 local ($file, $fullfile);
1725 foreach $file (@files)
1727 $fullfile = $relative_dir . "/" . $file;
1731 &push_dist_common ($file);
1733 elsif ($install_missing && -f ($am_dir . '/' . $file))
1735 # Install the missing file. Symlink if we can, copy if we must.
1736 if ($symlink_exists)
1738 symlink ($am_dir . '/' . $file, $fullfile);
1742 system ('cp', $am_dir . '/' . $file, $fullfile);
1744 &am_error ("required file \"$fullfile\" not found; installing");
1746 elsif ($strictness >= $mystrict)
1748 # Only an error if strictness constraint violated.
1749 &am_error ("required file \"$fullfile\" not found");
1754 # Push a list of files onto dist_common.
1755 sub push_dist_common
1757 local (@files) = @_;
1760 foreach $file (@files)
1762 $dist_common{$file} = 1;
1766 # Push a list of clean targets onto phony.
1767 sub push_phony_cleaners
1771 foreach $target ('mostly', 'dist', '', 'maintainer-')
1773 push (@phony, $target . 'clean-' . $base);
1780 $strictness_name = $_[0];
1781 if ($strictness_name eq 'gnu')
1785 elsif ($strictness_name eq 'gnits')
1787 $strictness = $GNITS;
1789 elsif ($strictness_name eq 'normal')
1791 $strictness = $NORMAL;
1795 die "automake: level \`$strictness_name' not recognized\n";
1800 ################################################################
1802 # Return directory name of file.
1808 ($sub = $file) =~ s,/+[^/]+,,g;
1809 $sub = '.' if $sub eq $file;
1816 local ($dirname) = @_;
1817 system ("mkdir", $dirname);
1820 ################################################################
1822 # Print an error message and set exit status.
1825 warn "automake: ${am_file}.am: ", join (' ', @_), "\n";
1829 # Print usage information.
1832 print "Usage: automake [OPTION] ... [Makefile]...\n";
1834 print "\nFiles which are automatically distributed, if found:\n";
1835 $~ = "USAGE_FORMAT";
1836 local (@lcomm) = sort ((@common_files, @common_sometimes));
1837 local ($one, $two, $three, $four);
1840 $one = shift @lcomm;
1841 $two = @lcomm ? shift @lcomm : '';
1842 $three = @lcomm ? shift @lcomm : '';
1843 $four = @lcomm ? shift @lcomm : '';
1850 format USAGE_FORMAT =
1851 @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<
1852 $one, $two, $three, $four