-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
107 lines (90 loc) · 3.81 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
APPNAME?=megafile
# version from last tag
VERSION := $(shell git describe --abbrev=0 --always --tags)
BUILD := $(shell git rev-parse $(VERSION))
BUILDDATE := $(shell git log -1 --format=%aI $(VERSION))
BUILDFILES?=$$(find . -mindepth 1 -maxdepth 1 -type f \( -iname "*${APPNAME}-v*" -a ! -iname "*.shasums" \))
LDFLAGS := -ldflags "-s -w -X=main.VERSION=$(VERSION) -X=main.BUILD=$(BUILD) -X=main.BUILDDATE=$(BUILDDATE)"
RELEASETMPDIR := $(shell mktemp -d -t ${APPNAME}-rel-XXXXXX)
APPANDVER := ${APPNAME}-$(VERSION)
RELEASETMPAPPDIR := $(RELEASETMPDIR)/$(APPANDVER)
UPXFLAGS := -v -9
# https://golang.org/doc/install/source#environment
LINUX_ARCHS := amd64 arm arm64 ppc64 ppc64le
WINDOWS_ARCHS := amd64
DARWIN_ARCHS := amd64
default: build
build:
@echo "GO BUILD..."
@CGO_ENABLED=0 go build $(LDFLAGS) -v -o ./bin/${APPNAME} .
linux-build:
@for arch in $(LINUX_ARCHS); do \
echo "GNU/Linux build... $$arch"; \
CGO_ENABLED=0 GOOS=linux GOARCH=$$arch go build $(LDFLAGS) -v -o ./bin/linux-$$arch/${APPNAME} . ; \
done
darwin-build:
@for arch in $(DARWIN_ARCHS); do \
echo "Darwin build... $$arch"; \
CGO_ENABLED=0 GOOS=darwin GOARCH=$$arch go build $(LDFLAGS) -v -o ./bin/darwin-$$arch/${APPNAME} . ; \
done
windows-build:
@for arch in $(WINDOWS_ARCHS); do \
echo "MS Windows build... $$arch"; \
CGO_ENABLED=0 GOOS=windows GOARCH=$$arch go build $(LDFLAGS) -v -o ./bin/windows-$$arch/${APPNAME}.exe . ; \
done
# Compress executables
upx-pack:
@upx $(UPXFLAGS) ./bin/linux-amd64/${APPNAME}
@upx $(UPXFLAGS) ./bin/linux-arm/${APPNAME}
@upx $(UPXFLAGS) ./bin/windows-amd64/${APPNAME}.exe
release: linux-build darwin-build windows-build upx-pack compress-everything shasums
@echo "release done..."
shasums:
@echo "Checksumming..."
@pushd "release/${VERSION}" && shasum -a 256 $(BUILDFILES) > $(APPANDVER).shasums
# Compress files: GNU/Linux
compress-linux:
@for arch in $(LINUX_ARCHS); do \
echo "GNU/Linux tar... $$arch"; \
cp -v "$(PWD)/bin/linux-$$arch/${APPNAME}" "$(RELEASETMPAPPDIR)/bin"; \
cd "$(RELEASETMPDIR)"; \
tar --numeric-owner --owner=0 --group=0 -zcvf "$(PWD)/release/${VERSION}/$(APPANDVER)-linux-$$arch.tar.gz" . ; \
rm "$(RELEASETMPAPPDIR)/bin/${APPNAME}"; \
done
# Compress files: Darwin
compress-darwin:
@for arch in $(DARWIN_ARCHS); do \
echo "Darwin tar... $$arch"; \
cp -v "$(PWD)/bin/darwin-$$arch/${APPNAME}" "$(RELEASETMPAPPDIR)/bin"; \
cd "$(RELEASETMPDIR)"; \
tar --numeric-owner --owner=0 --group=0 -zcvf "$(PWD)/release/${VERSION}/$(APPANDVER)-darwin-$$arch.tar.gz" . ; \
rm "$(RELEASETMPAPPDIR)/bin/${APPNAME}"; \
done
# Compress files: Microsoft Windows
compress-windows:
@for arch in $(WINDOWS_ARCHS); do \
echo "MS Windows zip... $$arch"; \
cp -v "$(PWD)/bin/windows-$$arch/${APPNAME}.exe" "$(RELEASETMPAPPDIR)/bin"; \
cd "$(RELEASETMPAPPDIR)"; \
mv "LICENSE" "LICENSE.txt" && \
pandoc --standalone --to rtf --output LICENSE.rtf LICENSE.txt && \
rm "LICENSE.txt" ; \
cd "$(RELEASETMPDIR)" ; \
zip -v -9 -r -o -9 "$(PWD)/release/${VERSION}/$(APPANDVER)-windows-$$arch.zip" . ; \
rm "$(RELEASETMPAPPDIR)/LICENSE.rtf"; \
cp -v "$(PWD)/LICENSE" "$(RELEASETMPAPPDIR)" ; \
rm "$(RELEASETMPAPPDIR)/bin/${APPNAME}.exe"; \
done
# Move all to temporary directory and compress with common files
compress-everything: copycommon compress-linux compress-darwin compress-windows
@echo "$@ ..."
rm -rf "$(RELEASETMPDIR)/*"
# Copy common files to release directory
# Creates $(APPNAME)-$(VERSION) directory prefix where everything will be copied by compress-$OS targets
copycommon:
@echo "Copying common files to temporary release directory '$(RELEASETMPAPPDIR)'.."
@mkdir -p "$(RELEASETMPAPPDIR)/bin"
@cp -v "./LICENSE" "$(RELEASETMPAPPDIR)"
@cp -v "./README.md" "$(RELEASETMPAPPDIR)"
@mkdir --parents "$(PWD)/release/${VERSION}"
.PHONY: all clean test default