#! /bin/sh

# Note: using source directory from pass1

cd $BLDDIR/cross-gcc-build
rm -rf *

# disable -B in configure, so doesn't pick up host's headers
sed -i '/FLAGS_FOR_TARGET.*\/lib\//s@-B[^ ]*/lib/@@g' ../gcc-$GCC_VER/configure

AR=ar LDFLAGS="-Wl,-rpath,/cross-tools/lib" \
  ../gcc-$GCC_VER/configure --prefix=/cross-tools \
  --build=${CHFS_HOST} --target=${CHFS_TARGET} --host=${CHFS_HOST} \
  --with-sysroot=${CHFS} --with-local-prefix=/tools --disable-nls \
  --enable-shared --enable-languages=c,c++ --enable-__cxa_atexit \
  --with-mpfr=/cross-tools --with-gmp=/cross-tools --enable-c99 \
  --enable-long-long --enable-threads=posix --disable-multilib

# gcc>4.3  
#  --with-ppl=/cross-tools --with-cloog=/cross-tools \

make AS_FOR_TARGET="${CHFS_TARGET}-as" \
    LD_FOR_TARGET="${CHFS_TARGET}-ld"

# clean up files installed in pass 1
rm -f $HURD_DIR/lib/libgcc_eh.a $CROSS_DIR/lib/gcc/$TARGET/$GCC_VER/{libgcc.a,libgcov.a}

make install

cd $ROOT
