#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1


# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

#sysname for arm is arm_linux26, sysname for i386 is i386_linux26
SYSNAME=`uname -m |  sed -e 's/i686/i386/'`_linux26
CFLAGS = -Wall -g

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O2
endif

config.status: configure
	dh_testdir
	# Add here commands to configure the package.
	# Yes, we need the real diablo kernel source to configure & compile openafs
	mkdir -p $(CURDIR)/builddir
	cd $(CURDIR)/builddir && tar xfi /usr/src/kernel-source-diablo.tar.bz2
	cd $(CURDIR)/builddir/kernel-source-diablo && make n800_defconfig && make modules_prepare
	cd $(CURDIR)/builddir && ../configure -with-afs-sysname=$(SYSNAME) --with-krb5-conf=/usr/bin/krb5-config --prefix=/usr --sysconfdir=/etc --disable-pam --enable-namei-fileserver --enable-supergroups --with-linux-kernel-headers=$(CURDIR)/builddir/kernel-source-diablo/
	

build: build-stamp

build-stamp:  config.status
	dh_testdir

	# Add here commands to compile the package.
	cd builddir && $(MAKE)

	touch $@

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp 

	# Add here commands to clean up after the build process.
	rm -fr builddir
	#$(MAKE) distclean
ifneq "$(wildcard /usr/share/misc/config.sub)" ""
	cp -f /usr/share/misc/config.sub config.sub
endif
ifneq "$(wildcard /usr/share/misc/config.guess)" ""
	cp -f /usr/share/misc/config.guess config.guess
endif


	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs

	#rm -fr $(CURDIR)/debian/openafs
	mkdir -p $(CURDIR)/debian/openafs/afs
	# Add here commands to install the package into debian/openafs.
	cd builddir && $(MAKE) prefix=$(CURDIR)/debian/openafs/usr install
	mkdir -p $(CURDIR)/debian/openafs/etc/init.d
	cp $(CURDIR)/debian/openafs.init $(CURDIR)/debian/openafs/etc/init.d/openafs
	rm -fr $(CURDIR)/debian/openafs/usr/libexec
	rm -fr $(CURDIR)/debian/openafs/usr/share/doc
	mkdir -p $(CURDIR)/debian/openafs/etc/openafs
	cp $(CURDIR)/src/afsd/CellServDB $(CURDIR)/debian/openafs/etc/openafs
	cp $(CURDIR)/debian/ThisCell $(CURDIR)/debian/openafs/etc/openafs
	#cp $(CURDIR)/debian/SuidCells $(CURDIR)/debian/openafs/etc/openafs
	cp $(CURDIR)/debian/cacheinfo $(CURDIR)/debian/openafs/etc/openafs
	mv $(CURDIR)/debian/openafs/usr/bin/kpasswd $(CURDIR)/debian/openafs/usr/bin/kpasswd.afs
	mv $(CURDIR)/debian/openafs/usr/bin/compile_et $(CURDIR)/debian/openafs/usr/bin/compile_et.afs
	touch  $(CURDIR)/debian/openafs/etc/openafs/SuidCells


# Build architecture-independent files here.
binary-indep:
# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs 
	dh_installdocs
#	dh_installexamples
#	dh_install
#	dh_installmenu
#	dh_installdebconf	
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_python
	dh_installinit -r 
#	dh_installcron
#	dh_installinfo
#	dh_installman
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
#	dh_perl
	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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