NAME=binutils
VERSION=( 2.17.50.0.14  2.4.11 )
SOURCE=(http://kernel.org/pub/linux/devel/binutils/binutils-$VERSION.tar.bz2
	http://kernel.org/pub/linux/devel/binutils/release.binutils-$VERSION
	http://kernel.org/pub/linux/utils/kernel/ksymoops/v${VERSION[1]%.*}/ksymoops-${VERSION[1]}.tar.bz2 )
PATCH=(	ksymoops.dynamic.bfd.diff.gz
	binutils.enable_gnu_hash_by_default.patch )
BUILD=${BUILD:-1}
ROOT_REQUIRED=1

OPTIMIZE=${OPTIMIZE:-"-O2"}

build() {
	_explode 0

	# Make --hash-style=gnu the default instead of --hash-style=sysv.
	# Binaries produced this way require glibc 2.5 to work.
	cd binutils-$VERSION
	_patch 1 -p1
	cd ..

	# Build outside the source tree.
	mkdir build
	cd build
	if [[ $ARCH == i?86 ]]; then # FIXME: athlonxp etc.
		# Build for an x86 glibc2-based Linux system:
		../binutils-$VERSION/$CONFIGURE \
			--build=$CONFIGURE_TRIPLET \
			--host=$CONFIGURE_TRIPLET \
			--target=$CONFIGURE_TRIPLET \
			--enable-shared \
			--enable-targets=$CONFIGURE_TRIPLET \
			--enable-64-bit-bfd
	else # Borrowed from Slamd64:
		../binutils-$VERSION/$CONFIGURE \
			--host=$CONFIGURE_TRIPLET \
			--target=$CONFIGURE_TRIPLET \
			--enable-shared \
			--enable-64-bit-bfd
	fi

	make clean
	make -j$MAKEJOBS tooldir=$PREFIX
	make info
	make install tooldir=$PREFIX DESTDIR=$PKG
	cd ../binutils-$VERSION

	# "make install" skips this, but binutils.spec doesn't.  Sneaky, huh?
	cp -a include/libiberty.h $PKG$INCLUDEDIR/libiberty.h

	# Docs adjustment:
	rm -f $PKG$MANDIR/man1/{dlltool.1,windres.1}
	rm -f $PKG$INFODIR/standards.info # Autoconf has a newer version.
	_doc 0 binutils-$VERSION  ${SOURCE[1]} COPYING* ChangeLog.linux MAI* README*

	# Conflicts with util-linux:
	mv $PKG$BINDIR/strings $PKG$BINDIR/strings-GNU
	mv $PKG$MANDIR/man1/strings.1 $PKG$MANDIR/man1/strings-GNU.1

	_chfix
	_chgrp_bin
	_tmp_pkg 0

	# By adding ksymoops to the binutils package, we can use the dynamic
	# libbfd and make the binary about 500K smaller.
	_explode 2
	cd $TMP/ksymoops-${VERSION[1]}
	_patch 0 -p1
	make
	mkdir -p $PKG$BINDIR $PKG$MANDIR/man8
	cp ksymoops $PKG$BINDIR/ksymoops
	cat ksymoops.8 > $PKG$MANDIR/man8/ksymoops.8
	_doc 0 ksymoops-${VERSION[1]}  COPYING Changelog INSTALL README*

	_chfix
	_chgrp_bin

	cat << EOF

#############################
oprofile links to libbfd so
be sure to recompile that
#############################

EOF

}
