-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
42 lines (34 loc) · 1.07 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
# GNU make手册:http://www.gnu.org/software/make/manual/make.html
# ************ 遇到不明白的地方请google以及阅读手册 *************
# 编译器设定和编译选项
CC = gcc
FLEX = flex
BISON = bison
CFLAGS = -std=c99
# 编译目标:src目录下的所有.c文件
CFILES = $(shell find ./ -name "*.c")
OBJS = $(CFILES:.c=.o)
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/)
LFO = $(LFC:.c=.o)
YFO = $(YFC:.c=.o)
parser: syntax $(filter-out $(LFO),$(OBJS))
$(CC) -o parser $(filter-out $(LFO),$(OBJS)) -lfl -ly
syntax: lexical syntax-c
$(CC) -c $(YFC) -o $(YFO)
lexical: $(LFILE)
$(FLEX) -o $(LFC) $(LFILE)
syntax-c: $(YFILE)
$(BISON) -o $(YFC) -d -v $(YFILE)
-include $(patsubst %.o, %.d, $(OBJS))
# 定义的一些伪目标
.PHONY: clean test
test:
./parser ../Test/test1.cmm
clean:
rm -f lex.yy.c syntax.tab.c syntax.tab.h syntax.output
rm -f $(OBJS) $(OBJS:.o=.d)
rm -f $(LFC) $(YFC) $(YFC:.c=.h)
rm -f *~