across/docker/v2ray/build_v2ray.sh

49 lines
1.8 KiB
Bash
Raw Permalink Normal View History

2020-02-18 21:52:01 +09:00
#!/bin/sh
#
# This is a Shell script for build multi-architectures v2ray binary file
#
# Supported architectures: amd64, arm32v6, arm32v7, arm64v8, i386, ppc64le, s390x
#
2022-01-03 15:11:58 +09:00
# Copyright (C) 2020 - 2022 Teddysun <i@teddysun.com>
2020-02-18 21:52:01 +09:00
#
# Reference URL:
2020-10-02 08:51:19 +09:00
# https://github.com/v2fly/v2ray-core.git
2020-02-18 21:52:01 +09:00
cur_dir="$(pwd)"
COMMANDS=( git go )
for CMD in "${COMMANDS[@]}"; do
if [ ! "$(command -v "${CMD}")" ]; then
echo "${CMD} is not installed, please install it and try again" && exit 1
fi
done
cd ${cur_dir}
2020-09-12 20:32:15 +09:00
git clone https://github.com/v2fly/v2ray-core.git
2020-02-18 21:52:01 +09:00
cd v2ray-core || exit 2
2021-08-24 18:43:02 +09:00
LDFLAGS="-s -w -buildid="
2020-02-18 21:52:01 +09:00
ARCHS=( 386 amd64 arm arm64 ppc64le s390x )
ARMS=( 6 7 )
for ARCH in ${ARCHS[@]}; do
if [ "${ARCH}" = "arm" ]; then
for V in ${ARMS[@]}; do
2022-01-03 15:11:58 +09:00
# echo "Building v2ray_linux_${ARCH}${V} and v2ctl_linux_${ARCH}${V}"
echo "Building v2ray_linux_${ARCH}${V}"
2021-08-24 18:43:02 +09:00
env CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} GOARM=${V} go build -v -trimpath -ldflags "${LDFLAGS}" -o ${cur_dir}/v2ray_linux_${ARCH}${V} ./main
2022-01-03 15:11:58 +09:00
# env CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} GOARM=${V} go build -v -trimpath -ldflags "${LDFLAGS}" -tags confonly -o ${cur_dir}/v2ctl_linux_${ARCH}${V} ./infra/control/main
2020-02-18 21:52:01 +09:00
done
else
2022-01-03 15:11:58 +09:00
# echo "Building v2ray_linux_${ARCH} and v2ctl_linux_${ARCH}"
echo "Building v2ray_linux_${ARCH}"
2021-08-24 18:43:02 +09:00
env CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -v -trimpath -ldflags "${LDFLAGS}" -o ${cur_dir}/v2ray_linux_${ARCH} ./main
2022-01-03 15:11:58 +09:00
# env CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -v -trimpath -ldflags "${LDFLAGS}" -tags confonly -o ${cur_dir}/v2ctl_linux_${ARCH} ./infra/control/main
2020-02-18 21:52:01 +09:00
fi
done
2022-01-03 15:11:58 +09:00
# chmod +x ${cur_dir}/v2ray_linux_* ${cur_dir}/v2ctl_linux_*
chmod +x ${cur_dir}/v2ray_linux_*
2020-02-18 21:52:01 +09:00
# clean up
cd ${cur_dir} && rm -fr v2ray-core