This repository has been archived by the owner on Jun 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
130 lines (104 loc) · 3.27 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
122
123
124
125
126
127
128
129
130
CC = gcc
CFLAGS = -Wall
LDFLAGS = -lfl
BIN = bin/
OBJ = obj/
SRC = src/
# Nom Projet
NPROJ=tpc
# Nom Analyseur Lexical
AL=$(NPROJ)-l
# Nom Analyseur Syntaxique
AS=$(NPROJ)-s
# Nom parser
EXEC=$(BIN)tpcc
ARGS=test/good/4-while.tpc
# Test
TESTDIR=test
GOOD_TESTS= $(shell find $(TESTDIR)/good/ -type f | sort -n);
SYN_ERR_TESTS= $(shell find $(TESTDIR)/syn-err/ -type f | sort -n);
SEM_ERR_TESTS= $(shell find $(TESTDIR)/sem-err/ -type f | sort -n);
WARN_ERR_TESTS=$(shell find $(TESTDIR)/warn/ -type f | sort -n);
TEST_REPORT=$(TESTDIR)/$(NPROJ)-test.txt
# Other module for the parser
MODULES=tree SymbolTable Compile
# makefile non verbeux
MAKEFLAGS += #--silent
all: compiler
###### AnaLyseur lexical #####
al: makeoutdir $(SRC)$(AL)
# exe
$(SRC)$(AL): $(SRC)$(AL).yy.o
$(CC) -o $@ $^ $(LDFLAGS)
$(SRC)$(AL).yy.c: $(SRC)$(NPROJ).lex
flex -o $@ $<
##### Analyseur syntaxique #####
as: makeoutdir $(SRC)$(AS).tab.c
$(SRC)$(AS).tab.c: $(SRC)$(NPROJ).y
bison -d -v -o $(SRC)$(AS).tab.c $<
##### Parser ####
# as + al + other module
compiler: makeoutdir $(EXEC)
$(EXEC): $(OBJ)$(AS).tab.o $(OBJ)$(AL).yy.o $(addprefix $(OBJ), $(addsuffix .o, $(MODULES)))
$(CC) -o $(EXEC) $^ $(LDFLAGS)
test: compiler
##### Test parser ####
# @echo "# 0 mean no error\n# 1 mean error" > $(TEST_REPORT)
# @echo "#[Good tests] all tests should give 0\n" >> $(TEST_REPORT)
# for t in $(GOOD_TESTS) do \
# ./$(EXEC) < $$t > /dev/null 2>&1 ; \
# echo "$(basename $$t) : $$?" >> $(TEST_REPORT) ; \
# done
# @echo "\n\n#[Syn-err tests] all tests should give 1\n" >> $(TEST_REPORT)
# for t in $(SYN_ERR_TESTS) do \
# ./$(EXEC) < $$t > /dev/null 2>&1 ; \
# echo "$(basename $$t) : $$?" >> $(TEST_REPORT) ; \
# done
##### Test compiler ####
@echo "\n# 0 mean no error\n# any other value means error" > $(TEST_REPORT)
@echo "#[Sem-err tests] all tests should give 2\n" >> $(TEST_REPORT)
for t in $(SEM_ERR_TESTS) do \
./$(EXEC) < $$t > /dev/null 2>&1 ; \
echo "$(basename $$t) : $$?" >> $(TEST_REPORT) ; \
done
@echo "\n\n# 0 mean no error\n# any other value means error" >> $(TEST_REPORT)
@echo "#[Warn tests] all tests should give 0\n" >> $(TEST_REPORT)
for t in $(WARN_ERR_TESTS) do \
./$(EXEC) < $$t > /dev/null 2>&1 ; \
echo "$(basename $$t) : $$?" >> $(TEST_REPORT) ; \
done
##### AST to dot #####
todot: parser
./$(EXEC) < $(ARGS)
dot -Tpdf "ast.dot" -o "ast.pdf"
evince ast.pdf
##### Util #####
$(OBJ)%.o: $(SRC)%.c
$(CC) -o $@ -c $< $(CFLAGS) $(LDFLAGS)
clean:
@rm -rf $(SRC)$(AL).yy.* $(SRC)*.tab.* $(OBJ)*.o ast.dot ast.pdf \
$(EXEC) $(TREPORT) $(AS) $(AL) test/*-test.txt $(SRC)*.output
@rm -rf *.o _anonymous bin/_anonymous
@rm -rf *.dot
@rm -rf *.pdf
@rm -rf $(ASM_EXEC).asm
@rm -rf ./bin/utils.asm
# Dependances
$(OBJ)$(AS).tab.o: $(SRC)$(AS).tab.c $(SRC)$(AS).tab.h $(SRC)tree.h
$(OBJ)$(AL).yy.o: $(SRC)$(AL).yy.c $(SRC)$(AS).tab.h
$(OBJ)tree.o: $(SRC)tree.c $(SRC)tree.h
$(OBJ)SymbolTable.o: $(SRC)SymbolTable.c $(SRC)SymbolTable.h
$(OBJ)Compile.o: $(SRC)Compile.c $(SRC)Compile.h
makeoutdir:
@mkdir -p $(BIN) $(OBJ)
@cp src/utils.asm bin/utils.asm
####### ASM
ASM_OBJ= _anonymous.o
ASM_EXEC= _anonymous
$(ASM_EXEC): $(ASM_OBJ)
$(CC) $^ -no-pie -nostartfiles -g -o bin/$@
%.o:%.asm
nasm -F dwarf -g -lc -felf64 -o $@ $<
exo%.o: exo%.asm
utils.o: utils.asm
_anonymous.o: _anonymous.asm