1#!/usr/bin/env bash
2
3# Licensed to the Apache Software Foundation (ASF) under one
4# or more contributor license agreements.  See the NOTICE file
5# distributed with this work for additional information
6# regarding copyright ownership.  The ASF licenses this file
7# to you under the Apache License, Version 2.0 (the
8# "License"); you may not use this file except in compliance
9# with the License.  You may obtain a copy of the License at
10#
11#   http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing,
14# software distributed under the License is distributed on an
15# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16# KIND, either express or implied.  See the License for the
17# specific language governing permissions and limitations
18# under the License.
19
20# This script builds the static library of zeroMQ that can be used as dependency of mxnet.
21set -ex
22ZEROMQ_VERSION=4.2.2
23if [[ $PLATFORM == 'darwin' ]]; then
24    DY_EXT="dylib"
25else
26    DY_EXT="so"
27fi
28
29if [[ ! -f $DEPS_PATH/lib/libzmq.a ]]; then
30    # Download and build zmq
31    >&2 echo "Building zmq..."
32    download \
33        https://github.com/zeromq/libzmq/archive/v${ZEROMQ_VERSION}.zip \
34        ${DEPS_PATH}/zeromq.zip
35    unzip -q $DEPS_PATH/zeromq.zip -d $DEPS_PATH
36    mkdir -p $DEPS_PATH/libzmq-$ZEROMQ_VERSION/build
37    pushd .
38    cd $DEPS_PATH/libzmq-$ZEROMQ_VERSION/build
39    cmake \
40          -D CMAKE_BUILD_TYPE=RELEASE \
41          -D CMAKE_INSTALL_PREFIX=$DEPS_PATH \
42          -D WITH_LIBSODIUM=OFF \
43          -D BUILD_SHARED_LIBS=OFF ..
44    $MAKE
45    $MAKE install
46
47    if [[ ! -f $DEPS_PATH/lib/libzmq.a ]]; then
48        rm $DEPS_PATH/lib64/*zmq*$DY_EXT*
49        mkdir -p $DEPS_PATH/lib
50        cp $DEPS_PATH/lib64/*zmq* $DEPS_PATH/lib
51    else
52        rm $DEPS_PATH/lib/*zmq*$DY_EXT*
53    fi
54
55    popd
56fi