#!/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 compatibility version to use.
export DH_COMPAT=11

PACKAGE = bforce

USER = uucp
GROUP = news

ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -g
endif
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	INSTALL_PROGRAM += -s
endif

configure: configure-stamp
configure-stamp: 
	dh_testdir
# 	Add here commands to configure the package.
#	cat $(CURDIR)/source/Makefile.in | sed 's/\(^INSTALL_.*\)-o \$${OWNER} -g \$${GROUP}/\1/' > \
#		$(CURDIR)/source/Makefile.in.new
#	mv $(CURDIR)/source/Makefile.in.new $(CURDIR)/source/Makefile.in
	cd source; ./configure --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info --sysconfdir=/etc/bforce -with-user=$(USER) --with-group=$(GROUP) --disable-log-passwd --disable-syslog
	touch configure-stamp


build: build-stamp

build-stamp: configure-stamp 
	dh_testdir

# 	Add here commands to compile the package.
	$(MAKE) -C source
#	/usr/bin/docbook-to-man debian/bforce.sgml > bforce.1

	touch build-stamp

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

#	 Add here commands to clean up after the build process.
#	-$(MAKE) -C source clean
	dh_clean
	rm -f source/config.cache source/include/config.h source/config.log\
		source/config.status source/Makefile

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

#	Add here commands to install the package into debian/bforce.
#	$(MAKE) -C source install DESTDIR=$(CURDIR)/debian/bforce/
#	install $(CURDIR)/debian/default $(CURDIR)/debian/bforce/etc/default/bforce/

	/usr/bin/install -c -o $(USER) -g $(GROUP) source/bin/bforce $(CURDIR)/debian/bforce/usr/bin/bforce 
	/usr/bin/install -c -o $(USER) -g $(GROUP) source/bin/bfindex $(CURDIR)/debian/bforce/usr/bin/bfindex
	/usr/bin/install -c -o $(USER) -g $(GROUP) source/bin/bfstat $(CURDIR)/debian/bforce/usr/bin/bfstat
	/usr/bin/install -c -o $(USER) -g $(GROUP) source/bin/nlookup $(CURDIR)/debian/bforce/usr/bin/nlookup
	/usr/bin/install -c -o $(USER) -g $(GROUP) contrib/outman $(CURDIR)/debian/bforce/usr/bin/outman
	/usr/bin/install -c -m 644 -o $(USER) -g $(GROUP) examples/bforce.conf $(CURDIR)/debian/bforce/etc/bforce/bforce.conf
	/usr/bin/install -c -m 644 -o $(USER) -g $(GROUP) examples/bforce.subst $(CURDIR)/debian/bforce/etc/bforce/bforce.subst
	/usr/bin/install -c -m 600 -o $(USER) -g $(GROUP) examples/bforce.passwd $(CURDIR)/debian/bforce/etc/bforce/bforce.passwd	
	/usr/bin/install -c -m 644 -o $(USER) -g $(GROUP) examples/freq.aliases $(CURDIR)/debian/bforce/etc/bforce/freq.aliases
	/usr/bin/install -c -m 644 -o $(USER) -g $(GROUP) examples/freq.dirs $(CURDIR)/debian/bforce/etc/bforce/freq.dirs
	/usr/bin/install -c -m 660 contrib/systemd/bforce.service $(CURDIR)/debian/bforce/usr/lib/systemd/system/bforce.service
	/usr/bin/install $(CURDIR)/debian/bfha.def $(CURDIR)/debian/bforce/etc/default/bforce/bfha
	/usr/bin/install $(CURDIR)/contrib/bfha/bfha-debian.pl $(CURDIR)/debian/bforce/usr/lib/bforce/bfha.pl

# 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_testdir
	dh_testroot
#	dh_installdebconf
	dh_installdocs -X.cvsignore
	dh_installexamples examples/*
#	dh_installlogrotate
	dh_installinit
#	dh_installcron
	dh_installman $(CURDIR)/man/bfindex.1 $(CURDIR)/man/bforce.1 \
			$(CURDIR)/man/bfstat.1 $(CURDIR)/man/nlookup.1 $(CURDIR)/man/outman.1
#	dh_installinfo
	dh_installchangelogs CHANGES
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	chown -R $(USER):news $(CURDIR)/debian/bforce/etc/bforce
	chown -R $(USER):news $(CURDIR)/debian/bforce/var/spool/fido $(CURDIR)/debian/bforce/var/spool/bforce
	chown -R $(USER):news $(CURDIR)/debian/bforce/var/log/bforce $(CURDIR)/debian/bforce/var/run/bforce
#	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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