automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: New auxiliary archive script


From: Peter Rosin
Subject: Re: New auxiliary archive script
Date: Fri, 06 Aug 2010 13:43:03 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.7) Gecko/20100713 Thunderbird/3.1.1

Hi Ralf,

Den 2010-08-06 07:22 skrev Ralf Wildenhues:
* Peter Rosin wrote on Fri, Aug 06, 2010 at 12:00:53AM CEST:
Den 2010-08-01 20:06 skrev Ralf Wildenhues:
For actual applicability, it is sufficient if you provide a working
script, post testsuite results with it in place (you might want to
   MAKE='make AR=...'

When I do

MAKE='make "AR=/path/to/archive lib"' make "AR=/path/to/archive lib" check

I get a whole bunch of failures when tests are running configure, the first
one being aclocal4.test:

Try passing in the environment, or in AM_MAKEFLAGS.

I haven't explored those options, instead I ended up wrapping the wrapper
with this 'arlib' script:

#! /bin/sh
/path/to/archive lib "$@"

and did the following to test
MAKE='make "AR=/path/to/arlib"' make "AR=/path/to/arlib" check

ar.test fails since it AC_SUBSTs AR to 'echo it works', but that
is then overridden by my MAKE assignment, and then things go south.
Other than that, no regressions in the automake test suite.
I did get a spurious failure in cond5.test, but it went away when
I ran it separately.

If I'm touching too many files, feel free to zap whatever hunk you
don't like...

Cheers,
Peter

commit 3d3229ff86bd8194974bcf56948f5c6b0b54d99a
Author: Peter Rosin <address@hidden>
Date:   Fri Aug 6 13:35:26 2010 +0200

    Add new auxiliary 'archive' script, wrapping Microsoft lib.

    * lib/archive: New auxiliary script.
    * lib/Makefile.am: Add above.
    * m4/archive.m4: New macro AM_PROG_AR, which locates an
    archiver and triggers the auxiliary 'archive' script if needed.
    * m4/Makefile.am: Add above.
    * automake.in (@common_files): Distribute the 'archive' script.
    * doc/automake.texi (Auxiliary Programs): Mention the new
    'archive' script.
    (Optional): Mention 'archive' in AC_CONFIG_AUX_DIR. Document
    AM_PROG_AR.
    (Subpackages): Add AM_PROG_AR to the example.
    (A Library): Adjust recommendations for AR given the new
    AM_PROG_AR macro.

diff --git a/ChangeLog b/ChangeLog
index 20adef2..1df96ea 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2010-08-06  Peter Rosin  <address@hidden>
+
+       Add new auxiliary 'archive' script, wrapping Microsoft lib.
+       * lib/archive: New auxiliary script.
+       * lib/Makefile.am: Add above.
+       * m4/archive.m4: New macro AM_PROG_AR, which locates an
+       archiver and triggers the auxiliary 'archive' script if needed.
+       * m4/Makefile.am: Add above.
+       * tests/archive.test: New test.
+       * tests/Makefile.am: Add above.
+       * automake.in (@common_files): Distribute the 'archive' script.
+       * doc/automake.texi (Auxiliary Programs): Mention the new
+       'archive' script.
+       (Optional): Mention 'archive' in AC_CONFIG_AUX_DIR. Document
+       AM_PROG_AR.
+       (Subpackages): Add AM_PROG_AR to the example.
+       (A Library): Adjust recommendations for AR given the new
+       AM_PROG_AR macro.
+       * NEWS: Update.
+
 2010-08-01  Peter Rosin  <address@hidden>

        Wrap some MSVC options in the compile script.
diff --git a/NEWS b/NEWS
index 54fac91..d0c2703 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.

+  - New macro AM_PROG_AR that looks for an archiver and wraps it in the new
+    'archive' 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 381202b..60994c3 100755
--- a/automake.in
+++ b/automake.in
@@ -235,9 +235,9 @@ my @libtool_sometimes = qw(ltconfig ltcf-c.sh ltcf-cxx.sh 
ltcf-gcj.sh);
 my @common_files =
     (qw(ABOUT-GNU ABOUT-NLS AUTHORS BACKLOG COPYING COPYING.DOC COPYING.LIB
        COPYING.LESSER ChangeLog INSTALL NEWS README THANKS TODO
-       ansi2knr.1 ansi2knr.c compile config.guess config.rpath config.sub
-       depcomp elisp-comp install-sh libversion.in mdate-sh missing
-       mkinstalldirs py-compile texinfo.tex ylwrap),
+       ansi2knr.1 ansi2knr.c archive compile config.guess config.rpath
+       config.sub depcomp elisp-comp install-sh libversion.in mdate-sh
+       missing mkinstalldirs py-compile texinfo.tex ylwrap),
      @libtool_files, @libtool_sometimes);

 # Commonly used files we auto-include, but only sometimes.  This list
