qtmobility/configure
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Mon, 21 Jun 2010 16:36:26 +0300
branchRCL_3
changeset 6 4203353e74ea
parent 3 eb34711bcc75
child 8 885c2596c964
permissions -rw-r--r--
Revision: 201023 Kit: 2010125

#!/bin/sh
#############################################################################
##
## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
## All rights reserved.
## Contact: Nokia Corporation (qt-info@nokia.com)
##
## This file is part of the Qt Mobility Components.
##
## $QT_BEGIN_LICENSE:LGPL$
## No Commercial Usage
## This file contains pre-release code and may not be distributed.
## You may use this file in accordance with the terms and conditions
## contained in the Technology Preview License Agreement accompanying
## this package.
##
## GNU Lesser General Public License Usage
## Alternatively, this file may be used under the terms of the GNU Lesser
## General Public License version 2.1 as published by the Free Software
## Foundation and appearing in the file LICENSE.LGPL included in the
## packaging of this file.  Please review the following information to
## ensure the GNU Lesser General Public License version 2.1 requirements
## will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
##
## In addition, as a special exception, Nokia gives you certain additional
## rights.  These rights are described in the Nokia Qt LGPL Exception
## version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
##
## If you have questions regarding the use of this file, please contact
## Nokia at qt-info@nokia.com.
##
##
##
##
##
##
##
##
## $QT_END_LICENSE$
##
#############################################################################

# return status of 1 if absolute path as first argument
# also prints the return status
isAbsPath() {
    slash=$(echo $1 | cut -c 1)
    if [ "$slash" != "/" ]; then
        echo 0
        return 0
    fi
    echo 1
    return 1
}

# Returns the absolute path for $1 for target $2
# as an example $2 might have value "maemo5".
# This is required because when building in scratchbox for
# maemo we do not want to follow symbolic links that are 
# introduced by scratchbox
absPath() {
    if [ "$2" = "maemo5" -o "$2" = "maemo6" ]; then
        if [ `isAbsPath $1` = '1' ]; then
            echo $1;
        else
            echo >&2 "Relative prefix/bin/lib/header/plugin paths are not supported for Maemo"
            exit 1;
        fi
    else
        PATH=`$relpath/bin/pathhelper $1`
        echo $PATH
    fi
}


# the current directory (shadow build dir)
shadowpath=`/bin/pwd`
# the name of this script
relconf=`basename $0`
# the directory of this script is the "source tree"
relpath=`dirname $0`
relpath=`(cd "$relpath"; /bin/pwd)`

CONFIG_IN="$shadowpath/config.in"
QT_MOBILITY_PREFIX=$shadowpath/install
QT_MOBILITY_INCLUDE=
QT_MOBILITY_LIB=
QT_MOBILITY_BIN=
QT_MOBILITY_PLUGINS=
BUILD_UNITTESTS=
BUILD_EXAMPLES=
BUILD_DOCS=yes
BUILD_TOOLS=yes
RELEASEMODE=
BUILD_SILENT=
LINUX_TARGET=
QMAKE_CACHE="$shadowpath/.qmake.cache"
LIB_PATH="lib"
BIN_PATH="bin"
PLUGIN_PATH="plugins"
MAC_SDK=
MOBILITY_MODULES="bearer location contacts multimedia publishsubscribe versit messaging systeminfo serviceframework sensors"
MOBILITY_MODULES_UNPARSED=
QMKSPEC=
OS="other"

