SUMMARY="A sound processing language and software synthesizer"
DESCRIPTION="Csound is a user-programmable and user-extensible sound processing \
language and software synthesizer. It is not restricted to any style of music, \
having been used for many years in at least classical, pop, techno, and ambient."
HOMEPAGE="https://github.com/csound/csound"
COPYRIGHT="1991 Barry L. Vercoe
	1991-2019 The Csound Developers"
LICENSE="GNU LGPL v2.1"
REVISION="3"
SOURCE_URI="$HOMEPAGE/archive/$portVersion.tar.gz"
CHECKSUM_SHA256="183beeb3b720bfeab6cc8af12fbec0bf9fef2727684ac79289fd12d0dfee728b"
SOURCE_FILENAME="csound-$portVersion.tar.gz"
PATCHES="csound-$portVersion.patchset"

ARCHITECTURES="all !x86_gcc2"
SECONDARY_ARCHITECTURES="x86"

GLOBAL_WRITABLE_FILES="
	non-packaged/lib/python2.7/site-packages directory keep-old
	"

libVersion="6.0"
libVersionCompat="$libVersion compat >= ${libVersion%%.*}"

PROVIDES="
	csound$secondaryArchSuffix = $portVersion
	cmd:atsa
	cmd:cs
	cmd:csanalyze
	cmd:csb64enc
	cmd:csbeats
	cmd:csdebugger
	cmd:csound
	cmd:cvanal
	cmd:dnoise
	cmd:envext
	cmd:extract
	cmd:extractor
	cmd:het_export
	cmd:het_import
	cmd:hetro
	cmd:lpanal
	cmd:lpc_export
	cmd:lpc_import
	cmd:makecsd
	cmd:mixer
	cmd:pv_export
	cmd:pv_import
	cmd:pvanal
	cmd:pvlook
	cmd:scale
	cmd:scot
	cmd:scsort
	cmd:sdif2ad
	cmd:sndinfo
	cmd:src_conv
	cmd:srconv
	lib:libcsnd6$secondaryArchSuffix = $libVersionCompat
	lib:libcsound64$secondaryArchSuffix = $libVersionCompat
	lib:luaCsnd6$secondaryArchSuffix
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libcurl$secondaryArchSuffix
	lib:libfluidsynth$secondaryArchSuffix
	lib:libhdf5$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:liblo$secondaryArchSuffix
	lib:liblua$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libsamplerate$secondaryArchSuffix
	lib:libsndfile$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

PROVIDES_devel="
	csound${secondaryArchSuffix}_devel = $portVersion
	devel:libcsnd6$secondaryArchSuffix = $libVersionCompat
	devel:libcsound64$secondaryArchSuffix = $libVersionCompat
	devel:luaCsnd6$secondaryArchSuffix
	"
REQUIRES_devel="
	csound$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libcurl$secondaryArchSuffix
	devel:libfluidsynth$secondaryArchSuffix
	devel:libhdf5$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	devel:liblo$secondaryArchSuffix
	devel:liblua$secondaryArchSuffix >= 5.1
	devel:libpng16$secondaryArchSuffix
	devel:libsamplerate$secondaryArchSuffix
	devel:libsndfile$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:bison
	cmd:cmake
	cmd:flex
	cmd:gcc$secondaryArchSuffix
	cmd:git
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:python2.7
	cmd:swig
	"

PYTHON_VERSION=2.7

defineDebugInfoPackage csound$secondaryArchSuffix \
	$libDir/luaCsnd6.so

BUILD()
{
	mkdir -p build && cd build
	cmake .. \
		-DCMAKE_BUILD_TYPE="Release" \
		-DCMAKE_INSTALL_PREFIX=$prefix \
		-DCMAKE_INSTALL_BINDIR=$prefix/bin \
		-DCMAKE_INSTALL_LIBDIR=$libDir \
		-DCMAKE_INSTALL_LOCALEDIR=$dataDir/locale \
		-DCMAKE_INSTALL_INCLUDEDIR=$includeDir \
		-DCMAKE_INSTALL_MODULEDIR=$dataDir/cmake/Modules/Csound \
		-DPYTHON_MODULE_INSTALL_DIR="$prefix/non-packaged/lib/python$PYTHON_VERSION/site-packages"
	make $jobArgs
}

INSTALL()
{
	cd build
	make install

	prepareInstalledDevelLibs libcsnd6 libcsound64 luaCsnd6

	packageEntries devel \
		$developDir \
		$dataDir/cmake
}
