Skip to content

Project with CMs as examples

Alexandr Akulich edited this page Sep 7, 2015 · 9 revisions

To simplify development process, it is useful to have TelepathyQt and connection managers in a single project.

Follow script can be used to (optionally) integrate Morse and Nonsense connection managers as TelepathyQt examples with all needed custom libraries (TelegramQt and QXmpp) and still have all projects in different directories to keep git operations the same.

Usage:

  • Create a new file in the working directory (say, bundle.sh) and copy/paste the script content to the file
  • sh bundle.sh
  • The script will extract subscripts and suggest you to run the scripts to clone and prepare sources.
  • The script creates "telepathy-bundle" directory with projects sources and bin subdirectory with integration scripts.
  • If you rejected automatic source setup, then (in the "telepathy-bundle" directory) you need to either:
    • Run bin/all.sh to setup both Morse and Nonsense as TelepathyQt examples.
    • Run bin/download-morse.sh && bin/link-morse.sh && bin/cmake-morse.sh to setup TelepathyQt with Morse and TelegramQt.
    • Run bin/download-nonsense.sh && bin/link-nonsense.sh && bin/cmake-nonsense.shto setup TelepathyQt with Nonsense and QXmpp.
  • Projects directories (except telepathy-qt/examples) are not changed and are suitable for usual VCS operations.

Script:

#!/bin/sh

mkdir telepathy-bundle
cd telepathy-bundle

mkdir bin
echo "bin/all.sh"
cat << 'EOF' > bin/all.sh
#!/bin/sh

# figure out the absolute path to the script being run a bit
# non-obvious, the ${0%/*} pulls the path out of $0, cd's into the
# specified directory, then uses $PWD to figure out where that
# directory lives - and all this in a subshell, so we don't affect
# $PWD

SCRIPTS_DIR=$(cd "${0%/*}" && echo $PWD)

BUNDLE_URL_PREFIX="https://github.com/"

read -p "Use ssh url for git clone (requires ssh key)? " yn
case $yn in
    [Yy]* ) BUNDLE_URL_PREFIX="[email protected]:" ;;
    * ) echo "Fallback to https urls.";;
esac

if [ ! -d "telepathy-qt" ]; then
    git clone ${BUNDLE_URL_PREFIX}TelepathyQt/telepathy-qt.git
fi

export BUNDLE_URL_PREFIX
$SCRIPTS_DIR/download-morse.sh
$SCRIPTS_DIR/link-morse.sh
$SCRIPTS_DIR/cmake-morse.sh

$SCRIPTS_DIR/download-nonsense.sh
$SCRIPTS_DIR/link-nonsense.sh
$SCRIPTS_DIR/cmake-nonsense.sh

echo "Bundle is ready."
echo "Use git for all projects as usual, but use single telepathy-qt project to build everything."

EOF
chmod +x bin/all.sh

echo "bin/download-morse.sh"
cat << 'EOF' > bin/download-morse.sh
#!/bin/sh

GIT_DEPTH="--depth 1"

URL_PREFIX=$BUNDLE_URL_PREFIX

if [ -z "$URL_PREFIX" ]; then
    URL_PREFIX="https://github.com/"
fi

if [ ! -d "telepathy-qt" ]; then
    git clone ${URL_PREFIX}TelepathyQt/telepathy-qt.git $GIT_DEPTH
fi

git clone ${URL_PREFIX}TelepathyQt/telepathy-morse.git
git clone ${URL_PREFIX}Kaffeine/telegram-qt.git

EOF
chmod +x bin/download-morse.sh
echo "bin/download-nonsense.sh"
cat << 'EOF' > bin/download-nonsense.sh
#!/bin/sh

GIT_DEPTH="--depth 1"

URL_PREFIX=$BUNDLE_URL_PREFIX

if [ -z "$URL_PREFIX" ]; then
    URL_PREFIX="https://github.com/"
fi

if [ ! -d "telepathy-qt" ]; then
    git clone ${URL_PREFIX}TelepathyQt/telepathy-qt.git $GIT_DEPTH
fi

git clone ${URL_PREFIX}TelepathyQt/telepathy-nonsense.git
git clone ${URL_PREFIX}qxmpp-project/qxmpp.git $GIT_DEPTH

EOF
chmod +x bin/download-nonsense.sh

echo "bin/link-morse.sh"
cat << 'EOF' > bin/link-morse.sh
#!/bin/sh

CM_DIR=telepathy-qt/examples/morse
TOP_DIR=`pwd`

if [ -d "$CM_DIR" ]; then
  echo "$CM_DIR already exists. Say 'y' to remove (and recreate)."
  rm -rI $CM_DIR
fi

mkdir $CM_DIR