diff --git a/doc/automake.texi b/doc/automake.texi
index 00e24eb..3860e20 100644
--- a/doc/automake.texi
+++ b/doc/automake.texi
@@ -2163,6 +2163,10 @@ copies are updated before each release, but we mention 
the original
 source in case you need more recent versions.

 @table @code
address@hidden archive
+This is a wrapper primarily for the Microsoft lib archiver, to make
+it more POSIX-like.
+
 @item ansi2knr.c
 @itemx ansi2knr.1
 These two files are used for de-ANSI-fication support (obsolete
@@ -2840,12 +2844,12 @@ The Autoconf Manual}.
 Automake will look for various helper scripts, such as
 @file{install-sh}, in the directory named in this macro invocation.
 @c This list is accurate relative to version 1.8
-(The full list of scripts is: @file{config.guess}, @file{config.sub},
address@hidden, @file{elisp-comp}, @file{compile}, @file{install-sh},
address@hidden, @file{mdate-sh}, @file{missing}, @file{mkinstalldirs},
address@hidden, @file{texinfo.tex}, and @file{ylwrap}.)  Not all
-scripts are always searched for; some scripts will only be sought if the
-generated @file{Makefile.in} requires them.
+(The full list of scripts is: @file{archive}, @file{config.guess},
address@hidden, @file{depcomp}, @file{elisp-comp}, @file{compile},
address@hidden, @file{ltmain.sh}, @file{mdate-sh}, @file{missing},
address@hidden, @file{py-compile}, @file{texinfo.tex}, and
address@hidden)  Not all scripts are always searched for; some scripts
+will only be sought if the generated @file{Makefile.in} requires them.

 If @code{AC_CONFIG_AUX_DIR} is not given, the scripts are looked for in
 their standard locations.  For @file{mdate-sh},
@@ -3857,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).

address@hidden AM_PROG_AR
address@hidden AM_PROG_AR
address@hidden 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
@@ -4481,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
@@ -4919,12 +4930,13 @@ 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
address@hidden (Automake will complain otherwise).  @code{AR} and
address@hidden default to @code{ar} and @code{cru} respectively; you
-can override these two variables my setting them in your
address@hidden, by @code{AC_SUBST}ing them from your
address@hidden, or by defining a per-library @code{maude_AR}
-variable (@pxref{Program and Library Variables}).
address@hidden (Automake will complain otherwise).  You should also
+call @code{AM_PROG_AR} to define @code{AR}. @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
address@hidden  You can override the @code{AR} variable by
+defining a per-library @code{maude_AR} variable (@pxref{Program
+and Library Variables}).

 @cindex Empty libraries
 Be careful when selecting library components conditionally.  Because
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 627368d..1702163 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -28,7 +28,7 @@ dist_pkgvdata_DATA = COPYING INSTALL texinfo.tex ansi2knr.c 
ansi2knr.1 \
 scriptdir = $(pkgvdatadir)
 dist_script_DATA = config.guess config.sub install-sh mdate-sh missing \
   mkinstalldirs elisp-comp ylwrap acinstall depcomp compile py-compile \
-  symlink-tree
+  symlink-tree archive

 EXTRA_DIST = gnupload

diff --git a/lib/Makefile.in b/lib/Makefile.in
index f90b085..d69e5cd 100644
--- a/lib/Makefile.in
+++ b/lib/Makefile.in
@@ -51,8 +51,8 @@ build_triplet = @build@
 subdir = lib
 DIST_COMMON = $(dist_pkgvdata_DATA) $(dist_script_DATA) \
        $(srcdir)/Makefile.am $(srcdir)/Makefile.in COPYING INSTALL \
-       ansi2knr.1 ansi2knr.c compile config.guess config.sub depcomp \
-       elisp-comp install-sh mdate-sh missing mkinstalldirs \
+       ansi2knr.1 ansi2knr.c archive compile config.guess config.sub \
+       depcomp elisp-comp install-sh mdate-sh missing mkinstalldirs \
        py-compile texinfo.tex ylwrap
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/m4/amversion.m4 \
@@ -231,7 +231,7 @@ dist_pkgvdata_DATA = COPYING INSTALL texinfo.tex ansi2knr.c 
ansi2knr.1 \
 scriptdir = $(pkgvdatadir)
 dist_script_DATA = config.guess config.sub install-sh mdate-sh missing \
   mkinstalldirs elisp-comp ylwrap acinstall depcomp compile py-compile \
-  symlink-tree
+  symlink-tree archive

 EXTRA_DIST = gnupload
 all: all-recursive
