1#!/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 22BUILDDIR=$ANDROIDBUILDDIR 23BASEDIR=$BUILDDIR/third_party 24 25GLSLANG_REVISION=$(cat $ANDROIDBUILDDIR/glslang_revision_android) 26SPIRV_TOOLS_REVISION=$(cat $ANDROIDBUILDDIR/spirv-tools_revision_android) 27SPIRV_HEADERS_REVISION=$(cat $ANDROIDBUILDDIR/spirv-headers_revision_android) 28SHADERC_REVISION=$(cat $ANDROIDBUILDDIR/shaderc_revision_android) 29 30echo "GLSLANG_REVISION=$GLSLANG_REVISION" 31echo "SPIRV_TOOLS_REVISION=$SPIRV_TOOLS_REVISION" 32echo "SPIRV_HEADERS_REVISION=$SPIRV_HEADERS_REVISION" 33echo "SHADERC_REVISION=$SHADERC_REVISION" 34 35GLSLANG_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 45if [[ $(uname) == "Linux" ]]; then 46 cores="$(nproc || echo 4)" 47elif [[ $(uname) == "Darwin" ]]; then 48 cores=$(sysctl -n hw.ncpu) 49fi 50 51# 52# Parse parameters 53# 54 55function printUsage { 56 echo "Supported parameters are:" 57 echo " --abi <abi> (optional)" 58 echo " --no-build (optional)" 59 echo 60 echo "i.e. ${0##*/} --abi arm64-v8a \\" 61 exit 1 62} 63 64while [[ $# -gt 0 ]] 65do 66 case $1 in 67 --abi) 68 abi="$2" 69 shift 2 70 ;; 71 --no-build) 72 nobuild=1 73 shift 1 74 ;; 75 *) 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 91echo no-build=$nobuild 92if [[ $nobuild ]] 93then 94 echo Skipping build. 95fi 96 97function create_glslang () { 98 rm -rf $BASEDIR/shaderc/third_party/glslang 99 echo "Creating local glslang repository ($BASEDIR/glslang)." 100 mkdir -p $BASEDIR/shaderc/third_party/glslang 101 cd $BASEDIR/shaderc/third_party/glslang 102 git clone $GLSLANG_URL . 103 git checkout $GLSLANG_REVISION 104} 105 106function update_glslang () { 107 echo "Updating $BASEDIR/shaderc/third_party/glslang" 108 cd $BASEDIR/shaderc/third_party/glslang 109 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 114 git fetch --all 115 git checkout $GLSLANG_REVISION 116} 117 118function create_spirv-tools () { 119 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 123 git clone $SPIRV_TOOLS_URL . 124 git checkout $SPIRV_TOOLS_REVISION 125} 126 127function update_spirv-tools () { 128 echo "Updating $BASEDIR/shaderc/third_party/spirv-tools" 129 cd $BASEDIR/shaderc/third_party/spirv-tools 130 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 135 git fetch --all 136 git checkout $SPIRV_TOOLS_REVISION 137} 138 139function create_spirv-headers () { 140 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 144 git clone $SPIRV_HEADERS_URL . 145 git checkout $SPIRV_HEADERS_REVISION 146} 147 148function update_spirv-headers () { 149 echo "Updating $BASEDIR/shaderc/third_party/spirv-tools/external/spirv-headers" 150 cd $BASEDIR/shaderc/third_party/spirv-tools/external/spirv-headers 151 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 156 git fetch --all 157 git checkout $SPIRV_HEADERS_REVISION 158} 159 160function create_shaderc () { 161 rm -rf $BASEDIR/shaderc 162 echo "Creating local shaderc repository ($BASEDIR/shaderc)." 163 mkdir -p $BASEDIR/shaderc 164 cd $BASEDIR/shaderc 165 git clone $SHADERC_URL . 166 git checkout $SHADERC_REVISION 167} 168 169function update_shaderc () { 170 echo "Updating $BASEDIR/shaderc" 171 cd $BASEDIR/shaderc 172 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 177 git fetch --all 178 git checkout $SHADERC_REVISION 179} 180 181function build_shaderc () { 182 echo "Building $BASEDIR/shaderc" 183 cd $BASEDIR/shaderc/android_test 184 if [[ $abi ]]; then 185 ndk-build NDK_APPLICATION_MK=../../../jni/shaderc/Application.mk THIRD_PARTY_PATH=../third_party APP_ABI=$abi -j $cores; 186 else 187 ndk-build NDK_APPLICATION_MK=../../../jni/shaderc/Application.mk THIRD_PARTY_PATH=../third_party -j $cores; 188 fi 189} 190 191if [ ! -d "$BASEDIR/shaderc" -o ! -d "$BASEDIR/shaderc/.git" ]; then 192 create_shaderc 193fi 194update_shaderc 195 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 211if [[ -z $nobuild ]] 212then 213build_shaderc 214fi 215 216echo "" 217echo "${0##*/} finished." 218 219