read

The DKMS framework makes it easy to create and distribute an out-of-tree kernel module, as demonstrated in part 1. However, the process is rather manual (read: error prone) for packages that will be updated regularly. This post is going to look at a way to set up the debian packaging components to make updating easier. A basic familiarity with debian packaging is assumed.

As an example, we’ll use an updated version of the apple-gmux-dkms source tree from part 1, which can be donwloaded here. This time it’s not necessary to extract it to /usr/src; just extract it to wherever you like in your home directory.

The layout of the files has changed a little bit. The source file and makefile are still in the root of the tree, but dkms.conf has been moved into the debian directory and renamed to apple-gmux-dkms.dkms.in. We’ll talk more about this file later. Most of the remaining files are the typical debian packaging boilerplate; examining these files is left as an exercise for the reader. The one file we will take a closer look at is debian/rules.

The first item of note in the rules file is that it grabs the version number for the package from the changelog with the following.

version := $(shell dpkg-parsechangelog | grep '^Version:' | cut -d' ' -f2 | cut -d- -f1)  

This eliminates the error-prone process of making sure the version gets updated throughout the package by making the changelog the canonical location for the version number. Towards that end, the rules file also has a rule to auto-generate the DKMS configuration file, debian/apple-gmux-dkms.dkms, from apple-gmux-dkms.dkms.in. This file is identical to the dkms.conf file used in part 1, except that the version number has been replaced by the string @VERSION@. A sed command is used to generate the config file with @VERSION@ replaced by the actual version number.

debian/apple-gmux-dkms.dkms: debian/apple-gmux-dkms.dkms.in  
    sed s/@VERSION@/$(version)/g $< > $@  

The other item worth noting is that there’s a DKMS debhelper, dh_dkms, which makes setting up the rules file a breeze when used along with the dh helper (for more information about the dh helper consult the man page). We just need a rule to let dh do its thing:

%:  
    dh $@  

Then we need to override a few of the debhelper commands to install files for the DKMS package and to invoke dh_dkms. We also need to clean up the auto-generated DKMS configuration file, and since we’re not actually building anything to generate the package we override the build command to do nothing. This leaves us with the following override rules.

override_dh_clean:
        dh_clean debian/apple-gmux-dkms.dkms

override_dh_auto_build:
        :

override_dh_auto_install: debian/apple-gmux-dkms.dkms
        dh_install apple-gmux.c Makefile /usr/src/apple-gmux-$(version)/
        dh_dkms

override_dh_auto_install_indep: debian/apple-gmux-dkms.dkms

That’s it! Now you can build the binary and source packages with the usual debian packaging commands. When it comes time to update the package, you only need to update the version number in the changelog to get it updated throughout the package.

Blog Logo

Seth Forshee


Published

Image

Seth Forshee's Blog

Back to Overview