-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
62 lines (44 loc) · 1.12 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
CC = gcc
FLEX = flex
BISON = bison
CFLAGS = -std=c11 -Wall -Werror -MD -ggdb #-D DEBUG
GDBFLAGS = -ex "set args test.cmm test.S"\
-ex "set print pretty on"
LFILE = $(shell find ./ -name "*.l")
YFILE = $(shell find ./ -name "*.y")
LFC = $(shell find ./ -name "*.l" | sed s/[^/]*\\.l/lex.yy.c/)
YFC = $(shell find ./ -name "*.y" | sed s/[^/]*\\.y/syntax.tab.c/)
CFILES = $(filter-out $(LFC) $(YFC), $(shell find ./ -name "*.c"))
OBJS = $(CFILES:.c=.o)
LFO = $(LFC:.c=.o)
YFO = $(YFC:.c=.o)
COMPILER := ncc
$(COMPILER): $(YFO) $(LFO) $(OBJS)
$(CC) -ggdb -o $@ $^
$(LFO): $(LFC)
$(CC) -ggdb -c $^
$(YFO): $(YFC)
$(CC) -ggdb -c $^
$(LFC): $(LFILE)
$(FLEX) -o $@ $^
$(YFC): $(YFILE)
$(BISON) -o $@ -d -v $^
-include $(patsubst %.o, %.d, $(OBJS))
.PHONY: clean test gdb
test: $(COMPILER)
./test.sh
execute: $(COMPILER)
./test.sh execute
nemu: $(COMPILER)
./test.sh nemu
gdb: $(COMPILER)
gdb $(COMPILER) $(GDBFLAGS)
clean:
rm -f $(COMPILER) syntax.output
rm -f $(OBJS) $(OBJS:.o=.d)
rm -f $(LFC) $(YFC) $(YFC:.c=.h) $(LFO) $(YFO)
rm -f *~
rm -f ./test/*.out
rm -f ./test/*.S
rm -f ./test/*.debug
rm -f ./test/*.ir