2019-02-26 21:30:03 +01:00
|
|
|
# Utility function for golang-using packages to setup a go toolchain.
|
|
|
|
termux_setup_golang() {
|
|
|
|
export GOOS=android
|
|
|
|
export CGO_ENABLED=1
|
|
|
|
export GO_LDFLAGS="-extldflags=-pie"
|
2019-03-10 22:27:52 +01:00
|
|
|
export CGO_LDFLAGS="$LDFLAGS"
|
2019-07-19 10:22:31 +02:00
|
|
|
export CGO_CFLAGS="-I$TERMUX_PREFIX/include"
|
2019-02-26 21:30:03 +01:00
|
|
|
if [ "$TERMUX_ARCH" = "arm" ]; then
|
|
|
|
export GOARCH=arm
|
|
|
|
export GOARM=7
|
|
|
|
elif [ "$TERMUX_ARCH" = "i686" ]; then
|
|
|
|
export GOARCH=386
|
|
|
|
export GO386=sse2
|
|
|
|
elif [ "$TERMUX_ARCH" = "aarch64" ]; then
|
|
|
|
export GOARCH=arm64
|
|
|
|
elif [ "$TERMUX_ARCH" = "x86_64" ]; then
|
|
|
|
export GOARCH=amd64
|
|
|
|
else
|
|
|
|
termux_error_exit "Unsupported arch: $TERMUX_ARCH"
|
|
|
|
fi
|
|
|
|
|
2019-08-06 14:39:42 +02:00
|
|
|
if [ -z "$TERMUX_ON_DEVICE_BUILD" ]; then
|
|
|
|
local TERMUX_GO_VERSION=go1.12.7
|
|
|
|
local TERMUX_GO_PLATFORM=linux-amd64
|
2019-02-26 21:30:03 +01:00
|
|
|
|
2019-08-06 14:39:42 +02:00
|
|
|
local TERMUX_BUILDGO_FOLDER=$TERMUX_COMMON_CACHEDIR/${TERMUX_GO_VERSION}
|
|
|
|
export GOROOT=$TERMUX_BUILDGO_FOLDER
|
|
|
|
export PATH=$GOROOT/bin:$PATH
|
2019-02-26 21:30:03 +01:00
|
|
|
|
2019-08-06 14:39:42 +02:00
|
|
|
if [ -d "$TERMUX_BUILDGO_FOLDER" ]; then return; fi
|
2019-02-26 21:30:03 +01:00
|
|
|
|
2019-08-06 14:39:42 +02:00
|
|
|
local TERMUX_BUILDGO_TAR=$TERMUX_COMMON_CACHEDIR/${TERMUX_GO_VERSION}.${TERMUX_GO_PLATFORM}.tar.gz
|
|
|
|
rm -Rf "$TERMUX_COMMON_CACHEDIR/go" "$TERMUX_BUILDGO_FOLDER"
|
|
|
|
termux_download https://storage.googleapis.com/golang/${TERMUX_GO_VERSION}.${TERMUX_GO_PLATFORM}.tar.gz \
|
|
|
|
"$TERMUX_BUILDGO_TAR" \
|
|
|
|
66d83bfb5a9ede000e33c6579a91a29e6b101829ad41fffb5c5bb6c900e109d9
|
2019-02-26 21:30:03 +01:00
|
|
|
|
2019-08-06 14:39:42 +02:00
|
|
|
( cd "$TERMUX_COMMON_CACHEDIR"; tar xf "$TERMUX_BUILDGO_TAR"; mv go "$TERMUX_BUILDGO_FOLDER"; rm "$TERMUX_BUILDGO_TAR" )
|
|
|
|
else
|
|
|
|
if [ "$(dpkg-query -W -f '${db:Status-Status}\n' golang 2>/dev/null)" != "installed" ]; then
|
|
|
|
echo "Package 'golang' is not installed."
|
|
|
|
echo "You can install it with"
|
|
|
|
echo
|
|
|
|
echo " pkg install golang"
|
|
|
|
echo
|
|
|
|
echo "or build it from source with"
|
|
|
|
echo
|
|
|
|
echo " ./build-package.sh golang"
|
|
|
|
echo
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
2019-02-26 21:30:03 +01:00
|
|
|
}
|