@ECHO OFF

::
:: flight.bat --
::
:: Extensible Adaptable Generalized Logic Engine (Eagle)
:: Release Preparation & Build Tool
::
:: Copyright (c) 2007-2012 by Joe Mistachkin.  All rights reserved.
::
:: See the file "license.terms" for information on usage and redistribution of
:: this file, and for a DISCLAIMER OF ALL WARRANTIES.
::
:: RCS: @(#) $Id: $
::

REM ****************************************************************************
REM ******************** Prologue / Command Line Processing ********************
REM ****************************************************************************

SETLOCAL
ECHO STARTED ON %DATE% AT %TIME% BY %USERDOMAIN%\%USERNAME%

REM SET __ECHO=ECHO
REM SET __ECHO2=ECHO
REM SET __ECHO3=ECHO
IF NOT DEFINED _AECHO (SET _AECHO=REM)
IF NOT DEFINED _CECHO (SET _CECHO=REM)
IF NOT DEFINED _VECHO (SET _VECHO=REM)

SET APPEND=^>^>
SET _CAPPEND=^^^>^^^>
IF DEFINED __ECHO SET APPEND=^^^>^^^>

SET PIPE=^|
SET _CPIPE=^^^|
IF DEFINED __ECHO SET PIPE=^^^|

%_AECHO% Running %0 %*

REM SET DFLAGS=/L

%_VECHO% DFlags = '%DFLAGS%'

SET FFLAGS=/V /F /G /H /I /R /Y /Z

%_VECHO% FFlags = '%FFLAGS%'

SET CONFIGURATION=%1

IF DEFINED CONFIGURATION (
  CALL :fn_UnquoteVariable CONFIGURATION
) ELSE (
  %_AECHO% No configuration specified, using default...
  SET CONFIGURATION=Release
)

%_VECHO% Configuration = '%CONFIGURATION%'

REM ****************************************************************************
REM ********************** Set Miscellaneous Environment ***********************
REM ****************************************************************************

IF NOT DEFINED PLATFORMS (
  %_AECHO% No platforms specified, using default...
  SET PLATFORMS=Win32 x86 x64
)

%_VECHO% Platforms = '%PLATFORMS%'

IF NOT DEFINED NATIVE_CONFIGURATION (
  %_AECHO% No native configuration specified, using default...
  SET NATIVE_CONFIGURATION=%CONFIGURATION%Dll
)

%_VECHO% NativeConfiguration = '%NATIVE_CONFIGURATION%'

IF NOT DEFINED DEFAULT_PLATFORM (
  SET DEFAULT_PLATFORM=Win32
)

%_VECHO% DefaultPlatform = '%DEFAULT_PLATFORM%'

IF NOT DEFINED PACKAGE_PLATFORM (
  %_AECHO% No package platform specified, using default...
  SET PACKAGE_PLATFORM=%DEFAULT_PLATFORM%
)

%_VECHO% PackagePlatform = '%PACKAGE_PLATFORM%'

REM
REM HACK: If we are not building any NetFx40 or NetFx45 build configurations
REM       then Garuda will not be built; therefore, disable other steps that
REM       require it.
REM
IF DEFINED NONETFX40 (
  IF DEFINED NONETFX45 (
    IF DEFINED NONETFX451 (
      SET NOPACKAGE=1
    )
  )
)

IF NOT DEFINED HASHBASES (
  SET HASHBASES=EagleSource EagleSetup EagleBinary EagleRuntime EagleCore

  IF NOT DEFINED NOPACKAGE (
    CALL :fn_AppendVariable HASHBASES " GarudaSetup GarudaBinary"
    CALL :fn_AppendVariable HASHBASES " GarudaRuntime GarudaCore"
  )
)

%_VECHO% HashBases = '%HASHBASES%'

IF NOT DEFINED HASHEXTS (
  SET HASHEXTS=exe rar zip
)

%_VECHO% HashExts = '%HASHEXTS%'

IF NOT DEFINED MANAGEDIMAGEFILES (
  SET MANAGEDIMAGEFILES=Eagle.dll EagleCmdlets.dll EagleExtensions.dll EagleTasks.dll EagleShell.exe Hippogriff.exe
)

%_VECHO% ManagedImageFiles = '%MANAGEDIMAGEFILES%'

IF NOT DEFINED NATIVEIMAGEFILES (
  SET NATIVEIMAGEFILES=Garuda.dll Spilornis.dll
)

%_VECHO% NativeImageFiles = '%NATIVEIMAGEFILES%'

IF NOT DEFINED PATCHLEVELFILES (
  SET PATCHLEVELFILES=BuildInfo.cs PatchLevel.cs
)

%_VECHO% PatchLevelFiles = '%PATCHLEVELFILES%'

IF NOT DEFINED TAGFILES (
  SET TAGFILES=BuildInfo.cs PatchLevel.cs
)

%_VECHO% TagFiles = '%TAGFILES%'

IF NOT DEFINED PACKAGE_TAGFILES (
  SET PACKAGE_TAGFILES=pkgVersion.h
)

%_VECHO% PackageTagFiles = '%PACKAGE_TAGFILES%'

SET ARGS=%*

%_VECHO% Args = '%ARGS%'

REM ****************************************************************************
REM **************************** Set Build Suffixes ****************************
REM ****************************************************************************

SET NETFX20_SUFFIX=NetFx20
SET NETFX40_SUFFIX=NetFx40
SET NETFX45_SUFFIX=NetFx45
SET NETFX451_SUFFIX=NetFx451
SET BARE_SUFFIX=Bare
SET LEAN_SUFFIX=LeanAndMean
SET DATABASE_SUFFIX=Database
SET UNIX_SUFFIX=MonoOnUnix

%_VECHO% NetFx20Suffix = '%NETFX20_SUFFIX%'
%_VECHO% NetFx40Suffix = '%NETFX40_SUFFIX%'
%_VECHO% NetFx45Suffix = '%NETFX45_SUFFIX%'
%_VECHO% NetFx451Suffix = '%NETFX451_SUFFIX%'
%_VECHO% BareSuffix = '%BARE_SUFFIX%'
%_VECHO% LeanSuffix = '%LEAN_SUFFIX%'
%_VECHO% DatabaseSuffix = '%DATABASE_SUFFIX%'
%_VECHO% UnixSuffix = '%UNIX_SUFFIX%'

REM ****************************************************************************
REM ************************* Set Build Configurations *************************
REM ****************************************************************************

IF NOT DEFINED NETFX20_CONFIGURATION (
  %_AECHO% No "%NETFX20_SUFFIX%" configuration specified, using default...
  SET NETFX20_CONFIGURATION=%CONFIGURATION%
)

%_VECHO% NetFx20Configuration = '%NETFX20_CONFIGURATION%'

IF NOT DEFINED NETFX40_CONFIGURATION (
  %_AECHO% No "%NETFX40_SUFFIX%" configuration specified, using default...
  SET NETFX40_CONFIGURATION=%CONFIGURATION%
)

%_VECHO% NetFx40Configuration = '%NETFX40_CONFIGURATION%'

IF NOT DEFINED NETFX45_CONFIGURATION (
  %_AECHO% No "%NETFX45_SUFFIX%" configuration specified, using default...
  SET NETFX45_CONFIGURATION=%CONFIGURATION%
)

%_VECHO% NetFx45Configuration = '%NETFX45_CONFIGURATION%'

IF NOT DEFINED NETFX451_CONFIGURATION (
  %_AECHO% No "%NETFX451_SUFFIX%" configuration specified, using default...
  SET NETFX451_CONFIGURATION=%CONFIGURATION%
)

%_VECHO% NetFx451Configuration = '%NETFX451_CONFIGURATION%'

IF NOT DEFINED NETFX40_BUILD_CONFIGURATION (
  %_AECHO% No "%NETFX40_SUFFIX%" build configuration specified, using default...

  IF NOT DEFINED NOPACKAGE (
    SET NETFX40_BUILD_CONFIGURATION=%NETFX40_CONFIGURATION%All
  ) ELSE (
    SET NETFX40_BUILD_CONFIGURATION=%NETFX40_CONFIGURATION%
  )
)

%_VECHO% NetFx40BuildConfiguration = '%NETFX40_BUILD_CONFIGURATION%'

IF NOT DEFINED NETFX45_BUILD_CONFIGURATION (
  %_AECHO% No "%NETFX45_SUFFIX%" build configuration specified, using default...

  IF NOT DEFINED NOPACKAGE (
    SET NETFX45_BUILD_CONFIGURATION=%NETFX45_CONFIGURATION%All
  ) ELSE (
    SET NETFX45_BUILD_CONFIGURATION=%NETFX45_CONFIGURATION%
  )
)

%_VECHO% NetFx45BuildConfiguration = '%NETFX45_BUILD_CONFIGURATION%'

IF NOT DEFINED NETFX451_BUILD_CONFIGURATION (
  %_AECHO% No "%NETFX451_SUFFIX%" build configuration specified, using default...

  IF NOT DEFINED NOPACKAGE (
    SET NETFX451_BUILD_CONFIGURATION=%NETFX451_CONFIGURATION%All
  ) ELSE (
    SET NETFX451_BUILD_CONFIGURATION=%NETFX451_CONFIGURATION%
  )
)

%_VECHO% NetFx451BuildConfiguration = '%NETFX451_BUILD_CONFIGURATION%'

IF NOT DEFINED BARE_CONFIGURATION (
  %_AECHO% No "%BARE_SUFFIX%" configuration specified, using default...
  SET BARE_CONFIGURATION=%CONFIGURATION%
)

%_VECHO% BareConfiguration = '%BARE_CONFIGURATION%'

IF NOT DEFINED LEAN_CONFIGURATION (
  %_AECHO% No "%LEAN_SUFFIX%" configuration specified, using default...
  SET LEAN_CONFIGURATION=%CONFIGURATION%
)

%_VECHO% LeanConfiguration = '%LEAN_CONFIGURATION%'

IF NOT DEFINED DATABASE_CONFIGURATION (
  %_AECHO% No "%DATABASE_SUFFIX%" configuration specified, using default...
  SET DATABASE_CONFIGURATION=%CONFIGURATION%
)

%_VECHO% DatabaseConfiguration = '%DATABASE_CONFIGURATION%'

IF NOT DEFINED UNIX_CONFIGURATION (
  %_AECHO% No "%UNIX_SUFFIX%" configuration specified, using default...
  SET UNIX_CONFIGURATION=%CONFIGURATION%
)

%_VECHO% UnixConfiguration = '%UNIX_CONFIGURATION%'

REM ****************************************************************************
REM ***************************** Set Build Paths ******************************
REM ****************************************************************************

SET RELEASES=%~dp0\..\..\Releases
SET RELEASES=%RELEASES:\\=\%

%_VECHO% Releases = '%RELEASES%'

SET LOGDIR=%RELEASES%
SET LOGPREFIX=EagleFlight

%_VECHO% LogDir = '%LOGDIR%'
%_VECHO% LogPrefix = '%LOGPREFIX%'

SET NUGETBASEPATH=%TEMP%\Eagle_NuGet_%NETFX20_CONFIGURATION%%NETFX20_SUFFIX%
SET NUGETOUTPUTDIR=%RELEASES%\%NETFX20_CONFIGURATION%%NETFX20_SUFFIX%

%_VECHO% NuGetBasePath = '%NUGETBASEPATH%'
%_VECHO% NuGetOutputDir = '%NUGETOUTPUTDIR%'

SET TOOLS=%~dp0
SET TOOLS=%TOOLS:~0,-1%

%_VECHO% Tools = '%TOOLS%'

SET PACKAGE_TOOLS=%~dp0\..\..\Native\Package\Tools
SET PACKAGE_TOOLS=%PACKAGE_TOOLS:\\=\%

%_VECHO% PackageTools = '%PACKAGE_TOOLS%'

SET ROOT=%~dp0\..\..
SET ROOT=%ROOT:\\=\%

%_VECHO% Root = '%ROOT%'

REM
REM NOTE: When performing the release process for just the core library, only
REM       look for files to tag inside of the "Library" sub-directory.
REM
IF DEFINED COREONLY (
  SET TAGPATTERN=\Library
) ELSE (
  CALL :fn_UnsetVariable TAGPATTERN
)

%_VECHO% TagPattern = '%TAGPATTERN%'

REM
REM NOTE: Reset the error level now so that we can easily check it against zero
REM       later.
REM
CALL :fn_ResetErrorLevel

REM ****************************************************************************
REM *********************** Verify Eagle Shell (in LKG) ************************
REM ****************************************************************************
REM
REM NOTE: Attempt to use the last known good build of Eagle to set the source
REM       identifier for the current build.  If the NOLKG environment variable
REM       is defined, we assume that the last known good build of Eagle will
REM       already be in the path; otherwise, the build will fail ^(below^) when
REM       we try to update the source identifier.
REM
IF DEFINED NOLKG GOTO skip_lastKnownGood
IF NOT DEFINED LKG GOTO skip_lastKnownGood

SET SRCLKGDIR=%LKG%\Eagle\bin
SET SRCLKGDIR=%SRCLKGDIR:\\=\%

%_VECHO% SrcLkgDir = '%SRCLKGDIR%'

IF NOT EXIST "%SRCLKGDIR%\EagleShell.exe" (
  ECHO The file "%SRCLKGDIR%\EagleShell.exe" does not exist.
  GOTO usage
)

%__ECHO% "%SRCLKGDIR%\EagleShell.exe" /? > NUL 2>&1

IF ERRORLEVEL 1 (
  ECHO The "%SRCLKGDIR%\EagleShell.exe" tool appears to be missing.
  GOTO usage
)

%_AECHO% Using LKG "EagleShell.exe" tool from "%SRCLKGDIR%"...

SET PATH=%PATH%;%SRCLKGDIR%

%_VECHO% Path = '%PATH%'

REM
REM NOTE: Skip checking for the "EagleShell.exe" tool along the PATH because we
REM       just found it in the LKG location.
REM
GOTO skip_eagleShell

:skip_lastKnownGood

REM ****************************************************************************
REM *********************** Verify Eagle Shell (in PATH) ***********************
REM ****************************************************************************

%__ECHO% EagleShell.exe /? > NUL 2>&1

IF ERRORLEVEL 1 (
  ECHO The "EagleShell.exe" tool appears to be missing.
  GOTO usage
)

%_AECHO% Using "EagleShell.exe" tool from the PATH...

:skip_eagleShell

REM ****************************************************************************
REM *********** Add Default (NetFx20) Build Output Directory to PATH ***********
REM ****************************************************************************
REM
REM NOTE: Always add the build output directory to the PATH because when we
REM       later execute the "EagleShell.exe" tool, we expect to get the patch
REM       level for the current release, not the last known good release.  Also,
REM       to make absolutely sure that we always get the current release version
REM       of the "EagleShell.exe" tool, we must prepend it to the PATH instead
REM       of appending it.
REM
SET SRCBINDIR=%~dp0\..\..\bin\%NETFX20_CONFIGURATION%%NETFX20_SUFFIX%\bin
SET SRCBINDIR=%SRCBINDIR:\\=\%

%_VECHO% SrcBinDir = '%SRCBINDIR%'

SET PATH=%SRCBINDIR%;%PATH%

%_VECHO% Path = '%PATH%'

REM ****************************************************************************
REM ***************** Verify Elevated Administrator Privileges *****************
REM ****************************************************************************
REM
REM NOTE: Using Eagle, make sure we have [elevated] administrator privileges
REM       before continuing unless we have been forbidden from doing so.
REM
IF DEFINED NOADMINISTRATOR GOTO skip_isAdministrator

SET IS_ADMINISTRATOR_CMD=EagleShell.exe -eval "puts stdout [isAdministrator]"

IF DEFINED __ECHO (
  %__ECHO% %IS_ADMINISTRATOR_CMD%
  SET ADMINISTRATOR=True
) ELSE (
  FOR /F %%T IN ('%IS_ADMINISTRATOR_CMD%') DO (SET ADMINISTRATOR=%%T)
)

IF NOT DEFINED ADMINISTRATOR (
  ECHO The ADMINISTRATOR environment variable could not be set.
  GOTO usage
)

%_VECHO% Administrator = '%ADMINISTRATOR%'

IF "%ADMINISTRATOR%" == "False" (
  ECHO This tool requires [elevated] administrator privileges.
  GOTO usage
)

:skip_isAdministrator

REM ****************************************************************************
REM ************************ Release Preparation HotFix ************************
REM ****************************************************************************

REM
REM NOTE: Normally, nothing should be done in this section; however, if most
REM       of the release process works perfectly and then fails on something
REM       minor near the very end, this section can be used to insert a GOTO
REM       batch command that skips the previously successful sections, thus
REM       potentially saving several hours of processing time.
REM
REM GOTO skip_successfulSections
REM

REM ****************************************************************************
REM ************************* Verify Release Directory *************************
REM ****************************************************************************

IF NOT EXIST "%ROOT%\Releases" (
  %__ECHO% MKDIR "%ROOT%\Releases"

  IF ERRORLEVEL 1 (
    ECHO Could not create directory "%ROOT%\Releases".
    GOTO errors
  )
)

REM ****************************************************************************
REM ************************ Clean Build/Release Output ************************
REM ****************************************************************************

IF NOT DEFINED NOCLEAN (
  REM
  REM HACK: The clean tool is being run from this tool; therefore, we must
  REM       have it skip trying to delete the log file that we are currently
  REM       using, if any.  The clean tool assumes that this tool uses log
  REM       file names matching the pattern "%TEMP%\EagleFlight*.log".  This
  REM       logging is typically accomplished by redirecting the output of
  REM       this tool on the command line.
  REM
  SET NOFLIGHT=1

  %__ECHO3% CALL "%TOOLS%\clean.bat"

  IF ERRORLEVEL 1 (
    ECHO Cleaning failed.
    GOTO errors
  )

  CALL :fn_UnsetVariable NOFLIGHT
)

REM ****************************************************************************
REM **************************** Skip Build Steps? *****************************
REM ****************************************************************************

IF DEFINED NOBUILD (
  %_AECHO% Skipping build steps...
  GOTO skip_build
)

REM ****************************************************************************
REM ****************** Default (NetFx20) Build Configuration *******************
REM ****************************************************************************

SET NETFX20_FLAGS=%NETFX20_FLAGS% /property:EagleBuildType=%NETFX20_SUFFIX%
SET NETFX20_FLAGS=%NETFX20_FLAGS% /property:EagleTestType=%NETFX20_SUFFIX%

IF DEFINED OFFICIAL (
  REM
  REM NOTE: For an official release build, set the necessary build property.
  REM
  SET NETFX20_FLAGS=%NETFX20_FLAGS% /property:EagleOfficial=true
)

IF DEFINED STRONGNAMETAG_ATTRIBUTE (
  REM
  REM NOTE: Technically, the EagleStrongNamePrefix MSBuild property and the
  REM       STRONGNAMETAG_ATTRIBUTE environment variable are related purely
  REM       as a matter of convention and need not contain the same value.
  REM
  SET NETFX20_FLAGS=%NETFX20_FLAGS% /property:EagleStrongNamePrefix=%STRONGNAMETAG_ATTRIBUTE%
)

IF NOT DEFINED NOTEST (
  SET NETFX20_FLAGS=%NETFX20_FLAGS% /property:EagleRunTests=true
)

IF NOT DEFINED NOPERFORMANCE (
  SET NETFX20_FLAGS=%NETFX20_FLAGS% /property:EagleTestPerformance=true
) ELSE (
  SET NETFX20_FLAGS=%NETFX20_FLAGS% /property:EagleTestPerformance=false
)

%_VECHO% NetFx20Flags = '%NETFX20_FLAGS%'

REM ****************************************************************************
REM *********************** NetFx40 Build Configuration ************************
REM ****************************************************************************

SET NETFX40_FLAGS=%NETFX40_FLAGS% /property:EagleBuildType=%NETFX40_SUFFIX%
SET NETFX40_FLAGS=%NETFX40_FLAGS% /property:EagleTestType=%NETFX40_SUFFIX%

IF DEFINED OFFICIAL (
  REM
  REM NOTE: For an official release build, set the necessary build property.
  REM
  SET NETFX40_FLAGS=%NETFX40_FLAGS% /property:EagleOfficial=true
)

IF DEFINED STRONGNAMETAG_ATTRIBUTE (
  REM
  REM NOTE: Technically, the EagleStrongNamePrefix MSBuild property and the
  REM       STRONGNAMETAG_ATTRIBUTE environment variable are related purely
  REM       as a matter of convention and need not contain the same value.
  REM
  SET NETFX40_FLAGS=%NETFX40_FLAGS% /property:EagleStrongNamePrefix=%STRONGNAMETAG_ATTRIBUTE%
)

IF NOT DEFINED NOTEST (
  SET NETFX40_FLAGS=%NETFX40_FLAGS% /property:EagleRunTests=true
)

IF NOT DEFINED NOTEST (
  SET NETFX40_FLAGS=%NETFX40_FLAGS% /property:EagleTestPerformance=false
)

%_VECHO% NetFx40Flags = '%NETFX40_FLAGS%'

REM ****************************************************************************
REM *********************** NetFx45 Build Configuration ************************
REM ****************************************************************************

SET NETFX45_FLAGS=%NETFX45_FLAGS% /property:EagleBuildType=%NETFX45_SUFFIX%
SET NETFX45_FLAGS=%NETFX45_FLAGS% /property:EagleTestType=%NETFX45_SUFFIX%

IF DEFINED OFFICIAL (
  REM
  REM NOTE: For an official release build, set the necessary build property.
  REM
  SET NETFX45_FLAGS=%NETFX45_FLAGS% /property:EagleOfficial=true
)

REM
REM HACK: Evidently, installing Visual Studio 2013 breaks using MSBuild to
REM       build native projects that specify a platform toolset of "v110"
REM       (e.g. the Garuda and Spilornis projects for Visual Studio 2012).
REM
SET NETFX45_FLAGS=%NETFX45_FLAGS% /property:VisualStudioVersion=11.0

IF DEFINED STRONGNAMETAG_ATTRIBUTE (
  REM
  REM NOTE: Technically, the EagleStrongNamePrefix MSBuild property and the
  REM       STRONGNAMETAG_ATTRIBUTE environment variable are related purely
  REM       as a matter of convention and need not contain the same value.
  REM
  SET NETFX45_FLAGS=%NETFX45_FLAGS% /property:EagleStrongNamePrefix=%STRONGNAMETAG_ATTRIBUTE%
)

IF NOT DEFINED NOTEST (
  SET NETFX45_FLAGS=%NETFX45_FLAGS% /property:EagleRunTests=true
)

IF NOT DEFINED NOTEST (
  SET NETFX45_FLAGS=%NETFX45_FLAGS% /property:EagleTestPerformance=false
)

%_VECHO% NetFx45Flags = '%NETFX45_FLAGS%'

REM ****************************************************************************
REM *********************** NetFx451 Build Configuration ***********************
REM ****************************************************************************

SET NETFX451_FLAGS=%NETFX451_FLAGS% /property:EagleBuildType=%NETFX451_SUFFIX%
SET NETFX451_FLAGS=%NETFX451_FLAGS% /property:EagleTestType=%NETFX451_SUFFIX%

IF DEFINED OFFICIAL (
  REM
  REM NOTE: For an official release build, set the necessary build property.
  REM
  SET NETFX451_FLAGS=%NETFX451_FLAGS% /property:EagleOfficial=true
)

REM
REM HACK: Evidently, using MSBuild with Visual Studio 2013 requires some
REM       extra magic to make it recognize the "v120" platform toolset.
REM       (e.g. the Garuda and Spilornis projects for Visual Studio 2013).
REM
SET NETFX451_FLAGS=%NETFX451_FLAGS% /property:VisualStudioVersion=12.0

IF DEFINED STRONGNAMETAG_ATTRIBUTE (
  REM
  REM NOTE: Technically, the EagleStrongNamePrefix MSBuild property and the
  REM       STRONGNAMETAG_ATTRIBUTE environment variable are related purely
  REM       as a matter of convention and need not contain the same value.
  REM
  SET NETFX451_FLAGS=%NETFX451_FLAGS% /property:EagleStrongNamePrefix=%STRONGNAMETAG_ATTRIBUTE%
)

IF NOT DEFINED NOTEST (
  SET NETFX451_FLAGS=%NETFX451_FLAGS% /property:EagleRunTests=true
)

IF NOT DEFINED NOTEST (
  SET NETFX451_FLAGS=%NETFX451_FLAGS% /property:EagleTestPerformance=false
)

%_VECHO% NetFx451Flags = '%NETFX451_FLAGS%'

REM ****************************************************************************
REM ************************* Bare Build Configuration *************************
REM ****************************************************************************

SET BARE_FLAGS=%BARE_FLAGS% /property:EagleBuildType=%BARE_SUFFIX%
SET BARE_FLAGS=%BARE_FLAGS% /property:EagleTestType=%BARE_SUFFIX%

IF DEFINED OFFICIAL (
  REM
  REM NOTE: For an official release build, set the necessary build property.
  REM
  SET BARE_FLAGS=%BARE_FLAGS% /property:EagleOfficial=true
)

IF DEFINED STRONGNAMETAG_ATTRIBUTE (
  REM
  REM NOTE: Technically, the EagleStrongNamePrefix MSBuild property and the
  REM       STRONGNAMETAG_ATTRIBUTE environment variable are related purely
  REM       as a matter of convention and need not contain the same value.
  REM
  SET BARE_FLAGS=%BARE_FLAGS% /property:EagleStrongNamePrefix=%STRONGNAMETAG_ATTRIBUTE%
)

IF NOT DEFINED NOTEST (
  SET BARE_FLAGS=%BARE_FLAGS% /property:EagleRunTests=true
)

IF NOT DEFINED NOTEST (
  SET BARE_FLAGS=%BARE_FLAGS% /property:EagleTestPerformance=false
)

%_VECHO% BareFlags = '%BARE_FLAGS%'

REM ****************************************************************************
REM ********************* LeanAndMean Build Configuration **********************
REM ****************************************************************************

SET LEAN_FLAGS=%LEAN_FLAGS% /property:EagleBuildType=%LEAN_SUFFIX%
SET LEAN_FLAGS=%LEAN_FLAGS% /property:EagleTestType=%LEAN_SUFFIX%

IF DEFINED OFFICIAL (
  REM
  REM NOTE: For an official release build, set the necessary build property.
  REM
  SET LEAN_FLAGS=%LEAN_FLAGS% /property:EagleOfficial=true
)

IF DEFINED STRONGNAMETAG_ATTRIBUTE (
  REM
  REM NOTE: Technically, the EagleStrongNamePrefix MSBuild property and the
  REM       STRONGNAMETAG_ATTRIBUTE environment variable are related purely
  REM       as a matter of convention and need not contain the same value.
  REM
  SET LEAN_FLAGS=%LEAN_FLAGS% /property:EagleStrongNamePrefix=%STRONGNAMETAG_ATTRIBUTE%
)

IF NOT DEFINED NOTEST (
  SET LEAN_FLAGS=%LEAN_FLAGS% /property:EagleRunTests=true
)

IF NOT DEFINED NOTEST (
  SET LEAN_FLAGS=%LEAN_FLAGS% /property:EagleTestPerformance=false
)

%_VECHO% LeanFlags = '%LEAN_FLAGS%'

REM ****************************************************************************
REM *********************** Database Build Configuration ***********************
REM ****************************************************************************

SET DATABASE_FLAGS=%DATABASE_FLAGS% /property:EagleBuildType=%DATABASE_SUFFIX%
SET DATABASE_FLAGS=%DATABASE_FLAGS% /property:EagleTestType=%DATABASE_SUFFIX%

IF DEFINED OFFICIAL (
  REM
  REM NOTE: For an official release build, set the necessary build property.
  REM
  SET DATABASE_FLAGS=%DATABASE_FLAGS% /property:EagleOfficial=true
)

IF DEFINED STRONGNAMETAG_ATTRIBUTE (
  REM
  REM NOTE: Technically, the EagleStrongNamePrefix MSBuild property and the
  REM       STRONGNAMETAG_ATTRIBUTE environment variable are related purely
  REM       as a matter of convention and need not contain the same value.
  REM
  SET DATABASE_FLAGS=%DATABASE_FLAGS% /property:EagleStrongNamePrefix=%STRONGNAMETAG_ATTRIBUTE%
)

IF NOT DEFINED NOTEST (
  SET DATABASE_FLAGS=%DATABASE_FLAGS% /property:EagleRunTests=true
)

IF NOT DEFINED NOTEST (
  SET DATABASE_FLAGS=%DATABASE_FLAGS% /property:EagleTestPerformance=false
)

%_VECHO% DatabaseFlags = '%DATABASE_FLAGS%'

REM ****************************************************************************
REM ********************** MonoOnUnix Build Configuration **********************
REM ****************************************************************************

SET UNIX_FLAGS=%UNIX_FLAGS% /property:EagleBuildType=%UNIX_SUFFIX%
SET UNIX_FLAGS=%UNIX_FLAGS% /property:EagleTestType=%UNIX_SUFFIX%

IF DEFINED OFFICIAL (
  REM
  REM NOTE: For an official release build, set the necessary build property.
  REM
  SET UNIX_FLAGS=%UNIX_FLAGS% /property:EagleOfficial=true
)

IF DEFINED STRONGNAMETAG_ATTRIBUTE (
  REM
  REM NOTE: Technically, the EagleStrongNamePrefix MSBuild property and the
  REM       STRONGNAMETAG_ATTRIBUTE environment variable are related purely
  REM       as a matter of convention and need not contain the same value.
  REM
  SET UNIX_FLAGS=%UNIX_FLAGS% /property:EagleStrongNamePrefix=%STRONGNAMETAG_ATTRIBUTE%
)

IF NOT DEFINED NOTEST (
  SET UNIX_FLAGS=%UNIX_FLAGS% /property:EagleRunTests=true
)

IF NOT DEFINED NOTEST (
  SET UNIX_FLAGS=%UNIX_FLAGS% /property:EagleTestPerformance=false
)

%_VECHO% UnixFlags = '%UNIX_FLAGS%'

REM ****************************************************************************
REM ************************** Query Eagle PatchLevel **************************
REM ****************************************************************************

REM
REM NOTE: This must be done now so that invocations of the "versionTag.eagle"
REM       tool can pickup the PATCHLEVEL environment variable, if necessary
REM       ^(e.g. if the NONETFX20 environment variable has been set for this
REM       release^).
REM
IF NOT DEFINED NONETFX20 GOTO skip_patchLevel1

SET GET_PATCHLEVEL_CMD=EagleShell.exe -eval "puts stdout [appendArgs [info engine Version] . [join [clock build] .]]"

IF NOT DEFINED PATCHLEVEL (
  IF DEFINED __ECHO (
    %__ECHO% %GET_PATCHLEVEL_CMD%
    SET PATCHLEVEL=1.0.X.X
  ) ELSE (
    FOR /F %%T IN ('%GET_PATCHLEVEL_CMD%') DO (SET PATCHLEVEL=%%T)
  )
)

IF NOT DEFINED PATCHLEVEL (
  ECHO The PATCHLEVEL environment variable could not be set.
  GOTO errors
)

%_VECHO% PatchLevel = '%PATCHLEVEL%'

:skip_patchLevel1

REM ****************************************************************************
REM ************************** Set Build Release Info **************************
REM ****************************************************************************

IF NOT DEFINED NOATTRIBUTE (
  IF DEFINED RELEASE_ATTRIBUTE (
    FOR %%T IN (%TAGFILES%) DO (
      FOR /F "delims=" %%F IN ('DIR /B /S "%ROOT%%TAGPATTERN%\%%T" 2^> NUL') DO (
        %__ECHO% ECHO %RELEASE_ATTRIBUTE% %PIPE% EagleShell.exe -file "%TOOLS%\versionTag.eagle" AssemblyReleaseMode "%%F"

        IF ERRORLEVEL 1 (
          ECHO Updating "%%F" failed.
          GOTO errors
        )
      )
    )
  ) ELSE (
    ECHO.
    ECHO WARNING: The RELEASE_ATTRIBUTE environment variable is not set.
    ECHO.
  )

  IF DEFINED STRONGNAMETAG_ATTRIBUTE (
    FOR %%T IN (%TAGFILES%) DO (
      FOR /F "delims=" %%F IN ('DIR /B /S "%ROOT%%TAGPATTERN%\%%T" 2^> NUL') DO (
        %__ECHO% ECHO %STRONGNAMETAG_ATTRIBUTE% %PIPE% EagleShell.exe -file "%TOOLS%\versionTag.eagle" AssemblyStrongNameTagMode "%%F"

        IF ERRORLEVEL 1 (
          ECHO Updating "%%F" failed.
          GOTO errors
        )
      )
    )
  ) ELSE (
    ECHO.
    ECHO WARNING: The STRONGNAMETAG_ATTRIBUTE environment variable is not set.
    ECHO.
  )
)

)

