-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
162 lines (135 loc) · 5.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
APPNAME?=json2archpkgbuild
# 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)"
TMPDIR := $(shell mktemp -d -t ${APPNAME}-rel-XXXXXX)
UPXFLAGS := -v -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
CHECKSUMFILE := ${APPNAME}-${VERSION}.shasums
default: build
build:
@echo "GO BUILD..."
@CGO_ENABLED=0 go build $(LDFLAGS) -v -o ./bin/${APPNAME} .
@./bin/${APPNAME} -example > example/example.json
# 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} . 2>/dev/null; \
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} . 2>/dev/null; \
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} . 2>/dev/null; \
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} . 2>/dev/null; \
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 . 2>/dev/null; \
done
upx-pack:
@upx $(UPXFLAGS) ./bin/linux-amd64/${APPNAME}
@upx $(UPXFLAGS) ./bin/linux-arm/${APPNAME}
@upx $(UPXFLAGS) ./bin/windows-amd64/${APPNAME}.exe
release: build linux-build darwin-build freebsd-build openbsd-build netbsd-build windows-build upx-pack tar-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) > ${CHECKSUMFILE}
# Copy common files to release directory
copycommon:
@echo "Copying common files to $(TMPDIR)"
@mkdir "$(TMPDIR)/bin"
@mkdir "$(TMPDIR)/example"
@cp -v LICENSE "$(TMPDIR)"
@cp -v README.md "$(TMPDIR)"
@cp -v example/example.json "$(TMPDIR)/example"
@cp -v example/install.sh "$(TMPDIR)/example"
# Move all to temporary directory and compress with common files
tar-everything: copycommon
@mkdir --parents "$(PWD)/release/${VERSION}"
@echo "tar-everything..."
# GNU/Linux
@for arch in $(LINUX_ARCHS); do \
echo "GNU/Linux tar... $$arch"; \
cp -v "$(PWD)/bin/linux-$$arch/${APPNAME}" "$(TMPDIR)/bin"; \
cd "$(TMPDIR)"; \
tar -zcvf "$(PWD)/release/${VERSION}/${APPNAME}-${VERSION}-linux-$$arch.tar.gz" . ; \
rm "$(TMPDIR)/bin/${APPNAME}"; \
done
# Darwin
@for arch in $(DARWIN_ARCHS); do \
echo "Darwin tar... $$arch"; \
cp -v "$(PWD)/bin/darwin-$$arch/${APPNAME}" "$(TMPDIR)/bin"; \
cd "$(TMPDIR)"; \
tar -zcvf "$(PWD)/release/${VERSION}/${APPNAME}-${VERSION}-darwin-$$arch.tar.gz" . ; \
rm "$(TMPDIR)/bin/${APPNAME}"; \
done
# FreeBSD
@for arch in $(FREEBSD_ARCHS); do \
echo "FreeBSD tar... $$arch"; \
cp -v "$(PWD)/bin/freebsd-$$arch/${APPNAME}" "$(TMPDIR)/bin"; \
cd "$(TMPDIR)"; \
tar -zcvf "$(PWD)/release/${VERSION}/${APPNAME}-${VERSION}-freebsd-$$arch.tar.gz" . ; \
rm "$(TMPDIR)/bin/${APPNAME}"; \
done
# OpenBSD
@for arch in $(OPENBSD_ARCHS); do \
echo "OpenBSD tar... $$arch"; \
cp -v "$(PWD)/bin/openbsd-$$arch/${APPNAME}" "$(TMPDIR)/bin"; \
cd "$(TMPDIR)"; \
tar -zcvf "$(PWD)/release/${VERSION}/${APPNAME}-${VERSION}-openbsd-$$arch.tar.gz" . ; \
rm "$(TMPDIR)/bin/${APPNAME}"; \
done
# NetBSD
@for arch in $(NETBSD_ARCHS); do \
echo "NetBSD tar... $$arch"; \
cp -v "$(PWD)/bin/netbsd-$$arch/${APPNAME}" "$(TMPDIR)/bin"; \
cd "$(TMPDIR)"; \
tar -zcvf "$(PWD)/release/${VERSION}/${APPNAME}-${VERSION}-netbsd-$$arch.tar.gz" . ; \
rm "$(TMPDIR)/bin/${APPNAME}"; \
done
#Windows
@for arch in $(WINDOWS_ARCHS); do \
echo "MS Windows zip... $$arch"; \
cp -v "$(PWD)/bin/windows-$$arch/${APPNAME}.exe" "$(TMPDIR)/bin"; \
cd "$(TMPDIR)"; \
zip -9 -y -r "$(PWD)/release/${VERSION}/${APPNAME}-${VERSION}-windows-$$arch.zip" . ; \
rm "$(TMPDIR)/bin/${APPNAME}.exe"; \
done
ldistro-arch: build
pushd release/linux/arch && \
../../../bin/${APPNAME} -name ${APPNAME} -ver ${VERSION} -install install.sh -sums ../../${VERSION}/${CHECKSUMFILE} package.json > "$(PWD)/release/${VERSION}/${APPNAME}-${VERSION}-linux-Arch.PKGBUILD" && \
popd
.PHONY: all clean test default