#! /bin/sh
# $NetBSD: cross-env,v 1.1 2016/06/19 16:18:28 wiz Exp $

PREFIX=/usr/pkg/cross

if [ -z "$CROSS_PKG" ] ;then
    cat <<END
You should set 'CROSS_PKG' to the name of the cross compile package, eg:
'sparc-netbsdelf'. If MACHINE_ARCH is not already set it will be set to
the part before the '-' (eg: 'sparc'). You may find it useful to also set
MACHINE.
END
exit 1
fi

if [ -z "$MACHINE_ARCH" ];then
    export MACHINE_ARCH=`echo $CROSS_PKG| sed 's:-.*::'`
fi

BINDIR=$PREFIX/$CROSS_PKG/bin
echo $BINDIR

if [ ! -d $BINDIR ];then
    echo "Unable to locate $MACHINE_ARCH cross compiler in $BINDIR"
    echo "Have you installed the appropriate pkgsrc/cross/$CROSS_PKG package?"
    exit 3
fi

export PATH=$BINDIR:$PATH

GCC_EXEC_PREFIX=$CROSS_PKG

export ADDR2LINE=$BINDIR/addr2line
export AR=$BINDIR/ar
export AS=$BINDIR/as
export CC=$BINDIR/gcc
export CPP=`$CC -print-prog-name=cpp`
export CXX=$BINDIR/c++
export FC=$BINDIR/f77
export GASP=$BINDIR/gasp
export LD=$BINDIR/ld
export NM=$BINDIR/nm
export OBJCOPY=$BINDIR/objcopy
export OBJDUMP=$BINDIR/objdump
export RANLIB=$BINDIR/ranlib
export SIZE=$BINDIR/size
export STRINGS=$BINDIR/strings
export STRIP=$BINDIR/strip

export	MKPROFILE=no
export	MKLINT=no
#export	MKMAN=no

export	HOSTED_CC=cc

export MAKE=make
#export MAKE="make -f ${DESTDIR}/usr/share/mk/sys.mk -f Makefile"
#export MAKEFLAGS="-I ${DESTDIR}/usr/share/mk"

set -x
exec "$@"
