#!/bin/sh
#
#   Boom builder for Zlib 1.2.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: [zlib]: $* - stop" 1>&2
    else
        echo "boom E: [zlib]: stop" 1>&2
    fi
    exit 1
}
carp() {
    echo "boom I: [zlib]: $*" 1>&2
}
trap 'croak "Interrupted"' INT
trap 'croak "Terminated"' TERM
trap 'croak "Quit"' QUIT
self=$0
MY_VERSION="1.2.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 Zlib 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 Zlib..."
    #   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
    [ "$BOOM_TRACE" ] && echo "c $MY_COPTS adler32"
    c $MY_COPTS adler32 || croak "\"c $MY_COPTS adler32\" failed"
    [ "$BOOM_TRACE" ] && echo "c $MY_COPTS compress"
    c $MY_COPTS compress || croak "\"c $MY_COPTS compress\" failed"
    [ "$BOOM_TRACE" ] && echo "c $MY_COPTS gzio"
    c $MY_COPTS gzio || croak "\"c $MY_COPTS gzio\" failed"
    [ "$BOOM_TRACE" ] && echo "c $MY_COPTS uncompr"
    c $MY_COPTS uncompr || croak "\"c $MY_COPTS uncompr\" failed"
    [ "$BOOM_TRACE" ] && echo "c $MY_COPTS crc32"
    c $MY_COPTS crc32 || croak "\"c $MY_COPTS crc32\" failed"
    [ "$BOOM_TRACE" ] && echo "c $MY_COPTS deflate"
    c $MY_COPTS deflate || croak "\"c $MY_COPTS deflate\" failed"
    [ "$BOOM_TRACE" ] && echo "c $MY_COPTS trees"
    c $MY_COPTS trees || croak "\"c $MY_COPTS trees\" failed"
    [ "$BOOM_TRACE" ] && echo "c $MY_COPTS zutil"
    c $MY_COPTS zutil || croak "\"c $MY_COPTS zutil\" failed"
    [ "$BOOM_TRACE" ] && echo "c $MY_COPTS inflate"
    c $MY_COPTS inflate || croak "\"c $MY_COPTS inflate\" failed"
    [ "$BOOM_TRACE" ] && echo "c $MY_COPTS infback"
    c $MY_COPTS infback || croak "\"c $MY_COPTS infback\" failed"
    [ "$BOOM_TRACE" ] && echo "c $MY_COPTS inftrees"
    c $MY_COPTS inftrees || croak "\"c $MY_COPTS inftrees\" failed"
    [ "$BOOM_TRACE" ] && echo "c $MY_COPTS inffast"
    c $MY_COPTS inffast || croak "\"c $MY_COPTS inffast\" failed"
    [ "$BOOM_TRACE" ] && echo "c $MY_COPTS -r libzip adler32"
    c $MY_COPTS -r libzip adler32 || croak "\"c $MY_COPTS -r libzip adler32\" failed"
    [ "$BOOM_TRACE" ] && echo "c $MY_COPTS -r libzip compress"
    c $MY_COPTS -r libzip compress || croak "\"c $MY_COPTS -r libzip compress\" failed"
    [ "$BOOM_TRACE" ] && echo "c $MY_COPTS -r libzip gzio"
    c $MY_COPTS -r libzip gzio || croak "\"c $MY_COPTS -r libzip gzio\" failed"
    [ "$BOOM_TRACE" ] && echo "c $MY_COPTS -r libzip uncompr"
    c $MY_COPTS -r libzip uncompr || croak "\"c $MY_COPTS -r libzip uncompr\" failed"
    [ "$BOOM_TRACE" ] && echo "c $MY_COPTS -r libzip crc32"
    c $MY_COPTS -r libzip crc32 || croak "\"c $MY_COPTS -r libzip crc32\" failed"
    [ "$BOOM_TRACE" ] && echo "c $MY_COPTS -r libzip deflate"
    c $MY_COPTS -r libzip deflate || croak "\"c $MY_COPTS -r libzip deflate\" failed"
    [ "$BOOM_TRACE" ] && echo "c $MY_COPTS -r libzip trees"
    c $MY_COPTS -r libzip trees || croak "\"c $MY_COPTS -r libzip trees\" failed"
    [ "$BOOM_TRACE" ] && echo "c $MY_COPTS -r libzip zutil"
    c $MY_COPTS -r libzip zutil || croak "\"c $MY_COPTS -r libzip zutil\" failed"
    [ "$BOOM_TRACE" ] && echo "c $MY_COPTS -r libzip inflate"
    c $MY_COPTS -r libzip inflate || croak "\"c $MY_COPTS -r libzip inflate\" failed"
    [ "$BOOM_TRACE" ] && echo "c $MY_COPTS -r libzip infback"
    c $MY_COPTS -r libzip infback || croak "\"c $MY_COPTS -r libzip infback\" failed"
    [ "$BOOM_TRACE" ] && echo "c $MY_COPTS -r libzip inftrees"
    c $MY_COPTS -r libzip inftrees || croak "\"c $MY_COPTS -r libzip inftrees\" failed"
    [ "$BOOM_TRACE" ] && echo "c $MY_COPTS -r libzip inffast"
    c $MY_COPTS -r libzip inffast || croak "\"c $MY_COPTS -r libzip inffast\" failed"
    PUSHDIR=`pwd`
    cd contrib/minizip/
    [ "$BOOM_TRACE" ] && echo "c $MY_COPTS ioapi"
    c $MY_COPTS ioapi || croak "\"c $MY_COPTS ioapi\" failed"
    [ "$BOOM_TRACE" ] && echo "c $MY_COPTS unzip"
    c $MY_COPTS unzip || croak "\"c $MY_COPTS unzip\" failed"
    [ "$BOOM_TRACE" ] && echo "c $MY_COPTS zip"
    c $MY_COPTS zip || croak "\"c $MY_COPTS zip\" failed"
    cd $PUSHDIR
    [ "$BOOM_TRACE" ] && echo "c $MY_COPTS -r libzip contrib/minizip/ioapi"
    c $MY_COPTS -r libzip contrib/minizip/ioapi || croak "\"c $MY_COPTS -r libzip contrib/minizip/ioapi\" failed"
    [ "$BOOM_TRACE" ] && echo "c $MY_COPTS -r libzip contrib/minizip/unzip"
    c $MY_COPTS -r libzip contrib/minizip/unzip || croak "\"c $MY_COPTS -r libzip contrib/minizip/unzip\" failed"
    [ "$BOOM_TRACE" ] && echo "c $MY_COPTS -r libzip contrib/minizip/zip"
    c $MY_COPTS -r libzip contrib/minizip/zip || croak "\"c $MY_COPTS -r libzip contrib/minizip/zip\" failed"
}

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

