2009-02-02 17:44:46 +03:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# Last Change: 2008-06-18 14:13:46
|
|
|
|
#
|
|
|
|
# Script to build libssh on UNIX.
|
|
|
|
#
|
2014-01-07 19:08:23 +04:00
|
|
|
# Copyright (c) 2006-2007 Andreas Schneider <asn@cryptomilk.org>
|
2009-02-02 17:44:46 +03:00
|
|
|
#
|
|
|
|
|
|
|
|
SOURCE_DIR=".."
|
|
|
|
|
|
|
|
LANG=C
|
|
|
|
export LANG
|
|
|
|
|
|
|
|
SCRIPT="$0"
|
|
|
|
COUNT=0
|
|
|
|
while [ -L "${SCRIPT}" ]
|
|
|
|
do
|
|
|
|
SCRIPT=$(readlink ${SCRIPT})
|
|
|
|
COUNT=$(expr ${COUNT} + 1)
|
|
|
|
if [ ${COUNT} -gt 100 ]; then
|
|
|
|
echo "Too many symbolic links"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
BUILDDIR=$(dirname ${SCRIPT})
|
|
|
|
|
|
|
|
cleanup_and_exit () {
|
|
|
|
if test "$1" = 0 -o -z "$1" ; then
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
exit $1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function configure() {
|
2009-09-16 16:47:45 +04:00
|
|
|
if [ -n "${CMAKEDIR}" ]; then
|
|
|
|
${CMAKEDIR}/bin/cmake "$@" ${SOURCE_DIR} || cleanup_and_exit $?
|
|
|
|
else
|
|
|
|
cmake "$@" ${SOURCE_DIR} || cleanup_and_exit $?
|
|
|
|
fi
|
2009-02-02 17:44:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function compile() {
|
2009-09-16 16:47:45 +04:00
|
|
|
if [ -f /proc/cpuinfo ]; then
|
|
|
|
CPUCOUNT=$(grep -c processor /proc/cpuinfo)
|
|
|
|
elif test `uname` = "SunOS" ; then
|
|
|
|
CPUCOUNT=$(psrinfo -p)
|
|
|
|
else
|
|
|
|
CPUCOUNT="1"
|
|
|
|
fi
|
|
|
|
|
2009-02-02 17:44:46 +03:00
|
|
|
if [ "${CPUCOUNT}" -gt "1" ]; then
|
2009-09-16 16:47:45 +04:00
|
|
|
${MAKE} -j${CPUCOUNT} $1 || cleanup_and_exit $?
|
2009-02-02 17:44:46 +03:00
|
|
|
else
|
2009-09-16 16:47:45 +04:00
|
|
|
${MAKE} $1 || exit $?
|
2009-02-02 17:44:46 +03:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function clean_build_dir() {
|
|
|
|
find ! -path "*.svn*" ! -name "*.bat" ! -name "*.sh" ! -name "." -print0 | xargs -0 rm -rf
|
|
|
|
}
|
|
|
|
|
|
|
|
function usage () {
|
2011-02-07 15:34:37 +03:00
|
|
|
echo "Usage: `basename $0` [--prefix /install_prefix|--build [debug|final]|--clean|--verbose|--libsuffix (32|64)|--help|--clang|--cmakedir /directory|--make
|
2018-05-14 16:55:06 +03:00
|
|
|
(gmake|make)|--ccompiler(gcc|cc)|--withstaticlib|--unittesting|--clientunittesting|--withserver|--withoutsymbolversioning]"
|
2009-02-02 17:44:46 +03:00
|
|
|
cleanup_and_exit
|
|
|
|
}
|
|
|
|
|
|
|
|
cd ${BUILDDIR}
|
|
|
|
|
2009-09-16 16:47:45 +04:00
|
|
|
# the default CMake options:
|
|
|
|
OPTIONS="--graphviz=${BUILDDIR}/libssh.dot"
|
|
|
|
|
|
|
|
# the default 'make' utility:
|
|
|
|
MAKE="make"
|
2009-02-02 17:44:46 +03:00
|
|
|
|
|
|
|
while test -n "$1"; do
|
|
|
|
PARAM="$1"
|
|
|
|
ARG="$2"
|
|
|
|
shift
|
|
|
|
case ${PARAM} in
|
|
|
|
*-*=*)
|
|
|
|
ARG=${PARAM#*=}
|
|
|
|
PARAM=${PARAM%%=*}
|
|
|
|
set -- "----noarg=${PARAM}" "$@"
|
|
|
|
esac
|
|
|
|
case ${PARAM} in
|
|
|
|
*-help|-h)
|
|
|
|
#echo_help
|
|
|
|
usage
|
|
|
|
cleanup_and_exit
|
|
|
|
;;
|
|
|
|
*-build)
|
|
|
|
DOMAKE="1"
|
|
|
|
BUILD_TYPE="${ARG}"
|
|
|
|
test -n "${BUILD_TYPE}" && shift
|
|
|
|
;;
|
|
|
|
*-clean)
|
|
|
|
clean_build_dir
|
|
|
|
cleanup_and_exit
|
|
|
|
;;
|
2011-02-07 15:34:37 +03:00
|
|
|
*-clang)
|
|
|
|
OPTIONS="${OPTIONS} -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++"
|
|
|
|
;;
|
2009-02-02 17:44:46 +03:00
|
|
|
*-verbose)
|
|
|
|
DOVERBOSE="1"
|
|
|
|
;;
|
|
|
|
*-memtest)
|
|
|
|
OPTIONS="${OPTIONS} -DMEM_NULL_TESTS=ON"
|
|
|
|
;;
|
|
|
|
*-libsuffix)
|
|
|
|
OPTIONS="${OPTIONS} -DLIB_SUFFIX=${ARG}"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*-prefix)
|
|
|
|
OPTIONS="${OPTIONS} -DCMAKE_INSTALL_PREFIX=${ARG}"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*-sysconfdir)
|
|
|
|
OPTIONS="${OPTIONS} -DSYSCONF_INSTALL_DIR=${ARG}"
|
|
|
|
shift
|
|
|
|
;;
|
2009-09-16 16:47:45 +04:00
|
|
|
*-cmakedir)
|
|
|
|
CMAKEDIR="${ARG}"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*-make)
|
|
|
|
MAKE="${ARG}"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*-ccompiler)
|
|
|
|
OPTIONS="${OPTIONS} -DCMAKE_C_COMPILER=${ARG}"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*-withstaticlib)
|
|
|
|
OPTIONS="${OPTIONS} -DWITH_STATIC_LIB=ON"
|
|
|
|
;;
|
|
|
|
*-unittesting)
|
2018-06-29 11:29:02 +03:00
|
|
|
OPTIONS="${OPTIONS} -DUNIT_TESTING=ON"
|
2009-09-16 16:47:45 +04:00
|
|
|
;;
|
2010-07-23 13:04:09 +04:00
|
|
|
*-clientunittesting)
|
2018-06-29 11:31:09 +03:00
|
|
|
OPTIONS="${OPTIONS} -DCLIENT_TESTING=ON"
|
2010-07-23 13:04:09 +04:00
|
|
|
;;
|
2009-09-16 16:47:45 +04:00
|
|
|
*-withserver)
|
|
|
|
OPTIONS="${OPTIONS} -DWITH_SERVER=ON"
|
|
|
|
;;
|
2018-05-14 16:55:06 +03:00
|
|
|
*-withoutsymbolversioning)
|
|
|
|
OPTIONS="${OPTIONS} -DWITH_SYMBOL_VERSIONING=OFF"
|
|
|
|
;;
|
|
|
|
*-finalrelease)
|
|
|
|
OPTIONS="${OPTIONS} -DWITH_FINAL=ON"
|
|
|
|
;;
|
2009-02-02 17:44:46 +03:00
|
|
|
----noarg)
|
|
|
|
echo "$ARG does not take an argument"
|
|
|
|
cleanup_and_exit
|
|
|
|
;;
|
|
|
|
-*)
|
|
|
|
echo Unknown Option "$PARAM". Exit.
|
|
|
|
cleanup_and_exit 1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2009-06-24 18:15:56 +04:00
|
|
|
if [ "${DOMAKE}" == "1" ]; then
|
2009-02-02 17:44:46 +03:00
|
|
|
OPTIONS="${OPTIONS} -DCMAKE_BUILD_TYPE=${BUILD_TYPE}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "${DOVERBOSE}" ]; then
|
|
|
|
OPTIONS="${OPTIONS} -DCMAKE_VERBOSE_MAKEFILE=1"
|
|
|
|
else
|
|
|
|
OPTIONS="${OPTIONS} -DCMAKE_VERBOSE_MAKEFILE=0"
|
|
|
|
fi
|
|
|
|
|
|
|
|
test -f "${BUILDDIR}/.build.log" && rm -f ${BUILDDIR}/.build.log
|
|
|
|
touch ${BUILDDIR}/.build.log
|
|
|
|
# log everything from here to .build.log
|
|
|
|
exec 1> >(exec -a 'build logging tee' tee -a ${BUILDDIR}/.build.log) 2>&1
|
|
|
|
echo "${HOST} started build at $(date)."
|
|
|
|
echo
|
|
|
|
|
|
|
|
configure ${OPTIONS} "$@"
|
|
|
|
|
|
|
|
if [ -n "${DOMAKE}" ]; then
|
|
|
|
test -n "${DOVERBOSE}" && compile VERBOSE=1 || compile
|
|
|
|
fi
|
|
|
|
|
|
|
|
DOT=$(which dot 2>/dev/null)
|
|
|
|
if [ -n "${DOT}" ]; then
|
|
|
|
${DOT} -Tpng -o${BUILDDIR}/libssh.png ${BUILDDIR}/libssh.dot
|
|
|
|
${DOT} -Tsvg -o${BUILDDIR}/libssh.svg ${BUILDDIR}/libssh.dot
|
|
|
|
fi
|
|
|
|
|
|
|
|
exec >&0 2>&0 # so that the logging tee finishes
|
|
|
|
sleep 1 # wait till tee terminates
|
|
|
|
|
|
|
|
cleanup_and_exit 0
|