#!/usr/bin/make -f
export DH_VERBOSE = 1
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

# Standardized flags from /usr/share/perl5/Debian/Debhelper/Buildsystem/cmake.pm.
CMAKE_OPTS := -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=None -DCMAKE_INSTALL_SYSCONFDIR=/etc -DCMAKE_INSTALL_LOCALSTATEDIR=/var -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON -DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON

include /usr/share/dpkg/default.mk  # provides DEB_VERSION

%:
	dh $@ --buildsystem=cmake+makefile --with sphinxdoc

override_dh_auto_configure:
	dh_auto_configure --builddirectory=build-openssl -- $(CMAKE_OPTS) -DUSE_ENCLIB=openssl
	dh_auto_configure --builddirectory=build-gnutls -- $(CMAKE_OPTS) -DUSE_ENCLIB=gnutls -DTARGET_srt=srt-gnutls

override_dh_auto_build-arch:
	dh_auto_build --builddirectory=build-openssl
	dh_auto_build --builddirectory=build-gnutls

override_dh_auto_build-indep:
	http_proxy='http://127.0.0.1:9/' sphinx-build -N -c debian -d debian/doctrees -bhtml docs debian/html

override_dh_auto_install-arch:
	dh_auto_install --builddirectory=build-openssl
	dh_auto_install --builddirectory=build-gnutls # this overwrites the *.pc files so we later need to install them from the respective builddirectory

# Fix arch-indep-only builds by not trying to install the libraries that were not built
override_dh_auto_install-indep:

override_dh_installman-indep:


override_dh_installman-arch:
	help2man --help-option=-help --no-discard-stderr --no-info --version-string="$(DEB_VERSION)" \
	--name "SRT sample application to transmit files" \
	-o ./debian/srt-file-transmit.1 ./build-gnutls/srt-file-transmit
	help2man --help-option=-help --no-discard-stderr --no-info --version-string="$(DEB_VERSION)" \
	--name "SRT sample application to transmit live streaming" \
	-o ./debian/srt-live-transmit.1 ./build-gnutls/srt-live-transmit
	dh_installman

override_dh_auto_test:
	true
