# Template file for 'cdrtools'
pkgname=cdrtools
version=3.02a09
revision=3
build_helper=qemu
hostmakedepends="smake"
makedepends="acl-devel libcap-devel e2fsprogs-devel"
depends="libcap-progs"
conf_files="/etc/default/rscsi /etc/default/cdrecord"
short_desc="Highly portable CD/DVD/BluRay command line recording software"
maintainer="Orphaned <orphan@voidlinux.org>"
license="CDDL-1.0"
homepage="http://cdrtools.sourceforge.net/private/cdrecord.html"
distfiles="${SOURCEFORGE_SITE}/${pkgname}/${pkgname}-${version}.tar.bz2"
checksum=aa28438f458ef3f314b79f2029db27679dae1d5ffe1569b6de57742511915e81

if [ "$CROSS_BUILD" ]; then
	export CONFIG_RMTCALL="qemu-$XBPS_TARGET_QEMU_MACHINE-static"
	export CONFIG_RMTHOST=non-exist
fi

do_build() {
	mkdir -p xinclude/linux
	for _file in "$XBPS_CROSS_BASE"/usr/include/ext2fs/*; do
		ln -sf "$_file" xinclude/linux
	done
	CPPFLAGS+=" -I$wrksrc/xinclude"
	CFLAGS+=" -I$wrksrc/xinclude"
	sed -i 's|/opt/schily|/usr|g' DEFAULTS/Defaults.linux
	sed -i 's|DEFINSGRP=.*|DEFINSGRP=root|' DEFAULTS/Defaults.linux

	sed -i 's|INSDIR=.*|INSDIR=bin|' rscsi/Makefile
	smake CC="$CC" COPTX="$CFLAGS" LDOPTX="$LDFLAGS" RUNPATH= LDPATH= NOWARN=1
}
do_install() {
	CPPFLAGS+=" -I$wrksrc/xinclude"
	CFLAGS+=" -I$wrksrc/xinclude"
	smake \
		CC="$CC" COPTX="$CFLAGS" LDOPTX="$LDFLAGS" \
		RUNPATH= LDPATH= NOWARN=1 \
		INS_BASE=/usr MANDIR=/man DESTDIR=${DESTDIR} \
		install
	# Remove useless stuff
	rm -rf ${DESTDIR}/usr/include
	rm -rf ${DESTDIR}/usr/lib/lib* ${DESTDIR}/usr/lib/profiled
	rm -rf ${DESTDIR}/usr/share/man/man3 ${DESTDIR}/usr/share/man/man5
	vmkdir usr/lib/modules-load.d
	echo sg > ${DESTDIR}/usr/lib/modules-load.d/cdrtools.conf
}
