github.com/psiphon-Labs/psiphon-tunnel-core@v2.0.28+incompatible/ClientLibrary/make.bash (about) 1 #!/usr/bin/env bash 2 3 set -e -u -x 4 5 if [ ! -f make.bash ]; then 6 echo "make.bash must be run from $GOPATH/src/github.com/Psiphon-Labs/psiphon-tunnel-core/ClientLibrary" 7 exit 1 8 fi 9 10 # $2, if specified, is go build tags 11 if [ -z ${2+x} ]; then BUILD_TAGS=""; else BUILD_TAGS="$2"; fi 12 13 BUILD_DIR=build 14 15 if [ ! -d ${BUILD_DIR} ]; then 16 mkdir ${BUILD_DIR} 17 fi 18 19 # At this time, we don't support modules 20 export GO111MODULE=off 21 22 prepare_build () { 23 24 BUILDDATE=$(date --iso-8601=seconds) 25 BUILDREPO=$(git config --get remote.origin.url) 26 BUILDREV=$(git rev-parse --short HEAD) 27 GOVERSION=$(go version | perl -ne '/go version (.*?) / && print $1') 28 29 # see DEPENDENCIES comment in MobileLibrary/Android/make.bash 30 DEPENDENCIES=$(echo -n "{" && GOOS=$1 go list -tags "${BUILD_TAGS}" -f '{{range $dep := .Deps}}{{printf "%s\n" $dep}}{{end}}' | GOOS=$1 xargs go list -tags "${BUILD_TAGS}" -f '{{if not .Standard}}{{.ImportPath}}{{end}}' | xargs -I pkg bash -c 'cd $GOPATH/src/$0 && if echo -n "$0" | grep -vEq "^github.com/Psiphon-Labs/psiphon-tunnel-core/" ; then echo -n "\"$0\":\"$(git rev-parse --short HEAD)\"," ; fi' pkg | sed 's/,$//' | tr -d '\n' && echo -n "}") 31 32 LDFLAGS="\ 33 -s \ 34 -w \ 35 -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.buildDate=$BUILDDATE \ 36 -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.buildRepo=$BUILDREPO \ 37 -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.buildRev=$BUILDREV \ 38 -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.goVersion=$GOVERSION \ 39 -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.dependencies=$DEPENDENCIES \ 40 " 41 42 echo "Variables for ldflags:" 43 echo " Build date: ${BUILDDATE}" 44 echo " Build repo: ${BUILDREPO}" 45 echo " Build revision: ${BUILDREV}" 46 echo " Go version: ${GOVERSION}" 47 echo " Dependencies: ${DEPENDENCIES}" 48 echo "" 49 50 } 51 52 53 build_for_android () { 54 55 TARGET_OS=android 56 OUTPUT_DIR="${BUILD_DIR}/${TARGET_OS}" 57 58 prepare_build android 59 60 TARGET_ARCH=arm 61 ARMV=7 62 63 CC="${ANDROID_NDK_TOOLCHAIN_ROOT}/${TARGET_ARCH}/bin/arm-linux-androideabi-clang" \ 64 CXX="${ANDROID_NDK_TOOLCHAIN_ROOT}/${TARGET_ARCH}/bin/arm-linux-androideabi-clang++" \ 65 GOARM=${ARMV} \ 66 GOOS=${TARGET_OS} GOARCH=${TARGET_ARCH} go build -buildmode=c-shared -ldflags "$LDFLAGS" -tags "${BUILD_TAGS}" -o "${OUTPUT_DIR}/${TARGET_ARCH}${ARMV}/libpsiphontunnel.so" PsiphonTunnel.go 67 68 69 TARGET_ARCH=arm64 70 71 CC="${ANDROID_NDK_TOOLCHAIN_ROOT}/${TARGET_ARCH}/bin/aarch64-linux-android-clang" \ 72 CXX="${ANDROID_NDK_TOOLCHAIN_ROOT}/${TARGET_ARCH}/bin/aarch64-linux-android-clang++" \ 73 GOOS=${TARGET_OS} GOARCH=${TARGET_ARCH} go build -buildmode=c-shared -ldflags "$LDFLAGS" -tags "${BUILD_TAGS}" -o "${OUTPUT_DIR}/${TARGET_ARCH}/libpsiphontunnel.so" PsiphonTunnel.go 74 75 } 76 77 78 build_for_linux () { 79 80 TARGET_OS=linux 81 OUTPUT_DIR="${BUILD_DIR}/${TARGET_OS}" 82 83 prepare_build linux 84 85 TARGET_ARCH=386 86 # TODO: is "CFLAGS=-m32" required? 87 CFLAGS=-m32 \ 88 GOOS=${TARGET_OS} GOARCH=${TARGET_ARCH} go build -buildmode=c-shared -ldflags "$LDFLAGS" -tags "${BUILD_TAGS}" -o "${OUTPUT_DIR}/${TARGET_ARCH}/libpsiphontunnel.so" PsiphonTunnel.go 89 90 91 TARGET_ARCH=amd64 92 GOOS=${TARGET_OS} GOARCH=${TARGET_ARCH} go build -buildmode=c-shared -ldflags "$LDFLAGS" -tags "${BUILD_TAGS}" -o "${OUTPUT_DIR}/${TARGET_ARCH}/libpsiphontunnel.so" PsiphonTunnel.go 93 94 } 95 96 97 build_for_windows () { 98 99 TARGET_OS=windows 100 OUTPUT_DIR="${BUILD_DIR}/${TARGET_OS}" 101 102 prepare_build windows 103 104 TARGET_ARCH=386 105 106 CGO_ENABLED=1 \ 107 CGO_LDFLAGS="-static-libgcc -L /usr/i686-w64-mingw32/lib/ -lwsock32 -lcrypt32 -lgdi32" \ 108 CC=/usr/bin/i686-w64-mingw32-gcc \ 109 GOOS=${TARGET_OS} GOARCH=${TARGET_ARCH} go build -buildmode=c-shared -ldflags "$LDFLAGS" -tags "${BUILD_TAGS}" -o "${OUTPUT_DIR}/${TARGET_ARCH}/psiphontunnel.dll" PsiphonTunnel.go 110 111 112 TARGET_ARCH=amd64 113 114 CGO_ENABLED=1 \ 115 CGO_LDFLAGS="-static-libgcc -L /usr/x86_64-w64-mingw32/lib/ -lwsock32 -lcrypt32 -lgdi32" \ 116 CC=/usr/bin/x86_64-w64-mingw32-gcc \ 117 GOOS=${TARGET_OS} GOARCH=${TARGET_ARCH} go build -buildmode=c-shared -ldflags "$LDFLAGS" -tags "${BUILD_TAGS}" -o "${OUTPUT_DIR}/${TARGET_ARCH}/psiphontunnel.dll" PsiphonTunnel.go 118 119 } 120 121 122 build_for_ios () { 123 124 echo "To build for iOS please use build-darwin.sh" 125 126 } 127 128 129 build_for_macos () { 130 131 echo "To build for macos please use build-darwin.sh" 132 133 } 134 135 136 TARGET=$1 137 case $TARGET in 138 windows) 139 echo "..Building for Windows" 140 build_for_windows 141 exit $? 142 143 ;; 144 linux) 145 echo "..Building for Linux" 146 build_for_linux 147 exit $? 148 149 ;; 150 macos) 151 echo "..Building for MacOS" 152 build_for_macos 153 exit $? 154 155 ;; 156 android) 157 echo "..Building for Android" 158 build_for_android 159 exit $? 160 161 ;; 162 ios) 163 echo "..Building for iOS" 164 build_for_ios 165 exit $? 166 167 ;; 168 all) 169 echo "..Building all" 170 build_for_windows 171 if [ $? != 0 ]; then 172 exit $? 173 fi 174 175 build_for_linux 176 if [ $? != 0 ]; then 177 exit $? 178 fi 179 180 build_for_macos 181 if [ $? != 0 ]; then 182 exit $? 183 fi 184 185 build_for_android 186 if [ $? != 0 ]; then 187 exit $? 188 fi 189 190 build_for_ios 191 if [ $? != 0 ]; then 192 exit $? 193 fi 194 195 ;; 196 *) 197 echo "..invalid target" 198 exit 1 199 200 201 ;; 202 203 esac 204 205 echo "BUILD DONE"