#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
# To skip tests:
#export DEB_BUILD_OPTIONS=nocheck

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

COMMON_CONFIG = \
  -DCMAKE_BUILD_RPATH_USE_ORIGIN=ON \
  -DUSE_IMPLICIT_CRYPTO=OFF -DREQUIRE_CRYPTO_GNUTLS=ON \
  -DSHOW_FAILED_TEST_OUTPUT=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo \
  -DQTEST_COLOR=OFF

SPHINX_VERSION != sphinx-build --version 2>/dev/null
ifeq ($(.SHELLSTATUS), 0)
  DOC_CONFIG = -DBUILD_DOC=ON -DINSTALL_MANUAL=ON
else
  DOC_CONFIG =
endif

%:
	dh $@

override_dh_compress:
	dh_compress --exclude examples/ --exclude qpdf-manual.pdf

override_dh_auto_configure:
	dh_auto_configure -- $(COMMON_CONFIG) $(DOC_CONFIG)

# This target is not run for arch only builds
execute_after_dh_auto_configure-indep:
	if test "$(SPHINX_VERSION)" = ""; then \
	    echo '*** sphinx is missing ***'; \
	fi

override_dh_install:
	rm -rf debian/tmp/usr/share/doc/qpdf/manual-single-page-html
	(echo 'Complete documentation for qpdf can be found in the qpdf-doc package or'; \
	 echo 'online at https://qpdf.readthedocs.io') \
	 > debian/tmp/usr/share/doc/qpdf/README-doc.txt
	mkdir -p debian/tmp/usr/share/doc/libqpdf-dev
	mv debian/tmp/usr/share/doc/qpdf/examples \
	    debian/tmp/usr/share/doc/libqpdf-dev/
	cp -p README.md debian/tmp/usr/share/doc/libqpdf-dev/README.md
	mkdir -p debian/tmp/usr/share/bash-completion/completions
	cp completions/bash/qpdf \
	    debian/tmp/usr/share/bash-completion/completions/qpdf
	mkdir -p debian/tmp/usr/share/zsh/vendor-completions
	cp completions/zsh/_qpdf \
	    debian/tmp/usr/share/zsh/vendor-completions/_qpdf
	dh_install
	if test "$(SPHINX_VERSION)" != ""; then \
	    dh_sphinxdoc; \
	fi
	dh_missing --list-missing
