#!/usr/bin/make -f

# Based on debhelper sample rules file by Joey Hess

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# This is the debhelper compatability version to use.
export DH_COMPAT=2

# shared library versions, option 1
version=2.0.5
major=2
# option 2, assuming the library is created as src/.libs/libfoo.so.2.0.5 or so
#version=`ls src/.libs/lib*.so.* | \
# awk '{if (match($$0,/[0-9]+\.[0-9]+\.[0-9]+$$/)) print substr($$0,RSTART)}'`
#major=`ls src/.libs/lib*.so.* | \
# awk '{if (match($$0,/\.so\.[0-9]+$$/)) print substr($$0,RSTART+4)}'`

build: build-stamp
build-stamp:
	dh_testdir

	# Add here commands to compile the package.
	$(MAKE) depend
	$(MAKE)

	touch build-stamp

clean:
	dh_testdir
	rm -f build-stamp configure-stamp

	# Add here commands to clean up after the build process.
	-$(MAKE) clean

	dh_clean

# Build architecture-independent files here.
binary-indep:
	@echo No architecture-independent packages.

VERSION := $(shell dpkg-parsechangelog | grep ^Version: | cut -d ' ' -f 2)
ARCH := $(shell dpkg-architecture -qDEB_HOST_ARCH)

# Build architecture-dependent files here.
binary-arch: build
	dh_testdir
	dh_testroot

	$(MAKE) install DESTDIR="$(shell pwd)/debian/tmp"

	dh_movefiles

	install -d debian/bogl-bterm-udeb/usr/bin
	install -m 755 debian/bogl-bterm/usr/bin/bterm debian/bogl-bterm-udeb/usr/bin/bterm
	install -d debian/bogl-bterm-udeb/usr/share/terminfo/b
	install -m 644 debian/bogl-bterm/usr/share/terminfo/b/bterm debian/bogl-bterm-udeb/usr/share/terminfo/b/bterm

	dh_installdocs -Nbogl-bterm-udeb
	dh_installexamples -Nbogl-bterm-udeb
	dh_installman -Nbogl-bterm-udeb
	dh_installinfo -Nbogl-bterm-udeb
	dh_installchangelogs -Nbogl-bterm-udeb
	dh_link
	dh_strip
	dh_compress
	dh_fixperms

	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps

	dh_gencontrol -Nbogl-bterm-udeb
	dh_gencontrol -pbogl-bterm-udeb -- -fdebian/files~
	dpkg-distaddfile bogl-bterm-udeb_$(VERSION)_$(ARCH).udeb debian-installer extra
	dh_md5sums -Nbogl-bterm-udeb
	dh_builddeb -Nbogl-bterm-udeb
	dh_builddeb -pbogl-bterm-udeb --filename=bogl-bterm-udeb_$(VERSION)_$(ARCH).udeb

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