Skip to content

Commit 9b0524f

Browse files
committed
examples/embedding: Build embed sources in the same make command.
Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
1 parent f1018ee commit 9b0524f

File tree

5 files changed

+65
-30
lines changed

5 files changed

+65
-30
lines changed

.github/workflows/examples.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ jobs:
2020
steps:
2121
- uses: actions/checkout@v4
2222
- name: Build
23-
run: make -C examples/embedding -f micropython_embed.mk && make -C examples/embedding
23+
run: make -C examples/embedding -f micropython_embed.mk && make -C examples/embedding -f makefile.mk
2424
- name: Run
2525
run: ./examples/embedding/embed | grep "hello world"
26+
- name: Clean
27+
run: make -C examples/embedding clean && [ ! -e embed ] && [ ! -e micropython_embed ]
28+
- name: Combined Build
29+
run: make -C examples/embedding
30+
- name: Combined Run
31+
run: ./examples/embedding/embed | grep "hello world"

examples/embedding/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
micropython_embed/
2+
embed
3+
*.o

examples/embedding/Makefile

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
11
# This file is part of the MicroPython project, http://micropython.org/
22
# The MIT License (MIT)
3-
# Copyright (c) 2022-2023 Damien P. George
4-
#
5-
# This is a very simple makefile that demonstrates how to build the embed port.
6-
# All it needs to do is build all *.c files in the micropython_embed directory.
7-
# This makefile would be replaced with your custom build system.
3+
# Copyright (c) 2025 Anson Mansfield
84

9-
EMBED_DIR = micropython_embed
10-
PROG = embed
5+
all: mpy
6+
$(MAKE) -f makefile.mk
7+
clean::
8+
$(MAKE) -f makefile.mk clean
119

12-
CFLAGS += -I.
13-
CFLAGS += -I$(EMBED_DIR)
14-
CFLAGS += -I$(EMBED_DIR)/port
15-
CFLAGS += -Wall -Og -fno-common
10+
mpy:
11+
$(MAKE) -f micropython_embed.mk
12+
clean::
13+
$(MAKE) -f micropython_embed.mk clean
1614

17-
SRC += main.c
18-
SRC += $(wildcard $(EMBED_DIR)/*/*.c) $(wildcard $(EMBED_DIR)/*/*/*.c)
19-
OBJ += $(SRC:.c=.o)
20-
21-
$(PROG): $(OBJ)
22-
$(CC) -o $@ $^
23-
24-
clean:
25-
/bin/rm -f $(OBJ) $(PROG)
15+
.PHONY: all clean mpy

examples/embedding/README.md

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,34 @@ simple Python scripts which print things to the standard output.
1010
Building the example
1111
--------------------
1212

13-
First build the embed port using:
14-
15-
$ make -f micropython_embed.mk
16-
17-
This will generate the `micropython_embed` directory which is a self-contained
18-
copy of MicroPython suitable for embedding. The .c files in this directory need
19-
to be compiled into your project, in whatever way your project can do that. The
20-
example here uses make and a provided `Makefile`.
21-
2213
To build the example project, based on `main.c`, use:
2314

2415
$ make
2516

17+
This will first build the micropython embedded sources using the
18+
`micropython_embed.mk` sub-make, then compile those sources together with `main.c`
19+
using the `makefile.mk` sub-make. (It's done this way, so that the second sub-make
20+
can discover sources that might not exist until after the first when building from
21+
clean.)
22+
2623
That will create an executable called `embed` which you can run:
2724

2825
$ ./embed
2926

27+
Building the embed port manually
28+
--------------------------------
29+
30+
You can also building the embed port directly using:
31+
32+
$ make -f micropython_embed.mk
33+
34+
This will generate the `micropython_embed` directory which is a self-contained
35+
copy of MicroPython suitable for embedding. The .c files in this directory need
36+
to be compiled into your project, in whatever way your project can do that. The
37+
example here uses make and the provided `makefile.mk`.
38+
39+
$ make -f makefile.mk
40+
3041
Out of tree build
3142
-----------------
3243

examples/embedding/makefile.mk

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# This file is part of the MicroPython project, http://micropython.org/
2+
# The MIT License (MIT)
3+
# Copyright (c) 2022-2023 Damien P. George
4+
#
5+
# This is a very simple makefile that demonstrates how to build the embed port.
6+
# All it needs to do is build all *.c files in the micropython_embed directory.
7+
# This makefile would be replaced with your custom build system.
8+
9+
EMBED_DIR = micropython_embed
10+
PROG = embed
11+
12+
CFLAGS += -I.
13+
CFLAGS += -I$(EMBED_DIR)
14+
CFLAGS += -I$(EMBED_DIR)/port
15+
CFLAGS += -Wall -Og -fno-common
16+
17+
SRC += main.c
18+
SRC += $(wildcard $(EMBED_DIR)/*/*.c) $(wildcard $(EMBED_DIR)/*/*/*.c)
19+
OBJ += $(SRC:.c=.o)
20+
21+
$(PROG): $(OBJ)
22+
$(CC) -o $@ $^
23+
24+
clean:
25+
/bin/rm -f $(OBJ) $(PROG)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy