-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
153 lines (112 loc) · 5.77 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
GO_SRCS := $(shell find . -type f -name '*.go' -a ! \( -name 'zz_generated*' -o -name '*_test.go' \))
GO_TESTS := $(shell find . -type f -name '*_test.go')
TAG_NAME = $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null)
TAG_NAME_DEV = $(shell git describe --tags --abbrev=0 2>/dev/null)
VERSION_CORE = $(shell echo $(TAG_NAME))
VERSION_CORE_DEV = $(shell echo $(TAG_NAME_DEV))
GIT_COMMIT = $(shell git rev-parse --short=7 HEAD)
VERSION = $(or $(and $(TAG_NAME),$(VERSION_CORE)),$(and $(TAG_NAME_DEV),$(VERSION_CORE_DEV)-dev),$(GIT_COMMIT))
wgo := $(shell which wgo)
ifeq ($(wgo),)
wgo := $(shell go env GOPATH)/bin/wgo
endif
golint := $(shell which golangci-lint)
ifeq ($(golint),)
golint := $(shell go env GOPATH)/bin/golangci-lint
endif
migrate := $(shell which migrate)
ifeq ($(migrate),)
migrate := $(shell go env GOPATH)/bin/migrate
endif
sqlc := $(shell which sqlc)
ifeq ($(sqlc),)
sqlc := $(shell go env GOPATH)/bin/sqlc
endif
.PHONY: build
build: bin/dpsproxy-server bin/dpsproxy
.PHONY: bin/dpsproxy-server
bin/dpsproxy-server: $(GO_SRCS)
go build -trimpath -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy-server/main.go
.PHONY: bin/dpsproxy
bin/dpsproxy: $(GO_SRCS)
go build -trimpath -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy/main.go
bin/checksums.txt: $(addprefix bin/,$(bins))
sha256sum -b $(addprefix bin/,$(bins)) | sed 's/bin\///' > $@
bin/checksums.md: bin/checksums.txt
@echo "### SHA256 Checksums" > $@
@echo >> $@
@echo "\`\`\`" >> $@
@cat $< >> $@
@echo "\`\`\`" >> $@
bin/dpsproxy-server-darwin-amd64: $(GO_SRCS)
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy-server/main.go
bin/dpsproxy-server-darwin-arm64: $(GO_SRCS)
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy-server/main.go
bin/dpsproxy-server-freebsd-amd64: $(GO_SRCS)
CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy-server/main.go
bin/dpsproxy-server-freebsd-arm64: $(GO_SRCS)
CGO_ENABLED=0 GOOS=freebsd GOARCH=arm64 go build -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy-server/main.go
bin/dpsproxy-server-linux-amd64: $(GO_SRCS)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy-server/main.go
bin/dpsproxy-server-linux-arm64: $(GO_SRCS)
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy-server/main.go
bin/dpsproxy-server-linux-riscv64: $(GO_SRCS)
CGO_ENABLED=0 GOOS=linux GOARCH=riscv64 go build -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy-server/main.go
bin/dpsproxy-server-windows-amd64.exe: $(GO_SRCS)
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy-server/main.go
bin/dpsproxy-darwin-amd64: $(GO_SRCS)
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy/main.go
bin/dpsproxy-darwin-arm64: $(GO_SRCS)
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy/main.go
bin/dpsproxy-freebsd-amd64: $(GO_SRCS)
CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy/main.go
bin/dpsproxy-freebsd-arm64: $(GO_SRCS)
CGO_ENABLED=0 GOOS=freebsd GOARCH=arm64 go build -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy/main.go
bin/dpsproxy-linux-amd64: $(GO_SRCS)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy/main.go
bin/dpsproxy-linux-arm64: $(GO_SRCS)
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy/main.go
bin/dpsproxy-linux-riscv64: $(GO_SRCS)
CGO_ENABLED=0 GOOS=linux GOARCH=riscv64 go build -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy/main.go
bin/dpsproxy-windows-amd64.exe: $(GO_SRCS)
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy/main.go
bins := dpsproxy-server-darwin-amd64 dpsproxy-server-darwin-arm64 dpsproxy-server-freebsd-arm64 dpsproxy-server-freebsd-arm64 dpsproxy-server-linux-amd64 dpsproxy-server-linux-arm64 dpsproxy-server-linux-riscv64 dpsproxy-server-windows-amd64.exe dpsproxy-darwin-amd64 dpsproxy-darwin-arm64 dpsproxy-freebsd-arm64 dpsproxy-freebsd-arm64 dpsproxy-linux-amd64 dpsproxy-linux-arm64 dpsproxy-linux-riscv64 dpsproxy-windows-amd64.exe
.PHONY: build-all
build-all: $(addprefix bin/,$(bins)) bin/checksums.md
.PHONY: run
run: bin/dpsproxy-server
@bin/dpsproxy-server
.PHONY: watch
watch: $(wgo)
$(wgo) -xdir "gen/" -xdir "bin/" -xfile ".*\.sql" sh -c 'make run || exit 1' --signal SIGTERM
.PHONY: lint
lint: $(golint)
$(golint) run ./...
.PHONY: clean
clean:
rm -rf bin/
.PHONY: sql
sql: $(sqlc)
$(sqlc) generate
.PHONY: migration
migration: $(migrate)
$(migrate) create -seq -ext sql -dir database/migrations $(MIGRATION_NAME)
.PHONY: up
up: $(MIGRATIONS) $(migrate)
$(migrate) -path database/migrations -database sqlite3://db.sqlite3?x-no-tx-wrap=true up
.PHONY: drop
drop: $(migrate)
$(migrate) -path database/migrations -database sqlite3://db.sqlite3?x-no-tx-wrap=true drop -f
$(migrate):
go install -tags 'sqlite3' github.com/golang-migrate/migrate/v4/cmd/migrate
$(wgo):
go install github.com/bokwoon95/wgo@latest
$(golint):
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
$(sqlc):
go install github.com/sqlc-dev/sqlc/cmd/sqlc
.PHONY: version
version:
@echo VERSION_CORE=${VERSION_CORE}
@echo VERSION_CORE_DEV=${VERSION_CORE_DEV}
@echo VERSION=${VERSION}