Compiling a kernel module after “make clean” on the sources.

This post was written by eli on May 19, 2011
Posted Under: Linux kernel

The textbook says, that if one wants to compile a module against a kernel, the headers must be there. Those who run distribution kernels are urged to apt-get or yum-install something, and their trouble is over. People like me, who cook their own food and download vanilla kernels, need to handle this themselves.

In the old times, I used to have the kernel compiled on the disk, but nowadays the kernel subdirectory takes a few Gigabytes after compilation, so one has to do a “make clean” sooner or later. Which should be OK, since the following comment can be found in the kernel source’s Makefile, in its very root directory:

# make clean     Delete most generated files
#                Leave enough to build external modules

But unfortunately, it’s not possible to compile any module after “make clean”. It blows with a nasty error message. (Ehm, see update at the bottom)

As it turns out, “make clean” removes two header files, whose absence kills the possibility to compile a module:  include/generated/asm-offsets.h and include/generated/bounds.h. As a matter of fact, the removal of these two files is the only change in the “include” subdirectory.

So a quick workaround is to make a copy of the “include” subdirectory, run “make clean” and then restore “include” to its pre-make-clean state.

Which make you wonder why those files are removed in the first place. Someone overlooked this issue? No, no and no. Is there any real reason to remove these files? I don’t know. Has this issue been fixed since 2.6.35? I’ll check it sometime.

If you know something I don’t, please comment below.

Update (Oct 1st, 2015):

$ make prepare scripts

on the machine that the kernel runs on solves this on v3.16.

Update (May 4th, 2016): Maybe this?

$ make modules_prepare

Will try next time. See Documentation/kbuild/modules.txt on your favorite kernel tree.

Add a Comment

required, use real name
required, will not be published
optional, your blog address