-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMakefile
240 lines (206 loc) · 6.9 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
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
233
234
235
236
237
238
239
240
#!/usr/bin/make -f
# Makefile for mod_prometheus_status.c
MAKE:=make
SHELL:=bash
APXS=./apxs.sh
WRAPPER_SOURCE=src/mod_prometheus_status.c src/mod_prometheus_status_format.c
WRAPPER_HEADER=src/mod_prometheus_status.h
GO_SRC_DIR=cmd/mod_prometheus_status
GO_SOURCES=\
$(GO_SRC_DIR)/dump.go\
$(GO_SRC_DIR)/logger.go\
$(GO_SRC_DIR)/prometheus.go\
$(GO_SRC_DIR)/module.go
DISTFILES=\
$(APXS) \
$(GO_SOURCES) \
$(WRAPPER_SOURCE) \
$(WRAPPER_HEADER) \
buildtools/ \
example_apache.conf \
go.* \
vendor \
Apache-Dashboard.json \
LICENSE \
README.md \
Changelog \
Makefile
GOVERSION:=$(shell \
go version | \
awk -F'go| ' '{ split($$5, a, /\./); printf ("%04d%04d", a[1], a[2]); exit; }' \
)
MINGOVERSION:=00010022
MINGOVERSIONSTR:=1.22
BUILDHASH:=$(shell git rev-parse --short HEAD)
BUILDDATE:=$(shell LC_TIME=C date +%Y-%d-%m_%T)
# see https://github.com/go-modules-by-example/index/blob/master/010_tools/README.md
# and https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module
TOOLSFOLDER=$(shell pwd)/tools
export GOBIN := $(TOOLSFOLDER)
export PATH := $(GOBIN):$(PATH)
GO=go
VERSION=$(shell grep "define VERSION" $(WRAPPER_HEADER) | cut -d " " -f 3 | tr -d '"')
NAME=$(shell grep "define NAME" $(WRAPPER_HEADER) | cut -d " " -f 3 | tr -d '"')
RELEASENAME=$(NAME)-$(VERSION)-$(shell uname | tr 'A-Z' 'a-z')-$(shell uname -m)
BUILD_TAG=$(shell git rev-parse --short HEAD >/dev/null 2>&1 >/dev/null 2>&1)
ifeq ($(BUILD_TAG),)
BUILD_TAG=$(VERSION)
endif
.PHONY: vendor
all: build
CMDS = $(shell cd ./cmd && ls -1)
tools: | versioncheck
set -e; for DEP in $(shell grep "_ " buildtools/tools.go | awk '{ print $$2 }' | grep -v go-spew); do \
( cd buildtools && $(GO) install $$DEP@latest ) ; \
done
set -e; for DEP in $(shell grep "_ " buildtools/tools.go | awk '{ print $$2 }' | grep go-spew); do \
( cd buildtools && $(GO) install $$DEP ) ; \
done
( cd buildtools && $(GO) mod tidy )
updatedeps: versioncheck
$(MAKE) clean
$(MAKE) tools
$(GO) mod download
set -e; for dir in $(shell ls -d1 cmd/*); do \
( cd ./$$dir && $(GO) mod download ); \
( cd ./$$dir && GOPROXY=direct $(GO) get -u ); \
( cd ./$$dir && GOPROXY=direct $(GO) get -t -u ); \
done
$(GO) mod download
$(MAKE) cleandeps
cleandeps:
set -e; for dir in $(shell ls -d1 cmd/*); do \
( cd ./$$dir && $(GO) mod tidy ); \
done
$(GO) mod tidy
( cd buildtools && $(GO) mod tidy )
vendor: go.work
$(GO) mod download
$(GO) mod tidy
GOWORK=off $(GO) mod vendor
go.work:
echo "go $(MINGOVERSIONSTR)" > go.work
$(GO) work use . cmd/* buildtools/.
build: mod_prometheus_status.so
install: mod_prometheus_status.so
@echo "make install is not supported, simply copy mod_prometheus_status.so to your apache folder"
@echo "and add a LoadModule configuration. See the README for an example configuration."
clean:
rm -rf *.so src/.libs/ src/*.la src/*.lo src/*.slo mod_prometheus_status_go.h
-$(MAKE) -C t clean
test: citest releasetest
$(MAKE) -C t test
testbox_centos8:
$(MAKE) -C t testbox_centos8
update_readme_available_metrics: testbox_centos8
echo '```' > metrics.txt
curl -qs http://localhost:3000/metrics >/dev/null 2>&1 # warm up metrics
curl -qs http://localhost:3000/metrics | grep ^# | grep apache | sort -k 3 >> metrics.txt
echo '```' >> metrics.txt
sed -e '/^\ *\# \(HELP\|TYPE\)/d' -i README.md
sed -zE 's/```\n```/###METRICS###/' -i README.md
sed -e '/###METRICS###/r metrics.txt' -i README.md
sed -e '/###METRICS###/d' -i README.md
rm metrics.txt
dist:
rm -f $(NAME)-$(VERSION).tar.gz
mv buildtools/tools.go buildtools/tools.go.off
go mod vendor
mv buildtools/tools.go.off buildtools/tools.go
mv cmd/mod_prometheus_status/dump.go .
echo "package main" > cmd/mod_prometheus_status/dump.go
tar --transform 's,^,./$(NAME)-$(VERSION)/,g' -cf $(NAME)-$(VERSION).tar $(DISTFILES)
gzip -9 $(NAME)-$(VERSION).tar
mv dump.go cmd/mod_prometheus_status/dump.go
go mod vendor
releasetarball: clean build
rm -f $(RELEASENAME).tar.gz
tar --transform 's,^,./$(RELEASENAME)/,g' -cf $(RELEASENAME).tar *.so example_apache.conf README.md LICENSE Changelog
gzip -9 $(RELEASENAME).tar
release: releasetest
@echo "***************************************"
@echo "release tarballs created:"
@echo " - $(RELEASENAME).tar.gz"
@echo " - $(NAME)-$(VERSION).tar.gz"
@echo "***************************************"
releasetest: releasetarball dist
tar zxf $(NAME)-$(VERSION).tar.gz
cd $(NAME)-$(VERSION) && make
rm -rf $(NAME)-$(VERSION)
version:
TIMESTAMP="$(shell LC_TIME=C date)" && \
NEWVERSION=$$(dialog --stdout --inputbox "New Version:" 0 0 "v$(VERSION)") && \
NEWVERSION=$$(echo $$NEWVERSION | sed "s/^v//g"); \
if [ "v$(VERSION)" = "v$$NEWVERSION" -o "x$$NEWVERSION" = "x" ]; then echo "no changes"; exit 1; fi; \
sed -i -e 's/define VERSION ".*"/define VERSION "'$$NEWVERSION'"/g' $(WRAPPER_HEADER); \
sed -i -e 's/next:/'"$$NEWVERSION"' '"$$TIMESTAMP"'/g' README.md;
versioncheck:
@[ $$( printf '%s\n' $(GOVERSION) $(MINGOVERSION) | sort | head -n 1 ) = $(MINGOVERSION) ] || { \
echo "**** ERROR:"; \
echo "**** build requires at least golang version $(MINGOVERSIONSTR) or higher"; \
echo "**** this is: $$(go version) from $$(type go)"; \
exit 1; \
}
dump:
if [ $(shell grep -rc Dump $(GO_SRC_DIR)/*.go | grep -v :0 | grep -v dump.go | wc -l) -ne 0 ]; then \
sed -i.bak 's/\/\/ +build.*/\/\/ build with debug functions/' $(GO_SRC_DIR)/dump.go; \
else \
sed -i.bak 's/\/\/ build.*/\/\/ +build ignore/' $(GO_SRC_DIR)/dump.go; \
fi
rm -f $(GO_SRC_DIR)/dump.go.bak
GOVET=$(GO) vet -all
SRCFOLDER=./cmd/. ./buildtools/.
fmt: tools
set -e; for CMD in $(CMDS); do \
$(GOVET) ./cmd/$$CMD; \
done
gofmt -w -s $(SRCFOLDER)
./tools/gofumpt -w $(SRCFOLDER)
./tools/gci write --skip-generated $(SRCFOLDER)
./tools/goimports -w $(SRCFOLDER)
citest:
#
# Checking gofmt errors
#
if [ $$(cd $(GO_SRC_DIR) && gofmt -s -l . | wc -l) -gt 0 ]; then \
echo "found format errors in these files:"; \
cd $(GO_SRC_DIR) && gofmt -s -l .; \
exit 1; \
fi
#
# Checking TODO items
#
if grep -rn TODO: cmd/ src/; then exit 1; fi
#
# Checking remaining debug calls
#
if grep -rn Dump cmd/*.go | grep -v dump.go; then exit 1; fi
#
# Run other subtests
#
$(MAKE) golangci
$(MAKE) fmt
#
# Normal test cases
#
cd $(GO_SRC_DIR) && go test -v
#
# Benchmark tests
#
cd $(GO_SRC_DIR) && go test -v -bench=B\* -run=^$$ . -benchmem
#
# All CI tests successfull
#
go mod tidy
golangci: tools
#
# golangci combines a few static code analyzer
# See https://github.com/golangci/golangci-lint
#
golangci-lint run $(GO_SRC_DIR)/...
mod_prometheus_status.so: mod_prometheus_status_go.so $(WRAPPER_SOURCE)
$(APXS) -c -n $@ -I. $(LIBS) $(WRAPPER_SOURCE)
install src/.libs/mod_prometheus_status.so mod_prometheus_status.so
mod_prometheus_status_go.so: $(GO_SOURCES) dump
go build -buildmode=c-shared -x -ldflags "-s -w -X main.Build=$(BUILD_TAG)" -o mod_prometheus_status_go.so $(GO_SOURCES)
chmod 755 mod_prometheus_status_go.so