# SliTaz package receipt.

PACKAGE="module-init-tools"
VERSION="3.12"
CATEGORY="base-system"
SHORT_DESC="Kernel modules manipulation tools."
MAINTAINER="pascal.bellard@slitaz.org"
DEPENDS="glibc-base gcc-lib-base zlib lzlib depmod"
TARBALL="$PACKAGE-$VERSION.tar.gz"
WEB_SITE="http://ftp.kernel.org/pub/linux/utils/kernel/module-init-tools/"
WGET_URL="https://cdn.kernel.org/pub/linux/utils/kernel/module-init-tools/$TARBALL"
BUILD_DEPENDS="zlib-dev lzlib-dev lzlib"

# Rules to configure and make the package.
compile_rules()
{
	cd $src
	for patch_file in lzlib depmod; do
		if [ -f done.$patch_file ]; then
			echo "Skipping $patch_file"
			continue
		fi
		echo "Apply $patch_file.u"
		patch -p1 < $stuff/$patch_file.u || return 1
		touch done.$patch_file
	done

	# Don't generate manpages to avoid failure.
	echo '.so man5/modprobe.conf.5' > modprobe.d.5

	./configure --enable-zlib \
	--sbindir=/sbin --bindir=/bin --sysconfdir=/etc \
	$CONFIGURE_ARGS &&
	make &&	make install
}

# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{
	mkdir -p $fs/sbin $fs/etc
	cp $_pkg/sbin/insmod $fs/sbin
	cp $_pkg/sbin/modinfo $fs/sbin
	cp $_pkg/sbin/modprobe $fs/sbin
	cp $_pkg/sbin/rmmod $fs/sbin
	# lsmod goes in /bin.
	cp -a $_pkg/bin $fs
	# Create the modprobe config directory
	mkdir -p $fs/etc/modprobe.d
}

# Remove Busybox symlink before installing
pre_install()
{
	rm -f $1/sbin/insmod
	rm -f $1/sbin/modinfo
	rm -f $1/sbin/modprobe
	rm -f $1/sbin/rmmod
	# BusyBox puts lsmod in /sbin, not /bin
	rm -f $1/sbin/lsmod
}

post_remove()
{
	ln -s /bin/busybox $1/sbin/insmod
	ln -s /bin/busybox $1/sbin/modinfo
	ln -s /bin/busybox $1/sbin/modprobe
	ln -s /bin/busybox $1/sbin/rmmod
	# BusyBox puts lsmod in /sbin, not /bin
	ln -s /bin/busybox $1/sbin/lsmod
}