Download Makefile source code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
CC=mpicc
CXX=mpic++
FLAGS=-g -Wall -Wextra
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