diff --git a/lib/archive b/lib/archive
new file mode 100755
index 0000000..90d60ea
--- /dev/null
+++ b/lib/archive
@@ -0,0 +1,245 @@
+#! /bin/sh
+# Wrapper for Microsoft lib.exe
+
+me=archive
+scriptversion=2010-08-06.11; # UTC
+
+# Copyright (C) 2010 Free Software
+# Foundation, Inc.
+# Written by Peter Rosin <address@hidden>.
+#
+# 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/>.
+
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# This file is maintained in Automake, please report
+# bugs to <address@hidden> or send patches to
+# <address@hidden>.
+
+
+# func_error message
+func_error ()
+{
+  echo "$me: $1" 1>&2
+  exit 1
+}
+
+file_conv=
+
+# func_file_conv build_file
+# Convert a $build file to $host form and store it in $file
+# Currently only supports Win32 hosts.
+func_file_conv ()
+{
+  file=$1
+  case $file in
+    / | /[^/]*) # absolute file, and not a UNC file
+      if test -z "$file_conv"; then
+       # lazily determine how to convert abs files
+       case `uname -s` in
+         MINGW*)
+           file_conv=mingw
+           ;;
+         CYGWIN*)
+           file_conv=cygwin
+           ;;
+         *)
+           file_conv=wine
+           ;;
+       esac
+      fi
+      case $file_conv in
+       mingw)
+         file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
+         ;;
+       cygwin)
+         file=`cygpath -m "$file" || echo "$file"`
+         ;;
+       wine)
+         file=`winepath -w "$file" || echo "$file"`
+         ;;
+      esac
+      ;;
+  esac
+}
+
+# func_at_file at_file operation archive
+# Iterate over all members in AT_FILE performing OPERATION on ARCHIVE
+# for each of them.
+# When interpreting the content of the @FILE, do NOT use func_file_conv,
+# since the user would need to supply preconverted file names to
+# binutils ar, at least for MinGW.
+func_at_file ()
+{
+  operation=$2
+  archive=$3
+  at_file_contents=`cat "$1"`
+  eval set x "$at_file_contents"
+  shift
+
+  for member
+  do
+    $AR -NOLOGO $operation:"$member" "$archive" || exit $?
+  done
+}
+
+case $1 in
+  '')
+     func_error "no command.  Try \`$0 --help' for more information."
+     ;;
+  -h | --h*)
+    cat <<\EOF
+Usage: archive [--help] [--version] PROGRAM ACTION ARCHIVE [MEMBER...]
+
+Members may be specified in a file named with @FILE.
+EOF
+    exit $?
+    ;;
+  -v | --v*)
+    echo "$me, version $scriptversion"
+    exit $?
+    ;;
+esac
+
+if test $# -lt 3; then
+  func_error "you must specify a program, an action and an archive"
+fi
+
+AR=$1
+shift
+action=$1
+shift
+orig_archive=$1
+shift
+func_file_conv "$orig_archive"
+archive=$file
+
+# strip leading dash in $action
+action=${action#-}
+
+delete=
+extract=
+list=
+replace=
+create=
+
+while test -n "$action"
+do
+  case $action in
+    d*) delete=yes  ;;
+    x*) extract=yes ;;
+    t*) list=yes    ;;
+    r*) replace=yes ;;
+    c*) create=yes  ;;
+    u*)             ;; # TODO: don't ignore the update modifier
+    *)
+      func_error "unknown action specified"
+      ;;
+  esac
+  action=${action#?}
+done
+
+case $delete$extract$list$replace in
+  yes)
+    ;;
+  yesyes*)
+    func_error "more than one action specified"
+    ;;
+  *)
+    func_error "no action specified"
+    ;;
+esac
+
+if test -n "$delete"; then
+  if test ! -f "$orig_archive"; then
+    func_error "archive not found"
+  fi
+  for member
+  do
+    case $1 in
+      @*)
+        func_at_file "address@hidden" -REMOVE "$archive"
+        ;;
+      *)
+        func_file_conv "$1"
+        $AR -NOLOGO -REMOVE:"$file" "$archive" || exit $?
+        ;;
+    esac
+  done
+
+elif test -n "$extract"; then
+  if test ! -f "$orig_archive"; then
+    func_error "archive not found"
+  fi
+  if test $# -gt 0; then
+    for member
+    do
+      case $1 in
+        @*)
+          func_at_file "address@hidden" -EXTRACT "$archive"
+          ;;
+        *)
+          func_file_conv "$1"
+          $AR -NOLOGO -EXTRACT:"$file" "$archive" || exit $?
+          ;;
+      esac
+    done
+  else
+    $AR -NOLOGO -LIST "$archive" | while read member
+    do
+      $AR -NOLOGO -EXTRACT:"$member" "$archive" || exit $?
+    done
+  fi
+
+elif test -n "$replace"; then
+  if test ! -f "$orig_archive"; then
+    if test -z "$create"; then
+      echo "$me: creating $orig_archive"
+    fi
+    orig_archive=
+  else
+    orig_archive=$archive
+  fi
+
+  for member
+  do
+    case $1 in
+    @*)
+      func_file_conv "address@hidden"
+      set x "$@" "@$file"
+      ;;
+    *)
+      func_file_conv "$1"
+      set x "$@" "$file"
+      ;;
+    esac
+    shift
+    shift
+  done
+
+  if test -n "$orig_archive"; then
+    $AR -NOLOGO -OUT:"$archive" "$orig_archive" "$@" || exit $?
+  else
+    $AR -NOLOGO -OUT:"$archive" "$@" || exit $?
+  fi
+
+elif test -n "$list"; then
+  if test ! -f "$orig_archive"; then
+    func_error "archive not found"
+  fi
+  $AR -NOLOGO -LIST "$archive" || exit $?
+fi
diff --git a/m4/Makefile.am b/m4/Makefile.am
index 0cf074b..bbf2515 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 \
+archive.m4 \
 as.m4 \
 auxdir.m4 \
 ccstdc.m4 \
diff --git a/m4/Makefile.in b/m4/Makefile.in
index 270ee91..de994df 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 \
+archive.m4 \
 as.m4 \
 auxdir.m4 \
 ccstdc.m4 \
