1@echo off
2setlocal
3set D=%~dp0
4set PCBUILD=%D%..\..\PCBuild\
5
6set BUILDX86=
7set BUILDX64=
8set REBUILD=
9set OUTPUT=
10set PACKAGES=
11
12:CheckOpts
13if "%~1" EQU "-h" goto Help
14if "%~1" EQU "-x86" (set BUILDX86=1) && shift && goto CheckOpts
15if "%~1" EQU "-x64" (set BUILDX64=1) && shift && goto CheckOpts
16if "%~1" EQU "-r" (set REBUILD=-r) && shift && goto CheckOpts
17if "%~1" EQU "-o" (set OUTPUT="/p:OutputPath=%~2") && shift && shift && goto CheckOpts
18if "%~1" EQU "--out" (set OUTPUT="/p:OutputPath=%~2") && shift && shift && goto CheckOpts
19if "%~1" EQU "-p" (set PACKAGES=%PACKAGES% %~2) && shift && shift && goto CheckOpts
20
21if not defined BUILDX86 if not defined BUILDX64 (set BUILDX86=1) && (set BUILDX64=1)
22
23call "%D%..\msi\get_externals.bat"
24call "%PCBUILD%env.bat" x86
25
26if defined PACKAGES set PACKAGES="/p:Packages=%PACKAGES%"
27
28if defined BUILDX86 (
29    if defined REBUILD ( call "%PCBUILD%build.bat" -e -r
30    ) else if not exist "%PCBUILD%win32\python.exe" call "%PCBUILD%build.bat" -e
31    if errorlevel 1 goto :eof
32
33    msbuild "%D%make_pkg.proj" /p:Configuration=Release /p:Platform=x86 %OUTPUT% %PACKAGES%
34    if errorlevel 1 goto :eof
35)
36
37if defined BUILDX64 (
38    if defined REBUILD ( call "%PCBUILD%build.bat" -p x64 -e -r
39    ) else if not exist "%PCBUILD%amd64\python.exe" call "%PCBUILD%build.bat" -p x64 -e
40    if errorlevel 1 goto :eof
41
42    msbuild "%D%make_pkg.proj" /p:Configuration=Release /p:Platform=x64 %OUTPUT% %PACKAGES%
43    if errorlevel 1 goto :eof
44)
45
46exit /B 0
47
48:Help
49echo build.bat [-x86] [-x64] [--out DIR] [-r] [-h]
50echo.
51echo    -x86                Build x86 installers
52echo    -x64                Build x64 installers
53echo    -r                  Rebuild rather than incremental build
54echo    --out [DIR]         Override output directory
55echo    -h                  Show usage
56