#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS=hardening=+all

# generate documentation unless nodoc requested
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
DOCS = README.html README.txt
endif

# avoid optimizations specific to build host
CONFIGURE_ARGS += --enable-generic

CONFIGURE_ARGS += --enable-opencl

# avoid namespace clash with other ircd-derived projects
CONFIGURE_ARGS += --sysconfdir=/etc/construct --libdir=/usr/lib/$(DEB_HOST_MULTIARCH)/ctor --includedir=/usr/include/ctor

# support DEB_BUILD_OPTIONS=noopt, and use upstream default optimization
export DEB_CXXFLAGS_MAINT_STRIP = -O2
ifeq (,$(filter noopt,$(DEB_BUILD_OPTIONS)))
CONFIGURE_ARGS += --enable-optimize
else
CONFIGURE_ARGS += --enable-optimize --with-optimize-level=0
endif

%:
	dh $@ --with linktree

%.html: %.md
	pandoc --from gfm-raw_html --to html --standalone --output $@ $<

%.txt: %.md
	pandoc --from gfm-raw_html --to plain --output $@ $<

execute_after_dh_auto_clean:
	rm -rf deps

override_dh_clean:
	dh_clean -- $(DOCS)

override_dh_auto_configure:
	mkdir -p deps
	ln -sfT ../Xrocksdb deps/rocksdb
	dh_auto_configure -- $(CONFIGURE_ARGS)

execute_after_dh_auto_build: $(DOCS)

override_dh_install:
	dh_install -X.la

override_dh_installdocs:
	dh_installdocs --all -- $(DOCS)

execute_after_dh_fixperms:
	chmod -x debian/construct-common/usr/share/construct/construct/webapp/favicon.ico
