# Contributor: Leo <thinkabit.ukim@gmail.com>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=libcorkipset
pkgver=1.1.1
_debver=20150311-8
pkgrel=4
pkgdesc="Small C helper library for storing sets of IPv4 and IPv6 addresses"
url="https://github.com/rogers0/libcorkipset"
arch="all"
license="BSD-3-Clause"
makedepends="cmake check-dev libcork-dev samurai"
checkdepends="python3"
subpackages="$pkgname-dev $pkgname-tools"
source="$pkgname-$pkgver.tar.gz::https://github.com/rogers0/$pkgname/archive/debian/$pkgver+$_debver.tar.gz
	fix-gcc-10.patch
	"
builddir="$srcdir/$pkgname-debian-$pkgver-$_debver"

prepare() {
	default_prepare

	for p in debian/patches/*.patch; do
		patch -p1 -i "$p"
	done

	sed -e 's%#include <ipset%#include <libcorkipset%' \
		-e 's%#include "ipset%#include "libcorkipset%' \
		-i include/ipset/*.h */*/*/*.c */*/*/*.c.in */*/*.c */*.c
	mv include/ipset include/libcorkipset
}

build() {
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DCMAKE_BUILD_TYPE=MinSizeRel
	cmake --build build
}

check() {
	cd build
	ninja test
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

tools() {
	pkgdesc="$pkgdesc (tools)"

	amove usr/bin
}

sha512sums="
5bbce2727da1665e734981959ecb253b4052d8cc6c426fded7e1678b6e2505bc9f4c0ab3cd3b6a03f834f5e20bd1d670cc19f7491fe0ad5b7cb772e7309f5009  libcorkipset-1.1.1.tar.gz
f0441ccc3800f450fa752ae4160dea0686fff2b5b255cfcb91bba8561301519fcc327125c2731ecbb909446ee6973c99d36d0d90f080bffd2d4a422f307e729d  fix-gcc-10.patch
"