CC=go
BUILD=build -v
VERSION=$(shell cat VERSION)
GCFLAGS=-gcflags '-e'
LDFLAGS=-ldflags '-X main.version=$(VERSION) -s -w'
PROGRAM=docstore
ENV=CGO_ENABLED=0

all: $(PROGRAM)

setup:
	$(CC) get github.com/client9/misspell

vendor: clean codeqa
	$(ENV) $(CC) $(BUILD) -mod=vendor $(LDFLAGS)

$(PROGRAM): clean codeqa
	$(ENV) $(CC) $(BUILD) $(LDFLAGS)

clean:
	$(CC) clean -x

codeqa: generate gofmt misspell golint test

generate:
	$(CC) generate

gofmt:
	gofmt -w pkg/ main.go

golint:
	$(GOPATH)/bin/golint .

misspell:
	$(GOPATH)/bin/misspell pkg/* templates/* main.go Makefile README.md sri.sh templates.sh

test:
ifeq ($(shell go env GOARCH), $(shell go env GOHOSTARCH))
ifeq ($(shell go env GOOS), $(shell go env GOHOSTOS))
	$(CC) test ./...
else
	$(info skipping tests of other platforms)
endif
else
	$(info skipping tests of other platforms)
endif

.PHONY: setup vendor build clean codeqa generate gofmt golint misspell test
