-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
52 lines (44 loc) · 2.08 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
PWD = $(shell pwd -L)
GOCMD=go
GOTEST=$(GOCMD) test
ifeq ($(OS), Windows_NT)
SHELL := powershell.exe
.SHELLFLAGS := -NoProfile -Command
SHELL_VERSION = $(shell (Get-Host | Select-Object Version | Format-Table -HideTableHeaders | Out-String).Trim())
OS = $(shell "{0} {1}" -f "windows", (Get-ComputerInfo -Property OsVersion, OsArchitecture | Format-Table -HideTableHeaders | Out-String).Trim())
PACKAGE = $(shell (Get-Content go.mod -head 1).Split(" ")[1])
CHECK_DIR_CMD = if (!(Test-Path $@)) { $$e = [char]27; Write-Error "$$e[31mDirectory $@ doesn't exist$${e}[0m" }
HELP_CMD = Select-String "^[a-zA-Z_-]+:.*?\#\# .*$$" "./Makefile" | Foreach-Object { $$_data = $$_.matches -split ":.*?\#\# "; $$obj = New-Object PSCustomObject; Add-Member -InputObject $$obj -NotePropertyName ('Command') -NotePropertyValue $$_data[0]; Add-Member -InputObject $$obj -NotePropertyName ('Description') -NotePropertyValue $$_data[1]; $$obj } | Format-Table -HideTableHeaders @{Expression={ $$e = [char]27; "$$e[36m$$($$_.Command)$${e}[0m" }}, Description
else
SHELL := bash
SHELL_VERSION = $(shell echo $$BASH_VERSION)
UNAME := $(shell uname -s)
VERSION_AND_ARCH = $(shell uname -rm)
ifeq ($(UNAME),Darwin)
OS = macos ${VERSION_AND_ARCH}
else ifeq ($(UNAME),Linux)
OS = linux ${VERSION_AND_ARCH}
else
$(error OS not supported by this Makefile)
endif
PACKAGE = $(shell head -1 go.mod | awk '{print $$2}')
CHECK_DIR_CMD = test -d $@ || (echo "\033[31mDirectory $@ doesn't exist\033[0m" && false)
HELP_CMD = grep -E '^[a-zA-Z_-]+:.*?\#\# .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?\#\# "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
endif
.DEFAULT_GOAL := help
.PHONY: help
about: ## Display info related to the build
@echo "OS: ${OS}"
@echo "Shell: ${SHELL} ${SHELL_VERSION}"
@echo "Go version: $(shell go version)"
@echo "Go package: ${PACKAGE}"
help: ## Show this help
@${HELP_CMD}
tidy: ## Downloads go dependencies
@$(GOCMD) mod tidy
fmt: tidy ## Run go fmt
@$(GOCMD) fmt ./...
test: fmt clean-cache ## Launch tests
@$(GOTEST) -race ./...
clean-cache: ## Clean cache
@$(GOCMD) clean -testcache