Skip to content

Commit 1bacf70

Browse files
authored
Merge pull request #21476 from mguetschow/examples-subfolders-external-module
examples/basic/subfolders: switch from DIRS to EXTERNAL_MODULE_DIRS
2 parents 5b5c1ba + 1f674a4 commit 1bacf70

File tree

6 files changed

+38
-23
lines changed

6 files changed

+38
-23
lines changed

examples/basic/subfolders/Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ BOARD ?= native
88
RIOTBASE ?= $(CURDIR)/../../..
99

1010
# Add subfolders as modules
11-
DIRS += module
12-
USEMODULE += my_module # name as defined in module/Makefile
11+
EXTERNAL_MODULE_DIRS += $(CURDIR)/external_modules/
12+
USEMODULE += module # module name must match folder name
1313

1414
# Add source files in subfolders manually
1515
SRC += main.c
@@ -18,9 +18,9 @@ SRC += folder/a.c folder/subfolder/b.c folder/subfolder/c.c
1818
# Alternative method to add files in subfolders using wildcards
1919
# SRC += $(wildcard *.c folder/*.c folder/**/*.c)
2020

21-
# Adding subfolders both via SRC and DIRS will generate a warning
22-
# and likely fail during linking
23-
# DIRS += folder
21+
# Adding files in subfolders both via SRC and EXTERNAL_MODULE_DIRS
22+
# will generate a warning and likely fail during linking
23+
# SRC += external_modules/module/a.c
2424

2525
# Comment this out to disable code in RIOT that does safety checking
2626
# which is not needed in a production environment but helps in the

examples/basic/subfolders/README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Application Example with Subfolders
22

33
This example demonstrates the usage of subfolders in a RIOT application
4-
(or in a RIOT module in general) show-casing two possible approaches: RIOT
5-
modules and simple subfolders.
4+
(or in a RIOT module in general) show-casing two possible approaches:
5+
External RIOT modules and simple subfolders.
66

77
## Details
88

@@ -12,16 +12,18 @@ while the source files in `folder` are considered part of the application itself
1212

1313
```
1414
.
15+
├── external_modules
16+
│ └── module
17+
│ ├── a.c
18+
│ ├── b.c
19+
│ └── Makefile
1520
├── folder
1621
│ ├── a.c
1722
│ └── subfolder
18-
│ └── b.c
23+
│ ├── b.c
24+
│ └── c.c
1925
├── main.c
2026
├── Makefile
21-
├── module
22-
│ ├── a.c
23-
│ ├── b.c
24-
│ └── Makefile
2527
└── README.md
2628
```
2729

@@ -30,14 +32,11 @@ while the source files in `folder` are considered part of the application itself
3032
At a minimum, each module in RIOT requires a `Makefile` with the following content:
3133

3234
```Makefile
33-
MODULE := my_module
34-
3535
include $(RIOTBASE)/Makefile.base
3636
```
3737

38-
If `MODULE` is not specified, the name of the module's directory is automatically used,
39-
leaving only the last line as minimal content.
40-
It is important to note that module names have to be unique both among _all_ RIOT modules,
38+
The name of the module's directory is automatically used as the module name.
39+
It is important to note that module names have to be unique among _all_ RIOT modules,
4140
i.e., including the modules that are part of RIOT itself.
4241

4342
If not manually specified via `SRC`, all source files which reside
@@ -47,12 +46,13 @@ RIOT modules are also described in greater detail [in the documentation](https:/
4746
Two lines need to be added to the application's Makefile in order to compile and use the module:
4847

4948
```Makefile
50-
DIRS += module
51-
USEMODULE += my_module
49+
EXTERNAL_MODULE_DIRS += $(CURDIR)/external_modules/
50+
USEMODULE += module
5251
```
5352

54-
The string added to `DIRS` has to match the directory name,
55-
while the string added to `USEMODULE` has to match the module's name as defined above.
53+
The path added to `EXTERNAL_MODULE_DIRS` is the parent directory of the external module,
54+
while the string added to `USEMODULE` has to match the module's directory name.
55+
External modules are described in greater detail [in the documentation](https://doc.riot-os.org/creating-an-application.html#autotoc_md2308).
5656

5757

5858
### Subfolders
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
MODULE := my_module
2-
31
include $(RIOTBASE)/Makefile.base
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env python3
2+
3+
import sys
4+
from testrunner import run
5+
6+
7+
def testfunc(child):
8+
child.expect_exact('./main.c')
9+
child.expect_exact('./module/a.c')
10+
child.expect_exact('./module/b.c')
11+
child.expect_exact('./folder/a.c')
12+
child.expect_exact('./folder/subfolder/b.c')
13+
child.expect_exact('./folder/subfolder/c.c')
14+
15+
16+
if __name__ == "__main__":
17+
sys.exit(run(testfunc))

0 commit comments

Comments
 (0)