service=bar
os=linux
arch=amd64
dir_guard=@mkdir -p $(@D)
party_host=xuj.local
exec=/usr/local/bin/$(service)

all: $(service)

$(service): $(wildcard **.go)
	go build .

run: $(service)
	./$(service)

put: build/$(service).$(os)_$(arch)
	# Move old binary out of the way and ask old instance to quit
	ssh $(party_host) [ -f $(exec) ] "&&" mv $(exec) $(exec).retired "||" /bin/true
	scp $^ $(party_host):$(exec)
	osc-utility message --host $(party_host) --port 9137 --address /bar/halt

build/$(service).%: $(wildcard **.go)
	$(dir_guard)
	GOOS=$(word 1, $(subst _, ,$*)) GOARCH=$(word 2, $(subst _, ,$*)) go build -o $@ .

build/@osc.%: $(wildcard at-osc/**.go)
	$(dir_guard)
	GOOS=$(word 1, $(subst _, ,$*)) GOARCH=$(word 2, $(subst _, ,$*)) go build -o $@ ./at-osc