#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk

OPEN_MM_PLUGIN_DIR=/usr/lib/$(DEB_HOST_MULTIARCH)/openmm/plugins
CONFIGURE_OPTIONS = -DOPTIMIZE=ON -DUBUNTU_LAYOUT=ON

ifeq ($(shell test -e $(OPEN_MM_PLUGIN_DIR) && echo YES),YES)
	CONFIGURE_OPTIONS += -DENABLE_MM=ON -DOPEN_MM_PLUGIN_DIR=$(OPEN_MM_PLUGIN_DIR)
endif

ifeq (amd64,$(DEB_HOST_ARCH))
    CONFIGURE_OPTIONS += -DENABLE_PARASAIL=ON
endif

%:
	dh $@ --with python3

override_dh_auto_configure:
	dh_auto_configure -- $(CONFIGURE_OPTIONS)

execute_after_dh_auto_install:
	find debian/tmp/usr/lib -name '*.pyc' | xargs --no-run-if-empty rm

execute_after_dh_install:
	find debian/python3-ost/usr/lib/python3/dist-packages -type f \
		| xargs --no-run-if-empty chmod -x
	find debian/tmp/usr/lib -name 'libost_*.so.*' \
		| while read LIB; \
			do dh_install -p$$(echo $$LIB | cut -d / -f 5 | cut -d . -f 1 | sed 's/_/-/g')2.10 \
				$$LIB usr/lib/$(DEB_HOST_MULTIARCH); \
			done
	find debian/tmp/usr/lib -name 'libost_*.so' \
		| while read LIB; \
			do dh_install -p$$(echo $$LIB | cut -d / -f 5 | cut -d . -f 1 | sed 's/_/-/g')-dev \
				$$LIB usr/lib/$(DEB_HOST_MULTIARCH); \
			done
	chmod u+w debian/openstructure/usr/bin/*
