forked from KMKfw/kmk_firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
152 lines (121 loc) · 3.78 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
.SILENT:
.PHONY: \
clean-dist \
devdeps \
dist \
dockerbase \
lint
.DEFAULT: all
DIST_DESCRIBE_CMD = git describe --always --abbrev=0 --dirty --broken
DOCKER_BASE_TAG ?= latest
DOCKER_TAG ?= latest
AMPY_PORT ?= /dev/ttyUSB0
AMPY_BAUD ?= 115200
AMPY_DELAY ?= 1.5
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
PY_KMK_TREE = $(shell find $(MPY_SOURCES) -name "*.py")
DIST_DESCRIBE = $(shell $(DIST_DESCRIBE_CMD))
TIMESTAMP := $(shell date +%s)
all: copy-kmk copy-bootpy copy-keymap copy-board
.PHONY: compile compile-check
compile: compile-check
ifeq ($(MPY_CROSS),)
compile-check:
@echo "===> Could not find mpy-cross in PATH, exiting"
@false
else
compile-check: $(PY_KMK_TREE:%.py=$(MPY_TARGET_DIR)/%.mpy)
@echo "===> Compiling all py files to mpy with flags $(MPY_FLAGS)"
$(MPY_TARGET_DIR)/%.mpy: %.py
@mkdir -p $(dir $@)
@$(MPY_CROSS) $(MPY_FLAGS) $? -o $@
endif
.devdeps: Pipfile.lock
@echo "===> Installing dependencies with pipenv"
@$(PIPENV) sync --dev
@touch .devdeps
devdeps: .devdeps
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)
lint: devdeps
@$(PIPENV) run flake8
spellcheck:
./util/spellcheck.sh --no-interactive
fix-formatting: devdeps
@$(PIPENV) run black .
fix-isort: devdeps
@find boards/ kmk/ tests/ user_keymaps/ -name "*.py" | xargs $(PIPENV) run isort
clean: clean-dist
@echo "===> Cleaning build artifacts"
@rm -rf .devdeps build dist $(MPY_TARGET_DIR)
clean-dist:
@echo "===> Cleaning KMKPython dists"
@rm -rf .dist
# 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...)
powerwash: clean
@echo "===> Removing vendor/ to force a re-pull"
@rm -rf vendor
@echo "===> Removing pipenv-managed virtual environment"
@$(PIPENV) --rm || true
test: lint unit-tests
.PHONY: unit-tests
unit-tests: devdeps
ifdef TESTS
@$(PIPENV) run python3 -m unittest $(TESTS)
else
@$(PIPENV) run python3 -m unittest discover -t . -s tests
endif # TESTS
reset-bootloader:
@echo "===> Rebooting your board to bootloader (safe to ignore file not found errors)"
@-timeout -k 5s 10s $(PIPENV) run ampy -p /dev/ttyACM0 -d ${AMPY_DELAY} -b ${AMPY_BAUD} run util/bootloader.py
reset-board:
@echo "===> Rebooting your board (safe to ignore file not found errors)"
@-timeout -k 5s 10s $(PIPENV) run ampy -p /dev/ttyACM0 -d ${AMPY_DELAY} -b ${AMPY_BAUD} run util/reset.py
ifdef MOUNTPOINT
ifdef BOARD
copy-board:
@echo "===> Copying your board from $(BOARD) to $(MOUNTPOINT)"
@rsync -rhu $(BOARD)/*.py $(MOUNTPOINT)/
@sync
else # BOARD
copy-board:
@echo "**** Missing BOARD argument ****" && exit 1
endif # BOARD
copy-bootpy:
@echo "===> Copying required boot.py"
@rsync -rhu boot.py $(MOUNTPOINT)/boot.py
@sync
copy-compiled:
@echo "===> Copying compiled KMK folder"
@rsync -rhu $(MPY_TARGET_DIR)/* $(MOUNTPOINT)/
@sync
ifdef USER_KEYMAP
copy-keymap:
@echo "===> Copying your keymap to main.py"
@rsync -rhu $(USER_KEYMAP) $(MOUNTPOINT)/main.py
@sync
else # USER_KEYMAP
copy-keymap:
@echo "**** Missing USER_KEYMAP argument ****" && exit 1
endif # USER_KEYMAP
copy-kmk:
@echo "===> Copying KMK source folder"
@rsync -rhu kmk $(MOUNTPOINT)/
@sync
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