#!/usr/bin/make -f
# -*- makefile -*-
# 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

PACKAGE=ppscsi-drivers
MA_DIR ?= /usr/share/modass
-include $(MA_DIR)/include/generic.make
-include $(MA_DIR)/include/common-rules.make
export CC

MAJOR=$(shell echo $(KVERS) | sed -e 's/\(...\).*/\1/')

CFLAGS = -Wall -g

configure: configure-stamp
configure-stamp:
	dh_testdir
	touch configure-stamp

build: build-stamp
build-stamp: configure-stamp 
	dh_testdir
	cat upstream/* | patch -p2 -f || true
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp
	rm -rf scsi

	# Add here commands to clean up after the build process.
	-$(MAKE) clean

	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs
	cp scsi/* addons/* README.ppscsi debian/ppscsi-source/usr/src/modules/ppscsi/
	cd debian && cp -a control control.modules.in changelog rules copyright compat docs $(CURDIR)/debian/ppscsi-source/usr/src/modules/ppscsi/debian
	cd debian/ppscsi-source/usr/src && tar c modules | bzip2 -9 > ppscsi.tar.bz2 && rm -rf modules

binary-arch: build install

binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installkpatches
	dh_installchangelogs 
	dh_installdocs
	dh_installexamples
#	dh_install
#	dh_installmenu
#	dh_installdebconf	
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_installinit
#	dh_installcron
#	dh_installinfo
	dh_installman
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
#	dh_perl
#	dh_python
#	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

kdist_clean:
	dh_clean
	rm -f *.o *.ko

kdist_config: prep-deb-files
	@test $(MAJOR) = 2.6 || (echo 'Only kernel 2.6.x is supported by this package. Please use the kernel patch instead! (The patch is part of this package or included in kernel-patch-ppscsi-2.4, for kernel 2.4.x)' ; exit 1)

binary-modules: kdist_config
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs -p$(PKGNAME) lib/modules/$(KVERS)/ppscsi
	make KERNEL_DIR=$(KSRC)
	cp *.ko $(CURDIR)/debian/$(PKGNAME)/lib/modules/$(KVERS)/ppscsi
	dh_installdocs
	dh_installchangelogs
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_gencontrol -- -v$(VERSION)
	dh_md5sums
	dh_builddeb --destdir=$(DEB_DESTDIR)


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