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-2018 The Csound Developers"
LICENSE="GNU LGPL v2.1"
REVISION="4"
SOURCE_URI="$HOMEPAGE/archive/$portVersion.tar.gz"
CHECKSUM_SHA256="39f4872b896eb1cbbf596fcacc0f2122fd3e5ebbb5cec14a81b4207d6b8630ff"
SOURCE_DIR="csound-$portVersion"
PATCHES="csound-$portVersion.patchset"

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

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:libluajit_5.1$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
	boost169${secondaryArchSuffix}_devel
	devel:libcurl$secondaryArchSuffix
	devel:libfluidsynth$secondaryArchSuffix
	devel:libhdf5$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	devel:liblo$secondaryArchSuffix
	devel:liblua$secondaryArchSuffix >= 5.1
	devel:libluajit_5.1$secondaryArchSuffix
	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:python
	cmd:swig
	"

defineDebugInfoPackage csound$secondaryArchSuffix \
	$libDir/luaCsnd6.so

BUILD()
{
	mkdir -p build
	cd build
	cmake -DCMAKE_INSTALL_PREFIX=$prefix ..\
		-DLUAJIT_INCLUDE_DIR="-I$(finddir B_SYSTEM_HEADERS_DIRECTORY)$secondaryArchSubDir" \
		-DLUAJIT_LIBRARY="$(finddir B_SYSTEM_DEVELOP_DIRECTORY)/lib$secondaryArchSubDir/libluajit-5.1.a" \
		-DLUA_H_PATH="-I$(finddir B_SYSTEM_HEADERS_DIRECTORY)$secondaryArchSubDir/lua5.1"
	make $jobArgs
}

INSTALL()
{
	cd build
	make install
	mkdir -p $includeDir
	mv $prefix/include/* $includeDir
	rm -r $prefix/include
	mv $prefix/lib $prefix/lib2
	mkdir -p $libDir/csound
	mv $prefix/lib2/* $libDir
	rm -rf $prefix/lib2
	mkdir -p $libDir/cmake/Csound
	cp -r $prefix/share/cmake/Csound/* $libDir/cmake/Csound
	rm -rf $prefix/share

	prepareInstalledDevelLibs libcsnd6 libcsound64 luaCsnd6
	fixPkgconfig

	packageEntries devel \
		$developDir \
		$libDir/cmake
}
