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