configure

Wed, 21 Jan 2015 20:38:21 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 21 Jan 2015 20:38:21 +0100
changeset 77
bc0ed99e49c7
parent 0
1f419bd32da1
child 79
052224670baf
permissions
-rwxr-xr-x

fixed memory allocation bug

#!/bin/bash
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#
# Copyright 2011 Olaf Wintermann. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
#   1. Redistributions of source code must retain the above copyright notice,
#      this list of conditions and the following disclaimer.
#
#   2. Redistributions in binary form must reproduce the above copyright
#      notice, this list of conditions and the following disclaimer in the
#      documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

OS=`uname -s`
OS_VERSION=`uname -r`
PREFIX=/opt/mk12

#
# parse arguments
#
for ARG in $@
do
    if [[ $ARG == --prefix=* ]]; then
        PREFIX=${ARG:9}
    elif [[ $ARG == --toolkit=* ]]; then
        # todo: check for invalid toolkit
        TOOLKIT=${ARG:10}
    elif [ $ARG = "--help" ]; then
        # todo: print help text
        echo "no help yet"
        exit 0
    fi
done

#
# check_pkgconfig_lib()
#
# arg1: display package name
# arg2: pkg-config package name
#
check_pkgconfig_lib()
{
    printf "checking for "
    printf $1
    printf "... "
    pkg-config $2
    RESULT=$?
    if [ $RESULT -eq 0 ]; then
        echo "ok"
    else
        echo "not found"
        echo
        echo "missing package" $1
        exit -1
    fi
}


#
# check OS and libraries
#

printf "checking for toolchain... "
if [ $OS = SunOS ]; then
    BUILD_CONFIG=suncc
    echo "suncc"
fi

if [ $OS = Linux ]; then
    BUILD_CONFIG=gcc
    echo "gcc"
fi

if [ $OS = Darwin ]; then
    BUILD_CONFIG=osx
    echo "gcc"
fi


if [ $OS != Darwin ]; then
    check_pkgconfig_lib "libxml2" "libxml-2.0"
fi

if [ -z $TOOLKIT ]; then
    printf "checking for gui library... "
    if [ $OS = SunOS ]; then
        if [ $OS_VERSION = 5.10 ]; then
            TOOLKIT=gtk2legacy
        else
            TOOLKIT=gtk2
        fi
        echo "gtk2"
    elif [ $OS = Darwin ]; then
        TOOLKIT=cocoa
        echo "Cocoa"
    else
        pkg-config gtk+-3.0
        RESULT=$?
        if [ $RESULT -eq 0 ]; then
            TOOLKIT=gtk3
            echo "gtk3"
        else
            pkg-config gtk+-2.0
            RESULT=$?
            if [ $RESULT -eq 0 ]; then
                TOOLKIT=gtk2legacy
                echo "gtk2"
            else
                echo "not found"
                exit 1
            fi
        fi
    fi
fi


# generate config.mk

cat > config.mk << __EOF__
#
# config.mk generated by configure
#

PREFIX = ${PREFIX}

include \$(BUILD_ROOT)/make/${BUILD_CONFIG}.mk

__EOF__

# toolkit config
make/configure_${TOOLKIT}.sh


echo "configure finished"
echo
echo "  PREFIX:       $PREFIX"
echo "  BUILD_CONFIG: $BUILD_CONFIG"
echo "  TOOLKIT:      $TOOLKIT"
echo

mercurial