#!/usr/bin/make -f

#export DH_VERBOSE=1

CC = gcc
CFLAGS = -Wall -Wno-format -Wno-pointer-sign -Wno-strict-aliasing -g
CONFIGURE_ARGS = \
	--disable-fips-prf --enable-openssl --enable-md4 --enable-nm \
	--enable-agent --enable-eap-gtc --enable-eap-md5 --enable-eap-mschapv2 \
	--enable-eap-identity --enable-ldap --enable-curl --sysconfdir=/etc \
	--prefix=/usr --libexecdir=/usr/lib --with-ipsecdir=/usr/lib/strongswan

ifeq (,$(filter noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O2
endif
ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
	NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
	MAKEFLAGS += -j$(NUMJOBS)
endif
ifeq ($(DEB_BUILD_ARCH_CPU),i386)
  CONFIGURE_ARGS += --enable-padlock
endif

build:
	dh_testdir
	./configure $(CONFIGURE_ARGS)
	$(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS)"
	touch build

clean:
	dh_testdir
	dh_testroot
	rm -f build
	[ ! -f Makefile ] || $(MAKE) clean
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean
	dh_installdirs
	$(MAKE) DESTDIR=$(CURDIR)/debian/tmp install

binary-indep: build install
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs NEWS
	dh_installdocs README
	dh_installinit --name=ipsec
	dh_install -s
	dh_link
	dh_strip
	dh_compress
	dh_fixperms -Xetc/ipsec.secrets -Xetc/ipsec.d
	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol -s
	dh_md5sums
	dh_builddeb -s

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install

