3.2.2 Example—Configuring a tool called via make

In this example we will add support for C files syntax checked by gcc called via make.

We’re not required to write any new functions, as Flymake already has functions for make. We just add a new entry to the flymake-proc-allowed-file-name-masks:

(setq flymake-proc-allowed-file-name-masks
      (cons '(".+\\.c$"
              flymake-proc-simple-make-init
              flymake-proc-simple-cleanup
              flymake-proc-get-real-file-name)
            flymake-proc-allowed-file-name-masks))

flymake-proc-simple-make-init builds the following make command line:

(list "make"
      (list "-s" "-C"
            base-dir
            (concat "CHK_SOURCES=" source)
            "SYNTAX_CHECK_MODE=1"
            "check-syntax"))

base-dir is a directory containing the Makefile, see Locating the buildfile.

Thus, Makefile must contain the check-syntax target. In our case this target might look like this:

check-syntax:
	gcc -o /dev/null -S ${CHK_SOURCES} || true

The format of error messages reported by gcc is already supported by Flymake, so we don’t have to add a new entry to flymake-err-line-patterns. Note that if you are using Automake, you may want to replace gcc with the standard Automake variable COMPILE:

check-syntax:
	$(COMPILE) -o /dev/null -S ${CHK_SOURCES} || true