-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
78 lines (56 loc) · 1.91 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
66
67
68
69
70
71
72
73
74
75
76
77
78
APP_NAME = turing
LIB_NAME = lib$(APP_NAME)
TEST_NAME = $(APP_NAME)-test
CC = gcc
CFLAGS = -W -Wall -Wextra -Werror
LFLAGS = -I src -MP -MMD
TESTFLAGS = -g
BIN_DIR = bin
OBJ_DIR = obj
SRC_DIR = src
TEST_DIR = test
THIRDPARTY = thirdparty
APP_PATH = $(BIN_DIR)/$(APP_NAME)
OBJ_PATH = $(OBJ_DIR)/$(SRC_DIR)
LIB_PATH = $(OBJ_DIR)/$(SRC_DIR)/$(LIB_NAME)/$(LIB_NAME).a
OBJ_TEST_PATH = $(OBJ_DIR)/$(TEST_DIR)
TEST_PATH = $(BIN_DIR)/$(TEST_NAME)
APP_SOURCES = $(shell find $(SRC_DIR)/$(APP_NAME) -name '*.c')
APP_OBJECTS = $(APP_SOURCES:$(SRC_DIR)/%.c=$(OBJ_PATH)/%.o)
LIB_SOURCES = $(shell find $(SRC_DIR)/$(LIB_NAME) -name '*.c')
LIB_OBJECTS = $(LIB_SOURCES:$(SRC_DIR)/%.c=$(OBJ_PATH)/%.o)
TEST_SOURCES = $(shell find $(TEST_DIR) -name '*.c')
TEST_OBJECTS = $(TEST_SOURCES:$(TEST_DIR)/%.c=$(OBJ_TEST_PATH)/%.o)
DEPS = $(APP_OBJECTS:.o=.d) $(LIB_OBJECTS:.o=.d) $(TEST_OBJECTS:.o=.d)
-include $(DEPS)
all: $(APP_PATH)
debug: CFLAGS += -DDEBUG -g
debug: all
# make bin/turing
$(APP_PATH): $(APP_OBJECTS) $(LIB_PATH)
$(CC) $(CFLAGS) $(LFLAGS) $^ -o $@
# make lib
$(LIB_PATH): $(LIB_OBJECTS)
ar rcs $@ $^
# make obj-files for lib
$(OBJ_DIR)/$(SRC_DIR)/$(LIB_NAME)/%.o: $(SRC_DIR)/$(LIB_NAME)/%.c
$(CC) $(CFLAGS) $(LFLAGS) -c $< -o $@
# make obj-files for app
$(OBJ_PATH)/$(APP_NAME)/%.o: $(SRC_DIR)/$(APP_NAME)/%.c
$(CC) $(CFLAGS) $(LFLAGS) -c $< -o $@
test: CFLAGS += -g
test: $(TEST_PATH)
$(TEST_PATH): $(TEST_OBJECTS) $(LIB_PATH)
$(CC) $(LFLAGS) $(TESTFLAGS) -I $(THIRDPARTY) $^ -o $@
$(OBJ_DIR)/$(TEST_DIR)/%.o: $(TEST_DIR)/%.c
$(CC) $(LFLAGS) $(TESTFLAGS) -I $(THIRDPARTY) -c $< -o $@
clean:
$(RM) $(APP_PATH) $(LIB_PATH) $(TEST_PATH)
find $(OBJ_DIR) -name '*.[od]' -exec $(RM) '{}' \;
@echo Done!
.clang-format:
wget -O $@ -c "https://csc-software-development.readthedocs.io/ru/2021/_static/.clang-format"
format: .clang-format
find . -name "*.[ch]" | xargs clang-format -i
@echo Done!
.PHONY: all clean format test debug