@echo off
:-
:-  Boom builder for iMatix Foreign 1.2b0
:-  Generated by iMatix Boom from product.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.
:-
:-  Start CMD.EXE version detection
verify other 2>nul
setlocal enableextensions
if errorlevel 0 goto __cmd_ok
echo %0: This command requires command extensions version 2 in CMD.EXE.  
echo %0: Please use a supported system (Windows 2000 or newer).
exit
:__cmd_ok
setlocal enabledelayedexpansion
:-  End CMD.EXE version detection
goto :init
:-
:-  Subroutine: boom_model_init
:-  Initialises BOOM_MODEL to default if not set
:-  Expands BOOM_MODEL components into individual environment variables
:-
:boom_model_init
if "!BOOM_MODEL!"=="" (
    set BOOM_MODEL=release,st
)
set BOOM_MODEL__PLACEHOLDER=1
for /f "usebackq delims==" %%v in (`set BOOM_MODEL_`) do set %%v=
set BOOM_MODEL__PLACEHOLDER=
for %%m in (!BOOM_MODEL!) do set BOOM_MODEL_%%m=1
:-  If the user set BOOM_MODEL but did not include release/debug or st/mt
:-  set these to defaults.
if not "!BOOM_MODEL_RELEASE!"=="1" (
    if not "!BOOM_MODEL_DEBUG!"=="1" (
        set BOOM_MODEL_RELEASE=1
        set BOOM_MODEL=!BOOM_MODEL!,release
    )
)
if not "!BOOM_MODEL_ST!"=="1" (
    if not "!BOOM_MODEL_MT!"=="1" (
        set BOOM_MODEL_ST=1
        set BOOM_MODEL=!BOOM_MODEL!,st
    )
)
goto :eof
:init
setlocal
:-
:-  Set environment variables to point to install location
:-  Start by using final IBASE, then handle -install path
set self=%0
set MY_VERSION=1.2b0
set OLDPATH=!PATH!
set OLDPERLLIB=!PERLLIB!
if .!IBASE!==. (
    echo boom E: [foreign]: The IBASE variable is not set.         Please set it to the location where iMatix Foreign should be installed.
    exit /b 1
)
if .%1==.-v (
    set BOOM_TRACE=1
    shift
)
call :boom_model_init
if .%1==.-install goto tempinst
:-  Normal use, use IBASE
    set PATH=!IBASE!\bin;!PATH!
    set PERLLIB=!IBASE!\bin;!PERLLIB!
    set INCDIR_ALT=!IBASE!\include
    set _INSTALL_ROOT=!IBASE!
    goto process

:tempinst
:-  Building product, we use -install directory first, then IBASE
    if not exist %2 (
       echo "Invalid command syntax - please contact imatix-tech"
       exit /b 1
    )
    pushd %2
    set _LOCAL_BASE=!cd!
    popd
    set PATH=!_LOCAL_BASE!\bin;!IBASE!\bin;!PATH!
    set PERLLIB=!_LOCAL_BASE!\bin;!IBASE!\bin;!PERLLIB!
    set INCDIR_ALT=!_LOCAL_BASE!\include;!IBASE!\include
    set _INSTALL_ROOT=!_LOCAL_BASE!
    shift
    shift
    goto process

:batch
    shift

:process
    set state=initial
    set event=ok
    set debug=0
    goto s_!state!

:-----------------------------   ALLGEN PROJECTS   ----------------------------

