forked from mergestat/mergestat-lite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
141 lines (112 loc) · 4.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
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
NAME=askgit
.PHONY: clean update vet test lint lint-ci test-cover bench
# default task invoked while running make
all: clean .build/libmergestat.so .build/mergestat
OS = $(shell uname -s | tr '[:upper:]' '[:lower:]')
ARCH = $(shell uname -m | sed 's/x86_64/amd64/')
ifeq ($(VERSION),)
VERSION_TAG=$(shell git describe --abbrev=0 --tags --exact-match 2>/dev/null || echo latest)
else
VERSION_TAG=$(VERSION)
endif
# pass these flags to linker to suppress missing symbol errors in intermediate artifacts
export CGO_CFLAGS = -DUSE_LIBSQLITE3
export CPATH = ${PWD}/pkg/sqlite
export CGO_LDFLAGS = -Wl,--unresolved-symbols=ignore-in-object-files
ifeq ($(shell uname -s),Darwin)
export CGO_LDFLAGS = -Wl,-undefined,dynamic_lookup
endif
UPX_VERSION=4.1.0
.bin/upx:
ifeq (, $(shell which upx))
ifeq ($(OS), darwin)
brew install upx
UPX=upx
else
wget -nv -O upx.tar.xz https://github.com/upx/upx/releases/download/v$(UPX_VERSION)/upx-$(UPX_VERSION)-$(ARCH)_$(OS).tar.xz
tar xf upx.tar.xz upx-$(UPX_VERSION)-$(ARCH)_$(OS)/upx
rm -rf upx.tar.xz
UPX=./upx
endif
else
UPX=$(shell which upx)
endif
compress: .bin/upx
upx -5 .build/mergestat*
# target to build and install libgit2
libgit2:
cd git2go; make install-static
# target to build a dynamic extension that can be loaded at runtime
.build/libmergestat.so: $(shell find . -type f -name '*.go' -o -name '*.c')
$(call log, $(CYAN), "building $@")
@go build -buildmode=c-shared -o $@ -tags="static,shared" shared.go
$(call log, $(GREEN), "built $@")
# target to compile mergestat executable
.build/mergestat: $(shell find . -type f -name '*.go' -o -name '*.c')
$(call log, $(CYAN), "building $@")
@go build -o $@ -tags="static" mergestat.go
$(call log, $(GREEN), "built $@")
# target to download latest sqlite3 amalgamation code
pkg/sqlite/sqlite3.c:
$(call log, $(CYAN), "downloading sqlite3 amalgamation source v3.38.2")
$(eval SQLITE_DOWNLOAD_DIR = $(shell mktemp -d))
@curl -sSLo $(SQLITE_DOWNLOAD_DIR)/sqlite3.zip https://www.sqlite.org/2022/sqlite-amalgamation-3380200.zip
$(call log, $(GREEN), "downloaded sqlite3 amalgamation source v3.38.2")
$(call log, $(CYAN), "unzipping to $(SQLITE_DOWNLOAD_DIR)")
@(cd $(SQLITE_DOWNLOAD_DIR) && unzip sqlite3.zip > /dev/null)
@-rm $(SQLITE_DOWNLOAD_DIR)/sqlite-amalgamation-3380200/shell.c
$(call log, $(CYAN), "moving to pkg/sqlite")
@mv $(SQLITE_DOWNLOAD_DIR)/sqlite-amalgamation-3380200/* pkg/sqlite
clean:
$(call log, $(YELLOW), "nuking .build/")
@-rm -rf .build/
.PHONY: linux
linux:
GOOS=linux GOARCH=amd64 go build -o ./.bin/$(NAME)_linux_amd64 -ldflags "-X \"main.version=$(VERSION_TAG)\"" mergestat.go
GOOS=linux GOARCH=arm64 go build -o ./.bin/$(NAME)_linux_arm64 -ldflags "-X \"main.version=$(VERSION_TAG)\"" mergestat.go
.PHONY: darwin
darwin:
GOOS=darwin GOARCH=amd64 go build -o ./.bin/$(NAME)_darwin_amd64 -ldflags "-X \"main.version=$(VERSION_TAG)\"" mergestat.go
GOOS=darwin GOARCH=arm64 go build -o ./.bin/$(NAME)_darwin_arm64 -ldflags "-X \"main.version=$(VERSION_TAG)\"" mergestat.go
.PHONY: binaries
binaries: linux darwin
.PHONY: release
release: binaries
mkdir -p .release
cp .bin/askgit* .release/
# ========================================
# target for common golang tasks
# go build tags used by test, vet and more
TAGS = "static"
update:
go get -tags=$(TAGS) -u ./...
vet:
go vet -v -tags=$(TAGS) ./...
build:
go build -v -tags=$(TAGS) mergestat.go
lint:
golangci-lint run --build-tags $(TAGS)
lint-ci:
./bin/golangci-lint run --build-tags $(TAGS) --out-format github-actions --timeout 5m
test:
go test -v -tags=$(TAGS) ./...
test-cover:
go test -v -tags=$(TAGS) ./... -cover -covermode=count -coverprofile=coverage.out
go tool cover -html=coverage.out
bench:
go test -v -tags=$(TAGS) -bench=. -benchmem -run=^nomatch ./...
# ========================================
# some utility methods
# ASCII color codes that can be used with functions that output to stdout
RED := 1;31
GREEN := 1;32
ORANGE := 1;33
YELLOW := 1;33
BLUE := 1;34
PURPLE := 1;35
CYAN := 1;36
# log:
# print out $2 to stdout using $1 as ASCII color codes
define log
@printf "\033[$(strip $1)m-- %s\033[0m\n" $2
endef