aboutsummaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile62
1 files changed, 62 insertions, 0 deletions
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