-
Notifications
You must be signed in to change notification settings - Fork 13
/
Makefile
110 lines (87 loc) · 2.93 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# SPDX-License-Identifier: ISC
# Copyright (c) 2019-2024 Bitmark Inc.
# Use of this source code is governed by an ISC
# license that can be found in the LICENSE file.
ARCH = $(shell /usr/bin/uname -m)
VERSION = $(shell \
changelog="debian/changelog" ; \
[ -f "$${changelog}" ] && version=$$(head -n 1 "$${changelog}" | sed -E 's/^[^(]*[(]([^)]+)-[[:digit:][:alpha:]]+[)].*$$/\1/') ; \
git_head="$$(git rev-list --max-count=1 HEAD)" ; \
git_tag="$$(git rev-list --max-count=1 "v$${version}" || true)" ; \
git_n="$$(git rev-list --count "v$${version}..HEAD" || echo 0)" ; \
git_hash_prefix="$${git_head#????????}" ; \
git_hash_prefix="$${git_head%$${git_hash_prefix}}" ; \
[ X"$${git_head}" != X"$${git_tag}" ] && version="$${version}+$${git_n}-$${git_hash_prefix}" ; \
printf '%s' "$${version}")
.PHONY: all
all: install
.PHONY: version
version:
printf 'version: %s\n' '${VERSION}'
# bitmarkd and command
.PHONY: install
install:
go install -v -ldflags="-w -s -X main.version=${VERSION}" -gcflags='-e' ./command/...
# local bitmarkd
.PHONY: build
build:
for p in ./command/* ; \
do \
base="$${p##*/}" ; \
printf '===> compiling: %-20s version: \033[1;34m%s\033[0m\n' "$${base}" "${VERSION}" ; \
go build -o "./bin/$${base}" -v -ldflags="-w -s -X main.version=${VERSION}" -gcflags='-e' "./command/$${base}" ; \
done
# to do a `go get -u` and not fail on private repos
# ensure that ${XDG_CONFIG_HOME}/git/config contains:
# [url "ssh://git@github.com/bitmark-inc/"]
# insteadof = https://github.com/bitmark-inc/
.PHONY: update-deps
update-deps:
go mod tidy
env GOPRIVATE='github.com/bitmark-inc/' go get -u ./...
go mod tidy
# TESTING
.PHONY: test
test:
go test -v ./...
.PHONY: vet
vet:
go mod tidy
@-[ X"$$(uname -s)" = X"FreeBSD" ] && set-sockio
go vet -v ./... 2>&1 | \
awk '/^#.*$$/{ printf "\033[31m%s\033[0m\n",$$0 } /^[^#]/{ print $$0 }'
.PHONY: clean
clean:
rm -rf bin
.PHONY: get-gocritic
get-gocritic:
go install -v github.com/go-critic/go-critic/cmd/gocritic@latest
CR_DISABLED = paramTypeCombine
CR_DISABLED += unnamedResult
CR_DISABLED += unlabelStmt
CR_DISABLED += commentFormatting
CR_DISABLED += commentedOutCode
CR_DISABLED += ifElseChain
CR_DISABLED += sloppyTestFuncName
CR_DISABLED += hugeParam
CR_DISABLED += redundantSprint
CR_DISABLED += commentedOutImport
SP = ${EMPTY} ${EMPTY}
CM = ${EMPTY},${EMPTY}
DIS = $(subst ${SP},${CM},${CR_DISABLED})
.PRONY: critic
critic:
gocritic check -enableAll -enable='#opinionated' -disable="${DIS}" ./...
# display top level targets
.PHONY: help
help:
@$(foreach m, ${MAKEFILE_LIST}, \
printf 'toplevel targets from: %s\n' '${m}' ; \
awk '/^[.]PHONY/{ print " " $$2 }' '${m}' | sort -u ; \
)
# Makefile debugging
# use like make print-VARIABLE_NAME
# note "print-" is always lowercase, VARIABLE_NAME is case sensitive
.PHONY: print-%
print-%:
@printf '%s: %s\n' "$(patsubst print-%,%,${@})" "${$(patsubst print-%,%,${@})}"