CRATE := kirmes
VERSION ?= $(shell git describe --tags --abbrev=0)
SOVERSION ?= $(shell command -v tomcli >/dev/null 2>&1 || { echo "tomcli is not installed, install with: sudo dnf install tomcli" >&2; exit 1; }; tomcli get Cargo.toml package.metadata.capi.library.version)
SOVERSION_MAJOR := $(word 1,$(subst ., ,$(SOVERSION)))
HOST_TUPLE ?= $(shell rustc --print host-tuple)
.PHONY: all help debug release doc clean dist test test-cmocka clippy examples
all: debug
help:
@echo "Available targets:"
@echo " all - Build debug version (default)"
@echo " debug - Build debug version with C API"
@echo " release - Build release version"
@echo " doc - Generate documentation"
@echo " test - Run Rust tests (cargo ctest)"
@echo " test-cmocka - Build and run CMocka C tests"
@echo " clippy - Run clippy linter"
@echo " examples - Build C examples"
@echo " clean - Clean build artifacts"
@echo " dist - Create source tarball"
debug:
command -v cargo || (echo "cargo isn't installed" && exit 1)
cargo build --features binaries
command -v cargo-cbuild || (echo "cargo cbuild isn't installed" && exit 1)
cargo cbuild
release:
command -v cargo || (echo "cargo isn't installed" && exit 1)
cargo build --release
doc:
command -v cargo || (echo "cargo isn't installed" && exit 1)
cargo doc
clean:
command -v cargo || (echo "cargo isn't installed" && exit 1)
cargo clean
dist:
git archive --format=tar.gz --output ./$(CRATE)-$(VERSION).tar.gz HEAD
test:
command -v cargo || (echo "cargo isn't installed" && exit 1)
cargo ctest
test-cmocka: all
ln -sf libkirmes.so target/$(HOST_TUPLE)/debug/libkirmes.so.$(SOVERSION_MAJOR)
ln -sf libkirmes.so.$(SOVERSION_MAJOR) target/$(HOST_TUPLE)/debug/libkirmes.so.$(SOVERSION)
ctest --build-and-test tests target/c/build --build-generator 'Unix Makefiles'
cd target/c/build && ctest --output-on-failure
clippy:
command -v cargo || (echo "cargo isn't installed" && exit 1)
cargo clippy -- -W clippy::pedantic
examples: all
gcc -O0 -ggdb example/user_record.c -o target/$(HOST_TUPLE)/debug/user_record -Itarget/$(HOST_TUPLE)/debug/include -Ltarget/$(HOST_TUPLE)/debug/ -lkirmes
gcc -O0 -ggdb example/group_record.c -o target/$(HOST_TUPLE)/debug/group_record -Itarget/$(HOST_TUPLE)/debug/include -Ltarget/$(HOST_TUPLE)/debug/ -lkirmes
gcc -O0 -ggdb example/user_in_group.c -o target/$(HOST_TUPLE)/debug/user_in_group -Itarget/$(HOST_TUPLE)/debug/include -Ltarget/$(HOST_TUPLE)/debug/ -lkirmes
gcc -O0 -ggdb example/groups_of_user.c -o target/$(HOST_TUPLE)/debug/groups_of_user -Itarget/$(HOST_TUPLE)/debug/include -Ltarget/$(HOST_TUPLE)/debug/ -lkirmes
gcc -O0 -ggdb example/user_record_from_json.c -o target/$(HOST_TUPLE)/debug/user_record_from_json -Itarget/$(HOST_TUPLE)/debug/include -Ltarget/$(HOST_TUPLE)/debug/ -lkirmes
ln -sf libkirmes.so target/$(HOST_TUPLE)/debug/libkirmes.so.$(SOVERSION_MAJOR)
ln -sf libkirmes.so.$(SOVERSION_MAJOR) target/$(HOST_TUPLE)/debug/libkirmes.so.$(SOVERSION)