| Zachary Ware | a67b97f | 2014-04-29 09:45:33 -0500 | [diff] [blame] | 1 | @echo off |
| Antoine Pitrou | 7f1e174 | 2011-02-25 14:19:48 +0000 | [diff] [blame] | 2 | setlocal |
| 3 | |
| Zachary Ware | a67b97f | 2014-04-29 09:45:33 -0500 | [diff] [blame] | 4 | pushd %~dp0 |
| 5 | |
| 6 | set this=%~n0 |
| 7 | |
| Zachary Ware | a37ff0f | 2014-04-18 15:10:40 -0500 | [diff] [blame] | 8 | if "%SPHINXBUILD%" EQU "" set SPHINXBUILD=sphinx-build |
| 9 | if "%PYTHON%" EQU "" set PYTHON=py |
| Zachary Ware | a67b97f | 2014-04-29 09:45:33 -0500 | [diff] [blame] | 10 | |
| Steve Dower | 312cef0 | 2015-02-07 22:20:48 -0800 | [diff] [blame] | 11 | if "%1" NEQ "htmlhelp" goto :skiphhcsearch |
| 12 | if exist "%HTMLHELP%" goto :skiphhcsearch |
| 13 | |
| 14 | rem Search for HHC in likely places |
| 15 | set HTMLHELP= |
| 16 | where hhc /q && set HTMLHELP=hhc && goto :skiphhcsearch |
| 17 | where /R ..\externals hhc > "%TEMP%\hhc.loc" 2> nul && set /P HTMLHELP= < "%TEMP%\hhc.loc" & del "%TEMP%\hhc.loc" |
| 18 | if not exist "%HTMLHELP%" where /R "%ProgramFiles(x86)%" hhc > "%TEMP%\hhc.loc" 2> nul && set /P HTMLHELP= < "%TEMP%\hhc.loc" & del "%TEMP%\hhc.loc" |
| 19 | if not exist "%HTMLHELP%" where /R "%ProgramFiles%" hhc > "%TEMP%\hhc.loc" 2> nul && set /P HTMLHELP= < "%TEMP%\hhc.loc" & del "%TEMP%\hhc.loc" |
| 20 | if not exist "%HTMLHELP%" echo Cannot find HHC on PATH or in externals & exit /B 1 |
| 21 | :skiphhcsearch |
| Zachary Ware | a67b97f | 2014-04-29 09:45:33 -0500 | [diff] [blame] | 22 | |
| Steve Dower | bb24087 | 2015-02-05 22:08:48 -0800 | [diff] [blame] | 23 | if "%DISTVERSION%" EQU "" for /f "usebackq" %%v in (`%PYTHON% tools/extensions/patchlevel.py`) do set DISTVERSION=%%v |
| Antoine Pitrou | 7f1e174 | 2011-02-25 14:19:48 +0000 | [diff] [blame] | 24 | |
| Zachary Ware | a67b97f | 2014-04-29 09:45:33 -0500 | [diff] [blame] | 25 | if "%BUILDDIR%" EQU "" set BUILDDIR=build |
| 26 | |
| 27 | rem Targets that don't require sphinx-build |
| Antoine Pitrou | 7f1e174 | 2011-02-25 14:19:48 +0000 | [diff] [blame] | 28 | if "%1" EQU "" goto help |
| Zachary Ware | a67b97f | 2014-04-29 09:45:33 -0500 | [diff] [blame] | 29 | if "%1" EQU "help" goto help |
| 30 | if "%1" EQU "check" goto check |
| 31 | if "%1" EQU "serve" goto serve |
| 32 | if "%1" == "clean" ( |
| 33 | rmdir /q /s %BUILDDIR% |
| 34 | goto end |
| 35 | ) |
| 36 | |
| 37 | %SPHINXBUILD% 2> nul |
| 38 | if 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 Dower | bb24087 | 2015-02-05 22:08:48 -0800 | [diff] [blame] | 47 | popd |
| 48 | exit /B 1 |
| Zachary Ware | a67b97f | 2014-04-29 09:45:33 -0500 | [diff] [blame] | 49 | ) |
| 50 | |
| 51 | rem Targets that do require sphinx-build and have their own label |
| 52 | if "%1" EQU "htmlview" goto htmlview |
| 53 | |
| 54 | rem Everything else |
| 55 | goto build |
| Antoine Pitrou | 7f1e174 | 2011-02-25 14:19:48 +0000 | [diff] [blame] | 56 | |
| 57 | :help |
| Zachary Ware | a67b97f | 2014-04-29 09:45:33 -0500 | [diff] [blame] | 58 | echo.usage: %this% BUILDER [filename ...] |
| Antoine Pitrou | 7f1e174 | 2011-02-25 14:19:48 +0000 | [diff] [blame] | 59 | echo. |
| Zachary Ware | a67b97f | 2014-04-29 09:45:33 -0500 | [diff] [blame] | 60 | echo.Call %this% with the desired Sphinx builder as the first argument, e.g. |
| 61 | echo.``%this% html`` or ``%this% doctest``. Interesting targets that are |
| 62 | echo.always available include: |
| Antoine Pitrou | 7f1e174 | 2011-02-25 14:19:48 +0000 | [diff] [blame] | 63 | echo. |
| Zachary Ware | a67b97f | 2014-04-29 09:45:33 -0500 | [diff] [blame] | 64 | echo. Provided by Sphinx: |
| 65 | echo. html, htmlhelp, latex, text |
| 66 | echo. suspicious, linkcheck, changes, doctest |
| 67 | echo. Provided by this script: |
| 68 | echo. clean, check, serve, htmlview |
| 69 | echo. |
| 70 | echo.All arguments past the first one are passed through to sphinx-build as |
| 71 | echo.filenames to build or are ignored. See README.txt in this directory or |
| 72 | echo.the documentation for your version of Sphinx for more exhaustive lists |
| 73 | echo.of available targets and descriptions of each. |
| 74 | echo. |
| 75 | echo.This script assumes that the SPHINXBUILD environment variable contains |
| 76 | echo.a legitimate command for calling sphinx-build, or that sphinx-build is |
| 77 | echo.on your PATH if SPHINXBUILD is not set. Options for sphinx-build can |
| 78 | echo.be passed by setting the SPHINXOPTS environment variable. |
| Antoine Pitrou | 7f1e174 | 2011-02-25 14:19:48 +0000 | [diff] [blame] | 79 | goto end |
| 80 | |
| Antoine Pitrou | 7f1e174 | 2011-02-25 14:19:48 +0000 | [diff] [blame] | 81 | :build |
| Zachary Ware | a67b97f | 2014-04-29 09:45:33 -0500 | [diff] [blame] | 82 | if NOT "%PAPER%" == "" ( |
| 83 | set SPHINXOPTS=-D latex_paper_size=%PAPER% %SPHINXOPTS% |
| 84 | ) |
| 85 | cmd /C %SPHINXBUILD% %SPHINXOPTS% -b%1 -dbuild\doctrees . %BUILDDIR%\%* |
| 86 | |
| 87 | if "%1" EQU "htmlhelp" ( |
| Zachary Ware | 5989511 | 2014-06-10 12:07:45 -0500 | [diff] [blame] | 88 | 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 Ware | a67b97f | 2014-04-29 09:45:33 -0500 | [diff] [blame] | 97 | 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 | |
| 102 | echo. |
| 103 | if 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 | ) |
| 109 | goto end |
| 110 | |
| 111 | :htmlview |
| 112 | if NOT "%2" EQU "" ( |
| 113 | echo.Can't specify filenames to build with htmlview target, ignoring. |
| 114 | ) |
| 115 | cmd /C %this% html |
| 116 | |
| 117 | if 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 | |
| 122 | goto end |
| 123 | |
| 124 | :check |
| 125 | cmd /C %PYTHON% tools\rstlint.py -i tools |
| 126 | goto end |
| 127 | |
| 128 | :serve |
| 129 | cmd /C %PYTHON% ..\Tools\scripts\serve.py %BUILDDIR%\html |
| Antoine Pitrou | 7f1e174 | 2011-02-25 14:19:48 +0000 | [diff] [blame] | 130 | goto end |
| 131 | |
| 132 | :end |
| Zachary Ware | a67b97f | 2014-04-29 09:45:33 -0500 | [diff] [blame] | 133 | popd |