#!/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

ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	INSTALL_PROGRAM += -s
endif

# The target kernel version is defined explicitly, 
# it could be different from the using on a build machine 
export KVER ?= 3.11.0-18-generic
export PKGNAME=netfpga
KERNELDIR ?= /lib/modules/$(KVER)/build

build: build-module build-utils

build-module: 
	dh_testdir
	dh_prep
	dh_installdirs lib/modules/$(KVER)/kernel/drivers/
	# Build the module 
	$(MAKE) KVER=$(KVER) KERNELDIR=$(KERNELDIR) module
	touch build-stamp

build-utils: 
	dh_testdir
	dh_prep
	dh_installdirs usr/local/sbin usr/local/bin
	# Build the utils
	$(MAKE) utils

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp 
	$(MAKE) clean
	dh_clean 

install:
	dh_testdir
	dh_testroot
	dh_installdirs usr/local/bin usr/local/sbin \
        	lib/modules/$(KVER)/kernel/drivers/ \
		usr/local/netfpga/bitfiles
	dh_install bitfiles/cpci.bit bitfiles/cpci_reprogrammer.bit \
		usr/local/netfpga/bitfiles
	dh_install lib/scripts/cpci_reprogram/cpci_reprogram.pl \
		lib/scripts/cpci_config_reg_access/dumpregs.sh \
		lib/scripts/cpci_config_reg_access/loadregs.sh \
		usr/local/sbin
	dh_install lib/scripts/grub_update/grub2_update.sh \
		usr/local/netfpga/scripts
	dh_installmodules
#	dh_usrlocal
	GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL=1 $(MAKE) install \
	DESTDIR=$(CURDIR)/debian/netfpga
	dh_installdeb

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

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
#	dh_installchangelogs ChangeLog
#	dh_installdocs
#	dh_gconf
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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