Open vladimiroltean opened 9 years ago
:%s/\ /\r/g
Nit pick: this is better written as :%s/ /\r/g
.
- by default, Syntastic treats include paths as relative to the configuration file. Obviously, we need to change those paths so that they are absolute (prefix them with
$(KDIR)
as described above, in our case/usr/linux/so2/
)
That might be achieved like this:
:%s!\m^-I\zs\ze[^/]!/usr/linux/so2/!
- for some reason, Syntastic's interpretation of
-D
macro predefinitions is different than gcc. It can be seen in the last 3 lines of the above text that KBUILD_BASENAME and KBUILD_MODNAME depend upon KBUILD_STR, but Syntastic doesn't know how to resolve that.
You don't understand. Syntastic config files does exactly two things, and both are trivial: (1) change -Irelative/path
to -I/absolute/path
, and (2) escape lines to survive shell expansion when passed to the compiler. If you write -D"KBUILD_STR(s)=#s"
, the result of escaping is '-D"KBUILD_STR(s)=#s"'
, which means after shell expansion gcc actually gets to see the argument -D"KBUILD_STR(s)=#s"
. What you want it to see instead is -DKBUILD_STR(s)=#s
, and that's what you have to write in the config file. That is, unquote everything. Of course, the same also applies to the other -D
s.
let g:syntastic_c_config_file = '.syntastic_c.conf'
Since you just wrote a bunch of options to a file named .syntastic_c_config
, this is confusing. :)
To check what we have done, write something to a C file, then
:w
to save it.
It's probably far more informative to enable debugging and look at the arguments syntastic passes to gcc: set g:syntastic_debug
to 1, run the checker, run :mes
, and look for makeprg
. This way, you'll probably find out you also need:
let g:syntastic_c_no_default_include_dirs = 1
let g:syntastic_c_compiler_options = ''
If all goes well, you should now have Syntastic working with the Linux kernel.
You might want to rephrase this.
Thanks, I have updated the wiki. I don't think g:syntastic_c_no_default_include_dirs
is needed, since -nostdinc
is already the first parameter in the kernel makefile. Writing that to the vimrc also makes it interfere with everything else that does use the default include dirs.
I don't think
g:syntastic_c_no_default_include_dirs
is needed
With the default g:syntastic_c_no_default_include_dirs
, syntastic adds -I. -I.. -Iinclude -Iincludes -I../include -I../includes
. You don't have to take my word for it though, you can check that in the debug output.
Writing that to the vimrc also makes it interfere with everything else that does use the default include dirs.
Adding -I. -I.. -Iinclude -Iincludes -I../include -I../includes
is useless in the vast majority of cases. There are a few cases when it's potentially harmful, specifically when the build process wants -nostdinc
.
Syntastic's interpretation of
-D
macro predefinitions is a little different fromgcc
, because of the way parameters in the config file are treated.
Syntastic doesn't care about macro definitions, only gcc does. Syntastic however quotes parameters in the config file to make them survive shell expansions. In makefiles the parameters are already quoted (for the same reason), so if you copy them unchanged to the config file the result is double quoting, which is not what you want.
Syntastic automatically encloses each parameter in quotes.
It doesn't. It only quotes parameters that need quoting.
Updated wiki again.
Syntastic internally encloses some of its parameters to
gcc
in double quotes
sigh Actually syntastic uses single quotes...
However, it can be seen in the last 3 parameters that
KBUILD_BASENAME
andKBUILD_MODNAME
depend uponKBUILD_STR
.
This isn't relevant for either syntastic, or make. The point is they include (...)
and #
, which have a special meaning to the shell and thus need to be escaped.
gcc will think that by
''-D"KBUILD_STR(s)=#s"''
we want to define the preprocessor macro namedKBUILD_STR(s)=#s
It's actually '-D"KBUILD_STR(s)=#s"'
, with one set of single quotes. Single quotes are doubled in the debug output because log functions print Vim strings, rather than raw values.
Also, any particular reason why you have now dropped the reference to g:syntastic_c_compiler_options
? If you omit that syntastic adds a flag -std=gnu99
, which is not what you want. I updated the wiki for gcc to (hopefully) make more sense.
Corrected again.
Hi,
This is not an issue, but I've been trying to properly configure Syntastic for the Linux kernel, and there's not one online tutorial that I could find about this, so I figured this might be of help.
Vladimir
https://github.com/vladimiroltean/blog/wiki