# Maintainer: Arthur Jones <arthur.jones@riverbed.com>
pkgname=frr
arch="all"
pkgver=@VERSION@
pkgrel=0
pkgdesc="FRRouting is a fork of quagga"
url="https://frrouting.org/"
license="GPL-2.0"
depends="json-c c-ares iproute2 python3 bash"
makedepends="ncurses-dev net-snmp-dev gawk texinfo perl
    acct autoconf automake bash binutils bison bsd-compat-headers build-base
    c-ares c-ares-dev ca-certificates cryptsetup-libs curl device-mapper-libs
    expat fakeroot flex fortify-headers gdbm git gmp json-c-dev kmod
    lddtree libacl libatomic libattr libblkid libburn libbz2 libc-dev
    libcap-dev libcurl libedit libffi libgcc libgomp libisoburn libisofs
    libltdl openssl libssh2 libstdc++ libtool libuuid
    linux-headers lzip lzo m4 make mkinitfs mpc1 mpfr4 mtools musl-dev
    ncurses-libs ncurses-terminfo ncurses-terminfo-base patch pax-utils pcre2
    perl pkgconf python3 python3-dev readline readline-dev sqlite-libs pcre2-dev
    squashfs-tools sudo tar texinfo xorriso xz-libs py-pip rtrlib rtrlib-dev
    py3-sphinx elfutils elfutils-dev protobuf-c-compiler protobuf-c-dev
    lua5.3-dev lua5.3 gzip"
checkdepends="pytest py-setuptools"
install="$pkgname.pre-install $pkgname.pre-deinstall $pkgname.post-deinstall"
subpackages="$pkgname-dev $pkgname-doc $pkgname-dbg"
source="$pkgname-$pkgver.tar.gz"

builddir="$srcdir"/$pkgname-$pkgver

_sysconfdir=/etc
_sbindir=/usr/lib/frr
_libdir=/usr/lib
_user=frr

build() {
	export ABUILD_APK_INDEX_OPTS="--allow-untrusted"

	cd "$builddir"

	./configure \
		--prefix=/usr \
		--sysconfdir=$_sysconfdir \
		--localstatedir=/var \
		--sbindir=$_sbindir \
		--libdir=$_libdir \
		--enable-rpki \
		--enable-vtysh \
		--enable-multipath=64 \
		--enable-vty-group=frrvty \
		--enable-user=$_user \
		--enable-group=$_user \
		--enable-pcre2posix \
		--enable-scripting
	make -j $(nproc)
}

check() {
	cd "$builddir"

	make -j 1 check
}

package() {
	cd "$builddir"
	make DESTDIR="$pkgdir" install

	install -d $pkgdir/$_sysconfdir/frr
	install -m 0644 tools/etc/frr/daemons $pkgdir/$_sysconfdir/frr/daemons

	install -d $pkgdir/$_sysconfdir/init.d
	ln -s ${_sbindir}/frr $pkgdir/$_sysconfdir/init.d/frr
}
