#!/bin/sh
#
#   Boom builder for apr 1.3.3
#   Generated by iMatix Boom from standard.pwl
#   
#   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.
#
#   Force environment variables to point to install location
#   Start by using final IBASE, then handle local -install path
#
boom_model_list () {
    set |
        awk 'BEGIN                      { FS="[=_]" }
             /^BOOM_MODEL_[A-Z0-9]*=1$/ { print $3  }'
}
boom_model_expand () {
    for MODEL in `boom_model_list`; do
        eval unset BOOM_MODEL_$MODEL
    done
    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
}
croak() {
    if [ -n "$*" ]; then
        echo "boom E: [apr]: $* - stop" 1>&2
    else
        echo "boom E: [apr]: stop" 1>&2
    fi
    exit 1
}
carp() {
    echo "boom I: [apr]: $*" 1>&2
}
trap 'croak "Interrupted"' INT
trap 'croak "Terminated"' TERM
trap 'croak "Quit"' QUIT
self=$0
MY_VERSION="1.3.3"
#
#   Set default values for BOOM_MODEL
#
#   Default is release,mt on all platforms.
#
if [ -z "$BOOM_MODEL" ]; then
    BOOM_MODEL=release,mt
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
            BOOM_MODEL="$BOOM_MODEL,mt"
    fi
fi
if [ -z "$IBASE" ]; then
    carp "The IBASE variable is not set.  Please set it to the location where apr should be installed."
    exit 1
fi
if [ "$1" = "-v" ]; then
    BOOM_TRACE=1
    export BOOM_TRACE
    shift
fi
if [ "$1" != "-install" ]; then
    #   Normal use, use IBASE
    PATH=.:$IBASE/bin:$PATH; export PATH
    PERLLIB=.:$IBASE/bin:$PERLLIB; export PERLLIB
    INCDIR_ALT=$IBASE/include; export INCDIR_ALT
    _LOCAL_BASE=
    _INSTALL_ROOT=$IBASE
else
    #   Building product, we use -install directory first, then IBASE
    CURDIR=`pwd`
    cd $2
    _LOCAL_BASE=`pwd`
    cd $CURDIR
    PATH=.:$_LOCAL_BASE/bin:$IBASE/bin:$PATH; export PATH
    PERLLIB=.:$_LOCAL_BASE/bin:$IBASE/bin:$PERLLIB; export PERLLIB
    INCDIR_ALT=$_LOCAL_BASE/include:$IBASE/include; export INCDIR_ALT
    shift
    shift
    _INSTALL_ROOT=$_LOCAL_BASE
fi

# --------------------------   BUILD BINARY FILES   ---------------------------

a_build_binary_files() {
:
    carp "Building apr..."
    #   To prevent compatibility warnings...
    INCDIR=
    LIBDIR=
    export LIBDIR INCDIR
    if [ "$BOOM_TRACE" ]; then
        MY_COPTS=-v
    else
        MY_COPTS=-q
    fi
    if [ ! -z "$_LOCAL_BASE" ]; then
        MY_COPTS="$MY_COPTS -li $_LOCAL_BASE/include -ll $_LOCAL_BASE/lib"
    fi

    conf_opts="--without-libtool --disable-shared --without-sendfile --enable-threads --enable-nonportable-atomics"
    if [ -z "$BOOM_TRACE" ]; then
        conf_opts="$conf_opts --quiet"
    fi
    if [ "$BOOM_MODEL_RELEASE" ]; then
        conf_opts="$conf_opts --disable-debug"
    elif [ "$BOOM_MODEL_DEBUG" ]; then
        conf_opts="$conf_opts --enable-debug"
    else 
        croak "BOOM_MODEL is invalid or not set"
    fi
    
    if type ranlib >/dev/null 2>&1; then
        RANLIB='ranlib'
    else
        RANLIB='/bin/true'
    fi
    if type gmake >/dev/null 2>&1; then
        MAKE='gmake'
    else
        MAKE='make'
    fi
    if [ -z "$BOOM_TRACE" ]; then
        MAKE="$MAKE -s"
    fi
    
    cd apr
    if [ ! -f Makefile ]; then
        [ "$BOOM_TRACE" ] && echo "(apr) ./configure $conf_opts"
        ./configure $conf_opts  || croak "(apr) ./configure $conf_opts failed"
    fi
    
    [ "$BOOM_TRACE" ] && echo "(apr) $MAKE RANLIB=/bin/true"
    $MAKE RANLIB=/bin/true    || croak "(apr) $MAKE RANLIB=/bin/true failed"
    $RANLIB libapr*.la
    cd ..
    
    conf_opts="$conf_opts --with-apr=../apr --without-gdbm --without-ndbm --without-berkeley-db --without-pgsql --without-mysql --without-sqlite2 --without-sqlite3 --without-oracle --without-freetds --without-odbc"
    cd apr-util
    if [ ! -f Makefile ]; then
        [ "$BOOM_TRACE" ] && echo "(apr-util) ./configure $conf_opts"
        ./configure $conf_opts  || croak "(apr-util) ./configure $conf_opts failed"
    fi
    [ "$BOOM_TRACE" ] && echo "(apr-util) $MAKE RANLIB=/bin/true"
    $MAKE RANLIB=/bin/true    || croak "(apr-util) $MAKE RANLIB=/bin/true failed"
    $RANLIB libaprutil*.la
    cd ..
    
    (
        cp apr/libapr*.la          libapr.a          || exit 1
        cp apr/include/apr*.h      .                 || exit 1
        cp apr-util/libaprutil*.la libaprutil.a      || exit 1
        cp apr-util/include/apr*.h .                 || exit 1
        cp apr-util/include/apu*.h .                 || exit 1
    ) || croak "Missing deliverables for apr/apr-util"
    
}

