# SliTaz package receipt.

PACKAGE="binutils223"
SOURCE="binutils"
VERSION="2.23.1"
CATEGORY="development"
TAGS="assembler linker"
SHORT_DESC="GNU assembler, linker and binary utilities."
MAINTAINER="pankso@slitaz.org"
LICENSE="GPL2"
WEB_SITE="https://www.gnu.org/software/binutils/"

TARBALL="$SOURCE-$VERSION.tar.bz2"
#WGET_URL="https://www.kernel.org/pub/linux/devel/binutils/$TARBALL"
WGET_URL="http://ftp.gnu.org/gnu/$SOURCE/$TARBALL"

PROVIDE="libbfd"
DEPENDS="flex glibc zlib"
BUILD_DEPENDS="glibc-dev texinfo zlib-dev"

HOST_ARCH="i486 arm"

# Handle cross compilation.
case "$ARCH" in
	arm) BUILD_DEPENDS="" ;;
esac

# @maintainer: Please update also: libbfd

# What is the latest version available today?
current_version()
{
	wget -O - ${WGET_URL%/*} 2>/dev/null | \
	sed "/latest/d;/$PACKAGE-/!d;/tar/!d;s|.*$PACKAGE-\\(.*\\).tar.*\".*|\\1|" | sort -Vr | sed q
}

# Rules to configure and make the package.
compile_rules()
{
	case "$ARCH" in
		i?86) ARCH_ARGS="--disable-werror --enable-64-bit-bfd" ;;
	esac

	mkdir	../binutils-build &&
	cd	../binutils-build &&
	$src/configure					\
		--program-prefix=$TOOLPREFIX		\
		--program-suffix=-2.23			\
		--enable-shared				\
		--disable-initfini-array		\
		--with-bugurl="http://bugs.slitaz.org/"	\
		$CONFIGURE_ARGS				\
		$ARCH_ARGS &&
	make tooldir=/usr &&
	make install tooldir=/usr &&
	# This is the default binutils, so create symlinks to the target platform
	# binutil binaries. Delete duplicate binaries to save space.
	for binutil in $(ls -1 $DESTDIR/usr/bin | grep "${TOOLPREFIX}")
	  do
		path="$DESTDIR/usr/bin/$(echo "$binutil" | sed "s:$TOOLPREFIX::g")"
		if [ -e $path ]
		  then
			rm -f $path
		fi
		ln -s $binutil $path
	  done
}

# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{
	cook_copy_folders	bin
	cook_copy_folders	include
	cook_copy_files		*.a
	cook_copy_files		*.so*

	# libiberty.h
	cp -a $src/include/libiberty.h	$fs/usr/include

	# Remove 'strings' (Busybox).
	#rm $fs/usr/lib/libiberty.a
	rm				$fs/usr/bin/strings*
	rm				$fs/usr/bin/*-strings*

	# Remove build directory (cookutils and tazwok path).
	rm -rf $WOK/$PACKAGE/source/$PACKAGE-build
	rm -rf $WOK/$PACKAGE/$PACKAGE-build

	chown -R root:root		$fs/usr/include/libiberty.h
	chmod 644			$fs/usr/include/libiberty.h
}