1

What does it mean to build a module against any kernel source tree present on file system and not just those happened to be install in /lib/ at sometime? Concretely, I have come across these two examples 1. and 2. but both of them are largely vague. The second has some code but it fails to say what the code is actually doing.

Community
  • 1
  • 1
user1343318
  • 2,093
  • 6
  • 32
  • 59

1 Answers1

1

/lib/modules/$(shell uname -r)/build refers to a directory that should contain the source tree; it's usually a symlink to a folder in /usr/src. If the source tree is not installed, it's a dangling symlink or an empty directory.

uname -r gives the release string for the running kernel (try it). This is used to label a subdirectory of /lib/modules, where the modules for that kernel are stored. By default, the kernel will not load a module that was compiled for a different version (e.g., 3.13.5 vs 3.13.4), so if you are writing you own module, you must compile it every version you want to use it with.

Since the makefile in your first link uses uname -r, it will only work for the currently running kernel; if you want to use it unchanged for a different version, you'd have to reboot with that version. The questioner is asking for a simple way to modify the makefile such that it could be used to compile a module for any kernel version, not just the one that is running. If you are reading the second link, which is an introduction to writing kernel modules, you do not have to be concerned with this issue.

CodeClown42
  • 11,194
  • 1
  • 32
  • 67