REM ****************************************************************************
REM ************************** Set Build Source Info ***************************
REM ****************************************************************************

IF NOT DEFINED NOSOURCEID (
  FOR %%T IN (%TAGFILES%) DO (
    FOR /F "delims=" %%F IN ('DIR /B /S "%ROOT%%TAGPATTERN%\%%T" 2^> NUL') DO (
      %__ECHO% EagleShell.exe -file "%TOOLS%\versionTag.eagle" SourceIdMode "%%F"

      IF ERRORLEVEL 1 (
        ECHO Updating "%%F" failed.
        GOTO errors
      )
    )
  )

  IF NOT DEFINED NOPACKAGE (
    FOR %%T IN (%PACKAGE_TAGFILES%) DO (
      FOR /F "delims=" %%F IN ('DIR /B /S "%ROOT%\Native\Package\%%T" 2^> NUL') DO (
        %__ECHO% EagleShell.exe -file "%TOOLS%\versionTag.eagle" SourceIdMode "%%F"

        IF ERRORLEVEL 1 (
          ECHO Updating "%%F" failed.
          GOTO errors
        )
      )
    )
  )
)

REM ****************************************************************************
REM ************************* Build Default (NetFx20) **************************
REM ****************************************************************************

IF NOT DEFINED NONETFX20 (
  SET LOGSUFFIX=%NETFX20_SUFFIX%
  CALL :fn_ShowVariable LogSuffix LOGSUFFIX

  IF NOT DEFINED NOFRAMEWORK (
    SET NETFX35ONLY=1
  )

  IF NOT DEFINED COMMERCIAL (
    SET NOCOMMERCIAL=1
  )

  IF NOT DEFINED ENTERPRISE (
    SET NOENTERPRISE=1
  )

  IF NOT DEFINED NOBUILDINFO (
    FOR %%T IN (%TAGFILES%) DO (
      FOR /F "delims=" %%F IN ('DIR /B /S "%ROOT%%TAGPATTERN%\%%T" 2^> NUL') DO (
        %__ECHO% ECHO %NETFX20_SUFFIX% %PIPE% EagleShell.exe -file "%TOOLS%\versionTag.eagle" AssemblyTextMode "%%F"

        IF ERRORLEVEL 1 (
          ECHO Updating "%%F" failed.
          GOTO errors
        )
      )
    )
  )

  IF NOT DEFINED NONATIVE (
    SET EagleConfigurationSuffix=%NETFX20_SUFFIX%
    SET UTILITYONLY=1
    SET PLATFORM=Win32

    %__ECHO3% CALL "%TOOLS%\build.bat" "%NATIVE_CONFIGURATION%" %NETFX20_FLAGS% /property:FlightType=%ARGS%

    IF ERRORLEVEL 1 (
      ECHO Building "%NATIVE_CONFIGURATION%%NETFX20_SUFFIX%" native utility binaries for x86 failed.
      GOTO errors
    )

    SET PLATFORM=x64

    %__ECHO3% CALL "%TOOLS%\build.bat" "%NATIVE_CONFIGURATION%" %NETFX20_FLAGS% /property:FlightType=%ARGS%

    IF ERRORLEVEL 1 (
      ECHO Building "%NATIVE_CONFIGURATION%%NETFX20_SUFFIX%" native utility binaries for x64 failed.
      GOTO errors
    )

    CALL :fn_UnsetVariable PLATFORM
    CALL :fn_UnsetVariable UTILITYONLY
    CALL :fn_UnsetVariable EagleConfigurationSuffix
  )

  %__ECHO3% CALL "%TOOLS%\build.bat" "%NETFX20_CONFIGURATION%" %NETFX20_FLAGS% /property:FlightType=%ARGS%

  IF ERRORLEVEL 1 (
    ECHO Building "%NETFX20_CONFIGURATION%%NETFX20_SUFFIX%" binaries failed.
    GOTO errors
  )

  IF NOT DEFINED ENTERPRISE (
    CALL :fn_UnsetVariable NOENTERPRISE
  )

  IF NOT DEFINED COMMERCIAL (
    CALL :fn_UnsetVariable NOCOMMERCIAL
  )

  IF NOT DEFINED NOFRAMEWORK (
    CALL :fn_UnsetVariable NETFX35ONLY
  )

  CALL :fn_UnsetVariable LOGSUFFIX
)

