-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
257 lines (214 loc) · 6.02 KB
/
Makefile
File metadata and controls
257 lines (214 loc) · 6.02 KB
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
##################
# CONFIGURATIONS #
##################
srcdir := .
objdir := $(srcdir)/.object
depdir := $(srcdir)/.depend
headir := $(srcdir)/header
datdir := dat
insdir := bin
hookdir := hook
exec := proofread
sources := $(wildcard $(srcdir)/*.c)
objects := $(sources:$(srcdir)/%.c=$(objdir)/%.o)
srcs_insdir_required := $(addprefix $(srcdir)/,optprocessor.c proofread.c)
objs_insdir_required := $(srcs_insdir_required:$(srcdir)/%.c=$(objdir)/%.o)
hook_exec := pre-commit
hook_srcs := $(hookdir)/$(hook_exec).c
hook_objs := $(hook_srcs:%.c=%.o)
hook_deps := $(addprefix $(objdir)/,strutil.o wrapper.o readline.o fatal.o)
SHELL := /bin/sh
CC := gcc
DEV_CFLAGS := -g -Wall -W -pedantic
CFLAGS := -O3 -g
CPPFLAGS := -I $(headir)
# resets the default suffix list
.SUFFIXES:
.SUFFIXES: .c .o .h
###############
# COMPILATION #
###############
# DEFAULT GOAL
.PHONY: all
all: $(exec)
$(exec): $(objects)
$(CC) $^ $(CFLAGS) -o $@
EXT_LIST :=
SHUTUP := 1
hook: $(hook_objs) $(hook_deps)
$(CC) $^ $(CPPFLAGS) $(CFLAGS) -o $(hookdir)/$(hook_exec)
$(hook_objs): $(hook_srcs)
$(CC) $(hook_srcs) -DEXT_LIST='$(EXT_LIST)' -DSHUTUP=$(SHUTUP) $(CPPFLAGS) $(CFLAGS) -c -o $@
# auto-generates dependency files
$(depdir)/%.d: $(srcdir)/%.c
@set -e; rm -f $@; \
$(CC) $< $(CPPFLAGS) -MM > $@.$$$$; \
printf "%s%s" "$(objdir)/" "$$(cat $@.$$$$)" > $@; \
rm -f $@.$$$$
include $(sources:$(srcdir)/%.c=$(depdir)/%.d)
# Note that this is a pattern rule and thus an implicit rule.
$(objdir)/%.o:
$(CC) $< $(CPPFLAGS) $(CFLAGS) -c -o $@
# This is an explicit rule and takes precedence over the implicit rule.
$(objs_insdir_required):
$(CC) $< -DPATH='"$(insdir)"' $(CPPFLAGS) $(CFLAGS) -c -o $@
#################
# MISCELLANEOUS #
#################
.PHONY: clean
clean:
rm -f $(exec) $(depdir)/*.d $(objdir)/*.o
rm -f $(hookdir)/$(hook_exec) $(hookdir)/$(hook_exec).o
.PHONY: install
bakdir := bak
install: $(exec)
test -d $(insdir) || (mkdir $(insdir) && mkdir $(insdir)/$(bakdir) && mkdir $(insdir)/$(datdir))
install $(exec) $(insdir)
install -m 444 --target-directory=$(insdir)/$(datdir) $(datdir)/*
.PHONY: help
define clrstr
"\033[$1m$2\033[0m"
endef
Cyellow = $(call clrstr,33,$1)
help:
@echo $(call Cyellow,make)
@echo " Builds the executable."
@echo ""
@echo $(call Cyellow,make install insdir=<directory-name>)
@echo " Copies the exe with related files under the specified directory."
@echo " Defaults to \"bin\"."
@echo ""
@echo $(call Cyellow,make hook EXT_LIST=<list> SHUTUP=<value>)
@echo " Builds the pre-commit hook. For the variables, please refer to the manual page."
###########
# DEVELOP #
###########
.PHONY: doc
docbase := $(datdir)/$(exec).1
docbasetmp := $(docbase).tmp
doctxt := $(docbase).txt
doctxttmp := $(doctxt).tmp
version_placeholder := %(describe:tags=true,exclude=nightly)
date_placeholder := %as
doc:
# update proofread.1
echo ".TH $(exec) 1 $$(git log -1 --pretty=format:'$(date_placeholder) $(version_placeholder)')" > $(docbasetmp)
tail --lines=+2 -- $(docbase) >> $(docbasetmp)
rm $(docbase)
mv $(docbasetmp) $(docbase)
# update proofread.1.txt
man $(docbase) > $(doctxt)
head --lines=-1 -- $(doctxt) > $(doctxttmp)
echo $$(git log -1 --pretty=format:'$(version_placeholder)') >> $(doctxttmp)
echo $$(git log -1 --pretty=format:'$(date_placeholder)') >> $(doctxttmp)
rm $(doctxt)
mv $(doctxttmp) $(doctxt)
.PHONY: version
vsntxt := $(datdir)/version.txt
version:
git describe --tags --exclude 'nightly' core > $(vsntxt)
.PHONY: dev
dev:
$(MAKE) CFLAGS='$(DEV_CFLAGS)' --always-make
.PHONY: hookinst
hookinst:
cp hook/pre-commit .git/hooks/
.PHONY: archive
archive_prefix := $(exec)_$$(cat $(vsntxt))
manpage := $(datdir)/$(exec).1
manpagetxt := $(manpage).txt
archive: doc version
git archive core \
--prefix=$(archive_prefix)/$(datdir)/ \
--add-file=$(manpage) \
--add-file=$(manpagetxt) \
--add-file=$(vsntxt) \
--prefix=$(archive_prefix)/ \
| gzip > $(archive_prefix).tar.gz
git checkout core -- $(manpage) $(manpagetxt) $(vsntxt)
.PHONY: night
night:
git push origin :nightly
git tag -d nightly
git tag --no-sign nightly core
git push origin --tags
tests := nt lt ft at ntl ltl ftl atl st kt wt
.PHONY: $(tests)
.ONESHELL: $(tests)
# test: does not test against any condition
nt:
cd test
proofread --dry-run + -- ok l f lf
# test: against -l option
lt:
cd test
proofread -l --dry-run + -- ok l f lf
# test: against -f option
ft:
cd test
proofread -f --dry-run + -- ok l f lf
# test: against -l and -f options
at:
cd test
proofread -lf --dry-run + -- ok l f lf
# test: dry-run=line, no condition
ntl:
cd test
proofread --dry-run=line + -- ok l f lf
# test: dry-run=line, -l
ltl:
cd test
proofread -l --dry-run=line + -- ok l f lf
# test: dry-run=line, -f
ftl:
cd test
proofread -f --dry-run=line + -- ok l f lf
# test: dry-run=line, -l -f
atl:
cd test
proofread -lf --dry-run=line + -- ok l f lf
# test: stdin-stdout
st:
cd test
proofread < lf | proofread --dry-run=line
proofread -l < lf | proofread -l --dry-run=line
proofread -f < lf | proofread -f --dry-run=line
proofread -lf < lf | proofread -lf --dry-run=line
# test: --keep option; compare original against fixed
kt:
cp test/lf test/lf.copy
proofread --keep=bak + test/lf
proofread --dry-run=line + bak/lf
proofread --dry-run=line + test/lf
cp test/lf.copy test/lf
proofread --keep=bak -l + test/lf
proofread -l --dry-run=line + bak/lf
proofread -l --dry-run=line + test/lf
cp test/lf.copy test/lf
proofread --keep=bak -f + test/lf
proofread -f --dry-run=line + bak/lf
proofread -f --dry-run=line + test/lf
cp test/lf.copy test/lf
proofread --keep=bak -lf + test/lf
proofread -lf --dry-run=line + bak/lf
proofread -lf --dry-run=line + test/lf
cp test/lf.copy test/lf
rm bak/lf
rm test/lf.copy
# test: write to a file
wt:
cd test
cp lf lf.copy
proofread + lf
proofread --dry-run=line + lf
cp lf.copy lf
proofread -l + lf
proofread -l --dry-run=line + lf
cp lf.copy lf
proofread -f + lf
proofread -f --dry-run=line + lf
cp lf.copy lf
proofread -lf + lf
proofread -lf --dry-run=line + lf
cp lf.copy lf
rm lf.copy