# SliTaz package receipt.

PACKED_SIZE="276.0K"
UNPACKED_SIZE="856.0K"
PACKAGE="cdrkit"
VERSION="1.1.11"
CATEGORY="utilities"
SHORT_DESC="Wodim for recording/blanking CDs/DVDs and genisoimage for ISO."
MAINTAINER="pankso@slitaz.org"
HOST_ARCH="i486 x86_64"
LICENSE="GPL2"
TARBALL="$PACKAGE-$VERSION.tar.gz"
WEB_SITE="https://web.archive.org/web/20140714024716/http://www.cdrkit.org/"
WGET_URL="https://github.com/Distrotech/cdrkit/archive/refs/tags/release_$VERSION.tar.gz"
EXTRA_SOURCE_FILES="cdrkit-1.1.9-efi-boot.patch"
DEPENDS="libcap zlib bzlib attr"
BUILD_DEPENDS="cmake libcap-dev zlib-dev bzip2-dev attr-dev"

current_version()
{
	wget -O - $WEB_SITE 2>/dev/null | \
	sed '/released/!d;s|Cdrkit ||;s| has.*||;q'
}

# Rules to configure and make the package.
compile_rules()
{
	sed -i -e '/USE_MAGIC/d' -e '/(MAGICLIBS magic)/d' \
		genisoimage/CMakeLists.txt
	# CMake 4.x requires cmake_minimum_required at the top of every CMakeLists.txt
	for cml in $(find . -name CMakeLists.txt); do
		grep -qi "cmake_minimum_required" "$cml" || \
			sed -i '1i cmake_minimum_required(VERSION 3.5)' "$cml"
	done
	[ -s $SOURCES_REPOSITORY/cdrkit-1.1.9-efi-boot.patch ] ||
		wget -P $SOURCES_REPOSITORY https://raw.githubusercontent.com/NixOS/nixpkgs/nixos-23.05/pkgs/tools/cd-dvd/cdrkit/cdrkit-1.1.9-efi-boot.patch
	patch -p1 < $SOURCES_REPOSITORY/cdrkit-1.1.9-efi-boot.patch
	patch -p1 < $stuff/cdrkit-1.1.9-sort-catalog.patch
	# Only apply the gcc10 -fno-common patch when present (not needed on GCC < 10)
	[ -f $stuff/cdrkit-1.1.11-gcc10.patch ] && \
		patch -p1 < $stuff/cdrkit-1.1.11-gcc10.patch
	make PREFIX=/usr && make install PREFIX=/usr
}

# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{
	mkdir -p $fs/usr/bin $install/usr/share/
	cp $install/usr/bin/genisoimage $fs/usr/bin
	cp $install/usr/bin/wodim $fs/usr/bin	
	# Make symlinks for cdrtools compatibility
	cd $fs/usr/bin
	ln -s wodim cdrecord
	ln -s genisoimage mkisofs
	ln -s genisoimage mkhybrid
	cp -a $src/doc $install/usr/share
	cp $src/FORK $src/FAQ $src/ABOUT $install/usr/share/doc
}
