maketests 2.5 KB

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