REM ****************************************************************************
REM ********************** Check Default (NetFx20) Files ***********************
REM ****************************************************************************

IF NOT DEFINED NONETFX20 (
  IF NOT DEFINED NOSTRONGNAME (
    FOR %%I IN (%MANAGEDIMAGEFILES%) DO (
      FOR /F "delims=" %%F IN ('DIR /B /S "%ROOT%\bin\%NETFX20_CONFIGURATION%%NETFX20_SUFFIX%\%%I" 2^> NUL') DO (
        %_AECHO% Checking strong name on file "%%F"...
        %_CECHO% sn.exe -vf "%%F"
        %__ECHO% sn.exe -vf "%%F"

        IF ERRORLEVEL 1 (
          ECHO Checking strong name on file "%%F" failed.
          GOTO errors
        )

        IF NOT DEFINED NOSIGN (
          IF NOT DEFINED NOSIGCHECK (
            %_AECHO% Checking signatures on file "%%F"...
            %_CECHO% SigCheck.exe "%%F" %_CPIPE% FINDSTR "/G:%TOOLS%\data\SigCheck.txt"
            %__ECHO% SigCheck.exe "%%F" %PIPE% FINDSTR "/G:%TOOLS%\data\SigCheck.txt"

            IF ERRORLEVEL 1 (
              ECHO Checking signatures on file "%%F" failed.
              GOTO errors
            )
          )
        )
      )
    )
  )

  IF NOT DEFINED NOSIGN (
    IF NOT DEFINED NOSIGCHECK (
      FOR %%P IN (%PLATFORMS%) DO (
        FOR %%I IN (%NATIVEIMAGEFILES%) DO (
          FOR /F "delims=" %%F IN ('DIR /B /S "%ROOT%\bin\%%P\%NATIVE_CONFIGURATION%%NETFX20_SUFFIX%\%%I" 2^> NUL') DO (
            %_AECHO% Checking signatures on file "%%F"...
            %_CECHO% SigCheck.exe "%%F" %_CPIPE% FINDSTR "/G:%TOOLS%\data\SigCheck.txt"
            %__ECHO% SigCheck.exe "%%F" %PIPE% FINDSTR "/G:%TOOLS%\data\SigCheck.txt"

            IF ERRORLEVEL 1 (
              ECHO Checking signatures on file "%%F" failed.
              GOTO errors
            )
          )
        )
      )
    )
  )
)

REM ****************************************************************************
REM *********************** Synchronize Build PatchLevel ***********************
REM ****************************************************************************

IF NOT DEFINED NOPATCHLEVEL (
  REM
  REM NOTE: All files named "PatchLevel.cs" must be updated with the correct
  REM       build number prior to building any non-default ^(NetFX20^) build
  REM       configuration.  If this is not done, building of the non-default
  REM       build configurations may fail because various projects may try
  REM       to include an AssemblyVersion attribute with a null value, due
  REM       to the EaglePatchLevel build property being true for those build
  REM       configurations.
  REM
  FOR %%T IN (%PATCHLEVELFILES%) DO (
    FOR /F "delims=" %%F IN ('DIR /B /S "%ROOT%%TAGPATTERN%\%%T" 2^> NUL') DO (
      %__ECHO% EagleShell.exe -file "%TOOLS%\versionTag.eagle" PatchLevelMode "%%F"

      IF ERRORLEVEL 1 (
        ECHO Updating "%%F" failed.
        GOTO errors
      )
    )
  )
)

REM ****************************************************************************
REM ****************************** Build NetFx40 *******************************
REM ****************************************************************************

IF NOT DEFINED NONETFX40 (
  SET LOGSUFFIX=%NETFX40_SUFFIX%
  CALL :fn_ShowVariable LogSuffix LOGSUFFIX

  IF NOT DEFINED NOFRAMEWORK (
    SET NETFX40ONLY=1
  )

  IF NOT DEFINED COMMERCIAL (
    SET NOCOMMERCIAL=1
  )

  IF NOT DEFINED ENTERPRISE (
    SET NOENTERPRISE=1
  )

  IF NOT DEFINED NOBUILDINFO (
    FOR %%T IN (%TAGFILES%) DO (
      FOR /F "delims=" %%F IN ('DIR /B /S "%ROOT%%TAGPATTERN%\%%T" 2^> NUL') DO (
        %__ECHO% ECHO %NETFX40_SUFFIX% %PIPE% EagleShell.exe -file "%TOOLS%\versionTag.eagle" AssemblyTextMode "%%F"

        IF ERRORLEVEL 1 (
          ECHO Updating "%%F" failed.
          GOTO errors
        )
      )
    )
  )

  IF NOT DEFINED NONATIVE (
    SET UTILITYONLY=1

    REM
    REM NOTE: If we are going to build the Eagle Package for Tcl, then the
    REM       Win32 platform binaries for the Eagle Native Utility Library
    REM       will also be built; therefore, skip building it separately in
    REM       that case.
    REM
    IF DEFINED NOPACKAGE (
      SET PLATFORM=Win32

      %__ECHO3% CALL "%TOOLS%\build.bat" "%NATIVE_CONFIGURATION%" %NETFX40_FLAGS% /property:FlightType=%ARGS%

      IF ERRORLEVEL 1 (
        ECHO Building "%NATIVE_CONFIGURATION%%NETFX40_SUFFIX%" native utility binaries for x86 failed.
        GOTO errors
      )
    )

    SET PLATFORM=x64

    %__ECHO3% CALL "%TOOLS%\build.bat" "%NATIVE_CONFIGURATION%" %NETFX40_FLAGS% /property:FlightType=%ARGS%

    IF ERRORLEVEL 1 (
      ECHO Building "%NATIVE_CONFIGURATION%%NETFX40_SUFFIX%" native utility binaries for x64 failed.
      GOTO errors
    )

    CALL :fn_UnsetVariable PLATFORM
    CALL :fn_UnsetVariable UTILITYONLY
  )

  %__ECHO3% CALL "%TOOLS%\build.bat" "%NETFX40_BUILD_CONFIGURATION%" %NETFX40_FLAGS% /property:FlightType=%ARGS%

  IF ERRORLEVEL 1 (
    ECHO Building "%NETFX40_BUILD_CONFIGURATION%%NETFX40_SUFFIX%" binaries failed.
    GOTO errors
  )

  REM
  REM NOTE: Unless explicitly disabled, the Eagle Native Package for Tcl
  REM       binaries will be built as part of this build configuration;
  REM       however, they will only be built for the default platform,
  REM       which is typically "Win32".  We need to make sure the other
  REM       platforms get built as well.
  REM
  IF NOT DEFINED NOPACKAGE (
    SET PACKAGEONLY=1
    SET PLATFORM=x64

    %__ECHO3% CALL "%TOOLS%\build.bat" "%NATIVE_CONFIGURATION%" %NETFX40_FLAGS% /property:FlightType=%ARGS%

    IF ERRORLEVEL 1 (
      ECHO Building "%NATIVE_CONFIGURATION%%NETFX40_SUFFIX%" native package binaries for x64 failed.
      GOTO errors
    )

    CALL :fn_UnsetVariable PLATFORM
    CALL :fn_UnsetVariable PACKAGEONLY
  )

  IF NOT DEFINED ENTERPRISE (
    CALL :fn_UnsetVariable NOENTERPRISE
  )

  IF NOT DEFINED COMMERCIAL (
    CALL :fn_UnsetVariable NOCOMMERCIAL
  )

  IF NOT DEFINED NOFRAMEWORK (
    CALL :fn_UnsetVariable NETFX40ONLY
  )

  CALL :fn_UnsetVariable LOGSUFFIX
)

REM ****************************************************************************
REM *************************** Check NetFx40 Files ****************************
REM ****************************************************************************

IF NOT DEFINED NONETFX40 (
  IF NOT DEFINED NOSTRONGNAME (
    FOR %%I IN (%MANAGEDIMAGEFILES%) DO (
        FOR /F "delims=" %%F IN ('DIR /B /S "%ROOT%\bin\%NETFX40_CONFIGURATION%%NETFX40_SUFFIX%\%%I" 2^> NUL') DO (
        %_AECHO% Checking strong name on file "%%F"...
        %_CECHO% sn.exe -vf "%%F"
        %__ECHO% sn.exe -vf "%%F"

        IF ERRORLEVEL 1 (
          ECHO Checking strong name on file "%%F" failed.
          GOTO errors
        )

        IF NOT DEFINED NOSIGN (
          IF NOT DEFINED NOSIGCHECK (
            %_AECHO% Checking signatures on file "%%F"...
            %_CECHO% SigCheck.exe "%%F" %_CPIPE% FINDSTR "/G:%TOOLS%\data\SigCheck.txt"
            %__ECHO% SigCheck.exe "%%F" %PIPE% FINDSTR "/G:%TOOLS%\data\SigCheck.txt"

            IF ERRORLEVEL 1 (
              ECHO Checking signatures on file "%%F" failed.
              GOTO errors
            )
          )
        )
      )
    )
  )

  IF NOT DEFINED NOSIGN (
    IF NOT DEFINED NOSIGCHECK (
      FOR %%P IN (%PLATFORMS%) DO (
        FOR %%I IN (%NATIVEIMAGEFILES%) DO (
          FOR /F "delims=" %%F IN ('DIR /B /S "%ROOT%\bin\%%P\%NATIVE_CONFIGURATION%%NETFX40_SUFFIX%\%%I" 2^> NUL') DO (
            %_AECHO% Checking signatures on file "%%F"...
            %_CECHO% SigCheck.exe "%%F" %_CPIPE% FINDSTR "/G:%TOOLS%\data\SigCheck.txt"
            %__ECHO% SigCheck.exe "%%F" %PIPE% FINDSTR "/G:%TOOLS%\data\SigCheck.txt"

            IF ERRORLEVEL 1 (
              ECHO Checking signatures on file "%%F" failed.
              GOTO errors
            )
          )
        )
      )
    )
  )
)

