]> git.ipfire.org Git - thirdparty/libtool.git/commitdiff
* ltmain.in (func_extract_archives,func_extract_an_archive): On
authorPeter O'Gorman <peter@pogma.com>
Sat, 11 Dec 2004 14:40:25 +0000 (14:40 +0000)
committerPeter O'Gorman <peter@pogma.com>
Sat, 11 Dec 2004 14:40:25 +0000 (14:40 +0000)
darwin, uniq can not take teh flags -cd together, thanks to Ralf
for the fix, also ar does not accept N, so we use the fact that
ar x libfoo.a foo.o will always extract the first foo.o in the
archive and we then delete foo.o from the archive, which will also
delete only the first foo.o, then rinse and repeat.
* tests/func_extract_archives.test: Test this feature.
* tests/Makefile.am: Add the test.

ChangeLog
ltmain.in
tests/Makefile.am
tests/func_extract_archives.test [new file with mode: 0755]

index b29007a0807ab1051529355ff728911dde9ce392..3b9f17c2b0c9be44871d3a740dc8b3cae502b7a1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2004-12-10  Peter O'Gorman  <peter@pogma.com>
+
+       * ltmain.in (func_extract_archives,func_extract_an_archive): On 
+       darwin, uniq can not take teh flags -cd together, thanks to Ralf
+       for the fix, also ar does not accept N, so we use the fact that
+       ar x libfoo.a foo.o will always extract the first foo.o in the
+       archive and we then delete foo.o from the archive, which will also
+       delete only the first foo.o, then rinse and repeat.
+       * tests/func_extract_archives.test: Test this feature.
+       * tests/Makefile.am: Add the test.
+
 2004-12-09  Albert Chin-A-Young  <china@thewrittenword.com>
 
        * ltmain.in: Preserve -model [arg] option, used
index 328e8c52477b4718039dbcb5f9f09798c2e98d0d..c0df607300d8fe831d8d35bbd161e565f8193fee 100644 (file)
--- a/ltmain.in
+++ b/ltmain.in
@@ -242,6 +242,44 @@ func_infer_tag () {
 }
 
 
