#!/bin/sh

. config/options $1

if [ "$TARGET_ARCH" = "x86_64" ]; then
  WITH_64B_BFD="--enable-64-bit-bfd"
fi

setup_toolchain host

CPPFLAGS=""
CFLAGS=""
CXXFLAGS=""
LDFLAGS=""

cd $PKG_BUILD
mkdir -p objdir && cd objdir
../configure --host=$HOST_NAME \
             --build=$HOST_NAME \
             --target=$TARGET_NAME \
             --prefix=$ROOT/$TOOLCHAIN \
             --with-sysroot=$SYSROOT_PREFIX \
             --with-gmp=$ROOT/$TOOLCHAIN \
             --with-mpfr=$ROOT/$TOOLCHAIN \
             --with-ppl=$ROOT/$TOOLCHAIN \
             --with-cloog=$ROOT/$TOOLCHAIN \
             --with-libelf=$ROOT/$TOOLCHAIN \
             --disable-werror \
             --disable-multilib \
             --disable-libada \
             --disable-libssp \
             --enable-version-specific-runtime-libs \
             $WITH_64B_BFD \
             --enable-plugins \
             --enable-gold \
             --enable-ld=default \
             --enable-lto \
             --disable-nls

make configure-host
make

cp -v ../include/libiberty.h $SYSROOT_PREFIX/usr/include

make install

cp ${TARGET_PREFIX}ld.gold ${TARGET_PREFIX}gold
cp $ROOT/$TOOLCHAIN/$TARGET_NAME/bin/ld.gold $ROOT/$TOOLCHAIN/$TARGET_NAME/bin/gold
