# Makefile template for small simple projects EXEC = execname DEPS = # static files like assets SOURCES = $(wildcard *.c) OBJECTS = $(SOURCES:.c=.o) HEADERS = $(wildcard *.h) INCLUDES = # additional headers, maybe in includes/ CC = gcc CFLAGS = -fno-omit-frame-pointer -std=c11 -Wall -Wextra -Wpedantic CFLAGS += -Wmissing-prototypes -Wshadow -Werror=vla CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 CFLAGS += $(shell pkg-config --cflags LIBNAME) LDFLAGS = LDLIBS = LDLIBS += $(shell pkg-config --libs LIBNAME) SANFLAGS = -fsanitize=address,leak,undefined ifndef BEAR CFLAGS += -fanalyzer endif ifdef RELEASE CFLAGS += -O2 else CFLAGS += -g3 -Og $(SANFLAGS) LDFLAGS += $(SANFLAGS) endif # if you have a file named as the execname, that is a sufficient target to # compile the entire project. eg: execname and execname.c all: $(EXEC) $(HEADERS) $(INCLUDES) # $(LINK.c) $^ $(LDLIBS) $(OUTPUT_OPTION) $(EXEC): $(OBJECTS) $(CC) $(LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $(EXEC) #%.o: %.c %.h $(DEPS) # $(COMPILE.c) $(OUTPUT_OPTION) $< # $@: $< $^ # $@ is the left side of the : # $^ is the right side of the : # the $< is the first item in the dependencies list .PHONY: check clean oclean release check debug clean: oclean rm -f $(EXEC) oclean: rm -f *.o release: all oclean check: $(SRCS) cppcheck --enable=all --std=c11 --inline-suppr \ --suppress=missingIncludeSystem $^ codespell $^ debug: sudo sysctl -w kernel.yama.ptrace_scope=0 #vim: set noexpandtab sw=8 ts=8 tw=80: