-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
50 lines (40 loc) · 2.43 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
EXECUTABLE=jrctl
VERSION=$(shell git describe --tags `git rev-list --tags --max-count=1`)
OS=linux
ARCH=amd64
.PHONY: help bump build-all clean docs optimize pretty package
help: ## Display available commands
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
bump: ## Bump version in source files based on latest git tag
VERSION=$(VERSION); sed -E -i '' "s/(Version-)([0-9.]+)(-green)/\1$$VERSION\3/g" README.md
VERSION=$(VERSION); sed -E -i '' "s/(version: )([0-9.]+)/\1$$VERSION/g" nfpm.yaml
VERSION=$(VERSION); sed -E -i '' "s/(const VersionString string = \")([0-9.]+)(\")/\1$$VERSION\3/g" sdk/version/version.go
build: ## Build for specified platforms
env GOOS=$(OS) GOARCH=$(ARCH) go build -v -o "bin/$(EXECUTABLE)_$(OS)_$(ARCH)" -ldflags="-s -w" -trimpath ./cmd/jrctl/main.go
build-all: ## Build for all platforms
make OS=darwin ARCH=amd64 build
make OS=linux ARCH=amd64 build
make OS=linux ARCH=arm64 build
clean: ## Delete built binaries
mkdir -p dist bin
rm -rf dist/* bin/* nfpm.generated.yaml
docs: ## Generate documentation
mkdir -p docs man
rm -rf man/* docs/*.md
DOCS=true NO_COLOR=true go run tools/generate-docs.go
pretty: ## Format code with goimports
gofmt -w -s cmd internal tools sdk pkg
goimports -w cmd internal tools sdk pkg
optimize: ## Optimize binaries (false positive for malware)
upx -d --best --lzma bin/*
package: clean build-all docs ## Package binary for many distributions
GOARCH=amd64 envsubst < nfpm.yaml > nfpm.generated.yaml
GOARCH=amd64 nfpm pkg --config nfpm.generated.yaml --packager apk --target dist/$(EXECUTABLE)_$(VERSION)_linux_amd64.apk
GOARCH=amd64 nfpm pkg --config nfpm.generated.yaml --packager deb --target dist/$(EXECUTABLE)_$(VERSION)_linux_amd64.deb
GOARCH=amd64 nfpm pkg --config nfpm.generated.yaml --packager rpm --target dist/$(EXECUTABLE)_$(VERSION)_linux_amd64.rpm
GOARCH=arm64 envsubst < nfpm.yaml > nfpm.generated.yaml
GOARCH=arm64 nfpm pkg --config nfpm.generated.yaml --packager apk --target dist/$(EXECUTABLE)_$(VERSION)_linux_arm64.apk
GOARCH=arm64 nfpm pkg --config nfpm.generated.yaml --packager deb --target dist/$(EXECUTABLE)_$(VERSION)_linux_arm64.deb
GOARCH=arm64 nfpm pkg --config nfpm.generated.yaml --packager rpm --target dist/$(EXECUTABLE)_$(VERSION)_linux_arm64.rpm
tar -czvf ./dist/$(EXECUTABLE)_$(VERSION)_darwin_amd64.tar.gz man bin/$(EXECUTABLE)_darwin_amd64
rm -f nfpm.generated.yaml