# plugin_crontab — ScorpioX Bot open-source cron schedule inspector
#
# Targets:
#   make            native build  -> ./plugin_crontab
#   make musl       static musl x86_64 -> ./plugin_crontab (fully static)
#   make win64      MinGW-w64 static -> ./plugin_crontab.exe
#   make macos      Apple clang -> ./plugin_crontab (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
WIN_CC        ?= x86_64-w64-mingw32-gcc
WIN_CFLAGS    := -O2 -std=c99 -Wall -Wextra -static -Wno-overlength-strings
SRC           := src/plugin_crontab.c
BIN           := plugin_crontab
EXE           := plugin_crontab.exe

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

all: native

native: $(BIN)

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

# Static musl build - the universal Linux artifact (Alpine, Debian, Arch, Omarchy)
musl: $(SRC)
	@echo "==> static musl build ($(MUSL_CC))"
	$(MUSL_CC) $(MUSL_CFLAGS) -o $(BIN).musl $(SRC)

# Native Win64 static PE - runs on any Windows 10/11 x64 node
win64: $(SRC)
	@echo "==> MinGW-w64 build ($(WIN_CC))"
	$(WIN_CC) $(WIN_CFLAGS) -o $(EXE) $(SRC)

# Apple clang build (run this on macOS)
macos: $(SRC)
	@echo "==> Apple clang build"
	$(CC) $(CFLAGS) -o $(BIN) $(SRC)

test: native
	@sh tests/run.sh

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

distclean: clean

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