a_build_source_packages() {
:
    rm -f _package.lst
    if [ -f "zlib/ChangeLog" ]; then
        echo zlib/ChangeLog>>_package.lst
    fi
    if [ -f "zlib/FAQ" ]; then
        echo zlib/FAQ>>_package.lst
    fi
    if [ -f "zlib/README" ]; then
        echo zlib/README>>_package.lst
    fi
    if [ -f "zlib/algorithm.txt" ]; then
        echo zlib/algorithm.txt>>_package.lst
    fi
    if [ -f "zlib/zlib.3" ]; then
        echo zlib/zlib.3>>_package.lst
    fi
    if [ -f "zlib/adler32.c" ]; then
        echo zlib/adler32.c>>_package.lst
    fi
    if [ -f "zlib/compress.c" ]; then
        echo zlib/compress.c>>_package.lst
    fi
    if [ -f "zlib/gzio.c" ]; then
        echo zlib/gzio.c>>_package.lst
    fi
    if [ -f "zlib/uncompr.c" ]; then
        echo zlib/uncompr.c>>_package.lst
    fi
    if [ -f "zlib/crc32.c" ]; then
        echo zlib/crc32.c>>_package.lst
    fi
    if [ -f "zlib/deflate.c" ]; then
        echo zlib/deflate.c>>_package.lst
    fi
    if [ -f "zlib/trees.c" ]; then
        echo zlib/trees.c>>_package.lst
    fi
    if [ -f "zlib/zutil.c" ]; then
        echo zlib/zutil.c>>_package.lst
    fi
    if [ -f "zlib/inflate.c" ]; then
        echo zlib/inflate.c>>_package.lst
    fi
    if [ -f "zlib/infback.c" ]; then
        echo zlib/infback.c>>_package.lst
    fi
    if [ -f "zlib/inftrees.c" ]; then
        echo zlib/inftrees.c>>_package.lst
    fi
    if [ -f "zlib/inffast.c" ]; then
        echo zlib/inffast.c>>_package.lst
    fi
    if [ -f "zlib/inffixed.h" ]; then
        echo zlib/inffixed.h>>_package.lst
    fi
    if [ -f "zlib/zconf.h" ]; then
        echo zlib/zconf.h>>_package.lst
    fi
    if [ -f "zlib/zlib.h" ]; then
        echo zlib/zlib.h>>_package.lst
    fi
    if [ -f "zlib/prelude.pdl" ]; then
        echo zlib/prelude.pdl>>_package.lst
    fi
    if [ -f "zlib/license.gpl" ]; then
        echo zlib/license.gpl>>_package.lst
    fi
    if [ -f "zlib/project.pdl" ]; then
        echo zlib/project.pdl>>_package.lst
    fi
    if [ -f "zlib/readme.txt" ]; then
        echo zlib/readme.txt>>_package.lst
    fi
    if [ -f "zlib/crc32.h" ]; then
        echo zlib/crc32.h>>_package.lst
    fi
    if [ -f "zlib/deflate.h" ]; then
        echo zlib/deflate.h>>_package.lst
    fi
    if [ -f "zlib/trees.h" ]; then
        echo zlib/trees.h>>_package.lst
    fi
    if [ -f "zlib/zutil.h" ]; then
        echo zlib/zutil.h>>_package.lst
    fi
    if [ -f "zlib/inflate.h" ]; then
        echo zlib/inflate.h>>_package.lst
    fi
    if [ -f "zlib/inftrees.h" ]; then
        echo zlib/inftrees.h>>_package.lst
    fi
    if [ -f "zlib/inffast.h" ]; then
        echo zlib/inffast.h>>_package.lst
    fi
    if [ -f "zlib/stamp_generate" ]; then
        echo zlib/stamp_generate>>_package.lst
    fi
    if [ -f "zlib/configure" ]; then
        echo zlib/configure>>_package.lst
    fi
    if [ -f "zlib/Makefile.unix" ]; then
        echo zlib/Makefile.unix>>_package.lst
    fi
    if [ -f "zlib/boomake" ]; then
        echo zlib/boomake>>_package.lst
    fi
    if [ -f "zlib/configure.bat" ]; then
        echo zlib/configure.bat>>_package.lst
    fi
    if [ -f "zlib/Makefile.win32" ]; then
        echo zlib/Makefile.win32>>_package.lst
    fi
    if [ -f "zlib/boomake.bat" ]; then
        echo zlib/boomake.bat>>_package.lst
    fi
    if [ -f "zlib/boomakew.bat" ]; then
        echo zlib/boomakew.bat>>_package.lst
    fi
    if [ -f "zlib/contrib/minizip/ChangeLogUnzip" ]; then
        echo zlib/contrib/minizip/ChangeLogUnzip>>_package.lst
    fi
    if [ -f "zlib/contrib/minizip/crypt.h" ]; then
        echo zlib/contrib/minizip/crypt.h>>_package.lst
    fi
    if [ -f "zlib/contrib/minizip/ioapi.c" ]; then
        echo zlib/contrib/minizip/ioapi.c>>_package.lst
    fi
    if [ -f "zlib/contrib/minizip/unzip.c" ]; then
        echo zlib/contrib/minizip/unzip.c>>_package.lst
    fi
    if [ -f "zlib/contrib/minizip/zip.c" ]; then
        echo zlib/contrib/minizip/zip.c>>_package.lst
    fi
    if [ -f "zlib/contrib/minizip/ioapi.h" ]; then
        echo zlib/contrib/minizip/ioapi.h>>_package.lst
    fi
    if [ -f "zlib/contrib/minizip/unzip.h" ]; then
        echo zlib/contrib/minizip/unzip.h>>_package.lst
    fi
    if [ -f "zlib/contrib/minizip/zip.h" ]; then
        echo zlib/contrib/minizip/zip.h>>_package.lst
    fi
    if [ -f "zlib/contrib/minizip/zconf.h" ]; then
        echo zlib/contrib/minizip/zconf.h>>_package.lst
    fi
    if [ -f "zlib/contrib/minizip/zlib.h" ]; then
        echo zlib/contrib/minizip/zlib.h>>_package.lst
    fi
    echo "Source package successfully generated">stamp_source
    echo "stamp_source">>_package.lst
    carp "Building zlib-$MY_VERSION-src.tar.gz..."
    zip  -rq _package.zip -@<_package.lst
    unzip -q _package.zip -d zlib-$MY_VERSION
    rm -f zlib-$MY_VERSION-src.tar.gz
    tar -cf  zlib-$MY_VERSION-src.tar zlib-$MY_VERSION
    gzip zlib-$MY_VERSION-src.tar
    rm -f zlib-$MY_VERSION-src.zip
    carp "Building zlib-$MY_VERSION-src.zip..."
    zip -lrmq zlib-$MY_VERSION-src.zip zlib-$MY_VERSION
    rm _package.zip
    rm _package.lst
    rm stamp_source
}

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