REM ****************************************************************************
REM ****************************** Build NetFx45 *******************************
REM ****************************************************************************

IF NOT DEFINED NONETFX45 (
  SET LOGSUFFIX=%NETFX45_SUFFIX%
  CALL :fn_ShowVariable LogSuffix LOGSUFFIX

  IF NOT DEFINED NOFRAMEWORK (
    SET NETFX45ONLY=1
  )

  IF NOT DEFINED COMMERCIAL (
    SET NOCOMMERCIAL=1
  )

  IF NOT DEFINED ENTERPRISE (
    SET NOENTERPRISE=1
  )

  IF NOT DEFINED NOBUILDINFO (
    FOR %%T IN (%TAGFILES%) DO (
      FOR /F "delims=" %%F IN ('DIR /B /S "%ROOT%%TAGPATTERN%\%%T" 2^> NUL') DO (
        %__ECHO% ECHO %NETFX45_SUFFIX% %PIPE% EagleShell.exe -file "%TOOLS%\versionTag.eagle" AssemblyTextMode "%%F"

        IF ERRORLEVEL 1 (
          ECHO Updating "%%F" failed.
          GOTO errors
        )
      )
    )
  )

  IF NOT DEFINED NONATIVE (
    SET UTILITYONLY=1

    REM
    REM NOTE: If we are going to build the Eagle Package for Tcl, then the
    REM       Win32 platform binaries for the Eagle Native Utility Library
    REM       will also be built; therefore, skip building it separately in
    REM       that case.
    REM
    IF DEFINED NOPACKAGE (
      SET PLATFORM=Win32

      %__ECHO3% CALL "%TOOLS%\build.bat" "%NATIVE_CONFIGURATION%" %NETFX45_FLAGS% /property:FlightType=%ARGS%

      IF ERRORLEVEL 1 (
        ECHO Building "%NATIVE_CONFIGURATION%%NETFX45_SUFFIX%" native utility binaries for x86 failed.
        GOTO errors
      )
    )

    SET PLATFORM=x64

    %__ECHO3% CALL "%TOOLS%\build.bat" "%NATIVE_CONFIGURATION%" %NETFX45_FLAGS% /property:FlightType=%ARGS%

    IF ERRORLEVEL 1 (
      ECHO Building "%NATIVE_CONFIGURATION%%NETFX45_SUFFIX%" native utility binaries for x64 failed.
      GOTO errors
    )

    SET PLATFORM=ARM

    %__ECHO3% CALL "%TOOLS%\build.bat" "%NATIVE_CONFIGURATION%" %NETFX45_FLAGS% /property:FlightType=%ARGS%

    IF ERRORLEVEL 1 (
      ECHO Building "%NATIVE_CONFIGURATION%%NETFX45_SUFFIX%" native utility binaries for ARM failed.
      GOTO errors
    )

    CALL :fn_UnsetVariable PLATFORM
    CALL :fn_UnsetVariable UTILITYONLY
  )

  %__ECHO3% CALL "%TOOLS%\build.bat" "%NETFX45_BUILD_CONFIGURATION%" %NETFX45_FLAGS% /property:FlightType=%ARGS%

  IF ERRORLEVEL 1 (
    ECHO Building "%NETFX45_BUILD_CONFIGURATION%%NETFX45_SUFFIX%" binaries failed.
    GOTO errors
  )

  REM
  REM NOTE: Unless explicitly disabled, the Eagle Native Package for Tcl
  REM       binaries will be built as part of this build configuration;
  REM       however, they will only be built for the default platform,
  REM       which is typically "Win32".  We need to make sure the other
  REM       platforms get built as well.
  REM
  IF NOT DEFINED NOPACKAGE (
    SET PACKAGEONLY=1
    SET PLATFORM=x64

    %__ECHO3% CALL "%TOOLS%\build.bat" "%NATIVE_CONFIGURATION%" %NETFX45_FLAGS% /property:FlightType=%ARGS%

    IF ERRORLEVEL 1 (
      ECHO Building "%NATIVE_CONFIGURATION%%NETFX45_SUFFIX%" native package binaries for x64 failed.
      GOTO errors
    )

    SET PLATFORM=ARM

    %__ECHO3% CALL "%TOOLS%\build.bat" "%NATIVE_CONFIGURATION%" %NETFX45_FLAGS% /property:FlightType=%ARGS%

    IF ERRORLEVEL 1 (
      ECHO Building "%NATIVE_CONFIGURATION%%NETFX45_SUFFIX%" native package binaries for ARM failed.
      GOTO errors
    )

    CALL :fn_UnsetVariable PLATFORM
    CALL :fn_UnsetVariable PACKAGEONLY
  )

  IF NOT DEFINED ENTERPRISE (
    CALL :fn_UnsetVariable NOENTERPRISE
  )

  IF NOT DEFINED COMMERCIAL (
    CALL :fn_UnsetVariable NOCOMMERCIAL
  )

  IF NOT DEFINED NOFRAMEWORK (
    CALL :fn_UnsetVariable NETFX45ONLY
  )

  CALL :fn_UnsetVariable LOGSUFFIX
)

REM ****************************************************************************
REM *************************** Check NetFx45 Files ****************************
REM ****************************************************************************

IF NOT DEFINED NONETFX45 (
  IF NOT DEFINED NOSTRONGNAME (
    FOR %%I IN (%MANAGEDIMAGEFILES%) DO (
        FOR /F "delims=" %%F IN ('DIR /B /S "%ROOT%\bin\%NETFX45_CONFIGURATION%%NETFX45_SUFFIX%\%%I" 2^> NUL') DO (
        %_AECHO% Checking strong name on file "%%F"...
        %_CECHO% sn.exe -vf "%%F"
        %__ECHO% sn.exe -vf "%%F"

        IF ERRORLEVEL 1 (
          ECHO Checking strong name on file "%%F" failed.
          GOTO errors
        )

        IF NOT DEFINED NOSIGN (
          IF NOT DEFINED NOSIGCHECK (
            %_AECHO% Checking signatures on file "%%F"...
            %_CECHO% SigCheck.exe "%%F" %_CPIPE% FINDSTR "/G:%TOOLS%\data\SigCheck.txt"
            %__ECHO% SigCheck.exe "%%F" %PIPE% FINDSTR "/G:%TOOLS%\data\SigCheck.txt"

            IF ERRORLEVEL 1 (
              ECHO Checking signatures on file "%%F" failed.
              GOTO errors
            )
          )
        )
      )
    )
  )

  IF NOT DEFINED NOSIGN (
    IF NOT DEFINED NOSIGCHECK (
      FOR %%P IN (%PLATFORMS%) DO (
        FOR %%I IN (%NATIVEIMAGEFILES%) DO (
          FOR /F "delims=" %%F IN ('DIR /B /S "%ROOT%\bin\%%P\%NATIVE_CONFIGURATION%%NETFX45_SUFFIX%\%%I" 2^> NUL') DO (
            %_AECHO% Checking signatures on file "%%F"...
            %_CECHO% SigCheck.exe "%%F" %_CPIPE% FINDSTR "/G:%TOOLS%\data\SigCheck.txt"
            %__ECHO% SigCheck.exe "%%F" %PIPE% FINDSTR "/G:%TOOLS%\data\SigCheck.txt"

            IF ERRORLEVEL 1 (
              ECHO Checking signatures on file "%%F" failed.
              GOTO errors
            )
          )
        )
      )
    )
  )
)

REM ****************************************************************************
REM ****************************** Build NetFx451 ******************************
REM ****************************************************************************

IF NOT DEFINED NONETFX451 (
  SET LOGSUFFIX=%NETFX451_SUFFIX%
  CALL :fn_ShowVariable LogSuffix LOGSUFFIX

  IF NOT DEFINED NOFRAMEWORK (
    SET NETFX451ONLY=1
  )

  IF NOT DEFINED COMMERCIAL (
    SET NOCOMMERCIAL=1
  )

  IF NOT DEFINED ENTERPRISE (
    SET NOENTERPRISE=1
  )

  IF NOT DEFINED NOBUILDINFO (
    FOR %%T IN (%TAGFILES%) DO (
      FOR /F "delims=" %%F IN ('DIR /B /S "%ROOT%%TAGPATTERN%\%%T" 2^> NUL') DO (
        %__ECHO% ECHO %NETFX451_SUFFIX% %PIPE% EagleShell.exe -file "%TOOLS%\versionTag.eagle" AssemblyTextMode "%%F"

        IF ERRORLEVEL 1 (
          ECHO Updating "%%F" failed.
          GOTO errors
        )
      )
    )
  )

  IF NOT DEFINED NONATIVE (
    SET UTILITYONLY=1

    REM
    REM NOTE: If we are going to build the Eagle Package for Tcl, then the
    REM       Win32 platform binaries for the Eagle Native Utility Library
    REM       will also be built; therefore, skip building it separately in
    REM       that case.
    REM
    IF DEFINED NOPACKAGE (
      SET PLATFORM=Win32

      %__ECHO3% CALL "%TOOLS%\build.bat" "%NATIVE_CONFIGURATION%" %NETFX451_FLAGS% /property:FlightType=%ARGS%

      IF ERRORLEVEL 1 (
        ECHO Building "%NATIVE_CONFIGURATION%%NETFX451_SUFFIX%" native utility binaries for x86 failed.
        GOTO errors
      )
    )

    SET PLATFORM=x64

    %__ECHO3% CALL "%TOOLS%\build.bat" "%NATIVE_CONFIGURATION%" %NETFX451_FLAGS% /property:FlightType=%ARGS%

    IF ERRORLEVEL 1 (
      ECHO Building "%NATIVE_CONFIGURATION%%NETFX451_SUFFIX%" native utility binaries for x64 failed.
      GOTO errors
    )

    SET PLATFORM=ARM

    %__ECHO3% CALL "%TOOLS%\build.bat" "%NATIVE_CONFIGURATION%" %NETFX451_FLAGS% /property:FlightType=%ARGS%

    IF ERRORLEVEL 1 (
      ECHO Building "%NATIVE_CONFIGURATION%%NETFX451_SUFFIX%" native utility binaries for ARM failed.
      GOTO errors
    )

    CALL :fn_UnsetVariable PLATFORM
    CALL :fn_UnsetVariable UTILITYONLY
  )

  %__ECHO3% CALL "%TOOLS%\build.bat" "%NETFX451_BUILD_CONFIGURATION%" %NETFX451_FLAGS% /property:FlightType=%ARGS%

  IF ERRORLEVEL 1 (
    ECHO Building "%NETFX451_BUILD_CONFIGURATION%%NETFX451_SUFFIX%" binaries failed.
    GOTO errors
  )

  REM
  REM NOTE: Unless explicitly disabled, the Eagle Native Package for Tcl
  REM       binaries will be built as part of this build configuration;
  REM       however, they will only be built for the default platform,
  REM       which is typically "Win32".  We need to make sure the other
  REM       platforms get built as well.
  REM
  IF NOT DEFINED NOPACKAGE (
    SET PACKAGEONLY=1
    SET PLATFORM=x64

    %__ECHO3% CALL "%TOOLS%\build.bat" "%NATIVE_CONFIGURATION%" %NETFX451_FLAGS% /property:FlightType=%ARGS%

    IF ERRORLEVEL 1 (
      ECHO Building "%NATIVE_CONFIGURATION%%NETFX451_SUFFIX%" native package binaries for x64 failed.
      GOTO errors
    )

    SET PLATFORM=ARM

    %__ECHO3% CALL "%TOOLS%\build.bat" "%NATIVE_CONFIGURATION%" %NETFX451_FLAGS% /property:FlightType=%ARGS%

    IF ERRORLEVEL 1 (
      ECHO Building "%NATIVE_CONFIGURATION%%NETFX451_SUFFIX%" native package binaries for ARM failed.
      GOTO errors
    )

    CALL :fn_UnsetVariable PLATFORM
    CALL :fn_UnsetVariable PACKAGEONLY
  )

  IF NOT DEFINED ENTERPRISE (
    CALL :fn_UnsetVariable NOENTERPRISE
  )

  IF NOT DEFINED COMMERCIAL (
    CALL :fn_UnsetVariable NOCOMMERCIAL
  )

  IF NOT DEFINED NOFRAMEWORK (
    CALL :fn_UnsetVariable NETFX451ONLY
  )

  CALL :fn_UnsetVariable LOGSUFFIX
)

REM ****************************************************************************
REM *************************** Check NetFx451 Files ***************************
REM ****************************************************************************

IF NOT DEFINED NONETFX451 (
  IF NOT DEFINED NOSTRONGNAME (
    FOR %%I IN (%MANAGEDIMAGEFILES%) DO (
        FOR /F "delims=" %%F IN ('DIR /B /S "%ROOT%\bin\%NETFX451_CONFIGURATION%%NETFX451_SUFFIX%\%%I" 2^> NUL') DO (
        %_AECHO% Checking strong name on file "%%F"...
        %_CECHO% sn.exe -vf "%%F"
        %__ECHO% sn.exe -vf "%%F"

        IF ERRORLEVEL 1 (
          ECHO Checking strong name on file "%%F" failed.
          GOTO errors
        )

        IF NOT DEFINED NOSIGN (
          IF NOT DEFINED NOSIGCHECK (
            %_AECHO% Checking signatures on file "%%F"...
            %_CECHO% SigCheck.exe "%%F" %_CPIPE% FINDSTR "/G:%TOOLS%\data\SigCheck.txt"
            %__ECHO% SigCheck.exe "%%F" %PIPE% FINDSTR "/G:%TOOLS%\data\SigCheck.txt"

            IF ERRORLEVEL 1 (
              ECHO Checking signatures on file "%%F" failed.
              GOTO errors
            )
          )
        )
      )
    )
  )

  IF NOT DEFINED NOSIGN (
    IF NOT DEFINED NOSIGCHECK (
      FOR %%P IN (%PLATFORMS%) DO (
        FOR %%I IN (%NATIVEIMAGEFILES%) DO (
          FOR /F "delims=" %%F IN ('DIR /B /S "%ROOT%\bin\%%P\%NATIVE_CONFIGURATION%%NETFX451_SUFFIX%\%%I" 2^> NUL') DO (
            %_AECHO% Checking signatures on file "%%F"...
            %_CECHO% SigCheck.exe "%%F" %_CPIPE% FINDSTR "/G:%TOOLS%\data\SigCheck.txt"
            %__ECHO% SigCheck.exe "%%F" %PIPE% FINDSTR "/G:%TOOLS%\data\SigCheck.txt"

            IF ERRORLEVEL 1 (
              ECHO Checking signatures on file "%%F" failed.
              GOTO errors
            )
          )
        )
      )
    )
  )
)

REM ****************************************************************************
REM ******************************** Build Bare ********************************
REM ****************************************************************************

