1@echo off
2REM Update source for glslang, spirv-tools, and shaderc
3
4REM
5REM Copyright 2016 The Android Open Source Project
6REM Copyright (C) 2015 Valve Corporation
7REM
8REM Licensed under the Apache License, Version 2.0 (the "License");
9REM you may not use this file except in compliance with the License.
10REM You may obtain a copy of the License at
11REM
12REM      http://www.apache.org/licenses/LICENSE-2.0
13REM
14REM Unless required by applicable law or agreed to in writing, software
15REM distributed under the License is distributed on an "AS IS" BASIS,
16REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17REM See the License for the specific language governing permissions and
18REM limitations under the License.
19REM
20
21setlocal EnableDelayedExpansion
22set errorCode=0
23set ANDROID_BUILD_DIR=%~dp0
24set BUILD_DIR=%ANDROID_BUILD_DIR%\..
25set BASE_DIR=%BUILD_DIR%\third_party
26set SHADERC_DIR=%BASE_DIR%\shaderc
27set SHADERC_THIRD_PARTY=%BASE_DIR%\shaderc\third_party
28set GLSLANG_DIR=%SHADERC_THIRD_PARTH%\glslang
29set SPIRV_TOOLS_DIR=%SHADERC_THIRD_PARTH%\spirv-tools
30set SPIRV_HEADERS_DIR=%SHADERC_THIRD_PARTH%\spirv-tools\external\spirv-headers
31
32for %%X in (where.exe) do (set FOUND=%%~$PATH:X)
33if not defined FOUND (
34   echo Dependency check failed:
35   echo   where.exe not found
36   echo   This script requires Windows Vista or later, which includes where.exe.
37   set errorCode=1
38)
39
40where /q git.exe
41if %ERRORLEVEL% equ 1 (
42   echo Dependency check failed:
43   echo   git.exe not found
44   echo   Git for Windows can be downloaded here:  https://git-scm.com/download/win
45   echo   Install and ensure git.exe makes it into your PATH
46   set errorCode=1
47)
48
49where /q ndk-build.cmd
50if %ERRORLEVEL% equ 1 (
51   echo Dependency check failed:
52   echo   ndk-build.cmd not found
53   echo   Android NDK can be downloaded here:  http://developer.android.com/ndk/guides/setup.html
54   echo   Install and ensure ndk-build.cmd makes it into your PATH
55   set errorCode=1
56)
57
58REM ensure where is working with below false test
59REM where /q foo
60REM if %ERRORLEVEL% equ 1 (
61REM echo foo
62REM )
63
64:main
65
66if %errorCode% neq 0 (goto:error)
67
68REM Read the target versions from external file, which is shared with Linux script
69
70if not exist %ANDROID_BUILD_DIR%\glslang_revision_android (
71   echo.
72   echo Missing glslang_revision_android file. Place it in %ANDROID_BUILD_DIR%
73   goto:error
74)
75
76if not exist %ANDROID_BUILD_DIR%\spirv-tools_revision_android (
77   echo.
78   echo Missing spirv-tools_revision_android file. Place it in %ANDROID_BUILD_DIR%
79   set errorCode=1
80   goto:error
81)
82
83if not exist %ANDROID_BUILD_DIR%\spirv-headers_revision_android (
84   echo.
85   echo Missing spirv-headers_revision_android file. Place it in %ANDROID_BUILD_DIR%
86   set errorCode=1
87   goto:error
88)
89
90if not exist %ANDROID_BUILD_DIR%\shaderc_revision_android (
91   echo.
92   echo Missing shaderc_revision_android file. Place it in %ANDROID_BUILD_DIR%
93   set errorCode=1
94   goto:error
95)
96
97set /p GLSLANG_REVISION= < glslang_revision_android
98set /p SPIRV_TOOLS_REVISION= < spirv-tools_revision_android
99set /p SPIRV_HEADERS_REVISION= < spirv-headers_revision_android
100set /p SHADERC_REVISION= < shaderc_revision_android
101echo GLSLANG_REVISION=%GLSLANG_REVISION%
102echo SPIRV_TOOLS_REVISION=%SPIRV_TOOLS_REVISION%
103echo SPIRV_HEADERS_REVISION=%SPIRV_HEADERS_REVISION%
104echo SHADERC_REVISION=%SHADERC_REVISION%
105
106
107echo Creating and/or updating glslang, spirv-tools, spirv-headers, shaderc in %BASE_DIR%
108
109set sync-glslang=1
110set sync-spirv-tools=1
111set sync-spirv-headers=1
112set sync-shaderc=1
113set build-shaderc=1
114
115REM Must be first as we create directories used by glslang and spriv-tools
116
117if %sync-shaderc% equ 1 (
118   if exist %SHADERC_DIR% (
119      rd /S /Q %SHADERC_DIR%
120   )
121   if not exist %SHADERC_DIR% (
122      call:create_shaderc
123   )
124   if %errorCode% neq 0 (goto:error)
125   call:update_shaderc
126   if %errorCode% neq 0 (goto:error)
127)
128
129if %sync-glslang% equ 1 (
130   if exist %GLSLANG_DIR% (
131      rd /S /Q %GLSLANG_DIR%
132   )
133   if not exist %GLSLANG_DIR% (
134      call:create_glslang
135   )
136   if %errorCode% neq 0 (goto:error)
137   call:update_glslang
138   if %errorCode% neq 0 (goto:error)
139)
140
141if %sync-spirv-tools% equ 1 (
142   if exist %SPIRV_TOOLS_DIR% (
143      rd /S /Q %SPIRV_TOOLS_DIR%
144   )
145   if %ERRORLEVEL% neq 0 (goto:error)
146   if not exist %SPIRV_TOOLS_DIR% (
147      call:create_spirv-tools
148   )
149   if %errorCode% neq 0 (goto:error)
150   call:update_spirv-tools
151   if %errorCode% neq 0 (goto:error)
152)
153
154if %sync-spirv-headers% equ 1 (
155   if exist %SPIRV_HEADERS_DIR% (
156      rd /S /Q %SPIRV_HEADERS_DIR%
157   )
158   if %ERRORLEVEL% neq 0 (goto:error)
159   if not exist %SPIRV_HEADERS_DIR% (
160      call:create_spirv-headers
161   )
162   if %errorCode% neq 0 (goto:error)
163   call:update_spirv-headers
164   if %errorCode% neq 0 (goto:error)
165)
166
167if %build-shaderc% equ 1 (
168   call:build_shaderc
169   if %errorCode% neq 0 (goto:error)
170)
171
172echo.
173echo Exiting
174goto:finish
175
176:error
177echo.
178echo Halting due to error
179goto:finish
180
181:finish
182if not "%cd%\" == "%BUILD_DIR%" ( cd %BUILD_DIR% )
183endlocal
184REM This needs a fix to return error, something like exit %errorCode%
185REM Right now it is returning 0
186goto:eof
187
188
189
190REM // ======== Functions ======== //
191
192:create_glslang
193   echo.
194   echo Creating local glslang repository %GLSLANG_DIR%
195   mkdir %GLSLANG_DIR%
196   cd %GLSLANG_DIR%
197   git clone https://github.com/KhronosGroup/glslang.git .
198   git checkout %GLSLANG_REVISION%
199   if not exist %GLSLANG_DIR%\SPIRV (
200      echo glslang source download failed!
201      set errorCode=1
202   )
203goto:eof
204
205:update_glslang
206   echo.
207   echo Updating %GLSLANG_DIR%
208   cd %GLSLANG_DIR%
209   git fetch --all
210   git checkout %GLSLANG_REVISION%
211   if not exist %GLSLANG_DIR%\SPIRV (
212      echo glslang source update failed!
213      set errorCode=1
214   )
215goto:eof
216
217:create_spirv-tools
218   echo.
219   echo Creating local spirv-tools repository %SPIRV_TOOLS_DIR%
220   mkdir %SPIRV_TOOLS_DIR%
221   cd %SPIRV_TOOLS_DIR%
222   git clone https://github.com/KhronosGroup/SPIRV-Tools.git .
223   git checkout %SPIRV_TOOLS_REVISION%
224   if not exist %SPIRV_TOOLS_DIR%\source (
225      echo spirv-tools source download failed!
226      set errorCode=1
227   )
228goto:eof
229
230:update_spirv-tools
231   echo.
232   echo Updating %SPIRV_TOOLS_DIR%
233   cd %SPIRV_TOOLS_DIR%
234   git fetch --all
235   git checkout %SPIRV_TOOLS_REVISION%
236   if not exist %SPIRV_TOOLS_DIR%\source (
237      echo spirv-tools source update failed!
238      set errorCode=1
239   )
240goto:eof
241
242:create_spirv-headers
243   echo.
244   echo Creating local spirv-headers repository %SPIRV_HEADERS_DIR%
245   mkdir %SPIRV_HEADERS_DIR%
246   cd %SPIRV_HEADERS_DIR%
247   git clone https://github.com/KhronosGroup/SPIRV-Headers.git .
248   git checkout %SPIRV_HEADERS_REVISION%
249   if not exist %SPIRV_HEADERS_DIR%\include (
250      echo spirv-headers source download failed!
251      set errorCode=1
252   )
253goto:eof
254
255:update_spirv-headers
256   echo.
257   echo Updating %SPIRV_HEADERS_DIR%
258   cd %SPIRV_HEADERS_DIR%
259   git fetch --all
260   git checkout %SPIRV_HEADERS_REVISION%
261   if not exist %SPIRV_HEADERS_DIR%\include (
262      echo spirv-headers source update failed!
263      set errorCode=1
264   )
265goto:eof
266
267:create_shaderc
268   echo.
269   echo Creating local shaderc repository %SHADERC_DIR%
270   mkdir %SHADERC_DIR%
271   cd %SHADERC_DIR%
272   git clone https://github.com/google/shaderc.git .
273   git checkout %SHADERC_REVISION%
274   if not exist %SHADERC_DIR%\libshaderc (
275      echo shaderc source download failed!
276      set errorCode=1
277   )
278goto:eof
279
280:update_shaderc
281   echo.
282   echo Updating %SHADERC_DIR%
283   cd %SHADERC_DIR%
284   git fetch --all
285   git checkout %SHADERC_REVISION%
286   if not exist %SHADERC_DIR%\libshaderc (
287      echo shaderc source update failed!
288      set errorCode=1
289   )
290goto:eof
291
292:build_shaderc
293   echo.
294   echo Building %SHADERC_DIR%
295   cd %SHADERC_DIR%\android_test
296   echo Building shaderc with Android NDK
297   call ndk-build THIRD_PARTY_PATH=../.. -j 4
298   REM Check for existence of one lib, even though we should check for all results
299   if not exist %SHADERC_DIR%\android_test\obj\local\x86\libshaderc.a (
300      echo.
301      echo shaderc build failed!
302      set errorCode=1
303   )
304goto:eof
305