DEVDIR=$PWD
GNU_INSTALL="${DEVDIR}/gnu/install"
mkdir -p gnu/install
mkdir -p gnu/build/gnumach
mkdir -p gnu/build/mig
mkdir -p gnu/build/hurd
mkdir -p ${DEVDIR}/toolchains/i686-gnu/install
. ${DEVDIR}/toolchains/i686-linux-gnu/activate.sh
#export CFLAGS="-static"

if [[ ! -f gnu/install/include/mach/mach_port.defs ]]; then
	cd src/gnumach
	autoreconf --install
	cd ${DEVDIR}/gnu/build/gnumach
	${DEVDIR}/src/gnumach/configure --prefix= --host=i686-gnu LD=i686-linux-gnu-ld CC=i686-linux-gnu-gcc
	make DESTDIR=${GNU_INSTALL} install-data
else
	echo "gnumach headers already installed"
fi

if [[ ! -f gnu/install/bin/mig ]]; then
	cd ${DEVDIR}/src/mig
	autoreconf --install
	cd ${DEVDIR}/gnu/build/mig
	TARGET_CPPFLAGS=-I"${GNU_INSTALL}"/include ${DEVDIR}/src/mig/configure --prefix=${GNU_INSTALL} --host=i686-linux-gnu
	make all install
	make install-local-mig --prefix=${DEVDIR}/toolchains/i686-gnu/install
else
	echo "mig already installed"
fi

export PATH="${GNU_INSTALL}/bin:$PATH"

if [[ ! -f $GNU_INSTALL/gnumach ]]; then
	cd ${DEVDIR}/gnu/build/gnumach
	make gnumach.gz
	make install DESTDIR=${GNU_INSTALL}
else
	echo "mach already compiled"
fi

cd ${DEVDIR}/src/hurd/
autoreconf -i
cd ${DEVDIR}/gnu/build/hurd
${DEVDIR}/src/hurd/configure \
    --host=i686-gnu \
    --prefix=$GNU_INSTALL \
    --disable-profile \
    --without-parted
make no_deps=t install-headers

