Subject: bug#19967: bug#20082: new warning from ar on rawhide systems

From: Pavel Raiskup <[email-masked]>
Date: Sat, 18 Apr 2015 11:50:31 +0200

On Friday 17 of April 2015 18:07:57 Peter Rosin wrote:
> On 2015-04-17 17:54, Pavel Raiskup wrote:
> > I tried to prepare the patch, but thats probably wrong.  It would be nice
> > if somebody could comment,
> 
> Microsofts archiver (lib.exe) uses a syntax like:
> 
>   lib -extract:file.o archive.lib
> 
> where -extract: was thought to be the content of $AR_FLAGS.
> 
> But since then, I added the ar-lib helper to Automake, which hides
> these brain-damaged flags that lib expects.

Thanks for the info, Peter.

Any objections against attached patches?

Pavel
>From 5e24b9305a1c1a32f171b6801597a6d335cea8fa Mon Sep 17 00:00:00 2001
From: Pavel Raiskup <[email-masked]>
Date: Fri, 17 Apr 2015 15:05:42 +0200
Subject: [PATCH 1/2] libool.m4: incorporate ARFLAGS variable

Libtool has used $AR_FLAGS since 2000-05-29 commit
8300de4c54e6f04f0d, Automake ARFLAGS since 2003-04-06 commit
a71b3490639831ca.  Even though ARFLAGS is younger, it sounds like
better naming according GNU Coding Standards.

Related to bug#20082.

* m4/libtool.m4 (_LT_PROG_AR): Start using ARFLAGS variable.
(lt_ar_flags): New _LT_DECL'ed variable to hold the configure-time
value of ARFLAGS.
(AR_FLAGS): Be sensitive to ARFLAGS env variable.  Reuse the
$lt_ar_flags during libtool runtime to set the default value.
* NEWS: Document.
---
 NEWS          |  5 +++++
 m4/libtool.m4 | 17 +++++++++++++++--
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index c5c9023..142d821 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,11 @@ NEWS - list of user-visible changes between releases of GNU Libtool
 
 * Noteworthy changes in release ?.? (????-??-??) [?]
 
+** New features:
+
+  - Libtool script now supports (configure-time and runtime) ARFLAGS
+    variable, which obsoletes AR_FLAGS.  This is due to naming conventions
+    among other *FLAGS and to be consistent with Automake's ARFLAGS.
 
 * Noteworthy changes in release 2.4.6 (2015-02-15) [stable]
 
diff --git a/m4/libtool.m4 b/m4/libtool.m4
index a3bc337..26b7530 100644
--- a/m4/libtool.m4
+++ b/m4/libtool.m4
@@ -1493,9 +1493,22 @@ need_locks=$enable_libtool_lock
 m4_defun([_LT_PROG_AR],
 [AC_CHECK_TOOLS(AR, [ar], false)
 : ${AR=ar}
-: ${AR_FLAGS=cru}
 _LT_DECL([], [AR], [1], [The archiver])
-_LT_DECL([], [AR_FLAGS], [1], [Flags to create an archive])
+
+# Use ARFLAGS variable as AR's operation code to sync the variable naming with
+# Automake.  If both AR_FLAGS and ARFLAGS are specified, AR_FLAGS should have
+# higher priority because thats what people were doing historically (setting
+# ARFLAGS for automake and AR_FLAGS for libtool).  FIXME: Make the AR_FLAGS
+# variable obsoleted/removed.
+
+: ${AR_FLAGS=${ARFLAGS-cru}}
+lt_ar_flags="$AR_FLAGS"
+_LT_DECL([], [lt_ar_flags], [0], [Flags to create an archive (by configure)])
+
+# Make AR_FLAGS overridable by 'make ARFLAGS='.  Don't try to run-time override
+# by AR_FLAGS because that was never working and AR_FLAGS is about to die.
+_LT_DECL([], [AR_FLAGS], [\${ARFLAGS-"\$lt_ar_flags"}],
+         [Flags to create an archive])
 
 AC_CACHE_CHECK([for archiver @FILE support], [lt_cv_ar_at_file],
   [lt_cv_ar_at_file=no
-- 
2.1.0

>From ea7619e81fc839634b38a9459e6b69026ebbe6d7 Mon Sep 17 00:00:00 2001
From: Pavel Raiskup <[email-masked]>
Date: Fri, 17 Apr 2015 16:54:58 +0200
Subject: [PATCH 2/2] ARFLAGS: use 'cr' instead of 'cru' by default

In some GNU/Linux distributions people started to compile 'ar'
binary with --enable-deterministic-archives (binutils project).
That, however, in combination with our previous long time working
default AR_FLAGS=cru causes warnings on such installations:
ar: `u' modifier ignored since `D' is the default (see `U')

The 'u' option (at least with GNU binutils) did small optimization
during repeated builds because it instructed 'ar' to not
open/close unchanged *.o files and to rather read their contents
from old archive file.  However, its removal should not cause a
big performance hit for usual workflows.

Distributions started using --enable-deterministic-archives
knowing that it would disable the 'u', just to rather have a bit
more deterministic builds.

Also, to justify this change a bit more, keeping 'u' in ARFLAGS
could only result in many per-project changes to override
Libtool's ARFLAGS default, just to silent such warnings.

Fixes bug#19967.  Reported by Eric Blake.

* m4/libtool.m4 (_LT_PROG_AR): Default AR_FLAGS to 'cr'.
(_LT_REQUIRED_DARWIN_CHECKS): Use $AR_FLAGS instead 'cru' string.
* doc/libtool.texi: Do 's/ar cru/ar cr/' in whole documentation,
to not document something which is not done by libtool.
* NEWS: Document.
---
 NEWS             |  4 ++++
 doc/libtool.texi | 10 +++++-----
 m4/libtool.m4    |  6 +++---
 3 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/NEWS b/NEWS
index 142d821..e4d75ff 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,10 @@ NEWS - list of user-visible changes between releases of GNU Libtool
     variable, which obsoletes AR_FLAGS.  This is due to naming conventions
     among other *FLAGS and to be consistent with Automake's ARFLAGS.
 
+** Important incompatible changes:
+
+  - Libtool changed ARFLAGS/AR_FLAGS default from 'cru' to 'cr'
+
 * Noteworthy changes in release 2.4.6 (2015-02-15) [stable]
 
 ** New features:
diff --git a/doc/libtool.texi b/doc/libtool.texi
index 0298627..4c664bb 100644
--- a/doc/libtool.texi
+++ b/doc/libtool.texi
@@ -602,7 +602,7 @@ Without libtool, the programmer would invoke the @command{ar} command to
 create a static library:
 
 @example
-burger$ @kbd{ar cru libhello.a hello.o foo.o}
+burger$ @kbd{ar cr libhello.a hello.o foo.o}
 burger$
 @end example
 
@@ -632,7 +632,7 @@ libtool are the same ones you would use to produce an executable named
 a23$ @kbd{libtool --mode=link gcc -g -O -o libhello.la foo.o hello.o}
 *** Warning: Linking the shared library libhello.la against the
 *** non-libtool objects foo.o hello.o is not portable!
-ar cru .libs/libhello.a
+ar cr .libs/libhello.a
 ranlib .libs/libhello.a
 creating libhello.la
 (cd .libs && rm -f libhello.la && ln -s ../libhello.la libhello.la)
@@ -662,7 +662,7 @@ archive, not a shared library (@pxref{Static libraries}).}:
 @example
 a23$ @kbd{libtool --mode=link gcc -g -O -o libhello.la foo.lo hello.lo \
                 -rpath /usr/local/lib -lm}
-ar cru @value{objdir}/libhello.a foo.o hello.o
+ar cr @value{objdir}/libhello.a foo.o hello.o
 ranlib @value{objdir}/libhello.a
 creating libhello.la
 (cd @value{objdir} && rm -f libhello.la && ln -s ../libhello.la libhello.la)
@@ -676,7 +676,7 @@ burger$ @kbd{libtool --mode=link gcc -g -O -o libhello.la foo.lo hello.lo \
                 -rpath /usr/local/lib -lm}
 rm -fr  @value{objdir}/libhello.a @value{objdir}/libhello.la
 ld -Bshareable -o @value{objdir}/libhello.so.0.0 @value{objdir}/foo.o @value{objdir}/hello.o -lm
-ar cru @value{objdir}/libhello.a foo.o hello.o
+ar cr @value{objdir}/libhello.a foo.o hello.o
 ranlib @value{objdir}/libhello.a
 creating libhello.la
 (cd @value{objdir} && rm -f libhello.la && ln -s ../libhello.la libhello.la)
@@ -6001,7 +6001,7 @@ in cases where it is necessary.
 @subsection Archivers
 
 On all known systems, building a static library can be accomplished by
-running @kbd{ar cru lib@var{name}.a @var{obj1}.o @var{obj2}.o @dots{}},
+running @kbd{ar cr lib@var{name}.a @var{obj1}.o @var{obj2}.o @dots{}},
 where the @file{.a} file is the output library, and each @file{.o} file is an
 object file.
 
diff --git a/m4/libtool.m4 b/m4/libtool.m4
index 26b7530..e1674f5 100644
--- a/m4/libtool.m4
+++ b/m4/libtool.m4
@@ -1042,8 +1042,8 @@ int forced_loaded() { return 2;}
 _LT_EOF
       echo "$LTCC $LTCFLAGS -c -o conftest.o conftest.c" >&AS_MESSAGE_LOG_FD
       $LTCC $LTCFLAGS -c -o conftest.o conftest.c 2>&AS_MESSAGE_LOG_FD
-      echo "$AR cru libconftest.a conftest.o" >&AS_MESSAGE_LOG_FD
-      $AR cru libconftest.a conftest.o 2>&AS_MESSAGE_LOG_FD
+      echo "$AR $AR_FLAGS libconftest.a conftest.o" >&AS_MESSAGE_LOG_FD
+      $AR $AR_FLAGS libconftest.a conftest.o 2>&AS_MESSAGE_LOG_FD
       echo "$RANLIB libconftest.a" >&AS_MESSAGE_LOG_FD
       $RANLIB libconftest.a 2>&AS_MESSAGE_LOG_FD
       cat > conftest.c << _LT_EOF
@@ -1501,7 +1501,7 @@ _LT_DECL([], [AR], [1], [The archiver])
 # ARFLAGS for automake and AR_FLAGS for libtool).  FIXME: Make the AR_FLAGS
 # variable obsoleted/removed.
 
-: ${AR_FLAGS=${ARFLAGS-cru}}
+: ${AR_FLAGS=${ARFLAGS-cr}}
 lt_ar_flags="$AR_FLAGS"
 _LT_DECL([], [lt_ar_flags], [0], [Flags to create an archive (by configure)])
 
-- 
2.1.0