#!/usr/bin/make -f

tempdir = debian/temp
# (not debian/tmp, which dh_clean removes too automatically)

DEB_MAKE_FLAVORS = A W
DEB_BUILDDIR = build
DEB_DESTDIR = $(CURDIR)/$(tempdir)
DEB_DH_INSTALL_SOURCEDIR = $(tempdir)
DEB_BUILD_ARCH = $(shell dpkg-architecture -qDEB_BUILD_ARCH)

clean::
	$(MAKE) -C test distclean
	rm -rf $(tempdir)
	rm -f debian/install
	rm -f test/src/common.o

include /usr/share/cdbs/1/class/autotools.mk
include /usr/share/cdbs/1/rules/debhelper.mk

DEB_CONFIGURE_EXTRA_FLAGS = --libdir=/usr/lib/$(DEB_HOST_MULTIARCH)/odbc --with-unixodbc

pre-build::
	chmod a+x $(CURDIR)/debian/odbc_config_dummy

DEB_CONFIGURE_EXTRA_FLAGS += ODBC_CONFIG='$(CURDIR)/debian/odbc_config_dummy'

DEB_CONFIGURE_EXTRA_FLAGS_A = --disable-unicode
DEB_CONFIGURE_EXTRA_FLAGS += $(DEB_CONFIGURE_EXTRA_FLAGS_$(cdbs_make_curflavor))

# there is no working PostgreSQL server on hurd, skip test
ifneq ($(DEB_BUILD_ARCH),hurd-i386)
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
build/odbc-postgresql::
	debian/tests/buildtime
endif
endif

install/odbc-postgresql::
	install -D -m 644 debian/odbcinst.ini.template $(DEB_DESTDIR)/usr/share/psqlodbc/odbcinst.ini.template
	rm $(CURDIR)/debian/temp/?/usr/lib/$(DEB_HOST_MULTIARCH)/odbc/*.la
	sed -e "s/\$${DEB_HOST_MULTIARCH}/$(DEB_HOST_MULTIARCH)/g" \
		< debian/install.in > debian/install
