1
1
#! /usr/bin/env bash
2
2
3
3
name=plexStats
4
+ export CGO_ENABLED=1
5
+
6
+ platforms=(
7
+ linux-amd64 windows-amd64
8
+ linux-386 windows-386
9
+ linux-armv5 linux-armv6 linux-armv7
10
+ # linux-armv8
11
+ )
4
12
5
13
checkCommand () {
6
14
which " $1 " > /dev/null 2>&1
@@ -16,13 +24,6 @@ checkCommand zip
16
24
17
25
DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
18
26
19
- # NOTE: The build process is somewhat similar to https://github.com/syncthing/syncthing, thanks for that!
20
- platforms=(
21
- linux-amd64 windows-amd64 darwin-amd64 dragonfly-amd64 freebsd-amd64 netbsd-amd64 openbsd-amd64 solaris-amd64
22
- freebsd-386 linux-386 netbsd-386 openbsd-386 windows-386
23
- linux-arm linux-arm64 linux-ppc64 linux-ppc64le
24
- )
25
-
26
27
cd " $DIR "
27
28
commit=" $( git rev-parse --short HEAD 2> /dev/null) "
28
29
date=" $( date --iso-8601=seconds) "
@@ -42,18 +43,37 @@ rm -Rf ./bin/
42
43
mkdir ./bin/ 2> /dev/null
43
44
44
45
for plat in " ${platforms[@]} " ; do
45
- echo Building " $plat " ...
46
-
47
- GOOS=" ${plat% -* } "
48
- GOARCH=" ${plat#* -} "
46
+ export GOOS=" ${plat% -* } "
47
+ export GOARCH=" ${plat#* -} "
49
48
50
49
if [ " $GOOS " != " windows" ]; then
51
50
tmpFile=" /tmp/${name} /bin/${name} "
52
51
else
53
52
tmpFile=" /tmp/${name} /bin/${name} .exe"
54
53
fi
55
54
56
- GOOS=" ${plat% -* } " GOARCH=" ${plat#* -} " go build -ldflags ' -X main.VERSION=' " $version " ' -X main.BUILD_COMMIT=' " $commit " ' -X main.BUILD_DATE=' " $date " \
55
+ if [ " $CGO_ENABLED " == 1 ]; then
56
+ if [ " $plat " = " windows-amd64" ]; then
57
+ export CC=x86_64-w64-mingw32-gcc
58
+ elif [ " $plat " = " windows-386" ]; then
59
+ export CC=i686-w64-mingw32-gcc
60
+ elif [ " ${GOARCH% v* } " = " arm" ]; then
61
+ export GOARM=" ${GOARCH#* v} "
62
+ if [ " GOARM" = 8 ]; then
63
+ unset GOARM=" "
64
+ export CC=armv8l-linux-gnueabihf-gcc
65
+ export GOARCH=" arm64"
66
+ else
67
+ export CC=arm-linux-gnueabihf-gcc
68
+ export GOARCH=" arm"
69
+ fi
70
+ else
71
+ export CC=gcc
72
+ fi
73
+ fi
74
+
75
+ echo Building " $plat " with " $CC " ...
76
+ go build -ldflags ' -extld=' " $CC " ' -X main.VERSION=' " $version " ' -X main.BUILD_COMMIT=' " $commit " ' -X main.BUILD_DATE=' " $date " \
57
77
-o " $tmpFile " " $DIR " /* .go
58
78
59
79
if [ " $? " != 0 ]; then
0 commit comments