IF NOT DEFINED NOBARE (
  SET LOGSUFFIX=%BARE_SUFFIX%
  CALL :fn_ShowVariable LogSuffix LOGSUFFIX

  IF NOT DEFINED NOFRAMEWORK (
    SET NETFX35ONLY=1
  )

  IF NOT DEFINED COMMERCIAL (
    SET NOCOMMERCIAL=1
  )

  IF NOT DEFINED ENTERPRISE (
    SET NOENTERPRISE=1
  )

  IF NOT DEFINED NOBUILDINFO (
    FOR %%T IN (%TAGFILES%) DO (
      FOR /F "delims=" %%F IN ('DIR /B /S "%ROOT%%TAGPATTERN%\%%T" 2^> NUL') DO (
        %__ECHO% ECHO %BARE_SUFFIX% %PIPE% EagleShell.exe -file "%TOOLS%\versionTag.eagle" AssemblyTextMode "%%F"

        IF ERRORLEVEL 1 (
          ECHO Updating "%%F" failed.
          GOTO errors
        )
      )
    )
  )

  %__ECHO3% CALL "%TOOLS%\build.bat" "%BARE_CONFIGURATION%" %BARE_FLAGS% /property:FlightType=%ARGS%

  IF ERRORLEVEL 1 (
    ECHO Building "%BARE_CONFIGURATION%%BARE_SUFFIX%" binaries failed.
    GOTO errors
  )

  IF NOT DEFINED ENTERPRISE (
    CALL :fn_UnsetVariable NOENTERPRISE
  )

  IF NOT DEFINED COMMERCIAL (
    CALL :fn_UnsetVariable NOCOMMERCIAL
  )

  IF NOT DEFINED NOFRAMEWORK (
    CALL :fn_UnsetVariable NETFX35ONLY
  )

  CALL :fn_UnsetVariable LOGSUFFIX
)

REM ****************************************************************************
REM ***************************** Check Bare Files *****************************
REM ****************************************************************************

IF NOT DEFINED NOBARE (
  IF NOT DEFINED NOSTRONGNAME (
    FOR %%I IN (%MANAGEDIMAGEFILES%) DO (
      FOR /F "delims=" %%F IN ('DIR /B /S "%ROOT%\bin\%BARE_CONFIGURATION%%BARE_SUFFIX%\%%I" 2^> NUL') DO (
        %_AECHO% Checking strong name on file "%%F"...
        %_CECHO% sn.exe -vf "%%F"
        %__ECHO% sn.exe -vf "%%F"

        IF ERRORLEVEL 1 (
          ECHO Checking strong name on file "%%F" failed.
          GOTO errors
        )

        IF NOT DEFINED NOSIGN (
          IF NOT DEFINED NOSIGCHECK (
            %_AECHO% Checking signatures on file "%%F"...
            %_CECHO% SigCheck.exe "%%F" %_CPIPE% FINDSTR "/G:%TOOLS%\data\SigCheck.txt"
            %__ECHO% SigCheck.exe "%%F" %PIPE% FINDSTR "/G:%TOOLS%\data\SigCheck.txt"

            IF ERRORLEVEL 1 (
              ECHO Checking signatures on file "%%F" failed.
              GOTO errors
            )
          )
        )
      )
    )
  )

  IF NOT DEFINED NOSIGN (
    IF NOT DEFINED NOSIGCHECK (
      FOR %%P IN (%PLATFORMS%) DO (
        FOR %%I IN (%NATIVEIMAGEFILES%) DO (
          FOR /F "delims=" %%F IN ('DIR /B /S "%ROOT%\bin\%%P\%NATIVE_CONFIGURATION%%BARE_SUFFIX%\%%I" 2^> NUL') DO (
            %_AECHO% Checking signatures on file "%%F"...
            %_CECHO% SigCheck.exe "%%F" %_CPIPE% FINDSTR "/G:%TOOLS%\data\SigCheck.txt"
            %__ECHO% SigCheck.exe "%%F" %PIPE% FINDSTR "/G:%TOOLS%\data\SigCheck.txt"

            IF ERRORLEVEL 1 (
              ECHO Checking signatures on file "%%F" failed.
              GOTO errors
            )
          )
        )
      )
    )
  )
)

REM ****************************************************************************
REM **************************** Build LeanAndMean *****************************
REM ****************************************************************************

IF NOT DEFINED NOLEAN (
  SET LOGSUFFIX=%LEAN_SUFFIX%
  CALL :fn_ShowVariable LogSuffix LOGSUFFIX

  IF NOT DEFINED NOFRAMEWORK (
    SET NETFX35ONLY=1
  )

  IF NOT DEFINED COMMERCIAL (
    SET NOCOMMERCIAL=1
  )

  IF NOT DEFINED ENTERPRISE (
    SET NOENTERPRISE=1
  )

  IF NOT DEFINED NOBUILDINFO (
    FOR %%T IN (%TAGFILES%) DO (
      FOR /F "delims=" %%F IN ('DIR /B /S "%ROOT%%TAGPATTERN%\%%T" 2^> NUL') DO (
        %__ECHO% ECHO %LEAN_SUFFIX% %PIPE% EagleShell.exe -file "%TOOLS%\versionTag.eagle" AssemblyTextMode "%%F"

        IF ERRORLEVEL 1 (
          ECHO Updating "%%F" failed.
          GOTO errors
        )
      )
    )
  )

  IF NOT DEFINED NONATIVE (
    SET EagleConfigurationSuffix=%LEAN_SUFFIX%
    SET UTILITYONLY=1
    SET PLATFORM=Win32

    %__ECHO3% CALL "%TOOLS%\build.bat" "%NATIVE_CONFIGURATION%" %LEAN_FLAGS% /property:FlightType=%ARGS%

    IF ERRORLEVEL 1 (
      ECHO Building "%NATIVE_CONFIGURATION%%LEAN_SUFFIX%" native utility binaries for x86 failed.
      GOTO errors
    )

    SET PLATFORM=x64

    %__ECHO3% CALL "%TOOLS%\build.bat" "%NATIVE_CONFIGURATION%" %LEAN_FLAGS% /property:FlightType=%ARGS%

    IF ERRORLEVEL 1 (
      ECHO Building "%NATIVE_CONFIGURATION%%LEAN_SUFFIX%" native utility binaries for x64 failed.
      GOTO errors
    )

    CALL :fn_UnsetVariable PLATFORM
    CALL :fn_UnsetVariable UTILITYONLY
    CALL :fn_UnsetVariable EagleConfigurationSuffix
  )

  %__ECHO3% CALL "%TOOLS%\build.bat" "%LEAN_CONFIGURATION%" %LEAN_FLAGS% /property:FlightType=%ARGS%

  IF ERRORLEVEL 1 (
    ECHO Building "%LEAN_CONFIGURATION%%LEAN_SUFFIX%" binaries failed.
    GOTO errors
  )

  IF NOT DEFINED ENTERPRISE (
    CALL :fn_UnsetVariable NOENTERPRISE
  )

  IF NOT DEFINED COMMERCIAL (
    CALL :fn_UnsetVariable NOCOMMERCIAL
  )

  IF NOT DEFINED NOFRAMEWORK (
    CALL :fn_UnsetVariable NETFX35ONLY
  )

  CALL :fn_UnsetVariable LOGSUFFIX
)

REM ****************************************************************************
REM ***************************** Check Lean Files *****************************
REM ****************************************************************************

IF NOT DEFINED NOLEAN (
  IF NOT DEFINED NOSTRONGNAME (
    FOR %%I IN (%MANAGEDIMAGEFILES%) DO (
      FOR /F "delims=" %%F IN ('DIR /B /S "%ROOT%\bin\%LEAN_CONFIGURATION%%LEAN_SUFFIX%\%%I" 2^> NUL') DO (
        %_AECHO% Checking strong name on file "%%F"...
        %_CECHO% sn.exe -vf "%%F"
        %__ECHO% sn.exe -vf "%%F"

        IF ERRORLEVEL 1 (
          ECHO Checking strong name on file "%%F" failed.
          GOTO errors
        )

        IF NOT DEFINED NOSIGN (
          IF NOT DEFINED NOSIGCHECK (
            %_AECHO% Checking signatures on file "%%F"...
            %_CECHO% SigCheck.exe "%%F" %_CPIPE% FINDSTR "/G:%TOOLS%\data\SigCheck.txt"
            %__ECHO% SigCheck.exe "%%F" %PIPE% FINDSTR "/G:%TOOLS%\data\SigCheck.txt"

            IF ERRORLEVEL 1 (
              ECHO Checking signatures on file "%%F" failed.
              GOTO errors
            )
          )
        )
      )
    )
  )

  IF NOT DEFINED NOSIGN (
    IF NOT DEFINED NOSIGCHECK (
      FOR %%P IN (%PLATFORMS%) DO (
        FOR %%I IN (%NATIVEIMAGEFILES%) DO (
          FOR /F "delims=" %%F IN ('DIR /B /S "%ROOT%\bin\%%P\%NATIVE_CONFIGURATION%%LEAN_SUFFIX%\%%I" 2^> NUL') DO (
            %_AECHO% Checking signatures on file "%%F"...
            %_CECHO% SigCheck.exe "%%F" %_CPIPE% FINDSTR "/G:%TOOLS%\data\SigCheck.txt"
            %__ECHO% SigCheck.exe "%%F" %PIPE% FINDSTR "/G:%TOOLS%\data\SigCheck.txt"

            IF ERRORLEVEL 1 (
              ECHO Checking signatures on file "%%F" failed.
              GOTO errors
            )
          )
        )
      )
    )
  )
)

REM ****************************************************************************
REM ****************************** Build Database ******************************
REM ****************************************************************************

IF NOT DEFINED NODATABASE (
  SET LOGSUFFIX=%DATABASE_SUFFIX%
  CALL :fn_ShowVariable LogSuffix LOGSUFFIX

  IF NOT DEFINED NOFRAMEWORK (
    SET NETFX35ONLY=1
  )

  IF NOT DEFINED COMMERCIAL (
    SET NOCOMMERCIAL=1
  )

  IF NOT DEFINED ENTERPRISE (
    SET NOENTERPRISE=1
  )

  IF NOT DEFINED NOBUILDINFO (
    FOR %%T IN (%TAGFILES%) DO (
      FOR /F "delims=" %%F IN ('DIR /B /S "%ROOT%%TAGPATTERN%\%%T" 2^> NUL') DO (
        %__ECHO% ECHO %DATABASE_SUFFIX% %PIPE% EagleShell.exe -file "%TOOLS%\versionTag.eagle" AssemblyTextMode "%%F"

        IF ERRORLEVEL 1 (
          ECHO Updating "%%F" failed.
          GOTO errors
        )
      )
    )
  )

  %__ECHO3% CALL "%TOOLS%\build.bat" "%DATABASE_CONFIGURATION%" %DATABASE_FLAGS% /property:FlightType=%ARGS%

  IF ERRORLEVEL 1 (
    ECHO Building "%DATABASE_CONFIGURATION%%DATABASE_SUFFIX%" binaries failed.
    GOTO errors
  )

  IF NOT DEFINED ENTERPRISE (
    CALL :fn_UnsetVariable NOENTERPRISE
  )

  IF NOT DEFINED COMMERCIAL (
    CALL :fn_UnsetVariable NOCOMMERCIAL
  )

  IF NOT DEFINED NOFRAMEWORK (
    CALL :fn_UnsetVariable NETFX35ONLY
  )

  CALL :fn_UnsetVariable LOGSUFFIX
)

REM ****************************************************************************
REM *************************** Check Database Files ***************************
REM ****************************************************************************

IF NOT DEFINED NODATABASE (
  IF NOT DEFINED NOSTRONGNAME (
    FOR %%I IN (%MANAGEDIMAGEFILES%) DO (
      FOR /F "delims=" %%F IN ('DIR /B /S "%ROOT%\bin\%DATABASE_CONFIGURATION%%DATABASE_SUFFIX%\%%I" 2^> NUL') DO (
        %_AECHO% Checking strong name on file "%%F"...
        %_CECHO% sn.exe -vf "%%F"
        %__ECHO% sn.exe -vf "%%F"

        IF ERRORLEVEL 1 (
          ECHO Checking strong name on file "%%F" failed.
          GOTO errors
        )

        IF NOT DEFINED NOSIGN (
          IF NOT DEFINED NOSIGCHECK (
            %_AECHO% Checking signatures on file "%%F"...
            %_CECHO% SigCheck.exe "%%F" %_CPIPE% FINDSTR "/G:%TOOLS%\data\SigCheck.txt"
            %__ECHO% SigCheck.exe "%%F" %PIPE% FINDSTR "/G:%TOOLS%\data\SigCheck.txt"

            IF ERRORLEVEL 1 (
              ECHO Checking signatures on file "%%F" failed.
              GOTO errors
            )
          )
        )
      )
    )
  )

  IF NOT DEFINED NOSIGN (
    IF NOT DEFINED NOSIGCHECK (
      FOR %%P IN (%PLATFORMS%) DO (
        FOR %%I IN (%NATIVEIMAGEFILES%) DO (
          FOR /F "delims=" %%F IN ('DIR /B /S "%ROOT%\bin\%%P\%NATIVE_CONFIGURATION%%DATABASE_SUFFIX%\%%I" 2^> NUL') DO (
            %_AECHO% Checking signatures on file "%%F"...
            %_CECHO% SigCheck.exe "%%F" %_CPIPE% FINDSTR "/G:%TOOLS%\data\SigCheck.txt"
            %__ECHO% SigCheck.exe "%%F" %PIPE% FINDSTR "/G:%TOOLS%\data\SigCheck.txt"

            IF ERRORLEVEL 1 (
              ECHO Checking signatures on file "%%F" failed.
              GOTO errors
            )
          )
        )
      )
    )
  )
)

REM ****************************************************************************
REM ***************************** Build MonoOnUnix *****************************
REM ****************************************************************************

IF NOT DEFINED NOUNIX (
  SET LOGSUFFIX=%UNIX_SUFFIX%
  CALL :fn_ShowVariable LogSuffix LOGSUFFIX

  IF NOT DEFINED NOFRAMEWORK (
    SET NETFX35ONLY=1
  )

  IF NOT DEFINED COMMERCIAL (
    SET NOCOMMERCIAL=1
  )

  IF NOT DEFINED ENTERPRISE (
    SET NOENTERPRISE=1
  )

  IF NOT DEFINED NOBUILDINFO (
    FOR %%T IN (%TAGFILES%) DO (
      FOR /F "delims=" %%F IN ('DIR /B /S "%ROOT%%TAGPATTERN%\%%T" 2^> NUL') DO (
        %__ECHO% ECHO %UNIX_SUFFIX% %PIPE% EagleShell.exe -file "%TOOLS%\versionTag.eagle" AssemblyTextMode "%%F"

        IF ERRORLEVEL 1 (
          ECHO Updating "%%F" failed.
          GOTO errors
        )
      )
    )
  )

  %__ECHO3% CALL "%TOOLS%\build.bat" "%UNIX_CONFIGURATION%" %UNIX_FLAGS% /property:FlightType=%ARGS%

  IF ERRORLEVEL 1 (
    ECHO Building "%UNIX_CONFIGURATION%%UNIX_SUFFIX%" binaries failed.
    GOTO errors
  )

  IF NOT DEFINED ENTERPRISE (
    CALL :fn_UnsetVariable NOENTERPRISE
  )

  IF NOT DEFINED COMMERCIAL (
    CALL :fn_UnsetVariable NOCOMMERCIAL
  )

  IF NOT DEFINED NOFRAMEWORK (
    CALL :fn_UnsetVariable NETFX35ONLY
  )

  CALL :fn_UnsetVariable LOGSUFFIX
)

