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

all: $(PROGRAM)

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

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

$(PROGRAM): clean codeqa
	CGO_ENABLED=0 $(CC) $(BUILD) $(LDFLAGS)

clean:
	$(CC) clean -x

codeqa: generate gofmt misspell golint test

generate:
	$(CC) generate

gofmt:
	gofmt -w .

golint:
	$(GOPATH)/bin/golint .

misspell:
	# ignore misspellings from vendor/
	$(GOPATH)/bin/misspell -i functionallity,avaliable,HALP,halp,agains,becuase,Christiaan,compatiblity,conjuction,frequence,inital,inot,occurance,overriden,pervious,preceeded,preceeds,precendence,PROPOGATE,reamining,represenation,soley,substract,supression,whcih,preceed *

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

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