a_check_all_source_files_exist() {
:
    if [ ! -f "ChangeLog" ]; then
        croak "ChangeLog is missing"
    fi
    if [ ! -f "FAQ" ]; then
        croak "FAQ is missing"
    fi
    if [ ! -f "README" ]; then
        croak "README is missing"
    fi
    if [ ! -f "algorithm.txt" ]; then
        croak "algorithm.txt is missing"
    fi
    if [ ! -f "zlib.3" ]; then
        croak "zlib.3 is missing"
    fi
    if [ ! -f "adler32.c" ]; then
        croak "adler32.c is missing"
    fi
    if [ ! -f "compress.c" ]; then
        croak "compress.c is missing"
    fi
    if [ ! -f "gzio.c" ]; then
        croak "gzio.c is missing"
    fi
    if [ ! -f "uncompr.c" ]; then
        croak "uncompr.c is missing"
    fi
    if [ ! -f "crc32.c" ]; then
        croak "crc32.c is missing"
    fi
    if [ ! -f "deflate.c" ]; then
        croak "deflate.c is missing"
    fi
    if [ ! -f "trees.c" ]; then
        croak "trees.c is missing"
    fi
    if [ ! -f "zutil.c" ]; then
        croak "zutil.c is missing"
    fi
    if [ ! -f "inflate.c" ]; then
        croak "inflate.c is missing"
    fi
    if [ ! -f "infback.c" ]; then
        croak "infback.c is missing"
    fi
    if [ ! -f "inftrees.c" ]; then
        croak "inftrees.c is missing"
    fi
    if [ ! -f "inffast.c" ]; then
        croak "inffast.c is missing"
    fi
    if [ ! -f "inffixed.h" ]; then
        croak "inffixed.h is missing"
    fi
    if [ ! -f "zconf.h" ]; then
        croak "zconf.h is missing"
    fi
    if [ ! -f "zlib.h" ]; then
        croak "zlib.h is missing"
    fi
    if [ ! -f "project.pdl" ]; then
        croak "project.pdl is missing"
    fi
    if [ ! -f "readme.txt" ]; then
        croak "readme.txt is missing"
    fi
    if [ ! -f "crc32.h" ]; then
        croak "crc32.h is missing"
    fi
    if [ ! -f "deflate.h" ]; then
        croak "deflate.h is missing"
    fi
    if [ ! -f "trees.h" ]; then
        croak "trees.h is missing"
    fi
    if [ ! -f "zutil.h" ]; then
        croak "zutil.h is missing"
    fi
    if [ ! -f "inflate.h" ]; then
        croak "inflate.h is missing"
    fi
    if [ ! -f "inftrees.h" ]; then
        croak "inftrees.h is missing"
    fi
    if [ ! -f "inffast.h" ]; then
        croak "inffast.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
    PUSHDIR=`pwd`
    cd contrib/minizip
    if [ ! -f "ChangeLogUnzip" ]; then
        croak "ChangeLogUnzip is missing"
    fi
    if [ ! -f "crypt.h" ]; then
        croak "crypt.h is missing"
    fi
    if [ ! -f "ioapi.c" ]; then
        croak "ioapi.c is missing"
    fi
    if [ ! -f "unzip.c" ]; then
        croak "unzip.c is missing"
    fi
    if [ ! -f "zip.c" ]; then
        croak "zip.c is missing"
    fi
    if [ ! -f "ioapi.h" ]; then
        croak "ioapi.h is missing"
    fi
    if [ ! -f "unzip.h" ]; then
        croak "unzip.h is missing"
    fi
    if [ ! -f "zip.h" ]; then
        croak "zip.h is missing"
    fi
    if [ ! -f "zconf.h" ]; then
        croak "zconf.h is missing"
    fi
    if [ ! -f "zlib.h" ]; then
        croak "zlib.h is missing"
    fi
    cd $PUSHDIR
}

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

