#! /bin/sh -x

libc_ldbl128=$1
suffix=$2
destdir=$3
usr_local_lib_system=$4

libldbl128=libldbl128$suffix.a
objdir=`dirname $libc_ldbl128`
tmpdir=$objdir/tmp
libm=libm$suffix.a
libgcc=libgcc
libgccppc=$libgcc-ppc.a
libm128='ArcHyperbolicDD.o ArcSinCosDD.o ArcTanDD.o AuxiliaryDD.o ErfDD.o ExpDD.o ExpTableLD.o GammaDD.o HyperbolicDD.o LogDD.o LogTableLD.o PowerDD.o SinCosTanDD.o SqrtDD.o complex.o complexld64.o d3ops.o floating.o fpmacros.o ld64.o'

mkdir -p $tmpdir
cd $tmpdir
rm -f *
lipo -thin ppc -output $libm $usr_local_lib_system/$libm
ar x $libm $libm128
rm -f $libm
ar x $libc_ldbl128
rm -f __.*
mkdir -p $destdir
ar cq $destdir/$libldbl128 `lorder * | tsort -q`
ranlib $destdir/$libldbl128
if [ -z "$suffix" ]; then
    lib=`gcc-3.5 -arch ppc -print-file-name=$libgcc.a`
    cp $lib $destdir/$libgccppc
fi
