-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
176 lines (150 loc) · 6.31 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
APPNAME?=heksa
# 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 := -trimpath -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
XZCOMPRESSFLAGS := --verbose --keep --compress --threads 0 --extreme -9
# https://golang.org/doc/install/source#environment
LINUX_ARCHS := amd64 arm arm64 ppc64 ppc64le
WINDOWS_ARCHS := amd64
DARWIN_ARCHS := amd64
FREEBSD_ARCHS := amd64 arm
NETBSD_ARCHS := amd64 arm
OPENBSD_ARCHS := amd64 arm arm64
default: build
build:
@echo "GO BUILD..."
@CGO_ENABLED=0 go build $(LDFLAGS) -v -o ./bin/${APPNAME} .
# Update go module(s)
modup:
@go get -u github.com/raspi/[email protected]
@go mod vendor
@go mod tidy
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
freebsd-build:
@for arch in $(FREEBSD_ARCHS); do \
echo "FreeBSD build... $$arch"; \
CGO_ENABLED=0 GOOS=freebsd GOARCH=$$arch go build $(LDFLAGS) -v -o ./bin/freebsd-$$arch/${APPNAME} . ; \
done
netbsd-build:
@for arch in $(NETBSD_ARCHS); do \
echo "NetBSD build... $$arch"; \
CGO_ENABLED=0 GOOS=netbsd GOARCH=$$arch go build $(LDFLAGS) -v -o ./bin/netbsd-$$arch/${APPNAME} . ; \
done
openbsd-build:
@for arch in $(OPENBSD_ARCHS); do \
echo "OpenBSD build... $$arch"; \
CGO_ENABLED=0 GOOS=openbsd GOARCH=$$arch go build $(LDFLAGS) -v -o ./bin/openbsd-$$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 freebsd-build openbsd-build netbsd-build windows-build upx-pack compress-everything shasums release-ldistros
@echo "release done..."
# Linux distributions
release-ldistros: ldistro-arch
@echo "Linux distros release done..."
shasums:
@echo "Checksumming..."
@pushd "release/${VERSION}" && shasum -a 256 $(BUILDFILES) > $(APPANDVER).shasums
# 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)"
@cp -v "./CODE_OF_CONDUCT.md" "$(RELEASETMPAPPDIR)"
@cp -v "./CONTRIBUTING.md" "$(RELEASETMPAPPDIR)"
@mkdir --parents "$(PWD)/release/${VERSION}"
# Compress files: FreeBSD
compress-freebsd:
@for arch in $(FREEBSD_ARCHS); do \
echo "FreeBSD xz... $$arch"; \
cp -v "$(PWD)/bin/freebsd-$$arch/${APPNAME}" "$(RELEASETMPAPPDIR)/bin"; \
cd "$(RELEASETMPDIR)"; \
tar --numeric-owner --owner=0 --group=0 -cf - . | xz $(XZCOMPRESSFLAGS) - > "$(PWD)/release/${VERSION}/$(APPANDVER)-freebsd-$$arch.tar.xz" ; \
rm "$(RELEASETMPAPPDIR)/bin/${APPNAME}"; \
done
# Compress files: OpenBSD
compress-openbsd:
@for arch in $(OPENBSD_ARCHS); do \
echo "OpenBSD xz... $$arch"; \
cp -v "$(PWD)/bin/openbsd-$$arch/${APPNAME}" "$(RELEASETMPAPPDIR)/bin"; \
cd "$(RELEASETMPDIR)"; \
tar --numeric-owner --owner=0 --group=0 -cf - . | xz $(XZCOMPRESSFLAGS) - > "$(PWD)/release/${VERSION}/$(APPANDVER)-openbsd-$$arch.tar.xz" ; \
rm "$(RELEASETMPAPPDIR)/bin/${APPNAME}"; \
done
# Compress files: NetBSD
compress-netbsd:
@for arch in $(NETBSD_ARCHS); do \
echo "NetBSD xz... $$arch"; \
cp -v "$(PWD)/bin/netbsd-$$arch/${APPNAME}" "$(RELEASETMPAPPDIR)/bin"; \
cd "$(RELEASETMPDIR)"; \
tar --numeric-owner --owner=0 --group=0 -cf - . | xz $(XZCOMPRESSFLAGS) - > "$(PWD)/release/${VERSION}/$(APPANDVER)-netbsd-$$arch.tar.xz" ; \
rm "$(RELEASETMPAPPDIR)/bin/${APPNAME}"; \
done
# 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 --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-windows compress-freebsd compress-netbsd compress-openbsd
@echo "$@ ..."
rm -rf "$(RELEASETMPDIR)/*"
# Distro: Arch linux - https://www.archlinux.org/
# Generates multi-arch PKGBUILD
ldistro-arch:
pushd release/linux/arch && go run . -version ${VERSION}
.PHONY: all clean test default