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