a_check_binary_files_exist() {
:
    if [ ! -f "ChangeLog" ]; then
        croak "ChangeLog is missing"
    fi
    if [ ! -f "FAQ" ]; then
        croak "FAQ is missing"
    fi
    if [ ! -f "README" ]; then
        croak "README is missing"
    fi
    if [ ! -f "algorithm.txt" ]; then
        croak "algorithm.txt is missing"
    fi
    if [ ! -f "zlib.3" ]; then
        croak "zlib.3 is missing"
    fi
    if [ ! -f "zconf.h" ]; then
        croak "zconf.h is missing"
    fi
    if [ ! -f "zlib.h" ]; then
        croak "zlib.h is missing"
    fi
    if [ ! -f "libzip.a" ]; then
        croak "libzip.a is missing"
    fi
    if [ ! -f "readme.txt" ]; then
        croak "readme.txt is missing"
    fi
    PUSHDIR=`pwd`
    cd contrib/minizip
    if [ ! -f "ChangeLogUnzip" ]; then
        croak "ChangeLogUnzip is missing"
    fi
    if [ ! -f "ioapi.h" ]; then
        croak "ioapi.h is missing"
    fi
    if [ ! -f "unzip.h" ]; then
        croak "unzip.h is missing"
    fi
    if [ ! -f "zip.h" ]; then
        croak "zip.h is missing"
    fi
    cd $PUSHDIR
}

