# Contributor: Andrew Manison <amanison@anselsystems.com>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=ebtables
pkgver=2.0.10.4
_realver=v${pkgver%.[0-9]}-${pkgver##*.}
pkgrel=2
pkgdesc="Ethernet bridge tables - Linux Ethernet filter for the Linux bridge."
url="http://ebtables.sourceforge.net/"
arch="all"
license="GPL"
depends=
makedepends="linux-headers"
install=
subpackages="$pkgname-doc"
source="http://downloads.sourceforge.net/$pkgname/$pkgname-$_realver.tar.gz
	ebtables.initd
	ebtables.confd
	musl-fixes.patch
	fix-extension-init.patch
	"

prepare() {
	cd "$srcdir"/$pkgname-$_realver
	# patches
	for i in $source; do
		case "$i" in
		*.patch) msg $i; patch -p1 -i "$srcdir"/$i || return 1;;
		esac
	done
	sed -i -e "s,^MANDIR:=.*,MANDIR:=/usr/share/man," \
		-e "s,^BINDIR:=.*,BINDIR:=/sbin," \
		-e "s,^INITDIR:=.*,INITDIR:=/usr/share/doc/ebtables," \
		-e "s,^SYSCONFIGDIR:=.*,SYSCONFIGDIR:=/usr/share/doc/ebtables,"\
		-e "s,^LIBDIR:=.*,LIBDIR:=/usr/lib/\$(PROGNAME)," \
		-e "s/^CFLAGS:=/CFLAGS?=/" \
		-e "s,^CC:=,CC?=," Makefile
}

build() {
	cd "$srcdir"/$pkgname-$_realver

	# This package uses _init functions to initialise extensions. With
	# --as-needed this will not work.
	export LDFLAGS="$LDFLAGS -Wl,--no-as-needed"
	make CFLAGS="$CFLAGS" || return 1
}

package() {
	cd "$srcdir"/$pkgname-$_realver
	make DESTDIR="$pkgdir" install
	install -D -m755 ../ebtables.initd "$pkgdir"/etc/init.d/ebtables
	install -D -m644 ../ebtables.confd "$pkgdir"/etc/conf.d/ebtables
}

md5sums="506742a3d44b9925955425a659c1a8d0  ebtables-v2.0.10-4.tar.gz
197852fae4bbac2fe75f81b36b6af852  ebtables.initd
285089ba2d846e72e321a12e3da3cc96  ebtables.confd
d443749e0a7bf542baec328b4520b36b  musl-fixes.patch
9b7470d60e7496e898428724e8fe653a  fix-extension-init.patch"
sha256sums="dc6f7b484f207dc712bfca81645f45120cb6aee3380e77a1771e9c34a9a4455d  ebtables-v2.0.10-4.tar.gz
893615d9f18eedd8e6d30252d6545b4ecaeca3f44219768f39c576ca949ec59a  ebtables.initd
fa8dedd95f1a6834022e409754e1e41219a7671a1bbb99b2094356239135730d  ebtables.confd
5d2cefaa945acce3fbe19568002a26b405d7d91cb213655b5db38ca90ad73919  musl-fixes.patch
dda93ff229e921d91efecb8667ed7dde2359fe5f13060fcd863a4acc54f7c750  fix-extension-init.patch"
sha512sums="a6832453812eaede3fcbb5b4cab5902ea1ea752a80a259eed276a01b61e2afaa6cf07d3d023d86a883f9a02505aecc44a1c6e0d27b3a61f341002e4c051cd60a  ebtables-v2.0.10-4.tar.gz
c8fccc96610ddc24a3a0c7c2c9f2460b87e582424e338beeb20d77726b27324f89906ef853680e62912ed3544c967469870d78aa6e39de11efda072dd8a4a836  ebtables.initd
b24afd1f5c2f200a1eec6ed7fd63500237dc168bfb9cc1297ffc288d12d30224a1ee84a7f61663daf408c42457dd7deac7594a23e448218806798294e9a1018d  ebtables.confd
d72e606381a8790a11228a7cf25fd5acfeb036742ca8dbc8603d3b7baec7cc77846c2fe4b4cde698fb1bd8f272cd5d2e260db4363f2e3e69f29a88c95e156608  musl-fixes.patch
d43ee171000c4a41063ba82a3659b0624654075d961711df45071a551a1e83f6aa3f51b4d537dc8c3b8001447fc8d6a6aeddf55569839c364c4c8471198b9383  fix-extension-init.patch"
