#!/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

PKG := freebsd-sendpr

VERSION = $(shell dpkg-parsechangelog | sed -e '/^Version:/!d' -e 's/^Version: //g' -e 's/-.*//g')
FREEBSD_VERSION = $(shell echo $(VERSION) | sed -e 's/^[^+]\++//g')
SVN = http://svn.freebsd.org/base/release/$(FREEBSD_VERSION).0
ORIGDIR = $(PKG)-$(VERSION)

get-orig-source:
	rm -rf $(ORIGDIR)
	mkdir -p $(ORIGDIR)
	for i in gnu/usr.bin/send-pr ; do \
	    svn export $(SVN)/$$i $(ORIGDIR)/$$i ; \
	done
	tar --numeric-owner --owner 0 --group 0 -czf ../$(PKG)_$(VERSION).orig.tar.gz $(ORIGDIR)
	rm -rf $(ORIGDIR)

pkgdir := $(CURDIR)/debian/$(PKG)

PMAKE := freebsd-make DESTDIR=$(pkgdir) BINDIR=/usr/bin

clean:
	dh_testdir
	dh_testroot

	$(PMAKE) -C gnu/usr.bin/send-pr clean

	dh_clean

build-indep:
	dh_testdir

	$(PMAKE) -C gnu/usr.bin/send-pr

build-arch:

build: build-indep build-arch

install: build-indep
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

	$(PMAKE) -C gnu/usr.bin/send-pr install etc-gnats-freefall
	for i in $(pkgdir)/usr/share/man/man1/*.gz ; do \
		[ -L $$i ] || gunzip $$i ; \
	done
	rm -f $(pkgdir)/usr/share/info/*

binary-indep: install
	dh_testdir
	dh_testroot
	dh_installdocs
	dh_installexamples
	dh_installman
	dh_installinfo
	dh_installchangelogs
	dh_link
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary-arch:
# Nothing to do.

binary: binary-indep binary-arch

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