SUMMARY="A highly portable CD/DVD/BluRay command line recording software"
DESCRIPTION="
Cdrtools is a set of command line programs that allows to record CD/DVD/BluRay \
media.
The suite includes the following programs:
- cdrecord  A CD/DVD/BD recording program 
- readcd    A program to read CD/DVD/BD media with CD-clone features 
- cdda2wav  The most evolved CD-audio extraction program with paranoia support 
- mkisofs   A program to create hybrid ISO9660/JOLIET/HFS filesystes with \
optional Rock Ridge attributes 
- isodebug  A program to print mkisofs debug information from media 
- isodump   A program to dump ISO-9660 media 
- isoinfo   A program to analyse/verify ISO/9660/Joliet/Rock-Ridge Filesystems 
- isovfy    A program to verify the ISO-9660 structures 
- rscsi     A Remote SCSI enabling daemon
"
HOMEPAGE="http://cdrecord.berlios.de" 
COPYRIGHT="
	1993-1997 Eric Youngdale, 1997-2010 J. Schilling (mkisofs)
	1995-2013 J. Schilling (cdrecord)
	"
LICENSE="
	GNU GPL v2
	CDDL v1
	"
SRC_URI="ftp://ftp.berlios.de/pub/cdrecord/alpha/cdrtools-3.01a18.tar.bz2"
CHECKSUM_SHA256="7e9ad9e00679bb0c0456455243eb41614a5a3395eebded9371a0c843dd3494d6"
REVISION="1"
ARCHITECTURES="x86_gcc2 x86"

PATCHES='cdrtools-3.01~a18.patch'

PROVIDES="
	cdrtools = $portVersion compat >= 3
	cmd:devdump = $portVersion compat >= 3
	cmd:rscsi = $portVersion compat >= 3
	cmd:scgcheck = $portVersion compat >= 3
	cmd:mkisofs = $portVersion compat >= 3
	cmd:btcflash = $portVersion compat >= 3
	cmd:scgskeleton = $portVersion compat >= 3
	cmd:isovfy = $portVersion compat >= 3
	cmd:readcd = $portVersion compat >= 3
	cmd:isodebug = $portVersion compat >= 3
	cmd:cdda2mp3 = $portVersion compat >= 3
	cmd:cdda2ogg = $portVersion compat >= 3
	cmd:cdda2wav = $portVersion compat >= 3
	cmd:mkhybrid = $portVersion compat >= 3
	cmd:cdrecord = $portVersion compat >= 3
	cmd:isodump = $portVersion compat >= 3
	cmd:isoinfo = $portVersion compat >= 3
	"
REQUIRES="
	haiku >= $haikuVersion
	"
BUILD_REQUIRES="
	"
BUILD_PREREQUIRES="
	haiku_devel >= $haikuVersion
	cmd:gcc
	cmd:ld
	cmd:make
	cmd:sed
	"

GLOBAL_WRITABLE_FILES="
	settings/cdrecord keep-old
	settings/rscsi keep-old
	"

SOURCE_DIR="cdrtools-3.01"

patchInsdir()
{
	# Usage: patchInsdir <oldDir> <newDir> <file> ...
	oldDir=$1
	newDir=$2
	shift 2

	sed -i "s,^INSDIR=\s*$oldDir,INSDIR= $newDir," $@
}

PATCH()
{
	allMakefiles="$(find . -name Makefile\*) $(find . -name \*.mk)"

	patchInsdir bin $relativeBinDir $allMakefiles
	patchInsdir sbin $relativeBinDir $allMakefiles
	patchInsdir share/doc $relativeDocDir $allMakefiles
	patchInsdir include $relativeIncludeDir $allMakefiles
	patchInsdir lib $relativeLibDir $allMakefiles
	patchInsdir etc/default settings $allMakefiles

	sed -i "s,/etc/default,$sysconfDir," \
		btcflash/btcflash.1 \
		cdda2wav/cdda2mp3 \
		cdda2wav/cdda2ogg \
		cdda2wav/cdda2*.1 \
		cdrecord/COPYING \
		cdrecord/README.* \
		cdrecord/auinfo.c \
		cdrecord/cdrecord.1 \
		doc/*.man \
		doc/*.ps \
		include/schily/deflts.h \
		libcdrdeflt/cdrdeflt.c \
		libcdrdeflt/cdrdeflt.h \
		mkisofs/diag/isoinfo.8 \
		readcd/readcd.1 \
		rscsi/rscsi.1 \
		rscsi/rscsi.c \
		scgskeleton/scgskeleton.1
}

BUILD()
{
	make GMAKE_NOWARN=true INS_BASE=$prefix INS_RBASE=$prefix LDPATH="" \
		RUNPATH="" DEFMANBASE=$relativeDocumentationDir
		# not multi-job safe
}

INSTALL()
{
	make GMAKE_NOWARN=true INS_BASE=$prefix INS_RBASE=$prefix LDPATH="" \
		RUNPATH="" DEFMANBASE=$relativeDocumentationDir install

	# The whole lib folder only contains static libraries (even in several
	# subdirectories).
	mkdir -p $developLibDir
	mv $libDir/* $developLibDir/
	rmdir $libDir

	# devel package
	packageEntries devel \
		$developDir
}

# ----- devel package -------------------------------------------------------

PROVIDES_devel="
	cdrtools_devel = $portVersion
	devel:libcdrdeflt = $portVersion compat >= 3
	devel:libedc_ecc = $portVersion compat >= 3
	devel:libedc_ecc_dec = $portVersion compat >= 3
	devel:libdeflt = $portVersion compat >= 3
	devel:libfile = $portVersion compat >= 3
	devel:libfind = $portVersion compat >= 3
	devel:libhfs = $portVersion compat >= 3
	devel:libmdigest = $portVersion compat >= 3
	devel:libparanoia = $portVersion compat >= 3
	devel:librscg = $portVersion compat >= 3
	devel:libscg = $portVersion compat >= 3
	devel:libsiconv = $portVersion compat >= 3
	devel:libscgcmd = $portVersion compat >= 3
	devel:libschily = $portVersion compat >= 3
	"
REQUIRES_devel="
	cdrtools == $portVersion
	"