# -------------------------   BUILD SOURCE PACKAGES   -------------------------

a_build_source_packages() {
:
    rm -f _package.lst
    if [ -f "apr/project.pdl" ]; then
        echo apr/project.pdl>>_package.lst
    fi
    if [ -f "apr/apr_package_lst.pl" ]; then
        echo apr/apr_package_lst.pl>>_package.lst
    fi
    if [ -f "apr/base_apr.h" ]; then
        echo apr/base_apr.h>>_package.lst
    fi
    if [ "`echo apr/apr*.h`" != "apr/apr*.h" ]; then
        for file in `echo apr/apr*.h`; do
            echo $file>>_package.lst
        done
    fi
    if [ "`echo apr/apu*.h`" != "apr/apu*.h" ]; then
        for file in `echo apr/apu*.h`; do
            echo $file>>_package.lst
        done
    fi
    if [ -f "apr/stamp_generate" ]; then
        echo apr/stamp_generate>>_package.lst
    fi
    if [ -f "apr/configure" ]; then
        echo apr/configure>>_package.lst
    fi
    if [ -f "apr/Makefile.unix" ]; then
        echo apr/Makefile.unix>>_package.lst
    fi
    if [ -f "apr/boomake" ]; then
        echo apr/boomake>>_package.lst
    fi
    if [ -f "apr/configure.bat" ]; then
        echo apr/configure.bat>>_package.lst
    fi
    if [ -f "apr/Makefile.win32" ]; then
        echo apr/Makefile.win32>>_package.lst
    fi
    if [ -f "apr/boomake.bat" ]; then
        echo apr/boomake.bat>>_package.lst
    fi
    if [ -f "apr/boomakew.bat" ]; then
        echo apr/boomakew.bat>>_package.lst
    fi
    echo "Source package successfully generated">stamp_source
    echo "stamp_source">>_package.lst
    carp "Building apr-$MY_VERSION-src.tar.gz..."
    zip  -rq _package.zip -@<_package.lst
    unzip -q _package.zip -d apr-$MY_VERSION
    rm -f apr-$MY_VERSION-src.tar.gz
    tar -cf  apr-$MY_VERSION-src.tar apr-$MY_VERSION
    gzip apr-$MY_VERSION-src.tar
    rm -f apr-$MY_VERSION-src.zip
    carp "Building apr-$MY_VERSION-src.zip..."
    zip -lrmq apr-$MY_VERSION-src.zip apr-$MY_VERSION
    rm _package.zip
    rm _package.lst
    rm stamp_source
}

# ---------------------   CHECK ALL SOURCE FILES EXIST   ----------------------

