SUMMARY="Astronomical World Coordinate System transformations library"
DESCRIPTION="WCSLIB is a C library, supplied with a full set of Fortran wrappers, \
that implements the World Coordinate System (WCS) convention in FITS \
(Flexible Image Transport System). Since PGPLOT is not yet available on Haiku, \
this package doesn't include PGBOX (routines for drawing general curvilinear \
coordinate graticules) and related utilities."
HOMEPAGE="https://www.atnf.csiro.au/people/mcalabre/WCS/"
COPYRIGHT="1995-2020 Mark Calabretta - Australia Telescope National Facility, CSIRO."
LICENSE="GNU GPL v3"
REVISION="2"
SOURCE_URI="ftp://ftp.atnf.csiro.au/pub/software/wcslib/wcslib-$portVersion.tar.bz2"
CHECKSUM_SHA256="63959eb4859517a1ecca48c91542318bebeed62e4a1663656de9a983af376e39"
PATCHES="wcslib-$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

portVersionCompat="$portVersion compat >= 7.1"
libVersion="$portVersion"
libVersionCompat="$libVersion compat >= ${libVersion%%.*}"

PROVIDES="
	wcslib$secondaryArchSuffix = $portVersionCompat
	lib:libwcs$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libcfitsio$secondaryArchSuffix
	lib:libgfortran$secondaryArchSuffix
	"

PROVIDES_devel="
	wcslib${secondaryArchSuffix}_devel = $portVersionCompat
	devel:libwcs$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	wcslib$secondaryArchSuffix == $portVersion base
	haiku$secondaryArchSuffix
	lib:libcfitsio$secondaryArchSuffix
	lib:libgfortran$secondaryArchSuffix
	"

PROVIDES_utils="
	wcslib${secondaryArchSuffix}_utils = $portVersion
	cmd:hpxcvt$commandSuffix = $portVersionCompat
	cmd:fitshdr$commandSuffix = $portVersionCompat
	cmd:wcsware$commandSuffix = $portVersionCompat
	"
REQUIRES_utils="
	wcslib$secondaryArchSuffix == $portVersion base
	haiku$secondaryArchSuffix
	lib:libcfitsio$secondaryArchSuffix
	lib:libgfortran$secondaryArchSuffix
	lib:libquadmath$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libcfitsio$secondaryArchSuffix
	devel:libgfortran$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoreconf
	cmd:awk
	cmd:gcc$secondaryArchSuffix
	cmd:gfortran$secondaryArchSuffix
	cmd:make
	cmd:xargs
"

defineDebugInfoPackage wcslib$secondaryArchSuffix \
	"$libDir"/libwcs.so.$libVersion

BUILD()
{
	autoreconf -vfi
	runConfigure --omit-dirs binDir ./configure \
		--bindir="$commandBinDir" \
		--with-cfitsiolib=`finddir B_SYSTEM_LIB_DIRECTORY`${secondaryArchSubDir}  \
		--with-cfitsioinc=`finddir B_SYSTEM_HEADERS_DIRECTORY`${secondaryArchSubDir}  \
		--without-pgplot \
		--enable-fortran

	make $jobArgs
}

INSTALL()
{
	make install

	rm -f $libDir/libwcs-7.2.a

	prepareInstalledDevelLib libwcs
	fixPkgconfig

	# devel package
	packageEntries devel \
		$docDir \
		$developDir

	# utils package
	packageEntries utils \
		$commandBinDir \
		$manDir
}

TEST()
{
	make check $jobArgs
}