IF DEFINED BUILDONLY (
  %_AECHO% Build phase complete in build-only mode, exiting...
  GOTO no_errors
)

REM ****************************************************************************
REM ************************** Check MonoOnUnix Files **************************
REM ****************************************************************************

IF NOT DEFINED NOUNIX (
  IF NOT DEFINED NOSTRONGNAME (
    FOR %%I IN (%MANAGEDIMAGEFILES%) DO (
      FOR /F "delims=" %%F IN ('DIR /B /S "%ROOT%\bin\%UNIX_CONFIGURATION%%UNIX_SUFFIX%\%%I" 2^> NUL') DO (
        %_AECHO% Checking strong name on file "%%F"...
        %_CECHO% sn.exe -vf "%%F"
        %__ECHO% sn.exe -vf "%%F"

        IF ERRORLEVEL 1 (
          ECHO Checking strong name on file "%%F" failed.
          GOTO errors
        )

        IF NOT DEFINED NOSIGN (
          IF NOT DEFINED NOSIGCHECK (
            %_AECHO% Checking signatures on file "%%F"...
            %_CECHO% SigCheck.exe "%%F" %_CPIPE% FINDSTR "/G:%TOOLS%\data\SigCheck.txt"
            %__ECHO% SigCheck.exe "%%F" %PIPE% FINDSTR "/G:%TOOLS%\data\SigCheck.txt"

            IF ERRORLEVEL 1 (
              ECHO Checking signatures on file "%%F" failed.
              GOTO errors
            )
          )
        )
      )
    )
  )

  IF NOT DEFINED NOSIGN (
    IF NOT DEFINED NOSIGCHECK (
      FOR %%P IN (%PLATFORMS%) DO (
        FOR %%I IN (%NATIVEIMAGEFILES%) DO (
          FOR /F "delims=" %%F IN ('DIR /B /S "%ROOT%\bin\%%P\%NATIVE_CONFIGURATION%%UNIX_SUFFIX%\%%I" 2^> NUL') DO (
            %_AECHO% Checking signatures on file "%%F"...
            %_CECHO% SigCheck.exe "%%F" %_CPIPE% FINDSTR "/G:%TOOLS%\data\SigCheck.txt"
            %__ECHO% SigCheck.exe "%%F" %PIPE% FINDSTR "/G:%TOOLS%\data\SigCheck.txt"

            IF ERRORLEVEL 1 (
              ECHO Checking signatures on file "%%F" failed.
              GOTO errors
            )
          )
        )
      )
    )
  )
)

:skip_build

REM ****************************************************************************
REM ************************** Create Setup Packages ***************************
REM ****************************************************************************

IF NOT DEFINED NOBAKE (
  SET SKIP_SIGN_UNINSTALLER=1

  IF NOT DEFINED NONETFX20 (
    CALL :fn_UnsetVariable SUFFIX
    CALL :fn_ShowVariable Suffix SUFFIX

    REM
    REM HACK: We know that the native components in the .NET Framework 2.0
    REM       setup package require the Visual C++ 2008 Runtime and we also
    REM       know that it is the default runtime used by the setup package
    REM       baking tool.
    REM
    %__ECHO3% CALL "%TOOLS%\bake.bat" "%NETFX20_CONFIGURATION%%NETFX20_SUFFIX%"

    IF ERRORLEVEL 1 (
      ECHO Baking "%NETFX20_CONFIGURATION%%NETFX20_SUFFIX%" setup failed.
      GOTO errors
    )

    REM CALL :fn_UnsetVariable SUFFIX
  )

  IF NOT DEFINED NONETFX40 (
    SET SUFFIX=%NETFX40_SUFFIX%_
    CALL :fn_ShowVariable Suffix SUFFIX

    REM
    REM HACK: We know that the native components in the .NET Framework 4.0
    REM       setup package require the Visual C++ 2010 Runtime and we also
    REM       know that it must be set explicitly.
    REM
    SET VCRUNTIME=2010_SP1_MFC

    %__ECHO3% CALL "%TOOLS%\bake.bat" "%NETFX40_CONFIGURATION%%NETFX40_SUFFIX%"

    IF ERRORLEVEL 1 (
      ECHO Baking "%NETFX40_CONFIGURATION%%NETFX40_SUFFIX%" setup failed.
      GOTO errors
    )

    CALL :fn_UnsetVariable VCRUNTIME
    CALL :fn_UnsetVariable SUFFIX
  )

  IF NOT DEFINED NONETFX45 (
    SET SUFFIX=%NETFX45_SUFFIX%_
    CALL :fn_ShowVariable Suffix SUFFIX

    REM
    REM HACK: We know that the native components in the .NET Framework 4.5
    REM       setup package require the Visual C++ 2012 Runtime and we also
    REM       know that it must be set explicitly.
    REM
    SET VCRUNTIME=2012_VSU3

    REM
    REM HACK: We know that the native components for the .NET Framework 4.5
    REM       setup package should include the ARM binaries.
    REM
    SET INCLUDEARM=1

    %__ECHO3% CALL "%TOOLS%\bake.bat" "%NETFX45_CONFIGURATION%%NETFX45_SUFFIX%"

    IF ERRORLEVEL 1 (
      ECHO Baking "%NETFX45_CONFIGURATION%%NETFX45_SUFFIX%" setup failed.
      GOTO errors
    )

    CALL :fn_UnsetVariable INCLUDEARM
    CALL :fn_UnsetVariable VCRUNTIME
    CALL :fn_UnsetVariable SUFFIX
  )

  IF NOT DEFINED NONETFX451 (
    SET SUFFIX=%NETFX451_SUFFIX%_
    CALL :fn_ShowVariable Suffix SUFFIX

    REM
    REM HACK: We know that the native components in the .NET Framework 4.5.1
    REM       setup package require the Visual C++ 2013 Runtime and we also
    REM       know that it must be set explicitly.
    REM
    SET VCRUNTIME=2013_RTM

    REM
    REM HACK: We know that the native components for the .NET Framework 4.5.1
    REM       setup package should include the ARM binaries.
    REM
    SET INCLUDEARM=1

    %__ECHO3% CALL "%TOOLS%\bake.bat" "%NETFX451_CONFIGURATION%%NETFX451_SUFFIX%"

    IF ERRORLEVEL 1 (
      ECHO Baking "%NETFX451_CONFIGURATION%%NETFX451_SUFFIX%" setup failed.
      GOTO errors
    )

    CALL :fn_UnsetVariable INCLUDEARM
    CALL :fn_UnsetVariable VCRUNTIME
    CALL :fn_UnsetVariable SUFFIX
  )

  IF NOT DEFINED NOPACKAGE (
    SET SUFFIX=%NETFX40_SUFFIX%_
    CALL :fn_ShowVariable Suffix SUFFIX

    REM
    REM HACK: We know that the native components in the Eagle Package for Tcl
    REM       setup package require the Visual C++ 2010 Runtime and we also
    REM       know that it is the default runtime used by the native setup
    REM       package baking tool.
    REM
    %__ECHO3% CALL "%PACKAGE_TOOLS%\bake.bat" "%PACKAGE_PLATFORM%" "%NATIVE_CONFIGURATION%%NETFX40_SUFFIX%"

    IF ERRORLEVEL 1 (
      ECHO Baking "%PACKAGE_PLATFORM%\%NATIVE_CONFIGURATION%%NETFX40_SUFFIX%" setup failed.
      GOTO errors
    )

    CALL :fn_UnsetVariable SUFFIX
  )

  CALL :fn_UnsetVariable SKIP_SIGN_UNINSTALLER
)

REM ****************************************************************************
REM ********************* Tag ChangeLog/Update/NuGet Files *********************
REM ****************************************************************************

IF NOT DEFINED NOTAG (
  IF EXIST "%TOOLS%\..\..\ChangeLog" (
    %__ECHO% EagleShell.exe -file "%TOOLS%\versionTag.eagle" ChangeLogMode "%TOOLS%\..\..\ChangeLog"

    IF ERRORLEVEL 1 (
      ECHO Updating "%TOOLS%\..\..\ChangeLog" failed.
      GOTO errors
    )
  )

  IF EXIST "%TOOLS%\..\..\web\update.txt" (
    %__ECHO% EagleShell.exe -file "%TOOLS%\versionTag.eagle" UpdateMode "%TOOLS%\..\..\web\update.txt"

    IF ERRORLEVEL 1 (
      ECHO Updating "%TOOLS%\..\..\web\update.txt" failed.
      GOTO errors
    )
  )

  IF EXIST "%TOOLS%\..\..\NuGet\Eagle.nuspec" (
    %__ECHO% EagleShell.exe -file "%TOOLS%\versionTag.eagle" NuSpecMode "%TOOLS%\..\..\NuGet\Eagle.nuspec"

    IF ERRORLEVEL 1 (
      ECHO Updating "%TOOLS%\..\..\NuGet\Eagle.nuspec" failed.
      GOTO errors
    )
  )

  IF EXIST "%TOOLS%\..\..\NuGet\Eagle.Beta.nuspec" (
    %__ECHO% EagleShell.exe -file "%TOOLS%\versionTag.eagle" NuSpecMode "%TOOLS%\..\..\NuGet\Eagle.Beta.nuspec"

    IF ERRORLEVEL 1 (
      ECHO Updating "%TOOLS%\..\..\NuGet\Eagle.Beta.nuspec" failed.
      GOTO errors
    )
  )

  IF EXIST "%TOOLS%\..\..\NuGet\Eagle.Test.nuspec" (
    %__ECHO% EagleShell.exe -file "%TOOLS%\versionTag.eagle" NuSpecMode "%TOOLS%\..\..\NuGet\Eagle.Test.nuspec"

    IF ERRORLEVEL 1 (
      ECHO Updating "%TOOLS%\..\..\NuGet\Eagle.Test.nuspec" failed.
      GOTO errors
    )
  )

  IF EXIST "%TOOLS%\..\..\NuGet\Eagle.src.nuspec" (
    %__ECHO% EagleShell.exe -file "%TOOLS%\versionTag.eagle" NuSpecMode "%TOOLS%\..\..\NuGet\Eagle.src.nuspec"

    IF ERRORLEVEL 1 (
      ECHO Updating "%TOOLS%\..\..\NuGet\Eagle.src.nuspec" failed.
      GOTO errors
    )
  )
)

REM ****************************************************************************
REM ************************** Query Eagle PatchLevel **************************
REM ****************************************************************************

IF DEFINED NONETFX20 GOTO skip_patchLevel2

SET GET_PATCHLEVEL_CMD=EagleShell.exe -eval "puts stdout [info engine PatchLevel]"

IF NOT DEFINED PATCHLEVEL (
  IF DEFINED __ECHO (
    %__ECHO% %GET_PATCHLEVEL_CMD%
    SET PATCHLEVEL=1.0.X.X
  ) ELSE (
    FOR /F %%T IN ('%GET_PATCHLEVEL_CMD%') DO (SET PATCHLEVEL=%%T)
  )
)

:skip_patchLevel2

IF NOT DEFINED PATCHLEVEL (
  ECHO The PATCHLEVEL environment variable could not be set.
  GOTO errors
)

%_VECHO% PatchLevel = '%PATCHLEVEL%'

REM ****************************************************************************
REM ************************* Query Garuda PatchLevel **************************
REM ****************************************************************************

SET GET_PACKAGE_PATCHLEVEL_CMD=EagleShell.exe -eval "puts stdout [file version {%ROOT%\bin\%PACKAGE_PLATFORM%\%NATIVE_CONFIGURATION%%NETFX40_SUFFIX%\Garuda.dll}]"

IF NOT DEFINED PACKAGE_PATCHLEVEL (
  IF DEFINED __ECHO (
    %__ECHO% %GET_PACKAGE_PATCHLEVEL_CMD%
    SET PACKAGE_PATCHLEVEL=1.0.X.X
  ) ELSE (
    FOR /F %%T IN ('%GET_PACKAGE_PATCHLEVEL_CMD%') DO (SET PACKAGE_PATCHLEVEL=%%T)
  )
)

IF NOT DEFINED PACKAGE_PATCHLEVEL (
  ECHO The PACKAGE_PATCHLEVEL environment variable could not be set.
  GOTO errors
)

%_VECHO% PackagePatchLevel = '%PACKAGE_PATCHLEVEL%'

REM ****************************************************************************
REM ************************** Create Source Packages **************************
REM ****************************************************************************

IF NOT DEFINED NOARCHIVE (
  IF NOT DEFINED NOSOURCE (
    %__ECHO3% CALL "%TOOLS%\archive.bat"

    IF ERRORLEVEL 1 (
      ECHO Creating source archives failed.
      GOTO errors
    )
  )

  IF NOT DEFINED NOSOURCEONLY (
    SET NOTOOL=1

    %__ECHO3% CALL "%TOOLS%\archive.bat"

    IF ERRORLEVEL 1 (
      ECHO Creating source-only archives failed.
      GOTO errors
    )

    CALL :fn_UnsetVariable NOTOOL
  )
)

REM ****************************************************************************
REM ************************** Create Binary Packages **************************
REM ****************************************************************************

