.PHONY: build build-server build-agent build-all clean templ help

# Default target
help:
	@echo "Nerd Monitor - Build Commands"
	@echo ""
	@echo "  make build          - Build server and agent for current OS"
	@echo "  make build-server   - Build server executable"
	@echo "  make build-agent    - Build agent executable"
	@echo "  make build-all      - Build for all platforms (Linux, macOS, Windows)"
	@echo "  make templ          - Generate code from Templ templates"
	@echo "  make clean          - Remove build artifacts"
	@echo ""

build: templ build-server build-agent

templ:
	@echo "Generating Templ templates..."
	@go run github.com/a-h/templ/cmd/templ@latest generate

build-server: templ
	@echo "Building server for $(GOOS)/$(GOARCH)..."
	@mkdir -p bin
	go build -o bin/nerd-monitor-server ./cmd/server

build-agent:
	@echo "Building agent for $(GOOS)/$(GOARCH)..."
	@mkdir -p bin
	go build -o bin/nerd-monitor-agent ./cmd/agent

build-all: templ
	@echo "Building for all platforms..."
	@mkdir -p bin
	@echo "  Linux AMD64..."
	@GOOS=linux GOARCH=amd64 go build -o bin/nerd-monitor-server-linux-amd64 ./cmd/server
	@GOOS=linux GOARCH=amd64 go build -o bin/nerd-monitor-agent-linux-amd64 ./cmd/agent
	@echo "  Linux ARM64..."
	@GOOS=linux GOARCH=arm64 go build -o bin/nerd-monitor-server-linux-arm64 ./cmd/server
	@GOOS=linux GOARCH=arm64 go build -o bin/nerd-monitor-agent-linux-arm64 ./cmd/agent
	@echo "  macOS AMD64..."
	@GOOS=darwin GOARCH=amd64 go build -o bin/nerd-monitor-server-darwin-amd64 ./cmd/server
	@GOOS=darwin GOARCH=amd64 go build -o bin/nerd-monitor-agent-darwin-amd64 ./cmd/agent
	@echo "  macOS ARM64..."
	@GOOS=darwin GOARCH=arm64 go build -o bin/nerd-monitor-server-darwin-arm64 ./cmd/server
	@GOOS=darwin GOARCH=arm64 go build -o bin/nerd-monitor-agent-darwin-arm64 ./cmd/agent
	@echo "  Windows AMD64..."
	@GOOS=windows GOARCH=amd64 go build -o bin/nerd-monitor-server-windows-amd64.exe ./cmd/server
	@GOOS=windows GOARCH=amd64 go build -o bin/nerd-monitor-agent-windows-amd64.exe ./cmd/agent
	@echo "Build complete!"
	@ls -lh bin/

clean:
	@echo "Cleaning build artifacts..."
	@rm -rf bin/
	@echo "Clean complete!"
