# SliTaz package receipt.

PACKAGE="coreutils"
VERSION="8.12"
CATEGORY="system-tools"
SHORT_DESC="Utilities for using and setting the basic system."
MAINTAINER="pankso@slitaz.org"
TARBALL="$PACKAGE-$VERSION.tar.xz"
WEB_SITE="http://www.gnu.org/software/coreutils/"
WGET_URL="ftp://ftp.gnu.org/gnu/$PACKAGE/$TARBALL"
DEPENDS="glibc-base gmp libcap"
BUILD_DEPENDS="slitaz-toolchain libcap-dev gmp-dev m4 autoconf automake"

# Rules to configure and make the package.
compile_rules()
{
	cd $src

	# NOTE: There does not seem to be a problem with sigcontext.h in Linux 2.6.29.3

	# Hack to fix ls: expected specifier-qualifier-list before '__u64'
	# Hack to change uname: so can see the cpu type your running on with uname
	while read patch_file; do
		if [ -f done.$patch_file ]; then
			echo "Skipping $patch_file"
			continue
		fi
		echo "Apply $patch_file"
		patch -p1 < $stuff/$patch_file || return 1
		touch done.$patch_file
	done <<EOT
ls.u
uname.u
EOT

	sed -i 's/1.10a/1.10.2/' configure.ac || return 1
	sed -i 's/dist-xz/dist-lzma/' configure.ac || return 1

	./configure $CONFIGURE_ARGS && 
	make && make install

	# Restore original sigcontext.h
	# mv -f /usr/include/asm/sigcontext.h.bak /usr/include/asm/sigcontext.h
}

# Rules to gen a SliTaz package suitable for Tazpkg.
#
# This is a special package for installed system or developer. We only take
# a fiew things, Busybox provide all the basic utilitie, but not for compiling.
# But DO NOT ecrase a Busybox applet, remove it before with pre_install rules.
#
genpkg_rules()
{
	mkdir -p $fs/usr/bin
	# Utils...
	cp -a $_pkg/usr/bin/base64 $fs/usr/bin
	cp -a $_pkg/usr/bin/csplit $fs/usr/bin
	cp -a $_pkg/usr/bin/factor $fs/usr/bin
	cp -a $_pkg/usr/bin/fmt $fs/usr/bin
	cp -a $_pkg/usr/bin/join $fs/usr/bin
	cp -a $_pkg/usr/bin/od $fs/usr/bin
	cp -a $_pkg/usr/bin/paste $fs/usr/bin
	cp -a $_pkg/usr/bin/ptx $fs/usr/bin
	cp -a $_pkg/usr/bin/shred $fs/usr/bin
	cp -a $_pkg/usr/bin/shuf $fs/usr/bin
	cp -a $_pkg/usr/bin/split $fs/usr/bin
	cp -a $_pkg/usr/bin/users $fs/usr/bin
	cp -a $_pkg/usr/bin/groups $fs/usr/bin
}

# Pre and post install commands for Tazpkg.
# We must remove all Busybox symlink before installing.
#
pre_install()
{
	local root
	root=$1
	echo "Processing pre-install commands..."
	echo -n "Removing all Busybox replaced utils... "
	rm -f $root/usr/bin/od $root/usr/bin/split
	status
}

post_remove()
{
	ln -s /bin/busybox $1/usr/bin/od
	ln -s /bin/busybox $1/usr/bin/split
}

clean_wok()
{
	rm -rf $WOK/$PACKAGE-*/taz
	rm -rf $WOK/$PACKAGE-*/process.log
}