From 202e73dcdf8dd69dcf3291e95580df96cfb4d15a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cenk=20G=C3=BCndo=C4=9Fan?= <mail-github@cgundogan.de>
Date: Tue, 3 Jul 2018 11:36:41 +0200
Subject: [PATCH] make: dedup USEMODULE_INCLUDES w/o shelling out

Currently, `USEMODULE_INCLUDES` is deduplicated using a combination of
`tr` and `awk`. The proposed method achieves a deduplication (no
sorting) without the need to shell out by using make internals only.
---
 Makefile.include | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/Makefile.include b/Makefile.include
index 4dbc9b08e2..7267c6ca66 100644
--- a/Makefile.include
+++ b/Makefile.include
@@ -327,7 +327,15 @@ $(info $(USEPKG:%=$(RIOTPKG)/%/Makefile.include))
 .PHONY: $(USEPKG:%=$(RIOTPKG)/%/Makefile.include)
 -include $(USEPKG:%=$(RIOTPKG)/%/Makefile.include)
 
-USEMODULE_INCLUDES_ = $(shell echo $(USEMODULE_INCLUDES) | tr ' ' '\n' | awk '!a[$$0]++' | tr '\n' ' ')
+# Deduplicate includes without sorting them
+# see https://stackoverflow.com/questions/16144115/makefile-remove-duplicate-words-without-sorting
+define uniq =
+  $(eval seen :=)
+  $(foreach _,$1,$(if $(filter $_,$(seen)),,$(eval seen += $_)))
+  $(seen)
+endef
+
+USEMODULE_INCLUDES_ = $(strip $(call uniq,$(USEMODULE_INCLUDES)))
 
 INCLUDES += $(USEMODULE_INCLUDES_:%=-I%)
 
-- 
GitLab