blob: 713810e5b4b509a7b5347361a2b5c0c7071fc6bf [file] [log] [blame]
Zachary Ware6b6e6872017-06-10 14:58:42 -05001@echo off
2goto 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.Alternatively you can put extra flags for MSBuild in a file named
15echo.`msbuild.rsp` in the `PCbuild` directory, one flag per line. This file
16echo.will be picked automatically by MSBuild. Flags put in this file does not
17echo.need to be quoted. You can still use environment variables inside the
18echo.response file.
19echo.
20echo.Available flags:
21echo. -h Display this help message
22echo. -V Display version information for the current build
23echo. -r Target Rebuild instead of Build
24echo. -d Set the configuration to Debug
25echo. -e Build external libraries fetched by get_externals.bat
26echo. Extension modules that depend on external libraries will not attempt
27echo. to build if this flag is not present
28echo. -m Enable parallel build (enabled by default)
29echo. -M Disable parallel build
30echo. -v Increased output messages
31echo. -k Attempt to kill any running Pythons before building (usually done
32echo. automatically by the pythoncore project)
33echo. --pgo Build with Profile-Guided Optimization. This flag
34echo. overrides -c and -d
35echo. --test-marker Enable the test marker within the build.
36echo.
37echo.Available flags to avoid building certain modules.
38echo.These flags have no effect if '-e' is not given:
39echo. --no-ssl Do not attempt to build _ssl
40echo. --no-tkinter Do not attempt to build Tkinter
41echo.
42echo.Available arguments:
43echo. -c Release ^| Debug ^| PGInstrument ^| PGUpdate
44echo. Set the configuration (default: Release)
45echo. -p x64 ^| Win32
46echo. Set the platform (default: Win32)
47echo. -t Build ^| Rebuild ^| Clean ^| CleanAll
48echo. Set the target manually
49echo. --pgo-job The job to use for PGO training; implies --pgo
50echo. (default: "-m test --pgo")
51exit /b 127
52
53:Run
54setlocal
55set platf=Win32
Zachary Ware6b6e6872017-06-10 14:58:42 -050056set conf=Release
57set target=Build
58set dir=%~dp0
59set parallel=/m
60set verbose=/nologo /v:m
61set kill=
62set do_pgo=
63set pgo_job=-m test --pgo
Zachary Ware6b6e6872017-06-10 14:58:42 -050064
65:CheckOpts
66if "%~1"=="-h" goto Usage
67if "%~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
72if "%~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
76if "%~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
78if "%~1"=="--test-marker" (set UseTestMarker=true) & shift & goto CheckOpts
79if "%~1"=="-V" shift & goto Version
80rem 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
83if "%~1"=="-e" (set IncludeExternals=true) & shift & goto CheckOpts
84if "%~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
90
91if "%IncludeExternals%"=="true" call "%dir%get_externals.bat"
92
Steve Dower40a23e82017-06-19 10:34:25 -070093if "%do_pgo%" EQU "true" if "%platf%" EQU "x64" (
94 if "%PROCESSOR_ARCHITEW6432%" NEQ "AMD64" if "%PROCESSOR_ARCHITECTURE%" NEQ "AMD64" (
95 echo.ERROR: Cannot cross-compile with PGO
96 echo. 32bit operating system detected. Ensure your PROCESSOR_ARCHITECTURE
97 echo. and PROCESSOR_ARCHITEW6432 environment variables are correct.
98 exit /b 1
Zachary Ware6b6e6872017-06-10 14:58:42 -050099 )
100)
101
102if not exist "%GIT%" where git > "%TEMP%\git.loc" 2> nul && set /P GIT= < "%TEMP%\git.loc" & del "%TEMP%\git.loc"
103if exist "%GIT%" set GITProperty=/p:GIT="%GIT%"
104if not exist "%GIT%" echo Cannot find Git on PATH & set GITProperty=
105
106rem Setup the environment
Steve Dower40a23e82017-06-19 10:34:25 -0700107call "%dir%find_msbuild.bat" %MSBUILD%
108if ERRORLEVEL 1 (echo Cannot locate MSBuild.exe on PATH or as MSBUILD variable & exit /b 2)
Zachary Ware6b6e6872017-06-10 14:58:42 -0500109
110if "%kill%"=="true" call :Kill
111
112if "%do_pgo%"=="true" (
113 set conf=PGInstrument
114 call :Build %1 %2 %3 %4 %5 %6 %7 %8 %9
115 del /s "%dir%\*.pgc"
116 del /s "%dir%\..\Lib\*.pyc"
117 echo on
118 call "%dir%\..\python.bat" %pgo_job%
119 @echo off
120 call :Kill
121 set conf=PGUpdate
122 set target=Build
123)
124goto Build
125:Kill
126echo on
Steve Dower40a23e82017-06-19 10:34:25 -0700127%MSBUILD% "%dir%\pythoncore.vcxproj" /t:KillPython %verbose%^
Zachary Ware6b6e6872017-06-10 14:58:42 -0500128 /p:Configuration=%conf% /p:Platform=%platf%^
129 /p:KillPython=true
130
131@echo off
132goto :eof
133
134:Build
135rem Call on MSBuild to do the work, echo the command.
136rem Passing %1-9 is not the preferred option, but argument parsing in
137rem batch is, shall we say, "lackluster"
138echo on
Steve Dower40a23e82017-06-19 10:34:25 -0700139%MSBUILD% "%dir%pcbuild.proj" /t:%target% %parallel% %verbose%^
Zachary Ware6b6e6872017-06-10 14:58:42 -0500140 /p:Configuration=%conf% /p:Platform=%platf%^
141 /p:IncludeExternals=%IncludeExternals%^
142 /p:IncludeSSL=%IncludeSSL% /p:IncludeTkinter=%IncludeTkinter%^
143 /p:UseTestMarker=%UseTestMarker% %GITProperty%^
144 %1 %2 %3 %4 %5 %6 %7 %8 %9
145
146@echo off
147goto :eof
148
149:Version
150rem Display the current build version information
Steve Dower40a23e82017-06-19 10:34:25 -0700151%MSBUILD% "%dir%python.props" /t:ShowVersionInfo /v:m /nologo %1 %2 %3 %4 %5 %6 %7 %8 %9