#!/usr/bin/make -f
#export DH_VERBOSE = 1

include /usr/share/dpkg/pkg-info.mk

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# Needed for GCC-12 and ABI issues.
# https://github.com/exeldro/obs-source-clone/issues/16
export DEB_CFLAGS_MAINT_APPEND = -Wno-psabi

# Exclude "obs-" from NAME and set a DEST
export PLUGIN_NAME=$(shell echo ${DEB_SOURCE} | cut -d"-" -f2-)
export PLUGIN_DEST=debian/${DEB_SOURCE}/usr/lib/${DEB_TARGET_MULTIARCH}/obs-plugins

%:
	dh $@

execute_before_dh_auto_configure:
	if [ "$(shell hostname)" = "canopus" ]; then \
	    LINESUS=$(shell cat data/locale/en-US.ini | wc -l); \
	    LINESPT=$(shell cat data/locale/pt-BR.ini | wc -l); \
	    if [ "$$LINESUS" != "$$LINESPT" ]; then \
	        echo "ERROR: Translation to pt_BR is out of date."; \
	        #exit 1; \
	    fi; \
	fi

override_dh_auto_configure:
	dh_auto_configure -- -DBUILD_OUT_OF_TREE=On \
                             -DLIB_OUT_DIR=lib/${DEB_TARGET_MULTIARCH}/obs-plugins \
                             -DDATA_OUT_DIR=share/obs/obs-plugins/${PLUGIN_NAME} \
                             -DLINUX_PORTABLE=Off

execute_before_dh_install:
	mkdir -p ${PLUGIN_DEST}
	find -name lib${PLUGIN_NAME}.so -exec cp {} ${PLUGIN_DEST}/${PLUGIN_NAME}.so \;

execute_after_dh_installdocs:
	cd debian/${DEB_SOURCE}/usr/share/doc/${DEB_SOURCE}; \
	pandoc README.md -f markdown -t plain -o README
