#!/usr/bin/make -f
include /usr/share/dpkg/architecture.mk

WITH_TREMOR=
ifeq ($(DEB_HOST_ARCH), arm)
WITH_TREMOR=--with-tremor
endif
ifeq ($(DEB_HOST_ARCH), armel)
WITH_TREMOR=--with-tremor
endif
ifeq ($(DEB_HOST_ARCH), armeb)
WITH_TREMOR=--with-tremor
endif

WITH_SYSTEMD=
ifeq ($(DEB_HOST_ARCH_OS), linux)
WITH_SYSTEMD=--enable-systemd-daemon --with-systemdsystemunitdir=/lib/systemd/system
endif

LDFLAGS += -Wl,--as-needed

%:
	dh $@

override_dh_auto_configure:
	./configure $(WITH_TREMOR) $(WITH_SYSTEMD) --enable-sqlite \
		--enable-un \
		--enable-ao \
		--enable-lastfm \
		--enable-pipe-output \
		--enable-lame-encoder \
		--enable-mikmod \
		--enable-soundcloud \
		--enable-iso9660 \
		--enable-modplug \
		--enable-curl \
		--prefix=/usr \
		--sysconfdir=/etc

override_dh_auto_build:
	dh_auto_build
	# from the available documentation, generate just the user manual, as one html file
	/usr/bin/xmlto --stringparam chunker.output.encoding=utf-8 html-nochunks $(CURDIR)/doc/user.xml
	mv user.html user-manual.html

override_dh_strip:
	dh_strip  --dbg-package=mpd-dbg

override_dh_installinit:
	dh_installinit -n

override_dh_installchangelogs:
	dh_installchangelogs NEWS

override_dh_install:
	dh_install
	cp $(CURDIR)/debian/mpd.tmpfiles $(CURDIR)/debian/mpd/usr/lib/tmpfiles.d/mpd.conf
