add command code constants, send header

This commit is contained in:
Vinzenz Schroeter 2025-04-12 21:47:23 +02:00
parent f193c659b9
commit ce70ecd9e2
12 changed files with 141 additions and 60 deletions

View file

@ -1,9 +1,12 @@
CC := gcc
CARGO := rustup run nightly cargo
TARGET := x86_64-unknown-linux-musl
PROFILE := size-optimized
THIS_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
REPO_ROOT := $(THIS_DIR)/..
RUST_TARGET_DIR := $(REPO_ROOT)/target/x86_64-unknown-linux-musl/size-optimized
RUST_TARGET_DIR := $(REPO_ROOT)/target/$(TARGET)/$(PROFILE)
export SERVICEPOINT_HEADER_OUT := $(REPO_ROOT)/include
RUSTFLAGS := -Zlocation-detail=none \
@ -17,9 +20,9 @@ RUSTFLAGS := -Zlocation-detail=none \
-C panic=abort
CARGOFLAGS := --manifest-path=$(REPO_ROOT)/Cargo.toml \
--profile=size-optimized \
--profile=$(PROFILE) \
--no-default-features \
--target=x86_64-unknown-linux-musl \
--target=$(TARGET) \
-Zbuild-std="core,std,alloc,proc_macro,panic_abort" \
-Zbuild-std-features="panic_immediate_abort" \
@ -45,23 +48,23 @@ CCFLAGS := -static -Os \
STRIPFLAGS := -s --strip-unneeded -R .comment -R .gnu.version -R .comment -R .note -R .note.gnu.build-id -R .note.ABI-tag
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
_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)
all: $(_bins)
clean:
rm -r out || true
rm include/servicepoint.h || true
cargo clean
PHONY: all clean sizes $(run_programs)
PHONY: all clean sizes $(_run_programs)
$(unstripped_bins): out/%_unstripped: %.c $(SERVICEPOINT_HEADER_OUT)/servicepoint.h $(RUST_TARGET_DIR)/libservicepoint_binding_c.a
$(_unstripped_bins): out/%_unstripped: %.c $(SERVICEPOINT_HEADER_OUT)/servicepoint.h $(RUST_TARGET_DIR)/libservicepoint_binding_c.a
mkdir -p out || true
${CC} $^ \
-I $(SERVICEPOINT_HEADER_OUT) \
@ -69,18 +72,18 @@ $(unstripped_bins): out/%_unstripped: %.c $(SERVICEPOINT_HEADER_OUT)/servicepoin
$(CCFLAGS) \
-o $@
$(bins): out/%: out/%_unstripped
$(_bins): out/%: out/%_unstripped
strip $(STRIPFLAGS) $^ -o $@
$(SERVICEPOINT_HEADER_OUT)/servicepoint.h $(RUST_TARGET_DIR)/libservicepoint_binding_c.a: $(rs_src)
$(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)
$(run_programs): run_%: out/% FORCE
$(_run_programs): run_%: out/% FORCE
./$<
sizes: $(bins)
sizes: $(_bins)
ls -lB out
#analyze-size: out/example_unstripped
@ -88,6 +91,4 @@ sizes: $(bins)
# | awk '{size=$$2+0; print size "\t" $$4}' \
# | less
FORCE: ;