#!/usr/bin/make -f
#
# Copyright (C) 1997 joost witteveen <joost@rulcmc.leidenuniv.nl>
# Copyright (C) 1997-2001 Juan Cespedes <cespedes@debian.org>
# Copyright (C) 2001 Adam Lazur <zal@debian.org>

# Uncomment me to turn on debugging
#export DH_VERBOSE=1

include /usr/share/dpatch/dpatch.make

# the debhelper compatability version
export DH_COMPAT=3

package = screen-n900

ROOT = $(shell pwd)/debian/$(package)

# statically define this... sucko
TTYGROUP = 5
configure: dpatch configure-stamp
configure-stamp: patch-stamp
	dh_testdir
	./configure --prefix=/usr \
		    --infodir='$$(prefix)/share/info' \
		    --mandir='$$(prefix)/share/man' \
		    --with-socket-dir=/var/run/screen \
		    --with-pty-mode=0620 \
		    --with-pty-group=${TTYGROUP} \
		    --enable-rxvt_osc \
		    --with-sys-screenrc=/etc/screenrc
#		    --enable-colors256
	touch $@

build: build-stamp
build-stamp: configure-stamp
	dh_testdir
	$(MAKE) CFLAGS+='-O2 -g -Wall'
	for file in doc/screen.texinfo doc/screen.1 ; do \
	    sed -f debian/mod_docs.sed $${file} > $${file}.new && \
	    mv $${file}.new $${file} ; \
	done
	touch $@

clean: unpatch
	dh_testdir
	dh_testroot
	rm -f configure-stamp build-stamp
	# clean up after the build process
	-$(MAKE) clean
	rm -rf config.status
	$(MAKE) -f debian/rules unpatch
	rm -f patch-stamp*
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs
	# can't call the normal install target b/c it installs the info files
	# and other crud
	$(MAKE) prefix=$(ROOT)/usr SCREENENCODINGS='$$(prefix)/share/screen/utf8encodings' installdirs install_bin
	# install the debian screenrc to etc
	install -m 644 debian/screenrc $(ROOT)/etc
	# hack around the fact that the install target makes screen a symlink
	# to screen-$(VERSION)
	rm -f $(ROOT)/usr/bin/screen
	mv -f $(ROOT)/usr/bin/screen* $(ROOT)/usr/bin/screen
	# make it setgid utmp
	chown root:utmp $(ROOT)/usr/bin/screen
	chmod 2755 $(ROOT)/usr/bin/screen
	chown root:utmp $(ROOT)/var/run/screen
	chmod 775 $(ROOT)/var/run/screen
	# lintian overrides for the setgid bin etc
	install -m 755 -d $(ROOT)/usr/share/lintian/overrides
	install -m 644 debian/screen.lintian.overrides $(ROOT)/usr/share/lintian/overrides/screen
	# cheat a little here and copy the README.terminfo into the terminfo
	# dir for dh_installdocs to pick up later
	install -m 644 debian/README.terminfo terminfo

binary-indep: build install

binary: binary-arch

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installdebconf
	dh_installdocs
	dh_installexamples
	dh_installman || true
	dh_installinfo
	dh_installchangelogs -k patchlevel.h
	dh_installinit --no-start --init-script='screen-cleanup' --update-rcd-params='start 70 S .'
	dh_strip
	dh_compress
	dh_fixperms -X/usr/bin/screen -X/var/run/screen
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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