forked from ankitects/anki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
204 lines (171 loc) · 4.81 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
SHELL := /bin/bash
ifndef SHELLFLAGS
SHELLFLAGS :=
endif
.SHELLFLAGS := -eu -o pipefail ${SHELLFLAGS} -c
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
FIND := $(if $(wildcard /bin/find),/bin/find,/usr/bin/find)
ifndef OS
OS := unknown
endif
ifeq (${OS},Windows_NT)
# Windows terminal is confusing it with its `cmd` builtin `rename` command
ifndef RENAME_BIN
RENAME_BIN := perl scripts/rename
endif
ifndef ACTIVATE_SCRIPT
ACTIVATE_SCRIPT := pyenv/Scripts/activate
endif
ifndef PYTHON_BIN
PYTHON_BIN := python
endif
else
ifndef RENAME_BIN
RENAME_BIN := scripts/rename
endif
ifndef ACTIVATE_SCRIPT
ACTIVATE_SCRIPT := pyenv/bin/activate
endif
ifndef PYTHON_BIN
PYTHON_BIN := python3
endif
endif
ifndef ANKI_EXTRA_PIP
ANKI_EXTRA_PIP := true
endif
.DELETE_ON_ERROR:
SUBMAKE := $(MAKE) --print-directory
.SUFFIXES:
BUILDFLAGS := --release --strip
DEVFLAGS :=
RUNFLAGS :=
CHECKABLE_PY := pylib qt
CHECKABLE_RS := rslib rspy
DEVEL := rslib rspy pylib ts qt
.PHONY: all
all: run
# - modern pip required for wheel
# - add qt if missing
pyenv:
# https://github.com/PyO3/maturin/issues/283 - Expected `python` to be a python interpreter inside a virtualenv
set -eu -o pipefail ${SHELLFLAGS}; \
"${PYTHON_BIN}" -m venv pyenv; \
case "$$(uname -s)" in CYGWIN*|MINGW*|MSYS*) \
dos2unix "${ACTIVATE_SCRIPT}"; \
VIRTUAL_ENV="$$(pwd)"; \
VIRTUAL_ENV="$$(cygpath -m "$${VIRTUAL_ENV}")"; \
sed -i -- "s@VIRTUAL_ENV=\".*\"@VIRTUAL_ENV=\"$$(pwd)/pyenv\"@g" "${ACTIVATE_SCRIPT}"; \
sed -i -- "s@export PATH@export PATH; VIRTUAL_ENV=\"$${VIRTUAL_ENV}/pyenv\";@g" "${ACTIVATE_SCRIPT}"; \
;; esac; \
. "${ACTIVATE_SCRIPT}"; \
python --version; \
python -m pip install --upgrade pip setuptools; \
${ANKI_EXTRA_PIP}; \
if ! python -c 'import PyQt5' 2>/dev/null; then \
python -m pip install -r qt/requirements.qt; \
fi;
# update build hash
.PHONY: buildhash
buildhash:
@set -eu -o pipefail ${SHELLFLAGS}; \
oldhash=$$(test -f meta/buildhash && cat meta/buildhash || true); \
newhash=$$(git rev-parse --short=8 HEAD || echo dev); \
if [ "$$oldhash" != "$$newhash" ]; then \
echo $$newhash > meta/buildhash; \
fi
.PHONY: develop
develop: pyenv buildhash prepare
@set -eu -o pipefail ${SHELLFLAGS}; \
. "${ACTIVATE_SCRIPT}"; \
for dir in $(DEVEL); do \
$(SUBMAKE) -C $$dir develop DEVFLAGS="$(DEVFLAGS)"; \
done
.PHONY: run
run: develop
@set -eu -o pipefail ${SHELLFLAGS}; \
. "${ACTIVATE_SCRIPT}"; \
echo "Starting Anki..."; \
python qt/runanki $(RUNFLAGS)
.PHONY: prepare
prepare: rslib/ftl/repo qt/ftl/repo qt/po/repo
rslib/ftl/repo:
$(MAKE) pull-i18n
qt/ftl/repo:
$(MAKE) pull-i18n
qt/po/repo:
$(MAKE) pull-i18n
.PHONY: build
build: clean-dist build-ts build-rspy build-pylib build-qt add-buildhash
@echo
@echo "Build complete."
.PHONY: build-ts
build-ts:
$(SUBMAKE) -C ts build
.PHONY: build-rspy
build-rspy: pyenv buildhash
@set -eu -o pipefail ${SHELLFLAGS}; \
. "${ACTIVATE_SCRIPT}"; \
$(SUBMAKE) -C rspy build BUILDFLAGS="$(BUILDFLAGS)"
.PHONY: build-pylib
build-pylib:
@set -eu -o pipefail ${SHELLFLAGS}; \
. "${ACTIVATE_SCRIPT}"; \
$(SUBMAKE) -C pylib build
.PHONY: build-qt
build-qt:
@set -eu -o pipefail ${SHELLFLAGS}; \
. "${ACTIVATE_SCRIPT}"; \
$(SUBMAKE) -C qt build
.PHONY: clean
clean: clean-dist
@set -eu -o pipefail ${SHELLFLAGS}; \
for dir in $(DEVEL); do \
$(SUBMAKE) -C $$dir clean; \
done
# remove any files in dist/ folder without current build hash
.PHONY: clean-dist
clean-dist: buildhash
"${FIND}" dist \! -name "*$$(cat meta/buildhash)*" -type f -delete
.PHONY: check
check: pyenv buildhash prepare
@set -eu -o pipefail ${SHELLFLAGS}; \
.github/scripts/trailing-newlines.sh; \
. "${ACTIVATE_SCRIPT}"; \
for dir in $(CHECKABLE_RS) ts $(CHECKABLE_PY); do \
$(SUBMAKE) -C $$dir check; \
done;
@echo
@echo "All checks passed!"
.PHONY: fix
fix: develop
@set -eu -o pipefail ${SHELLFLAGS}; \
. "${ACTIVATE_SCRIPT}"; \
for dir in $(CHECKABLE_RS) $(CHECKABLE_PY); do \
$(SUBMAKE) -C $$dir fix; \
done; \
.PHONY: add-buildhash
add-buildhash:
@set -eu -o pipefail ${SHELLFLAGS}; \
ver="$$(cat meta/version)"; \
hash="$$(cat meta/buildhash)"; \
${RENAME_BIN} -f "s/-$${ver}(\.|-)/-$${ver}+$${hash}\$$1/" dist/*-"$${ver}"*
.PHONY: pull-i18n
pull-i18n:
(cd rslib/ftl && scripts/fetch-latest-translations)
(cd qt/ftl && scripts/fetch-latest-translations)
(cd qt/po && scripts/fetch-latest-translations)
.PHONY: push-i18n-ftl
push-i18n-ftl: pull-i18n
(cd rslib/ftl && scripts/upload-latest-templates)
(cd qt/ftl && scripts/upload-latest-templates)
.PHONY: push-i18n-po
push-i18n-po: pull-i18n
(cd qt/po && scripts/upload-latest-template)
.PHONY: ts-dev
ts-dev: develop
@set -eu -o pipefail ${SHELLFLAGS}; \
. "${ACTIVATE_SCRIPT}"; \
tmux new -d -s anki-ts "ANKIDEV=1 ANKI_API_PORT=9001 python qt/runanki $(RUNFLAGS)"
tmux split-window "(cd ts && make dev)"
tmux attach