[pkg-nvidia-devel] Work towards 2.6.29 support.

Lennart Sorensen lsorense at csclub.uwaterloo.ca
Fri Mar 27 23:03:48 UTC 2009


I have been working towards getting the nvidia 180.29 package to work
with kbuild so that it will build with 2.6.29.  I have it building for
i386 with a small bit of manual work now using m-a.

Here are my changes so far.  i386 is hardcoded and needs to be replaced
with something that detects the right architecture instead.

So changes so far:
delete nvidia-kernel/debian/conf.mk
delete nvidia-kernel/makefile
delete nvidia-kernel/nv-kernel.o

So basicly stop including those files in the nvidia-kernel-source package.

Move source files to nv subdir.  This really is necesary.  I did this
before, so we already know how.

install nv-kernel.o from i386 and x86_64 with appropritate names like
nv-kernel.o.i386 and nv-kernel.o.x86_64 or whatever works with the
architecture detection code that isn't written yet.

Replacement debian/rules file:
#!/usr/bin/make -f


CFLAGS = -Wall -g
ifneq (,$(filter noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O2
endif
ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
	NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
	MAKEFLAGS += -j$(NUMJOBS)
endif

DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)


# Prefix of the target package name
PACKAGE		= nvidia-kernel

-include /usr/share/modass/include/generic.make
-include /usr/share/modass/include/common-rules.make

configure:


binary-modules:
	dh_testroot
	dh_prep

	# Build the modules
	$(MAKE) -C nv LINUXDIR=$(KSRC) KVERREL=$(KVERS)

	sed 's/#KVERS#/$(KVERS)/g' debian/control.template > $(CURDIR)/debian/control
	sed 's/#KVERS#/$(KVERS)/g' debian/dirs.template > $(CURDIR)/debian/dirs
	sed 's/#KVERS#/$(KVERS)/g' debian/override.template > $(CURDIR)/debian/override

	# Install the modules
	dh_installdirs
	install -m 0644 $(CURDIR)/debian/override $(CURDIR)/debian/nvidia-kernel-$(KVERS)/usr/share/lintian/overrides/nvidia-kernel-$(KVERS)
	install -m 0644 $(CURDIR)/nv/nvidia.ko $(CURDIR)/debian/nvidia-kernel-$(KVERS)/lib/modules/$(KVERS)/nvidia/nvidia.ko ; \

	dh_installdocs
	dh_installmodules
	dh_installchangelogs
	dh_installmodules
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_gencontrol -- -v$(VERSION)
	dh_md5sums
	dh_builddeb  --destdir=$(KPKG_DEST_DIR)
	dh_prep

clean:   unpatch
	if [ -f $(CURDIR)/debian/control.template ]; then \
		cp  $(CURDIR)/debian/control.template $(CURDIR)/debian/control; \
	fi

	dh_testroot
	rm -f build-stamp configure-stamp


	$(MAKE) clean SYSSRC=$(KSRC) -C $(CURDIR)/$(dirname) -f Makefile $(KPKG_EXTRAV_ARG)
        
	-rm $(CURDIR)/$(dirname)/gcc-check
	-rm $(CURDIR)/$(dirname)/cc-sanity-check
	
	-dh_clean

	-rm $(CURDIR)/debian/control
	-rm $(CURDIR)/debian/dirs
	-rm $(CURDIR)/debian/override


unpatch: 
	if [ -e patch-stamp ]; then \
	   dpatch deapply-all ; \
	   rm -rf patch-stamp debian/patched ; \
	fi

	
	   

# The kdist_configure target is called by make-kpkg modules_config. It
# should configure the module so it is ready for compilation (mostly
# useful for calling configure)
kdist_config kdist_configure:
	    $(ROOT_CMD) $(MAKE) $(MFLAGS) -f debian/rules configure

# the kdist_clean target is called by make-kpkg modules_clean. It is
# responsible for cleaning up any changes that have been made by the
# other kdist_commands (except for the .deb files created).
kdist_clean: 
	$(MAKE) -C nv LINUXDIR=$(KSRC) KVERREL=$(KVERS) clean

.PHONY: clean binary-modules
-------

New file nv/Makefile:
# Makefile -- For the nvidia module

#
# By default, the build is done against the running linux kernel source.
# To build against a different kernel source tree, set LINUXDIR:
#
#    make LINUXDIR=/path/to/kernel/source

SHELL=/bin/sh

.SUFFIXES:

ifndef LINUXDIR
RUNNING_REL := $(shell uname -r)

LINUXDIR := $(shell if [ -e /lib/modules/$(RUNNING_REL)/source ]; then \
		 echo /lib/modules/$(RUNNING_REL)/source; \
		 else echo /lib/modules/$(RUNNING_REL)/build; fi)
endif

ifndef O
O := $(shell if [ -e /lib/modules/$(RUNNING_REL)/build ]; then \
		 echo /lib/modules/$(RUNNING_REL)/build; \
		 else echo ""; fi)
#O := $(LINUXDIR)
endif

ifdef ARCH
MACHINE := $(ARCH)
else
MACHINE := $(shell uname -m)
endif

# Modules for all architectures
MODULE_LIST := nvidia.o

CLEANFILES = *.o *.ko .depend .*.flags .*.d .*.cmd *.mod.c .tmp_versions

# VERSION is not defined from the initial invocation.  It is defined when
# this Makefile is invoked from the kernel's root Makefile.

ifndef VERSION

ifdef RUNNING_REL

# SuSE has the version.h and autoconf.h headers for the current kernel
# in /boot as /boot/vmlinuz.version.h and /boot/vmlinuz.autoconf.h.
# Check these first to see if they match the running kernel.

BOOTVERSION_PREFIX = /boot/vmlinuz.

V := $(shell if [ -f $(BOOTVERSION_PREFIX)version.h ]; then \
	grep UTS_RELEASE $(BOOTVERSION_PREFIX)version.h | \
	cut -d' ' -f3; fi)

ifeq ($(V),"$(RUNNING_REL)")
HEADERFROMBOOT := 1
GETCONFIG := MAKEFILES=$(shell /bin/pwd)/.config
HAVECONFIG := y
endif

# On Red Hat we need to check if there is a .config file in the kernel
# source directory.  If there isn't, we need to check if there's a
# matching file in the configs subdirectory.

ifneq ($(HAVECONFIG),y)
HAVECONFIG := $(shell if [ -e $(LINUXDIR)/.config ]; then echo y; fi)
endif

ifneq ($(HAVECONFIG),y)
REL_BASE := $(shell echo $(RUNNING_REL) | sed 's/-.*//')
REL_TYPE := $(shell echo $(RUNNING_REL) | sed 's/[0-9.-]//g')
ifeq ($(REL_TYPE),)
RHCONFIG := configs/kernel-$(REL_BASE)-$(MACHINE).config
else
RHCONFIG := configs/kernel-$(REL_BASE)-$(MACHINE)-$(REL_TYPE).config
endif
HAVECONFIG := $(shell if [ -e $(LINUXDIR)/$(RHCONFIG) ]; then echo y; fi)
ifneq ($(HAVECONFIG),y)
RHCONFIG :=
endif
endif

ifneq ($(HAVECONFIG),y)
ifneq ($(0),$(LINUXDIR))
GETCONFIG += O=$(O)
endif
HAVECONFIG := $(shell if [ -e $(O)/.config ]; then echo y; fi)
endif

ifneq ($(HAVECONFIG),y)
$(error Cannot find a kernel config file)
endif

endif

CLEANCONFIG := $(shell if cmp -s $(LINUXDIR)/.config .config; then echo y; fi)
ifeq ($(CLEANCONFIG),y)
CLEANFILES += $(LINUXDIR)/.config .config $(LINUXDIR)/tmp_include_depends
endif

all: modules

modules: includes
	+ln -sf nv-kernel.o.i386 nv-kernel.o
	+make -C $(LINUXDIR) $(GETCONFIG) SUBDIRS=`/bin/pwd` NVSRCDIR=`/bin/pwd` modules

ifeq ($(HEADERFROMBOOT),1)

BOOTHEADERS = version.h autoconf.h
BOOTCONFIG = .config

CLEANFILES += $(BOOTHEADERS) $(BOOTCONFIG)

includes:: $(BOOTHEADERS) $(BOOTCONFIG)

version.h: $(BOOTVERSION_PREFIX)version.h
	rm -f $@
	ln -s $< $@

autoconf.h: $(BOOTVERSION_PREFIX)autoconf.h
	rm -f $@
	ln -s $< $@

.config: $(BOOTVERSION_PREFIX)config
	rm -f $@
	ln -s $< $@
endif

# This prepares an unused Red Hat kernel tree for the build.
ifneq ($(RHCONFIG),)
includes:: $(LINUXDIR)/.config $(LINUXDIR)/tmp_include_depends .config

$(LINUXDIR)/.config: $(LINUXDIR)/$(RHCONFIG)
	rm -f $@
	ln -s $< $@

.config: $(LINUXDIR)/$(RHCONFIG)
	rm -f $@
	ln -s $< $@

$(LINUXDIR)/tmp_include_depends:
	echo all: > $@
endif

clean cleandir:
	rm -rf $(CLEANFILES)

$(MODULE_LIST)::
	make modules

install:
	make -C $(LINUXDIR) $(GETCONFIG) SUBDIRS=`/bin/pwd` NVSRCDIR=`/bin/pwd` modules_install

else

# Check for kernel versions that we don't support.

BELOW26 := $(shell if [ $(VERSION) -lt 2 -o $(PATCHLEVEL) -lt 6 ]; then \
		echo y; fi)

ifeq ($(BELOW26),y)
$(error Only 2.6.x and later kernels are supported \
	($(VERSION).$(PATCHLEVEL).$(SUBLEVEL)))
endif

# This needs to go before all other include paths.
CC += -I$(NVSRCDIR)

include $(NVSRCDIR)/Makefile.kbuild

endif

.PHONY: includes
-------
Small patch to conftest.sh although that might not be needed.  Still
testing that.  Basicly it has to prevent conftest.sh from trying to
overwrite the new Makefile:
--- nvidia-kernel/nv/conftest.sh	2009-02-28 21:46:06.000000000 -0500
+++ nvidia-kernel.kbuild/nv/conftest.sh	2009-03-27 18:22:17.000000000 -0400
@@ -1152,7 +1152,7 @@
         # 2.6 and newer kernels, and the old Makefile for kernels older
         # than 2.6.
         #
-        rm -f Makefile
+        #rm -f Makefile
         RET=1
         VERBOSE=$6
         FILE="linux/version.h"
@@ -1215,7 +1215,7 @@
             if [ "$SELECTED_MFILE" = "Makefile.kbuild" -a -f Makefile.rmlite ]; then
                 SELECTED_MFILE=Makefile.rmlite
             fi
-            ln -s $SELECTED_MFILE Makefile
+            #ln -s $SELECTED_MFILE Makefile
         else
             echo "If you are using a Linux 2.4 kernel, please make sure";
             echo "you either have configured kernel sources matching your";
-------

Any comments?

So it worked for my on i386 using 2.6.29 headers
(after I added the missing Makefile_32.cpu to the
/usr/src/linux-headers-2.6.29-1-common/arch/x86/ directory).  I have
filed a bug report on the linux-headers package about this.

This may also go along way towards being built by the linux-modules
package.

-- 
Len Sorensen



More information about the Pkg-nvidia-devel mailing list