SUMMARY="A software implementation of the OpenAL 3D audio API"
DESCRIPTION="OpenAL stands for (Open Audio Library), a cross-platform audio application \
programming interface written in C. It is an environmental 3D audio \
library that aims to provide a replacement for proprietary 3D audio systems \
such as EAX and A3D. Openal is designed for efficient rendering of \
multichannel 3D positional audio."
HOMEPAGE="https://www.openal-soft.org/"
COPYRIGHT="1999-2000 Loki Software
	2005-2021 OpenAL Soft team"
LICENSE="GNU LGPL v2.1"
REVISION="5"
SOURCE_URI="https://github.com/kcat/openal-soft/archive/refs/tags/$portVersion.tar.gz"
CHECKSUM_SHA256="8ac17e4e3b32c1af3d5508acfffb838640669b4274606b7892aa796ca9d7467f"
SOURCE_DIR="openal-soft-$portVersion"
PATCHES="openal-$portVersion.patchset"
ADDITIONAL_FILES="openal.rdef.in"

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

commandBinDir=$binDir
commandSuffix=$secondaryArchSuffix
if [ "$targetArchitecture" = x86_gcc2 ]
then
	commandBinDir=$prefix/bin
	commandSuffix=
fi

PROVIDES="
	openal$secondaryArchSuffix = $portVersion compat >= 1
	lib:libopenal$secondaryArchSuffix = $portVersion compat >= 1
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libatomic$secondaryArchSuffix
	"

PROVIDES_devel="
	openal${secondaryArchSuffix}_devel = $portVersion compat >= 1
	devel:libopenal$secondaryArchSuffix = $portVersion compat >= 0
	"
REQUIRES_devel="
	haiku$secondaryArchSuffix
	lib:libopenal$secondaryArchSuffix == $portVersion base
	"

PROVIDES_tools="
	openal${secondaryArchSuffix}_tools = $portVersion
	cmd:alconvolve$commandSuffix
	cmd:alhrtf$commandSuffix
	cmd:allatency$commandSuffix
	cmd:alloopback$commandSuffix
	cmd:almultireverb$commandSuffix
	cmd:alplay$commandSuffix
	cmd:alrecord$commandSuffix
	cmd:alreverb$commandSuffix
	cmd:alsoft_config$commandSuffix
	cmd:alstream$commandSuffix
	cmd:alstreamcb$commandSuffix
	cmd:altonegen$commandSuffix
	cmd:makehrtf$commandSuffix
	cmd:openal_info$commandSuffix
	"

REQUIRES_tools="
	$REQUIRES
	lib:libopenal$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	lib:libsndfile$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	devel:libsndfile$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	mkdir -p build
	cd build
	cmake .. $cmakeDirArgs \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_BINDIR=$commandBinDir

	make $jobArgs
}

INSTALL()
{
	cd build
	make install

	prepareInstalledDevelLib libopenal
	fixPkgconfig

	local APP_SIGNATURE="application/x-vnd.openal-soft-configuration"
	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local MINOR="`echo "$portVersion" | cut -d. -f3`"
	local LONG_INFO="$SUMMARY"
	sed \
		-e "s|@APP_SIGNATURE@|$APP_SIGNATURE|" \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@MINOR@|$MINOR|" \
		-e "s|@LONG_INFO@|$LONG_INFO|" \
		$portDir/additional-files/openal.rdef.in > openal.rdef

	addResourcesToBinaries openal.rdef $commandBinDir/alsoft-config
	addPreferencesDeskbarSymlink $commandBinDir/alsoft-config "OpenAL Soft Configuration"

	# tools package
	packageEntries tools \
		$commandBinDir \
		$dataDir/deskbar

	# devel package
	packageEntries devel \
		$developDir \
		$libDir/cmake
}