IF NOT DEFINED NORELEASE (
  IF NOT DEFINED NONETFX20 (
    CALL :fn_UnsetVariable SUFFIX
    CALL :fn_ShowVariable Suffix SUFFIX

    IF NOT DEFINED NOBINARY (
      %__ECHO3% CALL "%TOOLS%\release.bat" "%NETFX20_CONFIGURATION%%NETFX20_SUFFIX%"

      IF ERRORLEVEL 1 (
        ECHO Creating "%NETFX20_CONFIGURATION%%NETFX20_SUFFIX%" binaries archive failed.
        GOTO errors
      )
    )

    IF NOT DEFINED NORUNTIME (
      %__ECHO3% CALL "%TOOLS%\release.bat" "%NETFX20_CONFIGURATION%%NETFX20_SUFFIX%" Runtime data\exclude_runtime.txt

      IF ERRORLEVEL 1 (
        ECHO Creating "%NETFX20_CONFIGURATION%%NETFX20_SUFFIX%" runtime binaries archive failed.
        GOTO errors
      )
    )

    IF NOT DEFINED NOCORE (
      %__ECHO3% CALL "%TOOLS%\release.bat" "%NETFX20_CONFIGURATION%%NETFX20_SUFFIX%" Core data\exclude_core.txt

      IF ERRORLEVEL 1 (
        ECHO Creating "%NETFX20_CONFIGURATION%%NETFX20_SUFFIX%" core binaries archive failed.
        GOTO errors
      )
    )

    REM CALL :fn_UnsetVariable SUFFIX
  )

  IF NOT DEFINED NONETFX40 (
    SET SUFFIX=%NETFX40_SUFFIX%_
    CALL :fn_ShowVariable Suffix SUFFIX

    IF NOT DEFINED NOBINARY (
      %__ECHO3% CALL "%TOOLS%\release.bat" "%NETFX40_CONFIGURATION%%NETFX40_SUFFIX%"

      IF ERRORLEVEL 1 (
        ECHO Creating "%NETFX40_CONFIGURATION%%NETFX40_SUFFIX%" binaries archive failed.
        GOTO errors
      )
    )

    IF NOT DEFINED NORUNTIME (
      %__ECHO3% CALL "%TOOLS%\release.bat" "%NETFX40_CONFIGURATION%%NETFX40_SUFFIX%" Runtime data\exclude_runtime.txt

      IF ERRORLEVEL 1 (
        ECHO Creating "%NETFX40_CONFIGURATION%%NETFX40_SUFFIX%" runtime binaries archive failed.
        GOTO errors
      )
    )

    IF NOT DEFINED NOCORE (
      %__ECHO3% CALL "%TOOLS%\release.bat" "%NETFX40_CONFIGURATION%%NETFX40_SUFFIX%" Core data\exclude_core.txt

      IF ERRORLEVEL 1 (
        ECHO Creating "%NETFX40_CONFIGURATION%%NETFX40_SUFFIX%" core binaries archive failed.
        GOTO errors
      )
    )

    CALL :fn_UnsetVariable SUFFIX
  )

  IF NOT DEFINED NONETFX45 (
    SET SUFFIX=%NETFX45_SUFFIX%_
    CALL :fn_ShowVariable Suffix SUFFIX

    IF NOT DEFINED NOBINARY (
      %__ECHO3% CALL "%TOOLS%\release.bat" "%NETFX45_CONFIGURATION%%NETFX45_SUFFIX%"

      IF ERRORLEVEL 1 (
        ECHO Creating "%NETFX45_CONFIGURATION%%NETFX45_SUFFIX%" binaries archive failed.
        GOTO errors
      )
    )

    IF NOT DEFINED NORUNTIME (
      %__ECHO3% CALL "%TOOLS%\release.bat" "%NETFX45_CONFIGURATION%%NETFX45_SUFFIX%" Runtime data\exclude_runtime.txt

      IF ERRORLEVEL 1 (
        ECHO Creating "%NETFX45_CONFIGURATION%%NETFX45_SUFFIX%" runtime binaries archive failed.
        GOTO errors
      )
    )

    IF NOT DEFINED NOCORE (
      %__ECHO3% CALL "%TOOLS%\release.bat" "%NETFX45_CONFIGURATION%%NETFX45_SUFFIX%" Core data\exclude_core.txt

      IF ERRORLEVEL 1 (
        ECHO Creating "%NETFX45_CONFIGURATION%%NETFX45_SUFFIX%" core binaries archive failed.
        GOTO errors
      )
    )

    CALL :fn_UnsetVariable SUFFIX
  )

  IF NOT DEFINED NONETFX451 (
    SET SUFFIX=%NETFX451_SUFFIX%_
    CALL :fn_ShowVariable Suffix SUFFIX

    IF NOT DEFINED NOBINARY (
      %__ECHO3% CALL "%TOOLS%\release.bat" "%NETFX451_CONFIGURATION%%NETFX451_SUFFIX%"

      IF ERRORLEVEL 1 (
        ECHO Creating "%NETFX451_CONFIGURATION%%NETFX451_SUFFIX%" binaries archive failed.
        GOTO errors
      )
    )

    IF NOT DEFINED NORUNTIME (
      %__ECHO3% CALL "%TOOLS%\release.bat" "%NETFX451_CONFIGURATION%%NETFX451_SUFFIX%" Runtime data\exclude_runtime.txt

      IF ERRORLEVEL 1 (
        ECHO Creating "%NETFX451_CONFIGURATION%%NETFX451_SUFFIX%" runtime binaries archive failed.
        GOTO errors
      )
    )

    IF NOT DEFINED NOCORE (
      %__ECHO3% CALL "%TOOLS%\release.bat" "%NETFX451_CONFIGURATION%%NETFX451_SUFFIX%" Core data\exclude_core.txt

      IF ERRORLEVEL 1 (
        ECHO Creating "%NETFX451_CONFIGURATION%%NETFX451_SUFFIX%" core binaries archive failed.
        GOTO errors
      )
    )

    CALL :fn_UnsetVariable SUFFIX
  )

  IF NOT DEFINED NOBARE (
    SET SUFFIX=%BARE_SUFFIX%
    CALL :fn_ShowVariable Suffix SUFFIX

    IF NOT DEFINED NOBINARY (
      %__ECHO3% CALL "%TOOLS%\release.bat" "%BARE_CONFIGURATION%%BARE_SUFFIX%"

      IF ERRORLEVEL 1 (
        ECHO Creating "%BARE_CONFIGURATION%%BARE_SUFFIX%" binaries archive failed.
        GOTO errors
      )
    )

    IF NOT DEFINED NORUNTIME (
      %__ECHO3% CALL "%TOOLS%\release.bat" "%BARE_CONFIGURATION%%BARE_SUFFIX%" Runtime data\exclude_runtime.txt

      IF ERRORLEVEL 1 (
        ECHO Creating "%BARE_CONFIGURATION%%BARE_SUFFIX%" runtime binaries archive failed.
        GOTO errors
      )
    )

    IF NOT DEFINED NOCORE (
      %__ECHO3% CALL "%TOOLS%\release.bat" "%BARE_CONFIGURATION%%BARE_SUFFIX%" Core data\exclude_core.txt

      IF ERRORLEVEL 1 (
        ECHO Creating "%BARE_CONFIGURATION%%BARE_SUFFIX%" core binaries archive failed.
        GOTO errors
      )
    )

    CALL :fn_UnsetVariable SUFFIX
  )

  SET NOLIB=1

  IF NOT DEFINED NOLEAN (
    SET SUFFIX=%LEAN_SUFFIX%
    CALL :fn_ShowVariable Suffix SUFFIX

    IF NOT DEFINED NOBINARY (
      %__ECHO3% CALL "%TOOLS%\release.bat" "%LEAN_CONFIGURATION%%LEAN_SUFFIX%"

      IF ERRORLEVEL 1 (
        ECHO Creating "%LEAN_CONFIGURATION%%LEAN_SUFFIX%" binaries archive failed.
        GOTO errors
      )
    )

    IF NOT DEFINED NORUNTIME (
      %__ECHO3% CALL "%TOOLS%\release.bat" "%LEAN_CONFIGURATION%%LEAN_SUFFIX%" Runtime data\exclude_runtime.txt

      IF ERRORLEVEL 1 (
        ECHO Creating "%LEAN_CONFIGURATION%%LEAN_SUFFIX%" runtime binaries archive failed.
        GOTO errors
      )
    )

    IF NOT DEFINED NOCORE (
      %__ECHO3% CALL "%TOOLS%\release.bat" "%LEAN_CONFIGURATION%%LEAN_SUFFIX%" Core data\exclude_core.txt

      IF ERRORLEVEL 1 (
        ECHO Creating "%LEAN_CONFIGURATION%%LEAN_SUFFIX%" core binaries archive failed.
        GOTO errors
      )
    )

    CALL :fn_UnsetVariable SUFFIX
  )

  IF NOT DEFINED NODATABASE (
    SET SUFFIX=%DATABASE_SUFFIX%
    CALL :fn_ShowVariable Suffix SUFFIX

    IF NOT DEFINED NOBINARY (
      %__ECHO3% CALL "%TOOLS%\release.bat" "%DATABASE_CONFIGURATION%%DATABASE_SUFFIX%"

      IF ERRORLEVEL 1 (
        ECHO Creating "%DATABASE_CONFIGURATION%%DATABASE_SUFFIX%" binaries archive failed.
        GOTO errors
      )
    )

    IF NOT DEFINED NORUNTIME (
      %__ECHO3% CALL "%TOOLS%\release.bat" "%DATABASE_CONFIGURATION%%DATABASE_SUFFIX%" Runtime data\exclude_runtime.txt

      IF ERRORLEVEL 1 (
        ECHO Creating "%DATABASE_CONFIGURATION%%DATABASE_SUFFIX%" runtime binaries archive failed.
        GOTO errors
      )
    )

    IF NOT DEFINED NOCORE (
      %__ECHO3% CALL "%TOOLS%\release.bat" "%DATABASE_CONFIGURATION%%DATABASE_SUFFIX%" Core data\exclude_core.txt

      IF ERRORLEVEL 1 (
        ECHO Creating "%DATABASE_CONFIGURATION%%DATABASE_SUFFIX%" core binaries archive failed.
        GOTO errors
      )
    )

    CALL :fn_UnsetVariable SUFFIX
  )

  CALL :fn_UnsetVariable NOLIB

  IF NOT DEFINED NOUNIX (
    SET SUFFIX=%UNIX_SUFFIX%
    CALL :fn_ShowVariable Suffix SUFFIX

    IF NOT DEFINED NOBINARY (
      %__ECHO3% CALL "%TOOLS%\release.bat" "%UNIX_CONFIGURATION%%UNIX_SUFFIX%"

      IF ERRORLEVEL 1 (
        ECHO Creating "%UNIX_CONFIGURATION%%UNIX_SUFFIX%" binaries archive failed.
        GOTO errors
      )
    )

    IF NOT DEFINED NORUNTIME (
      %__ECHO3% CALL "%TOOLS%\release.bat" "%UNIX_CONFIGURATION%%UNIX_SUFFIX%" Runtime data\exclude_runtime.txt

      IF ERRORLEVEL 1 (
        ECHO Creating "%UNIX_CONFIGURATION%%UNIX_SUFFIX%" runtime binaries archive failed.
        GOTO errors
      )
    )

    IF NOT DEFINED NOCORE (
      %__ECHO3% CALL "%TOOLS%\release.bat" "%UNIX_CONFIGURATION%%UNIX_SUFFIX%" Core data\exclude_core.txt

      IF ERRORLEVEL 1 (
        ECHO Creating "%UNIX_CONFIGURATION%%UNIX_SUFFIX%" core binaries archive failed.
        GOTO errors
      )
    )

    CALL :fn_UnsetVariable SUFFIX
  )

  IF NOT DEFINED NOPACKAGE (
    IF NOT DEFINED NONETFX40 (
      SET SUFFIX=%NETFX40_SUFFIX%_
      CALL :fn_ShowVariable Suffix SUFFIX

      IF NOT DEFINED NOBINARY (
        %__ECHO3% CALL "%PACKAGE_TOOLS%\release.bat" "%PACKAGE_PLATFORM%" "%NATIVE_CONFIGURATION%%NETFX40_SUFFIX%"

        IF ERRORLEVEL 1 (
          ECHO Creating "%PACKAGE_PLATFORM%\%NATIVE_CONFIGURATION%%NETFX40_SUFFIX%" binaries archive failed.
          GOTO errors
        )
      )

      IF NOT DEFINED NORUNTIME (
        %__ECHO3% CALL "%PACKAGE_TOOLS%\release.bat" "%PACKAGE_PLATFORM%" "%NATIVE_CONFIGURATION%%NETFX40_SUFFIX%" Runtime data\exclude_runtime.txt

        IF ERRORLEVEL 1 (
          ECHO Creating "%PACKAGE_PLATFORM%\%NATIVE_CONFIGURATION%%NETFX40_SUFFIX%" runtime binaries archive failed.
          GOTO errors
        )
      )

      IF NOT DEFINED NOCORE (
        %__ECHO3% CALL "%PACKAGE_TOOLS%\release.bat" "%PACKAGE_PLATFORM%" "%NATIVE_CONFIGURATION%%NETFX40_SUFFIX%" Core data\exclude_core.txt

        IF ERRORLEVEL 1 (
          ECHO Creating "%PACKAGE_PLATFORM%\%NATIVE_CONFIGURATION%%NETFX40_SUFFIX%" core binaries archive failed.
          GOTO errors
        )
      )

      CALL :fn_UnsetVariable SUFFIX
    )

    IF NOT DEFINED NONETFX45 (
      SET SUFFIX=%NETFX45_SUFFIX%_
      CALL :fn_ShowVariable Suffix SUFFIX

      IF NOT DEFINED NOBINARY (
        %__ECHO3% CALL "%PACKAGE_TOOLS%\release.bat" "%PACKAGE_PLATFORM%" "%NATIVE_CONFIGURATION%%NETFX45_SUFFIX%"

        IF ERRORLEVEL 1 (
          ECHO Creating "%PACKAGE_PLATFORM%\%NATIVE_CONFIGURATION%%NETFX45_SUFFIX%" binaries archive failed.
          GOTO errors
        )
      )

      IF NOT DEFINED NORUNTIME (
        %__ECHO3% CALL "%PACKAGE_TOOLS%\release.bat" "%PACKAGE_PLATFORM%" "%NATIVE_CONFIGURATION%%NETFX45_SUFFIX%" Runtime data\exclude_runtime.txt

        IF ERRORLEVEL 1 (
          ECHO Creating "%PACKAGE_PLATFORM%\%NATIVE_CONFIGURATION%%NETFX45_SUFFIX%" runtime binaries archive failed.
          GOTO errors
        )
      )

      IF NOT DEFINED NOCORE (
        %__ECHO3% CALL "%PACKAGE_TOOLS%\release.bat" "%PACKAGE_PLATFORM%" "%NATIVE_CONFIGURATION%%NETFX45_SUFFIX%" Core data\exclude_core.txt

        IF ERRORLEVEL 1 (
          ECHO Creating "%PACKAGE_PLATFORM%\%NATIVE_CONFIGURATION%%NETFX45_SUFFIX%" core binaries archive failed.
          GOTO errors
        )
      )

      CALL :fn_UnsetVariable SUFFIX
    )

    IF NOT DEFINED NONETFX451 (
      SET SUFFIX=%NETFX451_SUFFIX%_
      CALL :fn_ShowVariable Suffix SUFFIX

      IF NOT DEFINED NOBINARY (
        %__ECHO3% CALL "%PACKAGE_TOOLS%\release.bat" "%PACKAGE_PLATFORM%" "%NATIVE_CONFIGURATION%%NETFX451_SUFFIX%"

        IF ERRORLEVEL 1 (
          ECHO Creating "%PACKAGE_PLATFORM%\%NATIVE_CONFIGURATION%%NETFX451_SUFFIX%" binaries archive failed.
          GOTO errors
        )
      )

      IF NOT DEFINED NORUNTIME (
        %__ECHO3% CALL "%PACKAGE_TOOLS%\release.bat" "%PACKAGE_PLATFORM%" "%NATIVE_CONFIGURATION%%NETFX451_SUFFIX%" Runtime data\exclude_runtime.txt

        IF ERRORLEVEL 1 (
          ECHO Creating "%PACKAGE_PLATFORM%\%NATIVE_CONFIGURATION%%NETFX451_SUFFIX%" runtime binaries archive failed.
          GOTO errors
        )
      )

      IF NOT DEFINED NOCORE (
        %__ECHO3% CALL "%PACKAGE_TOOLS%\release.bat" "%PACKAGE_PLATFORM%" "%NATIVE_CONFIGURATION%%NETFX451_SUFFIX%" Core data\exclude_core.txt

        IF ERRORLEVEL 1 (
          ECHO Creating "%PACKAGE_PLATFORM%\%NATIVE_CONFIGURATION%%NETFX451_SUFFIX%" core binaries archive failed.
          GOTO errors
        )
      )

      CALL :fn_UnsetVariable SUFFIX
    )
  )
)

REM ****************************************************************************
REM ********************** Verify Release Archives Files ***********************
REM ****************************************************************************

IF NOT DEFINED NOVERIFY (
  %__ECHO% EagleShell.exe -file "%TOOLS%\verify.eagle" "%RELEASES%"

  IF ERRORLEVEL 1 (
    ECHO Verifying release archive files in "%RELEASES%" failed.
    GOTO errors
  )
)

REM ****************************************************************************
REM ************************ Copy Build/Test Log Files *************************
REM ****************************************************************************

