-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
215 lines (162 loc) · 4.58 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
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
SHELL := bash
ROOT := $(shell pwd)
BIN := bin
YS_VERSION := 0.1.81
YS_LOCAL := .local
YS_LOCAL_PREFIX := $(YS_LOCAL)/v$(YS_VERSION)
YS_LOCAL_BIN := $(YS_LOCAL_PREFIX)/bin
YS := $(YS_LOCAL_PREFIX)/bin/ys-$(YS_VERSION)
CFGLET := $(BIN)/configlet
SHELLCHECK := $(BIN)/shellcheck
VERIFY := $(BIN)/verify-exercises
ifdef EXERCISM_YAMLSCRIPT_GHA
YS := ys-$(YS_VERSION)
SHELLCHECK := shellcheck
endif
export PATH := $(ROOT)/bin:$(YS_LOCAL_BIN):$(PATH)
EXERCISE_DIRS := $(shell find exercises -name .meta | sort)
EXERCISE_DIRS := $(EXERCISE_DIRS:%/.meta=%)
EXERCISES := $(EXERCISE_DIRS:exercises/practice/%=%)
EXERCISE_MAKEFILES := $(EXERCISE_DIRS:%=%/Makefile)
EXERCISE_GNU_MAKEFILES := $(EXERCISE_DIRS:%=%/GNUmakefile)
EXERCISE_META_MAKEFILES := $(EXERCISE_DIRS:%=%/.meta/Makefile)
EXERCISE_YS_INSTALLERS := $(EXERCISE_DIRS:%=%/.yamlscript/exercism-ys-installer)
CHECKS := \
check-yaml \
check-shell \
check-exercism \
check-verify \
GEN_FILES := \
$(EXERCISE_MAKEFILES) \
$(EXERCISE_GNU_MAKEFILES) \
$(EXERCISE_META_MAKEFILES) \
$(EXERCISE_YS_INSTALLERS) \
config.json \
SHELL_FILES := \
$(BIN)/fetch-configlet \
$(BIN)/new-exercise \
$(BIN)/verify-exercises \
YAML_FILES := \
config.yaml \
PROBLEM_REPO := .problem
PROBLEM_REPO_URL := https://github.com/exercism/problem-specifications
CLOJURE_REPO := .clojure
CLOJURE_REPO_URL := https://github.com/exercism/clojure
SHELLCHECK_VERSION := v0.10.0
SHELLCHECK_REPO := https://github.com/koalaman/shellcheck
SHELLCHECK_RELEASES := $(SHELLCHECK_REPO)/releases/download
SHELLCHECK_DIR := shellcheck-$(SHELLCHECK_VERSION)
SHELLCHECK_TAR := $(SHELLCHECK_DIR).linux.x86_64.tar.xz
SHELLCHECK_RELEASE := \
$(SHELLCHECK_RELEASES)/$(SHELLCHECK_VERSION)/$(SHELLCHECK_TAR)
LINE := $(shell printf '%.0s-' {1..80})
slug ?=
test ?=
v ?=
ifeq (,$(test))
test-name := all exercises
override test := exercises/practice/*/.meta/*-test.ys
else
test-name := $(test)
override test := exercises/practice/$(test)/.meta/*-test.ys
endif
a := (
b := )
export YSPATH := $(shell IFS=:; p=$aexercises/practice/*/.meta$b; \
echo "$${p[*]}")
#------------------------------------------------------------------------------
default:
.PHONY: new
new: $(CFGLET) $(YS) $(PROBLEM_REPO) $(CLOJURE_REPO)
ifndef slug
$(error Please set the 'slug' variable)
endif
@exercise=$(slug) new-exercise
generate-all: $(PROBLEM_REPO)
generate-all-exercises $(slug) $(slugs)
check: $(YS) $(CHECKS)
@echo $(LINE)
test: test-exercises
@echo $(LINE)
test-each: update
for d in exercises/practice/*/.meta; do make -C $$d test || exit; done
update: $(GEN_FILES)
deps: $(YS) $(CFGLET) $(SHELLCHECK)
test-exercises: $(YS) update
@echo $(LINE)
@echo '*** Running tests for $(test-name)'
@$(MAKE) --no-print-directory run-tests
@echo '*** All exercises test ok'
run-tests:
prove $(if $v,-v ,)$(test)
check-yaml: $(YS) $(YAML_FILES)
@echo $(LINE)
@echo '*** Test YAML files'
@for yaml in $(YAML_FILES); do \
(set -x; $< -l $$yaml > /dev/null); \
done
@echo '*** YAML files are OK'
@echo
check-shell: $(SHELLCHECK)
@echo $(LINE)
@echo '*** Test shell script files'
$< $(SHELL_FILES)
@echo '*** Shell script files are OK'
@echo
check-exercism: $(CFGLET) update
@echo $(LINE)
@echo '*** Test Exercism setup'
$< lint
@echo '*** Exercism setup is OK'
@echo
check-verify: update
@echo $(LINE)
@echo '*** Test all exercises are verified'
$(VERIFY) $(slug)
@echo '*** All exercises are verified OK'
@echo
clean:
$(RM) -r shellcheck*
realclean: clean
$(RM) $(CFGLET)
$(RM) $(SHELLCHECK)
$(RM) -r $(CLOJURE_REPO) $(PROBLEM_REPO) $(YS_LOCAL)
reset:
git checkout -- config.*
git status -- exercises | grep exercises | xargs rm -fr
exercises/practice/%/GNUmakefile: common/gnumakefile.mk
cp -p $< $@
exercises/practice/%/Makefile: common/makefile.mk
cp -p $< $@
exercises/practice/%/.meta/Makefile: common/meta-makefile.mk
cp -p $< $@
exercises/practice/%/.yamlscript/exercism-ys-installer: common/exercism-ys-installer
mkdir -p $$(dirname $@)
cp -p $< $@
%.json: %.yaml $(YS) Makefile
$(YS) -l $< | jq > $@
$(PROBLEM_REPO):
git clone $(PROBLEM_REPO_URL) $@
$(CLOJURE_REPO):
git clone $(CLOJURE_REPO_URL) $@
$(CFGLET):
$(BIN)/fetch-configlet
ifdef EXERCISM_YAMLSCRIPT_GHA
# Dummy rule for GHA
$(YS) shellcheck:
else
$(YS):
curl -s https://yamlscript.org/install | \
BIN=1 PREFIX=$(YS_LOCAL_PREFIX) VERSION=$(YS_VERSION) bash
ifeq (,$(wildcard $(SHELLCHECK)))
bin/shellcheck: $(SHELLCHECK_DIR)
mv $</shellcheck $@
touch $@
$(RM) -r $<
$(RM) $(SHELLCHECK_TAR)
endif
$(SHELLCHECK_DIR): $(SHELLCHECK_TAR)
tar xf $<
$(SHELLCHECK_TAR):
curl -sSOL $(SHELLCHECK_RELEASE)
endif