NAME="cdrtools"
DESC="CD recording utilities, useful for reading, creating or writing (burning) CDs, DVDs, and Blu-ray discs"
VERSION="3.02a09"
FILES=("https://downloads.sourceforge.net/cdrtools/cdrtools-${VERSION}.tar.bz2")
HASHES=("1e224a6adbbe4ad40047b9fddbb0e60c")
DEPENDS=()

PACKAGE() {
  tar xf "${NAME}-${VERSION}.tar.bz2"
  cd "${NAME}-${VERSION%a*}"

  sed -i 's|/opt/schily|/usr|g' DEFAULTS/Defaults.linux
  sed -i 's|DEFINSGRP=.*|DEFINSGRP=root|' DEFAULTS/Defaults.linux
  sed -i 's|INSDIR=\s*sbin|INSDIR=bin|' rscsi/Makefile
	rm -rfv cdda2wav # this is broken

  export GMAKE_NOWARN=true
  export CFLAGS="${CFLAGS} -std=gnu89 -fno-strict-aliasing"
  make INS_BASE=/usr INS_RBASE=/ LDOPTX="${LDFLAGS}"
  make INS_BASE=/usr INS_RBASE=/ DESTDIR="${ROOTDIR}" install

  rm "${ROOTDIR}/usr/lib/"*.a
  rm -r "${ROOTDIR}/usr/lib/profiled"
  rm -r "${ROOTDIR}/usr/include"
  rm -r "${ROOTDIR}/usr/share/man/man3"

  echo sg | install -vDm644 /dev/stdin "${ROOTDIR}/usr/lib/modules-load.d/cdrecord.conf"

  chmod a+rx "${ROOTDIR}/usr/bin/"*

  ln -s /usr/bin/cdrecord "${ROOTDIR}/usr/bin/wodim"
  ln -s /usr/bin/readcd "${ROOTDIR}/usr/bin/readom"
  ln -s /usr/bin/mkisofs "${ROOTDIR}/usr/bin/genisoimage"
  ln -s /usr/bin/cdda2wav "${ROOTDIR}/usr/bin/icedax"

  cd .. && rm -r "${NAME}-${VERSION%a*}"
}