# ------------------------   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 "ChangeLog" ]; then
        croak "ChangeLog is missing"
    fi
    if [ ! -f "FAQ" ]; then
        croak "FAQ is missing"
    fi
    if [ ! -f "README" ]; then
        croak "README is missing"
    fi
    if [ ! -f "algorithm.txt" ]; then
        croak "algorithm.txt is missing"
    fi
    if [ ! -f "zlib.3" ]; then
        croak "zlib.3 is missing"
    fi
    if [ ! -f "adler32.c" ]; then
        croak "adler32.c is missing"
    fi
    if [ ! -f "compress.c" ]; then
        croak "compress.c is missing"
    fi
    if [ ! -f "gzio.c" ]; then
        croak "gzio.c is missing"
    fi
    if [ ! -f "uncompr.c" ]; then
        croak "uncompr.c is missing"
    fi
    if [ ! -f "crc32.c" ]; then
        croak "crc32.c is missing"
    fi
    if [ ! -f "deflate.c" ]; then
        croak "deflate.c is missing"
    fi
    if [ ! -f "trees.c" ]; then
        croak "trees.c is missing"
    fi
    if [ ! -f "zutil.c" ]; then
        croak "zutil.c is missing"
    fi
    if [ ! -f "inflate.c" ]; then
        croak "inflate.c is missing"
    fi
    if [ ! -f "infback.c" ]; then
        croak "infback.c is missing"
    fi
    if [ ! -f "inftrees.c" ]; then
        croak "inftrees.c is missing"
    fi
    if [ ! -f "inffast.c" ]; then
        croak "inffast.c is missing"
    fi
    if [ ! -f "inffixed.h" ]; then
        croak "inffixed.h is missing"
    fi
    if [ ! -f "zconf.h" ]; then
        croak "zconf.h is missing"
    fi
    if [ ! -f "zlib.h" ]; then
        croak "zlib.h is missing"
    fi
    if [ ! -f "project.pdl" ]; then
        croak "project.pdl is missing"
    fi
    if [ ! -f "readme.txt" ]; then
        croak "readme.txt is missing"
    fi
    if [ ! -f "crc32.h" ]; then
        croak "crc32.h is missing"
    fi
    if [ ! -f "deflate.h" ]; then
        croak "deflate.h is missing"
    fi
    if [ ! -f "trees.h" ]; then
        croak "trees.h is missing"
    fi
    if [ ! -f "zutil.h" ]; then
        croak "zutil.h is missing"
    fi
    if [ ! -f "inflate.h" ]; then
        croak "inflate.h is missing"
    fi
    if [ ! -f "inftrees.h" ]; then
        croak "inftrees.h is missing"
    fi
    if [ ! -f "inffast.h" ]; then
        croak "inffast.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
    if [ ! -d "contrib/minizip" ]; then
        croak "Directory contrib/minizip is missing"
    fi
    PUSHDIR=`pwd`
    cd contrib/minizip
    if [ ! -f "ChangeLogUnzip" ]; then
        croak "ChangeLogUnzip is missing"
    fi
    if [ ! -f "crypt.h" ]; then
        croak "crypt.h is missing"
    fi
    if [ ! -f "ioapi.c" ]; then
        croak "ioapi.c is missing"
    fi
    if [ ! -f "unzip.c" ]; then
        croak "unzip.c is missing"
    fi
    if [ ! -f "zip.c" ]; then
        croak "zip.c is missing"
    fi
    if [ ! -f "ioapi.h" ]; then
        croak "ioapi.h is missing"
    fi
    if [ ! -f "unzip.h" ]; then
        croak "unzip.h is missing"
    fi
    if [ ! -f "zip.h" ]; then
        croak "zip.h is missing"
    fi
    cd $PUSHDIR
}

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

