-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
199 lines (171 loc) · 6.41 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
GO_SRCS := $(shell find . -type f -name '*.go' -a -name '*.tpl' -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) | sed 's/^\(v[0-9]\+\.[0-9]\+\.[0-9]\+\)\(+\([0-9]\+\)\)\?$$/\1/')
VERSION_CORE_DEV = $(shell echo $(TAG_NAME_DEV) | sed 's/^\(v[0-9]\+\.[0-9]\+\.[0-9]\+\)\(+\([0-9]\+\)\)\?$$/\1/')
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))
VERSION_NO_V = $(shell echo $(VERSION) | sed 's/^v\(.*\)$$/\1/')
golint := $(shell which golangci-lint)
ifeq ($(golint),)
golint := $(shell go env GOPATH)/bin/golangci-lint
endif
pkgsite := $(shell which pkgsite)
ifeq ($(pkgsite),)
pkgsite := $(shell go env GOPATH)/bin/pkgsite
endif
.PHONY: bin/fc2-live-dl-go
bin/fc2-live-dl-go: $(GO_SRCS)
CGO_ENABLED=1 go build -trimpath -ldflags '-X main.version=${VERSION} -s -w' -o "$@" ./main.go
.PHONY: bin/fc2-live-dl-go-static
bin/fc2-live-dl-go-static: $(GO_SRCS)
CGO_ENABLED=1 go build -trimpath -ldflags '-X main.version=${VERSION} -s -w -extldflags "-lswresample -static"' -o "$@" ./main.go
.PHONY: bin/fc2-live-dl-go-static.exe
bin/fc2-live-dl-go-static.exe: $(GO_SRCS)
CGO_ENABLED=1 \
GOOS=windows \
GOARCH=amd64 \
go build -trimpath -ldflags '-X main.version=${VERSION} -linkmode external -s -w -extldflags "-static"' -o "$@" ./main.go
.PHONY: bin/fc2-live-dl-go-darwin
bin/fc2-live-dl-go-darwin: $(GO_SRCS)
CGO_ENABLED=1 \
GOOS=darwin \
go build -trimpath -ldflags '-X main.version=${VERSION} -linkmode external -s -w' -o "$@" ./main.go
.PHONY: all
all: $(addprefix bin/,$(bins))
.PHONY: unit
unit:
go test -race -covermode=atomic -tags=unit -timeout=30s ./...
.PHONY: coverage
coverage: $(GO_TESTS)
go test -race -covermode=atomic -tags=unit -timeout=30s -coverprofile=coverage.out ./...
go tool cover -html coverage.out -o coverage.html
.PHONY: integration
integration:
go test -race -covermode=atomic -tags=integration -timeout=300s ./...
$(golint):
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
$(pkgsite):
go install golang.org/x/pkgsite/cmd/pkgsite@latest
.PHONY: lint
lint: $(golint)
$(golint) run ./...
.PHONY: clean
clean:
rm -rf bin/
rm -rf target/
.PHONY: package
package: target/darwin \
target/static \
target/static-windows \
target/checksums.txt \
target/checksums.md
target/checksums.txt: target/darwin \
target/static \
target/static-windows
sha256sum -b $(addsuffix /*,$^) | sed 's|target/.*/||' > $@
target/checksums.md: target/checksums.txt
@echo "### SHA256 Checksums" > $@
@echo >> $@
@echo "\`\`\`" >> $@
@cat $< >> $@
@echo "\`\`\`" >> $@
target/static:
podman manifest rm localhost/builder:static || true
podman build \
--manifest localhost/builder:static \
--jobs=2 --platform=linux/amd64,linux/arm64/v8,linux/riscv64 \
--target busybox \
-f Dockerfile.static .
mkdir -p ./target/static
podman run --rm \
-v $(shell pwd)/target/:/target/ \
--arch amd64 \
--entrypoint sh \
localhost/builder:static -c "mv /fc2-live-dl-go /target/static/fc2-live-dl-go-linux-amd64"
podman run --rm \
-v $(shell pwd)/target/:/target/ \
--arch arm64 \
--variant v8 \
--entrypoint sh \
localhost/builder:static -c "mv /fc2-live-dl-go /target/static/fc2-live-dl-go-linux-arm64"
podman run --rm \
-v $(shell pwd)/target/:/target/ \
--arch riscv64 \
--entrypoint sh \
localhost/builder:static -c "mv /fc2-live-dl-go /target/static/fc2-live-dl-go-linux-riscv64"
./assert-arch.sh
target/static-windows:
podman build \
-t localhost/builder:static-windows \
-f Dockerfile.static-windows .
mkdir -p ./target/static-windows
podman run --rm \
-v $(shell pwd)/target/:/target/ \
localhost/builder:static-windows mv /work/bin/fc2-live-dl-go-static.exe /target/static-windows/fc2-live-dl-go-windows-amd64.exe
target/darwin:
podman manifest rm localhost/builder:darwin || true
podman build \
--manifest localhost/builder:darwin \
--jobs=2 --platform=linux/amd64,linux/arm64/v8 \
--target busybox \
-f Dockerfile.darwin .
mkdir -p ./target/darwin
podman run --rm \
-v $(shell pwd)/target/:/target/ \
--arch amd64 \
--entrypoint sh \
localhost/builder:darwin -c "mv /fc2-live-dl-go /target/darwin/fc2-live-dl-go-darwin-amd64"
podman run --rm \
-v $(shell pwd)/target/:/target/ \
--arch arm64 \
--variant v8 \
--entrypoint sh \
localhost/builder:darwin -c "mv /fc2-live-dl-go /target/darwin/fc2-live-dl-go-darwin-arm64"
.PHONY: docker-static
docker-static:
podman manifest rm ghcr.io/darkness4/fc2-live-dl-go:latest || true
podman build \
--manifest ghcr.io/darkness4/fc2-live-dl-go:latest \
--jobs=2 --platform=linux/amd64,linux/arm64/v8,linux/riscv64 \
-f Dockerfile.static .
podman manifest push --all ghcr.io/darkness4/fc2-live-dl-go:latest "docker://ghcr.io/darkness4/fc2-live-dl-go:latest"
podman manifest push --all ghcr.io/darkness4/fc2-live-dl-go:latest "docker://ghcr.io/darkness4/fc2-live-dl-go:${VERSION_NO_V}"
podman manifest push --all ghcr.io/darkness4/fc2-live-dl-go:latest "docker://ghcr.io/darkness4/fc2-live-dl-go:dev"
.PHONY: docker-static-base
docker-static-base:
podman build \
-t ghcr.io/darkness4/fc2-live-dl-go:latest-static-base \
--platform=linux/amd64 \
-f Dockerfile.static-base .
podman push ghcr.io/darkness4/fc2-live-dl-go:latest-static-base
.PHONY: docker-static-windows-base
docker-static-windows-base:
podman build \
-t ghcr.io/darkness4/fc2-live-dl-go:latest-static-windows-base \
-f Dockerfile.static-windows-base .
podman push ghcr.io/darkness4/fc2-live-dl-go:latest-static-windows-base
.PHONY: docker-darwin-base
docker-darwin-base:
podman build \
-t ghcr.io/darkness4/fc2-live-dl-go:latest-darwin-base-amd64 \
--build-arg TARGET_ARCH=x86_64 \
-f Dockerfile.darwin-base .
podman push ghcr.io/darkness4/fc2-live-dl-go:latest-darwin-base-amd64
podman build \
-t ghcr.io/darkness4/fc2-live-dl-go:latest-darwin-base-arm64 \
--build-arg TARGET_ARCH=aarch64 \
--build-arg OSX_VERSION_MIN=11.0 \
-f Dockerfile.darwin-base .
podman push ghcr.io/darkness4/fc2-live-dl-go:latest-darwin-base-arm64
.PHONY: version
version:
echo version=$(VERSION)
.PHONY: memleaks
memleaks:
cd video/probe && make valgrind
cd video/concat && make valgrind
.PHONY: doc
doc: $(pkgsite)
$(pkgsite) -open .