* automake.texi (Texinfo): Mention vers*.texi.
[automake.git] / automake.in
blobdd6102c1858c36b731ac359fdc0aae3684764c01
1 #!@PERL@
2 # -*- perl -*-
3 # @configure_input@
5 eval 'exec @PERL@ -S $0 ${1+"$@"}'
6     if 0;
8 # automake - create Makefile.in from Makefile.am
9 # Copyright (C) 1994-99, 2000 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)
14 # any later version.
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
24 # 02111-1307, USA.
26 # Originally written by David Mackenzie <djm@gnu.ai.mit.edu>.
27 # Perl reimplementation by Tom Tromey <tromey@cygnus.com>.
30 # Parameters set by configure.  Not to be changed.  NOTE: assign
31 # VERSION as string so that eg version 0.30 will print correctly.
32 $VERSION = "@VERSION@";
33 $PACKAGE = "@PACKAGE@";
34 $prefix = "@prefix@";
35 $am_dir = "@datadir@/@PACKAGE@";
37 # String constants.
38 $IGNORE_PATTERN = "^##([^#].*)?\$";
39 $WHITE_PATTERN = "^[ \t]*\$";
40 $COMMENT_PATTERN = "^#";
41 $RULE_PATTERN = "^([\$a-zA-Z_.][-.a-zA-Z0-9_(){}/\$]*) *:([^=].*|)\$";
42 $SUFFIX_RULE_PATTERN = "^\\.([a-zA-Z0-9]+)\\.([a-zA-Z0-9]+)\$";
43 $MACRO_PATTERN = "^([A-Za-z0-9_]+)[ \t]*([:+]?)=[ \t]*(.*)\$";
44 $BOGUS_MACRO_PATTERN = "^([^ \t]*)[ \t]*([:+]?)=[ \t]*(.*)\$";
45 $GNITS_VERSION_PATTERN = "[0-9]+\\.[0-9]+([a-z]|\\.[0-9]+)?";
46 $IF_PATTERN = "^if[ \t]+\([A-Za-z][A-Za-z0-9_]*\)[ \t]*\(#.*\)?\$";
47 $ELSE_PATTERN = "^else[ \t]*\(#.*\)?\$";
48 $ENDIF_PATTERN = "^endif[ \t]*\(#.*\)?\$";
49 $PATH_PATTERN='(\\w|[/.-])+';
50 # This will pass through anything not of the prescribed form.
51 $INCLUDE_PATTERN = "^include[ \t]+((\\\$\\\(top_srcdir\\\)/${PATH_PATTERN})|(\\\$\\\(srcdir\\\)/${PATH_PATTERN})|([^/\\\$]${PATH_PATTERN}))[ \t]*(#.*)?\$";
53 # Some regular expressions.  One reason to put them here is that it
54 # makes indentation work better in Emacs.
55 $AC_CONFIG_AUX_DIR_PATTERN = "AC_CONFIG_AUX_DIR\\(([^)]+)\\)";
56 $AM_INIT_AUTOMAKE_PATTERN = "AM_INIT_AUTOMAKE\\([^,]*,([^,)]+)[,)]";
57 $AM_PACKAGE_VERSION_PATTERN = "^\\s*\\[?([^]\\s]+)\\]?\\s*\$";
58 # Note that there is no AC_PATH_TOOL.  But we don't really care.
59 $AC_CHECK_PATTERN = "AC_(CHECK|PATH)_(PROG|PROGS|TOOL)\\(\\[?(\\w+)";
60 $AM_MISSING_PATTERN = "AM_MISSING_PROG\\(\\[?(\\w+)";
61 # Just check for alphanumeric in AC_SUBST.  If you do AC_SUBST(5),
62 # then too bad.
63 $AC_SUBST_PATTERN = "AC_SUBST\\(\\[?(\\w+)";
64 $AM_CONDITIONAL_PATTERN = "AM_CONDITIONAL\\((\\w+)";
66 # Constants to define the "strictness" level.
67 $FOREIGN = 0;
68 $GNU = 1;
69 $GNITS = 2;
71 # These constants are returned by lang_*_rewrite functions.
72 # LANG_SUBDIR means that the resulting object file should be in a
73 # subdir if the source file is.  In this case the file name cannot
74 # have `..' components.
75 $LANG_IGNORE = 0;
76 $LANG_PROCESS = 1;
77 $LANG_SUBDIR = 2;
81 # Variables global to entire run.
83 # TRUE if we should always generate Makefile.in.
84 $force_generation = 1;
86 # Strictness level as set on command line.
87 $default_strictness = $GNU;
89 # Name of strictness level, as set on command line.
90 $default_strictness_name = 'gnu';
92 # This is TRUE if automatic dependency generation code should be
93 # included in generated Makefile.in.
94 $cmdline_use_dependencies = 1;
96 # TRUE if in verbose mode.
97 $verbose = 0;
99 # This holds our (eventual) exit status.  We don't actually exit until
100 # we have processed all input files.
101 $exit_status = 0;
103 # From the Perl manual.
104 $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
106 # TRUE if missing standard files should be installed.
107 $add_missing = 0;
109 # TRUE if we should copy missing files; otherwise symlink if possible.
110 $copy_missing = 0;
112 # TRUE if we should always update files that we know about.
113 $force_missing = 0;
115 # Files found by scanning configure.in for LIBOBJS.
116 %libsources = ();
118 # True if AM_C_PROTOTYPES appears in configure.in.
119 $am_c_prototypes = 0;
121 # Names used in AC_CONFIG_HEADER call.  @config_fullnames holds the
122 # name which appears in AC_CONFIG_HEADER, colon and all.
123 # @config_names holds the file names.  @config_headers holds the '.in'
124 # files.  Ordinarily these are similar, but they can be different if
125 # the weird "NAME:FILE" syntax is used.
126 @config_fullnames = ();
127 @config_names = ();
128 @config_headers = ();
129 # Line number at which AC_CONFIG_HEADER appears in configure.in.
130 $config_header_line = 0;
132 # Directory where output files go.  Actually, output files are
133 # relative to this directory.
134 $output_directory = '.';
136 # Relative location of top build directory.
137 $top_builddir = '';
139 # List of Makefile.am's to process, and their corresponding outputs.
140 @input_files = ();
141 %output_files = ();
143 # Complete list of Makefile.am's that exist.
144 @configure_input_files = ();
146 # List of files in AC_OUTPUT without Makefile.am, and their outputs.
147 @other_input_files = ();
148 # Line number at which AC_OUTPUT seen.
149 $ac_output_line = 0;
151 # List of directories to search for configure-required files.  This
152 # can be set by AC_CONFIG_AUX_DIR.
153 @config_aux_path = ('.', '..', '../..');
154 $config_aux_dir = '';
156 # Whether AC_PROG_MAKE_SET has been seen in configure.in.
157 $seen_make_set = 0;
159 # Whether AM_GNU_GETTEXT has been seen in configure.in.
160 $seen_gettext = 0;
161 # Line number at which AM_GNU_GETTEXT seen.
162 $ac_gettext_line = 0;
164 # Whether ALL_LINGUAS has been seen.
165 $seen_linguas = '';
166 # The actual text.
167 $all_linguas = '';
168 # Line number at which it appears.
169 $all_linguas_line = 0;
171 # 1 if AC_PROG_INSTALL seen.
172 $seen_prog_install = 0;
174 # Whether AC_PATH_XTRA has been seen in configure.in.
175 $seen_path_xtra = 0;
177 # TRUE if AC_DECL_YYTEXT was seen.
178 $seen_decl_yytext = 0;
180 # TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM).  The presence of
181 # AC_CHECK_TOOL also sets this.
182 $seen_canonical = 0;
184 # TRUE if we've seen AC_ARG_PROGRAM.
185 $seen_arg_prog = 0;
187 # TRUE if we've seen AC_PROG_LIBTOOL.
188 $seen_libtool = 0;
189 $libtool_line = 0;
191 # Files installed by libtoolize.
192 @libtoolize_files = ('ltconfig', 'ltmain.sh', 'config.guess', 'config.sub');
194 # TRUE if we've seen AM_MAINTAINER_MODE.
195 $seen_maint_mode = 0;
197 # Actual version we've seen.
198 $package_version = '';
200 # Line number where we saw version definition.
201 $package_version_line = 0;
203 # TRUE if we've seen AM_PATH_LISPDIR.
204 $seen_lispdir = 0;
206 # TRUE if we've seen AM_CHECK_PYTHON.
207 $seen_pythondir = 0;
209 # TRUE if we've seen AC_EXEEXT.
210 $seen_exeext = 0;
212 # TRUE if we've seen AC_OBJEXT.
213 $seen_objext = 0;
215 # TRUE if we've seen AC_ENABLE_MULTILIB.
216 $seen_multilib = 0;
218 # TRUE if we've seen AM_PROG_CC_C_O
219 $seen_cc_c_o = 0;
221 # TRUE if we've seen AM_INIT_AUTOMAKE.
222 $seen_init_automake = 0;
224 # Hash table of discovered configure substitutions.  Keys are names,
225 # values are `FILE:LINE' strings which are used by error message
226 # generation.
227 %configure_vars = ();
229 # This is used to keep track of which variable definitions we are
230 # scanning.  It is only used in certain limited ways, but it has to be
231 # global.  It is declared just for documentation purposes.
232 %vars_scanned = ();
234 # Charsets used by maintainer and in distribution.  MAINT_CHARSET is
235 # handled in a funny way: if seen in the top-level Makefile.am, it is
236 # used for every directory which does not specify a different value.
237 # The rationale here is that some directories (eg gettext) might be
238 # distributions of other packages, and thus require their own charset
239 # info.  However, the DIST_CHARSET must be the same for the entire
240 # package; it can only be set at top-level.
241 # FIXME: this yields bugs when rebuilding.  What to do?  Always
242 # read (and sometimes discard) top-level Makefile.am?
243 $maint_charset = '';
244 $dist_charset = 'utf8';         # recode doesn't support this yet.
246 # Name of input file ("Makefile.in") and output file ("Makefile.am").
247 # These have no directory components.
248 $am_file_name = '';
249 $in_file_name = '';
251 # TRUE if --cygnus seen.
252 $cygnus_mode = 0;
254 # Hash table of AM_CONDITIONAL variables seen in configure.
255 %configure_cond = ();
257 # Map from obsolete macros to hints for new macros.
258 # If you change this, change the corresponding list in aclocal.in.
259 # FIXME: should just put this into a single file.
260 %obsolete_macros =
261     (
262      'AC_FEATURE_CTYPE', "use \`AC_HEADER_STDC'",
263      'AC_FEATURE_ERRNO', "add \`strerror' to \`AC_REPLACE_FUNCS(...)'",
264      'AC_FEATURE_EXIT', '',
265      'AC_SYSTEM_HEADER', '',
267      # Note that we do not handle this one, because it is still run
268      # from AM_CONFIG_HEADER.  So we deal with it specially in
269      # scan_configure.
270      # 'AC_CONFIG_HEADER', "use \`AM_CONFIG_HEADER'",
272      'fp_C_PROTOTYPES', "use \`AM_C_PROTOTYPES'",
273      'fp_PROG_CC_STDC', "use \`AM_PROG_CC_STDC'",
274      'fp_PROG_INSTALL', "use \`AC_PROG_INSTALL'",
275      'fp_WITH_DMALLOC', "use \`AM_WITH_DMALLOC'",
276      'fp_WITH_REGEX', "use \`AM_WITH_REGEX'",
277      'gm_PROG_LIBTOOL', "use \`AM_PROG_LIBTOOL'",
278      'jm_MAINTAINER_MODE', "use \`AM_MAINTAINER_MODE'",
279      'md_TYPE_PTRDIFF_T', "use \`AM_TYPE_PTRDIFF_T'",
280      'ud_PATH_LISPDIR', "use \`AM_PATH_LISPDIR'",
281      'ud_GNU_GETTEXT', "use \`AM_GNU_GETTEXT'",
283      # Now part of autoconf proper, under a different name.
284      'AM_FUNC_FNMATCH', "use \`AC_FUNC_FNMATCH'",
285      'fp_FUNC_FNMATCH', "use \`AC_FUNC_FNMATCH'",
286      'AM_SANITY_CHECK_CC', "automatically done by \`AC_PROG_CC'",
287      'AM_PROG_INSTALL', "use \`AC_PROG_INSTALL'",
288      'AM_EXEEXT', "use \`AC_EXEEXT'",
289      'AM_CYGWIN32', "use \`AC_CYGWIN'",
290      'AM_MINGW32', "use \`AC_MINGW32'",
291      'AM_FUNC_MKTIME', "use \`AC_FUNC_MKTIME'",
293 # These aren't quite obsolete.
294 #      'md_PATH_PROG',
295      );
297 # Regexp to match the above macros.
298 $obsolete_rx = '(' . join ('|', keys %obsolete_macros) . ')';
300 # This maps extensions onto language names.
301 %extension_map = ();
303 # This maps languages names onto properties.
304 %language_map = ();
306 # This holds all the files that would go in `dist_common' which we
307 # discovered while scanning configure.in.  We might distribute these
308 # in the top-level Makefile.in.
309 %configure_dist_common = ();
313 # Initialize global constants and our list of languages that are
314 # internally supported.
315 &initialize_global_constants;
317 &register_language ('c', 'ansi-p=1', 'autodep=', 'flags=CFLAGS',
318                     'compile=$(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)',
319                     'compiler-name=COMPILE',
320                     'output-arg=-c',
321                     'c');
322 &register_language ('cxx', 'linker=CXXLINK', 'autodep=CXX', 'flags=CXXFLAGS',
323                     'compile=$(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)',
324                     'compiler-name=CXXCOMPILE',
325                     'output-arg=-c -o $@',
326                     'c++', 'cc', 'cpp', 'cxx', 'C');
327 &register_language ('objc', 'linker=OBJCLINK', 'autodep=OBJC',
328                     'flags=OBJCFLAGS',
329                     'compile=$(OBJC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS)',
330                     'compiler-name=OBJCCOMPILE',
331                     'output-arg=-c -o $@',
332                     'm');
333 &register_language ('header',
334                     'h', 'H', 'hxx', 'h++', 'hh', 'hpp', 'inc');
336 # For now, yacc and lex can't be handled on a per-exe basis.
337 &register_language ('yacc', 'ansi-p=1',
338                     'y');
339 &register_language ('yaccxx', 'linker=CXXLINK',
340                     'y++', 'yy', 'yxx', 'ypp');
341 &register_language ('lex', 'ansi-p=1',
342                     'l');
343 &register_language ('lexxx', 'linker=CXXLINK',
344                     'l++', 'll', 'lxx', 'lpp');
346 &register_language ('asm',
347                     'flags=CFLAGS', # FIXME: asmflags?
348                     'compile=$(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)', # FIXME: a different compiler?
349                     'compiler-name=COMPILE',
350                     'output-arg=-c',
351                     's', 'S');
353 &register_language ('f77', 'linker=F77LINK', 'flags=FFLAGS',
354                     'compile=$(F77) $(AM_FFLAGS) $(FFLAGS)',
355                     'compiler-name=F77COMPILE',
356                     'output-arg=-c -o $@',
357                     'f', 'for', 'f90');
358 &register_language ('ppf77', 'linker=F77LINK', 'flags=FFLAGS',
359                     'compile=$(F77) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)',
360                     'compiler-name=PPF77COMPILE',
361                     'output-arg=-c -o $@',
362                     'F');
363 &register_language ('ratfor', 'linker=F77LINK',
364                     'flags=RFLAGS', # FIXME also FFLAGS.
365                     'compile=$(F77) $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)',
366                     'compiler-name=RCOMPILE',
367                     'output-arg=-c -o $@',
368                     'r');
369 # FIXME: for now we can't do dependency tracking for Java.
370 # autodep=GCJ
371 &register_language ('java', 'linker=GCJLINK', 'flags=GCJFLAGS',
372                     'compile=$(GCJ) $(DEFS) $(INCLUDES) $(AM_GCJFLAGS) $(GCJFLAGS)',
373                     'compiler-name=GCJCOMPILE',
374                     'output-arg=-c -o $@',
375                     'java', 'class', 'zip', 'jar');
378 # Parse command line.
379 &parse_arguments (@ARGV);
381 # Do configure.in scan only once.
382 &scan_configure;
384 die "automake: no \`Makefile.am' found or specified\n"
385     if ! @input_files;
387 # Now do all the work on each file.
388 foreach $am_file (@input_files)
390     if (! -f ($am_file . '.am'))
391     {
392         &am_error ("\`" . $am_file . ".am' does not exist");
393     }
394     else
395     {
396         &generate_makefile ($output_files{$am_file}, $am_file);
397     }
400 &am_conf_error ("AC_PROG_INSTALL must be used in configure.in")
401     if (! $seen_prog_install);
403 exit $exit_status;
406 ################################################################
408 # Parse command line.
409 sub parse_arguments
411     local (@arglist) = @_;
413     # Start off as gnu.
414     &set_strictness ('gnu');
416     while (@arglist)
417     {
418         if ($arglist[0] eq "--version")
419         {
420             print "automake (GNU $PACKAGE) $VERSION\n\n";
421             print "Copyright (C) 2000 Free Software Foundation, Inc.\n";
422             print "This is free software; see the source for copying conditions.  There is NO\n";
423             print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n";
424             print "Written by Tom Tromey <tromey\@cygnus.com>\n";
426             exit 0;
427         }
428         elsif ($arglist[0] eq "--help")
429         {
430             &usage;
431         }
432         elsif ($arglist[0] =~ /^--amdir=(.+)$/)
433         {
434             $am_dir = $1;
435         }
436         elsif ($arglist[0] eq '--amdir')
437         {
438             &require_argument (@arglist);
439             shift (@arglist);
440             $am_dir = $arglist[0];
441         }
442         elsif ($arglist[0] eq '--gnu')
443         {
444             &set_strictness ('gnu');
445         }
446         elsif ($arglist[0] eq '--gnits')
447         {
448             &set_strictness ('gnits');
449         }
450         elsif ($arglist[0] eq '--cygnus')
451         {
452             $cygnus_mode = 1;
453         }
454         elsif ($arglist[0] eq '--foreign')
455         {
456             &set_strictness ('foreign');
457         }
458         elsif ($arglist[0] eq '--include-deps')
459         {
460             $cmdline_use_dependencies = 1;
461         }
462         elsif ($arglist[0] eq '--ignore-deps' || $arglist[0] eq '-i')
463         {
464             $cmdline_use_dependencies = 0;
465         }
466         elsif ($arglist[0] eq '--no-force')
467         {
468             $force_generation = 0;
469         }
470         elsif ($arglist[0] eq '--force-missing')
471         {
472             $force_missing = 1;
473         }
474         elsif ($arglist[0] =~ /^--output-dir=(.*)$/)
475         {
476             # Set output directory.
477             $output_directory = $1;
478         }
479         elsif ($arglist[0] eq '--output-dir' || $arglist[0] eq '-o')
480         {
481             &require_argument (@arglist);
482             shift (@arglist);
483             $output_directory = $arglist[0];
484         }
485         elsif ($arglist[0] eq '--add-missing' || $arglist[0] eq '-a')
486         {
487             $add_missing = 1;
488         }
489         elsif ($arglist[0] eq '--copy' || $arglist[0] eq '-c')
490         {
491             $copy_missing = 1;
492         }
493         elsif ($arglist[0] eq '--verbose' || $arglist[0] eq '-v')
494         {
495             $verbose = 1;
496         }
497         elsif ($arglist[0] eq '--')
498         {
499             # Stop option processing.
500             shift (@arglist);
501             push (@input_files, @arglist);
502             last;
503         }
504         elsif ($arglist[0] =~ /^-/)
505         {
506             die "automake: unrecognized option -- \`$arglist[0]'\nTry \`automake --help' for more information.\n";
507         }
508         else
509         {
510             # Handle $local:$input syntax.  Note that we only examine
511             # the first ":" file to see if it is automake input; the
512             # rest are just taken verbatim.  We still keep all the
513             # files around for dependency checking, however.
514             local ($local, $input, @rest) = split (/:/, $arglist[0]);
515             if (! $input)
516             {
517                 $input = $local;
518             }
519             else
520             {
521                 # Strip .in; later on .am is tacked on.  That is how
522                 # the automake input file is found.  Maybe not the
523                 # best way, but it is easy to explain.  FIXME: should
524                 # be error if .in is missing.
525                 $input =~ s/\.in$//;
526             }
527             push (@input_files, $input);
528             $output_files{$input} = join (':', ($local, @rest));
529         }
531         shift (@arglist);
532     }
534     # Take global strictness from whatever we currently have set.
535     $default_strictness = $strictness;
536     $default_strictness_name = $strictness_name;
539 # Ensure argument exists, or die.
540 sub require_argument
542     local ($arg, @arglist) = @_;
543     die "automake: no argument given for option \`$arg'\n"
544         if ! @arglist;
547 ################################################################
549 # Generate a Makefile.in given the name of the corresponding Makefile and
550 # the name of the file output by config.status.
551 sub generate_makefile
553     local ($output, $makefile) = @_;
555     ($am_file_name = $makefile) =~ s/^.*\///;
556     $in_file_name = $am_file_name . '.in';
557     $am_file_name .= '.am';
559     # $OUTPUT is encoded.  If it contains a ":" then the first element
560     # is the real output file, and all remaining elements are input
561     # files.  We don't scan or otherwise deal with these input file,
562     # other than to mark them as dependencies.  See scan_configure for
563     # details.
564     local (@secondary_inputs);
565     ($output, @secondary_inputs) = split (/:/, $output);
567     &initialize_per_input;
568     $relative_dir = &dirname ($output);
569     $am_relative_dir = &dirname ($makefile);
571     # At the toplevel directory, we might need config.guess, config.sub
572     # or libtool scripts (ltconfig and ltmain.sh).
573     if ($relative_dir eq '.')
574     {
575         # libtool requires some files.
576         &require_conf_file_with_conf_line ($libtool_line, $FOREIGN,
577                                            @libtoolize_files)
578             if $seen_libtool;
580         # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
581         # config.sub.
582         &require_config_file ($FOREIGN, 'config.guess', 'config.sub')
583             if $seen_canonical;
584     }
586     # We still need Makefile.in here, because sometimes the `dist'
587     # target doesn't re-run automake.
588     if ($am_relative_dir eq $relative_dir)
589     {
590         # Only distribute the files if they are in the same subdir as
591         # the generated makefile.
592         &push_dist_common ($in_file_name, $am_file_name);
593     }
595     push (@sources, '$(SOURCES)')
596         if &variable_defined ('SOURCES');
597     push (@objects, '$(OBJECTS)')
598         if &variable_defined ('OBJECTS');
600     &read_main_am_file ($makefile . '.am');
601     if (&handle_options)
602     {
603         # Fatal error.  Just return, so we can continue with next file.
604         return;
605     }
607     # Must do this after reading .am file.  See read_main_am_file to
608     # understand weird tricks we play there with variables.
609     &define_variable ('subdir', $relative_dir);
611     # Check first, because we might modify some state.
612     &check_cygnus;
613     &check_gnu_standards;
614     &check_gnits_standards;
616     &handle_configure ($output, $makefile, @secondary_inputs);
617     &handle_gettext;
618     &handle_libraries;
619     &handle_ltlibraries;
620     &handle_programs;
621     &handle_scripts;
623     &handle_built_sources;
625     # This must be run after all the sources are scanned.
626     &finish_languages;
628     # Re-init SOURCES and OBJECTS.  FIXME: other code shouldn't depend
629     # on this (but currently does).
630     $contents{'SOURCES'} = join (' ', @sources);
631     $contents{'OBJECTS'} = join (' ', @objects);
632     &define_pretty_variable ('DIST_SOURCES', '', @dist_sources);
634     &handle_multilib;
635     &handle_texinfo;
636     &handle_emacs_lisp;
637     &handle_python;
638     &handle_java;
639     &handle_man_pages;
640     &handle_data;
641     &handle_headers;
642     &handle_subdirs;
643     &handle_tags;
644     &handle_minor_options;
645     &handle_dependencies;
646     &handle_tests;
648     # This must come after most other rules.
649     &handle_dist ($makefile);
651     &handle_footer;
652     &handle_merge_targets ($output);
653     &handle_installdirs;
654     &handle_clean;
655     &handle_phony;
657     &check_typos;
659     if (! -d ($output_directory . '/' . $am_relative_dir))
660     {
661         mkdir ($output_directory . '/' . $am_relative_dir, 0755);
662     }
664     local ($out_file) = $output_directory . '/' . $makefile . ".in";
665     if (! $force_generation && -e $out_file)
666     {
667         local ($am_time) = (stat ($makefile . '.am'))[9];
668         local ($in_time) = (stat ($out_file))[9];
669         # FIXME: should cache these times.
670         local ($conf_time) = (stat ('configure.in'))[9];
671         # FIXME: how to do unsigned comparison?
672         if ($am_time < $in_time || $am_time < $conf_time)
673         {
674             # No need to update.
675             return;
676         }
677         if (-f 'aclocal.m4')
678         {
679             local ($acl_time) = (stat _)[9];
680             return if ($am_time < $acl_time);
681         }
682     }
684     if (! open (GM_FILE, "> " . $out_file))
685     {
686         warn "automake: ${am_file}.in: cannot write: $!\n";
687         $exit_status = 1;
688         return;
689     }
690     print "automake: creating ", $makefile, ".in\n" if $verbose;
692     print GM_FILE $output_vars;
693     # We make sure that `all:' is the first target.
694     print GM_FILE $output_all;
695     print GM_FILE $output_header;
696     print GM_FILE $output_rules;
697     print GM_FILE $output_trailer;
699     if (! close (GM_FILE))
700       {
701         warn "automake: $am_file.in: cannot close: $!\n";
702         $exit_status = 1;
703         return;
704       }
707 ################################################################
709 # Handle AUTOMAKE_OPTIONS variable.  Return 1 on error, 0 otherwise.
710 sub handle_options
712     if (&variable_defined ('AUTOMAKE_OPTIONS'))
713     {
714         foreach (&variable_value_as_list ('AUTOMAKE_OPTIONS', ''))
715         {
716             $options{$_} = 1;
717             if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
718             {
719                 &set_strictness ($_);
720             }
721             elsif ($_ eq 'cygnus')
722             {
723                 $cygnus_mode = 1;
724             }
725             elsif (/ansi2knr/)
726             {
727                 # An option like "../lib/ansi2knr" is allowed.  With
728                 # no path prefix, we assume the required programs are
729                 # in this directory.  We save the actual option for
730                 # later.
731                 $options{'ansi2knr'} = $_;
732             }
733             elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
734                    || $_ eq 'dist-shar' || $_ eq 'dist-zip'
735                    || $_ eq 'dist-tarZ' || $_ eq 'dist-bzip2'
736                    || $_ eq 'dejagnu' || $_ eq 'no-texinfo.tex'
737                    || $_ eq 'readme-alpha' || $_ eq 'check-news'
738                    || $_ eq 'subdir-objects' || $_ eq 'nostdinc')
739             {
740                 # Explicitly recognize these.
741             }
742             elsif ($_ eq 'no-dependencies')
743             {
744                 $use_dependencies = 0;
745             }
746             elsif (/([0-9]+)\.([0-9]+)([a-z])?/)
747             {
748                 # Got a version number.
750                 local ($rmajor, $rminor, $ralpha) = ($1, $2, $3);
752                 if ($VERSION !~ /([0-9]+)\.([0-9]+)([a-z])?/)
753                 {
754                     print STDERR
755                         "automake: programming error: version is incorrect\n";
756                     exit 1;
757                 }
758                 local ($tmajor, $tminor, $talpha) = ($1, $2, $3);
760                 # 2.0 is better than 1.0.
761                 # 1.2 is better than 1.1.
762                 # 1.2a is better than 1.2.
763                 if ($rmajor > $tmajor
764                     || ($rmajor == $tmajor && $rminor > $tminor)
765                     || ($rminor == $tminor && $rminor == $tminor
766                         && $ralpha gt $talpha))
767                 {
768                     &am_line_error ('AUTOMAKE_OPTIONS',
769                                     "require version $_, only have $VERSION");
770                     return 1;
771                 }
772             }
773             else
774             {
775                 &am_line_error ('AUTOMAKE_OPTIONS',
776                                 "option \`" . $_ . "\' not recognized");
777             }
778         }
779     }
781     if ($strictness == $GNITS)
782     {
783         $options{'readme-alpha'} = 1;
784         $options{'check-news'} = 1;
785     }
787     return 0;
790 # Return object extension.  Just once, put some code into the output.
791 # Argument is the name of the output file
792 sub get_object_extension
794     local ($out) = @_;
796     # Maybe require libtool library object files.
797     local ($extension) = '.o';
798     $extension = '.$(OBJEXT)' if $seen_objext;
799     $extension = '.lo' if ($out =~ /\.la$/);
801     if (! $included_generic_compile)
802     {
803         # Boilerplate.
804         local ($xform) = '';
805         if (! defined $options{'nostdinc'})
806         {
807             $xform = ' -I. -I\$(srcdir)';
809             if (&variable_defined ('CONFIG_HEADER'))
810             {
811                 local ($one_hdr);
812                 foreach $one_hdr (split (' ',
813                                          &variable_value ('CONFIG_HEADER')))
814                 {
815                     local ($var);
816                     ($var = &dirname ($one_hdr)) =~ s/(\W)/\\$1/g;
817                     $xform .= ' -I' . $var;
818                 }
819             }
820         }
821         $xform = 's/\@DEFAULT_INCLUDES\@/' . $xform . '/go;';
822         $output_vars .= &file_contents_with_transform ($xform,
823                                                        'comp-vars');
825         $xform = $seen_objext ? 's/^OBJEXT//;' : 's/^OBJEXT.*$//;';
826         $output_rules .= &file_contents_with_transform ($xform, 'compile');
828         &push_phony_cleaners ('compile');
830         # If using X, include some extra variable definitions.  NOTE
831         # we don't want to force these into CFLAGS or anything,
832         # because not all programs will necessarily use X.
833         if ($seen_path_xtra)
834         {
835             local ($var);
836             foreach $var ('X_CFLAGS', 'X_LIBS', 'X_EXTRA_LIBS', 'X_PRE_LIBS')
837             {
838                 &define_configure_variable ($var);
839             }
840         }
842         push (@suffixes, '.c', '.o');
843         push (@suffixes, '.obj') if $seen_objext;
844         push (@clean, 'compile');
846         $included_generic_compile = 1;
847     }
849     if ($seen_libtool && ! $included_libtool_compile)
850     {
851         # Output the libtool compilation rules.
852         $output_rules .= &file_contents ('libtool');
854         &push_phony_cleaners ('libtool');
856         push (@suffixes, '.lo');
857         push (@clean, 'libtool');
859         $included_libtool_compile = 1;
860     }
862     # Check for automatic de-ANSI-fication.
863     if (defined $options{'ansi2knr'})
864     {
865         $extension = '$U' . $extension;
866         if (! $included_knr_compile)
867         {
868             if (! $am_c_prototypes)
869             {
870                 &am_line_error ('AUTOMAKE_OPTIONS',
871                                 "option \`ansi2knr' in use but \`AM_C_PROTOTYPES' not in configure.in");
872                 &keyed_aclocal_warning ('AM_C_PROTOTYPES');
873                 # Only give this error once.
874                 $am_c_prototypes = 1;
875             }
877             # Only require ansi2knr files if they should appear in
878             # this directory.
879             if ($options{'ansi2knr'} eq 'ansi2knr')
880             {
881                 &require_file_with_line ('AUTOMAKE_OPTIONS', $FOREIGN,
882                                          'ansi2knr.c', 'ansi2knr.1');
883                 $output_rules .= &file_contents ('kr-extra');
884                 push (@clean, 'krextra');
885                 &push_phony_cleaners ('krextra');
886             }
888             # Generate rules to build ansi2knr.  If it is in some
889             # other directory, then generate dependencies but have the
890             # rule just run elsewhere.
891             $objext = $seen_objext ? ".\$(OBJEXT)" : ".o";
892             $output_rules .= ($options{'ansi2knr'} . ': '
893                               . $options{'ansi2knr'} . $objext . "\n");
894             if ($options{'ansi2knr'} eq 'ansi2knr')
895             {
896                 $output_rules .= ("\t\$(LINK) ansi2knr" . $objext
897                                   . " \$(LIBS)\n"
898                                   . "ansi2knr" . $objext
899                                   . ": \$(CONFIG_HEADER)\n\n");
900             }
901             else
902             {
903                 $output_rules .= ("\tcd " . &dirname ($options{'ansi2knr'})
904                                   . " && \$(MAKE) \$(AM_MAKEFLAGS) "
905                                   . "ansi2knr\n\n");
906                 # This is required for non-GNU makes.
907                 $output_rules .= ($options{'ansi2knr'} . $objext . ":\n");
908                 $output_rules .= ("\tcd " . &dirname ($options{'ansi2knr'})
909                                   . " && \$(MAKE) \$(AM_MAKEFLAGS)"
910                                   . " ansi2knr" . $objext . "\n\n");
911             }
913             # Make sure ansi2knr can be found: if no path specified,
914             # specify "./".
915             if ($options{'ansi2knr'} eq 'ansi2knr')
916             {
917                 # Substitution from AM_C_PROTOTYPES.  This makes it be
918                 # built only when necessary.
919                 &define_configure_variable ('ANSI2KNR');
920                 # ansi2knr needs to be built before subdirs, so unshift it.
921                 unshift (@all, '$(ANSI2KNR)');
922             }
923             else
924             {
925                 # Found in another directory.
926                 &define_variable ("ANSI2KNR", $options{'ansi2knr'});
927             }
929             $output_rules .= &file_contents ('clean-kr');
931             push (@clean, 'kr');
932             &push_phony_cleaners ('kr');
934             $included_knr_compile = 1;
935         }
936     }
938     return $extension;
941 # Call finish function for each language that was used.
942 sub finish_languages
944     local ($ltcompile, $ltlink) = &libtool_compiler;
946     local ($ext, $name, $lang, %done);
947     local ($non_c) = 1;
948     foreach $ext (sort keys %extension_seen)
949     {
950         $lang = $extension_map{$ext};
952         # Generate the appropriate rules for this extension.  If
953         # dependency tracking was requested, and this extension
954         # supports it, then we don't generate the rule here.
955         local ($comp) = '';
957         if ($use_dependencies && $language_map{$lang . '-autodep'} ne 'no')
958         {
959             # Don't generate the rule, but still generate the variables.
960             if (defined $language_map{$lang . '-compile'})
961             {
962                 $comp = $language_map{$lang . '-compile'};
963             }
964         }
965         elsif (defined $language_map{$lang . '-compile'})
966         {
967             $comp = $language_map{$lang . '-compile'};
969             local ($outarg) = $language_map{$lang . '-output-arg'};
970             if ($language_map{$lang . '-flags'} eq 'CFLAGS')
971             {
972                 # C compilers don't always support -c -o.
973                 if (defined $options{'subdir-objects'})
974                 {
975                     $outarg .= ' -o $@';
976                 }
977             }
979             local ($full) = ("\t\$("
980                              . $language_map{$lang . '-compiler-name'}
981                              . ") "
982                              . $outarg);
983             $output_rules .= (".$ext.o:\n"
984                               . $full
985                               . " \$<\n");
986             # FIXME: Using cygpath should be somehow conditional.
987             $output_rules .= (".$ext.obj:\n"
988                               . $full
989                               . " \`cygpath -w \$<\`\n")
990                 if $seen_objext;
991             $output_rules .= (".$ext.lo:\n"
992                               . "\t\$(LT"
993                               . $language_map{$lang . '-compiler-name'}
994                               . ") "
995                               . $language_map{$lang . '-output-arg'}
996                               # We can always use -c -o with libtool.
997                               . ($language_map{$lang . '-flags'} eq 'CFLAGS'
998                                  ? ' -o $@' : '')
999                               . " \$<\n")
1000                 if $seen_libtool;
1001         }
1003         push (@suffixes, '.' . $ext);
1005         # The rest of the loop is done once per language.
1006         next if defined $done{$lang};
1007         $done{$lang} = 1;
1009         $non_c = 0 if $lang !~ /(objc|cxx|f77|ratfor)$/;
1011         if ($comp ne '')
1012         {
1013             &define_compiler_variable ($language_map{$lang . '-compiler-name'},
1014                                        $ltcompile, $comp);
1015         }
1016         # The compiler's flag must be a configure variable.
1017         if (defined $language_map{$lang . '-flags'})
1018         {
1019             &define_configure_variable ($language_map{$lang . '-flags'});
1020         }
1022         # Compute the function name of the finisher and then call it.
1023         $name = 'lang_' . $lang . '_finish';
1024         & $name ();
1025     }
1027     # If the project is entirely C++ or entirely Fortran 77, don't
1028     # bother with the C stuff.  But if anything else creeps in, then use
1029     # it.
1030     if (! $non_c || scalar keys %suffix_rules > 0)
1031     {
1032         if (! defined $done{'c'})
1033         {
1034             &define_configure_variable ($language_map{'c-flags'});
1035             &define_compiler_variable ($language_map{'c-compiler-name'},
1036                                        $ltcompile,
1037                                        $language_map{'c-compile'});
1038         }
1039         &define_variable ('CCLD', '$(CC)');
1040         &define_variable ('LINK', $ltlink . '$(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
1041     }
1044 # Output a rule to build from a YACC source.  The output from YACC is
1045 # compiled with C or C++, depending on the extension of the YACC file.
1046 sub output_yacc_build_rule
1048     local ($yacc_suffix, $use_ylwrap, $c_suffix) = @_;
1050     local ($suffix);
1051     ($suffix = $yacc_suffix) =~ tr/y/c/;
1052     push (@suffixes, $yacc_suffix, $suffix);
1054     # Generate rule for c/c++.
1055     $output_rules .= "$yacc_suffix$suffix:\n\t";
1057     if ($use_ylwrap)
1058     {
1059         $output_rules .= ('$(SHELL) $(YLWRAP)'
1060                           . ' "$(YACC)" $< y.tab.c $*' . $suffix
1061                           . ' y.tab.h $*.h -- $(AM_YFLAGS) $(YFLAGS)');
1062     }
1063     else
1064     {
1065         $output_rules .= ('$(YACC) $(AM_YFLAGS) $(YFLAGS) $< && mv y.tab.c $*'
1066                           . $suffix . "\n"
1067                           . "\tif test -f y.tab.h; then \\\n"
1068                           . "\tif cmp -s y.tab.h \$*.h; then rm -f y.tab.h; else mv y.tab.h \$*.h; fi; \\\n"
1069                           . "\telse :; fi");
1070     }
1071     $output_rules .= "\n";
1074 sub output_lex_build_rule
1076     local ($lex_suffix, $use_ylwrap) = @_;
1077     local ($c_suffix);
1079     ($c_suffix = $lex_suffix) =~ tr/l/c/;
1080     push (@suffixes, $lex_suffix);
1081     &define_configure_variable ('LEX_OUTPUT_ROOT');
1082     &define_configure_variable ('LEXLIB');
1083     $output_rules .= "$lex_suffix$c_suffix:\n\t";
1085     if ($use_ylwrap)
1086     {
1087         # Is the $@ correct here?  If so, why not use it in the ylwrap
1088         # build rule for yacc above?
1089         $output_rules .= '$(SHELL) $(YLWRAP)'
1090             . ' "$(LEX)" $< $(LEX_OUTPUT_ROOT).c $@ -- $(AM_LFLAGS) $(LFLAGS)';
1091     }
1092     else
1093     {
1094         $output_rules .= '$(LEX) $(AM_LFLAGS) $(LFLAGS) $< && mv $(LEX_OUTPUT_ROOT).c $@';
1095     }
1096     $output_rules .= "\n";
1100 # Check to make sure a source defined in LIBOBJS is not explicitly
1101 # mentioned.  This is a separate function (as opposed to being inlined
1102 # in handle_source_transform) because it isn't always appropriate to
1103 # do this check.
1104 sub check_libobjs_sources
1106     local ($one_file, $unxformed) = @_;
1108     local ($prefix, $file, @files);
1109     foreach $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1110                      'dist_EXTRA_', 'nodist_EXTRA_')
1111     {
1112         if (&variable_defined ($prefix . $one_file . '_SOURCES'))
1113         {
1114             @files = &variable_value_as_list (($prefix
1115                                                . $one_file . '_SOURCES'),
1116                                               'all');
1117         }
1118         elsif ($prefix eq '')
1119         {
1120             @files = ($unxformed . '.c');
1121         }
1122         else
1123         {
1124             next;
1125         }
1127         foreach $file (@files)
1128         {
1129             if (defined $libsources{$file})
1130             {
1131                 &am_line_error ($prefix . $one_file . '_SOURCES',
1132                                 "automatically discovered file \`$file' should not be explicitly mentioned");
1133             }
1134         }
1135     }
1138 # Does much of the actual work for handle_source_transform.
1139 # Arguments are:
1140 #   name of resulting executable or library ("derived")
1141 #   object extension (e.g., `$U.lo')
1142 #   list of source files to transform
1143 # Result is a list
1144 #   first element is name of linker to use (empty string for default linker)
1145 #   remaining elements are names of objects
1146 sub handle_single_transform_list
1148     local ($var, $derived, $obj, @files) = @_;
1149     local (@result) = ();
1150     local ($nonansi_obj) = $obj;
1151     $nonansi_obj =~ s/_//g;
1152     local (%linkers_used) = ();
1153     if (@files > 0)
1154     {
1155         # Turn sources into objects.
1156         foreach (@files)
1157         {
1158             # Configure substitutions in _SOURCES variables are errors.
1159             if (/^\@.*\@$/)
1160             {
1161                 &am_line_error ($var, "$var includes configure substitution \`$_'");
1162                 next;
1163             }
1165             # If the source file is in a subdirectory then the `.o' is
1166             # put into the current directory.
1168             # Split file name into base and extension.
1169             local ($full, $directory, $base, $extension, $linker, $object);
1170             next if ! /^((.*)\/)?([^\/]*)\.(.*)$/;
1171             $full = $_;
1172             $directory = $2;
1173             $base = $3;
1174             $extension = $4;
1176             local ($xbase) = $base;
1178             # We must generate a rule for the object if it requires
1179             # its own flags.
1180             local ($rule) = '';
1181             local ($renamed) = 0;
1183             $extension = &derive_suffix ($extension);
1184             local ($lang) = $extension_map{$extension};
1185             if ($lang)
1186             {
1187                 &saw_extension ($extension);
1188                 # Found the language, so see what it says.
1189                 local ($subr) = 'lang_' . $lang . '_rewrite';
1190                 # Note: computed subr call.
1191                 local ($r) = & $subr ($directory, $base, $extension);
1192                 # Skip this entry if we were asked not to process it.
1193                 next if $r == $LANG_IGNORE;
1195                 # Now extract linker and other info.
1196                 $linker = $language_map{$lang . '-linker'};
1198                 local ($this_obj_ext);
1199                 if ($language_map{$lang . '-ansi-p'})
1200                 {
1201                     $object = $base . $obj;
1202                     $this_obj_ext = $obj;
1203                 }
1204                 else
1205                 {
1206                     $object = $base . $nonansi_obj;
1207                     $this_obj_ext = $nonansi_obj;
1208                 }
1210                 if ($language_map{$lang . '-flags'} ne ''
1211                     && &variable_defined ($derived . '_'
1212                                           . $language_map{$lang . '-flags'}))
1213                 {
1214                     # We have a per-executable flag in effect for this
1215                     # object.  In this case we rewrite the object's
1216                     # name to ensure it is unique.  We also require
1217                     # the `compile' program to deal with compilers
1218                     # where `-c -o' does not work.
1220                     # We choose the name `DERIVED-OBJECT' to ensure
1221                     # (1) uniqueness, and (2) continuity between
1222                     # invocations.  However, this will result in a
1223                     # name that is too long for losing systems, in
1224                     # some situations.  So we provide _SHORTNAME to
1225                     # override.
1227                     local ($dname) = $derived;
1228                     if (&variable_defined ($derived . '_SHORTNAME'))
1229                     {
1230                         # FIXME: should use the same conditional as
1231                         # the _SOURCES variable.  But this is really
1232                         # silly overkill -- nobody should have
1233                         # conditional shortnames.
1234                         $dname = &variable_value ($derived . '_SHORTNAME');
1235                     }
1236                     $object = $dname . '-' . $object;
1238                     &require_file ($FOREIGN, 'compile')
1239                         if $lang eq 'c';
1241                     if (! defined $language_map{$lang . '-compile'})
1242                     {
1243                         print STDERR "automake: programming error: $lang flags defined without compiler\n";
1244                         exit 1;
1245                     }
1246                     # Compute the rule to compile this object.
1247                     local ($flag) = $language_map{$lang . '-flags'};
1248                     local ($val) = "(${derived}_${flag}";
1249                     ($rule = $language_map{$lang . '-compile'}) =~
1250                         s/\(AM_$flag/$val/;
1252                     $rule .= ' ' . $language_map{$lang . '-output-arg'};
1253                     # For C we have to add the -o, because the
1254                     # standard rule doesn't include it.
1255                     if ($language_map{$lang . '-flags'} eq 'CFLAGS')
1256                     {
1257                         $rule .= ' -o $@';
1258                     }
1260                     $renamed = 1;
1261                 }
1263                 # If rewrite said it was ok, put the object into a
1264                 # subdir.
1265                 if ($r == $LANG_SUBDIR && $directory ne '')
1266                 {
1267                     $object = $directory . '/' . $object;
1268                     $xbase = $directory . '/' . $base;
1269                 }
1271                 # If doing dependency tracking, then we can't print
1272                 # the rule.  Also, if we have a subdir object, we need
1273                 # to generate an explicit rule.
1274                 if (($use_dependencies
1275                      && $rule ne ''
1276                      && $language_map{$lang . '-autodep'} ne 'no')
1277                     || ($r == $LANG_SUBDIR && $directory ne ''))
1278                 {
1279                     $rule = '';
1280                     local ($obj_sans_ext) = substr ($object, 0,
1281                                                     - length ($this_obj_ext));
1282                     $lang_specific_files{$lang} .= (' ' . $derived
1283                                                     . ' ' . $full
1284                                                     . ' ' . $obj_sans_ext);
1285                 }
1286             }
1287             elsif ($extension eq 'o')
1288             {
1289                 # This is probably the result of a direct suffix rule.
1290                 # In this case we just accept the rewrite.  FIXME:
1291                 # this fails if we want libtool objects.
1292                 $object = $base . '.' . $extension;
1293                 $linker = '';
1294             }
1295             else
1296             {
1297                 # No error message here.  Used to have one, but it was
1298                 # very unpopular.
1299                 next;
1300             }
1302             $linkers_used{$linker} = 1;
1304             push (@result, $object);
1306             if (defined $object_map{$object})
1307             {
1308                 if ($object_map{$object} ne $full)
1309                 {
1310                     &am_error ("object \`$object' created by \`$full' and \`$object_map{$object}'");
1311                 }
1312             }
1313             else
1314             {
1315                 local (@dep_list) = ();
1316                 $object_map{$object} = $full;
1318                 # If file is in subdirectory, we need explicit
1319                 # dependency.
1320                 if ($directory ne '' || $renamed)
1321                 {
1322                     push (@dep_list, $full);
1323                 }
1325                 # If resulting object is in subdir, we need to make
1326                 # sure the subdir exists at build time.
1327                 if ($object =~ /\//)
1328                 {
1329                     # FIXME: check that $DIRECTORY is somewhere in the
1330                     # project
1332                     # We don't allow `..' in object file names for
1333                     # *any* source, not just Java.  For Java it just
1334                     # doesn't make sense, but in general it is
1335                     # a problem because we can't pick a good name for
1336                     # the .deps entry.
1337                     if ($object =~ /(\/|^)\.\.\//)
1338                     {
1339                         &am_error ("\`$full' contains \`..' component but should not");
1340                     }
1342                     push (@dep_list, $directory . '/.dirstamp');
1344                     # If we're generating dependencies, we also want
1345                     # to make sure that the appropriate subdir of the
1346                     # .deps directory is created.
1347                     if ($use_dependencies)
1348                     {
1349                         push (@dep_list, '.deps/' . $directory . '/.dirstamp');
1350                     }
1352                     if (! defined $directory_map{$directory})
1353                     {
1354                         $directory_map{$directory} = 1;
1355                         $output_rules .= ($directory . "/.dirstamp:\n"
1356                                           . "\t\@\$(mkinstalldirs) $directory\n"
1357                                           . "\t\@: > $directory/.dirstamp\n");
1358                         if ($use_dependencies)
1359                         {
1360                             $output_rules .= ('.deps/' . $directory
1361                                               . "/.dirstamp:\n"
1362                                               . "\t\@\$(mkinstalldirs) .deps/$directory\n"
1363                                               . "\t\@: > .deps/$directory/.dirstamp\n");
1364                         }
1365                     }
1366                 }
1368                 &pretty_print_rule ($object . ':', "\t", @dep_list)
1369                     if scalar @dep_list > 0 || $rule ne '';
1371                 # Print the rule if we have one.
1372                 if ($rule ne '')
1373                 {
1374                     # Turn `$@' into name of our object file.
1375                     local ($xform);
1376                     ($xform = $object) =~ s,/,\\/,g;
1377                     $rule =~ s/\$\@/$xform/;
1379                     # We cannot use $< here since this is an explicit
1380                     # rule and not all makes handle that.
1381                     $rule .= " \`test -f $full || echo '\$(srcdir)/'\`$full";
1383                     # FIXME: handle .lo and .obj as well.
1384                     $output_rules .= "\t" . $rule . "\n";
1385                 }
1386             }
1388             # Transform .o or $o file into .P file (for automatic
1389             # dependency code).
1390             local ($depfile) = $object;
1391             $depfile =~ s/\.([^.]*)$/.P$1/;
1392             $depfile =~ s/\$\(OBJEXT\)$/o/ if $seen_objext;
1393             $dep_files{'$(DEPDIR)/' . $depfile} = 1;
1394         }
1395     }
1397     return (&resolve_linker (%linkers_used), @result);
1400 # Handle SOURCE->OBJECT transform for one program or library.
1401 # Arguments are:
1402 #   canonical (transformed) name of object to build
1403 #   actual name of object to build
1404 #   object extension (ie either `.o' or `$o'.
1405 # Return result is name of linker variable that must be used.
1406 # Empty return means just use `LINK'.
1407 sub handle_source_transform
1409     # one_file is canonical name.  unxformed is given name.  obj is
1410     # object extension.
1411     local ($one_file, $unxformed, $obj) = @_;
1413     local ($linker) = '';
1415     if (&variable_defined ($one_file . "_OBJECTS"))
1416     {
1417         &am_line_error ($one_file . '_OBJECTS',
1418                         $one_file . '_OBJECTS', 'should not be defined');
1419         # No point in continuing.
1420         return;
1421     }
1423     local (@files, @result, $prefix, $temp, $xpfx);
1424     local (%used_pfx) = ();
1425     foreach $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1426                      'dist_EXTRA_', 'nodist_EXTRA_')
1427     {
1428         # We are going to define _OBJECTS variables using the prefix.
1429         # Then we glom them all together.  So we can't use the null
1430         # prefix here as we need it later.
1431         $xpfx = ($prefix eq '') ? 'am_' : $prefix;
1433         @files = ();
1434         local ($var) = $prefix . $one_file . "_SOURCES";
1435         if (&variable_defined ($var))
1436         {
1437             # Keep track of which prefixes we saw.
1438             $used_pfx{$xpfx} = 1
1439                 unless $prefix =~ /EXTRA_/;
1441             push (@sources, '$(' . $prefix . $one_file . "_SOURCES)");
1442             push (@objects, '$(' . $xpfx . $one_file . "_OBJECTS)")
1443                 unless $prefix =~ /EXTRA_/;
1444             push (@dist_sources, '$(' . $prefix . $one_file . "_SOURCES)")
1445                 unless $prefix =~ /^nodist_/;
1446             local (@conds) = &variable_conditions ($var);
1447             if (! @conds)
1448             {
1449                 @files = &variable_value_as_list ($var, '');
1450             }
1451             else
1452             {
1453                 local ($cond);
1454                 foreach $cond (@conds)
1455                 {
1456                     @files = &variable_value_as_list ($var, $cond);
1457                     ($temp, @result) =
1458                         &handle_single_transform_list ($var, $one_file, $obj,
1459                                                        @files);
1460                     $linker = $temp if $linker eq '';
1462                     # Define _OBJECTS conditionally.
1463                     &define_pretty_variable ($xpfx . $one_file . '_OBJECTS',
1464                                              $cond, @result)
1465                         unless $prefix =~ /EXTRA_/;
1466                 }
1468                 next;
1469             }
1470         }
1472         # Avoid defining needless variables.
1473         next if (scalar @files == 0);
1475         ($temp, @result) = &handle_single_transform_list ($var, $one_file,
1476                                                           $obj, @files);
1477         $linker = $temp if $linker eq '';
1478         &define_pretty_variable ($xpfx . $one_file . "_OBJECTS", '', @result)
1479             unless $prefix =~ /EXTRA_/;
1480     }
1482     local (@keys) = sort keys %used_pfx;
1483     if (scalar @keys == 0)
1484     {
1485         &define_variable ($one_file . "_SOURCES", $unxformed . ".c");
1486         push (@sources, $unxformed . '.c');
1487         push (@dist_sources, $unxformed . '.c');
1488         push (@objects, $unxformed . $obj);
1489         push (@files, $unxformed . '.c');
1491         ($temp, @result) = &handle_single_transform_list ($one_file . '_SOURCES',
1492                                                           $one_file, $obj,
1493                                                           @files);
1494         $linker = $temp if $linker eq '';
1495         &define_pretty_variable ($one_file . "_OBJECTS", '', @result)
1496     }
1497     else
1498     {
1499         grep ($_ = '$(' . $_ . $one_file . '_OBJECTS)', @keys);
1500         &define_pretty_variable ($one_file . '_OBJECTS', '', @keys);
1501     }
1503     return $linker;
1506 # Handle the BUILT_SOURCES variable.
1507 sub handle_built_sources
1509     return unless &variable_defined ('BUILT_SOURCES');
1511     local (@sources) = &variable_value_as_list ('BUILT_SOURCES', 'all');
1512     local ($s);
1513     foreach $s (@sources)
1514     {
1515         if (/^\@.*\@$/)
1516         {
1517             # FIXME: is this really the right thing to do?
1518             &am_line_error ('BUILT_SOURCES',
1519                             "\`BUILT_SOURCES' should not contain a configure substitution");
1520             last;
1521         }
1522     }
1525 # Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
1526 # Also, generate _DEPENDENCIES variable if appropriate.
1527 # Arguments are:
1528 #   transformed name of object being built, or empty string if no object
1529 #   name of _LDADD/_LIBADD-type variable to examine
1530 #   boolean (lex_seen) which is true if a lex source file was seen in this
1531 #     object.  valid only for LDADDs, not LIBADDs.
1532 # Returns 1 if LIBOBJS seen, 0 otherwise.
1533 sub handle_lib_objects
1535     local ($xname, $var, $lex_seen) = @_;
1536     local ($ret);
1538     die "automake: programming error 1 in handle_lib_objects\n"
1539         if ! &variable_defined ($var);
1541     die "automake: programming error 2 in handle_lib_objects\n"
1542         if $lex_seen && $var =~ /LIBADD/;
1544     local (@conds) = &variable_conditions ($var);
1545     if (! @conds)
1546     {
1547         $ret = &handle_lib_objects_cond ($xname, $var, $lex_seen, '');
1548     }
1549     else
1550     {
1551         local ($cond);
1552         $ret = 0;
1553         foreach $cond (@conds)
1554         {
1555             if (&handle_lib_objects_cond ($xname, $var, $lex_seen, $cond))
1556             {
1557                 $ret = 1;
1558             }
1559         }
1560     }
1562     return $ret;
1565 # Subroutine of handle_lib_objects: handle a particular condition.
1566 sub handle_lib_objects_cond
1568     local ($xname, $var, $lex_seen, $cond) = @_;
1570     # We recognize certain things that are commonly put in LIBADD or
1571     # LDADD.
1572     local ($lsearch);
1573     local (@dep_list) = ();
1575     local ($seen_libobjs) = 0;
1576     local ($flagvar) = 0;
1578     foreach $lsearch (&variable_value_as_list ($var, $cond))
1579     {
1580         # Skip -lfoo and -Ldir; these are explicitly allowed.
1581         next if $lsearch =~ /^-[lL]/;
1582         if (! $flagvar && $lsearch =~ /^-/)
1583         {
1584             if ($var =~ /^(.*)LDADD$/)
1585             {
1586                 # Skip -dlopen and -dlpreopen; these are explicitly allowed.
1587                 next if $lsearch =~ /^-dl(pre)?open$/;
1588                 &am_line_error ($var, "linker flags such as \`$lsearch' belong in \`${1}LDFLAGS");
1589             }
1590             else
1591             {
1592                 # Only get this error once.
1593                 $flagvar = 1;
1594                 &am_line_error ($var, "linker flags such as \`$lsearch' belong in \`${1}LDFLAGS");
1595             }
1596         }
1598         # Assume we have a file of some sort, and push it onto the
1599         # dependency list.  Autoconf substitutions are not pushed;
1600         # rarely is a new dependency substituted into (eg) foo_LDADD
1601         # -- but "bad things (eg -lX11) are routinely substituted.
1602         # Note that LIBOBJS and ALLOCA are exceptions to this rule,
1603         # and handled specially below.
1604         push (@dep_list, $lsearch)
1605             unless $lsearch =~ /^\@.*\@$/;
1607         # Automatically handle @LIBOBJS@ and @ALLOCA@.  Basically this
1608         # means adding entries to dep_files.
1609         if ($lsearch =~ /^\@(LT)?LIBOBJS\@$/)
1610         {
1611             local ($myobjext) = ($1 ? 'l' : '') . 'o';
1613             push (@dep_list, $lsearch);
1614             $seen_libobjs = 1;
1615             if (! keys %libsources
1616                 && ! &variable_defined ($1 . 'LIBOBJS'))
1617             {
1618                 &am_line_error ($var, "\@$1" . "LIBOBJS\@ seen but never set in \`configure.in'");
1619             }
1621             local ($iter, $rewrite);
1622             foreach $iter (keys %libsources)
1623             {
1624                 if ($iter =~ /\.([cly])$/)
1625                 {
1626                     &saw_extension ($1);
1627                     &saw_extension ('c');
1628                 }
1630                 if ($iter =~ /\.h$/)
1631                 {
1632                     &require_file_with_line ($var, $FOREIGN, $iter);
1633                 }
1634                 elsif ($iter ne 'alloca.c')
1635                 {
1636                     ($rewrite = $iter) =~ s/\.c$/.P$myobjext/;
1637                     $dep_files{'$(DEPDIR)/' . $rewrite} = 1;
1638                     ($rewrite = $iter) =~ s/(\W)/\\$1/g;
1639                     $rewrite = "^" . $rewrite . "\$";
1640                     # Only require the file if it is not a built source.
1641                     if (! &variable_defined ('BUILT_SOURCES')
1642                         || ! grep (/$rewrite/,
1643                                    &variable_value_as_list ('BUILT_SOURCES',
1644                                                             'all')))
1645                     {
1646                         &require_file_with_line ($var, $FOREIGN, $iter);
1647                     }
1648                 }
1649             }
1650         }
1651         elsif ($lsearch =~ /^\@(LT)?ALLOCA\@$/)
1652         {
1653             local ($myobjext) = ($1 ? 'l' : '') . 'o';
1655             push (@dep_list, $lsearch);
1656             &am_line_error ($var,
1657                             "\@$1" . "ALLOCA\@ seen but \`AC_FUNC_ALLOCA' not in \`configure.in'")
1658                 if ! defined $libsources{'alloca.c'};
1659             $dep_files{'$(DEPDIR)/alloca.P' . $myobjext} = 1;
1660             &require_file_with_line ($var, $FOREIGN, 'alloca.c');
1661             &saw_extension ('c');
1662         }
1663     }
1665     if ($xname ne '' && ! &variable_defined ($xname . '_DEPENDENCIES', $cond))
1666     {
1667         &define_pretty_variable ($xname . '_DEPENDENCIES', $cond, @dep_list);
1668     }
1670     return $seen_libobjs;
1673 # Canonicalize a name, and check to make sure the non-canonical name
1674 # is never used.  Returns canonical name.  Arguments are name and a
1675 # list of suffixes to check for.
1676 sub check_canonical_spelling
1678     local ($name, @suffixes) = @_;
1679     local ($xname, $xt);
1681     ($xname = $name) =~ tr/A-Za-z0-9_/_/c;
1682     if ($xname ne $name)
1683     {
1684         local ($xt);
1685         foreach $xt (@suffixes)
1686         {
1687             &am_line_error ($name . $xt,
1688                             "invalid variable \`" . $name . $xt
1689                             . "'; should be \`" . $xname . $xt . "'")
1690                 if &variable_defined ($name . $xt);
1691         }
1692     }
1694     return $xname;
1697 # Handle C programs.
1698 sub handle_programs
1700     local (@proglist) = &am_install_var ('-clean',
1701                                          'progs', 'PROGRAMS',
1702                                          'bin', 'sbin', 'libexec', 'pkglib',
1703                                          'noinst', 'check');
1704     return if ! @proglist;
1706     # If a program is installed, this is required.  We only want this
1707     # error to appear once.
1708     &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
1709         unless $seen_arg_prog;
1710     $seen_arg_prog = 1;
1712     local ($one_file, $xname, $munge);
1714     local ($seen_libobjs) = 0;
1715     foreach $one_file (@proglist)
1716     {
1717         local ($obj) = &get_object_extension ($one_file);
1719         # Canonicalize names and check for misspellings.
1720         $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
1721                                             '_SOURCES', '_OBJECTS',
1722                                             '_DEPENDENCIES');
1724         # FIXME: Using a trick to figure out if any lex sources appear
1725         # in our program; should use some cleaner method.
1726         local ($lex_num) = scalar (keys %lex_sources);
1727         local ($linker) = &handle_source_transform ($xname, $one_file, $obj);
1728         local ($lex_file_seen) = (scalar (keys %lex_sources) > $lex_num);
1730         local ($xt) = '';
1731         if (&variable_defined ($xname . "_LDADD"))
1732         {
1733             if (&handle_lib_objects ($xname, $xname . '_LDADD',
1734                                      $lex_file_seen))
1735             {
1736                 $seen_libobjs = 1;
1737             }
1738             $lex_file_seen = 0;
1739             $xt = '_LDADD';
1740         }
1741         else
1742         {
1743             # User didn't define prog_LDADD override.  So do it.
1744             &define_variable ($xname . '_LDADD', '$(LDADD)');
1746             # This does a bit too much work.  But we need it to
1747             # generate _DEPENDENCIES when appropriate.
1748             if (&variable_defined ('LDADD'))
1749             {
1750                 if (&handle_lib_objects ($xname, 'LDADD', $lex_file_seen))
1751                 {
1752                     $seen_libobjs = 1;
1753                 }
1754                 $lex_file_seen = 0;
1755             }
1756             elsif (! &variable_defined ($xname . '_DEPENDENCIES'))
1757             {
1758                 &define_variable ($xname . '_DEPENDENCIES', '');
1759             }
1760             $xt = '_SOURCES'
1761         }
1763         if (&variable_defined ($xname . '_LIBADD'))
1764         {
1765             &am_line_error ($xname . '_LIBADD',
1766                             "use \`" . $xname . "_LDADD', not \`"
1767                             . $xname . "_LIBADD'");
1768         }
1770         if (! &variable_defined ($xname . '_LDFLAGS'))
1771         {
1772             # Define the prog_LDFLAGS variable.
1773             &define_variable ($xname . '_LDFLAGS', '');
1774         }
1776         # Determine program to use for link.
1777         local ($xlink);
1778         if (&variable_defined ($xname . '_LINK'))
1779         {
1780             $xlink = $xname . '_LINK';
1781         }
1782         else
1783         {
1784             $xlink = $linker ? $linker : 'LINK';
1785         }
1787         local ($xexe);
1788         if ($seen_exeext && $one_file !~ /\./)
1789         {
1790             $xexe = 's/\@EXEEXT\@/\$(EXEEXT)/g;';
1791         }
1792         else
1793         {
1794             $xexe = 's/\@EXEEXT\@//g;';
1795         }
1797         $output_rules .=
1798             &file_contents_with_transform
1799                 ('s/\@PROGRAM\@/' . $one_file . '/go;'
1800                  . 's/\@XPROGRAM\@/' . $xname . '/go;'
1801                  . 's/\@XLINK\@/' . $xlink . '/go;'
1802                  . $xexe,
1803                  'program');
1804     }
1806     if (&variable_defined ('LDADD') && &handle_lib_objects ('', 'LDADD', 0))
1807     {
1808         $seen_libobjs = 1;
1809     }
1811     if ($seen_libobjs)
1812     {
1813         foreach $one_file (@proglist)
1814         {
1815             # Canonicalize names.
1816             ($xname = $one_file) =~ tr/A-Za-z0-9_/_/c;
1818             if (&variable_defined ($xname . '_LDADD'))
1819             {
1820                 &check_libobjs_sources ($xname, $xname . '_LDADD');
1821             }
1822             elsif (&variable_defined ('LDADD'))
1823             {
1824                 &check_libobjs_sources ($xname, 'LDADD');
1825             }
1826         }
1827     }
1831 # Handle libraries.
1832 sub handle_libraries
1834     local (@liblist) = &am_install_var ('-clean',
1835                                         'libs', 'LIBRARIES',
1836                                         'lib', 'pkglib', 'noinst', 'check');
1837     return if ! @liblist;
1839     local (%valid) = &am_primary_prefixes ('LIBRARIES', 0, 'lib', 'pkglib',
1840                                            'noinst', 'check');
1841     if (! defined $configure_vars{'RANLIB'})
1842     {
1843         local ($key);
1844         foreach $key (keys %valid)
1845         {
1846             if (&variable_defined ($key . '_LIBRARIES'))
1847             {
1848                 &am_line_error ($key . '_LIBRARIES', "library used but \`RANLIB' not defined in \`configure.in'");
1849                 # Only get this error once.  If this is ever printed,
1850                 # we have a bug.
1851                 $configure_vars{'RANLIB'} = 'BUG';
1852                 last;
1853             }
1854         }
1855     }
1857     local ($onelib);
1858     local ($munge);
1859     local ($xlib);
1860     local ($seen_libobjs) = 0;
1861     foreach $onelib (@liblist)
1862     {
1863         # Check that the library fits the standard naming convention.
1864         if ($onelib !~ /^lib.*\.a$/)
1865         {
1866             # FIXME should put line number here.  That means mapping
1867             # from library name back to variable name.
1868             &am_error ("\`$onelib' is not a standard library name");
1869         }
1871         local ($obj) = &get_object_extension ($onelib);
1873         # Canonicalize names and check for misspellings.
1874         $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
1875                                            '_OBJECTS', '_DEPENDENCIES', '_AR');
1877         if (! &variable_defined ($xlib . '_AR'))
1878         {
1879             &define_variable ($xlib . '_AR', '$(AR) cru');
1880         }
1882         if (&variable_defined ($xlib . '_LIBADD'))
1883         {
1884             if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
1885             {
1886                 $seen_libobjs = 1;
1887             }
1888         }
1889         else
1890         {
1891             # Generate support for conditional object inclusion in
1892             # libraries.
1893             &define_variable ($xlib . "_LIBADD", '');
1894         }
1896         if (&variable_defined ($xlib . '_LDADD'))
1897         {
1898             &am_line_error ($xlib . '_LDADD',
1899                             "use \`" . $xlib . "_LIBADD', not \`"
1900                             . $xlib . "_LDADD'");
1901         }
1903         # Make sure we at look at this.
1904         &examine_variable ($xlib . '_DEPENDENCIES');
1906         &handle_source_transform ($xlib, $onelib, $obj);
1908         $output_rules .=
1909             &file_contents_with_transform ('s/\@LIBRARY\@/' . $onelib . '/go;'
1910                                            . 's/\@XLIBRARY\@/'
1911                                            . $xlib . '/go;',
1912                                            'library');
1913     }
1915     if ($seen_libobjs)
1916     {
1917         foreach $onelib (@liblist)
1918         {
1919             # Canonicalize names.
1920             ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
1921             if (&variable_defined ($xlib . '_LIBADD'))
1922             {
1923                 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
1924             }
1925         }
1926     }
1928     &define_variable ('AR', 'ar');
1929     &define_configure_variable ('RANLIB');
1932 # Handle shared libraries.
1933 sub handle_ltlibraries
1935     local (@liblist) = &am_install_var ('-clean',
1936                                         'ltlib', 'LTLIBRARIES',
1937                                         'noinst', 'lib', 'pkglib', 'check');
1938     return if ! @liblist;
1940     local (%instdirs);
1941     local (%valid) = &am_primary_prefixes ('LTLIBRARIES', 0, 'lib', 'pkglib',
1942                                            'noinst', 'check');
1944     local ($key);
1945     foreach $key (keys %valid)
1946     {
1947         if (&variable_defined ($key . '_LTLIBRARIES'))
1948         {
1949             if (!$seen_libtool)
1950             {
1951                 &am_line_error ($key . '_LTLIBRARIES', "library used but \`LIBTOOL' not defined in \`configure.in'");
1952                 # Only get this error once.  If this is ever printed,
1953                 # we have a bug.
1954                 $configure_vars{'LIBTOOL'} = 'BUG';
1955                 $seen_libtool = 1;
1956             }
1958             # Get the installation directory of each library.
1959             for (&variable_value_as_list ($key . '_LTLIBRARIES', 'all'))
1960             {
1961                 if ($instdirs{$_})
1962                 {
1963                     &am_error ("\`$_' is already going to be installed in \`$instdirs{$_}'");
1964                 }
1965                 else
1966                 {
1967                     $instdirs{$_} = $key;
1968                 }
1969             }
1970         }
1971     }
1973     local ($onelib);
1974     local ($munge);
1975     local ($xlib);
1976     local ($seen_libobjs) = 0;
1977     foreach $onelib (@liblist)
1978     {
1979         local ($obj) = &get_object_extension ($onelib);
1981         # Canonicalize names and check for misspellings.
1982         $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
1983                                            '_SOURCES', '_OBJECTS',
1984                                            '_DEPENDENCIES');
1986         if (! &variable_defined ($xlib . '_LDFLAGS'))
1987         {
1988             # Define the lib_LDFLAGS variable.
1989             &define_variable ($xlib . '_LDFLAGS', '');
1990         }
1992         # Check that the library fits the standard naming convention.
1993         $libname_rx = "^lib.*\.la";
1994         if (&variable_value ($xlib . '_LDFLAGS') =~ /-module/
1995             || &variable_value ('LDFLAGS') =~ /-module/)
1996         {
1997                 # Relax name checking for libtool modules.
1998                 $libname_rx = "\.la";
1999         }
2000         if ($onelib !~ /$libname_rx$/)
2001         {
2002             # FIXME this should only be a warning for foreign packages
2003             # FIXME should put line number here.  That means mapping
2004             # from library name back to variable name.
2005             &am_error ("\`$onelib' is not a standard libtool library name");
2006         }
2008         if (&variable_defined ($xlib . '_LIBADD'))
2009         {
2010             if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
2011             {
2012                 $seen_libobjs = 1;
2013             }
2014         }
2015         else
2016         {
2017             # Generate support for conditional object inclusion in
2018             # libraries.
2019             &define_variable ($xlib . "_LIBADD", '');
2020         }
2022         if (&variable_defined ($xlib . '_LDADD'))
2023         {
2024             &am_line_error ($xlib . '_LDADD',
2025                             "use \`" . $xlib . "_LIBADD', not \`"
2026                             . $xlib . "_LDADD'");
2027         }
2029         # Make sure we at look at this.
2030         &examine_variable ($xlib . '_DEPENDENCIES');
2032         local ($linker) = &handle_source_transform ($xlib, $onelib, $obj);
2034         # Determine program to use for link.
2035         local ($xlink);
2036         if (&variable_defined ($xlib . '_LINK'))
2037         {
2038             $xlink = $xlib . '_LINK';
2039         }
2040         else
2041         {
2042             $xlink = $linker ? $linker : 'LINK';
2043         }
2045         local ($rpath);
2046         if ($instdirs{$onelib} eq 'EXTRA' || $instdirs{$onelib} eq 'noinst')
2047         {
2048             # It's an EXTRA_ library, so we can't specify -rpath,
2049             # because we don't know where the library will end up.
2050             # The user probably knows, but generally speaking automake
2051             # doesn't -- and in fact configure could decide
2052             # dynamically between two different locations.
2053             $rpath = 's/\@RPATH\@//go;';
2054         }
2055         else
2056         {
2057             $rpath = ('s/\@RPATH\@/-rpath \$(' . $instdirs{$onelib}
2058                       . 'dir)/go;');
2059         }
2061         $output_rules .=
2062             &file_contents_with_transform ('s/\@LTLIBRARY\@/'
2063                                            . $onelib . '/go;'
2064                                            . 's/\@XLTLIBRARY\@/'
2065                                            . $xlib . '/go;'
2066                                            . $rpath
2067                                            . 's/\@XLINK\@/' . $xlink . '/go;',
2068                                            'ltlibrary');
2069     }
2071     if ($seen_libobjs)
2072     {
2073         foreach $onelib (@liblist)
2074         {
2075             # Canonicalize names.
2076             ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
2077             if (&variable_defined ($xlib . '_LIBADD'))
2078             {
2079                 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2080             }
2081         }
2082     }
2085 # See if any _SOURCES variable were misspelled.  Also, make sure that
2086 # EXTRA_ variables don't contain configure substitutions.
2087 sub check_typos
2089     local ($varname, $primary);
2090     foreach $varname (keys %contents)
2091     {
2092         foreach $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
2093                           '_DEPENDENCIES')
2094         {
2095             if ($varname =~ /$primary$/ && ! $content_seen{$varname})
2096             {
2097                 &am_line_error ($varname,
2098                                 "invalid unused variable name: \`$varname'");
2099             }
2100         }
2101     }
2104 # Handle scripts.
2105 sub handle_scripts
2107     # NOTE we no longer automatically clean SCRIPTS, because it is
2108     # useful to sometimes distribute scripts verbatim.  This happens
2109     # eg in Automake itself.
2110     &am_install_var ('-candist', 'scripts', 'SCRIPTS',
2111                      'bin', 'sbin', 'libexec', 'pkgdata',
2112                      'noinst', 'check');
2114     local ($scripts_installed) = 0;
2115     # Set $scripts_installed if appropriate.  Make sure we only find
2116     # scripts which are actually installed -- this is why we can't
2117     # simply use the return value of am_install_var.
2118     local (%valid) = &am_primary_prefixes ('SCRIPTS', 1, 'bin', 'sbin',
2119                                            'libexec', 'pkgdata',
2120                                            'noinst', 'check');
2121     local ($key);
2122     foreach $key (keys %valid)
2123     {
2124         if ($key ne 'noinst'
2125             && $key ne 'check'
2126             && &variable_defined ($key . '_SCRIPTS'))
2127         {
2128             $scripts_installed = 1;
2129             # push (@check_tests, 'check-' . $key . 'SCRIPTS');
2130         }
2131     }
2133     if ($scripts_installed)
2134     {
2135         # If a program is installed, this is required.  We only want this
2136         # error to appear once.
2137         &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
2138             unless $seen_arg_prog;
2139         $seen_arg_prog = 1;
2140     }
2143 # Search a file for a "version.texi" Texinfo include.  Return the name
2144 # of the include file if found, or the empty string if not.  A
2145 # "version.texi" file is actually any file whose name matches
2146 # "vers*.texi".
2147 sub scan_texinfo_file
2149     local ($filename) = @_;
2151     if (! open (TEXI, $filename))
2152     {
2153         &am_error ("couldn't open \`$filename': $!");
2154         return '';
2155     }
2156     print "automake: reading $filename\n" if $verbose;
2158     local ($vfile, $outfile);
2159     while (<TEXI>)
2160     {
2161         if (/^\@setfilename +(\S+)/)
2162         {
2163             $outfile = $1;
2164             last if ($vfile);
2165         }
2167         if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
2168         {
2169             # Found version.texi include.
2170             $vfile = $1;
2171             last if $outfile;
2172         }
2173     }
2175     close (TEXI);
2176     return ($outfile, $vfile);
2179 # Handle all Texinfo source.
2180 sub handle_texinfo
2182     &am_line_error ('TEXINFOS',
2183                     "\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
2184         if &variable_defined ('TEXINFOS');
2185     return if (! &variable_defined ('info_TEXINFOS')
2186                && ! &variable_defined ('html_TEXINFOS'));
2188     if (&variable_defined ('html_TEXINFOS'))
2189     {
2190         &am_line_error ('html_TEXINFOS',
2191                         "HTML generation not yet supported");
2192         return;
2193     }
2195     local (@texis) = &variable_value_as_list ('info_TEXINFOS', 'all');
2197     local (@info_deps_list, @dvis_list, @texi_deps);
2198     local ($infobase, $info_cursor);
2199     local (%versions);
2200     local ($done) = 0;
2201     local ($vti);
2202     local ($tc_cursor, @texi_cleans);
2203     local ($canonical);
2205     foreach $info_cursor (@texis)
2206     {
2207         # FIXME: This is mildly hacky, since it recognizes "txinfo".
2208         # I don't feel like making it right.
2209         ($infobase = $info_cursor) =~ s/\.te?xi(nfo)?$//;
2211         # If 'version.texi' is referenced by input file, then include
2212         # automatic versioning capability.
2213         local ($out_file, $vtexi) = &scan_texinfo_file ($relative_dir
2214                                                         . "/" . $info_cursor);
2216         if ($out_file eq '')
2217         {
2218             &am_error ("\`$info_cursor' missing \@setfilename");
2219             next;
2220         }
2222         if ($out_file =~ /\.(.+)$/ && $1 ne 'info')
2223         {
2224             # FIXME should report line number in input file.
2225             &am_error ("output of \`$info_cursor', \`$out_file', has unrecognized extension");
2226             next;
2227         }
2229         if ($vtexi)
2230         {
2231             &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
2232                 if (defined $versions{$vtexi});
2233             $versions{$vtexi} = $info_cursor;
2235             # We number the stamp-vti files.  This is doable since the
2236             # actual names don't matter much.  We only number starting
2237             # with the second one, so that the common case looks nice.
2238             $vti = ($done ? $done : 'vti');
2239             ++$done;
2241             &push_dist_common ($vtexi, 'stamp-' . $vti);
2242             push (@clean, $vti);
2244             &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
2245                                           'mdate-sh');
2247             local ($conf_pat, $conf_dir);
2248             if ($config_aux_dir eq '.' || $config_aux_dir eq '')
2249             {
2250                 $conf_dir = '$(srcdir)/';
2251             }
2252             else
2253             {
2254                 $conf_dir = $config_aux_dir;
2255                 $conf_dir .= '/' unless $conf_dir =~ /\/$/;
2256             }
2257             ($conf_pat = $conf_dir) =~ s/(\W)/\\$1/g;
2258             $output_rules .=
2259                 &file_contents_with_transform
2260                     ('s/\@TEXI\@/' . $info_cursor . '/g; '
2261                      . 's/\@VTI\@/' . $vti . '/g; '
2262                      . 's/\@VTEXI\@/' . $vtexi . '/g;'
2263                      . 's,\@MDDIR\@,' . $conf_pat . ',g;',
2264                      'texi-vers');
2266             &push_phony_cleaners ($vti);
2267         }
2269         # If user specified file_TEXINFOS, then use that as explicit
2270         # dependency list.
2271         @texi_deps = ();
2272         push (@texi_deps, $info_cursor);
2273         push (@texi_deps, $vtexi) if $vtexi;
2275         # Canonicalize name first.
2276         ($canonical = $infobase) =~ tr/A-Za-z0-9_/_/c;
2277         if (&variable_defined ($canonical . "_TEXINFOS"))
2278         {
2279             push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
2280             &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
2281         }
2283         $output_rules .= ("\n" . $out_file . ": "
2284                           . join (' ', @texi_deps)
2285                           . "\n" . $infobase . ".dvi: "
2286                           . join (' ', @texi_deps)
2287                           . "\n\n");
2289         push (@info_deps_list, $out_file);
2290         push (@dvis_list, $infobase . '.dvi');
2292         # Generate list of things to clean for this target.  We do
2293         # this explicitly because otherwise too many things could be
2294         # removed.  In particular the ".log" extension might
2295         # reasonably be used in other contexts by the user.
2296         # FIXME: this is really out of control.
2297         foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns', 'pgs',
2298                             'ky', 'kys', 'ps', 'log', 'pg', 'toc', 'tp', 'tps',
2299                             'vr', 'vrs', 'op', 'tr', 'cv', 'cn', 'cm', 'ov')
2300         {
2301             push (@texi_cleans, $infobase . '.' . $tc_cursor);
2302         }
2303     }
2305     # Find these programs wherever they may lie.  Yes, this has
2306     # intimate knowledge of the structure of the texinfo distribution.
2307     &define_program_variable ('MAKEINFO', 'build', 'texinfo/makeinfo',
2308                               'makeinfo',
2309                               # Circumlocution to avoid accidental
2310                               # configure substitution.
2311                               '@MAKE' . 'INFO@');
2312     &define_program_variable ('TEXI2DVI', 'src', 'texinfo/util',
2313                               'texi2dvi');
2315     # Set transform for including texinfos.am.  First, handle --cygnus
2316     # stuff.
2317     local ($xform);
2318     if ($cygnus_mode)
2319     {
2320         $xform = 's/^NOTCYGNUS.*$//; s/^CYGNUS//;';
2321     }
2322     else
2323     {
2324         $xform = 's/^CYGNUS.*$//; s/^NOTCYGNUS//;';
2325     }
2327     # Handle location of texinfo.tex.
2328     local ($need_texi_file) = 0;
2329     local ($texinfo_tex);
2330     if ($cygnus_mode)
2331     {
2332         $texinfo_tex = '$(top_srcdir)/../texinfo/texinfo.tex';
2333         &define_variable ('TEXINFO_TEX', $texinfo_tex);
2335     }
2336     elsif ($config_aux_dir ne '.' && $config_aux_dir ne '')
2337     {
2338         $texinfo_tex = $config_aux_dir . '/texinfo.tex';
2339         &define_variable ('TEXINFO_TEX', $texinfo_tex);
2340         $need_texi_file = 2; # so that we require_conf_file later
2341     }
2342     elsif (&variable_defined ('TEXINFO_TEX'))
2343     {
2344         # The user defined TEXINFO_TEX so assume he knows what he is
2345         # doing.
2346         $texinfo_tex = ('$(srcdir)/'
2347                         . &dirname (&variable_value ('TEXINFO_TEX')));
2348     }
2349     else
2350     {
2351         $texinfo_tex = '$(srcdir)/texinfo.tex';
2352         $need_texi_file = 1;
2353     }
2354     local ($xxform);
2355     ($xxform = $texinfo_tex) =~ s/\/texinfo\.tex$//;
2356     $xxform =~ s/(\W)/\\$1/g;
2357     $xform .= ' s/\@TEXINFODIR\@/' . $xxform . '/g;';
2359     $output_rules .= &file_contents_with_transform ($xform, 'texinfos');
2360     push (@phony, 'install-info-am', 'uninstall-info');
2361     push (@dist_targets, 'dist-info');
2363     # How to clean.  The funny name is due to --cygnus influence; in
2364     # Cygnus mode, `clean-info' is a target that users can use.
2365     $output_rules .= "\nmostlyclean-aminfo:\n";
2366     &pretty_print_rule ("\t-rm -f", "\t  ", @texi_cleans);
2367     $output_rules .= ("\nclean-aminfo:\n\ndistclean-aminfo:\n\n"
2368                       . "maintainer-clean-aminfo:\n\t"
2369                       # Eww.  But how else can we find all the output
2370                       # files from makeinfo?
2371                       . ($cygnus_mode ? '' : 'cd $(srcdir) && ')
2372                       . 'for i in $(INFO_DEPS); do' . " \\\n"
2373                       . "\t" . '  rm -f $$i;' . " \\\n"
2374                       . "\t" . '  if test "`echo $$i-[0-9]*`" != "$$i-[0-9]*"; then' . " \\\n"
2375                       . "\t" . '    rm -f $$i-[0-9]*;' . " \\\n"
2376                       . "\t" . '  fi;' . " \\\n"
2377                       . "\tdone\n");
2378     &push_phony_cleaners ('aminfo');
2379     if ($cygnus_mode)
2380     {
2381         $output_rules .= "clean-info: mostlyclean-aminfo\n";
2382     }
2384     push (@suffixes, '.texi', '.texinfo', '.txi', '.info', '.dvi', '.ps');
2386     if (! defined $options{'no-installinfo'})
2387     {
2388         push (@uninstall, 'uninstall-info');
2389         push (@installdirs, '$(DESTDIR)$(infodir)');
2390         unshift (@install_data, 'install-info-am');
2392         # Make sure documentation is made and installed first.  Use
2393         # $(INFO_DEPS), not 'info', because otherwise recursive makes
2394         # get run twice during "make all".
2395         unshift (@all, '$(INFO_DEPS)');
2396     }
2397     push (@clean, 'aminfo');
2398     push (@info, '$(INFO_DEPS)');
2399     push (@dvi, '$(DVIS)');
2401     &define_variable ("INFO_DEPS", join (' ', @info_deps_list));
2402     &define_variable ("DVIS", join (' ', @dvis_list));
2403     # This next isn't strictly needed now -- the places that look here
2404     # could easily be changed to look in info_TEXINFOS.  But this is
2405     # probably better, in case noinst_TEXINFOS is ever supported.
2406     &define_variable ("TEXINFOS", &variable_value ('info_TEXINFOS'));
2408     # Do some error checking.  Note that this file is not required
2409     # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
2410     # up above.
2411     if ($need_texi_file && ! defined $options{'no-texinfo.tex'})
2412     {
2413         if ($need_texi_file > 1)
2414         {
2415             &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
2416                                           'texinfo.tex');
2417         }
2418         else
2419         {
2420             &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex');
2421         }
2422     }
2425 # Handle any man pages.
2426 sub handle_man_pages
2428     &am_line_error ('MANS', "\`MANS' is an anachronism; use \`man_MANS'")
2429         if &variable_defined ('MANS');
2430     return if ! &variable_defined ('man_MANS');
2432     # Find all the sections in use.  We do this by first looking for
2433     # "standard" sections, and then looking for any additional
2434     # sections used in man_MANS.
2435     local ($sect, %sections, %vlist);
2436     # Add more sections as needed.
2437     foreach $sect ('0'..'9', 'n', 'l')
2438     {
2439         if (&variable_defined ('man' . $sect . '_MANS'))
2440         {
2441             $sections{$sect} = 1;
2442             $vlist{'$(man' . $sect . '_MANS)'} = 1;
2443         }
2444     }
2446     if (&variable_defined ('man_MANS'))
2447     {
2448         $vlist{'$(man_MANS)'} = 1;
2449         foreach (&variable_value_as_list ('man_MANS', 'all'))
2450         {
2451             # A page like `foo.1c' goes into man1dir.
2452             if (/\.([0-9a-z])([a-z]*)$/)
2453             {
2454                 $sections{$1} = 1;
2455             }
2456         }
2457     }
2460     # Now for each section, generate an install and unintall rule.
2461     # Sort sections so output is deterministic.
2462     local (@namelist);
2463     foreach $sect (sort keys %sections)
2464     {
2465         &define_variable ('man' . $sect . 'dir', '$(mandir)/man' . $sect);
2466         push (@installdirs, '$(DESTDIR)$(mandir)/man' . $sect)
2467             unless defined $options{'no-installman'};
2468         $output_rules .= &file_contents_with_transform ('s/\@SECTION\@/'
2469                                                         . $sect . '/g;',
2470                                                         'mans');
2471         push (@phony, 'install-man' . $sect, 'uninstall-man' . $sect);
2472         push (@namelist, 'install-man' . $sect);
2473     }
2475     # We don't really need this, but we use it in case we ever want to
2476     # support noinst_MANS.
2477     &define_variable ("MANS", join (' ', sort keys %vlist));
2479     # Generate list of install dirs.
2480     $output_rules .= ("install-man: \$(MANS)\n"
2481                       . "\t\@\$(NORMAL_INSTALL)\n");
2482     &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ", @namelist);
2483     push (@phony, 'install-man');
2485     $output_rules .= "uninstall-man:\n\t\@\$(NORMAL_UNINSTALL)\n";
2486     grep ($_ = 'un' . $_, @namelist);
2487     &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ", @namelist);
2488     push (@phony, 'uninstall-man');
2490     $output_vars .= &file_contents ('mans-vars');
2492     if (! defined $options{'no-installman'})
2493     {
2494         push (@install_data, 'install-man');
2495         push (@uninstall, 'uninstall-man');
2496         push (@all, '$(MANS)');
2497     }
2500 # Handle DATA variables.
2501 sub handle_data
2503     &am_install_var ('-noextra', '-candist', 'data', 'DATA',
2504                      'data', 'sysconf', 'sharedstate', 'localstate',
2505                      'pkgdata', 'noinst', 'check');
2508 # Handle TAGS.
2509 sub handle_tags
2511     push (@phony, 'tags');
2512     local (@tag_deps) = ();
2513     if (&variable_defined ('SUBDIRS'))
2514     {
2515         $output_rules .= ("tags-recursive:\n"
2516                           . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
2517                           # Never fail here if a subdir fails; it
2518                           # isn't important.
2519                           . "\t  test \"\$\$subdir\" = . || (cd \$\$subdir"
2520                           . " && \$(MAKE) \$(AM_MAKEFLAGS) tags); \\\n"
2521                           . "\tdone\n");
2522         push (@tag_deps, 'tags-recursive');
2523         push (@phony, 'tags-recursive');
2524     }
2526     if (&saw_sources_p (1)
2527         || &variable_defined ('ETAGS_ARGS')
2528         || @tag_deps)
2529     {
2530         local ($xform) = '';
2531         local ($one_hdr);
2532         foreach $one_hdr (@config_headers)
2533         {
2534             if ($relative_dir eq &dirname ($one_hdr))
2535             {
2536                 # The config header is in this directory.  So require it.
2537                 local ($var);
2538                 ($var = &basename ($one_hdr)) =~ s/(\W)/\\$1/g;
2539                 $xform .= ' ' if $xform;
2540                 $xform .= $var;
2541             }
2542         }
2543         $xform = ('s/\@CONFIG\@/' . $xform . '/;'
2544                   . 's/\@DIRS\@/' . join (' ', @tag_deps) . '/;');
2546         if (&variable_defined ('SUBDIRS'))
2547         {
2548             $xform .= 's/^SUBDIRS//;';
2549         }
2550         else
2551         {
2552             $xform .= 's/^SUBDIRS.*$//;';
2553         }
2555         $output_rules .= &file_contents_with_transform ($xform, 'tags');
2556         $output_rules .= &file_contents ('tags-clean');
2557         push (@clean, 'tags');
2558         &push_phony_cleaners ('tags');
2559         &examine_variable ('TAGS_DEPENDENCIES');
2560     }
2561     elsif (&variable_defined ('TAGS_DEPENDENCIES'))
2562     {
2563         &am_line_error ('TAGS_DEPENDENCIES',
2564                         "doesn't make sense to define \`TAGS_DEPENDENCIES' without sources or \`ETAGS_ARGS'");
2565     }
2566     else
2567     {
2568         # Every Makefile must define some sort of TAGS rule.
2569         # Otherwise, it would be possible for a top-level "make TAGS"
2570         # to fail because some subdirectory failed.
2571         $output_rules .= "tags: TAGS\nTAGS:\n\n";
2572     }
2575 # Handle multilib support.
2576 sub handle_multilib
2578     return unless $seen_multilib;
2580     $output_rules .= &file_contents ('multilib.am');
2581     &push_phony_cleaners ('multi');
2582     push (@phony, 'all-multi', 'install-multi');
2585 # Worker for handle_dist.
2586 sub handle_dist_worker
2588     local ($makefile) = @_;
2590     $output_rules .= 'distdir: $(DISTFILES)' . "\n";
2592     # Initialization; only at top level.
2593     if ($relative_dir eq '.')
2594     {
2595         if (defined $options{'check-news'})
2596         {
2597             # For Gnits users, this is pretty handy.  Look at 15 lines
2598             # in case some explanatory text is desirable.
2599             $output_rules .= '  @if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" > /dev/null; then :; else \\
2600           echo "NEWS not updated; not releasing" 1>&2; \\
2601           exit 1; \\
2602         fi
2604         }
2607         # Create dist directory.
2608         $output_rules .= ("\t-chmod -R a+w \$(distdir) > /dev/null 2>&1; rm -rf \$(distdir)\n"
2609                           . "\tmkdir \$(distdir)\n");
2610     }
2612     # Scan EXTRA_DIST to see if we need to distribute anything from a
2613     # subdir.  If so, add it to the list.  I didn't want to do this
2614     # originally, but there were so many requests that I finally
2615     # relented.
2616     local (@dist_dirs);
2617     if (&variable_defined ('EXTRA_DIST'))
2618     {
2619         # FIXME: This should be fixed to work with conditionals.  That
2620         # will require only making the entries in @dist_dirs under the
2621         # appropriate condition.  This is meaningful if the nature of
2622         # the distribution should depend upon the configure options
2623         # used.
2624         foreach (&variable_value_as_list ('EXTRA_DIST', ''))
2625         {
2626             next if /^\@.*\@$/;
2627             next unless s,/+[^/]+$,,;
2628             push (@dist_dirs, $_)
2629                 unless $_ eq '.';
2630         }
2631     }
2633     # We have to check DIST_COMMON for extra directories in case the
2634     # user put a source used in AC_OUTPUT into a subdir.
2635     foreach (&variable_value_as_list ('DIST_COMMON', 'all'))
2636     {
2637         next if /^\@.*\@$/;
2638         next unless s,/+[^/]+$,,;
2639         push (@dist_dirs, $_)
2640             unless $_ eq '.';
2641     }
2643     if (@dist_dirs)
2644     {
2645         # Prepend $(distdir) to each directory given.  Doing it via a
2646         # hash lets us ensure that each directory is used only once.
2647         local (%dhash);
2648         grep ($dhash{'$(distdir)/' . $_} = 1, @dist_dirs);
2649         $output_rules .= "\t";
2650         &pretty_print_rule ('$(mkinstalldirs)', "\t   ", sort keys %dhash);
2651     }
2653     # In loop, test for file existence because sometimes a file gets
2654     # included in DISTFILES twice.  For example this happens when a
2655     # single source file is used in building more than one program.
2656     # Also, there are situations in which "ln" can fail.  For instance
2657     # a file to distribute could actually be a cross-filesystem
2658     # symlink -- this can easily happen if "gettextize" was run on the
2659     # distribution.
2660     $output_rules .= "\t\@for file in \$(DISTFILES); do \\\n";
2661     if ($cygnus_mode)
2662     {
2663         $output_rules .= "\t  if test -f \$\$file; then d=.; else d=\$(srcdir); fi; \\\n";
2664     }
2665     else
2666     {
2667         $output_rules .= "\t  d=\$(srcdir); \\\n";
2668     }
2669     $output_rules .= ("\t  if test -d \$\$d/\$\$file; then \\\n"
2670                       # Don't mention $$file in destination argument,
2671                       # since this fails if destination directory
2672                       # already exists.  Also, use `-R' and not `-r'.
2673                       # `-r' is almost always incorrect.
2674                       . "\t    cp -pR \$\$d/\$\$file \$(distdir) \\\n"
2675                       . "\t    || exit 1; \\\n"
2676                       . "\t  else \\\n"
2677                       . "\t    test -f \$(distdir)/\$\$file \\\n"
2678                       . "\t    || cp -p \$\$d/\$\$file \$(distdir)/\$\$file \\\n"
2679                       . "\t    || exit 1; \\\n"
2680                       . "\t  fi; \\\n"
2681                       . "\tdone\n");
2683     # If we have SUBDIRS, create all dist subdirectories and do
2684     # recursive build.
2685     if (&variable_defined ('SUBDIRS'))
2686     {
2687         # If SUBDIRS is conditionally defined, then set DIST_SUBDIRS
2688         # to all possible directories, and use it.  If DIST_SUBDIRS is
2689         # defined, just use it.
2690         local ($dist_subdir_name);
2691         if (&variable_conditions ('SUBDIRS')
2692             || &variable_defined ('DIST_SUBDIRS'))
2693         {
2694             $dist_subdir_name = 'DIST_SUBDIRS';
2695             if (! &variable_defined ('DIST_SUBDIRS'))
2696             {
2697                 local (@full_list) = &variable_value_as_list ('SUBDIRS',
2698                                                               'all');
2699                 local (@ds_list, %uniq, $iter);
2700                 foreach $iter (@full_list)
2701                 {
2702                     if (! defined $uniq{$iter})
2703                     {
2704                         $uniq{$iter} = 1;
2705                         push (@ds_list, $iter);
2706                     }
2707                 }
2708                 &define_pretty_variable ('DIST_SUBDIRS', '', @ds_list);
2709             }
2710         }
2711         else
2712         {
2713             $dist_subdir_name = 'SUBDIRS';
2714         }
2716         # Test for directory existence here because previous automake
2717         # invocation might have created some directories.  Note that
2718         # we explicitly set distdir for the subdir make; that lets us
2719         # mix-n-match many automake-using packages into one large
2720         # package, and have "dist" at the top level do the right
2721         # thing.  If we're in the topmost directory, then we use
2722         # `distdir' instead of `top_distdir'; this lets us work
2723         # correctly with an enclosing package.
2724         $output_rules .=
2725             ("\t" . 'for subdir in $(' . $dist_subdir_name . '); do ' . "\\\n"
2726              . "\t" . '  if test "$$subdir" = .; then :; else ' . "\\\n"
2727              . "\t" . '    test -d $(distdir)/$$subdir ' . "\\\n"
2728              . "\t" . '    || mkdir $(distdir)/$$subdir ' . "\\\n"
2729              . "\t" . '    || exit 1; ' . "\\\n"
2730              . "\t" . '    (cd $$subdir'
2731              . ' && $(MAKE) $(AM_MAKEFLAGS) top_distdir=../$('
2732              . (($relative_dir eq '.') ? 'distdir' : 'top_distdir')
2733              . ') distdir=../$(distdir)/$$subdir distdir) ' . "\\\n"
2734              . "\t" . '      || exit 1; ' . "\\\n"
2735              . "\t" . '  fi; ' . "\\\n"
2736              . "\tdone\n");
2737     }
2739     # If the target `dist-hook' exists, make sure it is run.  This
2740     # allows users to do random weird things to the distribution
2741     # before it is packaged up.
2742     push (@dist_targets, 'dist-hook') if &target_defined ('dist-hook');
2744     local ($targ);
2745     foreach $targ (@dist_targets)
2746     {
2747         # We must explicitly set distdir and top_distdir for these
2748         # sub-makes.
2749         $output_rules .= ("\t\$(MAKE) \$(AM_MAKEFLAGS)"
2750                           . " top_distdir=\"\$(top_distdir)\""
2751                           . " distdir=\"\$(distdir)\" $targ\n");
2752     }
2754     push (@phony, 'distdir');
2757 # Handle 'dist' target.
2758 sub handle_dist
2760     local ($makefile) = @_;
2762     # Set up maint_charset.
2763     $local_maint_charset = &variable_value ('MAINT_CHARSET')
2764         if &variable_defined ('MAINT_CHARSET');
2765     $maint_charset = $local_maint_charset
2766         if $relative_dir eq '.';
2768     if (&variable_defined ('DIST_CHARSET'))
2769     {
2770         &am_line_error ('DIST_CHARSET',
2771                         "DIST_CHARSET defined but no MAINT_CHARSET defined")
2772             if ! $local_maint_charset;
2773         if ($relative_dir eq '.')
2774         {
2775             $dist_charset = &variable_value ('DIST_CHARSET')
2776         }
2777         else
2778         {
2779             &am_line_error ('DIST_CHARSET',
2780                             "DIST_CHARSET can only be defined at top level");
2781         }
2782     }
2784     # Look for common files that should be included in distribution.
2785     local ($cfile);
2786     foreach $cfile (@common_files)
2787     {
2788         if (-f ($relative_dir . "/" . $cfile))
2789         {
2790             &push_dist_common ($cfile);
2791         }
2792     }
2794     # Always require configure.in and configure at top level, even if
2795     # they don't exist.  This is especially important for configure,
2796     # since it won't be created until autoconf is run -- which might
2797     # be after automake is run.
2798     &push_dist_common ('configure.in', 'configure')
2799         if $relative_dir eq '.';
2801     # We might copy elements from %configure_dist_common to
2802     # %dist_common if we think we need to.  If the file appears in our
2803     # directory, we would have discovered it already, so we don't
2804     # check that.  But if the file is in a subdir without a Makefile,
2805     # we want to distribute it here if we are doing `.'.  Ugly!
2806     if ($relative_dir eq '.')
2807     {
2808         local ($iter);
2809         foreach $iter (keys %configure_dist_common)
2810         {
2811             if (! &is_make_dir (&dirname ($iter)))
2812             {
2813                 &push_dist_common ($iter);
2814             }
2815         }
2816     }
2818     # Keys of %dist_common are names of files to distributed.  We put
2819     # README first because it then becomes easier to make a
2820     # Usenet-compliant shar file (in these, README must be first).
2821     # FIXME: do more ordering of files here.
2822     local (@coms);
2823     if (defined $dist_common{'README'})
2824     {
2825         push (@coms, 'README');
2826         delete $dist_common{'README'};
2827     }
2828     push (@coms, sort keys %dist_common);
2830     # Now that we've processed %dist_common, disallow further attempts
2831     # to set it.
2832     $handle_dist_run = 1;
2834     &define_pretty_variable ("DIST_COMMON", '', @coms);
2835     $output_vars .= "\n";
2837     # Some boilerplate.
2838     $output_vars .= &file_contents ('dist-vars') . "\n";
2839     &define_variable ('GZIP_ENV', '--best');
2841     # Put these things in rules section so it is easier for whoever
2842     # reads Makefile.in.
2843     if (! &variable_defined ('distdir'))
2844     {
2845         if ($relative_dir eq '.')
2846         {
2847             $output_rules .= "\n" . 'distdir = $(PACKAGE)-$(VERSION)' . "\n";
2848         }
2849         else
2850         {
2851             $output_rules .= ("\n"
2852                               . 'distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)'
2853                               . "\n");
2854         }
2855     }
2856     if ($relative_dir eq '.')
2857     {
2858         $output_rules .= "top_distdir = \$(distdir)\n";
2859     }
2860     $output_rules .= "\n";
2862     # Generate 'dist' target, and maybe other dist targets.
2863     if ($relative_dir eq '.')
2864     {
2865         # Rule to check whether a distribution is viable.
2866         local ($xform) = '';
2868         if (&target_defined ('distcheck-hook'))
2869         {
2870             $xform .= 's/^DISTHOOK//;';
2871         }
2872         else
2873         {
2874             $xform .= 's/^DISTHOOK.*$//;';
2875         }
2876         if ($seen_gettext)
2877         {
2878             $xform .= 's/^GETTEXT//;';
2879         }
2880         else
2881         {
2882             $xform .= 's/^GETTEXT.*$//;';
2883         }
2885         $output_rules .= &file_contents_with_transform ($xform, 'dist');
2887         local ($dist_all) = ('dist-all: distdir' . "\n"
2888                              . $dist_header);
2889         local ($curs);
2890         foreach $curs ('dist', 'dist-shar', 'dist-zip', 'dist-tarZ',
2891                        'dist-bzip2')
2892         {
2893             if (defined $options{$curs} || $curs eq 'dist')
2894             {
2895                 $output_rules .= ($curs . ': distdir' . "\n"
2896                                   . $dist_header
2897                                   . $dist{$curs}
2898                                   . $dist_trailer);
2899                 $dist_all .= $dist{$curs};
2900             }
2901         }
2902         $output_rules .= $dist_all . $dist_trailer;
2903     }
2905     # Generate distdir target.
2906     &handle_dist_worker ($makefile);
2909 # A subroutine of handle_dependencies.  This function includes
2910 # `depend2' with appropriate transformations.
2911 sub add_depend2
2913     local ($lang) = @_;
2915     # First include code for ordinary objects.
2916     local ($key) = $lang . '-autodep';
2917     local ($xform, $ext);
2919     local ($pfx) = $language_map{$key};
2920     local ($fpfx) = ($pfx eq '') ? 'CC' : $pfx;
2921     $xform = ('s/\@PFX\@/' . $pfx . '/g;'
2922               . 's/\@FPFX\@/' . $fpfx . '/g;'
2923               . ($seen_objext ? 's/^OBJEXT//;' : 's/^OBJEXT.*$//;')
2924               . ($seen_libtool ? 's/^LIBTOOL//;' : 's/^LIBTOOL.*$//;'));
2926     # This function can be called even when we don't want dependency
2927     # tracking.  This happens when we need an explicit rule for some
2928     # target.  In this case we don't want to include the generic code.
2929     if ($use_dependencies)
2930     {
2931         local ($xform1) = ($xform
2932                            . 's/\@BASE\@/\$\*/g;'
2933                            . 's/\@SOURCE\@/\$\</g;'
2934                            . 's/\@(LT|OBJ)?OBJ\@/\$\@/g;');
2936         foreach $ext (&lang_extensions ($lang))
2937         {
2938             $output_rules .= (&file_contents_with_transform ('s/\@EXT\@/'
2939                                                              . $ext . '/g;'
2940                                                              . $xform1,
2941                                                              'depend2')
2942                               . "\n");
2943         }
2944     }
2946     # Now include code for each specially handled object with this
2947     # language.
2948     local (@list) = grep ($_ ne '', split (' ', $lang_specific_files{$lang}));
2949     local ($max) = scalar @list;
2950     local ($i) = 0;
2951     local ($derived, $source, $obj);
2953     # If dependency tracking is disabled, we just elide the code.
2954     if (! $use_dependencies)
2955     {
2956         $xform .= 's/\@AMDEP\@.*$//;';
2957     }
2959     while ($i < $max)
2960     {
2961         $derived = $list[$i];
2962         ($source = $list[$i + 1]) =~ s,([/\$]),\\$1,g;
2963         ($obj = $list[$i + 2]) =~ s,([/\$]),\\$1,g;
2964         $i += 3;
2966         local ($flag) = $language_map{$lang . '-flags'};
2967         local ($val) = "(${derived}_${flag}";
2968         ($rule = $language_map{$lang . '-compile'}) =~
2969             s/\(AM_$flag/$val/;
2971         $rule =~ s,([/\$]),\\$1,g;
2973         # Generate a transform which will turn suffix targets in
2974         # depend2.am into real targets for the particular objects we
2975         # are building.
2976         $output_rules .=
2977             &file_contents_with_transform ($xform
2978                                            . 's/\$\(' . $pfx . 'COMPILE\)/'
2979                                            . $rule . '/g;'
2980                                            . 's/\$\(LT' . $pfx . 'COMPILE\)/'
2981                                            . '\$(LIBTOOL) --mode=compile '
2982                                            . $rule . '/g;'
2983                                            # Generate rule for `.o'.
2984                                            . 's/^\@EXT\@\.o:/'
2985                                            . $obj . '.o: ' . $source
2986                                            . '/g;'
2987                                            # Maybe generate rule for `.lo'.
2988                                            # Might be eliminated by
2989                                            # $XFORM.
2990                                            . 's/^\@EXT\@\.lo:/'
2991                                            . $obj . '.lo: ' . $source
2992                                            . '/g;'
2993                                            # Maybe generate rule for `.obj'.
2994                                            # Might be eliminated by
2995                                            # $XFORM.
2996                                            . 's/^\@EXT\@\.obj:/'
2997                                            . $obj . '.obj: ' . $source
2998                                            . '/g;'
2999                                            # Handle source and obj
3000                                            # transforms.
3001                                            . 's/\@OBJ\@/' . $obj . '.o/g;'
3002                                            . 's/\@OBJOBJ\@/' . $obj . '.obj/g;'
3003                                            . 's/\@LTOBJ\@/' . $obj . '.lo/g;'
3004                                            . 's/\@BASE\@/' . $obj . '/g;'
3005                                            . 's/\@SOURCE\@/' . $source . '/g;',
3006                                            'depend2');
3007     }
3010 # Handle auto-dependency code.
3011 sub handle_dependencies
3013     if ($use_dependencies)
3014     {
3015         # Include auto-dep code.  Don't include it if DEP_FILES would
3016         # be empty.
3017         if (&saw_sources_p (0) && keys %dep_files)
3018         {
3019             &require_config_file ($FOREIGN, 'depcomp');
3021             # Set location of depcomp.
3022             if ($config_aux_dir ne '.' && $config_aux_dir ne '')
3023             {
3024                 &define_variable ('depcomp', ('$(SHELL) ' . $config_aux_dir
3025                                               . '/depcomp'));
3026             }
3027             else
3028             {
3029                 &define_variable ('depcomp',
3030                                   '$(SHELL) $(top_srcdir)/depcomp');
3031             }
3033             local ($iter);
3034             local (@deplist) = sort keys %dep_files;
3036             &define_pretty_variable ('DEP_FILES', '', ("\@AMDEP\@", @deplist));
3038             # Generate each `include' individually.  Irix 6 make will
3039             # not properly include several files resulting from a
3040             # variable expansion; generating many separate includes
3041             # seems safest.
3042             $output_rules .= "\n";
3043             foreach $iter (@deplist)
3044             {
3045                 $output_rules .= "\@AMDEP\@" . 'include ' . $iter . "\n";
3046             }
3048             $output_rules .= &file_contents ('depend');
3049             push (@clean, 'depend');
3050             &push_phony_cleaners ('depend');
3051         }
3052     }
3053     else
3054     {
3055         &define_variable ('depcomp', '');
3056     }
3058     local ($key, $lang, $ext, $xform);
3059     foreach $key (sort keys %language_map)
3060     {
3061         next unless $key =~ /^(.*)-autodep$/;
3062         next if $language_map{$key} eq 'no';
3063         &add_depend2 ($1);
3064     }
3067 # Handle subdirectories.
3068 sub handle_subdirs
3070     return if ! &variable_defined ('SUBDIRS');
3072     # Make sure each directory mentioned in SUBDIRS actually exists.
3073     local ($dir);
3074     foreach $dir (&variable_value_as_list ('SUBDIRS', 'all'))
3075     {
3076         # Skip directories substituted by configure.
3077         next if $dir =~ /^\@.*\@$/;
3079         if (! -d $am_relative_dir . '/' . $dir)
3080         {
3081             &am_line_error ('SUBDIRS',
3082                             "required directory $am_relative_dir/$dir does not exist");
3083             next;
3084         }
3086         &am_line_error ('SUBDIRS', "directory should not contain \`/'")
3087             if $dir =~ /\//;
3088     }
3090     local ($xform) = ('s/\@INSTALLINFO\@/' .
3091                       (defined $options{'no-installinfo'}
3092                        ? 'install-info-recursive'
3093                        : '')
3094                       . '/;');
3095     $output_rules .= &file_contents_with_transform ($xform, 'subdirs');
3097     # Push a bunch of phony targets.
3098     local ($phonies);
3099     foreach $phonies ('', '-data', '-exec', 'dirs')
3100     {
3101         push (@phony, 'install' . $phonies . '-recursive');
3102         push (@phony, 'uninstall' . $phonies . '-recursive');
3103     }
3104     foreach $phonies ('all', 'check', 'installcheck', 'info', 'dvi')
3105     {
3106         push (@phony, $phonies . '-recursive');
3107     }
3108     &push_phony_cleaners ('recursive');
3110     $recursive_install = 1;
3113 # Handle aclocal.m4.
3114 sub handle_aclocal_m4
3116     local ($regen_aclocal) = 0;
3117     if (-f 'aclocal.m4')
3118     {
3119         &define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4');
3120         &push_dist_common ('aclocal.m4');
3122         if (open (ACLOCAL, '< aclocal.m4'))
3123         {
3124             local ($line);
3125             $line = <ACLOCAL>;
3126             close (ACLOCAL);
3128             if ($line =~ 'generated automatically by aclocal')
3129             {
3130                 $regen_aclocal = 1;
3131             }
3132         }
3133     }
3135     local ($acinclude) = 0;
3136     if (-f 'acinclude.m4')
3137     {
3138         $regen_aclocal = 1;
3139         $acinclude = 1;
3140     }
3142     # Note that it might be possible that aclocal.m4 doesn't exist but
3143     # should be auto-generated.  This case probably isn't very
3144     # important.
3145     if ($regen_aclocal)
3146     {
3147         local (@ac_deps) = (
3148                             ($seen_maint_mode
3149                              ? "\@MAINTAINER_MODE_TRUE\@"
3150                              : "") ,
3151                             "configure.in",
3152                             ($acinclude ? ' acinclude.m4' : '')
3153                             );
3155         # Scan all -I directories for m4 files.  These are our
3156         # dependencies.
3157         if (&variable_defined ('ACLOCAL_AMFLAGS'))
3158         {
3159             local ($examine_next, $amdir) = 0;
3160             foreach $amdir (&variable_value_as_list ('ACLOCAL_AMFLAGS', ''))
3161             {
3162                 if ($examine_next)
3163                 {
3164                     $examine_next = 0;
3165                     if ($amdir !~ /^\// && -d $amdir)
3166                     {
3167                         push (@ac_deps, &my_glob ($amdir . '/*.m4'));
3168                     }
3169                 }
3170                 elsif ($amdir eq '-I')
3171                 {
3172                     $examine_next = 1;
3173                 }
3174             }
3175         }
3177         &pretty_print_rule ("\$(ACLOCAL_M4):", "\t\t", @ac_deps);
3179         $output_rules .=  ("\t"
3180                            . 'cd $(srcdir) && $(ACLOCAL)'
3181                            . (&variable_defined ('ACLOCAL_AMFLAGS')
3182                               ? ' $(ACLOCAL_AMFLAGS)' : '')
3183                            . "\n");
3184     }
3187 # Rewrite a list of input files into a form suitable to put on a
3188 # dependency list.  The idea is that if an input file has a directory
3189 # part the same as the current directory, then the directory part is
3190 # simply removed.  But if the directory part is different, then
3191 # $(top_srcdir) is prepended.  Among other things, this is used to
3192 # generate the dependency list for the output files generated by
3193 # AC_OUTPUT.  Consider what the dependencies should look like in this
3194 # case:
3195 #   AC_OUTPUT(src/out:src/in1:lib/in2)
3196 # The first argument, ADD_SRCDIR, is 1 if $(top_srcdir) should be added.
3197 # If 0 then files that require this addition will simply be ignored.
3198 sub rewrite_inputs_into_dependencies
3200     local ($add_srcdir, @inputs) = @_;
3201     local ($single, @newinputs);
3203     foreach $single (@inputs)
3204     {
3205         if (&dirname ($single) eq $relative_dir)
3206         {
3207             push (@newinputs, &basename ($single));
3208         }
3209         elsif ($add_srcdir)
3210         {
3211             push (@newinputs, '$(top_srcdir)/' . $single);
3212         }
3213     }
3215     return @newinputs;
3218 # Handle remaking and configure stuff.
3219 # We need the name of the input file, to do proper remaking rules.
3220 sub handle_configure
3222     local ($local, $input, @secondary_inputs) = @_;
3224     local ($top_reldir);
3226     local ($input_base) = &basename ($input);
3227     local ($local_base) = &basename ($local);
3229     local ($amfile) = $input_base . '.am';
3230     # We know we can always add '.in' because it really should be an
3231     # error if the .in was missing originally.
3232     local ($infile) = '$(srcdir)/' . $input_base . '.in';
3233     local ($colon_infile);
3234     if ($local ne $input || @secondary_inputs)
3235     {
3236         $colon_infile = ':' . $input . '.in';
3237     }
3238     $colon_infile .= ':' . join (':', @secondary_inputs)
3239         if @secondary_inputs;
3241     local (@rewritten) = &rewrite_inputs_into_dependencies (1,
3242                                                             @secondary_inputs);
3244     # This rule remakes the Makefile.in.  Note use of
3245     # @MAINTAINER_MODE_TRUE@ forces us to abandon pretty-printing.
3246     # Sigh.
3247     $output_rules .= ($infile
3248                       # NOTE perl 5.003 (with -w) gives a
3249                       # uninitialized value error on the next line.
3250                       # Don't know why.
3251                       . ': '
3252                       . ($seen_maint_mode ? "\@MAINTAINER_MODE_TRUE\@ " : '')
3253                       . $amfile . ' '
3254                       . '$(top_srcdir)/configure.in $(ACLOCAL_M4)'
3255                       . ' ' . join (' ', @include_stack)
3256                       . "\n"
3257                       . "\tcd \$(top_srcdir) && \$(AUTOMAKE) "
3258                       . ($cygnus_mode ? '--cygnus' : ('--' . $strictness_name))
3259                       . ($cmdline_use_dependencies ? '' : ' --ignore-deps')
3260                       . ' ' . $input . $colon_infile . "\n\n");
3262     # This rule remakes the Makefile.
3263     $output_rules .= ($local_base
3264                       # NOTE: bogus uninit value error on next line;
3265                       # see comment above.
3266                       . ': '
3267                       . $infile . ' '
3268                       . join (' ', @rewritten)
3269                       . ' $(top_builddir)/config.status'
3270                       . "\n"
3271                       . "\tcd \$(top_builddir) \\\n"
3272                       . "\t  && CONFIG_FILES="
3273                       . (($relative_dir eq '.') ? '$@' : '$(subdir)/$@')
3274                       . $colon_infile
3275                       . ' CONFIG_HEADERS= $(SHELL) ./config.status'
3276                       . "\n\n");
3278     if ($relative_dir ne '.')
3279     {
3280         # In subdirectory.
3281         $top_reldir = '../';
3282     }
3283     else
3284     {
3285         &handle_aclocal_m4;
3286         $output_rules .= &file_contents ('remake');
3287         &examine_variable ('CONFIG_STATUS_DEPENDENCIES');
3288         &examine_variable ('CONFIGURE_DEPENDENCIES');
3289         $top_reldir = '';
3291         &push_dist_common ('acconfig.h')
3292             if -f 'acconfig.h';
3293     }
3295     # If we have a configure header, require it.
3296     local ($one_hdr);
3297     local (@local_fullnames) = @config_fullnames;
3298     local (@local_names) = @config_names;
3299     local ($hdr_index) = 0;
3300     local ($distclean_config) = '';
3301     foreach $one_hdr (@config_headers)
3302     {
3303         local ($one_fullname) = shift (@local_fullnames);
3304         local ($one_name) = shift (@local_names);
3305         $hdr_index += 1;
3306         local ($header_dir) = &dirname ($one_name);
3308         # If the header is in the current directory we want to build
3309         # the header here.  Otherwise, if we're at the topmost
3310         # directory and the header's directory doesn't have a
3311         # Makefile, then we also want to build the header.
3312         if ($relative_dir eq $header_dir
3313             || ($relative_dir eq '.' && ! &is_make_dir ($header_dir)))
3314         {
3315             local ($ch_sans_dir, $cn_sans_dir, $stamp_dir);
3316             if ($relative_dir eq $header_dir)
3317             {
3318                 $cn_sans_dir = &basename ($one_name);
3319                 $stamp_dir = '';
3320             }
3321             else
3322             {
3323                 $cn_sans_dir = $one_name;
3324                 if ($header_dir eq '.')
3325                 {
3326                     $stamp_dir = '';
3327                 }
3328                 else
3329                 {
3330                     $stamp_dir = $header_dir . '/';
3331                 }
3332             }
3334             # Compute relative path from directory holding output
3335             # header to directory holding input header.  FIXME:
3336             # doesn't handle case where we have multiple inputs.
3337             if (&dirname ($one_hdr) eq $relative_dir)
3338             {
3339                 $ch_sans_dir = &basename ($one_hdr);
3340             }
3341             else
3342             {
3343                 local (@rel_out_path);
3344                 # FIXME this chunk of code should be its own sub.
3345                 # It is used elsewhere.
3346                 foreach (split (/\//, $relative_dir))
3347                 {
3348                     next if $_ eq '' || $_ eq '.';
3349                     if ($_ eq '..')
3350                     {
3351                         # FIXME: actually this is an error.
3352                         pop @rel_out_path;
3353                     }
3354                     else
3355                     {
3356                         push (@rel_out_path, '..');
3357                     }
3358                 }
3359                 if (@rel_out_path)
3360                 {
3361                     $ch_sans_dir = join ('/', @rel_out_path) . '/' . $one_hdr;
3362                 }
3363                 else
3364                 {
3365                     $ch_sans_dir = $one_hdr;
3366                 }
3367             }
3369             &require_file_with_conf_line ($config_header_line,
3370                                           $FOREIGN, $ch_sans_dir);
3372             # Header defined and in this directory.
3373             local (@files);
3374             if (-f $one_name . '.top')
3375             {
3376                 push (@files, "${cn_sans_dir}.top");
3377             }
3378             if (-f $one_name . '.bot')
3379             {
3380                 push (@files, "${cn_sans_dir}.bot");
3381             }
3383             &push_dist_common (@files);
3385             # For now, acconfig.h can only appear in the top srcdir.
3386             if (-f 'acconfig.h')
3387             {
3388                 if ($relative_dir eq '.')
3389                 {
3390                     push (@files, 'acconfig.h');
3391                 }
3392                 else
3393                 {
3394                     # Strange quoting because this gets fed through
3395                     # Perl.
3396                     push (@files, '\$(top_srcdir)/acconfig.h');
3397                 }
3398             }
3400             local ($stamp_name) = 'stamp-h';
3401             $stamp_name .= "${hdr_index}" if scalar (@config_headers) > 1;
3403             local ($xform) = '';
3405             $xform = 's,\@FILES\@,' . join (' ', @files) . ',;';
3406             $xform .= 's,\@CONFIG_HEADER\@,' . "${cn_sans_dir}" . ',;';
3407             $xform .= 's,\@CONFIG_HEADER_IN\@,' . "${ch_sans_dir}" . ',;';
3408             $xform .= 's,\@CONFIG_HEADER_FULL\@,' . "${one_fullname}" . ',;';
3409             $xform .= 's,\@STAMP\@,' . "${stamp_dir}${stamp_name}" . ',g;';
3411             local ($out_dir) = &dirname ($ch_sans_dir);
3412             $xform .= 's,\@SRC_STAMP\@,' . "${out_dir}/${stamp_name}" . ',g;';
3413             $output_rules .= &file_contents_with_transform ($xform,
3414                                                             'remake-hdr');
3416             &create ("${relative_dir}/${out_dir}/${stamp_name}.in");
3417             &require_file_with_conf_line ($config_header_line, $FOREIGN,
3418                                           "${out_dir}/${stamp_name}.in");
3420             $distclean_config .= ' ' if $distclean_config;
3421             $distclean_config .= $cn_sans_dir;
3422         }
3423     }
3425     if ($distclean_config)
3426     {
3427         $output_rules .= &file_contents_with_transform ('s,\@FILES\@,'
3428                                                         . $distclean_config
3429                                                         . ',;',
3430                                                         'clean-hdr');
3431         push (@clean, 'hdr');
3432         &push_phony_cleaners ('hdr');
3433     }
3435     # Set location of mkinstalldirs.
3436     if ($config_aux_dir ne '.' && $config_aux_dir ne '')
3437     {
3438         &define_variable ('mkinstalldirs', ('$(SHELL) ' . $config_aux_dir
3439                                             . '/mkinstalldirs'));
3440     }
3441     else
3442     {
3443         &define_variable ('mkinstalldirs',
3444                           '$(SHELL) $(top_srcdir)/mkinstalldirs');
3445     }
3447     &am_line_error ('CONFIG_HEADER',
3448                     "\`CONFIG_HEADER' is an anachronism; now determined from \`configure.in'")
3449         if &variable_defined ('CONFIG_HEADER');
3451     local ($one_name);
3452     local ($config_header) = '';
3453     foreach $one_name (@config_names)
3454     {
3455         # Generate CONFIG_HEADER define.
3456         local ($one_hdr);
3457         if ($relative_dir eq &dirname ($one_name))
3458         {
3459             $one_hdr = &basename ($one_name);
3460         }
3461         else
3462         {
3463             $one_hdr = "${top_builddir}/${one_name}";
3464         }
3466         $config_header .= ' ' if $config_header;
3467         $config_header .= $one_hdr;
3468     }
3469     if ($config_header)
3470     {
3471         &define_variable ("CONFIG_HEADER", $config_header);
3472     }
3474     # Now look for other files in this directory which must be remade
3475     # by config.status, and generate rules for them.
3476     local (@actual_other_files) = ();
3477     local ($file, $local);
3478     local (@inputs, @rewritten_inputs, $single);
3479     local ($need_rewritten);
3480     foreach $file (@other_input_files)
3481     {
3482         if ($file =~ /^([^:]*):(.*)$/)
3483         {
3484             # This is the ":" syntax of AC_OUTPUT.
3485             $file = $1;
3486             $local = &basename ($file);
3487             @inputs = split (':', $2);
3488             @rewritten_inputs = &rewrite_inputs_into_dependencies (1, @inputs);
3489             $need_rewritten = 1;
3490         }
3491         else
3492         {
3493             # Normal usage.
3494             $local = &basename ($file);
3495             @inputs = ($local . '.in');
3496             @rewritten_inputs =
3497                 &rewrite_inputs_into_dependencies (1, $file . '.in');
3498             $need_rewritten = 0;
3499         }
3501         # Skip files not in this directory.
3502         next unless &dirname ($file) eq $relative_dir;
3504         # Skip any file that is an automake input.
3505         next if -f $file . '.am';
3507         # Some users have been tempted to put `stamp-h' in the
3508         # AC_OUTPUT line.  This won't do the right thing, so we
3509         # explicitly fail here.
3510         if ($local eq 'stamp-h')
3511         {
3512             # FIXME: allow real filename.
3513             &am_conf_error ('configure.in', $ac_output_line,
3514                             'stamp-h should not appear in AC_OUTPUT');
3515             next;
3516         }
3518         $output_rules .= ($local . ': '
3519                           . '$(top_builddir)/config.status '
3520                           . join (' ', @rewritten_inputs) . "\n"
3521                           . "\t"
3522                           . 'cd $(top_builddir) && CONFIG_FILES='
3523                           . ($relative_dir eq '.' ? '' : '$(subdir)/')
3524                           . '$@' . ($need_rewritten
3525                                     ? (':' . join (':', @inputs))
3526                                     : '')
3527                           . ' CONFIG_HEADERS= $(SHELL) ./config.status'
3528                           . "\n");
3529         &push_dist_common (@inputs);
3530         push (@actual_other_files, $local);
3532         # Require all input files.
3533         &require_file_with_conf_line ($ac_output_line, $FOREIGN,
3534                                       &rewrite_inputs_into_dependencies (0, @inputs));
3535     }
3537     # These files get removed by "make clean".
3538     &define_pretty_variable ('CONFIG_CLEAN_FILES', '', @actual_other_files);
3541 # Handle C headers.
3542 sub handle_headers
3544     local (@r);
3545     @r = &am_install_var ('-defaultdist', 'header', 'HEADERS', 'include',
3546                           'oldinclude', 'pkginclude',
3547                           'noinst', 'check');
3548     foreach (@r)
3549     {
3550         next unless /\.(.*)$/;
3551         &saw_extension ($1);
3552     }
3555 sub handle_gettext
3557     return if ! $seen_gettext || $relative_dir ne '.';
3559     if (! &variable_defined ('SUBDIRS'))
3560     {
3561         &am_conf_error
3562             ("AM_GNU_GETTEXT in configure.in but SUBDIRS not defined");
3563         return;
3564     }
3566     &require_file_with_conf_line ($ac_gettext_line, $GNU, 'ABOUT-NLS');
3568     if (&variable_defined ('SUBDIRS'))
3569     {
3570         &am_line_error
3571             ('SUBDIRS',
3572              "AM_GNU_GETTEXT in configure.in but \`po' not in SUBDIRS")
3573                 if $contents{'SUBDIRS'} !~ /\bpo\b/;
3574         &am_line_error
3575             ('SUBDIRS',
3576              "AM_GNU_GETTEXT in configure.in but \`intl' not in SUBDIRS")
3577                 if $contents{'SUBDIRS'} !~ /\bintl\b/;
3578     }
3580     # Ensure that each language in ALL_LINGUAS has a .po file, and
3581     # each po file is mentioned in ALL_LINGUAS.
3582     if ($seen_linguas)
3583     {
3584         local (%linguas) = ();
3585         grep ($linguas{$_} = 1, split (' ', $all_linguas));
3587         foreach (<po/*.po>)
3588         {
3589             s/^po\///;
3590             s/\.po$//;
3592             &am_line_error ($all_linguas_line,
3593                             ("po/$_.po exists but \`$_' not in \`ALL_LINGUAS'"))
3594                 if ! $linguas{$_};
3595         }
3597         foreach (keys %linguas)
3598         {
3599             &am_line_error ($all_linguas_line,
3600                             "$_ in \`ALL_LINGUAS' but po/$_.po does not exist")
3601                 if ! -f "po/$_.po";
3602         }
3603     }
3604     else
3605     {
3606         &am_error ("AM_GNU_GETTEXT in configure.in but \`ALL_LINGUAS' not defined");
3607     }
3610 # Handle footer elements.
3611 sub handle_footer
3613     if ($contents{'SOURCES'})
3614     {
3615         # NOTE don't use define_pretty_variable here, because
3616         # $contents{...} is already defined.
3617         $output_vars .= 'SOURCES = ' . $contents{'SOURCES'} . "\n";
3618     }
3619     if ($contents{'OBJECTS'})
3620     {
3621         # NOTE don't use define_pretty_variable here, because
3622         # $contents{...} is already defined.
3623         $output_vars .= 'OBJECTS = ' . $contents{'OBJECTS'} . "\n";
3624     }
3625     if ($contents{'SOURCES'} || $contents{'OBJECTS'})
3626     {
3627         $output_vars .= "\n";
3628     }
3630     if (&variable_defined ('SUFFIXES'))
3631     {
3632         # Push actual suffixes, and not $(SUFFIXES).  Some versions of
3633         # make do not like variable substitutions on the .SUFFIXES
3634         # line.
3635         push (@suffixes, &variable_value_as_list ('SUFFIXES', ''));
3636     }
3637     if (&target_defined ('.SUFFIXES'))
3638     {
3639         &am_line_error ('.SUFFIXES',
3640                         "use variable \`SUFFIXES', not target \`.SUFFIXES'");
3641     }
3643     # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
3644     # before .SUFFIXES.  So we make sure that .SUFFIXES appears before
3645     # anything else, by sticking it right after the default: target.
3646     $output_header .= ".SUFFIXES:\n";
3647     if (@suffixes)
3648     {
3649         # Make sure suffixes has unique elements.  Sort them to ensure
3650         # the output remains consistent.
3651         local (%suffixes);
3653         grep ($suffixes{$_} = 1, @suffixes);
3655         $output_header .= (".SUFFIXES: "
3656                            . join (' ', sort keys %suffixes)
3657                            . "\n");
3658     }
3659     $output_trailer .= &file_contents ('footer');
3662 # Deal with installdirs target.
3663 sub handle_installdirs
3665     # GNU Makefile standards recommend this.
3666     if ($recursive_install)
3667     {
3668         # We create a separate `-am' target so that the -recursive
3669         # rule will work correctly.
3670         $output_rules .= ("installdirs: installdirs-recursive\n"
3671                           . "installdirs-am:\n");
3672         push (@phony, 'installdirs-am');
3673     }
3674     else
3675     {
3676         $output_rules .= "installdirs:\n";
3677     }
3678     push (@phony, 'installdirs');
3679     if (@installdirs)
3680     {
3681         &pretty_print_rule ("\t" . '$(mkinstalldirs) ', "\t\t",
3682                             @installdirs);
3683     }
3684     $output_rules .= "\n";
3687 # There are several targets which need to be merged.  This is because
3688 # their complete definition is compiled from many parts.  Note that we
3689 # avoid double colon rules, otherwise we'd use them instead.
3690 sub handle_merge_targets
3692     local ($makefile) = @_;
3694     # There are a few install-related variables that you should not define.
3695     local ($var);
3696     foreach $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
3697     {
3698         if (&variable_defined ($var))
3699         {
3700             &am_line_error ($var, "\`$var' should not be defined");
3701         }
3702     }
3704     # Put this at the beginning for the sake of non-GNU makes.  This
3705     # is still wrong if these makes can run parallel jobs.  But it is
3706     # right enough.
3707     unshift (@all, &basename ($makefile));
3709     local ($one_name);
3710     foreach $one_name (@config_names)
3711     {
3712         push (@all, &basename ($one_name))
3713             if &dirname ($one_name) eq $relative_dir;
3714     }
3716     &do_one_merge_target ('info', @info);
3717     &do_one_merge_target ('dvi', @dvi);
3718     &do_check_merge_target;
3719     &do_one_merge_target ('installcheck', @installcheck);
3721     if (defined $options{'no-installinfo'})
3722     {
3723         &do_one_merge_target ('install-info', '');
3724     }
3725     elsif (&target_defined ('install-info-local'))
3726     {
3727         &am_line_error ('install-info-local',
3728                         "\`install-info-local' target defined but \`no-installinfo' option not in use");
3729     }
3731     local ($utarg);
3732     foreach $utarg ('uninstall-data-local', 'uninstall-data-hook',
3733                     'uninstall-exec-local', 'uninstall-exec-hook')
3734     {
3735         if (&target_defined ($utarg))
3736         {
3737             local ($x);
3738             ($x = $utarg) =~ s/(data|exec)-//;
3739             &am_line_error ($utarg, "use \`$x', not \`$utarg'");
3740         }
3741     }
3743     if (&target_defined ('install-local'))
3744     {
3745         &am_line_error ('install-local',
3746                         "use \`install-data-local' or \`install-exec-local', not \`install-local'");
3747     }
3749     if (@all)
3750     {
3751         local ($one_name);
3752         local ($local_headers) = '';
3753         foreach $one_name (@config_names)
3754         {
3755             if (&dirname ($one_name) eq $relative_dir)
3756             {
3757                 $local_headers .= ' ' if $local_headers;
3758                 $local_headers .= &basename ($one_name);
3759             }
3760         }
3761         if ($local_headers)
3762         {
3763             # This is kind of a hack, but I couldn't see a better way
3764             # to handle it.  In this particular case, we need to make
3765             # sure config.h is built before we recurse.  We can't do
3766             # this by changing the order of dependencies to the "all"
3767             # because that breaks when using parallel makes.  Instead
3768             # we handle things explicitly.
3769             $output_rules .= ("all-recursive-am: ${local_headers}"
3770                                   . "\n\t"
3771                                   . '$(MAKE) $(AM_MAKEFLAGS)'
3772                                   . " all-recursive"
3773                                   . "\n\n");
3774             $all_target = 'all-recursive-am';
3775             push (@phony, 'all-recursive-am');
3776         }
3777     }
3779     # Print definitions users can use.
3780     &do_one_merge_target ('install-exec', @install_exec);
3781     $output_rules .= "\n";
3783     &do_one_merge_target ('install-data', @install_data);
3784     $output_rules .= "\n";
3786     &do_one_merge_target ('install', 'all-am');
3787     &do_one_merge_target ('uninstall', @uninstall);
3789     &do_one_merge_target ('all', @all);
3791     # Generate the new 'install-strip' target.  We can't just set
3792     # INSTALL_PROGRAM because that might be a relative path.
3793     $output_rules .= ("install-strip:\n\t"
3794                       . '$(MAKE) $(AM_MAKEFLAGS) INSTALL_STRIP_FLAG=-s install'
3795                       . "\n");
3796     push (@phony, 'install-strip');
3799 # Helper for handle_merge_targets.  Note that handle_merge_targets
3800 # relies on the fact that this doesn't add an extra \n at the end.
3801 sub do_one_merge_target
3803     local ($name, @values) = @_;
3805     if (&target_defined ($name . '-local'))
3806     {
3807         # User defined local form of target.  So include it.
3808         push (@values, $name . '-local');
3809         push (@phony, $name . '-local');
3810     }
3812     &pretty_print_rule ($name . "-am:", "\t\t", @values);
3813     if ($name eq 'install')
3814     {
3815         # Special-case `install-am' to run install-exec-am and
3816         # install-data-am after all-am is built.
3817         &pretty_print_rule ("\t\@\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
3818                             'install-exec-am', 'install-data-am');
3819     }
3820     elsif ($name eq 'install-exec' && &target_defined ('install-exec-hook'))
3821     {
3822         $output_rules .= ("\t\@\$(NORMAL_INSTALL)\n"
3823                           . "\t" . '$(MAKE) $(AM_MAKEFLAGS) install-exec-hook'
3824                           . "\n");
3825     }
3826     elsif ($name eq 'install-data' && &target_defined ('install-data-hook'))
3827     {
3828         $output_rules .= ("\t\@\$(NORMAL_INSTALL)\n"
3829                           . "\t" . '$(MAKE) $(AM_MAKEFLAGS) install-data-hook'
3830                           . "\n");
3831     }
3833     local ($lname) = $name . ($recursive_install ? '-recursive' : '-am');
3834     local ($tname) = $name;
3835     # To understand this special case, see handle_merge_targets.
3836     if ($name eq 'all')
3837     {
3838         $tname = 'all-redirect';
3839         $lname = $all_target if $recursive_install;
3840         push (@phony, 'all-redirect');
3841         $output_all = "all: all-redirect\n";
3842     }
3843     &pretty_print_rule ($tname . ":", "\t\t", $lname);
3844     push (@phony, $name . '-am', $name);
3847 # Handle check merge target specially.
3848 sub do_check_merge_target
3850     if (&target_defined ('check-local'))
3851     {
3852         # User defined local form of target.  So include it.
3853         push (@check_tests, 'check-local');
3854         push (@phony, 'check-local');
3855     }
3857     # In --cygnus mode, check doesn't depend on all.
3858     if ($cygnus_mode)
3859     {
3860         # Just run the local check rules.
3861         &pretty_print_rule ('check-am:', "\t\t", @check);
3862     }
3863     else
3864     {
3865         # The check target must depend on the local equivalent of
3866         # `all', to ensure all the primary targets are built.  Then it
3867         # must build the local check rules.
3868         $output_rules .= "check-am: all-am\n";
3869         &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
3870                             @check)
3871             if @check;
3872     }
3873     &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
3874                         @check_tests)
3875         if @check_tests;
3877     push (@phony, 'check', 'check-am');
3878     $output_rules .= ("check: "
3879                       . ($recursive_install ? 'check-recursive' : 'check-am')
3880                       . "\n");
3883 # Handle all 'clean' targets.
3884 sub handle_clean
3886     local ($xform) = '';
3887     local ($name);
3889     # Don't include `MAINTAINER'; it is handled specially below.
3890     foreach $name ('MOSTLY', '', 'DIST')
3891     {
3892         if (! &variable_defined ($name . 'CLEANFILES'))
3893         {
3894             $xform .= 's/^' . $name . 'CLEAN.*$//;';
3895         }
3896         else
3897         {
3898             $xform .= 's/^' . $name . 'CLEAN//;';
3899         }
3900     }
3902     # Built sources are automatically removed by maintainer-clean.
3903     push (@maintainer_clean_files, '\$(BUILT_SOURCES)')
3904         if &variable_defined ('BUILT_SOURCES');
3905     push (@maintainer_clean_files, '\$(MAINTAINERCLEANFILES)')
3906         if &variable_defined ('MAINTAINERCLEANFILES');
3907     if (! @maintainer_clean_files)
3908     {
3909         $xform .= 's/^MAINTAINERCLEAN.*$//;';
3910     }
3911     else
3912     {
3913         $xform .= ('s/^MAINTAINERCLEAN//;'
3914                    # Join with no space to avoid spurious `test -z'
3915                    # success at runtime.
3916                    . 's,\@MCFILES\@,' . join ('', @maintainer_clean_files)
3917                    . ',;'
3918                    # A space is required in the join here.
3919                    . 's,\@MFILES\@,' . join (' ', @maintainer_clean_files)
3920                    . ',;');
3921     }
3923     $output_rules .= &file_contents_with_transform ($xform, 'clean');
3925     push (@clean, 'generic');
3926     &push_phony_cleaners ('generic');
3928     &do_one_clean_target ('clean', 'mostly', '', @clean);
3929     &do_one_clean_target ('clean', '', 'mostly', @clean);
3930     &do_one_clean_target ('clean', 'dist', '', @clean);
3931     &do_one_clean_target ('clean', 'maintainer-', 'dist', @clean);
3933     push (@phony, 'clean', 'mostlyclean', 'distclean', 'maintainer-clean');
3936 # Helper for handle_clean.
3937 sub do_one_clean_target
3939     local ($target, $name, $last_name, @deps) = @_;
3941     # Change each dependency `BLARG' into `clean-BLARG'.
3942     grep (($_ = $name . 'clean-' . $_) && 0, @deps);
3944     # Push the previous clean target.  There is no previous clean
3945     # target if we're doing mostlyclean.
3946     push (@deps, $last_name . $target . '-am')
3947         unless $name eq 'mostly';
3949     # If a -local version of the rule is given, add it to the list.
3950     if (&target_defined ($name . $target . '-local'))
3951     {
3952         push (@deps, $name . $target . '-local');
3953     }
3955     # Print the target and the dependencies.
3956     &pretty_print_rule ($name . $target . "-am: ", "\t\t", @deps);
3958     # FIXME: shouldn't we really print these messages before running
3959     # the dependencies?
3960     if ($name . $target eq 'maintainer-clean')
3961     {
3962         # Print a special warning.
3963         $output_rules .=
3964             ("\t\@echo \"This command is intended for maintainers to use;\"\n"
3965              . "\t\@echo \"it deletes files that may require special "
3966              . "tools to rebuild.\"\n");
3967     }
3968     elsif ($name . $target eq 'distclean')
3969     {
3970         $output_rules .= "\t-rm -f libtool\n" if $seen_libtool;
3971     }
3972     $output_rules .= "\n";
3974     # Now generate the actual clean target.
3975     $output_rules .= ($name . $target . ": " . $name . $target
3976                       . ($recursive_install ? '-recursive' : '-am')
3977                       . "\n");
3979     # We special-case config.status here.  If we do it as part of the
3980     # normal clean processing for this directory, then it might be
3981     # removed before some subdir is cleaned.  However, that subdir's
3982     # Makefile depends on config.status.
3983     if (($name . $target eq 'maintainer-clean'
3984          || $name . $target eq 'distclean')
3985         && $relative_dir eq '.')
3986     {
3987         $output_rules .= "\t-rm -f config.status\n";
3988     }
3989     $output_rules .= "\n";
3992 # Handle .PHONY target.
3993 sub handle_phony
3995     &pretty_print_rule ('.PHONY:', "", @phony);
3996     $output_rules .= "\n";
3999 # Handle TESTS variable and other checks.
4000 sub handle_tests
4002     if (defined $options{'dejagnu'})
4003     {
4004         push (@check_tests, 'check-DEJAGNU');
4005         push (@phony, 'check-DEJAGNU');
4007         local ($xform);
4008         if ($cygnus_mode)
4009         {
4010             $xform = 's/^CYGNUS//;';
4011         }
4012         else
4013         {
4014             $xform = 's/^CYGNUS.*$//;';
4015         }
4016         $output_rules .= &file_contents_with_transform ($xform, 'dejagnu');
4018         # In Cygnus mode, these are found in the build tree.
4019         # Otherwise they are looked for in $PATH.
4020         &define_program_variable ('EXPECT', 'build', 'expect', 'expect');
4021         &define_program_variable ('RUNTEST', 'src', 'dejagnu', 'runtest');
4023         # Only create site.exp rule if user hasn't already written
4024         # one.
4025         if (! &target_defined ('site.exp'))
4026         {
4027             # Note that in the rule we don't directly generate
4028             # site.exp to avoid the possibility of a corrupted
4029             # site.exp if make is interrupted.  Jim Meyering has some
4030             # useful text on this topic.
4031             $output_rules .= ("site.exp: Makefile\n"
4032                               . "\t\@echo 'Making a new site.exp file...'\n"
4033                               . "\t\@test ! -f site.bak || rm -f site.bak\n"
4034                               . "\t\@echo '## these variables are automatically generated by make ##' > \$\@-t\n"
4035                               . "\t\@echo '# Do not edit here.  If you wish to override these values' >> \$\@-t\n"
4036                               . "\t\@echo '# edit the last section' >> \$\@-t\n"
4037                               . "\t\@echo 'set tool \$(DEJATOOL)' >> \$\@-t\n"
4038                               . "\t\@echo 'set srcdir \$(srcdir)' >> \$\@-t\n"
4039                               . "\t\@echo 'set objdir' \`pwd\` >> \$\@-t\n");
4041             # Extra stuff for AC_CANONICAL_*
4042             local (@whatlist) = ();
4043             if ($seen_canonical)
4044             {
4045                 push (@whatlist, 'host');
4046             }
4048             # Extra stuff only for AC_CANONICAL_SYSTEM.
4049             if ($seen_canonical == $AC_CANONICAL_SYSTEM)
4050             {
4051                 push (@whatlist, 'target', 'build');
4052             }
4054             local ($c1, $c2);
4055             foreach $c1 (@whatlist)
4056             {
4057                 foreach $c2 ('alias', 'triplet')
4058                 {
4059                     $output_rules .= "\t\@echo 'set ${c1}_${c2} \$(${c1}_${c2})' >> \$\@-t\n";
4060                 }
4061             }
4063             $output_rules .= ("\t\@echo '## All variables above are generated by configure. Do Not Edit ##' >> \$\@-t\n"
4064                               . "\t\@test ! -f site.exp || sed '1,/^## All variables above are.*##/ d' site.exp >> \$\@-t\n"
4065                               . "\t\@test ! -f site.exp || mv site.exp site.bak\n"
4066                               . "\t\@mv \$\@-t site.exp\n");
4067         }
4068     }
4069     else
4070     {
4071         local ($c);
4072         foreach $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
4073         {
4074             if (&variable_defined ($c))
4075             {
4076                 &am_line_error ($c, "\`$c' defined but \`dejagnu' not in \`AUTOMAKE_OPTIONS'");
4077             }
4078         }
4079     }
4081     if (&variable_defined ('TESTS'))
4082     {
4083         push (@check_tests, 'check-TESTS');
4084         push (@phony, 'check-TESTS');
4086         # Note: Solaris 2.7 seems to expand TESTS using VPATH.  That's
4087         # why we also try `dir='
4088         $output_rules .= 'check-TESTS: $(TESTS)
4089         @failed=0; all=0; xfail=0; xpass=0; \\
4090         srcdir=$(srcdir); export srcdir; \\
4091         for tst in $(TESTS); do \\
4092           if test -f ./$$tst; then dir=./; \\
4093           elif test -f $$tst; then dir=; \\
4094           else dir="$(srcdir)/"; fi; \\
4095           if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \\
4096             all=`expr $$all + 1`; \\
4097             case " $(XFAIL_TESTS) " in \\
4098             *" $$tst "*) \\
4099               xpass=`expr $$xpass + 1`; \\
4100               failed=`expr $$failed + 1`; \\
4101               echo "XPASS: $$tst"; \\
4102             ;; \\
4103             *) \\
4104               echo "PASS: $$tst"; \\
4105             ;; \\
4106             esac; \\
4107           elif test $$? -ne 77; then \\
4108             all=`expr $$all + 1`; \\
4109             case " $(XFAIL_TESTS) " in \\
4110             *" $$tst "*) \\
4111               xfail=`expr $$xfail + 1`; \\
4112               echo "XFAIL: $$tst"; \\
4113             ;; \\
4114             *) \\
4115               failed=`expr $$failed + 1`; \\
4116               echo "FAIL: $$tst"; \\
4117             ;; \\
4118             esac; \\
4119           fi; \\
4120         done; \\
4121         if test "$$failed" -eq 0; then \\
4122           if test "$$xfail" -eq 0; then \\
4123             banner="All $$all tests passed"; \\
4124           else \\
4125             banner="All $$all tests behaved as expected ($$xfail expected failures)"; \\
4126           fi; \\
4127         else \\
4128           if test "$$xpass" -eq 0; then \\
4129             banner="$$failed of $$all tests failed"; \\
4130           else \\
4131             banner="$$failed of $$all tests did not behave as expected ($$xpass unexpected passes)"; \\
4132           fi; \\
4133         fi; \\
4134         dashes=`echo "$$banner" | sed s/./=/g`; \\
4135         echo "$$dashes"; \\
4136         echo "$$banner"; \\
4137         echo "$$dashes"; \\
4138         test "$$failed" -eq 0
4140     }
4143 # Handle Emacs Lisp.
4144 sub handle_emacs_lisp
4146     local (@elfiles) = &am_install_var ('-candist', 'lisp', 'LISP',
4147                                         'lisp', 'noinst');
4149     if (@elfiles)
4150     {
4151         # Found some lisp.
4152         &define_configure_variable ('lispdir');
4153         &define_configure_variable ('EMACS');
4154         $output_rules .= (".el.elc:\n"
4155                           . "\t\@echo 'WARNING: Warnings can be ignored. :-)'\n"
4156                           . "\tif test \$(EMACS) != no; then \\\n"
4157                           . "\t  EMACS=\$(EMACS) \$(SHELL) \$(srcdir)/elisp-comp \$<; \\\n"
4158                           . "\tfi\n");
4159         push (@suffixes, '.el', '.elc');
4161         # Generate .elc files.
4162         grep ($_ .= 'c', @elfiles);
4163         &define_pretty_variable ('ELCFILES', '', @elfiles);
4165         $output_rules .= &file_contents ('lisp-clean');
4166         push (@clean, 'lisp');
4167         &push_phony_cleaners ('lisp');
4169         push (@all, '$(ELCFILES)');
4171         local ($varname);
4172         if (&variable_defined ('lisp_LISP'))
4173         {
4174             $varname = 'lisp_LISP';
4175             &am_error ("\`lisp_LISP' defined but \`AM_PATH_LISPDIR' not in \`configure.in'")
4176                 if ! $seen_lispdir;
4177         }
4178         else
4179         {
4180             $varname = 'noinst_LISP';
4181         }
4183         &require_file_with_line ($varname, $FOREIGN, 'elisp-comp');
4184     }
4187 # Handle Python
4188 sub handle_python
4190     local (@pyfiles) = &am_install_var ('-defaultdist', 'python', 'PYTHON',
4191                                         'python', 'noinst');
4192     return if ! @pyfiles;
4194     # Found some python.
4195     &define_configure_variable ('pythondir');
4196     &define_configure_variable ('PYTHON');
4198     $output_rules .= &file_contents ('python-clean');
4199     push (@clean, 'python');
4201     &am_error ("\`python_PYTHON' defined but \`AM_CHECK_PYTHON' not in \`configure.in'")
4202         if ! $seen_pythondir && &variable_defined ('python_PYTHON');
4204     if ($config_aux_dir eq '.' || $config_aux_dir eq '')
4205     {
4206         &define_variable ('py_compile', '$(top_srcdir)/py-compile');
4207     }
4208     else
4209     {
4210         &define_variable ('py_compile', $config_aux_dir . '/py-compile');
4211     }
4214 # Handle Java.
4215 sub handle_java
4217     local (@sourcelist) = &am_install_var ('-candist', '-clean',
4218                                            'java', 'JAVA',
4219                                            'java', 'noinst', 'check');
4220     return if ! @sourcelist;
4222     &define_variable ('JAVAC', 'javac');
4223     &define_variable ('JAVACFLAGS', '');
4224     &define_variable ('CLASSPATH_ENV',
4225                       'CLASSPATH=$(JAVAROOT):$(srcdir)/$(JAVAROOT):$$CLASSPATH');
4226     &define_variable ('JAVAROOT', '$(top_builddir)');
4228     local (%valid) = &am_primary_prefixes ('JAVA', 1,
4229                                            'java', 'noinst', 'check');
4231     local ($dir, $curs);
4232     foreach $curs (keys %valid)
4233     {
4234         if (! &variable_defined ($curs . '_JAVA') || $curs eq 'noinst'
4235             || $curs eq 'EXTRA')
4236         {
4237             next;
4238         }
4240         if (defined $dir)
4241         {
4242             &am_line_error ($curs . '_JAVA',
4243                             "multiple _JAVA primaries in use");
4244         }
4245         $dir = $curs;
4246     }
4248     $output_rules .= ('class' . $dir . '.stamp: $(' . $dir . '_JAVA)' . "\n"
4249                       . "\t" . '$(CLASSPATH_ENV) $(JAVAC) -d $(JAVAROOT) '
4250                       . '$(JAVACFLAGS) $?' . "\n"
4251                       . "\t" . 'echo timestamp > class' . $dir . '.stamp'
4252                       . "\n");
4253     push (@all, 'class' . $dir . '.stamp');
4254     &push_dist_common ('$(' . $dir . '_JAVA)');
4257 # Handle some of the minor options.
4258 sub handle_minor_options
4260     if (defined $options{'readme-alpha'})
4261     {
4262         if ($relative_dir eq '.')
4263         {
4264             if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
4265             {
4266                 # FIXME: allow real filename.
4267                 &am_conf_line_error ('configure.in',
4268                                      $package_version_line,
4269                                      "version \`$package_version' doesn't follow Gnits standards");
4270             }
4271             elsif (defined $1 && -f 'README-alpha')
4272             {
4273                 # This means we have an alpha release.  See
4274                 # GNITS_VERSION_PATTERN for details.
4275                 &require_file ($FOREIGN, 'README-alpha');
4276             }
4277         }
4278     }
4281 ################################################################
4283 # Scan one file for interesting things.  Subroutine of scan_configure.
4284 sub scan_one_configure_file
4286     local ($filename) = @_;
4287     local (*CONFIGURE);
4289     open (CONFIGURE, $filename)
4290         || die "automake: couldn't open \`$filename': $!\n";
4291     print "automake: reading $filename\n" if $verbose;
4293     while (<CONFIGURE>)
4294     {
4295         # Remove comments from current line.
4296         s/\bdnl\b.*$//;
4297         s/\#.*$//;
4299         # Skip macro definitions.  Otherwise we might be confused into
4300         # thinking that a macro that was only defined was actually
4301         # used.
4302         next if /AC_DEFUN/;
4304         # Follow includes.  This is a weirdness commonly in use at
4305         # Cygnus and hopefully nowhere else.
4306         if (/sinclude\((.*)\)/ && -f $1)
4307         {
4308             &scan_one_configure_file ($1);
4309         }
4311         # Populate libobjs array.
4312         if (/AC_FUNC_ALLOCA/)
4313         {
4314             $libsources{'alloca.c'} = 1;
4315         }
4316         elsif (/AC_FUNC_GETLOADAVG/)
4317         {
4318             $libsources{'getloadavg.c'} = 1;
4319         }
4320         elsif (/AC_FUNC_MEMCMP/)
4321         {
4322             $libsources{'memcmp.c'} = 1;
4323         }
4324         elsif (/AC_STRUCT_ST_BLOCKS/)
4325         {
4326             $libsources{'fileblocks.c'} = 1;
4327         }
4328         elsif (/A[CM]_REPLACE_GNU_GETOPT/)
4329         {
4330             $libsources{'getopt.c'} = 1;
4331             $libsources{'getopt1.c'} = 1;
4332         }
4333         elsif (/AM_FUNC_STRTOD/)
4334         {
4335             $libsources{'strtod.c'} = 1;
4336         }
4337         elsif (/AM_WITH_REGEX/)
4338         {
4339             $libsources{'rx.c'} = 1;
4340             $libsources{'rx.h'} = 1;
4341             $libsources{'regex.c'} = 1;
4342             $libsources{'regex.h'} = 1;
4343             $omit_dependencies{'rx.h'} = 1;
4344             $omit_dependencies{'regex.h'} = 1;
4345         }
4346         elsif (/AC_FUNC_MKTIME/)
4347         {
4348             $libsources{'mktime.c'} = 1;
4349         }
4350         elsif (/AM_FUNC_ERROR_AT_LINE/)
4351         {
4352             $libsources{'error.c'} = 1;
4353             $libsources{'error.h'} = 1;
4354         }
4355         elsif (/AM_FUNC_OBSTACK/)
4356         {
4357             $libsources{'obstack.c'} = 1;
4358             $libsources{'obstack.h'} = 1;
4359         }
4360         elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
4361                || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
4362         {
4363             foreach $libobj_iter (split (' ', $1))
4364             {
4365                 if ($libobj_iter =~ /^(.*)\.o(bj)?$/
4366                     || $libobj_iter =~ /^(.*)\.\$ac_objext$/
4367                     || $libobj_iter =~ /^(.*)\.\$\{ac_objext\}$/)
4368                 {
4369                     $libsources{$1 . '.c'} = 1;
4370                 }
4371             }
4372         }
4374         if (! $in_ac_replace && s/AC_REPLACE_FUNCS\s*\(\[?//)
4375         {
4376             $in_ac_replace = 1;
4377         }
4378         if ($in_ac_replace)
4379         {
4380             $in_ac_replace = 0 if s/[\]\)].*$//;
4381             # Remove trailing backslash.
4382             s/\\$//;
4383             foreach (split)
4384             {
4385                 # Need to skip empty elements for Perl 4.
4386                 next if $_ eq '';
4387                 $libsources{$_ . '.c'} = 1;
4388             }
4389         }
4391         if (/$obsolete_rx/o)
4392         {
4393             local ($hint) = '';
4394             if ($obsolete_macros{$1} ne '')
4395             {
4396                 $hint = '; ' . $obsolete_macros{$1};
4397             }
4398             &am_conf_line_error ($filename, $., "\`$1' is obsolete$hint");
4399         }
4401         # Process the AC_OUTPUT and AC_CONFIG_FILES macros.
4402         if (! $in_ac_output && s/AC_(OUTPUT|CONFIG_FILES)\s*\(\[?//)
4403         {
4404             $in_ac_output = 1;
4405             $ac_output_line = $.;
4406         }
4407         if ($in_ac_output)
4408         {
4409             local ($closing) = 0;
4410             if (s/[\]\),].*$//)
4411             {
4412                 $in_ac_output = 0;
4413                 $closing = 1;
4414             }
4416             # Look at potential Makefile.am's.
4417             foreach (split)
4418             {
4419                 # Must skip empty string for Perl 4.
4420                 next if $_ eq "\\" || $_ eq '';
4422                 # Handle $local:$input syntax.  Note that we ignore
4423                 # every input file past the first, though we keep
4424                 # those around for later.
4425                 local ($local, $input, @rest) = split (/:/);
4426                 if (! $input)
4427                 {
4428                     $input = $local;
4429                 }
4430                 else
4431                 {
4432                     # FIXME: should be error if .in is missing.
4433                     $input =~ s/\.in$//;
4434                 }
4436                 if (-f $input . '.am')
4437                 {
4438                     # We have a file that automake should generate.
4439                     push (@make_input_list, $input);
4440                     $make_list{$input} = join (':', ($local, @rest));
4441                 }
4442                 else
4443                 {
4444                     # We have a file that automake should cause to be
4445                     # rebuilt, but shouldn't generate itself.
4446                     push (@other_input_files, $_);
4447                 }
4448             }
4450             if ($closing && @make_input_list == 0 && @other_input_files == 0)
4451             {
4452                 &am_conf_line_error ($filename, $ac_output_line,
4453                                      "No files mentioned in \`AC_OUTPUT'");
4454                 exit 1;
4455             }
4456         }
4458         if (/$AC_CONFIG_AUX_DIR_PATTERN/o)
4459         {
4460             @config_aux_path = $1;
4461         }
4463         # Check for ansi2knr.
4464         $am_c_prototypes = 1 if /AM_C_PROTOTYPES/;
4466         # Check for exe extension stuff.
4467         if (/AC_EXEEXT/)
4468         {
4469             $seen_exeext = 1;
4470             $configure_vars{'EXEEXT'} = $filename . ':' . $.;
4471         }
4473         if (/AC_OBJEXT/)
4474         {
4475             $seen_objext = 1;
4476             $configure_vars{'OBJEXT'} = $filename . ':' . $.;
4477         }
4479         # Check for `-c -o' code.
4480         $seen_cc_c_o = 1 if /AM_PROG_CC_C_O/;
4482         # Check for NLS support.
4483         if (/AM_GNU_GETTEXT/)
4484         {
4485             $seen_gettext = 1;
4486             $ac_gettext_line = $.;
4487             $omit_dependencies{'libintl.h'} = 1;
4488         }
4490         # Look for ALL_LINGUAS.
4491         if (/ALL_LINGUAS="(.*)"$/ || /ALL_LINGUAS=(.*)$/)
4492         {
4493             $seen_linguas = 1;
4494             $all_linguas = $1;
4495             $all_linguas_line = $.;
4496         }
4498         # Handle configuration headers.  A config header of `[$1]'
4499         # means we are actually scanning AM_CONFIG_HEADER from
4500         # aclocal.m4.
4501         if (/A([CM])_CONFIG_HEADERS?\s*\((.*)\)/
4502             && $2 ne '[$1]')
4503         {
4504             &am_conf_line_error
4505                 ($filename, $., "\`automake requires \`AM_CONFIG_HEADER', not \`AC_CONFIG_HEADER'")
4506                     if $1 eq 'C';
4508             $config_header_line = $.;
4509             local ($one_hdr);
4510             foreach $one_hdr (split (' ', $2))
4511             {
4512                 push (@config_fullnames, $one_hdr);
4513                 if ($one_hdr =~ /^([^:]+):(.+)$/)
4514                 {
4515                     push (@config_names, $1);
4516                     push (@config_headers, $2);
4517                 }
4518                 else
4519                 {
4520                     push (@config_names, $one_hdr);
4521                     push (@config_headers, $one_hdr . '.in');
4522                 }
4523             }
4524         }
4526         # Handle AC_CANONICAL_*.  Always allow upgrading to
4527         # AC_CANONICAL_SYSTEM, but never downgrading.
4528         $seen_canonical = $AC_CANONICAL_HOST
4529             if ! $seen_canonical
4530                 && (/AC_CANONICAL_HOST/ || /AC_CHECK_TOOL/);
4531         $seen_canonical = $AC_CANONICAL_SYSTEM if /AC_CANONICAL_SYSTEM/;
4533         $seen_path_xtra = 1 if /AC_PATH_XTRA/;
4535         # This macro handles several different things.
4536         if (/$AM_INIT_AUTOMAKE_PATTERN/o)
4537         {
4538             $seen_make_set = 1;
4539             $seen_arg_prog = 1;
4540             $seen_prog_install = 1;
4541             ($package_version = $1) =~ s/$AM_PACKAGE_VERSION_PATTERN/$1/o;
4542             $package_version_line = $.;
4543             $seen_init_automake = 1;
4544         }
4546         # Some things required by Automake.
4547         $seen_make_set = 1 if /AC_PROG_MAKE_SET/;
4548         $seen_arg_prog = 1 if /AC_ARG_PROGRAM/;
4550         if (/AM_PROG_LEX/)
4551         {
4552             $configure_vars{'LEX'} = $filename . ':' . $.;
4553             $seen_decl_yytext = 1;
4554         }
4555         if (/AC_DECL_YYTEXT/ && $filename =~ /configure\.in$/)
4556         {
4557             &am_conf_line_warning ($filename, $., "\`AC_DECL_YYTEXT' is covered by \`AM_PROG_LEX'");
4558         }
4559         if (/AC_PROG_LEX/ && $filename =~ /configure\.in$/)
4560         {
4561             &am_conf_line_warning ($filename, $., "automake requires \`AM_PROG_LEX', not \`AC_PROG_LEX'");
4562         }
4564         if (/AC_PROG_(F77|YACC|RANLIB|CC|CXXCPP|CXX|LEX|AWK|CPP|LN_S)/)
4565         {
4566             $configure_vars{$1} = $filename . ':' . $.;
4567         }
4568         if (/$AC_CHECK_PATTERN/o)
4569         {
4570             $configure_vars{$3} = $filename . ':' . $.;
4571         }
4572         if (/$AM_MISSING_PATTERN/o
4573             && $1 ne 'ACLOCAL'
4574             && $1 ne 'AUTOCONF'
4575             && $1 ne 'AUTOMAKE'
4576             && $1 ne 'AUTOHEADER')
4577         {
4578             $configure_vars{$1} = $filename . ':' . $.;
4579         }
4581         # Explicitly avoid ANSI2KNR -- we AC_SUBST that in protos.m4,
4582         # but later define it elsewhere.  This is pretty hacky.  We
4583         # also explicitly avoid INSTALL_SCRIPT and some other
4584         # variables because they are defined in header-vars.am.
4585         # FIXME.
4586         if (/$AC_SUBST_PATTERN/o
4587             && $1 ne 'ANSI2KNR'
4588             && $1 ne 'INSTALL_SCRIPT'
4589             && $1 ne 'INSTALL_DATA')
4590         {
4591             $configure_vars{$1} = $filename . ':' . $.;
4592         }
4594         $seen_decl_yytext = 1 if /AC_DECL_YYTEXT/;
4595         if (/AM_MAINTAINER_MODE/)
4596         {
4597             $seen_maint_mode = 1;
4598             $configure_cond{'MAINTAINER_MODE'} = 1;
4599         }
4601         $seen_prog_install = 1 if /AC_PROG_INSTALL/;
4602         $seen_lispdir = 1 if /AM_PATH_LISPDIR/;
4603         $seen_pythondir = 1 if /AM_PATH_PYTHON/;
4605         if (/A(C|M)_PROG_LIBTOOL/)
4606         {
4607             if (/AM_PROG_LIBTOOL/)
4608             {
4609                 &am_conf_line_warning ($filename, $., "\`AM_PROG_LIBTOOL' is obsolete, use \`AC_PROG_LIBTOOL' instead");
4610             }
4611             $seen_libtool = 1;
4612             $libtool_line = $.;
4613             $configure_vars{'LIBTOOL'} = $filename . ':' . $.;
4614             $configure_vars{'RANLIB'} = $filename . ':' . $.;
4615             $configure_vars{'CC'} = $filename . ':' . $.;
4616             # AC_PROG_LIBTOOL runs AC_CANONICAL_HOST.  Make sure we
4617             # never downgrade (if we've seen AC_CANONICAL_SYSTEM).
4618             $seen_canonical = $AC_CANONICAL_HOST if ! $seen_canonical;
4619         }
4621         $seen_multilib = 1 if (/AM_ENABLE_MULTILIB/);
4623         if (/$AM_CONDITIONAL_PATTERN/o)
4624         {
4625             $configure_cond{$1} = 1;
4626         }
4628         # Check for Fortran 77 intrinsic and run-time libraries.
4629         if (/AC_F77_LIBRARY_LDFLAGS/)
4630         {
4631             $configure_vars{'FLIBS'} = $filename . ':' . $.;
4632         }
4633     }
4635     close (CONFIGURE);
4638 # Scan configure.in and aclocal.m4 for interesting things.  We must
4639 # scan aclocal.m4 because there might be AC_SUBSTs and such there.
4640 sub scan_configure
4642     # Reinitialize libsources here.  This isn't really necessary,
4643     # since we currently assume there is only one configure.in.  But
4644     # that won't always be the case.
4645     %libsources = ();
4647     local ($in_ac_output, $in_ac_replace) = (0, 0);
4648     local (%make_list, @make_input_list);
4649     local ($libobj_iter);
4651     &scan_one_configure_file ('configure.in');
4652     &scan_one_configure_file ('aclocal.m4')
4653         if -f 'aclocal.m4';
4655     # Set input and output files if not specified by user.
4656     if (! @input_files)
4657     {
4658         @input_files = @make_input_list;
4659         %output_files = %make_list;
4660     }
4662     @configure_input_files = @make_input_list;
4664     &am_conf_error ("\`AM_INIT_AUTOMAKE' must be used in configure.in")
4665         if ! $seen_init_automake;
4667     # Always require AC_PROG_MAKE_SET.  We might randomly use $(MAKE)
4668     # for our own reasons.
4669     &am_conf_error ("\`AC_PROG_MAKE_SET' must be used in configure.in")
4670         if ! $seen_make_set;
4672     # Look for some files we need.  Always check for these.  This
4673     # check must be done for every run, even those where we are only
4674     # looking at a subdir Makefile.  We must set relative_dir so that
4675     # the file-finding machinery works.
4676     local ($relative_dir) = '.';
4677     &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs', 'missing');
4678     &am_error ("\`install.sh' is an anachronism; use \`install-sh' instead")
4679         if -f $config_aux_path[0] . '/install.sh';
4681     &require_config_file ($FOREIGN, 'py-compile')
4682         if $seen_pythondir;
4684     # Preserve dist_common for later.
4685     %configure_dist_common = %dist_common;
4688 ################################################################
4690 # Set up for Cygnus mode.
4691 sub check_cygnus
4693     return unless $cygnus_mode;
4695     &set_strictness ('foreign');
4696     $options{'no-installinfo'} = 1;
4697     $options{'no-dependencies'} = 1;
4698     $use_dependencies = 0;
4700     if (! $seen_maint_mode)
4701     {
4702         &am_conf_error ("\`AM_MAINTAINER_MODE' required when --cygnus specified");
4703     }
4705     if (! $seen_exeext)
4706     {
4707         &am_conf_error ("\`AC_EXEEXT' required when --cygnus specified");
4708     }
4711 # Do any extra checking for GNU standards.
4712 sub check_gnu_standards
4714     if ($relative_dir eq '.')
4715     {
4716         # In top level (or only) directory.
4717         &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
4718                        'AUTHORS', 'ChangeLog');
4719     }
4721     if ($strictness >= $GNU)
4722     {
4723         if (defined $options{'no-installman'})
4724         {
4725             &am_line_error ('AUTOMAKE_OPTIONS',
4726                             "option \`no-installman' disallowed by GNU standards");
4727         }
4729         if (defined $options{'no-installinfo'})
4730         {
4731             &am_line_error ('AUTOMAKE_OPTIONS',
4732                             "option \`no-installinfo' disallowed by GNU standards");
4733         }
4734     }
4737 # Do any extra checking for GNITS standards.
4738 sub check_gnits_standards
4740     if ($relative_dir eq '.')
4741     {
4742         # In top level (or only) directory.
4743         &require_file ($GNITS, 'THANKS');
4744     }
4747 ################################################################
4749 # Functions to handle files of each language.
4751 # Each `lang_X_rewrite' function follows a simple formula:
4752 # * Args are the directory, base name and extension of the file.
4753 # * Return value is 1 if file is to be dealt with, 0 otherwise.
4754 # Much of the actual processing is handled in handle_single_transform_list.
4755 # These functions exist so that auxiliary information can be recorded
4756 # for a later cleanup pass.  Note that the calls to these functions
4757 # are computed, so don't bother searching for their precise names
4758 # in the source.
4760 # This is just a convenience function that can be used to determine
4761 # when a subdir object should be used.
4762 sub lang_sub_obj
4764     return defined $options{'subdir-objects'} ? $LANG_SUBDIR : $LANG_PROCESS;
4767 # Rewrite a single C source file.
4768 sub lang_c_rewrite
4770     local ($directory, $base, $ext) = @_;
4772     if (defined $options{'ansi2knr'} && $base =~ /_$/)
4773     {
4774         # FIXME: include line number in error.
4775         &am_error ("C source file \`$base.c' would be deleted by ansi2knr rules");
4776     }
4778     local ($r) = $LANG_PROCESS;
4779     if (defined $options{'subdir-objects'})
4780     {
4781         $r = $LANG_SUBDIR;
4782         $base = $directory . '/' . $base;
4784         if (! $seen_cc_c_o)
4785         {
4786             # Only give error once.
4787             $seen_cc_c_o = 1;
4788             # FIXME: line number.
4789             &am_error ("C objects in subdir but \`AM_PROG_CC_C_O' not in \`configure.in'");
4790         }
4792         &require_file ($FOREIGN, 'compile')
4793             if $relative_dir eq '.';
4794     }
4796     $de_ansi_files{$base} = 1;
4797     return $r;
4800 # Rewrite a single C++ source file.
4801 sub lang_cxx_rewrite
4803     return &lang_sub_obj;
4806 # Rewrite a single header file.
4807 sub lang_header_rewrite
4809     # Header files are simply ignored.
4810     return $LANG_IGNORE;
4813 # Rewrite a single yacc file.
4814 sub lang_yacc_rewrite
4816     local ($directory, $base, $ext) = @_;
4818     local ($r) = &lang_c_rewrite ($directory, $base, $ext);
4819     local ($pfx) = '';
4820     if ($r == $LANG_SUBDIR)
4821     {
4822         $pfx = $directory . '/';
4823     }
4824     $yacc_sources{$pfx . $base . '.' . $ext} = 1;
4825     $ext =~ tr/y/c/;
4826     &saw_extension ('c');
4827     # FIXME: nodist.
4828     &push_dist_common ($pfx . $base . '.' . $ext);
4829     return $r;
4832 # Rewrite a single yacc++ file.
4833 sub lang_yaccxx_rewrite
4835     local ($directory, $base, $ext) = @_;
4837     local ($r) = $LANG_PROCESS;
4838     local ($pfx) = '';
4839     if (defined $options{'subdir-objects'})
4840     {
4841         $pfx = $directory . '/';
4842         $r = $LANG_SUBDIR;
4843     }
4844     $yacc_sources{$pfx . $base . '.' . $ext} = 1;
4845     $ext =~ tr/y/c/;
4846     &saw_extension ($ext);
4847     # FIXME: nodist.
4848     &push_dist_common ($pfx . $base . '.' . $ext);
4849     return $r;
4852 # Rewrite a single lex file.
4853 sub lang_lex_rewrite
4855     local ($directory, $base, $ext) = @_;
4857     local ($r) = &lang_c_rewrite ($directory, $base, $ext);
4858     local ($pfx) = '';
4859     if ($r == $LANG_SUBDIR)
4860     {
4861         $pfx = $directory . '/';
4862     }
4863     $lex_sources{$pfx . $base . '.' . $ext} = 1;
4864     $ext =~ tr/l/c/;
4865     &saw_extension ('c');
4866     # FIXME: nodist.
4867     &push_dist_common ($pfx . $base . '.' . $ext);
4868     return $r;
4871 # Rewrite a single lex++ file.
4872 sub lang_lexxx_rewrite
4874     local ($directory, $base, $ext) = @_;
4876     local ($r) = $LANG_PROCESS;
4877     local ($pfx) = '';
4878     if (defined $options{'subdir-objects'})
4879     {
4880         $pfx = $directory . '/';
4881         $r = $LANG_SUBDIR;
4882     }
4883     $lex_sources{$pfx . $base . '.' . $ext} = 1;
4884     $ext =~ tr/l/c/;
4885     &saw_extension ($ext);
4886     # FIXME: nodist.
4887     &push_dist_common ($pfx . $base . '.' . $ext);
4888     return $r;
4891 # Rewrite a single assembly file.
4892 sub lang_asm_rewrite
4894     return &lang_sub_obj;
4897 # Rewrite a single Fortran 77 file.
4898 sub lang_f77_rewrite
4900     return $LANG_PROCESS;
4903 # Rewrite a single preprocessed Fortran 77 file.
4904 sub lang_ppf77_rewrite
4906     return $LANG_PROCESS;
4909 # Rewrite a single ratfor file.
4910 sub lang_ratfor_rewrite
4912     return $LANG_PROCESS;
4915 # Rewrite a single Objective C file.
4916 sub lang_objc_rewrite
4918     return &lang_sub_obj;
4921 # Rewrite a single Java file.
4922 sub lang_java_rewrite
4924     return $LANG_SUBDIR;
4927 # The lang_X_finish functions are called after all source file
4928 # processing is done.  Each should handle defining rules for the
4929 # language, etc.  A finish function is only called if a source file of
4930 # the appropriate type has been seen.
4932 sub lang_c_finish
4934     # Push all libobjs files onto de_ansi_files.  We actually only
4935     # push files which exist in the current directory, and which are
4936     # genuine source files.
4937     local ($file);
4938     foreach $file (keys %libsources)
4939     {
4940         if ($file =~ /^(.*)\.[cly]$/ && -f "$relative_dir/$file")
4941         {
4942             $de_ansi_files{$1} = 1;
4943         }
4944     }
4946     if (defined $options{'ansi2knr'} && keys %de_ansi_files)
4947     {
4948         # Make all _.c files depend on their corresponding .c files.
4949         local ($base, @objects);
4950         foreach $base (sort keys %de_ansi_files)
4951         {
4952             # Each _.c file must depend on ansi2knr; otherwise it
4953             # might be used in a parallel build before it is built.
4954             # We need to support files in the srcdir and in the build
4955             # dir (because these files might be auto-generated.  But
4956             # we can't use $< -- some makes only define $< during a
4957             # suffix rule.
4958             $output_rules .= ($base . "_.c: $base.c \$(ANSI2KNR)\n\t"
4959                               . '$(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) '
4960                               . '`if test -f $(srcdir)/' . $base . '.c'
4961                               . '; then echo $(srcdir)/' . $base . '.c'
4962                               . '; else echo ' . $base . '.c; fi` '
4963                               . "| sed 's/^# \\([0-9]\\)/#line \\1/' "
4964                               . '| $(ANSI2KNR) > ' . $base . "_.c\n");
4965             push (@objects, $base . '_'
4966                   . ($seen_objext ? '.$(OBJEXT)' : '.o'));
4967             push (@objects, $base . '_.lo') if $seen_libtool;
4968         }
4970         # Make all _.o (and _.lo) files depend on ansi2knr.
4971         # Use a sneaky little hack to make it print nicely.
4972         &pretty_print_rule ('', '', @objects, ':', '$(ANSI2KNR)');
4973     }
4975     if (! defined $configure_vars{'CC'})
4976     {
4977         # FIXME: line number.
4978         &am_error ("C source seen but \`CC' not defined in \`configure.in'");
4979     }
4982 sub lang_cxx_finish
4984     local ($ltcompile, $ltlink) = &libtool_compiler;
4986     &define_variable ('CXXLD', '$(CXX)');
4987     &define_variable ('CXXLINK', $ltlink . '$(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
4989     if (! defined $configure_vars{'CXX'})
4990     {
4991         &am_error ("C++ source seen but \`CXX' not defined in \`configure.in'");
4992     }
4995 sub lang_header_finish
4997     # Nothing to do.
5000 # This is a helper for both lex and yacc.
5001 sub yacc_lex_finish_helper
5003     return if defined $language_scratch{'lex-yacc-done'};
5004     $language_scratch{'lex-yacc-done'} = 1;
5006     # If there is more than one distinct yacc (resp lex) source file
5007     # in a given directory, then the `ylwrap' program is required to
5008     # allow parallel builds to work correctly.  FIXME: for now, no
5009     # line number.
5010     &require_config_file ($FOREIGN, 'ylwrap');
5011     if ($config_aux_dir ne '.' && $config_aux_dir ne '')
5012     {
5013         &define_variable ('YLWRAP', $config_aux_dir . "/ylwrap");
5014     }
5015     else
5016     {
5017         &define_variable ('YLWRAP', '$(srcdir)/ylwrap');
5018     }
5021 sub lang_yacc_finish
5023     return if defined $language_scratch{'yacc-done'};
5024     $language_scratch{'yacc-done'} = 1;
5026     local ($file, $base, $hname, $cname);
5027     local (%seen_suffix) = ();
5028     local (@yacc_files) = sort keys %yacc_sources;
5029     local ($yacc_count) = scalar (@yacc_files);
5030     foreach $file (@yacc_files)
5031     {
5032         $file =~ /(\..*)$/;
5033         &output_yacc_build_rule ($1, $yacc_count > 1)
5034             if ! defined $seen_suffix{$1};
5035         $seen_suffix{$1} = 1;
5037         $file =~ /^(.*)\.(y|yy|y\+\+|yxx|ypp)$/;
5038         $base = $1;
5039         $hname = 'h';           # Always use `.h' for header file.
5040         ($cname = $2) =~ tr/y/c/;
5042         if ((&variable_defined ('AM_YFLAGS')
5043              && &variable_value ('AM_YFLAGS') =~ /(^|\s)-d(\s|$)/)
5044             || (&variable_defined ('YFLAGS')
5045                 && &variable_value ('YFLAGS') =~ /(^|\s)-d(\s|$)/)) {
5046             # Now generate rule to make the header file.  This should only
5047             # be generated if `yacc -d' specified.
5048             $output_rules .= "${base}.${hname}: ${base}.${cname}\n";
5050             # If the files are built in the build directory, then we want
5051             # to remove them with `make clean'.  If they are in srcdir
5052             # they shouldn't be touched.  However, we can't determine this
5053             # statically, and the GNU rules say that yacc/lex output files
5054             # should be removed by maintainer-clean.  So that's what we
5055             # do.
5056             push (@maintainer_clean_files, "${base}.${hname}");
5058             &push_dist_common ("${base}.${hname}");
5059         }
5060         push (@maintainer_clean_files, "${base}.${cname}");
5061     }
5062     $output_rules .= "\n";
5064     if (! defined $configure_vars{'YACC'})
5065     {
5066         &am_error ("yacc source seen but \`YACC' not defined in \`configure.in'");
5067     }
5068     if (&variable_defined ('YACCFLAGS'))
5069     {
5070         &am_line_error ('YACCFLAGS',
5071                         "\`YACCFLAGS' obsolete; use \`YFLAGS' instead");
5072     }
5074     if ($yacc_count > 1)
5075     {
5076         &yacc_lex_finish_helper;
5077     }
5080 sub lang_yaccxx_finish
5082     &lang_yacc_finish;
5085 sub lang_lex_finish
5087     return if defined $language_scratch{'lex-done'};
5088     $language_scratch{'lex-done'} = 1;
5090     local (%seen_suffix) = ();
5091     local ($file, $cname);
5092     local ($lex_count) = scalar (keys %lex_sources);
5093     foreach $file (sort keys %lex_sources)
5094     {
5095         $file =~ /(\..*)$/;
5096         &output_lex_build_rule ($1, $lex_count > 1)
5097             if (! defined $seen_suffix{$1});
5098         $seen_suffix{$1} = 1;
5100         # If the files are built in the build directory, then we want
5101         # to remove them with `make clean'.  If they are in srcdir
5102         # they shouldn't be touched.  However, we can't determine this
5103         # statically, and the GNU rules say that yacc/lex output files
5104         # should be removed by maintainer-clean.  So that's what we
5105         # do.
5106         $file =~ /^(.*)\.(l|ll|l\+\+|lxx|lpp)$/;
5107         ($cname = $2) =~ tr/l/c/;
5108         push (@maintainer_clean_files, "${1}.${cname}");
5109     }
5111     if (! defined $configure_vars{'LEX'})
5112     {
5113         &am_error ("lex source seen but \`LEX' not defined in \`configure.in'");
5114     }
5115     if (! $seen_decl_yytext)
5116     {
5117         &am_error ("lex source seen but \`AC_DECL_YYTEXT' not in \`configure.in'");
5118     }
5120     if ($lex_count > 1)
5121     {
5122         &yacc_lex_finish_helper;
5123     }
5126 sub lang_lexxx_finish
5128     &lang_lex_finish;
5131 sub lang_asm_finish
5133     # We need the C code for assembly.
5134     &lang_c_finish;
5137 sub lang_f77_finish
5139     # FIXME: this function can be called more than once.  We should
5140     # arrange for it to only do anything the first time through.
5142     local ($ltcompile, $ltlink) = &libtool_compiler;
5144     &define_variable ('F77LD', '$(F77)');
5145     &define_variable ('F77LINK', $ltlink . '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
5147     if (! defined $configure_vars{'F77'})
5148     {
5149         &am_error ("Fortran 77 source seen but \`F77' not defined in \`configure.in'");
5150     }
5153 # Preprocessed Fortran 77
5155 # The current support for preprocessing Fortran 77 just involves passing
5156 # `$(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)' as additional flags
5157 # to the Fortran 77 compiler, since this is how GNU Make does it; see
5158 # the `GNU Make Manual, Edition 0.51 for `make' Version 3.76 Beta'
5159 # (specifically, from info file `(make)Catalogue of Rules').
5161 # A better approach would be to write an Autoconf test
5162 # (i.e. AC_PROG_FPP) for a Fortran 77 preprocessor, because not all
5163 # Fortran 77 compilers know how to do preprocessing.  The Autoconf macro
5164 # AC_PROG_FPP should test the Fortran 77 compiler first for
5165 # preprocessing capabilities, and then fall back on cpp (if cpp were
5166 # available).
5167 sub lang_ppf77_finish
5169     &lang_f77_finish;
5171     # We also handle the case of preprocessing `.F' files into `.f'
5172     # files.
5173     $output_rules .= (".F.f:\n"
5174                       . "\t\$(F77COMPILE) -F \$<\n");
5177 sub lang_ratfor_finish
5179     &lang_f77_finish;
5181     # We also handle the case of preprocessing `.r' files into `.f'
5182     # files.
5183     $output_rules .= (".r.f:\n"
5184                       . "\t\$(RCOMPILE) -F \$<\n");
5187 sub lang_objc_finish
5189     local ($ltcompile, $ltlink) = &libtool_compiler;
5191     &define_variable ('OBJCLD', '$(OBJC)');
5192     &define_variable ('OBJCLINK', $ltlink . '$(OBJCLD) $(AM_OBJCFLAGS) $(OBJCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
5194     if (! defined $configure_vars{'OBJC'})
5195     {
5196         &am_error ("Objective C source seen but \`OBJC' not defined in \`configure.in'");
5197     }
5200 sub lang_java_finish
5202     local ($ltcompile, $ltlink) = &libtool_compiler;
5204     &define_variable ('GCJLD', '$(GCJ)');
5205     &define_variable ('GCJLINK', $ltlink . '$(GCJLD) $(AM_GCJFLAGS) $(GCJFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
5207     if (! defined $configure_vars{'GCJ'})
5208     {
5209         &am_error ("Java source seen but \`GCJ' not defined in \`configure.in'");
5210     }
5213 # A helper which computes a sorted list of all extensions for LANG.
5214 sub lang_extensions
5216     local ($lang) = @_;
5217     local ($key, @r);
5218     foreach $key (sort keys %extension_seen)
5219     {
5220         push (@r, '.' . $key) if $extension_map{$key} eq $lang;
5221     }
5222     return @r;
5225 # A helper which decides whether libtool is needed.  Returns prefix
5226 # for compiler and linker.
5227 sub libtool_compiler
5229     local ($ltcompile, $ltlink) = ('', '');
5230     if ($seen_libtool)
5231     {
5232         &define_configure_variable ("LIBTOOL");
5233         $ltcompile = '$(LIBTOOL) --mode=compile ';
5234         $ltlink = '$(LIBTOOL) --mode=link ';
5235     }
5236     return ($ltcompile, $ltlink);
5239 # Given a hash table of linker names, pick the name that has the most
5240 # precedence.  This is lame, but something has to have global
5241 # knowledge in order to eliminate the conflict.  Add more linkers as
5242 # required.
5243 sub resolve_linker
5245     local (%linkers) = @_;
5247     return 'GCJLINK'
5248         if defined $linkers{'GCJLINK'};
5249     return 'CXXLINK'
5250         if defined $linkers{'CXXLINK'};
5251     return 'F77LINK'
5252         if defined $linkers{'F77LINK'};
5253     return 'OBJCLINK'
5254         if defined $linkers{'OBJCLINK'};
5255     return 'LINK';
5258 # Called to indicate that an extension was used.
5259 sub saw_extension
5261     local ($ext) = @_;
5262     $extension_seen{$ext} = 1;
5265 # Called to ask whether source files have been seen . If HEADERS is 1,
5266 # headers can be included.
5267 sub saw_sources_p
5269     local ($headers) = @_;
5271     if ($headers)
5272     {
5273         $headers = 0;
5274     }
5275     else
5276     {
5277         local (@exts) = &lang_extensions ('header');
5278         $headers = @exts;
5279     }
5281     return scalar keys %extension_seen > $headers;
5284 # Register a single language.  LANGUAGE is the name of the language.
5285 # Each OPTION is either of the form NAME=VALUE, or is a file extension
5286 # (sans `.').
5287 sub register_language
5289     local ($language, @options) = @_;
5291     # Set the defaults.
5292     $language_map{$language . '-ansi-p'} = 0;
5293     $language_map{$language . '-linker'} = '';
5294     $language_map{$language . '-autodep'} = 'no';
5296     local ($iter);
5297     foreach $iter (@options)
5298     {
5299         if ($iter =~ /^(.*)=(.*)$/)
5300         {
5301             $language_map{$language . '-' . $1} = $2;
5302         }
5303         elsif (defined $extension_map{$iter})
5304         {
5305             print STDERR
5306                 "automake: programming error: duplicate extension $iter\n";
5307             exit 1;
5308         }
5309         else
5310         {
5311             $extension_map{$iter} = $language;
5312         }
5313     }
5316 # This function is used to find a path from a user-specified suffix to
5317 # `o' or to some other suffix we recognize internally, eg `cc'.
5318 sub derive_suffix
5320     local ($source_ext) = @_;
5322     # FIXME: hard-coding `o' is a mistake.  Doing something
5323     # intelligent is harder.
5324     while ($extension_map{$source_ext} eq ''
5325            && $source_ext ne 'o'
5326            && defined $suffix_rules{$source_ext})
5327     {
5328         $source_ext = $suffix_rules{$source_ext};
5329     }
5331     return $source_ext;
5335 ################################################################
5337 # Pretty-print something.  HEAD is what should be printed at the
5338 # beginning of the first line, FILL is what should be printed at the
5339 # beginning of every subsequent line.
5340 sub pretty_print_internal
5342     local ($head, $fill, @values) = @_;
5344     local ($column) = length ($head);
5345     local ($result) = $head;
5347     # Fill length is number of characters.  However, each Tab
5348     # character counts for eight.  So we count the number of Tabs and
5349     # multiply by 7.
5350     local ($fill_length) = length ($fill);
5351     $fill_length += 7 * ($fill =~ tr/\t/\t/d);
5353     local ($bol) = ($head eq '');
5354     foreach (@values)
5355     {
5356         # "71" because we also print a space.
5357         if ($column + length ($_) > 71)
5358         {
5359             $result .= " \\\n" . $fill;
5360             $column = $fill_length;
5361             $bol = 1;
5362         }
5364         $result .= ' ' unless ($bol);
5365         $result .= $_;
5366         $column += length ($_) + 1;
5367         $bol = 0;
5368     }
5370     $result .= "\n";
5371     return $result;
5374 # Pretty-print something and append to output_vars.
5375 sub pretty_print
5377     $output_vars .= &pretty_print_internal (@_);
5380 # Pretty-print something and append to output_rules.
5381 sub pretty_print_rule
5383     $output_rules .= &pretty_print_internal (@_);
5387 ################################################################
5389 # See if a target exists.
5390 sub target_defined
5392     local ($target) = @_;
5393     return defined $targets{$target};
5396 # See if two conditionals are the same.
5397 sub conditional_same
5399     local ($cond1, $cond2) = @_;
5401     return (&conditional_true_when ($cond1, $cond2)
5402             && &conditional_true_when ($cond2, $cond1));
5405 # See if a conditional is true.  Both arguments are conditional
5406 # strings.  This returns true if the first conditional is true when
5407 # the second conditional is true.
5408 sub conditional_true_when
5410     local ($cond, $when) = @_;
5412     # Check the easy case first.
5413     if ($cond eq $when)
5414     {
5415         return 1;
5416     }
5418     # Check each component of $cond, which looks @COND1@@COND2@.
5419     foreach $comp (split ('@', $cond))
5420     {
5421         # The way we split will give null strings between each
5422         # condition.
5423         next if ! $comp;
5425         if (index ($when, '@' . $comp . '@') == -1)
5426         {
5427             return 0;
5428         }
5429     }
5431     return 1;
5434 # Check for an ambiguous conditional.  This is called when a variable
5435 # or target is being defined conditionally.  If we already know about
5436 # a definition that is true under the same conditions, then we have an
5437 # ambiguity.
5438 sub check_ambiguous_conditional
5440     local ($var_name, $cond) = @_;
5441     local (@cond_vals) = split (' ', $conditional{$var_name});
5442     while (@cond_vals)
5443     {
5444         local ($vcond) = shift (@cond_vals);
5445         shift (@cond_vals);
5446         if (&conditional_true_when ($vcond, $cond)
5447             || &conditional_true_when ($cond, $vcond))
5448         {
5449             &am_line_error ($var_name,
5450                             "$var_name multiply defined in condition");
5451         }
5452     }
5455 # See if a variable exists.  The first argument is the variable name,
5456 # and the optional second argument is the condition which we should
5457 # check.  If no condition is given, we currently return true if the
5458 # variable is defined under any condition.
5459 sub variable_defined
5461     local ($var, $cond) = @_;
5462     if (defined $targets{$var})
5463     {
5464         &am_line_error ($var, "\`$var' is target; expected variable");
5465         return 0;
5466     }
5467     elsif (defined $contents{$var})
5468     {
5469         if ($cond && $conditional{$var})
5470         {
5471             # We have been asked to check for a particular condition,
5472             # and the variable is defined conditionally.  We need to
5473             # look through the conditions under which the variable is
5474             # defined, and see if any of them match the conditional we
5475             # have been asked to check.
5476             local (@cond_vars) = split (' ', $conditional{$var});
5477             while (@cond_vars)
5478             {
5479                 if (&conditional_same ($cond, shift (@cond_vars)))
5480                 {
5481                     # Even a conditional examination is good enough
5482                     # for us.  FIXME: really should maintain examined
5483                     # status on a per-condition basis.
5484                     $content_seen{$var} = 1;
5485                     return 1;
5486                 }
5487                 shift (@cond_vars);
5488             }
5490             # The variable is not defined for the given condition.
5491             return 0;
5492         }
5494         $content_seen{$var} = 1;
5495         return 1;
5496     }
5497     return 0;
5500 # Mark a variable as examined.
5501 sub examine_variable
5503     local ($var) = @_;
5504     &variable_defined ($var);
5507 # Quote a value in order to put it in $conditional.  We need to quote
5508 # spaces, and we need to handle null strings, so that we can later
5509 # retrieve values by splitting on space.
5510 sub quote_cond_val
5512     local ($val) = @_;
5513     $val =~ tr/ \t\n/\001\003\004/;
5514     $val = "\002" if $val eq '';
5515     return $val;
5518 # Unquote a value in $conditional.
5519 sub unquote_cond_val
5521     local ($val) = @_;
5522     $val =~ tr/\001\003\004/ \t\n/;
5523     $val =~ s/\002//g;
5524     return $val;
5527 # Return the set of conditions for which a variable is defined.
5529 # If the variable is not defined conditionally, and is not defined in
5530 # terms of any variables which are defined conditionally, then this
5531 # returns the empty list.
5533 # If the variable is defined conditionally, but is not defined in
5534 # terms of any variables which are defined conditionally, then this
5535 # returns the list of conditions for which the variable is defined.
5537 # If the variable is defined in terms of any variables which are
5538 # defined conditionally, then this returns a full set of permutations
5539 # of the subvariable conditions.  For example, if the variable is
5540 # defined in terms of a variable which is defined for @COND_TRUE@,
5541 # then this returns both @COND_TRUE@ and @COND_FALSE@.  This is
5542 # because we will need to define the variable under both conditions.
5544 sub variable_conditions
5546     local ($var) = @_;
5547     local (%uniqify);
5548     local (@uniq_list);
5549     local ($cond);
5551     %vars_scanned = ();
5552     foreach $cond (&variable_conditions_sub ($var, '', ()))
5553     {
5554         $uniqify{$cond} = 1;
5555     }
5557     @uniq_list = sort keys %uniqify;
5558     # Note we cannot just do `return sort keys %uniqify', because this
5559     # function is sometimes used in a scalar context.
5560     return @uniq_list;
5563 # A subroutine of variable_conditions.  We only return conditions
5564 # which are true for all the conditions in @PARENT_CONDS.
5565 sub variable_conditions_sub
5567     local ($var, $parent, @parent_conds) = @_;
5568     local (@new_conds) = ();
5570     if (defined $vars_scanned{$var})
5571     {
5572         &am_line_error ($parent, "variable \`$var' recursively defined");
5573         return ();
5574     }
5575     $vars_scanned{$var} = 1;
5577     if (! $conditional{$var})
5578     {
5579         foreach (split (' ', $contents{$var}))
5580         {
5581             # If a comment seen, just leave.
5582             last if /^#/;
5584             # Handle variable substitutions.
5585             if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
5586             {
5587                 push (@new_conds,
5588                       &variable_conditions_sub ($1, $var, @parent_conds));
5589             }
5590         }
5592         # Now we want to return all permutations of the subvariable
5593         # conditions.
5594         local (%allconds, $item);
5595         foreach $item (@new_conds)
5596         {
5597             foreach (split ('@', $item))
5598             {
5599                 next if ! $_;
5600                 s/_(TRUE|FALSE)$//;
5601                 $allconds{$_ . '_TRUE'} = 1;
5602             }
5603         }
5605         # Unset our entry in vars_scanned.  We only care about recursive
5606         # definitions.
5607         delete $vars_scanned{$var};
5609         return &variable_conditions_permutations (sort keys %allconds);
5610     }
5612     local (@this_conds) = ();
5613     local (@condvals) = split (' ', $conditional{$var});
5614     while (@condvals)
5615     {
5616         local ($cond) = shift (@condvals);
5617         local ($val) = &unquote_cond_val (shift (@condvals));
5619         if (@parent_conds)
5620         {
5621             local ($ok) = 1;
5622             local ($parent_cond);
5623             foreach $parent_cond (@parent_conds)
5624             {
5625                 if (! &conditional_true_when ($parent_cond, $cond))
5626                 {
5627                     $ok = 0;
5628                     last;
5629                 }
5630             }
5632             next if ! $ok;
5633         }
5635         push (@this_conds, $cond);
5637         push (@parent_conds, $cond);
5638         local (@subvar_conds) = ();
5639         foreach (split (' ', $val))
5640         {
5641             # If a comment seen, just leave.
5642             last if /^#/;
5644             # Handle variable substitutions.
5645             if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
5646             {
5647                 push (@subvar_conds,
5648                       &variable_conditions_sub ($1, $var, @parent_conds));
5649             }
5650         }
5651         pop (@parent_conds);
5653         # If there are no conditional subvariables, then we want to
5654         # return this condition.  Otherwise, we want to return the
5655         # permutations of the subvariables.
5656         if (! @subvar_conds)
5657         {
5658             push (@new_conds, $cond);
5659         }
5660         else
5661         {
5662             push (@new_conds, &variable_conditions_reduce (@subvar_conds));
5663         }
5664     }
5666     # Unset our entry in vars_scanned.  We only care about recursive
5667     # definitions.
5668     delete $vars_scanned{$var};
5670     return @new_conds
5671         if ! $parent;
5673     # If we are being called on behalf of another variable, we need to
5674     # return all possible permutations of the conditions.  We have
5675     # already handled everything in @this_conds along with their
5676     # subvariables.  We now need to add any permutations that are not
5677     # in @this_conds.
5678     local ($this_cond);
5679     foreach $this_cond (@this_conds)
5680     {
5681         local (@perms) =
5682             &variable_conditions_permutations (split('@', $this_cond));
5683         local ($perm);
5684         foreach $perm (@perms)
5685         {
5686             local ($scan);
5687             local ($ok) = 1;
5688             foreach $scan (@this_conds)
5689             {
5690                 if (&conditional_true_when ($perm, $scan)
5691                     || &conditional_true_when ($scan, $perm))
5692                 {
5693                     $ok = 0;
5694                     last;
5695                 }
5696             }
5697             next if ! $ok;
5699             if (@parent_conds)
5700             {
5701                 local ($ok) = 1;
5702                 local ($parent_cond);
5703                 foreach $parent_cond (@parent_conds)
5704                 {
5705                     if (! &conditional_true_when ($parent_cond, $perm))
5706                     {
5707                         $ok = 0;
5708                         last;
5709                     }
5710                 }
5712                 next if ! $ok;
5713             }
5715             # This permutation was not already handled, and is valid
5716             # for the parents.
5717             push (@new_conds, $perm);
5718         }
5719     }
5721     return @new_conds;
5724 # Subroutine for variable_conditions_sort
5725 sub variable_conditions_cmp
5727     local ($as) = $a;
5728     $as =~ s/[^@]//g;
5729     local ($bs) = $b;
5730     $bs =~ s/[^@]//g;
5731     return (length ($as) <=> length ($bs)
5732             || $a cmp $b);
5735 # Sort a list of conditionals so that only the exclusive ones are
5736 # retained.  For example, if both @COND1_TRUE@@COND2_TRUE@ and
5737 # @COND1_TRUE@ are in the list, discard the latter.
5738 sub variable_conditions_reduce
5740     local (@conds) = @_;
5741     local (@ret) = ();
5742     local ($cond);
5743     foreach $cond (sort variable_conditions_cmp @conds)
5744     {
5745         local ($ok) = 1;
5746         local ($scan);
5747         foreach $scan (@ret)
5748         {
5749             if (&conditional_true_when ($cond, $scan))
5750             {
5751                 $ok = 0;
5752                 last;
5753             }
5754         }
5755         next if ! $ok;
5756         push (@ret, $cond);
5757     }
5759     return @ret;
5762 # Return a list of permutations of a conditional string.
5763 sub variable_conditions_permutations
5765     local (@comps) = @_;
5766     return ()
5767         if ! @comps;
5768     local ($comp) = shift (@comps);
5769     return &variable_conditions_permutations (@comps)
5770         if $comp eq '';
5771     local ($neg) = $comp;
5772     $neg =~ s/TRUE$/TRUEO/;
5773     $neg =~ s/FALSE$/TRUE/;
5774     $neg =~ s/TRUEO$/FALSE/;
5775     local (@ret);
5776     local ($sub);
5777     foreach $sub (&variable_conditions_permutations (@comps))
5778     {
5779         push (@ret, '@' . $comp . '@' . $sub);
5780         push (@ret, '@' . $neg . '@' . $sub);
5781     }
5782     if (! @ret)
5783     {
5784         push (@ret, '@' . $comp . '@');
5785         push (@ret, '@' . $neg . '@');
5786     }
5787     return @ret;
5790 # Warn if a variable is conditionally defined.  This is called if we
5791 # are using the value of a variable.
5792 sub variable_conditionally_defined
5794     local ($var, $parent) = @_;
5795     if ($conditional{$var})
5796     {
5797         if ($parent)
5798         {
5799             &am_line_error ($parent,
5800                             "warning: automake does not support conditional definition of $var in $parent");
5801         }
5802         else
5803         {
5804             &am_line_error ($parent,
5805                             "warning: automake does not support $var being defined conditionally")
5806         }
5807     }
5810 # Get the value of a variable.  This just returns $contents, but warns
5811 # if the variable is conditionally defined.
5812 sub variable_value
5814     local ($var) = @_;
5815     &variable_conditionally_defined ($var);
5816     return $contents{$var};
5819 # Convert a variable value to a list, split as whitespace.  This will
5820 # recursively follow $(...) and ${...} inclusions.  It preserves @...@
5821 # substitutions.  If COND is 'all', then all values under all
5822 # conditions should be returned; if COND is a particular condition
5823 # (all conditions are surrounded by @...@) then only the value for
5824 # that condition should be returned; otherwise, warn if VAR is
5825 # conditionally defined.  SCANNED is a global hash listing whose keys
5826 # are all the variables already scanned; it is an error to rescan a
5827 # variable.
5828 sub value_to_list
5830     local ($var, $val, $cond) = @_;
5831     local (@result);
5833     # Strip backslashes
5834     $val =~ s/\\(\n|$)/ /g;
5836     foreach (split (' ', $val))
5837     {
5838         # If a comment seen, just leave.
5839         last if /^#/;
5841         # Handle variable substitutions.
5842         if (/^\$\{([^}]*)\}$/ || /^\$\(([^)]*)\)$/)
5843         {
5844             local ($varname) = $1;
5846             # If the user uses a losing variable name, just ignore it.
5847             # This isn't ideal, but people have requested it.
5848             next if ($varname =~ /\@.*\@/);
5850             local ($from, $to);
5851             local (@temp_list);
5852             if ($varname =~ /^([^:]*):([^=]*)=(.*)$/)
5853             {
5854                 $varname = $1;
5855                 $to = $3;
5856                 ($from = $2) =~ s/(\W)/\\$1/g;
5857             }
5859             # Find the value.
5860             @temp_list = &variable_value_as_list_worker ($1, $cond, $var);
5862             # Now rewrite the value if appropriate.
5863             if ($from)
5864             {
5865                 grep (s/$from$/$to/, @temp_list);
5866             }
5868             push (@result, @temp_list);
5869         }
5870         else
5871         {
5872             push (@result, $_);
5873         }
5874     }
5876     return @result;
5879 # Return contents of variable as list, split as whitespace.  This will
5880 # recursively follow $(...) and ${...} inclusions.  It preserves @...@
5881 # substitutions.  If COND is 'all', then all values under all
5882 # conditions should be returned; if COND is a particular condition
5883 # (all conditions are surrounded by @...@) then only the value for
5884 # that condition should be returned; otherwise, warn if VAR is
5885 # conditionally defined.  If PARENT is specified, it is the name of
5886 # the including variable; this is only used for error reports.
5887 sub variable_value_as_list_worker
5889     local ($var, $cond, $parent) = @_;
5890     local (@result);
5892     if (defined $targets{$var})
5893     {
5894         &am_line_error ($var, "\`$var' is target; expected variable");
5895     }
5896     elsif (! defined $contents{$var})
5897     {
5898         &am_line_error ($parent, "variable \`$var' not defined");
5899     }
5900     elsif (defined $vars_scanned{$var})
5901     {
5902         # `vars_scanned' is a global we use to keep track of which
5903         # variables we've already examined.
5904         &am_line_error ($parent, "variable \`$var' recursively defined");
5905     }
5906     elsif ($cond eq 'all' && $conditional{$var})
5907     {
5908         $vars_scanned{$var} = 1;
5909         local (@condvals) = split (' ', $conditional{$var});
5910         while (@condvals)
5911         {
5912             shift (@condvals);
5913             local ($val) = &unquote_cond_val (shift (@condvals));
5914             push (@result, &value_to_list ($var, $val, $cond));
5915         }
5916     }
5917     elsif ($cond && $conditional{$var})
5918     {
5919         $vars_scanned{$var} = 1;
5920         local (@condvals) = split (' ', $conditional{$var});
5921         local ($onceflag);
5922         while (@condvals)
5923         {
5924             local ($vcond) = shift (@condvals);
5925             local ($val) = &unquote_cond_val (shift (@condvals));
5926             if (&conditional_true_when ($vcond, $cond))
5927             {
5928                 # Warn if we have an ambiguity.  It's hard to know how
5929                 # to handle this case correctly.
5930                 &variable_conditionally_defined ($var, $parent)
5931                     if $onceflag;
5932                 $onceflag = 1;
5933                 push (@result, &value_to_list ($var, $val, $cond));
5934             }
5935         }
5936     }
5937     else
5938     {
5939         $vars_scanned{$var} = 1;
5940         &variable_conditionally_defined ($var, $parent);
5941         $content_seen{$var} = 1;
5942         push (@result, &value_to_list ($var, $contents{$var}, $cond));
5943     }
5945     # Unset our entry in vars_scanned.  We only care about recursive
5946     # definitions.
5947     delete $vars_scanned{$var};
5949     return @result;
5952 # This is just a wrapper for variable_value_as_list_worker that
5953 # initializes the global hash `vars_scanned'.  This hash is used to
5954 # avoid infinite recursion.
5955 sub variable_value_as_list
5957     local ($var, $cond, $parent) = @_;
5958     %vars_scanned = ();
5959     return &variable_value_as_list_worker ($var, $cond, $parent);
5962 # Define a new variable, but only if not already defined.
5963 sub define_variable
5965     local ($var, $value) = @_;
5967     if (! defined $contents{$var})
5968     {
5969         $output_vars .= $var . ' = ' . $value . "\n";
5970         $contents{$var} = $value;
5971         $content_seen{$var} = 1;
5972     }
5973     elsif ($var_was_plus_eq{$var})
5974     {
5975         &am_line_error ($var, "internally generated variable \`$var' was set with \`+='");
5976     }
5979 # Like define_variable, but the value is a list, and the variable may
5980 # be defined conditionally.  The second argument is the conditional
5981 # under which the value should be defined; this should be the empty
5982 # string to define the variable unconditionally.  The third argument
5983 # is a list holding the values to use for the variable.  The value is
5984 # pretty printed in the output file.
5985 sub define_pretty_variable
5987     local ($var, $cond, @value) = @_;
5988     if (! defined $contents{$var}
5989         || ($cond && ! &variable_defined ($var, $cond)))
5990     {
5991         $contents{$var} = join (' ', @value);
5992         if ($cond)
5993         {
5994             if ($conditional{$var})
5995             {
5996                 $conditional{$var} .= ' ';
5997             }
5998             else
5999             {
6000                 $conditional{$var} = '';
6001             }
6002             $conditional{$var} .= ($cond
6003                                    . ' '
6004                                    . &quote_cond_val ($contents{$var}));
6005         }
6006         &pretty_print ($cond . $var . ' = ', $cond, @value);
6007         $content_seen{$var} = 1;
6008     }
6011 # Like define_variable, but define a variable to be the configure
6012 # substitution by the same name.
6013 sub define_configure_variable
6015     local ($var) = @_;
6016     local ($value) = '@' . $var . '@';
6017     &define_variable ($var, $value);
6020 # Define a compiler variable.  We also handle defining the `LT'
6021 # version of the command when using libtool.
6022 sub define_compiler_variable
6024     local ($var, $ltcompile, $value) = @_;
6025     local ($name) = $var;
6026     &define_variable ($name, $value);
6027     &define_variable ('LT' . $name, $ltcompile . $value)
6028         if $seen_libtool;
6031 # Define a variable that represents a program to run.  If in Cygnus
6032 # mode, the program is searched for in the build (or source) tree.
6033 # Otherwise no searching is done at all.  Arguments are:
6034 # * VAR      Name of variable to define
6035 # * WHATDIR  Either `src' or `build', depending on where program should
6036 #            be found.  (runtest is in srcdir!)
6037 # * SUBDIR   Subdir of top-level dir
6038 # * PROGRAM  Name of program
6039 # * OVERRIDE If specified, the name of the program to use when not in
6040 #            Cygnus mode.  Defaults to PROGRAM.
6041 sub define_program_variable
6043     local ($var, $whatdir, $subdir, $program, $override) = @_;
6045     if (! $override)
6046     {
6047         $override = $program;
6048     }
6050     if ($cygnus_mode)
6051     {
6052         local ($full) = ('$(top_' . $whatdir . 'dir)/../'
6053                          . $subdir . '/' . $program);
6054         &define_variable ($var, ('`if test -f ' . $full
6055                                  . '; then echo ' . $full . '; else echo '
6056                                  . $program . '; fi`'));
6057     }
6058     else
6059     {
6060         &define_variable ($var, $override);
6061     }
6065 ################################################################
6067 # Read Makefile.am and set up %contents.  Simultaneously copy lines
6068 # from Makefile.am into $output_trailer or $output_vars as
6069 # appropriate.  NOTE we put rules in the trailer section.  We want
6070 # user rules to come after our generated stuff.
6071 sub read_am_file
6073     local ($amfile) = @_;
6074     local (*AM_FILE);
6076     open (AM_FILE, $amfile) || die "automake: couldn't open \`$amfile': $!\n";
6077     print "automake: reading $amfile\n" if $verbose;
6079     local ($saw_bk) = 0;
6080     local ($was_rule) = 0;
6081     local ($spacing) = '';
6082     local ($comment) = '';
6083     local ($last_var_name) = '';
6084     local ($blank) = 0;
6086     # We save the conditional stack on entry, and then check to make
6087     # sure it is the same on exit.  This lets us conditonally include
6088     # other files.
6089     local (@saved_cond_stack) = @conditional_stack;
6091     while (<AM_FILE>)
6092     {
6093         if (/$IGNORE_PATTERN/o)
6094         {
6095             # Merely delete comments beginning with two hashes.
6096         }
6097         elsif (/$WHITE_PATTERN/o)
6098         {
6099             # Stick a single white line before the incoming macro or rule.
6100             $spacing = "\n";
6101             $blank = 1;
6102         }
6103         elsif (/$COMMENT_PATTERN/o)
6104         {
6105             # Stick comments before the incoming macro or rule.  Make
6106             # sure a blank line preceeds first block of comments.
6107             $spacing = "\n" unless $blank;
6108             $blank = 1;
6109             $comment .= $spacing . $_;
6110             $spacing = '';
6111         }
6112         else
6113         {
6114             last;
6115         }
6116     }
6118     $output_vars .= $comment . "\n";
6119     $comment = '';
6120     $spacing = "\n";
6122     local ($is_ok_macro);
6123     while ($_)
6124     {
6125         $_ .= "\n"
6126             unless substr ($_, -1, 1) eq "\n";
6128         # Don't look at MAINTAINER_MODE_TRUE here.  That shouldn't be
6129         # used by users.  @MAINT@ is an anachronism now.
6130         $_ =~ s/\@MAINT\@//g
6131             unless $seen_maint_mode;
6133         if (/$IGNORE_PATTERN/o)
6134         {
6135             # Merely delete comments beginning with two hashes.
6136         }
6137         elsif (/$WHITE_PATTERN/o)
6138         {
6139             # Stick a single white line before the incoming macro or rule.
6140             $spacing = "\n";
6141             &am_line_error ($., "blank line following trailing backslash")
6142                 if $saw_bk;
6143         }
6144         elsif (/$COMMENT_PATTERN/o)
6145         {
6146             # Stick comments before the incoming macro or rule.
6147             $comment .= $spacing . $_;
6148             $spacing = '';
6149             &am_line_error ($., "comment following trailing backslash")
6150                 if $saw_bk;
6151         }
6152         elsif ($saw_bk)
6153         {
6154             if ($was_rule)
6155             {
6156                 $output_trailer .= join ('', @conditional_stack) . $_;
6157                 $saw_bk = /\\$/;
6158             }
6159             else
6160             {
6161                 $saw_bk = /\\$/;
6162                 $contents{$last_var_name} .= ' '
6163                     unless $contents{$last_var_name} =~ /\s$/;
6164                 $contents{$last_var_name} .= $_;
6165                 if (@conditional_stack)
6166                 {
6167                     $conditional{$last_var_name} .= &quote_cond_val ($_);
6168                 }
6169             }
6170         }
6171         elsif (/$IF_PATTERN/o)
6172         {
6173             &am_line_error ($., "$1 does not appear in AM_CONDITIONAL")
6174                 if (! $configure_cond{$1});
6175             push (@conditional_stack, "\@" . $1 . "_TRUE\@");
6176         }
6177         elsif (/$ELSE_PATTERN/o)
6178         {
6179             if (! @conditional_stack)
6180             {
6181                 &am_line_error ($., "else without if");
6182             }
6183             elsif ($conditional_stack[$#conditional_stack] =~ /_FALSE\@$/)
6184             {
6185                 &am_line_error ($., "else after else");
6186             }
6187             else
6188             {
6189                 $conditional_stack[$#conditional_stack]
6190                     =~ s/_TRUE\@$/_FALSE\@/;
6191             }
6192         }
6193         elsif (/$ENDIF_PATTERN/o)
6194         {
6195             if (! @conditional_stack)
6196             {
6197                 &am_line_error ($., "endif without if");
6198             }
6199             else
6200             {
6201                 pop @conditional_stack;
6202             }
6203         }
6204         elsif (/$RULE_PATTERN/o)
6205         {
6206             # Found a rule.
6207             $was_rule = 1;
6208             if (defined $contents{$1}
6209                 && (@conditional_stack
6210                     ? ! defined $conditional{$1}
6211                     : defined $conditional{$1}))
6212             {
6213                 &am_line_error ($1,
6214                                 "$1 defined both conditionally and unconditionally");
6215             }
6216             # Value here doesn't matter; for targets we only note
6217             # existence.
6218             $contents{$1} = 1;
6219             $targets{$1} = 1;
6220             local ($cond_string) = join ('', @conditional_stack);
6221             if (@conditional_stack)
6222             {
6223                 if ($conditional{$1})
6224                 {
6225                     &check_ambiguous_conditional ($1, $cond_string);
6226                     $conditional{$1} .= ' ';
6227                 }
6228                 else
6229                 {
6230                     $conditional{$1} = '';
6231                 }
6232                 $conditional{$1} .= $cond_string . ' 1';
6233             }
6234             $content_lines{$1} = $.;
6235             $output_trailer .= $comment . $spacing . $cond_string . $_;
6236             $comment = $spacing = '';
6237             $saw_bk = /\\$/;
6239             # Check the rule for being a suffix rule. If so, store in
6240             # a hash.
6242             local ($source_suffix);
6243             local ($object_suffix);
6245             if (($source_suffix, $object_suffix) = ($1 =~ $SUFFIX_RULE_PATTERN))
6246             {
6247               $suffix_rules{$source_suffix} = $object_suffix;
6248               print "Sources ending in .$source_suffix become .$object_suffix\n" if $verbose;
6249               $source_suffix_pattern = "(" . join ('|', keys %suffix_rules) . ")";
6250             }
6252             # FIXME: make sure both suffixes are in SUFFIXES? Or set
6253             # SUFFIXES from suffix_rules?
6254         }
6255         elsif (($is_ok_macro = /$MACRO_PATTERN/o)
6256                || /$BOGUS_MACRO_PATTERN/o)
6257         {
6258             # Found a macro definition.
6259             $was_rule = 0;
6260             $last_var_name = $1;
6261             if (defined $contents{$1}
6262                 && (@conditional_stack
6263                     ? ! defined $conditional{$1}
6264                     : defined $conditional{$1}))
6265             {
6266                 &am_line_error ($1,
6267                                 "$1 defined both conditionally and unconditionally");
6268             }
6269             local ($value);
6270             if ($3 ne '' && substr ($3, -1) eq "\\")
6271             {
6272                 # We preserve the `\' because otherwise the long lines
6273                 # that are generated will be truncated by broken
6274                 # `sed's.
6275                 $value = $3 . "\n";
6276             }
6277             else
6278             {
6279                 $value = $3;
6280             }
6281             local ($type) = $2;
6283             if (! defined $contents{$last_var_name})
6284             {
6285                 # The first assignment to a macro sets the line
6286                 # number.  Ideally I suppose we would associate line
6287                 # numbers with random bits of text.
6288                 $content_lines{$last_var_name} = $.;
6290                 # If first assignment, set `+=' indicator.
6291                 $var_was_plus_eq{$last_var_name} =
6292                     ($type eq '+'
6293                      && ! defined $am_var_defs{$last_var_name});
6294             }
6296             if ($type eq '+')
6297             {
6298                 if (! defined $contents{$last_var_name}
6299                     && defined $am_var_defs{$last_var_name})
6300                 {
6301                     $contents{$last_var_name} = $am_var_defs{$last_var_name};
6302                 }
6303                 if (substr ($contents{$last_var_name}, -1) eq "\n")
6304                 {
6305                     # Insert a backslash before a trailing newline.
6306                     $contents{$last_var_name}
6307                         = substr ($contents{$last_var_name}, 0, -1) . "\\\n";
6308                 }
6309                 $contents{$last_var_name} .= ' ' . $value;
6310             }
6311             else
6312             {
6313                 $contents{$last_var_name} = $value;
6314             }
6315             local ($cond_string) = join ('', @conditional_stack);
6316             if (@conditional_stack)
6317             {
6318                 local ($found) = 0;
6319                 local ($val);
6320                 if ($conditional{$last_var_name})
6321                 {
6322                     if ($type eq '+')
6323                     {
6324                         # If we're adding to the conditional, and it
6325                         # exists, then we might want to simply replace
6326                         # the old value with the new one.
6327                         local (@new_vals, @cond_vals);
6328                         @cond_vals = split (' ', $conditional{$last_var_name});
6329                         while (@cond_vals)
6330                         {
6331                             local ($vcond) = shift (@cond_vals);
6332                             push (@new_vals, $vcond);
6333                             if (&conditional_same ($vcond, $cond_string))
6334                             {
6335                                 $found = 1;
6336                                 $val = (&unquote_cond_val (shift (@cond_vals))
6337                                         . ' ' . $value);
6338                                 push (@new_vals, &quote_cond_val ($val));
6339                             }
6340                             else
6341                             {
6342                                 push (@new_vals, shift (@cond_vals));
6343                             }
6344                         }
6345                         if ($found)
6346                         {
6347                             $conditional{$last_var_name}
6348                                 = join (' ', @new_vals);
6349                         }
6350                     }
6352                     if (! $found)
6353                     {
6354                         &check_ambiguous_conditional ($last_var_name,
6355                                                       $cond_string);
6356                         $conditional{$last_var_name} .= ' ';
6357                         $val = $value;
6358                     }
6359                 }
6360                 else
6361                 {
6362                     $conditional{$last_var_name} = '';
6363                     $val = $contents{$last_var_name};
6364                 }
6365                 if (! $found)
6366                 {
6367                     $conditional{$last_var_name} .= ($cond_string
6368                                                      . ' '
6369                                                      . &quote_cond_val ($val));
6370                 }
6371             }
6373             # FIXME: this doesn't always work correctly; it will group
6374             # all comments for a given variable, no matter where
6375             # defined.
6376             $am_vars{$last_var_name} = $comment . $spacing;
6377             $def_type{$last_var_name} = ($type eq ':') ? ':' : '';
6378             push (@var_list, $last_var_name);
6379             $comment = $spacing = '';
6380             $saw_bk = /\\$/;
6382             # Error if bogus.
6383             &am_line_error ($., "bad macro name \`$last_var_name'")
6384                 if ! $is_ok_macro;
6385         }
6386         elsif (/$INCLUDE_PATTERN/o)
6387         {
6388             local ($path) = $1;
6390             if ($path =~ s/^\$\(top_srcdir\)\///)
6391             {
6392                 push (@include_stack, "\$\(top_srcdir\)/$path");
6393             }
6394             else
6395             {
6396                 $path =~ s/\$\(srcdir\)\///;
6397                 push (@include_stack, "\$\(srcdir\)/$path");
6398                 $path = $relative_dir . "/" . $path;
6399             }
6400             &read_am_file ($path);
6401         }
6402         else
6403         {
6404             # This isn't an error; it is probably a continued rule.
6405             # In fact, this is what we assume.
6406             $was_rule = 1;
6407             $output_trailer .= ($comment . $spacing
6408                                 . join ('', @conditional_stack) . $_);
6409             $comment = $spacing = '';
6410             $saw_bk = /\\$/;
6411         }
6413         $_ = <AM_FILE>;
6414     }
6416     $output_trailer .= $comment;
6418     if (join (' ', @saved_cond_stack) ne join (' ', @conditional_stack))
6419     {
6420         if (@conditional_stack)
6421         {
6422             &am_error ("unterminated conditionals: " . join (' ', @conditional_stack));
6423         }
6424         else
6425         {
6426             # FIXME: better error message here.
6427             &am_error ("conditionals not nested in include file");
6428         }
6429     }
6432 # A helper for read_main_am_file which initializes configure variables
6433 # and variables from header-vars.am.  This is a subr so we can call it
6434 # twice.
6435 sub define_standard_variables
6437     # Compute relative location of the top object directory.
6438     local (@topdir) = ();
6439     foreach (split (/\//, $relative_dir))
6440     {
6441         next if $_ eq '.' || $_ eq '';
6442         if ($_ eq '..')
6443         {
6444             pop @topdir;
6445         }
6446         else
6447         {
6448             push (@topdir, '..');
6449         }
6450     }
6451     @topdir = ('.') if ! @topdir;
6453     $top_builddir = join ('/', @topdir);
6454     local ($build_rx);
6455     ($build_rx = $top_builddir) =~ s/(\W)/\\$1/g;
6456     $output_vars .= &file_contents_with_transform
6457                         ('s/\@top_builddir\@/' . $build_rx . '/g;',
6458                          'header-vars');
6460     # Generate some useful variables when AC_CANONICAL_* used.  FIXME:
6461     # this should use generic %configure_vars method.
6462     if ($seen_canonical)
6463     {
6464         local ($curs, %vars);
6465         $vars{'host_alias'} = 'host_alias';
6466         $vars{'host_triplet'} = 'host';
6467         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
6468         {
6469             $vars{'build_alias'} = 'build_alias';
6470             $vars{'build_triplet'} = 'build';
6471             $vars{'target_alias'} = 'target_alias';
6472             $vars{'target_triplet'} = 'target';
6473         }
6474         foreach $curs (sort keys %vars)
6475         {
6476             $output_vars .= "$curs = \@$vars{$curs}\@\n";
6477             $contents{$curs} = "\@$vars{$curs}\@";
6478         }
6479     }
6481     local ($curs);
6482     foreach $curs (sort keys %configure_vars)
6483     {
6484         &define_configure_variable ($curs);
6485     }
6488 # Read main am file.
6489 sub read_main_am_file
6491     local ($amfile) = @_;
6493     # The keys here are variables we want to dump at the end of this
6494     # function.  The values are corresponding comments.
6495     local (%am_vars) = ();
6496     local (@var_list) = ();
6497     local (%def_type) = ();
6499     # This supports the strange variable tricks we are about to play.
6500     if (scalar keys %contents > 0)
6501     {
6502         print STDERR "automake: programming error: variable defined before read_main_am_file\n";
6503         exit 1;
6504     }
6506     # We want to predefine as many variables as possible.  This lets
6507     # the user set them with `+=' in Makefile.am.  However, we don't
6508     # want these initial definitions to end up in the output quite
6509     # yet.  So we adopt a hack: read the `.am' file twice, throwing
6510     # away the output the first time.  We also squirrel away a list of
6511     # all the variables defined by the .am file so that we know which
6512     # ones to remove from the content list.
6514     # First pass.
6515     &define_standard_variables;
6516     local (%saved_contents) = %contents;
6518     # Read user file, but discard text of variable assignments we just
6519     # made.
6520     $output_vars = '';
6521     &read_am_file ($amfile);
6523     # Now dump the variables that were defined.  We do it in the same
6524     # order in which they were defined (skipping duplicates).
6525     local (%done);
6526     foreach $curs (@var_list)
6527     {
6528         next if $done{$curs};
6529         $done{$curs} = 1;
6531         $output_vars .= $am_vars{$curs};
6532         if ($conditional{$curs})
6533         {
6534             local (@cond_vals) = split (' ', $conditional{$curs});
6535             while (@cond_vals)
6536             {
6537                 local ($vcond) = shift (@cond_vals);
6538                 local ($val) = &unquote_cond_val (shift (@cond_vals));
6539                 $output_vars .= ($vcond . $curs . ' '
6540                                  . $def_type{$curs} . "= ");
6541                 local ($line);
6542                 foreach $line (split ("\n", $val))
6543                 {
6544                     $output_vars .= $vcond . $line . "\n";
6545                 }
6546                 $output_vars .= "\n"
6547                     if $val eq '';
6548             }
6549         }
6550         else
6551         {
6552             $output_vars .= ($curs . ' ' . $def_type{$curs} . '= '
6553                              . $contents{$curs} . "\n");
6554         }
6555     }
6557     # Generate copyright header for generated Makefile.in.
6558     local ($ov) = $output_vars;
6559     $output_vars = ("# $in_file_name generated automatically by automake "
6560                    . $VERSION . " from $am_file_name\n");
6561     $output_vars .= $gen_copyright;
6563     # Now go through and delete all the variables that the user did
6564     # not change.
6565     local ($var);
6566     foreach $var (keys %saved_contents)
6567     {
6568         if ($contents{$var} eq $saved_contents{$var})
6569         {
6570             delete $contents{$var};
6571         }
6572     }
6574     # Re-read the standard variables, and this time keep their
6575     # contributions to the output.  Then add the user's output to the
6576     # end.
6577     &define_standard_variables;
6578     $output_vars .= $ov;
6582 ################################################################
6584 sub initialize_global_constants
6586     # Values for AC_CANONICAL_*
6587     $AC_CANONICAL_HOST = 1;
6588     $AC_CANONICAL_SYSTEM = 2;
6590     # Associative array of standard directory names.  Entry is TRUE if
6591     # corresponding directory should be installed during
6592     # 'install-exec' phase.
6593     %exec_dir_p =
6594         ('bin', 1,
6595          'sbin', 1,
6596          'libexec', 1,
6597          'data', 0,
6598          'sysconf', 1,
6599          'localstate', 1,
6600          'lib', 1,
6601          'info', 0,
6602          'man', 0,
6603          'include', 0,
6604          'oldinclude', 0,
6605          'pkgdata', 0,
6606          'pkglib', 1,
6607          'pkginclude', 0
6608          );
6610     # Commonly found files we look for and automatically include in
6611     # DISTFILES.
6612     @common_files =
6613         (
6614          "README", "THANKS", "TODO", "NEWS", "COPYING", "COPYING.LIB",
6615          "INSTALL", "ABOUT-NLS", "ChangeLog", "configure", "configure.in",
6616          "config.guess", "config.sub", "AUTHORS", "BACKLOG", "ABOUT-GNU",
6617          "libversion.in", "mdate-sh", "mkinstalldirs", "install-sh",
6618          'texinfo.tex', "ansi2knr.c", "ansi2knr.1", 'elisp-comp',
6619          'ylwrap', 'acinclude.m4', @libtoolize_files,
6620          'missing', 'depcomp', 'compile', 'py-compile'
6621          );
6623     # Commonly used files we auto-include, but only sometimes.
6624     @common_sometimes =
6625         (
6626          "aclocal.m4", "acconfig.h", "config.h.top",
6627          "config.h.bot", "stamp-h.in", 'stamp-vti'
6628          );
6630     $USAGE = "\
6631   -a, --add-missing     add missing standard files to package
6632   --amdir=DIR           directory storing config files
6633   -c, --copy            with -a, copy missing files (default is symlink)
6634   --cygnus              assume program is part of Cygnus-style tree
6635   --force-missing       force update of standard files
6636   --foreign             set strictness to foreign
6637   --gnits               set strictness to gnits
6638   --gnu                 set strictness to gnu
6639   --help                print this help, then exit
6640   -i, --ignore-deps     disable dependency tracking code
6641   --include-deps        enable dependency tracking code
6642   --no-force            only update Makefile.in's that are out of date
6643   -o DIR, --output-dir=DIR
6644                         put generated Makefile.in's into DIR
6645   -v, --verbose         verbosely list files processed
6646   --version             print version number, then exit\n";
6648     # Copyright on generated Makefile.ins.
6649     $gen_copyright = "\
6650 # Copyright (C) 1994, 1995-9, 2000 Free Software Foundation, Inc.
6651 # This Makefile.in is free software; the Free Software Foundation
6652 # gives unlimited permission to copy and/or distribute it,
6653 # with or without modifications, as long as this notice is preserved.
6655 # This program is distributed in the hope that it will be useful,
6656 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
6657 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
6658 # PARTICULAR PURPOSE.
6661     # This complex find command will try to avoid changing the modes of
6662     # links into the source tree, in case they're hard-linked.  It will
6663     # also make directories writable by everybody, because some
6664     # brain-dead tar implementations change ownership and permissions of
6665     # a directory before extracting the files, thus becoming unable to
6666     # extract them.
6667     # Ignore return result from chmod, because it might give an error
6668     # if we chmod a symlink.
6669     # Another nastiness: if the file is unreadable by us, we make it
6670     # readable regardless of the number of links to it.  This only
6671     # happens in perverse cases.
6672     # We use $(install_sh) because that is a known-portable way to
6673     # modify the file in place in the source tree.
6674     $dist_header = '    -find $(distdir) -type d ! -perm -777 -exec chmod a+rwx {} \; -o \\
6675           ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \\
6676           ! -type d ! -perm -400 -exec chmod a+r {} \; -o \\
6677           ! -type d ! -perm -444 -exec $(SHELL) $(install_sh) -c -m a+r {} {} \; \\
6678         || chmod -R a+r $(distdir)
6680     $dist{'dist-bzip2'} = ("\t"
6681                            . '$(AMTAR) chof - $(distdir) | bzip2 -9 -c > $(distdir).bz2'
6682                            . "\n");
6683     $dist{'dist-tarZ'} = ("\t"
6684                      . '$(AMTAR) chof - $(distdir) | compress -c > $(distdir).tar.Z'
6685                      . "\n");
6686     $dist{'dist-shar'} = ("\t"
6687                      . 'shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c > $(distdir).shar.gz'
6688                      . "\n");
6689     $dist{'dist-zip'} = ("\t" . '-rm -f $(distdir).zip' . "\n" .
6690                          "\t" . 'zip -rq $(distdir).zip $(distdir)' . "\n");
6692     # Note that we don't use GNU tar's `-z' option.  One reason (but
6693     # not the only reason) is that some versions of tar (e.g., OSF1)
6694     # interpret `-z' differently.
6695     $dist{'dist'} = ("\t"
6696                      .  '$(AMTAR) chof - $(distdir) | GZIP=$(GZIP_ENV) gzip -c > $(distdir).tar.gz'
6697                      . "\n");
6698     $dist_trailer = "\t" . '-chmod -R a+w $(distdir) > /dev/null 2>&1; rm -rf $(distdir)' . "\n";
6701 # (Re)-Initialize per-Makefile.am variables.
6702 sub initialize_per_input
6704     # These two variables are used when generating each Makefile.in.
6705     # They hold the Makefile.in until it is ready to be printed.
6706     $output_rules = '';
6707     $output_vars = '';
6708     $output_trailer = '';
6709     $output_all = '';
6710     $output_header = '';
6712     # Suffixes found during a run.
6713     @suffixes = ();
6715     # This holds the contents of a Makefile.am, as parsed by
6716     # read_am_file.
6717     %contents = ();
6719     # This holds the names which are targets.  These also appear in
6720     # %contents.
6721     %targets = ();
6723     # This maps a variable name onto a flag.  The flag is true iff the
6724     # variable was first defined with `+='.
6725     %var_was_plus_eq = ();
6727     # This holds definitions of all variables defined in .am files.
6728     # This is used during startup to determine which variables can be
6729     # assigned with `+='.
6730     %am_var_defs = ();
6732     # For a variable or target which is defined conditionally, this
6733     # holds an array of the conditional values.  The array is composed
6734     # of pairs of condition strings (the variables which configure
6735     # will substitute) and values (the value of a target is
6736     # meaningless).  For an unconditional variable, this is empty.
6737     %conditional = ();
6739     # This holds the line numbers at which various elements of
6740     # %contents are defined.
6741     %content_lines = ();
6743     # This holds a 1 if a particular variable was examined.
6744     %content_seen = ();
6746     # This is the conditional stack.
6747     @conditional_stack = ();
6749     # This holds the set of included files.
6750     @include_stack = ();
6752     # This holds the "relative directory" of the current Makefile.in.
6753     # Eg for src/Makefile.in, this is "src".
6754     $relative_dir = '';
6756     # This holds a list of files that are included in the
6757     # distribution.
6758     %dist_common = ();
6760     # List of dependencies for the obvious targets.
6761     @install_data = ();
6762     @install_exec = ();
6763     @uninstall = ();
6764     @installdirs = ();
6766     @info = ();
6767     @dvi = ();
6768     @all = ();
6769     @check = ();
6770     @check_tests = ();
6771     @installcheck = ();
6772     @clean = ();
6774     @phony = ();
6776     # A list of files deleted by `maintainer-clean'.
6777     @maintainer_clean_files = ();
6779     # These are pretty obvious, too.  They are used to define the
6780     # SOURCES and OBJECTS variables.
6781     @sources = ();
6782     @objects = ();
6783     # Sources which go in the distribution.
6784     @dist_sources = ();
6786     # This hash maps object file names onto their corresponding source
6787     # file names.  This is used to ensure that each object is created
6788     # by a single source file.
6789     %object_map = ();
6791     # This keeps track of the directories for which we've already
6792     # created `.dirstamp' code.
6793     %directory_map = ();
6795     # These variables track inclusion of various compile-related .am
6796     # files.  $included_generic_compile is TRUE if the basic code has
6797     # been included.  $included_knr_compile is TRUE if the ansi2knr
6798     # code has been included.  $included_libtool_compile is TRUE if
6799     # libtool support has been included.
6800     $included_generic_compile = 0;
6801     $included_knr_compile = 0;
6802     $included_libtool_compile = 0;
6804     # TRUE if install targets should work recursively.
6805     $recursive_install = 0;
6807     # All .P files.
6808     %dep_files = ();
6810     # Strictness levels.
6811     $strictness = $default_strictness;
6812     $strictness_name = $default_strictness_name;
6814     # Options from AUTOMAKE_OPTIONS.
6815     %options = ();
6817     # Whether or not dependencies are handled.  Can be further changed
6818     # in handle_options.
6819     $use_dependencies = $cmdline_use_dependencies;
6821     # Per Makefile.am.
6822     $local_maint_charset = $maint_charset;
6824     # All yacc and lex source filenames for this directory.  Use
6825     # filenames instead of raw count so that multiple instances are
6826     # counted correctly (eg one yacc file can appear in multiple
6827     # programs without harm).
6828     %yacc_sources = ();
6829     %lex_sources = ();
6831     # This is a list of all targets to run during "make dist".
6832     @dist_targets = ();
6834     # Keys in this hash are the basenames of files which must depend
6835     # on ansi2knr.
6836     %de_ansi_files = ();
6838     # This maps the source extension of a suffix rule to its
6839     # corresponding output extension.
6840     %suffix_rules = ();
6842     # This is a regular expression which matches all the known source
6843     # suffix.  A source suffix is one that appears in the first
6844     # position of a suffix rule.
6845     $source_suffix_pattern = '';
6847     # This is the name of the recursive `all' target to use.
6848     $all_target = 'all-recursive';
6850     # This keeps track of which extensions we've seen (that we care
6851     # about).
6852     %extension_seen = ();
6854     # This is random scratch space for the language finish functions.
6855     # Don't randomly overwrite it; examine other uses of keys first.
6856     %language_scratch = ();
6858     # We keep track of which objects need special (per-executable)
6859     # handling on a per-language basis.
6860     %lang_specific_files = ();
6862     # This is set when `handle_dist' has finished.  Once this happens,
6863     # we should no longer push on dist_common.
6864     $handle_dist_run = 0;
6868 ################################################################
6870 # Return contents of a file from $am_dir, automatically skipping
6871 # macros or rules which are already known.  Runs command on each line
6872 # as it is read; this command can modify $_.
6873 sub file_contents_with_transform
6875     local ($command, $basename) = @_;
6876     local ($file) = $am_dir . '/' . $basename . '.am';
6878     if ($command ne '' && substr ($command, -1) ne ';')
6879     {
6880         die "automake: programming error in file_contents_with_transform: $command\n";
6881     }
6883     open (FC_FILE, $file)
6884         || die "automake: installation error: cannot open \`$file'\n";
6885     # Looks stupid?
6886     # print "automake: reading $file\n" if $verbose;
6888     local ($was_rule) = 0;
6889     local ($result_vars) = '';
6890     local ($result_rules) = '';
6891     local ($comment) = '';
6892     local ($spacing) = "\n";
6893     local ($skipping) = 0;
6894     local ($had_chars);
6896     while (<FC_FILE>)
6897     {
6898         $_ =~ s/\@MAINTAINER_MODE_TRUE\@//g
6899             unless $seen_maint_mode;
6901         $had_chars = length ($_) && $_ ne "\n";
6902         eval $command;
6903         # If the transform caused all the characters to go away, then
6904         # ignore the line.  Why do this?  Because in Perl 4, a "next"
6905         # inside of an eval doesn't affect a loop outside the eval.
6906         # So we can't pass in a "transform" that uses next.  We used
6907         # to do this.  "Empty" also means consisting of a single
6908         # newline.
6909         next if $had_chars && ($_ eq '' || $_ eq "\n");
6911         if (/$IGNORE_PATTERN/o)
6912         {
6913             # Merely delete comments beginning with two hashes.
6914         }
6915         elsif (/$WHITE_PATTERN/o)
6916         {
6917             # Stick a single white line before the incoming macro or rule.
6918             $spacing = "\n";
6919             &am_line_error ($., "blank line following trailing backslash")
6920                 if $saw_bk;
6921         }
6922         elsif (/$COMMENT_PATTERN/o)
6923         {
6924             # Stick comments before the incoming macro or rule.
6925             $comment .= $spacing . $_;
6926             $spacing = '';
6927             &am_line_error ($., "comment following trailing backslash")
6928                 if $saw_bk;
6929         }
6930         elsif ($saw_bk)
6931         {
6932             if ($was_rule)
6933             {
6934                 $result_rules .= $_ if ! $skipping;
6935             }
6936             else
6937             {
6938                 $result_vars .= $_ if ! $skipping;
6939             }
6940             $saw_bk = /\\$/;
6941         }
6942         elsif (/$RULE_PATTERN/o)
6943         {
6944             # Found a rule.
6945             $was_rule = 1;
6946             $skipping = defined $contents{$1};
6947             $result_rules .= $comment . $spacing . $_ if ! $skipping;
6948             $comment = $spacing = '';
6949             $saw_bk = /\\$/;
6950         }
6951         elsif (/$MACRO_PATTERN/o)
6952         {
6953             # Found a variable reference.
6954             $was_rule = 0;
6955             $skipping = defined $contents{$1};
6956             $result_vars .= $comment . $spacing . $_ if ! $skipping;
6957             $comment = $spacing = '';
6958             $saw_bk = /\\$/;
6959             print STDERR "automake: programming error: .am macro \`$1' with trailing backslash\n"
6960                 if $saw_bk;
6961             $am_var_defs{$1} = $3;
6962         }
6963         else
6964         {
6965             # This isn't an error; it is probably a continued rule.
6966             # In fact, this is what we assume.
6967             $was_rule = 1;
6968             $result_rules .= $comment . $spacing . $_ if ! $skipping;
6969             $comment = $spacing = '';
6970             $saw_bk = /\\$/;
6971         }
6972     }
6974     close (FC_FILE);
6975     return $result_vars . $result_rules . $comment;
6978 # Like file_contents_with_transform, but no transform.
6979 sub file_contents
6981     return &file_contents_with_transform ('', @_);
6984 # Find all variable prefixes that are used for install directories.  A
6985 # prefix `zar' qualifies iff:
6986 # * `zardir' is a variable.
6987 # * `zar_PRIMARY' is a variable.
6988 sub am_primary_prefixes
6990     local ($primary, $can_dist, @prefixes) = @_;
6992     local (%valid, $varname);
6993     grep ($valid{$_} = 0, @prefixes);
6994     $valid{'EXTRA'} = 0;
6995     foreach $varname (keys %contents)
6996     {
6997         if ($varname =~ /^(nobase_)?(dist_|nodist_)?(.*)_$primary$/)
6998         {
6999             if (($2 ne '' && ! $can_dist)
7000                 || (! defined $valid{$3}
7001                     && ! &variable_defined ($3 . 'dir')
7002                     # Note that a configure variable is always
7003                     # legitimate.  It is natural to name such
7004                     # variables after the primary, so we explicitly
7005                     # allow it.
7006                     && ! defined $configure_vars{$varname}))
7007             {
7008                 &am_line_error ($varname, "invalid variable \`$varname'");
7009             }
7010             else
7011             {
7012                 # Ensure all extended prefixes are actually used.
7013                 $valid{$1 . $2 . $3} = 1;
7014             }
7015         }
7016     }
7018     return %valid;
7021 # Handle `where_HOW' variable magic.  Does all lookups, generates
7022 # install code, and possibly generates code to define the primary
7023 # variable.  The first argument is the name of the .am file to munge,
7024 # the second argument is the primary variable (eg HEADERS), and all
7025 # subsequent arguments are possible installation locations.  Returns
7026 # list of all values of all _HOW targets.
7028 # FIXME: this should be rewritten to be cleaner.  It should be broken
7029 # up into multiple functions.
7031 # Usage is: am_install_var (OPTION..., file, HOW, where...)
7032 sub am_install_var
7034     local (@args) = @_;
7036     local ($do_clean) = 0;
7037     local ($do_require) = 1;
7038     local ($can_dist) = 0;
7039     local ($default_dist) = 0;
7041     local ($ltxform);
7042     if (defined $configure_vars{'LIBTOOL'})
7043     {
7044         # Transform '@LIBTOOL ...@' to '$(LIBTOOL) ...'
7045         $ltxform = 's/\@LIBTOOL([^\@]*)\@/\$(LIBTOOL) $1/;';
7046     }
7047     else
7048     {
7049         # Delete '@LIBTOOL ...@'
7050         $ltxform = 's/\@LIBTOOL([^\@]*)\@//;';
7051     }
7053     local ($cygxform);
7054     if (! $seen_exeext)
7055     {
7056         $cygxform = 's/\@EXEEXT\@//g;';
7057     }
7058     else
7059     {
7060         $cygxform = 's/\@EXEEXT\@/\$(EXEEXT)/g;';
7061     }
7063     while (@args)
7064     {
7065         if ($args[0] eq '-clean')
7066         {
7067             $do_clean = 1;
7068         }
7069         elsif ($args[0] eq '-noextra')
7070         {
7071             $do_require = 0;
7072         }
7073         elsif ($args[0] eq '-candist')
7074         {
7075             $can_dist = 1;
7076         }
7077         elsif ($args[0] eq '-defaultdist')
7078         {
7079             $default_dist = 1;
7080             $can_dist = 1;
7081         }
7082         elsif ($args[0] !~ /^-/)
7083         {
7084             last;
7085         }
7086         shift (@args);
7087     }
7089     local ($file, $primary, @prefixes) = @args;
7091     local (@used) = ();
7092     local (@result) = ();
7094     # Now that configure substitutions are allowed in where_HOW
7095     # variables, it is an error to actually define the primary.  We
7096     # allow `JAVA', as it is customarily used to mean the Java
7097     # interpreter.  This is but one of several Java hacks.  Similarly,
7098     # `PYTHON' is customarily used to mean the Python interpreter.
7099     &am_line_error ($primary, "\`$primary' is an anachronism")
7100         if &variable_defined ($primary)
7101             && ($primary ne 'JAVA' && $primary ne 'PYTHON');
7104     # Look for misspellings.  It is an error to have a variable ending
7105     # in a "reserved" suffix whose prefix is unknown, eg
7106     # "bni_PROGRAMS".  However, unusual prefixes are allowed if a
7107     # variable of the same name (with "dir" appended) exists.  For
7108     # instance, if the variable "zardir" is defined, then
7109     # "zar_PROGRAMS" becomes valid.  This is to provide a little extra
7110     # flexibility in those cases which need it.
7111     local (%valid) = &am_primary_prefixes ($primary, $can_dist, @prefixes);
7113     # If a primary includes a configure substitution, then the EXTRA_
7114     # form is required.  Otherwise we can't properly do our job.
7115     local ($require_extra);
7116     local ($warned_about_extra) = 0;
7118     local ($clean_file) = $file . '-clean';
7119     local ($one_name);
7120     local ($X);
7121     local ($nodir_name);
7122     local ($strip_subdir) = 1;
7123     foreach $X (sort keys %valid)
7124     {
7125         $one_name = $X . '_' . $primary;
7126         if (&variable_defined ($one_name))
7127         {
7128             # If subdir prefix should be preserved, do so.
7129             if ($X =~ /^nobase_/)
7130             {
7131                 $strip_subdir = 0;
7132                 $X =~ s/^nobase_//;
7133             }
7135             # If files should be distributed, do so.
7136             if ($can_dist)
7137             {
7138                 if (($default_dist && $one_name !~ /^nodist_/)
7139                     || (! $default_dist && $one_name =~ /^dist_/))
7140                 {
7141                     &push_dist_common ('$(' . $one_name . ')');
7142                 }
7143                 ($nodir_name = $X) =~ s/^(dist|nodist)_//;
7144             }
7145             else
7146             {
7147                 $nodir_name = $X;
7148             }
7150             # Append actual contents of where_PRIMARY variable to
7151             # result.
7152             local ($rcurs);
7153             foreach $rcurs (&variable_value_as_list ($one_name, 'all'))
7154             {
7155                 # Skip configure substitutions.  Possibly bogus.
7156                 if ($rcurs =~ /^\@.*\@$/)
7157                 {
7158                     if ($X eq 'EXTRA')
7159                     {
7160                         if (! $warned_about_extra)
7161                         {
7162                             $warned_about_extra = 1;
7163                             {
7164                                 &am_line_error ($one_name,
7165                                                 "\`$one_name' contains configure substitution, but shouldn't");
7166                             }
7167                         }
7168                     }
7169                     # Check here to make sure variables defined in
7170                     # configure.in do not imply that EXTRA_PRIMARY
7171                     # must be defined.
7172                     elsif (! defined $configure_vars{$one_name})
7173                     {
7174                         $require_extra = $one_name
7175                             if $do_require;
7176                     }
7178                     next;
7179                 }
7181                 push (@result, $rcurs);
7182             }
7184             # "EXTRA" shouldn't be used when generating clean targets,
7185             # all, or install targets.
7186             if ($X eq 'EXTRA')
7187             {
7188                 # We used to warn if EXTRA_FOO was defined uselessly,
7189                 # but this was annoying.
7190                 next;
7191             }
7193             # A blatant hack: we rewrite each _PROGRAMS primary to
7194             # include EXEEXT when in Cygwin32 mode.
7195             if ($seen_exeext && $primary eq 'PROGRAMS')
7196             {
7197                 local (@conds) = &variable_conditions ($one_name);
7198                 local (@one_binlist);
7200                 # FIXME: this definitely loses aesthetically; it
7201                 # redefines $ONE_NAME.  Instead we should arrange for
7202                 # variable definitions to be output later, instead of
7203                 # at scan time.
7205                 if (! @conds)
7206                 {
7207                     @one_binlist = ();
7208                     foreach $rcurs (&variable_value_as_list ($one_name, ''))
7209                     {
7210                         if ($rcurs =~ /\./ || $rcurs =~ /^\@.*\@$/)
7211                         {
7212                             push (@one_binlist, $rcurs);
7213                         }
7214                         else
7215                         {
7216                             push (@one_binlist, $rcurs . '$(EXEEXT)');
7217                         }
7218                     }
7220                     delete $contents{$one_name};
7221                     &define_pretty_variable ($one_name, '', @one_binlist);
7222                 }
7223                 else
7224                 {
7225                     local ($cond);
7226                     local ($condvals) = '';
7227                     foreach $cond (@conds)
7228                     {
7229                         @one_binlist = ();
7230                         local (@condval) = &variable_value_as_list ($one_name,
7231                                                                     $cond);
7232                         foreach $rcurs (@condval)
7233                         {
7234                             if ($rcurs =~ /\./ || $rcurs =~ /^\@.*\@$/)
7235                             {
7236                                 push (@one_binlist, $rcurs);
7237                             }
7238                             else
7239                             {
7240                                 push (@one_binlist, $rcurs . '$(EXEEXT)');
7241                             }
7242                         }
7244                         push (@condvals, $cond);
7245                         push (@condvals, join (' ', @one_binlist));
7246                     }
7248                     delete $contents{$one_name};
7250                     while (@condvals)
7251                     {
7252                         $cond = shift (@condvals);
7253                         local (@val) = split (' ', shift (@condvals));
7254                         &define_pretty_variable ($one_name, $cond, @val);
7255                     }
7256                 }
7257             }
7259             if ($do_clean)
7260             {
7261                 $output_rules .=
7262                     &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go;'
7263                                                    . $cygxform,
7264                                                    $clean_file);
7266                 push (@clean, $X . $primary);
7267                 &push_phony_cleaners ($X . $primary);
7268             }
7270             if ($X eq 'check')
7271             {
7272                 push (@check, '$(' . $one_name . ')');
7273             }
7274             else
7275             {
7276                 push (@used, '$(' . $one_name . ')');
7277             }
7278             if ($X eq 'noinst' || $X eq 'check')
7279             {
7280                 # Objects which don't get installed by default.
7281                 next;
7282             }
7284             local ($subdir_xform);
7285             if ($strip_subdir)
7286             {
7287                 $subdir_xform = 's/^NOBASE.*$//; s/^BASE//;';
7288             }
7289             else
7290             {
7291                 $subdir_xform = 's/^BASE.*$//; s/^NOBASE//;';
7292             }
7294             $output_rules .=
7295                 &file_contents_with_transform ('s/\@DIR\@/' . $X . '/g;'
7296                                                . 's/\@NDIR\@/' . $nodir_name . '/go;'
7297                                                . $ltxform . $cygxform
7298                                                . $subdir_xform,
7299                                                $file);
7301             push (@uninstall, 'uninstall-' . $X . $primary);
7302             push (@phony, 'uninstall-' . $X . $primary);
7303             push (@installdirs, '$(DESTDIR)$(' . $X . 'dir)');
7304             if (defined $exec_dir_p{$X} ? $exec_dir_p{$X} : ($X =~ /exec/))
7305             {
7306                 push (@install_exec, 'install-' . $X . $primary);
7307                 push (@phony, 'install-' . $X . $primary);
7308             }
7309             else
7310             {
7311                 push (@install_data, 'install-' . $X . $primary);
7312                 push (@phony, 'install-' . $X . $primary);
7313             }
7314         }
7315     }
7317     # The JAVA variable is used as the name of the Java interpreter.
7318     # The PYTHON variable is used as the name of the Python interpreter.
7319     if (@used && $primary ne 'JAVA' && $primary ne 'PYTHON')
7320     {
7321         # Define it.
7322         &define_pretty_variable ($primary, '', @used);
7323         $output_vars .= "\n";
7324     }
7326     if ($require_extra && ! &variable_defined ('EXTRA_' . $primary))
7327     {
7328         &am_line_error ($require_extra,
7329                         "\`$require_extra' contains configure substitution, but \`EXTRA_$primary' not defined");
7330     }
7332     # Push here because PRIMARY might be configure time determined.
7333     push (@all, '$(' . $primary . ')')
7334         if @used && $primary ne 'JAVA' && $primary ne 'PYTHON';
7336     # Make the result unique.  This lets the user use conditionals in
7337     # a natural way, but still lets us program lazily -- we don't have
7338     # to worry about handling a particular object more than once.
7339     local (%uniquify) = ();
7340     grep ($uniquify{$_} = 1, @result);
7341     return sort keys %uniquify;
7345 ################################################################
7347 # Each key in this hash is the name of a directory holding a
7348 # Makefile.in.  These variables are local to `is_make_dir'.
7349 %make_dirs = ();
7350 $make_dirs_set = 0;
7352 sub is_make_dir
7354     local ($dir) = @_;
7355     if (! $make_dirs_set)
7356     {
7357         foreach $iter (@configure_input_files)
7358         {
7359             $make_dirs{&dirname ($iter)} = 1;
7360         }
7361         # We also want to notice Makefile.in's.
7362         foreach $iter (@other_input_files)
7363         {
7364             if ($iter =~ /Makefile\.in$/)
7365             {
7366                 $make_dirs{&dirname ($iter)} = 1;
7367             }
7368         }
7369         $make_dirs_set = 1;
7370     }
7371     return defined $make_dirs{$dir};
7374 ################################################################
7376 # This variable is local to the "require file" set of functions.
7377 @require_file_paths = ();
7379 # If a file name appears as a key in this hash, then it has already
7380 # been checked for.  This variable is local to the "require file"
7381 # functions.
7382 %require_file_found = ();
7384 # See if we want to push this file onto dist_common.  This function
7385 # encodes the rules for deciding when to do so.
7386 sub maybe_push_required_file
7388     local ($dir, $file, $fullfile) = @_;
7390     # FIXME: Once again, special-case `.'.
7391     if ($dir eq $relative_dir || $dir eq '.')
7392     {
7393         &push_dist_common ($file);
7394     }
7395     elsif ($relative_dir eq '.' && ! &is_make_dir ($dir))
7396     {
7397         # If we are doing the topmost directory, and the file is in a
7398         # subdir which does not have a Makefile, then we distribute it
7399         # here.
7400         &push_dist_common ($fullfile);
7401     }
7404 # Verify that the file must exist in the current directory.  Usage:
7405 # require_file (isconfigure, line_number, strictness, file) strictness
7406 # is the strictness level at which this file becomes required.  Must
7407 # set require_file_paths before calling this function.
7408 # require_file_paths is set to hold a single directory (the one in
7409 # which the first file was found) before return.
7410 sub require_file_internal
7412     local ($is_configure, $line, $mystrict, @files) = @_;
7413     local ($file, $fullfile);
7414     local ($found_it, $dangling_sym, $errfile, $errdir);
7415     local ($save_dir);
7417     foreach $file (@files)
7418     {
7419         # If we've already looked for it, we're done.
7420         next if defined $require_file_found{$file};
7421         $require_file_found{$file} = 1;
7423         $found_it = 0;
7424         $dangling_sym = 0;
7425         foreach $dir (@require_file_paths)
7426         {
7427             if ($dir eq '.')
7428             {
7429                 $fullfile = $relative_dir . "/" . $file;
7430                 $errdir = $relative_dir unless $errdir;
7431             }
7432             else
7433             {
7434                 $fullfile = $dir . "/" . $file;
7435                 $errdir = $dir unless $errdir;
7436             }
7438             # Use different name for "error filename".  Otherwise on
7439             # an error the bad file will be reported as eg
7440             # `../../install-sh' when using the default
7441             # config_aux_path.
7442             $errfile = $errdir . '/' . $file;
7444             if (-l $fullfile && ! -f readlink ($fullfile))
7445             {
7446                 $dangling_sym = 1;
7447                 last;
7448             }
7449             elsif (-f $fullfile)
7450             {
7451                 $found_it = 1;
7452                 &maybe_push_required_file ($dir, $file, $fullfile);
7453                 $save_dir = $dir;
7454                 last;
7455             }
7456         }
7458         if ($found_it && ! $force_missing)
7459         {
7460             # Prune the path list.
7461             @require_file_paths = $save_dir;
7462         }
7463         else
7464         {
7465             if ($strictness >= $mystrict)
7466             {
7467                 if ($dangling_sym && ($force_missing || $add_missing))
7468                 {
7469                     unlink ($fullfile);
7470                 }
7472                 local ($trailer) = '';
7473                 local ($suppress) = 0;
7475                 # Only install missing files according to our desired
7476                 # strictness level.
7477                 local ($message) = "required file \`$errfile' not found";
7478                 if ($add_missing)
7479                 {
7480                     $suppress = 1;
7482                     # Maybe run libtoolize.
7483                     local @syslist = ('libtoolize', '--automake');
7484                     push @syslist, '--copy'
7485                         if $copy_missing;
7486                     if ($seen_libtool
7487                         && grep ($_ eq $file, @libtoolize_files)
7488                         && system (@syslist))
7489                     {
7490                         $message = "installing \`$errfile'";
7491                         $suppress = 0;
7492                         $trailer = "; cannot run \`libtoolize': $!";
7493                     }
7494                     elsif (-f ($am_dir . '/' . $file))
7495                     {
7496                         # Install the missing file.  Symlink if we
7497                         # can, copy if we must.  Note: delete the file
7498                         # first, in case it is a dangling symlink.
7499                         $message = "installing \`$errfile'";
7500                         # Windows Perl will hang if we try to delete a
7501                         # file that doesn't exist.
7502                         unlink ($errfile) if -f $errfile;
7503                         if ($symlink_exists && ! $copy_missing)
7504                         {
7505                             if (! symlink ($am_dir . '/' . $file, $errfile))
7506                             {
7507                                 $suppress = 0;
7508                                 $trailer = "; error while making link: $!";
7509                             }
7510                         }
7511                         elsif (system ('cp', $am_dir . '/' . $file, $errfile))
7512                         {
7513                             $suppress = 0;
7514                             $trailer = "\n    error while copying";
7515                         }
7516                     }
7518                     &maybe_push_required_file (&dirname ($errfile),
7519                                                $errfile, $errfile);
7520                 }
7522                 local ($save) = $exit_status;
7523                 if ($is_configure)
7524                 {
7525                     # FIXME: allow actual file to be specified.
7526                     &am_conf_line_error ('configure.in', $line,
7527                                          "$message$trailer");
7528                 }
7529                 else
7530                 {
7531                     &am_line_error ($line, "$message$trailer");
7532                 }
7533                 $exit_status = $save if $suppress;
7534             }
7535         }
7536     }
7539 # Like require_file_with_line, but error messages refer to
7540 # configure.in, not the current Makefile.am.
7541 sub require_file_with_conf_line
7543     @require_file_paths = '.';
7544     &require_file_internal (1, @_);
7547 sub require_file_with_line
7549     @require_file_paths = '.';
7550     &require_file_internal (0, @_);
7553 sub require_file
7555     @require_file_paths = '.';
7556     &require_file_internal (0, '', @_);
7559 # Require a file that is also required by Autoconf.  Looks in
7560 # configuration path, as specified by AC_CONFIG_AUX_DIR.
7561 sub require_config_file
7563     @require_file_paths = @config_aux_path;
7564     &require_file_internal (1, '', @_);
7565     local ($dir) = $require_file_paths[0];
7566     @config_aux_path = @require_file_paths;
7567     if ($dir eq '.')
7568     {
7569         $config_aux_dir = '.';
7570     }
7571     else
7572     {
7573         $config_aux_dir = '$(top_srcdir)/' . $dir;
7574     }
7577 # Assumes that the line number is in Makefile.am.
7578 sub require_conf_file_with_line
7580     @require_file_paths = @config_aux_path;
7581     &require_file_internal (0, @_);
7582     local ($dir) = $require_file_paths[0];
7583     @config_aux_path = @require_file_paths;
7584     if ($dir eq '.')
7585     {
7586         $config_aux_dir = '.';
7587     }
7588     else
7589     {
7590         $config_aux_dir = '$(top_srcdir)/' . $dir;
7591     }
7594 # Assumes that the line number is in configure.in.
7595 sub require_conf_file_with_conf_line
7597     @require_file_paths = @config_aux_path;
7598     &require_file_internal (1, @_);
7599     local ($dir) = $require_file_paths[0];
7600     @config_aux_path = @require_file_paths;
7601     if ($dir eq '.')
7602     {
7603         $config_aux_dir = '.';
7604     }
7605     else
7606     {
7607         $config_aux_dir = '$(top_srcdir)/' . $dir;
7608     }
7611 ################################################################
7613 # Push a list of files onto dist_common.
7614 sub push_dist_common
7616     local (@files) = @_;
7617     local ($file);
7619     foreach $file (@files)
7620     {
7621         if (! defined $dist_common{$file})
7622         {
7623             if ($handle_dist_run)
7624             {
7625                 print STDERR
7626                     "automake: programming error: push_dist_common run after handle_dist\n";
7627                 exit 1;
7628             }
7629             $dist_common{$file} = 1;
7630         }
7631     }
7634 # Push a list of clean targets onto phony.
7635 sub push_phony_cleaners
7637     local ($base) = @_;
7638     local ($target);
7639     foreach $target ('mostly', 'dist', '', 'maintainer-')
7640     {
7641         push (@phony, $target . 'clean-' . $base);
7642     }
7645 # Set strictness.
7646 sub set_strictness
7648     $strictness_name = $_[0];
7649     if ($strictness_name eq 'gnu')
7650     {
7651         $strictness = $GNU;
7652     }
7653     elsif ($strictness_name eq 'gnits')
7654     {
7655         $strictness = $GNITS;
7656     }
7657     elsif ($strictness_name eq 'foreign')
7658     {
7659         $strictness = $FOREIGN;
7660     }
7661     else
7662     {
7663         die "automake: level \`$strictness_name' not recognized\n";
7664     }
7668 ################################################################
7670 # Return directory name of file.
7671 sub dirname
7673     local ($file) = @_;
7674     local ($sub);
7676     ($sub = $file) =~ s,/+[^/]+$,,g;
7677     $sub = '.' if $sub eq $file;
7678     return $sub;
7681 # Return file name of a file.
7682 sub basename
7684     local ($file) = @_;
7685     local ($sub);
7687     ($sub = $file) =~s,^.*/+,,g;
7688     return $sub;
7691 # Ensure a file exists.
7692 sub create
7694     local ($file) = @_;
7696     open (TOUCH, ">> $file");
7697     close (TOUCH);
7700 # Glob something.  Do this to avoid indentation screwups everywhere we
7701 # want to glob.  Gross!
7702 sub my_glob
7704     local ($pat) = @_;
7705     return <${pat}>;
7708 ################################################################
7710 # Print an error message and set exit status.
7711 sub am_error
7713     warn "automake: ${am_file}.am: ", join (' ', @_), "\n";
7714     $exit_status = 1;
7717 sub am_line_error
7719     local ($symbol, @args) = @_;
7721     if ($symbol && "$symbol" ne '-1')
7722     {
7723         local ($file) = "${am_file}.am";
7725         if ($symbol =~ /^\d+$/)
7726         {
7727             # SYMBOL is a line number, so just add the colon.
7728             $file .= ':' . $symbol;
7729         }
7730         elsif (defined $content_lines{$symbol})
7731         {
7732             # SYMBOL is a variable defined in Makefile.am, so add the
7733             # line number we saved from there.
7734             $file .= ':' . $content_lines{$symbol};
7735         }
7736         elsif (defined $configure_vars{$symbol})
7737         {
7738             # SYMBOL is a variable defined in configure.in, so add the
7739             # appropriate line number.
7740             $file = $configure_vars{$symbol};
7741         }
7742         else
7743         {
7744             # Couldn't find the line number.
7745         }
7746         warn $file, ": ", join (' ', @args), "\n";
7747         $exit_status = 1;
7748     }
7749     else
7750     {
7751         &am_error (@args);
7752     }
7755 # Like am_error, but while scanning configure.in.
7756 sub am_conf_error
7758     # FIXME: can run in subdirs.
7759     warn "automake: configure.in: ", join (' ', @_), "\n";
7760     $exit_status = 1;
7763 # Error message with line number referring to configure.in.
7764 sub am_conf_line_error
7766     local ($file, $line, @args) = @_;
7768     if ($line)
7769     {
7770         warn "$file: $line: ", join (' ', @args), "\n";
7771         $exit_status = 1;
7772     }
7773     else
7774     {
7775         &am_conf_error (@args);
7776     }
7779 # Warning message with line number referring to configure.in.
7780 # Does not affect exit_status
7781 sub am_conf_line_warning
7783     local ($saved_exit_status) = $exit_status;
7784     &am_conf_line_error (@_);
7785     $exit_status = $saved_exit_status;
7788 # Tell user where our aclocal.m4 is, but only once.
7789 sub keyed_aclocal_warning
7791     local ($key) = @_;
7792     warn "automake: macro \`$key' can be generated by \`aclocal'\n";
7795 # Print usage information.
7796 sub usage
7798     print "Usage: automake [OPTION] ... [Makefile]...\n\n";
7799     print "Generate Makefile.in for autoconf from Makefile.am\n";
7800     print $USAGE;
7801     print "\nFiles which are automatically distributed, if found:\n";
7802     $~ = "USAGE_FORMAT";
7803     local ($last, $iter, @lcomm);
7804     $last = '';
7805     foreach $iter (sort ((@common_files, @common_sometimes)))
7806     {
7807         push (@lcomm, $iter) unless $iter eq $last;
7808         $last = $iter;
7809     }
7811     local ($one, $two, $three, $four, $i, $max);
7812     $max = int (($#lcomm + 1) / 4);
7814     for ($i = 0; $i < $max; ++$i)
7815     {
7816         $one = $lcomm[$i];
7817         $two = $lcomm[$max + $i];
7818         $three = $lcomm[2 * $max + $i];
7819         $four = $lcomm[3 * $max + $i];
7820         write;
7821     }
7823     local ($mod) = ($#lcomm + 1) % 4;
7824     if ($mod != 0)
7825     {
7826         $one = $lcomm[$max];
7827         $two = ($mod > 1) ? $lcomm[2 * $max] : '';
7828         $three = ($mod > 2) ? $lcomm[3 * $max] : '';
7829         $four = ($mod > 3) ? $lcomm[4 * $max] : '';
7830         write;
7831     }
7833     print "\nReport bugs to <bug-automake\@gnu.org>.\n";
7835     exit 0;
7838 format USAGE_FORMAT =
7839   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
7840   $one,               $two,               $three,             $four