update_external_sources.bat revision e13dd83fa2357cd6d55b20019668b3222dbc43f2
1@echo off
2REM Update source for glslang, LunarGLASS, spirv-tools
3
4setlocal EnableDelayedExpansion
5set errorCode=0
6set BUILD_DIR=%~dp0
7set BASE_DIR=%BUILD_DIR%..
8set GLSLANG_DIR=%BASE_DIR%\glslang
9set LUNARGLASS_DIR=%BASE_DIR%\LunarGLASS
10set SPIRV_TOOLS_DIR=%BASE_DIR%\spirv-tools
11
12REM // ======== Parameter parsing ======== //
13
14   if "%1" == "" (
15      echo usage: update_external_sources.bat [options]
16      echo.
17      echo Available options:
18      echo   --sync-glslang      just pull glslang_revision
19      echo   --sync-LunarGLASS   just pull LunarGLASS_revision
20	  echo   --sync-spirv-tools  just pull spirv-tools_revision
21      echo   --build-glslang     pulls glslang_revision, configures CMake, builds Release and Debug
22      echo   --build-LunarGLASS  pulls LunarGLASS_revision, configures CMake, builds Release and Debug
23      echo   --build-spirv-tools pulls spirv-tools_revision, configures CMake, builds Release and Debug
24      echo   --all               sync and build glslang, LunarGLASS, spirv-tools
25      goto:finish
26   )
27
28   set sync-glslang=0
29   set sync-LunarGLASS=0
30   set sync-spirv-tools=0
31   set build-glslang=0
32   set build-LunarGLASS=0
33   set build-spirv-tools=0
34   set check-glslang-build-dependencies=0
35   set check-LunarGLASS-fetch-dependencies=0
36   set check-LunarGLASS-build-dependencies=0
37
38   :parameterLoop
39
40      if "%1"=="" goto:parameterContinue
41
42      if "%1" == "--sync-glslang" (
43         set sync-glslang=1
44         shift
45         goto:parameterLoop
46      )
47
48      if "%1" == "--sync-LunarGLASS" (
49         set sync-LunarGLASS=1
50         set check-LunarGLASS-fetch-dependencies=1
51         shift
52         goto:parameterLoop
53      )
54
55	  if "%1" == "--sync-spirv-tools" (
56         set sync-spirv-tools=1
57         shift
58         goto:parameterLoop
59      )
60
61      if "%1" == "--build-glslang" (
62         set sync-glslang=1
63         set check-glslang-build-dependencies=1
64         set build-glslang=1
65         shift
66         goto:parameterLoop
67      )
68
69      if "%1" == "--build-LunarGLASS" (
70         set sync-LunarGLASS=1
71         set check-LunarGLASS-fetch-dependencies=1
72         set check-LunarGLASS-build-dependencies=1
73         set build-LunarGLASS=1
74         shift
75         goto:parameterLoop
76      )
77
78	  if "%1" == "--build-spirv-tools" (
79         set sync-spirv-tools=1
80		 REM glslang has the same needs as spirv-tools
81         set check-glslang-build-dependencies=1
82         set build-spirv-tools=1
83         shift
84         goto:parameterLoop
85      )
86
87      if "%1" == "--all" (
88         set sync-glslang=1
89         set sync-LunarGLASS=1
90         set sync-spirv-tools=1
91         set build-glslang=1
92         set build-LunarGLASS=1
93         set build-spirv-tools=1
94         set check-LunarGLASS-fetch-dependencies=1
95         set check-glslang-build-dependencies=1
96         set check-LunarGLASS-build-dependencies=1
97         shift
98         goto:parameterLoop
99      )
100
101      echo Unrecognized options "%1"
102      goto:error
103
104   :parameterContinue
105
106REM // ======== end Parameter parsing ======== //
107
108
109REM // ======== Dependency checking ======== //
110   REM git is required for all paths
111   for %%X in (git.exe) do (set FOUND=%%~$PATH:X)
112   if not defined FOUND (
113      echo Dependency check failed:
114      echo   git.exe not found
115      echo   Git for Windows can be downloaded here:  https://git-scm.com/download/win
116      echo   Install and ensure git.exe makes it into your PATH
117      set errorCode=1
118   )
119
120   if %check-LunarGLASS-fetch-dependencies% equ 1 (
121      for %%X in (svn.exe) do (set FOUND=%%~$PATH:X)
122      if not defined FOUND (
123         echo Dependency check failed:
124         echo   svn.exe not found
125         echo   Get Subversion for Windows here:  http://sourceforge.net/projects/win32svn/
126         echo   Install and ensure svn.exe makes it into your PATH, default is "C:\Program Files (x86)\Subversion\bin"
127         set errorCode=1
128      )
129
130      for %%X in (wget.exe) do (set FOUND=%%~$PATH:X)
131      if not defined FOUND (
132         echo Dependency check failed:
133         echo   wget.exe not found
134         echo   Get wget for Windows here:  http://gnuwin32.sourceforge.net/packages/wget.htm
135         echo   Easiest to select "Complete package, except sources" link which will install and setup PATH
136         echo   Install and ensure each makes it into your PATH, default is "C:\Program Files (x86)\GnuWin32\bin"
137         set errorCode=1
138      )
139
140      for %%X in (gzip.exe) do (set FOUND=%%~$PATH:X)
141      if not defined FOUND (
142         echo Dependency check failed:
143         echo   gzip.exe not found
144         echo   Get gzip for Windows here:  http://gnuwin32.sourceforge.net/packages/gzip.htm
145         echo   Easiest to select "Complete package, except sources" link which will install and setup PATH
146         echo   Install and ensure each makes it into your PATH, default is "C:\Program Files (x86)\GnuWin32\bin"
147         set errorCode=1
148      )
149
150      for %%X in (tar.exe) do (set FOUND=%%~$PATH:X)
151      if not defined FOUND (
152         echo Dependency check failed:
153         echo   tar.exe not found
154         echo   Get tar for Windows here:  http://gnuwin32.sourceforge.net/packages/gtar.htm
155         echo   Easiest to select Binaries/Setup link which will install and setup PATH
156         echo   Install and ensure each makes it into your PATH, default is "C:\Program Files (x86)\GnuWin32\bin"
157         set errorCode=1
158      )
159   )
160
161   if %check-glslang-build-dependencies% equ 1 (
162      for %%X in (cmake.exe) do (set FOUND=%%~$PATH:X)
163      if not defined FOUND (
164         echo Dependency check failed:
165         echo   cmake.exe not found
166         echo   Get CNake 2.8 for Windows here:  http://www.cmake.org/cmake/resources/software.html
167         echo   Install and ensure each makes it into your PATH, default is "C:\Program Files (x86)\CMake\bin"
168         set errorCode=1
169      )
170   )
171
172   if %check-LunarGLASS-build-dependencies% equ 1 (
173      for %%X in (python.exe) do (set FOUND=%%~$PATH:X)
174      if not defined FOUND (
175         echo Dependency check failed:
176         echo   python.exe not found
177         echo   Get python 2.7x for Windows here:  http://www.python.org/download/releases/2.7.6/
178         echo   Install and ensure each makes it into your PATH, default is "C:\Python27"
179         set errorCode=1
180      )
181
182      for %%X in (cmake.exe) do (set FOUND=%%~$PATH:X)
183      if not defined FOUND (
184         echo Dependency check failed:
185         echo   cmake.exe not found
186         echo   Get CNake 2.8 for Windows here:  http://www.cmake.org/cmake/resources/software.html
187         echo   Install and ensure each makes it into your PATH, default is "C:\Program Files (x86)\CMake\bin"
188         set errorCode=1
189      )
190   )
191
192   REM goto:main
193
194REM // ======== end Dependency checking ======== //
195
196:main
197
198if %errorCode% neq 0 (goto:error)
199
200REM Read the target versions from external file, which is shared with Linux script
201if not exist LunarGLASS_revision (
202   echo.
203   echo Missing LunarGLASS_revision file!  Place it next to this script with target version in it.
204   set errorCode=1
205   goto:error
206)
207
208if not exist glslang_revision (
209   echo.
210   echo Missing glslang_revision file!  Place it next to this script with target version in it.
211   set errorCode=1
212   goto:error
213)
214
215if not exist spirv-tools_revision (
216   echo.
217   echo Missing spirv-tools_revision file!  Place it next to this script with target version in it.
218   set errorCode=1
219   goto:error
220)
221
222set /p LUNARGLASS_REVISION= < LunarGLASS_revision
223set /p GLSLANG_REVISION= < glslang_revision
224set /p SPIRV_TOOLS_REVISION= < spirv-tools_revision
225echo LUNARGLASS_REVISION=%LUNARGLASS_REVISION%
226echo GLSLANG_REVISION=%GLSLANG_REVISION%
227echo SPIRV_TOOLS_REVISION=%SPIRV_TOOLS_REVISION%
228
229set /p LUNARGLASS_REVISION_R32= < LunarGLASS_revision_R32
230echo LUNARGLASS_REVISION_R32=%LUNARGLASS_REVISION_R32%
231
232echo Creating and/or updating glslang, LunarGLASS, spirv-tools in %BASE_DIR%
233
234if %sync-glslang% equ 1 (
235   rd /S /Q %GLSLANG_DIR%
236   if not exist %GLSLANG_DIR% (
237      call:create_glslang
238   )
239   if %errorCode% neq 0 (goto:error)
240   call:update_glslang
241   if %errorCode% neq 0 (goto:error)
242)
243
244if %sync-LunarGLASS% equ 1 (
245   rd /S /Q %LUNARGLASS_DIR%
246   if not exist %LUNARGLASS_DIR% (
247      call:create_LunarGLASS
248   )
249   if %errorCode% neq 0 (goto:error)
250   call:update_LunarGLASS
251   if %errorCode% neq 0 (goto:error)
252)
253
254if %sync-spirv-tools% equ 1 (
255   rd /S /Q %SPIRV_TOOLS_DIR%
256   if %errorlevel% neq 0 (goto:error)
257   if not exist %SPIRV_TOOLS_DIR% (
258      call:create_spirv-tools
259   )
260   if %errorCode% neq 0 (goto:error)
261   call:update_spirv-tools
262   if %errorCode% neq 0 (goto:error)
263)
264
265if %build-glslang% equ 1 (
266   call:build_glslang
267   if %errorCode% neq 0 (goto:error)
268)
269
270if %build-LunarGLASS% equ 1 (
271   call:build_LunarGLASS
272   if %errorCode% neq 0 (goto:error)
273)
274
275if %build-spirv-tools% equ 1 (
276   call:build_spirv-tools
277   if %errorCode% neq 0 (goto:error)
278)
279
280echo.
281echo Exiting
282goto:finish
283
284:error
285echo.
286echo Halting due to error
287goto:finish
288
289:finish
290if not "%cd%\" == "%BUILD_DIR%" ( cd %BUILD_DIR% )
291endlocal
292goto:eof
293
294
295
296REM // ======== Functions ======== //
297
298:create_glslang
299   echo.
300   echo Creating local glslang repository %GLSLANG_DIR%)
301   mkdir %GLSLANG_DIR%
302   cd %GLSLANG_DIR%
303   git clone git@gitlab.khronos.org:GLSL/glslang.git .
304   git checkout %GLSLANG_REVISION%
305   if not exist %GLSLANG_DIR%\SPIRV (
306      echo glslang source download failed!
307      set errorCode=1
308   )
309goto:eof
310
311:update_glslang
312   echo.
313   echo Updating %GLSLANG_DIR%
314   cd %GLSLANG_DIR%
315   git fetch --all
316   git checkout %GLSLANG_REVISION%
317goto:eof
318
319:create_LunarGLASS
320   REM Windows complains if it can't find the directory below, no need to call
321   REM rd /S /Q %LUNARGLASS_DIR%
322   echo.
323   echo Creating local LunarGLASS repository %LUNARGLASS_DIR%)
324   mkdir %LUNARGLASS_DIR%
325   cd %LUNARGLASS_DIR%
326   git clone https://github.com/LunarG/LunarGLASS.git .
327   git checkout %LUNARGLASS_REVISION%
328   cd Core\LLVM
329   echo.
330   echo Downloading LLVM archive...
331   wget http://llvm.org/releases/3.4/llvm-3.4.src.tar.gz
332   REM tar on windows can't filter through gzip, so the below line doesn't work
333   REM tar --gzip -xf llvm-3.4.src.tar.gz
334   echo.
335   echo Unzipping the archive...
336   echo gzip --decompress --verbose --keep llvm-3.4.src.tar.gz
337   gzip --decompress --verbose --keep llvm-3.4.src.tar.gz
338   echo.
339   echo Extracting the archive... (this is slow)
340   echo tar -xf llvm-3.4.src.tar
341   tar -xf llvm-3.4.src.tar
342   if not exist %LUNARGLASS_DIR%\Core\LLVM\llvm-3.4\lib (
343      echo .
344      echo LLVM source download failed!
345      echo Delete LunarGLASS directory and try again
346      set errorCode=1
347      goto:eof
348   )
349   echo.
350   echo Syncing LunarGLASS source...
351   cd %LUNARGLASS_DIR%
352   REM put back the LunarGLASS github versions of some LLVM files
353   git checkout -f .
354   REM overwrite with private gitlab versions of some files
355   svn checkout -r %LUNARGLASS_REVISION_R32% --force https://cvs.khronos.org/svn/repos/SPIRV/trunk/LunarGLASS/ .
356   svn revert -R .
357   if not exist %LUNARGLASS_DIR%\Frontends\SPIRV (
358      echo.
359      echo LunarGLASS source download failed!
360      set errorCode=1
361   )
362goto:eof
363
364:update_LunarGLASS
365   echo.
366   echo Updating %LUNARGLASS_DIR%
367   cd %LUNARGLASS_DIR%
368   git fetch --all
369   git checkout -f %LUNARGLASS_REVISION% .
370   if not exist %LUNARGLASS_DIR%\.svn (
371      svn checkout -r %LUNARGLASS_REVISION_R32% --force https://cvs.khronos.org/svn/repos/SPIRV/trunk/LunarGLASS/ .
372   )
373   svn update -r %LUNARGLASS_REVISION_R325
374   svn revert -R .
375goto:eof
376
377:create_spirv-tools
378   echo.
379   echo Creating local spirv-tools repository %SPIRV_TOOLS_DIR%)
380   mkdir %SPIRV_TOOLS_DIR%
381   cd %SPIRV_TOOLS_DIR%
382   git clone git@gitlab.khronos.org:spirv/spirv-tools.git .
383   git checkout %SPIRV_TOOLS_REVISION%
384   if not exist %SPIRV_TOOLS_DIR%\source (
385      echo spirv-tools source download failed!
386      set errorCode=1
387   )
388goto:eof
389
390:update_spirv-tools
391   echo.
392   echo Updating %SPIRV_TOOLS_DIR%
393   cd %SPIRV_TOOLS_DIR%
394   git fetch --all
395   git checkout %SPIRV_TOOLS_REVISION%
396goto:eof
397
398:build_glslang
399   echo.
400   echo Building %GLSLANG_DIR%
401   cd  %GLSLANG_DIR%
402   mkdir build
403   set GLSLANG_BUILD_DIR=%GLSLANG_DIR%\build
404   cd %GLSLANG_BUILD_DIR%
405   cmake -G"Visual Studio 12 2013 Win64" -DCMAKE_INSTALL_PREFIX=install ..
406   msbuild INSTALL.vcxproj /p:Platform=x64 /p:Configuration=Debug
407   REM Check for existence of one lib, even though we should check for all results
408   if not exist %GLSLANG_BUILD_DIR%\glslang\Debug\glslang.lib (
409      echo.
410      echo glslang Debug build failed!
411      set errorCode=1
412   )
413   msbuild INSTALL.vcxproj /p:Platform=x64 /p:Configuration=Release
414   REM Check for existence of one lib, even though we should check for all results
415   if not exist %GLSLANG_BUILD_DIR%\glslang\Release\glslang.lib (
416      echo.
417      echo glslang Release build failed!
418      set errorCode=1
419   )
420goto:eof
421
422:build_LunarGLASS
423   echo.
424   echo Building %LUNARGLASS_DIR%
425   set LLVM_DIR=%LUNARGLASS_DIR%\Core\LLVM\llvm-3.4
426   cd %LLVM_DIR%
427   mkdir build
428   set LLVM_BUILD_DIR=%LLVM_DIR%\build
429   cd %LLVM_BUILD_DIR%
430   cmake -G"Visual Studio 12 2013 Win64" -DCMAKE_INSTALL_PREFIX=install ..
431   msbuild INSTALL.vcxproj /p:Platform=x64 /p:Configuration=Release
432   REM Check for existence of one lib, even though we should check for all results
433   if not exist %LLVM_BUILD_DIR%\lib\Release\LLVMCore.lib (
434      echo.
435      echo LLVM Release build failed!
436      set errorCode=1
437      goto:eof
438   )
439   REM disable Debug build of LLVM until LunarGLASS cmake files are updated to
440   REM handle Debug and Release builds of glslang simultaneously, instead of
441   REM whatever last lands in "./build/install"
442   REM   msbuild INSTALL.vcxproj /p:Platform=x64 /p:Configuration=Debug
443   REM Check for existence of one lib, even though we should check for all results
444   REM   if not exist %LLVM_BUILD_DIR%\lib\Debug\LLVMCore.lib (
445   REM      echo.
446   REM      echo LLVM Debug build failed!
447   REM      set errorCode=1
448   REM      goto:eof
449   REM   )
450   cd %LUNARGLASS_DIR%
451   mkdir build
452   set LUNARGLASS_BUILD_DIR=%LUNARGLASS_DIR%\build
453   cd %LUNARGLASS_BUILD_DIR%
454   cmake -G"Visual Studio 12 2013 Win64" -DCMAKE_INSTALL_PREFIX=install ..
455   msbuild INSTALL.vcxproj /p:Platform=x64 /p:Configuration=Release
456   REM Check for existence of one lib, even though we should check for all results
457   if not exist %LUNARGLASS_BUILD_DIR%\Core\Release\core.lib (
458      echo.
459      echo LunarGLASS build failed!
460      set errorCode=1
461      goto:eof
462   )
463   REM disable Debug build of LunarGLASS until its cmake file can be updated to
464   REM handle Debug and Release builds of glslang simultaneously, instead of
465   REM whatever last lands in "./build/install"
466   REM   msbuild INSTALL.vcxproj /p:Platform=x64 /p:Configuration=Debug
467   REM Check for existence of one lib, even though we should check for all results
468   REM  if not exist %LUNARGLASS_BUILD_DIR%\Core\Debug\core.lib (
469   REM     echo.
470   REM     echo LunarGLASS build failed!
471   REM     set errorCode=1
472   REM     goto:eof
473   REM  )
474goto:eof
475
476:build_spirv-tools
477   echo.
478   echo Building %SPIRV_TOOLS_DIR%
479   cd  %SPIRV_TOOLS_DIR%
480   mkdir build
481   set SPIRV_TOOLS_BUILD_DIR=%SPIRV_TOOLS_DIR%\build
482   cd %SPIRV_TOOLS_BUILD_DIR%
483   cmake -G "Visual Studio 12 2013 Win64" ..
484   msbuild ALL_BUILD.vcxproj /p:Platform=x64 /p:Configuration=Debug
485   REM Check for existence of one lib, even though we should check for all results
486   if not exist %SPIRV_TOOLS_BUILD_DIR%\Debug\SPIRV-Tools.lib (
487      echo.
488      echo spirv-tools Debug build failed!
489      set errorCode=1
490   )
491   msbuild ALL_BUILD.vcxproj /p:Platform=x64 /p:Configuration=Release
492   REM Check for existence of one lib, even though we should check for all results
493   if not exist %SPIRV_TOOLS_BUILD_DIR%\Release\SPIRV-Tools.lib (
494      echo.
495      echo spirv-tools Release build failed!
496      set errorCode=1
497   )
498goto:eof
499