a_check_all_source_files_exist() {
:
    if [ ! -f "project.pdl" ]; then
        croak "project.pdl is missing"
    fi
    if [ ! -f "apr_package_lst.pl" ]; then
        croak "apr_package_lst.pl is missing"
    fi
    if [ ! -f "base_apr.h" ]; then
        croak "base_apr.h is missing"
    fi
    if [ "`echo apr*.h`" = "apr*.h" ]; then
        croak "apr*.h is missing"
    fi
    if [ "`echo apu*.h`" = "apu*.h" ]; then
        croak "apu*.h is missing"
    fi
    if [ ! -f "stamp_generate" ]; then
        croak "stamp_generate is missing"
    fi
    if [ ! -f "configure" ]; then
        croak "configure is missing"
    fi
    if [ ! -f "Makefile.unix" ]; then
        croak "Makefile.unix is missing"
    fi
    if [ ! -f "boomake" ]; then
        croak "boomake is missing"
    fi
    if [ ! -f "configure.bat" ]; then
        croak "configure.bat is missing"
    fi
    if [ ! -f "Makefile.win32" ]; then
        croak "Makefile.win32 is missing"
    fi
    if [ ! -f "boomake.bat" ]; then
        croak "boomake.bat is missing"
    fi
    if [ ! -f "boomakew.bat" ]; then
        croak "boomakew.bat is missing"
    fi
}

# -----------------------   CHECK BINARY FILES EXIST   ------------------------

a_check_binary_files_exist() {
:
    if [ ! -f "libapr.a" ]; then
        croak "libapr.a is missing"
    fi
    if [ ! -f "libaprutil.a" ]; then
        croak "libaprutil.a is missing"
    fi
    if [ ! -f "base_apr.h" ]; then
        croak "base_apr.h is missing"
    fi
    if [ "`echo apr*.h`" = "apr*.h" ]; then
        croak "apr*.h is missing"
    fi
    if [ "`echo apu*.h`" = "apu*.h" ]; then
        croak "apu*.h is missing"
    fi
}

# ------------------------   CHECK OPERATING CONTEXT   ------------------------

a_check_operating_context() {
:
    if [ -f ./stamp_stripped ]; then
        event=stripped
    elif [ -f ./stamp_source ]; then
        event=source
    else
        event=repository
    fi
}

# -----------------------   CHECK PROJECT FILES EXIST   -----------------------

a_check_project_files_exist() {
:
    if [ ! -f "project.pdl" ]; then
        croak "project.pdl is missing"
    fi
    if [ ! -f "apr_package_lst.pl" ]; then
        croak "apr_package_lst.pl is missing"
    fi
    if [ ! -f "base_apr.h" ]; then
        croak "base_apr.h is missing"
    fi
    if [ ! -f "boomake" ]; then
        croak "boomake is missing"
    fi
    if [ ! -f "boomake.bat" ]; then
        croak "boomake.bat is missing"
    fi
    if [ ! -f "boomakew.bat" ]; then
        croak "boomakew.bat is missing"
    fi
}

# -----------------------   CHECK SOURCE FILES EXIST   ------------------------

a_check_source_files_exist() {
:
    if [ ! -f "project.pdl" ]; then
        croak "project.pdl is missing"
    fi
    if [ ! -f "apr_package_lst.pl" ]; then
        croak "apr_package_lst.pl is missing"
    fi
    if [ ! -f "base_apr.h" ]; then
        croak "base_apr.h is missing"
    fi
    if [ "`echo apr*.h`" = "apr*.h" ]; then
        croak "apr*.h is missing"
    fi
    if [ "`echo apu*.h`" = "apu*.h" ]; then
        croak "apu*.h is missing"
    fi
    if [ ! -f "stamp_generate" ]; then
        croak "stamp_generate is missing"
    fi
    if [ ! -f "configure" ]; then
        croak "configure is missing"
    fi
    if [ ! -f "Makefile.unix" ]; then
        croak "Makefile.unix is missing"
    fi
    if [ ! -f "boomake" ]; then
        croak "boomake is missing"
    fi
    if [ ! -f "configure.bat" ]; then
        croak "configure.bat is missing"
    fi
    if [ ! -f "Makefile.win32" ]; then
        croak "Makefile.win32 is missing"
    fi
    if [ ! -f "boomake.bat" ]; then
        croak "boomake.bat is missing"
    fi
    if [ ! -f "boomakew.bat" ]; then
        croak "boomakew.bat is missing"
    fi
}

# -------------------------   INSTALL DELIVERABLES   --------------------------

