diff --git a/Makefile.dep b/Makefile.dep index 006ad059dd9a..9b01c11117a1 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 6646a29bd150..2c1dd40102a3 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 9ac037a485b8..55ad515e2dcb 100644 --- a/doc/doxygen/src/creating-modules.md +++ b/doc/doxygen/src/creating-modules.md @@ -67,8 +67,15 @@ 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 + +An example can be found in +[`tests/external_module_dirs`](https://github.com/RIOT-OS/RIOT/tree/master/tests/external_module_dirs) Pseudomodules {#pseudomodules} ============= diff --git a/tests/external_module_dirs/Makefile b/tests/external_module_dirs/Makefile new file mode 100644 index 000000000000..0a0c17fb7e72 --- /dev/null +++ b/tests/external_module_dirs/Makefile @@ -0,0 +1,10 @@ +APPLICATION = external_module_dirs +BOARD ?= native +RIOTBASE ?= $(CURDIR)/../.. + +USEMODULE += random + +USEMODULE += external_module +EXTERNAL_MODULE_DIRS += $(CURDIR)/external_module + +include $(RIOTBASE)/Makefile.include diff --git a/tests/external_module_dirs/README.md b/tests/external_module_dirs/README.md new file mode 100644 index 000000000000..e19e6b36b873 --- /dev/null +++ b/tests/external_module_dirs/README.md @@ -0,0 +1,12 @@ +Test of `EXTERNAL_MODULE_DIRS` handling +======================================= + +This is a test for the `EXTERNAL_MODULE_DIRS` variable. + +It demonstrates: + + * Adding a module with source code + * Setting a header include directory + * Adding dependencies, which are evaluated before other modules dependencies + +If the application compiles, everything is ok. diff --git a/tests/external_module_dirs/external_module/Makefile b/tests/external_module_dirs/external_module/Makefile new file mode 100644 index 000000000000..48422e909a47 --- /dev/null +++ b/tests/external_module_dirs/external_module/Makefile @@ -0,0 +1 @@ +include $(RIOTBASE)/Makefile.base diff --git a/tests/external_module_dirs/external_module/Makefile.dep b/tests/external_module_dirs/external_module/Makefile.dep new file mode 100644 index 000000000000..970cc1be9dc5 --- /dev/null +++ b/tests/external_module_dirs/external_module/Makefile.dep @@ -0,0 +1,3 @@ +USEMODULE += random +# Set a different prng than the default prng_tinymt32 +USEMODULE += prng_xorshift diff --git a/tests/external_module_dirs/external_module/Makefile.include b/tests/external_module_dirs/external_module/Makefile.include new file mode 100644 index 000000000000..ced920dbfb8b --- /dev/null +++ b/tests/external_module_dirs/external_module/Makefile.include @@ -0,0 +1,3 @@ +# Use an immediate variable to evaluate `MAKEFILE_LIST` now +USEMODULE_INCLUDES_external_module := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))/include +USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_external_module) diff --git a/tests/external_module_dirs/external_module/external_module.c b/tests/external_module_dirs/external_module/external_module.c new file mode 100644 index 000000000000..31b679f8aa5f --- /dev/null +++ b/tests/external_module_dirs/external_module/external_module.c @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2018 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup tests + * @{ + * + * @file + * @brief Test the EXTERNAL_MODULE_DIRS feature + * @note Define a shared variable + * + * @author Gaëtan Harter + * + * @} + */ + +#include "external_module.h" + +char *external_module_message = "Linking worked"; diff --git a/tests/external_module_dirs/external_module/include/external_module.h b/tests/external_module_dirs/external_module/include/external_module.h new file mode 100644 index 000000000000..f358ef4786d8 --- /dev/null +++ b/tests/external_module_dirs/external_module/include/external_module.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2018 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup + * @ingroup + * @brief + * @{ + * + * @file + * @brief + * + * @author Gaëtan Harter + */ +#ifndef EXTERNAL_MODULE_H +#define EXTERNAL_MODULE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief A simple string message + */ +extern char *external_module_message; + +#ifdef __cplusplus +} +#endif + +/** @} */ +#endif /* EXTERNAL_MODULE_H */ diff --git a/tests/external_module_dirs/main.c b/tests/external_module_dirs/main.c new file mode 100644 index 000000000000..9695fb682611 --- /dev/null +++ b/tests/external_module_dirs/main.c @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2018 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup tests + * @{ + * + * @file + * @brief Test the EXTERNAL_MODULE_DIRS feature + * + * @author Gaëtan Harter + * + * @} + */ + +#include + +#include "external_module.h" + +#ifdef MODULE_PRNG_TINYMT32 +#error "Error: it included the default dependency" +#endif + +#ifndef MODULE_PRNG_XORSHIFT +#error "Dependency not included" +#endif + +int main(void) +{ + puts("If it compiles, it works!"); + printf("Message: %s\n", external_module_message); + return 0; +}