# 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 = -std=c99 -Wall -Wextra -Wpedantic -Wmissing-prototypes -Iinclude/ CFLAGS += $(shell pkg-config --cflags LIBNAME) LDFLAGS = LDLIBS = LDLIBS += $(shell pkg-config --libs LIBNAME) AFLAGS = -fanalyzer -fsanitize=address,leak,undefined -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 ifdef RELEASE CFLAGS += -O2 else CFLAGS += -g3 -O0 $(AFLAGS) LDFLAGS += $(AFLAGS) 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=c99 --suppress=missingIncludeSystem $^ debug: sudo sysctl -w kernel.yama.ptrace_scope=0 #vim: set noexpandtab sw=8 ts=8 tw=80: