.PHONY: all

BIN_NAME := api
BUILD_DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")

ifneq ($(DRONE_TAG),)
	VERSION ?= $(subst v,,$(DRONE_TAG))
else
	VERSION ?= $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')
endif

LDFLAGS ?= -X go-api/pkg/version.Version=$(VERSION) -X go-api/pkg/version.BuildDate=$(BUILD_DATE)

all: clean generate-spec bundle-static build
dev: clean generate-spec bundle-static

build:
	go build -o $(BIN_NAME) -ldflags "-s -w $(LDFLAGS)" .

clean:
	rm -rf $(BIN_NAME)
	go clean

generate-spec:
	swagger generate spec -m --compact -o spec.json

bundle-static:
	go-bindata -fs -pkg static -ignore .git -o static/bundle.go public/ schema/ spec.json

test:
	go test ./...
