I'm using Flymake for C code syntax checking. If the Makefile and the source file are located in the same directory, Flymake works fine. But if the Makefile is in the parent directory of the source code (like in most C projects), it seems like that Flymake can't find the Makefile anymore, and produces the following message in the *Flymake log*
buffer:
Warning [flymake hello.c]: Disabling backend flymake-cc because make: *** No rule to make target `check-syntax'. Stop.
I'm using the default configuration of Flymake. The C source code and the Makefile for testing are listed at the end of this post. I saw many people are using custom init functions for Flymake. But I found that the default init function for Flymake was able to locate the Makefile correctly, at least for C projects. For example, if I evaluate flymake-proc-simple-make-init
within the src/hello.c
buffer, I got this message:
("make" ("-s" "-C" "../" "CHK_SOURCES=src/hello_140332961481000_flymake.c" "SYNTAX_CHECK_MODE=1" "check-syntax"))
The "-C" "../"
part indicates that it knows the Makefile is located in the directory one level up. I can't find out why it didn't work eventually.
What I want to achieve are:
- Make Flymake work for all the source code files in the testing project below.
- As few customization as possible.
Any help would be appreciated.
$ tree .
.
|-- Makefile
|-- main.c
`-- src
|-- hello.c
`-- hello.h
# Makefile
INCLUDE=src
check-syntax:
clang -fsyntax-only -Wall -I${INCLUDE} ${CHK_SOURCES} || true
/* main.c */
#include "hello.h"
int main(void)
{
hello()
return 0;
}
/* src/hello.c */
#include "hello.h"
#include <stdio.h>
void hello(void)
{
printf("hello\n")
}
/* src/hello.h */
#ifndef HELLO_H
#define HELLO_H
void hello(void);
#endif