.PHONY: all build clean daemon client mcp install mcp-test mcp-tools

all: build

build: daemon client mcp

daemon:
	go build -o cremotedaemon ./daemon/cmd/cremotedaemon

client:
	go build -o cremote .

mcp:
	cd mcp && go build -o cremote-mcp .

clean:
	rm -f cremote cremotedaemon mcp/cremote-mcp

install: build
	@if [ -n "$(GOPATH)" ] && [ -d "$(GOPATH)/bin" ]; then \
		echo "Installing to $(GOPATH)/bin/"; \
		cp cremote $(GOPATH)/bin/; \
		cp cremotedaemon $(GOPATH)/bin/; \
		cp mcp/cremote-mcp $(GOPATH)/bin/; \
	else \
		echo "GOPATH not set or $(GOPATH)/bin doesn't exist, installing to ~/.local/bin/"; \
		mkdir -p ~/.local/bin; \
		cp cremote ~/.local/bin/; \
		cp cremotedaemon ~/.local/bin/; \
		cp mcp/cremote-mcp ~/.local/bin/; \
	fi

# MCP-related targets
mcp-test: mcp
	@echo "Testing standalone MCP server functionality..."
	@echo '{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2024-11-05", "capabilities": {}, "clientInfo": {"name": "test", "version": "1.0.0"}}}' | ./mcp/cremote-mcp

mcp-tools: mcp
	@echo "Listing available MCP tools from standalone server..."
	@echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {}}' | ./mcp/cremote-mcp | jq -r '.result.tools[]? | "\(.name): \(.description)"' 2>/dev/null || echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {}}' | ./mcp/cremote-mcp
