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