IF NOT DEFINED NOLOGS (
  IF EXIST "%TEMP%\EagleShell.exe.test.*.log" (
    %__ECHO% XCOPY "%TEMP%\EagleShell.exe.test.*.log" "%RELEASES%" %FFLAGS% %DFLAGS%

    IF ERRORLEVEL 1 (
      ECHO Failed to copy "%TEMP%\EagleShell.exe.test.*.log" to "%RELEASES%".
      GOTO errors
    )
  )

  IF NOT DEFINED NOPACKAGE (
    IF EXIST "%TEMP%\Garuda*Build.*" (
      %__ECHO% XCOPY "%TEMP%\Garuda*Build.*" "%RELEASES%" %FFLAGS% %DFLAGS%

      IF ERRORLEVEL 1 (
        ECHO Failed to copy "%TEMP%\Garuda*Build.*" to "%RELEASES%".
        GOTO errors
      )
    )
  )
)

REM ****************************************************************************
REM ************************** Create NuGet Packages ***************************
REM ****************************************************************************

IF NOT DEFINED NONUGET (
  IF NOT DEFINED NONETFX20 (
    IF NOT EXIST "%NUGETBASEPATH%" (
      %__ECHO% MKDIR "%NUGETBASEPATH%"

      IF ERRORLEVEL 1 (
        ECHO Could not create directory "%NUGETBASEPATH%".
        GOTO errors
      )
    )

    IF NOT EXIST "%NUGETOUTPUTDIR%\NuGet" (
      %__ECHO% MKDIR "%NUGETOUTPUTDIR%\NuGet"

      IF ERRORLEVEL 1 (
        ECHO Could not create directory "%NUGETOUTPUTDIR%\NuGet".
        GOTO errors
      )
    )

    IF NOT EXIST "%NUGETOUTPUTDIR%\SymbolSource" (
      %__ECHO% MKDIR "%NUGETOUTPUTDIR%\SymbolSource"

      IF ERRORLEVEL 1 (
        ECHO Could not create directory "%NUGETOUTPUTDIR%\SymbolSource".
        GOTO errors
      )
    )

    %__ECHO% XCOPY "%ROOT%\NuGet\install.ps1" "%NUGETBASEPATH%\" %FFLAGS% %DFLAGS%

    IF ERRORLEVEL 1 (
      ECHO Failed to copy "%ROOT%\NuGet\install.ps1" to "%NUGETBASEPATH%\".
      GOTO errors
    )

    %__ECHO% XCOPY "%SRCBINDIR%\Eagle.dll" "%NUGETBASEPATH%\bin\" %FFLAGS% %DFLAGS%

    IF ERRORLEVEL 1 (
      ECHO Failed to copy "%SRCBINDIR%\Eagle.dll" to "%NUGETBASEPATH%\bin\".
      GOTO errors
    )

    %__ECHO% XCOPY "%SRCBINDIR%\Eagle.pdb" "%NUGETBASEPATH%\bin\" %FFLAGS% %DFLAGS%

    IF ERRORLEVEL 1 (
      ECHO Failed to copy "%SRCBINDIR%\Eagle.pdb" to "%NUGETBASEPATH%\bin\".
      GOTO errors
    )

    %__ECHO% XCOPY "%SRCBINDIR%\x86\Spilornis.dll" "%NUGETBASEPATH%\bin\x86\" %FFLAGS% %DFLAGS%

    IF ERRORLEVEL 1 (
      ECHO Failed to copy "%SRCBINDIR%\x86\Spilornis.dll" to "%NUGETBASEPATH%\bin\x86\".
      GOTO errors
    )

    %__ECHO% XCOPY "%SRCBINDIR%\x86\Spilornis.pdb" "%NUGETBASEPATH%\bin\x86\" %FFLAGS% %DFLAGS%

    IF ERRORLEVEL 1 (
      ECHO Failed to copy "%SRCBINDIR%\x86\Spilornis.pdb" to "%NUGETBASEPATH%\bin\x86\".
      GOTO errors
    )

    %__ECHO% XCOPY "%SRCBINDIR%\x64\Spilornis.dll" "%NUGETBASEPATH%\bin\x64\" %FFLAGS% %DFLAGS%

    IF ERRORLEVEL 1 (
      ECHO Failed to copy "%SRCBINDIR%\x64\Spilornis.dll" to "%NUGETBASEPATH%\bin\x64\".
      GOTO errors
    )

    %__ECHO% XCOPY "%SRCBINDIR%\x64\Spilornis.pdb" "%NUGETBASEPATH%\bin\x64\" %FFLAGS% %DFLAGS%

    IF ERRORLEVEL 1 (
      ECHO Failed to copy "%SRCBINDIR%\x64\Spilornis.pdb" to "%NUGETBASEPATH%\bin\x64\".
      GOTO errors
    )

    REM
    REM HACK: We must change the current directory because the EXCLUDE argument
    REM       to the XCOPY command is very picky.  The first problem is that it
    REM       apparently cannot include surrounding double quotes, even though
    REM       this fact is not documented anywhere, thus making it impossible to
    REM       use any path that contains spaces.  The second problem is that all
    REM       the files we want to copy would match the exclusion rule "\Tools\"
    REM       because we are running from the "Tools" directory and we would
    REM       have to use our directory as the basis for the library source
    REM       directory ^(unless we could find a reasonable way of resolving it
    REM       to an absolute path beforehand^).
    REM
    %__ECHO2% PUSHD "%ROOT%"

    IF ERRORLEVEL 1 (
      ECHO Could not change directory to "%ROOT%".
      GOTO errors
    )

    REM
    REM HACK: Must use relative path for source files and EXCLUDE file here, see
    REM       above comment.
    REM
    %__ECHO% XCOPY "Library\*.cs" "%NUGETBASEPATH%\src\Library\" %FFLAGS% %DFLAGS% /S /EXCLUDE:data\exclude_nuget.txt

    IF ERRORLEVEL 1 (
      ECHO Failed to copy "Library\*.cs" to "%NUGETBASEPATH%\src\Library\".
      GOTO errors
    )

    %__ECHO% XCOPY "Native\Utility\*.c" "%NUGETBASEPATH%\src\Native\Utility\" %FFLAGS% %DFLAGS% /S /EXCLUDE:data\exclude_nuget.txt

    IF ERRORLEVEL 1 (
      ECHO Failed to copy "Native\Utility\*.c" to "%NUGETBASEPATH%\src\Native\Utility\".
      GOTO errors
    )

    %__ECHO% XCOPY "Native\Utility\*.h" "%NUGETBASEPATH%\src\Native\Utility\" %FFLAGS% %DFLAGS% /S /EXCLUDE:data\exclude_nuget.txt

    IF ERRORLEVEL 1 (
      ECHO Failed to copy "Native\Utility\*.h" to "%NUGETBASEPATH%\src\Native\Utility\".
      GOTO errors
    )

    %__ECHO2% POPD

    IF ERRORLEVEL 1 (
      ECHO Could not restore directory.
      GOTO errors
    )

    %_CECHO% NuGet.exe pack "%ROOT%\NuGet\Eagle.nuspec" /BasePath "%NUGETBASEPATH%" /OutputDirectory "%NUGETOUTPUTDIR%\NuGet"
    %__ECHO% NuGet.exe pack "%ROOT%\NuGet\Eagle.nuspec" /BasePath "%NUGETBASEPATH%" /OutputDirectory "%NUGETOUTPUTDIR%\NuGet"

    IF ERRORLEVEL 1 (
      ECHO Failed to create NuGet package from "%ROOT%\NuGet\Eagle.nuspec".
      GOTO errors
    )

    %_CECHO% NuGet.exe pack "%ROOT%\NuGet\Eagle.src.nuspec" /BasePath "%NUGETBASEPATH%" /OutputDirectory "%NUGETOUTPUTDIR%\SymbolSource"
    %__ECHO% NuGet.exe pack "%ROOT%\NuGet\Eagle.src.nuspec" /BasePath "%NUGETBASEPATH%" /OutputDirectory "%NUGETOUTPUTDIR%\SymbolSource"

    IF ERRORLEVEL 1 (
      ECHO Failed to create SymbolSource package from "%ROOT%\NuGet\Eagle.src.nuspec".
      GOTO errors
    )

    IF DEFINED NONUGETPUSH (
      %_AECHO% Skipping push of NuGet and SymbolSource packages...
      GOTO skip_nuGetPush
    )

    REM
    REM NOTE: Emit the necessary commands to the console to push the created
    REM       NuGet and SymbolSource packages; however, do not actually push the
    REM       created packages.  Eventually, we may decide to migrate to
    REM       automatically pushing the created packages; however, this will
    REM       have to be done with great care because we cannot really undo it.
    REM
    IF NOT DEFINED NUGET_API_KEY (
      ECHO The NUGET_API_KEY environment variable must be set first.
      GOTO usage
    )

    IF NOT DEFINED SYMBOLSOURCE_API_KEY (
      ECHO The SYMBOLSOURCE_API_KEY environment variable must be set first.
      GOTO usage
    )

    %_CECHO% NuGet.exe push "%NUGETOUTPUTDIR%\NuGet\Eagle.%PATCHLEVEL%.nupkg" "%NUGET_API_KEY%"
    ECHO NuGet.exe push "%NUGETOUTPUTDIR%\NuGet\Eagle.%PATCHLEVEL%.nupkg" "%NUGET_API_KEY%"

    IF ERRORLEVEL 1 (
      ECHO Failed to push NuGet package "%NUGETOUTPUTDIR%\NuGet\Eagle.%PATCHLEVEL%.nupkg".
      GOTO errors
    )

    %_CECHO% NuGet.exe push "%NUGETOUTPUTDIR%\SymbolSource\Eagle.%PATCHLEVEL%.nupkg" "%NUGET_API_KEY%" -source http://nuget.gw.symbolsource.org/Public/NuGet
    ECHO NuGet.exe push "%NUGETOUTPUTDIR%\SymbolSource\Eagle.%PATCHLEVEL%.nupkg" "%NUGET_API_KEY%" -source http://nuget.gw.symbolsource.org/Public/NuGet

    IF ERRORLEVEL 1 (
      ECHO Failed to push SymbolSource package "%NUGETOUTPUTDIR%\SymbolSource\Eagle.%PATCHLEVEL%.nupkg".
      GOTO errors
    )
  )
)

:skip_nuGetPush

REM ****************************************************************************
REM **************************** Hash All Packages *****************************
REM ****************************************************************************

IF NOT DEFINED NOHASH (
  IF EXIST "%TOOLS%\sha1sum.exe" (
    IF EXIST "%RELEASES%\hash.txt" (
      %__ECHO% DEL "%RELEASES%\hash.txt"

      IF ERRORLEVEL 1 (
        ECHO Could not delete file "%RELEASES%\hash.txt".
        GOTO errors
      )
    )

    %__ECHO% ECHO Hashed "%DATE%" at "%TIME%" by "%USERDOMAIN%\%USERNAME%" %APPEND% "%RELEASES%\hash.txt"
    %__ECHO% ECHO. %APPEND% "%RELEASES%\hash.txt"

    FOR %%B IN (%HASHBASES%) DO (
      FOR %%E IN (%HASHEXTS%) DO (
        FOR /F "delims=" %%F IN ('DIR /B /S /ON "%RELEASES%\%%B*%PATCHLEVEL%.%%E" 2^> NUL') DO (
          %_AECHO% Hashing file "%%F"...
          %_CECHO% "%TOOLS%\sha1sum.exe" "%%F" %_CAPPEND% "%RELEASES%\hash.txt"
          %__ECHO% "%TOOLS%\sha1sum.exe" "%%F" %APPEND% "%RELEASES%\hash.txt"

          IF ERRORLEVEL 1 (
            ECHO Hashing file "%%F" failed.
            GOTO errors
          )
        )

        FOR /F "delims=" %%F IN ('DIR /B /S /ON "%RELEASES%\%%B*%PACKAGE_PATCHLEVEL%.%%E" 2^> NUL') DO (
          %_AECHO% Hashing file "%%F"...
          %_CECHO% "%TOOLS%\sha1sum.exe" "%%F" %_CAPPEND% "%RELEASES%\hash.txt"
          %__ECHO% "%TOOLS%\sha1sum.exe" "%%F" %APPEND% "%RELEASES%\hash.txt"

          IF ERRORLEVEL 1 (
            ECHO Hashing file "%%F" failed.
            GOTO errors
          )
        )
      )
    )
  ) ELSE (
    %_AECHO% Hashing tool "%TOOLS%\sha1sum.exe" not found, skipping...
  )
)

GOTO no_errors

REM ****************************************************************************
REM ****************** Epilogue / Functions / Return Handling ******************
REM ****************************************************************************

:fn_UnquoteVariable
  IF NOT DEFINED %1 GOTO :EOF
  SETLOCAL
  SET __ECHO_CMD=ECHO %%%1%%
  FOR /F "delims=" %%V IN ('%__ECHO_CMD%') DO (
    SET VALUE=%%V
  )
  SET VALUE=%VALUE:"=%
  REM "
  ENDLOCAL && SET %1=%VALUE%
  GOTO :EOF

:fn_ShowVariable
  SETLOCAL
  SET __ECHO_CMD=ECHO %%%2%%
  FOR /F "delims=" %%V IN ('%__ECHO_CMD%') DO (
    IF NOT "%%V" == "" (
      IF NOT "%%V" == "%%%2%%" (
        %_VECHO% %1 = '%%V'
      )
    )
  )
  ENDLOCAL
  GOTO :EOF

:fn_AppendVariable
  SET __ECHO_CMD=ECHO %%%1%%
  IF DEFINED %1 (
    FOR /F "delims=" %%V IN ('%__ECHO_CMD%') DO (
      SET %1=%%V%~2
    )
  ) ELSE (
    SET %1=%~2
  )
  SET __ECHO_CMD=
  CALL :fn_ResetErrorLevel
  GOTO :EOF

:fn_UnsetVariable
  IF NOT "%1" == "" (
    SET %1=
    CALL :fn_ResetErrorLevel
  )
  GOTO :EOF

:fn_ResetErrorLevel
  VERIFY > NUL
  GOTO :EOF

:fn_SetErrorLevel
  VERIFY MAYBE 2> NUL
  GOTO :EOF

:usage
  ECHO.
  ECHO Usage: %~nx0 [configuration] [...]
  ECHO.
  ECHO The NUGET_API_KEY environment variable must be set to the NuGet API key.
  ECHO.
  ECHO The SYMBOLSOURCE_API_KEY environment variable must be set to the SymbolSource
  ECHO API key.
  ECHO.
  ECHO The latest Eagle binaries ^(including the "EagleShell.exe" tool^) are required to
  ECHO exist in the "%%LKG%%\Eagle\bin" directory or somewhere along your PATH.  They
  ECHO can be downloaded for free from:
  ECHO.
  ECHO                          http://eagle.to/
  ECHO.
  ECHO Several of the tasks performed by this tool require [elevated] administrator
  ECHO privileges.  Therefore, this tool will refuse to run without them.
  GOTO errors

:errors
  CALL :fn_SetErrorLevel
  ENDLOCAL
  ECHO.
  ECHO Flight failure, errors were encountered.
  GOTO end_of_file

:no_errors
  CALL :fn_ResetErrorLevel
  ENDLOCAL
  ECHO.
  ECHO Flight success, no errors were encountered.
  GOTO end_of_file

:end_of_file
ECHO STOPPED ON %DATE% AT %TIME% BY %USERDOMAIN%\%USERNAME%
%__ECHO% EXIT /B %ERRORLEVEL%
