CC=mpicc
CXX=mpic++
FLAGS=-g -Wall -Wextra -fopenmp
CFLAGS=$(FLAGS) -std=gnu11
CXXFLAGS=$(FLAGS) -std=gnu++11
LIBS=
LINTFILTERS=$\
-readability/casting,$\
-build/header_guard,$\
-build/include_subdir
APPNAME=$(shell basename $(shell pwd))
APPARGS=
HEADERS=$(wildcard *.h)
SOURCES=$(wildcard *.c *.cpp)
OBJECTS=$(SOURCES:%.cpp=build/%.o)
bin/$(APPNAME): $(OBJECTS) | bin/.
$(CXX) $(CXXFLAGS) $^ -o $@ $(LIBS)
build/%.o: %.c $(HEADERS) | build/.
$(CC) -c $(CFLAGS) $< -o $@ $(LIBS)
build/%.o: %.cpp $(HEADERS) | build/.
$(CXX) -c $(CXXFLAGS) $< -o $@ $(LIBS)
.PRECIOUS: %/.
%/.:
mkdir -p $(dir $@)
all: bin/$(APPNAME) lint memcheck helgrind
.PHONY: lint
lint:
cpplint --filter=$(LINTFILTERS) $(HEADERS) $(SOURCES)
.PHONY: memcheck
memcheck:
valgrind --tool=memcheck bin/$(APPNAME) $(APPARGS)
.PHONY: helgrind
helgrind:
valgrind --quiet --tool=helgrind bin/$(APPNAME) $(APPARGS)
.PHONY: gitignore
gitignore:
echo bin > .gitignore
echo build >> .gitignore
.PHONY: clean
clean:
rm -rf bin build