# Makefile — build & install the MuMu "sys" plugin

PLUGIN := sys

# Detect platform-specific dynamic library suffix
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
  DLL := dylib
else
  DLL := so
endif

TARGET  := libmumu$(PLUGIN).$(DLL)
PREFIX  ?= /usr/local
LIBDIR  ?= $(PREFIX)/lib

.PHONY: all debug release install install-debug uninstall clean print-target

all: release

debug:
	cargo build

release:
	cargo build --release

install: release
	# copy the correct artifact for this OS
	sudo install -m 0755 target/release/$(TARGET) $(LIBDIR)/$(TARGET)
	# ldconfig is Linux-only; on macOS we skip it
	@if [ "$(UNAME_S)" != "Darwin" ]; then sudo ldconfig; fi

install-debug: debug
	sudo install -m 0755 target/debug/$(TARGET) $(LIBDIR)/$(TARGET)
	@if [ "$(UNAME_S)" != "Darwin" ]; then sudo ldconfig; fi

uninstall:
	sudo rm -f $(LIBDIR)/$(TARGET)
	@if [ "$(UNAME_S)" != "Darwin" ]; then sudo ldconfig; fi

clean:
	cargo clean

print-target:
	@echo $(TARGET)
