.PHONY: all frontend backend backend-epics test test-epics clean

all: frontend backend

frontend:
	cd web && npm ci && npm run build

backend:
	go build -ldflags="-s -w" -o dist/uopi ./cmd/uopi

# Build backend with EPICS Channel Access support.
# Requires EPICS Base to be installed and the following environment variables:
#   EPICS_BASE=/path/to/epics/base
#   CGO_CFLAGS="-I${EPICS_BASE}/include -I${EPICS_BASE}/include/os/Linux"
#   CGO_LDFLAGS="-L${EPICS_BASE}/lib/linux-x86_64 -lca -lCom"
backend-epics:
	CGO_ENABLED=1 go build -tags epics -ldflags="-s -w" -o dist/uopi ./cmd/uopi

# Build backend without -s -w for debugging
backend-debug:
	go build -o dist/uopi ./cmd/uopi

test:
	go test ./...
	cd web && npm run check

# Run EPICS integration tests (requires EPICS Base; see backend-epics target).
test-epics:
	go test -tags epics ./internal/datasource/epics/...

lint:
	go vet ./...
	cd web && npm run lint

clean:
	rm -rf dist/ web/dist/

# Run dev servers (requires two terminals or a process manager)
run-backend:
	go run ./cmd/uopi

run-frontend:
	cd web && npm run dev
