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 < tests/input001.txt
HEADERS=$(wildcard *.h) # file1.h file2.h fileN.h
SOURCES=$(wildcard *.c) # file1.c file2.c fileN.c main.c
OBJECTS=$(SOURCES:%.c=build/%.o) # file1.o file2.o fileN.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) *.h *.c
.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