CC := gcc ifdef PROD CFLAGS := -std=c99 -Wpedantic -O3 -s # production flags else CFLAGS := -std=c99 -Wall -Wextra -Wpedantic -Wshadow -Wpointer-arith \ -Wstrict-prototypes -Wmissing-prototypes -Wcast-qual -g3 -DDEBUG ifdef MEMDEBUG CFLAGS += -DENABLE_MEMDEBUG endif endif NAME := nlisp SRC := src OBJ := obj BIN := bin TEST := tests # rebuild when flags change FLAGHASH := $(strip $(shell echo $(CFLAGS) | sha256sum | cut -d " " -f1 )) SRCS = $(wildcard $(SRC)/*.c) OBJS = $(SRCS:$(SRC)/%.c=$(OBJ)/%-$(FLAGHASH).o) DEPS = $(OBJS:%.o=%.d) -include $(DEPS) .PHONY: all clean $(NAME) analyze valgrind cppcheck .DEFAULT_GOAL := all all: $(NAME) $(NAME): $(BIN)/$(NAME) clean: rm -rf $(BIN) rm -rf $(OBJ) $(OBJ) $(BIN): mkdir -p $@ $(OBJ)/%-$(FLAGHASH).o: $(SRC)/%.c | $(OBJ) $(CC) $(CFLAGS) -MMD -MF $(@:%.o=%.d) -c $< -o $@ $(BIN)/%: $(OBJS) | $(BIN) $(CC) $(CFLAGS) $^ -o $@ analyze: clean scan-build \ -enable-checker alpha \ -enable-checker core \ -enable-checker deadcode \ -enable-checker security \ -enable-checker unix \ make valgrind: $(NAME) valgrind -s --leak-check=full --show-leak-kinds=all $(BIN)/$(NAME) cppcheck: clean cppcheck --enable=all $(SRCS) --check-level=exhaustive 2> cppcheck.log