* automake.in (%ac_config_files_condition): New.
(scan_autoconf_config_files): Record condition if any.
(scan_autoconf_traces): Trace _AM_COND_IF, _AM_COND_ELSE,
_AM_COND_ENDIF, updating @cond_stack as appropriate.
(handle_configure): Prefix config.status rule with condition.
Check that m4 quotation is done consistently.
* m4/cond.m4 (AM_CONDITION): Define `_AM_COND_VALUE_name'
with `name' being the name of the condition, to its shell
condition.
* m4/cond-if.m4: New file.
(_AM_COND_IF, _AM_COND_ELSE, _AM_COND_ENDIF): New trace helpers.
(AM_COND_IF): New macro, implements conditionals.
* m4/Makefile.am: Adjust.
* doc/automake.texi (Requirements, Optional, Conditionals):
Document AM_COND_IF.
* NEWS: Update.
* tests/cond39.test, tests/cond40.test, tests/cond41.test,
tests/cond42.test, tests/cond43.test: New tests.
* tests/Makefile.am: Adjust.
Signed-off-by: Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
+2008-03-26 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
+
+ Implement conditional AC_CONFIG_FILES: AM_COND_IF.
+ * automake.in (%ac_config_files_condition): New.
+ (scan_autoconf_config_files): Record condition if any.
+ (scan_autoconf_traces): Trace _AM_COND_IF, _AM_COND_ELSE,
+ _AM_COND_ENDIF, updating @cond_stack as appropriate.
+ (handle_configure): Prefix config.status rule with condition.
+ Check that m4 quotation is done consistently.
+ * m4/cond.m4 (AM_CONDITION): Define `_AM_COND_VALUE_name'
+ with `name' being the name of the condition, to its shell
+ condition.
+ * m4/cond-if.m4: New file.
+ (_AM_COND_IF, _AM_COND_ELSE, _AM_COND_ENDIF): New trace helpers.
+ (AM_COND_IF): New macro, implements conditionals.
+ * m4/Makefile.am: Adjust.
+ * doc/automake.texi (Requirements, Optional, Conditionals):
+ Document AM_COND_IF.
+ * NEWS: Update.
+ * tests/cond39.test, tests/cond40.test, tests/cond41.test,
+ tests/cond42.test, tests/cond43.test: New tests.
+ * tests/Makefile.am: Adjust.
+
2008-03-24 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
* doc/automake.texi (@ovar): New macro, from autoconf.texi.
- New prefix `notrans_' for manpages which should not be transformed
by --program-transform.
+ - New macro AM_COND_IF for conditional evaluation and conditional
+ config files.
+
Bugs fixed in 1.10a:
* Long standing bugs:
# Where each AC_CONFIG_FILES/AC_OUTPUT/AC_CONFIG_LINK/AC_CONFIG_HEADER appears.
# The keys are the files created by these macros.
my %ac_config_files_location = ();
+# The condition under which AC_CONFIG_FOOS appears.
+my %ac_config_files_condition = ();
# Directory to search for configure-required files. This
# will be computed by &locate_aux_dir and can be set using
# Cannot output rules for shell variables.
next if (substitute_ac_subst_variables $local) =~ /\$/;
- $output_rules .= ($local . ': '
+ my $condstr = '';
+ $condstr = $ac_config_files_condition{$lfile}->subst_string
+ if ($ac_config_files_condition{$lfile});
+ $output_rules .= ($condstr . $local . ': '
. '$(top_builddir)/config.status '
. "@rewritten_inputs\n"
- . "\t"
+ . $condstr . "\t"
. 'cd $(top_builddir) && '
. '$(SHELL) ./config.status '
. ($relative_dir eq '.' ? '' : '$(subdir)/')
push (@other_input_files, $_);
}
$ac_config_files_location{$local} = $where;
+ $ac_config_files_condition{$local} =
+ new Automake::Condition (@cond_stack)
+ if (@cond_stack);
}
}
AM_MAINTAINER_MODE => 0,
AM_PROG_CC_C_O => 0,
_AM_SUBST_NOTMAKE => 1,
+ _AM_COND_IF => 1,
+ _AM_COND_ELSE => 1,
+ _AM_COND_ENDIF => 1,
LT_SUPPORTED_TAG => 1,
_LT_AC_TAGCONFIG => 0,
m4_include => 1,
# Use a separator unlikely to be used, not `:', the default, which
# has a precise meaning for AC_CONFIG_FILES and so on.
$traces .= join (' ',
- map { "--trace=$_" . ':\$f:\$l::\$n::\${::}%' }
+ map { "--trace=$_" . ':\$f:\$l::\$d::\$n::\${::}%' }
(keys %traced));
my $tracefh = new Automake::XFile ("$traces $filename |");
verb "reading $traces";
+ @cond_stack = ();
+ my $where;
+
while ($_ = $tracefh->getline)
{
chomp;
- my ($here, @args) = split (/::/);
- my $where = new Automake::Location $here;
+ my ($here, $depth, @args) = split (/::/);
+ $where = new Automake::Location $here;
my $macro = $args[0];
prog_error ("unrequested trace `$macro'")
{
$seen_cc_c_o = $where;
}
+ elsif ($macro eq '_AM_COND_IF')
+ {
+ cond_stack_if ('', $args[1], $where);
+ error ($where, "missing m4 quoting, macro depth $depth")
+ if ($depth != 1);
+ }
+ elsif ($macro eq '_AM_COND_ELSE')
+ {
+ cond_stack_else ('!', $args[1], $where);
+ error ($where, "missing m4 quoting, macro depth $depth")
+ if ($depth != 1);
+ }
+ elsif ($macro eq '_AM_COND_ENDIF')
+ {
+ cond_stack_endif (undef, undef, $where);
+ error ($where, "missing m4 quoting, macro depth $depth")
+ if ($depth != 1);
+ }
elsif ($macro eq '_AM_SUBST_NOTMAKE')
{
$ignored_configure_vars{$args[1]} = $where;
}
}
+ error ($where, "condition stack not properly closed")
+ if (@cond_stack);
+
$tracefh->close;
}
that your setup requires such use of variables, you will have to tell
Automake which @file{Makefile.in}s to generate on the command-line.)
+It is possible to let @command{automake} emit conditional rules for
+@code{AC_CONFIG_FILES} with the help of @code{AM_COND_IF}
+(@pxref{Optional}).
+
To summarize:
@itemize @bullet
@item
This is required when using the obsolete de-ANSI-fication feature; see
@ref{ANSI}.
+@item AM_CONDITIONAL
+This introduces an Automake conditional (@pxref{Conditionals}).
+
+@item AM_COND_IF
+This macro allows @code{automake} to detect subsequent access within
+@file{configure.ac} to a conditional previously introduced with
+@code{AM_CONDITIONAL}, thus enabling conditional @code{AC_CONFIG_FILES}
+(@pxref{Conditionals}).
+
@item AM_GNU_GETTEXT
This macro is required for packages that use GNU gettext
(@pxref{gettext}). It is distributed with gettext. If Automake sees
since assigning the empty string to an otherwise undefined variable
makes no difference.
+@acindex AM_COND_IF
+In order to allow access to the condition registered by
+@code{AM_CONDITIONAL} inside @file{configure.ac}, and to allow
+conditional @code{AC_CONFIG_FILES}, @code{AM_COND_IF} may be used:
+
+@defmac AM_COND_IF (@var{conditional}, @ovar{if-true}, @ovar{if-false})
+If @var{conditional} is fulfilled, execute @var{if-true}, otherwise
+execute @var{if-false}. If either branch contains @code{AC_CONFIG_FILES},
+it will cause @command{automake} to output the rules for the respective
+files only for the given condition.
+@end defmac
+
+@code{AM_COND_IF} macros may be nested when m4 quotation is used
+properly (@pxref{M4 Quotation, ,, autoconf, The Autoconf Manual}).
+
+@cindex Example conditional @code{AC_CONFIG_FILES}
+@cindex @code{AC_CONFIG_FILES}, conditional
+
+Here is an example of how to define a conditional config file:
+
+@example
+AM_CONDITIONAL([SHELL_WRAPPER], [test "x$with_wrapper" = xtrue])
+AM_COND_IF([SHELL_WRAPPER],
+ [AC_CONFIG_FILES([wrapper:wrapper.in])])
+@end example
+
@unnumberedsec Portability
Note that conditionals in Automake are not the same as conditionals in
## Makefile for Automake m4.
-## Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2006
-## Free Software Foundation, Inc.
+## Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2006,
+## 2008 Free Software Foundation, Inc.
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
auxdir.m4 \
ccstdc.m4 \
cond.m4 \
+cond-if.m4 \
depend.m4 \
depout.m4 \
dmalloc.m4 \
auxdir.m4 \
ccstdc.m4 \
cond.m4 \
+cond-if.m4 \
depend.m4 \
depout.m4 \
dmalloc.m4 \
--- /dev/null
+# AM_COND_IF -*- Autoconf -*-
+
+# Copyright (C) 2008 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 1
+
+# _AM_COND_IF
+# _AM_COND_ELSE
+# _AM_COND_ENDIF
+# --------------
+# These macros are only used for tracing.
+m4_define([_AM_COND_IF])
+m4_define([_AM_COND_ELSE])
+m4_define([_AM_COND_ENDIF])
+
+
+# AM_COND_IF(COND, [IF-TRUE], [IF-FALSE])
+# ---------------------------------------
+# If the shell condition matching COND is true, execute IF-TRUE,
+# otherwise execute IF-FALSE. Allow automake to learn about conditional
+# instantiating macros (the AC_CONFIG_FOOS).
+AC_DEFUN([AM_COND_IF],
+[m4_ifndef([_AM_COND_VALUE_$1],
+ [m4_fatal([$0: no such condition "$1"])])dnl
+_AM_COND_IF([$1])dnl
+if _AM_COND_VALUE_$1; then
+ m4_default([$2], [:])
+m4_ifval([$3],
+[_AM_COND_ELSE([$1])dnl
+else
+ $3
+])dnl
+_AM_COND_ENDIF([$1])dnl
+fi[]dnl
+])
# AM_CONDITIONAL -*- Autoconf -*-
-# Copyright (C) 1997, 2000, 2001, 2003, 2004, 2005, 2006
+# Copyright (C) 1997, 2000, 2001, 2003, 2004, 2005, 2006, 2008
# Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
-# serial 8
+# serial 9
# AM_CONDITIONAL(NAME, SHELL-CONDITION)
# -------------------------------------
AC_SUBST([$1_FALSE])dnl
_AM_SUBST_NOTMAKE([$1_TRUE])dnl
_AM_SUBST_NOTMAKE([$1_FALSE])dnl
+m4_define([_AM_COND_VALUE_$1], [$2])dnl
if $2; then
$1_TRUE=
$1_FALSE='#'
cond36.test \
cond37.test \
cond38.test \
+cond39.test \
+cond40.test \
+cond41.test \
+cond42.test \
+cond43.test \
condd.test \
condhook.test \
condinc.test \
cond36.test \
cond37.test \
cond38.test \
+cond39.test \
+cond40.test \
+cond41.test \
+cond42.test \
+cond43.test \
condd.test \
condhook.test \
condinc.test \
--- /dev/null
+#!/bin/sh
+# Copyright (C) 2008 Free Software Foundation, Inc.
+#
+# This file is part of GNU Automake.
+#
+# GNU Automake is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Automake is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Automake; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+# Build either as CONFIG_FILE or as PROGRAM.
+
+. ./defs
+set -e
+
+cat >>configure.in <<'END'
+AC_PROG_CC
+AM_CONDITIONAL([COND], [test "$COND" = true])
+AM_COND_IF([COND], [],
+ [AC_CONFIG_FILES([prog], [chmod 755 prog])])
+AC_OUTPUT
+END
+
+cat >Makefile.am <<'END'
+if COND
+bin_PROGRAMS = prog
+prog_SOURCES = prog.c
+else
+# FIXME: the next line is still needed to get automake to output the
+# bin_PROGRAMS above in the right condition only.
+prog:
+bin_SCRIPTS = prog
+CLEANFILES = prog
+endif
+END
+
+cat >prog.c <<'END'
+int main () { return 42; }
+END
+
+cat >prog.in <<'END'
+#! /bin/sh
+bindir='@bindir@'
+echo "hi, this is $0, and bindir is $bindir"
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+./configure COND=true
+$MAKE 2>stderr
+cat stderr
+grep 'overriding commands' stderr && exit 1
+./prog && exit 1
+$MAKE clean
+$MAKE
+./prog && exit 1
+$MAKE distclean
+
+./configure COND=false
+$MAKE 2>stderr
+cat stderr
+grep 'overriding commands' stderr && exit 1
+./prog
+$MAKE clean
+$MAKE
+./prog
--- /dev/null
+#!/bin/sh
+# Copyright (C) 2008 Free Software Foundation, Inc.
+#
+# This file is part of GNU Automake.
+#
+# GNU Automake is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Automake is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Automake; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+# Test AM_COND_IF.
+
+. ./defs
+set -e
+
+cat >>configure.in <<'END'
+AC_DEFUN([FOO],
+ [AC_CONFIG_FILES([$1])])
+
+AM_CONDITIONAL([COND], [test "$cond" = yes])
+AM_COND_IF([COND],
+ [AC_CONFIG_FILES([file1])])
+
+AM_CONDITIONAL([COND1], [test "$cond1" = yes])
+AM_CONDITIONAL([COND2], [test "$cond2" = yes])
+AM_CONDITIONAL([COND3], [test "$cond3" = yes])
+
+AM_COND_IF([COND1],
+ [AM_COND_IF([COND2], [FOO([file2])],
+ [AM_COND_IF([COND3],
+ [FOO([file3])])])])
+
+AC_OUTPUT
+END
+
+: >Makefile.am
+: >file1.in
+: >file2.in
+: >file3.in
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure cond=yes cond1=yes cond2=no cond3=yes
+test -f file1
+test ! -f file2
+test -f file3
+rm -f file1 file3
+$MAKE file1 file3
+$MAKE file2 && exit 1
+test -f file1
+test ! -f file2
+test -f file3
+$MAKE distclean
+
+./configure cond=no cond1=yes cond2=yes
+test ! -f file1
+test -f file2
+test ! -f file3
+rm -f file2
+$MAKE file1 && exit 1
+$MAKE file2
+$MAKE file3 && exit 1
+test ! -f file1
+test -f file2
+test ! -f file3
+:
--- /dev/null
+#!/bin/sh
+# Copyright (C) 2008 Free Software Foundation, Inc.
+#
+# This file is part of GNU Automake.
+#
+# GNU Automake is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Automake is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Automake; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+# AM_COND_IF with an undefined condition should fail.
+
+. ./defs
+set -e
+
+cat >>configure.in <<'END'
+AM_COND_IF([COND],
+ [AC_CONFIG_FILES([file1])])
+AC_OUTPUT
+END
+
+$ACLOCAL && exit 1
+:
--- /dev/null
+#!/bin/sh
+# Copyright (C) 2008 Free Software Foundation, Inc.
+#
+# This file is part of GNU Automake.
+#
+# GNU Automake is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Automake is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Automake; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+# Ensure an error with inconsistent state of conditionals in configure.ac.
+# This shouldn't happen with user input, as _AM_COND_* are not documented,
+# but better to be safe.
+
+. ./defs
+set -e
+
+cat >>configure.in <<'END'
+AM_CONDITIONAL([COND], [:])
+# next line needed so that cond-if.m4 is pulled in.
+AM_COND_IF([COND])
+_AM_COND_IF([COND])
+AC_OUTPUT
+END
+: >Makefile.am
+
+$ACLOCAL
+AUTOMAKE_fails
+grep 'condition stack' stderr
+
+sed 's/_AM_COND_IF/_AM_COND_ELSE/' < configure.in >configure.int
+mv -f configure.int configure.in
+rm -rf autom4te*.cache
+AUTOMAKE_fails
+grep 'else without if' stderr
+
+sed 's/_AM_COND_ELSE/_AM_COND_ENDIF/' < configure.in >configure.int
+mv -f configure.int configure.in
+rm -rf autom4te*.cache
+AUTOMAKE_fails
+grep 'endif without if' stderr
+
+sed 's/\(_AM_COND_ENDIF\).*/_AM_COND_IF\
+_AM_COND_ENDIF/' < configure.in >configure.int
+mv -f configure.int configure.in
+rm -rf autom4te*.cache
+AUTOMAKE_fails
+test 2 = `grep -c 'not enough arguments' stderr`
+:
--- /dev/null
+#!/bin/sh
+# Copyright (C) 2008 Free Software Foundation, Inc.
+#
+# This file is part of GNU Automake.
+#
+# GNU Automake is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Automake is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Automake; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+# Ensure an error with underquoted usage of AM_COND_IF in configure.ac.
+
+. ./defs
+set -e
+
+cat >>configure.in <<'END'
+AM_CONDITIONAL([COND1], [:])
+AM_CONDITIONAL([COND2], [:])
+AM_COND_IF([COND1],
+ AM_COND_IF([COND2], [:])
+)
+AC_OUTPUT
+END
+: >Makefile.am
+
+$ACLOCAL
+AUTOMAKE_fails
+
+sed '/.AM_COND_IF/{
+ s/^/[/
+ s/$/]/
+ }' < configure.in > configure.int
+mv -f configure.int configure.in
+rm -rf autom4te*.cache
+$AUTOMAKE