-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathMakefile
More file actions
237 lines (197 loc) · 7.11 KB
/
Copy pathMakefile
File metadata and controls
237 lines (197 loc) · 7.11 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
.PHONY: default check-archive check-tutorial check clean tidy \
exercises rebuild tutorial
MAKEFILE_DIR:=$(dir $(realpath $(lastword $(MAKEFILE_LIST))))
default: tutorial
all: default
clean: tidy
rm -rf docs/exercises docs/solutions docs/exercises.zip \
build TAGS _temp _tests
find . -type f -regex '*.tmp' -delete
tidy:
(cd src/exercises; rm -rf cn.c cn.h *-exec.* *_gen.* *_test.* tests.out cn.o constructors.h)
##############################################################################
# Exercises
H = $(shell find src/exercises -type f -name *.h)
C = $(shell find src/exercises -type f -name *.c)
ALL = $(H) $(C)
TESTONLY = $(shell find src/exercises -type f -name *.test*.c)
VERIFONLY = $(shell find src/exercises -type f -name *.verif*.c)
BROKEN = $(shell find src/exercises -type f -name *broken* -or -name *partial*)
VERIF = $(filter-out $(BROKEN) $(TESTONLY), $(C))
TEST = $(filter-out $(BROKEN) $(VERIFONLY), $(C))
SOLUTIONS=$(patsubst src/exercises/%, docs/solutions/%, $(ALL))
EXERCISES=$(patsubst src/exercises/%, docs/exercises/%, $(ALL))
VERIFIED=$(patsubst src/exercises/%, _temp/verified/%, $(VERIF))
#TESTED=$(patsubst src/exercises/%, _temp/tested/%, $(TEST))
# TEMPORARY:
TESTED = $(patsubst src/exercises/%, _temp/tested/%, $(TESTONLY)) \
_temp/tested/abs_mem_struct.c \
_temp/tested/bcp_framerule.c \
_temp/tested/slf_quadruple_mem.c \
_temp/tested/const_example_lessgood.c \
_temp/tested/transpose2.c \
_temp/tested/slf2_basic_quadruple.signed.c \
_temp/tested/add_read.c \
_temp/tested/slf8_basic_transfer.c \
_temp/tested/slf3_basic_inplace_double.c \
_temp/tested/add_1.c \
_temp/tested/array_load.c \
_temp/tested/slf0_basic_incr.c \
_temp/tested/runway/funcs2.c \
_temp/tested/zero.c \
_temp/tested/slf_incr2_noalias.c \
_temp/tested/slf10_basic_ref.c \
_temp/tested/add_2.c \
_temp/tested/between.c \
_temp/tested/array_read_two.c \
_temp/tested/transpose.c \
_temp/tested/read2.c \
_temp/tested/read.c \
_temp/tested/slf1_basic_example_let.c \
_temp/tested/slf_incr2_alias.c \
_temp/tested/abs_mem.c \
_temp/tested/array_swap.c \
_temp/tested/const_example.c \
_temp/tested/add.partial.c \
_temp/tested/init_point.c \
_temp/tested/min3/min3.fixed.c \
_temp/tested/min3/min3.partial.c \
_temp/tested/id_by_div/id_by_div.fixed.c \
_temp/tested/slf2_basic_quadruple.c \
_temp/tested/swap.c \
_temp/tested/slf1_basic_example_let.signed.c \
_temp/tested/slf9_basic_transfer_aliased.c \
_temp/tested/array_load2.c \
_temp/tested/add_0.c \
_temp/tested/abs.c \
_temp/tested/slf0_basic_incr.signed.c \
_temp/tested/slf15_basic_succ_using_incr_attempt_.c
# Extra dependencies
define extradeps
_temp/tested/$1/*.c : src/exercises/$1/*.h
_temp/verified/$1/*.c : src/exercises/$1/*.h
endef
$(eval $(call extradeps,list))
$(eval $(call extradeps,queue))
$(eval $(call extradeps,dllist))
# NOT WORKING?
# _temp/tested/slf18_two_dice.c \
MD = $(shell find docs -type f -name "*.md")
CONSISTENT=$(patsubst %, _temp/consistent/%, $(MD))
exercises: $(EXERCISES) $(SOLUTIONS) $(TESTED) $(VERIFIED) $(CONSISTENT)
CNWAR=--include $(MAKEFILE_DIR)/src/exercises/cn_wars.h
CN=cn verify $(CNWAR)
CNTEST=cn test --output-dir _temp --progress-level=function $(CNWAR)
# Control verbosity (run make with V= to show everything that's happening)
V=@
# BCP: This is a temporary hack to use gcc to preprocess #includes
# because CN doesn't handle them right.
_temp/tested/% : src/exercises/%
$(V)echo Testing $<
$(V)-mkdir -p $(dir $@)
$(V)-mkdir -p $(dir _temp/$<.combined.c)
$(V)gcc -E -CC -P $< > _temp/$<.combined.c
$(V)$(CNTEST) _temp/$<.combined.c 2>&1 | tee $@.test.out
$(V)-grep "PASSED\\|FAILED" $@.test.out || true
@# Next line should not be needed!
$(V)if grep -q "FAILED\\|fatal error\\|Failed to compile\\|Failed to link\\|: error:" $@.test.out; then \
exit 1; \
fi
$(V)touch $@
## BCP: Better version...
#
# _temp/tested/% : src/exercises/%
# $(V)echo Testing $<
# $(V)-mkdir -p $(dir $@)
# $(V)$(CNTEST) $< 2>&1 | tee $@.test.out
# $(V)-grep "PASSED\\|FAILED" $@.test.out || true
# @# Next line should not be needed!
# $(V)if grep -q "fatal error\\|Failed to compile" $@.test.out; then \
# exit 1; \
# fi
# $(V)touch $@
_temp/verified/% : src/exercises/%
$(V)echo Verifying $<
$(V)-mkdir -p $(dir $@)
$(V)$(CN) $< 2>&1 | tee $@.verif.out
$(V)if grep -q "fatal error\\|Failed to compile\\|Failed to link\\|: error:" $@.verif.out; then \
exit 1; \
fi
$(V)touch $@
docs/exercises/%: src/exercises/%
$(V)echo Rebuild $@
$(V)-mkdir -p $(dir $@)
$(V)sed -E '\|^.*--BEGIN--.*$$|,\|^.*--END--.*$$|d' $< > $@
docs/solutions/%: src/exercises/%
$(V)echo Rebuild $@
$(V)-mkdir -p $(dir $@)
$(V)cat $< | sed '\|^.*--BEGIN--.*$$|d' | sed '\|^.*--END--.*$$|d' > $@
docs/exercises.zip: $(EXERCISES)
cd docs; zip -r exercises.zip exercises > /dev/null
WORKING=$(wildcard src/exercises/list_*.c)
WORKING_AUX=$(patsubst src/exercises/%, docs/solutions/%, $(WORKING))
# cn test --output-dir=$(HOME)/tmp read.broken.c
# OLD
# docs/solutions/%: src/exercises/%
# @-mkdir -p $(dir $@)
# @-mkdir -p _tests
# @if [ `which cn` ]; then \
# if [[ "$<" = *".c"* ]]; then \
# if [[ "$<" != *"broken"* && "$<" != *"partial"* && "$<" != *".DS_Store"* ]]; then \
# if [[ "$<" = *".test."*c ]]; then \
# echo $(CNTEST) $< && $(CNTEST) $< --output _tests; \
# else \
# echo $(CN) $< && $(CN) $<; \
# fi; \
# fi; \
# fi \
# fi
# @echo Rebuild $@
# @cat $< | sed '\|^.*--BEGIN--.*$$|d' | sed '\|^.*--END--.*$$|d' > $@
##############################################################################
# Check that the examples all run correctly
CN_PATH?=cn verify
CN_PATH+=$(CNWAR)
check-archive:
@echo Check archive examples
$(V)$(MAKEFILE_DIR)/src/example-archive/check-all.sh "$(CN_PATH)"
check: exercises check-archive
##############################################################################
# Check for inconsistent exercise names / paths
_temp/consistent/% : %
$(V)perl -0777 -ne \
'while (/c title=\"(.+)\"\n.+\n(.+)\n/g) {' \
-e 'if ($$1 ne $$2) {' \
-e 'print "Bad .md file ($<): $$1 does not match $$2\n";' \
-e 'exit 1;' \
-e '} }' \
$<
$(V)-mkdir -p $(dir $@)
$(V)touch $@
##############################################################################
# Tutorial document
# BCP: Added the --quiet flag to suppress a bunch of INFO messages
# that the macros plugin was generating on every compile
tutorial: rebuild
mkdocs build --strict --quiet
serve: rebuild
mkdocs serve --quiet
rebuild: exercises docs/exercises.zip mkdocs.yml $(shell find docs -type f)
servecomments:
TUTORIAL_TODOS= $(MAKE) serve
##############################################################################
# Misc
TAGS:
@echo Rebuilding TAGS
@etags src/tutorial.adoc $(SRC_EXERCISES)
##############################################################################
# Personal and site-specific stuff
bcp: TAGS
$(MAKE) default
osascript \
-e 'tell application "Safari"' \
-e 'tell its first document' \
-e 'set its URL to (get its URL)' \
-e 'end tell' \
-e 'activate' \
-e 'end tell'