-
Notifications
You must be signed in to change notification settings - Fork 53
/
Makefile
266 lines (209 loc) · 6.37 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
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
258
259
260
261
262
263
264
265
266
SHELL := /bin/bash
PWD=$(CURDIR)
PREFIX="$(PWD)/.stack-work/prefix"
UNAME := $(shell uname)
EXAMPLEMILESTONE=examples/milestone
EXAMPLEHTMLOUTPUT=docs/examples/html
EXAMPLES= Collatz/Collatz.juvix \
Fibonacci/Fibonacci.juvix \
Hanoi/Hanoi.juvix \
HelloWorld/HelloWorld.juvix \
PascalsTriangle/PascalsTriangle.juvix \
TicTacToe/CLI/TicTacToe.juvix \
Bank/Bank.juvix \
Tutorial/Tutorial.juvix
DEMO_EXAMPLE=examples/demo/Demo.juvix
MAKEAUXFLAGS?=-s
MAKE=make ${MAKEAUXFLAGS}
METAFILES:=README.md \
CHANGELOG.md \
CONTRIBUTING.md \
LICENSE.md
STACKFLAGS?=--jobs $(THREADS)
STACKTESTFLAGS?=--ta --hide-successes --ta --ansi-tricks=false --ta "+RTS -N -RTS"
SMOKEFLAGS?=--color --diff=git
STACK?=stack
JUVIXBIN?=juvix
CC=clang
ifeq ($(UNAME), Darwin)
THREADS := $(shell sysctl -n hw.logicalcpu)
else ifeq ($(UNAME), Linux)
THREADS := $(shell nproc)
else
THREADS := $(shell echo %NUMBER_OF_PROCESSORS%)
endif
all: build
clean: clean-runtime
@${STACK} clean --full
@rm -rf .hie
.PHONY: clean-hard
clean-hard: clean
@git clean -fdx
.PHONY: clean-runtime
clean-runtime: clean-juvix-build
@cd runtime && ${MAKE} clean
.PHONY: clean-juvix-build
clean-juvix-build:
@find . -type d -name '.juvix-build' | xargs rm -rf
repl:
@${STACK} ghci Juvix:lib ${STACKFLAGS}
# -- EXAMPLES HTML OUTPUT
.PHONY: html-examples
html-examples: $(EXAMPLES)
$(EXAMPLES):
$(eval OUTPUTDIR=$(EXAMPLEHTMLOUTPUT)/$(dir $@))
@mkdir -p ${OUTPUTDIR}
@${JUVIXBIN} html $(EXAMPLEMILESTONE)/$@ --output-dir=$(CURDIR)/${OUTPUTDIR}
.PHONY: demo-example
demo-example:
$(eval OUTPUTDIR=$(EXAMPLEHTMLOUTPUT)/Demo)
@mkdir -p ${OUTPUTDIR}
@${JUVIXBIN} html $(DEMO_EXAMPLE) --output-dir=$(CURDIR)/${OUTPUTDIR}
.PHONY : haddock
haddock :
@cabal --docdir=docs/ --htmldir=docs/ haddock --enable-documentation
# ------------------------------------------------------------------------------
# -- Codebase Health
# ------------------------------------------------------------------------------
ORMOLU?=${STACK} exec -- ormolu
ORMOLUFILES = $(shell git ls-files '*.hs' '*.hs-boot' | grep -v '^contrib/')
ORMOLUFLAGS?=--no-cabal
ORMOLUMODE?=inplace
.PHONY: ormolu
ormolu:
@${ORMOLU} ${ORMOLUFLAGS} \
--mode ${ORMOLUMODE} \
$(ORMOLUFILES)
.PHONY: format
format:
@${MAKE} clang-format
@${MAKE} ormolu
.PHONY: clang-format
clang-format:
@cd runtime && ${MAKE} format
JUVIX_PACKAGES_IN_REPO=$(shell find \
./examples \
./tests/positive \
./tests/negative \
-type d \( -name ".juvix-build" -o -name "FancyPaths" \) -prune -o \
-type f -name 'Package.juvix' -print \
| awk -F'/Package.juvix' '{print $$1}' | sort -u)
JUVIXFORMATFLAGS?=--in-place
JUVIXTYPECHECKFLAGS?=--log-level warn
.PHONY: format-juvix-files
format-juvix-files:
@for p in $(JUVIX_PACKAGES_IN_REPO); do \
${JUVIXBIN} format $(JUVIXFORMATFLAGS) "$$p" > /dev/null 2>&1; \
exit_code=$$?; \
if [ $$exit_code -eq 0 ]; then \
echo "[OK] $$p is formatted"; \
elif [[ $$exit_code -ne 0 && "$$p" == *"tests/"* ]]; then \
echo "[CONTINUE] $$p is in tests directory."; \
else \
echo "[FAIL] $$p formatting failed" && exit 1; \
fi; \
done;
.PHONY: check-format-juvix-files
check-format-juvix-files:
@JUVIXFORMATFLAGS=--check ${MAKE} format-juvix-files
JUVIXEXAMPLEFILES=$(shell find ./examples \
-type d \( -name ".juvix-build" \) -prune -o \
-name "*.juvix" -print)
.PHONY: typecheck-juvix-examples
typecheck-juvix-examples:
@for file in $(JUVIXEXAMPLEFILES); do \
${JUVIXBIN} typecheck "$$file" $(JUVIXTYPECHECKFLAGS); \
exit_code=$$?; \
if [ $$exit_code -eq 0 ]; then \
echo "[OK] $$file typechecks"; \
else \
echo "[FAIL] Typecking failed for $$file" && exit 1; \
fi; \
done
.PHONY: check-ormolu
check-ormolu: export ORMOLUMODE = check
check-ormolu:
@${MAKE} ormolu
PRECOMMIT := $(shell command -v pre-commit 2> /dev/null)
.PHONY : install-pre-commit
install-pre-commit :
@$(if $(PRECOMMIT),, pip install pre-commit)
.PHONY : pre-commit
pre-commit :
@pre-commit run --all-files
# ------------------------------------------------------------------------------
# -- Build-Install-Test-Release
# ------------------------------------------------------------------------------
.PHONY: check-only
check-only:
@${MAKE} build \
&& ${MAKE} install \
&& ${MAKE} test \
&& ${MAKE} smoke \
&& ${MAKE} check-format-juvix-files \
&& ${MAKE} typecheck-juvix-examples \
&& ${MAKE} check-ormolu \
&& export SKIP=ormolu,format-juvix-examples,typecheck-juvix-examples \
&& ${MAKE} pre-commit
.PHONY: check
check: clean
@${MAKE} check-only
.PHONY : bench
bench: runtime submodules
@${STACK} bench ${STACKFLAGS}
# -- Build requirements
.PHONY: submodules
submodules:
@git submodule sync
@git submodule update --init --recursive
.PHONY: build
build: submodules runtime
@${STACK} build ${STACKFLAGS}
.PHONY: fast-build
fast-build: submodules runtime
@${STACK} build --fast ${STACKFLAGS}
.PHONY: configure
configure:
CC=${CC} config/configure.sh
.PHONY: runtime
runtime: configure
cd runtime && make
# -- Install
.PHONY : install
install: runtime submodules
@${STACK} install ${STACKFLAGS}
.PHONY : fast-install
fast-install: runtime submodules
@${STACK} install --fast ${STACKFLAGS}
# -- Testing
.PHONY : test
test: build runtime submodules
@${STACK} test ${STACKFLAGS} ${STACKTESTFLAGS}
.PHONY : fast-test
fast-test: fast-build
@${STACK} test --fast ${STACKFLAGS} ${STACKTESTFLAGS}
.PHONY : test-skip-slow
test-skip-slow:
@${STACK} test ${STACKFLAGS} ${STACKTESTFLAGS} --ta '-p "! /slow tests/"'
.PHONY : fast-test-skip-slow
fast-test-skip-slow:
@${STACK} test --fast ${STACKFLAGS} ${STACKTESTFLAGS} --ta '-p "! /slow tests/"'
SMOKE := $(shell command -v smoke 2> /dev/null)
SHA256SUM := $(shell command -v sha256sum 2> /dev/null)
.PHONY : smoke-only
smoke-only:
@$(if $(SMOKE),, $(error "Smoke not found, please install it from https://github.com/jonaprieto/smoke"))
@$(if $(SHA256SUM),, $(error "sha256sum not found, please install the GNU coreutils package (e.g {apt, brew} install coreutils)"))
@smoke $(shell find tests -name '*.smoke.yaml')
.PHONY : smoke
smoke: install submodules
@${MAKE} smoke-only
# -- Release
.PHONY : changelog
changelog :
@github_changelog_generator
HYPERFINEBIN := $(shell command -v hyperfine 2> /dev/null)
.PHONY : hyperfine-benchmarks
hyperfine-benchmarks:
@$(if $(HYPERFINEBIN),, $(error "hyperfine not found, please install it using cargo or from https://github.com/sharkdp/hyperfine"))
cd bench/hyperfine && ${MAKE}