Using Flycheck/Flymake on Kernel Source Tree

Using flycheck/flymake on kernel source tree

I'd been thinking of doing this myself - here's what I've got:

You need to find the base of the kernel source tree, so the default flymake deal of looking for Makefile is counter productive. We'll add our own file which doubles for locating the source base, and for wrapping the normal kernel makefile:

Add a file flymake.mk to the base of the kernel source tree (configure for your own cross-compilation needs):

ARCH=mips
CROSS_COMPILE=mips-linux-gnu-

export ARCH
export CROSS_COMPILE

.PHONY: check-syntax
check-syntax:
make -f Makefile $(patsubst %_flymake.o,%.o,$(patsubst %.c,%.o,$(CHK_SOURCES)))

The gist is to strip out "_flymake.c" and only compile the real file, and build the file for real, rather than just for syntax. This avoids us accidentally creating file_flymake.o

We'll need to convince flymake to look for flymake.mk and run check-syntax against it - add these to your .emacs:

;; Build a custom command-line using flymake.mk
(defun flymake-get-kernel-make-cmdline (source base-dir)
(list "make"
(list "-s"
"-f"
"flymake.mk"
"-C"
base-dir
(concat "CHK_SOURCES=" source)
"SYNTAX_CHECK_MODE=1"
"check-syntax")))

;; Search for flymake.mk to locate kernel tree base
(defun flymake-kernel-make-init ()
(flymake-simple-make-init-impl 'flymake-create-temp-inplace t t "flymake.mk" 'flymake-get-kernel-make-cmdline))

;; Register against .c files under /linux/ or /kernel/
;; Since the list is parsed in order use `push`
(push '(".+/\\(linux\\|kernel\\)/.+\\.c$" flymake-kernel-make-init) flymake-allowed-file-name-masks)

Limitations:

  • Can't parse header files
  • Can't parse flymake temp files source_flymake.c (make sure you ignore flymake markup until it has run over the saved files). I have a keystroke that forcefully re-runs flymake.
  • No support for flymake in external modules
  • Needs pre-registration of the path-matcher (see push line above) - I don't know enough about flymake to allow it to override a single buffer as a one-off.

The header, temp and external modules limitations could be overcome by patching the kernel Makefile itself, which for now I wanted to avoid.

flycheck header file not found, but makefile is correct

Flycheck does not use Makefiles, nor does it attempt to parse them. I cannot help but wonder how you even got this idea, given that no such behaviour is documented in the manual, and no syntax checker for make files even exists.

Flycheck runs Clang directly. You need to explicitly configure the include path for syntax checking by setting flycheck-clang-include-path accordingly. You must do so yourself, this is not done automatically based on your Makefile.

You can set the path via file/dir local variables, or write some custom Emacs Lisp code to parse your Makefile.

Setting up Emacs to run python using elpy

I did not have python in my path of my environmental variables.

In order to fix this:

  • Open windows search bar
  • search for environmental variables
  • Path > Edit... > New
  • Add the location of the python files

Another way to do this is reopen the installer and be sure to select the box add to path when re installing it.
You may need to uninstall python to do this second way.

Good Luck!



Related Topics



Leave a reply



Submit