diff --git a/m4/archive.m4 b/m4/archive.m4
new file mode 100755
index 0000000..f8f9570
--- /dev/null
+++ b/m4/archive.m4
@@ -0,0 +1,44 @@
+##                                                          -*- 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_REQUIRE([AM_AUX_DIR_EXPAND])dnl
+AC_REQUIRE_AUX_FILE([archive])dnl
+AC_CHECK_TOOLS(AR, [ar lib], false)
+: ${AR=ar}
+
+AC_CACHE_CHECK([the archiver ($AR) interface],[am_cv_ar_interface],
+  [am_cv_ar_interface="ar"
+  printf "int some_variable = 0;" > conftest.$ac_ext
+  (eval echo "\"\$as_me:__oline__: $ac_compile\"" >&AS_MESSAGE_LOG_FD)
+  (eval "$ac_compile" 2>conftest.err)
+  cat conftest.err >&AS_MESSAGE_LOG_FD
+  (eval "$AR -NOLOGO -OUT:conftest.lib conftest.$ac_objext" &>conftest.err)
+  ac_status=$?
+  cat conftest.err >&AS_MESSAGE_LOG_FD
+  test $ac_status = 0 && test -f conftest.lib && am_cv_ar_interface="lib"
+  rm -f conftest*])
+
+case $am_cv_ar_interface in
+ar)
+  ;;
+lib)
+  # Microsoft lib, so override with the archive 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)/archive \$(AR)"
+  AR="$am_aux_dir/archive $AR"
+  ;;
+esac
+AC_SUBST([AR])dnl
+])
diff --git a/tests/Makefile.am b/tests/Makefile.am
index bfc5270..58cd452 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -90,6 +90,7 @@ ansi9.test \
 ansi10.test \
 ar.test \
 ar2.test \
+archive.test \
 asm.test \
 asm2.test \
 asm3.test \
diff --git a/tests/Makefile.in b/tests/Makefile.in
index 3a34745..cb30a3a 100644
--- a/tests/Makefile.in
+++ b/tests/Makefile.in
@@ -328,6 +328,7 @@ ansi9.test \
 ansi10.test \
 ar.test \
 ar2.test \
+archive.test \
 asm.test \
 asm2.test \
 asm3.test \
diff --git a/tests/archive.test b/tests/archive.test
new file mode 100755
index 0000000..1b8d328
--- /dev/null
+++ b/tests/archive.test
@@ -0,0 +1,75 @@
+#! /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/>.
+
+# Make sure `archive' wraps the Microsoft Library Manager (lib) correctly
+
+. ./defs || Exit 1
+
+set -e
+
+cp "$testsrcdir/../lib/archive" .
+# Use a dummy lib, since lib isn't readily available on all systems
+cat >lib <<'END'
+#! /bin/sh
+if test x"$2" = x-LIST -a $3 = fake.lib; then
+  echo fake.obj
+else
+  echo "lib $@"
+fi
+END
+
+chmod +x ./lib
+
+# Check if archive can create an archive with "cr"
+opts=`./archive ./lib cr foo.lib foo.obj`
+test x"$opts" = x"lib -NOLOGO -OUT:foo.lib foo.obj"
+
+# Check if archive can update an existing archive with "r"
+touch foo.lib
+opts=`./archive ./lib r foo.lib foo.obj`
+test x"$opts" = x"lib -NOLOGO -OUT:foo.lib foo.lib foo.obj"
+
+# Check if archive passes on @FILE with "r"
+opts=`./archive ./lib r foo.lib @list`
+test x"$opts" = x"lib -NOLOGO -OUT:foo.lib foo.lib @list"
+
+# Check if archive can delete a member from an archive with "d"
+opts=`./archive ./lib d foo.lib foo.obj`
+test x"$opts" = x"lib -NOLOGO -REMOVE:foo.obj foo.lib"
+
+# Check if archive can delete members in an @FILE
+echo foo.obj > foolist
+opts=`./archive ./lib d foo.lib @foolist`
+test x"$opts" = x"lib -NOLOGO -REMOVE:foo.obj foo.lib"
+
+# Check if archive can list archive members with "t"
+opts=`./archive ./lib t foo.lib`
+test x"$opts" = x"lib -NOLOGO -LIST foo.lib"
+
+# Check if archive can extract archive members with "x"
+touch fake.lib
+opts=`./archive ./lib x fake.lib`
+test x"$opts" = x"lib -NOLOGO -EXTRACT:fake.obj fake.lib"
+
+# Check if archive can extract specified archive members with "x"
+opts=`./archive ./lib x foo.lib foo.obj`
+test x"$opts" = x"lib -NOLOGO -EXTRACT:foo.obj foo.lib"
+
+# Check if archive can extract members in an @FILE
+opts=`./archive ./lib x foo.lib @foolist`
+test x"$opts" = x"lib -NOLOGO -EXTRACT:foo.obj foo.lib"
+
+:



reply via email to

[Prev in Thread] Current Thread [Next in Thread]