a_check_source_files_exist() {
:
    if [ ! -f "ChangeLog" ]; then
        croak "ChangeLog is missing"
    fi
    if [ ! -f "FAQ" ]; then
        croak "FAQ is missing"
    fi
    if [ ! -f "README" ]; then
        croak "README is missing"
    fi
    if [ ! -f "algorithm.txt" ]; then
        croak "algorithm.txt is missing"
    fi
    if [ ! -f "zlib.3" ]; then
        croak "zlib.3 is missing"
    fi
    if [ ! -f "adler32.c" ]; then
        croak "adler32.c is missing"
    fi
    if [ ! -f "compress.c" ]; then
        croak "compress.c is missing"
    fi
    if [ ! -f "gzio.c" ]; then
        croak "gzio.c is missing"
    fi
    if [ ! -f "uncompr.c" ]; then
        croak "uncompr.c is missing"
    fi
    if [ ! -f "crc32.c" ]; then
        croak "crc32.c is missing"
    fi
    if [ ! -f "deflate.c" ]; then
        croak "deflate.c is missing"
    fi
    if [ ! -f "trees.c" ]; then
        croak "trees.c is missing"
    fi
    if [ ! -f "zutil.c" ]; then
        croak "zutil.c is missing"
    fi
    if [ ! -f "inflate.c" ]; then
        croak "inflate.c is missing"
    fi
    if [ ! -f "infback.c" ]; then
        croak "infback.c is missing"
    fi
    if [ ! -f "inftrees.c" ]; then
        croak "inftrees.c is missing"
    fi
    if [ ! -f "inffast.c" ]; then
        croak "inffast.c is missing"
    fi
    if [ ! -f "inffixed.h" ]; then
        croak "inffixed.h is missing"
    fi
    if [ ! -f "zconf.h" ]; then
        croak "zconf.h is missing"
    fi
    if [ ! -f "zlib.h" ]; then
        croak "zlib.h is missing"
    fi
    if [ ! -f "project.pdl" ]; then
        croak "project.pdl is missing"
    fi
    if [ ! -f "readme.txt" ]; then
        croak "readme.txt is missing"
    fi
    if [ ! -f "crc32.h" ]; then
        croak "crc32.h is missing"
    fi
    if [ ! -f "deflate.h" ]; then
        croak "deflate.h is missing"
    fi
    if [ ! -f "trees.h" ]; then
        croak "trees.h is missing"
    fi
    if [ ! -f "zutil.h" ]; then
        croak "zutil.h is missing"
    fi
    if [ ! -f "inflate.h" ]; then
        croak "inflate.h is missing"
    fi
    if [ ! -f "inftrees.h" ]; then
        croak "inftrees.h is missing"
    fi
    if [ ! -f "inffast.h" ]; then
        croak "inffast.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
    PUSHDIR=`pwd`
    cd contrib/minizip
    if [ ! -f "ChangeLogUnzip" ]; then
        croak "ChangeLogUnzip is missing"
    fi
    if [ ! -f "crypt.h" ]; then
        croak "crypt.h is missing"
    fi
    if [ ! -f "ioapi.c" ]; then
        croak "ioapi.c is missing"
    fi
    if [ ! -f "unzip.c" ]; then
        croak "unzip.c is missing"
    fi
    if [ ! -f "zip.c" ]; then
        croak "zip.c is missing"
    fi
    if [ ! -f "ioapi.h" ]; then
        croak "ioapi.h is missing"
    fi
    if [ ! -f "unzip.h" ]; then
        croak "unzip.h is missing"
    fi
    if [ ! -f "zip.h" ]; then
        croak "zip.h is missing"
    fi
    if [ ! -f "zconf.h" ]; then
        croak "zconf.h is missing"
    fi
    if [ ! -f "zlib.h" ]; then
        croak "zlib.h is missing"
    fi
    cd $PUSHDIR
}

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

