blob: 6aae34a7e2815defc04c6410744574d021a5588f [file] [log] [blame]
Zachary Warea67b97f2014-04-29 09:45:33 -05001@echo off
Antoine Pitrou7f1e1742011-02-25 14:19:48 +00002setlocal
3
Zachary Warea67b97f2014-04-29 09:45:33 -05004pushd %~dp0
5
6set this=%~n0
7
Zachary Warea37ff0f2014-04-18 15:10:40 -05008if "%SPHINXBUILD%" EQU "" set SPHINXBUILD=sphinx-build
9if "%PYTHON%" EQU "" set PYTHON=py
Zachary Warea67b97f2014-04-29 09:45:33 -050010
Steve Dower312cef02015-02-07 22:20:48 -080011if "%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"
20if not exist "%HTMLHELP%" echo Cannot find HHC on PATH or in externals & exit /B 1
21:skiphhcsearch
Zachary Warea67b97f2014-04-29 09:45:33 -050022
Steve Dowerbb240872015-02-05 22:08:48 -080023if "%DISTVERSION%" EQU "" for /f "usebackq" %%v in (`%PYTHON% tools/extensions/patchlevel.py`) do set DISTVERSION=%%v
Antoine Pitrou7f1e1742011-02-25 14:19:48 +000024
Zachary Warea67b97f2014-04-29 09:45:33 -050025if "%BUILDDIR%" EQU "" set BUILDDIR=build
26
27rem Targets that don't require sphinx-build
Antoine Pitrou7f1e1742011-02-25 14:19:48 +000028if "%1" EQU "" goto help
Zachary Warea67b97f2014-04-29 09:45:33 -050029if "%1" EQU "help" goto help
30if "%1" EQU "check" goto check
31if "%1" EQU "serve" goto serve
32if "%1" == "clean" (
33 rmdir /q /s %BUILDDIR%
34 goto end
35)
36
37%SPHINXBUILD% 2> nul
38if errorlevel 9009 (
39 echo.
40 echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
41 echo.installed, then set the SPHINXBUILD environment variable to point
42 echo.to the full path of the 'sphinx-build' executable. Alternatively you
43 echo.may add the Sphinx directory to PATH.
44 echo.
45 echo.If you don't have Sphinx installed, grab it from
46 echo.http://sphinx-doc.org/
Steve Dowerbb240872015-02-05 22:08:48 -080047 popd
48 exit /B 1
Zachary Warea67b97f2014-04-29 09:45:33 -050049)
50
51rem Targets that do require sphinx-build and have their own label
52if "%1" EQU "htmlview" goto htmlview
53
54rem Everything else
55goto build
Antoine Pitrou7f1e1742011-02-25 14:19:48 +000056
57:help
Zachary Warea67b97f2014-04-29 09:45:33 -050058echo.usage: %this% BUILDER [filename ...]
Antoine Pitrou7f1e1742011-02-25 14:19:48 +000059echo.
Zachary Warea67b97f2014-04-29 09:45:33 -050060echo.Call %this% with the desired Sphinx builder as the first argument, e.g.
61echo.``%this% html`` or ``%this% doctest``. Interesting targets that are
62echo.always available include:
Antoine Pitrou7f1e1742011-02-25 14:19:48 +000063echo.
Zachary Warea67b97f2014-04-29 09:45:33 -050064echo. Provided by Sphinx:
65echo. html, htmlhelp, latex, text
66echo. suspicious, linkcheck, changes, doctest
67echo. Provided by this script:
68echo. clean, check, serve, htmlview
69echo.
70echo.All arguments past the first one are passed through to sphinx-build as
71echo.filenames to build or are ignored. See README.txt in this directory or
72echo.the documentation for your version of Sphinx for more exhaustive lists
73echo.of available targets and descriptions of each.
74echo.
75echo.This script assumes that the SPHINXBUILD environment variable contains
76echo.a legitimate command for calling sphinx-build, or that sphinx-build is
77echo.on your PATH if SPHINXBUILD is not set. Options for sphinx-build can
78echo.be passed by setting the SPHINXOPTS environment variable.
Antoine Pitrou7f1e1742011-02-25 14:19:48 +000079goto end
80
Antoine Pitrou7f1e1742011-02-25 14:19:48 +000081:build
Zachary Warea67b97f2014-04-29 09:45:33 -050082if NOT "%PAPER%" == "" (
83 set SPHINXOPTS=-D latex_paper_size=%PAPER% %SPHINXOPTS%
84)
85cmd /C %SPHINXBUILD% %SPHINXOPTS% -b%1 -dbuild\doctrees . %BUILDDIR%\%*
86
87if "%1" EQU "htmlhelp" (
Zachary Ware59895112014-06-10 12:07:45 -050088 if not exist "%HTMLHELP%" (
89 echo.
90 echo.The HTML Help Workshop was not found. Set the HTMLHELP variable
91 echo.to the path to hhc.exe or download and install it from
92 echo.http://msdn.microsoft.com/en-us/library/ms669985
93 rem Set errorlevel to 1 and exit
94 cmd /C exit /b 1
95 goto end
96 )
Zachary Warea67b97f2014-04-29 09:45:33 -050097 cmd /C "%HTMLHELP%" build\htmlhelp\python%DISTVERSION:.=%.hhp
98 rem hhc.exe seems to always exit with code 1, reset to 0 for less than 2
99 if not errorlevel 2 cmd /C exit /b 0
100)
101
102echo.
103if errorlevel 1 (
104 echo.Build failed (exit code %ERRORLEVEL%^), check for error messages
105 echo.above. Any output will be found in %BUILDDIR%\%1
106) else (
107 echo.Build succeeded. All output should be in %BUILDDIR%\%1
108)
109goto end
110
111:htmlview
112if NOT "%2" EQU "" (
113 echo.Can't specify filenames to build with htmlview target, ignoring.
114)
115cmd /C %this% html
116
117if EXIST %BUILDDIR%\html\index.html (
118 echo.Opening %BUILDDIR%\html\index.html in the default web browser...
119 start %BUILDDIR%\html\index.html
120)
121
122goto end
123
124:check
125cmd /C %PYTHON% tools\rstlint.py -i tools
126goto end
127
128:serve
129cmd /C %PYTHON% ..\Tools\scripts\serve.py %BUILDDIR%\html
Antoine Pitrou7f1e1742011-02-25 14:19:48 +0000130goto end
131
132:end
Zachary Warea67b97f2014-04-29 09:45:33 -0500133popd