# SliTaz package receipt.

PACKED_SIZE="32.0K"
UNPACKED_SIZE="40.0K"
PACKAGE="x86test"
VERSION="0.10a"
CATEGORY="base-system"
SHORT_DESC="CPU failures detection tool."
GROUP="misc"
MAINTAINER="pascal.bellard@slitaz.org"
LICENSE="GPL2"
WEB_SITE="https://web.archive.org/web/20090327202227/http://www.vortex.prodigynet.co.uk/x86test/"
#TARBALL="$PACKAGE-$VERSION.tar.bz2"
#WGET_URL="https://web.archive.org/web/20080509064221/http://www.vortex.prodigynet.co.uk/x86test/$TARBALL"
TARGET="i486"

BUILD_DEPENDS="xz"

tune_lzma()
{
	cp $stuff/*.S $stuff/pack .
	sed "s/VERSION/$VERSION/;s|lzma1=|&nice=$1,|" -i pack
	sed -i '/#define ONLY8086/d' unpack.S
	while [ -n "$2" ]; do
		sed "s|^#define PROP_$2 .*|#define PROP_$2 $3|" -i unlzma.S
		shift 2
	done
	for i in bootloader unpack patch ; do
		cc -o $i.o -Wa,-a=$i.lst -c $i.S
		objcopy -O binary $i.o $i.bin
	done
	./pack --build bootloader.bin unpack.bin
}

# Rules to configure and make the package.
compile_rules()
{
	mkdir -p $src && cd $src && cp $stuff/x86test .
	tune_lzma 35,mf=bt2,lc=3,lp=0,pb=0 LC 3 LP 0 PB 0
	patch=$((0x$(sed '/patch$/!d;s|.*text:0*||;s| .*||' patch.lst)))
	dd if=patch.bin bs=1 skip=$patch 2> /dev/null | dd conv=notrunc of=x86test bs=1 seek=$((0xA00+$patch)) 2> /dev/null
	./pack x86test x86test.packed
	dd if=bootloader.bin of=x86test conv=notrunc 2> /dev/null
} 

# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{
	mkdir -p $fs/boot
	cp $src/x86test.packed $fs/boot/$PACKAGE
}

# Post install/remove commands for Tazpkg.
post_install()
{
	grep -qs ^x86test $1/boot/bootmenu ||
	echo "x86test	X86test,cpu,x86		Check X86 CPU (may run under DOS if renamed to x86test.exe)" >> $1/boot/bootmenu
}