Browse Source

chore(build): slightly refactor bootstrap.sh

Also adjust style.
pull/4017/head
Zetok Zalbavar 9 years ago
parent
commit
28c817d853
No known key found for this signature in database
GPG Key ID: C953D3880212068A
  1. 295
      bootstrap.sh

295
bootstrap.sh

@ -20,7 +20,8 @@
set -eu -o pipefail set -eu -o pipefail
# windows check # windows check
if cmd.exe /c ver 2>/dev/null ; then if cmd.exe /c ver 2>/dev/null
then
cd windows cd windows
./bootstrap.sh ./bootstrap.sh
exit $? exit $?
@ -37,12 +38,13 @@ readonly INSTALL_DIR=libs
# just for convenience # just for convenience
readonly BASE_DIR="${SCRIPT_DIR}/${INSTALL_DIR}" readonly BASE_DIR="${SCRIPT_DIR}/${INSTALL_DIR}"
# toxcore version to checkout # versions of libs to checkout
readonly TOXCORE_VERSION="v0.1.2" readonly TOXCORE_VERSION="v0.1.2"
readonly SQLCIPHER_VERSION="v3.4.0"
# directory names of cloned repositories # directory names of cloned repositories
readonly TOXCORE_DIR="libtoxcore-$TOXCORE_VERSION" readonly TOXCORE_DIR="libtoxcore-$TOXCORE_VERSION"
readonly SQLCIPHER_DIR="sqlcipher-stable" readonly SQLCIPHER_DIR="sqlcipher-$SQLCIPHER_VERSION"
# default values for user given parameters # default values for user given parameters
INSTALL_TOX=true INSTALL_TOX=true
@ -51,70 +53,38 @@ SYSTEM_WIDE=true
KEEP_BUILD_FILES=false KEEP_BUILD_FILES=false
# if Fedora, by default install sqlcipher # if Fedora, by default install sqlcipher
if which dnf &> /dev/null ; then if which dnf &> /dev/null
then
INSTALL_SQLCIPHER=true INSTALL_SQLCIPHER=true
fi fi
########## parse input parameters ########## print_help() {
while [ $# -ge 1 ] ; do echo "Use this script to install/update libtoxcore"
if [ ${1} = "--with-tox" ] ; then echo ""
INSTALL_TOX=true echo "usage:"
shift echo " ${0} PARAMETERS"
elif [ ${1} = "--without-tox" ] ; then echo ""
INSTALL_TOX=false echo "parameters:"
shift echo " --with-tox : install/update libtoxcore"
elif [ ${1} = "--with-sqlcipher" ] ; then echo " --without-tox : do not install/update libtoxcore"
INSTALL_SQLCIPHER=true echo " --with-sqlcipher : install/update sqlcipher"
shift echo " --without-sqlcipher : do not install/update sqlcipher"
elif [ ${1} = "--without-sqlcipher" ] ; then echo " -h|--help : displays this help"
INSTALL_SQLCIPHER=false echo " -l|--local : install packages into ${INSTALL_DIR}"
shift echo " -k|--keep : keep build files after installation/update"
elif [ ${1} = "-l" -o ${1} = "--local" ] ; then echo ""
SYSTEM_WIDE=false echo "example usages:"
shift echo " ${0} -- install libtoxcore"
elif [ ${1} = "-k" -o ${1} = "--keep" ]; then }
KEEP_BUILD_FILES=true
shift
else
if [ ${1} != "-h" -a ${1} != "--help" ] ; then
echo "[ERROR] Unknown parameter \"${1}\""
echo ""
fi
# print help
echo "Use this script to install/update libtoxcore"
echo ""
echo "usage:"
echo " ${0} PARAMETERS"
echo ""
echo "parameters:"
echo " --with-tox : install/update libtoxcore"
echo " --without-tox : do not install/update libtoxcore"
echo " --with-sqlcipher : install/update sqlcipher"
echo " --without-sqlcipher : do not install/update sqlcipher"
echo " -h|--help : displays this help"
echo " -l|--local : install packages into ${INSTALL_DIR}"
echo " -k|--keep : keep build files after installation/update"
echo ""
echo "example usages:"
echo " ${0} -- install libtoxcore"
exit 1
fi
done
############ print debug output ############ ############ print debug output ############
echo "with tox : ${INSTALL_TOX}" print_debug_output() {
echo "with sqlcipher : ${INSTALL_SQLCIPHER}" echo "with tox : ${INSTALL_TOX}"
echo "install system-wide : ${SYSTEM_WIDE}" echo "with sqlcipher : ${INSTALL_SQLCIPHER}"
echo "keep build files : ${KEEP_BUILD_FILES}" echo "install system-wide : ${SYSTEM_WIDE}"
echo "keep build files : ${KEEP_BUILD_FILES}"
}
############### prepare step ###############
# create BASE_DIR directory if necessary
mkdir -p "${BASE_DIR}"
# remove not needed dirs # remove not needed dirs
remove_build_dirs() { remove_build_dirs() {
@ -122,90 +92,149 @@ remove_build_dirs() {
rm -rf "${BASE_DIR}/${SQLCIPHER_DIR}" rm -rf "${BASE_DIR}/${SQLCIPHER_DIR}"
} }
install_toxcore() {
if [[ $INSTALL_TOX = "true" ]]
then
git clone https://github.com/toktok/c-toxcore.git \
--branch $TOXCORE_VERSION \
--depth 1 \
"${BASE_DIR}/${TOXCORE_DIR}"
pushd ${BASE_DIR}/${TOXCORE_DIR}
./autogen.sh
# configure
if [[ $SYSTEM_WIDE = "false" ]]
then
./configure --prefix=${BASE_DIR}
else
./configure
fi
# maybe an earlier run of this script failed # ensure A/V support is enabled
# thus we should remove the cloned repositories if ! grep -Fxq "BUILD_AV_TRUE=''" config.log
# if exists, otherwise cloning them may fail then
remove_build_dirs echo "A/V support of libtoxcore is disabled but required by qTox. Aborting."
echo "Maybe the dev-packages of libopus and libvpx are not installed?"
exit 1
fi
############### install step ############### # compile
#install libtoxcore make -j $(nproc)
if [[ $INSTALL_TOX = "true" ]]; then
git clone https://github.com/toktok/c-toxcore.git \
--branch $TOXCORE_VERSION \
--depth 1 \
"${BASE_DIR}/${TOXCORE_DIR}"
pushd ${BASE_DIR}/${TOXCORE_DIR} # install
./autogen.sh if [[ $SYSTEM_WIDE = "false" ]]
then
make install
else
sudo make install
sudo ldconfig
fi
# configure popd
if [[ $SYSTEM_WIDE = "false" ]]; then
./configure --prefix=${BASE_DIR}
else
./configure
fi fi
}
# ensure A/V support is enabled
if ! grep -Fxq "BUILD_AV_TRUE=''" config.log
then
echo "A/V support of libtoxcore is disabled but required by qTox. Aborting."
echo "Maybe the dev-packages of libopus and libvpx are not installed?"
exit 1
fi
# compile install_sqlcipher() {
make -j $(nproc) if [[ $INSTALL_SQLCIPHER = "true" ]]
then
git clone https://github.com/sqlcipher/sqlcipher.git \
"${BASE_DIR}/${SQLCIPHER_DIR}" \
--branch $SQLCIPHER_VERSION \
--depth 1
pushd "${BASE_DIR}/${SQLCIPHER_DIR}"
autoreconf -if
if [[ $SYSTEM_WIDE = "false" ]]
then
./configure --prefix="${BASE_DIR}" \
--enable-tempstore=yes \
CFLAGS="-DSQLITE_HAS_CODEC"
make -j$(nproc)
make install || \
echo "" && \
echo "Sqlcipher failed to install locally." && \
echo "" && \
echo "Try without \"-l|--local\"" && \
exit 1
else
./configure \
--enable-tempstore=yes \
CFLAGS="-DSQLITE_HAS_CODEC"
make -j$(nproc)
sudo make install
sudo ldconfig
fi
# install popd
if [[ $SYSTEM_WIDE = "false" ]]; then
make install
else
sudo make install
sudo ldconfig
fi fi
}
popd
fi
#install sqlcipher main() {
if [[ $INSTALL_SQLCIPHER = "true" ]]; then ########## parse input parameters ##########
git clone https://github.com/sqlcipher/sqlcipher.git \ while [ $# -ge 1 ]
"${BASE_DIR}/${SQLCIPHER_DIR}" \ do
--depth 1 \ if [ ${1} = "--with-tox" ]
--branch v3.4.0 then
INSTALL_TOX=true
pushd "${BASE_DIR}/${SQLCIPHER_DIR}" shift
autoreconf -if elif [ ${1} = "--without-tox" ]
then
if [[ $SYSTEM_WIDE = "false" ]]; then INSTALL_TOX=false
./configure --prefix="${BASE_DIR}" \ shift
--enable-tempstore=yes \ elif [ ${1} = "--with-sqlcipher" ]
CFLAGS="-DSQLITE_HAS_CODEC" then
make -j$(nproc) INSTALL_SQLCIPHER=true
make install || \ shift
echo "" && \ elif [ ${1} = "--without-sqlcipher" ]
echo "Sqlcipher failed to install locally." && \ then
echo "" && \ INSTALL_SQLCIPHER=false
echo "Try without \"-l|--local\"" && \ shift
exit 1 elif [ ${1} = "-l" -o ${1} = "--local" ]
else then
./configure \ SYSTEM_WIDE=false
--enable-tempstore=yes \ shift
CFLAGS="-DSQLITE_HAS_CODEC" elif [ ${1} = "-k" -o ${1} = "--keep" ]
make -j$(nproc) then
sudo make install KEEP_BUILD_FILES=true
sudo ldconfig shift
fi else
if [ ${1} != "-h" -a ${1} != "--help" ]
then
echo "[ERROR] Unknown parameter \"${1}\""
echo ""
print_help
exit 1
fi
print_help
exit 0
fi
done
popd print_debug_output
fi
############### prepare step ###############
# create BASE_DIR directory if necessary
mkdir -p "${BASE_DIR}"
############### cleanup step ############### # maybe an earlier run of this script failed
# remove cloned repositories # thus we should remove the cloned repositories
if [[ $KEEP_BUILD_FILES = "false" ]]; then # if they exist, otherwise cloning them may fail
remove_build_dirs remove_build_dirs
fi
############### install step ###############
install_toxcore
install_sqlcipher
############### cleanup step ###############
# remove cloned repositories
if [[ $KEEP_BUILD_FILES = "false" ]]
then
remove_build_dirs
fi
}
main $@

Loading…
Cancel
Save