-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
65 lines (52 loc) · 1.61 KB
/
Makefile
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
TARGET_EXEC = ccalc
BUILD_DIR = ./bin/release
# No trailing forward slash in INSTALL_PATH!
# Note that install path is cwd when compiling tests or debug
INSTALL_PATH = /etc/ccalc
SRC_DIRS = ./src
CFLAGS = "-DINSTALL_PATH=\"$(INSTALL_PATH)\"" -MMD -MP -std=c17 -Wall -Wextra -Werror -pedantic -Werror=vla
LDFLAGS = -lm
# Compile with readline if no opt-out and target is not test
ifeq (,$(filter $(MAKECMDGOALS),tests))
ifeq ($(NOREADLINE),)
CFLAGS += -DUSE_READLINE
LDFLAGS += -lreadline
endif
endif
# Compile with debugging flags if target is debug
ifneq (,$(filter $(MAKECMDGOALS),debug))
BUILD_DIR = ./bin/debug
INSTALL_PATH = .
CFLAGS += -DDEBUG -g3 -O0
endif
# Compile additional test sources
ifneq (,$(filter $(MAKECMDGOALS),tests))
TARGET_EXEC = test
BUILD_DIR = ./bin/tests
INSTALL_PATH = .
SRC_DIRS += ./tests
CFLAGS += -g3 -O0 -DDEBUG
SRCS = $(shell find $(SRC_DIRS) -name *.c ! -wholename "./src/client/main.c")
else
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)
tests: $(BUILD_DIR)/$(TARGET_EXEC)
@echo Running tests...
@./$(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
clean:
$(RM) -r ./bin
-include $(DEPS)