#!/bin/sh
. ./environ.sh
if [[ "$TARGET" == ""  || "$PREFIX" == "" ]] ; then
	echo "You need to set: TARGET and PREFIX"; exit 0;
fi
export PATH=$PATH:$PREFIX/$TARGET
# make sure build area is clean
rm -rf $PREFIX/newlib_build/*
(cd $PREFIX/newlib_build ; \
    ../newlib_sources/configure -v --quiet --target=$TARGET --prefix=$PREFIX \
    --disable-newlib-supplied-syscalls --enable-interwork --enable-multilib \
    --with-gnu-ld --with-gnu-as --disable-newlib-io-float)
zcat downloads/newlib_makefile_patch.gz | patch -d $PREFIX/newlib_build -p0
(cd $PREFIX/newlib_build ;  make all install 2>&1 | tee make.log)
# delete libm
# find $PREFIX/$TARGET/lib/ -type f -name 'libm.a' | xargs -ilibname rm libname

