Hi Jim,

* Jim Meyering wrote on Thu, Aug 13, 2009 at 08:29:21AM CEST:
[...]
> systems with automake older than 1.11.
> On those systems, it's fine to ignore or disable these
> two unsupported options.

Yes.  Often, automake's rejection of unsupported options is stricter
than it would need to be.  Unfortunately, I don't know of a general way
to solve that, as just ignoring (and warning about) them is definitely
not strict enough: some options cause incompatible behavior that may be
desired.

> I proposed a configure.ac-modifying "solution",
> 
>     https://www.redhat.com/archives/libguestfs/2009-August/msg00160.html
> 
> but it's too ugly.
> 
> Can you think of another way?

I think Automake should provide an API to allow users to say "if the
Automake version is >= X, then expand this configure.ac code".  I think
that would be general enough (it could use Automake conditionals to
adjust Makefile.am files, it could check for >= X and not >= X+1 to
enforce exact versions (or we could just provide a general version
compare function) and it could then call AM_INIT_AUTOMAKE with the
appropriate options).  Also, it would be explicit enough for the
developer to be conscious about not using this by accident.

However, it would likely allow fool any tools that directly grepped the
configure.ac files for AM_INIT_AUTOMAKE invocations, instead of using
  autom4te --language=Autoconf-without-aclocal-m4 --trace=AM_INIT_AUTOMAKE

and even that would probably not give the right answer then (as
aclocal.m4 contents will be needed in order to provide it).

The initial patch below ought to improve the situation for future
Automake versions (but unfortunately not for past ones).  With it,
you will be able to write code like

  AM_VERSION_PREREQ([1.12],
                    [# this code assumes Automake 1.12
                     AM_INIT_AUTOMAKE([foreign fancy-new-option])],
                    [# this code does not assume 1.12
                     AM_INIT_AUTOMAKE([foreign])])

Does that look like a viable approach to people?

Of course, just like m4_version_prereq, it violates the Autoconf
principle that you should test the actual feature you would like to use,
rather than some version number.  I don't know how to solve that without
another layer of indirection, which would amount to something you
outline in the URL above.  (The other rationale why it may not be so bad
here is that luckily, distros seem to provide pretty much plain upstream
Automake these days, without many patches tacked on and features added,
so that a version number actually retains some meaning.)


What you can do in the meantime to have things work well for you with
git Automake (once that provides AM_VERSION_PREREQ) is something like
  m4_ifdef([AM_VERSION_PREREQ],
           [ use AM_VERSION_PREREQ like above ... ],
           [ backward compat code ... ])

and you could even extend the idea to work back to 1.11 by testing for
some macro that was new in 1.11, such as AM_SILENT_RULES or AM_COND_IF.
However, there is a glitch: in case these macros are defined, i.e., the
version is >= 1.11, you have to also actually use them in your
configure.ac, so that not only aclocal (who searches in the
.../share/aclocal-X.Y directory by default) finds them as defined, but
also actually includes their definition into the aclocal.m4 file, so
that a subsequent autoconf (who doesn't search .../share/aclocal-X.Y)
finds them defined, too.  Clear?

As an unrelated side note, we don't use @defmac to define our macros,
which can cause bugs when used with @dvar on a @-continued definition
line, in the manual.  This should be fixed.

Cheers,
Ralf

    New macro AM_VERSION_PREREQ.
    
    * m4/amversion.in (_AM_AUTOMAKE_VERSION): New define.
    * m4/prereq.m4 (AM_VERSION_PREREQ): New file, new macro,
    with code taken from Autoconf's m4_version_prereq.
    * tests/prereq.test: New test.
    * tests/Makefile.am: Adjust.
    * doc/automake.texi (@dvar): New texinfo macro, taken from
    Autoconf.
    (Public Macros): Document AM_VERSION_PREREQ.
    * NEWS: Update.
    Based on suggestion from Jim Meyering.

diff --git a/NEWS b/NEWS
index 7e14ed8..fe11327 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,10 @@
 New in 1.11a:
 
+* Miscellaneous changes:
+
+  - New macro AM_VERSION_PREREQ to allow expanding different code at M4 run
+    time based upon the Automake version used.
+
 Bugs fixed in 1.11a:
 
 * Bugs introduced by 1.11:
diff --git a/doc/automake.texi b/doc/automake.texi
index b3f4a76..9a489ef 100644
--- a/doc/automake.texi
+++ b/doc/automake.texi
@@ -15,6 +15,14 @@
 @r...@var{\varname\}@r{]}
 @end macro
 
