Question

I am trying to set up syntax checking with flymake and I've got the basic setup working.

My makefile for flymake is simply like follows:

INCLUDES = -I ./inc ## list of more includes omitted for brevity
.PHONY: check-syntax
check-syntax:
    gcc -Wall -Wextra -pedantic -fsyntax-only -Wno-variadic-macros -std=c99 $(INCLUDES) $(CHK_SOURCES)

This works ok for my C sources.

Now how to use the same makefile and the same check-syntax target for C++? I can't set multiple -std options like -std=c99 -std=c++98 to the same gcc invocation or can I? Do I need to use some conditional? I can't have multiple check-syntax targets on the same Makefile.

Was it helpful?

Solution

You could split it up into two targets:

check-syntax: check-syntax-c check-syntax-cxx

Then check the syntax using the C compiler and the C flags in one target, and using the C++ and C++ flags for the other.

Although you have to split up your sources in C and C++ sources, which you should do anyway.


If you don't have the files split already, you can do it using a GNU Make text function named filter to split the sources:

CHK_SOURCES_C   = $(filter %.c,$(CHK_SOURCES))
CHK_SOURCES_CXX = $(filter %.cpp,$(CHK_SOURCES))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top