Skip to content

Commit 16c0131

Browse files
committed
makefile: package examples as cpio.gz archive as well
Signed-off-by: Stefan Kerkmann <s.kerkmann@pengutronix.de>
1 parent 5a9b742 commit 16c0131

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

Makefile

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,27 @@ check-toolchain:
6262
%-build: check-toolchain
6363
CROSS_CONTAINER_ENGINE=$(CROSS_CONTAINER_ENGINE) RUSTFLAGS="$(RUSTFLAGS)" $(CARGO_RUNNER) +nightly build --all-targets --target $* $(if $(TARGET_PROFILE),--profile $(TARGET_PROFILE)) $(CARGO_FLAGS)
6464

65+
# Create a compressed cpio archive containing a binary renamed to 'init'.
66+
# Usage: $(call create-init-cpio,<source-binary>,<output-base-path>)
67+
# Produces: <output-base-path>.cpio.gz
68+
define create-init-cpio
69+
tmp=$$(mktemp -d) && \
70+
cp "$(1)" "$$tmp/init" && \
71+
(cd "$$tmp" && find init | cpio --create --format=newc --quiet > "$(abspath .)/$(2).cpio") && \
72+
gzip --best --force "$(abspath .)/$(2).cpio" && \
73+
rm -rf "$$tmp"
74+
endef
75+
6576
%-cpio: T=target/$*/$(if $(TARGET_PROFILE),$(TARGET_PROFILE),debug)
6677
%-cpio: %-build
67-
cd $T && find init | cpio --create --format=newc > init-$*.cpio
68-
cd $T && gzip --keep --best --force init-$*.cpio
78+
@echo "Packaging: $T/init"
79+
@$(call create-init-cpio,$T/init,$T/init-$*)
80+
@for bin in $T/examples/*; do \
81+
[ -f "$$bin" ] && [ -x "$$bin" ] || continue; \
82+
name=$$(basename "$$bin"); \
83+
echo "Packaging: $T/examples/$$name"; \
84+
$(call create-init-cpio,$$bin,$T/examples/$$name); \
85+
done
6986

7087
clean:
7188
cargo clean

0 commit comments

Comments
 (0)