#!/usr/bin/make -f

# $Progeny: rules 4252 2004-04-09 12:34:45Z licquia $

# This is the debhelper compatibility version to use.
export DH_COMPAT=4

PACKAGE=$(shell dh_listpackages | grep -- -udeb$$)
VERSION=$(shell dpkg-parsechangelog | grep ^Version: | cut -d ' ' -f 2)
UFILENAME=$(PACKAGE)_$(VERSION)_all.udeb

build: build-stamp
build-stamp:
#	This package is so insanely simple, we have nothing to do here.
	dh_testdir
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp

	$(MAKE) clean

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean

	make install \
		prefix=/usr \
		hwlistsdir=/lib/discover \
		DESTDIR=$(CURDIR)/debian/discover-data

	mkdir -p $(CURDIR)/debian/discover-data/usr/share/discover
	for f in *.lst; do \
		ln -sf /lib/discover/$$f \
			$(CURDIR)/debian/discover-data/usr/share/discover/$$f;\
	done

#	for discover-data-udeb
	make install-udeb \
		prefix=/usr \
		hwlistsdir=/lib/discover \
		DESTDIR=$(CURDIR)/debian/$(PACKAGE)

binary-indep: build install $(PACKAGE)
	dh_testdir
	dh_testroot
	dh_installdocs -N$(PACKAGE)
	dh_installchangelogs ChangeLog -N$(PACKAGE)
	dh_compress -N$(PACKAGE)
	dh_fixperms -N$(PACKAGE)
	dh_installdeb -N$(PACKAGE)
	dh_gencontrol -N$(PACKAGE)
	dh_md5sums -N$(PACKAGE)
	dh_builddeb -N$(PACKAGE)

$(PACKAGE): build install
	dh_testdir
	dh_testroot
	dh_strip -p$(PACKAGE)
	dh_compress -p$(PACKAGE)
	dh_fixperms -p$(PACKAGE)
	dh_installdeb -p$(PACKAGE)  --filename=$(PACKAGE).udeb
	dh_shlibdeps -ldebian/libdiscover1/usr/lib -p$(PACKAGE)
	# Don't write stupid guesses to debian/files.
	dh_gencontrol -p$(PACKAGE) -- -fdebian/files~
	# Register file manually.
	dpkg-distaddfile $(UFILENAME) debian-installer extra
	dh_builddeb -p$(PACKAGE) --filename=$(UFILENAME)

binary: binary-indep
PHONY: build clean binary binary-indep $(PACKAGE) install
