#!/usr/bin/make -f

# Copyright (C) 2012-2018 by Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation; either version 3 of the License, 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.

# this doesn't work, so commenting it out...
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all
#export DEB_CFLAGS_MAINT_APPEND = -Wall
#include /usr/share/dpkg/buildflags.mk

export PREFIX=/usr
export DESTDIR="$(DEB_DESTDIR)"
export SKIP_INSTALL_PYMODULE=1

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk
CFLAGS+=$(CPPFLAGS)
CXXFLAGS+=$(CPPFLAGS)

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

# disable unit tests (for now), they don't (yet) work with offline builds
#DEB_MAKE_CHECK_TARGET = check
DEB_MAKE_INSTALL_TARGET = install

DEB_PYTHON_SYSTEM = $(shell test -f /usr/bin/dh_python3 && echo "" || echo "pysupport")

include /usr/share/cdbs/1/class/python-distutils.mk

configure/python-x2gobroker-doc::
	if [ ! -f docs/build/html/index.html ]; then \
		make -f Makefile.docupload docbuild; \
	fi

# somehow, the symlinks do not make it into the upstream tarball...
post-patches::
	ln -fs x2gobroker.1 man/man1/x2gobroker-daemon.1
	ln -fs x2gobroker.1 man/man1/x2gobroker-ssh.1

common-binary-indep::
	cp pam/x2gobroker.Debian pam/x2gobroker
	cp x2gobroker-ssh.sudo x2gobroker-ssh

common-binary-arch:: common-binary-indep
common-binary-post-install-arch:: list-missing

clean::
	if [ -e Makefile.docupload ]; then make -f Makefile.docupload clean; fi
	rm -f pam/x2gobroker
	rm -f lib/x2gobroker-agent
	rm -f x2gobroker-ssh
	rm -f man/man1/x2gobroker-daemon.1
	rm -f man/man1/x2gobroker-ssh.1
	rm -Rf x2gobroker.egg-info/

get-orig-source:
	uscan --noconf --force-download --rename --download-current-version --destdir=..
