Added explanatory comment
[automake.git] / automake.in
blob13b9f78761ca2cb0acfd0e34bde7cd9a14a169ef
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, 1995, 1996, 1997, 1998, 1999 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 # Files found by scanning configure.in for LIBOBJS.
113 %libsources = ();
115 # True if AM_C_PROTOTYPES appears in configure.in.
116 $am_c_prototypes = 0;
118 # Names used in AC_CONFIG_HEADER call.  @config_fullnames holds the
119 # name which appears in AC_CONFIG_HEADER, colon and all.
120 # @config_names holds the file names.  @config_headers holds the '.in'
121 # files.  Ordinarily these are similar, but they can be different if
122 # the weird "NAME:FILE" syntax is used.
123 @config_fullnames = ();
124 @config_names = ();
125 @config_headers = ();
126 # Line number at which AC_CONFIG_HEADER appears in configure.in.
127 $config_header_line = 0;
129 # Directory where output files go.  Actually, output files are
130 # relative to this directory.
131 $output_directory = '.';
133 # Relative location of top build directory.
134 $top_builddir = '';
136 # List of Makefile.am's to process, and their corresponding outputs.
137 @input_files = ();
138 %output_files = ();
140 # Complete list of Makefile.am's that exist.
141 @configure_input_files = ();
143 # List of files in AC_OUTPUT without Makefile.am, and their outputs.
144 @other_input_files = ();
145 # Line number at which AC_OUTPUT seen.
146 $ac_output_line = 0;
148 # List of directories to search for configure-required files.  This
149 # can be set by AC_CONFIG_AUX_DIR.
150 @config_aux_path = ('.', '..', '../..');
151 $config_aux_dir = '';
153 # Whether AC_PROG_MAKE_SET has been seen in configure.in.
154 $seen_make_set = 0;
156 # Whether AM_GNU_GETTEXT has been seen in configure.in.
157 $seen_gettext = 0;
158 # Line number at which AM_GNU_GETTEXT seen.
159 $ac_gettext_line = 0;
161 # Whether ALL_LINGUAS has been seen.
162 $seen_linguas = '';
163 # The actual text.
164 $all_linguas = '';
165 # Line number at which it appears.
166 $all_linguas_line = 0;
168 # 1 if AC_PROG_INSTALL seen.
169 $seen_prog_install = 0;
171 # Whether AC_PATH_XTRA has been seen in configure.in.
172 $seen_path_xtra = 0;
174 # TRUE if AC_DECL_YYTEXT was seen.
175 $seen_decl_yytext = 0;
177 # TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM).  The presence of
178 # AC_CHECK_TOOL also sets this.
179 $seen_canonical = 0;
181 # TRUE if we've seen AC_ARG_PROGRAM.
182 $seen_arg_prog = 0;
184 # TRUE if we've seen AC_PROG_LIBTOOL.
185 $seen_libtool = 0;
186 $libtool_line = 0;
188 # Files installed by libtoolize.
189 @libtoolize_files = ('ltconfig', 'ltmain.sh', 'config.guess', 'config.sub');
191 # TRUE if we've seen AM_MAINTAINER_MODE.
192 $seen_maint_mode = 0;
194 # TRUE if we've seen PACKAGE and VERSION.
195 $seen_package = 0;
196 $seen_version = 0;
198 # Actual version we've seen.
199 $package_version = '';
201 # Line number where we saw version definition.
202 $package_version_line = 0;
204 # TRUE if we've seen AM_PATH_LISPDIR.
205 $seen_lispdir = 0;
207 # TRUE if we've seen AM_CHECK_PYTHON.
208 $seen_pythondir = 0;
210 # TRUE if we've seen AC_EXEEXT.
211 $seen_exeext = 0;
213 # TRUE if we've seen AC_OBJEXT.
214 $seen_objext = 0;
216 # TRUE if we've seen AC_ENABLE_MULTILIB.
217 $seen_multilib = 0;
219 # TRUE if we've seen AM_PROG_CC_C_O
220 $seen_cc_c_o = 0;
222 # Hash table of discovered configure substitutions.  Keys are names,
223 # values are `FILE:LINE' strings which are used by error message
224 # generation.
225 %configure_vars = ();
227 # This is used to keep track of which variable definitions we are
228 # scanning.  It is only used in certain limited ways, but it has to be
229 # global.  It is declared just for documentation purposes.
230 %vars_scanned = ();
232 # Charsets used by maintainer and in distribution.  MAINT_CHARSET is
233 # handled in a funny way: if seen in the top-level Makefile.am, it is
234 # used for every directory which does not specify a different value.
235 # The rationale here is that some directories (eg gettext) might be
236 # distributions of other packages, and thus require their own charset
237 # info.  However, the DIST_CHARSET must be the same for the entire
238 # package; it can only be set at top-level.
239 # FIXME: this yields bugs when rebuilding.  What to do?  Always
240 # read (and sometimes discard) top-level Makefile.am?
241 $maint_charset = '';
242 $dist_charset = 'utf8';         # recode doesn't support this yet.
244 # Name of input file ("Makefile.in") and output file ("Makefile.am").
245 # These have no directory components.
246 $am_file_name = '';
247 $in_file_name = '';
249 # TRUE if --cygnus seen.
250 $cygnus_mode = 0;
252 # Hash table of AM_CONDITIONAL variables seen in configure.
253 %configure_cond = ();
255 # Map from obsolete macros to hints for new macros.
256 # If you change this, change the corresponding list in aclocal.in.
257 # FIXME: should just put this into a single file.
258 %obsolete_macros =
259     (
260      'AC_FEATURE_CTYPE', "use \`AC_HEADER_STDC'",
261      'AC_FEATURE_ERRNO', "add \`strerror' to \`AC_REPLACE_FUNCS(...)'",
262      'AC_FEATURE_EXIT', '',
263      'AC_SYSTEM_HEADER', '',
265      # Note that we do not handle this one, because it is still run
266      # from AM_CONFIG_HEADER.  So we deal with it specially in
267      # scan_configure.
268      # 'AC_CONFIG_HEADER', "use \`AM_CONFIG_HEADER'",
270      'fp_C_PROTOTYPES', "use \`AM_C_PROTOTYPES'",
271      'fp_PROG_CC_STDC', "use \`AM_PROG_CC_STDC'",
272      'fp_PROG_INSTALL', "use \`AC_PROG_INSTALL'",
273      'fp_WITH_DMALLOC', "use \`AM_WITH_DMALLOC'",
274      'fp_WITH_REGEX', "use \`AM_WITH_REGEX'",
275      'gm_PROG_LIBTOOL', "use \`AM_PROG_LIBTOOL'",
276      'jm_MAINTAINER_MODE', "use \`AM_MAINTAINER_MODE'",
277      'md_TYPE_PTRDIFF_T', "use \`AM_TYPE_PTRDIFF_T'",
278      'ud_PATH_LISPDIR', "use \`AM_PATH_LISPDIR'",
279      'ud_GNU_GETTEXT', "use \`AM_GNU_GETTEXT'",
281      # Now part of autoconf proper, under a different name.
282      'AM_FUNC_FNMATCH', "use \`AC_FUNC_FNMATCH'",
283      'fp_FUNC_FNMATCH', "use \`AC_FUNC_FNMATCH'",
284      'AM_SANITY_CHECK_CC', "automatically done by \`AC_PROG_CC'",
285      'AM_PROG_INSTALL', "use \`AC_PROG_INSTALL'",
286      'AM_EXEEXT', "use \`AC_EXEEXT'",
287      'AM_CYGWIN32', "use \`AC_CYGWIN'",
288      'AM_MINGW32', "use \`AC_MINGW32'",
289      'AM_FUNC_MKTIME', "use \`AC_FUNC_MKTIME'",
291 # These aren't quite obsolete.
292 #      'md_PATH_PROG',
293      );
295 # Regexp to match the above macros.
296 $obsolete_rx = '(' . join ('|', keys %obsolete_macros) . ')';
298 # This maps extensions onto language names.
299 %extension_map = ();
301 # This maps languages names onto properties.
302 %language_map = ();
306 # Initialize global constants and our list of languages that are
307 # internally supported.
308 &initialize_global_constants;
310 &register_language ('c', 'ansi-p=1', 'autodep=', 'flags=CFLAGS',
311                     'compile=$(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)',
312                     'compiler-name=COMPILE',
313                     'output-arg=-c',
314                     'c');
315 &register_language ('cxx', 'linker=CXXLINK', 'autodep=CXX', 'flags=CXXFLAGS',
316                     'compile=$(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)',
317                     'compiler-name=CXXCOMPILE',
318                     'output-arg=-c -o $@',
319                     'c++', 'cc', 'cpp', 'cxx', 'C');
320 &register_language ('objc', 'linker=OBJCLINK', 'autodep=OBJC',
321                     'flags=OBJCFLAGS',
322                     'compile=$(OBJC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS)',
323                     'compiler-name=OBJCCOMPILE',
324                     'output-arg=-c -o $@',
325                     'm');
326 &register_language ('header',
327                     'h', 'H', 'hxx', 'h++', 'hh', 'hpp', 'inc');
329 # For now, yacc and lex can't be handled on a per-exe basis.
330 &register_language ('yacc', 'ansi-p=1',
331                     'y');
332 &register_language ('yaccxx', 'linker=CXXLINK',
333                     'y++', 'yy', 'yxx', 'ypp');
334 &register_language ('lex', 'ansi-p=1',
335                     'l');
336 &register_language ('lexxx', 'linker=CXXLINK',
337                     'l++', 'll', 'lxx', 'lpp');
339 &register_language ('asm',
340                     'flags=CFLAGS', # FIXME: asmflags?
341                     'compile=$(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)', # FIXME: a different compiler?
342                     'compiler-name=COMPILE',
343                     'output-arg=-c',
344                     's', 'S');
346 &register_language ('f77', 'linker=F77LINK', 'flags=FFLAGS',
347                     'compile=$(F77) $(AM_FFLAGS) $(FFLAGS)',
348                     'compiler-name=F77COMPILE',
349                     'output-arg=-c -o $@',
350                     'f', 'for', 'f90');
351 &register_language ('ppf77', 'linker=F77LINK', 'flags=FFLAGS',
352                     'compile=$(F77) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)',
353                     'compiler-name=PPF77COMPILE',
354                     'output-arg=-c -o $@',
355                     'F');
356 &register_language ('ratfor', 'linker=F77LINK',
357                     'flags=RFLAGS', # FIXME also FFLAGS.
358                     'compile=$(F77) $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)',
359                     'compiler-name=RCOMPILE',
360                     'output-arg=-c -o $@',
361                     'r');
362 # FIXME: for now we can't do dependency tracking for Java.
363 # autodep=GCJ
364 &register_language ('java', 'linker=GCJLINK', 'flags=GCJFLAGS',
365                     'compile=$(GCJ) $(DEFS) $(INCLUDES) $(AM_GCJFLAGS) $(GCJFLAGS)',
366                     'compiler-name=GCJCOMPILE',
367                     'output-arg=-c -o $@',
368                     'java', 'class', 'zip', 'jar');
371 # Parse command line.
372 &parse_arguments (@ARGV);
374 # Do configure.in scan only once.
375 &scan_configure;
377 die "automake: no \`Makefile.am' found or specified\n"
378     if ! @input_files;
380 # Now do all the work on each file.
381 foreach $am_file (@input_files)
383     if (! -f ($am_file . '.am'))
384     {
385         &am_error ("\`" . $am_file . ".am' does not exist");
386     }
387     else
388     {
389         &generate_makefile ($output_files{$am_file}, $am_file);
390     }
393 &am_conf_error ("AC_PROG_INSTALL must be used in configure.in")
394     if (! $seen_prog_install);
396 exit $exit_status;
399 ################################################################
401 # Parse command line.
402 sub parse_arguments
404     local (@arglist) = @_;
406     # Start off as gnu.
407     &set_strictness ('gnu');
409     while (@arglist)
410     {
411         if ($arglist[0] eq "--version")
412         {
413             print "automake (GNU $PACKAGE) $VERSION\n\n";
414             print "Copyright (C) 1999 Free Software Foundation, Inc.\n";
415             print "This is free software; see the source for copying conditions.  There is NO\n";
416             print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n";
417             print "Written by Tom Tromey <tromey\@cygnus.com>\n";
419             exit 0;
420         }
421         elsif ($arglist[0] eq "--help")
422         {
423             &usage;
424         }
425         elsif ($arglist[0] =~ /^--amdir=(.+)$/)
426         {
427             $am_dir = $1;
428         }
429         elsif ($arglist[0] eq '--amdir')
430         {
431             &require_argument (@arglist);
432             shift (@arglist);
433             $am_dir = $arglist[0];
434         }
435         elsif ($arglist[0] eq '--gnu')
436         {
437             &set_strictness ('gnu');
438         }
439         elsif ($arglist[0] eq '--gnits')
440         {
441             &set_strictness ('gnits');
442         }
443         elsif ($arglist[0] eq '--cygnus')
444         {
445             $cygnus_mode = 1;
446         }
447         elsif ($arglist[0] eq '--foreign')
448         {
449             &set_strictness ('foreign');
450         }
451         elsif ($arglist[0] eq '--include-deps')
452         {
453             $cmdline_use_dependencies = 1;
454         }
455         elsif ($arglist[0] eq '--ignore-deps' || $arglist[0] eq '-i')
456         {
457             $cmdline_use_dependencies = 0;
458         }
459         elsif ($arglist[0] eq '--no-force')
460         {
461             $force_generation = 0;
462         }
463         elsif ($arglist[0] =~ /^--output-dir=(.*)$/)
464         {
465             # Set output directory.
466             $output_directory = $1;
467         }
468         elsif ($arglist[0] eq '--output-dir' || $arglist[0] eq '-o')
469         {
470             &require_argument (@arglist);
471             shift (@arglist);
472             $output_directory = $arglist[0];
473         }
474         elsif ($arglist[0] eq '--add-missing' || $arglist[0] eq '-a')
475         {
476             $add_missing = 1;
477         }
478         elsif ($arglist[0] eq '--copy' || $arglist[0] eq '-c')
479         {
480             $copy_missing = 1;
481         }
482         elsif ($arglist[0] eq '--verbose' || $arglist[0] eq '-v')
483         {
484             $verbose = 1;
485         }
486         elsif ($arglist[0] eq '--')
487         {
488             # Stop option processing.
489             shift (@arglist);
490             push (@input_files, @arglist);
491             last;
492         }
493         elsif ($arglist[0] =~ /^-/)
494         {
495             die "automake: unrecognized option -- \`$arglist[0]'\nTry \`automake --help' for more information.\n";
496         }
497         else
498         {
499             # Handle $local:$input syntax.  Note that we only examine
500             # the first ":" file to see if it is automake input; the
501             # rest are just taken verbatim.  We still keep all the
502             # files around for dependency checking, however.
503             local ($local, $input, @rest) = split (/:/, $arglist[0]);
504             if (! $input)
505             {
506                 $input = $local;
507             }
508             else
509             {
510                 # Strip .in; later on .am is tacked on.  That is how
511                 # the automake input file is found.  Maybe not the
512                 # best way, but it is easy to explain.  FIXME: should
513                 # be error if .in is missing.
514                 $input =~ s/\.in$//;
515             }
516             push (@input_files, $input);
517             $output_files{$input} = join (':', ($local, @rest));
518         }
520         shift (@arglist);
521     }
523     # Take global strictness from whatever we currently have set.
524     $default_strictness = $strictness;
525     $default_strictness_name = $strictness_name;
528 # Ensure argument exists, or die.
529 sub require_argument
531     local ($arg, @arglist) = @_;
532     die "automake: no argument given for option \`$arg'\n"
533         if ! @arglist;
536 ################################################################
538 # Generate a Makefile.in given the name of the corresponding Makefile and
539 # the name of the file output by config.status.
540 sub generate_makefile
542     local ($output, $makefile) = @_;
544     ($am_file_name = $makefile) =~ s/^.*\///;
545     $in_file_name = $am_file_name . '.in';
546     $am_file_name .= '.am';
548     # $OUTPUT is encoded.  If it contains a ":" then the first element
549     # is the real output file, and all remaining elements are input
550     # files.  We don't scan or otherwise deal with these input file,
551     # other than to mark them as dependencies.  See scan_configure for
552     # details.
553     local (@secondary_inputs);
554     ($output, @secondary_inputs) = split (/:/, $output);
556     &initialize_per_input;
557     $relative_dir = &dirname ($output);
558     $am_relative_dir = &dirname ($makefile);
560     # At the toplevel directory, we might need config.guess, config.sub
561     # or libtool scripts (ltconfig and ltmain.sh).
562     if ($relative_dir eq '.')
563     {
564         # libtool requires some files.
565         &require_conf_file_with_conf_line ($libtool_line, $FOREIGN,
566                                            @libtoolize_files)
567             if $seen_libtool;
569         # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
570         # config.sub.
571         &require_config_file ($FOREIGN, 'config.guess', 'config.sub')
572             if $seen_canonical;
573     }
575     # We still need Makefile.in here, because sometimes the `dist'
576     # target doesn't re-run automake.
577     if ($am_relative_dir eq $relative_dir)
578     {
579         # Only distribute the files if they are in the same subdir as
580         # the generated makefile.
581         &push_dist_common ($in_file_name, $am_file_name);
582     }
584     push (@sources, '$(SOURCES)')
585         if &variable_defined ('SOURCES');
586     push (@objects, '$(OBJECTS)')
587         if &variable_defined ('OBJECTS');
589     &read_main_am_file ($makefile . '.am');
590     if (&handle_options)
591     {
592         # Fatal error.  Just return, so we can continue with next file.
593         return;
594     }
596     # Must do this after reading .am file.  See read_main_am_file to
597     # understand weird tricks we play there with variables.
598     &define_variable ('subdir', $relative_dir);
600     # Check first, because we might modify some state.
601     &check_cygnus;
602     &check_gnu_standards;
603     &check_gnits_standards;
605     &handle_configure ($output, $makefile, @secondary_inputs);
606     &handle_gettext;
607     &handle_libraries;
608     &handle_ltlibraries;
609     &handle_programs;
610     &handle_scripts;
612     &handle_built_sources;
614     # This must be run after all the sources are scanned.
615     &finish_languages;
617     # Re-init SOURCES and OBJECTS.  FIXME: other code shouldn't depend
618     # on this (but currently does).
619     $contents{'SOURCES'} = join (' ', @sources);
620     $contents{'OBJECTS'} = join (' ', @objects);
621     &define_pretty_variable ('DIST_SOURCES', '', @dist_sources);
623     &handle_multilib;
624     &handle_texinfo;
625     &handle_emacs_lisp;
626     &handle_python;
627     &handle_java;
628     &handle_man_pages;
629     &handle_data;
630     &handle_headers;
631     &handle_subdirs;
632     &handle_tags;
633     &handle_minor_options;
634     &handle_dist ($makefile);
635     &handle_dependencies;
636     &handle_tests;
637     &handle_footer;
638     &handle_merge_targets ($output);
639     &handle_installdirs;
640     &handle_clean;
641     &handle_phony;
643     &check_typos;
645     if (! -d ($output_directory . '/' . $am_relative_dir))
646     {
647         mkdir ($output_directory . '/' . $am_relative_dir, 0755);
648     }
650     local ($out_file) = $output_directory . '/' . $makefile . ".in";
651     if (! $force_generation && -e $out_file)
652     {
653         local ($am_time) = (stat ($makefile . '.am'))[9];
654         local ($in_time) = (stat ($out_file))[9];
655         # FIXME: should cache these times.
656         local ($conf_time) = (stat ('configure.in'))[9];
657         # FIXME: how to do unsigned comparison?
658         if ($am_time < $in_time || $am_time < $conf_time)
659         {
660             # No need to update.
661             return;
662         }
663         if (-f 'aclocal.m4')
664         {
665             local ($acl_time) = (stat _)[9];
666             return if ($am_time < $acl_time);
667         }
668     }
670     if (! open (GM_FILE, "> " . $out_file))
671     {
672         warn "automake: ${am_file}.in: cannot write: $!\n";
673         $exit_status = 1;
674         return;
675     }
676     print "automake: creating ", $makefile, ".in\n" if $verbose;
678     print GM_FILE $output_vars;
679     # We make sure that `all:' is the first target.
680     print GM_FILE $output_all;
681     print GM_FILE $output_header;
682     print GM_FILE $output_rules;
683     print GM_FILE $output_trailer;
685     close (GM_FILE);
688 ################################################################
690 # Handle AUTOMAKE_OPTIONS variable.  Return 1 on error, 0 otherwise.
691 sub handle_options
693     if (&variable_defined ('AUTOMAKE_OPTIONS'))
694     {
695         foreach (&variable_value_as_list ('AUTOMAKE_OPTIONS', ''))
696         {
697             $options{$_} = 1;
698             if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
699             {
700                 &set_strictness ($_);
701             }
702             elsif ($_ eq 'cygnus')
703             {
704                 $cygnus_mode = 1;
705             }
706             elsif (/ansi2knr/)
707             {
708                 # An option like "../lib/ansi2knr" is allowed.  With
709                 # no path prefix, we assume the required programs are
710                 # in this directory.  We save the actual option for
711                 # later.
712                 $options{'ansi2knr'} = $_;
713             }
714             elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
715                    || $_ eq 'dist-shar' || $_ eq 'dist-zip'
716                    || $_ eq 'dist-tarZ' || $_ eq 'dist-bzip2'
717                    || $_ eq 'dejagnu' || $_ eq 'no-texinfo.tex'
718                    || $_ eq 'readme-alpha' || $_ eq 'check-news'
719                    || $_ eq 'subdir-objects' || $_ eq 'nostdinc')
720             {
721                 # Explicitly recognize these.
722             }
723             elsif ($_ eq 'no-dependencies')
724             {
725                 $use_dependencies = 0;
726             }
727             elsif (/([0-9]+)\.([0-9]+)([a-z])?/)
728             {
729                 # Got a version number.
731                 local ($rmajor, $rminor, $ralpha) = ($1, $2, $3);
733                 if ($VERSION !~ /([0-9]+)\.([0-9]+)([a-z])?/)
734                 {
735                     print STDERR
736                         "automake: programming error: version is incorrect\n";
737                     exit 1;
738                 }
739                 local ($tmajor, $tminor, $talpha) = ($1, $2, $3);
741                 # 2.0 is better than 1.0.
742                 # 1.2 is better than 1.1.
743                 # 1.2a is better than 1.2.
744                 if ($rmajor > $tmajor
745                     || ($rmajor == $tmajor && $rminor > $tminor)
746                     || ($rminor == $tminor && $rminor == $tminor
747                         && $ralpha gt $talpha))
748                 {
749                     &am_line_error ('AUTOMAKE_OPTIONS',
750                                     "require version $_, only have $VERSION");
751                     return 1;
752                 }
753             }
754             else
755             {
756                 &am_line_error ('AUTOMAKE_OPTIONS',
757                                 "option \`" . $_ . "\' not recognized");
758             }
759         }
760     }
762     if ($strictness == $GNITS)
763     {
764         $options{'readme-alpha'} = 1;
765         $options{'check-news'} = 1;
766     }
768     return 0;
771 # Return object extension.  Just once, put some code into the output.
772 # Argument is the name of the output file
773 sub get_object_extension
775     local ($out) = @_;
777     # Maybe require libtool library object files.
778     local ($extension) = '.o';
779     $extension = '.$(OBJEXT)' if $seen_objext;
780     $extension = '.lo' if ($out =~ /\.la$/);
782     if (! $included_generic_compile)
783     {
784         # Boilerplate.
785         local ($xform) = '';
786         if (! defined $options{'nostdinc'})
787         {
788             $xform = '-I. -I\$(srcdir)';
790             if (&variable_defined ('CONFIG_HEADER'))
791             {
792                 local ($one_hdr);
793                 foreach $one_hdr (split (' ',
794                                          &variable_value ('CONFIG_HEADER')))
795                 {
796                     local ($var);
797                     ($var = &dirname ($one_hdr)) =~ s/(\W)/\\$1/g;
798                     $xform .= ' -I' . $var;
799                 }
800             }
801         }
802         $xform = 's/\@DEFAULT_INCLUDES\@/' . $xform . '/go;';
803         $output_vars .= &file_contents_with_transform ($xform,
804                                                        'comp-vars');
806         $xform = $seen_objext ? 's/^OBJEXT//;' : 's/^OBJEXT.*$//;';
807         $output_rules .= &file_contents_with_transform ($xform, 'compile');
809         &push_phony_cleaners ('compile');
811         # If using X, include some extra variable definitions.  NOTE
812         # we don't want to force these into CFLAGS or anything,
813         # because not all programs will necessarily use X.
814         if ($seen_path_xtra)
815         {
816             local ($var);
817             foreach $var ('X_CFLAGS', 'X_LIBS', 'X_EXTRA_LIBS', 'X_PRE_LIBS')
818             {
819                 &define_configure_variable ($var);
820             }
821         }
823         push (@suffixes, '.c', '.o');
824         push (@suffixes, '.obj') if $seen_objext;
825         push (@clean, 'compile');
827         $included_generic_compile = 1;
828     }
830     if ($seen_libtool && ! $included_libtool_compile)
831     {
832         # Output the libtool compilation rules.
833         $output_rules .= &file_contents ('libtool');
835         &push_phony_cleaners ('libtool');
837         push (@suffixes, '.lo');
838         push (@clean, 'libtool');
840         $included_libtool_compile = 1;
841     }
843     # Check for automatic de-ANSI-fication.
844     if (defined $options{'ansi2knr'})
845     {
846         $extension = '$U' . $extension;
847         if (! $included_knr_compile)
848         {
849             if (! $am_c_prototypes)
850             {
851                 &am_line_error ('AUTOMAKE_OPTIONS',
852                                 "option \`ansi2knr' in use but \`AM_C_PROTOTYPES' not in configure.in");
853                 &keyed_aclocal_warning ('AM_C_PROTOTYPES');
854                 # Only give this error once.
855                 $am_c_prototypes = 1;
856             }
858             # Only require ansi2knr files if they should appear in
859             # this directory.
860             if ($options{'ansi2knr'} eq 'ansi2knr')
861             {
862                 &require_file_with_line ('AUTOMAKE_OPTIONS', $FOREIGN,
863                                          'ansi2knr.c', 'ansi2knr.1');
864                 $output_rules .= &file_contents ('kr-extra');
865                 push (@clean, 'krextra');
866                 &push_phony_cleaners ('krextra');
867             }
869             # Generate rules to build ansi2knr.  If it is in some
870             # other directory, then generate dependencies but have the
871             # rule just run elsewhere.
872             $objext = $seen_objext ? ".\$(OBJEXT)" : ".o";
873             $output_rules .= ($options{'ansi2knr'} . ': '
874                               . $options{'ansi2knr'} . $objext . "\n");
875             if ($options{'ansi2knr'} eq 'ansi2knr')
876             {
877                 $output_rules .= ("\t\$(LINK) ansi2knr" . $objext
878                                   . " \$(LIBS)\n"
879                                   . "ansi2knr" . $objext
880                                   . ": \$(CONFIG_HEADER)\n\n");
881             }
882             else
883             {
884                 $output_rules .= ("\tcd " . &dirname ($options{'ansi2knr'})
885                                   . " && \$(MAKE) \$(AM_MAKEFLAGS) "
886                                   . "ansi2knr\n\n");
887                 # This is required for non-GNU makes.
888                 $output_rules .= ($options{'ansi2knr'} . $objext . ":\n");
889                 $output_rules .= ("\tcd " . &dirname ($options{'ansi2knr'})
890                                   . " && \$(MAKE) \$(AM_MAKEFLAGS)"
891                                   . " ansi2knr" . $objext . "\n\n");
892             }
894             # Make sure ansi2knr can be found: if no path specified,
895             # specify "./".
896             if ($options{'ansi2knr'} eq 'ansi2knr')
897             {
898                 # Substitution from AM_C_PROTOTYPES.  This makes it be
899                 # built only when necessary.
900                 &define_configure_variable ('ANSI2KNR');
901                 # ansi2knr needs to be built before subdirs, so unshift it.
902                 unshift (@all, '$(ANSI2KNR)');
903             }
904             else
905             {
906                 # Found in another directory.
907                 &define_variable ("ANSI2KNR", $options{'ansi2knr'});
908             }
910             $output_rules .= &file_contents ('clean-kr');
912             push (@clean, 'kr');
913             &push_phony_cleaners ('kr');
915             $included_knr_compile = 1;
916         }
917     }
919     return $extension;
922 # Call finish function for each language that was used.
923 sub finish_languages
925     local ($ltcompile, $ltlink) = &libtool_compiler;
927     local ($ext, $name, $lang, %done);
928     local ($non_c) = 1;
929     foreach $ext (sort keys %extension_seen)
930     {
931         $lang = $extension_map{$ext};
933         # Generate the appropriate rules for this extension.  If
934         # dependency tracking was requested, and this extension
935         # supports it, then we don't generate the rule here.
936         local ($comp) = '';
937         
938         if ($use_dependencies && $language_map{$lang . '-autodep'} ne 'no')
939         {
940             # Don't generate the rule, but still generate the variables.
941             if (defined $language_map{$lang . '-compile'})
942             {
943                 $comp = $language_map{$lang . '-compile'};
944             }
945         }
946         elsif (defined $language_map{$lang . '-compile'})
947         {
948             $comp = $language_map{$lang . '-compile'};
950             local ($outarg) = $language_map{$lang . '-output-arg'};
951             if ($language_map{$lang . '-flags'} eq 'CFLAGS')
952             {
953                 # C compilers don't always support -c -o.
954                 if (defined $options{'subdir-objects'})
955                 {
956                     $outarg .= ' -o $@';
957                 }
958             }
960             local ($full) = ("\t\$("
961                              . $language_map{$lang . '-compiler-name'}
962                              . ") "
963                              . $outarg);
964             $output_rules .= (".$ext.o:\n"
965                               . $full
966                               . " \$<\n");
967             # FIXME: Using cygpath should be somehow conditional.
968             $output_rules .= (".$ext.obj:\n"
969                               . $full
970                               . " \`cygpath -w \$<\`\n")
971                 if $seen_objext;
972             $output_rules .= (".$ext.lo:\n"
973                               . "\t\$(LT"
974                               . $language_map{$lang . '-compiler-name'}
975                               . ") "
976                               . $language_map{$lang . '-output-arg'}
977                               # We can always use -c -o with libtool.
978                               . ($language_map{$lang . '-flags'} eq 'CFLAGS'
979                                  ? ' -o $@' : '')
980                               . " \$<\n")
981                 if $seen_libtool;
982         }
984         push (@suffixes, '.' . $ext);
986         # The rest of the loop is done once per language.
987         next if defined $done{$lang};
988         $done{$lang} = 1;
990         $non_c = 0 if $lang !~ /(objc|cxx|f77|ratfor)$/;
992         if ($comp ne '')
993         {
994             &define_compiler_variable ($language_map{$lang . '-compiler-name'},
995                                        $ltcompile, $comp);
996         }
997         # The compiler's flag must be a configure variable.
998         if (defined $language_map{$lang . '-flags'})
999         {
1000             &define_configure_variable ($language_map{$lang . '-flags'});
1001         }
1003         # Compute the function name of the finisher and then call it.
1004         $name = 'lang_' . $lang . '_finish';
1005         & $name ();
1006     }
1008     # If the project is entirely C++ or entirely Fortran 77, don't
1009     # bother with the C stuff.  But if anything else creeps in, then use
1010     # it.
1011     if (! $non_c || scalar keys %suffix_rules > 0)
1012     {
1013         if (! defined $done{'c'})
1014         {
1015             &define_configure_variable ($language_map{'c-flags'});
1016             &define_compiler_variable ($language_map{'c-compiler-name'},
1017                                        $ltcompile,
1018                                        $language_map{'c-compile'});
1019         }
1020         &define_variable ('CCLD', '$(CC)');
1021         &define_variable ('LINK', $ltlink . '$(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
1022     }
1025 # Output a rule to build from a YACC source.  The output from YACC is
1026 # compiled with C or C++, depending on the extension of the YACC file.
1027 sub output_yacc_build_rule
1029     local ($yacc_suffix, $use_ylwrap, $c_suffix) = @_;
1031     local ($suffix);
1032     ($suffix = $yacc_suffix) =~ tr/y/c/;
1033     push (@suffixes, $yacc_suffix, $suffix);
1035     # Generate rule for c/c++.
1036     $output_rules .= "$yacc_suffix$suffix:\n\t";
1038     if ($use_ylwrap)
1039     {
1040         $output_rules .= ('$(SHELL) $(YLWRAP)'
1041                           . ' "$(YACC)" $< y.tab.c $*' . $suffix
1042                           . ' y.tab.h $*.h -- $(AM_YFLAGS) $(YFLAGS)');
1043     }
1044     else
1045     {
1046         $output_rules .= ('$(YACC) $(AM_YFLAGS) $(YFLAGS) $< && mv y.tab.c $*'
1047                           . $suffix . "\n"
1048                           . "\tif test -f y.tab.h; then \\\n"
1049                           . "\tif cmp -s y.tab.h \$*.h; then rm -f y.tab.h; else mv y.tab.h \$*.h; fi; \\\n"
1050                           . "\telse :; fi");
1051     }
1052     $output_rules .= "\n";
1055 sub output_lex_build_rule
1057     local ($lex_suffix, $use_ylwrap) = @_;
1058     local ($c_suffix);
1060     ($c_suffix = $lex_suffix) =~ tr/l/c/;
1061     push (@suffixes, $lex_suffix);
1062     &define_configure_variable ('LEX_OUTPUT_ROOT');
1063     &define_configure_variable ('LEXLIB');
1064     $output_rules .= "$lex_suffix$c_suffix:\n\t";
1066     if ($use_ylwrap)
1067     {
1068         # Is the $@ correct here?  If so, why not use it in the ylwrap
1069         # build rule for yacc above?
1070         $output_rules .= '$(SHELL) $(YLWRAP)'
1071             . ' "$(LEX)" $< $(LEX_OUTPUT_ROOT).c $@ -- $(AM_LFLAGS) $(LFLAGS)';
1072     }
1073     else
1074     {
1075         $output_rules .= '$(LEX) $(AM_LFLAGS) $(LFLAGS) $< && mv $(LEX_OUTPUT_ROOT).c $@';
1076     }
1077     $output_rules .= "\n";
1081 # Check to make sure a source defined in LIBOBJS is not explicitly
1082 # mentioned.  This is a separate function (as opposed to being inlined
1083 # in handle_source_transform) because it isn't always appropriate to
1084 # do this check.
1085 sub check_libobjs_sources
1087     local ($one_file, $unxformed) = @_;
1089     local ($prefix, $file, @files);
1090     foreach $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1091                      'dist_EXTRA_', 'nodist_EXTRA_')
1092     {
1093         if (&variable_defined ($prefix . $one_file . '_SOURCES'))
1094         {
1095             @files = &variable_value_as_list (($prefix
1096                                                . $one_file . '_SOURCES'),
1097                                               'all');
1098         }
1099         elsif ($prefix eq '')
1100         {
1101             @files = ($unxformed . '.c');
1102         }
1103         else
1104         {
1105             next;
1106         }
1108         foreach $file (@files)
1109         {
1110             if (defined $libsources{$file})
1111             {
1112                 &am_line_error ($prefix . $one_file . '_SOURCES',
1113                                 "automatically discovered file \`$file' should not be explicitly mentioned");
1114             }
1115         }
1116     }
1119 # Does much of the actual work for handle_source_transform.
1120 # Arguments are:
1121 #   name of resulting executable or library ("derived")
1122 #   object extension (e.g., `$U.lo')
1123 #   list of source files to transform
1124 # Result is a list
1125 #   first element is name of linker to use (empty string for default linker)
1126 #   remaining elements are names of objects
1127 sub handle_single_transform_list
1129     local ($var, $derived, $obj, @files) = @_;
1130     local (@result) = ();
1131     local ($nonansi_obj) = $obj;
1132     $nonansi_obj =~ s/_//g;
1133     local (%linkers_used) = ();
1134     if (@files > 0)
1135     {
1136         # Turn sources into objects.
1137         foreach (@files)
1138         {
1139             # Configure substitutions in _SOURCES variables are errors.
1140             if (/^\@.*\@$/)
1141             {
1142                 &am_line_error ($var, "$var includes configure substitution \`$_'");
1143                 next;
1144             }
1146             # If the source file is in a subdirectory then the `.o' is
1147             # put into the current directory.
1149             # Split file name into base and extension.
1150             local ($full, $directory, $base, $extension, $linker, $object);
1151             next if ! /^((.*)\/)?([^\/]*)\.(.*)$/;
1152             $full = $_;
1153             $directory = $2;
1154             $base = $3;
1155             $extension = $4;
1157             local ($xbase) = $base;
1159             # We must generate a rule for the object if it requires
1160             # its own flags.
1161             local ($rule) = '';
1162             local ($renamed) = 0;
1164             $extension = &derive_suffix ($extension);
1165             local ($lang) = $extension_map{$extension};
1166             if ($lang)
1167             {
1168                 &saw_extension ($extension);
1169                 # Found the language, so see what it says.
1170                 local ($subr) = 'lang_' . $lang . '_rewrite';
1171                 # Note: computed subr call.
1172                 local ($r) = & $subr ($directory, $base, $extension);
1173                 # Skip this entry if we were asked not to process it.
1174                 next if $r == $LANG_IGNORE;
1176                 # Now extract linker and other info.
1177                 $linker = $language_map{$lang . '-linker'};
1179                 local ($this_obj_ext);
1180                 if ($language_map{$lang . '-ansi-p'})
1181                 {
1182                     $object = $base . $obj;
1183                     $this_obj_ext = $obj;
1184                 }
1185                 else
1186                 {
1187                     $object = $base . $nonansi_obj;
1188                     $this_obj_ext = $nonansi_obj;
1189                 }
1191                 if ($language_map{$lang . '-flags'} ne ''
1192                     && &variable_defined ($derived . '_'
1193                                           . $language_map{$lang . '-flags'}))
1194                 {
1195                     # We have a per-executable flag in effect for this
1196                     # object.  In this case we rewrite the object's
1197                     # name to ensure it is unique.  We also require
1198                     # the `compile' program to deal with compilers
1199                     # where `-c -o' does not work.
1201                     # We choose the name `DERIVED-OBJECT' to ensure
1202                     # (1) uniqueness, and (2) continuity between
1203                     # invocations.  However, this will result in a
1204                     # name that is too long for losing systems, in
1205                     # some situations.  So we provide _SHORTNAME to
1206                     # override.
1208                     local ($dname) = $derived;
1209                     if (&variable_defined ($derived . '_SHORTNAME'))
1210                     {
1211                         # FIXME: should use the same conditional as
1212                         # the _SOURCES variable.  But this is really
1213                         # silly overkill -- nobody should have
1214                         # conditional shortnames.
1215                         $dname = &variable_value ($derived . '_SHORTNAME');
1216                     }
1217                     $object = $dname . '-' . $object;
1219                     &require_file ($FOREIGN, 'compile')
1220                         if $lang eq 'c';
1222                     if (! defined $language_map{$lang . '-compile'})
1223                     {
1224                         print STDERR "automake: programming error: $lang flags defined without compiler\n";
1225                         exit 1;
1226                     }
1227                     # Compute the rule to compile this object.
1228                     local ($flag) = $language_map{$lang . '-flags'};
1229                     local ($val) = "(${derived}_${flag}";
1230                     ($rule = $language_map{$lang . '-compile'}) =~    
1231                         s/\(AM_$flag/$val/;
1233                     $rule .= ' ' . $language_map{$lang . '-output-arg'};
1234                     # For C we have to add the -o, because the
1235                     # standard rule doesn't include it.
1236                     if ($language_map{$lang . '-flags'} eq 'CFLAGS')
1237                     {
1238                         $rule .= ' -o $@';
1239                     }
1241                     $renamed = 1;
1242                 }
1244                 # If rewrite said it was ok, put the object into a
1245                 # subdir.
1246                 if ($r == $LANG_SUBDIR && $directory ne '')
1247                 {
1248                     $object = $directory . '/' . $object;
1249                     $xbase = $directory . '/' . $base;
1250                 }
1252                 # If doing dependency tracking, then we can't print
1253                 # the rule.  Also, if we have a subdir object, we need
1254                 # to generate an explicit rule.
1255                 if (($use_dependencies
1256                      && $rule ne ''
1257                      && $language_map{$lang . '-autodep'} ne 'no')
1258                     || ($r == $LANG_SUBDIR && $directory ne ''))
1259                 {
1260                     $rule = '';
1261                     local ($obj_sans_ext) = substr ($object, 0,
1262                                                     - length ($this_obj_ext));
1263                     $lang_specific_files{$lang} .= (' ' . $derived
1264                                                     . ' ' . $full
1265                                                     . ' ' . $obj_sans_ext);
1266                 }
1267             }
1268             elsif ($extension eq 'o')
1269             {
1270                 # This is probably the result of a direct suffix rule.
1271                 # In this case we just accept the rewrite.  FIXME:
1272                 # this fails if we want libtool objects.
1273                 $object = $base . '.' . $extension;
1274                 $linker = '';
1275             }
1276             else
1277             {
1278                 # No error message here.  Used to have one, but it was
1279                 # very unpopular.
1280                 next;
1281             }
1283             $linkers_used{$linker} = 1;
1285             push (@result, $object);
1287             if (defined $object_map{$object})
1288             {
1289                 if ($object_map{$object} ne $full)
1290                 {
1291                     &am_error ("object \`$object' created by \`$full' and \`$object_map{$object}'");
1292                 }
1293             }
1294             else
1295             {
1296                 local (@dep_list) = ();
1297                 $object_map{$object} = $full;
1299                 # If file is in subdirectory, we need explicit
1300                 # dependency.
1301                 if ($directory ne '' || $renamed)
1302                 {
1303                     push (@dep_list, $full);
1304                 }
1306                 # If resulting object is in subdir, we need to make
1307                 # sure the subdir exists at build time.
1308                 if ($object =~ /\//)
1309                 {
1310                     # FIXME: check that $DIRECTORY is somewhere in the
1311                     # project
1313                     # We don't allow `..' in object file names for
1314                     # *any* source, not just Java.  For Java it just
1315                     # doesn't make sense, but in general it is
1316                     # a problem because we can't pick a good name for
1317                     # the .deps entry.
1318                     if ($object =~ /(\/|^)\.\.\//)
1319                     {
1320                         &am_error ("\`$full' contains \`..' component but should not");
1321                     }
1323                     push (@dep_list, $directory . '/.dirstamp');
1325                     # If we're generating dependencies, we also want
1326                     # to make sure that the appropriate subdir of the
1327                     # .deps directory is created.
1328                     if ($use_dependencies)
1329                     {
1330                         push (@dep_list, '.deps/' . $directory . '/.dirstamp');
1331                     }
1333                     if (! defined $directory_map{$directory})
1334                     {
1335                         $directory_map{$directory} = 1;
1336                         $output_rules .= ($directory . "/.dirstamp:\n"
1337                                           . "\t\@\$(mkinstalldirs) $directory\n"
1338                                           . "\t\@: > $directory/.dirstamp\n");
1339                         if ($use_dependencies)
1340                         {
1341                             $output_rules .= ('.deps/' . $directory
1342                                               . "/.dirstamp:\n"
1343                                               . "\t\@\$(mkinstalldirs) .deps/$directory\n"
1344                                               . "\t\@: > .deps/$directory/.dirstamp\n");
1345                         }
1346                     }
1347                 }
1349                 &pretty_print_rule ($object . ':', "\t", @dep_list)
1350                     if scalar @dep_list > 0 || $rule ne '';
1352                 # Print the rule if we have one.
1353                 if ($rule ne '')
1354                 {
1355                     # Turn `$@' into name of our object file.
1356                     local ($xform);
1357                     ($xform = $object) =~ s,/,\\/,g;
1358                     $rule =~ s/\$\@/$xform/;
1359                     # FIXME: we use $< in an explicit rule here.
1360                     # We can't use $(srcdir)/<file> because we don't
1361                     # actually know it is in srcdir.
1362                     $rule .= ' $<';
1363                     # FIXME: handle .lo and .obj as well.
1364                     $output_rules .= "\t" . $rule . "\n";
1365                 }
1366             }
1368             # Transform .o or $o file into .P file (for automatic
1369             # dependency code).
1370             local ($depfile) = $object;
1371             $depfile =~ s/\.([^.]*)$/.P$1/;
1372             $depfile =~ s/\$\(OBJEXT\)$/o/ if $seen_objext;
1373             $dep_files{'$(DEPDIR)/' . $depfile} = 1;
1374         }
1375     }
1377     return (&resolve_linker (%linkers_used), @result);
1380 # Handle SOURCE->OBJECT transform for one program or library.
1381 # Arguments are:
1382 #   canonical (transformed) name of object to build
1383 #   actual name of object to build
1384 #   object extension (ie either `.o' or `$o'.
1385 # Return result is name of linker variable that must be used.
1386 # Empty return means just use `LINK'.
1387 sub handle_source_transform
1389     # one_file is canonical name.  unxformed is given name.  obj is
1390     # object extension.
1391     local ($one_file, $unxformed, $obj) = @_;
1393     local ($linker) = '';
1395     if (&variable_defined ($one_file . "_OBJECTS"))
1396     {
1397         &am_line_error ($one_file . '_OBJECTS',
1398                         $one_file . '_OBJECTS', 'should not be defined');
1399         # No point in continuing.
1400         return;
1401     }
1403     local (@files, @result, $prefix, $temp, $xpfx);
1404     local (%used_pfx) = ();
1405     foreach $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1406                      'dist_EXTRA_', 'nodist_EXTRA_')
1407     {
1408         # We are going to define _OBJECTS variables using the prefix.
1409         # Then we glom them all together.  So we can't use the null
1410         # prefix here as we need it later.
1411         $xpfx = ($prefix eq '') ? 'am_' : $prefix;
1413         @files = ();
1414         local ($var) = $prefix . $one_file . "_SOURCES";
1415         if (&variable_defined ($var))
1416         {
1417             # Keep track of which prefixes we saw.
1418             $used_pfx{$xpfx} = 1
1419                 unless $prefix =~ /EXTRA_/;
1421             push (@sources, '$(' . $prefix . $one_file . "_SOURCES)");
1422             push (@objects, '$(' . $xpfx . $one_file . "_OBJECTS)")
1423                 unless $prefix =~ /EXTRA_/;
1424             push (@dist_sources, '$(' . $prefix . $one_file . "_SOURCES)")
1425                 unless $prefix =~ /^nodist_/;
1426             local (@conds) = &variable_conditions ($var);
1427             if (! @conds)
1428             {
1429                 @files = &variable_value_as_list ($var, '');
1430             }
1431             else
1432             {
1433                 local ($cond);
1434                 foreach $cond (@conds)
1435                 {
1436                     @files = &variable_value_as_list ($var, $cond);
1437                     ($temp, @result) =
1438                         &handle_single_transform_list ($var, $one_file, $obj,
1439                                                        @files);
1440                     $linker = $temp if $linker eq '';
1442                     # Define _OBJECTS conditionally.
1443                     &define_pretty_variable ($xpfx . $one_file . '_OBJECTS',
1444                                              $cond, @result)
1445                         unless $prefix =~ /EXTRA_/;
1446                 }
1448                 next;
1449             }
1450         }
1452         # Avoid defining needless variables.
1453         next if (scalar @files == 0);
1455         ($temp, @result) = &handle_single_transform_list ($var, $one_file,
1456                                                           $obj, @files);
1457         $linker = $temp if $linker eq '';
1458         &define_pretty_variable ($xpfx . $one_file . "_OBJECTS", '', @result)
1459             unless $prefix =~ /EXTRA_/;
1460     }
1462     local (@keys) = sort keys %used_pfx;
1463     if (scalar @keys == 0)
1464     {
1465         &define_variable ($one_file . "_SOURCES", $unxformed . ".c");
1466         push (@sources, $unxformed . '.c');
1467         push (@dist_sources, $unxformed . '.c');
1468         push (@objects, $unxformed . $obj);
1469         push (@files, $unxformed . '.c');
1471         ($temp, @result) = &handle_single_transform_list ($one_file . '_SOURCES',
1472                                                           $one_file, $obj,
1473                                                           @files);
1474         $linker = $temp if $linker eq '';
1475         &define_pretty_variable ($one_file . "_OBJECTS", '', @result)
1476     }
1477     else
1478     {
1479         grep ($_ = '$(' . $_ . $one_file . '_OBJECTS)', @keys);
1480         &define_pretty_variable ($one_file . '_OBJECTS', '', @keys);
1481     }
1483     return $linker;
1486 # Handle the BUILT_SOURCES variable.
1487 sub handle_built_sources
1489     return unless &variable_defined ('BUILT_SOURCES');
1491     local (@sources) = &variable_value_as_list ('BUILT_SOURCES', 'all');
1492     local ($s);
1493     foreach $s (@sources)
1494     {
1495         if (/^\@.*\@$/)
1496         {
1497             # FIXME: is this really the right thing to do?
1498             &am_line_error ('BUILT_SOURCES',
1499                             "\`BUILT_SOURCES' should not contain a configure substitution");
1500             last;
1501         }
1502     }
1505 # Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
1506 # Also, generate _DEPENDENCIES variable if appropriate.
1507 # Arguments are:
1508 #   transformed name of object being built, or empty string if no object
1509 #   name of _LDADD/_LIBADD-type variable to examine
1510 #   boolean (lex_seen) which is true if a lex source file was seen in this
1511 #     object.  valid only for LDADDs, not LIBADDs.
1512 # Returns 1 if LIBOBJS seen, 0 otherwise.
1513 sub handle_lib_objects
1515     local ($xname, $var, $lex_seen) = @_;
1516     local ($ret);
1518     die "automake: programming error 1 in handle_lib_objects\n"
1519         if ! &variable_defined ($var);
1521     die "automake: programming error 2 in handle_lib_objects\n"
1522         if $lex_seen && $var =~ /LIBADD/;
1524     local (@conds) = &variable_conditions ($var);
1525     if (! @conds)
1526     {
1527         $ret = &handle_lib_objects_cond ($xname, $var, $lex_seen, '');
1528     }
1529     else
1530     {
1531         local ($cond);
1532         $ret = 0;
1533         foreach $cond (@conds)
1534         {
1535             if (&handle_lib_objects_cond ($xname, $var, $lex_seen, $cond))
1536             {
1537                 $ret = 1;
1538             }
1539         }
1540     }
1542     return $ret;
1545 # Subroutine of handle_lib_objects: handle a particular condition.
1546 sub handle_lib_objects_cond
1548     local ($xname, $var, $lex_seen, $cond) = @_;
1550     # We recognize certain things that are commonly put in LIBADD or
1551     # LDADD.
1552     local ($lsearch);
1553     local (@dep_list) = ();
1555     local ($seen_libobjs) = 0;
1556     local ($flagvar) = 0;
1558     foreach $lsearch (&variable_value_as_list ($var, $cond))
1559     {
1560         # Skip -lfoo and -Ldir; these are explicitly allowed.
1561         next if $lsearch =~ /^-[lL]/;
1562         if (! $flagvar && $lsearch =~ /^-/)
1563         {
1564             if ($var =~ /^(.*)LDADD$/)
1565             {
1566                 # Skip -dlopen and -dlpreopen; these are explicitly allowed.
1567                 next if $lsearch =~ /^-dl(pre)?open$/;
1568                 &am_line_error ($var, "linker flags such as \`$lsearch' belong in \`${1}LDFLAGS");
1569             }
1570             else
1571             {
1572                 # Only get this error once.
1573                 $flagvar = 1;
1574                 &am_line_error ($var, "linker flags such as \`$lsearch' belong in \`${1}LDFLAGS");
1575             }
1576         }
1578         # Assume we have a file of some sort, and push it onto the
1579         # dependency list.  Autoconf substitutions are not pushed;
1580         # rarely is a new dependency substituted into (eg) foo_LDADD
1581         # -- but "bad things (eg -lX11) are routinely substituted.
1582         # Note that LIBOBJS and ALLOCA are exceptions to this rule,
1583         # and handled specially below.
1584         push (@dep_list, $lsearch)
1585             unless $lsearch =~ /^\@.*\@$/;
1587         # Automatically handle @LIBOBJS@ and @ALLOCA@.  Basically this
1588         # means adding entries to dep_files.
1589         if ($lsearch =~ /^\@(LT)?LIBOBJS\@$/)
1590         {
1591             local ($myobjext) = ($1 ? 'l' : '') . 'o';
1593             push (@dep_list, $lsearch);
1594             $seen_libobjs = 1;
1595             if (! keys %libsources
1596                 && ! &variable_defined ($1 . 'LIBOBJS'))
1597             {
1598                 &am_line_error ($var, "\@$1" . "LIBOBJS\@ seen but never set in \`configure.in'");
1599             }
1601             local ($iter, $rewrite);
1602             foreach $iter (keys %libsources)
1603             {
1604                 if ($iter =~ /\.([cly])$/)
1605                 {
1606                     &saw_extension ($1);
1607                     &saw_extension ('c');
1608                 }
1610                 if ($iter =~ /\.h$/)
1611                 {
1612                     &require_file_with_line ($var, $FOREIGN, $iter);
1613                 }
1614                 elsif ($iter ne 'alloca.c')
1615                 {
1616                     ($rewrite = $iter) =~ s/\.c$/.P$myobjext/;
1617                     $dep_files{'$(DEPDIR)/' . $rewrite} = 1;
1618                     ($rewrite = $iter) =~ s/(\W)/\\$1/g;
1619                     $rewrite = "^" . $rewrite . "\$";
1620                     # Only require the file if it is not a built source.
1621                     if (! &variable_defined ('BUILT_SOURCES')
1622                         || ! grep (/$rewrite/,
1623                                    &variable_value_as_list ('BUILT_SOURCES',
1624                                                             'all')))
1625                     {
1626                         &require_file_with_line ($var, $FOREIGN, $iter);
1627                     }
1628                 }
1629             }
1630         }
1631         elsif ($lsearch =~ /^\@(LT)?ALLOCA\@$/)
1632         {
1633             local ($myobjext) = ($1 ? 'l' : '') . 'o';
1635             push (@dep_list, $lsearch);
1636             &am_line_error ($var,
1637                             "\@$1" . "ALLOCA\@ seen but \`AC_FUNC_ALLOCA' not in \`configure.in'")
1638                 if ! defined $libsources{'alloca.c'};
1639             $dep_files{'$(DEPDIR)/alloca.P' . $myobjext} = 1;
1640             &require_file_with_line ($var, $FOREIGN, 'alloca.c');
1641             &saw_extension ('c');
1642         }
1643     }
1645     if ($xname ne '' && ! &variable_defined ($xname . '_DEPENDENCIES', $cond))
1646     {
1647         &define_pretty_variable ($xname . '_DEPENDENCIES', $cond, @dep_list);
1648     }
1650     return $seen_libobjs;
1653 # Canonicalize a name, and check to make sure the non-canonical name
1654 # is never used.  Returns canonical name.  Arguments are name and a
1655 # list of suffixes to check for.
1656 sub check_canonical_spelling
1658     local ($name, @suffixes) = @_;
1659     local ($xname, $xt);
1661     ($xname = $name) =~ tr/A-Za-z0-9_/_/c;
1662     if ($xname ne $name)
1663     {
1664         local ($xt);
1665         foreach $xt (@suffixes)
1666         {
1667             &am_line_error ($name . $xt,
1668                             "invalid variable \`" . $name . $xt
1669                             . "'; should be \`" . $xname . $xt . "'")
1670                 if &variable_defined ($name . $xt);
1671         }
1672     }
1674     return $xname;
1677 # Handle C programs.
1678 sub handle_programs
1680     local (@proglist) = &am_install_var ('-clean',
1681                                          'progs', 'PROGRAMS',
1682                                          'bin', 'sbin', 'libexec', 'pkglib',
1683                                          'noinst', 'check');
1684     return if ! @proglist;
1686     # If a program is installed, this is required.  We only want this
1687     # error to appear once.
1688     &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
1689         unless $seen_arg_prog;
1690     $seen_arg_prog = 1;
1692     local ($one_file, $xname, $munge);
1694     local ($seen_libobjs) = 0;
1695     foreach $one_file (@proglist)
1696     {
1697         local ($obj) = &get_object_extension ($one_file);
1699         # Canonicalize names and check for misspellings.
1700         $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
1701                                             '_SOURCES', '_OBJECTS',
1702                                             '_DEPENDENCIES');
1704         # FIXME: Using a trick to figure out if any lex sources appear
1705         # in our program; should use some cleaner method.
1706         local ($lex_num) = scalar (keys %lex_sources);
1707         local ($linker) = &handle_source_transform ($xname, $one_file, $obj);
1708         local ($lex_file_seen) = (scalar (keys %lex_sources) > $lex_num);
1710         local ($xt) = '';
1711         if (&variable_defined ($xname . "_LDADD"))
1712         {
1713             if (&handle_lib_objects ($xname, $xname . '_LDADD',
1714                                      $lex_file_seen))
1715             {
1716                 $seen_libobjs = 1;
1717             }
1718             $lex_file_seen = 0;
1719             $xt = '_LDADD';
1720         }
1721         else
1722         {
1723             # User didn't define prog_LDADD override.  So do it.
1724             &define_variable ($xname . '_LDADD', '$(LDADD)');
1726             # This does a bit too much work.  But we need it to
1727             # generate _DEPENDENCIES when appropriate.
1728             if (&variable_defined ('LDADD'))
1729             {
1730                 if (&handle_lib_objects ($xname, 'LDADD', $lex_file_seen))
1731                 {
1732                     $seen_libobjs = 1;
1733                 }
1734                 $lex_file_seen = 0;
1735             }
1736             elsif (! &variable_defined ($xname . '_DEPENDENCIES'))
1737             {
1738                 &define_variable ($xname . '_DEPENDENCIES', '');
1739             }
1740             $xt = '_SOURCES'
1741         }
1743         if (&variable_defined ($xname . '_LIBADD'))
1744         {
1745             &am_line_error ($xname . '_LIBADD',
1746                             "use \`" . $xname . "_LDADD', not \`"
1747                             . $xname . "_LIBADD'");
1748         }
1750         if (! &variable_defined ($xname . '_LDFLAGS'))
1751         {
1752             # Define the prog_LDFLAGS variable.
1753             &define_variable ($xname . '_LDFLAGS', '');
1754         }
1756         # Determine program to use for link.
1757         local ($xlink);
1758         if (&variable_defined ($xname . '_LINK'))
1759         {
1760             $xlink = $xname . '_LINK';
1761         }
1762         else
1763         {
1764             $xlink = $linker ? $linker : 'LINK';
1765         }
1767         local ($xexe);
1768         if ($seen_exeext && $one_file !~ /\./)
1769         {
1770             $xexe = 's/\@EXEEXT\@/\$(EXEEXT)/g;';
1771         }
1772         else
1773         {
1774             $xexe = 's/\@EXEEXT\@//g;';
1775         }
1777         $output_rules .=
1778             &file_contents_with_transform
1779                 ('s/\@PROGRAM\@/' . $one_file . '/go;'
1780                  . 's/\@XPROGRAM\@/' . $xname . '/go;'
1781                  . 's/\@XLINK\@/' . $xlink . '/go;'
1782                  . $xexe,
1783                  'program');
1784     }
1786     if (&variable_defined ('LDADD') && &handle_lib_objects ('', 'LDADD', 0))
1787     {
1788         $seen_libobjs = 1;
1789     }
1791     if ($seen_libobjs)
1792     {
1793         foreach $one_file (@proglist)
1794         {
1795             # Canonicalize names.
1796             ($xname = $one_file) =~ tr/A-Za-z0-9_/_/c;
1798             if (&variable_defined ($xname . '_LDADD'))
1799             {
1800                 &check_libobjs_sources ($xname, $xname . '_LDADD');
1801             }
1802             elsif (&variable_defined ('LDADD'))
1803             {
1804                 &check_libobjs_sources ($xname, 'LDADD');
1805             }
1806         }
1807     }
1811 # Handle libraries.
1812 sub handle_libraries
1814     local (@liblist) = &am_install_var ('-clean',
1815                                         'libs', 'LIBRARIES',
1816                                         'lib', 'pkglib', 'noinst', 'check');
1817     return if ! @liblist;
1819     local (%valid) = &am_primary_prefixes ('LIBRARIES', 0, 'lib', 'pkglib',
1820                                            'noinst', 'check');
1821     if (! defined $configure_vars{'RANLIB'})
1822     {
1823         local ($key);
1824         foreach $key (keys %valid)
1825         {
1826             if (&variable_defined ($key . '_LIBRARIES'))
1827             {
1828                 &am_line_error ($key . '_LIBRARIES', "library used but \`RANLIB' not defined in \`configure.in'");
1829                 # Only get this error once.  If this is ever printed,
1830                 # we have a bug.
1831                 $configure_vars{'RANLIB'} = 'BUG';
1832                 last;
1833             }
1834         }
1835     }
1837     local ($onelib);
1838     local ($munge);
1839     local ($xlib);
1840     local ($seen_libobjs) = 0;
1841     foreach $onelib (@liblist)
1842     {
1843         # Check that the library fits the standard naming convention.
1844         if ($onelib !~ /^lib.*\.a$/)
1845         {
1846             # FIXME should put line number here.  That means mapping
1847             # from library name back to variable name.
1848             &am_error ("\`$onelib' is not a standard library name");
1849         }
1851         local ($obj) = &get_object_extension ($onelib);
1853         # Canonicalize names and check for misspellings.
1854         $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
1855                                            '_OBJECTS', '_DEPENDENCIES', '_AR');
1857         if (! &variable_defined ($xlib . '_AR'))
1858         {
1859             &define_variable ($xlib . '_AR', '$(AR) cru');
1860         }
1862         if (&variable_defined ($xlib . '_LIBADD'))
1863         {
1864             if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
1865             {
1866                 $seen_libobjs = 1;
1867             }
1868         }
1869         else
1870         {
1871             # Generate support for conditional object inclusion in
1872             # libraries.
1873             &define_variable ($xlib . "_LIBADD", '');
1874         }
1876         if (&variable_defined ($xlib . '_LDADD'))
1877         {
1878             &am_line_error ($xlib . '_LDADD',
1879                             "use \`" . $xlib . "_LIBADD', not \`"
1880                             . $xlib . "_LDADD'");
1881         }
1883         # Make sure we at look at this.
1884         &examine_variable ($xlib . '_DEPENDENCIES');
1886         &handle_source_transform ($xlib, $onelib, $obj);
1888         $output_rules .=
1889             &file_contents_with_transform ('s/\@LIBRARY\@/' . $onelib . '/go;'
1890                                            . 's/\@XLIBRARY\@/'
1891                                            . $xlib . '/go;',
1892                                            'library');
1893     }
1895     if ($seen_libobjs)
1896     {
1897         foreach $onelib (@liblist)
1898         {
1899             # Canonicalize names.
1900             ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
1901             if (&variable_defined ($xlib . '_LIBADD'))
1902             {
1903                 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
1904             }
1905         }
1906     }
1908     &define_variable ('AR', 'ar');
1909     &define_configure_variable ('RANLIB');
1912 # Handle shared libraries.
1913 sub handle_ltlibraries
1915     local (@liblist) = &am_install_var ('-clean',
1916                                         'ltlib', 'LTLIBRARIES',
1917                                         'noinst', 'lib', 'pkglib', 'check');
1918     return if ! @liblist;
1920     local (%instdirs);
1921     local (%valid) = &am_primary_prefixes ('LTLIBRARIES', 0, 'lib', 'pkglib',
1922                                            'noinst', 'check');
1924     local ($key);
1925     foreach $key (keys %valid)
1926     {
1927         if (&variable_defined ($key . '_LTLIBRARIES'))
1928         {
1929             if (!$seen_libtool)
1930             {
1931                 &am_line_error ($key . '_LTLIBRARIES', "library used but \`LIBTOOL' not defined in \`configure.in'");
1932                 # Only get this error once.  If this is ever printed,
1933                 # we have a bug.
1934                 $configure_vars{'LIBTOOL'} = 'BUG';
1935                 $seen_libtool = 1;
1936             }
1938             # Get the installation directory of each library.
1939             for (&variable_value_as_list ($key . '_LTLIBRARIES', 'all'))
1940             {
1941                 if ($instdirs{$_})
1942                 {
1943                     &am_error ("\`$_' is already going to be installed in \`$instdirs{$_}'");
1944                 }
1945                 else
1946                 {
1947                     $instdirs{$_} = $key;
1948                 }
1949             }
1950         }
1951     }
1953     local ($onelib);
1954     local ($munge);
1955     local ($xlib);
1956     local ($seen_libobjs) = 0;
1957     foreach $onelib (@liblist)
1958     {
1959         local ($obj) = &get_object_extension ($onelib);
1961         # Canonicalize names and check for misspellings.
1962         $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
1963                                            '_SOURCES', '_OBJECTS',
1964                                            '_DEPENDENCIES');
1966         if (! &variable_defined ($xlib . '_LDFLAGS'))
1967         {
1968             # Define the lib_LDFLAGS variable.
1969             &define_variable ($xlib . '_LDFLAGS', '');
1970         }
1972         # Check that the library fits the standard naming convention.
1973         $libname_rx = "^lib.*\.la";
1974         if (&variable_value ($xlib . '_LDFLAGS') =~ /-module/
1975             || &variable_value ('LDFLAGS') =~ /-module/) 
1976         {
1977                 # Relax name checking for libtool modules.
1978                 $libname_rx = "\.la";
1979         }
1980         if ($onelib !~ /$libname_rx$/)
1981         {
1982             # FIXME this should only be a warning for foreign packages
1983             # FIXME should put line number here.  That means mapping
1984             # from library name back to variable name.
1985             &am_error ("\`$onelib' is not a standard libtool library name");
1986         }
1988         if (&variable_defined ($xlib . '_LIBADD'))
1989         {
1990             if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
1991             {
1992                 $seen_libobjs = 1;
1993             }
1994         }
1995         else
1996         {
1997             # Generate support for conditional object inclusion in
1998             # libraries.
1999             &define_variable ($xlib . "_LIBADD", '');
2000         }
2002         if (&variable_defined ($xlib . '_LDADD'))
2003         {
2004             &am_line_error ($xlib . '_LDADD',
2005                             "use \`" . $xlib . "_LIBADD', not \`"
2006                             . $xlib . "_LDADD'");
2007         }
2009         # Make sure we at look at this.
2010         &examine_variable ($xlib . '_DEPENDENCIES');
2012         local ($linker) = &handle_source_transform ($xlib, $onelib, $obj);
2014         # Determine program to use for link.
2015         local ($xlink);
2016         if (&variable_defined ($xlib . '_LINK'))
2017         {
2018             $xlink = $xlib . '_LINK';
2019         }
2020         else
2021         {
2022             $xlink = $linker ? $linker : 'LINK';
2023         }
2025         local ($rpath);
2026         if ($instdirs{$onelib} eq 'EXTRA' || $instdirs{$onelib} eq 'noinst')
2027         {
2028             # It's an EXTRA_ library, so we can't specify -rpath,
2029             # because we don't know where the library will end up.
2030             # The user probably knows, but generally speaking automake
2031             # doesn't -- and in fact configure could decide
2032             # dynamically between two different locations.
2033             $rpath = 's/\@RPATH\@//go;';
2034         }
2035         else
2036         {
2037             $rpath = ('s/\@RPATH\@/-rpath \$(' . $instdirs{$onelib}
2038                       . 'dir)/go;');
2039         }
2041         $output_rules .=
2042             &file_contents_with_transform ('s/\@LTLIBRARY\@/'
2043                                            . $onelib . '/go;'
2044                                            . 's/\@XLTLIBRARY\@/'
2045                                            . $xlib . '/go;'
2046                                            . $rpath
2047                                            . 's/\@XLINK\@/' . $xlink . '/go;',
2048                                            'ltlibrary');
2049     }
2051     if ($seen_libobjs)
2052     {
2053         foreach $onelib (@liblist)
2054         {
2055             # Canonicalize names.
2056             ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
2057             if (&variable_defined ($xlib . '_LIBADD'))
2058             {
2059                 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2060             }
2061         }
2062     }
2065 # See if any _SOURCES variable were misspelled.  Also, make sure that
2066 # EXTRA_ variables don't contain configure substitutions.
2067 sub check_typos
2069     local ($varname, $primary);
2070     foreach $varname (keys %contents)
2071     {
2072         foreach $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
2073                           '_DEPENDENCIES')
2074         {
2075             if ($varname =~ /$primary$/ && ! $content_seen{$varname})
2076             {
2077                 &am_line_error ($varname,
2078                                 "invalid unused variable name: \`$varname'");
2079             }
2080         }
2081     }
2084 # Handle scripts.
2085 sub handle_scripts
2087     # NOTE we no longer automatically clean SCRIPTS, because it is
2088     # useful to sometimes distribute scripts verbatim.  This happens
2089     # eg in Automake itself.
2090     &am_install_var ('-candist', 'scripts', 'SCRIPTS',
2091                      'bin', 'sbin', 'libexec', 'pkgdata',
2092                      'noinst', 'check');
2094     local ($scripts_installed) = 0;
2095     # Set $scripts_installed if appropriate.  Make sure we only find
2096     # scripts which are actually installed -- this is why we can't
2097     # simply use the return value of am_install_var.
2098     local (%valid) = &am_primary_prefixes ('SCRIPTS', 1, 'bin', 'sbin',
2099                                            'libexec', 'pkgdata',
2100                                            'noinst', 'check');
2101     local ($key);
2102     foreach $key (keys %valid)
2103     {
2104         if ($key ne 'noinst'
2105             && $key ne 'check'
2106             && &variable_defined ($key . '_SCRIPTS'))
2107         {
2108             $scripts_installed = 1;
2109             # push (@check_tests, 'check-' . $key . 'SCRIPTS');
2110         }
2111     }
2113     if ($scripts_installed)
2114     {
2115         # If a program is installed, this is required.  We only want this
2116         # error to appear once.
2117         &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
2118             unless $seen_arg_prog;
2119         $seen_arg_prog = 1;
2120     }
2123 # Search a file for a "version.texi" Texinfo include.  Return the name
2124 # of the include file if found, or the empty string if not.  A
2125 # "version.texi" file is actually any file whose name matches
2126 # "vers*.texi".
2127 sub scan_texinfo_file
2129     local ($filename) = @_;
2131     if (! open (TEXI, $filename))
2132     {
2133         &am_error ("couldn't open \`$filename': $!");
2134         return '';
2135     }
2136     print "automake: reading $filename\n" if $verbose;
2138     local ($vfile, $outfile);
2139     while (<TEXI>)
2140     {
2141         if (/^\@setfilename +(\S+)/)
2142         {
2143             $outfile = $1;
2144             last if ($vfile);
2145         }
2147         if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
2148         {
2149             # Found version.texi include.
2150             $vfile = $1;
2151             last if $outfile;
2152         }
2153     }
2155     close (TEXI);
2156     return ($outfile, $vfile);
2159 # Handle all Texinfo source.
2160 sub handle_texinfo
2162     &am_line_error ('TEXINFOS',
2163                     "\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
2164         if &variable_defined ('TEXINFOS');
2165     return if (! &variable_defined ('info_TEXINFOS')
2166                && ! &variable_defined ('html_TEXINFOS'));
2168     if (&variable_defined ('html_TEXINFOS'))
2169     {
2170         &am_line_error ('html_TEXINFOS',
2171                         "HTML generation not yet supported");
2172         return;
2173     }
2175     local (@texis) = &variable_value_as_list ('info_TEXINFOS', 'all');
2177     local (@info_deps_list, @dvis_list, @texi_deps);
2178     local ($infobase, $info_cursor);
2179     local (%versions);
2180     local ($done) = 0;
2181     local ($vti);
2182     local ($tc_cursor, @texi_cleans);
2183     local ($canonical);
2185     foreach $info_cursor (@texis)
2186     {
2187         # FIXME: This is mildly hacky, since it recognizes "txinfo".
2188         # I don't feel like making it right.
2189         ($infobase = $info_cursor) =~ s/\.te?xi(nfo)?$//;
2191         # If 'version.texi' is referenced by input file, then include
2192         # automatic versioning capability.
2193         local ($out_file, $vtexi) = &scan_texinfo_file ($relative_dir
2194                                                         . "/" . $info_cursor);
2196         if ($out_file eq '')
2197         {
2198             &am_error ("\`$info_cursor' missing \@setfilename");
2199             next;
2200         }
2202         if ($out_file =~ /\.(.+)$/ && $1 ne 'info')
2203         {
2204             # FIXME should report line number in input file.
2205             &am_error ("output of \`$info_cursor', \`$out_file', has unrecognized extension");
2206             next;
2207         }
2209         if ($vtexi)
2210         {
2211             &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
2212                 if (defined $versions{$vtexi});
2213             $versions{$vtexi} = $info_cursor;
2215             # We number the stamp-vti files.  This is doable since the
2216             # actual names don't matter much.  We only number starting
2217             # with the second one, so that the common case looks nice.
2218             $vti = ($done ? $done : 'vti');
2219             &push_dist_common ($vtexi, 'stamp-' . $vti);
2220             push (@clean, $vti);
2222             # Only require once.
2223             &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
2224                                           'mdate-sh')
2225                 if ! $done;
2226             ++$done;
2228             local ($conf_pat, $conf_dir);
2229             if ($config_aux_dir eq '.' || $config_aux_dir eq '')
2230             {
2231                 $conf_dir = '$(srcdir)/';
2232             }
2233             else
2234             {
2235                 $conf_dir = $config_aux_dir;
2236                 $conf_dir .= '/' unless $conf_dir =~ /\/$/;
2237             }
2238             ($conf_pat = $conf_dir) =~ s/(\W)/\\$1/g;
2239             $output_rules .=
2240                 &file_contents_with_transform
2241                     ('s/\@TEXI\@/' . $info_cursor . '/g; '
2242                      . 's/\@VTI\@/' . $vti . '/g; '
2243                      . 's/\@VTEXI\@/' . $vtexi . '/g;'
2244                      . 's,\@MDDIR\@,' . $conf_pat . ',g;',
2245                      'texi-vers');
2247             &push_phony_cleaners ($vti);
2248         }
2250         # If user specified file_TEXINFOS, then use that as explicit
2251         # dependency list.
2252         @texi_deps = ();
2253         push (@texi_deps, $info_cursor);
2254         push (@texi_deps, $vtexi) if $vtexi;
2256         # Canonicalize name first.
2257         ($canonical = $infobase) =~ tr/A-Za-z0-9_/_/c;
2258         if (&variable_defined ($canonical . "_TEXINFOS"))
2259         {
2260             push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
2261             &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
2262         }
2264         $output_rules .= ("\n" . $out_file . ": "
2265                           . join (' ', @texi_deps)
2266                           . "\n" . $infobase . ".dvi: "
2267                           . join (' ', @texi_deps)
2268                           . "\n\n");
2270         push (@info_deps_list, $out_file);
2271         push (@dvis_list, $infobase . '.dvi');
2273         # Generate list of things to clean for this target.  We do
2274         # this explicitly because otherwise too many things could be
2275         # removed.  In particular the ".log" extension might
2276         # reasonably be used in other contexts by the user.
2277         # FIXME: this is really out of control.
2278         foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns', 'pgs',
2279                             'ky', 'kys', 'ps', 'log', 'pg', 'toc', 'tp', 'tps',
2280                             'vr', 'vrs', 'op', 'tr', 'cv', 'cn', 'cm', 'ov')
2281         {
2282             push (@texi_cleans, $infobase . '.' . $tc_cursor);
2283         }
2284     }
2286     # Find these programs wherever they may lie.  Yes, this has
2287     # intimate knowledge of the structure of the texinfo distribution.
2288     &define_program_variable ('MAKEINFO', 'build', 'texinfo/makeinfo',
2289                               'makeinfo',
2290                               # Circumlocution to avoid accidental
2291                               # configure substitution.
2292                               '@MAKE' . 'INFO@');
2293     &define_program_variable ('TEXI2DVI', 'src', 'texinfo/util',
2294                               'texi2dvi');
2296     # Set transform for including texinfos.am.  First, handle --cygnus
2297     # stuff.
2298     local ($xform);
2299     if ($cygnus_mode)
2300     {
2301         $xform = 's/^NOTCYGNUS.*$//; s/^CYGNUS//;';
2302     }
2303     else
2304     {
2305         $xform = 's/^CYGNUS.*$//; s/^NOTCYGNUS//;';
2306     }
2308     # Handle location of texinfo.tex.
2309     local ($need_texi_file) = 0;
2310     local ($texinfo_tex);
2311     if ($cygnus_mode)
2312     {
2313         $texinfo_tex = '$(top_srcdir)/../texinfo/texinfo.tex';
2314         &define_variable ('TEXINFO_TEX', $texinfo_tex);
2316     }
2317     elsif ($config_aux_dir ne '.' && $config_aux_dir ne '')
2318     {
2319         $texinfo_tex = $config_aux_dir . '/texinfo.tex';
2320         &define_variable ('TEXINFO_TEX', $texinfo_tex);
2321         $need_texi_file = 2; # so that we require_conf_file later
2322     }
2323     elsif (&variable_defined ('TEXINFO_TEX'))
2324     {
2325         # The user defined TEXINFO_TEX so assume he knows what he is
2326         # doing.
2327         $texinfo_tex = ('$(srcdir)/'
2328                         . &dirname (&variable_value ('TEXINFO_TEX')));
2329     }
2330     else
2331     {
2332         $texinfo_tex = '$(srcdir)/texinfo.tex';
2333         $need_texi_file = 1;
2334     }
2335     local ($xxform);
2336     ($xxform = $texinfo_tex) =~ s/\/texinfo\.tex$//;
2337     $xxform =~ s/(\W)/\\$1/g;
2338     $xform .= ' s/\@TEXINFODIR\@/' . $xxform . '/g;';
2340     $output_rules .= &file_contents_with_transform ($xform, 'texinfos');
2341     push (@phony, 'install-info-am', 'uninstall-info');
2342     push (@dist_targets, 'dist-info');
2344     # How to clean.  The funny name is due to --cygnus influence; in
2345     # Cygnus mode, `clean-info' is a target that users can use.
2346     $output_rules .= "\nmostlyclean-aminfo:\n";
2347     &pretty_print_rule ("\t-rm -f", "\t  ", @texi_cleans);
2348     $output_rules .= ("\nclean-aminfo:\n\ndistclean-aminfo:\n\n"
2349                       . "maintainer-clean-aminfo:\n\t"
2350                       # Eww.  But how else can we find all the output
2351                       # files from makeinfo?
2352                       . ($cygnus_mode ? '' : 'cd $(srcdir) && ')
2353                       . 'for i in $(INFO_DEPS); do' . " \\\n"
2354                       . "\t" . '  rm -f $$i;' . " \\\n"
2355                       . "\t" . '  if test "`echo $$i-[0-9]*`" != "$$i-[0-9]*"; then' . " \\\n"
2356                       . "\t" . '    rm -f $$i-[0-9]*;' . " \\\n"
2357                       . "\t" . '  fi;' . " \\\n"
2358                       . "\tdone\n");
2359     &push_phony_cleaners ('aminfo');
2360     if ($cygnus_mode)
2361     {
2362         $output_rules .= "clean-info: mostlyclean-aminfo\n";
2363     }
2365     push (@suffixes, '.texi', '.texinfo', '.txi', '.info', '.dvi', '.ps');
2367     if (! defined $options{'no-installinfo'})
2368     {
2369         push (@uninstall, 'uninstall-info');
2370         push (@installdirs, '$(DESTDIR)$(infodir)');
2371         unshift (@install_data, 'install-info-am');
2373         # Make sure documentation is made and installed first.  Use
2374         # $(INFO_DEPS), not 'info', because otherwise recursive makes
2375         # get run twice during "make all".
2376         unshift (@all, '$(INFO_DEPS)');
2377     }
2378     push (@clean, 'aminfo');
2379     push (@info, '$(INFO_DEPS)');
2380     push (@dvi, '$(DVIS)');
2382     &define_variable ("INFO_DEPS", join (' ', @info_deps_list));
2383     &define_variable ("DVIS", join (' ', @dvis_list));
2384     # This next isn't strictly needed now -- the places that look here
2385     # could easily be changed to look in info_TEXINFOS.  But this is
2386     # probably better, in case noinst_TEXINFOS is ever supported.
2387     &define_variable ("TEXINFOS", &variable_value ('info_TEXINFOS'));
2389     # Do some error checking.  Note that this file is not required
2390     # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
2391     # up above.
2392     if ($need_texi_file && ! defined $options{'no-texinfo.tex'})
2393     {
2394         if ($need_texi_file > 1)
2395         {
2396             &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
2397                                           'texinfo.tex');
2398         }
2399         else
2400         {
2401             &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex');
2402         }
2403     }
2406 # Handle any man pages.
2407 sub handle_man_pages
2409     &am_line_error ('MANS', "\`MANS' is an anachronism; use \`man_MANS'")
2410         if &variable_defined ('MANS');
2411     return if ! &variable_defined ('man_MANS');
2413     # Find all the sections in use.  We do this by first looking for
2414     # "standard" sections, and then looking for any additional
2415     # sections used in man_MANS.
2416     local ($sect, %sections, %vlist);
2417     # Add more sections as needed.
2418     foreach $sect ('0'..'9', 'n', 'l')
2419     {
2420         if (&variable_defined ('man' . $sect . '_MANS'))
2421         {
2422             $sections{$sect} = 1;
2423             $vlist{'$(man' . $sect . '_MANS)'} = 1;
2424         }
2425     }
2427     if (&variable_defined ('man_MANS'))
2428     {
2429         $vlist{'$(man_MANS)'} = 1;
2430         foreach (&variable_value_as_list ('man_MANS', 'all'))
2431         {
2432             # A page like `foo.1c' goes into man1dir.
2433             if (/\.([0-9a-z])([a-z]*)$/)
2434             {
2435                 $sections{$1} = 1;
2436             }
2437         }
2438     }
2441     # Now for each section, generate an install and unintall rule.
2442     # Sort sections so output is deterministic.
2443     local (@namelist);
2444     foreach $sect (sort keys %sections)
2445     {
2446         &define_variable ('man' . $sect . 'dir', '$(mandir)/man' . $sect);
2447         push (@installdirs, '$(DESTDIR)$(mandir)/man' . $sect)
2448             unless defined $options{'no-installman'};
2449         $output_rules .= &file_contents_with_transform ('s/\@SECTION\@/'
2450                                                         . $sect . '/g;',
2451                                                         'mans');
2452         push (@phony, 'install-man' . $sect, 'uninstall-man' . $sect);
2453         push (@namelist, 'install-man' . $sect);
2454     }
2456     # We don't really need this, but we use it in case we ever want to
2457     # support noinst_MANS.
2458     &define_variable ("MANS", join (' ', sort keys %vlist));
2460     # Generate list of install dirs.
2461     $output_rules .= ("install-man: \$(MANS)\n"
2462                       . "\t\@\$(NORMAL_INSTALL)\n");
2463     &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ", @namelist);
2464     push (@phony, 'install-man');
2466     $output_rules .= "uninstall-man:\n\t\@\$(NORMAL_UNINSTALL)\n";
2467     grep ($_ = 'un' . $_, @namelist);
2468     &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ", @namelist);
2469     push (@phony, 'uninstall-man');
2471     $output_vars .= &file_contents ('mans-vars');
2473     if (! defined $options{'no-installman'})
2474     {
2475         push (@install_data, 'install-man');
2476         push (@uninstall, 'uninstall-man');
2477         push (@all, '$(MANS)');
2478     }
2481 # Handle DATA variables.
2482 sub handle_data
2484     &am_install_var ('-noextra', '-defaultdist', 'data', 'DATA',
2485                      'data', 'sysconf', 'sharedstate', 'localstate',
2486                      'pkgdata', 'noinst', 'check');
2489 # Handle TAGS.
2490 sub handle_tags
2492     push (@phony, 'tags');
2493     local (@tag_deps) = ();
2494     if (&variable_defined ('SUBDIRS'))
2495     {
2496         $output_rules .= ("tags-recursive:\n"
2497                           . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
2498                           # Never fail here if a subdir fails; it
2499                           # isn't important.
2500                           . "\t  test \"\$\$subdir\" = . || (cd \$\$subdir"
2501                           . " && \$(MAKE) \$(AM_MAKEFLAGS) tags); \\\n"
2502                           . "\tdone\n");
2503         push (@tag_deps, 'tags-recursive');
2504         push (@phony, 'tags-recursive');
2505     }
2507     if (&saw_sources_p (1)
2508         || &variable_defined ('ETAGS_ARGS')
2509         || @tag_deps)
2510     {
2511         local ($xform) = '';
2512         local ($one_hdr);
2513         foreach $one_hdr (@config_headers)
2514         {
2515             if ($relative_dir eq &dirname ($one_hdr))
2516             {
2517                 # The config header is in this directory.  So require it.
2518                 local ($var);
2519                 ($var = &basename ($one_hdr)) =~ s/(\W)/\\$1/g;
2520                 $xform .= ' ' if $xform;
2521                 $xform .= $var;
2522             }
2523         }
2524         $xform = ('s/\@CONFIG\@/' . $xform . '/;'
2525                   . 's/\@DIRS\@/' . join (' ', @tag_deps) . '/;');
2527         if (&variable_defined ('SUBDIRS'))
2528         {
2529             $xform .= 's/^SUBDIRS//;';
2530         }
2531         else
2532         {
2533             $xform .= 's/^SUBDIRS.*$//;';
2534         }
2536         $output_rules .= &file_contents_with_transform ($xform, 'tags');
2537         $output_rules .= &file_contents ('tags-clean');
2538         push (@clean, 'tags');
2539         &push_phony_cleaners ('tags');
2540         &examine_variable ('TAGS_DEPENDENCIES');
2541     }
2542     elsif (&variable_defined ('TAGS_DEPENDENCIES'))
2543     {
2544         &am_line_error ('TAGS_DEPENDENCIES',
2545                         "doesn't make sense to define \`TAGS_DEPENDENCIES' without sources or \`ETAGS_ARGS'");
2546     }
2547     else
2548     {
2549         # Every Makefile must define some sort of TAGS rule.
2550         # Otherwise, it would be possible for a top-level "make TAGS"
2551         # to fail because some subdirectory failed.
2552         $output_rules .= "tags: TAGS\nTAGS:\n\n";
2553     }
2556 # Handle multilib support.
2557 sub handle_multilib
2559     return unless $seen_multilib;
2561     $output_rules .= &file_contents ('multilib.am');
2562     &push_phony_cleaners ('multi');
2563     push (@phony, 'all-multi', 'install-multi');
2566 # Worker for handle_dist.
2567 sub handle_dist_worker
2569     local ($makefile) = @_;
2571     $output_rules .= 'distdir: $(DISTFILES)' . "\n";
2573     # Initialization; only at top level.
2574     if ($relative_dir eq '.')
2575     {
2576         if (defined $options{'check-news'})
2577         {
2578             # For Gnits users, this is pretty handy.  Look at 15 lines
2579             # in case some explanatory text is desirable.
2580             $output_rules .= '  @if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" > /dev/null; then :; else \\
2581           echo "NEWS not updated; not releasing" 1>&2; \\
2582           exit 1; \\
2583         fi
2585         }
2588         # Create dist directory.
2589         $output_rules .= ("\t-chmod -R a+w \$(distdir) > /dev/null 2>&1; rm -rf \$(distdir)\n"
2590                           . "\tmkdir \$(distdir)\n");
2591     }
2593     # Scan EXTRA_DIST to see if we need to distribute anything from a
2594     # subdir.  If so, add it to the list.  I didn't want to do this
2595     # originally, but there were so many requests that I finally
2596     # relented.
2597     local (@dist_dirs);
2598     if (&variable_defined ('EXTRA_DIST'))
2599     {
2600         # FIXME: This should be fixed to work with conditionals.  That
2601         # will require only making the entries in @dist_dirs under the
2602         # appropriate condition.  This is meaningful if the nature of
2603         # the distribution should depend upon the configure options
2604         # used.
2605         foreach (&variable_value_as_list ('EXTRA_DIST', ''))
2606         {
2607             next if /^\@.*\@$/;
2608             next unless s,/+[^/]+$,,;
2609             push (@dist_dirs, $_)
2610                 unless $_ eq '.';
2611         }
2612     }
2613     if (@dist_dirs)
2614     {
2615         # Prepend $(distdir) to each directory given.  Doing it via a
2616         # hash lets us ensure that each directory is used only once.
2617         local (%dhash);
2618         grep ($dhash{'$(distdir)/' . $_} = 1, @dist_dirs);
2619         $output_rules .= "\t";
2620         &pretty_print_rule ('$(mkinstalldirs)', "\t   ", sort keys %dhash);
2621     }
2623     # In loop, test for file existence because sometimes a file gets
2624     # included in DISTFILES twice.  For example this happens when a
2625     # single source file is used in building more than one program.
2626     # Also, there are situations in which "ln" can fail.  For instance
2627     # a file to distribute could actually be a cross-filesystem
2628     # symlink -- this can easily happen if "gettextize" was run on the
2629     # distribution.
2630     $output_rules .= "\t\@for file in \$(DISTFILES); do \\\n";
2631     if ($cygnus_mode)
2632     {
2633         $output_rules .= "\t  if test -f \$\$file; then d=.; else d=\$(srcdir); fi; \\\n";
2634     }
2635     else
2636     {
2637         $output_rules .= "\t  d=\$(srcdir); \\\n";
2638     }
2639     $output_rules .= ("\t  if test -d \$\$d/\$\$file; then \\\n"
2640                       # Don't mention $$file in destination argument,
2641                       # since this fails if destination directory
2642                       # already exists.  Also, use `-R' and not `-r'.
2643                       # `-r' is almost always incorrect.
2644                       . "\t    cp -pR \$\$d/\$\$file \$(distdir); \\\n"
2645                       . "\t  else \\\n"
2646                       . "\t    test -f \$(distdir)/\$\$file \\\n"
2647                       . "\t    || ln \$\$d/\$\$file \$(distdir)/\$\$file 2> /dev/null \\\n"
2648                       . "\t    || cp -p \$\$d/\$\$file \$(distdir)/\$\$file || :; \\\n"
2649                       . "\t  fi; \\\n"
2650                       . "\tdone\n");
2652     # If we have SUBDIRS, create all dist subdirectories and do
2653     # recursive build.
2654     if (&variable_defined ('SUBDIRS'))
2655     {
2656         # If SUBDIRS is conditionally defined, then set DIST_SUBDIRS
2657         # to all possible directories, and use it.  If DIST_SUBDIRS is
2658         # defined, just use it.
2659         local ($dist_subdir_name);
2660         if (&variable_conditions ('SUBDIRS')
2661             || &variable_defined ('DIST_SUBDIRS'))
2662         {
2663             $dist_subdir_name = 'DIST_SUBDIRS';
2664             if (! &variable_defined ('DIST_SUBDIRS'))
2665             {
2666                 local (@full_list) = &variable_value_as_list ('SUBDIRS',
2667                                                               'all');
2668                 local (@ds_list, %uniq, $iter);
2669                 foreach $iter (@full_list)
2670                 {
2671                     if (! defined $uniq{$iter})
2672                     {
2673                         $uniq{$iter} = 1;
2674                         push (@ds_list, $iter);
2675                     }
2676                 }
2677                 &define_pretty_variable ('DIST_SUBDIRS', '', @ds_list);
2678             }
2679         }
2680         else
2681         {
2682             $dist_subdir_name = 'SUBDIRS';
2683         }
2685         # Test for directory existence here because previous automake
2686         # invocation might have created some directories.  Note that
2687         # we explicitly set distdir for the subdir make; that lets us
2688         # mix-n-match many automake-using packages into one large
2689         # package, and have "dist" at the top level do the right
2690         # thing.  If we're in the topmost directory, then we use
2691         # `distdir' instead of `top_distdir'; this lets us work
2692         # correctly with an enclosing package.
2693         $output_rules .= 
2694             ("\t" . 'for subdir in $(' . $dist_subdir_name . '); do ' . "\\\n"
2695              . "\t" . '  if test "$$subdir" = .; then :; else ' . "\\\n"
2696              . "\t" . '    test -d $(distdir)/$$subdir ' . "\\\n"
2697              . "\t" . '    || mkdir $(distdir)/$$subdir ' . "\\\n"
2698              . "\t" . '    || exit 1; ' . "\\\n"
2699              . "\t" . '    (cd $$subdir'
2700              . ' && $(MAKE) $(AM_MAKEFLAGS) top_distdir=../$('
2701              . (($relative_dir eq '.') ? 'distdir' : 'top_distdir')
2702              . ') distdir=../$(distdir)/$$subdir distdir) ' . "\\\n"
2703              . "\t" . '      || exit 1; ' . "\\\n"
2704              . "\t" . '  fi; ' . "\\\n"
2705              . "\tdone\n");
2706     }
2708     # If the target `dist-hook' exists, make sure it is run.  This
2709     # allows users to do random weird things to the distribution
2710     # before it is packaged up.
2711     push (@dist_targets, 'dist-hook') if &target_defined ('dist-hook');
2713     local ($targ);
2714     foreach $targ (@dist_targets)
2715     {
2716         # We must explicitly set distdir and top_distdir for these
2717         # sub-makes.
2718         $output_rules .= ("\t\$(MAKE) \$(AM_MAKEFLAGS)"
2719                           . " top_distdir=\"\$(top_distdir)\""
2720                           . " distdir=\"\$(distdir)\" $targ\n");
2721     }
2723     push (@phony, 'distdir');
2726 # Handle 'dist' target.
2727 sub handle_dist
2729     local ($makefile) = @_;
2731     # Set up maint_charset.
2732     $local_maint_charset = &variable_value ('MAINT_CHARSET')
2733         if &variable_defined ('MAINT_CHARSET');
2734     $maint_charset = $local_maint_charset
2735         if $relative_dir eq '.';
2737     if (&variable_defined ('DIST_CHARSET'))
2738     {
2739         &am_line_error ('DIST_CHARSET',
2740                         "DIST_CHARSET defined but no MAINT_CHARSET defined")
2741             if ! $local_maint_charset;
2742         if ($relative_dir eq '.')
2743         {
2744             $dist_charset = &variable_value ('DIST_CHARSET')
2745         }
2746         else
2747         {
2748             &am_line_error ('DIST_CHARSET',
2749                             "DIST_CHARSET can only be defined at top level");
2750         }
2751     }
2753     # Look for common files that should be included in distribution.
2754     local ($cfile);
2755     foreach $cfile (@common_files)
2756     {
2757         if (-f ($relative_dir . "/" . $cfile))
2758         {
2759             &push_dist_common ($cfile);
2760         }
2761     }
2763     # Always require configure.in and configure at top level, even if
2764     # they don't exist.  This is especially important for configure,
2765     # since it won't be created until autoconf is run -- which might
2766     # be after automake is run.
2767     &push_dist_common ('configure.in', 'configure')
2768         if $relative_dir eq '.';
2770     # Keys of %dist_common are names of files to distributed.  We put
2771     # README first because it then becomes easier to make a
2772     # Usenet-compliant shar file (in these, README must be first).
2773     # FIXME: do more ordering of files here.
2774     local (@coms);
2775     if (defined $dist_common{'README'})
2776     {
2777         push (@coms, 'README');
2778         delete $dist_common{'README'};
2779     }
2780     push (@coms, sort keys %dist_common);
2782     &define_pretty_variable ("DIST_COMMON", '', @coms);
2783     $output_vars .= "\n";
2785     # Some boilerplate.
2786     $output_vars .= &file_contents ('dist-vars') . "\n";
2787     &define_variable ('GZIP_ENV', '--best');
2789     # Put these things in rules section so it is easier for whoever
2790     # reads Makefile.in.
2791     if (! &variable_defined ('distdir'))
2792     {
2793         if ($relative_dir eq '.')
2794         {
2795             $output_rules .= "\n" . 'distdir = $(PACKAGE)-$(VERSION)' . "\n";
2796         }
2797         else
2798         {
2799             $output_rules .= ("\n"
2800                               . 'distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)'
2801                               . "\n");
2802         }
2803     }
2804     if ($relative_dir eq '.')
2805     {
2806         $output_rules .= "top_distdir = \$(distdir)\n";
2807     }
2808     $output_rules .= "\n";
2810     # Generate 'dist' target, and maybe other dist targets.
2811     if ($relative_dir eq '.')
2812     {
2813         # Rule to check whether a distribution is viable.
2814         local ($xform) = '';
2816         if (&target_defined ('distcheck-hook'))
2817         {
2818             $xform .= 's/^DISTHOOK//;';
2819         }
2820         else
2821         {
2822             $xform .= 's/^DISTHOOK.*$//;';
2823         }
2824         if ($seen_gettext)
2825         {
2826             $xform .= 's/^GETTEXT//;';
2827         }
2828         else
2829         {
2830             $xform .= 's/^GETTEXT.*$//;';
2831         }
2833         $output_rules .= &file_contents_with_transform ($xform, 'dist');
2835         local ($dist_all) = ('dist-all: distdir' . "\n"
2836                              . $dist_header);
2837         local ($curs);
2838         foreach $curs ('dist', 'dist-shar', 'dist-zip', 'dist-tarZ',
2839                        'dist-bzip2')
2840         {
2841             if (defined $options{$curs} || $curs eq 'dist')
2842             {
2843                 $output_rules .= ($curs . ': distdir' . "\n"
2844                                   . $dist_header
2845                                   . $dist{$curs}
2846                                   . $dist_trailer);
2847                 $dist_all .= $dist{$curs};
2848             }
2849         }
2850         $output_rules .= $dist_all . $dist_trailer;
2851     }
2853     # Generate distdir target.
2854     &handle_dist_worker ($makefile);
2857 # A subroutine of handle_dependencies.  This function includes
2858 # `depend2' with appropriate transformations.
2859 sub add_depend2
2861     local ($lang) = @_;
2863     # First include code for ordinary objects.
2864     local ($key) = $lang . '-autodep';
2865     local ($xform, $ext);
2867     local ($pfx) = $language_map{$key};
2868     local ($fpfx) = ($pfx eq '') ? 'CC' : $pfx;
2869     $xform = ('s/\@PFX\@/' . $pfx . '/g;'
2870               . 's/\@FPFX\@/' . $fpfx . '/g;'
2871               . ($seen_objext ? 's/^OBJEXT//;' : 's/^OBJEXT.*$//;')
2872               . ($seen_libtool ? 's/^LIBTOOL//;' : 's/^LIBTOOL.*$//;'));
2874     # This function can be called even when we don't want dependency
2875     # tracking.  This happens when we need an explicit rule for some
2876     # target.  In this case we don't want to include the generic code.
2877     if ($use_dependencies)
2878     {
2879         local ($xform1) = ($xform
2880                            . 's/\@BASE\@/\$\*/g;'
2881                            . 's/\@SOURCE\@/\$\</g;'
2882                            . 's/\@(LT|OBJ)?OBJ\@/\$\@/g;');
2884         foreach $ext (&lang_extensions ($lang))
2885         {
2886             $output_rules .= (&file_contents_with_transform ('s/\@EXT\@/'
2887                                                              . $ext . '/g;'
2888                                                              . $xform1,
2889                                                              'depend2')
2890                               . "\n");
2891         }
2892     }
2894     # Now include code for each specially handled object with this
2895     # language.
2896     local (@list) = grep ($_ ne '', split (' ', $lang_specific_files{$lang}));
2897     local ($max) = scalar @list;
2898     local ($i) = 0;
2899     local ($derived, $source, $obj);
2901     # If dependency tracking is disabled, we just elide the code.
2902     if (! $use_dependencies)
2903     {
2904         $xform .= 's/\@AMDEP\@.*$//;';
2905     }
2907     while ($i < $max)
2908     {
2909         $derived = $list[$i];
2910         ($source = $list[$i + 1]) =~ s,([/\$]),\\$1,g;
2911         ($obj = $list[$i + 2]) =~ s,([/\$]),\\$1,g;
2912         $i += 3;
2914         local ($flag) = $language_map{$lang . '-flags'};
2915         local ($val) = "(${derived}_${flag}";
2916         ($rule = $language_map{$lang . '-compile'}) =~    
2917             s/\(AM_$flag/$val/;
2919         $rule =~ s,([/\$]),\\$1,g;
2921         # Generate a transform which will turn suffix targets in
2922         # depend2.am into real targets for the particular objects we
2923         # are building.
2924         $output_rules .=
2925             &file_contents_with_transform ($xform
2926                                            . 's/\$\(' . $pfx . 'COMPILE\)/'
2927                                            . $rule . '/g;'
2928                                            . 's/\$\(LT' . $pfx . 'COMPILE\)/'
2929                                            . '\$(LIBTOOL) --mode=compile '
2930                                            . $rule . '/g;'
2931                                            # Generate rule for `.o'.
2932                                            . 's/^\@EXT\@\.o:/'
2933                                            . $obj . '.o: ' . $source
2934                                            . '/g;'
2935                                            # Maybe generate rule for `.lo'.
2936                                            # Might be eliminated by
2937                                            # $XFORM.
2938                                            . 's/^\@EXT\@\.lo:/'
2939                                            . $obj . '.lo: ' . $source
2940                                            . '/g;'
2941                                            # Maybe generate rule for `.obj'.
2942                                            # Might be eliminated by
2943                                            # $XFORM.
2944                                            . 's/^\@EXT\@\.obj:/'
2945                                            . $obj . '.obj: ' . $source
2946                                            . '/g;'
2947                                            # Handle source and obj
2948                                            # transforms.
2949                                            . 's/\@OBJ\@/' . $obj . '.o/g;'
2950                                            . 's/\@OBJOBJ\@/' . $obj . '.obj/g;'
2951                                            . 's/\@LTOBJ\@/' . $obj . '.lo/g;'
2952                                            . 's/\@BASE\@/' . $obj . '/g;'
2953                                            . 's/\@SOURCE\@/' . $source . '/g;',
2954                                            'depend2');
2955     }
2958 # Handle auto-dependency code.
2959 sub handle_dependencies
2961     if ($use_dependencies)
2962     {
2963         # Include auto-dep code.  Don't include it if DEP_FILES would
2964         # be empty.
2965         if (&saw_sources_p (0) && keys %dep_files)
2966         {
2967             # Set location of depcomp.
2968             if ($config_aux_dir ne '.' && $config_aux_dir ne '')
2969             {
2970                 &define_variable ('depcomp', ('$(SHELL) ' . $config_aux_dir
2971                                               . '/depcomp'));
2972             }
2973             else
2974             {
2975                 &define_variable ('depcomp',
2976                                   '$(SHELL) $(top_srcdir)/depcomp');
2977             }
2979             local ($iter);
2980             local (@deplist) = sort keys %dep_files;
2982             &define_pretty_variable ('DEP_FILES', '', ("\@AMDEP\@", @deplist));
2984             # Generate each `include' individually.  Irix 6 make will
2985             # not properly include several files resulting from a
2986             # variable expansion; generating many separate includes
2987             # seems safest.
2988             $output_rules .= "\n";
2989             foreach $iter (@deplist)
2990             {
2991                 $output_rules .= "\@AMDEP\@" . 'include ' . $iter . "\n";
2992             }
2994             $output_rules .= &file_contents ('depend');
2995             push (@clean, 'depend');
2996             &push_phony_cleaners ('depend');
2997         }
2998     }
2999     else
3000     {
3001         &define_variable ('depcomp', '');
3002     }
3004     local ($key, $lang, $ext, $xform);
3005     foreach $key (sort keys %language_map)
3006     {
3007         next unless $key =~ /^(.*)-autodep$/;
3008         next if $language_map{$key} eq 'no';
3009         &add_depend2 ($1);
3010     }
3013 # Handle subdirectories.
3014 sub handle_subdirs
3016     return if ! &variable_defined ('SUBDIRS');
3018     # Make sure each directory mentioned in SUBDIRS actually exists.
3019     local ($dir);
3020     foreach $dir (&variable_value_as_list ('SUBDIRS', 'all'))
3021     {
3022         # Skip directories substituted by configure.
3023         next if $dir =~ /^\@.*\@$/;
3025         if (! -d $am_relative_dir . '/' . $dir)
3026         {
3027             &am_line_error ('SUBDIRS',
3028                             "required directory $am_relative_dir/$dir does not exist");
3029             next;
3030         }
3032         &am_line_error ('SUBDIRS', "directory should not contain \`/'")
3033             if $dir =~ /\//;
3034     }
3036     local ($xform) = ('s/\@INSTALLINFO\@/' .
3037                       (defined $options{'no-installinfo'}
3038                        ? 'install-info-recursive'
3039                        : '')
3040                       . '/;');
3041     $output_rules .= &file_contents_with_transform ($xform, 'subdirs');
3043     # Push a bunch of phony targets.
3044     local ($phonies);
3045     foreach $phonies ('', '-data', '-exec', 'dirs')
3046     {
3047         push (@phony, 'install' . $phonies . '-recursive');
3048         push (@phony, 'uninstall' . $phonies . '-recursive');
3049     }
3050     foreach $phonies ('all', 'check', 'installcheck', 'info', 'dvi')
3051     {
3052         push (@phony, $phonies . '-recursive');
3053     }
3054     &push_phony_cleaners ('recursive');
3056     $recursive_install = 1;
3059 # Handle aclocal.m4.
3060 sub handle_aclocal_m4
3062     local ($regen_aclocal) = 0;
3063     if (-f 'aclocal.m4')
3064     {
3065         &define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4');
3066         &push_dist_common ('aclocal.m4');
3068         if (open (ACLOCAL, '< aclocal.m4'))
3069         {
3070             local ($line);
3071             $line = <ACLOCAL>;
3072             close (ACLOCAL);
3074             if ($line =~ 'generated automatically by aclocal')
3075             {
3076                 $regen_aclocal = 1;
3077             }
3078         }
3079     }
3081     local ($acinclude) = 0;
3082     if (-f 'acinclude.m4')
3083     {
3084         $regen_aclocal = 1;
3085         $acinclude = 1;
3086     }
3088     # Note that it might be possible that aclocal.m4 doesn't exist but
3089     # should be auto-generated.  This case probably isn't very
3090     # important.
3091     if ($regen_aclocal)
3092     {
3093         local (@ac_deps) = (
3094                             ($seen_maint_mode
3095                              ? "\@MAINTAINER_MODE_TRUE\@"
3096                              : "") ,
3097                             "configure.in",
3098                             ($acinclude ? ' acinclude.m4' : '')
3099                             );
3101         # Scan all -I directories for m4 files.  These are our
3102         # dependencies.
3103         if (&variable_defined ('ACLOCAL_AMFLAGS'))
3104         {
3105             local ($examine_next, $amdir) = 0;
3106             foreach $amdir (&variable_value_as_list ('ACLOCAL_AMFLAGS', ''))
3107             {
3108                 if ($examine_next)
3109                 {
3110                     $examine_next = 0;
3111                     if ($amdir !~ /^\// && -d $amdir)
3112                     {
3113                         push (@ac_deps, &my_glob ($amdir . '/*.m4'));
3114                     }
3115                 }
3116                 elsif ($amdir eq '-I')
3117                 {
3118                     $examine_next = 1;
3119                 }
3120             }
3121         }
3123         &pretty_print_rule ("\$(ACLOCAL_M4):", "\t\t", @ac_deps);
3125         $output_rules .=  ("\t"
3126                            . 'cd $(srcdir) && $(ACLOCAL)'
3127                            . (&variable_defined ('ACLOCAL_AMFLAGS')
3128                               ? ' $(ACLOCAL_AMFLAGS)' : '')
3129                            . "\n");
3130     }
3133 # Rewrite a list of input files into a form suitable to put on a
3134 # dependency list.  The idea is that if an input file has a directory
3135 # part the same as the current directory, then the directory part is
3136 # simply removed.  But if the directory part is different, then
3137 # $(top_srcdir) is prepended.  Among other things, this is used to
3138 # generate the dependency list for the output files generated by
3139 # AC_OUTPUT.  Consider what the dependencies should look like in this
3140 # case:
3141 #   AC_OUTPUT(src/out:src/in1:lib/in2)
3142 # The first argument, ADD_SRCDIR, is 1 if $(top_srcdir) should be added.
3143 # If 0 then files that require this addition will simply be ignored.
3144 sub rewrite_inputs_into_dependencies
3146     local ($add_srcdir, @inputs) = @_;
3147     local ($single, @newinputs);
3149     foreach $single (@inputs)
3150     {
3151         if (&dirname ($single) eq $relative_dir)
3152         {
3153             push (@newinputs, &basename ($single));
3154         }
3155         elsif ($add_srcdir)
3156         {
3157             push (@newinputs, '$(top_srcdir)/' . $single);
3158         }
3159     }
3161     return @newinputs;
3164 # Handle remaking and configure stuff.
3165 # We need the name of the input file, to do proper remaking rules.
3166 sub handle_configure
3168     local ($local, $input, @secondary_inputs) = @_;
3170     # If SUBDIRS defined, require AC_PROG_MAKE_SET.
3171     &am_line_error ('SUBDIRS', "AC_PROG_MAKE_SET must be used in configure.in")
3172         if &variable_defined ('SUBDIRS') && ! $seen_make_set;
3174     local ($top_reldir);
3176     local ($input_base) = &basename ($input);
3177     local ($local_base) = &basename ($local);
3179     local ($amfile) = $input_base . '.am';
3180     # We know we can always add '.in' because it really should be an
3181     # error if the .in was missing originally.
3182     local ($infile) = '$(srcdir)/' . $input_base . '.in';
3183     local ($colon_infile);
3184     if ($local ne $input || @secondary_inputs)
3185     {
3186         $colon_infile = ':' . $input . '.in';
3187     }
3188     $colon_infile .= ':' . join (':', @secondary_inputs)
3189         if @secondary_inputs;
3191     local (@rewritten) = &rewrite_inputs_into_dependencies (1,
3192                                                             @secondary_inputs);
3194     # This rule remakes the Makefile.in.  Note use of
3195     # @MAINTAINER_MODE_TRUE@ forces us to abandon pretty-printing.
3196     # Sigh.
3197     $output_rules .= ($infile
3198                       # NOTE perl 5.003 (with -w) gives a
3199                       # uninitialized value error on the next line.
3200                       # Don't know why.
3201                       . ': '
3202                       . ($seen_maint_mode ? "\@MAINTAINER_MODE_TRUE\@ " : '')
3203                       . $amfile . ' '
3204                       . '$(top_srcdir)/configure.in $(ACLOCAL_M4)'
3205                       . ' ' . join (' ', @include_stack)
3206                       . "\n"
3207                       . "\tcd \$(top_srcdir) && \$(AUTOMAKE) "
3208                       . ($cygnus_mode ? '--cygnus' : ('--' . $strictness_name))
3209                       . ($cmdline_use_dependencies ? '' : ' --ignore-deps')
3210                       . ' ' . $input . $colon_infile . "\n\n");
3212     # This rule remakes the Makefile.
3213     $output_rules .= ($local_base
3214                       # NOTE: bogus uninit value error on next line;
3215                       # see comment above.
3216                       . ': '
3217                       . $infile . ' '
3218                       . join (' ', @rewritten)
3219                       . ' $(top_builddir)/config.status'
3220                       # NOTE: Makefile only depends on BUILT_SOURCES
3221                       # when dependencies are being computed.  This is
3222                       # a workaround for an obscure bug with
3223                       # AC_LINK_FILES.  Anyway, when dependencies are
3224                       # turned off, this shouldn't matter.
3225                       . ($use_dependencies ? ' $(BUILT_SOURCES)' : '')
3226                       . "\n"
3227                       . "\tcd \$(top_builddir) \\\n"
3228                       . "\t  && CONFIG_FILES="
3229                       . (($relative_dir eq '.') ? '$@' : '$(subdir)/$@')
3230                       . $colon_infile
3231                       . ' CONFIG_HEADERS= $(SHELL) ./config.status'
3232                       . "\n\n");
3234     if ($relative_dir ne '.')
3235     {
3236         # In subdirectory.
3237         $top_reldir = '../';
3238     }
3239     else
3240     {
3241         &handle_aclocal_m4;
3242         $output_rules .= &file_contents ('remake');
3243         &examine_variable ('CONFIG_STATUS_DEPENDENCIES');
3244         &examine_variable ('CONFIGURE_DEPENDENCIES');
3245         $top_reldir = '';
3247         &push_dist_common ('acconfig.h')
3248             if -f 'acconfig.h';
3249     }
3251     # Make it easy to see if there is a Makefile.am in a given
3252     # directory.
3253     local (%make_dirs, $iter);
3254     foreach $iter (@configure_input_files)
3255     {
3256         $make_dirs{&dirname ($iter)} = 1;
3257     }
3258     # We also want to notice Makefile.in's.
3259     foreach $iter (@other_input_files)
3260     {
3261         if ($iter =~ /Makefile\.in$/)
3262         {
3263             $make_dirs{&dirname ($iter)} = 1;
3264         }
3265     }
3267     # If we have a configure header, require it.
3268     local ($one_hdr);
3269     local (@local_fullnames) = @config_fullnames;
3270     local (@local_names) = @config_names;
3271     local ($hdr_index) = 0;
3272     local ($distclean_config) = '';
3273     foreach $one_hdr (@config_headers)
3274     {
3275         local ($one_fullname) = shift (@local_fullnames);
3276         local ($one_name) = shift (@local_names);
3277         $hdr_index += 1;
3278         local ($header_dir) = &dirname ($one_name);
3280         # If the header is in the current directory we want to build
3281         # the header here.  Otherwise, if we're at the topmost
3282         # directory and the header's directory doesn't have a
3283         # Makefile, then we also want to build the header.
3284         if ($relative_dir eq $header_dir
3285             || ($relative_dir eq '.' && ! defined $make_dirs{$header_dir}))
3286         {
3287             local ($ch_sans_dir, $cn_sans_dir, $stamp_dir);
3288             if ($relative_dir eq $header_dir)
3289             {
3290                 $cn_sans_dir = &basename ($one_name);
3291                 $stamp_dir = '';
3292             }
3293             else
3294             {
3295                 $cn_sans_dir = $one_name;
3296                 if ($header_dir eq '.')
3297                 {
3298                     $stamp_dir = '';
3299                 }
3300                 else
3301                 {
3302                     $stamp_dir = $header_dir . '/';
3303                 }
3304             }
3306             # Compute relative path from directory holding output
3307             # header to directory holding input header.  FIXME:
3308             # doesn't handle case where we have multiple inputs.
3309             if (&dirname ($one_hdr) eq $relative_dir)
3310             {
3311                 $ch_sans_dir = &basename ($one_hdr);
3312             }
3313             else
3314             {
3315                 local (@rel_out_path);
3316                 # FIXME this chunk of code should be its own sub.
3317                 # It is used elsewhere.
3318                 foreach (split (/\//, $relative_dir))
3319                 {
3320                     next if $_ eq '' || $_ eq '.';
3321                     if ($_ eq '..')
3322                     {
3323                         # FIXME: actually this is an error.
3324                         pop @rel_out_path;
3325                     }
3326                     else
3327                     {
3328                         push (@rel_out_path, '..');
3329                     }
3330                 }
3331                 if (@rel_out_path)
3332                 {
3333                     $ch_sans_dir = join ('/', @rel_out_path) . '/' . $one_hdr;
3334                 }
3335                 else
3336                 {
3337                     $ch_sans_dir = $one_hdr;
3338                 }
3339             }
3341             &require_file_with_conf_line ($config_header_line,
3342                                           $FOREIGN, $ch_sans_dir);
3344             # Header defined and in this directory.
3345             local (@files);
3346             if (-f $one_name . '.top')
3347             {
3348                 push (@files, "${cn_sans_dir}.top");
3349             }
3350             if (-f $one_name . '.bot')
3351             {
3352                 push (@files, "${cn_sans_dir}.bot");
3353             }
3355             &push_dist_common (@files);
3357             # For now, acconfig.h can only appear in the top srcdir.
3358             if (-f 'acconfig.h')
3359             {
3360                 if ($relative_dir eq '.')
3361                 {
3362                     push (@files, 'acconfig.h');
3363                 }
3364                 else
3365                 {
3366                     # Strange quoting because this gets fed through
3367                     # Perl.
3368                     push (@files, '\$(top_srcdir)/acconfig.h');
3369                 }
3370             }
3372             local ($stamp_name) = 'stamp-h';
3373             $stamp_name .= "${hdr_index}" if scalar (@config_headers) > 1;
3375             local ($xform) = '';
3377             $xform = 's,\@FILES\@,' . join (' ', @files) . ',;';
3378             $xform .= 's,\@CONFIG_HEADER\@,' . "${cn_sans_dir}" . ',;';
3379             $xform .= 's,\@CONFIG_HEADER_IN\@,' . "${ch_sans_dir}" . ',;';
3380             $xform .= 's,\@CONFIG_HEADER_FULL\@,' . "${one_fullname}" . ',;';
3381             $xform .= 's,\@STAMP\@,' . "${stamp_dir}${stamp_name}" . ',g;';
3383             local ($out_dir) = &dirname ($ch_sans_dir);
3384             $xform .= 's,\@SRC_STAMP\@,' . "${out_dir}/${stamp_name}" . ',g;';
3385             $output_rules .= &file_contents_with_transform ($xform,
3386                                                             'remake-hdr');
3388             &create ("${relative_dir}/${out_dir}/${stamp_name}.in");
3389             &require_file_with_conf_line ($config_header_line, $FOREIGN,
3390                                           "${out_dir}/${stamp_name}.in");
3392             $distclean_config .= ' ' if $distclean_config;
3393             $distclean_config .= $cn_sans_dir;
3394         }
3395     }
3397     if ($distclean_config)
3398     {
3399         $output_rules .= &file_contents_with_transform ('s,\@FILES\@,'
3400                                                         . $distclean_config
3401                                                         . ',;',
3402                                                         'clean-hdr');
3403         push (@clean, 'hdr');
3404         &push_phony_cleaners ('hdr');
3405     }
3407     # Set location of mkinstalldirs.
3408     if ($config_aux_dir ne '.' && $config_aux_dir ne '')
3409     {
3410         &define_variable ('mkinstalldirs', ('$(SHELL) ' . $config_aux_dir
3411                                             . '/mkinstalldirs'));
3412     }
3413     else
3414     {
3415         &define_variable ('mkinstalldirs',
3416                           '$(SHELL) $(top_srcdir)/mkinstalldirs');
3417     }
3419     &am_line_error ('CONFIG_HEADER',
3420                     "\`CONFIG_HEADER' is an anachronism; now determined from \`configure.in'")
3421         if &variable_defined ('CONFIG_HEADER');
3423     local ($one_name);
3424     local ($config_header) = '';
3425     foreach $one_name (@config_names)
3426     {
3427         # Generate CONFIG_HEADER define.
3428         local ($one_hdr);
3429         if ($relative_dir eq &dirname ($one_name))
3430         {
3431             $one_hdr = &basename ($one_name);
3432         }
3433         else
3434         {
3435             $one_hdr = "${top_builddir}/${one_name}";
3436         }
3438         $config_header .= ' ' if $config_header;
3439         $config_header .= $one_hdr;
3440     }
3441     if ($config_header)
3442     {
3443         &define_variable ("CONFIG_HEADER", $config_header);
3444     }
3446     # Now look for other files in this directory which must be remade
3447     # by config.status, and generate rules for them.
3448     local (@actual_other_files) = ();
3449     local ($file, $local);
3450     local (@inputs, @rewritten_inputs, $single);
3451     local ($need_rewritten);
3452     foreach $file (@other_input_files)
3453     {
3454         if ($file =~ /^([^:]*):(.*)$/)
3455         {
3456             # This is the ":" syntax of AC_OUTPUT.
3457             $file = $1;
3458             $local = &basename ($file);
3459             @inputs = split (':', $2);
3460             @rewritten_inputs = &rewrite_inputs_into_dependencies (1, @inputs);
3461             $need_rewritten = 1;
3462         }
3463         else
3464         {
3465             # Normal usage.
3466             $local = &basename ($file);
3467             @inputs = ($local . '.in');
3468             @rewritten_inputs =
3469                 &rewrite_inputs_into_dependencies (1, $file . '.in');
3470             $need_rewritten = 0;
3471         }
3473         # Skip files not in this directory.
3474         next unless &dirname ($file) eq $relative_dir;
3476         # Skip any file that is an automake input.
3477         next if -f $file . '.am';
3479         # Some users have been tempted to put `stamp-h' in the
3480         # AC_OUTPUT line.  This won't do the right thing, so we
3481         # explicitly fail here.
3482         if ($local eq 'stamp-h')
3483         {
3484             # FIXME: allow real filename.
3485             &am_conf_error ('configure.in', $ac_output_line,
3486                             'stamp-h should not appear in AC_OUTPUT');
3487             next;
3488         }
3490         $output_rules .= ($local . ': '
3491                           . '$(top_builddir)/config.status '
3492                           . join (' ', @rewritten_inputs) . "\n"
3493                           . "\t"
3494                           . 'cd $(top_builddir) && CONFIG_FILES='
3495                           . ($relative_dir eq '.' ? '' : '$(subdir)/')
3496                           . '$@' . ($need_rewritten
3497                                     ? (':' . join (':', @inputs))
3498                                     : '')
3499                           . ' CONFIG_HEADERS= $(SHELL) ./config.status'
3500                           . "\n");
3501         &push_dist_common (@inputs);
3502         push (@actual_other_files, $local);
3504         # Require all input files.
3505         &require_file_with_conf_line ($ac_output_line, $FOREIGN,
3506                                       &rewrite_inputs_into_dependencies (0, @inputs));
3507     }
3509     # These files get removed by "make clean".
3510     &define_pretty_variable ('CONFIG_CLEAN_FILES', '', @actual_other_files);
3513 # Handle C headers.
3514 sub handle_headers
3516     local (@r);
3517     @r = &am_install_var ('-defaultdist', 'header', 'HEADERS', 'include',
3518                           'oldinclude', 'pkginclude',
3519                           'noinst', 'check');
3520     foreach (@r)
3521     {
3522         next unless /\.(.*)$/;
3523         &saw_extension ($1);
3524     }
3527 sub handle_gettext
3529     return if ! $seen_gettext || $relative_dir ne '.';
3531     if (! &variable_defined ('SUBDIRS'))
3532     {
3533         &am_conf_error
3534             ("AM_GNU_GETTEXT in configure.in but SUBDIRS not defined");
3535         return;
3536     }
3538     &require_file_with_conf_line ($ac_gettext_line, $GNU, 'ABOUT-NLS');
3540     if (&variable_defined ('SUBDIRS'))
3541     {
3542         &am_line_error
3543             ('SUBDIRS',
3544              "AM_GNU_GETTEXT in configure.in but \`po' not in SUBDIRS")
3545                 if $contents{'SUBDIRS'} !~ /\bpo\b/;
3546         &am_line_error
3547             ('SUBDIRS',
3548              "AM_GNU_GETTEXT in configure.in but \`intl' not in SUBDIRS")
3549                 if $contents{'SUBDIRS'} !~ /\bintl\b/;
3550     }
3552     # Ensure that each language in ALL_LINGUAS has a .po file, and
3553     # each po file is mentioned in ALL_LINGUAS.
3554     if ($seen_linguas)
3555     {
3556         local (%linguas) = ();
3557         grep ($linguas{$_} = 1, split (' ', $all_linguas));
3559         foreach (<po/*.po>)
3560         {
3561             s/^po\///;
3562             s/\.po$//;
3564             &am_line_error ($all_linguas_line,
3565                             ("po/$_.po exists but \`$_' not in \`ALL_LINGUAS'"))
3566                 if ! $linguas{$_};
3567         }
3569         foreach (keys %linguas)
3570         {
3571             &am_line_error ($all_linguas_line,
3572                             "$_ in \`ALL_LINGUAS' but po/$_.po does not exist")
3573                 if ! -f "po/$_.po";
3574         }
3575     }
3576     else
3577     {
3578         &am_error ("AM_GNU_GETTEXT in configure.in but \`ALL_LINGUAS' not defined");
3579     }
3582 # Handle footer elements.
3583 sub handle_footer
3585     if ($contents{'SOURCES'})
3586     {
3587         # NOTE don't use define_pretty_variable here, because
3588         # $contents{...} is already defined.
3589         $output_vars .= 'SOURCES = ' . $contents{'SOURCES'} . "\n";
3590     }
3591     if ($contents{'OBJECTS'})
3592     {
3593         # NOTE don't use define_pretty_variable here, because
3594         # $contents{...} is already defined.
3595         $output_vars .= 'OBJECTS = ' . $contents{'OBJECTS'} . "\n";
3596     }
3597     if ($contents{'SOURCES'} || $contents{'OBJECTS'})
3598     {
3599         $output_vars .= "\n";
3600     }
3602     if (&variable_defined ('SUFFIXES'))
3603     {
3604         # Push actual suffixes, and not $(SUFFIXES).  Some versions of
3605         # make do not like variable substitutions on the .SUFFIXES
3606         # line.
3607         push (@suffixes, &variable_value_as_list ('SUFFIXES', ''));
3608     }
3609     if (&target_defined ('.SUFFIXES'))
3610     {
3611         &am_line_error ('.SUFFIXES',
3612                         "use variable \`SUFFIXES', not target \`.SUFFIXES'");
3613     }
3615     # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
3616     # before .SUFFIXES.  So we make sure that .SUFFIXES appears before
3617     # anything else, by sticking it right after the default: target.
3618     $output_header .= ".SUFFIXES:\n";
3619     if (@suffixes)
3620     {
3621         # Make sure suffixes has unique elements.  Sort them to ensure
3622         # the output remains consistent.
3623         local (%suffixes);
3625         grep ($suffixes{$_} = 1, @suffixes);
3627         $output_header .= (".SUFFIXES: "
3628                            . join (' ', sort keys %suffixes)
3629                            . "\n");
3630     }
3631     $output_trailer .= &file_contents ('footer');
3634 # Deal with installdirs target.
3635 sub handle_installdirs
3637     # GNU Makefile standards recommend this.
3638     if ($recursive_install)
3639     {
3640         # We create a separate `-am' target so that the -recursive
3641         # rule will work correctly.
3642         $output_rules .= ("installdirs: installdirs-recursive\n"
3643                           . "installdirs-am:\n");
3644         push (@phony, 'installdirs-am');
3645     }
3646     else
3647     {
3648         $output_rules .= "installdirs:\n";
3649     }
3650     push (@phony, 'installdirs');
3651     if (@installdirs)
3652     {
3653         &pretty_print_rule ("\t" . '$(mkinstalldirs) ', "\t\t",
3654                             @installdirs);
3655     }
3656     $output_rules .= "\n";
3659 # There are several targets which need to be merged.  This is because
3660 # their complete definition is compiled from many parts.  Note that we
3661 # avoid double colon rules, otherwise we'd use them instead.
3662 sub handle_merge_targets
3664     local ($makefile) = @_;
3666     # There are a few install-related variables that you should not define.
3667     local ($var);
3668     foreach $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
3669     {
3670         if (&variable_defined ($var))
3671         {
3672             &am_line_error ($var, "\`$var' should not be defined");
3673         }
3674     }
3676     # Put this at the beginning for the sake of non-GNU makes.  This
3677     # is still wrong if these makes can run parallel jobs.  But it is
3678     # right enough.
3679     unshift (@all, &basename ($makefile));
3681     local ($one_name);
3682     foreach $one_name (@config_names)
3683     {
3684         push (@all, &basename ($one_name))
3685             if &dirname ($one_name) eq $relative_dir;
3686     }
3688     &do_one_merge_target ('info', @info);
3689     &do_one_merge_target ('dvi', @dvi);
3690     &do_check_merge_target;
3691     &do_one_merge_target ('installcheck', @installcheck);
3693     if (defined $options{'no-installinfo'})
3694     {
3695         &do_one_merge_target ('install-info', '');
3696     }
3697     elsif (&target_defined ('install-info-local'))
3698     {
3699         &am_line_error ('install-info-local',
3700                         "\`install-info-local' target defined but \`no-installinfo' option not in use");
3701     }
3703     local ($utarg);
3704     foreach $utarg ('uninstall-data-local', 'uninstall-data-hook',
3705                     'uninstall-exec-local', 'uninstall-exec-hook')
3706     {
3707         if (&target_defined ($utarg))
3708         {
3709             local ($x);
3710             ($x = $utarg) =~ s/(data|exec)-//;
3711             &am_line_error ($utarg, "use \`$x', not \`$utarg'");
3712         }
3713     }
3715     if (&target_defined ('install-local'))
3716     {
3717         &am_line_error ('install-local',
3718                         "use \`install-data-local' or \`install-exec-local', not \`install-local'");
3719     }
3721     if (@all)
3722     {
3723         local ($one_name);
3724         local ($local_headers) = '';
3725         foreach $one_name (@config_names)
3726         {
3727             if (&dirname ($one_name) eq $relative_dir)
3728             {
3729                 $local_headers .= ' ' if $local_headers;
3730                 $local_headers .= &basename ($one_name);
3731             }
3732         }
3733         if ($local_headers)
3734         {
3735             # This is kind of a hack, but I couldn't see a better way
3736             # to handle it.  In this particular case, we need to make
3737             # sure config.h is built before we recurse.  We can't do
3738             # this by changing the order of dependencies to the "all"
3739             # because that breaks when using parallel makes.  Instead
3740             # we handle things explicitly.
3741             $output_rules .= ("all-recursive-am: ${local_headers}"
3742                                   . "\n\t"
3743                                   . '$(MAKE) $(AM_MAKEFLAGS)'
3744                                   . " all-recursive"
3745                                   . "\n\n");
3746             $all_target = 'all-recursive-am';
3747             push (@phony, 'all-recursive-am');
3748         }
3749     }
3751     # Print definitions users can use.
3752     &do_one_merge_target ('install-exec', @install_exec);
3753     $output_rules .= "\n";
3755     &do_one_merge_target ('install-data', @install_data);
3756     $output_rules .= "\n";
3758     &do_one_merge_target ('install', 'all-am');
3759     &do_one_merge_target ('uninstall', @uninstall);
3761     &do_one_merge_target ('all', @all);
3763     # Generate the new 'install-strip' target.  We can't just set
3764     # INSTALL_PROGRAM because that might be a relative path.
3765     $output_rules .= ("install-strip:\n\t"
3766                       . '$(MAKE) $(AM_MAKEFLAGS) INSTALL_STRIP_FLAG=-s install'
3767                       . "\n");
3768     push (@phony, 'install-strip');
3771 # Helper for handle_merge_targets.  Note that handle_merge_targets
3772 # relies on the fact that this doesn't add an extra \n at the end.
3773 sub do_one_merge_target
3775     local ($name, @values) = @_;
3777     if (&target_defined ($name . '-local'))
3778     {
3779         # User defined local form of target.  So include it.
3780         push (@values, $name . '-local');
3781         push (@phony, $name . '-local');
3782     }
3784     &pretty_print_rule ($name . "-am:", "\t\t", @values);
3785     if ($name eq 'install')
3786     {
3787         # Special-case `install-am' to run install-exec-am and
3788         # install-data-am after all-am is built.
3789         &pretty_print_rule ("\t\@\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
3790                             'install-exec-am', 'install-data-am');
3791     }
3792     elsif ($name eq 'install-exec' && &target_defined ('install-exec-hook'))
3793     {
3794         $output_rules .= ("\t\@\$(NORMAL_INSTALL)\n"
3795                           . "\t" . '$(MAKE) $(AM_MAKEFLAGS) install-exec-hook'
3796                           . "\n");
3797     }
3798     elsif ($name eq 'install-data' && &target_defined ('install-data-hook'))
3799     {
3800         $output_rules .= ("\t\@\$(NORMAL_INSTALL)\n"
3801                           . "\t" . '$(MAKE) $(AM_MAKEFLAGS) install-data-hook'
3802                           . "\n");
3803     }
3805     local ($lname) = $name . ($recursive_install ? '-recursive' : '-am');
3806     local ($tname) = $name;
3807     # To understand this special case, see handle_merge_targets.
3808     if ($name eq 'all')
3809     {
3810         $tname = 'all-redirect';
3811         $lname = $all_target if $recursive_install;
3812         push (@phony, 'all-redirect');
3813         $output_all = "all: all-redirect\n";
3814     }
3815     &pretty_print_rule ($tname . ":", "\t\t", $lname);
3816     push (@phony, $name . '-am', $name);
3819 # Handle check merge target specially.
3820 sub do_check_merge_target
3822     if (&target_defined ('check-local'))
3823     {
3824         # User defined local form of target.  So include it.
3825         push (@check_tests, 'check-local');
3826         push (@phony, 'check-local');
3827     }
3829     # In --cygnus mode, check doesn't depend on all.
3830     if ($cygnus_mode)
3831     {
3832         # Just run the local check rules.
3833         &pretty_print_rule ('check-am:', "\t\t", @check);
3834     }
3835     else
3836     {
3837         # The check target must depend on the local equivalent of
3838         # `all', to ensure all the primary targets are built.  Then it
3839         # must build the local check rules.
3840         $output_rules .= "check-am: all-am\n";
3841         &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
3842                             @check)
3843             if @check;
3844     }
3845     &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
3846                         @check_tests)
3847         if @check_tests;
3849     push (@phony, 'check', 'check-am');
3850     $output_rules .= ("check: "
3851                       . ($recursive_install ? 'check-recursive' : 'check-am')
3852                       . "\n");
3855 # Handle all 'clean' targets.
3856 sub handle_clean
3858     local ($xform) = '';
3859     local ($name);
3861     # Don't include `MAINTAINER'; it is handled specially below.
3862     foreach $name ('MOSTLY', '', 'DIST')
3863     {
3864         if (! &variable_defined ($name . 'CLEANFILES'))
3865         {
3866             $xform .= 's/^' . $name . 'CLEAN.*$//;';
3867         }
3868         else
3869         {
3870             $xform .= 's/^' . $name . 'CLEAN//;';
3871         }
3872     }
3874     # Built sources are automatically removed by maintainer-clean.
3875     push (@maintainer_clean_files, '\$(BUILT_SOURCES)')
3876         if &variable_defined ('BUILT_SOURCES');
3877     push (@maintainer_clean_files, '\$(MAINTAINERCLEANFILES)')
3878         if &variable_defined ('MAINTAINERCLEANFILES');
3879     if (! @maintainer_clean_files)
3880     {
3881         $xform .= 's/^MAINTAINERCLEAN.*$//;';
3882     }
3883     else
3884     {
3885         $xform .= ('s/^MAINTAINERCLEAN//;'
3886                    # Join with no space to avoid spurious `test -z'
3887                    # success at runtime.
3888                    . 's,\@MCFILES\@,' . join ('', @maintainer_clean_files)
3889                    . ',;'
3890                    # A space is required in the join here.
3891                    . 's,\@MFILES\@,' . join (' ', @maintainer_clean_files)
3892                    . ',;');
3893     }
3895     $output_rules .= &file_contents_with_transform ($xform, 'clean');
3897     push (@clean, 'generic');
3898     &push_phony_cleaners ('generic');
3900     &do_one_clean_target ('clean', 'mostly', '', @clean);
3901     &do_one_clean_target ('clean', '', 'mostly', @clean);
3902     &do_one_clean_target ('clean', 'dist', '', @clean);
3903     &do_one_clean_target ('clean', 'maintainer-', 'dist', @clean);
3905     push (@phony, 'clean', 'mostlyclean', 'distclean', 'maintainer-clean');
3908 # Helper for handle_clean.
3909 sub do_one_clean_target
3911     local ($target, $name, $last_name, @deps) = @_;
3913     # Change each dependency `BLARG' into `clean-BLARG'.
3914     grep (($_ = $name . 'clean-' . $_) && 0, @deps);
3916     # Push the previous clean target.  There is no previous clean
3917     # target if we're doing mostlyclean.
3918     push (@deps, $last_name . $target . '-am')
3919         unless $name eq 'mostly';
3921     # If a -local version of the rule is given, add it to the list.
3922     if (&target_defined ($name . $target . '-local'))
3923     {
3924         push (@deps, $name . $target . '-local');
3925     }
3927     # Print the target and the dependencies.
3928     &pretty_print_rule ($name . $target . "-am: ", "\t\t", @deps);
3930     # FIXME: shouldn't we really print these messages before running
3931     # the dependencies?
3932     if ($name . $target eq 'maintainer-clean')
3933     {
3934         # Print a special warning.
3935         $output_rules .=
3936             ("\t\@echo \"This command is intended for maintainers to use;\"\n"
3937              . "\t\@echo \"it deletes files that may require special "
3938              . "tools to rebuild.\"\n");
3939     }
3940     elsif ($name . $target eq 'distclean')
3941     {
3942         $output_rules .= "\t-rm -f libtool\n" if $seen_libtool;
3943     }
3944     $output_rules .= "\n";
3946     # Now generate the actual clean target.
3947     $output_rules .= ($name . $target . ": " . $name . $target
3948                       . ($recursive_install ? '-recursive' : '-am')
3949                       . "\n");
3951     # We special-case config.status here.  If we do it as part of the
3952     # normal clean processing for this directory, then it might be
3953     # removed before some subdir is cleaned.  However, that subdir's
3954     # Makefile depends on config.status.
3955     if (($name . $target eq 'maintainer-clean'
3956          || $name . $target eq 'distclean')
3957         && $relative_dir eq '.')
3958     {
3959         $output_rules .= "\t-rm -f config.status\n";
3960     }
3961     $output_rules .= "\n";
3964 # Handle .PHONY target.
3965 sub handle_phony
3967     &pretty_print_rule ('.PHONY:', "", @phony);
3968     $output_rules .= "\n";
3971 # Handle TESTS variable and other checks.
3972 sub handle_tests
3974     if (defined $options{'dejagnu'})
3975     {
3976         push (@check_tests, 'check-DEJAGNU');
3977         push (@phony, 'check-DEJAGNU');
3979         local ($xform);
3980         if ($cygnus_mode)
3981         {
3982             $xform = 's/^CYGNUS//;';
3983         }
3984         else
3985         {
3986             $xform = 's/^CYGNUS.*$//;';
3987         }
3988         $output_rules .= &file_contents_with_transform ($xform, 'dejagnu');
3990         # In Cygnus mode, these are found in the build tree.
3991         # Otherwise they are looked for in $PATH.
3992         &define_program_variable ('EXPECT', 'build', 'expect', 'expect');
3993         &define_program_variable ('RUNTEST', 'src', 'dejagnu', 'runtest');
3995         # Only create site.exp rule if user hasn't already written
3996         # one.
3997         if (! &target_defined ('site.exp'))
3998         {
3999             # Note that in the rule we don't directly generate
4000             # site.exp to avoid the possibility of a corrupted
4001             # site.exp if make is interrupted.  Jim Meyering has some
4002             # useful text on this topic.
4003             $output_rules .= ("site.exp: Makefile\n"
4004                               . "\t\@echo 'Making a new site.exp file...'\n"
4005                               . "\t\@test ! -f site.bak || rm -f site.bak\n"
4006                               . "\t\@echo '## these variables are automatically generated by make ##' > \$\@-t\n"
4007                               . "\t\@echo '# Do not edit here.  If you wish to override these values' >> \$\@-t\n"
4008                               . "\t\@echo '# edit the last section' >> \$\@-t\n"
4009                               . "\t\@echo 'set tool \$(DEJATOOL)' >> \$\@-t\n"
4010                               . "\t\@echo 'set srcdir \$(srcdir)' >> \$\@-t\n"
4011                               . "\t\@echo 'set objdir' \`pwd\` >> \$\@-t\n");
4013             # Extra stuff for AC_CANONICAL_*
4014             local (@whatlist) = ();
4015             if ($seen_canonical)
4016             {
4017                 push (@whatlist, 'host');
4018             }
4020             # Extra stuff only for AC_CANONICAL_SYSTEM.
4021             if ($seen_canonical == $AC_CANONICAL_SYSTEM)
4022             {
4023                 push (@whatlist, 'target', 'build');
4024             }
4026             local ($c1, $c2);
4027             foreach $c1 (@whatlist)
4028             {
4029                 foreach $c2 ('alias', 'triplet')
4030                 {
4031                     $output_rules .= "\t\@echo 'set ${c1}_${c2} \$(${c1}_${c2})' >> \$\@-t\n";
4032                 }
4033             }
4035             $output_rules .= ("\t\@echo '## All variables above are generated by configure. Do Not Edit ##' >> \$\@-t\n"
4036                               . "\t\@test ! -f site.exp || sed '1,/^## All variables above are.*##/ d' site.exp >> \$\@-t\n"
4037                               . "\t\@test ! -f site.exp || mv site.exp site.bak\n"
4038                               . "\t\@mv \$\@-t site.exp\n");
4039         }
4040     }
4041     else
4042     {
4043         local ($c);
4044         foreach $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
4045         {
4046             if (&variable_defined ($c))
4047             {
4048                 &am_line_error ($c, "\`$c' defined but \`dejagnu' not in \`AUTOMAKE_OPTIONS'");
4049             }
4050         }
4051     }
4053     if (&variable_defined ('TESTS'))
4054     {
4055         push (@check_tests, 'check-TESTS');
4056         push (@phony, 'check-TESTS');
4058         # Note: Solaris 2.7 seems to expand TESTS using VPATH.  That's
4059         # why we also try `dir='
4060         $output_rules .= 'check-TESTS: $(TESTS)
4061         @failed=0; all=0; xfail=0; xpass=0; \\
4062         srcdir=$(srcdir); export srcdir; \\
4063         for tst in $(TESTS); do \\
4064           if test -f ./$$tst; then dir=./; \\
4065           elif test -f $$tst; then dir=; \\
4066           else dir="$(srcdir)/"; fi; \\
4067           if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \\
4068             all=`expr $$all + 1`; \\
4069             case " $(XFAIL_TESTS) " in \\
4070             *" $$tst "*) \\
4071               xpass=`expr $$xpass + 1`; \\
4072               failed=`expr $$failed + 1`; \\
4073               echo "XPASS: $$tst"; \\
4074             ;; \\
4075             *) \\
4076               echo "PASS: $$tst"; \\
4077             ;; \\
4078             esac; \\
4079           elif test $$? -ne 77; then \\
4080             all=`expr $$all + 1`; \\
4081             case " $(XFAIL_TESTS) " in \\
4082             *" $$tst "*) \\
4083               xfail=`expr $$xfail + 1`; \\
4084               echo "XFAIL: $$tst"; \\
4085             ;; \\
4086             *) \\
4087               failed=`expr $$failed + 1`; \\
4088               echo "FAIL: $$tst"; \\
4089             ;; \\
4090             esac; \\
4091           fi; \\
4092         done; \\
4093         if test "$$failed" -eq 0; then \\
4094           if test "$$xfail" -eq 0; then \\
4095             banner="All $$all tests passed"; \\
4096           else \\
4097             banner="All $$all tests behaved as expected ($$xfail expected failures)"; \\
4098           fi; \\
4099         else \\
4100           if test "$$xpass" -eq 0; then \\
4101             banner="$$failed of $$all tests failed"; \\
4102           else \\
4103             banner="$$failed of $$all tests did not behave as expected ($$xpass unexpected passes)"; \\
4104           fi; \\
4105         fi; \\
4106         dashes=`echo "$$banner" | sed s/./=/g`; \\
4107         echo "$$dashes"; \\
4108         echo "$$banner"; \\
4109         echo "$$dashes"; \\
4110         test "$$failed" -eq 0
4112     }
4115 # Handle Emacs Lisp.
4116 sub handle_emacs_lisp
4118     local (@elfiles) = &am_install_var ('-candist', 'lisp', 'LISP',
4119                                         'lisp', 'noinst');
4121     if (@elfiles)
4122     {
4123         # Found some lisp.
4124         &define_configure_variable ('lispdir');
4125         &define_configure_variable ('EMACS');
4126         $output_rules .= (".el.elc:\n"
4127                           . "\t\@echo 'WARNING: Warnings can be ignored. :-)'\n"
4128                           . "\tif test \$(EMACS) != no; then \\\n"
4129                           . "\t  EMACS=\$(EMACS) \$(SHELL) \$(srcdir)/elisp-comp \$<; \\\n"
4130                           . "\tfi\n");
4131         push (@suffixes, '.el', '.elc');
4133         # Generate .elc files.
4134         grep ($_ .= 'c', @elfiles);
4135         &define_pretty_variable ('ELCFILES', '', @elfiles);
4137         $output_rules .= &file_contents ('lisp-clean');
4138         push (@clean, 'lisp');
4139         &push_phony_cleaners ('lisp');
4141         push (@all, '$(ELCFILES)');
4143         local ($varname);
4144         if (&variable_defined ('lisp_LISP'))
4145         {
4146             $varname = 'lisp_LISP';
4147             &am_error ("\`lisp_LISP' defined but \`AM_PATH_LISPDIR' not in \`configure.in'")
4148                 if ! $seen_lispdir;
4149         }
4150         else
4151         {
4152             $varname = 'noinst_LISP';
4153         }
4155         &require_file_with_line ($varname, $FOREIGN, 'elisp-comp');
4156     }
4159 # Handle Python
4160 sub handle_python
4162     local (@pyfiles) = &am_install_var ('-defaultdist', 'python', 'PYTHON',
4163                                         'python', 'noinst');
4164     return if ! @pyfiles;
4166     # Found some python.
4167     &define_configure_variable ('pythondir');
4168     &define_configure_variable ('PYTHON');
4170     $output_rules .= &file_contents ('python-clean');
4171     push (@clean, 'python');
4173     &am_error ("\`python_PYTHON' defined but \`AM_CHECK_PYTHON' not in \`configure.in'")
4174         if ! $seen_pythondir && &variable_defined ('python_PYTHON');
4176     if ($config_aux_dir eq '.' || $config_aux_dir eq '')
4177     {
4178         &define_variable ('py_compile', '$(top_srcdir)/py-compile');
4179     }
4180     else
4181     {
4182         &define_variable ('py_compile', $config_aux_dir . '/py-compile');
4183     }
4186 # Handle Java.
4187 sub handle_java
4189     local (@sourcelist) = &am_install_var ('-candist', '-clean',
4190                                            'java', 'JAVA',
4191                                            'java', 'noinst', 'check');
4192     return if ! @sourcelist;
4194     &define_variable ('JAVAC', 'javac');
4195     &define_variable ('JAVACFLAGS', '');
4196     &define_variable ('CLASSPATH_ENV',
4197                       'CLASSPATH=$(JAVAROOT):$(srcdir)/$(JAVAROOT):$$CLASSPATH');
4198     &define_variable ('JAVAROOT', '$(top_builddir)');
4200     local (%valid) = &am_primary_prefixes ('JAVA', 1,
4201                                            'java', 'noinst', 'check');
4203     local ($dir, $curs);
4204     foreach $curs (keys %valid)
4205     {
4206         if (! &variable_defined ($curs . '_JAVA') || $curs eq 'noinst'
4207             || $curs eq 'EXTRA')
4208         {
4209             next;
4210         }
4212         if (defined $dir)
4213         {
4214             &am_line_error ($curs . '_JAVA',
4215                             "multiple _JAVA primaries in use");
4216         }
4217         $dir = $curs;
4218     }
4220     $output_rules .= ('class' . $dir . '.stamp: $(' . $dir . '_JAVA)' . "\n"
4221                       . "\t" . '$(CLASSPATH_ENV) $(JAVAC) -d $(JAVAROOT) '
4222                       . '$(JAVACFLAGS) $?' . "\n"
4223                       . "\t" . 'echo timestamp > class' . $dir . '.stamp'
4224                       . "\n");
4225     push (@all, 'class' . $dir . '.stamp');
4226     &push_dist_common ('$(' . $dir . '_JAVA)');
4229 # Handle some of the minor options.
4230 sub handle_minor_options
4232     if (defined $options{'readme-alpha'})
4233     {
4234         if ($relative_dir eq '.')
4235         {
4236             if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
4237             {
4238                 # FIXME: allow real filename.
4239                 &am_conf_line_error ('configure.in',
4240                                      $package_version_line,
4241                                      "version \`$package_version' doesn't follow Gnits standards");
4242             }
4243             elsif (defined $1 && -f 'README-alpha')
4244             {
4245                 # This means we have an alpha release.  See
4246                 # GNITS_VERSION_PATTERN for details.
4247                 &require_file ($FOREIGN, 'README-alpha');
4248             }
4249         }
4250     }
4253 ################################################################
4255 # Scan one file for interesting things.  Subroutine of scan_configure.
4256 sub scan_one_configure_file
4258     local ($filename) = @_;
4259     local (*CONFIGURE);
4261     open (CONFIGURE, $filename)
4262         || die "automake: couldn't open \`$filename': $!\n";
4263     print "automake: reading $filename\n" if $verbose;
4265     while (<CONFIGURE>)
4266     {
4267         # Remove comments from current line.
4268         s/\bdnl\b.*$//;
4269         s/\#.*$//;
4271         # Skip macro definitions.  Otherwise we might be confused into
4272         # thinking that a macro that was only defined was actually
4273         # used.
4274         next if /AC_DEFUN/;
4276         # Follow includes.  This is a weirdness commonly in use at
4277         # Cygnus and hopefully nowhere else.
4278         if (/sinclude\((.*)\)/ && -f $1)
4279         {
4280             &scan_one_configure_file ($1);
4281         }
4283         # Populate libobjs array.
4284         if (/AC_FUNC_ALLOCA/)
4285         {
4286             $libsources{'alloca.c'} = 1;
4287         }
4288         elsif (/AC_FUNC_GETLOADAVG/)
4289         {
4290             $libsources{'getloadavg.c'} = 1;
4291         }
4292         elsif (/AC_FUNC_MEMCMP/)
4293         {
4294             $libsources{'memcmp.c'} = 1;
4295         }
4296         elsif (/AC_STRUCT_ST_BLOCKS/)
4297         {
4298             $libsources{'fileblocks.c'} = 1;
4299         }
4300         elsif (/A[CM]_REPLACE_GNU_GETOPT/)
4301         {
4302             $libsources{'getopt.c'} = 1;
4303             $libsources{'getopt1.c'} = 1;
4304         }
4305         elsif (/AM_FUNC_STRTOD/)
4306         {
4307             $libsources{'strtod.c'} = 1;
4308         }
4309         elsif (/AM_WITH_REGEX/)
4310         {
4311             $libsources{'rx.c'} = 1;
4312             $libsources{'rx.h'} = 1;
4313             $libsources{'regex.c'} = 1;
4314             $libsources{'regex.h'} = 1;
4315             $omit_dependencies{'rx.h'} = 1;
4316             $omit_dependencies{'regex.h'} = 1;
4317         }
4318         elsif (/AC_FUNC_MKTIME/)
4319         {
4320             $libsources{'mktime.c'} = 1;
4321         }
4322         elsif (/AM_FUNC_ERROR_AT_LINE/)
4323         {
4324             $libsources{'error.c'} = 1;
4325             $libsources{'error.h'} = 1;
4326         }
4327         elsif (/AM_FUNC_OBSTACK/)
4328         {
4329             $libsources{'obstack.c'} = 1;
4330             $libsources{'obstack.h'} = 1;
4331         }
4332         elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
4333                || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
4334         {
4335             foreach $libobj_iter (split (' ', $1))
4336             {
4337                 if ($libobj_iter =~ /^(.*)\.o(bj)?$/
4338                     || $libobj_iter =~ /^(.*)\.\$ac_objext$/
4339                     || $libobj_iter =~ /^(.*)\.\$\{ac_objext\}$/)
4340                 {
4341                     $libsources{$1 . '.c'} = 1;
4342                 }
4343             }
4344         }
4346         if (! $in_ac_replace && s/AC_REPLACE_FUNCS\s*\(\[?//)
4347         {
4348             $in_ac_replace = 1;
4349         }
4350         if ($in_ac_replace)
4351         {
4352             $in_ac_replace = 0 if s/[\]\)].*$//;
4353             # Remove trailing backslash.
4354             s/\\$//;
4355             foreach (split)
4356             {
4357                 # Need to skip empty elements for Perl 4.
4358                 next if $_ eq '';
4359                 $libsources{$_ . '.c'} = 1;
4360             }
4361         }
4363         if (/$obsolete_rx/o)
4364         {
4365             local ($hint) = '';
4366             if ($obsolete_macros{$1} ne '')
4367             {
4368                 $hint = '; ' . $obsolete_macros{$1};
4369             }
4370             &am_conf_line_error ($filename, $., "\`$1' is obsolete$hint");
4371         }
4373         # Process the AC_OUTPUT macro.
4374         if (! $in_ac_output && s/AC_OUTPUT\s*\(\[?//)
4375         {
4376             $in_ac_output = 1;
4377             $ac_output_line = $.;
4378         }
4379         if ($in_ac_output)
4380         {
4381             local ($closing) = 0;
4382             if (s/[\]\),].*$//)
4383             {
4384                 $in_ac_output = 0;
4385                 $closing = 1;
4386             }
4388             # Look at potential Makefile.am's.
4389             foreach (split)
4390             {
4391                 # Must skip empty string for Perl 4.
4392                 next if $_ eq "\\" || $_ eq '';
4394                 # Handle $local:$input syntax.  Note that we ignore
4395                 # every input file past the first, though we keep
4396                 # those around for later.
4397                 local ($local, $input, @rest) = split (/:/);
4398                 if (! $input)
4399                 {
4400                     $input = $local;
4401                 }
4402                 else
4403                 {
4404                     # FIXME: should be error if .in is missing.
4405                     $input =~ s/\.in$//;
4406                 }
4408                 if (-f $input . '.am')
4409                 {
4410                     # We have a file that automake should generate.
4411                     push (@make_input_list, $input);
4412                     $make_list{$input} = join (':', ($local, @rest));
4413                 }
4414                 else
4415                 {
4416                     # We have a file that automake should cause to be
4417                     # rebuilt, but shouldn't generate itself.
4418                     push (@other_input_files, $_);
4419                 }
4420             }
4422             if ($closing && @make_input_list == 0 && @other_input_files == 0)
4423             {
4424                 &am_conf_line_error ($filename, $ac_output_line,
4425                                      "No files mentioned in \`AC_OUTPUT'");
4426                 exit 1;
4427             }
4428         }
4430         if (/$AC_CONFIG_AUX_DIR_PATTERN/o)
4431         {
4432             @config_aux_path = $1;
4433         }
4435         # Check for ansi2knr.
4436         $am_c_prototypes = 1 if /AM_C_PROTOTYPES/;
4438         # Check for exe extension stuff.
4439         if (/AC_EXEEXT/)
4440         {
4441             $seen_exeext = 1;
4442             $configure_vars{'EXEEXT'} = $filename . ':' . $.;
4443         }
4445         if (/AC_OBJEXT/)
4446         {
4447             $seen_objext = 1;
4448             $configure_vars{'OBJEXT'} = $filename . ':' . $.;
4449         }
4451         # Check for `-c -o' code.
4452         $seen_cc_c_o = 1 if /AM_PROG_CC_C_O/;
4454         # Check for NLS support.
4455         if (/AM_GNU_GETTEXT/)
4456         {
4457             $seen_gettext = 1;
4458             $ac_gettext_line = $.;
4459             $omit_dependencies{'libintl.h'} = 1;
4460         }
4462         # Look for ALL_LINGUAS.
4463         if (/ALL_LINGUAS="(.*)"$/ || /ALL_LINGUAS=(.*)$/)
4464         {
4465             $seen_linguas = 1;
4466             $all_linguas = $1;
4467             $all_linguas_line = $.;
4468         }
4470         # Handle configuration headers.  A config header of `[$1]'
4471         # means we are actually scanning AM_CONFIG_HEADER from
4472         # aclocal.m4.
4473         if (/A([CM])_CONFIG_HEADER\s*\((.*)\)/
4474             && $2 ne '[$1]')
4475         {
4476             &am_conf_line_error
4477                 ($filename, $., "\`automake requires \`AM_CONFIG_HEADER', not \`AC_CONFIG_HEADER'")
4478                     if $1 eq 'C';
4480             $config_header_line = $.;
4481             local ($one_hdr);
4482             foreach $one_hdr (split (' ', $2))
4483             {
4484                 push (@config_fullnames, $one_hdr);
4485                 if ($one_hdr =~ /^([^:]+):(.+)$/)
4486                 {
4487                     push (@config_names, $1);
4488                     push (@config_headers, $2);
4489                 }
4490                 else
4491                 {
4492                     push (@config_names, $one_hdr);
4493                     push (@config_headers, $one_hdr . '.in');
4494                 }
4495             }
4496         }
4498         # Handle AC_CANONICAL_*.  Always allow upgrading to
4499         # AC_CANONICAL_SYSTEM, but never downgrading.
4500         $seen_canonical = $AC_CANONICAL_HOST
4501             if ! $seen_canonical
4502                 && (/AC_CANONICAL_HOST/ || /AC_CHECK_TOOL/);
4503         $seen_canonical = $AC_CANONICAL_SYSTEM if /AC_CANONICAL_SYSTEM/;
4505         $seen_path_xtra = 1 if /AC_PATH_XTRA/;
4507         # This macro handles several different things.
4508         if (/$AM_INIT_AUTOMAKE_PATTERN/o)
4509         {
4510             $seen_make_set = 1;
4511             $seen_package = 1;
4512             $seen_version = 1;
4513             $seen_arg_prog = 1;
4514             $seen_prog_install = 1;
4515             ($package_version = $1) =~ s/$AM_PACKAGE_VERSION_PATTERN/$1/o;
4516             $package_version_line = $.;
4517         }
4519         # This is like AM_INIT_AUTOMAKE, but doesn't actually set the
4520         # package and version number.  (This might change in the
4521         # future).  Yes, I'm not above hacking Automake so it works
4522         # well with other GNU tools -- that is actually the point.
4523         if (/AM_INIT_GUILE_MODULE/)
4524         {
4525             $seen_make_set = 1;
4526             $seen_package = 1;
4527             $seen_version = 1;
4528             $seen_arg_prog = 1;
4529             $seen_prog_install = 1;
4530             @config_aux_path = ('..');
4531         }
4533         # Some things required by Automake.
4534         $seen_make_set = 1 if /AC_PROG_MAKE_SET/;
4535         $seen_arg_prog = 1 if /AC_ARG_PROGRAM/;
4537         if (/AM_PROG_LEX/)
4538         {
4539             $configure_vars{'LEX'} = $filename . ':' . $.;
4540             $seen_decl_yytext = 1;
4541         }
4542         if (/AC_DECL_YYTEXT/ && $filename =~ /configure\.in$/)
4543         {
4544             &am_conf_line_warning ($filename, $., "\`AC_DECL_YYTEXT' is covered by \`AM_PROG_LEX'");
4545         }
4546         if (/AC_PROG_LEX/ && $filename =~ /configure\.in$/)
4547         {
4548             &am_conf_line_warning ($filename, $., "automake requires \`AM_PROG_LEX', not \`AC_PROG_LEX'");
4549         }
4551         if (/AC_PROG_(F77|YACC|RANLIB|CC|CXXCPP|CXX|LEX|AWK|CPP|LN_S)/)
4552         {
4553             $configure_vars{$1} = $filename . ':' . $.;
4554         }
4555         if (/$AC_CHECK_PATTERN/o)
4556         {
4557             $configure_vars{$3} = $filename . ':' . $.;
4558         }
4559         if (/$AM_MISSING_PATTERN/o
4560             && $1 ne 'ACLOCAL'
4561             && $1 ne 'AUTOCONF'
4562             && $1 ne 'AUTOMAKE'
4563             && $1 ne 'AUTOHEADER')
4564         {
4565             $configure_vars{$1} = $filename . ':' . $.;
4566         }
4568         # Explicitly avoid ANSI2KNR -- we AC_SUBST that in protos.m4,
4569         # but later define it elsewhere.  This is pretty hacky.  We
4570         # also explicitly avoid INSTALL_SCRIPT and some other
4571         # variables because they are defined in header-vars.am.
4572         # FIXME.
4573         if (/$AC_SUBST_PATTERN/o
4574             && $1 ne 'ANSI2KNR'
4575             && $1 ne 'INSTALL_SCRIPT'
4576             && $1 ne 'INSTALL_DATA')
4577         {
4578             $configure_vars{$1} = $filename . ':' . $.;
4579         }
4581         $seen_decl_yytext = 1 if /AC_DECL_YYTEXT/;
4582         if (/AM_MAINTAINER_MODE/)
4583         {
4584             $seen_maint_mode = 1;
4585             $configure_cond{'MAINTAINER_MODE'} = 1;
4586         }
4587         $seen_package = 1 if /PACKAGE=/;
4589         # Skip VERSION of [$2]; that is from AM_INIT_AUTOMAKE.
4590         if (/\bVERSION=(\S+)/ && $1 ne '[$2]')
4591         {
4592             $seen_version = 1;
4593             $package_version = $1;
4594             $package_version_line = $.;
4595         }
4596         elsif (/VERSION=/)
4597         {
4598             $seen_version = 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 ("\`PACKAGE' not defined in configure.in")
4665         if ! $seen_package;
4666     &am_conf_error ("\`VERSION' not defined in configure.in")
4667         if ! $seen_version;
4669     # Look for some files we need.  Always check for these.  This
4670     # check must be done for every run, even those where we are only
4671     # looking at a subdir Makefile.  We must set relative_dir so that
4672     # the file-finding machinery works.
4673     local ($relative_dir) = '.';
4674     &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs', 'missing');
4675     if ($cmdline_use_dependencies)
4676     {
4677         &require_config_file ($FOREIGN, 'depcomp');
4678     }
4679     &am_error ("\`install.sh' is an anachronism; use \`install-sh' instead")
4680         if -f $config_aux_path[0] . '/install.sh';
4682     &require_config_file ($FOREIGN, 'py-compile')
4683         if $seen_pythondir;
4686 ################################################################
4688 # Set up for Cygnus mode.
4689 sub check_cygnus
4691     return unless $cygnus_mode;
4693     &set_strictness ('foreign');
4694     $options{'no-installinfo'} = 1;
4695     $options{'no-dependencies'} = 1;
4696     $use_dependencies = 0;
4698     if (! $seen_maint_mode)
4699     {
4700         &am_conf_error ("\`AM_MAINTAINER_MODE' required when --cygnus specified");
4701     }
4703     if (! $seen_exeext)
4704     {
4705         &am_conf_error ("\`AC_EXEEXT' required when --cygnus specified");
4706     }
4709 # Do any extra checking for GNU standards.
4710 sub check_gnu_standards
4712     if ($relative_dir eq '.')
4713     {
4714         # In top level (or only) directory.
4715         &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
4716                        'AUTHORS', 'ChangeLog');
4717     }
4719     if ($strictness >= $GNU)
4720     {
4721         if (defined $options{'no-installman'})
4722         {
4723             &am_line_error ('AUTOMAKE_OPTIONS',
4724                             "option \`no-installman' disallowed by GNU standards");
4725         }
4727         if (defined $options{'no-installinfo'})
4728         {
4729             &am_line_error ('AUTOMAKE_OPTIONS',
4730                             "option \`no-installinfo' disallowed by GNU standards");
4731         }
4732     }
4735 # Do any extra checking for GNITS standards.
4736 sub check_gnits_standards
4738     if ($relative_dir eq '.')
4739     {
4740         # In top level (or only) directory.
4741         &require_file ($GNITS, 'THANKS');
4742     }
4745 ################################################################
4747 # Functions to handle files of each language.
4749 # Each `lang_X_rewrite' function follows a simple formula:
4750 # * Args are the directory, base name and extension of the file.
4751 # * Return value is 1 if file is to be dealt with, 0 otherwise.
4752 # Much of the actual processing is handled in handle_single_transform_list.
4753 # These functions exist so that auxiliary information can be recorded
4754 # for a later cleanup pass.  Note that the calls to these functions
4755 # are computed, so don't bother searching for their precise names
4756 # in the source.
4758 # This is just a convenience function that can be used to determine
4759 # when a subdir object should be used.
4760 sub lang_sub_obj
4762     return defined $options{'subdir-objects'} ? $LANG_SUBDIR : $LANG_PROCESS;
4765 # Rewrite a single C source file.
4766 sub lang_c_rewrite
4768     local ($directory, $base, $ext) = @_;
4770     if (defined $options{'ansi2knr'} && $base =~ /_$/)
4771     {
4772         # FIXME: include line number in error.
4773         &am_error ("C source file \`$base.c' would be deleted by ansi2knr rules");
4774     }
4776     local ($r) = $LANG_PROCESS;
4777     if (defined $options{'subdir-objects'})
4778     {
4779         $r = $LANG_SUBDIR;
4780         $base = $directory . '/' . $base;
4782         if (! $seen_cc_c_o)
4783         {
4784             # Only give error once.
4785             $seen_cc_c_o = 1;
4786             # FIXME: line number.
4787             &am_error ("C objects in subdir but \`AM_PROG_CC_C_O' not in \`configure.in'");
4788         }
4790         &require_file ($FOREIGN, 'compile')
4791             if $relative_dir eq '.';
4792     }
4794     $de_ansi_files{$base} = 1;
4795     return $r;
4798 # Rewrite a single C++ source file.
4799 sub lang_cxx_rewrite
4801     return &lang_sub_obj;
4804 # Rewrite a single header file.
4805 sub lang_header_rewrite
4807     # Header files are simply ignored.
4808     return $LANG_IGNORE;
4811 # Rewrite a single yacc file.
4812 sub lang_yacc_rewrite
4814     local ($directory, $base, $ext) = @_;
4816     local ($r) = &lang_c_rewrite ($directory, $base, $ext);
4817     local ($pfx) = '';
4818     if ($r == $LANG_SUBDIR)
4819     {
4820         $pfx = $directory . '/';
4821     }
4822     $yacc_sources{$pfx . $base . '.' . $ext} = 1;
4823     $ext =~ tr/y/c/;
4824     &saw_extension ('c');
4825     # FIXME: nodist.
4826     &push_dist_common ($pfx . $base . '.' . $ext);
4827     return $r;
4830 # Rewrite a single yacc++ file.
4831 sub lang_yaccxx_rewrite
4833     local ($directory, $base, $ext) = @_;
4835     local ($r) = $LANG_PROCESS;
4836     local ($pfx) = '';
4837     if (defined $options{'subdir-objects'})
4838     {
4839         $pfx = $directory . '/';
4840         $r = $LANG_SUBDIR;
4841     }
4842     $yacc_sources{$pfx . $base . '.' . $ext} = 1;
4843     $ext =~ tr/y/c/;
4844     &saw_extension ($ext);
4845     # FIXME: nodist.
4846     &push_dist_common ($pfx . $base . '.' . $ext);
4847     return $r;
4850 # Rewrite a single lex file.
4851 sub lang_lex_rewrite
4853     local ($directory, $base, $ext) = @_;
4855     local ($r) = &lang_c_rewrite ($directory, $base, $ext);
4856     local ($pfx) = '';
4857     if ($r == $LANG_SUBDIR)
4858     {
4859         $pfx = $directory . '/';
4860     }
4861     $lex_sources{$pfx . $base . '.' . $ext} = 1;
4862     $ext =~ tr/l/c/;
4863     &saw_extension ('c');
4864     # FIXME: nodist.
4865     &push_dist_common ($pfx . $base . '.' . $ext);
4866     return $r;
4869 # Rewrite a single lex++ file.
4870 sub lang_lexxx_rewrite
4872     local ($directory, $base, $ext) = @_;
4874     local ($r) = $LANG_PROCESS;
4875     local ($pfx) = '';
4876     if (defined $options{'subdir-objects'})
4877     {
4878         $pfx = $directory . '/';
4879         $r = $LANG_SUBDIR;
4880     }
4881     $lex_sources{$pfx . $base . '.' . $ext} = 1;
4882     $ext =~ tr/l/c/;
4883     &saw_extension ($ext);
4884     # FIXME: nodist.
4885     &push_dist_common ($pfx . $base . '.' . $ext);
4886     return $r;
4889 # Rewrite a single assembly file.
4890 sub lang_asm_rewrite
4892     return &lang_sub_obj;
4895 # Rewrite a single Fortran 77 file.
4896 sub lang_f77_rewrite
4898     return $LANG_PROCESS;
4901 # Rewrite a single preprocessed Fortran 77 file.
4902 sub lang_ppf77_rewrite
4904     return $LANG_PROCESS;
4907 # Rewrite a single ratfor file.
4908 sub lang_ratfor_rewrite
4910     return $LANG_PROCESS;
4913 # Rewrite a single Objective C file.
4914 sub lang_objc_rewrite
4916     return &lang_sub_obj;
4919 # Rewrite a single Java file.
4920 sub lang_java_rewrite
4922     return $LANG_SUBDIR;
4925 # The lang_X_finish functions are called after all source file
4926 # processing is done.  Each should handle defining rules for the
4927 # language, etc.  A finish function is only called if a source file of
4928 # the appropriate type has been seen.
4930 sub lang_c_finish
4932     # Push all libobjs files onto de_ansi_files.  We actually only
4933     # push files which exist in the current directory, and which are
4934     # genuine source files.
4935     local ($file);
4936     foreach $file (keys %libsources)
4937     {
4938         if ($file =~ /^(.*)\.[cly]$/ && -f "$relative_dir/$file")
4939         {
4940             $de_ansi_files{$1} = 1;
4941         }
4942     }
4944     if (defined $options{'ansi2knr'} && keys %de_ansi_files)
4945     {
4946         # Make all _.c files depend on their corresponding .c files.
4947         local ($base, @objects);
4948         foreach $base (sort keys %de_ansi_files)
4949         {
4950             # Each _.c file must depend on ansi2knr; otherwise it
4951             # might be used in a parallel build before it is built.
4952             # We need to support files in the srcdir and in the build
4953             # dir (because these files might be auto-generated.  But
4954             # we can't use $< -- some makes only define $< during a
4955             # suffix rule.
4956             $output_rules .= ($base . "_.c: $base.c \$(ANSI2KNR)\n\t"
4957                               . '$(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) '
4958                               . '`if test -f $(srcdir)/' . $base . '.c'
4959                               . '; then echo $(srcdir)/' . $base . '.c'
4960                               . '; else echo ' . $base . '.c; fi` '
4961                               . "| sed 's/^# \\([0-9]\\)/#line \\1/' "
4962                               . '| $(ANSI2KNR) > ' . $base . "_.c\n");
4963             push (@objects, $base . '_'
4964                   . ($seen_objext ? '.$(OBJEXT)' : '.o'));
4965             push (@objects, $base . '_.lo') if $seen_libtool;
4966         }
4968         # Make all _.o (and _.lo) files depend on ansi2knr.
4969         # Use a sneaky little hack to make it print nicely.
4970         &pretty_print_rule ('', '', @objects, ':', '$(ANSI2KNR)');
4971     }
4973     if (! defined $configure_vars{'CC'})
4974     {
4975         # FIXME: line number.
4976         &am_error ("C source seen but \`CC' not defined in \`configure.in'");
4977     }
4980 sub lang_cxx_finish
4982     local ($ltcompile, $ltlink) = &libtool_compiler;
4984     &define_variable ('CXXLD', '$(CXX)');
4985     &define_variable ('CXXLINK', $ltlink . '$(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
4987     if (! defined $configure_vars{'CXX'})
4988     {
4989         &am_error ("C++ source seen but \`CXX' not defined in \`configure.in'");
4990     }
4993 sub lang_header_finish
4995     # Nothing to do.
4998 # This is a helper for both lex and yacc.
4999 sub yacc_lex_finish_helper
5001     return if defined $language_scratch{'lex-yacc-done'};
5002     $language_scratch{'lex-yacc-done'} = 1;
5004     # If there is more than one distinct yacc (resp lex) source file
5005     # in a given directory, then the `ylwrap' program is required to
5006     # allow parallel builds to work correctly.  FIXME: for now, no
5007     # line number.
5008     &require_config_file ($FOREIGN, 'ylwrap');
5009     if ($config_aux_dir ne '.' && $config_aux_dir ne '')
5010     {
5011         &define_variable ('YLWRAP', $config_aux_dir . "/ylwrap");
5012     }
5013     else
5014     {
5015         &define_variable ('YLWRAP', '$(srcdir)/ylwrap');
5016     }
5019 sub lang_yacc_finish
5021     return if defined $language_scratch{'yacc-done'};
5022     $language_scratch{'yacc-done'} = 1;
5024     local ($file, $base, $hname, $cname);
5025     local (%seen_suffix) = ();
5026     local (@yacc_files) = sort keys %yacc_sources;
5027     local ($yacc_count) = scalar (@yacc_files);
5028     foreach $file (@yacc_files)
5029     {
5030         $file =~ /(\..*)$/;
5031         &output_yacc_build_rule ($1, $yacc_count > 1)
5032             if ! defined $seen_suffix{$1};
5033         $seen_suffix{$1} = 1;
5035         $file =~ /^(.*)\.(y|yy|y\+\+|yxx|ypp)$/;
5036         $base = $1;
5037         $hname = 'h';           # Always use `.h' for header file.
5038         ($cname = $2) =~ tr/y/c/;
5040         if ((&variable_defined ('AM_YFLAGS')
5041              && &variable_value ('AM_YFLAGS') =~ /(^|\s)-d(\s|$)/)
5042             || (&variable_defined ('YFLAGS')
5043                 && &variable_value ('YFLAGS') =~ /(^|\s)-d(\s|$)/)) {
5044             # Now generate rule to make the header file.  This should only
5045             # be generated if `yacc -d' specified.
5046             $output_rules .= "${base}.${hname}: ${base}.${cname}\n";
5048             # If the files are built in the build directory, then we want
5049             # to remove them with `make clean'.  If they are in srcdir
5050             # they shouldn't be touched.  However, we can't determine this
5051             # statically, and the GNU rules say that yacc/lex output files
5052             # should be removed by maintainer-clean.  So that's what we
5053             # do.
5054             push (@maintainer_clean_files, "${base}.${hname}");
5056             &push_dist_common ("${base}.${hname}");
5057         }
5058         push (@maintainer_clean_files, "${base}.${cname}");
5059     }
5060     $output_rules .= "\n";
5062     if (! defined $configure_vars{'YACC'})
5063     {
5064         &am_error ("yacc source seen but \`YACC' not defined in \`configure.in'");
5065     }
5066     if (&variable_defined ('YACCFLAGS'))
5067     {
5068         &am_line_error ('YACCFLAGS',
5069                         "\`YACCFLAGS' obsolete; use \`YFLAGS' instead");
5070     }
5072     if ($yacc_count > 1)
5073     {
5074         &yacc_lex_finish_helper;
5075     }
5078 sub lang_yaccxx_finish
5080     &lang_yacc_finish;
5083 sub lang_lex_finish
5085     return if defined $language_scratch{'lex-done'};
5086     $language_scratch{'lex-done'} = 1;
5088     local (%seen_suffix) = ();
5089     local ($file, $cname);
5090     local ($lex_count) = scalar (keys %lex_sources);
5091     foreach $file (sort keys %lex_sources)
5092     {
5093         $file =~ /(\..*)$/;
5094         &output_lex_build_rule ($1, $lex_count > 1)
5095             if (! defined $seen_suffix{$1});
5096         $seen_suffix{$1} = 1;
5098         # If the files are built in the build directory, then we want
5099         # to remove them with `make clean'.  If they are in srcdir
5100         # they shouldn't be touched.  However, we can't determine this
5101         # statically, and the GNU rules say that yacc/lex output files
5102         # should be removed by maintainer-clean.  So that's what we
5103         # do.
5104         $file =~ /^(.*)\.(l|ll|l\+\+|lxx|lpp)$/;
5105         ($cname = $2) =~ tr/l/c/;
5106         push (@maintainer_clean_files, "${1}.${cname}");
5107     }
5109     if (! defined $configure_vars{'LEX'})
5110     {
5111         &am_error ("lex source seen but \`LEX' not defined in \`configure.in'");
5112     }
5113     if (! $seen_decl_yytext)
5114     {
5115         &am_error ("lex source seen but \`AC_DECL_YYTEXT' not in \`configure.in'");
5116     }
5118     if ($lex_count > 1)
5119     {
5120         &yacc_lex_finish_helper;
5121     }
5124 sub lang_lexxx_finish
5126     &lang_lex_finish;
5129 sub lang_asm_finish
5131     # We need the C code for assembly.
5132     &lang_c_finish;
5135 sub lang_f77_finish
5137     # FIXME: this function can be called more than once.  We should
5138     # arrange for it to only do anything the first time through.
5140     local ($ltcompile, $ltlink) = &libtool_compiler;
5142     &define_variable ('F77LD', '$(F77)');
5143     &define_variable ('F77LINK', $ltlink . '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
5145     if (! defined $configure_vars{'F77'})
5146     {
5147         &am_error ("Fortran 77 source seen but \`F77' not defined in \`configure.in'");
5148     }
5151 # Preprocessed Fortran 77
5153 # The current support for preprocessing Fortran 77 just involves passing
5154 # `$(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)' as additional flags
5155 # to the Fortran 77 compiler, since this is how GNU Make does it; see
5156 # the `GNU Make Manual, Edition 0.51 for `make' Version 3.76 Beta'
5157 # (specifically, from info file `(make)Catalogue of Rules').
5159 # A better approach would be to write an Autoconf test
5160 # (i.e. AC_PROG_FPP) for a Fortran 77 preprocessor, because not all
5161 # Fortran 77 compilers know how to do preprocessing.  The Autoconf macro
5162 # AC_PROG_FPP should test the Fortran 77 compiler first for
5163 # preprocessing capabilities, and then fall back on cpp (if cpp were
5164 # available).
5165 sub lang_ppf77_finish
5167     &lang_f77_finish;
5169     # We also handle the case of preprocessing `.F' files into `.f'
5170     # files.
5171     $output_rules .= (".F.f:\n"
5172                       . "\t\$(F77COMPILE) -F \$<\n");
5175 sub lang_ratfor_finish
5177     &lang_f77_finish;
5179     # We also handle the case of preprocessing `.r' files into `.f'
5180     # files.
5181     $output_rules .= (".r.f:\n"
5182                       . "\t\$(RCOMPILE) -F \$<\n");
5185 sub lang_objc_finish
5187     local ($ltcompile, $ltlink) = &libtool_compiler;
5189     &define_variable ('OBJCLD', '$(OBJC)');
5190     &define_variable ('OBJCLINK', $ltlink . '$(OBJCLD) $(AM_OBJCFLAGS) $(OBJCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
5192     if (! defined $configure_vars{'OBJC'})
5193     {
5194         &am_error ("Objective C source seen but \`OBJC' not defined in \`configure.in'");
5195     }
5198 sub lang_java_finish
5200     local ($ltcompile, $ltlink) = &libtool_compiler;
5202     &define_variable ('GCJLD', '$(GCJ)');
5203     &define_variable ('GCJLINK', $ltlink . '$(GCJLD) $(AM_GCJFLAGS) $(GCJFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
5205     if (! defined $configure_vars{'GCJ'})
5206     {
5207         &am_error ("Java source seen but \`GCJ' not defined in \`configure.in'");
5208     }
5211 # A helper which computes a sorted list of all extensions for LANG.
5212 sub lang_extensions
5214     local ($lang) = @_;
5215     local ($key, @r);
5216     foreach $key (sort keys %extension_seen)
5217     {
5218         push (@r, '.' . $key) if $extension_map{$key} eq $lang;
5219     }
5220     return @r;
5223 # A helper which decides whether libtool is needed.  Returns prefix
5224 # for compiler and linker.
5225 sub libtool_compiler
5227     local ($ltcompile, $ltlink) = ('', '');
5228     if ($seen_libtool)
5229     {
5230         &define_configure_variable ("LIBTOOL");
5231         $ltcompile = '$(LIBTOOL) --mode=compile ';
5232         $ltlink = '$(LIBTOOL) --mode=link ';
5233     }
5234     return ($ltcompile, $ltlink);
5237 # Given a hash table of linker names, pick the name that has the most
5238 # precedence.  This is lame, but something has to have global
5239 # knowledge in order to eliminate the conflict.  Add more linkers as
5240 # required.
5241 sub resolve_linker
5243     local (%linkers) = @_;
5245     return 'GCJLINK'
5246         if defined $linkers{'GCJLINK'};
5247     return 'CXXLINK'
5248         if defined $linkers{'CXXLINK'};
5249     return 'F77LINK'
5250         if defined $linkers{'F77LINK'};
5251     return 'OBJCLINK'
5252         if defined $linkers{'OBJCLINK'};
5253     return 'LINK';
5256 # Called to indicate that an extension was used.
5257 sub saw_extension
5259     local ($ext) = @_;
5260     $extension_seen{$ext} = 1;
5263 # Called to ask whether source files have been seen . If HEADERS is 1,
5264 # headers can be included.
5265 sub saw_sources_p
5267     local ($headers) = @_;
5269     if ($headers)
5270     {
5271         $headers = 0;
5272     }
5273     else
5274     {
5275         local (@exts) = &lang_extensions ('header');
5276         $headers = @exts;
5277     }
5279     return scalar keys %extension_seen > $headers;
5282 # Register a single language.  LANGUAGE is the name of the language.
5283 # Each OPTION is either of the form NAME=VALUE, or is a file extension
5284 # (sans `.').
5285 sub register_language
5287     local ($language, @options) = @_;
5289     # Set the defaults.
5290     $language_map{$language . '-ansi-p'} = 0;
5291     $language_map{$language . '-linker'} = '';
5292     $language_map{$language . '-autodep'} = 'no';
5294     local ($iter);
5295     foreach $iter (@options)
5296     {
5297         if ($iter =~ /^(.*)=(.*)$/)
5298         {
5299             $language_map{$language . '-' . $1} = $2;
5300         }
5301         elsif (defined $extension_map{$iter})
5302         {
5303             print STDERR
5304                 "automake: programming error: duplicate extension $iter\n";
5305             exit 1;
5306         }
5307         else
5308         {
5309             $extension_map{$iter} = $language;
5310         }
5311     }
5314 # This function is used to find a path from a user-specified suffix to
5315 # `o' or to some other suffix we recognize internally, eg `cc'.
5316 sub derive_suffix
5318     local ($source_ext) = @_;
5320     # FIXME: hard-coding `o' is a mistake.  Doing something
5321     # intelligent is harder.
5322     while ($extension_map{$source_ext} eq ''
5323            && $source_ext ne 'o'
5324            && defined $suffix_rules{$source_ext})
5325     {
5326         $source_ext = $suffix_rules{$source_ext};
5327     }
5329     return $source_ext;
5333 ################################################################
5335 # Pretty-print something.  HEAD is what should be printed at the
5336 # beginning of the first line, FILL is what should be printed at the
5337 # beginning of every subsequent line.
5338 sub pretty_print_internal
5340     local ($head, $fill, @values) = @_;
5342     local ($column) = length ($head);
5343     local ($result) = $head;
5345     # Fill length is number of characters.  However, each Tab
5346     # character counts for eight.  So we count the number of Tabs and
5347     # multiply by 7.
5348     local ($fill_length) = length ($fill);
5349     $fill_length += 7 * ($fill =~ tr/\t/\t/d);
5351     local ($bol) = ($head eq '');
5352     foreach (@values)
5353     {
5354         # "71" because we also print a space.
5355         if ($column + length ($_) > 71)
5356         {
5357             $result .= " \\\n" . $fill;
5358             $column = $fill_length;
5359             $bol = 1;
5360         }
5362         $result .= ' ' unless ($bol);
5363         $result .= $_;
5364         $column += length ($_) + 1;
5365         $bol = 0;
5366     }
5368     $result .= "\n";
5369     return $result;
5372 # Pretty-print something and append to output_vars.
5373 sub pretty_print
5375     $output_vars .= &pretty_print_internal (@_);
5378 # Pretty-print something and append to output_rules.
5379 sub pretty_print_rule
5381     $output_rules .= &pretty_print_internal (@_);
5385 ################################################################
5387 # See if a target exists.
5388 sub target_defined
5390     local ($target) = @_;
5391     return defined $targets{$target};
5394 # See if two conditionals are the same.
5395 sub conditional_same
5397     local ($cond1, $cond2) = @_;
5399     return (&conditional_true_when ($cond1, $cond2)
5400             && &conditional_true_when ($cond2, $cond1));
5403 # See if a conditional is true.  Both arguments are conditional
5404 # strings.  This returns true if the first conditional is true when
5405 # the second conditional is true.
5406 sub conditional_true_when
5408     local ($cond, $when) = @_;
5410     # Check the easy case first.
5411     if ($cond eq $when)
5412     {
5413         return 1;
5414     }
5416     # Check each component of $cond, which looks @COND1@@COND2@.
5417     foreach $comp (split ('@', $cond))
5418     {
5419         # The way we split will give null strings between each
5420         # condition.
5421         next if ! $comp;
5423         if (index ($when, '@' . $comp . '@') == -1)
5424         {
5425             return 0;
5426         }
5427     }
5429     return 1;
5432 # Check for an ambiguous conditional.  This is called when a variable
5433 # or target is being defined conditionally.  If we already know about
5434 # a definition that is true under the same conditions, then we have an
5435 # ambiguity.
5436 sub check_ambiguous_conditional
5438     local ($var_name, $cond) = @_;
5439     local (@cond_vals) = split (' ', $conditional{$var_name});
5440     while (@cond_vals)
5441     {
5442         local ($vcond) = shift (@cond_vals);
5443         shift (@cond_vals);
5444         if (&conditional_true_when ($vcond, $cond)
5445             || &conditional_true_when ($cond, $vcond))
5446         {
5447             &am_line_error ($var_name,
5448                             "$var_name multiply defined in condition");
5449         }
5450     }
5453 # See if a variable exists.  The first argument is the variable name,
5454 # and the optional second argument is the condition which we should
5455 # check.  If no condition is given, we currently return true if the
5456 # variable is defined under any condition.
5457 sub variable_defined
5459     local ($var, $cond) = @_;
5460     if (defined $targets{$var})
5461     {
5462         &am_line_error ($var, "\`$var' is target; expected variable");
5463         return 0;
5464     }
5465     elsif (defined $contents{$var})
5466     {
5467         if ($cond && $conditional{$var})
5468         {
5469             # We have been asked to check for a particular condition,
5470             # and the variable is defined conditionally.  We need to
5471             # look through the conditions under which the variable is
5472             # defined, and see if any of them match the conditional we
5473             # have been asked to check.
5474             local (@cond_vars) = split (' ', $conditional{$var});
5475             while (@cond_vars)
5476             {
5477                 if (&conditional_same ($cond, shift (@cond_vars)))
5478                 {
5479                     # Even a conditional examination is good enough
5480                     # for us.  FIXME: really should maintain examined
5481                     # status on a per-condition basis.
5482                     $content_seen{$var} = 1;
5483                     return 1;
5484                 }
5485                 shift (@cond_vars);
5486             }
5488             # The variable is not defined for the given condition.
5489             return 0;
5490         }
5492         $content_seen{$var} = 1;
5493         return 1;
5494     }
5495     return 0;
5498 # Mark a variable as examined.
5499 sub examine_variable
5501     local ($var) = @_;
5502     &variable_defined ($var);
5505 # Quote a value in order to put it in $conditional.  We need to quote
5506 # spaces, and we need to handle null strings, so that we can later
5507 # retrieve values by splitting on space.
5508 sub quote_cond_val
5510     local ($val) = @_;
5511     $val =~ tr/ \t\n/\001\003\004/;
5512     $val = "\002" if $val eq '';
5513     return $val;
5516 # Unquote a value in $conditional.
5517 sub unquote_cond_val
5519     local ($val) = @_;
5520     $val =~ tr/\001\003\004/ \t\n/;
5521     $val =~ s/\002//g;
5522     return $val;
5525 # Return the set of conditions for which a variable is defined.
5527 # If the variable is not defined conditionally, and is not defined in
5528 # terms of any variables which are defined conditionally, then this
5529 # returns the empty list.
5531 # If the variable is defined conditionally, but is not defined in
5532 # terms of any variables which are defined conditionally, then this
5533 # returns the list of conditions for which the variable is defined.
5535 # If the variable is defined in terms of any variables which are
5536 # defined conditionally, then this returns a full set of permutations
5537 # of the subvariable conditions.  For example, if the variable is
5538 # defined in terms of a variable which is defined for @COND_TRUE@,
5539 # then this returns both @COND_TRUE@ and @COND_FALSE@.  This is
5540 # because we will need to define the variable under both conditions.
5542 sub variable_conditions
5544     local ($var) = @_;
5545     local (%uniqify);
5546     local (@uniq_list);
5547     local ($cond);
5549     %vars_scanned = ();
5550     foreach $cond (&variable_conditions_sub ($var, '', ()))
5551     {
5552         $uniqify{$cond} = 1;
5553     }
5555     @uniq_list = sort keys %uniqify;
5556     # Note we cannot just do `return sort keys %uniqify', because this
5557     # function is sometimes used in a scalar context.
5558     return @uniq_list;
5561 # A subroutine of variable_conditions.  We only return conditions
5562 # which are true for all the conditions in @PARENT_CONDS.
5563 sub variable_conditions_sub
5565     local ($var, $parent, @parent_conds) = @_;
5566     local (@new_conds) = ();
5568     if (defined $vars_scanned{$var})
5569     {
5570         &am_line_error ($parent, "variable \`$var' recursively defined");
5571         return ();
5572     }
5573     $vars_scanned{$var} = 1;
5575     if (! $conditional{$var})
5576     {
5577         foreach (split (' ', $contents{$var}))
5578         {
5579             # If a comment seen, just leave.
5580             last if /^#/;
5582             # Handle variable substitutions.
5583             if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
5584             {
5585                 push (@new_conds,
5586                       &variable_conditions_sub ($1, $var, @parent_conds));
5587             }
5588         }
5590         # Now we want to return all permutations of the subvariable
5591         # conditions.
5592         local (%allconds, $item);
5593         foreach $item (@new_conds)
5594         {
5595             foreach (split ('@', $item))
5596             {
5597                 next if ! $_;
5598                 s/_(TRUE|FALSE)$//;
5599                 $allconds{$_ . '_TRUE'} = 1;
5600             }
5601         }
5603         # Unset our entry in vars_scanned.  We only care about recursive
5604         # definitions.
5605         delete $vars_scanned{$var};
5607         return &variable_conditions_permutations (sort keys %allconds);
5608     }
5610     local (@this_conds) = ();
5611     local (@condvals) = split (' ', $conditional{$var});
5612     while (@condvals)
5613     {
5614         local ($cond) = shift (@condvals);
5615         local ($val) = &unquote_cond_val (shift (@condvals));
5617         if (@parent_conds)
5618         {
5619             local ($ok) = 1;
5620             local ($parent_cond);
5621             foreach $parent_cond (@parent_conds)
5622             {
5623                 if (! &conditional_true_when ($parent_cond, $cond))
5624                 {
5625                     $ok = 0;
5626                     last;
5627                 }
5628             }
5630             next if ! $ok;
5631         }
5633         push (@this_conds, $cond);
5635         push (@parent_conds, $cond);
5636         local (@subvar_conds) = ();
5637         foreach (split (' ', $val))
5638         {
5639             # If a comment seen, just leave.
5640             last if /^#/;
5642             # Handle variable substitutions.
5643             if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
5644             {
5645                 push (@subvar_conds,
5646                       &variable_conditions_sub ($1, $var, @parent_conds));
5647             }
5648         }
5649         pop (@parent_conds);
5651         # If there are no conditional subvariables, then we want to
5652         # return this condition.  Otherwise, we want to return the
5653         # permutations of the subvariables.
5654         if (! @subvar_conds)
5655         {
5656             push (@new_conds, $cond);
5657         }
5658         else
5659         {
5660             push (@new_conds, &variable_conditions_reduce (@subvar_conds));
5661         }
5662     }
5664     # Unset our entry in vars_scanned.  We only care about recursive
5665     # definitions.
5666     delete $vars_scanned{$var};
5668     return @new_conds
5669         if ! $parent;
5671     # If we are being called on behalf of another variable, we need to
5672     # return all possible permutations of the conditions.  We have
5673     # already handled everything in @this_conds along with their
5674     # subvariables.  We now need to add any permutations that are not
5675     # in @this_conds.
5676     local ($this_cond);
5677     foreach $this_cond (@this_conds)
5678     {
5679         local (@perms) =
5680             &variable_conditions_permutations (split('@', $this_cond));
5681         local ($perm);
5682         foreach $perm (@perms)
5683         {
5684             local ($scan);
5685             local ($ok) = 1;
5686             foreach $scan (@this_conds)
5687             {
5688                 if (&conditional_true_when ($perm, $scan)
5689                     || &conditional_true_when ($scan, $perm))
5690                 {
5691                     $ok = 0;
5692                     last;
5693                 }
5694             }
5695             next if ! $ok;
5697             if (@parent_conds)
5698             {
5699                 local ($ok) = 1;
5700                 local ($parent_cond);
5701                 foreach $parent_cond (@parent_conds)
5702                 {
5703                     if (! &conditional_true_when ($parent_cond, $perm))
5704                     {
5705                         $ok = 0;
5706                         last;
5707                     }
5708                 }
5710                 next if ! $ok;
5711             }
5713             # This permutation was not already handled, and is valid
5714             # for the parents.
5715             push (@new_conds, $perm);
5716         }
5717     }
5719     return @new_conds;
5722 # Subroutine for variable_conditions_sort
5723 sub variable_conditions_cmp
5725     local ($as) = $a;
5726     $as =~ s/[^@]//g;
5727     local ($bs) = $b;
5728     $bs =~ s/[^@]//g;
5729     return (length ($as) <=> length ($bs)
5730             || $a cmp $b);
5733 # Sort a list of conditionals so that only the exclusive ones are
5734 # retained.  For example, if both @COND1_TRUE@@COND2_TRUE@ and
5735 # @COND1_TRUE@ are in the list, discard the latter.
5736 sub variable_conditions_reduce
5738     local (@conds) = @_;
5739     local (@ret) = ();
5740     local ($cond);
5741     foreach $cond (sort variable_conditions_cmp @conds)
5742     {
5743         local ($ok) = 1;
5744         local ($scan);
5745         foreach $scan (@ret)
5746         {
5747             if (&conditional_true_when ($cond, $scan))
5748             {
5749                 $ok = 0;
5750                 last;
5751             }
5752         }
5753         next if ! $ok;
5754         push (@ret, $cond);
5755     }
5757     return @ret;
5760 # Return a list of permutations of a conditional string.
5761 sub variable_conditions_permutations
5763     local (@comps) = @_;
5764     return ()
5765         if ! @comps;
5766     local ($comp) = shift (@comps);
5767     return &variable_conditions_permutations (@comps)
5768         if $comp eq '';
5769     local ($neg) = $comp;
5770     $neg =~ s/TRUE$/TRUEO/;
5771     $neg =~ s/FALSE$/TRUE/;
5772     $neg =~ s/TRUEO$/FALSE/;
5773     local (@ret);
5774     local ($sub);
5775     foreach $sub (&variable_conditions_permutations (@comps))
5776     {
5777         push (@ret, '@' . $comp . '@' . $sub);
5778         push (@ret, '@' . $neg . '@' . $sub);
5779     }
5780     if (! @ret)
5781     {
5782         push (@ret, '@' . $comp . '@');
5783         push (@ret, '@' . $neg . '@');
5784     }
5785     return @ret;
5788 # Warn if a variable is conditionally defined.  This is called if we
5789 # are using the value of a variable.
5790 sub variable_conditionally_defined
5792     local ($var, $parent) = @_;
5793     if ($conditional{$var})
5794     {
5795         if ($parent)
5796         {
5797             &am_line_error ($parent,
5798                             "warning: automake does not support conditional definition of $var in $parent");
5799         }
5800         else
5801         {
5802             &am_line_error ($parent,
5803                             "warning: automake does not support $var being defined conditionally")
5804         }
5805     }
5808 # Get the value of a variable.  This just returns $contents, but warns
5809 # if the variable is conditionally defined.
5810 sub variable_value
5812     local ($var) = @_;
5813     &variable_conditionally_defined ($var);
5814     return $contents{$var};
5817 # Convert a variable value to a list, split as whitespace.  This will
5818 # recursively follow $(...) and ${...} inclusions.  It preserves @...@
5819 # substitutions.  If COND is 'all', then all values under all
5820 # conditions should be returned; if COND is a particular condition
5821 # (all conditions are surrounded by @...@) then only the value for
5822 # that condition should be returned; otherwise, warn if VAR is
5823 # conditionally defined.  SCANNED is a global hash listing whose keys
5824 # are all the variables already scanned; it is an error to rescan a
5825 # variable.
5826 sub value_to_list
5828     local ($var, $val, $cond) = @_;
5829     local (@result);
5831     # Strip backslashes
5832     $val =~ s/\\(\n|$)/ /g;
5834     foreach (split (' ', $val))
5835     {
5836         # If a comment seen, just leave.
5837         last if /^#/;
5839         # Handle variable substitutions.
5840         if (/^\$\{([^}]*)\}$/ || /^\$\(([^)]*)\)$/)
5841         {
5842             local ($varname) = $1;
5844             # If the user uses a losing variable name, just ignore it.
5845             # This isn't ideal, but people have requested it.
5846             next if ($varname =~ /\@.*\@/);
5848             local ($from, $to);
5849             local (@temp_list);
5850             if ($varname =~ /^([^:]*):([^=]*)=(.*)$/)
5851             {
5852                 $varname = $1;
5853                 $to = $3;
5854                 ($from = $2) =~ s/(\W)/\\$1/g;
5855             }
5857             # Find the value.
5858             @temp_list = &variable_value_as_list_worker ($1, $cond, $var);
5860             # Now rewrite the value if appropriate.
5861             if ($from)
5862             {
5863                 grep (s/$from$/$to/, @temp_list);
5864             }
5866             push (@result, @temp_list);
5867         }
5868         else
5869         {
5870             push (@result, $_);
5871         }
5872     }
5874     return @result;
5877 # Return contents of variable as list, split as whitespace.  This will
5878 # recursively follow $(...) and ${...} inclusions.  It preserves @...@
5879 # substitutions.  If COND is 'all', then all values under all
5880 # conditions should be returned; if COND is a particular condition
5881 # (all conditions are surrounded by @...@) then only the value for
5882 # that condition should be returned; otherwise, warn if VAR is
5883 # conditionally defined.  If PARENT is specified, it is the name of
5884 # the including variable; this is only used for error reports.
5885 sub variable_value_as_list_worker
5887     local ($var, $cond, $parent) = @_;
5888     local (@result);
5890     if (defined $targets{$var})
5891     {
5892         &am_line_error ($var, "\`$var' is target; expected variable");
5893     }
5894     elsif (! defined $contents{$var})
5895     {
5896         &am_line_error ($parent, "variable \`$var' not defined");
5897     }
5898     elsif (defined $vars_scanned{$var})
5899     {
5900         # `vars_scanned' is a global we use to keep track of which
5901         # variables we've already examined.
5902         &am_line_error ($parent, "variable \`$var' recursively defined");
5903     }
5904     elsif ($cond eq 'all' && $conditional{$var})
5905     {
5906         $vars_scanned{$var} = 1;
5907         local (@condvals) = split (' ', $conditional{$var});
5908         while (@condvals)
5909         {
5910             shift (@condvals);
5911             local ($val) = &unquote_cond_val (shift (@condvals));
5912             push (@result, &value_to_list ($var, $val, $cond));
5913         }
5914     }
5915     elsif ($cond && $conditional{$var})
5916     {
5917         $vars_scanned{$var} = 1;
5918         local (@condvals) = split (' ', $conditional{$var});
5919         local ($onceflag);
5920         while (@condvals)
5921         {
5922             local ($vcond) = shift (@condvals);
5923             local ($val) = &unquote_cond_val (shift (@condvals));
5924             if (&conditional_true_when ($vcond, $cond))
5925             {
5926                 # Warn if we have an ambiguity.  It's hard to know how
5927                 # to handle this case correctly.
5928                 &variable_conditionally_defined ($var, $parent)
5929                     if $onceflag;
5930                 $onceflag = 1;
5931                 push (@result, &value_to_list ($var, $val, $cond));
5932             }
5933         }
5934     }
5935     else
5936     {
5937         $vars_scanned{$var} = 1;
5938         &variable_conditionally_defined ($var, $parent);
5939         $content_seen{$var} = 1;
5940         push (@result, &value_to_list ($var, $contents{$var}, $cond));
5941     }
5943     # Unset our entry in vars_scanned.  We only care about recursive
5944     # definitions.
5945     delete $vars_scanned{$var};
5947     return @result;
5950 # This is just a wrapper for variable_value_as_list_worker that
5951 # initializes the global hash `vars_scanned'.  This hash is used to
5952 # avoid infinite recursion.
5953 sub variable_value_as_list
5955     local ($var, $cond, $parent) = @_;
5956     %vars_scanned = ();
5957     return &variable_value_as_list_worker ($var, $cond, $parent);
5960 # Define a new variable, but only if not already defined.
5961 sub define_variable
5963     local ($var, $value) = @_;
5965     if (! defined $contents{$var})
5966     {
5967         $output_vars .= $var . ' = ' . $value . "\n";
5968         $contents{$var} = $value;
5969         $content_seen{$var} = 1;
5970     }
5971     elsif ($var_was_plus_eq{$var})
5972     {
5973         &am_line_error ($var, "internally generated variable \`$var' was set with \`+='");
5974     }
5977 # Like define_variable, but the value is a list, and the variable may
5978 # be defined conditionally.  The second argument is the conditional
5979 # under which the value should be defined; this should be the empty
5980 # string to define the variable unconditionally.  The third argument
5981 # is a list holding the values to use for the variable.  The value is
5982 # pretty printed in the output file.
5983 sub define_pretty_variable
5985     local ($var, $cond, @value) = @_;
5986     if (! defined $contents{$var}
5987         || ($cond && ! &variable_defined ($var, $cond)))
5988     {
5989         $contents{$var} = join (' ', @value);
5990         if ($cond)
5991         {
5992             if ($conditional{$var})
5993             {
5994                 $conditional{$var} .= ' ';
5995             }
5996             else
5997             {
5998                 $conditional{$var} = '';
5999             }
6000             $conditional{$var} .= ($cond
6001                                    . ' '
6002                                    . &quote_cond_val ($contents{$var}));
6003         }
6004         &pretty_print ($cond . $var . ' = ', $cond, @value);
6005         $content_seen{$var} = 1;
6006     }
6009 # Like define_variable, but define a variable to be the configure
6010 # substitution by the same name.
6011 sub define_configure_variable
6013     local ($var) = @_;
6014     local ($value) = '@' . $var . '@';
6015     &define_variable ($var, $value);
6018 # Define a compiler variable.  We also handle defining the `LT'
6019 # version of the command when using libtool.
6020 sub define_compiler_variable
6022     local ($var, $ltcompile, $value) = @_;
6023     local ($name) = $var;
6024     &define_variable ($name, $value);
6025     &define_variable ('LT' . $name, $ltcompile . $value)
6026         if $seen_libtool;
6029 # Define a variable that represents a program to run.  If in Cygnus
6030 # mode, the program is searched for in the build (or source) tree.
6031 # Otherwise no searching is done at all.  Arguments are:
6032 # * VAR      Name of variable to define
6033 # * WHATDIR  Either `src' or `build', depending on where program should
6034 #            be found.  (runtest is in srcdir!)
6035 # * SUBDIR   Subdir of top-level dir
6036 # * PROGRAM  Name of program
6037 # * OVERRIDE If specified, the name of the program to use when not in
6038 #            Cygnus mode.  Defaults to PROGRAM.
6039 sub define_program_variable
6041     local ($var, $whatdir, $subdir, $program, $override) = @_;
6043     if (! $override)
6044     {
6045         $override = $program;
6046     }
6048     if ($cygnus_mode)
6049     {
6050         local ($full) = ('$(top_' . $whatdir . 'dir)/../'
6051                          . $subdir . '/' . $program);
6052         &define_variable ($var, ('`if test -f ' . $full
6053                                  . '; then echo ' . $full . '; else echo '
6054                                  . $program . '; fi`'));
6055     }
6056     else
6057     {
6058         &define_variable ($var, $override);
6059     }
6063 ################################################################
6065 # Read Makefile.am and set up %contents.  Simultaneously copy lines
6066 # from Makefile.am into $output_trailer or $output_vars as
6067 # appropriate.  NOTE we put rules in the trailer section.  We want
6068 # user rules to come after our generated stuff.
6069 sub read_am_file
6071     local ($amfile) = @_;
6072     local (*AM_FILE);
6074     open (AM_FILE, $amfile) || die "automake: couldn't open \`$amfile': $!\n";
6075     print "automake: reading $amfile\n" if $verbose;
6077     local ($saw_bk) = 0;
6078     local ($was_rule) = 0;
6079     local ($spacing) = '';
6080     local ($comment) = '';
6081     local ($last_var_name) = '';
6082     local ($blank) = 0;
6084     # We save the conditional stack on entry, and then check to make
6085     # sure it is the same on exit.  This lets us conditonally include
6086     # other files.
6087     local (@saved_cond_stack) = @conditional_stack;
6089     while (<AM_FILE>)
6090     {
6091         if (/$IGNORE_PATTERN/o)
6092         {
6093             # Merely delete comments beginning with two hashes.
6094         }
6095         elsif (/$WHITE_PATTERN/o)
6096         {
6097             # Stick a single white line before the incoming macro or rule.
6098             $spacing = "\n";
6099             $blank = 1;
6100         }
6101         elsif (/$COMMENT_PATTERN/o)
6102         {
6103             # Stick comments before the incoming macro or rule.  Make
6104             # sure a blank line preceeds first block of comments.
6105             $spacing = "\n" unless $blank;
6106             $blank = 1;
6107             $comment .= $spacing . $_;
6108             $spacing = '';
6109         }
6110         else
6111         {
6112             last;
6113         }
6114     }
6116     $output_vars .= $comment . "\n";
6117     $comment = '';
6118     $spacing = "\n";
6120     local ($is_ok_macro);
6121     while ($_)
6122     {
6123         $_ .= "\n"
6124             unless substr ($_, -1, 1) eq "\n";
6126         # Don't look at MAINTAINER_MODE_TRUE here.  That shouldn't be
6127         # used by users.  @MAINT@ is an anachronism now.
6128         $_ =~ s/\@MAINT\@//g
6129             unless $seen_maint_mode;
6131         if (/$IGNORE_PATTERN/o)
6132         {
6133             # Merely delete comments beginning with two hashes.
6134         }
6135         elsif (/$WHITE_PATTERN/o)
6136         {
6137             # Stick a single white line before the incoming macro or rule.
6138             $spacing = "\n";
6139             &am_line_error ($., "blank line following trailing backslash")
6140                 if $saw_bk;
6141         }
6142         elsif (/$COMMENT_PATTERN/o)
6143         {
6144             # Stick comments before the incoming macro or rule.
6145             $comment .= $spacing . $_;
6146             $spacing = '';
6147             &am_line_error ($., "comment following trailing backslash")
6148                 if $saw_bk;
6149         }
6150         elsif ($saw_bk)
6151         {
6152             if ($was_rule)
6153             {
6154                 $output_trailer .= join ('', @conditional_stack) . $_;
6155                 $saw_bk = /\\$/;
6156             }
6157             else
6158             {
6159                 $saw_bk = /\\$/;
6160                 $contents{$last_var_name} .= ' '
6161                     unless $contents{$last_var_name} =~ /\s$/;
6162                 $contents{$last_var_name} .= $_;
6163                 if (@conditional_stack)
6164                 {
6165                     $conditional{$last_var_name} .= &quote_cond_val ($_);
6166                 }
6167             }
6168         }
6169         elsif (/$IF_PATTERN/o)
6170         {
6171             &am_line_error ($., "$1 does not appear in AM_CONDITIONAL")
6172                 if (! $configure_cond{$1});
6173             push (@conditional_stack, "\@" . $1 . "_TRUE\@");
6174         }
6175         elsif (/$ELSE_PATTERN/o)
6176         {
6177             if (! @conditional_stack)
6178             {
6179                 &am_line_error ($., "else without if");
6180             }
6181             elsif ($conditional_stack[$#conditional_stack] =~ /_FALSE\@$/)
6182             {
6183                 &am_line_error ($., "else after else");
6184             }
6185             else
6186             {
6187                 $conditional_stack[$#conditional_stack]
6188                     =~ s/_TRUE\@$/_FALSE\@/;
6189             }
6190         }
6191         elsif (/$ENDIF_PATTERN/o)
6192         {
6193             if (! @conditional_stack)
6194             {
6195                 &am_line_error ($., "endif without if");
6196             }
6197             else
6198             {
6199                 pop @conditional_stack;
6200             }
6201         }
6202         elsif (/$RULE_PATTERN/o)
6203         {
6204             # Found a rule.
6205             $was_rule = 1;
6206             if (defined $contents{$1}
6207                 && (@conditional_stack
6208                     ? ! defined $conditional{$1}
6209                     : defined $conditional{$1}))
6210             {
6211                 &am_line_error ($1,
6212                                 "$1 defined both conditionally and unconditionally");
6213             }
6214             # Value here doesn't matter; for targets we only note
6215             # existence.
6216             $contents{$1} = 1;
6217             $targets{$1} = 1;
6218             local ($cond_string) = join ('', @conditional_stack);
6219             if (@conditional_stack)
6220             {
6221                 if ($conditional{$1})
6222                 {
6223                     &check_ambiguous_conditional ($1, $cond_string);
6224                     $conditional{$1} .= ' ';
6225                 }
6226                 else
6227                 {
6228                     $conditional{$1} = '';
6229                 }
6230                 $conditional{$1} .= $cond_string . ' 1';
6231             }
6232             $content_lines{$1} = $.;
6233             $output_trailer .= $comment . $spacing . $cond_string . $_;
6234             $comment = $spacing = '';
6235             $saw_bk = /\\$/;
6237             # Check the rule for being a suffix rule. If so, store in
6238             # a hash.
6240             local ($source_suffix);
6241             local ($object_suffix);
6243             if (($source_suffix, $object_suffix) = ($1 =~ $SUFFIX_RULE_PATTERN)) 
6244             {
6245               $suffix_rules{$source_suffix} = $object_suffix;
6246               print "Sources ending in .$source_suffix become .$object_suffix\n" if $verbose;
6247               $source_suffix_pattern = "(" . join ('|', keys %suffix_rules) . ")";
6248             }
6250             # FIXME: make sure both suffixes are in SUFFIXES? Or set
6251             # SUFFIXES from suffix_rules?
6252         }
6253         elsif (($is_ok_macro = /$MACRO_PATTERN/o)
6254                || /$BOGUS_MACRO_PATTERN/o)
6255         {
6256             # Found a macro definition.
6257             $was_rule = 0;
6258             $last_var_name = $1;
6259             if (defined $contents{$1}
6260                 && (@conditional_stack
6261                     ? ! defined $conditional{$1}
6262                     : defined $conditional{$1}))
6263             {
6264                 &am_line_error ($1,
6265                                 "$1 defined both conditionally and unconditionally");
6266             }
6267             local ($value);
6268             if ($3 ne '' && substr ($3, -1) eq "\\")
6269             {
6270                 # We preserve the `\' because otherwise the long lines
6271                 # that are generated will be truncated by broken
6272                 # `sed's.
6273                 $value = $3 . "\n";
6274             }
6275             else
6276             {
6277                 $value = $3;
6278             }
6279             local ($type) = $2;
6281             if (! defined $contents{$last_var_name})
6282             {
6283                 # The first assignment to a macro sets the line
6284                 # number.  Ideally I suppose we would associate line
6285                 # numbers with random bits of text.
6286                 $content_lines{$last_var_name} = $.;
6288                 # If first assignment, set `+=' indicator.
6289                 $var_was_plus_eq{$last_var_name} =
6290                     ($type eq '+'
6291                      && ! defined $am_var_defs{$last_var_name});
6292             }
6294             if ($type eq '+')
6295             {
6296                 if (! defined $contents{$last_var_name}
6297                     && defined $am_var_defs{$last_var_name})
6298                 {
6299                     $contents{$last_var_name} = $am_var_defs{$last_var_name};
6300                 }
6301                 if (substr ($contents{$last_var_name}, -1) eq "\n")
6302                 {
6303                     # Insert a backslash before a trailing newline.
6304                     $contents{$last_var_name}
6305                         = substr ($contents{$last_var_name}, 0, -1) . "\\\n";
6306                 }
6307                 $contents{$last_var_name} .= ' ' . $value;
6308             }
6309             else
6310             {
6311                 $contents{$last_var_name} = $value;
6312             }
6313             local ($cond_string) = join ('', @conditional_stack);
6314             if (@conditional_stack)
6315             {
6316                 local ($found) = 0;
6317                 local ($val);
6318                 if ($conditional{$last_var_name})
6319                 {
6320                     if ($type eq '+')
6321                     {
6322                         # If we're adding to the conditional, and it
6323                         # exists, then we might want to simply replace
6324                         # the old value with the new one.
6325                         local (@new_vals, @cond_vals);
6326                         @cond_vals = split (' ', $conditional{$last_var_name});
6327                         while (@cond_vals)
6328                         {
6329                             local ($vcond) = shift (@cond_vals);
6330                             push (@new_vals, $vcond);
6331                             if (&conditional_same ($vcond, $cond_string))
6332                             {
6333                                 $found = 1;
6334                                 $val = (&unquote_cond_val (shift (@cond_vals))
6335                                         . ' ' . $value);
6336                                 push (@new_vals, &quote_cond_val ($val));
6337                             }
6338                             else
6339                             {
6340                                 push (@new_vals, shift (@cond_vals));
6341                             }
6342                         }
6343                         if ($found)
6344                         {
6345                             $conditional{$last_var_name}
6346                                 = join (' ', @new_vals);
6347                         }
6348                     }
6350                     if (! $found)
6351                     {
6352                         &check_ambiguous_conditional ($last_var_name,
6353                                                       $cond_string);
6354                         $conditional{$last_var_name} .= ' ';
6355                         $val = $value;
6356                     }
6357                 }
6358                 else
6359                 {
6360                     $conditional{$last_var_name} = '';
6361                     $val = $contents{$last_var_name};
6362                 }
6363                 if (! $found)
6364                 {
6365                     $conditional{$last_var_name} .= ($cond_string
6366                                                      . ' '
6367                                                      . &quote_cond_val ($val));
6368                 }
6369             }
6371             # FIXME: this doesn't always work correctly; it will group
6372             # all comments for a given variable, no matter where
6373             # defined.
6374             $am_vars{$last_var_name} = $comment . $spacing;
6375             $def_type{$last_var_name} = ($type eq ':') ? ':' : '';
6376             push (@var_list, $last_var_name);
6377             $comment = $spacing = '';
6378             $saw_bk = /\\$/;
6380             # Error if bogus.
6381             &am_line_error ($., "bad macro name \`$last_var_name'")
6382                 if ! $is_ok_macro;
6383         }
6384         elsif (/$INCLUDE_PATTERN/o)
6385         {
6386             local ($path) = $1;
6388             if ($path =~ s/^\$\(top_srcdir\)\///)
6389             {
6390                 push (@include_stack, "\$\(top_srcdir\)/$path");
6391             }
6392             else
6393             {
6394                 $path =~ s/\$\(srcdir\)\///;
6395                 push (@include_stack, "\$\(srcdir\)/$path");
6396                 $path = $relative_dir . "/" . $path;
6397             }
6398             &read_am_file ($path);
6399         }
6400         else
6401         {
6402             # This isn't an error; it is probably a continued rule.
6403             # In fact, this is what we assume.
6404             $was_rule = 1;
6405             $output_trailer .= ($comment . $spacing
6406                                 . join ('', @conditional_stack) . $_);
6407             $comment = $spacing = '';
6408             $saw_bk = /\\$/;
6409         }
6411         $_ = <AM_FILE>;
6412     }
6414     $output_trailer .= $comment;
6416     if (join (' ', @saved_cond_stack) ne join (' ', @conditional_stack))
6417     {
6418         if (@conditional_stack)
6419         {
6420             &am_error ("unterminated conditionals: " . join (' ', @conditional_stack));
6421         }
6422         else
6423         {
6424             # FIXME: better error message here.
6425             &am_error ("conditionals not nested in include file");
6426         }
6427     }
6430 # A helper for read_main_am_file which initializes configure variables
6431 # and variables from header-vars.am.  This is a subr so we can call it
6432 # twice.
6433 sub define_standard_variables
6435     # Compute relative location of the top object directory.
6436     local (@topdir) = ();
6437     foreach (split (/\//, $relative_dir))
6438     {
6439         next if $_ eq '.' || $_ eq '';
6440         if ($_ eq '..')
6441         {
6442             pop @topdir;
6443         }
6444         else
6445         {
6446             push (@topdir, '..');
6447         }
6448     }
6449     @topdir = ('.') if ! @topdir;
6451     $top_builddir = join ('/', @topdir);
6452     local ($build_rx);
6453     ($build_rx = $top_builddir) =~ s/(\W)/\\$1/g;
6454     $output_vars .= &file_contents_with_transform
6455                         ('s/\@top_builddir\@/' . $build_rx . '/g;',
6456                          'header-vars');
6458     # Generate some useful variables when AC_CANONICAL_* used.  FIXME:
6459     # this should use generic %configure_vars method.
6460     if ($seen_canonical)
6461     {
6462         local ($curs, %vars);
6463         $vars{'host_alias'} = 'host_alias';
6464         $vars{'host_triplet'} = 'host';
6465         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
6466         {
6467             $vars{'build_alias'} = 'build_alias';
6468             $vars{'build_triplet'} = 'build';
6469             $vars{'target_alias'} = 'target_alias';
6470             $vars{'target_triplet'} = 'target';
6471         }
6472         foreach $curs (sort keys %vars)
6473         {
6474             $output_vars .= "$curs = \@$vars{$curs}\@\n";
6475             $contents{$curs} = "\@$vars{$curs}\@";
6476         }
6477     }
6479     local ($curs);
6480     foreach $curs (sort keys %configure_vars)
6481     {
6482         &define_configure_variable ($curs);
6483     }
6486 # Read main am file.
6487 sub read_main_am_file
6489     local ($amfile) = @_;
6491     # The keys here are variables we want to dump at the end of this
6492     # function.  The values are corresponding comments.
6493     local (%am_vars) = ();
6494     local (@var_list) = ();
6495     local (%def_type) = ();
6497     # This supports the strange variable tricks we are about to play.
6498     if (scalar keys %contents > 0)
6499     {
6500         print STDERR "automake: programming error: variable defined before read_main_am_file\n";
6501         exit 1;
6502     }
6504     # We want to predefine as many variables as possible.  This lets
6505     # the user set them with `+=' in Makefile.am.  However, we don't
6506     # want these initial definitions to end up in the output quite
6507     # yet.  So we adopt a hack: read the `.am' file twice, throwing
6508     # away the output the first time.  We also squirrel away a list of
6509     # all the variables defined by the .am file so that we know which
6510     # ones to remove from the content list.
6512     # First pass.
6513     &define_standard_variables;
6514     local (%saved_contents) = %contents;
6516     # Read user file, but discard text of variable assignments we just
6517     # made.
6518     $output_vars = '';
6519     &read_am_file ($amfile);
6521     # Now dump the variables that were defined.  We do it in the same
6522     # order in which they were defined (skipping duplicates).
6523     local (%done);
6524     foreach $curs (@var_list)
6525     {
6526         next if $done{$curs};
6527         $done{$curs} = 1;
6529         $output_vars .= $am_vars{$curs};
6530         if ($conditional{$curs})
6531         {
6532             local (@cond_vals) = split (' ', $conditional{$curs});
6533             while (@cond_vals)
6534             {
6535                 local ($vcond) = shift (@cond_vals);
6536                 local ($val) = &unquote_cond_val (shift (@cond_vals));
6537                 $output_vars .= ($vcond . $curs . ' '
6538                                  . $def_type{$curs} . "= ");
6539                 local ($line);
6540                 foreach $line (split ("\n", $val))
6541                 {
6542                     $output_vars .= $vcond . $line . "\n";
6543                 }
6544                 $output_vars .= "\n"
6545                     if $val eq '';
6546             }
6547         }
6548         else
6549         {
6550             $output_vars .= ($curs . ' ' . $def_type{$curs} . '= '
6551                              . $contents{$curs} . "\n");
6552         }
6553     }
6555     # Generate copyright header for generated Makefile.in.
6556     local ($ov) = $output_vars;
6557     $output_vars = ("# $in_file_name generated automatically by automake "
6558                    . $VERSION . " from $am_file_name\n");
6559     $output_vars .= $gen_copyright;
6561     # Now go through and delete all the variables that the user did
6562     # not change.
6563     local ($var);
6564     foreach $var (keys %saved_contents)
6565     {
6566         if ($contents{$var} eq $saved_contents{$var})
6567         {
6568             delete $contents{$var};
6569         }
6570     }
6572     # Re-read the standard variables, and this time keep their
6573     # contributions to the output.  Then add the user's output to the
6574     # end.
6575     &define_standard_variables;
6576     $output_vars .= $ov;
6580 ################################################################
6582 sub initialize_global_constants
6584     # Values for AC_CANONICAL_*
6585     $AC_CANONICAL_HOST = 1;
6586     $AC_CANONICAL_SYSTEM = 2;
6588     # Associative array of standard directory names.  Entry is TRUE if
6589     # corresponding directory should be installed during
6590     # 'install-exec' phase.
6591     %exec_dir_p =
6592         ('bin', 1,
6593          'sbin', 1,
6594          'libexec', 1,
6595          'data', 0,
6596          'sysconf', 1,
6597          'localstate', 1,
6598          'lib', 1,
6599          'info', 0,
6600          'man', 0,
6601          'include', 0,
6602          'oldinclude', 0,
6603          'pkgdata', 0,
6604          'pkglib', 1,
6605          'pkginclude', 0
6606          );
6608     # Commonly found files we look for and automatically include in
6609     # DISTFILES.
6610     @common_files =
6611         (
6612          "README", "THANKS", "TODO", "NEWS", "COPYING", "COPYING.LIB",
6613          "INSTALL", "ABOUT-NLS", "ChangeLog", "configure", "configure.in",
6614          "config.guess", "config.sub", "AUTHORS", "BACKLOG", "ABOUT-GNU",
6615          "libversion.in", "mdate-sh", "mkinstalldirs", "install-sh",
6616          'texinfo.tex', "ansi2knr.c", "ansi2knr.1", 'elisp-comp',
6617          'ylwrap', 'acinclude.m4', @libtoolize_files,
6618          'missing', 'depcomp', 'compile', 'py-compile'
6619          );
6621     # Commonly used files we auto-include, but only sometimes.
6622     @common_sometimes =
6623         (
6624          "aclocal.m4", "acconfig.h", "config.h.top",
6625          "config.h.bot", "stamp-h.in", 'stamp-vti'
6626          );
6628     $USAGE = "\
6629   -a, --add-missing     add missing standard files to package
6630   --amdir=DIR           directory storing config files
6631   -c, --copy            with -a, copy missing files (default is symlink)
6632   --cygnus              assume program is part of Cygnus-style tree
6633   --foreign             set strictness to foreign
6634   --gnits               set strictness to gnits
6635   --gnu                 set strictness to gnu
6636   --help                print this help, then exit
6637   -i, --ignore-deps     disable dependency tracking code
6638   --include-deps        enable dependency tracking code
6639   --no-force            only update Makefile.in's that are out of date
6640   -o DIR, --output-dir=DIR
6641                         put generated Makefile.in's into DIR
6642   -v, --verbose         verbosely list files processed
6643   --version             print version number, then exit\n";
6645     # Copyright on generated Makefile.ins.
6646     $gen_copyright = "\
6647 # Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
6648 # This Makefile.in is free software; the Free Software Foundation
6649 # gives unlimited permission to copy and/or distribute it,
6650 # with or without modifications, as long as this notice is preserved.
6652 # This program is distributed in the hope that it will be useful,
6653 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
6654 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
6655 # PARTICULAR PURPOSE.
6658     # This complex find command will try to avoid changing the modes of
6659     # links into the source tree, in case they're hard-linked.  It will
6660     # also make directories writable by everybody, because some
6661     # brain-dead tar implementations change ownership and permissions of
6662     # a directory before extracting the files, thus becoming unable to
6663     # extract them.
6664     # Ignore return result from chmod, because it might give an error
6665     # if we chmod a symlink.
6666     # Another nastiness: if the file is unreadable by us, we make it
6667     # readable regardless of the number of links to it.  This only
6668     # happens in perverse cases.
6669     # We use $(install_sh) because that is a known-portable way to
6670     # modify the file in place in the source tree.
6671     $dist_header = '    -find $(distdir) -type d ! -perm -777 -exec chmod a+rwx {} \; -o \\
6672           ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \\
6673           ! -type d ! -perm -400 -exec chmod a+r {} \; -o \\
6674           ! -type d ! -perm -444 -exec $(SHELL) $(install_sh) -c -m a+r {} {} \; \\
6675         || chmod -R a+r $(distdir)
6677     $dist{'dist-bzip2'} = ("\t"
6678                            . '$(AMTAR) chof - $(distdir) | bzip2 -9 -c > $(distdir).bz2'
6679                            . "\n");
6680     $dist{'dist-tarZ'} = ("\t"
6681                      . '$(AMTAR) chof - $(distdir) | compress -c > $(distdir).tar.Z'
6682                      . "\n");
6683     $dist{'dist-shar'} = ("\t"
6684                      . 'shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c > $(distdir).shar.gz'
6685                      . "\n");
6686     $dist{'dist-zip'} = ("\t" . '-rm -f $(distdir).zip' . "\n" .
6687                          "\t" . 'zip -rq $(distdir).zip $(distdir)' . "\n");
6688     $dist{'dist'} = ("\t"
6689                      .  '$(AMTAR) chof - $(distdir) | GZIP=$(GZIP_ENV) gzip -c > $(distdir).tar.gz'
6690                      . "\n");
6691     $dist_trailer = "\t" . '-chmod -R a+w $(distdir) > /dev/null 2>&1; rm -rf $(distdir)' . "\n";
6694 # (Re)-Initialize per-Makefile.am variables.
6695 sub initialize_per_input
6697     # These two variables are used when generating each Makefile.in.
6698     # They hold the Makefile.in until it is ready to be printed.
6699     $output_rules = '';
6700     $output_vars = '';
6701     $output_trailer = '';
6702     $output_all = '';
6703     $output_header = '';
6705     # Suffixes found during a run.
6706     @suffixes = ();
6708     # This holds the contents of a Makefile.am, as parsed by
6709     # read_am_file.
6710     %contents = ();
6712     # This holds the names which are targets.  These also appear in
6713     # %contents.
6714     %targets = ();
6716     # This maps a variable name onto a flag.  The flag is true iff the
6717     # variable was first defined with `+='.
6718     %var_was_plus_eq = ();
6720     # This holds definitions of all variables defined in .am files.
6721     # This is used during startup to determine which variables can be
6722     # assigned with `+='.
6723     %am_var_defs = ();
6725     # For a variable or target which is defined conditionally, this
6726     # holds an array of the conditional values.  The array is composed
6727     # of pairs of condition strings (the variables which configure
6728     # will substitute) and values (the value of a target is
6729     # meaningless).  For an unconditional variable, this is empty.
6730     %conditional = ();
6732     # This holds the line numbers at which various elements of
6733     # %contents are defined.
6734     %content_lines = ();
6736     # This holds a 1 if a particular variable was examined.
6737     %content_seen = ();
6739     # This is the conditional stack.
6740     @conditional_stack = ();
6742     # This holds the set of included files.
6743     @include_stack = ();
6745     # This holds the "relative directory" of the current Makefile.in.
6746     # Eg for src/Makefile.in, this is "src".
6747     $relative_dir = '';
6749     # This holds a list of files that are included in the
6750     # distribution.
6751     %dist_common = ();
6753     # List of dependencies for the obvious targets.
6754     @install_data = ();
6755     @install_exec = ();
6756     @uninstall = ();
6757     @installdirs = ();
6759     @info = ();
6760     @dvi = ();
6761     @all = ();
6762     @check = ();
6763     @check_tests = ();
6764     @installcheck = ();
6765     @clean = ();
6767     @phony = ();
6769     # A list of files deleted by `maintainer-clean'.
6770     @maintainer_clean_files = ();
6772     # These are pretty obvious, too.  They are used to define the
6773     # SOURCES and OBJECTS variables.
6774     @sources = ();
6775     @objects = ();
6776     # Sources which go in the distribution.
6777     @dist_sources = ();
6779     # This hash maps object file names onto their corresponding source
6780     # file names.  This is used to ensure that each object is created
6781     # by a single source file.
6782     %object_map = ();
6784     # This keeps track of the directories for which we've already
6785     # created `.dirstamp' code.
6786     %directory_map = ();
6788     # These variables track inclusion of various compile-related .am
6789     # files.  $included_generic_compile is TRUE if the basic code has
6790     # been included.  $included_knr_compile is TRUE if the ansi2knr
6791     # code has been included.  $included_libtool_compile is TRUE if
6792     # libtool support has been included.
6793     $included_generic_compile = 0;
6794     $included_knr_compile = 0;
6795     $included_libtool_compile = 0;
6797     # TRUE if install targets should work recursively.
6798     $recursive_install = 0;
6800     # All .P files.
6801     %dep_files = ();
6803     # Strictness levels.
6804     $strictness = $default_strictness;
6805     $strictness_name = $default_strictness_name;
6807     # Options from AUTOMAKE_OPTIONS.
6808     %options = ();
6810     # Whether or not dependencies are handled.  Can be further changed
6811     # in handle_options.
6812     $use_dependencies = $cmdline_use_dependencies;
6814     # Per Makefile.am.
6815     $local_maint_charset = $maint_charset;
6817     # All yacc and lex source filenames for this directory.  Use
6818     # filenames instead of raw count so that multiple instances are
6819     # counted correctly (eg one yacc file can appear in multiple
6820     # programs without harm).
6821     %yacc_sources = ();
6822     %lex_sources = ();
6824     # This is a list of all targets to run during "make dist".
6825     @dist_targets = ();
6827     # Keys in this hash are the basenames of files which must depend
6828     # on ansi2knr.
6829     %de_ansi_files = ();
6831     # This maps the source extension of a suffix rule to its
6832     # corresponding output extension.
6833     %suffix_rules = ();
6835     # This is a regular expression which matches all the known source
6836     # suffix.  A source suffix is one that appears in the first
6837     # position of a suffix rule.
6838     $source_suffix_pattern = '';
6840     # This is the name of the recursive `all' target to use.
6841     $all_target = 'all-recursive';
6843     # This keeps track of which extensions we've seen (that we care
6844     # about).
6845     %extension_seen = ();
6847     # This is random scratch space for the language finish functions.
6848     # Don't randomly overwrite it; examine other uses of keys first.
6849     %language_scratch = ();
6851     # We keep track of which objects need special (per-executable)
6852     # handling on a per-language basis.
6853     %lang_specific_files = ();
6857 ################################################################
6859 # Return contents of a file from $am_dir, automatically skipping
6860 # macros or rules which are already known.  Runs command on each line
6861 # as it is read; this command can modify $_.
6862 sub file_contents_with_transform
6864     local ($command, $basename) = @_;
6865     local ($file) = $am_dir . '/' . $basename . '.am';
6867     if ($command ne '' && substr ($command, -1) ne ';')
6868     {
6869         die "automake: programming error in file_contents_with_transform: $command\n";
6870     }
6872     open (FC_FILE, $file)
6873         || die "automake: installation error: cannot open \`$file'\n";
6874     # Looks stupid?
6875     # print "automake: reading $file\n" if $verbose;
6877     local ($was_rule) = 0;
6878     local ($result_vars) = '';
6879     local ($result_rules) = '';
6880     local ($comment) = '';
6881     local ($spacing) = "\n";
6882     local ($skipping) = 0;
6883     local ($had_chars);
6885     while (<FC_FILE>)
6886     {
6887         $_ =~ s/\@MAINTAINER_MODE_TRUE\@//g
6888             unless $seen_maint_mode;
6890         $had_chars = length ($_) && $_ ne "\n";
6891         eval $command;
6892         # If the transform caused all the characters to go away, then
6893         # ignore the line.  Why do this?  Because in Perl 4, a "next"
6894         # inside of an eval doesn't affect a loop outside the eval.
6895         # So we can't pass in a "transform" that uses next.  We used
6896         # to do this.  "Empty" also means consisting of a single
6897         # newline.
6898         next if $had_chars && ($_ eq '' || $_ eq "\n");
6900         if (/$IGNORE_PATTERN/o)
6901         {
6902             # Merely delete comments beginning with two hashes.
6903         }
6904         elsif (/$WHITE_PATTERN/o)
6905         {
6906             # Stick a single white line before the incoming macro or rule.
6907             $spacing = "\n";
6908             &am_line_error ($., "blank line following trailing backslash")
6909                 if $saw_bk;
6910         }
6911         elsif (/$COMMENT_PATTERN/o)
6912         {
6913             # Stick comments before the incoming macro or rule.
6914             $comment .= $spacing . $_;
6915             $spacing = '';
6916             &am_line_error ($., "comment following trailing backslash")
6917                 if $saw_bk;
6918         }
6919         elsif ($saw_bk)
6920         {
6921             if ($was_rule)
6922             {
6923                 $result_rules .= $_ if ! $skipping;
6924             }
6925             else
6926             {
6927                 $result_vars .= $_ if ! $skipping;
6928             }
6929             $saw_bk = /\\$/;
6930         }
6931         elsif (/$RULE_PATTERN/o)
6932         {
6933             # Found a rule.
6934             $was_rule = 1;
6935             $skipping = defined $contents{$1};
6936             $result_rules .= $comment . $spacing . $_ if ! $skipping;
6937             $comment = $spacing = '';
6938             $saw_bk = /\\$/;
6939         }
6940         elsif (/$MACRO_PATTERN/o)
6941         {
6942             # Found a variable reference.
6943             $was_rule = 0;
6944             $skipping = defined $contents{$1};
6945             $result_vars .= $comment . $spacing . $_ if ! $skipping;
6946             $comment = $spacing = '';
6947             $saw_bk = /\\$/;
6948             print STDERR "automake: programming error: .am macro \`$1' with trailing backslash\n"
6949                 if $saw_bk;
6950             $am_var_defs{$1} = $3;
6951         }
6952         else
6953         {
6954             # This isn't an error; it is probably a continued rule.
6955             # In fact, this is what we assume.
6956             $was_rule = 1;
6957             $result_rules .= $comment . $spacing . $_ if ! $skipping;
6958             $comment = $spacing = '';
6959             $saw_bk = /\\$/;
6960         }
6961     }
6963     close (FC_FILE);
6964     return $result_vars . $result_rules . $comment;
6967 # Like file_contents_with_transform, but no transform.
6968 sub file_contents
6970     return &file_contents_with_transform ('', @_);
6973 # Find all variable prefixes that are used for install directories.  A
6974 # prefix `zar' qualifies iff:
6975 # * `zardir' is a variable.
6976 # * `zar_PRIMARY' is a variable.
6977 sub am_primary_prefixes
6979     local ($primary, $can_dist, @prefixes) = @_;
6981     local (%valid, $varname);
6982     grep ($valid{$_} = 0, @prefixes);
6983     $valid{'EXTRA'} = 0;
6984     foreach $varname (keys %contents)
6985     {
6986         if ($varname =~ /^(dist_|nodist_)?(.*)_$primary$/)
6987         {
6988             if (($1 ne '' && ! $can_dist)
6989                 || (! defined $valid{$2}
6990                     && ! &variable_defined ($2 . 'dir')
6991                     # Note that a configure variable is always
6992                     # legitimate.  It is natural to name such
6993                     # variables after the primary, so we explicitly
6994                     # allow it.
6995                     && ! defined $configure_vars{$varname}))
6996             {
6997                 &am_line_error ($varname, "invalid variable \`$varname'");
6998             }
6999             else
7000             {
7001                 # Ensure all extended prefixes are actually used.
7002                 $valid{$1 . $2} = 1;
7003             }
7004         }
7005     }
7007     return %valid;
7010 # Handle `where_HOW' variable magic.  Does all lookups, generates
7011 # install code, and possibly generates code to define the primary
7012 # variable.  The first argument is the name of the .am file to munge,
7013 # the second argument is the primary variable (eg HEADERS), and all
7014 # subsequent arguments are possible installation locations.  Returns
7015 # list of all values of all _HOW targets.
7017 # FIXME: this should be rewritten to be cleaner.  It should be broken
7018 # up into multiple functions.
7020 # Usage is: am_install_var (OPTION..., file, HOW, where...)
7021 sub am_install_var
7023     local (@args) = @_;
7025     local ($do_clean) = 0;
7026     local ($do_require) = 1;
7027     local ($can_dist) = 0;
7028     local ($default_dist) = 0;
7030     local ($ltxform);
7031     if (defined $configure_vars{'LIBTOOL'})
7032     {
7033         # Transform '@LIBTOOL ...@' to '$(LIBTOOL) ...'
7034         $ltxform = 's/\@LIBTOOL([^\@]*)\@/\$(LIBTOOL) $1/;';
7035     }
7036     else
7037     {
7038         # Delete '@LIBTOOL ...@'
7039         $ltxform = 's/\@LIBTOOL([^\@]*)\@//;';
7040     }
7042     local ($cygxform);
7043     if (! $seen_exeext)
7044     {
7045         $cygxform = 's/\@EXEEXT\@//g;';
7046     }
7047     else
7048     {
7049         $cygxform = 's/\@EXEEXT\@/\$(EXEEXT)/g;';
7050     }
7052     while (@args)
7053     {
7054         if ($args[0] eq '-clean')
7055         {
7056             $do_clean = 1;
7057         }
7058         elsif ($args[0] eq '-noextra')
7059         {
7060             $do_require = 0;
7061         }
7062         elsif ($args[0] eq '-candist')
7063         {
7064             $can_dist = 1;
7065         }
7066         elsif ($args[0] eq '-defaultdist')
7067         {
7068             $default_dist = 1;
7069             $can_dist = 1;
7070         }
7071         elsif ($args[0] !~ /^-/)
7072         {
7073             last;
7074         }
7075         shift (@args);
7076     }
7078     local ($file, $primary, @prefixes) = @args;
7080     local (@used) = ();
7081     local (@result) = ();
7083     # Now that configure substitutions are allowed in where_HOW
7084     # variables, it is an error to actually define the primary.  We
7085     # allow `JAVA', as it is customarily used to mean the Java
7086     # interpreter.  This is but one of several Java hacks.  Similarly,
7087     # `PYTHON' is customarily used to mean the Python interpreter.
7088     &am_line_error ($primary, "\`$primary' is an anachronism")
7089         if &variable_defined ($primary)
7090             && ($primary ne 'JAVA' && $primary ne 'PYTHON');
7093     # Look for misspellings.  It is an error to have a variable ending
7094     # in a "reserved" suffix whose prefix is unknown, eg
7095     # "bni_PROGRAMS".  However, unusual prefixes are allowed if a
7096     # variable of the same name (with "dir" appended) exists.  For
7097     # instance, if the variable "zardir" is defined, then
7098     # "zar_PROGRAMS" becomes valid.  This is to provide a little extra
7099     # flexibility in those cases which need it.
7100     local (%valid) = &am_primary_prefixes ($primary, $can_dist, @prefixes);
7102     # If a primary includes a configure substitution, then the EXTRA_
7103     # form is required.  Otherwise we can't properly do our job.
7104     local ($require_extra);
7105     local ($warned_about_extra) = 0;
7107     local ($clean_file) = $file . '-clean';
7108     local ($one_name);
7109     local ($X);
7110     local ($nodir_name);
7111     foreach $X (sort keys %valid)
7112     {
7113         $one_name = $X . '_' . $primary;
7114         if (&variable_defined ($one_name))
7115         {
7116             # If files should be distributed, do so.
7117             if ($can_dist)
7118             {
7119                 if (($default_dist && $one_name !~ /^nodist_/)
7120                     || (! $default_dist && $one_name =~ /^dist_/))
7121                 {
7122                     &push_dist_common ('$(' . $one_name . ')');
7123                 }
7124                 ($nodir_name = $X) =~ s/^(dist|nodist)_//;
7125             }
7126             else
7127             {
7128                 $nodir_name = $X;
7129             }
7131             # Append actual contents of where_PRIMARY variable to
7132             # result.
7133             local ($rcurs);
7134             foreach $rcurs (&variable_value_as_list ($one_name, 'all'))
7135             {
7136                 # Skip configure substitutions.  Possibly bogus.
7137                 if ($rcurs =~ /^\@.*\@$/)
7138                 {
7139                     if ($X eq 'EXTRA')
7140                     {
7141                         if (! $warned_about_extra)
7142                         {
7143                             $warned_about_extra = 1;
7144                             {
7145                                 &am_line_error ($one_name,
7146                                                 "\`$one_name' contains configure substitution, but shouldn't");
7147                             }
7148                         }
7149                     }
7150                     # Check here to make sure variables defined in
7151                     # configure.in do not imply that EXTRA_PRIMARY
7152                     # must be defined.
7153                     elsif (! defined $configure_vars{$one_name})
7154                     {
7155                         $require_extra = $one_name
7156                             if $do_require;
7157                     }
7159                     next;
7160                 }
7162                 push (@result, $rcurs);
7163             }
7165             # "EXTRA" shouldn't be used when generating clean targets,
7166             # all, or install targets.
7167             if ($X eq 'EXTRA')
7168             {
7169                 # We used to warn if EXTRA_FOO was defined uselessly,
7170                 # but this was annoying.
7171                 next;
7172             }
7174             # A blatant hack: we rewrite each _PROGRAMS primary to
7175             # include EXEEXT when in Cygwin32 mode.
7176             if ($seen_exeext && $primary eq 'PROGRAMS')
7177             {
7178                 local (@conds) = &variable_conditions ($one_name);
7179                 local (@one_binlist);
7181                 # FIXME: this definitely loses aesthetically; it
7182                 # redefines $ONE_NAME.  Instead we should arrange for
7183                 # variable definitions to be output later, instead of
7184                 # at scan time.
7186                 if (! @conds)
7187                 {
7188                     @one_binlist = ();
7189                     foreach $rcurs (&variable_value_as_list ($one_name, ''))
7190                     {
7191                         if ($rcurs =~ /\./ || $rcurs =~ /^\@.*\@$/)
7192                         {
7193                             push (@one_binlist, $rcurs);
7194                         }
7195                         else
7196                         {
7197                             push (@one_binlist, $rcurs . '$(EXEEXT)');
7198                         }
7199                     }
7201                     delete $contents{$one_name};
7202                     &define_pretty_variable ($one_name, '', @one_binlist);
7203                 }
7204                 else
7205                 {
7206                     local ($cond);
7207                     local ($condvals) = '';
7208                     foreach $cond (@conds)
7209                     {
7210                         @one_binlist = ();
7211                         local (@condval) = &variable_value_as_list ($one_name,
7212                                                                     $cond);
7213                         foreach $rcurs (@condval)
7214                         {
7215                             if ($rcurs =~ /\./ || $rcurs =~ /^\@.*\@$/)
7216                             {
7217                                 push (@one_binlist, $rcurs);
7218                             }
7219                             else
7220                             {
7221                                 push (@one_binlist, $rcurs . '$(EXEEXT)');
7222                             }
7223                         }
7225                         push (@condvals, $cond);
7226                         push (@condvals, join (' ', @one_binlist));
7227                     }
7229                     delete $contents{$one_name};
7231                     while (@condvals)
7232                     {
7233                         $cond = shift (@condvals);
7234                         local (@val) = split (' ', shift (@condvals));
7235                         &define_pretty_variable ($one_name, $cond, @val);
7236                     }
7237                 }
7238             }
7240             if ($do_clean)
7241             {
7242                 $output_rules .=
7243                     &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go;'
7244                                                    . $cygxform,
7245                                                    $clean_file);
7247                 push (@clean, $X . $primary);
7248                 &push_phony_cleaners ($X . $primary);
7249             }
7251             if ($X eq 'check')
7252             {
7253                 push (@check, '$(' . $one_name . ')');
7254             }
7255             else
7256             {
7257                 push (@used, '$(' . $one_name . ')');
7258             }
7259             if ($X eq 'noinst' || $X eq 'check')
7260             {
7261                 # Objects which don't get installed by default.
7262                 next;
7263             }
7265             $output_rules .=
7266                 &file_contents_with_transform ('s/\@DIR\@/' . $X . '/g;'
7267                                                . 's/\@NDIR\@/' . $nodir_name . '/go;'
7268                                                . $ltxform . $cygxform,
7269                                                $file);
7271             push (@uninstall, 'uninstall-' . $X . $primary);
7272             push (@phony, 'uninstall-' . $X . $primary);
7273             push (@installdirs, '$(DESTDIR)$(' . $X . 'dir)');
7274             if (defined $exec_dir_p{$X} ? $exec_dir_p{$X} : ($X =~ /exec/))
7275             {
7276                 push (@install_exec, 'install-' . $X . $primary);
7277                 push (@phony, 'install-' . $X . $primary);
7278             }
7279             else
7280             {
7281                 push (@install_data, 'install-' . $X . $primary);
7282                 push (@phony, 'install-' . $X . $primary);
7283             }
7284         }
7285     }
7287     # The JAVA variable is used as the name of the Java interpreter.
7288     # The PYTHON variable is used as the name of the Python interpreter.
7289     if (@used && $primary ne 'JAVA' && $primary ne 'PYTHON')
7290     {
7291         # Define it.
7292         &define_pretty_variable ($primary, '', @used);
7293         $output_vars .= "\n";
7294     }
7296     if ($require_extra && ! &variable_defined ('EXTRA_' . $primary))
7297     {
7298         &am_line_error ($require_extra,
7299                         "\`$require_extra' contains configure substitution, but \`EXTRA_$primary' not defined");
7300     }
7302     # Push here because PRIMARY might be configure time determined.
7303     push (@all, '$(' . $primary . ')')
7304         if @used && $primary ne 'JAVA' && $primary ne 'PYTHON';
7306     # Make the result unique.  This lets the user use conditionals in
7307     # a natural way, but still lets us program lazily -- we don't have
7308     # to worry about handling a particular object more than once.
7309     local (%uniquify) = ();
7310     grep ($uniquify{$_} = 1, @result);
7311     return sort keys %uniquify;
7315 ################################################################
7317 # This variable is local to the "require file" set of functions.
7318 @require_file_paths = ();
7320 # Verify that the file must exist in the current directory.  Usage:
7321 # require_file (isconfigure, line_number, strictness, file) strictness
7322 # is the strictness level at which this file becomes required.  Must
7323 # set require_file_paths before calling this function.
7324 # require_file_paths is set to hold a single directory (the one in
7325 # which the first file was found) before return.
7326 sub require_file_internal
7328     local ($is_configure, $line, $mystrict, @files) = @_;
7329     local ($file, $fullfile);
7330     local ($found_it, $errfile, $errdir);
7331     local ($save_dir);
7333     foreach $file (@files)
7334     {
7335         $found_it = 0;
7336         foreach $dir (@require_file_paths)
7337         {
7338             if ($dir eq '.')
7339             {
7340                 $fullfile = $relative_dir . "/" . $file;
7341                 $errdir = $relative_dir unless $errdir;
7342             }
7343             else
7344             {
7345                 $fullfile = $dir . "/" . $file;
7346                 $errdir = $dir unless $errdir;
7347             }
7349             # Use different name for "error filename".  Otherwise on
7350             # an error the bad file will be reported as eg
7351             # `../../install-sh' when using the default
7352             # config_aux_path.
7353             $errfile = $errdir . '/' . $file;
7355             if (-f $fullfile)
7356             {
7357                 $found_it = 1;
7358                 # FIXME: Once again, special-case `.'.
7359                 &push_dist_common ($file)
7360                     if $dir eq $relative_dir || $dir eq '.';
7361                 $save_dir = $dir;
7362                 last;
7363             }
7364         }
7366         if ($found_it)
7367         {
7368             # Prune the path list.
7369             @require_file_paths = $save_dir;
7370         }
7371         else
7372         {
7373             if ($strictness >= $mystrict)
7374             {
7375                 local ($trailer) = '';
7376                 local ($suppress) = 0;
7378                 # Only install missing files according to our desired
7379                 # strictness level.
7380                 local ($message) = "required file \`$errfile' not found";
7381                 if ($add_missing)
7382                 {
7383                     $suppress = 1;
7385                     # Maybe run libtoolize.
7386                     if ($seen_libtool
7387                         && grep ($_ eq $file, @libtoolize_files)
7388                         && system ('libtoolize', '--automake'))
7389                     {
7390                         $message = "installing \`$errfile'";
7391                         $suppress = 0;
7392                         $trailer = "; cannot run \`libtoolize': $!";
7393                     }
7394                     elsif (-f ($am_dir . '/' . $file))
7395                     {
7396                         # Install the missing file.  Symlink if we
7397                         # can, copy if we must.  Note: delete the file
7398                         # first, in case it is a dangling symlink.
7399                         $message = "installing \`$errfile'";
7400                         # Windows Perl will hang if we try to delete a
7401                         # file that doesn't exist.
7402                         unlink ($errfile) if -f $errfile;
7403                         if ($symlink_exists && ! $copy_missing)
7404                         {
7405                             if (! symlink ($am_dir . '/' . $file, $errfile))
7406                             {
7407                                 $suppress = 0;
7408                                 $trailer = "; error while making link: $!\n";
7409                             }
7410                         }
7411                         elsif (system ('cp', $am_dir . '/' . $file, $errfile))
7412                         {
7413                             $suppress = 0;
7414                             $trailer = "\n    error while copying\n";
7415                         }
7416                     }
7417                 }
7419                 local ($save) = $exit_status;
7420                 if ($is_configure)
7421                 {
7422                     # FIXME: allow actual file to be specified.
7423                     &am_conf_line_error ('configure.in', $line,
7424                                          "$message$trailer");
7425                 }
7426                 else
7427                 {
7428                     &am_line_error ($line, "$message$trailer");
7429                 }
7430                 $exit_status = $save if $suppress;
7431             }
7432         }
7433     }
7436 # Like require_file_with_line, but error messages refer to
7437 # configure.in, not the current Makefile.am.
7438 sub require_file_with_conf_line
7440     @require_file_paths = '.';
7441     &require_file_internal (1, @_);
7444 sub require_file_with_line
7446     @require_file_paths = '.';
7447     &require_file_internal (0, @_);
7450 sub require_file
7452     @require_file_paths = '.';
7453     &require_file_internal (0, '', @_);
7456 # Require a file that is also required by Autoconf.  Looks in
7457 # configuration path, as specified by AC_CONFIG_AUX_DIR.
7458 sub require_config_file
7460     @require_file_paths = @config_aux_path;
7461     &require_file_internal (1, '', @_);
7462     local ($dir) = $require_file_paths[0];
7463     @config_aux_path = @require_file_paths;
7464     if ($dir eq '.')
7465     {
7466         $config_aux_dir = '.';
7467     }
7468     else
7469     {
7470         $config_aux_dir = '$(top_srcdir)/' . $dir;
7471     }
7474 # Assumes that the line number is in Makefile.am.
7475 sub require_conf_file_with_line
7477     @require_file_paths = @config_aux_path;
7478     &require_file_internal (0, @_);
7479     local ($dir) = $require_file_paths[0];
7480     @config_aux_path = @require_file_paths;
7481     if ($dir eq '.')
7482     {
7483         $config_aux_dir = '.';
7484     }
7485     else
7486     {
7487         $config_aux_dir = '$(top_srcdir)/' . $dir;
7488     }
7491 # Assumes that the line number is in configure.in.
7492 sub require_conf_file_with_conf_line
7494     @require_file_paths = @config_aux_path;
7495     &require_file_internal (1, @_);
7496     local ($dir) = $require_file_paths[0];
7497     @config_aux_path = @require_file_paths;
7498     if ($dir eq '.')
7499     {
7500         $config_aux_dir = '.';
7501     }
7502     else
7503     {
7504         $config_aux_dir = '$(top_srcdir)/' . $dir;
7505     }
7508 ################################################################
7510 # Push a list of files onto dist_common.
7511 sub push_dist_common
7513     local (@files) = @_;
7514     local ($file);
7516     foreach $file (@files)
7517     {
7518         $dist_common{$file} = 1;
7519     }
7522 # Push a list of clean targets onto phony.
7523 sub push_phony_cleaners
7525     local ($base) = @_;
7526     local ($target);
7527     foreach $target ('mostly', 'dist', '', 'maintainer-')
7528     {
7529         push (@phony, $target . 'clean-' . $base);
7530     }
7533 # Set strictness.
7534 sub set_strictness
7536     $strictness_name = $_[0];
7537     if ($strictness_name eq 'gnu')
7538     {
7539         $strictness = $GNU;
7540     }
7541     elsif ($strictness_name eq 'gnits')
7542     {
7543         $strictness = $GNITS;
7544     }
7545     elsif ($strictness_name eq 'foreign')
7546     {
7547         $strictness = $FOREIGN;
7548     }
7549     else
7550     {
7551         die "automake: level \`$strictness_name' not recognized\n";
7552     }
7556 ################################################################
7558 # Return directory name of file.
7559 sub dirname
7561     local ($file) = @_;
7562     local ($sub);
7564     ($sub = $file) =~ s,/+[^/]+$,,g;
7565     $sub = '.' if $sub eq $file;
7566     return $sub;
7569 # Return file name of a file.
7570 sub basename
7572     local ($file) = @_;
7573     local ($sub);
7575     ($sub = $file) =~s,^.*/+,,g;
7576     return $sub;
7579 # Ensure a file exists.
7580 sub create
7582     local ($file) = @_;
7584     open (TOUCH, ">> $file");
7585     close (TOUCH);
7588 # Glob something.  Do this to avoid indentation screwups everywhere we
7589 # want to glob.  Gross!
7590 sub my_glob
7592     local ($pat) = @_;
7593     return <${pat}>;
7596 ################################################################
7598 # Print an error message and set exit status.
7599 sub am_error
7601     warn "automake: ${am_file}.am: ", join (' ', @_), "\n";
7602     $exit_status = 1;
7605 sub am_line_error
7607     local ($symbol, @args) = @_;
7609     if ($symbol && "$symbol" ne '-1')
7610     {
7611         local ($file) = "${am_file}.am";
7613         if ($symbol =~ /^\d+$/)
7614         {
7615             # SYMBOL is a line number, so just add the colon.
7616             $file .= ':' . $symbol;
7617         }
7618         elsif (defined $content_lines{$symbol})
7619         {
7620             # SYMBOL is a variable defined in Makefile.am, so add the
7621             # line number we saved from there.
7622             $file .= ':' . $content_lines{$symbol};
7623         }
7624         elsif (defined $configure_vars{$symbol})
7625         {
7626             # SYMBOL is a variable defined in configure.in, so add the
7627             # appropriate line number.
7628             $file = $configure_vars{$symbol};
7629         }
7630         else
7631         {
7632             # Couldn't find the line number.
7633         }
7634         warn $file, ": ", join (' ', @args), "\n";
7635         $exit_status = 1;
7636     }
7637     else
7638     {
7639         &am_error (@args);
7640     }
7643 # Like am_error, but while scanning configure.in.
7644 sub am_conf_error
7646     # FIXME: can run in subdirs.
7647     warn "automake: configure.in: ", join (' ', @_), "\n";
7648     $exit_status = 1;
7651 # Error message with line number referring to configure.in.
7652 sub am_conf_line_error
7654     local ($file, $line, @args) = @_;
7656     if ($line)
7657     {
7658         warn "$file: $line: ", join (' ', @args), "\n";
7659         $exit_status = 1;
7660     }
7661     else
7662     {
7663         &am_conf_error (@args);
7664     }
7667 # Warning message with line number referring to configure.in.
7668 # Does not affect exit_status
7669 sub am_conf_line_warning
7671     local ($saved_exit_status) = $exit_status;
7672     &am_conf_line_error (@_);
7673     $exit_status = $saved_exit_status;
7676 # Tell user where our aclocal.m4 is, but only once.
7677 sub keyed_aclocal_warning
7679     local ($key) = @_;
7680     warn "automake: macro \`$key' can be generated by \`aclocal'\n";
7683 # Print usage information.
7684 sub usage
7686     print "Usage: automake [OPTION] ... [Makefile]...\n\n";
7687     print "Generate Makefile.in for autoconf from Makefile.am\n";
7688     print $USAGE;
7689     print "\nFiles which are automatically distributed, if found:\n";
7690     $~ = "USAGE_FORMAT";
7691     local ($last, $iter, @lcomm);
7692     $last = '';
7693     foreach $iter (sort ((@common_files, @common_sometimes)))
7694     {
7695         push (@lcomm, $iter) unless $iter eq $last;
7696         $last = $iter;
7697     }
7699     local ($one, $two, $three, $four, $i, $max);
7700     $max = int (($#lcomm + 1) / 4);
7702     for ($i = 0; $i < $max; ++$i)
7703     {
7704         $one = $lcomm[$i];
7705         $two = $lcomm[$max + $i];
7706         $three = $lcomm[2 * $max + $i];
7707         $four = $lcomm[3 * $max + $i];
7708         write;
7709     }
7711     local ($mod) = ($#lcomm + 1) % 4;
7712     if ($mod != 0)
7713     {
7714         $one = $lcomm[$max];
7715         $two = ($mod > 1) ? $lcomm[2 * $max] : '';
7716         $three = ($mod > 2) ? $lcomm[3 * $max] : '';
7717         $four = ($mod > 3) ? $lcomm[4 * $max] : '';
7718         write;
7719     }
7721     print "\nReport bugs to <bug-automake\@gnu.org>.\n";
7723     exit 0;
7726 format USAGE_FORMAT =
7727   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
7728   $one,               $two,               $three,             $four