-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
48 lines (37 loc) · 1.61 KB
/
Makefile
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
.PHONY : proto test build clean autocomplete-bash
OUTPUT_DIR=${PWD}/dist
BINARY_DIR=${OUTPUT_DIR}/bin
BINARY_NAME=keyquarry
BINARY_PATH=${BINARY_DIR}/${BINARY_NAME}
AUTOCOMPLETE_PATH_BASH=${OUTPUT_DIR}/autocomplete/bash/keyquarry
BUILD_TIME=$(shell date -u --iso-8601=seconds)
BUILD_USER=$(shell whoami)
COMMIT := $(if $(and $(wildcard .git),$(shell which git)),$(shell git rev-parse HEAD), "unknown")
VERSION ?= unknown
CGO_ENABLED ?= 0
GOOS ?= linux
GOARCH ?= amd64
GO_BUILD_LDFLAGS=-ldflags "-X 'github.com/arcward/keyquarry/build.Version=${VERSION}' -X 'github.com/arcward/keyquarry/build.Time=${BUILD_TIME}' -X 'github.com/arcward/keyquarry/build.User=${BUILD_USER}' -X 'github.com/arcward/keyquarry/build.Commit=${COMMIT}'"
GO_BUILD_FLAGS=${GO_BUILD_LDFLAGS} -o ${BINARY_PATH}
.PHONY: all
all: test proto build autocomplete-bash
.PHONY: proto
proto:
@protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative api/keyquarry.proto
@protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative api/admin.proto
.PHONY: test
test:
go test -timeout 30s -v ./...
.PHONY: build
build: proto
@echo "Building..."
GOOS=${GOOS} GOARCH=${GOARCH} CGO_ENABLED=${CGO_ENABLED} go build ${GO_BUILD_FLAGS}
@echo "built ${BINARY_PATH} (commit: ${COMMIT}) (time: ${BUILD_TIME}) (user: ${BUILD_USER}) (GOOS: ${GOOS} GOARCH: ${GOARCH} CGO_ENABLED: ${CGO_ENABLED})"
.PHONY: clean
clean:
-go clean
-rm -rf ${OUTPUT_DIR}
.PHONY: autocomplete-bash
autocomplete-bash:
@mkdir -p ${OUTPUT_DIR}/autocomplete/bash
@${BINARY_PATH} completion bash > ${AUTOCOMPLETE_PATH_BASH}