-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
executable file
·57 lines (39 loc) · 1.58 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
CC = clang
CFLAGS = -Wall -Wextra -g -O0 -std=gnu99 -fstack-protector-all -ftrapv
BUILD_DIR = build
all:$(BUILD_DIR)/compiler
$(BUILD_DIR):
@mkdir $(BUILD_DIR)
$(BUILD_DIR)/lex.yy.c: sysy_lex.l $(BUILD_DIR)/y.tab.h
lex -t $< > $@
$(BUILD_DIR)/lex.yy.o: $(BUILD_DIR)/lex.yy.c
$(CC) $(CFLAGS) -Wno-unused-function -c $< -o $@
$(BUILD_DIR)/y.tab.c $(BUILD_DIR)/y.tab.h: sysy_parse.y
yacc -d $< -o $(BUILD_DIR)/y.tab.c
$(BUILD_DIR)/y.tab.o: $(BUILD_DIR)/y.tab.c syntax.c stack.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/stack.o: stack.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/assembly.o: assembly.c syntax.c environment.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/syntax.o: syntax.c list.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/list.o: list.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/context.o: context.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/environment.o: environment.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/compiler: $(BUILD_DIR) $(BUILD_DIR)/lex.yy.o $(BUILD_DIR)/y.tab.o $(BUILD_DIR)/syntax.o $(BUILD_DIR)/environment.o $(BUILD_DIR)/assembly.o $(BUILD_DIR)/stack.o $(BUILD_DIR)/context.o $(BUILD_DIR)/list.o main.c
$(CC) $(CFLAGS) -o $@ main.c $(BUILD_DIR)/lex.yy.o $(BUILD_DIR)/y.tab.o $(BUILD_DIR)/syntax.o $(BUILD_DIR)/environment.o $(BUILD_DIR)/assembly.o $(BUILD_DIR)/stack.o $(BUILD_DIR)/context.o $(BUILD_DIR)/list.o
.PHONY: clean
clean:
rm -rf $(BUILD_DIR)
$(BUILD_DIR)/run_tests: run_tests.c $(BUILD_DIR)/compiler
$(CC) $(CFLAGS) $< -o $@
.PHONY: test
test: $(BUILD_DIR)/run_tests
@./$^
.PHONY: format
format:
find -name "*.[ch]" -type f | xargs clang-format -i