2020-02-24 18:58:07 +01:00
|
|
|
SHELL := /bin/bash
|
|
|
|
|
2020-03-22 19:52:56 +01:00
|
|
|
ifndef SHELLFLAGS
|
|
|
|
SHELLFLAGS :=
|
|
|
|
endif
|
|
|
|
|
|
|
|
.SHELLFLAGS := -eu -o pipefail ${SHELLFLAGS} -c
|
|
|
|
MAKEFLAGS += --warn-undefined-variables
|
|
|
|
MAKEFLAGS += --no-builtin-rules
|
2020-04-26 08:02:02 +02:00
|
|
|
FIND := $(if $(wildcard /bin/find),/bin/find,/usr/bin/find)
|
2020-03-22 19:52:56 +01:00
|
|
|
|
2020-03-04 00:51:24 +01:00
|
|
|
ifndef OS
|
|
|
|
OS := unknown
|
|
|
|
endif
|
|
|
|
|
2020-03-22 19:52:56 +01:00
|
|
|
ifeq (${OS},Windows_NT)
|
2020-04-25 02:48:46 +02:00
|
|
|
# Windows terminal is confusing it with its `cmd` builtin `rename` command
|
2020-03-22 19:52:56 +01:00
|
|
|
ifndef RENAME_BIN
|
2020-04-14 11:49:07 +02:00
|
|
|
RENAME_BIN := perl scripts/rename
|
2020-03-22 19:52:56 +01:00
|
|
|
endif
|
|
|
|
|
2020-03-02 00:49:45 +01:00
|
|
|
ifndef ACTIVATE_SCRIPT
|
|
|
|
ACTIVATE_SCRIPT := pyenv/Scripts/activate
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifndef PYTHON_BIN
|
|
|
|
PYTHON_BIN := python
|
|
|
|
endif
|
2020-02-24 18:58:07 +01:00
|
|
|
else
|
2020-03-22 19:52:56 +01:00
|
|
|
ifndef RENAME_BIN
|
2020-04-14 11:49:07 +02:00
|
|
|
RENAME_BIN := scripts/rename
|
2020-03-22 19:52:56 +01:00
|
|
|
endif
|
|
|
|
|
2020-03-02 00:49:45 +01:00
|
|
|
ifndef ACTIVATE_SCRIPT
|
|
|
|
ACTIVATE_SCRIPT := pyenv/bin/activate
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifndef PYTHON_BIN
|
|
|
|
PYTHON_BIN := python3
|
|
|
|
endif
|
2020-02-24 18:58:07 +01:00
|
|
|
endif
|
|
|
|
|
2020-02-27 04:42:49 +01:00
|
|
|
ifndef ANKI_EXTRA_PIP
|
2020-02-27 05:22:53 +01:00
|
|
|
ANKI_EXTRA_PIP := true
|
2020-02-27 04:42:49 +01:00
|
|
|
endif
|
|
|
|
|
2020-01-04 00:38:04 +01:00
|
|
|
.DELETE_ON_ERROR:
|
|
|
|
SUBMAKE := $(MAKE) --print-directory
|
|
|
|
.SUFFIXES:
|
|
|
|
|
|
|
|
BUILDFLAGS := --release --strip
|
2020-03-06 04:29:23 +01:00
|
|
|
DEVFLAGS := $(BUILDFLAGS)
|
2020-01-04 00:38:04 +01:00
|
|
|
RUNFLAGS :=
|
2020-01-28 23:57:42 +01:00
|
|
|
CHECKABLE_PY := pylib qt
|
2020-04-30 09:11:50 +02:00
|
|
|
CHECKABLE_RS := rslib rspy
|
2020-02-06 01:16:50 +01:00
|
|
|
DEVEL := rslib rspy pylib qt
|
2020-01-04 00:38:04 +01:00
|
|
|
|
2020-02-02 23:43:10 +01:00
|
|
|
.PHONY: all
|
|
|
|
all: run
|
|
|
|
|
2020-01-04 00:38:04 +01:00
|
|
|
# - modern pip required for wheel
|
|
|
|
# - add qt if missing
|
|
|
|
pyenv:
|
2020-05-09 05:00:16 +02:00
|
|
|
# https://github.com/PyO3/maturin/issues/283 - Expected `python` to be a python interpreter inside a virtualenv
|
2020-03-25 05:38:37 +01:00
|
|
|
set -eu -o pipefail ${SHELLFLAGS}; \
|
|
|
|
"${PYTHON_BIN}" -m pip install virtualenv; \
|
|
|
|
"${PYTHON_BIN}" -m venv pyenv; \
|
2020-03-22 19:52:56 +01:00
|
|
|
case "$$(uname -s)" in CYGWIN*|MINGW*|MSYS*) \
|
2020-03-25 05:38:37 +01:00
|
|
|
dos2unix "${ACTIVATE_SCRIPT}"; \
|
|
|
|
VIRTUAL_ENV="$$(pwd)"; \
|
|
|
|
VIRTUAL_ENV="$$(cygpath -m "$${VIRTUAL_ENV}")"; \
|
|
|
|
sed -i -- "s@VIRTUAL_ENV=\".*\"@VIRTUAL_ENV=\"$$(pwd)/pyenv\"@g" "${ACTIVATE_SCRIPT}"; \
|
2020-03-24 03:39:05 +01:00
|
|
|
sed -i -- "s@export PATH@export PATH; VIRTUAL_ENV=\"$${VIRTUAL_ENV}/pyenv\";@g" "${ACTIVATE_SCRIPT}"; \
|
2020-03-25 05:38:37 +01:00
|
|
|
;; esac; \
|
|
|
|
. "${ACTIVATE_SCRIPT}"; \
|
|
|
|
python --version; \
|
|
|
|
python -m pip install --upgrade pip setuptools; \
|
|
|
|
${ANKI_EXTRA_PIP}; \
|
2020-03-24 17:51:59 +01:00
|
|
|
if ! python -c 'import PyQt5' 2>/dev/null; then \
|
|
|
|
python -m pip install -r qt/requirements.qt; \
|
|
|
|
fi;
|
2020-01-04 00:38:04 +01:00
|
|
|
|
|
|
|
# update build hash
|
2020-01-05 01:28:48 +01:00
|
|
|
.PHONY: buildhash
|
|
|
|
buildhash:
|
2020-03-25 05:38:37 +01:00
|
|
|
@set -eu -o pipefail ${SHELLFLAGS}; \
|
|
|
|
oldhash=$$(test -f meta/buildhash && cat meta/buildhash || true); \
|
|
|
|
newhash=$$(git rev-parse --short=8 HEAD || echo dev); \
|
2020-01-04 00:38:04 +01:00
|
|
|
if [ "$$oldhash" != "$$newhash" ]; then \
|
|
|
|
echo $$newhash > meta/buildhash; \
|
|
|
|
fi
|
|
|
|
|
2020-01-08 21:44:46 +01:00
|
|
|
.PHONY: develop
|
2020-02-26 08:52:25 +01:00
|
|
|
develop: pyenv buildhash prepare
|
2020-03-25 05:38:37 +01:00
|
|
|
@set -eu -o pipefail ${SHELLFLAGS}; \
|
|
|
|
. "${ACTIVATE_SCRIPT}"; \
|
2020-01-04 00:38:04 +01:00
|
|
|
for dir in $(DEVEL); do \
|
2020-03-06 00:33:53 +01:00
|
|
|
$(SUBMAKE) -C $$dir develop DEVFLAGS="$(DEVFLAGS)"; \
|
2020-01-08 21:44:46 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
.PHONY: run
|
|
|
|
run: develop
|
2020-03-25 05:38:37 +01:00
|
|
|
@set -eu -o pipefail ${SHELLFLAGS}; \
|
|
|
|
. "${ACTIVATE_SCRIPT}"; \
|
|
|
|
echo "Starting Anki..."; \
|
2020-02-24 18:58:07 +01:00
|
|
|
python qt/runanki $(RUNFLAGS)
|
2020-01-04 00:38:04 +01:00
|
|
|
|
2020-02-26 08:52:25 +01:00
|
|
|
.PHONY: prepare
|
|
|
|
prepare: rslib/ftl/repo qt/ftl/repo qt/po/repo
|
|
|
|
|
2020-02-26 09:32:47 +01:00
|
|
|
rslib/ftl/repo:
|
2020-02-26 11:07:55 +01:00
|
|
|
$(MAKE) pull-i18n
|
2020-02-26 09:32:47 +01:00
|
|
|
qt/ftl/repo:
|
2020-02-26 11:07:55 +01:00
|
|
|
$(MAKE) pull-i18n
|
2020-02-26 09:32:47 +01:00
|
|
|
qt/po/repo:
|
2020-02-26 11:07:55 +01:00
|
|
|
$(MAKE) pull-i18n
|
2020-02-26 08:52:25 +01:00
|
|
|
|
2020-01-04 00:38:04 +01:00
|
|
|
.PHONY: build
|
2020-01-04 01:02:43 +01:00
|
|
|
build: clean-dist build-rspy build-pylib build-qt add-buildhash
|
2020-02-25 06:32:17 +01:00
|
|
|
@echo
|
|
|
|
@echo "Build complete."
|
2020-01-04 00:38:04 +01:00
|
|
|
|
2020-01-04 01:02:43 +01:00
|
|
|
.PHONY: build-rspy
|
2020-01-05 01:28:48 +01:00
|
|
|
build-rspy: pyenv buildhash
|
2020-03-25 05:38:37 +01:00
|
|
|
@set -eu -o pipefail ${SHELLFLAGS}; \
|
|
|
|
. "${ACTIVATE_SCRIPT}"; \
|
2020-01-04 01:02:43 +01:00
|
|
|
$(SUBMAKE) -C rspy build BUILDFLAGS="$(BUILDFLAGS)"
|
|
|
|
|
|
|
|
.PHONY: build-pylib
|
|
|
|
build-pylib:
|
2020-03-25 05:38:37 +01:00
|
|
|
@set -eu -o pipefail ${SHELLFLAGS}; \
|
|
|
|
. "${ACTIVATE_SCRIPT}"; \
|
2020-01-04 01:02:43 +01:00
|
|
|
$(SUBMAKE) -C pylib build
|
|
|
|
|
|
|
|
.PHONY: build-qt
|
|
|
|
build-qt:
|
2020-03-25 05:38:37 +01:00
|
|
|
@set -eu -o pipefail ${SHELLFLAGS}; \
|
|
|
|
. "${ACTIVATE_SCRIPT}"; \
|
2020-01-04 01:02:43 +01:00
|
|
|
$(SUBMAKE) -C qt build
|
|
|
|
|
2020-01-04 00:38:04 +01:00
|
|
|
.PHONY: clean
|
2020-01-04 01:02:43 +01:00
|
|
|
clean: clean-dist
|
2020-03-25 05:38:37 +01:00
|
|
|
@set -eu -o pipefail ${SHELLFLAGS}; \
|
|
|
|
for dir in $(DEVEL); do \
|
2020-03-25 05:22:37 +01:00
|
|
|
$(SUBMAKE) -C $$dir clean; \
|
2020-01-04 00:38:04 +01:00
|
|
|
done
|
|
|
|
|
2020-04-07 02:56:41 +02:00
|
|
|
# remove any files in dist/ folder without current build hash
|
2020-01-04 01:02:43 +01:00
|
|
|
.PHONY: clean-dist
|
2020-04-07 02:56:41 +02:00
|
|
|
clean-dist: buildhash
|
2020-04-26 08:02:02 +02:00
|
|
|
"${FIND}" dist \! -name "*$$(cat meta/buildhash)*" -type f -delete
|
2020-01-04 01:02:43 +01:00
|
|
|
|
2020-01-04 00:38:04 +01:00
|
|
|
.PHONY: check
|
2020-02-27 11:52:05 +01:00
|
|
|
check: pyenv buildhash prepare
|
2020-03-25 05:38:37 +01:00
|
|
|
@set -eu -o pipefail ${SHELLFLAGS}; \
|
|
|
|
.github/scripts/trailing-newlines.sh; \
|
|
|
|
. "${ACTIVATE_SCRIPT}"; \
|
2020-04-30 09:11:50 +02:00
|
|
|
for dir in $(CHECKABLE_RS) $(CHECKABLE_PY); do \
|
2020-03-25 05:22:37 +01:00
|
|
|
$(SUBMAKE) -C $$dir check; \
|
2020-01-04 00:38:04 +01:00
|
|
|
done;
|
2020-02-25 06:32:17 +01:00
|
|
|
@echo
|
|
|
|
@echo "All checks passed!"
|
2020-01-04 00:38:04 +01:00
|
|
|
|
|
|
|
.PHONY: fix
|
|
|
|
fix:
|
2020-03-25 05:38:37 +01:00
|
|
|
@set -eu -o pipefail ${SHELLFLAGS}; \
|
|
|
|
. "${ACTIVATE_SCRIPT}"; \
|
2020-01-28 23:57:42 +01:00
|
|
|
for dir in $(CHECKABLE_RS) $(CHECKABLE_PY); do \
|
2020-03-25 05:22:37 +01:00
|
|
|
$(SUBMAKE) -C $$dir fix; \
|
2020-01-04 00:38:04 +01:00
|
|
|
done; \
|
2020-01-04 01:02:43 +01:00
|
|
|
|
|
|
|
.PHONY: add-buildhash
|
|
|
|
add-buildhash:
|
2020-03-25 05:38:37 +01:00
|
|
|
@set -eu -o pipefail ${SHELLFLAGS}; \
|
|
|
|
ver="$$(cat meta/version)"; \
|
|
|
|
hash="$$(cat meta/buildhash)"; \
|
2020-04-07 02:56:41 +02:00
|
|
|
${RENAME_BIN} -f "s/-$${ver}(\.|-)/-$${ver}+$${hash}\$$1/" dist/*-"$${ver}"*
|
2020-02-25 06:32:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
.PHONY: pull-i18n
|
|
|
|
pull-i18n:
|
|
|
|
(cd rslib/ftl && scripts/fetch-latest-translations)
|
|
|
|
(cd qt/ftl && scripts/fetch-latest-translations)
|
2020-02-26 08:47:02 +01:00
|
|
|
(cd qt/po && scripts/fetch-latest-translations)
|
2020-02-25 06:32:11 +01:00
|
|
|
|
2020-03-15 03:24:07 +01:00
|
|
|
.PHONY: push-i18n-ftl
|
|
|
|
push-i18n-ftl: pull-i18n
|
2020-02-25 06:32:11 +01:00
|
|
|
(cd rslib/ftl && scripts/upload-latest-templates)
|
|
|
|
(cd qt/ftl && scripts/upload-latest-templates)
|
2020-03-15 03:24:07 +01:00
|
|
|
|
|
|
|
.PHONY: push-i18n-po
|
|
|
|
push-i18n-po: pull-i18n
|
2020-02-26 08:47:02 +01:00
|
|
|
(cd qt/po && scripts/upload-latest-template)
|