SUMMARY="Non-DNS IP-to-country resolver C library & utils"
DESCRIPTION="The GeoIP Legacy C library enables the user to find geographical \
and network information of an IP address. geoiplookup and geoiplookup6 will \
use any GeoIP Legacy databases available in /system/cache/GeoIP. Call
\"geoipupdate.sh -a\" after installation to download the GeoIP(v6), \
GeoLiteCity(v6) and GeoIPASNum(v6) free databases for the first time. Call \
\"geoipupdate.sh\" (without any argument) from time to time (e.g. once per \
month) to update them later. Another package, geoipupdate, may be used to \
download GeoLite Legacy, GeoLite2 and GeoIP2 databases from MaxMind."
HOMEPAGE="https://dev.maxmind.com/geoip/legacy/"
COPYRIGHT="2002-2018 MaxMind, Inc."
LICENSE="GNU LGPL v2.1"
REVISION="1"
SOURCE_URI="https://github.com/maxmind/geoip-api-c/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="99b119f8e21e94f1dfd6d49fbeed29a70df1544896e76cd456f25e397b07d476"
SOURCE_FILENAME="geoip-api-c-$portVersion.tar.gz"
SOURCE_DIR="geoip-api-c-$portVersion"
SOURCE_FILENAME_2="geoipupdate-r6.sh"
srcGitRev_2="f04629f7a52972218915225be56b063db14569a9"
SOURCE_URI_2="https://gitweb.gentoo.org/repo/gentoo.git/plain/dev-libs/geoip/files/$SOURCE_FILENAME_2?id=$srcGitRev_2#noarchive"
CHECKSUM_SHA256_2="daebeb831f1a70e0f926525cc755fc97296dded7d63dd7b267dd7556f12a3f28"
SOURCE_DIR_2=""
PATCHES="geoip-$portVersion.patchset"
PATCHES_2="geoipupdate-r6.patchset"

ARCHITECTURES="all"
SECONDARY_ARCHITECTURES="x86_gcc2 x86"

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

PROVIDES="
	geoip$secondaryArchSuffix = $portVersion
	lib:libGeoIP$secondaryArchSuffix = $libVersionCompat
	"
if [ -z "$secondaryArchSuffix" ]; then
	PROVIDES="$PROVIDES
		cmd:geoiplookup
		cmd:geoiplookup6
		cmd:geoipupdate.sh
		"
fi

REQUIRES="
	haiku$secondaryArchSuffix
	cmd:curl
	"

PROVIDES_devel="
	geoip${secondaryArchSuffix}_devel = $portVersion
	devel:libGeoIP$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	geoip$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:ar$secondaryArchSuffix
	cmd:autoconf
	cmd:autom4te
	cmd:automake
	cmd:make
	cmd:gcc$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	"

defineDebugInfoPackage geoip$secondaryArchSuffix \
	$libDir/libGeoIP.so.$libVersion

BUILD()
{
	aclocal
	libtoolize
	autoconf
	automake --add-missing
	runConfigure --omit-dirs dataDir ./configure \
		--datadir="`finddir B_SYSTEM_CACHE_DIRECTORY`"
	make $jobArgs
}

INSTALL()
{
	make install

	# remove libtool file
	rm -f $libDir/libGeoIP.la

	if [ -z "$secondaryArchSuffix" ]; then
		CACHE_DIR="`finddir B_SYSTEM_CACHE_DIRECTORY`"
		mkdir -p $binDir $prefix${CACHE_DIR#/boot/system}/GeoIP
		sed -e "s,^\(GEOIPDIR=\).*,\1${CACHE_DIR#/boot}/GeoIP," \
			$sourceDir2/$SOURCE_FILENAME_2 > $binDir/geoipupdate.sh
		chmod +x $binDir/geoipupdate.sh
	else
		rm -rf $binDir $documentationDir
	fi

	prepareInstalledDevelLib libGeoIP

	fixPkgconfig

	# devel package
	packageEntries devel \
		$developDir
}

TEST()
{
	make check
}
