2018-10-09 01:16:05 +02:00
|
|
|
.SILENT:
|
|
|
|
|
2018-09-03 10:23:15 +02:00
|
|
|
.PHONY: \
|
2020-11-27 05:48:02 +01:00
|
|
|
clean-dist \
|
2018-09-03 10:23:15 +02:00
|
|
|
devdeps \
|
2020-11-27 05:48:02 +01:00
|
|
|
dist \
|
|
|
|
dockerbase \
|
2018-09-03 10:23:15 +02:00
|
|
|
lint
|
2018-09-03 05:06:53 +02:00
|
|
|
|
2018-10-15 11:49:12 +02:00
|
|
|
.DEFAULT: all
|
|
|
|
|
2019-07-21 01:14:58 +02:00
|
|
|
DIST_DESCRIBE_CMD = git describe --always --abbrev=0 --dirty --broken
|
|
|
|
|
2018-10-12 02:44:02 +02:00
|
|
|
DOCKER_BASE_TAG ?= latest
|
|
|
|
DOCKER_TAG ?= latest
|
|
|
|
|
2018-09-16 09:15:16 +02:00
|
|
|
AMPY_PORT ?= /dev/ttyUSB0
|
|
|
|
AMPY_BAUD ?= 115200
|
|
|
|
AMPY_DELAY ?= 1.5
|
2019-07-21 00:50:56 +02:00
|
|
|
PIPENV ?= $(shell which pipenv 2>/dev/null)
|
|
|
|
|
|
|
|
MPY_CROSS ?= $(shell which mpy-cross 2>/dev/null)
|
|
|
|
MPY_FLAGS ?= '-O2'
|
2022-03-31 18:46:51 +02:00
|
|
|
MPY_SOURCES ?= 'kmk/'
|
2019-07-21 00:50:56 +02:00
|
|
|
MPY_TARGET_DIR ?= .compiled
|
2019-07-25 05:21:56 +02:00
|
|
|
PY_KMK_TREE = $(shell find $(MPY_SOURCES) -name "*.py")
|
|
|
|
DIST_DESCRIBE = $(shell $(DIST_DESCRIBE_CMD))
|
2018-09-03 12:22:11 +02:00
|
|
|
|
2020-11-27 05:48:02 +01:00
|
|
|
TIMESTAMP := $(shell date +%s)
|
|
|
|
|
2020-10-21 21:19:42 +02:00
|
|
|
all: copy-kmk copy-bootpy copy-keymap copy-board
|
2018-10-15 11:49:12 +02:00
|
|
|
|
2023-02-16 10:53:56 +01:00
|
|
|
.PHONY: compile compile-check
|
|
|
|
compile: compile-check
|
2019-07-21 00:50:56 +02:00
|
|
|
ifeq ($(MPY_CROSS),)
|
2023-02-16 10:53:56 +01:00
|
|
|
compile-check:
|
2019-07-21 00:50:56 +02:00
|
|
|
@echo "===> Could not find mpy-cross in PATH, exiting"
|
|
|
|
@false
|
2023-02-16 10:53:56 +01:00
|
|
|
else
|
|
|
|
compile-check: $(PY_KMK_TREE:%.py=$(MPY_TARGET_DIR)/%.mpy)
|
2019-07-25 05:21:56 +02:00
|
|
|
@echo "===> Compiling all py files to mpy with flags $(MPY_FLAGS)"
|
2023-02-16 10:53:56 +01:00
|
|
|
$(MPY_TARGET_DIR)/%.mpy: %.py
|
|
|
|
@mkdir -p $(dir $@)
|
|
|
|
@$(MPY_CROSS) $(MPY_FLAGS) $? -o $@
|
|
|
|
endif
|
2019-07-21 01:14:58 +02:00
|
|
|
|
2018-10-06 10:32:17 +02:00
|
|
|
.devdeps: Pipfile.lock
|
2018-10-08 16:06:34 +02:00
|
|
|
@echo "===> Installing dependencies with pipenv"
|
2019-07-25 05:21:56 +02:00
|
|
|
@$(PIPENV) sync --dev
|
2018-10-06 10:32:17 +02:00
|
|
|
@touch .devdeps
|
|
|
|
|
|
|
|
devdeps: .devdeps
|
2018-09-03 05:06:53 +02:00
|
|
|
|
2020-11-27 05:48:02 +01:00
|
|
|
dist: clean-dist dockerbase
|
|
|
|
@mkdir -p .dist
|
|
|
|
@docker run --rm -it -v $$(pwd)/.dist:/dist kmkpy:$(TIMESTAMP)
|
|
|
|
|
|
|
|
dockerbase:
|
|
|
|
docker build . \
|
|
|
|
-t kmkpy:$(TIMESTAMP) \
|
|
|
|
--build-arg KMKPY_URL=$$(cut -f1 < kmkpython_ref.tsv) \
|
|
|
|
--build-arg KMKPY_REF=$$(cut -f2 < kmkpython_ref.tsv)
|
|
|
|
|
2018-09-03 05:06:53 +02:00
|
|
|
lint: devdeps
|
2018-10-06 00:31:00 +02:00
|
|
|
@$(PIPENV) run flake8
|
2018-09-03 05:06:53 +02:00
|
|
|
|
2019-07-25 07:56:10 +02:00
|
|
|
fix-formatting: devdeps
|
|
|
|
@$(PIPENV) run black .
|
|
|
|
|
2018-09-22 08:44:03 +02:00
|
|
|
fix-isort: devdeps
|
2022-10-14 17:25:10 +02:00
|
|
|
@find boards/ kmk/ tests/ user_keymaps/ -name "*.py" | xargs $(PIPENV) run isort
|
2018-10-06 00:31:00 +02:00
|
|
|
|
2020-11-27 05:48:02 +01:00
|
|
|
clean: clean-dist
|
2018-10-08 16:06:34 +02:00
|
|
|
@echo "===> Cleaning build artifacts"
|
2019-07-21 01:14:58 +02:00
|
|
|
@rm -rf .devdeps build dist $(MPY_TARGET_DIR)
|
2018-10-08 16:06:34 +02:00
|
|
|
|
2020-11-27 05:48:02 +01:00
|
|
|
clean-dist:
|
|
|
|
@echo "===> Cleaning KMKPython dists"
|
|
|
|
@rm -rf .dist
|
|
|
|
|
2019-07-21 00:01:17 +02:00
|
|
|
# This is mostly a leftover from the days we vendored stuff from
|
|
|
|
# micropython-lib via submodules. Leaving this here mostly in case someone goes
|
|
|
|
# exploring through the history of KMK's repo and manages to screw up their
|
|
|
|
# repo state (those were glitchy times...)
|
2018-10-06 00:31:00 +02:00
|
|
|
powerwash: clean
|
2018-10-08 16:06:34 +02:00
|
|
|
@echo "===> Removing vendor/ to force a re-pull"
|
|
|
|
@rm -rf vendor
|
|
|
|
@echo "===> Removing pipenv-managed virtual environment"
|
|
|
|
@$(PIPENV) --rm || true
|
2018-09-22 08:44:03 +02:00
|
|
|
|
2022-02-03 10:06:53 +01:00
|
|
|
test: lint unit-tests
|
|
|
|
|
|
|
|
.PHONY: unit-tests
|
|
|
|
unit-tests: devdeps
|
2023-02-16 10:21:13 +01:00
|
|
|
@$(PIPENV) run python3 -m unittest $(TESTS)
|
2018-09-23 11:38:28 +02:00
|
|
|
|
2018-09-27 08:19:11 +02:00
|
|
|
reset-bootloader:
|
2018-10-15 11:49:12 +02:00
|
|
|
@echo "===> Rebooting your board to bootloader (safe to ignore file not found errors)"
|
2018-10-06 00:31:00 +02:00
|
|
|
@-timeout -k 5s 10s $(PIPENV) run ampy -p /dev/ttyACM0 -d ${AMPY_DELAY} -b ${AMPY_BAUD} run util/bootloader.py
|
2018-09-27 08:19:11 +02:00
|
|
|
|
|
|
|
reset-board:
|
2018-10-15 11:49:12 +02:00
|
|
|
@echo "===> Rebooting your board (safe to ignore file not found errors)"
|
2018-10-06 00:31:00 +02:00
|
|
|
@-timeout -k 5s 10s $(PIPENV) run ampy -p /dev/ttyACM0 -d ${AMPY_DELAY} -b ${AMPY_BAUD} run util/reset.py
|
2018-10-15 11:49:12 +02:00
|
|
|
|
|
|
|
|
2023-02-18 19:24:19 +01:00
|
|
|
ifdef MOUNTPOINT
|
2023-02-24 18:58:40 +01:00
|
|
|
ifdef BOARD
|
2023-02-18 19:24:19 +01:00
|
|
|
copy-board:
|
2023-02-24 18:58:40 +01:00
|
|
|
@echo "===> Copying your board from $(BOARD) to $(MOUNTPOINT)"
|
|
|
|
@rsync -rhu $(BOARD)/*.py $(MOUNTPOINT)/
|
2020-10-21 21:19:42 +02:00
|
|
|
@sync
|
2023-02-24 18:58:40 +01:00
|
|
|
else # BOARD
|
2023-02-18 19:24:19 +01:00
|
|
|
copy-board:
|
2023-02-24 18:58:40 +01:00
|
|
|
@echo "**** Missing BOARD argument ****" && exit 1
|
|
|
|
endif # BOARD
|
2020-10-21 21:19:42 +02:00
|
|
|
|
2023-02-24 18:58:40 +01:00
|
|
|
copy-bootpy:
|
2018-12-29 15:03:31 +01:00
|
|
|
@echo "===> Copying required boot.py"
|
2023-02-24 18:58:40 +01:00
|
|
|
@rsync -rhu boot.py $(MOUNTPOINT)/boot.py
|
2018-12-29 15:03:31 +01:00
|
|
|
@sync
|
|
|
|
|
2023-02-24 18:58:40 +01:00
|
|
|
copy-compiled:
|
|
|
|
@echo "===> Copying compiled KMK folder"
|
|
|
|
@rsync -rhu $(MPY_TARGET_DIR)/* $(MOUNTPOINT)/
|
|
|
|
@sync
|
2018-12-29 15:03:31 +01:00
|
|
|
|
2023-02-24 18:58:40 +01:00
|
|
|
ifdef USER_KEYMAP
|
|
|
|
copy-keymap:
|
2018-10-16 13:04:39 +02:00
|
|
|
@echo "===> Copying your keymap to main.py"
|
2023-02-24 18:58:40 +01:00
|
|
|
@rsync -rhu $(USER_KEYMAP) $(MOUNTPOINT)/main.py
|
2018-10-15 11:49:12 +02:00
|
|
|
@sync
|
2023-02-24 18:58:40 +01:00
|
|
|
else # USER_KEYMAP
|
|
|
|
copy-keymap:
|
|
|
|
@echo "**** Missing USER_KEYMAP argument ****" && exit 1
|
2018-10-15 11:49:12 +02:00
|
|
|
endif # USER_KEYMAP
|
|
|
|
|
2023-02-24 18:58:40 +01:00
|
|
|
copy-kmk:
|
|
|
|
@echo "===> Copying KMK source folder"
|
|
|
|
@rsync -rhu kmk $(MOUNTPOINT)/
|
|
|
|
@sync
|
2020-10-21 21:19:42 +02:00
|
|
|
|
2023-02-24 18:58:40 +01:00
|
|
|
else # MOUNTPOINT
|
|
|
|
copy-board copy-bootpy copy-compiled copy-keymap copy-kmk:
|
|
|
|
@echo "**** MOUNTPOINT must be defined (wherever your CIRCUITPY drive is mounted) ****" && exit 1
|
|
|
|
endif # ifndef MOUNTPOINT
|