#!/usr/bin/make -f

DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
DEB_HOST_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
DEB_HOST_ARCH      ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)

CFLAGS+= -g -gdwarf-2 -fno-omit-frame-pointer
ifeq ($(DEB_HOST_ARCH),solaris-i386)
	HOST32FLAG = --host=i386-pc-solaris2.11
	CFLAGS+= -msave-args
#	CFLAGS += -m32
endif
ifeq ($(DEB_HOST_ARCH),solaris-sparc)
	HOST32FLAG = --host=sparc-sun-solaris2.11
#	CFLAGS += -m32
endif
export CFLAGS

CONFIGURE_EXTRA_FLAGS += --with-libgcrypt
CONFIGURE_EXTRA_FLAGS += --libdir=\$${prefix}/lib/$(DEB_HOST_MULTIARCH)
CONFIGURE_EXTRA_FLAGS += --disable-rpath

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

override_dh_auto_configure:
	dh_auto_configure --builddirectory=build64/ -- $(CONFIGURE_EXTRA_FLAGS)

override_dh_auto_build:
	dh_auto_build --builddirectory=build64/

override_dh_auto_install:
	$(MAKE) -C build64/ install DESTDIR=$(CURDIR)/debian/tmp
	dh_auto_install

override_dh_auto_clean:
	dh_auto_clean
	rm -rf build64

override_dh_installexamples:
	dh_installexamples -a -X .deps -X Makefile -X .gitignore

override_dh_installchangelogs:
	dh_installchangelogs NEWS

#
# mansyntax.sh test duplicates functionality of debhelper and requires presence
# of en_US.utf8 locale. Ensure it is not run by providing fake man(1) tool.
#
override_dh_auto_test:
	PATH=$(CURDIR)/debian:$$PATH dh_auto_test -a
