libtool
[Top][All Lists]
Advanced

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

Re: Archiver handling


From: Peter Rosin
Subject: Re: Archiver handling
Date: Tue, 02 Sep 2008 12:40:30 +0200
User-agent: Thunderbird 2.0.0.16 (Windows/20080708)

Back to the patches list...

Den 2008-08-31 23:17, skrev Peter Rosin:
*snip*
I can see one way out, and that is to create a new libtool mode, i.e.
an interface something like this:

    .../libtool --mode=ar cru foo.a a.o b.o c.o
    .../libtool --mode=ar x foo.a
    .../libtool --mode=ar t foo.a

Then in libtool.m4 set LTAR to '.../libtool --mode=ar' if $AR is "too
incompatible" with a standard archiver interface. If $AR is compatible,
simply set LTAR=$AR.

Makefiles (and automake) can then use $LTAR if they like, or continue
to use $AR if they wish to remain incompatible...

Ok, no comments. To show what I mean, here's a patch for the
pr-msvc-support branch. It needs documentation and test suite
exposure of course, but that part is not fun enough to do
without any sign that this change is at all welcome...

I know that I can fix this with an external wrapper, but an
archive is a library of sorts, so IMHO Libtool is not a bad
place at all to add this. Libtool is after all a tool to make
library handling portable.

The Automake part is very hard for me to do, my perl-fu is very
weak. I suppose it has to check if the project is using libtool
and if libtool is new enough, and if that is indeed the case,
insert "$(LTAR) $(LTAR_FLAGS)" instead of "$(AR) $(ARFLAGS)" in
Makefile.in.

This patch does not try to clear up the $ARFLAGS vs $AR_FLAGS
confusion, but I suppose something like this could be added
somewhere:

if test -n "$AR_FLAGS" || test -z "$ARFLAGS"; then
  LTAR_FLAGS='$(AR_FLAGS)'
else
  LTAR_FLAGS='$(ARFLAGS)'
fi

Maybe that part is completely orthogonal, i.e. maybe it can be
fixed without involving this $LTAR layer at all, and maybe the
above $AR_FLAGS resolution is flawed in multiple ways? Did I
mention untested? :-)

Cheers,
Peter

diff --git a/Makefile.am b/Makefile.am
index 1049289..fafd69b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -476,7 +476,8 @@ EXTRA_DIST     += $(srcdir)/$(TESTSUITE) $(TESTSUITE_AT) 
$(srcdir)/tests/package
 TESTS_ENVIRONMENT = MAKE="$(MAKE)" CC="$(CC)" CFLAGS="$(CFLAGS)" \
        CPP="$(CPP)" CPPFLAGS="$(CPPFLAGS)" LD="$(LD)" LDFLAGS="$(LDFLAGS)" \
        LIBS="$(LIBS)" LN_S="$(LN_S)" NM="$(NM)" RANLIB="$(RANLIB)" \
-       AR="$(AR)" AR_FLAGS="${AR_FLAGS}" AR_SEP="${AR_SEP}" \
+       AR="$(AR)" AR_FLAGS="$(AR_FLAGS)" \
+       LTAR="$(LTAR)" LTAR_FLAGS="$(LTAR_FLAGS)" \
        STRIP="$(STRIP)" \
        OBJEXT="$(OBJEXT)" EXEEXT="$(EXEEXT)" \
        SHELL="$(SHELL)" CONFIG_SHELL="$(SHELL)" \
diff --git a/libltdl/config/ltmain.m4sh b/libltdl/config/ltmain.m4sh
index b78d7ac..2cb4a57 100644
--- a/libltdl/config/ltmain.m4sh
+++ b/libltdl/config/ltmain.m4sh
@@ -47,6 +47,7 @@ m4_divert_push([SCRIPT])# @configure_input@
 #
 # MODE must be one of the following:
 #
+#       ar                 handle archives
 #       clean              remove files from the build directory
 #       compile            compile a source file into a libtool object
 #       execute            automatically set library path, then run a program
@@ -256,6 +257,9 @@ func_enable_tag ()
 
   # Shorthand for --mode=foo, only valid as the first argument
   case $1 in
+  ar|a)
+    shift; set dummy --mode ar ${1+"$@"}; shift
+    ;;
   clean|clea|cle|cl)
     shift; set dummy --mode clean ${1+"$@"}; shift
     ;;
@@ -305,6 +309,7 @@ func_enable_tag ()
       --mode)          test "$#" -eq 0 && func_missing_arg "$opt" && break
                        case $1 in
                          # Valid mode arguments:
+                         ar)           ;;
                          clean)        ;;
                          compile)      ;;
                          execute)      ;;
@@ -1050,6 +1055,22 @@ func_mode_help ()
         func_help
         ;;
 
