-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
75 lines (55 loc) · 1.67 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
SRC_DIR = source
BUILD_DIR = build
OBJ_DIR = $(BUILD_DIR)/obj
BIN_DIR = $(BUILD_DIR)/bin
COMPILER ?= clang
OPTIMIZATION_LEVEL ?= -O3
SANITIZERS ?=
CC = $(COMPILER)
CFLAGS = -g -I $(SRC_DIR)
CFLAGS += -Wall -Werror
CFLAGS += -fno-omit-frame-pointer
CFLAGS += $(OPTIMIZATION_LEVEL)
CFLAGS += $(SANITIZERS)
LDFLAGS = $(CFLAGS)
SRCS := $(shell find source -iname '*.c') $(shell find source -iname '*.S')
OBJS := $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SRCS))
OBJS := $(patsubst $(SRC_DIR)/%.S, $(OBJ_DIR)/%.o, $(OBJS))
TARGET = app
run: $(BIN_DIR)/$(TARGET)
./$(BIN_DIR)/$(TARGET)
compile: clean $(BIN_DIR)/$(TARGET)
clean:
rm -rf $(BUILD_DIR)
rm -rf ./**/*.o
$(BIN_DIR)/$(TARGET): $(BIN_DIR) $(OBJ_DIR) $(OBJS)
$(CC) $(OBJS) -o $@ $(LDFLAGS)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
mkdir -p $(shell dirname $@)
$(CC) $(CFLAGS) -c $< -o $@
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.S
mkdir -p $(shell dirname $@)
$(CC) $(CFLAGS) -c $< -o $@
$(OBJ_DIR): $(BUILD_DIR)
mkdir -p $(OBJ_DIR)
$(BIN_DIR): $(BUILD_DIR)
mkdir -p $(BIN_DIR)
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
check-style:
find source -iname '*.h' -o -iname '*.c' \
| xargs clang-tidy -p compile_commands.json
check-format:
find source -iname '*.h' -o -iname '*.c' \
| xargs clang-format -Werror --dry-run --fallback-style=Google --verbose
fix-format:
find source -iname '*.h' -o -iname '*.c' \
| xargs clang-format -i --fallback-style=Google --verbose
info:
$(info CC = $(CC))
$(info CFLAGS = $(CFLAGS))
$(info LDFLAGS = $(LDFLAGS))
$(info SRC_DIR = $(SRC_DIR))
$(info BUILD_DIR = $(BUILD_DIR))
$(info SRCS = $(SRCS))
$(info OBJS = $(OBJS))