#!/bin/sh
#   PCRE configuration script
#
#   Generated by iMatix Boom
#
#   This script is provided to assist users new to Boom.  It displays the
#   configuration settings in effect.
#   
#   Copyright (c) 1996-2009 iMatix Corporation
#   All rights reserved.
#   
#   This file is licensed under the BSD license as follows:
#   
#   Redistribution and use in source and binary forms, with or without
#   modification, are permitted provided that the following conditions
#   are met:
#   
#   * Redistributions of source code must retain the above copyright
#     notice, this list of conditions and the following disclaimer.
#   * 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.
#   * Neither the name of iMatix Corporation nor the names of its
#     contributors may be used to endorse or promote products derived
#     from this software without specific prior written permission.
#   
#   THIS SOFTWARE IS PROVIDED BY IMATIX CORPORATION "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 IMATIX CORPORATION 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.
#
#   Utility functions for parsing BOOM_MODEL
#

#   Returns a list of all BOOM_MODEL_$MODEL variables set
boom_model_list () {
    set |
        awk 'BEGIN                      { FS="[=_]" }
             /^BOOM_MODEL_[A-Z0-9]*=1$/ { print $3  }'
}

#   Expands $BOOM_MODEL into individual BOOM_MODEL_$MODEL variables
boom_model_expand () {
    #   Clear any existing settings
    for MODEL in `boom_model_list`; do
        eval unset BOOM_MODEL_$MODEL
    done
    #   Iterate over BOOM_MODEL using ',' as FS
    OLD_IFS=$IFS
    IFS=,
    for MODEL in $BOOM_MODEL; do
        MODEL=`echo $MODEL | tr \[a-z\] \[A-Z\]`
        eval BOOM_MODEL_$MODEL=1
        eval export BOOM_MODEL_$MODEL
    done
    IFS=$OLD_IFS
}

#
#   Set default values for BOOM_MODEL
#
#   Default is release,st on all platforms except Linux and Solaris.
#
if [ -s /usr/bin/uname ]; then BOOM_PLATFORM=`/usr/bin/uname`; fi
if [ -s /bin/uname ];     then BOOM_PLATFORM=`/bin/uname`;     fi
if [ -z "$BOOM_MODEL" ]; then
    if [ "$BOOM_PLATFORM" = "Linux" -o "$BOOM_PLATFORM" = "SunOS" ]; then
        BOOM_MODEL=release,mt
    else
        BOOM_MODEL=release,st
    fi
fi
boom_model_expand
if [ "$BOOM_MODEL_RELEASE" != "1" ]; then
    if [ "$BOOM_MODEL_DEBUG" != "1" ]; then
        BOOM_MODEL_RELEASE=1
        BOOM_MODEL="$BOOM_MODEL,release"
    fi
fi
if [ "$BOOM_MODEL_ST" != "1" ]; then
    if [ "$BOOM_MODEL_MT" != "1" ]; then
        if [ "$BOOM_PLATFORM" = "Linux" -o "$BOOM_PLATFORM" = "SunOS" ]; then
            BOOM_MODEL_MT=1
            BOOM_MODEL="$BOOM_MODEL,mt"
        else
            BOOM_MODEL_ST=1
            BOOM_MODEL="$BOOM_MODEL,st"
        fi
    fi
fi

#   Check that IBASE has been configured
if [ -z "$IBASE" ]; then
    echo "boom E: The IBASE variable is not set.  Please set it to the"
    echo "boom E: location where PCRE should be installed."
    exit 1
fi

echo "boom I: PCRE configured for model           : $BOOM_MODEL"
echo "boom I: PCRE will be installed into         : $IBASE"
echo "boom I: Run './boomake build' to build PCRE"
exit 0
