aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 278ed8d2aeb09186362aa274ed1a3d288c73aad5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
CASHIER_CMD := ./cmd/cashier
CASHIERD_CMD := ./cmd/cashierd
SRC_FILES = $(shell find * -type f -name '*.go' -not -path 'vendor/*' -not -name 'a_*-packr.go')
VERSION_PKG := github.com/nsheridan/cashier/lib.Version
VERSION := $(shell git describe --tags --always --dirty)

STATIC_LINKER_FLAGS ?= -linkmode external -extldflags -static -w
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
CGO_ENABLED ?= $(shell go env CGO_ENABLED)

all: test build

test:
	go test -coverprofile=coverage.txt -covermode=count ./...
	go install -race $(CASHIER_CMD) $(CASHIERD_CMD)

lint: dep
	go vet ./...
	go list ./... |xargs -L1 golint -set_exit_status
	gofmt -s -d -l -e $(SRC_FILES)
	$(MAKE) generate
	@[ -z "`git status --porcelain`" ] || (echo "unexpected files: `git status --porcelain`" && exit 1)

build: cashier cashierd
install: install-cashierd install-cashier
cashier: cashier-bin
cashierd: cashierd-bin

generate:
	go generate ./...

%-bin:
	CGO_ENABLED=$(CGO_ENABLED) GOARCH=$(GOARCH) GOOS=$(GOOS) go build -ldflags="-X $(VERSION_PKG)=$(VERSION) $(STATIC_LINKER_FLAGS)" ./cmd/$*
install-%: generate
	CGO_ENABLED=$(CGO_ENABLED) GOARCH=$(GOARCH) GOOS=$(GOOS) go install -ldflags="-X $(VERSION_PKG)=$(VERSION) $(STATIC_LINKER_FLAGS)" ./cmd/$*

docker-image:
	docker build -f Dockerfile .

clean:
	rm -f cashier cashierd

# usage: make migration name=whatever
migration:
	go run ./generate/migration/migration.go $(name)

dep:
	go get -u golang.org/x/lint/golint

version:
	@echo $(VERSION)

.PHONY: all build dep generate test cashier cashierd clean migration