a_install_deliverables() {
:
    carp "Installing apr into $_INSTALL_ROOT..."
    if [ ! -d "$_INSTALL_ROOT" ]; then
        if mkdir -p $_INSTALL_ROOT; then
            :
        else
            croak "Could not create directory \"$_INSTALL_ROOT\""
        fi
    fi
    mkdir -p $_INSTALL_ROOT/lib/
    [ "$BOOM_TRACE" ] && echo "cp libapr.a $_INSTALL_ROOT/lib/"
    cp libapr.a $_INSTALL_ROOT/lib/ || croak "\"cp libapr.a $_INSTALL_ROOT/lib/\" failed"
    [ "$BOOM_TRACE" ] && echo "chmod 0644 $_INSTALL_ROOT/lib/libapr.a"
    chmod 0644 $_INSTALL_ROOT/lib/libapr.a || croak "\"chmod 0644 $_INSTALL_ROOT/lib/libapr.a\" failed"
    [ "$BOOM_TRACE" ] && echo "cp libaprutil.a $_INSTALL_ROOT/lib/"
    cp libaprutil.a $_INSTALL_ROOT/lib/ || croak "\"cp libaprutil.a $_INSTALL_ROOT/lib/\" failed"
    [ "$BOOM_TRACE" ] && echo "chmod 0644 $_INSTALL_ROOT/lib/libaprutil.a"
    chmod 0644 $_INSTALL_ROOT/lib/libaprutil.a || croak "\"chmod 0644 $_INSTALL_ROOT/lib/libaprutil.a\" failed"
    mkdir -p $_INSTALL_ROOT/include/
    [ "$BOOM_TRACE" ] && echo "cp base_apr.h $_INSTALL_ROOT/include/"
    cp base_apr.h $_INSTALL_ROOT/include/ || croak "\"cp base_apr.h $_INSTALL_ROOT/include/\" failed"
    [ "$BOOM_TRACE" ] && echo "chmod 0644 $_INSTALL_ROOT/include/base_apr.h"
    chmod 0644 $_INSTALL_ROOT/include/base_apr.h || croak "\"chmod 0644 $_INSTALL_ROOT/include/base_apr.h\" failed"
    [ "$BOOM_TRACE" ] && echo "cp apr*.h $_INSTALL_ROOT/include/"
    cp apr*.h $_INSTALL_ROOT/include/ || croak "\"cp apr*.h $_INSTALL_ROOT/include/\" failed"
    [ "$BOOM_TRACE" ] && echo "chmod 0644 $_INSTALL_ROOT/include/apr*.h"
    chmod 0644 $_INSTALL_ROOT/include/apr*.h || croak "\"chmod 0644 $_INSTALL_ROOT/include/apr*.h\" failed"
    [ "$BOOM_TRACE" ] && echo "cp apu*.h $_INSTALL_ROOT/include/"
    cp apu*.h $_INSTALL_ROOT/include/ || croak "\"cp apu*.h $_INSTALL_ROOT/include/\" failed"
    [ "$BOOM_TRACE" ] && echo "chmod 0644 $_INSTALL_ROOT/include/apu*.h"
    chmod 0644 $_INSTALL_ROOT/include/apu*.h || croak "\"chmod 0644 $_INSTALL_ROOT/include/apu*.h\" failed"
    if [ -f ./installer ]; then
    [ "$BOOM_TRACE" ] && echo "sh ./installer"
    sh ./installer || croak "\"sh ./installer\" failed"
    fi
}

# ----------------------   PRODUCE ALL GENERATED FILES   ----------------------

a_produce_all_generated_files() {
:
    carp "Generating files..."

    echo "/*  Placeholder  */">apr.h
    echo "/*  Placeholder  */">apu.h
    
    echo "Source files successfully generated">stamp_generate
}

# ------------------------   PRODUCE GENERATED FILES   ------------------------

a_produce_generated_files() {
:
    carp "Generating files..."

    echo "/*  Placeholder  */">apr.h
    echo "/*  Placeholder  */">apu.h
    
    echo "Source files successfully generated">stamp_generate
}

# -----------------------   REMOVE GENERATED BINARIES   -----------------------

a_remove_generated_binaries() {
:
    rm -f libapr.a
    rm -f libaprutil.a
    rm -f liblocal.a

    (cd apr;      test -f Makefile && make -s distclean>/dev/null)
    (cd apr-util; test -f Makefile && make -s distclean>/dev/null)
    rm -f libapr*.a apr*.h apu*.h
    if [ -f stamp_source ]; then
        echo "/*  Placeholder  */">apr.h
        echo "/*  Placeholder  */">apu.h
    fi
    
}

# -----------------------   REMOVE GENERATED SOURCES   ------------------------

