+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
}
+# 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
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://'`
# 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`
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
--- /dev/null
+#! /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