From 68a62ad356603d64d537e231f06b5d9445e79abe Mon Sep 17 00:00:00 2001 From: kartofen Date: Fri, 23 Aug 2024 19:55:13 +0300 Subject: usefull commit message --- Makefile | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 Makefile (limited to 'Makefile') diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b474b62 --- /dev/null +++ b/Makefile @@ -0,0 +1,62 @@ +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 -g -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 +.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) 2> cppcheck.log -- cgit v1.2.3