-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
49 lines (40 loc) · 1.22 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
# GNU make手册:http://www.gnu.org/software/make/manual/make.html
# ************ 遇到不明白的地方请google以及阅读手册 *************
# 编译器设定和编译选项
CC = gcc
FLEX = flex
BISON = bison
#CFLAGS = -std=c99
# use gdb to debug
CFLAGS =-g -std=c99
CUR_DIR = $(shell pwd)
SRC_DIR = $(CUR_DIR)/src
BUILD_DIR = $(CUR_DIR)/build
# 编译目标:src目录下的所有.c文件
CFILES = $(shell find $(SRC_DIR) -name "*.c")
OBJS = $(CFILES:.c=.o)
LFILE = $(shell find $(SRC_DIR) -name "*.l")
YFILE = $(shell find $(SRC_DIR) -name "*.y")
LFC = $(shell find $(SRC_DIR) -name "*.l" | sed s/[^/]*\\.l/lex.yy.c/)
YFC = $(shell find $(SRC_DIR) -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
rm -f $(OBJS)
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 parser
rm -f $(OBJS) $(OBJS:.o=.d)
rm -f $(LFC) $(YFC) $(YFC:.c=.h) $(YFC:.tab.c=.output)
rm -f *~