# mfscli-c — static, zero-dependency C port of mfscli-go.
#
# Default build is a static, stripped musl binary (~0.5-0.8 MB target).
# Requires musl-gcc (Debian: musl-tools, see ./setup-musl.sh).

# NB: plain '=' (not '?=') so we override make's built-in CC default of 'cc';
# a command-line 'make CC=gcc' still wins over this.
CC      = musl-gcc
CFLAGS  ?= -O2 -Wall -Wextra -std=c11
LDFLAGS ?= -static -s

# Engine + data layer + sections + CLI. More sections get added as they land.
SRCS = conn.c version.c util.c render.c cluster.c dataprovider.c dataprovider2.c dataprovider3.c dataprovider4.c sorts.c sections.c charts.c influx.c json.c gui.c assets.c health.c fileinfo.c main.c
OBJS = $(SRCS:.c=.o)
HDRS = mfs.h model.h constants.h MFSCommunication.h

BIN = mfscli

$(BIN): $(OBJS)
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS)

%.o: %.c $(HDRS)
	$(CC) $(CFLAGS) -c -o $@ $<

# Standalone render-engine validation harness (uses demo.c's own main()).
renderdemo: conn.o version.o util.o render.o demo.o
	$(CC) $(CFLAGS) $(LDFLAGS) -o renderdemo conn.o version.o util.o render.o demo.o

# Quick non-static build with the host gcc (handy for valgrind/asan).
debug: CC = gcc
debug: CFLAGS = -O0 -g -Wall -Wextra -std=c11 -fsanitize=address,undefined
debug: LDFLAGS = -fsanitize=address,undefined
debug: $(BIN)

# Regenerate the embedded GUI assets (assets.c) from the source files.
assets: gui_index.html jetbrainsmono-400.woff2 jetbrainsmono-700.woff2 gen_assets.py
	python3 gen_assets.py


clean:
	rm -f $(OBJS) $(BIN)

.PHONY: clean debug assets
