blob: c43135d75beb835b33cf0b2241208ba95abb0291 [file] [log] [blame]
Zachary Ware3f8f16d2017-06-10 23:04:36 -05001@echo off
2setlocal
3
4pushd %~dp0
5
6set this=%~n0
7
Steve Dower68d663c2017-07-17 11:15:48 +02008call ..\PCBuild\find_python.bat %PYTHON%
Steve Dowerd5cd21d2017-09-04 14:26:27 -07009if not defined SPHINXBUILD if defined PYTHON (
10 %PYTHON% -c "import sphinx" > nul 2> nul
11 if errorlevel 1 (
Steve Dower68d663c2017-07-17 11:15:48 +020012 echo Installing sphinx with %PYTHON%
Steve Dowerd5cd21d2017-09-04 14:26:27 -070013 %PYTHON% -m pip install sphinx
Steve Dower68d663c2017-07-17 11:15:48 +020014 if errorlevel 1 exit /B
15 )
Steve Dowerd5cd21d2017-09-04 14:26:27 -070016 set SPHINXBUILD=%PYTHON% -c "import sphinx, sys; sys.argv[0] = 'sphinx-build'; sphinx.main()"
Steve Dower68d663c2017-07-17 11:15:48 +020017)
18
Steve Dower5fcd5e62017-09-06 10:01:38 -070019if not defined BLURB if defined PYTHON (
20 %PYTHON% -c "import blurb" > nul 2> nul
21 if errorlevel 1 (
22 echo Installing blurb with %PYTHON%
23 %PYTHON% -m pip install blurb
24 if errorlevel 1 exit /B
25 )
26 set BLURB=%PYTHON% -m blurb
27)
28
Steve Dowerd5cd21d2017-09-04 14:26:27 -070029if not defined PYTHON set PYTHON=py
30if not defined SPHINXBUILD set SPHINXBUILD=sphinx-build
Steve Dower5fcd5e62017-09-06 10:01:38 -070031if not defined BLURB set BLURB=blurb
Zachary Ware3f8f16d2017-06-10 23:04:36 -050032
33if "%1" NEQ "htmlhelp" goto :skiphhcsearch
34if exist "%HTMLHELP%" goto :skiphhcsearch
35
36rem Search for HHC in likely places
37set HTMLHELP=
38where hhc /q && set HTMLHELP=hhc && goto :skiphhcsearch
39where /R ..\externals hhc > "%TEMP%\hhc.loc" 2> nul && set /P HTMLHELP= < "%TEMP%\hhc.loc" & del "%TEMP%\hhc.loc"
40if not exist "%HTMLHELP%" where /R "%ProgramFiles(x86)%" hhc > "%TEMP%\hhc.loc" 2> nul && set /P HTMLHELP= < "%TEMP%\hhc.loc" & del "%TEMP%\hhc.loc"
41if not exist "%HTMLHELP%" where /R "%ProgramFiles%" hhc > "%TEMP%\hhc.loc" 2> nul && set /P HTMLHELP= < "%TEMP%\hhc.loc" & del "%TEMP%\hhc.loc"
42if not exist "%HTMLHELP%" (
43 echo.
44 echo.The HTML Help Workshop was not found. Set the HTMLHELP variable
45 echo.to the path to hhc.exe or download and install it from
46 echo.http://msdn.microsoft.com/en-us/library/ms669985
47 exit /B 1
48)
49:skiphhcsearch
50
51if "%DISTVERSION%" EQU "" for /f "usebackq" %%v in (`%PYTHON% tools/extensions/patchlevel.py`) do set DISTVERSION=%%v
52
53if "%BUILDDIR%" EQU "" set BUILDDIR=build
54
55rem Targets that don't require sphinx-build
56if "%1" EQU "" goto help
57if "%1" EQU "help" goto help
58if "%1" EQU "check" goto check
59if "%1" EQU "serve" goto serve
60if "%1" == "clean" (
61 rmdir /q /s %BUILDDIR%
62 goto end
63)
64
65%SPHINXBUILD% >nul 2> nul
66if errorlevel 9009 (
67 echo.
68 echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
69 echo.installed, then set the SPHINXBUILD environment variable to point
70 echo.to the full path of the 'sphinx-build' executable. Alternatively you
71 echo.may add the Sphinx directory to PATH.
72 echo.
73 echo.If you don't have Sphinx installed, grab it from
74 echo.http://sphinx-doc.org/
75 popd
76 exit /B 1
77)
78
79rem Targets that do require sphinx-build and have their own label
80if "%1" EQU "htmlview" goto htmlview
81
82rem Everything else
83goto build
84
85:help
86echo.usage: %this% BUILDER [filename ...]
87echo.
88echo.Call %this% with the desired Sphinx builder as the first argument, e.g.
89echo.``%this% html`` or ``%this% doctest``. Interesting targets that are
90echo.always available include:
91echo.
92echo. Provided by Sphinx:
93echo. html, htmlhelp, latex, text
94echo. suspicious, linkcheck, changes, doctest
95echo. Provided by this script:
96echo. clean, check, serve, htmlview
97echo.
98echo.All arguments past the first one are passed through to sphinx-build as
99echo.filenames to build or are ignored. See README.rst in this directory or
100echo.the documentation for your version of Sphinx for more exhaustive lists
101echo.of available targets and descriptions of each.
102echo.
103echo.This script assumes that the SPHINXBUILD environment variable contains
104echo.a legitimate command for calling sphinx-build, or that sphinx-build is
105echo.on your PATH if SPHINXBUILD is not set. Options for sphinx-build can
106echo.be passed by setting the SPHINXOPTS environment variable.
107goto end
108
109:build
Steve Dower5fcd5e62017-09-06 10:01:38 -0700110if exist ..\Misc\NEWS (
111 echo.Copying Misc\NEWS to build\NEWS
112 copy ..\Misc\NEWS build\NEWS > nul
113) else if exist ..\Misc\NEWS.D (
114 if defined BLURB (
115 echo.Merging Misc/NEWS with %BLURB%
116 %BLURB% merge -f build\NEWS
117 ) else (
118 echo.No Misc/NEWS file and Blurb is not available.
119 exit /B 1
120 )
121)
122
Zachary Ware3f8f16d2017-06-10 23:04:36 -0500123if NOT "%PAPER%" == "" (
124 set SPHINXOPTS=-D latex_elements.papersize=%PAPER% %SPHINXOPTS%
125)
Steve Dowerd5cd21d2017-09-04 14:26:27 -0700126cmd /C "%SPHINXBUILD% %SPHINXOPTS% -b%1 -dbuild\doctrees . %BUILDDIR%\%*"
Zachary Ware3f8f16d2017-06-10 23:04:36 -0500127
128if "%1" EQU "htmlhelp" (
129 cmd /C "%HTMLHELP%" build\htmlhelp\python%DISTVERSION:.=%.hhp
130 rem hhc.exe seems to always exit with code 1, reset to 0 for less than 2
131 if not errorlevel 2 cmd /C exit /b 0
132)
133
134echo.
135if errorlevel 1 (
136 echo.Build failed (exit code %ERRORLEVEL%^), check for error messages
137 echo.above. Any output will be found in %BUILDDIR%\%1
138) else (
139 echo.Build succeeded. All output should be in %BUILDDIR%\%1
140)
141goto end
142
143:htmlview
144if NOT "%2" EQU "" (
145 echo.Can't specify filenames to build with htmlview target, ignoring.
146)
147cmd /C %this% html
148
149if EXIST %BUILDDIR%\html\index.html (
150 echo.Opening %BUILDDIR%\html\index.html in the default web browser...
151 start %BUILDDIR%\html\index.html
152)
153
154goto end
155
156:check
157cmd /C %PYTHON% tools\rstlint.py -i tools
158goto end
159
160:serve
161cmd /C %PYTHON% ..\Tools\scripts\serve.py %BUILDDIR%\html
162goto end
163
164:end
165popd