1#!/bin/bash 2# Update source for glslang, LunarGLASS, spirv-tools 3 4set -e 5 6GLSLANG_REVISION=$(cat "${PWD}"/glslang_revision) 7SPIRV_TOOLS_REVISION=$(cat "${PWD}"/spirv-tools_revision) 8SPIRV_HEADERS_REVISION=$(cat "${PWD}"/spirv-headers_revision) 9echo "GLSLANG_REVISION=${GLSLANG_REVISION}" 10echo "SPIRV_TOOLS_REVISION=${SPIRV_TOOLS_REVISION}" 11echo "SPIRV_HEADERS_REVISION=${SPIRV_HEADERS_REVISION}" 12 13BUILDDIR=$PWD 14BASEDIR=$BUILDDIR/external 15 16function create_glslang () { 17 rm -rf "${BASEDIR}"/glslang 18 echo "Creating local glslang repository (${BASEDIR}/glslang)." 19 mkdir -p "${BASEDIR}"/glslang 20 cd "${BASEDIR}"/glslang 21 git clone https://github.com/KhronosGroup/glslang.git . 22 git checkout ${GLSLANG_REVISION} 23} 24 25function update_glslang () { 26 echo "Updating ${BASEDIR}/glslang" 27 cd "${BASEDIR}"/glslang 28 git fetch --all 29 git checkout --force ${GLSLANG_REVISION} 30} 31 32function create_spirv-tools () { 33 rm -rf "${BASEDIR}"/spirv-tools 34 echo "Creating local spirv-tools repository (${BASEDIR}/spirv-tools)." 35 mkdir -p "${BASEDIR}"/spirv-tools 36 cd "${BASEDIR}"/spirv-tools 37 git clone https://github.com/KhronosGroup/SPIRV-Tools.git . 38 git checkout ${SPIRV_TOOLS_REVISION} 39 mkdir -p "${BASEDIR}"/spirv-tools/external/spirv-headers 40 cd "${BASEDIR}"/spirv-tools/external/spirv-headers 41 git clone https://github.com/KhronosGroup/SPIRV-Headers . 42 git checkout ${SPIRV_HEADERS_REVISION} 43} 44 45function update_spirv-tools () { 46 echo "Updating ${BASEDIR}/spirv-tools" 47 cd "${BASEDIR}"/spirv-tools 48 git fetch --all 49 git checkout ${SPIRV_TOOLS_REVISION} 50 if [ ! -d "${BASEDIR}/spirv-tools/external/spirv-headers" -o ! -d "${BASEDIR}/spirv-tools/external/spirv-headers/.git" ]; then 51 mkdir -p "${BASEDIR}"/spirv-tools/external/spirv-headers 52 cd "${BASEDIR}"/spirv-tools/external/spirv-headers 53 git clone https://github.com/KhronosGroup/SPIRV-Headers . 54 else 55 cd "${BASEDIR}"/spirv-tools/external/spirv-headers 56 git fetch --all 57 fi 58 git checkout ${SPIRV_HEADERS_REVISION} 59} 60 61function build_glslang () { 62 echo "Building ${BASEDIR}/glslang" 63 cd "${BASEDIR}"/glslang 64 mkdir -p build 65 cd build 66 cmake -D CMAKE_BUILD_TYPE=Release .. 67 make -j $(nproc) 68 make install 69} 70 71function build_spirv-tools () { 72 echo "Building ${BASEDIR}/spirv-tools" 73 cd "${BASEDIR}"/spirv-tools 74 mkdir -p build 75 cd build 76 cmake -D CMAKE_BUILD_TYPE=Release .. 77 make -j $(nproc) 78} 79 80# If any options are provided, just compile those tools 81# If no options are provided, build everything 82INCLUDE_GLSLANG=false 83INCLUDE_SPIRV_TOOLS=false 84 85if [ "$#" == 0 ]; then 86 echo "Building glslang, spirv-tools" 87 INCLUDE_GLSLANG=true 88 INCLUDE_SPIRV_TOOLS=true 89else 90 # Parse options 91 while [[ $# > 0 ]] 92 do 93 option="$1" 94 95 case $option in 96 # options to specify build of glslang components 97 -g|--glslang) 98 INCLUDE_GLSLANG=true 99 echo "Building glslang ($option)" 100 ;; 101 # options to specify build of spirv-tools components 102 -s|--spirv-tools) 103 INCLUDE_SPIRV_TOOLS=true 104 echo "Building spirv-tools ($option)" 105 ;; 106 *) 107 echo "Unrecognized option: $option" 108 echo "Try the following:" 109 echo " -g | --glslang # enable glslang" 110 echo " -s | --spirv-tools # enable spirv-tools" 111 exit 1 112 ;; 113 esac 114 shift 115 done 116fi 117 118if [ ${INCLUDE_GLSLANG} == "true" ]; then 119 if [ ! -d "${BASEDIR}/glslang" -o ! -d "${BASEDIR}/glslang/.git" -o -d "${BASEDIR}/glslang/.svn" ]; then 120 create_glslang 121 fi 122 update_glslang 123 build_glslang 124fi 125 126 127if [ ${INCLUDE_SPIRV_TOOLS} == "true" ]; then 128 if [ ! -d "${BASEDIR}/spirv-tools" -o ! -d "${BASEDIR}/spirv-tools/.git" ]; then 129 create_spirv-tools 130 fi 131 update_spirv-tools 132 build_spirv-tools 133fi 134