#!/usr/bin/make -f
#
# debian/rules for nvidia-graphics-modules-*-amd64
#
# GNU copyright 1997 to 1999 by Joey Hess.
# Copyright (c) 1999-2001 Herbert Xu <herbert@debian.org>
# Fixes by Steve Kowalik for the New Alsa-Source.
# Customized by Randall Donald for nvidia-kernel-source



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

SHELL := sh -e

revision := $(shell \
	head -1 debian/changelog | \
	sed 's/^.*(\(.*\)).*$$/\1/' \
)
version := 2.6.18-4
flavours := amd64
#krevision := $(shell \
#	zcat /usr/share/doc/kernel-build-$(version)/changelog.Debian.gz | \
#	head -1 | sed 's/^.*(\(.*\)).*$$/\1/' \
#	)


unpack: unpack-stamp
unpack-stamp:
	tar zxf /usr/src/nvidia-kernel-legacy-source.tar.gz
	cp debian/changelog modules/nvidia-kernel-legacy/debian
	touch unpack-stamp

build: unpack-stamp

clean:
      	
	$(RM) unpack-stamp install-stamp
	$(RM) -r kernel-source-$(version) build-* modules
	$(RM) *.deb
	dh_clean

# Build architecture-independent files here.
binary-indep:
	     dh_installdirs
	     dh_installchangelogs
	     dh_installdocs
	     dh_install
	     dh_fixperms
	     dh_gencontrol
	     dh_builddeb



# Build architecture-dependent files here.
binary-arch: build
	cd modules/nvidia-kernel-legacy; \
		cp ../../control.template debian/ ; \
	   	sed -e 's/^Source.*$$/Source: nvidia-graphics-legacy-modules-amd64/' debian/control.template > debian/control.template.new; \
		mv debian/control.template.new debian/control.template ; \
	   	for i in $(flavours); do \
		DO_NOT_PATCH_NV=$(DO_NOT_PATCH_NV) KERNEL_DEPENDS=y MODVERS=$(revision) KSRC=/usr/src/linux-headers-$(version)-$$i KVERS=$(version)-$$i debian/rules binary_modules ; \
		KSRC=/usr/src/linux-headers-$(version)-$$i KVERS=$(version)-$$i debian/rules clean; \
	done
	mv modules/*.deb .
	for p in *.deb; do \
		dpkg-distaddfile $$p "non-free/x11" optional; \
	done
	mv *.deb ..

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

