blob: 3d55728a1bc072e30873825545084478a718f5ff [file] [log] [blame]
Cody Northropb3106db2016-03-29 10:06:49 -06001#!/bin/bash
2# Update source for glslang, spirv-tools, shaderc
3
4# Copyright 2016 The Android Open Source Project
5# Copyright (C) 2015 Valve Corporation
6#
7# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18
19set -e
20
21ANDROIDBUILDDIR=$PWD
Cody Northrop544a42e2016-11-03 14:44:55 -060022BUILDDIR=$ANDROIDBUILDDIR
Mike Stroyanf7995182017-10-06 11:05:21 -060023BASEDIR=$BUILDDIR/third_party
Cody Northropb3106db2016-03-29 10:06:49 -060024
Cody Northrop4bf55d72016-03-31 16:33:00 -060025GLSLANG_REVISION=$(cat $ANDROIDBUILDDIR/glslang_revision_android)
26SPIRV_TOOLS_REVISION=$(cat $ANDROIDBUILDDIR/spirv-tools_revision_android)
Cody Northrop83ff93f2016-08-01 10:27:25 -060027SPIRV_HEADERS_REVISION=$(cat $ANDROIDBUILDDIR/spirv-headers_revision_android)
Cody Northrop4bf55d72016-03-31 16:33:00 -060028SHADERC_REVISION=$(cat $ANDROIDBUILDDIR/shaderc_revision_android)
Cody Northropb3106db2016-03-29 10:06:49 -060029
30echo "GLSLANG_REVISION=$GLSLANG_REVISION"
31echo "SPIRV_TOOLS_REVISION=$SPIRV_TOOLS_REVISION"
Cody Northrop7396cb02017-03-27 16:30:14 -060032echo "SPIRV_HEADERS_REVISION=$SPIRV_HEADERS_REVISION"
Cody Northropb3106db2016-03-29 10:06:49 -060033echo "SHADERC_REVISION=$SHADERC_REVISION"
34
Cody Northrop7396cb02017-03-27 16:30:14 -060035GLSLANG_URL=$(cat $ANDROIDBUILDDIR/glslang_url_android)
36SPIRV_TOOLS_URL=$(cat $ANDROIDBUILDDIR/spirv-tools_url_android)
37SPIRV_HEADERS_URL=$(cat $ANDROIDBUILDDIR/spirv-headers_url_android)
38SHADERC_URL=$(cat $ANDROIDBUILDDIR/shaderc_url_android)
39
40echo "GLSLANG_URL=$GLSLANG_URL"
41echo "SPIRV_TOOL_URLS_=$SPIRV_TOOLS_URL"
42echo "SPIRV_HEADERS_URL=$SPIRV_HEADERS_URL"
43echo "SHADERC_URL=$SHADERC_URL"
44
Cody Northrop6e556a12016-11-03 14:35:08 -060045if [[ $(uname) == "Linux" ]]; then
Ciro Santilli0a05dd72017-03-07 08:00:31 +000046 cores="$(nproc || echo 4)"
Cody Northrop6e556a12016-11-03 14:35:08 -060047elif [[ $(uname) == "Darwin" ]]; then
48 cores=$(sysctl -n hw.ncpu)
49fi
50
Cody Northrop749c6cc2017-09-29 15:34:45 -060051#
52# Parse parameters
53#
54
55function printUsage {
56 echo "Supported parameters are:"
57 echo " --abi <abi> (optional)"
Cody Northrop51cd02a2017-10-12 20:44:04 -060058 echo " --no-build (optional)"
Cody Northrop749c6cc2017-09-29 15:34:45 -060059 echo
60 echo "i.e. ${0##*/} --abi arm64-v8a \\"
61 exit 1
62}
63
Cody Northrop749c6cc2017-09-29 15:34:45 -060064while [[ $# -gt 0 ]]
65do
66 case $1 in
67 --abi)
68 abi="$2"
69 shift 2
70 ;;
Cody Northrop51cd02a2017-10-12 20:44:04 -060071 --no-build)
72 nobuild=1
73 shift 1
74 ;;
Cody Northrop749c6cc2017-09-29 15:34:45 -060075 *)
76 # unknown option
77 echo Unknown option: $1
78 echo
79 printUsage
80 exit 1
81 ;;
82 esac
83done
84
85echo abi=$abi
86if [[ -z $abi ]]
87then
88 echo No abi provided, so building for all supported abis.
89fi
90
Cody Northrop51cd02a2017-10-12 20:44:04 -060091echo no-build=$nobuild
92if [[ $nobuild ]]
93then
94 echo Skipping build.
95fi
96
Cody Northropb3106db2016-03-29 10:06:49 -060097function create_glslang () {
Mike Stroyanf7995182017-10-06 11:05:21 -060098 rm -rf $BASEDIR/shaderc/third_party/glslang
Cody Northropb3106db2016-03-29 10:06:49 -060099 echo "Creating local glslang repository ($BASEDIR/glslang)."
Mike Stroyanf7995182017-10-06 11:05:21 -0600100 mkdir -p $BASEDIR/shaderc/third_party/glslang
101 cd $BASEDIR/shaderc/third_party/glslang
Cody Northrop7396cb02017-03-27 16:30:14 -0600102 git clone $GLSLANG_URL .
Cody Northropb3106db2016-03-29 10:06:49 -0600103 git checkout $GLSLANG_REVISION
104}
105
106function update_glslang () {
Mike Stroyanf7995182017-10-06 11:05:21 -0600107 echo "Updating $BASEDIR/shaderc/third_party/glslang"
108 cd $BASEDIR/shaderc/third_party/glslang
Cody Northrop7396cb02017-03-27 16:30:14 -0600109 if [[ $(git config --get remote.origin.url) != $GLSLANG_URL ]]; then
110 echo "glslang URL mismatch, recreating local repo"
111 create_glslang
112 return
113 fi
Cody Northropb3106db2016-03-29 10:06:49 -0600114 git fetch --all
115 git checkout $GLSLANG_REVISION
116}
117
118function create_spirv-tools () {
Mike Stroyanf7995182017-10-06 11:05:21 -0600119 rm -rf $BASEDIR/shaderc/third_party/spirv-tools
120 echo "Creating local spirv-tools repository ($BASEDIR/shaderc/third_party/spirv-tools)."
121 mkdir -p $BASEDIR/shaderc/third_party/spirv-tools
122 cd $BASEDIR/shaderc/third_party/spirv-tools
Cody Northrop7396cb02017-03-27 16:30:14 -0600123 git clone $SPIRV_TOOLS_URL .
Cody Northropb3106db2016-03-29 10:06:49 -0600124 git checkout $SPIRV_TOOLS_REVISION
125}
126
127function update_spirv-tools () {
Mike Stroyanf7995182017-10-06 11:05:21 -0600128 echo "Updating $BASEDIR/shaderc/third_party/spirv-tools"
129 cd $BASEDIR/shaderc/third_party/spirv-tools
Cody Northrop7396cb02017-03-27 16:30:14 -0600130 if [[ $(git config --get remote.origin.url) != $SPIRV_TOOLS_URL ]]; then
131 echo "spirv-tools URL mismatch, recreating local repo"
132 create_spirv-tools
133 return
134 fi
Cody Northropb3106db2016-03-29 10:06:49 -0600135 git fetch --all
136 git checkout $SPIRV_TOOLS_REVISION
137}
138
Cody Northrop83ff93f2016-08-01 10:27:25 -0600139function create_spirv-headers () {
Mike Stroyanf7995182017-10-06 11:05:21 -0600140 rm -rf $BASEDIR/shaderc/third_party/spirv-tools/external/spirv-headers
141 echo "Creating local spirv-headers repository ($BASEDIR/shaderc/third_party/spirv-tools/external/spirv-headers)."
142 mkdir -p $BASEDIR/shaderc/third_party/spirv-tools/external/spirv-headers
143 cd $BASEDIR/shaderc/third_party/spirv-tools/external/spirv-headers
Cody Northrop7396cb02017-03-27 16:30:14 -0600144 git clone $SPIRV_HEADERS_URL .
Cody Northrop83ff93f2016-08-01 10:27:25 -0600145 git checkout $SPIRV_HEADERS_REVISION
146}
147
148function update_spirv-headers () {
Mike Stroyanf7995182017-10-06 11:05:21 -0600149 echo "Updating $BASEDIR/shaderc/third_party/spirv-tools/external/spirv-headers"
150 cd $BASEDIR/shaderc/third_party/spirv-tools/external/spirv-headers
Cody Northrop7396cb02017-03-27 16:30:14 -0600151 if [[ $(git config --get remote.origin.url) != $SPIRV_HEADERS_URL ]]; then
152 echo "spirv-headers URL mismatch, recreating local repo"
153 create_spirv-headers
154 return
155 fi
Cody Northrop83ff93f2016-08-01 10:27:25 -0600156 git fetch --all
157 git checkout $SPIRV_HEADERS_REVISION
158}
159
Cody Northropb3106db2016-03-29 10:06:49 -0600160function create_shaderc () {
161 rm -rf $BASEDIR/shaderc
162 echo "Creating local shaderc repository ($BASEDIR/shaderc)."
Mike Stroyanf7995182017-10-06 11:05:21 -0600163 mkdir -p $BASEDIR/shaderc
164 cd $BASEDIR/shaderc
165 git clone $SHADERC_URL .
Cody Northropb3106db2016-03-29 10:06:49 -0600166 git checkout $SHADERC_REVISION
167}
168
169function update_shaderc () {
170 echo "Updating $BASEDIR/shaderc"
171 cd $BASEDIR/shaderc
Cody Northrop7396cb02017-03-27 16:30:14 -0600172 if [[ $(git config --get remote.origin.url) != $SHADERC_URL ]]; then
173 echo "shaderc URL mismatch, recreating local repo"
174 create_shaderc
175 return
176 fi
Cody Northropb3106db2016-03-29 10:06:49 -0600177 git fetch --all
178 git checkout $SHADERC_REVISION
179}
180
181function build_shaderc () {
182 echo "Building $BASEDIR/shaderc"
183 cd $BASEDIR/shaderc/android_test
Cody Northrop749c6cc2017-09-29 15:34:45 -0600184 if [[ $abi ]]; then
Cody Northropaa83e7f2017-12-17 22:05:31 -0700185 ndk-build NDK_APPLICATION_MK=../../../jni/shaderc/Application.mk THIRD_PARTY_PATH=../third_party APP_ABI=$abi -j $cores;
Cody Northrop749c6cc2017-09-29 15:34:45 -0600186 else
Cody Northropaa83e7f2017-12-17 22:05:31 -0700187 ndk-build NDK_APPLICATION_MK=../../../jni/shaderc/Application.mk THIRD_PARTY_PATH=../third_party -j $cores;
Cody Northrop749c6cc2017-09-29 15:34:45 -0600188 fi
Cody Northropb3106db2016-03-29 10:06:49 -0600189}
190
Cody Northropb3106db2016-03-29 10:06:49 -0600191if [ ! -d "$BASEDIR/shaderc" -o ! -d "$BASEDIR/shaderc/.git" ]; then
192 create_shaderc
193fi
194update_shaderc
Mike Stroyanf7995182017-10-06 11:05:21 -0600195
196if [ ! -d "$BASEDIR/shaderc/third_party/glslang" -o ! -d "$BASEDIR/shaderc/third_party/glslang/.git" -o -d "$BASEDIR/shaderc/third_party/glslang/.svn" ]; then
197 create_glslang
198fi
199update_glslang
200
201if [ ! -d "$BASEDIR/shaderc/third_party/spirv-tools" -o ! -d "$BASEDIR/shaderc/third_party/spirv-tools/.git" ]; then
202 create_spirv-tools
203fi
204update_spirv-tools
205
206if [ ! -d "$BASEDIR/shaderc/third_party/spirv-tools/external/spirv-headers" -o ! -d "$BASEDIR/shaderc/third_party/spirv-tools/external/spirv-headers/.git" ]; then
207 create_spirv-headers
208fi
209update_spirv-headers
210
Cody Northrop51cd02a2017-10-12 20:44:04 -0600211if [[ -z $nobuild ]]
212then
Cody Northropb3106db2016-03-29 10:06:49 -0600213build_shaderc
Cody Northrop51cd02a2017-10-12 20:44:04 -0600214fi
Cody Northropb3106db2016-03-29 10:06:49 -0600215
216echo ""
217echo "${0##*/} finished."
218