github.com/psiphon-labs/psiphon-tunnel-core@v2.0.28+incompatible/ConsoleClient/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/ConsoleClient" 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 # At this time, we don't support modules 14 export GO111MODULE=off 15 16 EXE_BASENAME="psiphon-tunnel-core" 17 18 prepare_build () { 19 BUILDINFOFILE="${EXE_BASENAME}_buildinfo.txt" 20 BUILDDATE=$(date --iso-8601=seconds) 21 BUILDREPO=$(git config --get remote.origin.url) 22 BUILDREV=$(git rev-parse --short HEAD) 23 GOVERSION=$(go version | perl -ne '/go version (.*?) / && print $1') 24 25 # see DEPENDENCIES comment in MobileLibrary/Android/make.bash 26 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 "}") 27 28 LDFLAGS="\ 29 -s \ 30 -w \ 31 -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.buildDate=$BUILDDATE \ 32 -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.buildRepo=$BUILDREPO \ 33 -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.buildRev=$BUILDREV \ 34 -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.goVersion=$GOVERSION \ 35 -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.dependencies=$DEPENDENCIES \ 36 " 37 echo -e "${BUILDDATE}\n${BUILDREPO}\n${BUILDREV}\n" > $BUILDINFOFILE 38 39 echo "Variables for ldflags:" 40 echo " Build date: ${BUILDDATE}" 41 echo " Build repo: ${BUILDREPO}" 42 echo " Build revision: ${BUILDREV}" 43 echo " Go version: ${GOVERSION}" 44 echo " Dependencies: ${DEPENDENCIES}" 45 echo "" 46 } 47 48 if [ ! -d bin ]; then 49 mkdir bin 50 fi 51 52 build_for_windows () { 53 prepare_build windows 54 55 echo "...Building windows-i686" 56 57 CGO_LDFLAGS="-L /usr/i686-w64-mingw32/lib/ -lwsock32 -lcrypt32 -lgdi32" \ 58 CC=/usr/bin/i686-w64-mingw32-gcc \ 59 GOOS=windows GOARCH=386 go build -v -x -ldflags "$LDFLAGS" -tags "${BUILD_TAGS}" -o bin/windows/${EXE_BASENAME}-i686.exe 60 RETVAL=$? 61 echo ".....gox completed, exit code: $?" 62 if [ $RETVAL != 0 ]; then 63 echo ".....gox failed, exiting" 64 exit $RETVAL 65 fi 66 unset RETVAL 67 68 ## We are finding that UPXing the full Windows Psiphon client produces better results if psiphon-tunnel-core.exe is not already UPX'd. 69 echo "....No UPX for this build" 70 71 echo "...Building windows-x86_64" 72 73 CGO_LDFLAGS="-L /usr/x86_64-w64-mingw32/lib/ -lwsock32 -lcrypt32 -lgdi32" \ 74 CC=/usr/bin/x86_64-w64-mingw32-gcc \ 75 GOOS=windows GOARCH=amd64 go build -v -x -ldflags "$LDFLAGS" -tags "${BUILD_TAGS}" -o bin/windows/${EXE_BASENAME}-x86_64.exe 76 RETVAL=$? 77 if [ $RETVAL != 0 ]; then 78 echo ".....gox failed, exiting" 79 exit $RETVAL 80 fi 81 unset RETVAL 82 83 # We are finding that UPXing the full Windows Psiphon client produces better results if psiphon-tunnel-core.exe is not already UPX'd. 84 echo "....No UPX for this build" 85 } 86 87 build_for_linux () { 88 prepare_build linux 89 90 echo "...Building linux-i686" 91 # TODO: is "CFLAGS=-m32" required? 92 CFLAGS=-m32 GOOS=linux GOARCH=386 go build -v -x -ldflags "$LDFLAGS" -tags "${BUILD_TAGS}" -o bin/linux/${EXE_BASENAME}-i686 93 RETVAL=$? 94 if [ $RETVAL != 0 ]; then 95 echo ".....gox failed, exiting" 96 exit $RETVAL 97 fi 98 unset RETVAL 99 100 echo "....UPX packaging output" 101 goupx --best bin/linux/${EXE_BASENAME}-i686 102 RETVAL=$? 103 if [ $RETVAL != 0 ]; then 104 echo ".....goupx failed, exiting" 105 exit $RETVAL 106 fi 107 unset RETVAL 108 109 echo "...Building linux-x86_64" 110 GOOS=linux GOARCH=amd64 go build -v -x -ldflags "$LDFLAGS" -tags "${BUILD_TAGS}" -o bin/linux/${EXE_BASENAME}-x86_64 111 RETVAL=$? 112 if [ $RETVAL != 0 ]; then 113 echo "....gox failed, exiting" 114 exit $RETVAL 115 fi 116 unset RETVAL 117 118 echo "....UPX packaging output" 119 goupx --best bin/linux/${EXE_BASENAME}-x86_64 120 RETVAL=$? 121 if [ $RETVAL != 0 ]; then 122 echo ".....goupx failed, exiting" 123 exit $RETVAL 124 fi 125 unset RETVAL 126 } 127 128 build_for_osx () { 129 prepare_build darwin 130 131 echo "Building darwin-x86_64..." 132 echo "..Disabling CGO for this build" 133 # TODO: is "CGO_ENABLED=0" required? 134 CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -v -x -ldflags "$LDFLAGS" -tags "${BUILD_TAGS}" -o bin/darwin/${EXE_BASENAME}-x86_64 135 # Darwin binaries don't seem to be UPXable when built this way 136 echo "..No UPX for this build" 137 } 138 139 TARGET=$1 140 case $TARGET in 141 windows) 142 echo "..Building for Windows" 143 build_for_windows 144 exit $? 145 146 ;; 147 linux) 148 echo "..Building for Linux" 149 build_for_linux 150 exit $? 151 152 ;; 153 osx) 154 echo "..Building for OSX" 155 build_for_osx 156 exit $? 157 158 ;; 159 all) 160 echo "..Building all" 161 build_for_windows 162 if [ $? != 0 ]; then 163 exit $? 164 fi 165 166 build_for_linux 167 if [ $? != 0 ]; then 168 exit $? 169 fi 170 171 build_for_osx 172 if [ $? != 0 ]; then 173 exit $? 174 fi 175 176 ;; 177 *) 178 echo "..invalid target" 179 exit 1 180 181 ;; 182 183 esac 184 185 echo "Done"