+      ar)
+        $ECHO \
+"Usage: $progname [OPTION]... --mode=ar COMMAND ARCHIVE [OBJECT...]
+
+Create and extract files from archives.
+
+This mode accepts the following archiver COMMANDs:
+
+  cru               create the ARCHIVE, consisting of the given OBJECTs.
+  x                 extract the ARCHIVE
+  t                 list the ARCHIVE content
+
+Note that this mode is not for creating static libtool libraries, it is
+a compatibility layer for \"weird\" archivers."
+        ;;
+
       clean)
         $ECHO \
 "Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
@@ -8045,6 +8066,54 @@ func_mode_uninstall ()
 { test "$mode" = uninstall || test "$mode" = clean; } &&
     func_mode_uninstall ${1+"$@"}
 
+
+# func_mode_ar arg...
+func_mode_ar ()
+{
+    $opt_debug
+    ar_action="$nonopt"
+    archive=
+    files=
+
+    for arg
+    do
+      if test -z "$archive"; then
+        archive=$arg
+      else
+        files="$files $arg"
+      fi
+    done
+
+    test -z "$archive" && \
+      func_fatal_help "you must specify an archive"
+
+    case "$ar_action" in
+    cru)
+      test -z "$files" && \
+       func_fatal_help "you must specify some objects"
+      func_show_eval "$AR $AR_FLAGS$AR_SEP$archive $files" 'exit $?'
+      ;;
+    x)
+      if test "x$ar_extract_one_by_one" = xyes; then
+       func_extract_an_archive . "$archive"
+       exit $?
+      else
+       func_show_eval "$AR $AR_XFLAGS$AR_SEP$archive" 'exit $?'
+      fi
+      ;;
+    t)
+      func_show_eval "$AR $AR_TFLAGS$AR_SEP$archive" 'exit $?'
+      ;;
+    *)
+      func_fatal_help "bad archive action, either cru, x or t"
+      ;;
+    esac
+
+    exit $EXIT_SUCCESS
+}
+
+test "$mode" = ar && func_mode_ar ${1+"$@"}
+
 test -z "$mode" && {
   help="$generic_help"
   func_fatal_help "you must specify a MODE"
diff --git a/libltdl/m4/libtool.m4 b/libltdl/m4/libtool.m4
index a9f9035..18c319b 100644
--- a/libltdl/m4/libtool.m4
+++ b/libltdl/m4/libtool.m4
@@ -1394,6 +1394,18 @@ lib)
   ;;
 esac
 
+if test -n "$AR_SEP" &&
+   test "X$AR_TFLAGS" = Xt &&
+   test "X$AR_XFLAGS" = Xx &&
+   test "$ar_extract_one_by_one" = no
+then
+  LTAR='$(AR)'
+  LTAR_FLAGS='$(AR_FLAGS)'
+else
+  LTAR='$(SHELL) $(abs_top_builddir)/libtool --quiet --mode=ar'
+  LTAR_FLAGS=cru
+fi
+
 _LT_DECL([], [ar_extract_one_by_one], [1],
   [Extract archive members one by one])
 _LT_DECL([], [archiver_list_spec], [1],
@@ -1403,10 +1415,10 @@ _LT_DECL([], [AR_FLAGS], [1], [Flags to create an 
archive])
 _LT_DECL([], [AR_TFLAGS], [1], [Flags to list archive content])
 _LT_DECL([], [AR_XFLAGS], [1], [Flags to extract an archive])
 _LT_DECL([], [AR_SEP], [1], [Separator between AR flags and AR files])
+AC_SUBST([LTAR])
+AC_SUBST([LTAR_FLAGS])
 AC_SUBST([AR])
 AC_SUBST([AR_FLAGS])
-AC_SUBST([AR_TFLAGS])
-AC_SUBST([AR_SEP])
 ])# LT_PROG_AR
 
 
diff --git a/tests/archive-in-archive.at b/tests/archive-in-archive.at
index dd4a122..bab79b9 100644
--- a/tests/archive-in-archive.at
+++ b/tests/archive-in-archive.at
@@ -50,8 +50,7 @@ AT_CHECK([$LIBTOOL --mode=link --tag=CC --tag=disable-shared 
$CC $CFLAGS $LDFLAG
 AT_CHECK([$LIBTOOL --mode=install cp libbar.la $thisdir], [], [ignore], 
[ignore])
 eval `$EGREP '^(old_library)=' < libbar.la`
 libbar=$old_library
-eval `$LIBTOOL --config | $EGREP '^(AR_TFLAGS|AR_SEP)='`
-AT_CHECK([$AR $AR_TFLAGS$AR_SEP$libbar | grep $libfoo],[1],[ignore],[ignore])
-archive_contents=`$AR $AR_TFLAGS$AR_SEP$libbar`
+AT_CHECK([$LTAR t $libbar | grep $libfoo],[1],[ignore],[ignore])
+archive_contents=`$LTAR t $libbar`
 AT_XFAIL_IF([case "$archive_contents" in *"$libfoo"*) : ;; esac])
 AT_CLEANUP

reply via email to

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