Download Makefile source code

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