SUMMARY="C++ Wrappers for the cfitsio library"
DESCRIPTION="CCfits is an object oriented interface to the cfitsio library. \
It is designed to make the capabilities of cfitsio available to programmers \
working in C++. It is written in ANSI C++ and implemented \
using the C++ Standard Library with namespaces, exception handling, \
and member template functions."
HOMEPAGE="https://heasarc.gsfc.nasa.gov/fitsio/CCfits"
COPYRIGHT="2002-2019 Ben Dorman, Craig Gordon, Bryan Irby - HEASARC, NASA/GSFC"
LICENSE="CCFITS"
REVISION="2"
SOURCE_URI="https://heasarc.gsfc.nasa.gov/fitsio/CCfits/CCfits-$portVersion.tar.gz"
CHECKSUM_SHA256="938ecd25239e65f519b8d2b50702416edc723de5f0a5387cceea8c4004a44740"
SOURCE_DIR="CCfits"
PATCHES="ccfits-$portVersion.patchset"

ARCHITECTURES="all !x86_gcc2 ?arm ?ppc ?sparc"
SECONDARY_ARCHITECTURES="x86"

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

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

PROVIDES="
	ccfits$secondaryArchSuffix = $portVersion compat >= 2.5
	lib:libccfits$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libcfitsio$secondaryArchSuffix
	"

PROVIDES_devel="
	ccfits${secondaryArchSuffix}_devel = $portVersion
	devel:libCCfits$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	ccfits$secondaryArchSuffix == $portVersion base
	devel:libcfitsio$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libcfitsio$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:automake
	cmd:awk
	cmd:gcc$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	"

TEST_REQUIRES="
	cmd:test
	"

defineDebugInfoPackage ccfits$secondaryArchSuffix \
	"$libDir"/libCCfits.so.$libVersion

PATCH()
{
	mv configure.in configure.ac || true
}

BUILD()
{
	if [ "$effectiveTargetArchitecture" != x86_gcc2 ]; then
		export CXXFLAGS="-Wno-catch-value"
	fi

	libtoolize --force --copy --install
	aclocal -I m4 -I config/m4 --force --install
	autoconf --force
	automake --add-missing --force-missing
	runConfigure --omit-dirs binDir ./configure \
		--bindir="$commandBinDir" \
		--with-cfitsio-libdir=`finddir B_SYSTEM_LIB_DIRECTORY`${secondaryArchSubDir} \
		--with-cfitsio-include=`finddir B_SYSTEM_HEADERS_DIRECTORY`${secondaryArchSubDir}

	make $jobArgs
}

INSTALL()
{
	make install

	rm -f $libDir/libCCfits.la

	prepareInstalledDevelLib libCCfits
	fixPkgconfig

	# copy pdf documentation
	mkdir -p $developDocDir
	cp -rd *.pdf $developDocDir

	# copy html documentation
	cp -rd html $developDocDir/

	# devel package
	packageEntries devel $developDir
}

TEST()
{
	make check $jobArgs
	cookbook 1>/dev/null

	declare -a testfiles=("atestfil" "btestfil" "ctestfil")
	for i in "${testfiles[@]}"
	do
		test -f ${i}.fit
	done
}
