From 6b534a935f4466423a97ac64fb0a09e2f2893b4b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= <gaetan.harter@fu-berlin.de>
Date: Thu, 19 Apr 2018 16:05:43 +0200
Subject: [PATCH] make: process include and dep for external modules

Process `Makefile.include` for external modules. It is included after the others
so it could overwrite some of the configuration if wanted.

Process `Makefile.dep` for external modules. It is included before the others so
it could be parsed before setting 'default' values to dependencies.
---
 Makefile.dep                        | 4 ++++
 Makefile.include                    | 3 +++
 doc/doxygen/src/creating-modules.md | 8 ++++++--
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/Makefile.dep b/Makefile.dep
index 006ad059dd..9b01c11117 100644
--- a/Makefile.dep
+++ b/Makefile.dep
@@ -5,6 +5,10 @@ OLD_USEPKG := $(sort $(USEPKG))
 # include board dependencies
 -include $(RIOTBOARD)/$(BOARD)/Makefile.dep
 
+# include external modules dependencies
+# processed before RIOT ones to be evaluated before the 'default' rules.
+-include $(EXTERNAL_MODULE_DIRS:%=%/Makefile.dep)
+
 # pull dependencies from sys and drivers
 include $(RIOTBASE)/sys/Makefile.dep
 include $(RIOTBASE)/drivers/Makefile.dep
diff --git a/Makefile.include b/Makefile.include
index 6646a29bd1..2c1dd40102 100644
--- a/Makefile.include
+++ b/Makefile.include
@@ -353,6 +353,9 @@ $(RIOTPKG)/%/Makefile.include::
 $(USEPKG:%=$(RIOTPKG)/%/Makefile.include): FORCE
 -include $(USEPKG:%=$(RIOTPKG)/%/Makefile.include)
 
+# include external modules configuration
+-include $(EXTERNAL_MODULE_DIRS:%=%/Makefile.include)
+
 # Deduplicate includes without sorting them
 # see https://stackoverflow.com/questions/16144115/makefile-remove-duplicate-words-without-sorting
 define uniq
diff --git a/doc/doxygen/src/creating-modules.md b/doc/doxygen/src/creating-modules.md
index 9ac037a485..776024be7f 100644
--- a/doc/doxygen/src/creating-modules.md
+++ b/doc/doxygen/src/creating-modules.md
@@ -67,8 +67,12 @@ their dependencies.
 Modules outside of RIOTBASE                      {#modules-outside-of-riotbase}
 ===========================
 Modules can be defined outside `RIOTBASE`. In addition to add it to `USEMODULE`
-the user needs to add the path to the module to `EXTERNAL_MODULE_DIRS` and add
-the include path to the API definitions to `INCLUDES`.
+the user needs to add the module path to `EXTERNAL_MODULE_DIRS`.
+
+The external module can optionally define the following files:
+* `Makefile.include` file to set global build configuration like `CFLAGS` or add
+  API headers include paths to the `USEMODULE_INCLUDES` variable.
+* `Makefile.dep` file to set module dependencies
 
 Pseudomodules                                                  {#pseudomodules}
 =============
-- 
GitLab