svn_revision = $(shell git describe --always --dirty --tags --long)

LDFLAGS = "-X main.version=$(svn_revision)"

build:
	@echo "Building the website..."
	rm -rf bin
	mkdir bin
	go build -ldflags=$(LDFLAGS) -o bin/alfheim-website ./cmd/web
	cp -r ui bin
	cp Caddyfile bin
	mkdir bin/linux_amd64
	GOOS=linux GOARCH=amd64 go build -ldflags=$(LDFLAGS) -o bin/linux_amd64/alfheim-website ./cmd/web
	cp -r ui bin/linux_amd64
	cp Caddyfile bin/linux_amd64

.PHONY: run
run:
	@echo "Running the website..."
	go run ./cmd/web/*.go

.PHONY: production/deploy
production/deploy:
	rsync -rP --delete bin/linux_amd64 alfheim@alfheimgame.com:/home/alfheim
	rsync -P remote/production/alfheim-website.service alfheim@alfheimgame.com:/home/alfheim
	ssh -t root@alfheimgame.com 'systemctl daemon-reload && systemctl stop alfheim-website.service && mv /home/alfheim/alfheim-website.service /etc/systemd/system && systemctl enable alfheim-website && systemctl restart alfheim-website'

.PHONY: production/connect
production/connect:
	ssh alfheim@losandesgames.com
