#!/usr/bin/make -f
# -*- mode: makefile; coding: utf-8 -*-
# Copyright © 2014 IOhannes m zmölnig <zmoelnig@iem.at>
# Description: Main Debian packaging script for snd
#
# The authors hereby grant permission to use, copy, modify, distribute,
# and license this software and its documentation for any purpose.  No
# written agreement, license, or royalty fee is required.  Modifications
# to this software may be copyrighted by their authors and need not
# follow the licensing terms described here.
#
# IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
# FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
# ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
# DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.  THIS SOFTWARE
# IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
# NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
# MODIFICATIONS.

# needs to be declared before including makefile.mk
DEB_MAKE_FLAVORS = nox gtk-jack gtk-pulse

DEB_BUILDDIR = build

export AUTOHEADER=true

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/autotools.mk
include /usr/share/cdbs/1/rules/autoreconf.mk
include /usr/share/cdbs/1/rules/utils.mk

DEB_COPYRIGHT_CHECK_IGNORE_REGEX = \
	^(pix/.*\.png|debian/(changelog|copyright(|_hints|_newhints)))$

DEB_CONFIGURE_EXTRA_FLAGS = \
	--with-ladspa \
	--with-gmp \
	--prefix=/usr

## per flavor configure options
# the code includes inline-asm for atomic ops, but only for i386/amd64/powerpc
# see https://bugs.debian.org/#555538
ifneq (,$(findstring :$(DEB_HOST_ARCH_CPU):,:i386:powerpc:amd64:))
configureflags_audio_jack  = --with-jack
else
configureflags_audio_jack  =
endif
# use ALSA on linux, and OSS non non-linux
ifneq (,$(findstring linux,$(DEB_HOST_ARCH_OS)))
configureflags_audio_default  = --with-alsa
else
configureflags_audio_default  = --with-oss
endif

# nox (alsa/oss + jack)
DEB_CONFIGURE_EXTRA_FLAGS_nox       = --without-gui \
	$(configureflags_audio_default) $(configureflags_audio_jack)

# gtk-jack (jack + alsa[sic!]/oss)
DEB_CONFIGURE_EXTRA_FLAGS_gtk-jack  = --with-gtk \
	$(configureflags_audio_default) $(configureflags_audio_jack)

## gtk-pulse (pulseaudio)
DEB_CONFIGURE_EXTRA_FLAGS_gtk-pulse = --with-gtk --with-pulseaudio

## append any extra args for configure
DEB_CONFIGURE_EXTRA_FLAGS += $(DEB_CONFIGURE_EXTRA_FLAGS_$(cdbs_make_curflavor))

## do not embed __DATE__ (see debian/patches/reproducible.diff)
CPPFLAGS+=-DREPRODUCIBLE_BUILD=1

# upstream naively (and wrongly) assumes
# that they only need to link against "-lpulse-simple"
DEB_MAKE_EXTRA_ARGS_gtk-pulse=AUDIO_LIB="$(shell pkg-config --libs libpulse-simple)"

## append any extra args for make
DEB_MAKE_EXTRA_ARGS += $(DEB_MAKE_EXTRA_ARGS_$(cdbs_make_curflavor))

## right; everybody their own changelog filename!
DEB_INSTALL_CHANGELOGS_ALL=HISTORY.Snd


SND_MANPAGES=snd.nox.1 snd.gtk-jack.1 snd.gtk-pulse.1
$(SND_MANPAGES): snd.1
	cp $^ $@

build/snd-nox:: snd.nox.1
build/snd-gtk-jack:: snd.gtk-jack.1
build/snd-gtk-pulse:: snd.gtk-pulse.1

binary-post-install/snd-nox binary-post-install/snd-gtk-jack binary-post-install/snd-gtk-pulse::
	mv $(CURDIR)/debian/$(cdbs_curpkg)/usr/bin/snd \
	   $(CURDIR)/debian/$(cdbs_curpkg)/usr/bin/snd.$(patsubst snd-%,%,$(cdbs_curpkg))

clean::
	rm -f $(SND_MANPAGES)
