#!/usr/bin/make -f
# debian/rules for device3dfx to build device3dfx-source
#
# Copyright © 1999 Steve Haslam
# Copyright © 2003, 2004, 2006-2008, 2011, 2013, 2015 Guillem Jover
#
# Distributable under the terms of the GNU GPL version 2 (or later).

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

pname = device3dfx
psource = $(pname)-source
pmodule = $(pname)-module

DEB_RELEASE_DATE ?= $(shell dpkg-parsechangelog --show-field Date)

build-indep build-arch build:

.PHONY: build-indep build-arch build

clean:
	dh_testdir
	dh_testroot
	dh_clean

target = debian/$(psource)/usr/src/modules/$(pname)

INSTALL = install
INSTALL_DIR = $(INSTALL) -d -m755
INSTALL_DATA = $(INSTALL) -m644
INSTALL_SCRIPT = $(INSTALL) -m755

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	
	$(INSTALL_DIR) $(target)
	$(INSTALL_DATA) Makefile *.c $(target)
	$(INSTALL_DIR) $(target)/kbuild
	$(INSTALL_DATA) kbuild/* $(target)/kbuild/
	$(INSTALL_DIR) $(target)/debian/source
	$(INSTALL_DATA) debian/source/* $(target)/debian/source/
	$(INSTALL_DATA) debian/module/* $(target)/debian/
	sed -n '0,/^$$/p' debian/control > $(target)/debian/control.modules.in
	cat debian/control.templ >> $(target)/debian/control.modules.in
	chmod 644 $(target)/debian/control.modules.in
	$(INSTALL_DATA) $(target)/debian/control.modules.in \
	                $(target)/debian/control
	$(INSTALL_DATA) debian/compat debian/copyright debian/changelog $(target)/debian/
	$(INSTALL_SCRIPT) debian/rules $(target)/debian
	tar -C debian/$(psource)/usr/src --mtime="$(DEB_RELEASE_DATE)" \
	  -cvJf debian/$(psource)/usr/src/$(pname).tar.xz modules/$(pname)
	rm -r debian/$(psource)/usr/src/modules

testmodule: install
	tar -C .. -xvJf debian/$(psource)/usr/src/$(pname).tar.xz

binary-indep: install
	dh_testdir
	dh_testroot
	dh_installdocs
	dh_installexamples
	dh_installchangelogs
	dh_link
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary-arch: install
	# Nothing to do.

binary: binary-indep binary-arch


PACKAGE := $(pmodule)

MA_DIR ?= /usr/share/modass

-include $(MA_DIR)/include/generic.mk
-include $(MA_DIR)/include/common-rules.mk

kdist_config: prep-deb-files

kdist_configure: kdist_config

kdist_clean: clean
	dh_testdir
	dh_testroot
	dh_clean
	
	$(MAKE) clean

binary-modules: prep-deb-files
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	
	$(MAKE) install_modules DESTDIR=debian/$(PKGNAME)
	
	dh_installdocs
	dh_installexamples
	dh_installmodules
	dh_installchangelogs
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_gencontrol -- -v"$(VERSION)"
	dh_md5sums
	dh_builddeb --destdir=$(DEB_DESTDIR)

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