blob: 5ab80850a3103b0d7ae49125b96bde3e39e0e774 [file] [log] [blame]
Zachary Ware4c9c8482015-04-13 11:59:54 -05001@echo off
2setlocal
3
4pushd %~dp0
5
6set this=%~n0
7
8if "%SPHINXBUILD%" EQU "" set SPHINXBUILD=sphinx-build
9if "%PYTHON%" EQU "" set PYTHON=py
10
Zachary Ware774ac372015-04-13 12:11:40 -050011if "%1" NEQ "htmlhelp" goto :skiphhcsearch
12if exist "%HTMLHELP%" goto :skiphhcsearch
13
14rem Search for HHC in likely places
15set HTMLHELP=
16where hhc /q && set HTMLHELP=hhc && goto :skiphhcsearch
17where /R ..\externals hhc > "%TEMP%\hhc.loc" 2> nul && set /P HTMLHELP= < "%TEMP%\hhc.loc" & del "%TEMP%\hhc.loc"
18if not exist "%HTMLHELP%" where /R "%ProgramFiles(x86)%" hhc > "%TEMP%\hhc.loc" 2> nul && set /P HTMLHELP= < "%TEMP%\hhc.loc" & del "%TEMP%\hhc.loc"
19if not exist "%HTMLHELP%" where /R "%ProgramFiles%" hhc > "%TEMP%\hhc.loc" 2> nul && set /P HTMLHELP= < "%TEMP%\hhc.loc" & del "%TEMP%\hhc.loc"
Steve Dowere1f68052015-07-20 21:34:45 -070020if not exist "%HTMLHELP%" (
21 echo.
22 echo.The HTML Help Workshop was not found. Set the HTMLHELP variable
23 echo.to the path to hhc.exe or download and install it from
24 echo.http://msdn.microsoft.com/en-us/library/ms669985
25 exit /B 1
26)
Zachary Ware774ac372015-04-13 12:11:40 -050027:skiphhcsearch
Zachary Ware4c9c8482015-04-13 11:59:54 -050028
29if "%DISTVERSION%" EQU "" for /f "usebackq" %%v in (`%PYTHON% tools/extensions/patchlevel.py`) do set DISTVERSION=%%v
30
31if "%BUILDDIR%" EQU "" set BUILDDIR=build
32
33rem Targets that don't require sphinx-build
34if "%1" EQU "" goto help
35if "%1" EQU "help" goto help
36if "%1" EQU "check" goto check
37if "%1" EQU "serve" goto serve
38if "%1" == "clean" (
39 rmdir /q /s %BUILDDIR%
40 goto end
41)
42
43%SPHINXBUILD% 2> nul
44if errorlevel 9009 (
45 echo.
46 echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
47 echo.installed, then set the SPHINXBUILD environment variable to point
48 echo.to the full path of the 'sphinx-build' executable. Alternatively you
49 echo.may add the Sphinx directory to PATH.
50 echo.
51 echo.If you don't have Sphinx installed, grab it from
52 echo.http://sphinx-doc.org/
Zachary Ware774ac372015-04-13 12:11:40 -050053 popd
54 exit /B 1
Zachary Ware4c9c8482015-04-13 11:59:54 -050055)
56
57rem Targets that do require sphinx-build and have their own label
58if "%1" EQU "htmlview" goto htmlview
59
60rem Everything else
61goto build
62
63:help
64echo.usage: %this% BUILDER [filename ...]
65echo.
66echo.Call %this% with the desired Sphinx builder as the first argument, e.g.
67echo.``%this% html`` or ``%this% doctest``. Interesting targets that are
68echo.always available include:
69echo.
70echo. Provided by Sphinx:
71echo. html, htmlhelp, latex, text
72echo. suspicious, linkcheck, changes, doctest
73echo. Provided by this script:
74echo. clean, check, serve, htmlview
75echo.
76echo.All arguments past the first one are passed through to sphinx-build as
77echo.filenames to build or are ignored. See README.txt in this directory or
78echo.the documentation for your version of Sphinx for more exhaustive lists
79echo.of available targets and descriptions of each.
80echo.
81echo.This script assumes that the SPHINXBUILD environment variable contains
82echo.a legitimate command for calling sphinx-build, or that sphinx-build is
83echo.on your PATH if SPHINXBUILD is not set. Options for sphinx-build can
84echo.be passed by setting the SPHINXOPTS environment variable.
85goto end
86
87:build
88if NOT "%PAPER%" == "" (
89 set SPHINXOPTS=-D latex_paper_size=%PAPER% %SPHINXOPTS%
90)
91cmd /C %SPHINXBUILD% %SPHINXOPTS% -b%1 -dbuild\doctrees . %BUILDDIR%\%*
92
93if "%1" EQU "htmlhelp" (
Zachary Ware4c9c8482015-04-13 11:59:54 -050094 cmd /C "%HTMLHELP%" build\htmlhelp\python%DISTVERSION:.=%.hhp
95 rem hhc.exe seems to always exit with code 1, reset to 0 for less than 2
96 if not errorlevel 2 cmd /C exit /b 0
97)
98
99echo.
100if errorlevel 1 (
101 echo.Build failed (exit code %ERRORLEVEL%^), check for error messages
102 echo.above. Any output will be found in %BUILDDIR%\%1
103) else (
104 echo.Build succeeded. All output should be in %BUILDDIR%\%1
105)
106goto end
107
108:htmlview
109if NOT "%2" EQU "" (
110 echo.Can't specify filenames to build with htmlview target, ignoring.
111)
112cmd /C %this% html
113
114if EXIST %BUILDDIR%\html\index.html (
115 echo.Opening %BUILDDIR%\html\index.html in the default web browser...
116 start %BUILDDIR%\html\index.html
117)
118
119goto end
120
121:check
122cmd /C %PYTHON% tools\rstlint.py -i tools
123goto end
124
125:serve
126cmd /C %PYTHON% ..\Tools\scripts\serve.py %BUILDDIR%\html
127goto end
128
129:end
130popd