DKMS package guidelines

From ArchWiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Arch package guidelines

32-bitCLRCMakeCrossDKMSEclipseElectronFontFree PascalGNOMEGoHaskellJavaKDEKernelLispMesonMinGWNode.jsNonfreeOCamlPerlPHPPythonRRubyRustShellVCSWebWine

Here are some guidelines to follow when creating a DKMS package.

Package name

DKMS packages are named by appending "-dkms" to the original package name.

The variable $_pkgname is often used below $pkgname to describe the package name minus the "-dkms" suffix (e.g. _pkgname=${pkgname%-*}

Dependencies

Dependencies should be inherited from the original version with dkms added and linux-headers removed (as it is listed by the dkms package as optional).

Build source location

Build sources should go into (this is the default build directory for DKMS):

/usr/src/PACKAGE_NAME-PACKAGE_VERSION

In the package directory, a DKMS configuration tells DKMS how to build the module (dkms.conf), including the variables PACKAGE_NAME and PACKAGE_VERSION.

  • PACKAGE_NAME - the actual project name (usually $_pkgname or $_pkgbase).
  • PACKAGE_VERSION - by convention this should also be the $pkgver.

Patching

The sources can be patched either directly in the PKGBUILD or through dkms.conf.

Module loading automatically in .install

Loading and unloading modules should be left to the user. Consider the possibility a module may crash when loaded.

Also, please note that you do not have to call depmod explicitly to update the dependencies of your kernel module. Pacman is now calling DKMS dkms install and dkms remove automatically as hooks. dkms install is making sure depmod is called at the end of its process. dkms install depends on dkms build (to build the source against the current kernel), which itself depends on dkms add (to add a symlink from /var/lib/dkms/<package>/<version>/source to /usr/src/<package>).

Example

Here is an example package that edits dkms.conf according to the package name and version.

PKGBUILD

PKGBUILD
# Maintainer: foo <foo(at)example(dot)org>
# Contributor: bar <bar(at)example(dot)org>

_pkgbase=example
pkgname=example-dkms
pkgver=1
pkgrel=1
pkgdesc="The Example kernel modules (DKMS)"
arch=('i686' 'x86_64')
url="https://www.example.org/"
license=('GPL2')
depends=('dkms')
conflicts=("${_pkgbase}")
install=${pkgname}.install
source=("${url}/files/tarball.tar.gz"
        'dkms.conf'
        'linux-3.14.patch')
md5sums=(use 'updpkgsums')

prepare() {
  cd ${_pkgbase}-${pkgver}

  # Patch
  patch -p1 -i "${srcdir}"/linux-3.14.patch

}

package() {
  # Install
  make DESTDIR="${pkgdir}" install

  # Copy dkms.conf
  install -Dm644 dkms.conf "${pkgdir}"/usr/src/${_pkgbase}-${pkgver}/dkms.conf

  # Set name and version
  sed -e "s/@_PKGBASE@/${_pkgbase}/" \
      -e "s/@PKGVER@/${pkgver}/" \
      -i "${pkgdir}"/usr/src/${_pkgbase}-${pkgver}/dkms.conf

  # Copy sources (including Makefile)
  cp -r ${_pkgbase}/* "${pkgdir}"/usr/src/${_pkgbase}-${pkgver}/
}

dkms.conf

dkms.conf
PACKAGE_NAME="@_PKGBASE@"
PACKAGE_VERSION="@PKGVER@"
MAKE[0]="make --uname_r=$kernelver"
CLEAN="make clean"
BUILT_MODULE_NAME[0]="@_PKGBASE@"
DEST_MODULE_LOCATION[0]="/kernel/drivers/misc"
AUTOINSTALL="yes"

.install

Now pacman has DKMS hooks implemented, you do not have to specify DKMS-specific configuration in your .install file. Calls to dkms install and dkms remove will be automatic.