#! /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)

export DEB_CPPFLAGS_MAINT_APPEND := \
	-I/usr/include/tcl8.6 \
	-D_FILE_OFFSET_BITS=64

%:
	dh $@ --sourcedirectory=build --builddirectory=debian/build \
		--with=autoreconf --parallel

autoreconf:
	autoreconf -f -i build
	cp -f /usr/share/misc/config.guess /usr/share/misc/config.sub build/

override_dh_autoreconf:
	dh_autoreconf debian/rules -- autoreconf

override_dh_auto_configure:
	dh_auto_configure -- --with-x --enable-db --enable-re

ifneq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
override_dh_auto_build:
	$(MAKE) -C debian/build a2c CC=gcc
	dh_auto_build
endif

override_dh_clean:
	# This is in the upstream tarball, so shouldn't be removed.
	dh_clean -X 'vi/#v_xchar.c#'

override_dh_auto_install:
	mkdir -p debian/vigor  # work around #707336
	dh_auto_install -- prefix=$(CURDIR)/debian/vigor/usr

override_dh_installchangelogs:
	dh_installchangelogs docs/changelog