+...@c @dvar(ARG, DEFAULT)
+...@c -------------------
+...@c The ARG is an optional argument, defaulting to DEFAULT.  To be used
+...@c for macro arguments in their documentation (@defmac).
+...@macro dvar{varname, default}
+...@r{[}@var{\varname\} = @samp{\defaul...@r{]}@c
+...@end macro
+
 @copying
 
 This manual is for @acronym{GNU} Automake (version @value{VERSION},
@@ -3896,6 +3904,15 @@ compiler is found.
 @acindex AM_SILENT_RULES
 Enable the machinery for less verbose build output (@pxref{Options}).
 
+...@item AM_VERSION_PREREQ(@var{version}, @ovar{if-new-enough}, @dvar{if-old, 
m4_fatal})
+...@acindex AM_VERSION_PREREQ
+If the Automake version used is at least @var{version}, then expand
+...@var{if-new-enough}, otherwise expand @var{if-old}, which defaults to
+printing an error message and exiting m4sugar with status 63.
+
+For example, this macro may be used to invoke @code{AM_INIT_AUTOMAKE}
+differently based upon the Automake version used.
+
 @item AM_WITH_DMALLOC
 @acindex AM_WITH_DMALLOC
 @cindex @command{dmalloc}, support for
diff --git a/m4/amversion.in b/m4/amversion.in
index 0ca73cf..30f96ef 100644
--- a/m4/amversion.in
+++ b/m4/amversion.in
@@ -1,11 +1,16 @@
 ##                                                          -*- Autoconf -*-
 ## @configure_input@
-# Copyright (C) 2002, 2003, 2005, 2006, 2007, 2008  Free Software Foundation, 
Inc.
+# Copyright (C) 2002, 2003, 2005, 2006, 2007, 2008, 2009  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.
 
+# _AM_AUTOMAKE_VERSION
+# --------------------
+m4_define([_AM_AUTOMAKE_VERSION], [...@version@])dnl
+
 # AM_AUTOMAKE_VERSION(VERSION)
 # ----------------------------
 # Automake X.Y traces this macro to ensure aclocal.m4 has been
diff --git a/m4/prereq.m4 b/m4/prereq.m4
new file mode 100644
index 0000000..c0b497d
--- /dev/null
+++ b/m4/prereq.m4
@@ -0,0 +1,25 @@
+# Expand code based on Automake version used.            -*- Autoconf -*-
+
+# Copyright (C) 2009 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_VERSION_PREREQ(VERSION, [IF-OK], [IF-NOT = FAIL])
+# ----------------------------------------------------
+# If the Automake version used is at least VERSION, expand
+# IF-OK, otherwise expand IF-NOT, defaulting to failure.
+# This macro may be used before AM_INIT_AUTOMAKE, and AM_INIT_AUTOMAKE
+# may be called in the second or third arguments.
+AC_DEFUN([AM_VERSION_PREREQ],
+m4_ifdef([_AM_AUTOMAKE_VERSION],
+[[m4_if(m4_version_compare(]m4_dquote(m4_defn([_AM_AUTOMAKE_VERSION]))[, [$1]),
+        [-1],
+        [m4_default([$3],
+                    [m4_fatal([Automake version $1 or higher is required],
+                              [63])])],
+        [$2])]],
+[[m4_fatal([amversion.m4 not found])]]))
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ae250b6..917ad48 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -544,6 +544,7 @@ pr401.test \
 pr401b.test \
 pr401c.test \
 prefix.test \
+prereq.test \
 primary.test \
 primary2.test \
 primary3.test \
diff --git a/tests/prereq.test b/tests/prereq.test
new file mode 100755
index 0000000..50d71ec
--- /dev/null
+++ b/tests/prereq.test
@@ -0,0 +1,83 @@
+#! /bin/sh
+# Copyright (C) 2009  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
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Test AM_VERSION_PREREQ.
+
+. ./defs || Exit 1
+
+set -e
+
+cat > Makefile.am << 'END'
+TESTS =
+END
+
+cat > configure.in << END
+AC_INIT([$me], [1.0])
+AM_VERSION_PREREQ([9999.9])
+AM_INIT_AUTOMAKE([foreign])
+AC_CONFIG_FILES(Makefile)
+AC_OUTPUT
+END
+
+$ACLOCAL && Exit 1
+
+cat > configure.in << END
+AC_INIT([$me], [1.0])
+AM_VERSION_PREREQ([9999.9], [], [ ])
+AM_INIT_AUTOMAKE([foreign])
+AC_CONFIG_FILES(Makefile)
+AC_OUTPUT
+END
+
+$ACLOCAL --force
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+cat > configure.in << END
+AC_INIT([$me], [1.0])
+AM_VERSION_PREREQ([9999.9],
+  [echo version is new
+   AM_INIT_AUTOMAKE([foreign parallel-tests])],
+  [echo version is old
+   AM_INIT_AUTOMAKE([foreign])])
+AM_INIT_AUTOMAKE([foreign])
+AC_CONFIG_FILES(Makefile)
+AC_OUTPUT
+END
+
+$ACLOCAL --force
+$AUTOMAKE
+grep TEST_SUITE_LOG Makefile.in && Exit 1
+$AUTOCONF --force
+./configure | grep 'version is old'
+
+cat > configure.in << END
+AC_INIT([$me], [1.0])
+AM_VERSION_PREREQ([1.11],
+  [echo version is new
+   AM_INIT_AUTOMAKE([foreign parallel-tests])],
+  [echo version is old
+   AM_INIT_AUTOMAKE([foreign])])
+AM_INIT_AUTOMAKE([foreign])
+AC_CONFIG_FILES(Makefile)
+AC_OUTPUT
+END
+
+$ACLOCAL --force
+$AUTOMAKE
+grep TEST_SUITE_LOG Makefile.in
+$AUTOCONF --force
+./configure | grep 'version is new'


Reply via email to