forked from tianxinghe/cmmc_optimizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
121 lines (84 loc) · 2.76 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# Files of CMMC
SRC_DIR := ./src
BUILD_DIR := ./build
GENERATE_DIR := $(BUILD_DIR)/generate
SRCS += $(SRC_DIR)/main.c $(TEST_SRC) \
$(shell find $(SRC_DIR)/container -name "*.c" -or -name "*.cpp") \
$(shell find $(SRC_DIR)/IR -name "*.c" -or -name "*.cpp")
OBJ_DIR := $(BUILD_DIR)/obj
OBJS += $(addprefix $(OBJ_DIR)/, $(addsuffix .o, $(basename $(SRCS))))
PARSER := ./parser
# Modules
## IR_PARSE
IR_PARSE_DIR := $(SRC_DIR)/IR_parse
IR_PARSE_GENERATE_DIR := $(GENERATE_DIR)/IR_parse
SRCS += $(shell find $(IR_PARSE_DIR) -name "*.c" -or -name "*.cpp")
IR_LEXICAL_L := $(shell find $(IR_PARSE_DIR) -name "*.l")
IR_SYNTAX_Y := $(shell find $(IR_PARSE_DIR) -name "*.y")
IR_LEX_YY_C := $(IR_PARSE_GENERATE_DIR)/IR_lex.yy.c
IR_SYNTAX_TAB_C := $(IR_PARSE_GENERATE_DIR)/IR_syntax.tab.c
IR_LEX_YY_O := $(OBJ_DIR)/IR_lex.yy.o
IR_SYNTAX_TAB_O := $(OBJ_DIR)/IR_syntax.tab.o
OBJS += $(IR_LEX_YY_O) $(IR_SYNTAX_TAB_O)
INC_PATH += $(IR_PARSE_DIR)/include $(IR_PARSE_GENERATE_DIR)
## IR_OPTIMIZE
IR_OPTIMIZE_DIR := $(SRC_DIR)/IR_optimize
SRCS += $(shell find $(IR_OPTIMIZE_DIR) -name "*.c" -or -name "*.cpp")
INC_PATH += $(IR_OPTIMIZE_DIR)/include
# Tools
LEX := flex
YACC := bison
CC := gcc
CXX := g++
LD := gcc
# Flags
YACC_FLAGS += -d -v
INC_PATH += ./include
INCLUDES = $(addprefix -I, $(INC_PATH))
COMMON_CFLAGS += -MMD -c -Wall $(INCLUDES) -O2
CFLAGS += $(COMMON_CFLAGS)
CXX_FLAGS += $(COMMON_CFLAGS) -std=c++17
LDFLAGS += -lfl -ly
# Building rules
## Compile c/cpp files
$(OBJ_DIR)/%.o: %.c
@echo "+ CC" $(notdir $<)
@mkdir -p $(dir $@)
@$(CC) $(CFLAGS) -o $@ $<
$(OBJ_DIR)/%.o: %.cpp
@echo "+ CXX" $(notdir $<)
@mkdir -p $(dir $@)
@$(CXX) $(CXX_FLAGS) -o $@ $<
# Link the objects
$(PARSER): $(OBJS)
@echo "+ LD" $(notdir $@)
@$(LD) -o $@ $^ $(LDFLAGS)
# IR_PARSE
## Generate lex.yy.c by Flex
$(IR_LEX_YY_C): $(IR_LEXICAL_L)
@echo "+ LEX" $(notdir $<)
@mkdir -p $(dir $@)
@$(LEX) -o $@ $<
## Generate syntax.tab.c and syntax.tab.h by Bison
$(IR_SYNTAX_TAB_C): $(IR_SYNTAX_Y)
@echo "+ YACC" $(notdir $<)
@mkdir -p $(dir $@)
@$(YACC) $(YACC_FLAGS) -o $@ $<
$(OBJ_DIR)/%.o: $(IR_PARSE_GENERATE_DIR)/%.c $(IR_SYNTAX_TAB_C)
@echo "+ CC" $(notdir $<)
@mkdir -p $(dir $@)
@$(CC) $(CFLAGS) -o $@ $<
# Rule (`#include` dependencies): paste in `.d` files generated by gcc on `-MMD`
-include $(OBJS:.o=.d)
.PHONY: all build clean run gdb test
.DEFAULT_GOAL = $(PARSER)
all: $(PARSER)
clean:
rm -rf $(BUILD_DIR) $(PARSER)
build: all
run: $(PARSER)
$(PARSER) $(ARG)
gdb: all
gdb $(PARSER)
test: all # Add args
$(PARSER)