From 8f5511327e6abfa5abd62b43d60e9b235190d3f9 Mon Sep 17 00:00:00 2001 From: Josh Klar Date: Sat, 20 Jul 2019 15:50:56 -0700 Subject: [PATCH] Makefile can compile KMK to MPY files --- Dockerfile_base => Dockerfile | 2 -- Makefile | 21 ++++++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) rename Dockerfile_base => Dockerfile (96%) diff --git a/Dockerfile_base b/Dockerfile similarity index 96% rename from Dockerfile_base rename to Dockerfile index 01d5900..7f433cb 100644 --- a/Dockerfile_base +++ b/Dockerfile @@ -1,5 +1,3 @@ -# vim: ft=dockerfile - FROM python:3.7-alpine RUN mkdir -p /app diff --git a/Makefile b/Makefile index 557119c..7792be7 100644 --- a/Makefile +++ b/Makefile @@ -12,13 +12,28 @@ DOCKER_TAG ?= latest AMPY_PORT ?= /dev/ttyUSB0 AMPY_BAUD ?= 115200 AMPY_DELAY ?= 1.5 -PIPENV ?= $(shell which pipenv) +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 all: copy-kmk copy-bootpy copy-keymap -.docker_base: Dockerfile_base +compile: $(MPY_TARGET_DIR)/.mpy.compiled +ifeq ($(MPY_CROSS),) + @echo "===> Could not find mpy-cross in PATH, exiting" + @false +endif + +$(MPY_TARGET_DIR)/.mpy.compiled: $(shell find $(MPY_SOURCES) -name "*.py") + @mkdir -p $(MPY_TARGET_DIR) + @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' \; + +.docker_base: Dockerfile @echo "===> Building Docker base image kmkfw/base:${DOCKER_BASE_TAG}" - @docker build -f Dockerfile_base -t kmkfw/base:${DOCKER_BASE_TAG} . + @docker build -t kmkfw/base:${DOCKER_BASE_TAG} . @touch .docker_base docker-base: .docker_base