1# Values: debian:<version>, ubuntu:<version> 2BASE_IMAGE ?= debian:buster 3# Values: python, python3 4PYTHON ?= python3 5# Values: rpi, aarch64, native 6TENSORFLOW_TARGET ?= native 7# Values: n, y 8BUILD_DEB ?= n 9# Values: according to https://www.python.org/dev/peps/pep-0440/ 10VERSION_SUFFIX ?= 11 12MAKEFILE_DIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST)))) 13TENSORFLOW_DIR := $(MAKEFILE_DIR)/../../../.. 14OUT_DIR := $(CURDIR)/out/$(PYTHON)/$(subst :,-,$(BASE_IMAGE)) 15TAG_IMAGE := "tflite-runtime-builder-$(subst :,-,$(BASE_IMAGE))" 16 17.PHONY: help \ 18 docker-image \ 19 docker-shell \ 20 docker-build \ 21 clean 22 23help: 24 @echo "make docker-image -- build docker image" 25 @echo "make docker-shell -- run shell inside the docker image" 26 @echo "make docker-build -- build wheel and deb inside the docker image" 27 @echo "make clean -- remove wheel and deb files" 28 29docker-image: 30 docker build -t $(TAG_IMAGE) --build-arg IMAGE=$(BASE_IMAGE) . 31 32docker-shell: docker-image 33 docker run --rm --interactive --tty \ 34 --volume $(TENSORFLOW_DIR):/tensorflow \ 35 --workdir /tensorflow \ 36 $(TAG_IMAGE) 37 38docker-build: docker-image 39 mkdir -p $(OUT_DIR) 40 docker run --user $(shell id -u):$(shell id -g) \ 41 --rm --interactive $(shell tty -s && echo --tty) \ 42 --env "PYTHON=$(PYTHON)" \ 43 --env "TENSORFLOW_TARGET=$(TENSORFLOW_TARGET)" \ 44 --env "BUILD_DEB=$(BUILD_DEB)" \ 45 --env "VERSION_SUFFIX=$(VERSION_SUFFIX)" \ 46 --volume $(TENSORFLOW_DIR):/tensorflow \ 47 --volume $(OUT_DIR):/out \ 48 $(TAG_IMAGE) \ 49 /bin/bash -c "/tensorflow/tensorflow/lite/tools/pip_package/build_pip_package.sh && \ 50 (cp /tensorflow/tensorflow/lite/tools/pip_package/gen/tflite_pip/*.deb \ 51 /tensorflow/tensorflow/lite/tools/pip_package/gen/tflite_pip/${PYTHON}/dist/{*.whl,*.tar.gz} \ 52 /out 2>/dev/null || true)" 53 54clean: 55 rm -rf $(CURDIR)/out 56