blob: 3f201de1db796c9dc657c0e4e4fde44606863fa2 [file] [log] [blame]
Zachary Ware3f8f16d2017-06-10 23:04:36 -05001@echo off
2setlocal
3
4pushd %~dp0
5
6set this=%~n0
7
Stefan Grönkef1502d02017-09-25 18:58:10 +02008call ..\PCbuild\find_python.bat %PYTHON%
Steve Dowerd5cd21d2017-09-04 14:26:27 -07009if not defined SPHINXBUILD if defined PYTHON (
10 %PYTHON% -c "import sphinx" > nul 2> nul
11 if errorlevel 1 (
Steve Dower68d663c2017-07-17 11:15:48 +020012 echo Installing sphinx with %PYTHON%
Steve Dowerd5cd21d2017-09-04 14:26:27 -070013 %PYTHON% -m pip install sphinx
Steve Dower68d663c2017-07-17 11:15:48 +020014 if errorlevel 1 exit /B
15 )
Steve Dowerd5cd21d2017-09-04 14:26:27 -070016 set SPHINXBUILD=%PYTHON% -c "import sphinx, sys; sys.argv[0] = 'sphinx-build'; sphinx.main()"
Steve Dower68d663c2017-07-17 11:15:48 +020017)
18
Steve Dower5fcd5e62017-09-06 10:01:38 -070019if not defined BLURB if defined PYTHON (
20 %PYTHON% -c "import blurb" > nul 2> nul
21 if errorlevel 1 (
22 echo Installing blurb with %PYTHON%
23 %PYTHON% -m pip install blurb
24 if errorlevel 1 exit /B
25 )
26 set BLURB=%PYTHON% -m blurb
27)
28
Steve Dowerd5cd21d2017-09-04 14:26:27 -070029if not defined PYTHON set PYTHON=py
30if not defined SPHINXBUILD set SPHINXBUILD=sphinx-build
Steve Dower5fcd5e62017-09-06 10:01:38 -070031if not defined BLURB set BLURB=blurb
Zachary Ware3f8f16d2017-06-10 23:04:36 -050032
33if "%1" NEQ "htmlhelp" goto :skiphhcsearch
34if exist "%HTMLHELP%" goto :skiphhcsearch
35
36rem Search for HHC in likely places
37set HTMLHELP=
38where hhc /q && set HTMLHELP=hhc && goto :skiphhcsearch
39where /R ..\externals hhc > "%TEMP%\hhc.loc" 2> nul && set /P HTMLHELP= < "%TEMP%\hhc.loc" & del "%TEMP%\hhc.loc"
40if not exist "%HTMLHELP%" where /R "%ProgramFiles(x86)%" hhc > "%TEMP%\hhc.loc" 2> nul && set /P HTMLHELP= < "%TEMP%\hhc.loc" & del "%TEMP%\hhc.loc"
41if not exist "%HTMLHELP%" where /R "%ProgramFiles%" hhc > "%TEMP%\hhc.loc" 2> nul && set /P HTMLHELP= < "%TEMP%\hhc.loc" & del "%TEMP%\hhc.loc"
42if not exist "%HTMLHELP%" (
43 echo.
44 echo.The HTML Help Workshop was not found. Set the HTMLHELP variable
45 echo.to the path to hhc.exe or download and install it from
46 echo.http://msdn.microsoft.com/en-us/library/ms669985
47 exit /B 1
48)
49:skiphhcsearch
50
51if "%DISTVERSION%" EQU "" for /f "usebackq" %%v in (`%PYTHON% tools/extensions/patchlevel.py`) do set DISTVERSION=%%v
52
53if "%BUILDDIR%" EQU "" set BUILDDIR=build
54
55rem Targets that don't require sphinx-build
56if "%1" EQU "" goto help
57if "%1" EQU "help" goto help
58if "%1" EQU "check" goto check
59if "%1" EQU "serve" goto serve
60if "%1" == "clean" (
Steve Dowera4bb58f2017-09-19 12:31:28 -070061 rmdir /q /s "%BUILDDIR%"
Zachary Ware3f8f16d2017-06-10 23:04:36 -050062 goto end
63)
64
65%SPHINXBUILD% >nul 2> nul
66if errorlevel 9009 (
67 echo.
68 echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
69 echo.installed, then set the SPHINXBUILD environment variable to point
70 echo.to the full path of the 'sphinx-build' executable. Alternatively you
71 echo.may add the Sphinx directory to PATH.
72 echo.
73 echo.If you don't have Sphinx installed, grab it from
74 echo.http://sphinx-doc.org/
75 popd
76 exit /B 1
77)
78
79rem Targets that do require sphinx-build and have their own label
80if "%1" EQU "htmlview" goto htmlview
81
82rem Everything else
83goto build
84
85:help
86echo.usage: %this% BUILDER [filename ...]
87echo.
88echo.Call %this% with the desired Sphinx builder as the first argument, e.g.
89echo.``%this% html`` or ``%this% doctest``. Interesting targets that are
90echo.always available include:
91echo.
92echo. Provided by Sphinx:
93echo. html, htmlhelp, latex, text
94echo. suspicious, linkcheck, changes, doctest
95echo. Provided by this script:
96echo. clean, check, serve, htmlview
97echo.
98echo.All arguments past the first one are passed through to sphinx-build as
99echo.filenames to build or are ignored. See README.rst in this directory or
100echo.the documentation for your version of Sphinx for more exhaustive lists
101echo.of available targets and descriptions of each.
102echo.
103echo.This script assumes that the SPHINXBUILD environment variable contains
104echo.a legitimate command for calling sphinx-build, or that sphinx-build is
105echo.on your PATH if SPHINXBUILD is not set. Options for sphinx-build can
106echo.be passed by setting the SPHINXOPTS environment variable.
107goto end
108
109:build
Steve Dowera4bb58f2017-09-19 12:31:28 -0700110if not exist "%BUILDDIR%" mkdir "%BUILDDIR%"
111
Steve Dower5fcd5e62017-09-06 10:01:38 -0700112if exist ..\Misc\NEWS (
113 echo.Copying Misc\NEWS to build\NEWS
114 copy ..\Misc\NEWS build\NEWS > nul
115) else if exist ..\Misc\NEWS.D (
116 if defined BLURB (
117 echo.Merging Misc/NEWS with %BLURB%
118 %BLURB% merge -f build\NEWS
119 ) else (
120 echo.No Misc/NEWS file and Blurb is not available.
121 exit /B 1
122 )
123)
124
Zachary Ware3f8f16d2017-06-10 23:04:36 -0500125if NOT "%PAPER%" == "" (
126 set SPHINXOPTS=-D latex_elements.papersize=%PAPER% %SPHINXOPTS%
127)
Steve Dowera4bb58f2017-09-19 12:31:28 -0700128cmd /S /C "%SPHINXBUILD% %SPHINXOPTS% -b%1 -dbuild\doctrees . "%BUILDDIR%\%1" %2 %3 %4 %5 %6 %7 %8 %9"
Zachary Ware3f8f16d2017-06-10 23:04:36 -0500129
130if "%1" EQU "htmlhelp" (
Steve Dowera4bb58f2017-09-19 12:31:28 -0700131 "%HTMLHELP%" "%BUILDDIR%\htmlhelp\python%DISTVERSION:.=%.hhp"
Zachary Ware3f8f16d2017-06-10 23:04:36 -0500132 rem hhc.exe seems to always exit with code 1, reset to 0 for less than 2
133 if not errorlevel 2 cmd /C exit /b 0
134)
135
136echo.
137if errorlevel 1 (
138 echo.Build failed (exit code %ERRORLEVEL%^), check for error messages
139 echo.above. Any output will be found in %BUILDDIR%\%1
140) else (
141 echo.Build succeeded. All output should be in %BUILDDIR%\%1
142)
143goto end
144
145:htmlview
146if NOT "%2" EQU "" (
147 echo.Can't specify filenames to build with htmlview target, ignoring.
148)
149cmd /C %this% html
150
Steve Dowera4bb58f2017-09-19 12:31:28 -0700151if EXIST "%BUILDDIR%\html\index.html" (
152 echo.Opening "%BUILDDIR%\html\index.html" in the default web browser...
153 start "%BUILDDIR%\html\index.html"
Zachary Ware3f8f16d2017-06-10 23:04:36 -0500154)
155
156goto end
157
158:check
Steve Dowera4bb58f2017-09-19 12:31:28 -0700159cmd /S /C "%PYTHON% tools\rstlint.py -i tools"
Zachary Ware3f8f16d2017-06-10 23:04:36 -0500160goto end
161
162:serve
Steve Dowera4bb58f2017-09-19 12:31:28 -0700163cmd /S /C "%PYTHON% ..\Tools\scripts\serve.py "%BUILDDIR%\html""
Zachary Ware3f8f16d2017-06-10 23:04:36 -0500164goto end
165
166:end
167popd