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