#!/bin/sh

. config/options

export BUILD_CC=$HOST_CC
export OBJDUMP_FOR_HOST=objdump

if [ "$TARGET_ARCH" = powerpc ]; then
  CFLAGS="-mpowerpc"
elif [ "$TARGET_ARCH" = powerpc64 ]; then
  CFLAGS="-mpowerpc64"
elif [ "$TARGET_ARCH" = i386 ]; then
  CFLAGS="-march=$(echo $TARGET_NAME | cut -d- -f 1) -mtune=generic"
else
  CFLAGS="-mtune=generic"
fi
CFLAGS="$CFLAGS -g -O2"

if [ "$DEBUG" = yes ]; then
  DEBUG_CONFIG="--enable-debug"
else
  DEBUG_CONFIG="--disable-debug"
fi

cd $BUILD/glibc*
mkdir -p objdir-$1
cd objdir-$1

cat >config.cache <<EOF
libc_cv_forced_unwind=yes
libc_cv_c_cleanup=yes
libc_cv_gnu99_inline=yes
EOF

../configure --host=$TARGET_NAME \
             --build=$HOST_NAME \
             --prefix=/usr \
             --libexecdir=/usr/lib/glibc \
             --disable-profile \
             --disable-sanity-checks \
             --enable-add-ons=nptl \
             --with-tls \
             --enable-kernel=2.6.0 \
             --with-__thread \
             --with-binutils=$BUILD/toolchain/bin \
             --with-headers=$SYSROOT_PREFIX/usr/include \
             --cache-file=config.cache \
             --without-cvs \
             --without-gd \
             $DEBUG_CONFIG \

make
make_install

sed -i 's%bash%sh%g' .install/usr/bin/ldd

rm -rf ../.install
mv .install ..
