#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/rules/dpatch.mk

DEB_INSTALL_DOCS_ALL := -XTHANKS

# Please use one of the following version scheme/URL combinations, and
# use 'debian/rules get-orig-source' to obtain the orig.tar.gz
#
# Upstream Major Release
# Version:	1:0.9.2-1
# URL:		sf.net/madwifi
# or
# Upstream SVN snapshot
# Version:	1:0.9.2+r1711.20060914-1
# URL:		snapshots.madwifi.org/madwifi
#
DEBVERS := $(shell dpkg-parsechangelog | sed -n 's/^Version: .*:\(.*\)-.*/\1/p')
UPSVERS := $(shell echo $(DEBVERS) | cut -d'+' -f1)
SNAPVERS := $(shell echo $(DEBVERS) | sed -n 's/.*+\(.*\)/\1/p')
ifneq "$(SNAPVERS)" ""
SVNVERS := $(shell echo $(SNAPVERS) | sed -n 's/\./-/p')
UPBRAN := ng
UPSTAR := madwifi-$(UPBRAN)-$(SVNVERS).tar.gz
UPSURL := http://snapshots.madwifi.org/madwifi-$(UPBRAN)/$(UPSTAR)
else
UPSTAR := madwifi-$(UPSVERS).tar.gz
UPSURL := http://optusnet.dl.sourceforge.net/sourceforge/madwifi/$(UPSTAR)
endif
ORIGTAR := madwifi_$(DEBVERS).orig.tar.gz

install/madwifi-source::
	# Enforce executable bit on debian/rules, and create directory 
	# structure for modules source
	install -D -m 0755 debian/rules.modules \
		debian/tmp/modules/madwifi/debian/rules
	
	# Prepare the other debian stuff
	for f in *.modules.in control compat copyright changelog; do \
		install -m 0644 debian/$$f \
			debian/tmp/modules/madwifi/debian/; \
	done
	
	# Prepare upstream source
	find . -path ./debian/\* -type d -prune -o -printf "%P\n" | \
		egrep -v 'debian|contrib|regression|.svn' | \
		cpio -admp debian/tmp/modules/madwifi/
	
	# Prepare the debian source tarball
	tar jcf debian/madwifi-source/usr/src/madwifi.tar.bz2 \
		-C debian/tmp modules

get-orig-source:
	@dh_testdir
	@echo -e "Deb version:\t$(DEBVERS)"
	@echo -e "Upstream MV:\t$(UPSVERS)"
ifneq "$(SNAPVERS)" ""
	@echo -e "SVN version:\t$(SVNVERS)"
endif
	@test -d ../tarballs || mkdir -p ../tarballs
	@wget -Nc -T10 -O ../tarballs/$(ORIGTAR) $(UPSURL)
