#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk
include /usr/share/dpkg/buildtools.mk

#export DH_VERBOSE=1
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
INSTALL := install -m 755

export CC
export PKG_CONFIG ?= $(DEB_HOST_GNU_TYPE)-pkg-config
export DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
export DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

ifeq ($(DEB_HOST_ARCH_BITS),32)
	export DEB_CFLAGS_MAINT_APPEND = -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
endif

%:
	dh $@

# dh_autoreconf can only be run once, it does nothing for hydra itself,
# however it's required for hydra-gtk, so we run it only for hydra-gtk.
override_dh_autoreconf:
	dh_autoreconf -D hydra-gtk

override_dh_auto_configure:
	dh_auto_configure -- --disable-xhydra
	dh_auto_configure -D hydra-gtk

execute_after_dh_auto_build:
	dh_auto_build -D hydra-gtk

override_dh_auto_install:
	$(INSTALL) hydra $(CURDIR)/debian/hydra/usr/bin
	$(INSTALL) pw-inspector $(CURDIR)/debian/hydra/usr/bin
	$(INSTALL) hydra-gtk/src/xhydra $(CURDIR)/debian/hydra-gtk/usr/bin

execute_after_dh_install:
	recode ISO-8859-1..UTF-8 $(CURDIR)/debian/hydra/usr/share/hydra/dpl4hydra_local.csv

# Makefile.orig is part of the upstream's tarball and should not be removed
override_dh_clean:
	dh_clean --exclude=Makefile.orig
