Question

I'm sorta lost because I'm not sure where to place, or exactly how to create the flymake makefile. I saw the emacswiki article on it, but (and maybe I just overlooked it) I didn't find where to place the file, or how to specify where it is.

Was it helpful?

Solution

The exact place of the Makefile does not matter.

Flymake searches for a Makefile in the directory containing the file being checked, and any ancestor directory thereof. Suppose, you edit foo/bar/test.c, then Flymake would first try foo/bar/Makefile, then foo/Makefile, and so on, until the root directory is reached.

The Makefile must provide special support for Flymake, however: It must provide a check-syntax target, and should look at CHK_SOURCES for the file being checked. How to write such a target depends on the language and compiler you are using. If your Makefile does not provide this target, syntax checking will fail!

Flymake uses Makefiles for C and C++ files with common extensions (e.g. .c, .cpp, etc.). Note that Flymake looks at the file name of the buffer, not at its mode. As such, the buffer must have a backing file, and it must have an extension known to Flymake. If your files have unusual extensions, customize flymake-allowed-file-name-masks accordingly, to add regular expressions matching your file names, e.g.:

(require 'flymake)
(add-to-list 'flymake-allowed-file-name-masks 
             '("\\.an-exotic-c-extension\\'" flymake-simple-make-init))

If you set up the Makefile and customized Flymake accordingly, M-x flymake-mode should then be sufficient to enable syntax checking.

You may also want to look at Flycheck as recommended in the comments. Flycheck is an alternative implementation for syntax checking, that works out of the box for many languages. It does not support Makefiles, but provides support for many languages. If the language you are using is supported, changes are good that you don't even need a Makefile.

Disclaimer: I'm the author and maintainer of Flycheck.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top