# Template file for 'iptables'
pkgname=iptables
version=1.4.12.1
homepage="http://www.iptables.org"
distfiles="$homepage/projects/iptables/files/$pkgname-$version.tar.bz2"
short_desc="Linux IPv[46] packet filtering ruleset"
maintainer="Juan RP <xtraeme@gmail.com>"
homepage="http://www.netfilter.org/"
license="GPL-2"
checksum=77e6581f21f15946a814fa311236e5f3f7c6593180f9d695cea06aa95e464aba
long_desc="
 iptables is the userspace command line program used to configure the Linux
 IPv4 packet filtering ruleset. It is targeted towards system administrators.

 Since Network Address Translation is also configured from the packet filter
 ruleset, iptables is used for this, too.

 The iptables package also includes ip6tables. ip6tables is used for
 configuring the IPv6 packet filter."

subpackages="$pkgname-devel"

Add_dependency build sed
Add_dependency build kernel-headers

do_configure() {
	sed -i '87 i libxt_RATEEST.so: libxt_RATEEST.oo' \
		extensions/GNUmakefile.in
	sed -i '88 i \\t${AM_VERBOSE_CCLD} ${CCLD} ${AM_LDFLAGS} -lm -shared ${LDFLAGS} -o $@ $<;\n' \
		extensions/GNUmakefile.in

	./configure ${CONFIGURE_SHARED_ARGS} --enable-devel --enable-libipq \
		--sbindir=/sbin \
		--with-kernel=/usr/src/kernel-headers-$(${XBPS_PKGDB_CMD} version kernel-headers)
}

do_build() {
	make ${makejobs}
}

do_install() {
	make DESTDIR=${DESTDIR} install

	vinstall ${FILESDIR}/iptables.service 644 lib/systemd/system
	vinstall ${FILESDIR}/ip6tables.service 644 lib/systemd/system
	vinstall ${FILESDIR}/iptables-flush.scripts 755 \
		lib/systemd/scripts iptables-flush

	for f in empty.rules simple_firewall.rules; do
		vinstall ${FILESDIR}/${f} 644 etc/iptables
	done
	for f in filter mangle nat raw security; do
		vinstall ${FILESDIR}/empty-${f}.rules 644 \
			var/lib/iptables empty-${f}.rules
	done

	# Override wrong symlinks from xtables_multi.
	for f in iptables iptables-restore iptables-save ip6tables \
		ip6tables-restore ip6tables-save; do
		cd ${DESTDIR}/sbin && ln -sf xtables-multi ${f}
	done
	cd ${DESTDIR}/usr/bin && ln -sf ../../sbin/xtables-multi iptables-xml
}
