diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 6613f106625a2..81ebcc22f5a9b 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -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" diff --git a/examples/embedding/.gitignore b/examples/embedding/.gitignore new file mode 100644 index 0000000000000..cbd76005594ce --- /dev/null +++ b/examples/embedding/.gitignore @@ -0,0 +1,3 @@ +micropython_embed/ +embed +*.o diff --git a/examples/embedding/Makefile b/examples/embedding/Makefile index c3ca14836f1d3..75734dddfbd74 100644 --- a/examples/embedding/Makefile +++ b/examples/embedding/Makefile @@ -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 diff --git a/examples/embedding/README.md b/examples/embedding/README.md index 3f19aff41f257..023d5178bb7e4 100644 --- a/examples/embedding/README.md +++ b/examples/embedding/README.md @@ -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 ----------------- diff --git a/examples/embedding/makefile.mk b/examples/embedding/makefile.mk new file mode 100644 index 0000000000000..c3ca14836f1d3 --- /dev/null +++ b/examples/embedding/makefile.mk @@ -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)
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: