#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 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=3

configure: configure-stamp
configure-stamp:
	dh_testdir
	# Add here commands to configure the package.
	( [ "`dpkg --print-architecture`" = "powerpc" ] && export CFLAGS=-D__BYTEORDER_HAS_U64__; \
 	  ./configure --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info --sysconfdir=/etc --with-ext2direct=yes --enable-rpcsetquota=yes)

	touch configure-stamp

build: configure-stamp build-stamp
build-stamp:
	dh_testdir

	# Add here commands to compile the package.
	# Make sure _PATH_VI is set to /usr/bin/editor according to policy
	-mv quotaops.c q.c
	cat q.c|sed -e 's#_PATH_VI#"/usr/bin/editor"#'>quotaops.c
	$(MAKE) 
	-mv q.c quotaops.c

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp *~ debian/*~ configure-stamp

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

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	# Add here commands to install the package into debian/quota.
	-mv edquota.8 e.8
	# change default editor to /usr/bin/editor
	cat e.8 | sed 's#vi (1)#editor (1)#' > edquota.8
	-rm e.8
	$(MAKE) ROOTDIR=`pwd`/debian/quota  \
		BIN_OWNER=root BIN_GROUP=root \
		LN="ln -s"\
		mandir=/usr/share/man \
                DEF_BIN_MODE=755 DEF_SBIN_MODE=755 install

	install -o root -g root -m 644 debian/warnquota.conf `pwd`/debian/quota/etc
	install -o root -g root -m 644 debian/quotatab `pwd`/debian/quota/etc
	# Since version 3.07 quota doesn't install files into /sbin anymore
	# so we have to move the files
	mv `pwd`/debian/quota/usr/sbin/quotacheck `pwd`/debian/quota/sbin
	mv `pwd`/debian/quota/usr/sbin/quotaon `pwd`/debian/quota/sbin
	mv `pwd`/debian/quota/usr/sbin/quotaoff `pwd`/debian/quota/sbin
	mv `pwd`/debian/quota/usr/sbin/convertquota `pwd`/debian/quota/sbin

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

# Build architecture-dependent files here.
binary-arch: build install
#	dh_testversion
	dh_testdir
	dh_testroot
	dh_installdebconf	
	dh_installdocs doc/*.* warnquota.conf
	dh_installexamples
	dh_installmenu
#	dh_installemacsen
#	dh_installpam
	dh_installinit --init-script=quotarpc
	#
	# dh_installinit cannot be configured to not install the defaults
	# file for quotarpc, so we have to manually delete it
	#
	-rm -rf `pwd`/debian/quota/etc/default/quotarpc
	dh_installinit
	dh_installcron
	dh_installmanpages
	# remove man pages already in libc
	-rm -rf `pwd`/debian/quota/usr/share/man/man2
	# and include files in libc-dev
	-rm -rf `pwd`/debian/quota/usr/include
	(cd `pwd`/debian/quota/usr/share/man/man8 && \
	 ln -s rquotad.8.gz rpc.rquotad.8.gz)
	(cd `pwd`/debian/quota/usr/share/man/man8 && \
	 ln -s quotaon.8.gz quotaoff.8.gz)
	dh_installinfo
	dh_installchangelogs Changelog
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
#	dh_makeshlibs
	dh_installdeb
#	dh_perl
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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

%:      %pod
	pod2man \
		--section=`echo $@ | sed 's/^.*\.//'` \
		--center="Debian GNU/Linux manual"\
		--date="Debian Project"\
		--release="`date '+%B %Y'`" \
	$< >,$@ && mv -f ,$@ $@;\
	rm -f ,$@