+# func_extract_an_archive dir oldlib
+func_extract_an_archive () {
+    f_ex_an_ar_dir="$1"; shift
+    f_ex_an_ar_oldlib="$1"
+    f_ex_an_ar_lib=`$echo "X$f_ex_an_ar_oldlib" | $Xsed -e 's%^.*/%%'`
+
+    $show "(cd $f_ex_an_ar_dir && $AR x $f_ex_an_ar_oldlib)"
+    $run eval "(cd \$f_ex_an_ar_dir && $AR x \$f_ex_an_ar_oldlib)" || exit $?
+    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
+     :
+    else
+      $echo "$modename: warning: object name conflicts; renaming object files" 1>&2
+      $echo "$modename: warning: to ensure that they will not overwrite" 1>&2
+      $show "cp $f_ex_an_ar_oldlib $f_ex_an_ar_dir/$f_ex_an_ar_lib"
+      $run eval "cp \$f_ex_an_ar_oldlib \$f_ex_an_ar_dir/\$f_ex_an_ar_lib"
+      $AR t "$f_ex_an_ar_oldlib" | sort | uniq -c \
+       | $EGREP -v '^[         ]*1[    ]' | while read -r count name
+      do
+       i=1
+       while test "$i" -le "$count"
+         do
+         # Put our $i before any first dot (extension)
+         # Never overwrite any file
+         name_to="$name"
+         while test "X$name_to" = "X$name" || test -f "$f_ex_an_ar_dir/$name_to"
+           do
+           name_to=`$echo "X$name_to" | $Xsed -e "s/\([^.]*\)/\1-$i/"`
+         done
+         $show "(cd $f_ex_an_ar_dir && $AR x  $f_ex_an_ar_lib '$name' && $mv '$name' '$name_to')"
+         $run eval "(cd \$f_ex_an_ar_dir && $AR x \$f_ex_an_ar_lib '$name' && $mv '$name' '$name_to' && $AR -d \$f_ex_an_ar_lib '$name')" || exit $?
+         i=`expr $i + 1`
+       done
+      done
+      $show "$rm $f_ex_an_ar_dir/$f_ex_an_ar_lib"
+      $run eval "$rm \$f_ex_an_ar_dir/\$f_ex_an_ar_lib"
+    fi
+}
+
 # func_extract_archives gentop oldlib ...
 func_extract_archives () {
     my_gentop="$1"; shift
@@ -287,7 +325,7 @@ func_extract_archives () {
          cd $my_xdir || exit $?
          darwin_archive=$my_xabs
          darwin_curdir=`pwd`
-         darwin_base_archive=`basename $darwin_archive`
+         darwin_base_archive=`$echo "X$darwin_archive" | $Xsed -e 's%^.*/%%'`
          darwin_arches=`lipo -info "$darwin_archive" 2>/dev/null | $EGREP Architectures 2>/dev/null`
          if test -n "$darwin_arches"; then 
            darwin_arches=`echo "$darwin_arches" | $SED -e 's/.*are://'`
@@ -299,10 +337,8 @@ func_extract_archives () {
              # Remove the table of contents from the thin files.
              $AR -d "unfat-$$/${darwin_base_archive}-${darwin_arch}/${darwin_base_archive}" __.SYMDEF 2>/dev/null || true
              $AR -d "unfat-$$/${darwin_base_archive}-${darwin_arch}/${darwin_base_archive}" __.SYMDEF\ SORTED 2>/dev/null || true
-             cd "unfat-$$/${darwin_base_archive}-${darwin_arch}"
-             $AR -xo "${darwin_base_archive}"
-             rm "${darwin_base_archive}"
-             cd "$darwin_curdir"
+             func_extract_an_archive "unfat-$$/${darwin_base_archive}-${darwin_arch}" "${darwin_base_archive}"
+             $rm "unfat-$$/${darwin_base_archive}-${darwin_arch}/${darwin_base_archive}"
            done # $darwin_arches
       ## Okay now we have a bunch of thin objects, gotta fatten them up :)
            darwin_filelist=`find unfat-$$ -type f | xargs basename | sort -u | $NL2SP`
@@ -312,48 +348,20 @@ func_extract_archives () {
              darwin_files=`find unfat-$$ -name $darwin_file -print | $NL2SP`
              lipo -create -output "$darwin_file" $darwin_files
            done # $darwin_filelist
-           rm -rf unfat-$$
+           ${rm}f unfat-$$
            cd "$darwin_orig_dir"
          else
-           cd $darwin_orig_dir
-           (cd $my_xdir && $AR x $my_xabs) || exit $?
+           cd "$darwin_orig_dir"
+           func_extract_an_archive "$my_xdir" "$my_xabs"
          fi # $darwin_arches
        fi # $run
       ;;
       *)
-       # We will extract separately just the conflicting names and we will
-       # no longer touch any unique names. It is faster to leave these
-       # extract automatically by $AR in one run.
-       $show "(cd $my_xdir && $AR x $my_xabs)"
-       $run eval "(cd \$my_xdir && $AR x \$my_xabs)" || exit $?
-       if ($AR t "$my_xabs" | sort | sort -uc >/dev/null 2>&1); then
-         :
-       else
-         $echo "$modename: warning: object name conflicts; renaming object files" 1>&2
-         $echo "$modename: warning: to ensure that they will not overwrite" 1>&2
-         $AR t "$my_xabs" | sort | uniq -cd | while read -r count name
-         do
-           i=1
-           while test "$i" -le "$count"
-           do
-             # Put our $i before any first dot (extension)
-             # Never overwrite any file
-             name_to="$name"
-             while test "X$name_to" = "X$name" || test -f "$my_xdir/$name_to"
-             do
-               name_to=`$echo "X$name_to" | $Xsed -e "s/\([^.]*\)/\1-$i/"`
-             done
-             $show "(cd $my_xdir && $AR xN $i $my_xabs '$name' && $mv '$name' '$name_to')"
-             $run eval "(cd \$my_xdir && $AR xN $i \$my_xabs '$name' && $mv '$name' '$name_to')" || exit $?
-             i=`expr $i + 1`
-           done
-         done
-       fi
-       ;;
+        func_extract_an_archive "$my_xdir" "$my_xabs"
+        ;;
       esac
       my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | $NL2SP`
     done
-
     func_extract_archives_result="$my_oldobjs"
 }
 # End of Shell function definitions
index ab3c34bfdc272f6755f24c77c9ec2fc4594b6273..1ea7f05104488b8f1a969ac1149d0c04a9004c8a 100644 (file)
@@ -45,7 +45,8 @@ COMMON_TESTS = \
        quote.test sh.test suffix.test pdemo-conf.test \
        pdemo-make.test pdemo-exec.test pdemo-inst.test \
        mdemo-conf.test mdemo-make.test mdemo2-conf.test \
-       mdemo2-make.test mdemo2-exec.test
+       mdemo2-make.test mdemo2-exec.test \
+       func_extract_archives.test 
 
 
 if HAVE_CXX
@@ -91,4 +92,4 @@ clean-local:
        -test -f ../mdemo/Makefile && cd ../mdemo && $(MAKE) distclean
        -test -f ../tagdemo/Makefile && cd ../tagdemo && $(MAKE) distclean
        -test -f ../f77demo/Makefile && cd ../f77demo && $(MAKE) distclean
-       rm -rf _inst
+       rm -rf _inst .libs
diff --git a/tests/func_extract_archives.test b/tests/func_extract_archives.test
new file mode 100755 (executable)
index 0000000..797b5d8
--- /dev/null
@@ -0,0 +1,82 @@
+#! /bin/sh
+# func_extract_archives.test
+
+need_prefix=no
+if test -z "$srcdir"; then
+  srcdir=`echo "$0" | sed 's%/[^/]*$%%'`
+  test "$srcdir" = "$0" && srcdir=.
+  test "${VERBOSE+set}" != "set" && VERBOSE=yes
+fi
+. $srcdir/defs || exit 1
+case $host in 
+*darwin*)
+  makefatdarwin=yes
+  ;;
+  *)
+  makefatdarwin=
+  ;;
+esac
+rm -f foo.o bar.o libfoo.a
+SED=${SED-sed}
+Xsed="$SED -e s/^X//"
+for afile in baz foobar foobaz
+do
+  if test -n "$makefatdarwin"; then
+    echo "ppc $afile" > $afile.ppc.o
+    echo "m68k $afile" > $afile.m68k.o
+    echo "i386 $afile" > $afile.i386.o
+    lipo -create -output $afile.o -arch ppc $afile.ppc.o -arch m68k \
+      $afile.m68k.o -arch i386 $afile.i386.o
+    rm -f $afile.*.o
+    ar -q libfoo.a $afile.o
+    rm -f $afile.o
+  else
+    echo "$afile" > $afile.o
+    ar -q libfoo.a $afile.o
+    rm -f $afile.o
+  fi
+done
+for anum in 1 2 3 4 5 6 7 8 9 10 11 12
+do
+  if test -n "$makefatdarwin"; then
+    echo "ppc foo $anum" > foo.ppc.o
+    echo "m68k foo $anum" > foo.m68k.o
+    echo "i386 foo $anum" > foo.i386.o
+    lipo -create -output foo.o -arch ppc foo.ppc.o -arch m68k foo.m68k.o \
+      -arch i386 foo.i386.o
+    ar -q libfoo.a foo.o
+    rm -f foo.o foo.*.o
+    echo "ppc bar $anum" > bar.ppc.o
+    echo "m68k bar $anum" > bar.m68k.o
+    echo "i386 bar $anum" > bar.i386.o
+    lipo -create -output bar.o -arch ppc bar.ppc.o -arch m68k bar.m68k.o \
+      -arch i386 bar.i386.o
+    ar -q libfoo.a bar.o
+    rm -f bar.o bar.*.o
+  else
+    echo "foo $anum" > foo.o
+    echo "bar $anum" > bar.o
+    ar -q libfoo.a foo.o bar.o
+  fi
+done
+test -d .libs || mkdir .libs
+
+eval "`$SED -n -e '/^# Shell function definitions:'$z'$/,/^# End of Shell function definitions'$z'$/p' < $libtool`"
+
+modename=libtool
+show=echo
+run=
+mkdir=mkdir
+rm="rm -f"
+mv=mv
+echo=echo
+AR=${AR-ar}
+func_extract_archives ".libs/libfoo" "libfoo.a"
+for anum in 1 2 3 4 5 6 7 8 9 10 11 12
+do
+  test -f ".libs/libfoo/libfoo.a/foo-$anum.o" || exit 1
+  $EGREP -v "foo-$anum" ".libs/libfoo/libfoo.a/foo-$anum.o" || exit 1
+  rm -f ".libs/libfoo/libfoo.a/foo-$anum.o"
+done
+rm -rf ".libs/libfoo"
+exit 0