# Template file for 'mingw-w64-binutils'
pkgname=mingw-w64-binutils
version=2.21.1
revision=3
distfiles="${GNU_SITE}/binutils/binutils-$version.tar.bz2"
depends="glibc zlib"
makedepends="flex"
short_desc="GNU binary utilities (mingw-w64 version)"
maintainer="davehome <davehome@redthumb.info.tm>"
homepage="http://www.gnu.org/software/binutils/"
license="GPL-3"
checksum=f769b64350a02fbee009e1582cc12b6ed43b41985de65effb741e258e075dd05
long_desc="
 The GNU binutils package contains essential tools to assemble, link and
 manipulate binary and object files. They are often used with a compiler
 and additional libraries for building software.

 It includes the GNU linker, the portable GNU assembler, ar for modifying
 archives (such as libraries), nm for listing symbols from object files,
 objdump for displaying object file information, ranlib for generating
 archive indexes, size for listing section sizes of object files,
 strings for outputing the printable characters in files, strip for
 stripping out symbols (like debugging information) from object files,
 and other tools.

 * This is a special version for mingw-w64."



wrksrc=binutils-$version

_mingwprefix=/opt

do_build()
{
	if [ "${XBPS_MACHINE}" = "x86_64" ]; then
		_mingwtriplet="${XBPS_MACHINE}-w64-mingw32"
		_target_args="--enable-targets=${_mingwtriplet},i686-w64-mingw32"
		_multilib_args="--enable-multilib --enable-64-bit-bfd"
	else
		_mingwtriplet="${XBPS_MACHINE}-w64-mingw32"
		_target_args="--enable-targets=${_mingwtriplet}"
		_multilib_args="--disable-multilib"
	fi

	./configure --prefix=${_mingwprefix} --bindir=${_mingwprefix}/bin \
		--libdir=${_mingwprefix}/lib --libexecdir=${_mingwprefix}/lib \
		--target=${_mingwtriplet} ${_target_args} ${_multilib_args} \
		--enable-plugins --enable-secureplt --with-mmap --disable-nls \
		--enable-threads --with-sysroot=${_mingwprefix}

	make ${makejobs}
}

do_install()
{
	make DESTDIR=${DESTDIR} install

	# Remove useless manpages
	rm -rf ${DESTDIR}/${_mingwprefix}/share

	# Remove lib64 directory and it's only file: libiberty.a
	[ -d ${DESTDIR}/${_mingwprefix}/lib64 ] && \
		rm -rf ${DESTDIR}/${_mingwprefix}/lib64

	if [ "${XBPS_MACHINE}" = "x86_64" ]; then
		_mingwtriplet="${XBPS_MACHINE}-w64-mingw32"
	else
		_mingwtriplet="${XBPS_MACHINE}-w64-mingw32"
	fi

	# The mingw-w64 faq advises to create a symlink here
	if [ "${XBPS_MACHINE}" = "x86_64" ]; then
		cd ${DESTDIR}/${_mingwprefix}/${_mingwtriplet} && \
		ln -sf lib lib64
	fi

	# The mingw-w64 faq advises to create a symlink here
	cd ${DESTDIR}/${_mingwprefix} && ln -sf ${_mingwtriplet} mingw
}