usage() 
{
    echo "Usage: configure [-prefix <dir>] [headerdir <dir>] [libdir <dir>]"
    echo "                 [-bindir <dir>] [-tests] [-examples] [-no-docs]"
    echo "                 [-no-tools] [-debug] [-release] [-silent]"
    echo "                 [-modules <list>]"
    echo
    echo "Options:"
    echo
    echo "-prefix <dir> ..... This will install everything relative to <dir>"
    echo "                    (default prefix: $shadowpath/install)"
    echo "-headerdir <dir> .. Header files will be installed to <dir>"
    echo "                    (default prefix: PREFIX/include)"
    echo "-libdir <dir> ..... Libraries will be installed to <dir>"
    echo "                    (default PREFIX/lib)"
    echo "-bindir <dir> ..... Executables will be installed to <dir>"
    echo "                    (default PREFIX/bin)"
    echo "-plugindir <dir> .. Plug-ins will be installed to <dir>"
    echo "                    (default PREFIX/plugins)"
    echo "-debug ............ Build with debugging symbols"
    echo "-release .......... Build without debugging symbols"
    echo "-silent ........... Reduces build output"
    echo "-tests ............ Build unit tests (not build by default)"
    echo "                    Note, this adds test symbols to all libraries"
    echo "                    and should not be used for release builds."
    echo "-examples ......... Build example applications"
    echo "-no-docs .......... Do not build documentation (build by default)"
    echo "-no-tools ......... Do not build tools (build by default)"
    echo "-modules <list> ... Restrict list of modules to build (default all supported)"
    echo "                    Choose from: bearer contacts location publishsubscribe"
    echo "                    messaging multimedia systeminfo serviceframework versit"
    echo "                    sensors"
    echo "                    Modules should be separated by a space and surrounded"
    echo "                    by double quotation. If a"
    echo "                    selected module depends on other modules dependencies"
    echo "                    will automatically be enabled."
    echo "-maemo6 ........... Build Qt Mobility for Maemo6 (Harmattan)."
    echo "-maemo5 ........... Build Qt Mobility for Maemo5 (Freemantle)."
    echo "-sdk <sdk>..........Build using Apple provided SDK <path/to/sdk>."
    echo "                    example: -sdk /Developer/SDKs/MacOSX10.6.sdk"
    echo
    
    rm -f "$CONFIG_IN"
    exit 1
}

rm -rf "$QMAKE_CACHE"
CONFIG_LOG="$shadowpath/config.log"
rm -rf "$CONFIG_LOG"

while [ "$#" -gt 0 ]; do
    case "$1" in 
        -h|-help|--help)
            usage
            ;;
        -headerdir)
            QT_MOBILITY_INCLUDE="$2"
            shift
            ;;
        -libdir)
            QT_MOBILITY_LIB="$2"
            shift
            ;;
        --prefix|-prefix)
            QT_MOBILITY_PREFIX="$2"
            shift
            ;;
        -bindir)
            QT_MOBILITY_BIN="$2"
            shift
            ;;
        -plugindir)
            QT_MOBILITY_PLUGINS="$2"
            shift
            ;;
        -tests)
            BUILD_UNITTESTS="yes"
            ;;
        -examples)
            BUILD_EXAMPLES="yes"
            ;;
        -no-docs)
            BUILD_DOCS=
            ;;
        -no-tools)
            BUILD_TOOLS=
            ;;
        -debug)
            RELEASEMODE=debug
            ;;
        -release)
            RELEASEMODE=release
            ;;
        -silent)
            BUILD_SILENT=yes
            ;;
        -maemo5)
            LINUX_TARGET=maemo5
            ;;
        -maemo6)
            LINUX_TARGET=maemo6
            ;;
        -sdk)
            MAC_SDK="$2"
            shift
            ;;
        -modules)
            MOBILITY_MODULES_UNPARSED=$2
            #reset default selection
            MOBILITY_MODULES=
            for m in $MOBILITY_MODULES_UNPARSED; do
                case "$m" in
                    bearer|contacts|location|messaging|multimedia|publishsubscribe|serviceframework|systeminfo|versit|sensors)
                        MOBILITY_MODULES="$MOBILITY_MODULES $m";
                        ;;
                    *)
                        echo "Unknown module: $m"
                        echo
                        usage
                        ;;

                esac
            done
            if [ -z "$MOBILITY_MODULES" ]; then
                echo "List of selected modules is empty."
                echo 
                usage
            fi
            shift
            ;;
        *)
            echo "Unknown option: $1"
            usage
            ;;
    esac
    shift
done

checkostype()
{
    match="darwin" 
    if [ "$OSTYPE" = "${match}"* ]; then
        OS="darwin"
        QMKSPEC="-spec macx-g++"
        echo "QMAKESPEC = "$QMKSPEC >> "$CONFIG_IN"
    fi
}

findframeworks()
{
# figure out if Qt was built with frameworks
# if so, install in the correct place.
# and fix rpath
    echo "contains(QT_CONFIG,qt_framework):message(1)" > 1.pro
    SOMETHING=`qmake -spec macx-g++ 1.pro 2>&1`
        if [ "$SOMETHING" = "Project MESSAGE: 1" ]; then
            LIB_PATH="Library/Frameworks"
            BIN_PATH="Applications"
        fi
    rm 1.pro
}


