From 86dec1b762a3451c9d338e3338fa5f529380bd58 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lo=C3=AFc=20Dauphin?= <astralien3000@yahoo.fr>
Date: Wed, 17 Jan 2018 18:12:17 +0100
Subject: [PATCH] dist/tools: make teensy-loader-cli work on MACOSX

---
 dist/tools/teensy-loader-cli/.gitignore |  1 +
 dist/tools/teensy-loader-cli/Makefile   | 30 ++++++++++++++++++
 dist/tools/teensy-loader-cli/build.sh   | 42 -------------------------
 3 files changed, 31 insertions(+), 42 deletions(-)
 create mode 100644 dist/tools/teensy-loader-cli/.gitignore
 create mode 100644 dist/tools/teensy-loader-cli/Makefile
 delete mode 100755 dist/tools/teensy-loader-cli/build.sh

diff --git a/dist/tools/teensy-loader-cli/.gitignore b/dist/tools/teensy-loader-cli/.gitignore
new file mode 100644
index 0000000000..552fed5265
--- /dev/null
+++ b/dist/tools/teensy-loader-cli/.gitignore
@@ -0,0 +1 @@
+teensy_loader
diff --git a/dist/tools/teensy-loader-cli/Makefile b/dist/tools/teensy-loader-cli/Makefile
new file mode 100644
index 0000000000..eec2e614c6
--- /dev/null
+++ b/dist/tools/teensy-loader-cli/Makefile
@@ -0,0 +1,30 @@
+PKG_NAME=teensy-loader-cli
+PKG_LICENSE=GPL-3
+PKG_BUILDDIR=$(CURDIR)/bin
+
+# resolv build host in a hacky way
+UNAME=$(shell uname)
+TARGET=WINDOWS
+ifeq ("$(UNAME)","Linux")
+  TARGET=LINUX
+else ifeq ("$(UNAME)","Darwin")
+  TARGET=MACOSX
+endif
+
+# get sources from repository
+ifeq ("$(TARGET)","MACOSX")
+  # hacked version to make it work on MACOSX
+  PKG_URL=https://github.com/alswl/teensy_loader_cli.git
+  PKG_VERSION=9c16bb0add3ba847df5509328ad6bd5bc09d9ecd
+else
+  PKG_URL=https://github.com/PaulStoffregen/teensy_loader_cli.git
+  PKG_VERSION=76921edbdd81ae99b869b104404c16c06b0a266f
+endif
+
+.PHONY: all
+
+all: git-download
+	env -i PATH=$(PATH) TERM=$(TERM) "$(MAKE)" -C $(PKG_BUILDDIR)
+	mv $(PKG_BUILDDIR)/teensy_loader_cli ./teensy_loader
+
+include $(RIOTBASE)/pkg/pkg.mk
diff --git a/dist/tools/teensy-loader-cli/build.sh b/dist/tools/teensy-loader-cli/build.sh
deleted file mode 100755
index 080a2d70e4..0000000000
--- a/dist/tools/teensy-loader-cli/build.sh
+++ /dev/null
@@ -1,42 +0,0 @@
-#!/usr/bin/env sh
-
-#
-# Copyright (c) 2015 Nick v. IJzendoorn <nijzendoorn@engineering-spirit.nl>
-#
-# A simple script to fetch and build the teensy_loader_cli tool used for the
-# Teensy boards.
-# For more information see: https://www.pjrc.com/teensy/loader_cli.html
-#
-
-# get sources from repository
-git clone https://github.com/PaulStoffregen/teensy_loader_cli.git
-cd teensy_loader_cli
-
-# resolv build host in a hacky way
-UNAME=`uname`
-TARGET="WINDOWS";
-if [ "x$UNAME" = "xLinux" ]; then
-    TARGET="LINUX";
-elif [ "x$UNAME" = "xDarwin" ]; then
-    TARGET="MACOSX";
-fi;
-
-# check if the library exists
-if [ "x$TARGET" = "xLINUX" ] && ! ldconfig -p | grep 'libusb' > /dev/null; then
-    echo "please install libusb-dev";
-    exit 1;
-elif [ "x$TARGET" = "xMACOSX" ] && ! pkg-config --list-all | grep 'libusb' > /dev/null; then
-    echo "please install libusb-dev";
-    exit 1;
-elif [ "x$TARGET" = "xWINDOWS" ]; then
-    echo "can't build for windows... yet";
-    exit 1;
-fi;
-
-# build the application
-OS=$TARGET make
-
-# copy the tool to the base directory
-mv teensy_loader_cli ../teensy_loader
-cd ..
-rm -rf teensy_loader_cli
-- 
GitLab