a_remove_generated_sources() {
:
    rm -f apr*.h
    rm -f apu*.h
    rm -f stamp_generate
    rm -f configure
    rm -f Makefile.unix
    rm -f configure.bat
    rm -f Makefile.win32
    rm -f apr_*.zip
    rm -f apr_*.tar.gz
}

# ------------------------   REPORT HELP INFORMATION   ------------------------

a_report_help_information() {
:
    echo "The commands you can currently use on this project are:"
    echo ""
    eval "actions_$state"
}

# ------------------------   REPORT PROJECT VERSION   -------------------------

a_report_project_version() {
:
    echo "apr-1.3.3"
}

# -------------------------   RUN REGRESSION TESTS   --------------------------

a_run_regression_tests() {
:
    #   Run local selftest script if present
    if [ -f ./selftest ]; then
    [ "$BOOM_TRACE" ] && echo "sh ./selftest"
    sh ./selftest || croak "\"sh ./selftest\" failed"
    fi
}

# ----------------------   USE SOURCE CONTROL REVISION   ----------------------

a_use_source_control_revision() {
:
    if [ -d .svn ]; then
        SVN_REVISION="`svn info | awk '/^Revision:/ { print $2 }'`"
    else
        SVN_REVISION="svn"
    fi
    MY_VERSION=${MY_VERSION}-${SVN_REVISION}
}

actions_initial() {
    return
}

actions_initial_check() {
    return
}

actions_repository() {
echo "build:"
    echo "  From the raw project sources, produces all generated files, and"
    echo "    compiles all source files."
echo "compile:"
    echo "  From the raw project sources, compiles all source files without any"
    echo "    code generation."
echo "clean:"
    echo "  When working with the raw project sources, removes all generated"
    echo "    source and binary files from the project directory."
echo "regen:"
    echo "  Produces generated files required for building using the"
    echo "    current model."
echo "allgen:"
    echo "  Produces all generated files."
echo "distrib:"
    echo "  Creates a source distribution for the project.  Note that binary"
    echo "    distributions can only be created at the product level."
echo "distsrc:"
    echo "  Equivalent to distrib, provided for compatibility."
echo "distrev:"
    echo "  Creates a source distribution for the project.  Builds distribution"
    echo "    packages based on source control version number. Note that binary"
    echo "    distributions can only be created at the product level."
actions_default
    return
}

actions_source() {
echo "build:"
    echo "  From the packaged sources, compiles all source files without any"
    echo "    code generation."
echo "clean:"
    echo "  When working with the packaged sources, removes all generated"
    echo "    binary files from the project directory."
echo "regen:"
    echo "  Produces generated files required for building using the"
    echo "    current model."
echo "allgen:"
    echo "  Produces all generated files."
actions_default
    return
}

actions_stripped() {
echo "build:"
    echo "  From the stripped-down packaged sources, compiles all source files"
    echo "    without any code generation."
echo "clean:"
    echo "  When working with the packaged sources, removes all generated"
    echo "    binary files from the project directory."
actions_default
    return
}

actions_default() {
echo "install:"
    echo "  Installs deliverables into the final or temporary install tree."
    echo "    This action is only valid after a successful build."
echo "test:"
    echo "  Runs regression tests for the project."
echo "help:"
    echo "  Shows a list of the commands allowed on the project."
echo "version:"
    echo "  Show project version."
    return
}

