NAS := luxick@192.168.3.3

COMPANION_WIN := companion/datascape-companion-windows-amd64.exe
COMPANION_LIN := companion/datascape-companion-linux-amd64
COMPANION_SRCS := $(wildcard cmd/companion/*.go) $(wildcard cmd/companion/*.html) go.mod go.sum

.PHONY: deploy companion companion-windows companion-linux companion-release

# Cross-compiled companion artifacts the wiki binary embeds. Both must exist
# before `go build .` so embed.FS picks them up.
companion-release: $(COMPANION_WIN) $(COMPANION_LIN)

$(COMPANION_WIN): $(COMPANION_SRCS)
	GOOS=windows GOARCH=amd64 go build -ldflags="-H windowsgui" -o $@ ./cmd/companion

$(COMPANION_LIN): $(COMPANION_SRCS)
	GOOS=linux GOARCH=amd64 go build -o $@ ./cmd/companion

companion-windows: $(COMPANION_WIN)
companion-linux: $(COMPANION_LIN)

# Local companion build for the host OS (handy for development).
companion:
	mkdir -p bin
	go build -o bin/ ./cmd/companion

deploy: companion-release
	GOOS=linux GOARCH=arm GOARM=7 go build -o datascape-arm .
	ssh $(NAS) 'kill $$(cat /share/homes/luxick/.local/bin/datascape.pid) 2>/dev/null; rm -f /share/homes/luxick/.local/bin/datascape.pid'
	scp datascape-arm $(NAS):/share/homes/luxick/.local/bin/datascape
	ssh $(NAS) /share/homes/luxick/.local/bin/datascape-start.sh
	rm datascape-arm
