#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
export JAVA_HOME := /usr/lib/jvm/default-java

# Not all architectures have a java compiler
HAVE_JAVAC:=$(shell if which javac >/dev/null 2>&1; then echo Yes; fi)
ifneq (,$(strip $(HAVE_JAVAC)))
JAVA_CONF_OPTION:=--enable-swig-java --with-java-prefix=$(JAVA_HOME)
else
JAVA_CONF_OPTION:=
endif

%:
	dh $@ --with autoreconf --with python2

override_dh_auto_configure:
	dh_auto_configure -- $(JAVA_CONF_OPTION) --enable-swig-python \
                             --enable-swig-tcl   --disable-bwidget-check \
                             --with-tcl=/usr/lib/ --with-tk=/usr/lib/ \
                             --with-tkinclude=/usr/include/tcl/ \
                             --disable-selinux-check

override_dh_auto_test:

override_dh_install:
	find $(CURDIR)/debian/tmp/usr/lib/ -name 'setools-1.0.egg-info' -delete
	dh_install --list-missing

override_dh_fixperms:
	dh_fixperms
	find $(CURDIR)/debian/libsetools-tcl/usr/lib/$(DEB_HOST_MULTIARCH)/setools/ -type f -name '*.tcl' -exec chmod -x {} \;
	find $(CURDIR)/debian/setools/usr/lib/$(DEB_HOST_MULTIARCH)/setools/ -type f -name '*.tcl' -exec chmod -x {} \;
	chmod +x $(CURDIR)/debian/setools/etc/logwatch/scripts/services/seaudit-report-service
	chmod +x $(CURDIR)/debian/setools/usr/share/setools/3.3/seaudit-report-service
