CARGO ?= cargo
CC ?= cc
PROFILE ?= release
CARGO_FLAGS = --features ffi
ifeq ($(PROFILE),release)
CARGO_FLAGS += --release
TARGET_DIR = target/release
else
TARGET_DIR = target/debug
endif
UNAME := $(shell uname -s)
ifeq ($(UNAME),Darwin)
SHARED_LIB = libxmloxide.dylib
LDFLAGS = -lpthread -ldl -lm -framework Security
DYLD = DYLD_LIBRARY_PATH=$(TARGET_DIR)
else ifeq ($(UNAME),Linux)
SHARED_LIB = libxmloxide.so
LDFLAGS = -lpthread -ldl -lm
DYLD = LD_LIBRARY_PATH=$(TARGET_DIR)
else
SHARED_LIB = xmloxide.dll
LDFLAGS =
DYLD =
endif
.PHONY: all shared static debug example clean
shared:
$(CARGO) rustc --lib $(CARGO_FLAGS) --crate-type=cdylib
@echo "Built: $(TARGET_DIR)/$(SHARED_LIB)"
static:
$(CARGO) rustc --lib $(CARGO_FLAGS) --crate-type=staticlib
@echo "Built: $(TARGET_DIR)/libxmloxide.a"
all: shared static
debug:
$(MAKE) PROFILE=debug all
example: all
$(CC) -o ffi_usage examples/ffi_usage.c -Iinclude \
-L$(TARGET_DIR) -lxmloxide $(LDFLAGS)
@echo "Built: ./ffi_usage"
@echo "Run with: $(DYLD) ./ffi_usage"
clean:
$(CARGO) clean
rm -f ffi_usage