#!/usr/bin/make -f
# -*- makefile -*-
# Uncomment this to turn on verbose mode.
# export DH_VERBOSE=1

# see FEATURE AREAS in dpkg-buildflags(1)
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

include /usr/share/dpkg/architecture.mk

# Disable parallel build to circumvent some random build error
# (needs further investigation)
%:
	dh $@ --buildsystem=cmake --with pkgkde_symbolshelper --no-parallel

BUILD_OPTIONS = \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_INSTALL_LIBDIR=/usr/lib/$(DEB_HOST_MULTIARCH)/ \
    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_BUNDLED_LIBMARISA=OFF

ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
BUILD_OPTIONS += -DBUILD_DOCUMENTATION=ON
else
BUILD_OPTIONS += -DBUILD_DOCUMENTATION=OFF
endif

ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
BUILD_OPTIONS += -DENABLE_GTEST=ON
else
BUILD_OPTIONS += -DENABLE_GTEST=OFF
endif

override_dh_auto_configure:
	dh_auto_configure -- $(BUILD_OPTIONS)

execute_after_dh_auto_clean:
	find . -name *.pyc -delete

execute_after_dh_installdocs-indep:
ifeq (,$(findstring nodoc,$(DEB_BUILD_OPTIONS)))
	dh_doxygen --indep
endif

override_dh_installdocs:
	dh_installdocs -plibopencc-doc --doc-main-package=opencc
	dh_installdocs --remaining-packages

override_dh_installchangelogs:
	dh_installchangelogs -k NEWS.md