findUniversal()
{
    if [ -e "mac.inc" ]; then 
        rm mac.inc
    fi
    echo "contains(QT_CONFIG,x86): system(echo CONFIG+=x86 >> mac.inc)" > 2.pro
    echo "contains(QT_CONFIG,ppc): system(echo CONFIG+=ppc >> mac.inc)" >> 2.pro
    echo "contains(QT_CONFIG,ppc64): system(echo CONFIG+=ppc64 >> mac.inc)" >> 2.pro
    echo "contains(QT_CONFIG,x86_64): system(echo CONFIG+=x86_64 >> mac.inc)" >> 2.pro
    SOMETIME=`qmake -spec macx-g++ 2.pro 2>&1`
    rm 2.pro
    if [ -e "mac.inc" ]; then 
         echo "exists(mac.inc): include(mac.inc)" >> "$CONFIG_IN"
    fi
}

checkostype

if [ "$OS" = "darwin" ] ; then
    findframeworks
fi

if [ -n "$BUILD_SILENT" ]; then
    echo "CONFIG += silent"  > "$CONFIG_IN"
fi

if [ "$OS" = "darwin" ] ; then
    findUniversal
fi

if [ -z "$RELEASEMODE" ]; then
    RELEASEMODE="debug"
fi
echo "CONFIG += $RELEASEMODE" >> "$CONFIG_IN"

#do we build for Maemo?
if [ -n "$LINUX_TARGET" ]; then
    if [ "$LINUX_TARGET" = "maemo5" ]; then
        echo "CONFIG+=maemo5" >> "$CONFIG_IN"
    elif [ "$LINUX_TARGET" = "maemo6" ]; then
        echo "CONFIG+=maemo6" >> "$CONFIG_IN"
    fi
fi

#process PREFIX
QT_MOBILITY_PREFIX=`absPath $QT_MOBILITY_PREFIX $LINUX_TARGET`
if [ "$?" -eq "1" ]; then
    exit 1
fi
echo "QT_MOBILITY_PREFIX = $QT_MOBILITY_PREFIX" >> "$CONFIG_IN"

#process include path
if [ -z "$QT_MOBILITY_INCLUDE" ]; then
    QT_MOBILITY_INCLUDE="$QT_MOBILITY_PREFIX/include"
else
    QT_MOBILITY_INCLUDE=`absPath $QT_MOBILITY_INCLUDE $LINUX_TARGET`
    if [ "$?" -eq "1" ]; then
        exit 1
    fi
fi
echo "QT_MOBILITY_INCLUDE = $QT_MOBILITY_INCLUDE" >> "$CONFIG_IN"


#process library path
if [ -z "$QT_MOBILITY_LIB" ]; then
    QT_MOBILITY_LIB="$QT_MOBILITY_PREFIX/$LIB_PATH"
else
    QT_MOBILITY_LIB=`absPath $QT_MOBILITY_LIB $LINUX_TARGET`
    if [ "$?" -eq "1" ]; then
        exit 1
    fi
fi
echo "QT_MOBILITY_LIB = $QT_MOBILITY_LIB" >> "$CONFIG_IN"

#process bin path
if [ -z "$QT_MOBILITY_BIN" ]; then
    QT_MOBILITY_BIN="$QT_MOBILITY_PREFIX/$BIN_PATH"
else
    QT_MOBILITY_BIN=`absPath $QT_MOBILITY_BIN $LINUX_TARGET`
    if [ "$?" -eq "1" ]; then
        exit 1
    fi
fi
echo "QT_MOBILITY_BIN = $QT_MOBILITY_BIN" >> "$CONFIG_IN"

#process plugin path
if [ -z "$QT_MOBILITY_PLUGINS" ]; then
    QT_MOBILITY_PLUGINS="$QT_MOBILITY_PREFIX/$PLUGIN_PATH"
else
    QT_MOBILITY_PLUGINS=`absPath $QT_MOBILITY_PLUGINS $LINUX_TARGET`
    if [ "$?" -eq "1" ]; then
        exit 1
    fi
fi
echo "QT_MOBILITY_PLUGINS = $QT_MOBILITY_PLUGINS" >> "$CONFIG_IN"


