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