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

WITH_TREMOR=--without-tremor --enable-vorbis
ifeq ($(DEB_HOST_ARCH), arm)
WITH_TREMOR=--with-tremor --disable-vorbis
endif
ifeq ($(DEB_HOST_ARCH), armel)
WITH_TREMOR=--with-tremor --disable-vorbis
endif
ifeq ($(DEB_HOST_ARCH), armeb)
WITH_TREMOR=--with-tremor --disable-vorbis
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 --enable-alsa
CP_SYSTEMD_UNIT=mkdir -p debian/mpd/lib/systemd && cp -a debian/tmp/lib/systemd/system debian/mpd/lib/systemd/
else
WITH_SYSTEMD=--disable-systemd-daemon --disable-alsa
CP_SYSTEMD_UNIT=echo "no systemd, not copying systemd .service file"
endif

# disable tests on s390x until #726733 is solved
RUN_TESTS=--enable-test
ifeq ($(DEB_HOST_ARCH), s390x)
    RUN_TESTS=
endif


###############################################################
## Define Debian feature set (in configure summary order)

# Archive support
ENABLE_ARCHIVES=--enable-bzip2 \
	        --enable-iso9660 \
		--enable-zzip

# Autodiscovery support
ENABLE_AUTODISCOVERY=--with-zeroconf=avahi

# Client support
ENABLE_CLIENTS=--enable-ipv6 \
	       --enable-tcp \
	       --enable-un

# File format support
# Note: OggTremor / OggVorbis are in WITH_TREMOR
ENABLE_FILEFORMATS=--enable-aac \
		   --enable-adplug \
		   --enable-sidplay \
		   --enable-ffmpeg \
		   --enable-flac \
		   --enable-fluidsynth \
		   --enable-gme \
		   --enable-sndfile \
		   --enable-mikmod \
		   --enable-modplug \
		   --enable-mad \
		   --enable-mpg123 \
		   --enable-mpc \
		   --enable-opus \
		   --enable-audiofile \
		   --enable-wavpack \
		   --enable-wildmidi

# Other features
ENABLE_OTHER=--enable-lsr \
	     --enable-libmpdclient \
	     --enable-inotify \
	     --enable-sqlite

# Metadata support
ENABLE_METADATA=--enable-id3

# Playback support
# Note: ALSA is in WITH_SYSTEMD
ENABLE_PLAYBACKS=--enable-fifo \
		 --enable-recorder-output \
		 --enable-httpd-output \
		 --enable-jack \
		 --enable-ao \
		 --enable-oss \
		 --enable-openal \
		 --enable-pipe-output \
		 --enable-pulse \
		 --enable-roar \
		 --enable-shout

# Streaming encoder support
# Note: Opus enabled under file formats
ENABLE_ENCODERS=--enable-flac-encoder \
		--enable-lame-encoder \
		--enable-vorbis-encoder \
		--enable-wave-encoder

# Streaming support
ENABLE_STREAMING=--enable-cdio-paranoia \
		 --enable-curl \
		 --enable-soundcloud \
		 --enable-mms

###############################################################


LDFLAGS += -Wl,--as-needed

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

override_dh_auto_configure:
	./configure $(WITH_TREMOR) $(WITH_SYSTEMD) $(RUN_TESTS) \
		--prefix=/usr \
		--sysconfdir=/etc \
		$(ENABLE_ARCHIVES) \
		$(ENABLE_AUTODISCOVERY) \
		$(ENABLE_CLIENTS) \
		$(ENABLE_FILEFORMATS) \
		$(ENABLE_OTHER) \
		$(ENABLE_METADATA) \
		$(ENABLE_PLAYBACKS) \
		$(ENABLE_ENCODERS) \
		$(ENABLE_STREAMING)

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_installchangelogs:
	dh_installchangelogs NEWS

override_dh_install:
	dh_install
	$(CP_SYSTEMD_UNIT)