a_install_deliverables() {
:
    carp "Installing Zlib 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/doc/Zlib/
    [ "$BOOM_TRACE" ] && echo "cp ChangeLog $_INSTALL_ROOT/doc/Zlib/"
    cp ChangeLog $_INSTALL_ROOT/doc/Zlib/ || croak "\"cp ChangeLog $_INSTALL_ROOT/doc/Zlib/\" failed"
    [ "$BOOM_TRACE" ] && echo "chmod 0644 $_INSTALL_ROOT/doc/Zlib/ChangeLog"
    chmod 0644 $_INSTALL_ROOT/doc/Zlib/ChangeLog || croak "\"chmod 0644 $_INSTALL_ROOT/doc/Zlib/ChangeLog\" failed"
    [ "$BOOM_TRACE" ] && echo "cp FAQ $_INSTALL_ROOT/doc/Zlib/"
    cp FAQ $_INSTALL_ROOT/doc/Zlib/ || croak "\"cp FAQ $_INSTALL_ROOT/doc/Zlib/\" failed"
    [ "$BOOM_TRACE" ] && echo "chmod 0644 $_INSTALL_ROOT/doc/Zlib/FAQ"
    chmod 0644 $_INSTALL_ROOT/doc/Zlib/FAQ || croak "\"chmod 0644 $_INSTALL_ROOT/doc/Zlib/FAQ\" failed"
    [ "$BOOM_TRACE" ] && echo "cp README $_INSTALL_ROOT/doc/Zlib/"
    cp README $_INSTALL_ROOT/doc/Zlib/ || croak "\"cp README $_INSTALL_ROOT/doc/Zlib/\" failed"
    [ "$BOOM_TRACE" ] && echo "chmod 0644 $_INSTALL_ROOT/doc/Zlib/README"
    chmod 0644 $_INSTALL_ROOT/doc/Zlib/README || croak "\"chmod 0644 $_INSTALL_ROOT/doc/Zlib/README\" failed"
    [ "$BOOM_TRACE" ] && echo "cp algorithm.txt $_INSTALL_ROOT/doc/Zlib/"
    cp algorithm.txt $_INSTALL_ROOT/doc/Zlib/ || croak "\"cp algorithm.txt $_INSTALL_ROOT/doc/Zlib/\" failed"
    [ "$BOOM_TRACE" ] && echo "chmod 0644 $_INSTALL_ROOT/doc/Zlib/algorithm.txt"
    chmod 0644 $_INSTALL_ROOT/doc/Zlib/algorithm.txt || croak "\"chmod 0644 $_INSTALL_ROOT/doc/Zlib/algorithm.txt\" failed"
    [ "$BOOM_TRACE" ] && echo "cp zlib.3 $_INSTALL_ROOT/doc/Zlib/"
    cp zlib.3 $_INSTALL_ROOT/doc/Zlib/ || croak "\"cp zlib.3 $_INSTALL_ROOT/doc/Zlib/\" failed"
    [ "$BOOM_TRACE" ] && echo "chmod 0644 $_INSTALL_ROOT/doc/Zlib/zlib.3"
    chmod 0644 $_INSTALL_ROOT/doc/Zlib/zlib.3 || croak "\"chmod 0644 $_INSTALL_ROOT/doc/Zlib/zlib.3\" failed"
    mkdir -p $_INSTALL_ROOT/include/
    [ "$BOOM_TRACE" ] && echo "cp zconf.h $_INSTALL_ROOT/include/"
    cp zconf.h $_INSTALL_ROOT/include/ || croak "\"cp zconf.h $_INSTALL_ROOT/include/\" failed"
    [ "$BOOM_TRACE" ] && echo "chmod 0644 $_INSTALL_ROOT/include/zconf.h"
    chmod 0644 $_INSTALL_ROOT/include/zconf.h || croak "\"chmod 0644 $_INSTALL_ROOT/include/zconf.h\" failed"
    [ "$BOOM_TRACE" ] && echo "cp zlib.h $_INSTALL_ROOT/include/"
    cp zlib.h $_INSTALL_ROOT/include/ || croak "\"cp zlib.h $_INSTALL_ROOT/include/\" failed"
    [ "$BOOM_TRACE" ] && echo "chmod 0644 $_INSTALL_ROOT/include/zlib.h"
    chmod 0644 $_INSTALL_ROOT/include/zlib.h || croak "\"chmod 0644 $_INSTALL_ROOT/include/zlib.h\" failed"
    mkdir -p $_INSTALL_ROOT/lib/
    [ "$BOOM_TRACE" ] && echo "cp libzip.a $_INSTALL_ROOT/lib/"
    cp libzip.a $_INSTALL_ROOT/lib/ || croak "\"cp libzip.a $_INSTALL_ROOT/lib/\" failed"
    [ "$BOOM_TRACE" ] && echo "chmod 0644 $_INSTALL_ROOT/lib/libzip.a"
    chmod 0644 $_INSTALL_ROOT/lib/libzip.a || croak "\"chmod 0644 $_INSTALL_ROOT/lib/libzip.a\" failed"
    mkdir -p $_INSTALL_ROOT/bin/
    mkdir -p $_INSTALL_ROOT/doc/Zlib/
    [ "$BOOM_TRACE" ] && echo "cp readme.txt $_INSTALL_ROOT/doc/Zlib/"
    cp readme.txt $_INSTALL_ROOT/doc/Zlib/ || croak "\"cp readme.txt $_INSTALL_ROOT/doc/Zlib/\" failed"
    [ "$BOOM_TRACE" ] && echo "chmod 0644 $_INSTALL_ROOT/doc/Zlib/readme.txt"
    chmod 0644 $_INSTALL_ROOT/doc/Zlib/readme.txt || croak "\"chmod 0644 $_INSTALL_ROOT/doc/Zlib/readme.txt\" failed"
    [ "$BOOM_TRACE" ] && echo "cp contrib/minizip/ChangeLogUnzip $_INSTALL_ROOT/doc/Zlib/"
    cp contrib/minizip/ChangeLogUnzip $_INSTALL_ROOT/doc/Zlib/ || croak "\"cp contrib/minizip/ChangeLogUnzip $_INSTALL_ROOT/doc/Zlib/\" failed"
    [ "$BOOM_TRACE" ] && echo "chmod 0644 $_INSTALL_ROOT/doc/Zlib/ChangeLogUnzip"
    chmod 0644 $_INSTALL_ROOT/doc/Zlib/ChangeLogUnzip || croak "\"chmod 0644 $_INSTALL_ROOT/doc/Zlib/ChangeLogUnzip\" failed"
    mkdir -p $_INSTALL_ROOT/include/
    [ "$BOOM_TRACE" ] && echo "cp contrib/minizip/ioapi.h $_INSTALL_ROOT/include/"
    cp contrib/minizip/ioapi.h $_INSTALL_ROOT/include/ || croak "\"cp contrib/minizip/ioapi.h $_INSTALL_ROOT/include/\" failed"
    [ "$BOOM_TRACE" ] && echo "chmod 0644 $_INSTALL_ROOT/include/ioapi.h"
    chmod 0644 $_INSTALL_ROOT/include/ioapi.h || croak "\"chmod 0644 $_INSTALL_ROOT/include/ioapi.h\" failed"
    [ "$BOOM_TRACE" ] && echo "cp contrib/minizip/unzip.h $_INSTALL_ROOT/include/"
    cp contrib/minizip/unzip.h $_INSTALL_ROOT/include/ || croak "\"cp contrib/minizip/unzip.h $_INSTALL_ROOT/include/\" failed"
    [ "$BOOM_TRACE" ] && echo "chmod 0644 $_INSTALL_ROOT/include/unzip.h"
    chmod 0644 $_INSTALL_ROOT/include/unzip.h || croak "\"chmod 0644 $_INSTALL_ROOT/include/unzip.h\" failed"
    [ "$BOOM_TRACE" ] && echo "cp contrib/minizip/zip.h $_INSTALL_ROOT/include/"
    cp contrib/minizip/zip.h $_INSTALL_ROOT/include/ || croak "\"cp contrib/minizip/zip.h $_INSTALL_ROOT/include/\" failed"
    [ "$BOOM_TRACE" ] && echo "chmod 0644 $_INSTALL_ROOT/include/zip.h"
    chmod 0644 $_INSTALL_ROOT/include/zip.h || croak "\"chmod 0644 $_INSTALL_ROOT/include/zip.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..."
    PUSHDIR=`pwd`
    cd contrib/minizip
    cd $PUSHDIR
    [ "$BOOM_TRACE" ] && echo "cp -p ./zconf.h contrib/minizip/"
    cp -p ./zconf.h contrib/minizip/ || croak "\"cp -p ./zconf.h contrib/minizip/\" failed"
    [ "$BOOM_TRACE" ] && echo "cp -p ./zlib.h contrib/minizip/"
    cp -p ./zlib.h contrib/minizip/ || croak "\"cp -p ./zlib.h contrib/minizip/\" failed"
    echo "Source files successfully generated">stamp_generate
}

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

