source: vendor/automake/1.4-p6/automake.in@ 3124

Last change on this file since 3124 was 3124, checked in by bird, 18 years ago

automake 1.4-p6

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