#!/bin/bash
#
# Recompile both libnftnl and nftables so that nft does not use the host
# libnftnl anymore.

LIBNFTNL_PATH=/home/$USER/git/libnftnl

cd "$(dirname $0)"

# first libnftnl build
cd $LIBNFTNL_PATH
rm -rf install
./autogen.sh
./configure --enable-static --prefix="$PWD/install" || {
	echo "libnftnl: configure failed"
	exit 1
}
make clean
make || { echo "libnftnl: make failed"; exit 2; }
make install || { echo "libnftnl: make install failed"; exit 3; }
cd -

# now build nftables and link against static libnftnl
./autogen.sh
./configure --enable-static --enable-shared --with-json --with-xtables \
	--prefix="$PWD/install" \
	PKG_CONFIG_PATH="${LIBNFTNL_PATH}/install/lib/pkgconfig"
#	CFLAGS="-fprofile-arcs -ftest-coverage"
[[ $? -eq 0 ]] || { echo "nftables: configure failed"; exit 4; }
make clean
make V=1 || { echo "nftables: make failed"; exit 5; }
make install || { echo "nftables: make install failed"; exit 6; }
