Adding mingw64 (msys2) to build script

This commit is contained in:
Nicolas Dextraze 2018-03-17 11:28:23 -07:00
parent 996431a4d9
commit da907dbbd8

View File

@ -1,30 +1,92 @@
#!/bin/bash
case "$(uname -s)" in
Linux*) platform=linux;;
Darwin*) platform=unsupported;;
CYGWIN*) platform=unsupported;;
MINGW*) platform=mingw;;
*) platform=unsupported
esac
if [ "$platform" == "unsupported" ]; then
echo "Error: Unsupported platform $(uname -s)"
exit
fi
# check for dependencies
if [ ! "$(which pacman)" == "" ]; then
pacman -S --needed --noconfirm msys/autoconf msys/automake-wrapper msys/libtool msys/pkg-config msys/git
fi
git=`which git`
if [ "$git" == "" ]; then
echo "Error: Git not found in PATH"
exit -1
fi
go=`which go`
if [ "$go" == "" ]; then
echo "Error: Go not found in PATH"
exit -1
fi
# clean
rm -rf bin
# create folders
mkdir .go
mkdir .deps
if [ ! -e .deps ]; then
mkdir .deps
fi
# get and build libzmq
cd .deps
git clone https://github.com/zeromq/libzmq
if [ ! -e libzmq ]; then
git clone https://github.com/zeromq/libzmq
fi
cd libzmq
git checkout v4.2.3
./autogen.sh && ./configure && make
if [ ! -e Makefile ]; then
./autogen.sh && ./configure --enable-static
fi
if [ "$platform" == "mingw" ]; then
sed -i 's/MAKE=make/MAKE=mingw32-make/' Makefile
mingw32-make
else
make
fi
cd ../..
# get and build go zmq4
GOPATH=`pwd`/.go
go get
GOPATH=`pwd`/.deps go get
# use built libzmq
ESC_PWD=`pwd | sed 's/\//\\\\\//g'`
cflags="\#cgo \!windows CFLAGS\: \-I${ESC_PWD}\/\.deps\/libzmq\/include"
ldflags="\#cgo \!windows LDFLAGS\: ${ESC_PWD}\/\.deps\/libzmq\/src\/\.libs\/libzmq\.a \-lstdc\+\+ \-lm"
sed -i "4s/.*/${cflags}/" .go/src/github.com/pebbe/zmq4/zmq4.go
sed -i "5s/.*/${ldflags}/" .go/src/github.com/pebbe/zmq4/zmq4.go
if [ "$platform" == "linux" ]; then
ESC_PWD=`pwd | sed 's/\//\\\\\//g'`
cflags="\#cgo \!windows CFLAGS\: \-I${ESC_PWD}\/\.deps\/libzmq\/include"
ldflags="\#cgo \!windows LDFLAGS\: ${ESC_PWD}\/\.deps\/libzmq\/src\/\.libs\/libzmq\.a \-lstdc\+\+ \-lm"
sed -i "4s/.*/${cflags}/" .deps/src/github.com/pebbe/zmq4/zmq4.go
sed -i "5s/.*/${ldflags}/" .deps/src/github.com/pebbe/zmq4/zmq4.go
fi
if [ "$platform" == "mingw" ]; then
ESC_PWD=`pwd | sed 's/\/\(.\)/\1:/' | sed 's/\//\\\\\//g'`
cflags="\#cgo windows CFLAGS\: \-I${ESC_PWD}\/\.deps\/libzmq\/include \-DZMQ_STATIC"
ldflags="\#cgo windows LDFLAGS\: ${ESC_PWD}\/\.deps\/libzmq\/src\/\.libs\/libzmq\.a -lstdc++ -lwsock32 -lws2_32 -lIphlpapi"
sed -i "5s/.*/${cflags}/" .deps/src/github.com/pebbe/zmq4/zmq4.go
sed -i "6s/.*/${ldflags}/" .deps/src/github.com/pebbe/zmq4/zmq4.go
fi
# build goes
go build -a -ldflags '-s' -o bin/goes goes.go
OUTPUT=bin/goes
if [ "$platform" == "mingw" ]; then
OUTPUT=bin/goes.exe
fi
GOPATH=`pwd`/.deps go build -a -ldflags '-s' -o ${OUTPUT} goes.go
# copy libstdc++ deps mingw
if [ "$platform" == "mingw" ]; then
cp /mingw64/bin/libstd*.dll bin
cp /mingw64/bin/libgcc*.dll bin
cp /mingw64/bin/libwin*.dll bin
fi
# copy licenses
cp .deps/libzmq/COPYING bin/libzmq.COPYING
@ -32,4 +94,3 @@ cp .deps/libzmq/COPYING.LESSER bin/libzmq.COPYING.LESSER
cp LICENSE bin/LICENSE
tar -czvf goes.tar.gz bin/