-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
116 lines (81 loc) · 2.31 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
# Default: compile for debug
DEBUG ?= 1
DEBUG_GEN_FILES ?= 0
PROFILE ?= 0
CC = gcc -g
BASICFLAGS= -std=c11
DEBUGFLAGS= -g
OPTFLAGS= -finline -march=native -O3 -DNDEBUG
ifeq ($(PROFILE),1)
PROFFLAGS= -pg
PLFLAGS= -pg
BISONFLAGS=
else
PROFFLAGS=
PLFLAGS=
BISONFLAGS=-d --report=state --report-file=./bstate.debug
endif
INCLUDE_PATH=-I.
CFLAGS= -Wall -D_GNU_SOURCE $(BASICFLAGS)
ifneq ($(DEBUG_GEN_FILES), 1)
SAMPLE_CFLAGS= -D_GNU_SOURCE $(BASICFLAGS) -w
else
SAMPLE_CFLAGS= $(CFLAGS)
endif
ifeq ($(DEBUG),1)
CFLAGS+= $(DEBUGFLAGS) $(PROFFLAGS) $(INCLUDE_PATH)
else
CFLAGS+= $(OPTFLAGS) $(PROFFLAGS) $(INCLUDE_PATH)
endif
LDFLAGS= $(PLFLAGS) $(BASICFLAGS)
LIBS=-lfl
FLEX=flex
BISON=bison
#------------------------------------------
# app
#------------------------------------------
C_PROG= ptucc ptucc_scan sample001
C_SOURCES= ptucc.c ptucc_scan.c cgen.c hashtable.c config.c
C_GEN=ptucc_lex.c ptucc_parser.tab.h ptucc_parser.tab.c sample001.c
C_SRC= $(C_SOURCES) $(C_GEN)
C_OBJECTS=$(C_SRC:.c=.o)
.PHONY: all tests release clean distclean
all: ptucc_lex.c ptucc
ptucc: ptucc.o ptucc_lex.o ptucc_parser.tab.o cgen.o hashtable.o config.o
$(CC) $(CFLAGS) -o $@ $+ $(LIBS)
ptucc_scan: ptucc_scan.o ptucc_lex.o ptucc_parser.tab.o cgen.o hashtable.o config.o
$(CC) $(CFLAGS) -o $@ $+ $(LIBS)
ptucc_lex.c: ptucc_lex.l ptucc_parser.tab.h
$(FLEX) -o ptucc_lex.c ptucc_lex.l
ptucc_parser.tab.c ptucc_parser.tab.h: ptucc_parser.y
$(BISON) $(BISONFLAGS) ptucc_parser.y
%: ptucc_scan ptucc %.ptuc
./ptucc < [email protected] > [email protected]
$(CC) $(SAMPLE_CFLAGS) -o $@ [email protected]
./$@
test: ptucc_scan ptucc
./ptucc < sample001.ptuc > sample001.c
$(CC) $(SAMPLE_CFLAGS) -o sample001 sample001.c
./sample001
#-----------------------------------------------------
# Build control
#-----------------------------------------------------
distclean: realclean
-touch .depend
-rm *~
realclean:
-rm $(C_PROG) $(C_OBJECTS) $(C_GEN) .depend *.o sample001.c sample001
-rm .depend
-touch .depend
clean: realclean
include .depend
# Create release archive
release: clean-release-files ptucc.tgz
clean-release-files:
-rm ptucc.tgz
TARFILES= cgen.c cgen.h Makefile ptucc.c ptucc_lex.l \
ptucc_parser.y ptucc_scan.c ptuclib.h \
README.md hashtable.c hashtable.h
ptucc.tgz: $(TARFILES)
$(MAKE) distclean
tar czvhf ptucc.tgz $(TARFILES)