-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
106 lines (86 loc) · 3.29 KB
/
Makefile
File metadata and controls
106 lines (86 loc) · 3.29 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# ==============================================
# Compiler Configuration
# ==============================================
CXX ?= g++
CXXFLAGS ?= -Wall -Wextra -pedantic -Iinclude -g
PY = python3
# ==============================================
# LLVM Configuration
# ==============================================
LLVM_CONFIG ?= llvm-config
LLVM_CXXFLAGS = $(shell $(LLVM_CONFIG) --cxxflags)
LLVM_LDFLAGS = $(shell $(LLVM_CONFIG) --ldflags)
CLANG_LDFLAGS = $(shell $(LLVM_CONFIG) --libs core) -lclang-cpp
LDFLAGS ?= $(CLANG_LDFLAGS) $(LLVM_LDFLAGS) -lsqlite3
DEBUG_FLAG ?= -D_DEBUG_ -O0
RELEASE_FLAGS ?= -O2
TARGET = build/demo
SRC_DIR = src
OBJ_DIR = build/obj
INCLUDE_DIR = include
SCRIPT_DIR = scripts
# 将源文件分为两组:需要LLVM标志的和不需要的
LLVM_SRCS = $(wildcard $(SRC_DIR)/core/*.cc \
$(SRC_DIR)/util/key_generator/*.cc \
$(SRC_DIR)/core/processor/*.cc)
NORMAL_SRCS = $(wildcard $(SRC_DIR)/*.cc \
$(SRC_DIR)/interface/*.cc \
$(SRC_DIR)/util/*.cc \
$(SRC_DIR)/db/*.cc \
$(SRC_DIR)/model/*/*.cc)
# 生成对应的目标文件路径
LLVM_OBJS = $(patsubst $(SRC_DIR)/%.cc, $(OBJ_DIR)/%.o, $(LLVM_SRCS))
NORMAL_OBJS = $(patsubst $(SRC_DIR)/%.cc, $(OBJ_DIR)/%.o, $(NORMAL_SRCS))
ALL_OBJS = $(LLVM_OBJS) $(NORMAL_OBJS)
# ==============================================
# Build Targets
# ==============================================
all: $(TARGET)
$(TARGET): $(ALL_OBJS)
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) $(LLVM_CXXFLAGS) -o $@ $^ $(LDFLAGS)
# 使用LLVM标志编译核心文件
$(OBJ_DIR)/core/%.o: $(SRC_DIR)/core/%.cc
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) $(LLVM_CXXFLAGS) -MMD -MP -c $< -o $@
# ==============================================
# Code Generation
# ==============================================
src/db/storage_facade_instantiations.inc: $(wildcard include/model/db/*.h) $(SCRIPT_DIR)/generate_instantiations.py
$(PY) $(SCRIPT_DIR)/generate_instantiations.py
# 不使用LLVM标志编译其他文件
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cc
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) -MMD -MP -c $< -o $@
# 使目标文件依赖于生成的实例化代码
$(OBJ_DIR)/db/storage_facade.o: src/db/storage_facade_instantiations.inc
-include $(ALL_OBJS:.o=.d)
# ==============================================
# Build Variants
# ==============================================
debug: CXXFLAGS += $(DEBUG_FLAG)
debug: all
release: CXXFLAGS += $(RELEASE_FLAGS)
release: all
# ==============================================
# Cleanup
# ==============================================
clean:
rm -rf $(OBJ_DIR) $(TARGET)
# ==============================================
# Run & Help
# ==============================================
run: CXXFLAGS += $(DEBUG_FLAG)
run: $(TARGET)
./$(TARGET) -c config.example.toml -s tests/slight-case.cc -o tests/ast.db
# ==============================================
# Help Information
# ==============================================
help:
@echo "Usage:"
@echo " make # Build"
@echo " make debug # Build with debug flags"
@echo " make release # Build with release flags"
@echo " make run # Build and run to show testing output"
@echo " make clean # Clean up all build files"
.PHONY: all clean help run debug release