#!/usr/bin/make -f
# Sample debian/rules that uses debhelper. GNU copyright 1997 by Joey Hess.
#
# modifiacations for use as ssh's rules file by Philip Hands <phil@hands.com>

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

#PACKAGE   = $(shell perl -e 'print <> =~ /(\S*)\s/' debian/changelog)
PKG_VER	  = $(shell perl -e 'print <> =~ /\((.*)\)/' debian/changelog)
#PKG_UPVER = $(shell perl -e 'print <> =~ /\((.*)-[^-]*\)/' debian/changelog)

build:
	# libc5 line
	#no_libnsl=yes no_libutil=yes CC="i486-linuxlibc1-gcc" ./configure --prefix=/usr --with-etcdir=/etc/ssh -with-libwrap
	# libc6 line
	PERL=/usr/bin/perl ./configure --prefix=/usr --with-etcdir=/etc/ssh -with-libwrap --with-rsh=/usr/bin/rsh
	$(MAKE) CFLAGS="-O2 -g -Wall"
	touch build


clean: checkdir
	-rm -f build
	-$(MAKE) -i distclean
	dh_clean

# Build architecture-independent files here.
binary-indep: build
# We have nothing to do by default.

binary-arch:	checkroot build
	dh_clean -k
	dh_installdirs
	
	$(MAKE) CFLAGS=-O2 LDFLAGS=-s install_prefix=`pwd`/debian/tmp install
	rm debian/tmp/etc/ssh/ssh_host_key*
	# move all the man symlinks to be .gz
	for i in `find debian/tmp/usr/man -type l` ;\
		do j=`ls -ld $$i | sed -e 's/^.* [-][>] //'` ;\
		rm $$i ; ln -s $$j.gz $$i.gz ; done
	mkdir -p debian/ssh-askpass/usr/man/man1
	ln -sf ../man7/undocumented.7.gz debian/ssh-askpass/usr/man/man1/ssh-askpass.1.gz
	# put the current version in ssh-askpass.substvars
	echo "package:Version=$(PKG_VER)" > debian/ssh-askpass.substvars

	dh_installdocs OVERVIEW RFC* INSTALL README* TODO libdes-*
	#dh_installexamples
	#dh_installmenu
	dh_installinit
	#dh_installcron
	#dh_installmanpages
	dh_installchangelogs ChangeLog
	dh_movefiles
	dh_strip
	dh_compress
	dh_fixperms
	dh_suidregister
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_makeshlibs
	dh_md5sums
	dh_builddeb

# Below here is fairly generic really

binary:		binary-indep binary-arch

source diff:
	@echo >&2 'source and diff are obsolete - use dpkg-source -b'; false

checkdir:
	@test -f ssh.c -a -f debian/rules

checkroot: checkdir
	@test 0 = `id -u` || { echo "Error: not super-user"; exit 1; }

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