# Template build file for 'mingw-w64-crt'
#
_shortname=mingw-w64
pkgname=${_shortname}-crt
_majversion=1.0
_snapshot=20110523
version=${_majversion}.${_snapshot}
revision=3
distfiles=${SOURCEFORGE_SITE}/${_shortname}/${_shortname}/${_shortname}-v${_majversion}-snapshot-${_snapshot}.tar.bz2
makedepends="flex"
if [ "${XBPS_MACHINE}" = "x86_64" ]; then
	makedepends="${makedepends} gcc-multilib"
fi
fulldepends="mingw-w64-binutils mingw-w64-headers mingw-w64-gcc"
short_desc="The mingw-w64 cross-compiler runtime"
maintainer="davehome <davehome@redthumb.info.tm>"
homepage="http://mingw-w64.sourceforge.net/"
license="Public Domain, BSD, LGPL, ZPL"
checksum=12dc02c40cb2d28dd70aeea792fe998e29acfc614589ecf7508cd1fbb93a4154
long_desc="
 The mingw-w64 cross-compiler runtime.

 This is the mingw-64 cross-compiler, which supports building code for Win32
 or Win64 (multilib).  For the i686 platform, only 32bit is available."

_mingwprefix=/opt

if [ "${XBPS_MACHINE}" = "x86_64" ]; then
	_mingwtriplet="${XBPS_MACHINE}-w64-mingw32"
	_multilib_args="--enable-lib32 --enable-lib64"
else
	_mingwtriplet="${XBPS_MACHINE}-w64-mingw32"
	_multilib_args="--enable-lib32 --disable-lib64"
fi

strip_cmd=${_mingwprefix}/bin/${_mingwtriplet}-strip
wrksrc=${_shortname}-v${_majversion}-${_snapshot}
build_wrksrc=${pkgname}

do_build() {
	unset LD_LIBRARY_PATH LDLIBPATH LDFLAGS CPPFLAGS
	local SAVEDPATH=$PATH
	export PATH="/opt/bin:/usr/local/bin:/usr/local/sbin:/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin"

	./configure --prefix=${_mingwprefix} --with-sysroot=${_mingwprefix} \
		--host=${_mingwtriplet} ${_multilib_args} \
		--bindir=${_mingwprefix}/bin --libdir=${_mingwprefix}/lib \
		--libexecdir=${_mingwprefix}/lib
            
	make ${makejobs}
	
	export PATH=$SAVEDPATH
}

do_install() {
	# This path setting is necessary so that it finds ${_mingwprefix}-ranlib
	unset LD_LIBRARY_PATH LDLIBPATH LDFLAGS CPPFLAGS
	local SAVEDPATH=$PATH
	export PATH="/opt/bin:/usr/local/bin:/usr/local/sbin:/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin"

	make DESTDIR=${DESTDIR} install

	export PATH=$SAVEDPATH
}
