1#! /bin/sh 2# Build tests/* executables; assumes that libzmq.a or libzmq.so/libzmq.x 3# is already built 4# 5# If libzmq.so and libzmq.x exist, then dynamic linking is used, otherwise 6# static linking is used. 7# 8# Written by Ewen McNeill <ewen@imatix.com>, 2014-07-21 9# Updated by Ewen McNeill <ewen@imatix.com>, 2014-07-22 10#--------------------------------------------------------------------------- 11 12set -e # Stop on errors 13 14VERBOSE="${VERBOSE:-}" # Set to non-empty for already done status 15export VERBOSE 16 17# Figure out where we are 18BIN_DIR=$(dirname $0) 19if [ -z "${BIN_DIR}" ]; then BIN_DIR="."; fi 20case "${BIN_DIR}" in 21 .) BIN_DIR="$(pwd)"; ;; 22 /*) ;; 23 *) BIN_DIR="$(pwd)/${BIN_DIR}"; ;; 24esac 25 26# Locate compiler wrapper 27ZCXX="${BIN_DIR}/zc++" 28 29# Locate top of source tree, assuming we're in builds/zos 30TOP="${BIN_DIR}/../.." 31SRC="${TOP}/src" 32TESTS="${TOP}/tests" 33 34# Figure out how we are going to link to ZMQ 35LINK_TYPE=unknown 36 37if [ -f "${SRC}/platform.hpp" -a -f "${SRC}/libzmq.so" -a -f "${SRC}/libzmq.x" ]; then 38 LINK_TYPE=dynamic 39elif [ -f "${SRC}/platform.hpp" -a -f "${SRC}/libzmq.a" ]; then 40 LINK_TYPE=static 41else 42 echo "Error: run makezmqlib to build libzmq.a and/or libzmq.so/libzmq.x first" >&2 43 exit 1 44fi 45 46# Copy in replacement test with timeout, if main version is not already 47# up to date 48# 49if [ -f "${TESTS}/test_fork.cpp" ] && 50 grep "TIMEOUT" "${TESTS}/test_fork.cpp" >/dev/null 2>&1; then 51 : # Already copied in 52else 53 echo "Updating test_fork.cpp to version with master timeout" 54 cp -p "${BIN_DIR}/test_fork.cpp" "${TESTS}/test_fork.cpp" 55fi 56 57# Compile all the source 58if [ "${LINK_TYPE}" = "dynamic" ]; then 59 ZCXXFLAGS="${ZCXXFLAGS} -Wc,DLL" 60 export ZXCCFLAGS 61 echo "Building tests to use DLL: ${ZCXXFLAGS}" 62fi 63 64cd "${TESTS}" 65"${BIN_DIR}/cxxall" 66 67# Link all the executables that are not already linked 68skip() { 69 OBJ="$1" 70 EXE="$2" 71 if [ -n "${VERBOSE}" ]; then 72 echo "${OBJ} linked to ${EXE}" 73 fi 74} 75 76link() { 77 OBJ="$1" 78 EXE="$2" 79 echo " LD ${EXE}" 80 case "${LINK_TYPE}" in 81 static) "${ZCXX}" -L ../src -o "${EXE}" "${OBJ}" -lzmq 82 ;; 83 dynamic) "${ZCXX}" -o "${EXE}" "${OBJ}" ../src/libzmq.x 84 ;; 85 *) echo "Do not know how to do ${LINK_TYPE} linking!" 2>&1 86 exit 1 87 ;; 88 esac 89} 90 91for OBJ in *.o; do 92 EXE=$(echo "${OBJ}" | sed 's/\.o//;') 93 if [ -f "${EXE}" ]; then 94 if [ "${EXE}" -nt "${OBJ}" ]; then 95 skip "${OBJ}" "${EXE}" 96 else 97 link "${OBJ}" "${EXE}" 98 fi 99 else 100 link "${OBJ}" "${EXE}" 101 fi 102done 103