-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
61 lines (46 loc) · 1.32 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
BISON = bison -d -v
FLEX = flex
CC = gcc
CXX = g++
OFLAGS = -std=c++11
FLAGS = # add the -g flag to compile with debugging output for gdb
TARGET = lang
OBJS = ast.o parser.o lexer.o typecheck.o codegen.o main.o
all: $(TARGET)
$(TARGET): $(OBJS)
$(CXX) $(OFLAGS) -o $(TARGET) $(OBJS)
lexer.o: lexer.l
$(FLEX) -o lexer.cpp lexer.l
$(CXX) $(FLAGS) -c -o lexer.o lexer.cpp
parser.o: parser.y
$(BISON) -o parser.cpp parser.y
$(CXX) $(OFLAGS) $(FLAGS) -c -o parser.o parser.cpp
genast: ast.cpp
ast.cpp:
python3 genast.py -i lang.def -o ast
ast.o: ast.cpp
$(CXX) $(OFLAGS) $(FLAGS) -c -o ast.o ast.cpp
typecheck.o: typecheck.cpp typecheck.hpp
$(CXX) $(OFLAGS) $(FLAGS) -c -o typecheck.o typecheck.cpp
codegen.o: codegeneration.cpp codegeneration.hpp
$(CXX) $(OFLAGS) $(FLAGS) -c -o codegen.o codegeneration.cpp
main.o: main.cpp
$(CXX) $(OFLAGS) $(FLAGS) -c -o main.o main.cpp
.PHONY: run
run: $(TARGET)
@python3 runtests.py
.PHONY: diff
diff: $(TARGET)
python3 runtests.py | diff - output.txt
test: $(TARGET) test.lang
./$(TARGET) < test.lang > code.s
ifeq ($(shell uname), Darwin)
gcc -Wl,-no_pie -m32 -o test tester.c code.s
else
gcc -m32 -o test tester.c code.s
endif
./test
.PHONY: clean
clean:
rm -f *.o *~ lexer.cpp parser.cpp parser.hpp ast.cpp ast.hpp parser.output $(TARGET) test code.s
rm -f tests/*.s tests/*.c