This repository has been archived by the owner on Aug 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGolang.def.mk
232 lines (191 loc) · 7.61 KB
/
Golang.def.mk
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!/usr/bin/make --no-print-directory --jobs=1 --environment-overrides -f
# Copyright (c) 2023 The Go-Curses Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
MAKEFILE_KEYS += GOLANG_DEF
GOLANG_DEF_MK_FILE := Golang.def.mk
GOLANG_DEF_MK_VERSION := v0.2.0
GOLANG_DEF_MK_DESCRIPTION := make target definitions
.PHONY: help
.PHONY: clean distclean realclean
.PHONY: local unlocal deps tidy fmt be-update generate
.PHONY: debug build build-all build-amd64 build-arm64
.PHONY: release release-all release-amd64 release-arm64
.PHONY: install install-autocomplete
.PHONY: test coverage reportcard
SRC_CMD_PATH ?= .
SRC_AUTOCOMPLETE_FILE ?= ./bash_autocomplete
CUSTOM_HELP_KEYS ?=
INCLUDE_DEFAULT_AUTOCOMPLETE_FILE ?= true
ifeq (${INCLUDE_DEFAULT_AUTOCOMPLETE_FILE},true)
AUTOCOMPLETE_FILES += ${INSTALL_AUTOCOMPLETE_PATH}/${BIN_NAME}
endif
help:
@echo "usage: make [target]"
@echo
@echo "golang qa targets:"
@echo " test - perform all available tests"
@echo " coverage - generate coverage reports"
@echo " goconvey - start goconvey http://${GOCONVEY_HOST}:${GOCONVEY_PORT}"
@echo " reportcard - run sanity checks"
@echo
@echo "cleanup targets:"
@echo " clean - removes CLEAN_FILES (${CLEAN_FILES})"
@echo " distclean - clean and DISTCLEAN_FILES (${DISTCLEAN_FILES})"
@echo " realclean - distclean REALCLEAN_FILES (${REALCLEAN_FILES})"
@echo
@echo "build targets:"
@echo " debug - build debug ${BUILD_NAME}"
@echo " build - build clean ${BUILD_NAME}"
@echo " release - build clean and compress ${BUILD_NAME}"
@echo
@echo "cross-build targets:"
@echo " build-all - both build-arm64 and build-amd64"
@echo " build-arm64 - build clean ${BIN_NAME}.${BUILD_OS}.arm64"
@echo " build-amd64 - build clean ${BIN_NAME}.${BUILD_OS}.amd64"
@echo " release-all - both release-arm64 and release-amd64"
@echo " release-arm64 - build clean and compress ${BIN_NAME}.${BUILD_OS}.arm64"
@echo " release-amd64 - build clean and compress ${BIN_NAME}.${BUILD_OS}.amd64"
@echo
@echo "install targets:"
@echo " install - installs ${BUILD_NAME} to ${DESTDIR}${prefix}/bin/${BIN_NAME}"
@echo " install-arm64 - installs ${BIN_NAME}.${BUILD_OS}.arm64 to ${DESTDIR}${prefix}/bin/${BIN_NAME}"
@echo " install-amd64 - installs ${BIN_NAME}.${BUILD_OS}.amd64 to ${DESTDIR}${prefix}/bin/${BIN_NAME}"
ifneq (${AUTOCOMPLETE_FILES},)
@echo " install-autocomplete"
@echo " - installs ${SRC_AUTOCOMPLETE_FILE} to:"
@$(foreach dst,${AUTOCOMPLETE_FILES},echo " $(dst)";)
endif
ifdef help_custom_targets
@echo
@echo "custom targets:"
$(call help_custom_targets)
endif
@$(if ${CUSTOM_HELP_SECTIONS},$(foreach section,${CUSTOM_HELP_SECTIONS},\
echo;\
echo "$($(section)_NAME) targets:" \
$(foreach key,$($(section)_KEYS),; echo " $($(section)_$(key)_TARGET) - $($(section)_$(key)_USAGE)")\
))
@echo
@echo "go helpers:"
@echo " deps - install dependencies"
@echo " fmt - run gofmt and goimports"
@echo " tidy - run go mod tidy"
@echo " local - add go.mod local GOPKG_KEYS replacements"
@echo " unlocal - remove go.mod local GOPKG_KEYS replacements"
@echo " generate - run go generate ./..."
@echo " be-update - get latest GOPKG_KEYS dependencies"
@echo
@echo "build system details:"
@echo
@printf " %-15s %-40s %s\n" GOPKG_KEYS GO_PACKAGE LOCAL_PATH
@printf " %-15s %-40s %s\n" ---------- ---------- ----------
@$(foreach key,${GOPKG_KEYS},$(shell \
echo "printf \" %-15s %-40s %s\\n\" \"$(key)\" \"$($(key)_GO_PACKAGE)\" \"$($(key)_LOCAL_PATH)\";" \
))
@echo
@printf " %-20s %-10s %s\n" MAKEFILE VERSION DESCRIPTION
@printf " %-20s %-10s %s\n" -------- ------- -----------
@$(foreach key,${MAKEFILE_KEYS},$(shell \
echo "printf \" %-20s %-10s %-10s\\n\" \"$($(key)_MK_FILE)\" \"$($(key)_MK_VERSION)\" \"$($(key)_MK_DESCRIPTION)\";" \
))
clean:
@$(call __clean,${CLEAN_FILES})
distclean: clean
@$(call __clean,${DISTCLEAN_FILES})
realclean: distclean
@$(call __clean,${REALCLEAN_FILES})
debug: BUILD_VERSION=$(call __tag_ver)
debug: BUILD_RELEASE=$(call __rel_ver)
debug: TRIM_PATHS=$(call __go_trim_path)
debug: BUILD_TAGS += ${DEBUG_BUILD_TAGS}
debug: _BUILD_TAGS = $(call __build_tags)
debug: __golang
@$(call __go_build_debug,"${BUILD_NAME}",${BUILD_OS},${BUILD_ARCH},${SRC_CMD_PATH})
@${SHASUM_CMD} "${BUILD_NAME}"
build: BUILD_VERSION=$(call __tag_ver)
build: BUILD_RELEASE=$(call __rel_ver)
build: TRIM_PATHS=$(call __go_trim_path)
build: __golang
@$(call __go_build_release,"${BUILD_NAME}",${BUILD_OS},${BUILD_ARCH},${SRC_CMD_PATH})
@${SHASUM_CMD} "${BUILD_NAME}"
build-amd64: BUILD_VERSION=$(call __tag_ver)
build-amd64: BUILD_RELEASE=$(call __rel_ver)
build-amd64: TRIM_PATHS=$(call __go_trim_path)
build-amd64: __golang
@$(call __go_build_release,"${BIN_NAME}.${BUILD_OS}.amd64",${BUILD_OS},amd64,${SRC_CMD_PATH})
@${SHASUM_CMD} "${BIN_NAME}.${BUILD_OS}.amd64"
build-arm64: BUILD_VERSION=$(call __tag_ver)
build-arm64: BUILD_RELEASE=$(call __rel_ver)
build-arm64: TRIM_PATHS=$(call __go_trim_path)
build-arm64: __golang
@$(call __go_build_release,"${BIN_NAME}.${BUILD_OS}.arm64",${BUILD_OS},arm64,${SRC_CMD_PATH})
@${SHASUM_CMD} "${BIN_NAME}.${BUILD_OS}.arm64"
build-all: build-amd64 build-arm64
release: build
@$(call __upx_build,"${BUILD_NAME}")
release-arm64: build-arm64
@$(call __upx_build,"${BIN_NAME}.${BUILD_OS}.arm64")
release-amd64: build-amd64
@$(call __upx_build,"${BIN_NAME}.${BUILD_OS}.amd64")
release-all: release-amd64 release-arm64
install:
@if [ -f "${BUILD_NAME}" ]; then \
echo "# ${BUILD_NAME} present"; \
$(call __install_exe,"${BUILD_NAME}","${INSTALL_BIN_PATH}/${BIN_NAME}"); \
elif [ -f "${BIN_NAME}.${BUILD_OS}.${BUILD_ARCH}" ]; then \
echo "# ${BIN_NAME}.${BUILD_OS}.${BUILD_ARCH} present"; \
$(call __install_exe,"${BIN_NAME}.${BUILD_OS}.${BUILD_ARCH}","${INSTALL_BIN_PATH}/${BIN_NAME}"); \
else \
echo "error: missing ${BUILD_NAME} binary" 1>&2; \
false; \
fi
install-arm64:
@if [ -f "${BIN_NAME}.${BUILD_OS}.arm64" ]; then \
echo "# ${BIN_NAME}.${BUILD_OS}.arm64 present"; \
$(call __install_exe,"${BIN_NAME}.${BUILD_OS}.arm64","${INSTALL_BIN_PATH}/${BIN_NAME}"); \
else \
echo "error: missing ${BIN_NAME}.${BUILD_OS}.arm64 binary" 1>&2; \
false; \
fi
install-amd64:
@if [ -f "${BIN_NAME}.${BUILD_OS}.amd64" ]; then \
echo "# ${BIN_NAME}.${BUILD_OS}.amd64 present"; \
$(call __install_exe,"${BIN_NAME}.${BUILD_OS}.amd64","${INSTALL_BIN_PATH}/${BIN_NAME}"); \
else \
echo "error: missing ${BIN_NAME}.${BUILD_OS}.amd64 binary" 1>&2; \
false; \
fi
install-autocomplete:
@if [ ! -f "${SRC_AUTOCOMPLETE_FILE}" ]; then \
echo "error: SRC_AUTOCOMPLETE_FILE=${SRC_AUTOCOMPLETE_FILE} not found"; \
false; \
elif [ -z "${AUTOCOMPLETE_FILES}" ]; then \
echo "error: no AUTOCOMPLETE_FILES to install"; \
false; \
fi
@for DST in ${AUTOCOMPLETE_FILES}; do \
echo "# installing ${SRC_AUTOCOMPLETE_FILE} to: $${DST}"; \
$(call __install_exe,${SRC_AUTOCOMPLETE_FILE},$${DST}); \
done
deps: __deps
tidy: __tidy
be-update: __be_update
local: __local
unlocal: __unlocal
fmt: __fmt
reportcard: __reportcard
test: __test
coverage: __coverage
goconvey: __goconvey
generate: __generate