# SliTaz package receipt.

PACKED_SIZE="60.0K"
UNPACKED_SIZE="64.0K"
PACKAGE="memtest"
VERSION="5.01"
CATEGORY="base-system"
SHORT_DESC="Memory failures detection tool."
MAINTAINER="pascal.bellard@slitaz.org"
LICENSE="GPL2"
SOURCE="memtest86+"
TARBALL="$SOURCE-$VERSION.tar.gz"
WEB_SITE="http://www.memtest.org/"
WGET_URL="${WEB_SITE}download/$VERSION/$TARBALL"

BUILD_DEPENDS="xz"

# Rules to configure and make the package.
compile_rules()
{
	sed -i '/scp memtest.bin/d' Makefile
	for i in array-size io setup ; do
		patch -p1 < $stuff/$SOURCE-$VERSION-$i.patch
	done
	make
	cp $stuff/*.S $stuff/pack .
	for i in bootloader unpack ; do
		cc -o $i.o -Wa,-a=$i.lst -c $i.S
		objcopy -O binary $i.o $i.bin
	done
	sed -i "s/VERSION/$VERSION/" pack
	./pack --build bootloader.bin unpack.bin
	./pack memtest.bin memtest.packed
	mv memtest.bin memtest.bin.console
	sed -i  -e 's/SERIAL_CONSOLE_DEFAULT 0/SERIAL_CONSOLE_DEFAULT 1/' \
		-e 's/SERIAL_BAUD_RATE 9600/SERIAL_BAUD_RATE 115200/' config.h
	make clean
	make
	./pack memtest.bin memtest.packed-115200
	mv memtest.bin memtest.bin.serial
} 


# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{
	mkdir -p $fs/boot $install/usr/share/doc
	cp $src/README* $install/usr/share/doc
	cp $src/FAQ $install/usr/share/doc
	cp $src/memtest.packed $fs/boot/memtest.exe
}

# Pre and post install commands for Tazpkg.
post_install()
{
	[ -s $1/boot/isolinux/isolinux.cfg ] &&
	! grep -qs 'Check memory' $1/boot/isolinux/isolinux.cfg && sed -i \
's|LABEL md5|LABEL memtest mem ram\
	MENU LABEL Check memory\
	KERNEL /boot/memtest.exe\
\n&|' $1/boot/isolinux/isolinux.cfg
	true
}
