-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
82 lines (61 loc) · 2.83 KB
/
Copy pathMakefile
File metadata and controls
82 lines (61 loc) · 2.83 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
.PHONY: all clean
# This Makefile is compatible with autotest
# autotest requirements:
# The main target file should be named 'compiler' and located in the $(BUILD_DIR) directory.
SRC := src
FLEX := flex
BISON := bison
CPP := clang++
DEBUG ?= 0
CDE_LIBRARY_PATH ?= /opt/lib
CDE_INCLUDE_PATH ?= /opt/include
BUILD_DIR ?= build
LIB_DIR ?= $(CDE_LIBRARY_PATH)/native
INC_DIR ?= $(CDE_INCLUDE_PATH)
ifneq ($(DEBUG), 0)
DEBUG_FLAG := -DYYDEBUG -g -fsanitize=undefined,address -fno-inline-functions
OPTIMIZE_FLAG := -O0
LD_FLAGS := -L$(LIB_DIR) -lasan -lubsan -lkoopa
else
DEBUG_FLAG := -DNDEBUG
OPTIMIZE_FLAG := -O3
LD_FLAGS := -L$(LIB_DIR) -lkoopa
endif
CPP_FLAGS = -c -std=c++20 -Wall -Wextra -Wno-unused-result -Wno-unused-function $(OPTIMIZE_FLAG) $(DEBUG_FLAG) -I$(INC_DIR)
all: $(BUILD_DIR)/compiler
cp $(BUILD_DIR)/compiler .
echo "OK"
# $(BUILD_DIR)/compiler: headers $(SRC)/main.cpp $(SRC)/asmgen.cpp $(SRC)/irgen.cpp $(SRC)/ast.cpp $(BUILD_DIR)/sysy.lex.cpp $(BUILD_DIR)/sysy.tab.cpp
# $(CPP) $(CPP_FLAGS) -o $(BUILD_DIR)/compiler $(SRC)/main.cpp $(SRC)/asmgen.cpp $(SRC)/irgen.cpp $(SRC)/ast.cpp $(BUILD_DIR)/sysy.lex.cpp $(BUILD_DIR)/sysy.tab.cpp
HEADERS_SRC = $(SRC)/debug.hpp $(SRC)/ast.hpp $(SRC)/sysy_exceptions.hpp $(SRC)/mir.hpp $(SRC)/riscv.hpp
HEADERS = $(BUILD_DIR)/debug.hpp $(BUILD_DIR)/ast.hpp $(BUILD_DIR)/sysy_exceptions.hpp $(BUILD_DIR)/mir.hpp
OBJS := $(BUILD_DIR)/sysy.lex.o $(BUILD_DIR)/sysy.tab.o $(BUILD_DIR)/ast.o $(BUILD_DIR)/irgen.o $(BUILD_DIR)/asmgen.o $(BUILD_DIR)/main.o
$(BUILD_DIR)/compiler: $(OBJS)
$(CPP) $(OBJS) $(LD_FLAGS) -o $(BUILD_DIR)/compiler
$(BUILD_DIR)/sysy.lex.o: $(HEADERS) $(BUILD_DIR)/sysy.lex.cpp $(BUILD_DIR)/sysy.tab.hpp
$(CPP) $(CPP_FLAGS) -o $(BUILD_DIR)/sysy.lex.o $(BUILD_DIR)/sysy.lex.cpp
$(BUILD_DIR)/sysy.tab.o: $(HEADERS) $(BUILD_DIR)/sysy.tab.cpp $(BUILD_DIR)/sysy.tab.hpp
$(CPP) $(CPP_FLAGS) -o $(BUILD_DIR)/sysy.tab.o $(BUILD_DIR)/sysy.tab.cpp
$(BUILD_DIR)/ast.o: $(HEADERS_SRC) $(SRC)/ast.cpp
$(CPP) $(CPP_FLAGS) -o $(BUILD_DIR)/ast.o $(SRC)/ast.cpp
$(BUILD_DIR)/irgen.o: $(HEADERS_SRC) $(SRC)/irgen.cpp
$(CPP) $(CPP_FLAGS) -o $(BUILD_DIR)/irgen.o $(SRC)/irgen.cpp
$(BUILD_DIR)/asmgen.o: $(HEADERS_SRC) $(SRC)/asmgen.cpp
$(CPP) $(CPP_FLAGS) -o $(BUILD_DIR)/asmgen.o $(SRC)/asmgen.cpp
$(BUILD_DIR)/main.o: $(HEADERS_SRC) $(SRC)/main.cpp
$(CPP) $(CPP_FLAGS) -o $(BUILD_DIR)/main.o $(SRC)/main.cpp
$(BUILD_DIR)/sysy.lex.cpp: $(SRC)/sysy.l $(SRC)/sysy.y | $(BUILD_DIR)
$(FLEX) -o $(BUILD_DIR)/sysy.lex.cpp $(SRC)/sysy.l
$(BUILD_DIR)/sysy.tab.hpp $(BUILD_DIR)/sysy.tab.cpp: $(SRC)/sysy.y | $(BUILD_DIR)
$(BISON) -d -o $(BUILD_DIR)/sysy.tab.cpp $(SRC)/sysy.y
# -Wcounterexamples
$(BUILD_DIR)/%.hpp: $(SRC)/%.hpp | $(BUILD_DIR)
@if [ ! -f $@ ] || [ $< -nt $@ ]; then \
echo "Copying $< to $@"; \
cp $< $@; \
fi
$(BUILD_DIR):
mkdir $(BUILD_DIR)
clean:
rm -f compiler
rm -rf $(BUILD_DIR)