echo "QT_MOBILITY_SOURCE_TREE = $relpath" >> "$QMAKE_CACHE"
echo "QT_MOBILITY_BUILD_TREE = $shadowpath" >> "$QMAKE_CACHE"

if [ -n "$MAC_SDK" ]; then
    QMAKE_MAC_SDK="$MAC_SDK"
   echo "QMAKE_MAC_SDK = $QMAKE_MAC_SDK" >> "$CONFIG_IN"
fi

if [ -z "$BUILD_UNITTESTS" ]; then
    echo "build_unit_tests = no" >> "$CONFIG_IN"
else
    echo "build_unit_tests = yes" >> "$CONFIG_IN"
fi

if [ -z "$BUILD_EXAMPLES" ]; then
    echo "build_examples = no" >> "$CONFIG_IN"
else
    echo "build_examples = yes" >> "$CONFIG_IN"
fi

if [ -z "$BUILD_DOCS" ]; then
    echo "build_docs = no" >> "$CONFIG_IN"
else
    echo "build_docs = yes" >> "$CONFIG_IN"
fi

if [ -z "$BUILD_TOOLS" ]; then
    echo "build_tools = no" >> "$CONFIG_IN"
else
    echo "build_tools = yes" >> "$CONFIG_IN"
fi

echo "Configuring Qt Mobility"
echo 

WHICH="$relpath/config.tests/tools/which.test"

printf "Checking available Qt"
if ! "$WHICH" qmake 2>/dev/null 1>&2; then
    printf " ... Not found\n\n" >&2
    echo >&2 "Cannot find 'qmake' in your PATH.";
    echo >&2 "Aborting." 
else
    printf " ... "
    qmake -query QT_VERSION
fi

# find out which make we want to use
MAKE=
for m in make gmake; do
    if "$WHICH" $m >/dev/null 2>&1; then
        MAKE=`$WHICH $m`
        break
    fi
done
if [ -z "$MAKE" ]; then
    echo >&2 "Cannot find 'make' or 'gmake' in your PATH";
    echo >&2 "Aborting." 
fi

compileTest()
{
    printf "Checking $1"
    CURRENT_PWD=`pwd`
    
    if [ "$shadowpath" = "$relpath" ]; then 
        #doing source tree build
        cd "$relpath/config.tests/$2"
        rm -rf ./$2
    else
        #using shadow build
        rm -rf config.tests/$2
        mkdir -p config.tests/$2
        cd config.tests/$2
    fi

    qmake $QMKSPEC "$relpath/config.tests/$2/$2.pro" 2>> "$CONFIG_LOG" >> "$CONFIG_LOG"
    printf  " ."
    "$MAKE" clean >> "$CONFIG_LOG"
    printf "."
    "$MAKE" >> "$CONFIG_LOG" 2>&1
    printf ". "
    if ./$2 >> "$CONFIG_LOG" 2>&1; then
        echo "OK"
        echo "$2_enabled = yes" >> "$CONFIG_IN"
    else
        echo "Not Found"
        echo "$2_enabled = no" >> "$CONFIG_IN"
    fi
    cd "$CURRENT_PWD"
}

#compile tests
compileTest QMF qmf
compileTest NetworkManager networkmanager
compileTest "CoreWLAN (MacOS 10.6)" corewlan
compileTest "Maemo ICD" maemo-icd
compileTest "Maemo ICD WLAN" maemo-icd-network-wlan
compileTest "Maemo5 contacts dependencies" maemo5-contacts
if [ "$LINUX_TARGET" = maemo6 ]; then
    compileTest sensord sensord
else
    echo "sensord_enabled = no" >> "$CONFIG_IN"
fi

# Now module selection
# using 'expr match ....' should help a bit
#if [ -n "$MOBILITY_MODULES_UNPARSED" ]; then
    # In theory we should do some sanity checking here.
#    MOBILITY_MODULES="$MOBILITY_MODULES_UNPARSED"
#fi

# Test if able to build multimedia
for module in $MOBILITY_MODULES; do
    case "$module" in
        multimedia)
            echo "contains(QT_CONFIG,multimedia):message(1)" > 1.pro
            SOMETHING=`qmake 1.pro 2>&1`
            if [ "$SOMETHING" = "Project MESSAGE: 1" ]; then
                MOBILITY_MODULES="$(echo $MOBILITY_MODULES | sed 's:multimedia::g')"
                echo "Only one multimedia module allowed, please rebuild Qt with -no-multimedia"
            fi
            rm 1.pro
            ;;
    esac
