# Contributor: Holger Jaekel <holger.jaekel@gmx.de>
# Maintainer: Holger Jaekel <holger.jaekel@gmx.de>
pkgname=ogdi
pkgver=4.1.1
_testver=3.1.0
pkgrel=1
pkgdesc="Open Geographic Datastore Interface Library"
url="https://ogdi.sourceforge.net/"
arch="all"
license="MIT"
depends_dev="libtirpc-dev"
makedepends="
	$depends_dev
	expat-dev
	tcl-dev
	zlib-dev
	"
subpackages="
	$pkgname-dev
	$pkgname-tcl
	"
source="https://github.com/libogdi/ogdi/releases/download/ogdi_${pkgver//./_}/ogdi-$pkgver.tar.gz
	https://downloads.sourceforge.net/project/ogdi/OGDI_Test_Suite/${_testver%.*}/ogdits-$_testver.tar.gz
	10-optimisation.patch
	20-external.patch
	30-format-security.patch
	gcc14.patch
	"

build() {
	export TOPDIR=$builddir TARGET=Linux LD_LIBRARY_PATH=$builddir/bin/Linux
	rm -r external
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--with-binconfigs \
		--with-zlib \
		--with-expat
	make -j1  # fails to find own libraries if built with more buildjobs

	# build tcl interface
	make -C ogdi/tcl_interface \
		TCL_LINKLIB="-ltcl8.6"

	# build contributions
	make -C contrib/gdal
}

check() {
	export TOPDIR=$builddir TARGET=Linux LD_LIBRARY_PATH=$builddir/bin/Linux PATH=$PATH:$builddir/bin/Linux
	ogdi_info -u gltp:/vrf/$srcdir/ogdits-${_testver%.*}/data/vpf/vm2alv2/texash | \
		grep "Projection = \`+proj=longlat +datum=wgs84'"
}

package() {
	export TOPDIR=$builddir TARGET=Linux
	make install \
		INST_INCLUDE=$pkgdir/usr/include/ogdi \
		INST_LIB=$pkgdir/usr/lib \
		INST_BIN=$pkgdir/usr/bin

	# install gdal contribution
	make install -C contrib/gdal \
		INST_LIB=$pkgdir/usr/lib

	# install pkgconfig file
	mkdir -p $pkgdir/usr/lib/pkgconfig
	install -p -m 644 ogdi.pc $pkgdir/usr/lib/pkgconfig
}

tcl() {
	pkgdesc="TCL wrapper for $pkgdesc"
	export TOPDIR=$builddir TARGET=Linux
	make install -C $builddir/ogdi/tcl_interface \
		INST_LIB=$subpkgdir/usr/lib
}

sha512sums="
ebd32fec2c83d49c998683c8701ab215e494a8ecba04877da7f7d4fd19594ff2d30831f2b580be3c7f95946f499763c8b7f7603c8df52b5bf7b3620fdf4eb5b0  ogdi-4.1.1.tar.gz
7fbd7c165466b6bf298d3d18b33c13b6f0166c3b1efe12b7c09e77539a20076950bc89db6c4e1e411ba374ebcf81744ec0410d3a414f395bd12339a7ae0e336b  ogdits-3.1.0.tar.gz
24682c9e893e410d08bfc0a1b06196e5d0555d4b552e07662ec26433e07f44a8f99686f79a1a5ed40de71f7da838516ffc33918837a6d79f35ab2a9b380f5592  10-optimisation.patch
fa54844a68a00633a3a36567ba9eaa5429533814028241be9697070fd933a94dc1f8a25c51a983c2c0a1c15858fa2259ed87975a3f233d124c525b5f877e4a0e  20-external.patch
e6fbf2207e2c6042929d38f19eb0d0b14544afd9be82172fe46366cd20de9ee02a2f652223aa81edb2af61d3743d8e88247c451ffd854490b953479a504bf550  30-format-security.patch
434f1d36d1c2e2350e80faf5e748c6822eadf1a7bf6d62780177959b7f2e95468756b82dbfadb3d9e389b8c9318e7385596f979acc6e7694a1c8efd24f7b8c38  gcc14.patch
"
