Hi! This is a second attempt to implement AM_PROG_AR. The previous attempt was bundled with the addition of the 'ar-lib' script but was left behind. I have now fleshed it out with tests and portability warnings etc.
I think I have everything in the thread covered: http://lists.gnu.org/archive/html/automake-patches/2010-08/msg00116.html This is going with case (1) in that message. However, I have only updated tests/ar.test to cope with the new reality. So, a lot of tests (100?) are likely to fall over due to the new portability warnings. The reason is that I don't know on what branch I should base such an intrusive patch. I fear that such a patch, when merged elsewhere, will be incomplete or otherwise difficult to merge due to other changes. I'm also not sure if this is the desired route. Please advise. This patch is on top of the msvc branch. AC_PROG_RANLIB is rendered obsolete by LT_INIT. Is it also rendered obsolete by AC_PROG_LIBTOOL? Should I not care about libtool 1.5? Cheers, Peter >From e4810ab05c41461c3b6c5638a41d8d415ebcc40f Mon Sep 17 00:00:00 2001 From: Peter Rosin <p...@lysator.liu.se> Date: Tue, 14 Sep 2010 14:58:17 +0200 Subject: [PATCH] Add new 'AM_PROG_AR' macro, triggering the 'ar-lib' script. * m4/ar-lib.m4: New macro AM_PROG_AR, which locates an archiver and triggers the auxiliary 'ar-lib' script if needed. * m4/Makefile.am: Add above. * automake.in (seen_ar): New variable. (scan_autoconf_traces): Set it. (handle_libraries): Don't set default values for AR and ARFLAGS if AM_PROG_AR has been seen. (handle_libraries, handle_ltlibraries): Require AM_PROG_AR for portability. * doc/automake.texi (Public Macros): Mention the new 'AM_PROG_AR' macro. (Subpackages): Add AM_PROG_AR to the example. (A Library): Adjust recommendations for AR given the new AM_PROG_AR macro. * tests/ar.test: Adjust to avoid portability warnings. * tests/ar-lib2.test: New test. Test if AM_PROG_AR triggers install of ar-lib. * tests/ar-lib3.test: New test. Test if lib_LIBRARIES requires AM_PROG_AR. * tests/ar-lib4.test: New test. Test if lib_LTLIBRARIES requires AM_PROG_AR. * tests/ar-lib5.test: New test. Test if AM_PROG_AR triggers use of ar-lib when the archiver is Microsoft lib. * tests/ar-lib6.test: New test. Test ordering of AM_PROG_AR and LT_INIT. * tests/defs.in: New required entry 'lib'. * tests/Makefile.am: Add new tests. * NEWS: Update. --- ChangeLog | 33 +++++++++++++++++++++++++++ NEWS | 3 ++ automake.in | 29 ++++++++++++++++++++++- doc/automake.texi | 18 ++++++++++---- m4/Makefile.am | 1 + m4/Makefile.in | 1 + m4/ar-lib.m4 | 55 +++++++++++++++++++++++++++++++++++++++++++++ tests/Makefile.am | 5 ++++ tests/Makefile.in | 5 ++++ tests/ar-lib2.test | 40 +++++++++++++++++++++++++++++++++ tests/ar-lib3.test | 51 ++++++++++++++++++++++++++++++++++++++++++ tests/ar-lib4.test | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/ar-lib5.test | 56 ++++++++++++++++++++++++++++++++++++++++++++++ tests/ar-lib6.test | 38 +++++++++++++++++++++++++++++++ tests/ar.test | 3 +- tests/defs.in | 10 ++++++++ 16 files changed, 403 insertions(+), 8 deletions(-) create mode 100644 m4/ar-lib.m4 create mode 100755 tests/ar-lib2.test create mode 100755 tests/ar-lib3.test create mode 100755 tests/ar-lib4.test create mode 100755 tests/ar-lib5.test create mode 100755 tests/ar-lib6.test diff --git a/ChangeLog b/ChangeLog index 02f2fcd..b911686 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,36 @@ +2010-09-14 Peter Rosin <p...@lysator.liu.se> + Ralf Wildenhues <ralf.wildenh...@gmx.de> + + Add new 'AM_PROG_AR' macro, triggering the 'ar-lib' script. + * m4/ar-lib.m4: New macro AM_PROG_AR, which locates an + archiver and triggers the auxiliary 'ar-lib' script if needed. + * m4/Makefile.am: Add above. + * automake.in (seen_ar): New variable. + (scan_autoconf_traces): Set it. + (handle_libraries): Don't set default values for AR and ARFLAGS + if AM_PROG_AR has been seen. + (handle_libraries, handle_ltlibraries): Require AM_PROG_AR for + portability. + * doc/automake.texi (Public Macros): Mention the new + 'AM_PROG_AR' macro. + (Subpackages): Add AM_PROG_AR to the example. + (A Library): Adjust recommendations for AR given the new + AM_PROG_AR macro. + * tests/ar.test: Adjust to avoid portability warnings. + * tests/ar-lib2.test: New test. Test if AM_PROG_AR triggers + install of ar-lib. + * tests/ar-lib3.test: New test. Test if lib_LIBRARIES requires + AM_PROG_AR. + * tests/ar-lib4.test: New test. Test if lib_LTLIBRARIES requires + AM_PROG_AR. + * tests/ar-lib5.test: New test. Test if AM_PROG_AR triggers + use of ar-lib when the archiver is Microsoft lib. + * tests/ar-lib6.test: New test. Test ordering of AM_PROG_AR and + LT_INIT. + * tests/defs.in: New required entry 'lib'. + * tests/Makefile.am: Add new tests. + * NEWS: Update. + 2010-09-02 Peter Rosin <p...@lysator.liu.se> Make ar-lib support backslashed files in archives. diff --git a/NEWS b/NEWS index 6971bd7..41a6cc8 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,9 @@ New in 1.11.0a: - The `compile' script now converts some options for MSVC for a better user experience. Similarly, the new `ar-lib' script wraps Microsoft lib. + - New macro AM_PROG_AR that looks for an archiver and wraps it in the new + 'ar-lib' auxiliary script if the found archiver is Microsoft lib. + Bugs fixed in 1.11.0a: * Bugs introduced by 1.11: diff --git a/automake.in b/automake.in index 8fd6869..f672286 100755 --- a/automake.in +++ b/automake.in @@ -396,6 +396,9 @@ my $package_version_location; # TRUE if we've seen AM_ENABLE_MULTILIB. my $seen_multilib = 0; +# TRUE if we've seen AM_PROG_AR +my $seen_ar = 0; + # TRUE if we've seen AM_PROG_CC_C_O my $seen_cc_c_o = 0; @@ -2718,8 +2721,11 @@ sub handle_libraries $var->requires_variables ('library used', 'RANLIB'); } - &define_variable ('AR', 'ar', INTERNAL); - &define_variable ('ARFLAGS', 'cru', INTERNAL); + if (! $seen_ar) + { + &define_variable ('AR', 'ar', INTERNAL); + &define_variable ('ARFLAGS', 'cru', INTERNAL); + } &define_verbose_tagvar ('AR'); foreach my $pair (@liblist) @@ -2800,6 +2806,13 @@ sub handle_libraries &check_libobjs_sources ($xlib, $xlib . '_LIBADD'); } } + + if (! $seen_ar) + { + msg ('portability', $where, + "`$onelib': linking libraries requires " + . "`AM_PROG_AR' in `$configure_ac'") + } } } @@ -3037,6 +3050,13 @@ sub handle_ltlibraries &check_libobjs_sources ($xlib, $xlib . '_LIBADD'); } } + + if (! $seen_ar) + { + msg ('portability', $where, + "`$onelib': linking libtool libraries requires " + . "`AM_PROG_AR' in `$configure_ac'") + } } } @@ -5242,6 +5262,7 @@ sub scan_autoconf_traces ($) AM_GNU_GETTEXT_INTL_SUBDIR => 0, AM_INIT_AUTOMAKE => 0, AM_MAINTAINER_MODE => 0, + AM_PROG_AR => 0, AM_PROG_CC_C_O => 0, AM_SILENT_RULES => 0, _AM_SUBST_NOTMAKE => 1, @@ -5433,6 +5454,10 @@ sub scan_autoconf_traces ($) { $seen_maint_mode = $where; } + elsif ($macro eq 'AM_PROG_AR') + { + $seen_ar = $where; + } elsif ($macro eq 'AM_PROG_CC_C_O') { $seen_cc_c_o = $where; diff --git a/doc/automake.texi b/doc/automake.texi index 66c5a7e..97d7a60 100644 --- a/doc/automake.texi +++ b/doc/automake.texi @@ -3861,6 +3861,12 @@ environment, or use the @option{--with-lispdir} option to @command{configure} to explicitly set the correct path (if you're sure you have an @command{emacs} that supports Emacs Lisp). +...@item AM_PROG_AR +...@acindex AM_PROG_AR +...@vindex AR +You must use this macro when you use the archiver in your project, if +you want support for weird archivers such as Microsoft lib. + @item AM_PROG_AS @acindex AM_PROG_AS @vindex CCAS @@ -4485,6 +4491,7 @@ AC_INIT([hand], [1.2]) AC_CONFIG_AUX_DIR([.]) AM_INIT_AUTOMAKE AC_PROG_CC +AM_PROG_AR AC_PROG_RANLIB AC_CONFIG_FILES([Makefile]) AC_OUTPUT @@ -4923,11 +4930,12 @@ by invoking @samp{$(AR) $(ARFLAGS)} followed by the name of the library and the list of objects, and finally by calling @samp{$(RANLIB)} on that library. You should call @code{AC_PROG_RANLIB} from your @file{configure.ac} to define -...@code{ranlib} (Automake will complain otherwise). @code{AR} and -...@code{arflags} default to @code{ar} and @code{cru} respectively; you -can override these two variables my setting them in your -...@file{makefile.am}, by @code{AC_SUBST}ing them from your -...@file{configure.ac}, or by defining a per-library @code{maude_AR} +...@code{ranlib} (Automake will complain otherwise). You should also +call @code{AM_PROG_AR} to define @code{AR}, in order to support weird +archivers. @code{ARFLAGS} will default to @code{cru}; you can override +this variable by setting it in your @file{Makefile.am} or by +...@code{ac_subst}ing it from your @file{configure.ac}. You can override +the @code{AR} variable by defining a per-library @code{maude_AR} variable (@pxref{Program and Library Variables}). @cindex Empty libraries diff --git a/m4/Makefile.am b/m4/Makefile.am index 0cf074b..c801894 100644 --- a/m4/Makefile.am +++ b/m4/Makefile.am @@ -22,6 +22,7 @@ m4datadir = $(datadir)/aclocal-$(APIVERSION) dist_m4data_DATA = \ $(top_srcdir)/m4/amversion.m4 \ +ar-lib.m4 \ as.m4 \ auxdir.m4 \ ccstdc.m4 \ diff --git a/m4/Makefile.in b/m4/Makefile.in index 270ee91..4cd3e28 100644 --- a/m4/Makefile.in +++ b/m4/Makefile.in @@ -185,6 +185,7 @@ top_srcdir = @top_srcdir@ m4datadir = $(datadir)/aclocal-$(APIVERSION) dist_m4data_DATA = \ $(top_srcdir)/m4/amversion.m4 \ +ar-lib.m4 \ as.m4 \ auxdir.m4 \ ccstdc.m4 \ diff --git a/m4/ar-lib.m4 b/m4/ar-lib.m4 new file mode 100644 index 0000000..b5a349e --- /dev/null +++ b/m4/ar-lib.m4 @@ -0,0 +1,55 @@ +## -*- Autoconf -*- +# Copyright (C) 2010 +# 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_PROG_AR +# -------------- +AC_DEFUN([AM_PROG_AR], +[AC_BEFORE([$0], [LT_INIT])dnl +AC_BEFORE([$0], [AC_PROG_LIBTOOL])dnl +AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl +AC_REQUIRE_AUX_FILE([ar-lib])dnl +AC_CHECK_TOOLS(AR, [ar lib "link -lib"], false) +: ${AR=ar} + +AC_CACHE_CHECK([the archiver ($AR) interface], [am_cv_ar_interface], + [am_cv_ar_interface=ar + AC_COMPILE_IFELSE([[int some_variable = 0;]], + [am_ar_try='$AR cru libconftest.a conftest.$ac_objext >&AS_MESSAGE_LOG_FD' + AC_TRY_EVAL([am_ar_try]) + if test "$ac_status" -eq 0; then + am_cv_ar_interface=ar + else + am_ar_try='$AR -NOLOGO -OUT:conftest.lib conftest.$ac_objext' + AC_TRY_EVAL([am_ar_try]) + if test "$ac_status" -eq 0; then + am_cv_ar_interface=lib + else + m4_default([$1], + [AC_MSG_ERROR([could not determine $AR interface])]) + fi + fi + rm -f conftest.lib libconftest.a + ]) + ]) + +case $am_cv_ar_interface in +ar) + ;; +lib) + # Microsoft lib, so override with the ar-lib wrapper script. + # FIXME: It is wrong to rewrite AR. + # But if we don't then we get into trouble of one sort or another. + # A longer-term fix would be to have automake use am__AR in this case, + # and then we could set am__AR="\$(top_srcdir)/ar-lib \$(AR)" + AR="$am_aux_dir/ar-lib $AR" + ;; +esac +AC_SUBST([AR])dnl +]) diff --git a/tests/Makefile.am b/tests/Makefile.am index 01acd76..7297fcb 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -89,6 +89,11 @@ ansi8.test \ ansi9.test \ ansi10.test \ ar-lib.test \ +ar-lib2.test \ +ar-lib3.test \ +ar-lib4.test \ +ar-lib5.test \ +ar-lib6.test \ ar.test \ ar2.test \ asm.test \ diff --git a/tests/Makefile.in b/tests/Makefile.in index ff547a0..9826c65 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -327,6 +327,11 @@ ansi8.test \ ansi9.test \ ansi10.test \ ar-lib.test \ +ar-lib2.test \ +ar-lib3.test \ +ar-lib4.test \ +ar-lib5.test \ +ar-lib6.test \ ar.test \ ar2.test \ asm.test \ diff --git a/tests/ar-lib2.test b/tests/ar-lib2.test new file mode 100755 index 0000000..7697876 --- /dev/null +++ b/tests/ar-lib2.test @@ -0,0 +1,40 @@ +#! /bin/sh +# Copyright (C) 2010 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 if AM_PROG_AR installs ar-lib. + +. ./defs || Exit 1 + +set -e + +cat >> configure.in << 'END' +AC_PROG_CC +AM_PROG_AR +END + +cat > Makefile.am << 'END' +bin_PROGRAMS = wish +wish_SOURCES = a.c +END + +$ACLOCAL +$AUTOMAKE --add-missing 2>stderr || { cat stderr >&2; Exit 1; } +cat stderr >&2 +# Make sure ar-lib is installed, and that Automake says so. +grep 'install.*ar-lib' stderr +test -f ar-lib + +: diff --git a/tests/ar-lib3.test b/tests/ar-lib3.test new file mode 100755 index 0000000..c5cbb2f --- /dev/null +++ b/tests/ar-lib3.test @@ -0,0 +1,51 @@ +#! /bin/sh +# Copyright (C) 2010 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 if lib_LIBRARIES requests AM_PROG_AR. + +. ./defs || Exit 1 + +set -e + +cat >> configure.in << 'END' +AC_PROG_CC +AC_PROG_RANLIB +END + +cat > Makefile.am << 'END' +lib_LIBRARIES = libfoo.a +libfoo_a_SOURCES = foo.c +END + +$ACLOCAL +$AUTOCONF +AUTOMAKE_fails + +grep 'requires.*AM_PROG_AR' stderr + +cat >> configure.in << 'END' +AM_PROG_AR +END + +$ACLOCAL +$AUTOCONF +AUTOMAKE_fails + +grep 'ar-lib.*not found' stderr + +$AUTOMAKE --add-missing + +: diff --git a/tests/ar-lib4.test b/tests/ar-lib4.test new file mode 100755 index 0000000..c389189 --- /dev/null +++ b/tests/ar-lib4.test @@ -0,0 +1,63 @@ +#! /bin/sh +# Copyright (C) 2010 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 if lib_LTLIBRARIES requests AM_PROG_AR. + +required=libtoolize +. ./defs || Exit 1 + +set -e + +cp configure.in X + +cat >> configure.in << 'END' +AC_PROG_CC +AC_PROG_RANLIB +AC_PROG_LIBTOOL +AC_OUTPUT +END + +cat > Makefile.am << 'END' +lib_LTLIBRARIES = libfoo.la +libfoo_la_SOURCES = foo.c +END + +libtoolize +$ACLOCAL +$AUTOCONF +AUTOMAKE_fails + +grep 'requires.*AM_PROG_AR' stderr + +cp X configure.in + +cat >> configure.in << 'END' +AC_PROG_CC +AM_PROG_AR +AC_PROG_RANLIB +AC_PROG_LIBTOOL +AC_OUTPUT +END + +$ACLOCAL +$AUTOCONF +AUTOMAKE_fails + +grep 'ar-lib.*not found' stderr + +$AUTOMAKE --add-missing + +: diff --git a/tests/ar-lib5.test b/tests/ar-lib5.test new file mode 100755 index 0000000..f6eb5b4 --- /dev/null +++ b/tests/ar-lib5.test @@ -0,0 +1,56 @@ +#! /bin/sh +# Copyright (C) 2010 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 if AM_PROG_AR triggers the use of the ar-lib script. + +requires=lib +. ./defs || Exit 1 + +set -e + +cat >> configure.in << 'END' +AC_PROG_CC +AM_PROG_AR +AC_PROG_RANLIB +AC_OUTPUT +END + +cat > Makefile.am << 'END' +lib_LIBRARIES = libwish.a +libwish_a_SOURCES = wish.c +END + +cat > wish.c << 'END' +int wish(void) { return 0; } +END + +$ACLOCAL +$AUTOCONF +$AUTOMAKE --add-missing --copy +./configure AR=lib RANLIB=: + +cat > ar-lib << 'END' +# /bin/sh +echo "It works" +END +chmod +x ar-lib + +$MAKE > stdout +cat stdout + +grep 'It works' stdout + +: diff --git a/tests/ar-lib6.test b/tests/ar-lib6.test new file mode 100755 index 0000000..45693dd --- /dev/null +++ b/tests/ar-lib6.test @@ -0,0 +1,38 @@ +#! /bin/sh +# Copyright (C) 2010 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_PROG_AR ordering requirements + +required=libtoolize +. ./defs || Exit 1 + +set -e + +cat >> configure.in << 'END' +AC_PROG_CC +AC_PROG_RANLIB +m4_ifdef([LT_INIT], [LT_INIT], [AC_PROG_LIBTOOL]) +AM_PROG_AR +END + +libtoolize +$ACLOCAL +$AUTOCONF 2>stderr +cat stderr + +$EGREP '(AC_PROG_LIBTOOL|LT_INIT).*before.*AM_PROG_AR' stderr + +: diff --git a/tests/ar.test b/tests/ar.test index d68fc54..00ea69e 100755 --- a/tests/ar.test +++ b/tests/ar.test @@ -21,6 +21,7 @@ set -e cat >> configure.in << 'END' +AM_PROG_AR AC_SUBST([AR], ['echo it works']) AC_SUBST([ARFLAGS], ['>']) AC_SUBST([RANLIB], ['echo really works >>']) @@ -34,7 +35,7 @@ END $ACLOCAL $AUTOCONF -$AUTOMAKE +$AUTOMAKE --add-missing ./configure $MAKE grep 'it works' libfoo.a diff --git a/tests/defs.in b/tests/defs.in index af4a3cd..31003ff 100644 --- a/tests/defs.in +++ b/tests/defs.in @@ -156,6 +156,16 @@ do echo "$me: running $CC -V -help" ( $CC -V -help ) || exit 77 ;; + lib) + AR=lib + export AR + # There is no way to get any identifying output with + # a zero exit status. So, remap exit status 76 to 0. + echo "$me: running $AR -?" + exit_status=0 + ( $AR -? ) || exit_status=$? + test $exit_status = 76 && exit 77 + ;; makedepend) echo "$me: running makedepend -f-" ( makedepend -f- ) || exit 77 -- 1.7.1