-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile.in
263 lines (203 loc) · 7.11 KB
/
Makefile.in
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
PACKAGE = stash.kopano.io/kc/libkcoidc
PACKAGE_NAME = $(shell basename $(PACKAGE))
# Autoconf
prefix ?= @prefix@
exec_prefix ?= @exec_prefix@
libdir ?= @libdir@
includedir ?= @includedir@/kcoidc
# Tools
GO ?= @GO@
GOFMT ?= @GOFMT@
GOLINT ?= @GOLINT@
GO2XUNIT ?= @GO2XUNIT@
DST_BIN ?= ./bin
DST_LIBS ?= ./.libs
DST_HDRS ?= ./.libs/include/kcoidc
CC ?= @CC@
CXX ?= @CXX@
CFLAGS := $(CFLAGS) -I$(DST_HDRS)
PYTHON ?= @PYTHON@
CHGLOG ?= @GITCHGLOG@
# Cgo
CGO_ENABLED ?= 0
# Go modules
GO111MODULE ?= on
# Library
SHAREDLIB=libkcoidc.so
SHAREDLIBV=libkcoidc.so.0
# Variables
export CGO_ENABLED GO111MODULE
unexport GOPATH
ARGS ?=
PWD := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
VERSION ?= $(shell git describe --tags --always --dirty --match=v* 2>/dev/null | sed 's/^v//' || \
cat $(CURDIR)/.version 2> /dev/null || echo 0.0.0-unreleased)
PKGS = $(or $(PKG),$(shell $(GO) list -mod=readonly ./... | grep -v "^$(PACKAGE)/vendor/"))
TESTPKGS = $(shell $(GO) list -mod=readonly -f '{{ if or .TestGoFiles .XTestGoFiles }}{{ .ImportPath }}{{ end }}' $(PKGS) 2>/dev/null)
CMDS = $(or $(CMD),$(addprefix cmd/,$(notdir $(shell find "$(PWD)/cmd/" -type d))))
LIBS = $(or $(CMD),$(addprefix lib/,$(notdir $(shell find "$(PWD)/lib/" -type d))))
HDRS = $(shell find "$(PWD)/lib/" -name "*.h")
CAPIVER := 0
CDEPS = $(addprefix $(DST_LIBS)/,$(addsuffix .h,$(notdir $(LIBS))))
CLIBS = $(addprefix $(DST_LIBS)/lib,$(addsuffix .so.$(CAPIVER),$(notdir $(LIBS))))
CHDRS = $(DST_HDRS)/$(notdir $(HDRS))
TIMEOUT = 30
# Build
LDFLAGS ?=
EXTLDFLAGS ?=
ASMFLAGS ?=
GCFLAGS ?=
.PHONY: default
default: lib
.PHONY: all
all: lib python
$(DST_BIN):
@mkdir $@
$(DST_LIBS):
@mkdir $@
$(DST_HDRS):
@mkdir -p $@
.PHONY: $(CMDS)
$(CMDS): vendor ; $(info building $@ ...) @
CGO_ENABLED=$(CGO_ENABLED) $(GO) build \
-mod=vendor \
-tags release \
-trimpath \
-ldflags '-s -w -buildid=reproducible/$(VERSION) -X $(PACKAGE)/internal/version.Version=$(VERSION) -X $(PACKAGE)/internal/version.BuildDate=$(DATE) -extldflags -static' \
-o bin/$(notdir $@) ./$@
.PHONY: $(LIBS)
$(LIBS): vendor | $(DST_BIN) $(DST_LIBS) $(DST_HDRS) ; $(info building C libs $@ ...) @
CGO_ENABLED=1 $(GO) build \
-mod=vendor \
-tags release \
-trimpath \
-buildmode=c-shared \
-asmflags '$(ASMFLAGS)' \
-gcflags '$(GCFLAGS)' \
-ldflags '$(LDFLAGS) -buildid=reproducible/$(VERSION) -X $(PACKAGE)/internal/version.Version=$(VERSION) -X $(PACKAGE)/internal/version.BuildDate=$(DATE) -linkmode external "-extldflags=-Wl,-soname,lib$(notdir $@).so.0 $(EXTLDFLAGS)"' \
-o $(DST_LIBS)/$(notdir $@).so ./$@
@mv -f $(DST_LIBS)/$(notdir $@).so $(DST_LIBS)/lib$(notdir $@).so.$(CAPIVER)
cd $(DST_LIBS) && ln -sfn lib$(notdir $@).so.$(CAPIVER) lib$(notdir $@).so
@mv -f $(DST_LIBS)/$(notdir $@).h $(DST_HDRS)
.PHONY: $(HDRS)
$(HDRS): $(DST_HDRS)
@cp -af $@ $(DST_HDRS)/$(notdir $@)
$(CHDRS): $(HDRS)
$(CLIBS): $(LIBS) $(CHDRS)
.PHONY: lib
lib: fmt vendor | $(CLIBS)
.PHONY: lib-stripped
lib-stripped: LDFLAGS= -s -w
lib-stripped: lib
.PHONY: python
python: $(CLIBS)
(cd python && $(PYTHON) setup.py build)
# Examples
.PHONY: examples
examples: $(DST_BIN)/validate-c $(DST_BIN)/benchmark-cpp $(CMDS)
$(DST_BIN)/validate-c: examples/validate.c $(CLIBS)
$(CC) -Wall -std=c11 -o $@ $^ $(CFLAGS)
$(DST_BIN)/benchmark-cpp: examples/benchmark.cpp $(CLIBS)
$(CXX) -Wall -O3 -std=c++0x -o $@ $^ -pthread $(CFLAGS)
# Helpers
.PHONY: lint
lint: vendor ; $(info running $(GOLINT) ...) @
CGO_ENABLED=1 $(GOLINT) run
.PHONY: lint-checkstyle
lint-checkstyle: vendor ; $(info running $(GOLINT) checkstyle ...) @
@mkdir -p test
CGO_ENABLED=1 $(GOLINT) run --out-format checkstyle --issues-exit-code 0 > test/tests.lint.xml
.PHONY: fmt
fmt: ; $(info running gofmt ...) @
@ret=0 && for d in $$($(GO) list -mod=readonly -f '{{.Dir}}' ./... | grep -v /vendor/); do \
$(GOFMT) -l -w $$d/*.go || ret=$$? ; \
done ; exit $$ret
.PHONY: check
check: ; $(info checking dependencies ...) @
@$(GO) mod verify && echo OK
# Tests
TEST_TARGETS := test-default test-bench test-short test-race test-verbose
.PHONY: $(TEST_TARGETS)
test-bench: ARGS=-run=_Bench* -test.benchmem -bench=.
test-short: ARGS=-short
test-race: ARGS=-race
test-race: CGO_ENABLED=1
test-verbose: ARGS=-v
$(TEST_TARGETS): NAME=$(MAKECMDGOALS:test-%=%)
$(TEST_TARGETS): test
.PHONY: test
test: vendor ; $(info running $(NAME:%=% )tests ...) @
@CGO_ENABLED=$(CGO_ENABLED) $(GO) test -timeout $(TIMEOUT)s $(ARGS) $(TESTPKGS)
TEST_XML_TARGETS := test-xml-default test-xml-short test-xml-race
.PHONY: $(TEST_XML_TARGETS)
test-xml-short: ARGS=-short
test-xml-race: ARGS=-race
test-xml-race: CGO_ENABLED=1
$(TEST_XML_TARGETS): NAME=$(MAKECMDGOALS:test-%=%)
$(TEST_XML_TARGETS): test-xml
.PHONY: test-xml
test-xml: vendor ; $(info running $(NAME:%=% )tests ...) @
@mkdir -p test
2>&1 CGO_ENABLED=$(CGO_ENABLED) $(GO) test -timeout $(TIMEOUT)s $(ARGS) -v $(TESTPKGS) | tee test/tests.output
test -s test/tests.output && $(GO2XUNIT) -fail -input test/tests.output -output test/tests.xml
# Mod
go.sum: go.mod ; $(info updating dependencies ...)
@$(GO) mod tidy -v
@touch $@
.PHONY: vendor
vendor: go.sum ; $(info retrieving dependencies ...)
@$(GO) mod vendor
@touch $@
# Dist
.PHONY: licenses
licenses: ; $(info building licenses files ...)
$(CURDIR)/scripts/go-license-ranger.py > $(CURDIR)/3rdparty-LICENSES.md
3rdparty-LICENSES.md: licenses
.PHONY: dist
dist: licenses ; $(info building dist tarball ...)
@mkdir -p "dist/${PACKAGE_NAME}-${VERSION}"
@cd dist && \
cp -avf ../LICENSE.txt "${PACKAGE_NAME}-${VERSION}" && \
cp -avf ../3rdparty-LICENSES.md "${PACKAGE_NAME}-${VERSION}" && \
cp -avf ../README.md "${PACKAGE_NAME}-${VERSION}" && \
cp -avf ../libkcoidc.pc "${PACKAGE_NAME}-${VERSION}" && \
cp -avf ../.libs/* "${PACKAGE_NAME}-${VERSION}" && \
chmod 755 "${PACKAGE_NAME}-${VERSION}"/*.so* && \
rm -f "${PACKAGE_NAME}-${VERSION}"/$(SHAREDLIB) && \
ln -s $(SHAREDLIBV) "${PACKAGE_NAME}-${VERSION}"/$(SHAREDLIB) && \
tar --owner=0 --group=0 -czvf ${PACKAGE_NAME}-${VERSION}.tar.gz "${PACKAGE_NAME}-${VERSION}" && \
cd ..
.PHONY: changelog
changelog: ; $(info updating changelog ...)
$(CHGLOG) --output CHANGELOG.md $(ARGS)
# Install
.PHONY: install
install: lib libkcoidc.pc ; $(info installing ...)
@mkdir -p $(DESTDIR)$(libdir)/pkgconfig
@mkdir -p $(DESTDIR)$(includedir)
cp -af libkcoidc.pc $(DESTDIR)$(libdir)/pkgconfig
cp -f $(CLIBS) $(DESTDIR)$(libdir)
chmod 755 $(DESTDIR)$(libdir)/$(SHAREDLIBV)
rm -f $(DESTDIR)$(libdir)/$(SHAREDLIB)
ln -s $(SHAREDLIBV) $(DESTDIR)$(libdir)/$(SHAREDLIB)
cp -f $(CHDRS) $(DESTDIR)$(includedir)
(ldconfig || true) >/dev/null 2>&1
.PHONY: uninstall
uninstall: ; $(info uninstalling ...)
rm -f $(DESTDIR)$(libdir)/pkgconfig/libkcoidc.pc
rm -f $(DESTDIR)$(libdir)/$(notdir $(CLIBS))
rm -f $(DESTDIR)$(libdir)/$(SHAREDLIB)
rm -f $(DESTDIR)$(includedir)/$(notdir $(CHDRS))
# Rest
.PHONY: clean
clean: ; $(info cleaning ...) @
@rm -f config.* Makefile
@rm -rf .libs
@rm -rf bin
@rm -rf test/test.*
@rm -f libkcoidc.pc
(cd python && $(PYTHON) setup.py clean)
.PHONY: version
version:
@echo $(VERSION)