#!/usr/bin/make -f

# This script uses debhelper by Joey Hess
# Portions grabbed from device3dfx-source Copyright (C) 1999 Steve Haslam

export DH_VERBOSE=1
export DH_COMPAT=3
# enables magic below
export DH_OPTIONS

DESTDIR_SOURCE=debian/thinkpad-source
DRIVERTREE=$(DESTDIR_SOURCE)/usr/src/modules/thinkpad
#DOC=$(DESTDIR_SOURCE)/usr/share/doc/thinkpad-source

DESTDIR_BASE=debian/thinkpad-base

#VER=$(shell pwd |sed -e 's/.*-//')
# We write the source version number into the modules proto-changelog
# file. Determine it automagically
OURVERSION := $(shell head -1 debian/changelog | sed -e 's/.*(\(.*\)).*/\1/')

clean:
	dh_testdir
	dh_clean

build:
	dh_testdir

binary-indep:

binary-arch: build
	dh_testdir
	dh_testroot
	#
	# set up -base tree
	dh_installdirs -pthinkpad-base etc/devfs/conf.d
	cp debian/thinkpad-base.devfs $(DESTDIR_BASE)/etc/devfs/conf.d/thinkpad
	dh_installman -pthinkpad-base man/thinkpad.4
	#
	# set up -source tree
	dh_installdirs -pthinkpad-source usr/src/modules/thinkpad/debian usr/src/modules/thinkpad/2.5
	cp -a drivers include $(DRIVERTREE)/2.5
	cp -a 2.2 $(DRIVERTREE)
	cp -a 2.4 $(DRIVERTREE)
	cp -a debian/thinkpad-modules.d/* debian/copyright $(DRIVERTREE)/debian
	chmod +x $(DRIVERTREE)/debian/rules $(DRIVERTREE)/debian/buildpkg
	sed -e "s!\$$OURVERSION!$(OURVERSION)!" debian/thinkpad-modules.changelog.sed > $(DRIVERTREE)/debian/changelog.sed
	cat debian/changelog >> $(DRIVERTREE)/debian/changelog.sed
	chown -R root.src $(DRIVERTREE)
	find $(DRIVERTREE) -type d | xargs chmod 775
	tar -C $(DESTDIR_SOURCE)/usr/src -c -v -z -f $(DESTDIR_SOURCE)/usr/src/thinkpad.tar.gz modules/thinkpad
	rm -r $(DESTDIR_SOURCE)/usr/src/modules
	#
	dh_installdebconf
	dh_installmodules
	mv $(DESTDIR_BASE)/etc/modutils/thinkpad-base $(DESTDIR_BASE)/etc/modutils/thinkpad
	dh_installdocs README TECHNOTES
	dh_installchangelogs ChangeLog
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary:	binary-indep binary-arch

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