-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Vim can be a hard-to-use editor, especially in large projects like the Linux kernel, but certain plugins and distros like Janus (which I personally use) can make it much easier, especially when configured correctly. By default, Syntastic won't work out of the box with such a project because of the complex flags and include directories that the Linux Makefile uses, but Syntastic has no clue how to reproduce them when invoking gcc. So this tutorial is going to be precisely about this.
First of all, I'm going to be assuming you want to write an out-of-tree kernel module. If you don't know how to do this, you will need two special files:
-
a
Makefile
containing:KDIR = /usr/src/linux-so2 kbuild: make -C $(KDIR) M=`pwd`
-
a
Kbuild
file with contents in the likes of:EXTRA_CFLAGS = -Wall -g obj-m = my-module.o
Of course, you also need some kernel sources (which you can get from here). In this example, I am using some Linux 3.13 sources symbolically linked to the folder /usr/src/linux-so2
.
What is happening is that, by invoking Makefile, in return it changes the directory to that of the kernel source (KDIR
) and invokes the Makefile found there. The Linux kernel Makefile is a huge beast that, amongst other things, checks for the M environment variable (set to pwd
) so that it knows to return to our folder when compiling our module.
The second file (Kbuild
) contains further details about our module (how it needs to be compiled, which source files are to be used, etc). Without further ado, we will see that EXTRA_CFLAGS
will be added to the set of CFLAGS
already provided by the current kernel source we are using.
So the Makefile
of our module does little more than call the kernel one, so let's explore that a bit. What we're looking to find are the CFLAGS
that gcc is using, so we can copy and pass them to syntastic and it can emulate what gcc is doing.
It turns out that the CFLAGS are dynamically set, but using the command
make V=1
in our module folder, we can activate verbose output for module compilation. This gives us access to all parameters used by gcc. A sample output may be: