# SliTaz package receipt.

PACKAGE="aufs"
VERSION="20110214"
CATEGORY="base-system"
SHORT_DESC="aufs2 kernel module"
MAINTAINER="slaxemulator@gmail.com"
WEB_SITE="http://aufs.sf.net/"
PROVIDE="linux-aufs"
TARBALL="$PACKAGE-$VERSION.tar.bz2"
WGET_URL="git|http://git.c3sl.ufpr.br/pub/scm/aufs/aufs2-standalone.git"
BRANCH="origin/${PACKAGE}2.1-37"

DEPENDS="linux"
BUILD_DEPENDS="linux-module-headers git lzma"

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

	sed -i 's|CONFIG_AUFS_BRANCH_MAX_127 =.*|CONFIG_AUFS_BRANCH_MAX_127 =|' \
		config.mk || return 1
	sed -i 's|#CONFIG_AUFS_BRANCH_MAX_32767 =.*|CONFIG_AUFS_BRANCH_MAX_32767 = y|' \
		config.mk || return 1
	sed -i 's|CONFIG_AUFS_HNOTIFY =.*|CONFIG_AUFS_HNOTIFY = y|' \
		config.mk || return 1
	sed -i 's|CONFIG_AUFS_HFSNOTIFY =.*|CONFIG_AUFS_HFSNOTIFY = y|' \
		config.mk || return 1
	sed -i 's|CONFIG_AUFS_EXPORT =.*|CONFIG_AUFS_EXPORT = y|' \
		config.mk || return 1
	sed -i 's|CONFIG_AUFS_SHWH =.*|CONFIG_AUFS_SHWH = y|' \
		config.mk || return 1
	sed -i 's|CONFIG_AUFS_BDEV_LOOP =.*|CONFIG_AUFS_BDEV_LOOP = y|' \
		config.mk || return 1
	sed -i 's|CONFIG_AUFS_BR_RAMFS =.*|CONFIG_AUFS_BR_RAMFS = y|' \
		config.mk || return 1
	sed -i 's|CONFIG_AUFS_DEBUG =.*|CONFIG_AUFS_DEBUG =|' \
		config.mk || return 1

	# The sed fixes are from gentoo portage build.
	sed -i "s:aufs.ko usr/include/linux/aufs_type.h:aufs.ko:g" Makefile
	sed -i "s:__user::g" include/linux/aufs_type.h
	make -j 1 KDIR=/usr/src/linux
}

# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{
	EXTRAVERSION=_${kvers}
	mkdir -p $fs/lib/modules/$kvers-slitaz/kernel/fs/aufs
	lzma e $src/fs/aufs/aufs.ko \
		$fs/lib/modules/$kvers-slitaz/kernel/fs/aufs/aufs.ko.gz
	chown root $fs/lib/modules/$kvers-slitaz/kernel/fs/aufs/aufs.ko.gz
	chown 0644 $fs/lib/modules/$kvers-slitaz/kernel/fs/aufs/aufs.ko.gz
	install -D -m 644 $src/include/linux/aufs_type.h \
		$fs/usr/include/linux/aufs_type.h 
}

post_install()
{
	echo "Processing post-install commands..."
	chroot "$1/" depmod -a ${EXTRAVERSION#_}-slitaz
}

post_remove()
{
	echo "Processing post-remove commands..."
	chroot "$1/" depmod -a ${EXTRAVERSION#_}-slitaz
}