#!/usr/bin/make -f
# -*- mode: makefile; coding: utf-8 -*-
# Copyright © 2014-2021 IOhannes m zmölnig <zmoelnig@iem.at>
# Description: Main Debian packaging script for SoundScape Renderer
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

## some archs only have OpenGL-ES (at least with Qt):
OPENGL_ES_ARCHS := armhf armel

# needs to be declared before including makefile.mk
FLAVORS = nox
ifneq (,$(findstring $(DEB_HOST_ARCH), $(OPENGL_ES_ARCHS)))
export DH_OPTIONS=-Nsoundscaperenderer
else
FLAVORS += qt
endif
builddir=debian/build/flavor-

DEB_BUILDDIR = build

export QT_SELECT=qt5

# global configure options
## disables all optimization
## (x86_64 should be turned on automatically by the compiler)
CONFIG = --disable-optimization
# per flavor configure options
CONFIG_qt  = --enable-gui  --program-suffix=.qt
CONFIG_nox = --disable-gui --program-suffix=.nox
CONFIG_indep = --program-suffix=.indep --disable-all --disable-gui --disable-ip-interface --disable-ecasound --disable-polhemus --disable-razor --disable-vrpn --disable-intersense --disable-isatty


# Use the default debhelper scripts, where possible.
%:
	dh $@

execute_before_dh_autoreconf:
	mkdir -p autotools/config autotools/m4

# Add configuration options:
override_dh_auto_configure-indep: configure_indep
override_dh_auto_configure-arch: $(patsubst %,configure_%,$(FLAVORS))
configure_%:
	dh_auto_configure -B $(builddir)$* -- $(strip $(CONFIG) $(CONFIG_$*))

# Remove the subdirectories generated for the flavors.
override_dh_auto_clean:
	rm -rf $(patsubst %,$(builddir)%,$(FLAVORS) indep)
	rmdir -p $(dir $(builddir)) || echo "couldn't cleanup build-dirs...ignoring"
	rm -rf doc/manual/_build/

override_dh_auto_build-indep:
	dh_auto_build -i --sourcedirectory=$(builddir)indep || (cat $(builddir)indep/config.log && exit 1)
	$(CURDIR)/debian/scripts/alternatives $(CURDIR)/$(builddir)indep/src $(CURDIR)/$(builddir)indep/alternatives
# Create sphinx documentation:
	make -C $(CURDIR)/doc/manual html
override_dh_auto_build-arch: $(patsubst %,build_%,$(FLAVORS))
build_%:
	dh_auto_build -a --sourcedirectory=$(builddir)$* || (cat $(builddir)$*/config.log && exit 1)
	$(CURDIR)/debian/scripts/alternatives $(CURDIR)/$(builddir)$*/src $(CURDIR)/$(builddir)$*/alternatives

override_dh_auto_install-indep:
	dh_auto_install -i --sourcedirectory=$(builddir)indep
override_dh_auto_install-arch: $(patsubst %,install_%,$(FLAVORS))
install_%:
	dh_auto_install -a --sourcedirectory=$(builddir)$*

override_dh_installman:
	dh_installman --language=C

##################################################
#
#DEB_MAKE_CHECK_TARGET = check
#
#CDBS_BUILD_DEPENDS_rules_utils_copyright-check =
#CDBS_BUILD_DEPENDS_rules_utils_buildinfo =
#
#export BOOST_LIB_DIR=/usr/lib/$(DEB_HOST_MULTIARCH)
#
#DEB_COPYRIGHT_CHECK_IGNORE_REGEX = ^(doc/manual/images/.*\.(png|eps)|data/images/.*\.png|data/MacOSX/.*/.*\.(png|jpg)|data/MacOSX/(SSRIcon.icns|run-ssr.scpt)|data/impulse_responses/hrirs/hrirs_fabian.*\.wav|data/impulse_responses/wfs_prefilters/wfs_prefilter_[0-9]*_[0-9]*_[0-9]*\.wav|flext/(hrirs_fabian|wfs_prefilter_120_1500_44100)\.wav|debian/(changelog|copyright(|_hints|_newhints)))$
#
#DEB_INSTALL_MANPAGES_soundscaperenderer="--language=C"
#DEB_INSTALL_MANPAGES_soundscaperenderer-nox="--language=C"
#
#DEB_INSTALL_CHANGELOGS_soundscaperenderer-common=NEWS
#
#
#binary-install/soundscaperenderer-common::
#	rm -rf $(CURDIR)/debian/$(cdbs_curpkg)/usr/share/ssr/images/
#build/soundscaperenderer-common::
#	make -C $(CURDIR)/doc/manual latexpdf
#build/soundscaperenderer-nox::
#	$(CURDIR)/debian/scripts/help2man $(CURDIR)/$(DEB_BUILDDIR)/nox/src $(CURDIR)/build/manpages .nox.1
#	$(CURDIR)/debian/scripts/alternatives $(CURDIR)/$(DEB_BUILDDIR)/nox/src $(CURDIR)/$(DEB_BUILDDIR)/nox.deb/alternatives
#
#ifeq (,$(findstring $(DEB_HOST_ARCH), $(OPENGL_ES_ARCHS)))
#build/soundscaperenderer::
#	$(CURDIR)/debian/scripts/help2man $(CURDIR)/$(DEB_BUILDDIR)/qt/src $(CURDIR)/build/manpages .qt.1
#	$(CURDIR)/debian/scripts/alternatives $(CURDIR)/$(DEB_BUILDDIR)/qt/src $(CURDIR)/$(DEB_BUILDDIR)/qt.deb/alternatives
#endif
#
#clean::
#	rm -rf $(CURDIR)/build/
#	rm -rf $(CURDIR)/doc/manual/_build/
