1#! /bin/bash
2#
3#   Builds czmq.node package from a fresh git clone
4#
5################################################################################
6#  THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY  #
7#  Read the zproject/README.md for information about making permanent changes. #
8################################################################################
9#
10set -e                      #   exit on any error
11FORCE=0
12VERBOSE=0
13QUIET="--quiet"
14LOGLEVEL="--loglevel=error"
15
16for ARG in $*; do
17    if [ "$ARG" == "--help" -o "$ARG" == "-h" ]; then
18        echo "build.sh"
19        echo " --help / -h          This help"
20        echo " --force / -f         Force full rebuild"
21        echo " --verbose / -v       Show build output"
22        echo " --xverbose / -x      Extra verbose"
23        exit
24    elif [ "$ARG" == "--force" -o "$ARG" == "-f" ]; then
25        FORCE=1
26    elif [ "$ARG" == "--verbose" -o "$ARG" == "-v" ]; then
27        VERBOSE=1
28        QUIET=""
29        LOGLEVEL=""
30    elif [ "$ARG" == "--xverbose" -o "$ARG" == "-x" ]; then
31        VERBOSE=1
32        QUIET=""
33        LOGLEVEL="--loglevel=verbose"
34        set -x
35    fi
36done
37
38BUILD_ROOT=`pwd`
39cd ../../..
40
41#   Check dependent projects
42if [ ! -d libzmq ]; then
43    echo "I:    cloning https://github.com/zeromq/libzmq.git into `pwd`/libzmq..."
44    git clone $QUIET https://github.com/zeromq/libzmq.git
45fi
46if [ ! -f libzmq/builds/gyp/project.gyp ]; then
47    echo "E:    `pwd`/libzmq out of date (builds/gyp/project.gyp missing)"
48    exit
49fi
50
51
52#   Check Node.js dependencies
53cd $BUILD_ROOT
54echo "I: checking Node.js dependencies..."
55
56failed=0
57set +e
58for package in node-ninja bindings nan prebuild; do
59    npm list --depth 1 $package > /dev/null 2>&1
60    if [ $? -eq 1 ]; then
61        npm list --global --depth 1 $package > /dev/null 2>&1
62        if [ $? -eq 1 ]; then
63            echo "E: $package isn't installed, run 'npm install [-g] $package'"
64            failed=1
65        fi
66    fi
67done
68test $failed -eq 0 || exit
69set -e
70
71#   Calculate how many compiles we can do in parallel
72export JOBS=$([[ $(uname) = 'Darwin' ]] \
73    && sysctl -n hw.logicalcpu_max \
74    || lscpu -p | egrep -v '^#' | wc -l)
75
76#   Build the binding using node-ninja directly, not prebuild
77echo "I: building Node.js binding:"
78node-ninja configure
79node-ninja build
80