Skip to content

examples/embedding: Build embed sources in the same make command. #16948

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Build
run: make -C examples/embedding -f micropython_embed.mk && make -C examples/embedding
run: make -C examples/embedding -f micropython_embed.mk && make -C examples/embedding -f makefile.mk
- name: Run
run: ./examples/embedding/embed | grep "hello world"
- name: Clean
run: make -C examples/embedding clean && [ ! -e embed ] && [ ! -e micropython_embed ]
- name: Combined Build
run: make -C examples/embedding
- name: Combined Run
run: ./examples/embedding/embed | grep "hello world"
3 changes: 3 additions & 0 deletions examples/embedding/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
micropython_embed/
embed
*.o
30 changes: 10 additions & 20 deletions examples/embedding/Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
# This file is part of the MicroPython project, http://micropython.org/
# The MIT License (MIT)
# Copyright (c) 2022-2023 Damien P. George
#
# This is a very simple makefile that demonstrates how to build the embed port.
# All it needs to do is build all *.c files in the micropython_embed directory.
# This makefile would be replaced with your custom build system.
# Copyright (c) 2025 Anson Mansfield

EMBED_DIR = micropython_embed
PROG = embed
all: mpy
$(MAKE) -f makefile.mk
clean::
$(MAKE) -f makefile.mk clean

CFLAGS += -I.
CFLAGS += -I$(EMBED_DIR)
CFLAGS += -I$(EMBED_DIR)/port
CFLAGS += -Wall -Og -fno-common
mpy:
$(MAKE) -f micropython_embed.mk
clean::
$(MAKE) -f micropython_embed.mk clean

SRC += main.c
SRC += $(wildcard $(EMBED_DIR)/*/*.c) $(wildcard $(EMBED_DIR)/*/*/*.c)
OBJ += $(SRC:.c=.o)

$(PROG): $(OBJ)
$(CC) -o $@ $^

clean:
/bin/rm -f $(OBJ) $(PROG)
.PHONY: all clean mpy
29 changes: 20 additions & 9 deletions examples/embedding/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,34 @@ simple Python scripts which print things to the standard output.
Building the example
--------------------

First build the embed port using:

$ make -f micropython_embed.mk

This will generate the `micropython_embed` directory which is a self-contained
copy of MicroPython suitable for embedding. The .c files in this directory need
to be compiled into your project, in whatever way your project can do that. The
example here uses make and a provided `Makefile`.

To build the example project, based on `main.c`, use:

$ make

This will first build the micropython embedded sources using the
`micropython_embed.mk` sub-make, then compile those sources together with `main.c`
using the `makefile.mk` sub-make. (It's done this way, so that the second sub-make
can discover sources that might not exist until after the first when building from
clean.)

That will create an executable called `embed` which you can run:

$ ./embed

Building the embed port manually
--------------------------------

You can also building the embed port directly using:

$ make -f micropython_embed.mk

This will generate the `micropython_embed` directory which is a self-contained
copy of MicroPython suitable for embedding. The .c files in this directory need
to be compiled into your project, in whatever way your project can do that. The
example here uses make and the provided `makefile.mk`.

$ make -f makefile.mk

Out of tree build
-----------------

Expand Down
25 changes: 25 additions & 0 deletions examples/embedding/makefile.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This file is part of the MicroPython project, http://micropython.org/
# The MIT License (MIT)
# Copyright (c) 2022-2023 Damien P. George
#
# This is a very simple makefile that demonstrates how to build the embed port.
# All it needs to do is build all *.c files in the micropython_embed directory.
# This makefile would be replaced with your custom build system.

EMBED_DIR = micropython_embed
PROG = embed

CFLAGS += -I.
CFLAGS += -I$(EMBED_DIR)
CFLAGS += -I$(EMBED_DIR)/port
CFLAGS += -Wall -Og -fno-common

SRC += main.c
SRC += $(wildcard $(EMBED_DIR)/*/*.c) $(wildcard $(EMBED_DIR)/*/*/*.c)
OBJ += $(SRC:.c=.o)

$(PROG): $(OBJ)
$(CC) -o $@ $^

clean:
/bin/rm -f $(OBJ) $(PROG)
Loading
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