I have been updating my build tools to optionally us autotools (autoconfig/automake/libtool etc.).
As part of this change I have written a couple of M4 macros. This not being something I have done before, any input appreciated on style or if things can be done better.
AC_DEFUN(
[AX_FUNC_THOR_BUILD],
[
AC_CHECK_PROGS([WGET], [wget], [:])
if test "$WGET" = :; then
AC_MSG_ERROR([This package needs wget.])
fi
AC_CHECK_PROGS([UNZIP], [unzip], [:])
if test "$UNZIP" = :; then
AC_MSG_ERROR([This package needs unzip.])
fi
AC_PROG_CXX
git submodule init
git submodule update
pushd build/third
./setup "$CXX" || AC_MSG_ERROR([Failed to set up the test utilities], [1])
popd
]
)
Should I pull the setup script into this macro or leave it separate?
#!/bin/bash
set -e
CXX=$1
#
# Change this as required to point at the root of ThorsAnvil code
ROOT=$(pwd)
THORSANVIL_ROOT=$(dirname ${ROOT})
if [[ -e ${THORSANVIL_ROOT}/lib/libgtest.a ]]; then
exit 0
fi
echo "Un-archiving google test"
GTEST_ARCHIEVE=`ls gtest-*.zip 2>/dev/null | tail -n 1`
if [[ ${GTEST_ARCHIEVE} == "" ]]; then
echo "Retrieving: gtest-1.7.0"
wget http://googletest.googlecode.com/files/gtest-1.7.0.zip
GTEST_ARCHIEVE=`ls gtest-*.zip 2>/dev/null | tail -n 1`
fi
GTEST_ARCHIEVE_DIR=${GTEST_ARCHIEVE%.zip}
if [[ ! -d ${GTEST_ARCHIEVE_DIR} ]]; then
unzip ${GTEST_ARCHIEVE}
fi
echo "Building google test"
GTEST_DIR=${ROOT}/${GTEST_ARCHIEVE_DIR}
pushd ${GTEST_DIR}
${CXX} -I${GTEST_DIR}/include -I${GTEST_DIR} -c ${GTEST_DIR}/src/gtest-all.cc
${CXX} -I${GTEST_DIR}/include -I${GTEST_DIR} -c ${GTEST_DIR}/src/gtest_main.cc
ar -rv libgtest.a gtest-all.o gtest_main.o
popd
echo "Installing google test"
pushd ${THORSANVIL_ROOT}
mkdir -p bin include include3rd lib
rm -f lib/libgtest.*
cp ${GTEST_DIR}/libgtest.a lib/
rm -f include3rd/gtest
ln -s ${GTEST_DIR}/include/gtest include3rd/gtest
popd