#!/usr/bin/make -f
# -*- makefile-gmake -*-
#
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
# This has to be exported to make some magic below work.
export DH_OPTIONS
# Enable hardening build, @see https://wiki.debian.org/Hardening
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk
# support MULTIARCH
export DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

%:
	dh $@ --without autoreconf --with gir

override_dh_auto_configure:
	dh_auto_configure							 \
	  --builddirectory=meson-build						 \
	  --buildsystem=meson+ninja						 \
	  --									 \
	  -Ddefault-connection-spec=unix:/run/milter-manager/milter-manager.sock \
	  -Ddefault-connection-spec=unix:/run/milter-manager/milter-manager.sock \
	  -Ddefault-effective-group=mail					 \
	  -Ddefault-effective-user=milter-manager				 \
	  -Ddefault-pid-file=/run/milter-manager/milter-manager.pid		 \
	  -Ddefault-socket-group=mail						 \
	  -Druby-install-dir=vendor
	dh_auto_configure								\
	  --										\
	  --enable-ruby-milter								\
	  --with-default-connection-spec=unix:/run/milter-manager/milter-manager.sock	\
	  --with-default-connection-spec=unix:/run/milter-manager/milter-manager.sock	\
	  --with-default-effective-group=mail						\
	  --with-default-effective-user=milter-manager					\
	  --with-default-pid-file=/run/milter-manager/milter-manager.pid		\
	  --with-default-socket-group=mail

override_dh_auto_test:
	TZ=Asia/Tokyo dh_auto_test

override_dh_auto_install:
	dh_auto_install				\
	  --builddirectory=meson-build		\
	  --buildsystem=meson+ninja		\
	  --destdir=debian/tmp-meson
	dh_auto_install
	find debian/tmp/usr/lib/ -name *.la -delete
	mv debian/tmp-meson/usr/share/gir-1.0/	\
	   debian/tmp/usr/share/
	mv debian/tmp-meson/usr/lib/$(DEB_HOST_MULTIARCH)/girepository-1.0/	\
	   debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/
	mkdir -p debian/tmp/usr/lib/python3/dist-packages/
	mv debian/tmp-meson/usr/lib/python*/*-packages/*	\
	   debian/tmp/usr/lib/python3/dist-packages/
	mv debian/tmp-meson/usr/share/milter-manager/python/	\
	   debian/tmp/usr/share/milter-manager/

override_dh_installdocs:
	dh_installdocs --all README.ja TODO

override_dh_auto_clean:
	dh_auto_clean				\
	  --builddirectory=meson-build		\
	  --buildsystem=meson+ninja
	dh_auto_clean
	-find $(CURDIR)/binding/ruby -name Makefile | xargs rm -f
	-rm -fr $(CURDIR)/doc/reference/ja/*.xml
	-rm -fr $(CURDIR)/doc/reference/ja/html.stamp
	-rm -fr $(CURDIR)/doc/reference/ja/xml
	-rm -fr $(CURDIR)/binding/ruby/test/.test-result/
	-rm -fr $(CURDIR)/test/tool/.test-result/
