# -*- mode: makefile -*-

PROJECTNAME := client
GO_LDFLAGS_STATIC=-ldflags "-w $(CTIMEVAR) -extldflags -static"
GO := go

all: build fmt lint test

.PHONY: fmt
fmt: ## Verifies all files have been `gofmt`ed.
	@echo "+ $@"
	$(eval var = $(shell gofmt -s -l . | grep -v vendor | tee /dev/stderr))
	@if [ ! -z "${var}" ]; then exit 1; fi


.PHONY: build
build: ## Builds a static executable.
	@echo "+ $@"
	CGO_ENABLED=0 $(GO) build -mod=vendor \
	 -o $(PROJECTNAME) \
	 -tags "static_build netgo" \
	 -installsuffix netgo ${GO_LDFLAGS_STATIC} .;


.PHONY: test
test: ## Generates test certificates & run unit tests.
	go vet -mod=vendor
	go test -v -mod=vendor


.PHONY: lint
lint: ## Verifies `golint` passes.
	@echo "+ $@"
	$(eval var = $(shell golint ./... | grep -v vendor | tee /dev/stderr))
	@if [ ! -z "${var}" ]; then exit 1; fi

.PHONY: clean
clean:
	rm -f $(PROJECTNAME)
