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
CC=cc
CXX=g++
CFLAGS=-g -std=gnu11 -Wall -Wextra
LIBS=-pthread
LINTFILTERS=$\
	-readability/casting,$\
	-build/header_guard,$\
	-build/include_subdir

APPNAME=$(shell basename $(shell pwd))
APPARGS=4
HEADERS=$(wildcard *.h)
SOURCES=$(wildcard *.c)
OBJECTS=$(SOURCES:%.c=build/%.o)

bin/$(APPNAME): $(OBJECTS) | bin/.
	$(CC) $(CFLAGS) $^ -o $@ $(LIBS)

build/%.o: %.c $(HEADERS) | build/.
	$(CC) -c $(CFLAGS) $< -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