done

if [ -z "$MOBILITY_MODULES" ]; then
    echo "No module available to build."
    exit 1
fi

# It's a lot easier to make qmake do the dependency checking...
echo "mobility_modules = $MOBILITY_MODULES" >> "$CONFIG_IN"
echo "contains(mobility_modules,versit): mobility_modules *= contacts" >> "$CONFIG_IN"
echo "maemo5|maemo6:contains(maemo-icd_enabled, no): mobility_modules -= bearer" >> "$CONFIG_IN"

# If libicd-network-wlan-dev.h is not present, use own copy.
# At time of writing, libicd-network-wlan-dev is not released for maemo5.
echo "maemo5:contains(maemo-icd-network-wlan_enabled, no): INCLUDEPATH += $relpath/src/3rdparty/icd-network-wlan" >> "$CONFIG_IN"

# Ideally we'd skip generating headers for modules that are not enabled
echo "Generating Mobility Headers..."
#remove old headers
rm -rf $shadowpath/include
mkdir $shadowpath/include
for module in $MOBILITY_MODULES; do
    case "$module" in 
        bearer)
            $relpath/bin/syncheaders $shadowpath/include/QtmBearer $relpath/src/bearer
            ;;
        publishsubscribe)
            $relpath/bin/syncheaders $shadowpath/include/QtmPubSub $relpath/src/publishsubscribe
            ;;
        location)
            $relpath/bin/syncheaders $shadowpath/include/QtmLocation $relpath/src/location
            ;;
        serviceframework)
            $relpath/bin/syncheaders $shadowpath/include/QtmServiceFramework $relpath/src/serviceframework
            ;;
        systeminfo)
            $relpath/bin/syncheaders $shadowpath/include/QtmSystemInfo $relpath/src/systeminfo
            ;;
        contacts)
            $relpath/bin/syncheaders $shadowpath/include/QtmContacts $relpath/src/contacts
            $relpath/bin/syncheaders $shadowpath/include/QtmContacts $relpath/src/contacts/details
            $relpath/bin/syncheaders $shadowpath/include/QtmContacts $relpath/src/contacts/requests
            $relpath/bin/syncheaders $shadowpath/include/QtmContacts $relpath/src/contacts/filters
            ;;
        multimedia)
            $relpath/bin/syncheaders $shadowpath/include/QtMultimedia $relpath/src/multimedia
            $relpath/bin/syncheaders $shadowpath/include/QtMultimedia $relpath/src/multimedia/audio
            $relpath/bin/syncheaders $shadowpath/include/QtMultimedia $relpath/src/multimedia/video
            ;;
        messaging)
            $relpath/bin/syncheaders $shadowpath/include/QtmMessaging $relpath/src/messaging
            ;;
        versit)
            #versit implies contacts
            $relpath/bin/syncheaders $shadowpath/include/QtmVersit $relpath/src/versit
            $relpath/bin/syncheaders $shadowpath/include/QtmContacts $relpath/src/contacts
            $relpath/bin/syncheaders $shadowpath/include/QtmContacts $relpath/src/contacts/details
            $relpath/bin/syncheaders $shadowpath/include/QtmContacts $relpath/src/contacts/requests
            $relpath/bin/syncheaders $shadowpath/include/QtmContacts $relpath/src/contacts/filters
            ;;
        sensors)
            $relpath/bin/syncheaders $shadowpath/include/QtmSensors $relpath/src/sensors
            ;;
        *)
            echo "Cannot generate headers for $module"
            ;;
    esac
done

mv "$CONFIG_IN" config.pri
mkdir -p "$shadowpath/features"
if [ "$shadowpath" != "$relpath" ]; then 
    cp -f "$relpath/features/strict_flags.prf" "$shadowpath/features"
fi

echo "Running qmake..."
if qmake -makefile $QMKSPEC -recursive "$relpath/qtmobility.pro"; then
    echo ""
    echo "configure has finished. You may run make or gmake to build the project now."
else
    echo ""
    echo "configure failed."
fi