-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
167 lines (139 loc) · 3.82 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#
# Basic Parser - TurboBasic XL compatible parsing and transformation tool.
# Copyright (C) 2015 Daniel Serpell
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>
#
CROSS=
EXT=
CC=gcc
CFLAGS=-Wall -O2 -g -Wstrict-prototypes -Wmissing-prototypes -Wimplicit-fallthrough
DEPFLAGS=-MMD -MP
LDFLAGS=
LDLIBS=-lm
PEGOPTS=
B=build
# C sources, in "src" directory
SOURCES=\
ataribcd.c\
basexpr.c\
basic.c\
baswriter.c\
convertbas.c\
darray.c\
defs.c\
expr.c\
hash.c\
lister.c\
listexpr.c\
main.c\
optconst.c\
optconstvar.c\
optifgoto.c\
optimize.c\
optlinenum.c\
optrmvars.c\
parser.c\
procparams.c\
program.c\
sbuf.c\
vars.c\
# Word lists, in "peg" directory
WORDS=\
statements.txt\
tokens.txt\
# Source PEG file, in "peg" directory
PEGS=\
peg/basic-base.peg\
peg/directives.peg\
# Generated PEG file
GENPEG=\
$(B)/src/basic.peg
# Output dirs
ODIRS=$(B)/src $(B)/obj
# Git version
GIT_VERSION := $(shell git describe --long --dirty)
# Compressed distribution file, generated with "make dist"
DISTNAME=basicParser-$(GIT_VERSION)
D=$(B)/$(DISTNAME)
ZIPFILE=$(DISTNAME).zip
# Generated source files form PEG and word lists
W_SRC=$(patsubst %.txt, $(B)/src/%.c, $(WORDS))
W_INC=$(patsubst %.txt, $(B)/src/%.h, $(WORDS))
W_PEG=$(patsubst %.txt, $(B)/src/%.peg, $(WORDS))
P_SRC=$(patsubst %.peg, %_peg.c, $(GENPEG))
VERSION_TMP=$(B)/src/version.tmp
VERSION_H=$(B)/src/version.h
# Compiled object files
OBJS=$(patsubst %.c, $(B)/obj/%.o, $(notdir $(SOURCES) $(W_SRC)))
# Add include path from build directory
INCLUDES=-I$(B)/src/
# Main Target
TARGET=$(B)/basicParser$(EXT)
# Main rule - build output directories and main program
all: $(ODIRS) $(TARGET)
# Make directories
$(ODIRS):
mkdir -p $@
# Compile main program
$(TARGET): $(OBJS)
$(CROSS)$(CC) $(CFLAGS) $(INCLUDES) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS)
# Force generating of header files *before* compilation of depending sources
$(OBJS): $(VERSION_H) $(W_INC) $(P_SRC)
# Compile C source
$(B)/obj/%.o: src/%.c
$(CROSS)$(CC) -c $(CFLAGS) $(INCLUDES) $(DEPFLAGS) -o $@ $<
$(B)/obj/%.o: $(B)/src/%.c
$(CROSS)$(CC) -c $(CFLAGS) $(INCLUDES) $(DEPFLAGS) -o $@ $<
# Generate C source from PEG
$(P_SRC): %_peg.c: %.peg
leg -o$@ $<
# Generate version info from GIT
.PHONY: $(VERSION_TMP)
$(VERSION_TMP):
echo "#define GIT_VERSION \"$(GIT_VERSION)\"" > $@
$(VERSION_H): $(VERSION_TMP)
cmp -s $@ $< || cp -f $< $@
rm -f $<
# Special rules for generated word lists
$(W_PEG): $(B)/src/%.peg: peg/%.txt peg/gen-%.awk
awk -f peg/gen-$*.awk $< $(B)/src/
$(W_INC): $(B)/src/%.h: peg/%.txt peg/gen-%.awk
awk -f peg/gen-$*.awk $< $(B)/src/
$(W_SRC): $(B)/src/%.c: peg/%.txt peg/gen-%.awk
awk -f peg/gen-$*.awk $< $(B)/src/
# Concatenation of all peg files
$(B)/src/basic.peg: $(PEGS) $(B)/src/statements.peg $(B)/src/tokens.peg
cat $^ > $@
.PHONY:
clean:
rm -f $(OBJS) $(OBJS:.o=.d) $(TARGET)
distclean: clean
rm -f $(W_PEG) $(W_INC) $(W_SRC) $(P_SRC) $(GENPEG) $(VERSION_H) $(VERSION_TMP)
-rmdir $(ODIRS)
-rmdir $(B)
# Make distribution ZIP
.PHONY:
dist: all
rm -rf $(D)
mkdir -p $(D)
$(CROSS)strip $(TARGET)
cp -a $(TARGET) $(D)/
cp -a README.md $(D)/
cp -a LICENSE $(D)/
cp -a samples $(D)/
rm -f $(B)/$(ZIPFILE)
(cd $B; zip -9vr $(ZIPFILE) $(DISTNAME))
# Include dependencies
-include $(OBJS:.o=.d)