# plugin_sglang - SCORPIOX BOT open-source SGLang server metrics monitor
#
# Targets:
#   make            native build          -> ./plugin_sglang
#   make musl       static musl x86_64     -> ./plugin_sglang.musl
#   make arm64      static aarch64 musl    -> ./plugin_sglang.arm64
#   make win64      MinGW-w64 static PE    -> ./plugin_sglang.exe
#   make macos      Apple clang (run on macOS)
#   make test       build + run tests/run.sh
#   make clean

CC            ?= cc
CFLAGS        ?= -O2 -std=c99 -Wall -Wextra -pedantic -Wno-overlength-strings
MUSL_CC       ?= musl-gcc
MUSL_CFLAGS   := -O2 -std=c99 -Wall -Wextra -static -Wno-overlength-strings
ARM_CC        ?= aarch64-linux-gnu-gcc
ARM_CFLAGS    := -O2 -std=c99 -Wall -Wextra -static -Wno-overlength-strings
WIN_CC        ?= x86_64-w64-mingw32-gcc
WIN_CFLAGS    := -O2 -std=c99 -Wall -Wextra -static -Wno-overlength-strings
SRC           := src/plugin_sglang.c
HDR           := src/bot_theme_plugin.h
BIN           := plugin_sglang
EXE           := plugin_sglang.exe

.PHONY: all native musl arm64 win64 macos test clean help

all: native

native: $(BIN)

$(BIN): $(SRC) $(HDR)
	@echo "==> native build ($(CC))"
	$(CC) $(CFLAGS) -o $(BIN) $(SRC)

musl: $(SRC) $(HDR)
	@echo "==> static musl build ($(MUSL_CC))"
	$(MUSL_CC) $(MUSL_CFLAGS) -o $(BIN).musl $(SRC)

arm64: $(SRC) $(HDR)
	@echo "==> static arm64 build ($(ARM_CC))"
	$(ARM_CC) $(ARM_CFLAGS) -o $(BIN).arm64 $(SRC)

win64: $(SRC) $(HDR)
	@echo "==> MinGW-w64 build ($(WIN_CC))"
	$(WIN_CC) $(WIN_CFLAGS) -o $(EXE) $(SRC)

macos: $(SRC) $(HDR)
	@echo "==> Apple clang build"
	$(CC) -O2 -std=c99 -Wall -Wextra -Wno-overlength-strings -o $(BIN) $(SRC)

test: native
	@sh tests/run.sh

clean:
	rm -f $(BIN) $(EXE) $(BIN).musl $(BIN).arm64 $(BIN).macos-arm64 $(BIN).macos-x86_64
	rm -rf bin

help:
	@echo "make | make musl | make arm64 | make win64 | make macos | make test | make clean"
