| 1 | #! /bin/sh |
| 2 | # Attempt to compile all *.cpp files in the current directory, that are |
| 3 | # not already compiled. Uses zc++ wrapper around C++ compiler, to add |
| 4 | # additional compile arguments. |
| 5 | # |
| 6 | # Written by Ewen McNeill <[email protected]>, 2014-07-19 |
| 7 | # Updated by Ewen McNeill <[email protected]>, 2014-07-24 |
| 8 | #--------------------------------------------------------------------------- |
| 9 | |
| 10 | VERBOSE="${VERBOSE:-}" # Set to non-empty for already done status |
| 11 | export VERBOSE |
| 12 | |
| 13 | # Locate compiler wrapper |
| 14 | BIN_DIR=$(dirname $0) |
| 15 | if [ -z "${BIN_DIR}" ]; then BIN_DIR="."; fi |
| 16 | case "${BIN_DIR}" in |
| 17 | .) BIN_DIR="$(pwd)"; ;; |
| 18 | /*) ;; |
| 19 | *) BIN_DIR="$(pwd)/${BIN_DIR}"; ;; |
| 20 | esac |
| 21 | ZCXX="${BIN_DIR}/zc++" |
| 22 | |
| 23 | # Determine compile flags |
| 24 | CPPFLAGS="-D_XOPEN_SOURCE_EXTENDED=1 -D_OPEN_THREADS=3 -D_OPEN_SYS_SOCK_IPV6" |
| 25 | CXXFLAGS="-DZMQ_HAVE_ZOS -DHAVE_CONFIG_H -D_REENTRANT -D_THREAD_SAFE -DZMQ_USE_POLL" |
| 26 | case $(pwd) in |
| 27 | *src) CXXFLAGS="${CXXFLAGS} -I." |
| 28 | ;; |
| 29 | *tests) CXXFLAGS="${CXXFLAGS} -I. -I../src -I../include" |
| 30 | ;; |
| 31 | *) echo "Currently only builds in src/ and tests/" >&2 |
| 32 | exit 1 |
| 33 | ;; |
| 34 | esac |
| 35 | |
| 36 | skip() { |
| 37 | SRC="$1" |
| 38 | OBJ="$2" |
| 39 | if [ -n "${VERBOSE}" ]; then |
| 40 | echo " ${SRC} compiled already" |
| 41 | fi |
| 42 | } |
| 43 | |
| 44 | compile() { |
| 45 | SRC="$1" |
| 46 | OBJ="$2" |
| 47 | echo "CXX ${SRC}" |
| 48 | "${ZCXX}" ${CXXFLAGS} ${CPPFLAGS} -+ -c -o "${OBJ}" "${SRC}" |
| 49 | } |
| 50 | |
| 51 | for SRC in *.cpp; do |
| 52 | OBJ=$(echo $SRC | sed 's/\.cpp/.o/;') |
| 53 | if [ -f "${OBJ}" ]; then |
| 54 | if [ "${OBJ}" -nt "${SRC}" ]; then |
| 55 | skip "${SRC}" "${OBJ}" |
| 56 | else |
| 57 | compile "${SRC}" "${OBJ}" |
| 58 | fi |
| 59 | else |
| 60 | compile "${SRC}" "${OBJ}" |
| 61 | fi |
| 62 | done |