# Build template for 'kernel-uml'
pkgname=kernel-uml
version=3.10.30
revision=1
wrksrc=linux-${version}
hostmakedepends="perl bc"
makedepends="libpcap-devel uml-utilities"
depends="uml-utilities"
homepage="http://www.kernel.org"
license="GPL-2"
short_desc="Kernel ${version} for User Mode Linux"
distfiles="http://www.kernel.org/pub/linux/kernel/v3.x/linux-${version}.tar.xz"
checksum=150a05c96f9f00337d9bf14de0dfff4efe395c9b7776c189f1fb1901de113d29

case "$XBPS_TARGET_MACHINE" in
	i686*) _subarch="x86";;
	x86_64*) _subarch="x86_64";;
	*) msg_error "${pkgname}-${version} cannot be built for ${XBPS_TARGET_MACHINE}.\n";;
esac

do_configure() {
	if [ "$CROSS_BUILD" ]; then
		_args="CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-"
	fi
	make ${_args} ARCH=um SUBARCH=${_subarch} defconfig
}

do_build() {
	unset LDFLAGS
	if [ "$CROSS_BUILD" ]; then
		_args="CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-"
	fi
	make ${_args} ARCH=um SUBARCH=${_subarch} ${makejobs}
}

do_install() {
	vinstall linux 755 usr/bin
	make ARCH=um INSTALL_MOD_PATH=${DESTDIR}/usr/lib/uml modules_install
	rm -f ${DESTDIR}/usr/lib/uml/lib/modules/${version}/{build,source}
	mv ${DESTDIR}/usr/lib/uml/lib/modules ${DESTDIR}/usr/lib/uml
	rmdir ${DESTDIR}/usr/lib/uml/lib
}