:a_allgen_projects
    pushd c
    if exist boomake.bat (
        call boomake allgen
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    pushd apr
    if exist boomake.bat (
        call boomake allgen
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    pushd pcre
    if exist boomake.bat (
        call boomake allgen
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    pushd zlib
    if exist boomake.bat (
        call boomake allgen
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    pushd tests
    if exist boomake.bat (
        call boomake allgen
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    goto :eof

:---------------------   BUILD PRODUCT INSTALL PACKAGES   ---------------------

:a_build_product_install_packages
    echo boom I: [foreign]: building Foreign Install...
    if exist _install\nul rmdir /s /q _install
    mkdir _install
    mkdir _install\lib
    mkdir _install\include
    mkdir _install\bin
    pushd c
    if exist boomake.bat (
    call boomake -install ..\_install install
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    pushd apr
    if exist boomake.bat (
    call boomake -install ..\_install install
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    pushd pcre
    if exist boomake.bat (
    call boomake -install ..\_install install
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    pushd zlib
    if exist boomake.bat (
    call boomake -install ..\_install install
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    pushd tests
    if exist boomake.bat (
    call boomake -install ..\_install install
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    if exist foreign-!MY_VERSION! rmdir /s/q foreign-!MY_VERSION!
    ren _install foreign-!MY_VERSION!
    if "!BOOM_TRACE!"=="1" echo pkg_zip foreign-!MY_VERSION!
    verify>nul
    call pkg_zip foreign-!MY_VERSION!
    if errorlevel 1 (
        echo boom E: [foreign]: 'pkg_zip foreign-!MY_VERSION!' failed - stop.
        set _exception=1
        goto :eof
    )
    rmdir /s/q foreign-!MY_VERSION!
    goto :eof

:----------------------   BUILD PRODUCT SOURCE PACKAGES   ---------------------

:a_build_product_source_packages
    if exist _package.lst del _package.lst
    if exist project.pdl echo project.pdl>>_package.lst
    if exist readme.txt echo readme.txt>>_package.lst
    if exist release.txt echo release.txt>>_package.lst
    if exist stamp_generate echo stamp_generate>>_package.lst
    if exist configure echo configure>>_package.lst
    if exist Makefile.unix echo Makefile.unix>>_package.lst
    if exist boomake echo boomake>>_package.lst
    if exist configure.bat echo configure.bat>>_package.lst
    if exist Makefile.win32 echo Makefile.win32>>_package.lst
    if exist boomake.bat echo boomake.bat>>_package.lst
    if exist boomakew.bat echo boomakew.bat>>_package.lst
    pushd c
    popd
    if exist c\c echo c\c>>_package.lst
    if exist c\c.bat echo c\c.bat>>_package.lst
    if exist c\c.cmd echo c\c.cmd>>_package.lst
    if exist c\gcccat echo c\gcccat>>_package.lst
    if exist c\gcccat.bat echo c\gcccat.bat>>_package.lst
    if exist c\boomvs.bat echo c\boomvs.bat>>_package.lst
    if exist c\convert71.js echo c\convert71.js>>_package.lst
    if exist c\convert80.js echo c\convert80.js>>_package.lst
    if exist c\prelude.pdl echo c\prelude.pdl>>_package.lst
    if exist c\license.gpl echo c\license.gpl>>_package.lst
    if exist c\project.pdl echo c\project.pdl>>_package.lst
    if exist c\readme.txt echo c\readme.txt>>_package.lst
    if exist c\stamp_generate echo c\stamp_generate>>_package.lst
    if exist c\configure echo c\configure>>_package.lst
    if exist c\Makefile.unix echo c\Makefile.unix>>_package.lst
    if exist c\boomake echo c\boomake>>_package.lst
    if exist c\configure.bat echo c\configure.bat>>_package.lst
    if exist c\Makefile.win32 echo c\Makefile.win32>>_package.lst
    if exist c\boomake.bat echo c\boomake.bat>>_package.lst
    if exist c\boomakew.bat echo c\boomakew.bat>>_package.lst
    if exist c\liblocal.vcproj echo c\liblocal.vcproj>>_package.lst
    pushd apr

    set APR_TARGET=
    if "!BOOM_MODEL_ST!"=="1" (
        set APR_TARGET=apr_nonthreaded
        set APRUTIL_TARGET=aprutil_nonthreaded
        set XML_TARGET=xml_nonthreaded
    )
    if "!BOOM_MODEL_MT!"=="1" (
        set APR_TARGET=apr
        set APRUTIL_TARGET=aprutil
        set XML_TARGET=xml
    )
    if !APR_TARGET!.==. (
        echo boom E: BOOM_MODEL invalid or not set
        exit /b 1
    )
    call boomvs --where=apr --using=apr --target=!APR_TARGET! clean
    if errorlevel 1 exit /b 1
    call boomvs --where=apr-util\xml\expat\lib --using=xml --target=!XML_TARGET! clean
    if errorlevel 1 exit /b 1
    call boomvs --where=apr-util --using=aprutil --target=!APRUTIL_TARGET! clean
    if errorlevel 1 exit /b 1

    pushd .. 
    perl apr\apr_package_lst.pl apr\apr apr\apr-util >>_package.lst
    popd
   
    popd
    if exist apr\project.pdl echo apr\project.pdl>>_package.lst
    if exist apr\apr_package_lst.pl echo apr\apr_package_lst.pl>>_package.lst
    if exist apr\base_apr.h echo apr\base_apr.h>>_package.lst
    if exist apr\apr*.h echo apr\apr*.h>>_package.lst
    if exist apr\apu*.h echo apr\apu*.h>>_package.lst
    if exist apr\stamp_generate echo apr\stamp_generate>>_package.lst
    if exist apr\configure echo apr\configure>>_package.lst
    if exist apr\Makefile.unix echo apr\Makefile.unix>>_package.lst
    if exist apr\boomake echo apr\boomake>>_package.lst
    if exist apr\configure.bat echo apr\configure.bat>>_package.lst
    if exist apr\Makefile.win32 echo apr\Makefile.win32>>_package.lst
    if exist apr\boomake.bat echo apr\boomake.bat>>_package.lst
    if exist apr\boomakew.bat echo apr\boomakew.bat>>_package.lst
    if exist apr\liblocal.vcproj echo apr\liblocal.vcproj>>_package.lst
    pushd pcre
    popd
    if exist pcre\pcre_chartables.c echo pcre\pcre_chartables.c>>_package.lst
    if exist pcre\pcre_compile.c echo pcre\pcre_compile.c>>_package.lst
    if exist pcre\pcre_config.c echo pcre\pcre_config.c>>_package.lst
    if exist pcre\pcre_dfa_exec.c echo pcre\pcre_dfa_exec.c>>_package.lst
    if exist pcre\pcre_exec.c echo pcre\pcre_exec.c>>_package.lst
    if exist pcre\pcre_fullinfo.c echo pcre\pcre_fullinfo.c>>_package.lst
    if exist pcre\pcre_get.c echo pcre\pcre_get.c>>_package.lst
    if exist pcre\pcre_globals.c echo pcre\pcre_globals.c>>_package.lst
    if exist pcre\pcre_info.c echo pcre\pcre_info.c>>_package.lst
    if exist pcre\pcre_maketables.c echo pcre\pcre_maketables.c>>_package.lst
    if exist pcre\pcre_ord2utf8.c echo pcre\pcre_ord2utf8.c>>_package.lst
    if exist pcre\pcre_refcount.c echo pcre\pcre_refcount.c>>_package.lst
    if exist pcre\pcre_study.c echo pcre\pcre_study.c>>_package.lst
    if exist pcre\pcre_tables.c echo pcre\pcre_tables.c>>_package.lst
    if exist pcre\pcre_try_flipped.c echo pcre\pcre_try_flipped.c>>_package.lst
    if exist pcre\pcre_ucp_searchfuncs.c echo pcre\pcre_ucp_searchfuncs.c>>_package.lst
    if exist pcre\pcre_valid_utf8.c echo pcre\pcre_valid_utf8.c>>_package.lst
    if exist pcre\pcre_version.c echo pcre\pcre_version.c>>_package.lst
    if exist pcre\pcre_xclass.c echo pcre\pcre_xclass.c>>_package.lst
    if exist pcre\pcre.h echo pcre\pcre.h>>_package.lst
    if exist pcre\pcre_internal.h echo pcre\pcre_internal.h>>_package.lst
    if exist pcre\pcre_scanner.h echo pcre\pcre_scanner.h>>_package.lst
    if exist pcre\pcre_printint.src echo pcre\pcre_printint.src>>_package.lst
    if exist pcre\ucpinternal.h echo pcre\ucpinternal.h>>_package.lst
    if exist pcre\ucp.h echo pcre\ucp.h>>_package.lst
    if exist pcre\ucptable.c echo pcre\ucptable.c>>_package.lst
    if exist pcre\config.h echo pcre\config.h>>_package.lst
    if exist pcre\dftables.c echo pcre\dftables.c>>_package.lst
    if exist pcre\pcregrep.c echo pcre\pcregrep.c>>_package.lst
    if exist pcre\pcredemo.c echo pcre\pcredemo.c>>_package.lst
    if exist pcre\pcretest.c echo pcre\pcretest.c>>_package.lst
    if exist pcre\AUTHORS echo pcre\AUTHORS>>_package.lst
    if exist pcre\ChangeLog echo pcre\ChangeLog>>_package.lst
    if exist pcre\COPYING echo pcre\COPYING>>_package.lst
    if exist pcre\INSTALL echo pcre\INSTALL>>_package.lst
    if exist pcre\LICENCE echo pcre\LICENCE>>_package.lst
    if exist pcre\NEWS echo pcre\NEWS>>_package.lst
    if exist pcre\NON-UNIX-USE echo pcre\NON-UNIX-USE>>_package.lst
    if exist pcre\README echo pcre\README>>_package.lst
    if exist pcre\prelude.pdl echo pcre\prelude.pdl>>_package.lst
    if exist pcre\license.gpl echo pcre\license.gpl>>_package.lst
    if exist pcre\project.pdl echo pcre\project.pdl>>_package.lst
    if exist pcre\readme.txt echo pcre\readme.txt>>_package.lst
    if exist pcre\stamp_generate echo pcre\stamp_generate>>_package.lst
    if exist pcre\configure echo pcre\configure>>_package.lst
    if exist pcre\Makefile.unix echo pcre\Makefile.unix>>_package.lst
    if exist pcre\boomake echo pcre\boomake>>_package.lst
    if exist pcre\configure.bat echo pcre\configure.bat>>_package.lst
    if exist pcre\Makefile.win32 echo pcre\Makefile.win32>>_package.lst
    if exist pcre\boomake.bat echo pcre\boomake.bat>>_package.lst
    if exist pcre\boomakew.bat echo pcre\boomakew.bat>>_package.lst
    if exist pcre\libpcre.vcproj echo pcre\libpcre.vcproj>>_package.lst
    pushd zlib
    popd
    if exist zlib\ChangeLog echo zlib\ChangeLog>>_package.lst
    if exist zlib\FAQ echo zlib\FAQ>>_package.lst
    if exist zlib\README echo zlib\README>>_package.lst
    if exist zlib\algorithm.txt echo zlib\algorithm.txt>>_package.lst
    if exist zlib\zlib.3 echo zlib\zlib.3>>_package.lst
    if exist zlib\adler32.c echo zlib\adler32.c>>_package.lst
    if exist zlib\compress.c echo zlib\compress.c>>_package.lst
    if exist zlib\gzio.c echo zlib\gzio.c>>_package.lst
    if exist zlib\uncompr.c echo zlib\uncompr.c>>_package.lst
    if exist zlib\crc32.c echo zlib\crc32.c>>_package.lst
    if exist zlib\deflate.c echo zlib\deflate.c>>_package.lst
    if exist zlib\trees.c echo zlib\trees.c>>_package.lst
    if exist zlib\zutil.c echo zlib\zutil.c>>_package.lst
    if exist zlib\inflate.c echo zlib\inflate.c>>_package.lst
    if exist zlib\infback.c echo zlib\infback.c>>_package.lst
    if exist zlib\inftrees.c echo zlib\inftrees.c>>_package.lst
    if exist zlib\inffast.c echo zlib\inffast.c>>_package.lst
    if exist zlib\inffixed.h echo zlib\inffixed.h>>_package.lst
    if exist zlib\zconf.h echo zlib\zconf.h>>_package.lst
    if exist zlib\zlib.h echo zlib\zlib.h>>_package.lst
    if exist zlib\prelude.pdl echo zlib\prelude.pdl>>_package.lst
    if exist zlib\license.gpl echo zlib\license.gpl>>_package.lst
    if exist zlib\project.pdl echo zlib\project.pdl>>_package.lst
    if exist zlib\readme.txt echo zlib\readme.txt>>_package.lst
    if exist zlib\crc32.h echo zlib\crc32.h>>_package.lst
    if exist zlib\deflate.h echo zlib\deflate.h>>_package.lst
    if exist zlib\trees.h echo zlib\trees.h>>_package.lst
    if exist zlib\zutil.h echo zlib\zutil.h>>_package.lst
    if exist zlib\inflate.h echo zlib\inflate.h>>_package.lst
    if exist zlib\inftrees.h echo zlib\inftrees.h>>_package.lst
    if exist zlib\inffast.h echo zlib\inffast.h>>_package.lst
    if exist zlib\stamp_generate echo zlib\stamp_generate>>_package.lst
    if exist zlib\configure echo zlib\configure>>_package.lst
    if exist zlib\Makefile.unix echo zlib\Makefile.unix>>_package.lst
    if exist zlib\boomake echo zlib\boomake>>_package.lst
    if exist zlib\configure.bat echo zlib\configure.bat>>_package.lst
    if exist zlib\Makefile.win32 echo zlib\Makefile.win32>>_package.lst
    if exist zlib\boomake.bat echo zlib\boomake.bat>>_package.lst
    if exist zlib\boomakew.bat echo zlib\boomakew.bat>>_package.lst
    if exist zlib\libzip.vcproj echo zlib\libzip.vcproj>>_package.lst
    if exist zlib\contrib\minizip\ChangeLogUnzip echo zlib\contrib\minizip\ChangeLogUnzip>>_package.lst
    if exist zlib\contrib\minizip\crypt.h echo zlib\contrib\minizip\crypt.h>>_package.lst
    if exist zlib\contrib\minizip\ioapi.c echo zlib\contrib\minizip\ioapi.c>>_package.lst
    if exist zlib\contrib\minizip\unzip.c echo zlib\contrib\minizip\unzip.c>>_package.lst
    if exist zlib\contrib\minizip\zip.c echo zlib\contrib\minizip\zip.c>>_package.lst
    if exist zlib\contrib\minizip\ioapi.h echo zlib\contrib\minizip\ioapi.h>>_package.lst
    if exist zlib\contrib\minizip\unzip.h echo zlib\contrib\minizip\unzip.h>>_package.lst
    if exist zlib\contrib\minizip\zip.h echo zlib\contrib\minizip\zip.h>>_package.lst
    if exist zlib\contrib\minizip\zconf.h echo zlib\contrib\minizip\zconf.h>>_package.lst
    if exist zlib\contrib\minizip\zlib.h echo zlib\contrib\minizip\zlib.h>>_package.lst
    pushd tests
    popd
    if exist tests\pthread_rwlock_test.c echo tests\pthread_rwlock_test.c>>_package.lst
    if exist tests\prelude.pdl echo tests\prelude.pdl>>_package.lst
    if exist tests\license.gpl echo tests\license.gpl>>_package.lst
    if exist tests\project.pdl echo tests\project.pdl>>_package.lst
    if exist tests\readme.txt echo tests\readme.txt>>_package.lst
    if exist tests\stamp_generate echo tests\stamp_generate>>_package.lst
    if exist tests\configure echo tests\configure>>_package.lst
    if exist tests\Makefile.unix echo tests\Makefile.unix>>_package.lst
    if exist tests\boomake echo tests\boomake>>_package.lst
    if exist tests\configure.bat echo tests\configure.bat>>_package.lst
    if exist tests\Makefile.win32 echo tests\Makefile.win32>>_package.lst
    if exist tests\boomake.bat echo tests\boomake.bat>>_package.lst
    if exist tests\boomakew.bat echo tests\boomakew.bat>>_package.lst
    if exist tests\liblocal.vcproj echo tests\liblocal.vcproj>>_package.lst
    echo "Source package successfully generated">c\stamp_source
    echo "c\stamp_source">>_package.lst
    echo "Source package successfully generated">apr\stamp_source
    echo "apr\stamp_source">>_package.lst
    echo "Source package successfully generated">pcre\stamp_source
    echo "pcre\stamp_source">>_package.lst
    echo "Source package successfully generated">zlib\stamp_source
    echo "zlib\stamp_source">>_package.lst
    echo "Source package successfully generated">tests\stamp_source
    echo "tests\stamp_source">>_package.lst
    echo "Source package successfully generated">stamp_source
    echo "stamp_source">>_package.lst
    echo boom I: [foreign]: Building foreign-!MY_VERSION!-src.zip...
    zip  -rq _package -@<_package.lst
    unzip -q _package -d foreign-!MY_VERSION!
    if exist  foreign-!MY_VERSION!-src.zip del foreign-!MY_VERSION!-src.zip
    zip -rmq foreign-!MY_VERSION!-src.zip foreign-!MY_VERSION!
    del _package.zip
    del _package.lst
    del stamp_source
    del c\stamp_source
    del apr\stamp_source
    del pcre\stamp_source
    del zlib\stamp_source
    del tests\stamp_source
    goto :eof

:-----------------------------   BUILD PROJECTS   -----------------------------

:a_build_projects
    if exist _install\nul rmdir /s /q _install
    mkdir _install
    mkdir _install\lib
    mkdir _install\include
    mkdir _install\bin
    pushd c
    if exist boomake.bat (
        call boomake -install ..\_install build install
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    pushd apr
    if exist boomake.bat (
        call boomake -install ..\_install build install
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    pushd pcre
    if exist boomake.bat (
        call boomake -install ..\_install build install
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    pushd zlib
    if exist boomake.bat (
        call boomake -install ..\_install build install
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    pushd tests
    if exist boomake.bat (
        call boomake -install ..\_install build install
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    goto :eof

:-------------------------   CHECK OPERATING CONTEXT   ------------------------

:a_check_operating_context
    set event=repository
    if exist stamp_source   set event=source
    if exist stamp_stripped set event=stripped
    goto :eof

:-----------------------------   CLEAN PROJECTS   -----------------------------

:a_clean_projects
    if exist _install\nul rmdir /s /q _install
    pushd c
    if exist boomake.bat (
        call boomake clean
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    pushd apr
    if exist boomake.bat (
        call boomake clean
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    pushd pcre
    if exist boomake.bat (
        call boomake clean
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    pushd zlib
    if exist boomake.bat (
        call boomake clean
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    pushd tests
    if exist boomake.bat (
        call boomake clean
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    goto :eof

:----------------------------   COMPILE PROJECTS   ----------------------------

:a_compile_projects
    pushd c
    if exist boomake.bat (
        call boomake compile
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    pushd apr
    if exist boomake.bat (
        call boomake compile
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    pushd pcre
    if exist boomake.bat (
        call boomake compile
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    pushd zlib
    if exist boomake.bat (
        call boomake compile
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    pushd tests
    if exist boomake.bat (
        call boomake compile
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    goto :eof

:----------------------------   INSTALL PROJECTS   ----------------------------

:a_install_projects
    pushd c
    if exist boomake.bat (
        call boomake install
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    pushd apr
    if exist boomake.bat (
        call boomake install
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    pushd pcre
    if exist boomake.bat (
        call boomake install
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    pushd zlib
    if exist boomake.bat (
        call boomake install
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    pushd tests
    if exist boomake.bat (
        call boomake install
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    if exist installer.bat (
    if "!BOOM_TRACE!"=="1" echo installer
    verify>nul
    call installer
    if errorlevel 1 (
        echo boom E: [foreign]: 'installer' failed - stop.
        set _exception=1
        goto :eof
    )
    )
    goto :eof

:-----------------------------   REGEN PROJECTS   -----------------------------

:a_regen_projects
    pushd c
    if exist boomake.bat (
        call boomake regen
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    pushd apr
    if exist boomake.bat (
        call boomake regen
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    pushd pcre
    if exist boomake.bat (
        call boomake regen
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    pushd zlib
    if exist boomake.bat (
        call boomake regen
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    pushd tests
    if exist boomake.bat (
        call boomake regen
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    goto :eof

:-------------------------   REPORT HELP INFORMATION   ------------------------

:a_report_help_information
    echo The commands you can currently use on this project are:
    echo.
    goto r_!state!
    goto :eof

:-------------------------   REPORT PROJECT VERSION   -------------------------

:a_report_project_version
    echo foreign-1.2b0
    goto :eof

:------------------------------   TEST PROJECTS   -----------------------------

:a_test_projects
    pushd c
    if exist boomake.bat (
        call boomake test
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    pushd apr
    if exist boomake.bat (
        call boomake test
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    pushd pcre
    if exist boomake.bat (
        call boomake test
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    pushd zlib
    if exist boomake.bat (
        call boomake test
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    pushd tests
    if exist boomake.bat (
        call boomake test
    ) else (
        echo boom E: [foreign]: project is not configured - run 'boom configure'
    )
    popd
    if exist selftest.bat (
    if "!BOOM_TRACE!"=="1" echo selftest
    verify>nul
    call selftest
    if errorlevel 1 (
        echo boom E: [foreign]: 'selftest' failed - stop.
        set _exception=1
        goto :eof
    )
    )
    goto :eof

:-----------------------   USE SOURCE CONTROL REVISION   ----------------------

:a_use_source_control_revision
    set SVN_REVISION=svn
    if exist .svn
ul (
        for /f "usebackq tokens=1,2 delims=: " %%v in (`svn info`) do if "%%v"=="Revision" set SVN_REVISION=%%w
    )
    set MY_VERSION=!MY_VERSION!-!SVN_REVISION!
    goto :eof

:s_initial
    if "!debug!"=="1" echo State: initial
    if "!event!"=="" goto s_1_empty
    if "!event!"=="ok" goto s_1_1
    echo Unknown command - use one of:
    echo.
    goto r_!state!
:s_1_1
    if "!debug!"=="1" echo Event: ok
    set event=
    if "!debug!"=="1" echo Action: check operating context
    set _exception=
    call :a_check_operating_context
    if "!_exception!"=="1" exit /b 1
    set state=initial_check
    goto s_!state!
:s_1_empty
    if "!debug!"=="1" echo Get event from user
    set event=%1
    shift
    if "!event!"=="" set event=empty
    goto s_initial
:r_initial
    exit /b 0

:s_initial_check
    if "!debug!"=="1" echo State: initial check
    if "!event!"=="" goto s_2_empty
    if "!event!"=="repository" goto s_2_1
    if "!event!"=="source" goto s_2_2
    if "!event!"=="stripped" goto s_2_3
    echo Unknown command - use one of:
    echo.
    goto r_!state!
:s_2_1
    if "!debug!"=="1" echo Event: repository
    set event=
    set state=repository
    goto s_!state!
:s_2_2
    if "!debug!"=="1" echo Event: source
    set event=
    set state=source
    goto s_!state!
:s_2_3
    if "!debug!"=="1" echo Event: stripped
    set event=
    set state=stripped
    goto s_!state!
:s_2_empty
    if "!debug!"=="1" echo Get event from user
    set event=%1
    shift
    if "!event!"=="" set event=empty
    goto s_initial_check
:r_initial_check
    exit /b 0

:s_repository
    if "!debug!"=="1" echo State: repository
    if "!event!"=="" goto s_3_empty
    if "!event!"=="build" goto s_3_1
    if "!event!"=="compile" goto s_3_2
    if "!event!"=="clean" goto s_3_3
    if "!event!"=="regen" goto s_3_4
    if "!event!"=="allgen" goto s_3_5
    if "!event!"=="distrib" goto s_3_6
    if "!event!"=="distsrc" goto s_3_7
    if "!event!"=="distrev" goto s_3_8
    goto s_default
:s_3_1
    if "!debug!"=="1" echo Event: build
    set event=
    if "!debug!"=="1" echo Action: build projects
    set _exception=
    call :a_build_projects
    if "!_exception!"=="1" exit /b 1
    if not "%1"=="" goto process
    exit /b 0
:s_3_2
    if "!debug!"=="1" echo Event: compile
    set event=
    if "!debug!"=="1" echo Action: compile projects
    set _exception=
    call :a_compile_projects
    if "!_exception!"=="1" exit /b 1
    if not "%1"=="" goto process
    exit /b 0
:s_3_3
    if "!debug!"=="1" echo Event: clean
    set event=
    if "!debug!"=="1" echo Action: clean projects
    set _exception=
    call :a_clean_projects
    if "!_exception!"=="1" exit /b 1
    if not "%1"=="" goto process
    exit /b 0
:s_3_4
    if "!debug!"=="1" echo Event: regen
    set event=
    if "!debug!"=="1" echo Action: regen projects
    set _exception=
    call :a_regen_projects
    if "!_exception!"=="1" exit /b 1
    if not "%1"=="" goto process
    exit /b 0
:s_3_5
    if "!debug!"=="1" echo Event: allgen
    set event=
    if "!debug!"=="1" echo Action: allgen projects
    set _exception=
    call :a_allgen_projects
    if "!_exception!"=="1" exit /b 1
    if not "%1"=="" goto process
    exit /b 0
:s_3_6
    if "!debug!"=="1" echo Event: distrib
    set event=
    if "!debug!"=="1" echo Action: build projects
    set _exception=
    call :a_build_projects
    if "!_exception!"=="1" exit /b 1
    if "!debug!"=="1" echo Action: build product source packages
    set _exception=
    call :a_build_product_source_packages
    if "!_exception!"=="1" exit /b 1
    if "!debug!"=="1" echo Action: build product install packages
    set _exception=
    call :a_build_product_install_packages
    if "!_exception!"=="1" exit /b 1
    if not "%1"=="" goto process
    exit /b 0
:s_3_7
    if "!debug!"=="1" echo Event: distsrc
    set event=
    if "!debug!"=="1" echo Action: allgen projects
    set _exception=
    call :a_allgen_projects
    if "!_exception!"=="1" exit /b 1
    if "!debug!"=="1" echo Action: build product source packages
    set _exception=
    call :a_build_product_source_packages
    if "!_exception!"=="1" exit /b 1
    if not "%1"=="" goto process
    exit /b 0
:s_3_8
    if "!debug!"=="1" echo Event: distrev
    set event=
    if "!debug!"=="1" echo Action: allgen projects
    set _exception=
    call :a_allgen_projects
    if "!_exception!"=="1" exit /b 1
    if "!debug!"=="1" echo Action: use source control revision
    set _exception=
    call :a_use_source_control_revision
    if "!_exception!"=="1" exit /b 1
    if "!debug!"=="1" echo Action: build product source packages
    set _exception=
    call :a_build_product_source_packages
    if "!_exception!"=="1" exit /b 1
    if not "%1"=="" goto process
    exit /b 0
:s_3_empty
    if "!debug!"=="1" echo Get event from user
    set event=%1
    shift
    if "!event!"=="" set event=empty
    goto s_repository
:r_repository
echo build:
    echo   For each project in the product, regenerate code and build binary
    echo     files ready for installation.  The projects are built in their
    echo     individual directories and installed into the temporary install tree.
echo compile:
    echo   For each project in the product, build binary files ready for installation,
    echo     but don't run the code generation phase .  The projects are built in their
    echo     individual directories and installed into the temporary install tree.
echo clean:
    echo   Deletes generated project files.  This action removes generated source
    echo     and binary files.
echo regen:
    echo   For each project in the product, regenerate any source files that
    echo     are produced via GSL, Libero or another code generation tool.
    echo     Generates only those files that are required to build under
    echo     the current model.
echo allgen:
    echo   For each project in the product, regenerate any source files that
    echo     are produced via GSL, Libero or another code generation tool.
    echo     Generates all files.
echo distrib:
    echo   Build all projects and create full distribution packages.  If you do
    echo     not want to rebuild the projects, you can use the 'distsrc' and 'distbin'
    echo     actions as shortcuts.
echo distsrc:
    echo   Build source distribution packages based on product version number.
echo distrev:
    echo   Build source distribution packages based on source control revision
    echo     number.
    goto r_default

:s_source
    if "!debug!"=="1" echo State: source
    if "!event!"=="" goto s_4_empty
    if "!event!"=="build" goto s_4_1
    if "!event!"=="clean" goto s_4_2
    if "!event!"=="regen" goto s_4_3
    if "!event!"=="allgen" goto s_4_4
    goto s_default
:s_4_1
    if "!debug!"=="1" echo Event: build
    set event=
    if "!debug!"=="1" echo Action: build projects
    set _exception=
    call :a_build_projects
    if "!_exception!"=="1" exit /b 1
    if not "%1"=="" goto process
    exit /b 0
:s_4_2
    if "!debug!"=="1" echo Event: clean
    set event=
    if "!debug!"=="1" echo Action: clean projects
    set _exception=
    call :a_clean_projects
    if "!_exception!"=="1" exit /b 1
    if not "%1"=="" goto process
    exit /b 0
:s_4_3
    if "!debug!"=="1" echo Event: regen
    set event=
    if "!debug!"=="1" echo Action: regen projects
    set _exception=
    call :a_regen_projects
    if "!_exception!"=="1" exit /b 1
    if not "%1"=="" goto process
    exit /b 0
:s_4_4
    if "!debug!"=="1" echo Event: allgen
    set event=
    if "!debug!"=="1" echo Action: allgen projects
    set _exception=
    call :a_allgen_projects
    if "!_exception!"=="1" exit /b 1
    if not "%1"=="" goto process
    exit /b 0
:s_4_empty
    if "!debug!"=="1" echo Get event from user
    set event=%1
    shift
    if "!event!"=="" set event=empty
    goto s_source
:r_source
echo build:
    echo   For each project in the product, build binary files ready for
    echo     installation.  The projects are built in their individual directories
    echo     and installed into the temporary install tree.
echo clean:
    echo   Deletes generated project files.  This action removes generated binary
    echo     files.
echo regen:
    echo   For each project in the product, regenerate any source files that
    echo     are produced via GSL, Libero or another code generation tool.
    echo     Generates only those files that are required to build under
    echo     the current model.
echo allgen:
    echo   For each project in the product, regenerate any source files that
    echo     are produced via GSL, Libero or another code generation tool.
    echo     Generates all files.
    goto r_default

:s_stripped
    if "!debug!"=="1" echo State: stripped
    if "!event!"=="" goto s_5_empty
    if "!event!"=="build" goto s_5_1
    if "!event!"=="clean" goto s_5_2
    goto s_default
:s_5_1
    if "!debug!"=="1" echo Event: build
    set event=
    if "!debug!"=="1" echo Action: build projects
    set _exception=
    call :a_build_projects
    if "!_exception!"=="1" exit /b 1
    if not "%1"=="" goto process
    exit /b 0
:s_5_2
    if "!debug!"=="1" echo Event: clean
    set event=
    if "!debug!"=="1" echo Action: clean projects
    set _exception=
    call :a_clean_projects
    if "!_exception!"=="1" exit /b 1
    if not "%1"=="" goto process
    exit /b 0
:s_5_empty
    if "!debug!"=="1" echo Get event from user
    set event=%1
    shift
    if "!event!"=="" set event=empty
    goto s_stripped
:r_stripped
echo build:
    echo   For each project in the product, build binary files ready for
    echo     installation.  The projects are built in their individual directories
    echo     and installed into the temporary install tree.
echo clean:
    echo   Deletes generated project files.  This action removes generated binary
    echo     files.
    goto r_default

:s_default
    if "!debug!"=="1" echo State: default
    if "!event!"=="" goto s_6_empty
    if "!event!"=="install" goto s_6_1
    if "!event!"=="distbin" goto s_6_2
    if "!event!"=="test" goto s_6_3
    if "!event!"=="help" goto s_6_4
    if "!event!"=="version" goto s_6_5
    if "!event!"=="empty" goto s_6_6
    echo Unknown command - use one of:
    echo.
    goto r_!state!
:s_6_1
    if "!debug!"=="1" echo Event: install
    set event=
    if "!debug!"=="1" echo Action: install projects
    set _exception=
    call :a_install_projects
    if "!_exception!"=="1" exit /b 1
    if not "%1"=="" goto process
    exit /b 0
:s_6_2
    if "!debug!"=="1" echo Event: distbin
    set event=
    if "!debug!"=="1" echo Action: build product install packages
    set _exception=
    call :a_build_product_install_packages
    if "!_exception!"=="1" exit /b 1
    if not "%1"=="" goto process
    exit /b 0
:s_6_3
    if "!debug!"=="1" echo Event: test
    set event=
    if "!debug!"=="1" echo Action: test projects
    set _exception=
    call :a_test_projects
    if "!_exception!"=="1" exit /b 1
    if not "%1"=="" goto process
    exit /b 0
:s_6_4
    if "!debug!"=="1" echo Event: help
    set event=
    if "!debug!"=="1" echo Action: report help information
    set _exception=
    call :a_report_help_information
    if "!_exception!"=="1" exit /b 1
    if not "%1"=="" goto process
    exit /b 0
:s_6_5
    if "!debug!"=="1" echo Event: version
    set event=
    if "!debug!"=="1" echo Action: report project version
    set _exception=
    call :a_report_project_version
    if "!_exception!"=="1" exit /b 1
    if not "%1"=="" goto process
    exit /b 0
:s_6_6
    if "!debug!"=="1" echo Event: empty
    set event=
    if "!debug!"=="1" echo Action: report help information
    set _exception=
    call :a_report_help_information
    if "!_exception!"=="1" exit /b 1
    if not "%1"=="" goto process
    exit /b 0
:s_6_empty
    if "!debug!"=="1" echo Get event from user
    set event=%1
    shift
    if "!event!"=="" set event=empty
    goto s_default
:r_default
echo install:
    echo   Install each project into its target directory.  The projects must
    echo     have been built (and installed into the temporary install tree, which
    echo     is what the build action does).
echo distbin:
    echo   Build binary distribution packages.  The actual packages built depend on
    echo     the project packagers used, but typically you will get a ZIP or TGZ file
    echo     containing all the projects' deliverables.  Note that this action works
    echo     entirely from the temporary install tree, which the 'build' action makes.
echo test:
    echo   Runs each project's test process.
echo help:
    echo   Shows a list of the commands allowed on the project.
echo version:
    echo   Show product version.
    exit /b 0


exit /b 0
