#!/bin/sh -ue
NAME=libnl-tiny
VERSION=39ec78bb
RELEASE=1
SOURCE="https://github.com/sabotage-linux/libnl-tiny/archive/39ec78bb012edc2739c3d3d0058e4076411068b1.tar.gz"
BUILD_STYLE=gmake

build() {
	msg "applying patches..."
	patch -p1 < "$PORTDIR/patch/nla_s8.patch" || die "patch failed"

	msg "building libnl-tiny..."
	gmake \
		CC="${CC:-cc}" \
		CFLAGS="${CFLAGS:--O2}" \
		ALL_LIBS=libnl-tiny.a \
		PREFIX=/usr || die "gmake failed"

	msg "installing libnl-tiny..."
	gmake ALL_LIBS=libnl-tiny.a PREFIX=/usr install || true

	install -d "$PKG/$PREFIX/lib" "$PKG/$PREFIX/include"
	install -m 644 libnl-tiny.a "$PKG/$PREFIX/lib/libnl-3.a"
	ln -sf libnl-3.a "$PKG/$PREFIX/lib/libnl-genl-3.a"
	cp -r include/* "$PKG/$PREFIX/include/" || die "header install failed"

	install -d "$PKG/$PREFIX/lib/pkgconfig"
	cat > "$PKG/$PREFIX/lib/pkgconfig/libnl-3.0.pc" <<EOF
prefix=$PREFIX
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: libnl-3
Description: Minimal netlink library (libnl-tiny)
Version: 3.0
Libs: -L${libdir} -lnl-3
Cflags: -I${includedir}
EOF

	cat > "$PKG/$PREFIX/lib/pkgconfig/libnl-genl-3.0.pc" <<EOF
prefix=$PREFIX
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: libnl-genl-3
Description: Minimal netlink generic netlink library (libnl-tiny)
Version: 3.0
Requires: libnl-3
Libs: -L${libdir} -lnl-genl-3
Cflags: -I${includedir}
EOF
}
. ${0%/*}/../../libsh/libdmake.sh
