CC = gcc SHELL := /usr/bin/env .SHELLFLAGS := -S bash -c CFLAGS := -std=c2x $$(pkg-config --cflags libsodium) $$(sdl2-config --cflags) DEBUG_CFLAGS := -Wall -Wextra -Wpedantic -fanalyzer -Wanalyzer-too-complex -ggdb -g3 -O0 RELEASE_CFLAGS := -O3 -fipa-pta -fipa-cp -fuse-linker-plugin -flto=auto DEFS := -D_GNU_SOURCE=1 DEBUG_DEFS := -DDEBUG=1 RELEASE_DEFS := -DRELEASE=1 LDLIBS := $$(pkg-config --libs-only-l libsodium) $$(sdl2-config --libs) LDFLAGS := $$(pkg-config --libs-only-L libsodium) RELEASE_LDFLAGS := -fuse-linker-plugin -flto=auto SOURCES := $(wildcard *.c) TIMESTAMP_DIR := .timestamps TIMESTAMPS := $(patsubst %.c,$(TIMESTAMP_DIR)/%.t,$(SOURCES)) .PHONY: deps debug release c clean v val t test .DELETE_ON_ERROR: .ONESHELL: # Rule specific var redefs tests debug: CFLAGS += $(DEBUG_CFLAGS) tests debug: DEFS += $(DEBUG_DEFS) release: CFLAGS += $(RELEASE_CFLAGS) release: LDFLAGS += $(RELEASE_LDFLAGS) release: DEFS += $(RELEASE_DEFS) debug: main release: main clay.h: cd .. git submodule update --init --recursive cp -fl clay/clay.h src/ $(TIMESTAMP_DIR): mkdir -p $(TIMESTAMP_DIR) $(TIMESTAMPS): $(TIMESTAMP_DIR)/%.t: %.c | $(TIMESTAMP_DIR) touch $@ main: clay.h main tests: %: %.c $(TIMESTAMPS) $(CC) $(DEFS) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@ # Phony rules c clean: -rm -rvf main tests $(TIMESTAMP_DIR) $(wildcard *.test*) $(wildcard *.enc) v val: main valgrind --leak-check=yes ./main t test: tests valgrind --leak-check=yes ./tests deps: sudo apt install libsodium-dev libsdl2-dev libsdl2-ttf-dev