#! /usr/bin/make -f

# rlwrap for Debian
# Oyvind Gronnesby <oyving@pvv.org>

# needed if dpkg-buildpackage is not used

export DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
export DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

# cross-compilation

ifeq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE))
  configure_options += --build $(DEB_BUILD_GNU_TYPE)
else
  configure_options += --host $(DEB_HOST_GNU_TYPE) --build $(DEB_BUILD_GNU_TYPE)
endif

configure_options += --enable-homegrown-redisplay
# so that sshc server bash -i will work

DEB_INSTALL_DIR = $(CURDIR)/debian/rlwrap

configure: configure-stamp
configure-stamp:
	dh_testdir -v
	./configure $(configure_options) \
		--prefix=/usr \
		--mandir=/usr/share/man \
		--sysconfdir=/etc \
		--datadir=/etc 
	touch $@

build: build-stamp
build-stamp: configure-stamp 
	dh_testdir
	$(MAKE)
	touch $@

install: install-stamp
install-stamp: build-stamp
	dh_testdir
	dh_testroot
	dh_clean
	dh_installdirs
	mkdir -p $(DEB_INSTALL_DIR)
	$(MAKE) install DESTDIR=$(DEB_INSTALL_DIR)
	touch $@

clean:
	dh_testdir
	dh_testroot
	rm -f configure-stamp build-stamp install-stamp
	rm -rf $(DEB_INSTALL_DIR)
	-$(MAKE) distclean
	dh_clean doc/rlwrap.1

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installdocs README NEWS BUGS AUTHORS
	dh_installchangelogs ChangeLog
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary-indep:

binary: binary-arch binary-indep

.PHONY: configure build install clean binary binary-arch binary-indep
