-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
143 lines (121 loc) · 5.32 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
APPNAME?=kallu
# 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) -buildid="
RELEASETMPDIR := $(shell mktemp -d -t ${APPNAME}-rel-XXXXXX)
APPANDVER := ${APPNAME}-$(VERSION)
RELEASETMPAPPDIR := $(RELEASETMPDIR)/$(APPANDVER)
BINFILE := ./cmd/kallu
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
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} ${BINFILE}
linux-build:
@for arch in $(LINUX_ARCHS); do \
echo "GNU/Linux build... $$arch"; \
CGO_ENABLED=0 GOOS=linux GOARCH=$$arch go build $(LDFLAGS) -o ./bin/linux-$$arch/${APPNAME} ${BINFILE} ; \
done
darwin-build:
@for arch in $(DARWIN_ARCHS); do \
echo "Darwin build... $$arch"; \
CGO_ENABLED=0 GOOS=darwin GOARCH=$$arch go build $(LDFLAGS) -o ./bin/darwin-$$arch/${APPNAME} ${BINFILE} ; \
done
freebsd-build:
@for arch in $(FREEBSD_ARCHS); do \
echo "FreeBSD build... $$arch"; \
CGO_ENABLED=0 GOOS=freebsd GOARCH=$$arch go build $(LDFLAGS) -o ./bin/freebsd-$$arch/${APPNAME} ${BINFILE} ; \
done
netbsd-build:
@for arch in $(NETBSD_ARCHS); do \
echo "NetBSD build... $$arch"; \
CGO_ENABLED=0 GOOS=netbsd GOARCH=$$arch go build $(LDFLAGS) -o ./bin/netbsd-$$arch/${APPNAME} ${BINFILE} ; \
done
openbsd-build:
@for arch in $(OPENBSD_ARCHS); do \
echo "OpenBSD build... $$arch"; \
CGO_ENABLED=0 GOOS=openbsd GOARCH=$$arch go build $(LDFLAGS) -o ./bin/openbsd-$$arch/${APPNAME} ${BINFILE} ; \
done
# Compress executables
upx-pack:
@upx $(UPXFLAGS) ./bin/linux-amd64/${APPNAME}
@upx $(UPXFLAGS) ./bin/linux-arm/${APPNAME}
release: linux-build darwin-build freebsd-build openbsd-build netbsd-build upx-pack compress-everything shasums
@echo "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)"
@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
# Move all to temporary directory and compress with common files
compress-everything: copycommon compress-linux compress-freebsd compress-netbsd compress-openbsd
@echo "$@ ..."
rm -rf "$(RELEASETMPDIR)/*"
# See: https://pkg.go.dev/golang.org/x/text/message#hdr-Translation_Pipeline
updatelocales:
@echo "Updating locales.."
pushd cmd/kallu; go generate; popd
find cmd/kallu/locales -mindepth 1 -maxdepth 2 -type d -exec ./json_merge.py "{}/messages.gotext.json" "{}/out.gotext.json" \;
@echo "now translate messages.gotext.json and run this again"
.PHONY: all clean test default