CARGO := cargo
export BUILD_MODE ?= release
ROOT_DIR := $(CURDIR)
C_EXAMPLES_DIR := $(ROOT_DIR)/c-examples
EXAMPLES_DIR := $(ROOT_DIR)/examples
RUST_TARGET_DIR := $(ROOT_DIR)/target
export RUST_LIB_NAME := cc_teec
export RUST_LIB_FILE := lib$(RUST_LIB_NAME).so
export ANDROID_API_LEVEL ?= 35
export ANDROID_TARGET := aarch64-linux-android
ANDROID_OUT_DIR := $(RUST_TARGET_DIR)/$(ANDROID_TARGET)/release
ifeq ($(BUILD_MODE), release)
CARGO_FLAGS += --release
BUILD_TYPE := release
CARGO_PROFILE := --profile release
else
BUILD_TYPE := debug
CARGO_PROFILE :=
endif
export RUST_TARGET_BUILD_DIR := $(RUST_TARGET_DIR)/$(BUILD_TYPE)
export LD_LIBRARY_PATH=$(RUST_TARGET_BUILD_DIR):$$LD_LIBRARY_PATH
CARGO_BUILD_FLAGS := $(CARGO_FLAGS)
CARGO_TEST_FLAGS := $(CARGO_FLAGS)
CARGO_DOC_FLAGS := $(CARGO_FLAGS)
.DEFAULT_GOAL := all
.PHONY: all
all: build test
.PHONY: build
build: build-rust build-c-examples
.PHONY: build-rust
build-rust:
@echo "Building Rust library and examples..."
$(CARGO) build $(CARGO_BUILD_FLAGS) --lib
$(CARGO) build $(CARGO_BUILD_FLAGS) --example cc-teec
@echo "Rust build completed"
.PHONY: build-c-examples
build-c-examples:
@echo "Building C examples..."
$(MAKE) -C $(C_EXAMPLES_DIR)
@echo "C examples build completed"
.PHONY: test
test:
@echo "Running Rust tests..."
$(CARGO) test $(CARGO_TEST_FLAGS)
@echo "Rust tests completed"
.PHONY: test-c-examples
test-c-examples: build-c-examples
$(C_EXAMPLES_DIR)/cc-teec
.PHONY: doc
doc:
@echo "Generating documentation..."
$(CARGO) doc $(CARGO_DOC_FLAGS) --no-deps --open
@echo "Documentation generated"
.PHONY: doc-no-open
doc-no-open:
@echo "Generating documentation..."
$(CARGO) doc $(CARGO_DOC_FLAGS) --no-deps
@echo "Documentation generated"
.PHONY: fmt
fmt:
@echo "Checking code formatting..."
cargo fmt -- --check
@echo "Format check completed"
.PHONY: fmt-fix
fmt-fix:
@echo "Formatting code..."
cargo fmt
@echo "Code formatted"
.PHONY: clippy
clippy:
@echo "Running Clippy..."
$(CARGO) clippy $(CARGO_BUILD_FLAGS) -- -D warnings
@echo "Clippy check completed"
.PHONY: audit
audit:
@echo "Running security audit..."
$(CARGO) audit
@echo "Security audit completed"
.PHONY: check
check: fmt clippy audit test
@echo "All checks passed!"
.PHONY: clean-c-examples
clean-c-examples:
@echo "Cleaning C examples..."
$(MAKE) -C $(C_EXAMPLES_DIR) clean
@echo "C examples cleaned"
.PHONY: clean
clean: clean-c-examples
@echo "Cleaning Rust build artifacts..."
$(CARGO) clean
@echo "All cleaned"
.PHONY: release
release:
@echo "Building release version..."
$(MAKE) build BUILD_MODE=release
@echo "Release build completed"
.PHONY: coverage
coverage:
@echo "Installing cargo-tarpaulin if not present..."
@cargo install cargo-tarpaulin --quiet 2>/dev/null || true
@echo "Running code coverage analysis..."
mkdir -p coverage-report
cargo tarpaulin --out html --output-dir coverage-report --no-fail-fast --skip-clean --engine llvm
cargo tarpaulin --out xml --output-dir coverage-report --no-fail-fast --skip-clean --engine llvm
mv -f coverage-report/tarpaulin-report.html coverage-report/coverage.html
mv -f coverage-report/cobertura.xml coverage-report/coverage.xml
@echo "Coverage report generated in coverage-report/"
PREFIX ?= /usr/local
LIBDIR ?= $(PREFIX)$(shell echo /usr/lib/$$(uname -m)-linux-gnu)/
INCLUDE_DIR ?= $(PREFIX)/usr/include/cc-teec/
.PHONY: install
install:
@echo "Installing library and headers..."
install -d $(LIBDIR)
install -m 0755 $(RUST_TARGET_BUILD_DIR)/$(RUST_LIB_FILE) $(LIBDIR)
install -d $(INCLUDE_DIR)
install -m 0644 $(C_EXAMPLES_DIR)/include/*.h $(INCLUDE_DIR)
@echo "Installation completed"
.PHONY: uninstall
uninstall:
@echo "Uninstalling library..."
rm -rf $(LIBDIR)/$(RUST_LIB_FILE)
rm -rf $(INCLUDE_DIR)
@echo "Uninstallation completed"
build-c-examples: build-rust
test: build-rust
android-ndk-check:
@if [ -z "$(ANDROID_NDK_HOME)" ]; then \
echo "Error: ANDROID_NDK_HOME is not set. Please export ANDROID_NDK_HOME=/path/to/android-ndk-r29"; \
exit 1; \
fi
android: android-ndk-check
@echo "Building for Android $(ANDROID_TARGET) - API $(ANDROID_API_LEVEL)..."
ANDROID_NDK_HOME=$(ANDROID_NDK_HOME) cargo ndk --platform $(ANDROID_API_LEVEL) build --target arm64-v8a --release --lib
@echo "Android build completed: $(ANDROID_OUT_DIR)/$(RUST_LIB_FILE)"
android-c-examples: android
@echo "Building C examples for Android..."
$(MAKE) -C $(C_EXAMPLES_DIR) android-sign
@echo "Android C examples build completed"
android-all: android android-c-examples
.PHONY: all build build-rust build-c-examples test\
doc doc-no-open \
fmt fmt-fix clippy audit check \
clean clean-c-examples \
release install uninstall \
android-ndk-check android android-c-examples android-all