# Template file for 'aufs2-kmod'
pkgname=aufs2-kmod
version=2.6.31_20090910
wrksrc=aufs2-${version}
distfiles="ftp://ftp.archlinux.org/other/aufs2/aufs2-${version}.tar.bz2"
build_style=custom-install
short_desc="Another UnionFS Implementation for the Linux kernel"
maintainer="Juan RP <xtraeme@gmail.com>"
checksum=76725760e5d44727f861a14cfe53f7749df911b0fe1110f72585eabe8fa7983b
long_desc="
 This packages provides the kernel module for aufs2, another unionfs
 implementation for the Linux kernel."

Add_dependency run	kernel		"-2.6.31.2_1"
Add_dependency build	kernel-headers	"-2.6.31.2_1"

do_install()
{
	local _kver kver inot64

	cd ${wrksrc} || return 1
	sed -i  -e 's|CONFIG_AUFS_HINOTIFY =.*|CONFIG_AUFS_HINOTIFY = y|' \
		-e 's|CONFIG_AUFS_EXPORT =.*|CONFIG_AUFS_EXPORT = y|' \
		-e 's|CONFIG_AUFS_SHWH =.*|CONFIG_AUFS_SHWH = y|' \
		-e 's|CONFIG_AUFS_BDEV_LOOP =.*|CONFIG_AUFS_BDEV_LOOP = y|' \
		-e 's|CONFIG_AUFS_BR_RAMFS =.*|CONFIG_AUFS_BR_RAMFS = y|' \
		-e 's|CONFIG_AUFS_DEBUG =.*|CONFIG_AUFS_DEBUG =|' \
		config.mk || return 1
	[ "${xbps_machine}" = "x86_64" ] && inot64="y"
	sed -i "s|CONFIG_AUFS_INO_T_64 =.*|CONFIG_AUFS_INO_T_64 =${inot64}|" \
		config.mk || return 1

	_kver=$(basename /usr/src/kernel-headers*)
	kver=$(${XBPS_PKGDB_CMD} getpkgversion ${_kver})
	make KDIR=/usr/src/kernel-headers-${kver} || return 1
	install -D -m644 fs/aufs/aufs.ko \
		${DESTDIR}/lib/modules/${kver}/kernel/fs/aufs/aufs.ko \
		|| return 1
	install -D -m 644 include/linux/aufs_type.h \
		${DESTDIR}/usr/src/kernel-headers-${kver}/include/linux/aufs_type.h
}
