#!/usr/bin/make -f
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

DEB_HOST_ARCH_OS := $(shell dpkg-architecture -qDEB_HOST_ARCH_OS)

CONFIGURE_OPTS = --ghc-options="-optl -Wl,-z,relro -optl -Wl,--as-needed"

ifeq ($(DEB_HOST_ARCH_OS),linux)
    CONFIGURE_OPTS += --flags="with_xft with_inotify with_iwlib with_mpris with_dbus"
else
    CONFIGURE_OPTS += --flags="with_xft"
endif

%:
	dh $@

override_dh_auto_configure:
	ghc --make Setup.*hs -o setup-ghc
	./setup-ghc configure --ghc --prefix=/usr $(CONFIGURE_OPTS)

override_dh_auto_build:
	./setup-ghc build

override_dh_auto_install:
	./setup-ghc copy --destdir=debian/tmp/

override_dh_auto_clean:
	-./setup-ghc clean
	-rm -f Setup.o Setup.hi setup-ghc

.PHONY: override_dh_auto_configure override_dh_auto_build \
        override_dh_auto_install override_dh_auto_clean
