#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/buildcore.mk
include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/autotools.mk

post-patches:: debian/autoreconf.after

debian/autoreconf.after:
	dh_autoreconf $(DEB_DH_AUTORECONF_ARGS)

reverse-config::
	if test -e debian/autoreconf.before; then \
		dh_autoreconf_clean $(DEB_DH_AUTORECONF_CLEAN_ARGS); \
	fi

DEB_CONFIGURE_EXTRA_FLAGS = --enable-experimental --disable-python

DEB_DH_GENCONTROL_ARGS_ALL = -- \
	-Vlib:Depends=$(shell dpkg-query -W -f '$${Depends}' libvdeplug-dev \
			| sed -E 's/.*(libvdeplug[[:alnum:].-]+).*/\1/')

# TUN/TAP is almost unsupported on kFreeBSD, so install the corresponding files
# only on Linux.
binary-install/vde2::
	if test "x`uname -s`" = "xLinux"; then \
		dh_install -pvde2 debian/tmp/usr/sbin/vde_tunctl; \
		dh_install -pvde2 debian/tmp/usr/lib/vde2/libvdetap.so; \
		dh_install -pvde2 debian/tmp/usr/lib/vde2/vdetap; \
		dh_installman -pvde2 debian/tmp/usr/share/man/man8/vde_tunctl.8; \
		dh_installman -pvde2 debian/tmp/usr/share/man/man1/vdetaplib.1; \
	fi

binary-install/libvde-dev::
	if test "x`uname -o`" = "xGNU/Linux"; then \
		dh_install -plibvde-dev debian/tmp/usr/lib/vde2/libvdetap.a; \
	fi

install/vde2::
	install -D -m 0755 debian/network/if-pre-up.d/vde2 debian/vde2/etc/network/if-pre-up.d/vde2
	install -D -m 0755 debian/network/if-post-down.d/vde2 debian/vde2/etc/network/if-post-down.d/vde2
