-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
103 lines (77 loc) · 3.66 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
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
CC = g++
FLEX = flex
BISON = bison
SOURCE_DIR = ./src
BUILD_DIR = ./build
BINARY_DIR = ./bin
CPPFLAGS ?= -g
CPPFLAGS += -I$(SOURCE_DIR) -I$(BUILD_DIR) -std=c++17
FLEXFLAGS ?=
BISONFLAGS ?= -t
# source files for utilities
SPL_ENUM_HPP = $(SOURCE_DIR)/spl-enum.hpp
SPL_AST_HPP = $(SOURCE_DIR)/spl-ast.hpp
SPL_SEMANTIC_ERROR_HPP = $(SOURCE_DIR)/spl-semantic-error.hpp
SPL_IR_HPP = $(SOURCE_DIR)/spl-ir.hpp
# source files for lexer
SPL_LEXER_BODY_L = $(SOURCE_DIR)/spl-lexer-body.l
SPL_LEXER_MODULE_CPP = $(SOURCE_DIR)/spl-lexer-module.cpp
SPL_LEXER_STANDALONE_CPP = $(SOURCE_DIR)/spl-lexer-standalone.cpp
# target files for lexer
SPL_LEXER_BODY_CPP = $(BUILD_DIR)/spl-lexer-body.cpp
SPL_LEXER_STANDALONE_OUT = $(BUILD_DIR)/spl-lexer-standalone
# source files for parser
SPL_PARSER_BODY_Y = $(SOURCE_DIR)/spl-parser-body.y
SPL_PARSER_MODULE_CPP = $(SOURCE_DIR)/spl-parser-module.cpp
SPL_PARSER_STANDALONE_CPP = $(SOURCE_DIR)/spl-parser-standalone.cpp
# target files for parser
SPL_PARSER_BODY_CPP = $(BUILD_DIR)/spl-parser-body.cpp
SPL_PARSER_BODY_HPP = $(BUILD_DIR)/spl-parser-body.hpp
SPL_PARSER_BODY_LOG = $(BUILD_DIR)/spl-parser-body.output
SPL_PARSER_STANDALONE_OUT = $(BUILD_DIR)/spl-parser-standalone
# source files for semantic analyzer
SPL_SEMANTIC_ANALYZER_BODY_CPP = $(SOURCE_DIR)/spl-semantic-analyzer-body.cpp
SPL_SEMANTIC_ANALYZER_MODULE_CPP = $(SOURCE_DIR)/spl-semantic-analyzer-module.cpp
SPL_SEMANTIC_ANALYZER_STANDALONE_CPP = $(SOURCE_DIR)/spl-semantic-analyzer-standalone.cpp
# target files for semantic analyzer
SPL_SEMANTIC_ANALYZER_STANDALONE_OUT = $(BUILD_DIR)/spl-semantic-analyzer-standalone
# source files for ir generator
SPL_IR_GENERATOR_BODY_CPP = $(SOURCE_DIR)/spl-ir-generator-body.cpp
SPL_IR_GENERATOR_STANDALONE_CPP = $(SOURCE_DIR)/spl-ir-generator-standalone.cpp
# target files for ir generator
SPL_IR_GENERATOR_STANDALONE_OUT = $(BUILD_DIR)/spl-ir-generator-standalone
# binary products
SPLC = $(BINARY_DIR)/splc
.PHONY: splc
splc: $(SPLC)
$(SPL_LEXER_BODY_CPP): $(SPL_LEXER_BODY_L)
@mkdir -p $(dir $@)
$(FLEX) $(FLEXFLAGS) -o $(SPL_LEXER_BODY_CPP) $(SPL_LEXER_BODY_L)
$(SPL_LEXER_STANDALONE_OUT): $(SPL_LEXER_BODY_CPP) $(SPL_LEXER_STANDALONE_CPP)
@mkdir -p $(dir $@)
$(CC) $(CPPFLAGS) $(SPL_LEXER_STANDALONE_CPP) -lfl -o $(SPL_LEXER_STANDALONE_OUT)
$(SPL_PARSER_BODY_CPP): $(SPL_PARSER_BODY_Y) $(SPL_LEXER_MODULE_CPP) $(SPL_LEXER_BODY_CPP) \
$(SPL_ENUM_HPP)
@mkdir -p $(dir $@)
$(BISON) $(BISONFLAGS) --report=state --report-file=$(SPL_PARSER_BODY_LOG) \
--defines=$(SPL_PARSER_BODY_HPP) -o $(SPL_PARSER_BODY_CPP) $(SPL_PARSER_BODY_Y)
$(SPL_PARSER_STANDALONE_OUT): $(SPL_PARSER_BODY_CPP) $(SPL_PARSER_STANDALONE_CPP) $(SPL_AST_HPP)
@mkdir -p $(dir $@)
$(CC) $(CPPFLAGS) $(SPL_PARSER_STANDALONE_CPP) -lfl -ly -o $(SPL_PARSER_STANDALONE_OUT)
$(SPL_SEMANTIC_ANALYZER_STANDALONE_OUT): $(SPL_SEMANTIC_ANALYZER_BODY_CPP) $(SPL_SEMANTIC_ANALYZER_STANDALONE_CPP) \
$(SPL_ENUM_HPP) $(SPL_AST_HPP) $(SPL_SEMANTIC_ERROR_HPP) \
$(SPL_PARSER_MODULE_CPP) $(SPL_PARSER_BODY_CPP)
@mkdir -p $(dir $@)
$(CC) $(CPPFLAGS) $(SPL_SEMANTIC_ANALYZER_STANDALONE_CPP) -o $(SPL_SEMANTIC_ANALYZER_STANDALONE_OUT)
$(SPL_IR_GENERATOR_STANDALONE_OUT): $(SPL_IR_GENERATOR_BODY_CPP) $(SPL_IR_GENERATOR_STANDALONE_CPP) \
$(SPL_ENUM_HPP) $(SPL_AST_HPP) $(SPL_SEMANTIC_ERROR_HPP) $(SPL_IR_HPP) \
$(SPL_SEMANTIC_ANALYZER_MODULE_CPP) $(SPL_SEMANTIC_ANALYZER_BODY_CPP) \
$(SPL_PARSER_MODULE_CPP) $(SPL_PARSER_BODY_CPP)
@mkdir -p $(dir $@)
$(CC) $(CPPFLAGS) $(SPL_IR_GENERATOR_STANDALONE_CPP) -o $(SPL_IR_GENERATOR_STANDALONE_OUT)
$(SPLC): $(SPL_IR_GENERATOR_STANDALONE_OUT)
@mkdir -p $(dir $@)
cp $(SPL_IR_GENERATOR_STANDALONE_OUT) $(SPLC)
.PHONY: clean
clean:
@rm -rf $(BUILD_DIR) $(BINARY_DIR)