#!/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

# no systemd and no alsa on non-linux arches
ifeq ($(DEB_HOST_ARCH_OS), linux)
WITH_SYSTEMD=--enable-systemd-daemon --with-systemdsystemunitdir=/lib/systemd/system
CP_SYSTEMD_UNIT=mkdir -p debian/mpd/lib/systemd && cp -a debian/tmp/lib/systemd/system debian/mpd/lib/systemd/
else
WITH_SYSTEMD=--disable-alsa
CP_SYSTEMD_UNIT=echo "no systemd, not copying systemd .service file"
endif

LDFLAGS += -Wl,--as-needed

%:
	dh $@ --with autoreconf --with=systemd

override_dh_auto_configure:
	./configure $(WITH_TREMOR) $(WITH_SYSTEMD) \
		--enable-sqlite \
		--enable-un \
		--enable-ao \
		--enable-pipe-output \
		--enable-lame \
		--disable-cue \
		--enable-mikmod \
		--enable-soundcloud \
		--enable-iso9660 \
		--enable-modplug \
		--enable-curl \
		--enable-fluidsynth \
		--enable-test \
		--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
	$(CP_SYSTEMD_UNIT)

override_dh_auto_test:
	chmod +x test/*.sh
	dh_auto_test