#   State machine starts here
#
firsttime=true
while [ "$1" -o "$firsttime" ]; do
  firsttime=
  state=initial
  event=ok
  debug=
  export state event debug
  while [ -n "$state" ]; do
    if [ "$inherit_state" ]; then
        check_state=$inherit_state
        inherit_state=
    else
        check_state=$state
    fi
    case "$check_state" in
    initial)
        if [ -n "$debug" ]; then
            echo "State: initial"
        fi
        case "$event" in
        "")
            if [ -n "$debug" ]; then
                echo "Get event from user"
            fi
            if [ "$1" ]; then
                event=$1
                shift
            else
                event=empty
            fi
            continue
        ;;
        ok)
            if [ -n "$debug" ]; then
                echo "Event: ok"
            fi
            event=
            exception=
            if [ -n "$debug" ]; then
                echo "Action: check operating context"
            fi
            if [ -z "$exception" ]; then
                a_check_operating_context
            fi
            state=initial_check
            if [ -n "$exception" ]; then
                continue
            fi
        ;;
        *)
            echo "Unknown command - use one of:"
            echo ""
            eval "actions_$state"
            exit 1
        ;;
        esac
    ;;
    initial_check)
        if [ -n "$debug" ]; then
            echo "State: initial check"
        fi
        case "$event" in
        "")
            if [ -n "$debug" ]; then
                echo "Get event from user"
            fi
            if [ "$1" ]; then
                event=$1
                shift
            else
                event=empty
            fi
            continue
        ;;
        repository)
            if [ -n "$debug" ]; then
                echo "Event: repository"
            fi
            event=
            exception=
            state=repository
            if [ -n "$exception" ]; then
                continue
            fi
        ;;
        source)
            if [ -n "$debug" ]; then
                echo "Event: source"
            fi
            event=
            exception=
            state=source
            if [ -n "$exception" ]; then
                continue
            fi
        ;;
        stripped)
            if [ -n "$debug" ]; then
                echo "Event: stripped"
            fi
            event=
            exception=
            state=stripped
            if [ -n "$exception" ]; then
                continue
            fi
        ;;
        *)
            echo "Unknown command - use one of:"
            echo ""
            eval "actions_$state"
            exit 1
        ;;
        esac
    ;;
    repository)
        if [ -n "$debug" ]; then
            echo "State: repository"
        fi
        case "$event" in
        "")
            if [ -n "$debug" ]; then
                echo "Get event from user"
            fi
            if [ "$1" ]; then
                event=$1
                shift
            else
                event=empty
            fi
            continue
        ;;
        build)
            if [ -n "$debug" ]; then
                echo "Event: build"
            fi
            event=
            exception=
            if [ -n "$debug" ]; then
                echo "Action: check project files exist"
            fi
            if [ -z "$exception" ]; then
                a_check_project_files_exist
            fi
            if [ -n "$debug" ]; then
                echo "Action: produce generated files"
            fi
            if [ -z "$exception" ]; then
                a_produce_generated_files
            fi
            if [ -n "$debug" ]; then
                echo "Action: check source files exist"
            fi
            if [ -z "$exception" ]; then
                a_check_source_files_exist
            fi
            if [ -n "$debug" ]; then
                echo "Action: build binary files"
            fi
            if [ -z "$exception" ]; then
                a_build_binary_files
            fi
            if [ -n "$1" -a -z "$exception" ]; then
                continue 2
            fi
            state=
        ;;
        compile)
            if [ -n "$debug" ]; then
                echo "Event: compile"
            fi
            event=
            exception=
            if [ -n "$debug" ]; then
                echo "Action: check source files exist"
            fi
            if [ -z "$exception" ]; then
                a_check_source_files_exist
            fi
            if [ -n "$debug" ]; then
                echo "Action: build binary files"
            fi
            if [ -z "$exception" ]; then
                a_build_binary_files
            fi
            if [ -n "$1" -a -z "$exception" ]; then
                continue 2
            fi
            state=
        ;;
        clean)
            if [ -n "$debug" ]; then
                echo "Event: clean"
            fi
            event=
            exception=
            if [ -n "$debug" ]; then
                echo "Action: remove generated sources"
            fi
            if [ -z "$exception" ]; then
                a_remove_generated_sources
            fi
            if [ -n "$debug" ]; then
                echo "Action: remove generated binaries"
            fi
            if [ -z "$exception" ]; then
                a_remove_generated_binaries
            fi
            if [ -n "$1" -a -z "$exception" ]; then
                continue 2
            fi
            state=
        ;;
        regen)
            if [ -n "$debug" ]; then
                echo "Event: regen"
            fi
            event=
            exception=
            if [ -n "$debug" ]; then
                echo "Action: check project files exist"
            fi
            if [ -z "$exception" ]; then
                a_check_project_files_exist
            fi
            if [ -n "$debug" ]; then
                echo "Action: produce generated files"
            fi
            if [ -z "$exception" ]; then
                a_produce_generated_files
            fi
            if [ -n "$1" -a -z "$exception" ]; then
                continue 2
            fi
            state=
        ;;
        allgen)
            if [ -n "$debug" ]; then
                echo "Event: allgen"
            fi
            event=
            exception=
            if [ -n "$debug" ]; then
                echo "Action: check project files exist"
            fi
            if [ -z "$exception" ]; then
                a_check_project_files_exist
            fi
            if [ -n "$debug" ]; then
                echo "Action: produce all generated files"
            fi
            if [ -z "$exception" ]; then
                a_produce_all_generated_files
            fi
            if [ -n "$1" -a -z "$exception" ]; then
                continue 2
            fi
            state=
        ;;
        distrib)
            if [ -n "$debug" ]; then
                echo "Event: distrib"
            fi
            event=
            exception=
            if [ -n "$debug" ]; then
                echo "Action: produce all generated files"
            fi
            if [ -z "$exception" ]; then
                a_produce_all_generated_files
            fi
            if [ -n "$debug" ]; then
                echo "Action: check all source files exist"
            fi
            if [ -z "$exception" ]; then
                a_check_all_source_files_exist
            fi
            if [ -n "$debug" ]; then
                echo "Action: build source packages"
            fi
            if [ -z "$exception" ]; then
                a_build_source_packages
            fi
            if [ -n "$1" -a -z "$exception" ]; then
                continue 2
            fi
            state=
        ;;
        distsrc)
            if [ -n "$debug" ]; then
                echo "Event: distsrc"
            fi
            event=
            exception=
            if [ -n "$debug" ]; then
                echo "Action: produce all generated files"
            fi
            if [ -z "$exception" ]; then
                a_produce_all_generated_files
            fi
            if [ -n "$debug" ]; then
                echo "Action: check all source files exist"
            fi
            if [ -z "$exception" ]; then
                a_check_all_source_files_exist
            fi
            if [ -n "$debug" ]; then
                echo "Action: build source packages"
            fi
            if [ -z "$exception" ]; then
                a_build_source_packages
            fi
            if [ -n "$1" -a -z "$exception" ]; then
                continue 2
            fi
            state=
        ;;
        distrev)
            if [ -n "$debug" ]; then
                echo "Event: distrev"
            fi
            event=
            exception=
            if [ -n "$debug" ]; then
                echo "Action: produce all generated files"
            fi
            if [ -z "$exception" ]; then
                a_produce_all_generated_files
            fi
            if [ -n "$debug" ]; then
                echo "Action: check all source files exist"
            fi
            if [ -z "$exception" ]; then
                a_check_all_source_files_exist
            fi
            if [ -n "$debug" ]; then
                echo "Action: use source control revision"
            fi
            if [ -z "$exception" ]; then
                a_use_source_control_revision
            fi
            if [ -n "$debug" ]; then
                echo "Action: build source packages"
            fi
            if [ -z "$exception" ]; then
                a_build_source_packages
            fi
            if [ -n "$1" -a -z "$exception" ]; then
                continue 2
            fi
            state=
        ;;
        *)
            inherit_state=default
        ;;
        esac
    ;;
    source)
        if [ -n "$debug" ]; then
            echo "State: source"
        fi
        case "$event" in
        "")
            if [ -n "$debug" ]; then
                echo "Get event from user"
            fi
            if [ "$1" ]; then
                event=$1
                shift
            else
                event=empty
            fi
            continue
        ;;
        build)
            if [ -n "$debug" ]; then
                echo "Event: build"
            fi
            event=
            exception=
            if [ -n "$debug" ]; then
                echo "Action: check source files exist"
            fi
            if [ -z "$exception" ]; then
                a_check_source_files_exist
            fi
            if [ -n "$debug" ]; then
                echo "Action: build binary files"
            fi
            if [ -z "$exception" ]; then
                a_build_binary_files
            fi
            if [ -n "$1" -a -z "$exception" ]; then
                continue 2
            fi
            state=
        ;;
        clean)
            if [ -n "$debug" ]; then
                echo "Event: clean"
            fi
            event=
            exception=
            if [ -n "$debug" ]; then
                echo "Action: remove generated binaries"
            fi
            if [ -z "$exception" ]; then
                a_remove_generated_binaries
            fi
            if [ -n "$1" -a -z "$exception" ]; then
                continue 2
            fi
            state=
        ;;
        regen)
            if [ -n "$debug" ]; then
                echo "Event: regen"
            fi
            event=
            exception=
            if [ -n "$debug" ]; then
                echo "Action: check project files exist"
            fi
            if [ -z "$exception" ]; then
                a_check_project_files_exist
            fi
            if [ -n "$debug" ]; then
                echo "Action: produce generated files"
            fi
            if [ -z "$exception" ]; then
                a_produce_generated_files
            fi
            if [ -n "$1" -a -z "$exception" ]; then
                continue 2
            fi
            state=
        ;;
        allgen)
            if [ -n "$debug" ]; then
                echo "Event: allgen"
            fi
            event=
            exception=
            if [ -n "$debug" ]; then
                echo "Action: check project files exist"
            fi
            if [ -z "$exception" ]; then
                a_check_project_files_exist
            fi
            if [ -n "$debug" ]; then
                echo "Action: produce all generated files"
            fi
            if [ -z "$exception" ]; then
                a_produce_all_generated_files
            fi
            if [ -n "$1" -a -z "$exception" ]; then
                continue 2
            fi
            state=
        ;;
        *)
            inherit_state=default
        ;;
        esac
    ;;
    stripped)
        if [ -n "$debug" ]; then
            echo "State: stripped"
        fi
        case "$event" in
        "")
            if [ -n "$debug" ]; then
                echo "Get event from user"
            fi
            if [ "$1" ]; then
                event=$1
                shift
            else
                event=empty
            fi
            continue
        ;;
        build)
            if [ -n "$debug" ]; then
                echo "Event: build"
            fi
            event=
            exception=
            if [ -n "$debug" ]; then
                echo "Action: build binary files"
            fi
            if [ -z "$exception" ]; then
                a_build_binary_files
            fi
            if [ -n "$1" -a -z "$exception" ]; then
                continue 2
            fi
            state=
        ;;
        clean)
            if [ -n "$debug" ]; then
                echo "Event: clean"
            fi
            event=
            exception=
            if [ -n "$debug" ]; then
                echo "Action: remove generated binaries"
            fi
            if [ -z "$exception" ]; then
                a_remove_generated_binaries
            fi
            if [ -n "$1" -a -z "$exception" ]; then
                continue 2
            fi
            state=
        ;;
        *)
            inherit_state=default
        ;;
        esac
    ;;
    default)
        if [ -n "$debug" ]; then
            echo "State: default"
        fi
        case "$event" in
        "")
            if [ -n "$debug" ]; then
                echo "Get event from user"
            fi
            if [ "$1" ]; then
                event=$1
                shift
            else
                event=empty
            fi
            continue
        ;;
        install)
            if [ -n "$debug" ]; then
                echo "Event: install"
            fi
            event=
            exception=
            if [ -n "$debug" ]; then
                echo "Action: check binary files exist"
            fi
            if [ -z "$exception" ]; then
                a_check_binary_files_exist
            fi
            if [ -n "$debug" ]; then
                echo "Action: install deliverables"
            fi
            if [ -z "$exception" ]; then
                a_install_deliverables
            fi
            if [ -n "$1" -a -z "$exception" ]; then
                continue 2
            fi
            state=
        ;;
        test)
            if [ -n "$debug" ]; then
                echo "Event: test"
            fi
            event=
            exception=
            if [ -n "$debug" ]; then
                echo "Action: check binary files exist"
            fi
            if [ -z "$exception" ]; then
                a_check_binary_files_exist
            fi
            if [ -n "$debug" ]; then
                echo "Action: run regression tests"
            fi
            if [ -z "$exception" ]; then
                a_run_regression_tests
            fi
            if [ -n "$1" -a -z "$exception" ]; then
                continue 2
            fi
            state=
        ;;
        help)
            if [ -n "$debug" ]; then
                echo "Event: help"
            fi
            event=
            exception=
            if [ -n "$debug" ]; then
                echo "Action: report help information"
            fi
            if [ -z "$exception" ]; then
                a_report_help_information
            fi
            if [ -n "$1" -a -z "$exception" ]; then
                continue 2
            fi
            state=
        ;;
        version)
            if [ -n "$debug" ]; then
                echo "Event: version"
            fi
            event=
            exception=
            if [ -n "$debug" ]; then
                echo "Action: report project version"
            fi
            if [ -z "$exception" ]; then
                a_report_project_version
            fi
            if [ -n "$1" -a -z "$exception" ]; then
                continue 2
            fi
            state=
        ;;
        empty)
            if [ -n "$debug" ]; then
                echo "Event: empty"
            fi
            event=
            exception=
            if [ -n "$debug" ]; then
                echo "Action: report help information"
            fi
            if [ -z "$exception" ]; then
                a_report_help_information
            fi
            if [ -n "$1" -a -z "$exception" ]; then
                continue 2
            fi
            state=
        ;;
        *)
            echo "Unknown command - use one of:"
            echo ""
            eval "actions_$state"
            exit 1
        ;;
        esac
    ;;
    esac
  done
done
