2018-10-09 01:16:05 +02:00
|
|
|
.SILENT:
|
|
|
|
|
2018-09-03 10:23:15 +02:00
|
|
|
.PHONY: \
|
|
|
|
devdeps \
|
|
|
|
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'
|
|
|
|
MPY_SOURCES = 'kmk/'
|
|
|
|
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
|
|
|
|
2018-12-29 15:03:31 +01:00
|
|
|
all: copy-kmk copy-bootpy copy-keymap
|
2018-10-15 11:49:12 +02:00
|
|
|
|
2019-07-21 00:50:56 +02:00
|
|
|
compile: $(MPY_TARGET_DIR)/.mpy.compiled
|
2019-07-21 01:14:58 +02:00
|
|
|
|
2019-07-25 05:21:56 +02:00
|
|
|
$(MPY_TARGET_DIR)/.mpy.compiled: $(PY_KMK_TREE)
|
2019-07-21 00:50:56 +02:00
|
|
|
ifeq ($(MPY_CROSS),)
|
|
|
|
@echo "===> Could not find mpy-cross in PATH, exiting"
|
|
|
|
@false
|
|
|
|
endif
|
2019-07-25 05:21:56 +02:00
|
|
|
@echo "===> Compiling all py files to mpy with flags $(MPY_FLAGS)"
|
2019-07-21 00:50:56 +02:00
|
|
|
@mkdir -p $(MPY_TARGET_DIR)
|
2019-07-25 05:54:06 +02:00
|
|
|
@echo "KMK_RELEASE = '$(DIST_DESCRIBE)'" > $(MPY_SOURCES)/release_info.py
|
2019-07-21 00:50:56 +02:00
|
|
|
@find $(MPY_SOURCES) -name "*.py" -exec sh -c 'mkdir -p $(MPY_TARGET_DIR)/$$(dirname {}) && mpy-cross $(MPY_FLAGS) {} -o $(MPY_TARGET_DIR)/$$(dirname {})/$$(basename -s .py {}).mpy' \;
|
2019-07-25 05:54:06 +02:00
|
|
|
@rm -rf $(MPY_SOURCES)/release_info.py
|
2019-07-21 01:14:58 +02:00
|
|
|
@touch $(MPY_TARGET_DIR)/.mpy.compiled
|
|
|
|
|
2019-07-25 05:54:06 +02:00
|
|
|
dist: dist/kmk-latest.zip dist/kmk-latest.unoptimized.zip dist/$(DIST_DESCRIBE).zip dist/$(DIST_DESCRIBE).unoptimized.zip
|
2019-07-25 05:21:56 +02:00
|
|
|
|
|
|
|
dist-deploy: devdeps dist
|
|
|
|
@echo "===> Uploading artifacts to https://cdn.kmkfw.io/"
|
2019-07-25 06:04:15 +02:00
|
|
|
@$(PIPENV) run s3cmd -c .s3cfg put -P dist/kmk-$(DIST_DESCRIBE).zip dist/kmk-$(DIST_DESCRIBE).unoptimized.zip s3://kmk-releases/ >/dev/null
|
2019-07-25 05:21:56 +02:00
|
|
|
@[[ "$${CIRCLE_BRANCH}" == "master" ]] && echo "====> Uploading artifacts as 'latest' to https://cdn.kmkfw.io/" || true
|
2019-07-25 06:04:15 +02:00
|
|
|
@[[ "$${CIRCLE_BRANCH}" == "master" ]] && $(PIPENV) run s3cmd -c .s3cfg put -P dist/kmk-latest.zip dist/kmk-latest.unoptimized.zip s3://kmk-releases/ >/dev/null || true
|
2019-07-25 05:21:56 +02:00
|
|
|
@[[ -n "$${CIRCLE_TAG}" ]] && echo "====> Uploading artifacts as '$${CIRCLE_TAG}' to https://cdn.kmkfw.io/" || true
|
2019-07-25 06:04:15 +02:00
|
|
|
@[[ -n "$${CIRCLE_TAG}" ]] && $(PIPENV) run s3cmd -c .s3cfg put -P dist/kmk-latest.zip s3://kmk-releases/$${CIRCLE_TAG}.zip >/dev/null || true
|
|
|
|
@[[ -n "$${CIRCLE_TAG}" ]] && $(PIPENV) run s3cmd -c .s3cfg put -P dist/kmk-latest.unoptimized.zip s3://kmk-releases/$${CIRCLE_TAG}.unoptimized.zip >/dev/null || true
|
2019-07-21 01:14:58 +02:00
|
|
|
|
2019-07-25 08:28:13 +02:00
|
|
|
dist/kmk-latest.zip: compile boot.py
|
2019-07-25 05:21:56 +02:00
|
|
|
@echo "===> Building optimized ZIP"
|
2019-07-21 01:14:58 +02:00
|
|
|
@mkdir -p dist
|
2019-07-25 05:54:06 +02:00
|
|
|
@cd $(MPY_TARGET_DIR) && zip -r ../dist/kmk-latest.zip kmk 2>&1 >/dev/null
|
2019-07-25 08:28:13 +02:00
|
|
|
@zip -r dist/kmk-latest.zip boot.py 2>&1 >/dev/null
|
2019-07-21 01:14:58 +02:00
|
|
|
|
2019-07-25 05:54:06 +02:00
|
|
|
dist/$(DIST_DESCRIBE).zip: dist/kmk-latest.zip
|
2019-07-25 05:21:56 +02:00
|
|
|
@echo "===> Aliasing optimized ZIP"
|
2019-07-25 05:54:06 +02:00
|
|
|
@cp dist/kmk-latest.zip dist/kmk-$(DIST_DESCRIBE).zip
|
2019-07-21 01:14:58 +02:00
|
|
|
|
2019-07-25 08:28:13 +02:00
|
|
|
dist/kmk-latest.unoptimized.zip: $(PY_KMK_TREE) boot.py
|
2019-07-25 05:21:56 +02:00
|
|
|
@echo "===> Building unoptimized ZIP"
|
2019-07-21 01:14:58 +02:00
|
|
|
@mkdir -p dist
|
2019-07-25 05:54:06 +02:00
|
|
|
@echo "KMK_RELEASE = '$(DIST_DESCRIBE)'" > kmk/release_info.py
|
2019-07-25 08:28:13 +02:00
|
|
|
@zip -r dist/kmk-latest.unoptimized.zip kmk boot.py 2>&1 >/dev/null
|
2019-07-25 05:54:06 +02:00
|
|
|
@rm -rf kmk/release_info.py
|
2019-07-21 01:14:58 +02:00
|
|
|
|
2019-07-25 05:54:06 +02:00
|
|
|
dist/$(DIST_DESCRIBE).unoptimized.zip: dist/kmk-latest.unoptimized.zip
|
2019-07-25 05:21:56 +02:00
|
|
|
@echo "===> Aliasing unoptimized ZIP"
|
2019-07-25 05:54:06 +02:00
|
|
|
@cp dist/kmk-latest.unoptimized.zip dist/kmk-$(DIST_DESCRIBE).unoptimized.zip
|
2019-07-21 00:50:56 +02:00
|
|
|
|
|
|
|
.docker_base: Dockerfile
|
2018-10-12 02:44:02 +02:00
|
|
|
@echo "===> Building Docker base image kmkfw/base:${DOCKER_BASE_TAG}"
|
2019-07-21 00:50:56 +02:00
|
|
|
@docker build -t kmkfw/base:${DOCKER_BASE_TAG} .
|
2018-10-12 02:44:02 +02:00
|
|
|
@touch .docker_base
|
|
|
|
|
|
|
|
docker-base: .docker_base
|
|
|
|
|
|
|
|
docker-base-deploy: docker-base
|
|
|
|
@echo "===> Pushing Docker base image kmkfw/base:${DOCKER_BASE_TAG} to Docker Hub"
|
|
|
|
@docker push kmkfw/base:${DOCKER_BASE_TAG}
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
2019-07-25 09:07:08 +02:00
|
|
|
@find kmk/ user_keymaps/ -name "*.py" | xargs $(PIPENV) run isort
|
2018-10-06 00:31:00 +02:00
|
|
|
|
2019-07-25 05:21:56 +02:00
|
|
|
clean:
|
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
|
|
|
|
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
|
|
|
|
2018-10-17 08:11:23 +02:00
|
|
|
test: lint
|
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
|
|
|
|
|
|
|
ifdef MOUNTPOINT
|
|
|
|
$(MOUNTPOINT)/kmk/.copied: $(shell find kmk/ -name "*.py" | xargs -0)
|
|
|
|
@echo "===> Copying KMK source folder"
|
|
|
|
@rsync -rh kmk $(MOUNTPOINT)/
|
|
|
|
@touch $(MOUNTPOINT)/kmk/.copied
|
|
|
|
@sync
|
|
|
|
|
|
|
|
copy-kmk: $(MOUNTPOINT)/kmk/.copied
|
|
|
|
else
|
|
|
|
copy-kmk:
|
|
|
|
echo "**** MOUNTPOINT must be defined (wherever your CIRCUITPY drive is mounted) ****" && exit 1
|
|
|
|
endif
|
|
|
|
|
2018-12-29 15:03:31 +01:00
|
|
|
ifdef MOUNTPOINT
|
|
|
|
$(MOUNTPOINT)/kmk/boot.py: boot.py
|
|
|
|
@echo "===> Copying required boot.py"
|
|
|
|
@rsync -rh boot.py $(MOUNTPOINT)/
|
|
|
|
@sync
|
|
|
|
|
|
|
|
copy-bootpy: $(MOUNTPOINT)/kmk/boot.py
|
|
|
|
else
|
|
|
|
copy-bootpy:
|
|
|
|
echo "**** MOUNTPOINT must be defined (wherever your CIRCUITPY drive is mounted) ****" && exit 1
|
|
|
|
endif
|
|
|
|
|
2018-10-15 11:49:12 +02:00
|
|
|
ifdef MOUNTPOINT
|
|
|
|
ifndef USER_KEYMAP
|
2018-10-16 13:04:39 +02:00
|
|
|
$(MOUNTPOINT)/main.py:
|
2018-10-15 11:49:12 +02:00
|
|
|
@echo "**** USER_KEYMAP must be defined (ex. USER_KEYMAP=user_keymaps/noop.py) ****" && exit 1
|
|
|
|
else
|
2018-10-16 13:04:39 +02:00
|
|
|
$(MOUNTPOINT)/main.py: $(USER_KEYMAP)
|
|
|
|
@echo "===> Copying your keymap to main.py"
|
2018-10-15 11:49:12 +02:00
|
|
|
@rsync -rh $(USER_KEYMAP) $@
|
|
|
|
@sync
|
|
|
|
endif # USER_KEYMAP
|
|
|
|
|
2018-10-16 13:04:39 +02:00
|
|
|
copy-keymap: $(MOUNTPOINT)/main.py
|
2018-10-15 11:49:12 +02:00
|
|
|
else
|
|
|
|
copy-keymap:
|
|
|
|
echo "**** MOUNTPOINT must be defined (wherever your CIRCUITPY drive is mounted) ****" && exit 1
|
|
|
|
endif # MOUNTPOINT
|