Skip to content

Commit

Permalink
Add Makefile providing container based build workflow
Browse files Browse the repository at this point in the history
Currently it needs a lot of steps to build single firmware, so lets
streamline this workflow by using container.

 Usage: make [all|build_container|build_firmware]
 Targets:
   all             Build container and firmware
   build_container Build container
   build_firmware  Build firmware
   help            Show this help message

 Options:
   build_firmware MANIFESTS=<path>  Override default manifest files (default: all .yaml/.yml files in manifests/)

 Examples:
   # Build the container image
   make build_container

   # Build all firmware manifests
   make build_firmware

   # Build a specific firmware manifest
   make build_firmware MANIFESTS=manifests/nabucasa/yellow_bootloader.yaml

Signed-off-by: Petr Štetiar <[email protected]>
  • Loading branch information
ynezz committed Dec 1, 2024
1 parent 42a0996 commit 8c7a7f4
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
TOPDIR = $(shell pwd)
CONTAINER_TOOL = podman
CONTAINER_NAME = silabs-firmware-builder
CONTAINER_USER_GROUP = $(shell id -u):$(shell id -g)

ifeq ($(CONTAINER_TOOL),docker)
VOLUME_OPTS=
else
VOLUME_OPTS=:z
endif

define run_in_container
$(CONTAINER_TOOL) \
run --rm -it \
--user $(CONTAINER_USER_GROUP) \
-v $(TOPDIR):/build$(VOLUME_OPTS) \
-v $(TOPDIR)/outputs:/outputs$(VOLUME_OPTS) \
-v $(TOPDIR)/build_dir:/build_dir$(VOLUME_OPTS) \
$(CONTAINER_NAME)
endef

MANIFESTS ?= $(shell find manifests -type f \( -name "*.yaml" -o -name "*.yml" \) -print)

all: build_container build_firmware

help:
@echo "Usage: make [all|build_container|build_firmware]"
@echo ""
@echo "Targets:"
@echo " all Build container and firmware"
@echo " build_container Build container"
@echo " build_firmware Build firmware"
@echo " help Show this help message"
@echo ""
@echo "Options:"
@echo " build_firmware MANIFESTS=<path> Override default manifest files (default: all .yaml/.yml files in manifests/)"
@echo ""
@echo "Examples:"
@echo " # Build the container image"
@echo " make build_container"
@echo ""
@echo " # Build all firmware manifests"
@echo " make build_firmware"
@echo ""
@echo " # Build a specific firmware manifest"
@echo " make build_firmware MANIFESTS=manifests/nabucasa/yellow_bootloader.yaml"
@echo ""

./outputs ./build_dir:
mkdir -p $@
ifneq ($(CONTAINER_TOOL),docker)
$(CONTAINER_TOOL) unshare chown -R $(shell id -u):$(shell id -g) $@
endif

build_container:
$(CONTAINER_TOOL) build -t $(CONTAINER_NAME) .

build_firmware: ./outputs ./build_dir
$(run_in_container) \
bash -c " \
build_firmware.sh \
--build-dir /build_dir \
--output-dir /outputs \
$(foreach manifest,$(MANIFESTS),--manifest $(manifest)) \
"

0 comments on commit 8c7a7f4

Please sign in to comment.