#!/usr/bin/make -f
# -*- makefile -*-
# 
# debian/rules file for the `kbd' package

# turn around bug in dpkg-parsechangelog
export LC_ALL=C

package=kbd

ARCH=$(shell dpkg --print-architecture)

topdir=$(shell pwd)
debdir=${topdir}/debian
tmpdir=${debdir}/tmp
bindir=${tmpdir}/bin
ubindir=${tmpdir}/usr/bin
usbindir=${tmpdir}/usr/sbin
docdir=${tmpdir}/usr/share/doc/${package}

configure-stamp:
	${topdir}/configure --mandir=/usr/share/man
	touch configure-stamp

build: build-stamp
build-stamp: configure-stamp
	dh_testdir
	make CFLAGS="-O2 -g -Wall" ARCH=${ARCH}
	make CFLAGS="-O2 -g -Wall" ARCH=${ARCH} -C contrib splitfont
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp \
	  contrib/splitfont
	-make reallyclean ARCH=${ARCH}
#	rm -f compress
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean

	make install-progs install-man DESTDIR=${tmpdir} ARCH=${ARCH}
     # install contribs
	install -m 755 ${topdir}/contrib/splitfont ${ubindir}

     # correct locations
	install -d -m755 ${tmpdir}/sbin
	mv ${tmpdir}/usr/bin/kbdrate ${tmpdir}/sbin/

     # open compat symlink
	ln -s openvt ${tmpdir}/usr/bin/open
	ln -s openvt.1 ${tmpdir}/usr/share/man/man1/open.1

binary-indep:
	dh_testdir

binary-arch:	install
	dh_testdir
	dh_testroot

	dh_installdirs

#	dh_installdebconf
	dh_installdocs

	dh_undocumented

     # correct
	mv ${docdir}/doc/* ${docdir}
	rmdir ${docdir}/doc
     # do not install the FAQ/HOWTO (already in doc-linux)
	rm ${docdir}/kbd.FAQ*

     # correct some install locations for programs
	mv ${ubindir}/showfont ${ubindir}/shfont
	rm ${ubindir}/spawn_*
	install -m 755 ${topdir}/data/keymaps/i386/mk_modmap ${ubindir}

    # some deb-specific files
	install -m 644 debian/conffiles.d/config ${tmpdir}/etc/kbd/

	dh_installinit --init-script=console-screen.kbd.sh -r -u"start 48 S ."

	dh_installchangelogs CHANGES
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Below here is fairly generic really

binary: binary-indep binary-arch

.PHONY: binary binary-arch binary-indep clean checkroot
