Building of a module (driver) linux kernel by using of configure, automake, autoconf and other autotools.

Modules of kernel Linux are files with the.ko extension. As a rule the insmod command or modprobe command is used for loading of the module team, or the modprobe team is used. For unloading of the module the command rmmod is used. For viewing of the list of the loaded modules there is a lsmod command. For getting of the information about the module the modinfo command is used.

Here is an example for module building by using of autotools:
1. Let's create a directory for the project module.
2. Let's create the directory src in the directory module.
3. Let's create the file module_hello.c in src

/*  src/module_hello.c */

#include <linux/init.h>
#include <linux/module.h>

static int __init
   printk("Hello, world!\n");
   return 0;


static void __exit
   printk("Goodbye, world!\n");


MODULE_AUTHOR("noname ");
MODULE_DESCRIPTION("\"Hello, world!\" test module");

The building algorithm of the kernel module by means of autotools differs from building algorithm of a simple program or library. It is required to create two more additional Makefile.

Let's create a file in the root directory of the module (in the directory module):



The keyword SUBDIRS means that the source files for building are in this directory.

The file named should be also created in the directory src with the following content:

# src/

EXTRA_PROGRAMS = automake_dummy 
automake_dummy_SOURCES = module_hello.c 
module_DATA = module_hello.o 
include ../Makefile.common

automake_dummy_SOURCES — are sources which the module will be build of.

module_DATA = module_hello.o - the module name.

include ../Makefile.common - it is necessary to connect the external file which will run the module building. It has to exist in the root catalog of the module.

In the root directory of the module (in the directory module) let's create the file named Makefile.common

# Makefile.common
moduledir = @moduledir@

export module_DATA

$(module_DATA): $(automake_dummy_SOURCES) 
	mv Makefile Makefile.automake 
	cp $(srcdir)/../Makefile.kernel Makefile 
        ARCH="x86" CC="gcc" M=$(PWD) modules\
	mv Makefile.automake Makefile 

CLEANFILES = $(module_DATA) .$(module_DATA).flags $(module_DATA:.o=.mod.c) $(module_DATA:.o=.@kernelext@) *~

Here a replacement of Makefile and Makefile.kernel takes place and module building is started. Very important parameter of building is initialization of variable KERNEL_LOCATION. It will be initialized in configure, through transfer of parameters. Or it is possible to replace the line:



$(MAKE) -C /lib/modules/$(shell uname -r)/build \

The last file to be created is the Makefile.kernel file. It has to exist in a root directory of the module (in the directory module):

#  Makefile.kernel
MI_OBJS      = $(module_DATA)

all clean:
	mv Makefile.automake Makefile
	$(MAKE) $@

That is all.

Let's create by using of autoscan. This program creates the file configure.scan which is the prototype of

Let's run the following:


Let's edit the configure.scan and then rename it into

#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.



# Checks for programs.

# Checks for libraries.

# Checks for header files.

# Checks for typedefs, structures, and compiler characteristics.

# Checks for library functions.


The macro of AC_PATH_KERNEL_SOURCE adds to configure an option - with-kerneldir, in which it is necessary to set the path (" / to $ lib/modules/(to shell uname - r) / build"). If this parameter will not be set, the path will be found automatically and it will be set by default. This parameter is needed for cross-compilation.
If this parameter is not specified, the path will be found automatically.

THAT IS ALL! Now let's run the following sequence and Makefile is ready.

aclocal - creates aclocal.m4.

autoconf - the utility creates the script configure in accordance with macros which are listed in the file `'.

autoheader — creates the header file (

touch NEWS README AUTHORS ChangeLog (these files are needed for automake)

automake --add-missing - the program creates the files "" based on the files "".

configure — creates Makefile

make — creates a module