-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
67 lines (50 loc) · 1.87 KB
/
Makefile
File metadata and controls
67 lines (50 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
SRC_DIRS = ./src
CFLAGS = -MMD -MP -std=c2x -Wall -Wextra -Werror -pedantic -Werror=vla -Wno-unused-function
LDFLAGS = -lm
FORMAT_FILES := $(shell find $(SRC_DIRS) -path '$(SRC_DIRS)/util' -prune -o -type f \( -name '*.c' -o -name '*.h' \) -print)
ifeq ($(MAKECMDGOALS),debug)
TARGET_EXEC = Cluedo
BUILD_DIR = ./bin/debug
CFLAGS += -DDEBUG -g3 -O0 -Wno-unused-variable -Wno-unused-but-set-parameter -Wno-unused-parameter -Wno-unused-but-set-variable
LDFLAGS += -lreadline
SRCS = $(shell find $(SRC_DIRS) -name *.c)
else
TARGET_EXEC = Cluedo
BUILD_DIR = ./bin/release
CFLAGS += -DNDEBUG -O2
LDFLAGS += -lreadline
SRCS = $(shell find $(SRC_DIRS) -name *.c)
endif
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
INC_DIRS := $(shell find $(SRC_DIRS) -type d)
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
all: $(BUILD_DIR)/$(TARGET_EXEC)
debug: $(BUILD_DIR)/$(TARGET_EXEC)
$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS)
@$(CC) $(OBJS) -o $@ $(LDFLAGS)
@echo Done. Placed executable at $(BUILD_DIR)/$(TARGET_EXEC)
$(BUILD_DIR)/%.c.o: %.c
@mkdir -p $(dir $@)
@echo Compiling $<
@$(CC) $(INC_FLAGS) $(CFLAGS) -c $< -o $@
.PHONY: clean format format-check check install-hooks
clean:
$(RM) -r ./bin
format:
@for f in $(FORMAT_FILES); do \
if ! clang-format --style=file "$$f" | diff -q "$$f" - > /dev/null 2>&1; then \
clang-format -i --style=file "$$f"; \
echo "Reformatted: $$f"; \
fi; \
done
format-check:
@for f in $(FORMAT_FILES); do \
clang-format --dry-run --Werror --style=file "$$f"; \
done
check:
@cppcheck --enable=warning,style,performance,portability --std=c23 --language=c --error-exitcode=1 --quiet --suppress=memleakOnRealloc:src/sat/cdcl.c --suppress=memleakOnRealloc:tests/main.c -i src/util src tests
install-hooks:
@git config core.hooksPath .githooks
@echo "Configured git hooks path to .githooks"
-include $(DEPS)