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.
52 # Strictness level as set on command line.
53 $default_strictness = $NORMAL;
55 # Name of strictness level, as set on command line.
56 $default_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.
72 # Files found by scanning configure.in for LIBOBJS.
75 # True if fp_C_PROTOTYPES appears in configure.in.
78 # Names used in AC_CONFIG_HEADER call. $config_name is the actual
79 # (first) argument. $config_header is the '.in' file. Ordinarily the
80 # second is derived from the first, but they can be different if the
81 # weird "NAME:FILE" syntax is used.
85 # Relative location of top build directory.
88 # List of Makefile.am's to process.
91 # List of files in AC_OUTPUT without Makefile.am.
92 @other_input_files = ();
94 # Whether AC_PROG_MAKE_SET has been seen in configure.in.
97 # Whether ud_GNU_GETTEXT has been seen in configure.in.
100 # 1 if AC_PROG_INSTALL seen, 2 if fp_PROG_INSTALL seen.
101 $seen_prog_install = 0;
103 # 1 if any scripts installed, 0 otherwise.
104 $scripts_installed = 0;
108 &initialize_global_constants;
110 # Parse command line.
111 &parse_arguments (@ARGV);
113 # Do configure.in scan only once.
116 die "automake: no \`Makefile.am' found or specified\n"
119 # Now do all the work on each file.
120 foreach $am_file (@input_files)
122 if (! -f ($am_file . '.am'))
124 &am_error ('no such file');
128 &generate_makefile ($am_file);
132 &am_conf_error ($scripts_installed ? 'fp_PROG_INSTALL' : 'AC_PROG_INSTALL'
133 . " must be used in configure.in")
134 unless $seen_prog_install > $scripts_installed;
139 ################################################################
141 # Parse command line.
144 local (@arglist) = @_;
146 # Start off as normal.
147 &set_strictness ('normal');
151 if ($arglist[0] eq "--version")
153 print "Automake version $VERSION\n";
156 elsif ($arglist[0] eq "--help")
160 elsif ($arglist[0] =~ /^--amdir=(.+)$/)
164 elsif ($arglist[0] eq '--amdir')
166 &require_argument (@arglist);
168 $am_dir = $arglist[0];
170 elsif ($arglist[0] =~ /^--strictness=(.+)$/)
172 &set_strictness ($1);
174 elsif ($arglist[0] eq '--gnu')
176 &set_strictness ('gnu');
178 elsif ($arglist[0] eq '--gnits')
180 &set_strictness ('gnits');
182 elsif ($arglist[0] eq '--strictness')
184 &require_argument (@arglist);
186 &set_strictness ($arglist[0]);
188 elsif ($arglist[0] eq '--include-deps')
190 $use_dependencies = 0;
192 elsif ($arglist[0] =~ /^--output-dir=(.*)$/)
194 # Set output directory.
195 $output_directory = $1;
197 elsif ($arglist[0] eq '--output-dir')
199 &require_argument (@arglist);
201 $output_directory = $arglist[0];
203 elsif ($arglist[0] eq '--install-missing')
205 $install_missing = 1;
207 elsif ($arglist[0] eq '--')
209 # Stop option processing.
211 push (@input_files, @arglist);
214 elsif ($arglist[0] =~ /^-/)
216 die "automake: unrecognized option -- \`$arglist[0]'\n";
220 push (@input_files, $arglist[0]);
226 # Take global strictness from whatever we currently have set.
227 $default_strictness = $strictness;
228 $default_strictness_name = $strictness_name;
231 # Ensure argument exists, or die.
234 local ($arg, @arglist) = @_;
235 die "automake: no argument given for option \`$arg'\n"
239 ################################################################
241 # Generate a Makefile.in given the name of the corresponding Makefile.
242 sub generate_makefile
244 local ($makefile) = @_;
246 print "creating ", $makefile, ".in\n";
248 &initialize_per_input;
249 $relative_dir = &dirname ($makefile);
250 # FIXME with new 'dist' target, don't need Makefile.in. Probably
251 # should remove it here.
252 &push_dist_common ('Makefile.in', 'Makefile.am');
253 push (@sources, '$(SOURCES)') if defined $contents{'SOURCES'};
254 push (@objects, '$(OBJECTS)') if defined $contents{'OBJECTS'};
256 # This is always the default target. This gives us freedom to do
257 # things in whatever order is convenient.
258 $output_rules .= "default: all\n\n";
259 push (@phony, 'default');
261 &read_am_file ($makefile . '.am');
264 # Check first, because we might modify some state.
265 &check_gnu_standards;
266 &check_gnits_standards;
273 # Re-init SOURCES and OBJECTS. FIXME other code shouldn't depend
274 # on this (but currently does).
275 $contents{'SOURCES'} = join (' ', @sources);
276 $contents{'OBJECTS'} = join (' ', @objects);
285 &handle_dependencies;
287 &handle_merge_targets;
292 if (! -d ($output_directory . '/' . $relative_dir))
294 &mkdir ($output_directory . '/' . $relative_dir);
296 if (! open (GM_FILE, "> " . $output_directory . '/' . $makefile . ".in"))
298 warn "automake: ${am_file}.in: cannot open: $!\n";
303 print GM_FILE $output_vars;
304 print GM_FILE $output_rules;
305 print GM_FILE $output_trailer;
310 ################################################################
312 # Handle AUTOMAKE_OPTIONS variable.
315 return if ! defined $contents{'AUTOMAKE_OPTIONS'};
317 foreach (split (/\s+/, $contents{'AUTOMAKE_OPTIONS'}))
320 if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'normal')
322 &set_strictness ($_);
324 elsif ($_ eq 'no-installman' || $_ eq 'ansi2knr' || $_ eq 'dist-shar')
326 # Explicitly recognize these.
328 elsif ($_ eq 'no-dependencies')
330 # FIXME for now this is global.
331 $use_dependencies = 0;
335 &am_error ('option ', $_, 'not recognized');
340 # Return object extension. Just once, put some code into the output.
341 sub get_object_extension
343 if (! $dir_holds_sources)
347 $output_vars .= &file_contents ('compile-vars');
348 $output_rules .= &file_contents ('compile');
349 &push_phony_cleaners ('compile');
351 # Check for automatic de-ANSI-fication.
352 $dir_holds_sources = '.o';
353 push (@suffixes, '.c', '.o');
354 push (@clean, 'compile');
356 if (defined $options{'ansi2knr'} || defined $contents{'@kr@'})
358 &am_error ("option \`ansi2knr' in use but \`fp_C_PROTOTYPES' not in configure.in")
359 if ! $fp_c_prototypes;
361 $dir_holds_sources = '$o';
362 push (@suffixes, '._c', '._o');
364 &require_file ($NORMAL, 'ansi2knr.c', 'ansi2knr.1');
366 $output_vars .= &file_contents ('kr-vars');
367 $output_rules .= &file_contents ('compile-kr');
368 $output_rules .= &file_contents ('clean-kr');
371 &push_phony_cleaners ('kr');
374 return $dir_holds_sources;
377 # Handle SOURCE->OBJECT transform for one program or library.
378 sub handle_source_transform
380 local ($one_file, $obj) = @_;
381 local ($objpat) = $obj;
382 $objpat =~ s/(\W)/\\\1/g;
384 # Look for file_SOURCES and file_OBJECTS.
385 if (defined $contents{$one_file . "_SOURCES"})
387 if (! defined $contents{$one_file . "_OBJECTS"})
389 # Turn sources into objects.
390 local (@files) = split (/\s+/, $contents{$one_file . "_SOURCES"});
391 local (@result) = ();
396 # Skip things that look like macro references.
397 next if /^\$\(.*\)$/;
398 next if /^\$\{.*\}$/;
402 # Automatically include generated .c file in
404 &push_dist_common ($1 . '.c');
407 # Transform source files into .o files.
409 s/\.[cCmylfs]$/$obj/g;
412 # Transform .o or $o file into .P file (for automatic
415 $dep_files{'$(srcdir)/.deps/' . $_} = 1;
418 &pretty_print ($one_file . "_OBJECTS =", '', @result);
422 &am_error ($one_file . '_OBJECTS', 'should not be defined');
425 push (@sources, '$(' . $one_file . "_SOURCES)");
426 push (@objects, '$(' . $one_file . "_OBJECTS)");
430 $output_vars .= ($one_file . "_SOURCES = " . $one_file . ".c\n"
431 . $one_file . "_OBJECTS = ". $one_file
433 push (@sources, $one_file . '.c');
434 push (@objects, $one_file . $obj);
435 $dep_files{'$(srcdir)/.deps/' . $one_file . '.P'} = 1;
438 if (defined $contents{'CONFIG_HEADER'})
440 $output_rules .= ('$(' . $one_file . "_OBJECTS): "
441 . $contents{'CONFIG_HEADER'} . "\n");
450 local (@proglist) = &am_install_var ('-clean',
451 'programs', 'PROGRAMS',
452 'bin', 'sbin', 'libexec', 'noinst');
453 # FIXME error if PROGRAMS defined but no blah_PROGRAMS defined.
454 return if ! @proglist;
456 local ($obj) = &get_object_extension;
457 local ($one_file, $munge);
459 foreach $one_file (@proglist)
461 &handle_source_transform ($one_file, $obj);
463 if (! defined $contents{$one_file . "_LDADD"})
465 # User didn't define prog_LDADD override. So do it.
466 $output_vars .= $one_file . '_LDADD = $(LDADD)' . "\n";
470 &file_contents_with_transform ('s/\@PROGRAM\@/' . $one_file
478 local (@liblist) = &am_install_var ('-no-all', '-clean',
479 'libraries', 'LIBRARIES',
480 'lib', 'pkglib', 'noinst');
481 # FIXME error if LIBRARIES defined but no blah_LIBRARIES defined.
482 return if ! @liblist;
484 # Generate _LIBFILES variables. Too bad we can't do this in
486 local ($onedir, $onelib);
488 foreach $onedir ('lib', 'pkglib', 'noinst')
490 if (defined $contents{$onedir . '_LIBRARIES'})
493 foreach $onelib (split (/\s+/, $contents{$onedir . '_LIBRARIES'}))
495 push (@outlist, 'lib' . $onelib . '.a');
497 &pretty_print ($onedir . '_LIBFILES =', '', @outlist);
500 push (@all, '$(LIBFILES)');
502 local ($obj) = &get_object_extension;
504 foreach $onelib (@liblist)
506 if (defined $contents{$onelib . '_LIBADD'})
508 # We recognize certain things that are commonly put in
512 foreach $lsearch (split (/\s+/, $contents{$onelib . '_LIBADD'}))
514 # Automatically handle @LIBOBJS@ and @ALLOCA@.
515 # Basically this means adding entries to dep_files.
516 if ($lsearch eq '@LIBOBJS@')
518 local ($iter, $rewrite);
519 foreach $iter (keys %libsources)
521 if ($iter ne 'alloca.c')
523 ($rewrite = $iter) =~ s/\.c$/.P/;
524 $dep_files{'$(srcdir)/.deps/' . $rewrite} = 1;
525 &require_file ($NORMAL, $iter);
529 elsif ($lsearch eq '@ALLOCA@')
531 &am_error ("\@ALLOCA\@ seen but \`AC_FUNC_ALLOCA' not in \`configure.in'")
532 if ! defined $libsources{'alloca.c'};
533 $dep_files{'$(srcdir)/.deps/alloca.P'} = 1;
534 &require_file ($NORMAL, 'alloca.c');
540 # Generate support for conditional object inclusion in
542 $output_vars .= $onelib . "_LIBADD =\n";
545 &handle_source_transform ($onelib, $obj);
548 &file_contents_with_transform ('s/\@LIBRARY\@/' . $onelib . '/go',
552 # Turn "foo" into "libfoo.a" and include macro definition.
553 grep (($_ = 'lib' . $_ . '.a') && 0, @liblist);
555 if (! defined $contents{'LIBFILES'})
557 &pretty_print ('LIBFILES = ', '', @liblist);
559 $output_vars .= &file_contents ('libraries-vars');
565 # FIXME can't determine if these scripts are really being
567 $scripts_installed = &am_install_var ('-clean',
568 'scripts', 'SCRIPTS',
569 'bin', 'sbin', 'libexec', 'noinst');
572 # Search a file for a "version.texi" Texinfo include. Return the name
573 # of the include file if found, or the empty string if not. A
574 # "version.texi" file is actually any file whose name matches
576 sub grep_for_vers_texi
578 local ($filename) = @_;
580 if (! open (TEXI, $filename))
582 &am_error ("couldn't open \`$filename': $!");
588 if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
600 # Handle all Texinfo source.
601 # Anyplace marked FIXME in this code is for multi-texi changes.
604 &am_error ("\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
605 if defined $contents{'TEXINFOS'};
606 return if ! defined $contents{'info_TEXINFOS'};
608 local (@texis) = split (/\s+/, $contents{'info_TEXINFOS'});
611 &am_error ('sorry, only one file allowed in `info_TEXINFOS\'');
615 local (@infos_list, @info_deps_list, @dvis_list, @texi_deps);
616 local ($infobase, $info_cursor);
620 local ($tc_cursor, @texi_cleans);
622 foreach $info_cursor (@texis)
624 ($infobase = $info_cursor) =~ s/\.texi$//;
626 # If 'version.texi' is referenced by input file, then include
627 # automatic versioning capability.
629 = &grep_for_vers_texi ($relative_dir . "/" . $info_cursor);
632 &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
633 if (defined $versions{$vtexi});
634 $versions{$vtexi} = $info_cursor;
637 push (@texis, $vtexi);
638 # We number the stamp-vti files. This is doable since the
639 # actual names don't matter much. We only number starting
640 # with the second one, so that the common case looks nice.
641 $vti = 'vti' . ($done ? $done : '');
642 &push_dist_common ($vtexi, 'stamp-' . $vti);
646 &file_contents_with_transform
647 ('s/\@TEXI\@/' . $info_cursor . '/g; '
648 . 's/\@VTI\@/' . $vti . '/g; '
649 . 's/\@VTEXI\@/' . $vtexi . '/g',
652 &push_phony_cleaners ($vti);
655 &require_file ($NORMAL, 'mdate-sh') if ! $done;
659 # If user specified file_TEXINFOS, then use that as explicit
662 push (@texi_deps, $info_cursor);
663 if (defined $contents{$infobase . "_TEXINFOS"})
665 push (@texi_deps, "\$" . $infobase . '_TEXINFOS');
666 &push_dist_common ("\$" . $infobase . '_TEXINFOS');
669 $output_rules .= ("\n" . $infobase . ".info: "
670 . join (' ', @texi_deps) . "\n\n");
672 push (@infos_list, $infobase . '.info*');
673 push (@info_deps_list, $infobase . '.info');
674 push (@dvis_list, $infobase . '.dvi');
676 # Generate list of things to clean for this target. We do
677 # this explicitly because otherwise too many things could be
678 # removed. In particular the ".log" extension might
679 # reasonably be used in other contexts by the user.
680 foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns',
681 'ky', 'log', 'pg', 'toc', 'tp', 'vr', 'op')
683 push (@texi_cleans, $infobase . '.' . $tc_cursor);
688 $output_vars .= &file_contents ('texinfos-vars');
689 $output_rules .= &file_contents ('texinfos');
690 push (@phony, 'install-info', 'uninstall-info');
693 $output_rules .= "\nmostlyclean-info:\n";
694 &pretty_print_rule ("\trm -f", "\t ", @texi_cleans);
695 $output_rules .= ("\nclean-info:\n\ndistclean-info:\n\n"
696 . "maintainer-clean-info:\n\t"
697 . 'rm -f $(INFOS)' . "\n");
698 &push_phony_cleaners ('info');
700 push (@suffixes, '.texi', '.info', '.dvi');
701 push (@uninstall, 'uninstall-info');
702 push (@clean, 'info');
703 push (@info, '$(INFO_DEPS)');
704 push (@dvi, '$(DVIS)');
705 push (@installdirs, '$(infodir)');
706 # Make sure documentation is made and installed first.
707 unshift (@install_data, 'install-info');
708 unshift (@all, 'info');
710 $output_vars .= ("INFOS = " . join (' ', @infos_list) . "\n"
711 . "INFO_DEPS = " . join (' ', @info_deps_list) . "\n"
712 . "DVIS = " . join (' ', @dvis_list) . "\n"
713 # This next isn't strictly needed now -- the
714 # places that look here could easily be changed
715 # to look in info_TEXINFOS. But this is probably
716 # better, in case noinst_TEXINFOS is ever
718 . "TEXINFOS = " . $contents{'info_TEXINFOS'} . "\n\n");
720 # Do some error checking.
721 &require_file ($NORMAL, 'texinfo.tex');
724 # Handle any man pages.
727 &am_error ("\`MANS' is an anachronism; use \`man_MANS'")
728 if defined $contents{'MANS'};
729 return if ! defined $contents{'man_MANS'};
731 # We generate the manpage install code by hand to avoid the use of
732 # basename in the generated Makefile.
733 local (@mans) = split (/\s+/, $contents{'man_MANS'});
734 local (%sections, %inames, %secmap, %fullsecmap);
737 # FIXME: statement without effect:
738 /^(.*)\.([0-9])([a-z]*)$/;
742 $fullsecmap{$1} = $2 . $3;
745 # We don't really need this, but we use it in case we ever want to
746 # support noinst_MANS.
747 $output_vars .= "MANS = " . $contents{'man_MANS'} . "\n";
749 # Generate list of install dirs.
750 $output_rules .= "install-man: \$(MANS)\n";
751 foreach (keys %sections)
753 push (@installdirs, '$(mandir)/man' . $_);
754 $output_rules .= ("\t" . '$(top_srcdir)/mkinstalldirs $(mandir)/man'
757 push (@phony, 'install-man');
759 # Generate install target.
761 foreach $key (keys %inames)
763 $_ = $install_man_format;
764 s/\@SECTION\@/$secmap{$key}/g;
765 s/\@MAN\@/$inames{$key}/g;
766 s/\@FULLSECT\@/$fullsecmap{$key}/g;
767 s/\@MANBASE\@/$key/g;
770 $output_rules .= "\n";
772 $output_rules .= "uninstall-man:\n";
773 foreach $key (keys %inames)
775 $_ = $uninstall_man_format;
776 s/\@SECTION\@/$secmap{$key}/g;
777 s/\@MAN\@/$inames{$key}/g;
778 s/\@FULLSECT\@/$fullsecmap{$key}/g;
779 s/\@MANBASE\@/$key/g;
782 $output_rules .= "\n";
783 push (@phony, 'uninstall-man');
785 $output_vars .= &file_contents ('mans-vars');
787 if (! defined $options{'no-installman'})
789 push (@install_data, 'install-man');
790 push (@uninstall, 'uninstall-man');
791 push (@all, '$(MANS)');
795 # Handle DATA variables.
798 &am_install_var ('data', 'DATA', 'data', 'sysconf',
799 'sharedstate', 'localstate', 'pkgdata',
806 local ($tagging) = 0;
808 push (@phony, 'tags');
809 if (defined $contents{'SUBDIRS'})
811 $output_rules .= &file_contents ('tags');
814 elsif ($dir_holds_sources || defined $contents{'ETAGS_ARGS'})
816 $output_rules .= &file_contents ('tags-subd');
822 $output_rules .= &file_contents ('tags-clean');
823 push (@clean, 'tags');
824 &push_phony_cleaners ('tags');
828 # Every Makefile must define some sort of TAGS rule.
829 # Otherwise, it would be possible for a top-level "make TAGS"
830 # to fail because some subdirectory failed.
831 $output_rules .= "tags: TAGS\nTAGS:\n\n";
835 # Generate actual 'dist' (or dist-shar) rule.
836 sub handle_dist_worker
838 local ($distshar) = @_;
839 local ($target) = $distshar ? 'dist-shar' : 'dist';
841 $output_rules .= $target . ': $(DEP_DISTFILES)' . "\n";
843 # Initialization; only at top level.
844 if ($relative_dir eq '.')
846 if ($strictness >= $GNITS)
848 # For Gnits users, this is pretty handy. Look at 15 lines
849 # in case some explanatory text is desirable.
850 $output_rules .= ' @if sed 15q NEWS | grep -e "$(VERSION)" > /dev/null; then :; else \\
851 echo "NEWS not updated; not releasing" 1>&2; \\
860 # Create dist directory.
865 # We need an absolute path for --output-dir. Thus the
867 . ' distdir=`cd $(distdir) && pwd` \\
869 && automake --include-deps --output-dir=$$distdir --strictness='
870 # Set strictness of output.
871 . $strictness_name . "\n"
875 # In loop, test for file existence because sometimes a file gets
876 # included in DISTFILES twice. For example this happens when a
877 # single source file is used in building more than one program.
878 # Also, there are situations in which "ln" can fail. For instance
879 # a file to distribute could actually be a cross-filesystem
880 # symlink -- this can easily happen if "gettextize" was run on the
881 # distribution. Note that DISTFILES can contain a wildcard (for
882 # info files, sigh), so we must use the echo trick.
884 $output_rules .= ' @for file in `cd $(srcdir) && echo $(DISTFILES)`; do \\
885 test -f $(distdir)/$$file \\
886 || ln $(srcdir)/$$file $(distdir)/$$file 2> /dev/null \\
887 || cp -p $(srcdir)/$$file $(distdir)/$$file; \\
891 # If we have SUBDIRS, create all dist subdirectories and do
893 if (defined $contents{'SUBDIRS'})
895 # Test for directory existence here because previous automake
896 # invocation might have created some directories.
897 $output_rules .= ' for subdir in $(SUBDIRS); do \\
898 test -d $(distdir)/$$subdir \\
899 || mkdir $(distdir)/$$subdir \\
901 chmod 777 $(distdir)/$$subdir; \\
902 (cd $$subdir && $(MAKE) dist) || exit 1; \\
907 # Make verbatim copies of some subdirectories if required. This
908 # is a hack which might go away.
909 if (defined $contents{'DIST_SUBDIRS'})
911 $output_rules .= ' @for dir in $(DIST_SUBDIRS); do \\
912 echo copying directory $$dir; \\
913 tar chf - $$dir | (cd $(distdir) && tar xBpf -); \\
919 if ($relative_dir eq '.')
921 $output_rules .= ' chmod -R a+r $(distdir)' . "\n\t";
924 $output_rules .= 'shar $(distdir) | gzip > $(distdir).shar.gz';
928 $output_rules .= 'tar chozf $(distdir).tar.gz $(distdir)';
930 $output_rules .= "\n\t" . 'rm -rf $(distdir)' . "\n";
933 push (@phony, $target);
936 # Handle 'dist' target.
939 # Look for common files that should be included in distribution.
941 foreach $cfile (@common_files)
943 if (-f ($relative_dir . "/" . $cfile))
945 &push_dist_common ($cfile);
949 # Keys of %dist_common are names of files to distributed. We put
950 # README first because it then becomes easier to make a
951 # Usenet-compliant shar file (in these, README must be first).
952 # FIXME do more ordering of files here.
954 if (defined $dist_common{'README'})
956 push (@coms, 'README');
957 undef $dist_common{'README'};
959 push (@coms, sort keys %dist_common);
961 &pretty_print ("DIST_COMMON =", '', @coms);
962 $output_vars .= "\n";
965 $output_vars .= &file_contents ('dist-vars');
967 # Put these things in rules section so it is easier for whoever
969 if ($relative_dir eq '.')
971 $output_rules .= "\n" . 'distdir = $(PACKAGE)-$(VERSION)' . "\n";
975 $output_rules .= ("\nsubdir = " . $relative_dir . "\n"
976 . 'distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)'
980 # Generate 'dist' target, and maybe dist-shar.
981 &handle_dist_worker (0);
982 &handle_dist_worker (1) if defined $options{'dist-shar'};
985 # Handle auto-dependency code.
986 sub handle_dependencies
988 if ($use_dependencies)
990 # Include GNU-make-specific auto-dep code.
991 if ($dir_holds_sources)
993 &pretty_print ('DEP_FILES =', '', sort keys %dep_files);
994 $output_rules .= &file_contents ('depend');
999 # Include any auto-generated deps that are present.
1000 if (-d ($relative_dir . "/.deps") && -f ($relative_dir . "/.deps/.P"))
1003 local ($gpat) = $relative_dir . "/.deps/*.P";
1005 foreach $depfile (<${gpat}>)
1007 if (! open (DEP_FILE, $depfile))
1009 &am_error ("couldn't open $depfile", $!);
1013 # Slurp entire file.
1014 $output_rules .= join ('', <DEP_FILE>);
1019 $output_rules .= "\n";
1024 # Handle subdirectories.
1027 if (! defined $contents{'SUBDIRS'})
1030 ("ud_GNU_GETTEXT in configure.in but SUBDIRS not defined")
1031 if $seen_gettext && $relative_dir eq '.';
1036 ("ud_GNU_GETTEXT in configure.in but \`po' not in SUBDIRS")
1037 if $seen_gettext && $contents{'SUBDIRS'} !~ /\bpo\b/;
1039 ("ud_GNU_GETTEXT in configure.in but \`intl' not in SUBDIRS")
1040 if $seen_gettext && $contents{'SUBDIRS'} !~ /\bintl\b/;
1042 &require_file ($NORMAL, 'ABOUT-NLS') if $seen_gettext;
1044 return if ! defined $contents{'SUBDIRS'};
1046 $output_rules .= &file_contents ('subdirs');
1048 # Push a bunch of phony targets.
1050 foreach $phonies ('-data', '-exec', 'dirs')
1052 push (@phony, 'install' . $phonies . '-recursive');
1053 push (@phony, 'uninstall' . $phonies . '-recursive');
1055 foreach $phonies ('all', 'check', 'installcheck', 'info', 'dvi')
1057 push (@phony, $phonies . '-recursive');
1059 &push_phony_cleaners ('recursive');
1061 push (@all, "all-recursive");
1062 push (@check, "check-recursive");
1063 push (@installcheck, "installcheck-recursive");
1064 push (@info, "info-recursive");
1065 push (@dvi, "dvi-recursive");
1067 $recursive_install = 1;
1070 # Handle remaking and configure stuff.
1071 sub handle_configure
1073 # If SUBDIRS defined, require AC_PROG_MAKE_SET.
1074 &am_error ("AC_PROG_MAKE_SET must be used in configure.in")
1075 if defined $contents{'SUBDIRS'} && ! $seen_make_set;
1077 local ($top_reldir);
1078 if ($relative_dir ne '.')
1081 $output_rules .= &file_contents ('remake-subd');
1082 $top_reldir = '../';
1086 if (-f 'aclocal.m4')
1088 $output_vars .= "ACLOCAL = aclocal.m4\n";
1089 &push_dist_common ('aclocal.m4');
1091 $output_rules .= &file_contents ('remake');
1093 # Look for some files we need.
1094 &require_file ($NORMAL, 'install-sh', 'mkinstalldirs');
1097 ("\`install.sh' is an anachronism; use \`install-sh' instead")
1098 if -f $relative_dir . '/install.sh';
1100 # If we have a configure header, require it.
1103 # FIXME this restriction should be lifted.
1104 # FIXME first see if it is even needed as-is.
1105 &am_error ("argument to AC_CONFIG_HEADER contains \`/'\n")
1106 if ($config_header =~ /\//);
1108 &require_file ($NORMAL, $config_header);
1110 # Header defined and in this directory.
1111 if (-f 'acconfig.h')
1113 $output_vars .= "ACCONFIG = acconfig.h\n";
1114 &push_dist_common ('acconfig.h');
1116 if (-f $config_name . '.top')
1118 $output_vars .= "CONFIG_TOP = ${config_name}.top\n";
1119 &push_dist_common ($config_name . '.top');
1121 if (-f $config_name . '.bot')
1123 $output_vars .= "CONFIG_BOT = ${config_name}.bot\n";
1124 &push_dist_common ($config_name . '.bot');
1127 &push_dist_common ('stamp-h.in');
1129 $output_rules .= &file_contents ('remake-hdr');
1130 $output_vars .= "CONFIG_HEADER_IN = ${config_header}\n";
1136 &am_error ("\`CONFIG_HEADER' is an anachronism; now determined from \`configure.in'")
1137 if defined $contents{'CONFIG_HEADER'};
1139 # Generate CONFIG_HEADER define, and define interally.
1140 $output_vars .= "CONFIG_HEADER = ${top_builddir}/${config_name}\n"
1142 $contents{'CONFIG_HEADER'} = "${top_builddir}/${config_name}"
1145 # Now look for other files in this directory which must be remade
1146 # by config.status, and generate rules for them.
1147 local ($file, $local);
1148 foreach $file (@other_input_files)
1150 # Skip files not in this directory, any Makefile, and the
1151 # config header. These last two must be handled specially.
1152 next unless &dirname ($file) eq $relative_dir;
1153 next if $file eq $top_builddir . '/' . $config_name;
1154 ($local = $file) =~ s/^.*\///;
1155 next if $local eq 'Makefile';
1157 # FIXME support ":" syntax of AC_OUTPUT here.
1158 $output_rules .= ($local . ': '
1159 . '$(top_builddir)/config.status ' . $local . ".in\n"
1161 . 'cd $(top_srcdir) && CONFIG_FILES='
1162 . ($relative_dir eq '.' ? '' : '$(subdir)/')
1163 . '$@ CONFIG_HEADERS= ./config.status'
1165 &require_file ($NORMAL, $local . '.in');
1172 &am_install_var ('header', 'HEADERS', 'include',
1173 'oldinclude', 'pkginclude',
1177 # Handle footer elements.
1180 if ($contents{'SOURCES'})
1182 &pretty_print ('SOURCES =', '', split (/\s+/, $contents{'SOURCES'}));
1184 if ($contents{'OBJECTS'})
1186 &pretty_print ('OBJECTS =', '', split (/\s+/, $contents{'OBJECTS'}));
1188 if ($contents{'SOURCES'} || $contents{'OBJECTS'})
1190 $output_vars .= "\n";
1193 if (defined $contents{'SUFFIXES'})
1195 push (@suffixes, '$(SUFFIXES)');
1198 $output_trailer .= ".SUFFIXES:\n";
1201 $output_trailer .= ".SUFFIXES: " . join (' ', @suffixes) . "\n";
1203 $output_trailer .= &file_contents ('footer');
1206 # Deal with installdirs target.
1207 sub handle_installdirs
1209 # GNU Makefile standards recommend this.
1210 $output_rules .= ("installdirs:"
1211 . ($recursive_install
1212 ? " installdirs-recursive\n"
1214 push (@phony, 'installdirs');
1217 &pretty_print_rule ("\t\$(top_srcdir)/mkinstalldirs ", "\t\t",
1220 $output_rules .= "\n";
1223 # There are several targets which need to be merged. This is because
1224 # their complete definition is compiled from many parts. Note that we
1225 # avoid double colon rules, otherwise we'd use them instead.
1226 sub handle_merge_targets
1228 &do_one_merge_target ('all', @all);
1229 &do_one_merge_target ('info', @info);
1230 &do_one_merge_target ('dvi', @dvi);
1232 if (! defined $contents{'SUBDIRS'} || $relative_dir ne '.')
1234 # 'check' must depend on 'all', but not at top level.
1235 unshift (@check, 'all');
1237 &do_one_merge_target ('check', @check);
1238 &do_one_merge_target ('installcheck', @installcheck);
1240 # Handle the various install targets specially. We do this so
1241 # that (eg) "make install-exec" will run "install-exec-recursive"
1242 # if required, but "make install" won't run it twice. Step one is
1243 # to see if the user specified local versions of any of the
1244 # targets we handle.
1245 if (defined $contents{'install-exec-local'})
1247 push (@install_exec, 'install-exec-local');
1249 if (defined $contents{'install-data-local'})
1251 push (@install_data, 'install-data-local');
1253 if (defined $contents{'uninstall-local'})
1255 push (@uninstall, 'uninstall-local');
1258 if (defined $contents{'install-local'})
1260 &am_error ("use \`install-data' or \`install-exec', not \`install'");
1263 # Step two: if we are doing recursive makes, write out the
1264 # appropriate rules.
1266 if ($recursive_install)
1268 push (@install, 'install-recursive');
1269 push (@uninstall, 'uninstall-recursive');
1273 $output_rules .= ('install-exec-am: '
1274 . join (' ', @install_exec)
1276 @install_exec = ('install-exec-recursive', 'install-exec-am');
1277 push (@install, 'install-exec-am');
1278 push (@phony, 'install-exec-am');
1282 $output_rules .= ('install-data-am: '
1283 . join (' ', @install_data)
1285 @install_data = ('install-data-recursive', 'install-data-am');
1286 push (@install, 'install-data-am');
1287 push (@phony, 'install-data-am');
1291 $output_rules .= ('uninstall-am: '
1292 . join (' ', @uninstall)
1294 @uninstall = ('uninstall-recursive', 'uninstall-am');
1295 push (@phony, 'uninstall-am');
1299 # Step three: print definitions users can use.
1302 $output_rules .= ("install-exec: "
1303 . join (' ', @install_exec)
1305 push (@install, 'install-exec') if !$recursive_install;
1306 push (@phony, 'install-exec');
1310 $output_rules .= ("install-data: "
1311 . join (' ', @install_data)
1313 push (@install, 'install-data') if !$recursive_install;
1314 push (@phony, 'install-data');
1317 # If no dependencies for 'install', add 'all'. Why? That way
1318 # "make install" at top level of distclean'd distribution won't
1319 # fail because stuff in 'lib' fails to build.
1320 push (@install, 'all') if ! @install;
1321 $output_rules .= ('install: '
1322 . join (' ', @install)
1323 # Use "@:" as empty command so nothing prints.
1327 . join (' ', @uninstall)
1329 push (@phony, 'install', 'uninstall');
1332 # Helper for handle_merge_targets.
1333 sub do_one_merge_target
1335 local ($name, @values) = @_;
1337 if (defined $contents{$name . '-local'})
1339 # User defined local form of target. So include it.
1340 push (@values, $name . '-local');
1341 push (@phony, $name . '-local');
1344 $output_rules .= $name . ":";
1347 $output_rules .= ' ' . join (' ', @values);
1349 $output_rules .= "\n\n";
1350 push (@phony, $name);
1353 # Handle all 'clean' targets.
1356 push (@clean, 'generic');
1357 $output_rules .= &file_contents ('clean');
1358 &push_phony_cleaners ('generic');
1360 local ($target) = $recursive_install ? 'clean-am' : 'clean';
1361 &do_one_clean_target ($target, 'mostly', '', @clean);
1362 &do_one_clean_target ($target, '', 'mostly', @clean);
1363 &do_one_clean_target ($target, 'dist', '', @clean);
1364 &do_one_clean_target ($target, 'maintainer-', 'dist', @clean);
1366 push (@phony, 'clean', 'mostlyclean', 'distclean', 'maintainer-clean');
1369 if ($recursive_install)
1371 @deps = ('am', 'recursive');
1372 &do_one_clean_target ('', 'mostly', '', @deps);
1373 &do_one_clean_target ('', '', '', @deps);
1374 &do_one_clean_target ('', 'dist', '', @deps);
1375 &do_one_clean_target ('', 'maintainer-', '', @deps);
1379 # Helper for handle_clean.
1380 sub do_one_clean_target
1382 local ($target, $name, $last_name, @deps) = @_;
1384 # Special case: if target not passed, then don't generate
1385 # dependency on next "lower" clean target (eg no
1386 # clean<-mostlyclean derivation). In this case the target is
1387 # implicitly known to be 'clean'.
1388 local ($flag) = $target;
1389 $target = 'clean' if ! $flag;
1391 grep (($_ = $name . 'clean-' . $_) && 0, @deps);
1394 if ($last_name || $name ne 'mostly')
1396 push (@deps, $last_name . $target . " ");
1399 &pretty_print_rule ($name . $target . ": ", '', @deps);
1401 # FIXME shouldn't we really print these messages before running
1403 if ($name . $target eq 'maintainer-clean')
1405 # Print a special warning.
1407 ("\t\@echo \"This command is intended for maintainers to use;\"\n"
1408 . "\t\@echo \"it deletes files that may require special "
1409 . "tools to rebuild.\"\n");
1411 $output_rules .= "\trm -f config.status\n"
1412 if $relative_dir eq '.';
1414 elsif ($name . $target eq 'distclean')
1416 $output_rules .= "\trm -f config.status\n";
1418 $output_rules .= "\n";
1421 # Handle .PHONY target.
1424 &pretty_print_rule ('.PHONY:', '', @phony);
1425 $output_rules .= "\n";
1428 ################################################################
1430 # Scan configure.in for interesting things.
1431 # FIXME ensure VERSION, PACKAGE are set.
1434 open (CONFIGURE, 'configure.in')
1435 || die "automake: couldn't open configure.in: $!\n";
1437 # Reinitialize libsources here. This isn't really necessary,
1438 # since we currently assume there is only one configure.in. But
1439 # that won't always be the case.
1442 local ($in_ac_output, @make_list) = 0;
1443 local ($seen_arg_prog) = 0;
1444 local ($seen_canonical) = 0;
1447 # Remove comments from current line.
1451 # Populate libobjs array.
1452 if (/AC_FUNC_ALLOCA/)
1454 $libsources{'alloca.c'} = 1;
1456 elsif (/AC_FUNC_GETLOADAVG/)
1458 $libsources{'getloadavg.c'} = 1;
1460 elsif (/AC_FUNC_MEMCMP/)
1462 $libsources{'memcmp.c'} = 1;
1464 elsif (/AC_STRUCT_ST_BLOCKS/)
1466 $libsources{'fileblocks.c'} = 1;
1468 elsif (/AC_REPLACE_FUNCS\s*\((.*)\)/)
1470 foreach (split (/\s+/, $1))
1472 $libsources{$_ . '.c'} = 1;
1475 elsif (/LIBOBJS="(.*)\.o\s+\$LIBOBJS"/)
1477 $libsources{$1 . '.c'} = 1;
1479 elsif (/LIBOBJS="\$LIBOBJS\s+(.*)\.o"/)
1481 $libsources{$1 . '.c'} = 1;
1484 # Process the AC_OUTPUT macro.
1485 if (! $in_ac_output && s/AC_OUTPUT\s*\(\[?//)
1492 $in_ac_output = 0 if s/[\),]//;
1494 # Look at potential Makefile.am's.
1499 push (@make_list, $_);
1503 push (@other_input_files, $_);
1508 # Check for ansi2knr.
1509 $fp_c_prototypes = 1 if /fp_C_PROTOTYPES/;
1511 # Check for NLS support.
1512 if (/ud_GNU_GETTEXT/)
1517 # Handle configuration headers.
1518 if (/AC_CONFIG_HEADER\s*\((.*)\)/)
1521 if ($config_name =~ /^([^:]+):(.+)$/)
1524 $config_header = $2;
1528 $config_header = $config_name . '.in';
1532 $seen_canonical = 1 if /AC_CANONICAL_(HOST|SYSTEM)/;
1534 # Some things required by Automake. FIXME we only really
1535 # require fp_PROG_INSTALL if some scripts are installed. And
1536 # we only really require AC_ARG_PROGRAM if any program is
1538 $seen_make_set = 1 if /AC_PROG_MAKE_SET/;
1539 $seen_prog_install = 1 if ! $seen_prog_install && /AC_PROG_INSTALL/;
1540 $seen_prog_install = 2 if ! $seen_prog_install && /fp_PROG_INSTALL/;
1541 $seen_arg_prog = 1 if /AC_ARG_PROGRAM/;
1544 # Set input files if not specified by user.
1545 @input_files = @make_list if (! @input_files);
1547 # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
1549 &require_file ($NORMAL, 'config.guess', 'config.sub')
1552 &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
1553 unless $seen_arg_prog;
1558 ################################################################
1560 # Do any extra checking for GNU standards.
1561 sub check_gnu_standards
1563 &require_file ($GNU, 'ChangeLog');
1565 if ($relative_dir eq '.')
1567 # In top level (or only) directory.
1568 &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
1573 # Do any extra checking for GNITS standards.
1574 sub check_gnits_standards
1576 if ($strictness >= $GNITS && -f $relative_dir . '/COPYING.LIB')
1579 ("\`${relative_dir}/COPYING.LIB' disallowed by Gnits standards");
1582 if ($relative_dir eq '.')
1584 # In top level (or only) directory.
1585 &require_file ($GNITS, 'THANKS');
1589 ################################################################
1591 # Pretty-print something. HEAD is what should be printed at the
1592 # beginning of the first line, FILL is what should be printed at the
1593 # beginning of every subsequent line.
1594 sub pretty_print_internal
1596 local ($head, $fill, @values) = @_;
1598 local ($column) = length ($head);
1599 local ($result) = $head;
1604 # "71" because we also print a space.
1605 if ($column + length ($_) > 71)
1607 $result .= " \\\n" . $fill;
1608 $column = length ($fill);
1612 $result .= ' ' unless ($bol);
1614 $column += length ($_) + 1;
1622 # Pretty-print something and append to output_vars.
1625 $output_vars .= &pretty_print_internal (@_);
1628 # Pretty-print something and append to output_rules.
1629 sub pretty_print_rule
1631 $output_rules .= &pretty_print_internal (@_);
1635 ################################################################
1637 # Read Makefile.am and set up %contents. Simultaneously copy lines
1638 # from Makefile.am into $output_trailer or $output_vars as
1639 # appropriate. NOTE we put rules in the trailer section. We want
1640 # user rules to come after our generated stuff.
1643 local ($amfile) = @_;
1645 # Compute relative location of the top object directory.
1646 local (@topdir) = ();
1647 foreach (split (/\//, $relative_dir))
1649 next if $_ eq '.' || $_ eq '';
1656 push (@topdir, '..');
1659 @topdir = ('.') if ! @topdir;
1661 $top_builddir = join ('/', @topdir);
1663 ($build_rx = $top_builddir) =~ s/(\W)/\\$1/g;
1664 local ($header_vars) =
1665 &file_contents_with_transform
1666 ('s/\@top_builddir\@/' . $build_rx . '/g',
1669 open (AM_FILE, $amfile) || die "automake: couldn't open $amfile: $!\n";
1671 $output_vars .= ("# Makefile.in generated automatically by automake "
1672 . $VERSION . " from Makefile.am\n");
1674 # Generate copyright for generated Makefile.in.
1675 $output_vars .= $gen_copyright;
1677 local ($saw_bk) = 0;
1678 local ($was_rule) = 0;
1679 local ($spacing) = '';
1680 local ($comment) = '';
1681 local ($last_var_name) = '';
1685 if (/$IGNORE_PATTERN/o)
1687 # Merely delete comments beginning with two hashes.
1689 elsif (/$WHITE_PATTERN/o)
1691 # Stick a single white line before the incoming macro or rule.
1694 elsif (/$COMMENT_PATTERN/o)
1696 # Stick comments before the incoming macro or rule.
1697 $comment .= $spacing . $_;
1706 $output_vars .= $comment . "\n" . $header_vars;
1712 if (/$IGNORE_PATTERN/o)
1714 # Merely delete comments beginning with two hashes.
1716 elsif (/$WHITE_PATTERN/o)
1718 # Stick a single white line before the incoming macro or rule.
1721 elsif (/$COMMENT_PATTERN/o)
1723 # Stick comments before the incoming macro or rule.
1724 $comment .= $spacing . $_;
1731 $output_trailer .= $_;
1738 # Chop newline and backslash if this line is
1739 # continued. FIXME maybe ensure trailing whitespace
1743 $contents{$last_var_name} .= $_;
1746 elsif (/$RULE_PATTERN/o)
1748 # warn "** Saw rule .$1.\n";
1751 # Value here doesn't matter; for targets we only note
1754 $output_trailer .= $comment . $spacing . $_;
1755 $comment = $spacing = '';
1758 elsif (/$MACRO_PATTERN/o)
1760 # warn "** Saw macro .$1.\n";
1761 # Found a macro definition.
1763 $last_var_name = $1;
1764 if (substr ($2, -1) eq "\\")
1766 $contents{$1} = substr ($2, 0, length ($2) - 1);
1772 $output_vars .= $comment . $spacing . $_;
1773 $comment = $spacing = '';
1776 elsif ($_ eq "\@kr\@\n")
1778 # Special case: this means we want automatic
1779 # de-ANSI-fication. This is deprecated. Remove in the
1781 $contents{'@kr@'} = 1;
1782 &am_error ('`@kr@\' is deprecated; put `ansi2knr\' in AUTOMAKE_OPTIONS instead');
1786 # This isn't an error; it is probably a continued rule.
1787 # In fact, this is what we assume.
1789 $output_trailer .= $comment . $spacing . $_;
1790 $comment = $spacing = '';
1797 $output_trailer .= $comment;
1800 ################################################################
1802 sub initialize_global_constants
1804 # Associative array of standard directory names. Entry is TRUE if
1805 # corresponding directory should be installed during
1806 # 'install-exec' phase.
1824 # Helper text for dealing with man pages.
1825 $install_man_format =
1826 ' @sect=@SECTION@; \\
1827 inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
1828 echo installing @MAN@ as $(mandir)/man$$sect/$$inst; \\
1829 $(INSTALL_DATA) $(srcdir)/@MAN@ $(mandir)/man$$sect/$$inst
1832 $uninstall_man_format =
1833 ' inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
1834 rm -f $(mandir)/man@SECTION@/$$inst
1837 # Commonly found files we look for and automatically include in
1841 "README", "THANKS", "TODO", "NEWS", "COPYING", "COPYING.LIB",
1842 "INSTALL", "ABOUT-NLS", "ChangeLog", "configure", "configure.in",
1843 "config.guess", "config.sub", "AUTHORS", "BACKLOG", "ABOUT-GNU"
1846 # Commonly used files we auto-include, but only sometimes.
1849 "version.texi", "aclocal.m4", "acconfig.h", "config.h.top",
1850 "config.h.bot", "stamp-h.in", "mdate-sh", "ansi2knr.c",
1851 "ansi2knr.1", 'stamp-vti', "mkinstalldirs", "install-sh"
1855 --amdir=DIR directory storing config files
1856 --gnits same as --strictness=gnits
1857 --gnu same as --strictness=gnu
1858 --help print this help, then exit
1859 --include-deps include generated dependencies in Makefile.in
1860 --install-missing install missing standard files
1861 --output-dir=DIR put generated Makefile.in's into DIR
1862 --strictness=LEVEL set strictness level. LEVEL is normal, gnu, gnits
1863 --version print version number, then exit\n";
1865 # Copyright on generated Makefile.ins.
1867 # Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
1868 # This Makefile.in is free software; the Free Software Foundation
1869 # gives unlimited permission to copy, distribute and modify it.
1873 # (Re)-Initialize per-Makefile.am variables.
1874 sub initialize_per_input
1876 # These two variables are used when generating each Makefile.in.
1877 # They hold the Makefile.in until it is ready to be printed.
1880 $output_trailer = '';
1882 # Suffixes found during a run.
1885 # This holds the contents of a Makefile.am, as parsed by
1889 # This holds the "relative directory" of the current Makefile.in.
1890 # Eg for src/Makefile.in, this is "src".
1893 # Directory where output files go. Actually, output files are
1894 # relative to this directory.
1895 $output_directory = '.';
1897 # This holds a list of files that are included in the
1901 # List of dependencies for the obvious targets.
1916 # These are pretty obvious, too. They are used to define the
1917 # SOURCES and OBJECTS variables.
1921 # TRUE if current directory holds any C source files. (Actually
1922 # holds object extension, but this information is encapsulated in
1923 # the function get_object_extension).
1924 $dir_holds_sources = '';
1926 # TRUE if install targets should work recursively.
1927 $recursive_install = 0;
1932 # Strictness levels.
1933 $strictness = $default_strictness;
1934 $strictness_name = $default_strictness_name;
1936 # Options from AUTOMAKE_OPTIONS.
1941 ################################################################
1943 # Return contents of a file from $am_dir, automatically skipping
1944 # macros or rules which are already known. Runs command on each line
1945 # as it is read; this command can modify $_.
1946 sub file_contents_with_transform
1948 local ($command, $basename) = @_;
1949 local ($file) = $am_dir . '/' . $basename . '.am';
1951 open (FC_FILE, $file)
1952 || die "automake: installation error: cannot open \`$file'\n";
1954 local ($was_rule) = 0;
1955 local ($result_vars) = '';
1956 local ($result_rules) = '';
1957 local ($comment) = '';
1958 local ($spacing) = "\n";
1959 local ($skipping) = 0;
1965 if (/$IGNORE_PATTERN/o)
1967 # Merely delete comments beginning with two hashes.
1969 elsif (/$WHITE_PATTERN/o)
1971 # Stick a single white line before the incoming macro or rule.
1974 elsif (/$COMMENT_PATTERN/o)
1976 # Stick comments before the incoming macro or rule.
1977 $comment .= $spacing . $_;
1984 $result_rules .= $_ if ! $skipping;
1988 $result_vars .= $_ if ! $skipping;
1992 elsif (/$RULE_PATTERN/o)
1994 # warn "** Found rule .$1.\n";
1997 $skipping = defined $contents{$1};
1998 # warn "** Skip $skipping\n" if $skipping;
1999 $result_rules .= $comment . $spacing . $_ if ! $skipping;
2000 $comment = $spacing = '';
2003 elsif (/$MACRO_PATTERN/o)
2005 # warn "** Found macro .$1.\n";
2006 # Found a variable reference.
2008 $skipping = defined $contents{$1};
2009 # warn "** Skip $skipping\n" if $skipping;
2010 $result_vars .= $comment . $spacing . $_ if ! $skipping;
2011 $comment = $spacing = '';
2016 # This isn't an error; it is probably a continued rule.
2017 # In fact, this is what we assume.
2019 $result_rules .= $comment . $spacing . $_ if ! $skipping;
2020 $comment = $spacing = '';
2026 return $result_vars . $result_rules . $comment;
2029 # Like file_contents_with_transform, but no transform.
2032 return &file_contents_with_transform ('', @_);
2035 # Handle `where_HOW' variable magic. Does all lookups, generates
2036 # install code,and possibly generates code to define the primary
2037 # variable. The first argument is the name of the .am file to munge,
2038 # the second argument is the primary variable (eg HEADERS), and all
2039 # subsequent arguments are possible installation locations. Returns
2040 # list of all values of all _HOW targets.
2042 # FIXME this should be rewritten to be cleaner. It should be broken
2043 # up into multiple functions.
2045 # Usage is: am_install_var (OPTION..., file, HOW, where...)
2050 local ($do_all, $do_clean) = (1, 0);
2053 if ($args[0] eq '-clean')
2057 elsif ($args[0] eq '-no-all')
2061 elsif ($args[0] !~ /^-/)
2067 local ($file, $primary, @prefixes) = @args;
2070 local (@result) = ();
2072 local ($clean_file) = $file . '-clean';
2075 foreach $X (@prefixes)
2077 $one_name = $X . '_' . $primary;
2078 if (defined $contents{$one_name})
2080 # Append actual contents to result.
2081 push (@result, split (/\s+/, $contents{$one_name}));
2086 &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go',
2089 push (@clean, $X . $primary);
2090 &push_phony_cleaners ($X . $primary);
2093 push (@used, '$(' . $one_name . ')');
2096 # Objects in noinst_FOO never get installed.
2101 &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go',
2104 push (@uninstall, 'uninstall-' . $X . $primary);
2105 push (@phony, 'uninstall-' . $X . $primary);
2106 push (@installdirs, '$(' . $X . 'dir)');
2107 if ($exec_dir_p{$X})
2109 push (@install_exec, 'install-' . $X . $primary);
2113 push (@install_data, 'install-' . $X . $primary);
2118 if (! defined $contents{$primary} && @used)
2121 &pretty_print ($primary . ' =', '', @used);
2122 $output_vars .= "\n";
2125 # Push here because PRIMARY might be configure time determined.
2126 push (@all, '$(' . $primary . ')') if ($do_all && @used);
2128 # Look for misspellings. It is an error to have a variable ending
2129 # in a "reserved" suffix whose prefix is unknown, eg
2131 local (%valid, $varname);
2132 grep ($valid{$_} = 0, @prefixes);
2133 foreach $varname (keys %contents)
2135 if ($varname =~ /^(.*)_$primary$/ && ! defined $valid{$1})
2137 &am_error ("invalid variable \"$varname\"");
2145 ################################################################
2147 # Verify that the file must exist in the current directory.
2148 # Usage: require_file (strictness, file)
2149 # strictness is the strictness level at which this file becomes
2153 local ($mystrict, @files) = @_;
2154 local ($file, $fullfile);
2156 foreach $file (@files)
2158 $fullfile = $relative_dir . "/" . $file;
2162 &push_dist_common ($file);
2164 elsif ($strictness >= $mystrict)
2166 # Only install missing files according to our desired
2168 if ($install_missing && -f ($am_dir . '/' . $file))
2170 # Install the missing file. Symlink if we can, copy
2172 if ($symlink_exists)
2174 symlink ($am_dir . '/' . $file, $fullfile);
2178 system ('cp', $am_dir . '/' . $file, $fullfile);
2181 ("required file \"$fullfile\" not found; installing");
2185 # Only an error if strictness constraint violated.
2186 &am_error ("required file \"$fullfile\" not found");
2192 # Push a list of files onto dist_common.
2193 sub push_dist_common
2195 local (@files) = @_;
2198 foreach $file (@files)
2200 $dist_common{$file} = 1;
2204 # Push a list of clean targets onto phony.
2205 sub push_phony_cleaners
2209 foreach $target ('mostly', 'dist', '', 'maintainer-')
2211 push (@phony, $target . 'clean-' . $base);
2218 $strictness_name = $_[0];
2219 if ($strictness_name eq 'gnu')
2223 elsif ($strictness_name eq 'gnits')
2225 $strictness = $GNITS;
2227 elsif ($strictness_name eq 'normal')
2229 $strictness = $NORMAL;
2233 die "automake: level \`$strictness_name' not recognized\n";
2238 ################################################################
2240 # Return directory name of file.
2246 ($sub = $file) =~ s,/+[^/]+$,,g;
2247 $sub = '.' if $sub eq $file;
2254 local ($dirname) = @_;
2255 system ("mkdir", $dirname);
2258 ################################################################
2260 # Print an error message and set exit status.
2263 warn "automake: ${am_file}.am: ", join (' ', @_), "\n";
2267 # The same, but while scanning configure.in.
2270 # FIXME can run in subdirs.
2271 warn "automake: configure.in: ", join (' ', @_), "\n";
2275 # Print usage information.
2278 print "Usage: automake [OPTION] ... [Makefile]...\n";
2280 print "\nFiles which are automatically distributed, if found:\n";
2281 $~ = "USAGE_FORMAT";
2282 local (@lcomm) = sort ((@common_files, @common_sometimes));
2283 local ($one, $two, $three, $four);
2286 $one = shift @lcomm;
2287 $two = @lcomm ? shift @lcomm : '';
2288 $three = @lcomm ? shift @lcomm : '';
2289 $four = @lcomm ? shift @lcomm : '';
2296 format USAGE_FORMAT =
2297 @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<
2298 $one, $two, $three, $four