blob: 98fa2671f63d8da49746720024702822e5a8ad14 [file] [log] [blame]
Zachary Ware4c9c8482015-04-13 11:59:54 -05001@echo off
Zachary Ware67323432015-09-02 13:21:19 -05002goto Run
3:Usage
4echo.%~nx0 [flags and arguments] [quoted MSBuild options]
5echo.
6echo.Build CPython from the command line. Requires the appropriate
7echo.version(s) of Microsoft Visual Studio to be installed (see readme.txt).
8echo.Also requires Subversion (svn.exe) to be on PATH if the '-e' flag is
9echo.given.
10echo.
11echo.After the flags recognized by this script, up to 9 arguments to be passed
12echo.directly to MSBuild may be passed. If the argument contains an '=', the
13echo.entire argument must be quoted (e.g. `%~nx0 "/p:PlatformToolset=v100"`)
14echo.
15echo.Available flags:
16echo. -h Display this help message
17echo. -V Display version information for the current build
18echo. -r Target Rebuild instead of Build
19echo. -d Set the configuration to Debug
20echo. -e Build external libraries fetched by get_externals.bat
Zachary Wareb27f3c32015-09-03 23:43:54 -050021echo. Extension modules that depend on external libraries will not attempt
22echo. to build if this flag is not present
Zachary Ware67323432015-09-02 13:21:19 -050023echo. -m Enable parallel build (enabled by default)
24echo. -M Disable parallel build
25echo. -v Increased output messages
26echo. -k Attempt to kill any running Pythons before building (usually done
27echo. automatically by the pythoncore project)
Zachary Warebed30c32016-01-12 01:26:50 -060028echo. --pgo Build with Profile-Guided Optimization. This flag
29echo. overrides -c and -d
30echo. --test-marker Enable the test marker within the build.
Zachary Ware67323432015-09-02 13:21:19 -050031echo.
Zachary Wareb27f3c32015-09-03 23:43:54 -050032echo.Available flags to avoid building certain modules.
33echo.These flags have no effect if '-e' is not given:
34echo. --no-ssl Do not attempt to build _ssl
35echo. --no-tkinter Do not attempt to build Tkinter
36echo.
Zachary Ware67323432015-09-02 13:21:19 -050037echo.Available arguments:
38echo. -c Release ^| Debug ^| PGInstrument ^| PGUpdate
39echo. Set the configuration (default: Release)
40echo. -p x64 ^| Win32
41echo. Set the platform (default: Win32)
42echo. -t Build ^| Rebuild ^| Clean ^| CleanAll
43echo. Set the target manually
Zachary Warebed30c32016-01-12 01:26:50 -060044echo. --pgo-job The job to use for PGO training; implies --pgo
45echo. (default: "-m test --pgo")
Zachary Ware67323432015-09-02 13:21:19 -050046exit /b 127
Zachary Ware4c9c8482015-04-13 11:59:54 -050047
Zachary Ware67323432015-09-02 13:21:19 -050048:Run
Zachary Ware4c9c8482015-04-13 11:59:54 -050049setlocal
50set platf=Win32
Zachary Ware774ac372015-04-13 12:11:40 -050051set vs_platf=x86
Zachary Ware4c9c8482015-04-13 11:59:54 -050052set conf=Release
Zachary Ware774ac372015-04-13 12:11:40 -050053set target=Build
Zachary Ware4c9c8482015-04-13 11:59:54 -050054set dir=%~dp0
Zachary Ware774ac372015-04-13 12:11:40 -050055set parallel=/m
56set verbose=/nologo /v:m
Zachary Ware6250df82015-06-09 23:16:52 -050057set kill=
Zachary Warebed30c32016-01-12 01:26:50 -060058set do_pgo=
59set pgo_job=-m test --pgo
60set on_64_bit=true
61
62rem This may not be 100% accurate, but close enough.
63if "%ProgramFiles(x86)%"=="" (set on_64_bit=false)
Zachary Ware4c9c8482015-04-13 11:59:54 -050064
65:CheckOpts
Zachary Ware67323432015-09-02 13:21:19 -050066if "%~1"=="-h" goto Usage
Steve Dowere1f68052015-07-20 21:34:45 -070067if "%~1"=="-c" (set conf=%2) & shift & shift & goto CheckOpts
68if "%~1"=="-p" (set platf=%2) & shift & shift & goto CheckOpts
69if "%~1"=="-r" (set target=Rebuild) & shift & goto CheckOpts
70if "%~1"=="-t" (set target=%2) & shift & shift & goto CheckOpts
71if "%~1"=="-d" (set conf=Debug) & shift & goto CheckOpts
Steve Dowere1f68052015-07-20 21:34:45 -070072if "%~1"=="-m" (set parallel=/m) & shift & goto CheckOpts
73if "%~1"=="-M" (set parallel=) & shift & goto CheckOpts
74if "%~1"=="-v" (set verbose=/v:n) & shift & goto CheckOpts
75if "%~1"=="-k" (set kill=true) & shift & goto CheckOpts
Zachary Warebed30c32016-01-12 01:26:50 -060076if "%~1"=="--pgo" (set do_pgo=true) & shift & goto CheckOpts
77if "%~1"=="--pgo-job" (set do_pgo=true) & (set pgo_job=%~2) & shift & shift & goto CheckOpts
Steve Dower940f6a82015-10-31 12:17:11 -070078if "%~1"=="--test-marker" (set UseTestMarker=true) & shift & goto CheckOpts
Steve Dowere1f68052015-07-20 21:34:45 -070079if "%~1"=="-V" shift & goto Version
Zachary Wareb27f3c32015-09-03 23:43:54 -050080rem These use the actual property names used by MSBuild. We could just let
81rem them in through the environment, but we specify them on the command line
82rem anyway for visibility so set defaults after this
Zachary Warea6deff22015-09-04 01:10:23 -050083if "%~1"=="-e" (set IncludeExternals=true) & shift & goto CheckOpts
Zachary Wareb27f3c32015-09-03 23:43:54 -050084if "%~1"=="--no-ssl" (set IncludeSSL=false) & shift & goto CheckOpts
85if "%~1"=="--no-tkinter" (set IncludeTkinter=false) & shift & goto CheckOpts
86
87if "%IncludeExternals%"=="" set IncludeExternals=false
88if "%IncludeSSL%"=="" set IncludeSSL=true
89if "%IncludeTkinter%"=="" set IncludeTkinter=true
Zachary Ware4c9c8482015-04-13 11:59:54 -050090
Zachary Warea6deff22015-09-04 01:10:23 -050091if "%IncludeExternals%"=="true" call "%dir%get_externals.bat"
92
Zachary Warebed30c32016-01-12 01:26:50 -060093if "%platf%"=="x64" (
94 if "%on_64_bit%"=="true" (
95 rem This ought to always be correct these days...
96 set vs_platf=amd64
97 ) else (
98 if "%do_pgo%"=="true" (
99 echo.ERROR: Cannot cross-compile with PGO
100 echo. 32bit operating system detected, if this is incorrect,
101 echo. make sure the ProgramFiles(x86^) environment variable is set
102 exit /b 1
103 )
104 set vs_platf=x86_amd64
105 )
106)
Zachary Ware774ac372015-04-13 12:11:40 -0500107
Steve Dower190dbd92016-12-03 11:18:53 -0800108if not exist "%HG%" where hg > "%TEMP%\hg.loc" 2> nul && set /P HG= < "%TEMP%\hg.loc" & del "%TEMP%\hg.loc"
109if not exist "%HG%" echo Cannot find Mercurial on PATH && exit /B 1
110
Zachary Ware774ac372015-04-13 12:11:40 -0500111rem Setup the environment
112call "%dir%env.bat" %vs_platf% >nul
113
Zachary Warebed30c32016-01-12 01:26:50 -0600114if "%kill%"=="true" call :Kill
Zachary Ware6250df82015-06-09 23:16:52 -0500115
Zachary Warebed30c32016-01-12 01:26:50 -0600116if "%do_pgo%"=="true" (
117 set conf=PGInstrument
118 call :Build
119 del /s "%dir%\*.pgc"
120 del /s "%dir%\..\Lib\*.pyc"
121 echo on
122 call "%dir%\..\python.bat" %pgo_job%
123 @echo off
124 call :Kill
125 set conf=PGUpdate
126)
127goto Build
128
129:Kill
130echo on
131msbuild "%dir%\pythoncore.vcxproj" /t:KillPython %verbose%^
132 /p:Configuration=%conf% /p:Platform=%platf%^
133 /p:KillPython=true
134
135@echo off
136goto :eof
137
138:Build
Zachary Ware774ac372015-04-13 12:11:40 -0500139rem Call on MSBuild to do the work, echo the command.
140rem Passing %1-9 is not the preferred option, but argument parsing in
141rem batch is, shall we say, "lackluster"
142echo on
Zachary Wareb27f3c32015-09-03 23:43:54 -0500143msbuild "%dir%pcbuild.proj" /t:%target% %parallel% %verbose%^
144 /p:Configuration=%conf% /p:Platform=%platf%^
145 /p:IncludeExternals=%IncludeExternals%^
146 /p:IncludeSSL=%IncludeSSL% /p:IncludeTkinter=%IncludeTkinter%^
Steve Dower940f6a82015-10-31 12:17:11 -0700147 /p:UseTestMarker=%UseTestMarker%^
Steve Dower190dbd92016-12-03 11:18:53 -0800148 /p:HG="%HG%"^
Zachary Wareb27f3c32015-09-03 23:43:54 -0500149 %1 %2 %3 %4 %5 %6 %7 %8 %9
Steve Dower49437492015-07-08 20:18:44 -0700150
Zachary Warebed30c32016-01-12 01:26:50 -0600151@echo off
152goto :eof
Steve Dower49437492015-07-08 20:18:44 -0700153
154:Version
155rem Display the current build version information
156msbuild "%dir%python.props" /t:ShowVersionInfo /v:m /nologo %1 %2 %3 %4 %5 %6 %7 %8 %9