a_produce_generated_files() {
:
    carp "Generating files..."
    PUSHDIR=`pwd`
    cd contrib/minizip
    cd $PUSHDIR
    [ "$BOOM_TRACE" ] && echo "cp -p ./zconf.h contrib/minizip/"
    cp -p ./zconf.h contrib/minizip/ || croak "\"cp -p ./zconf.h contrib/minizip/\" failed"
    [ "$BOOM_TRACE" ] && echo "cp -p ./zlib.h contrib/minizip/"
    cp -p ./zlib.h contrib/minizip/ || croak "\"cp -p ./zlib.h contrib/minizip/\" failed"
    echo "Source files successfully generated">stamp_generate
}

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

a_remove_generated_binaries() {
:
    rm -f libzip.a
    rm -f adler32.o
    rm -f compress.o
    rm -f gzio.o
    rm -f uncompr.o
    rm -f crc32.o
    rm -f deflate.o
    rm -f trees.o
    rm -f zutil.o
    rm -f inflate.o
    rm -f infback.o
    rm -f inftrees.o
    rm -f inffast.o
    rm -f contrib/minizip/ioapi.o
    rm -f contrib/minizip/unzip.o
    rm -f contrib/minizip/zip.o
    rm -f contrib/minizip/libzip.a
    PUSHDIR=`pwd`
    cd contrib/minizip
    cd $PUSHDIR
}

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

a_remove_generated_sources() {
:
    rm -f stamp_generate
    rm -f configure
    rm -f Makefile.unix
    rm -f configure.bat
    rm -f Makefile.win32
    rm -f contrib/minizip/zconf.h
    rm -f contrib/minizip/zlib.h
    PUSHDIR=`pwd`
    cd contrib/minizip
    cd $PUSHDIR
    rm -f zlib_*.zip
    rm -f zlib_*.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 "zlib-1.2.3"
}

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

a_run_regression_tests() {
:
    PUSHDIR=`pwd`
    cd contrib/minizip
    cd $PUSHDIR
    #   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
