-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
86 lines (71 loc) · 2.19 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
WHOAMI ?= $(shell whoami)
CWD := $(shell pwd)
NAME := pls
BIN_NAME := pls
INSTALL_LOCATION := /usr/local/bin
COMMIT := $(shell git rev-parse --short HEAD)
TODAY = $(shell date +%Y-%m-%d)
VERSION := $(COMMIT)-$(TODAY)
BUILD_OUTPUT_DIR := $(CWD)/build
BINARY_LOCATION := $(BUILD_OUTPUT_DIR)/$(BIN_NAME)
MODULE := $(shell go list -m)
CMD_MODULE := $(MODULE)/cmd/$(BIN_NAME)
${BUILD_OUTPUT_DIR}:
@mkdir -p $(BUILD_OUTPUT_DIR)
UNAME_S := $(shell uname -s)
ifeq ($(PLATFORM),)
ifeq ($(UNAME_S),Darwin)
PLATFORM ?= darwin
endif
ifeq ($(UNAME_S),Linux)
PLATFORM ?= linux
endif
endif
GOOS = $(PLATFORM)
GOARCH ?= amd64
GO := $(shell command -v go 2>/dev/null)
GO_LINKER_FLAGS = -X $(CMD_MODULE).Builder=$(WHOAMI) -X $(CMD_MODULE).Version=$(VERSION) -X $(CMD_MODULE).Commit=$(COMMIT) -X $(CMD_MODULE).Date=$(TODAY)
GO_BUILD_FLAGS = -trimpath -tags 'osusergo netgo' -ldflags "$(GO_LINKER_FLAGS)" -o $(BINARY_LOCATION)
.PHONY: build
build: ${BUILD_OUTPUT_DIR} ## build the pls binary
@echo "compiling ${NAME}..."
@export GOOS=$(GOOS) GOARCH=$(GOARCH) && \
export CGO_ENABLED=0 && \
$(GO) build $(GO_BUILD_FLAGS)
@echo "${NAME} bin compiled!"
.PHONY: install
install: build ## install the pls binary to /usr/local/bin
@echo "installing pls to ${INSTALL_LOCATION}"
@cp ${BINARY_LOCATION} ${INSTALL_LOCATION}
@chmod 755 ${INSTALL_LOCATION}/${BIN_NAME}
@echo "installation complete"
.PHONY: tidy
tidy:
@go mod tidy
.PHONY: lint-fix
lint-fix: ## run linter and fix issues if possible
@echo "running golangci-lint with --fix enabled..."
@golangci-lint run --fix
.PHONY: lint
lint: ## run golangci-lint checks
@echo "running golangci-lint"
@golangci-lint run
.PHONY: test
test: lint ## run linter and unit tests
@echo "running tests..."
@$(GO) test ./...
.PHONY: clean
clean: ## delete the build binary
@rm -rf ${BUILD_OUTPUT_DIR}
@echo "removed ${BUILD_OUTPUT_DIR}..."
.PHONY: pages
pages: ## run pages site locally
@cd docs && \
bundle && \
bundle install && \
bundle exec jekyll serve && \
cd ..
.PHONY: help
help: ## lists some available makefile commands
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.DEFAULT_GOAL := help