From 9227c6f0d89cb6bf6ce591ba498791b50495f56c Mon Sep 17 00:00:00 2001
From: Kaspar Schleiser <kaspar@schleiser.de>
Date: Thu, 1 Feb 2018 12:20:50 +0100
Subject: [PATCH] pkg: add local.mk, allow source folder override for git
 packages

---
 pkg/local.mk | 24 ++++++++++++++++++++++++
 pkg/pkg.mk   |  7 +++++++
 2 files changed, 31 insertions(+)
 create mode 100644 pkg/local.mk

diff --git a/pkg/local.mk b/pkg/local.mk
new file mode 100644
index 0000000000..c2a8f0ece7
--- /dev/null
+++ b/pkg/local.mk
@@ -0,0 +1,24 @@
+#
+# This file allows specifying a local folder using PKG_SOURCE_LOCAL.
+#
+# Every clean or prepare will remove $(PKG_BUILDDIR) and copy over
+# $(PKG_SOURCE_LOCAL).  This is intended to be used during package development.
+#
+# WARNING: any local changes made to $(PKG_BUILDDIR) *will* get lost!
+
+.PHONY: prepare git-download clean
+
+git-download:
+	@true
+
+prepare: $(PKG_BUILDDIR)/.prepared
+	@true
+
+$(PKG_BUILDDIR)/.prepared:
+	rm -Rf $(PKG_BUILDDIR)
+	mkdir -p $$(dirname $(PKG_BUILDDIR))
+	cp -a $(PKG_SOURCE_LOCAL) $(PKG_BUILDDIR)
+	touch $@
+
+clean::
+	@rm -f $(PKG_BUILDDIR)/.prepared
diff --git a/pkg/pkg.mk b/pkg/pkg.mk
index b8166f9f32..401ac49cf4 100644
--- a/pkg/pkg.mk
+++ b/pkg/pkg.mk
@@ -4,6 +4,11 @@
 PKG_DIR?=$(CURDIR)
 PKG_BUILDDIR?=$(PKGDIRBASE)/$(PKG_NAME)
 
+# allow overriding package source with local folder (useful during development)
+ifneq (,$(PKG_SOURCE_LOCAL))
+  include $(RIOTBASE)/pkg/local.mk
+else
+
 .PHONY: prepare git-download clean
 
 prepare: git-download
@@ -39,3 +44,5 @@ clean::
 
 distclean::
 	rm -rf "$(PKG_BUILDDIR)"
+
+endif
-- 
GitLab