#!/usr/bin/make -f
export DEB_CXXFLAGS_MAINT_APPEND = -std=c++20 -fcoroutines
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

DH_VERBOSE = 1
# see EXAMPLES in dpkg-buildflags(1) and read /usr/share/dpkg/*
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/default.mk

BUILDDIR := $(CURDIR)/_build

ifeq (,$(filter libdrogon-doc,$(shell dh_listpackages)))
    DOC = OFF
else
    DOC = ON
endif

%:
	dh $@ --with=cmake --builddirectory=_build

override_dh_auto_configure:
	dh_auto_configure -- -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DUSE_SUBMODULE=OFF -DCMAKE_SKIP_INSTALL_RPATH=ON -DBUILD_DOC=$(DOC)

# drogon_ctl links against the freshly built libdrogon, which is not installed
# yet, and cannot be executed at all when cross building. _drogon_ctl is a
# bootstrap build that lacks help.cc, so it has no usable --help output and its
# page is shipped pre-written instead.
execute_after_dh_auto_build-arch:
ifeq ($(DEB_BUILD_ARCH),$(DEB_HOST_ARCH))
	LD_LIBRARY_PATH=$(BUILDDIR) help2man --no-info \
	    --version-string='$(DEB_VERSION_UPSTREAM)' \
	    --name='command-line utility for the Drogon web framework' \
	    $(BUILDDIR)/drogon_ctl/drogon_ctl > $(BUILDDIR)/drogon_ctl.1
endif

override_dh_installexamples:
	dh_installexamples
	find debian/drogon/usr/share/doc/drogon/examples -name '.gitignore' -delete
	chmod -x debian/drogon/usr/share/doc/drogon/examples/CMakeLists.txt
