translate announce and brightness tester examples

This commit is contained in:
Vinzenz Schroeter 2025-04-12 19:29:10 +02:00
parent 8dcced489a
commit f193c659b9
6 changed files with 96 additions and 24 deletions

View file

@ -4,6 +4,7 @@ CARGO := rustup run nightly cargo
THIS_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
REPO_ROOT := $(THIS_DIR)/..
RUST_TARGET_DIR := $(REPO_ROOT)/target/x86_64-unknown-linux-musl/size-optimized
export SERVICEPOINT_HEADER_OUT := $(REPO_ROOT)/include
RUSTFLAGS := -Zlocation-detail=none \
-Zfmt-debug=none \
@ -36,46 +37,57 @@ CCFLAGS := -static -Os \
-fvisibility=hidden \
-Bsymbolic \
-Wl,--exclude-libs,ALL \
-fno-ident
-fno-ident \
-Wall
#-fuse-ld=gold \
-fno-exceptions
#-Wl,--icf=all \
export SERVICEPOINT_HEADER_OUT := $(REPO_ROOT)/include
STRIPFLAGS := -s --strip-unneeded -R .comment -R .gnu.version -R .comment -R .note -R .note.gnu.build-id -R .note.ABI-tag
build: out/example
c_src := $(wildcard *.c)
programs := $(basename $(c_src))
bins := $(addprefix out/, $(programs))
unstripped_bins := $(addsuffix _unstripped, $(bins))
run_programs := $(addprefix run_, $(programs))
rs_src := $(wildcard ../src/*.rs) ../Cargo.lock
all: $(bins)
clean:
rm -r out || true
rm include/servicepoint.h || true
cargo clean
run: out/example
out/example
PHONY: all clean sizes $(run_programs)
PHONY: build clean dependencies run
out/example_unstripped: dependencies main.c
$(unstripped_bins): out/%_unstripped: %.c $(SERVICEPOINT_HEADER_OUT)/servicepoint.h $(RUST_TARGET_DIR)/libservicepoint_binding_c.a
mkdir -p out || true
${CC} main.c \
${CC} $^ \
-I $(SERVICEPOINT_HEADER_OUT) \
-L $(RUST_TARGET_DIR)\
$(CCFLAGS) \
-o out/example_unstripped
out/example: out/example_unstripped
strip -s --strip-unneeded \
-R .comment -R .gnu.version -R .comment -R .note -R .note.gnu.build-id -R .note.ABI-tag \
out/example_unstripped \
-o out/example
-o $@
dependencies: FORCE
$(bins): out/%: out/%_unstripped
strip $(STRIPFLAGS) $^ -o $@
$(SERVICEPOINT_HEADER_OUT)/servicepoint.h $(RUST_TARGET_DIR)/libservicepoint_binding_c.a: $(rs_src)
mkdir -p include || true
# generate servicepoint header and binary to link against
${CARGO} rustc $(CARGOFLAGS) -- $(RUSTFLAGS)
analyze-size: out/example_unstripped
nm --print-size --size-sort --reverse-sort --radix=d --demangle out/example_unstripped \
| awk '{size=$$2+0; print size "\t" $$4}' \
| less
$(run_programs): run_%: out/% FORCE
./$<
sizes: $(bins)
ls -lB out
#analyze-size: out/example_unstripped
# nm --print-size --size-sort --reverse-sort --radix=d --demangle out/example_unstripped \
# | awk '{size=$$2+0; print size "\t" $$4}' \
# | less
FORCE: ;