#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk
-include /usr/share/dpkg/buildtools.mk

%:
	dh $@

override_dh_auto_configure:
	./configure \
		--lua-version=5.4 \
		--lua-suffix=5.4 \
		--runwith=lua5.4 \
		--with-lua-include=/usr/include/lua5.4 \
		--idn-library=icu \
		--prefix=/usr \
		--c-compiler="$(CC) -std=c99" \
		--linker="$(CC)" \
		--add-cflags="$(CFLAGS)" \
		--add-ldflags="$(LDFLAGS)" \
		--no-example-certs

override_dh_auto_build:
	dh_auto_build
	$(MAKE) -C tools/migration
	$(MAKE) -C man

override_dh_auto_install:
	$(MAKE) install DESTDIR=debian/tmp
	$(MAKE) prosody.install prosodyctl.install prosody.cfg.lua.install
	$(MAKE) -C tools/migration install DESTDIR=../../debian/tmp
	cp tools/ejabberd2prosody.lua debian/tmp/usr/bin/ejabberd2prosody
	cp tools/erlparse.lua debian/tmp/usr/lib/prosody/util

override_dh_installman:
	txt2man -t "prosody 8" -r "Prosody IM" -v "" debian/prosody.man.txt | sed 1d > prosody.8
	txt2man -t "ejabberd2prosody 8" -r "Prosody IM" -v "" debian/ejabberd2prosody.man.txt | sed 1d > ejabberd2prosody.8
	txt2man -t "prosody-migrator 8" -r "Prosody IM" -v "" debian/prosody-migrator.man.txt | sed 1d > prosody-migrator.8
	dh_installman

override_dh_auto_clean:
	if [ -f config.unix ]; then \
		make -C tools/migration clean; \
		make clean; \
		rm -f config.unix; \
	fi
	rm -f man/*.man
	rm -f util/*.so
	rm -f prosody.8 prosodyctl.1 ejabberd2prosody.8 prosody-migrator.8