cd $CM_DIR
ln -s $TOP_DIR/telepathy-morse/*.cpp .
ln -s $TOP_DIR/telepathy-morse/*.hpp .
ln -s $TOP_DIR/telepathy-morse/*.in .

mkdir telegram-qt

cd telegram-qt
ln -s $TOP_DIR/telegram-qt/telegram-qt/* .
rm CMakeLists.txt

EOF
chmod +x bin/link-morse.sh
echo "bin/link-nonsense.sh"
cat << 'EOF' > bin/link-nonsense.sh
#!/bin/sh

CM_DIR=telepathy-qt/examples/nonsense
TOP_DIR=`pwd`

if [ -d "$CM_DIR" ]; then
  echo "$CM_DIR already exists. Say 'y' to remove (and recreate)."
  rm -rI $CM_DIR
fi

mkdir $CM_DIR

cd $CM_DIR
ln -s $TOP_DIR/telepathy-nonsense/*.cc .
ln -s $TOP_DIR/telepathy-nonsense/*.hh .
ln -s $TOP_DIR/telepathy-nonsense/*.in .

mkdir qxmpp

cd qxmpp
ln -s $TOP_DIR/qxmpp/src .

EOF
chmod +x bin/link-nonsense.sh

echo "bin/cmake-morse.sh"
cat << 'EOF' > bin/cmake-morse.sh
#!/bin/sh

TOP_DIR=`pwd`

cd telepathy-qt/examples

if [ `grep morse CMakeLists.txt|wc -l` = '0' ]; then
 echo "add_subdirectory(morse)" >> CMakeLists.txt
fi

cd morse
cp $TOP_DIR/telepathy-morse/CMakeLists.txt .

# Remove all find_package TelepathyQt
sed -i '/find_package(TelepathyQt/d' CMakeLists.txt

# Remove all find_package TelegramQt
sed -i '/find_package(TelegramQt/d' CMakeLists.txt

sed -i 's/${TELEGRAM_QT._INCLUDE_DIR}/telegram-qt/g' CMakeLists.txt

# Replace TelepathyQt CMake-found libraries with TpQt "this-project" ones.
sed -i 's/\${TELEPATHY_QT._LIBRARIES}/telepathy-qt\${QT_VERSION_MAJOR}/g' CMakeLists.txt
sed -i 's/\${TELEPATHY_QT._SERVICE_LIBRARIES}/telepathy-qt\${QT_VERSION_MAJOR}-service/g' CMakeLists.txt

sed -i 's/\${TELEGRAM_QT._LIBRARIES}/telegram-qt\${QT_VERSION_MAJOR}/g' CMakeLists.txt

echo "add_subdirectory(telegram-qt)" >> CMakeLists.txt

cd telegram-qt
cp $TOP_DIR/telegram-qt/telegram-qt/CMakeLists.txt .

sed '/CMakePackageConfigHelpers/{q}' -i CMakeLists.txt

# Enabled developer build
sed 's/if (DEVELOPER_BUILD)/if (TRUE)/' -i CMakeLists.txt

EOF
chmod +x bin/cmake-morse.sh
echo "bin/cmake-nonsense.sh"
cat << 'EOF' > bin/cmake-nonsense.sh
#!/bin/sh

TOP_DIR=`pwd`

cd telepathy-qt/examples

if [ `grep nonsense CMakeLists.txt|wc -l` = '0' ]; then
 echo "add_subdirectory(nonsense)" >> CMakeLists.txt
fi

cd nonsense
cp $TOP_DIR/telepathy-nonsense/CMakeLists.txt .

# Remove all find_package TelepathyQt
sed -i '/find_package(TelepathyQt/d' CMakeLists.txt

# Remove all find_package QXmpp
sed -i '/find_package(QXmpp/d' CMakeLists.txt

# ${QXMPP_INCLUDE_DIR} to qxmpp/src/base and qxmpp/src/client
sed -i 's/${QXMPP_INCLUDE_DIR}/qxmpp\/src\/base qxmpp\/src\/client/g' CMakeLists.txt

# Replace TelepathyQt CMake-found libraries with TpQt "this-project" ones.
sed -i 's/\${TELEPATHY_QT._LIBRARIES}/telepathy-qt\${QT_VERSION_MAJOR}/g' CMakeLists.txt
sed -i 's/\${TELEPATHY_QT._SERVICE_LIBRARIES}/telepathy-qt\${QT_VERSION_MAJOR}-service/g' CMakeLists.txt

sed -i 's/\${QXMPP_LIBRARIES}/qxmpp/g' CMakeLists.txt

echo "add_subdirectory(qxmpp)" >> CMakeLists.txt

cd qxmpp
wget https://raw.githubusercontent.com/pol51/QXMPP-CMake/master/CMakeLists.txt

echo "remove_definitions(-DQT_NO_CAST_FROM_ASCII)" >> CMakeLists.txt

EOF
chmod +x bin/cmake-nonsense.sh

echo "Bundle scripts extracted."

read -p "Clone and prepare sources now? " yn
case $yn in
    [Yy]* ) bin/all.sh ;;
    * ) echo "Run bin/all.sh to continue.";;
esac
Clone this wiki locally