#!/usr/bin/make -f
SHELL=/bin/bash -e

#export DH_VERBOSE=1

include debian/scripts/vars

BUILD_DIR := $(SOURCE_DIR)/$(TAR_DIR)
B := $(BUILD_DIR)
D := $(CURDIR)/debian/speedtouch

DOCS := AUTHORS TODO doc-linux/BUGS doc-linux/FAQ \
 doc-linux/howto/SpeedTouch-HOWTO-*.html doc-linux/pppoax-doc-*.txt \
 doc-linux/results.txt


all: build

unpack: $(STAMP_DIR)/unpack
$(STAMP_DIR)/unpack:
	$(MAKE) -f debian/sys-build.mk source.make
	touch $@

# used by the maintainer
unpack.nopatch: 
	$(MAKE) -f debian/sys-build.mk source.build

# used by the maintainer
diff:
	$(MAKE) -f debian/sys-build.mk make-diff

clean:
	$(MAKE) -f debian/sys-build.mk source.clean
	dh_clean


configure: $(STAMP_DIR)/configure
$(STAMP_DIR)/configure: $(STAMP_DIR)/unpack
	$(MAKE) -f debian/sys-build.mk source.command SOURCE_CMD=" \
		./configure \
	"
	touch $@

build: $(STAMP_DIR)/build
$(STAMP_DIR)/build: $(STAMP_DIR)/configure $(STAMP_DIR)/unpack
	dh_testdir
	$(MAKE) -f debian/sys-build.mk source.command SOURCE_CMD=" \
		$(MAKE) \
	"
	touch $@

binary-arch: $(STAMP_DIR)/build checkroot
	dh_testdir
	dh_clean -k
	dh_installdirs /usr/sbin/ /etc/hotplug/usb/

	cp $B/src/modem_run $B/src/pppoa3 $D/usr/sbin/
	install -m 755 extra/hotplug $D/etc/hotplug/usb/speedtouch
	cp extra/hotplug.usermap $D/etc/hotplug/usb/speedtouch.usermap

	dh_installchangelogs $B/ChangeLog
	dh_installdocs $(addprefix $B/,$(DOCS))
	dh_installexamples extra/peers-pppoa extra/interfaces
	dh_installman $B/doc-linux/man/modem_run.1 $B/doc-linux/man/pppoa3.1

	dh_strip
	dh_compress
	dh_fixperms
	chown root:dip $D/usr/sbin/modem_run
	chmod 4754 $D/usr/sbin/modem_run
	dh_shlibdeps
	dh_installdeb
	dh_gencontrol
	dh_builddeb


binary:	binary-arch

checkroot:
	test root = "`whoami`"

.PHONY: binary binary-arch binary-indep unpack configure build clean checkroot
