[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
conditional AC_CONFIG_FILES: AM_COND_IF.
From: |
Ralf Wildenhues |
Subject: |
conditional AC_CONFIG_FILES: AM_COND_IF. |
Date: |
Sun, 16 Mar 2008 22:26:54 +0100 |
User-agent: |
Mutt/1.5.17+20080114 (2008-01-14) |
Proposed patch for conditional AC_CONFIG_FILES. This enables to fix one
half of <http://gcc.gnu.org/ml/gcc-patches/2008-03/msg00941.html>
(the other half is the FIXME in the test below.)
Comments, reviews appreciated.
autoconf/lib/autom4te.cfg should preselect _AM_COND_{IF,ELSE,ENDIF} if
this goes in.
Thanks,
Ralf
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.
* m4/cond.m4 (AM_CONDITION): Define `_AM_COND_VALUE_][NAME'
with NAME being the name of the condition, to its shell
condition.
(_AM_COND_IF, _AM_COND_ELSE, _AM_COND_ENDIF): New trace helpers.
(AM_COND_IF): New macro, implements conditionals.
* doc/automake.texi (Requirements, Optional, Conditionals):
Document AM_COND_IF.
* NEWS: Update.
* tests/cond39.test, tests/cond40.test, tests/cond41.test: New
tests.
* tests/Makefile.am: Adjust.
diff --git a/NEWS b/NEWS
index 39ae49a..72081f1 100644
--- a/NEWS
+++ b/NEWS
@@ -60,6 +60,9 @@ New in 1.10a:
- 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:
diff --git a/automake.in b/automake.in
index 3d679fb..be9d65e 100755
--- a/automake.in
+++ b/automake.in
@@ -326,6 +326,8 @@ my @other_input_files = ();
# 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
@@ -4196,10 +4198,13 @@ sub handle_configure ($$$@)
# 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)/')
@@ -4844,6 +4849,9 @@ sub scan_autoconf_config_files ($$)
push (@other_input_files, $_);
}
$ac_config_files_location{$local} = $where;
+ $ac_config_files_condition{$local} =
+ new Automake::Condition (@cond_stack)
+ if (@cond_stack);
}
}
@@ -4881,6 +4889,9 @@ sub scan_autoconf_traces ($)
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,
@@ -4899,11 +4910,14 @@ sub scan_autoconf_traces ($)
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;
+ $where = new Automake::Location $here;
my $macro = $args[0];
prog_error ("unrequested trace `$macro'")
@@ -5067,6 +5081,18 @@ sub scan_autoconf_traces ($)
{
$seen_cc_c_o = $where;
}
+ elsif ($macro eq '_AM_COND_IF')
+ {
+ cond_stack_if ('', $args[1], $where);
+ }
+ elsif ($macro eq '_AM_COND_ELSE')
+ {
+ cond_stack_else ('!', $args[1], $where);
+ }
+ elsif ($macro eq '_AM_COND_ENDIF')
+ {
+ cond_stack_endif (undef, undef, $where);
+ }
elsif ($macro eq '_AM_SUBST_NOTMAKE')
{
$ignored_configure_vars{$args[1]} = $where;
@@ -5112,6 +5138,9 @@ sub scan_autoconf_traces ($)
}
}
+ error ($where, "condition stack not properly closed")
+ if (@cond_stack);
+
$tracefh->close;
}
diff --git a/doc/automake.texi b/doc/automake.texi
index a56eca4..add6b5b 100644
--- a/doc/automake.texi
+++ b/doc/automake.texi
@@ -2654,6 +2654,10 @@ to check whether @file{Makefile.am} exists. (In the
very hairy case
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
address@hidden with the help of @code{AM_COND_IF}
+(@pxref{Optional}).
+
To summarize:
@itemize @bullet
@item
@@ -2831,6 +2835,15 @@ you can use these variables in any @file{Makefile.am} if
This is required when using the obsolete de-ANSI-fication feature; see
@ref{ANSI}.
address@hidden AM_CONDITIONAL
+This introduces an Automake conditional (@pxref{Conditionals}).
+
address@hidden AM_COND_IF
+This macro allows to access a conditional introduced with
address@hidden later in @file{configure.ac} in a way that
address@hidden can detect, thus enabling conditional
address@hidden (@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
@@ -8933,6 +8946,31 @@ The @code{else} branch of the above two examples could
be omitted,
since assigning the empty string to an otherwise undefined variable
makes no difference.
address@hidden AM_COND_IF
+In order to allow access to the condition registered by
address@hidden inside @file{configure.ac} and to allow
+conditional @code{AC_CONFIG_FILES}, @code{AM_COND_IF} may be used:
+
address@hidden AM_COND_IF (@var{conditional}, @var{if-true}, @var{if-false})
+If @var{conditional} is fulfilled, execute @var{if-true}, otherwise
+execute @var{if-false}. If the contain @code{AC_CONFIG_FILES}, it
+will cause @command{automake} to output the rules for the respective
+files only for the given condition.
address@hidden defmac
+
address@hidden macros may be nested.
+
address@hidden Example conditional @code{AC_CONFIG_FILES}
address@hidden @code{AC_CONFIG_FILES}, conditional
+
+Here is an example of how to define a conditional config file:
+
address@hidden
+AM_CONDITIONAL([SHELL_WRAPPER], [test "x$with_wrapper" = xtrue])
+AM_COND_IF([SHELL_WRAPPER],
+ [AC_CONFIG_FILES([wrapper:wrapper.in])])
address@hidden example
+
@unnumberedsec Portability
Note that conditionals in Automake are not the same as conditionals in
diff --git a/m4/cond.m4 b/m4/cond.m4
index d9a58d2..3aacfbe 100644
--- a/m4/cond.m4
+++ b/m4/cond.m4
@@ -1,13 +1,13 @@
# 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)
# -------------------------------------
@@ -20,6 +20,7 @@ AC_SUBST([$1_TRUE])dnl
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='#'
@@ -32,3 +33,34 @@ AC_CONFIG_COMMANDS_PRE(
AC_MSG_ERROR([[conditional "$1" was never defined.
Usually this means the macro was only invoked conditionally.]])
fi])])
+
+
+# _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 matchind 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
+])
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1221672..9420f3d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -157,6 +157,9 @@ cond35.test \
cond36.test \
cond37.test \
cond38.test \
+cond39.test \
+cond40.test \
+cond41.test \
condd.test \
condhook.test \
condinc.test \
diff --git a/tests/Makefile.in b/tests/Makefile.in
index 15951f2..217956a 100644
--- a/tests/Makefile.in
+++ b/tests/Makefile.in
@@ -307,6 +307,9 @@ cond35.test \
cond36.test \
cond37.test \
cond38.test \
+cond39.test \
+cond40.test \
+cond41.test \
condd.test \
condhook.test \
condinc.test \
diff --git a/tests/cond39.test b/tests/cond39.test
new file mode 100755
index 0000000..93f0363
--- /dev/null
+++ b/tests/cond39.test
@@ -0,0 +1,78 @@
+#!/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
diff --git a/tests/cond40.test b/tests/cond40.test
new file mode 100755
index 0000000..d567a68
--- /dev/null
+++ b/tests/cond40.test
@@ -0,0 +1,78 @@
+#!/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
+:
diff --git a/tests/cond41.test b/tests/cond41.test
new file mode 100755
index 0000000..281e484
--- /dev/null
+++ b/tests/cond41.test
@@ -0,0 +1,33 @@
+#!/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
+:
- conditional AC_CONFIG_FILES: AM_COND_IF.,
Ralf Wildenhues <=