forked from justas05/Compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
118 lines (95 loc) · 4.29 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
CC := g++ # this is the main compiler
# CC := clang --analyze # and comment out the linker last line
CFLAGS := -g -Wall -Wextra -Wpedantic -std=c++11
LEXINC := -Ic_lexer/include
LEXBUILDDIR := c_lexer/build
LEXSRCDIR := c_lexer/src
PARINC := -Ic_parser/include
PARBUILDDIR := c_parser/build
PARSRCDIR := c_parser/src
COMPINC := -Ic_compiler/include
COMPBUILDDIR := c_compiler/build
COMPSRCDIR := c_compiler/src
all : bin/c_lexer bin/c_parser bin/c_compiler
# Make the c_lexer
bin/c_lexer : $(LEXBUILDDIR)/main.o $(LEXBUILDDIR)/c_lexer.o $(LEXBUILDDIR)/c_lexer.yy.o
@echo "Linking..."
@echo " mkdir -p bin"; mkdir -p bin
@echo " $(CC) $^ -o $@"; $(CC) $^ -o $@
$(LEXBUILDDIR)/%.o : $(LEXSRCDIR)/%.cpp
@echo "Building sources..."
@echo " mkdir -p $(LEXBUILDDIR)"; mkdir -p $(LEXBUILDDIR)
@echo " $(CC) $(CFLAGS) $(LEXINC) -c -o $@ $<"; $(CC) $(CFLAGS) $(LEXINC) -c -o $@ $<
$(LEXBUILDDIR)/%.yy.o : $(LEXSRCDIR)/%.yy.cpp
@echo "Building lex..."
@echo " mkdir -p $(LEXBUILDDIR)"; mkdir -p $(LEXBUILDDIR)
@echo " $(CC) $(CFLAGS) $(LEXINC) -c -o $@ $<"; $(CC) $(CFLAGS) $(LEXINC) -c -o $@ $<
$(LEXSRCDIR)/c_lexer.yy.cpp : $(LEXSRCDIR)/c_lexer.flex
@echo "Creating flex"
@echo " flex -o $@ $<"; flex -o $@ $<
# Make the c_parser
bin/c_parser : $(PARBUILDDIR)/parser_main.o $(PARBUILDDIR)/c_parser.tab.o $(PARBUILDDIR)/c_lexer.yy.o
@echo "Linking..."
@echo " mkdir -p bin"; mkdir -p bin
@echo " $(CC) $^ -o $@"; $(CC) $^ -o $@
$(PARBUILDDIR)/%.o : $(PARSRCDIR)/%.cpp
@echo "Building sources..."
@echo " mkdir -p $(PARBUILDDIR)"; mkdir -p $(PARBUILDDIR)
@echo " $(CC) $(CFLAGS) $(PARINC) -c -o $@ $<"; $(CC) $(CFLAGS) $(PARINC) -c -o $@ $<
$(PARBUILDDIR)/%.yy.o : $(PARSRCDIR)/%.yy.cpp
@echo "Building lex..."
@echo " mkdir -p $(PARBUILDDIR)"; mkdir -p $(PARBUILDDIR)
@echo " $(CC) $(CFLAGS) $(PARINC) -c -o $@ $<"; $(CC) $(CFLAGS) $(PARINC) -c -o $@ $<
$(PARBUILDDIR)/c_parser.tab.o : $(PARSRCDIR)/c_parser.tab.cpp
@echo "Building yacc..."
@echo " mkdir -p $(PARBUILDDIR)"; mkdir -p $(PARBUILDDIR)
@echo " $(CC) $(CFLAGS) $(PARINC) -c -o $@ $<"; $(CC) $(CFLAGS) $(PARINC) -c -o $@ $<
$(PARSRCDIR)/c_lexer.yy.cpp : $(PARSRCDIR)/c_lexer.flex
@echo "Creating lex..."
@echo " flex -o $@ $<"; flex -o $@ $<
$(PARSRCDIR)/c_parser.tab.cpp $(PARSRCDIR)/c_parser.tab.hpp : $(PARSRCDIR)/c_parser.y
@echo "Creating yacc..."
@echo " bison -v -d $< -o $(PARSRCDIR)/c_parser.tab.cpp"; bison -v -d $< -o $(PARSRCDIR)/c_parser.tab.cpp
# Make the c_parser
bin/c_compiler: $(COMPBUILDDIR)/compiler_main.o $(COMPBUILDDIR)/statement.o \
$(COMPBUILDDIR)/function.o $(COMPBUILDDIR)/expression.o \
$(COMPBUILDDIR)/translation_unit.o $(COMPBUILDDIR)/bindings.o \
$(COMPBUILDDIR)/declaration.o $(COMPBUILDDIR)/type.o \
$(COMPBUILDDIR)/c_parser.tab.o $(COMPBUILDDIR)/c_lexer.yy.o
@echo "Linking..."
@echo " mkdir -p bin"; mkdir -p bin
@echo " $(CC) $^ -o $@"; $(CC) $^ -o $@
$(COMPBUILDDIR)/%.o : $(COMPSRCDIR)/%.cpp
@echo "Building sources..."
@echo " mkdir -p $(COMPBUILDDIR)"; mkdir -p $(COMPBUILDDIR)
@echo " $(CC) $(CFLAGS) $(COMPINC) -c -o $@ $<"; $(CC) $(CFLAGS) $(COMPINC) -c -o $@ $<
$(COMPBUILDDIR)/%.yy.o : $(COMPSRCDIR)/%.yy.cpp
@echo "Building lex..."
@echo " mkdir -p $(COMPBUILDDIR)"; mkdir -p $(COMPBUILDDIR)
@echo " $(CC) $(CFLAGS) $(COMPINC) -c -o $@ $<"; $(CC) $(CFLAGS) $(COMPINC) -c -o $@ $<
$(COMPBUILDDIR)/c_parser.tab.o : $(COMPSRCDIR)/c_parser.tab.cpp
@echo "Building yacc..."
@echo " mkdir -p $(COMPBUILDDIR)"; mkdir -p $(COMPBUILDDIR)
@echo " $(CC) $(CFLAGS) $(COMPINC) -c -o $@ $<"; $(CC) $(CFLAGS) $(COMPINC) -c -o $@ $<
$(COMPSRCDIR)/c_lexer.yy.cpp : $(COMPSRCDIR)/c_lexer.flex
@echo "Creating lex..."
@echo " flex -o $@ $<"; flex -o $@ $<
$(COMPSRCDIR)/c_parser.tab.cpp $(COMPSRCDIR)/c_parser.tab.hpp : $(COMPSRCDIR)/c_parser.y
@echo "Creating yacc..."
@echo " bison -v -d $< -o $(COMPSRCDIR)/c_parser.tab.cpp"; bison -v -d $< -o $(COMPSRCDIR)/c_parser.tab.cpp
clean :
@echo "Cleaning..."
rm -rf bin
rm -rf $(LEXBUILDDIR)
rm -f $(LEXSRCDIR)/c_lexer.yy.cpp
rm -rf $(PARBUILDDIR)
rm -f $(PARSRCDIR)/c_lexer.yy.cpp
rm -f $(PARSRCDIR)/c_parser.tab.cpp
rm -f $(PARSRCDIR)/c_parser.tab.hpp
rm -f $(PARSRCDIR)/c_parser.output
rm -rf $(COMPBUILDDIR)
rm -f $(COMPSRCDIR)/c_lexer.yy.cpp
rm -f $(COMPSRCDIR)/c_parser.tab.cpp
rm -f $(COMPSRCDIR)/c_parser.tab.hpp
rm -f $(COMPSRCDIR)/c_parser.output
.PHONY : clean