Blob Blame History Raw
#! /bin/sh
#
# Copyright (C) 2013 Christian Dywan <christian@twotoasts.de>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# See the file COPYING for the full license text.
#
#~  Usage:
#~    ./configure [OPTIONS]
#~  Options:
#~    --prefix=PREFIX        Installation prefix
#~    --enable-gtk3          Use GTK+3
#~    --disable-zeitgeist    Disable Zeitgeist history integration
#~    --enable-granite       Fancy notebook and pop-overs
#~    --enable-apidocs       API documentation
#~
#~  Environment:
#~    VALAC if defined the valac executable to use, for example valac-0.16
#

if [ -z `command -v cmake` ]; then
    echo Fatal: cmake not installed
    exit 1
fi

while [ $# != 0 ]; do
    case $1 in
        --enable-gtk3)
            ARGS="$ARGS -DUSE_GTK3=1";;
        --disable-zeitgeist)
            ARGS="$ARGS -DUSE_ZEITGEIST=0";;
        --enable-granite)
            ARGS="$ARGS -DUSE_GRANITE=1";;
        --enable-apidocs)
            ARGS="$ARGS -DUSE_APIDOCS=1";;
        --extra-warnings)
            ARGS="$ARGS -DEXTRA_WARNINGS=1";;
        --prefix=*)
            ARGS="$ARGS -DCMAKE_INSTALL_PREFIX=${1#*=}";;
        *)
            grep -e '^#~' $0 | sed s/#~//
            exit
    esac
    shift
done

BUILD_DIR="_build"

if [ ! -f GNUmakefile ]; then
    cp -v GNUmakefile.in GNUmakefile || exit 1
fi

# cmake was invoked in toplevel folder before
# clean up cmake generated build files to prevent conflicts
if [ -f CMakeCache.txt ]; then
    echo
    echo '####################################################################################'
    echo 'CMake build files detected in toplevel folder !!'
    echo 'Please always run "cmake" command from distinct folder when you use cmake yourself.'
    echo '####################################################################################'
    echo
    echo 'Cleaning up...'
    echo

    rm -fr $BUILD_DIR
    rm CMakeCache.txt config.h Makefile
    find . -iname CMakeFiles -type d|xargs rm -fr
    find . -iname cmake_install.cmake -exec rm {} \;
    find . -iname CTestTestfile.cmake -exec rm {} \;

    find . -iname *-folders -type d|xargs rm -fr
    rm -fr data/logo-shade
fi

mkdir -p $BUILD_DIR && cd $BUILD_DIR || exit 1
cmake $ARGS .. || exit 1

echo
echo "Configuring done, run \"make\" to compile"