-
Notifications
You must be signed in to change notification settings - Fork 1
/
compile
executable file
·112 lines (93 loc) · 3.81 KB
/
compile
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
#!/bin/bash
declare -r PKG_NAME="${PWD##*/}";
declare -r OS_LINUX="linux";
declare -r OS_MAC="darwin";
declare -r OS_WINDOWS="windows";
declare -r OS_ANDROID="android";
declare -r ARCH_32="386";
declare -r ARCH_64="amd64";
declare -r ARCH_32_ARM="arm";
# declare -r ARCH_64_ARM="arm64";
# Capitalize the first letter of a string.
_capitalize() {
# For Bash 4+:
echo "${1^}";
# For zsh:
# echo "${(C)1}";
};
# Run `go build` and move the compiled binary to its destination folder.
_build() {
if [ -e "${PKG_NAME}" ]; then
gvfs-trash "${PKG_NAME}";
fi;
local os="${1}";
local arch="${2}";
GOOS="${1}" GOARCH="${2}" go build;
if [ $? != 0 ]; then
local statusCode=$?;
echo "Build failed for '${os}' on '${arch}' architecture";
exit "${statusCode}";
else
echo "Build successful for '${os}' on '${arch}' architecture";
fi;
local binary="${PKG_NAME}";
if [ "${os}" = "${OS_WINDOWS}" ]; then
binary="${PKG_NAME}.exe";
fi;
local osCapitalized;
osCapitalized="$(_capitalize "${os}")";
local bits="32";
if [ "${arch: -2}" = "64" ]; then
bits="64";
fi;
local dst="${osCapitalized}_${bits}";
mv "${binary}" "${dst}/";
if [ $? != 0 ]; then
local statusCode=$?;
echo "Failed to move '${PKG_NAME}' to '${dst}/'";
exit "${statusCode}";
fi;
};
_buildAndroid() {
# _build "${OS_ANDROID}" "${ARCH_32_ARM}";
# _build "${OS_ANDROID}" "${ARCH_64_ARM}";
##############################
# THIS ONE ACTUALLY WORKS!!!!!
##############################
# Add '-x' for verbose output
# GOMOBILE="${GOPATH}/pkg/gomobile" GOOS="android" GOARCH="arm" CC="${GOMOBILE}/android-ndk-r12b/arm/bin/arm-linux-androideabi-clang" CXX="${GOMOBILE}/android-ndk-r12b/arm/bin/arm-linux-androideabi-clang++" CGO_CFLAGS="-target armv7a-none-linux-androideabi --sysroot ${GOMOBILE}/android-ndk-r12b/arm/sysroot" CGO_CPPFLAGS="-target armv7a-none-linux-androideabi --sysroot ${GOMOBILE}/android-ndk-r12b/arm/sysroot" CGO_LDFLAGS="-target armv7a-none-linux-androideabi --sysroot ${GOMOBILE}/android-ndk-r12b/arm/sysroot" CGO_ENABLED=1 GOARM=7 go build -pkgdir="${GOMOBILE}/pkg_android_arm" -tags="" -ldflags="-extldflags=-pie" -buildmode="c-shared" -o "${GOPATH}/src/github.com/GreenRaccoon23/snapzip/Android_32/snapzip" "github.com/GreenRaccoon23/snapzip";
GOMOBILE="${GOPATH}/pkg/gomobile" \
GOOS="android" \
GOARCH="arm" \
CC="${GOMOBILE}/android-ndk-r12b/arm/bin/arm-linux-androideabi-clang" \
CXX="${GOMOBILE}/android-ndk-r12b/arm/bin/arm-linux-androideabi-clang++" \
CGO_CFLAGS="-target armv7a-none-linux-androideabi --sysroot ${GOMOBILE}/android-ndk-r12b/arm/sysroot" \
CGO_CPPFLAGS="-target armv7a-none-linux-androideabi --sysroot ${GOMOBILE}/android-ndk-r12b/arm/sysroot" \
CGO_LDFLAGS="-target armv7a-none-linux-androideabi --sysroot ${GOMOBILE}/android-ndk-r12b/arm/sysroot" \
CGO_ENABLED=1 \
GOARM=7 \
go build \
-pkgdir="${GOMOBILE}/pkg_android_arm" \
-tags="" \
-ldflags="-extldflags=-pie" \
-buildmode="c-shared" \
-o "${GOPATH}/src/github.com/GreenRaccoon23/snapzip/Android_32/snapzip" \
"github.com/GreenRaccoon23/snapzip";
if [ $? != 0 ]; then
local statusCode=$?;
echo "Build failed for '${OS_ANDROID}' on '${ARCH_32_ARM}' architecture";
exit "${statusCode}";
else
echo "Build successful for '${OS_ANDROID}' on '${ARCH_32_ARM}' architecture";
fi;
};
_main() {
local os;
for os in "${OS_LINUX}" "${OS_MAC}" "${OS_WINDOWS}"; do
# for os in "${OS_WINDOWS}" "${OS_LINUX}" "${OS_MAC}"; do
_build "${os}" "${ARCH_32}";
_build "${os}" "${ARCH_64}";
done;
_buildAndroid;
};
_main;