Courtney Goeltzenleuchter | 8709496 | 2014-10-17 18:21:42 -0600 | [diff] [blame] | 1 | #!/bin/bash |
Cody Northrop | 983c1fa | 2015-12-29 14:42:24 -0700 | [diff] [blame] | 2 | # Update source for glslang, LunarGLASS, spirv-tools |
Courtney Goeltzenleuchter | 8709496 | 2014-10-17 18:21:42 -0600 | [diff] [blame] | 3 | |
Cody Northrop | a8ac135 | 2015-05-12 16:23:59 -0600 | [diff] [blame] | 4 | set -e |
| 5 | |
Cody Northrop | 0abc48e | 2016-12-02 09:10:20 -0700 | [diff] [blame] | 6 | if [[ $(uname) == "Linux" ]]; then |
| 7 | CURRENT_DIR="$(dirname "$(readlink -f ${BASH_SOURCE[0]})")" |
Cody Northrop | 3d76d48 | 2016-12-02 09:28:42 -0700 | [diff] [blame] | 8 | CORE_COUNT=$(nproc || echo 4) |
Cody Northrop | 0abc48e | 2016-12-02 09:10:20 -0700 | [diff] [blame] | 9 | elif [[ $(uname) == "Darwin" ]]; then |
Michael Jurka | 3859b21 | 2016-12-19 16:31:43 +0100 | [diff] [blame] | 10 | CURRENT_DIR="$(dirname "$(python -c 'import os,sys;print(os.path.realpath(sys.argv[1]))' ${BASH_SOURCE[0]})")" |
Cody Northrop | 3d76d48 | 2016-12-02 09:28:42 -0700 | [diff] [blame] | 11 | CORE_COUNT=$(sysctl -n hw.ncpu || echo 4) |
Cody Northrop | 0abc48e | 2016-12-02 09:10:20 -0700 | [diff] [blame] | 12 | fi |
Cody Northrop | 3d76d48 | 2016-12-02 09:28:42 -0700 | [diff] [blame] | 13 | echo CORE_COUNT=$CORE_COUNT |
Cody Northrop | 0abc48e | 2016-12-02 09:10:20 -0700 | [diff] [blame] | 14 | |
Mark Lobodzinski | a9d7bfa | 2016-11-22 08:02:59 -0700 | [diff] [blame] | 15 | REVISION_DIR="$CURRENT_DIR/external_revisions" |
Mark Lobodzinski | 2200836 | 2016-11-18 13:20:36 -0700 | [diff] [blame] | 16 | |
Mark Lobodzinski | a9d7bfa | 2016-11-22 08:02:59 -0700 | [diff] [blame] | 17 | GLSLANG_REVISION=$(cat "${REVISION_DIR}/glslang_revision") |
| 18 | SPIRV_TOOLS_REVISION=$(cat "${REVISION_DIR}/spirv-tools_revision") |
| 19 | SPIRV_HEADERS_REVISION=$(cat "${REVISION_DIR}/spirv-headers_revision") |
Karl Schultz | cb788b3 | 2016-09-27 18:38:02 -0600 | [diff] [blame] | 20 | echo "GLSLANG_REVISION=${GLSLANG_REVISION}" |
| 21 | echo "SPIRV_TOOLS_REVISION=${SPIRV_TOOLS_REVISION}" |
| 22 | echo "SPIRV_HEADERS_REVISION=${SPIRV_HEADERS_REVISION}" |
Courtney Goeltzenleuchter | 90a6f4b | 2014-10-29 17:50:15 -0600 | [diff] [blame] | 23 | |
Mark Lobodzinski | a9d7bfa | 2016-11-22 08:02:59 -0700 | [diff] [blame] | 24 | BUILDDIR=${CURRENT_DIR} |
| 25 | BASEDIR="$BUILDDIR/external" |
Courtney Goeltzenleuchter | 8709496 | 2014-10-17 18:21:42 -0600 | [diff] [blame] | 26 | |
| 27 | function create_glslang () { |
Karl Schultz | cb788b3 | 2016-09-27 18:38:02 -0600 | [diff] [blame] | 28 | rm -rf "${BASEDIR}"/glslang |
| 29 | echo "Creating local glslang repository (${BASEDIR}/glslang)." |
| 30 | mkdir -p "${BASEDIR}"/glslang |
| 31 | cd "${BASEDIR}"/glslang |
Peter Lohrmann | 5d93b0d | 2016-02-16 15:20:58 -0800 | [diff] [blame] | 32 | git clone https://github.com/KhronosGroup/glslang.git . |
Karl Schultz | cb788b3 | 2016-09-27 18:38:02 -0600 | [diff] [blame] | 33 | git checkout ${GLSLANG_REVISION} |
Courtney Goeltzenleuchter | 8709496 | 2014-10-17 18:21:42 -0600 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | function update_glslang () { |
Karl Schultz | cb788b3 | 2016-09-27 18:38:02 -0600 | [diff] [blame] | 37 | echo "Updating ${BASEDIR}/glslang" |
| 38 | cd "${BASEDIR}"/glslang |
Cody Northrop | 139ec4f | 2015-07-08 09:53:03 -0600 | [diff] [blame] | 39 | git fetch --all |
Karl Schultz | cb788b3 | 2016-09-27 18:38:02 -0600 | [diff] [blame] | 40 | git checkout --force ${GLSLANG_REVISION} |
Courtney Goeltzenleuchter | 8709496 | 2014-10-17 18:21:42 -0600 | [diff] [blame] | 41 | } |
| 42 | |
Cody Northrop | 983c1fa | 2015-12-29 14:42:24 -0700 | [diff] [blame] | 43 | function create_spirv-tools () { |
Karl Schultz | cb788b3 | 2016-09-27 18:38:02 -0600 | [diff] [blame] | 44 | rm -rf "${BASEDIR}"/spirv-tools |
| 45 | echo "Creating local spirv-tools repository (${BASEDIR}/spirv-tools)." |
| 46 | mkdir -p "${BASEDIR}"/spirv-tools |
| 47 | cd "${BASEDIR}"/spirv-tools |
Peter Lohrmann | 5d93b0d | 2016-02-16 15:20:58 -0800 | [diff] [blame] | 48 | git clone https://github.com/KhronosGroup/SPIRV-Tools.git . |
Karl Schultz | cb788b3 | 2016-09-27 18:38:02 -0600 | [diff] [blame] | 49 | git checkout ${SPIRV_TOOLS_REVISION} |
| 50 | mkdir -p "${BASEDIR}"/spirv-tools/external/spirv-headers |
| 51 | cd "${BASEDIR}"/spirv-tools/external/spirv-headers |
GregF | 264d7a7 | 2016-06-17 12:26:49 -0600 | [diff] [blame] | 52 | git clone https://github.com/KhronosGroup/SPIRV-Headers . |
Karl Schultz | cb788b3 | 2016-09-27 18:38:02 -0600 | [diff] [blame] | 53 | git checkout ${SPIRV_HEADERS_REVISION} |
Cody Northrop | 983c1fa | 2015-12-29 14:42:24 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | function update_spirv-tools () { |
Karl Schultz | cb788b3 | 2016-09-27 18:38:02 -0600 | [diff] [blame] | 57 | echo "Updating ${BASEDIR}/spirv-tools" |
| 58 | cd "${BASEDIR}"/spirv-tools |
Cody Northrop | 983c1fa | 2015-12-29 14:42:24 -0700 | [diff] [blame] | 59 | git fetch --all |
Karl Schultz | cb788b3 | 2016-09-27 18:38:02 -0600 | [diff] [blame] | 60 | git checkout ${SPIRV_TOOLS_REVISION} |
| 61 | if [ ! -d "${BASEDIR}/spirv-tools/external/spirv-headers" -o ! -d "${BASEDIR}/spirv-tools/external/spirv-headers/.git" ]; then |
| 62 | mkdir -p "${BASEDIR}"/spirv-tools/external/spirv-headers |
| 63 | cd "${BASEDIR}"/spirv-tools/external/spirv-headers |
GregF | 264d7a7 | 2016-06-17 12:26:49 -0600 | [diff] [blame] | 64 | git clone https://github.com/KhronosGroup/SPIRV-Headers . |
| 65 | else |
Karl Schultz | cb788b3 | 2016-09-27 18:38:02 -0600 | [diff] [blame] | 66 | cd "${BASEDIR}"/spirv-tools/external/spirv-headers |
GregF | 264d7a7 | 2016-06-17 12:26:49 -0600 | [diff] [blame] | 67 | git fetch --all |
GregF | 264d7a7 | 2016-06-17 12:26:49 -0600 | [diff] [blame] | 68 | fi |
Karl Schultz | cb788b3 | 2016-09-27 18:38:02 -0600 | [diff] [blame] | 69 | git checkout ${SPIRV_HEADERS_REVISION} |
Cody Northrop | 983c1fa | 2015-12-29 14:42:24 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Courtney Goeltzenleuchter | 8709496 | 2014-10-17 18:21:42 -0600 | [diff] [blame] | 72 | function build_glslang () { |
Karl Schultz | cb788b3 | 2016-09-27 18:38:02 -0600 | [diff] [blame] | 73 | echo "Building ${BASEDIR}/glslang" |
| 74 | cd "${BASEDIR}"/glslang |
Courtney Goeltzenleuchter | 8709496 | 2014-10-17 18:21:42 -0600 | [diff] [blame] | 75 | mkdir -p build |
| 76 | cd build |
| 77 | cmake -D CMAKE_BUILD_TYPE=Release .. |
Cody Northrop | 3d76d48 | 2016-12-02 09:28:42 -0700 | [diff] [blame] | 78 | make -j $CORE_COUNT |
Courtney Goeltzenleuchter | 8709496 | 2014-10-17 18:21:42 -0600 | [diff] [blame] | 79 | make install |
| 80 | } |
| 81 | |
Cody Northrop | 983c1fa | 2015-12-29 14:42:24 -0700 | [diff] [blame] | 82 | function build_spirv-tools () { |
Karl Schultz | cb788b3 | 2016-09-27 18:38:02 -0600 | [diff] [blame] | 83 | echo "Building ${BASEDIR}/spirv-tools" |
| 84 | cd "${BASEDIR}"/spirv-tools |
Cody Northrop | 983c1fa | 2015-12-29 14:42:24 -0700 | [diff] [blame] | 85 | mkdir -p build |
| 86 | cd build |
| 87 | cmake -D CMAKE_BUILD_TYPE=Release .. |
Cody Northrop | 3d76d48 | 2016-12-02 09:28:42 -0700 | [diff] [blame] | 88 | make -j $CORE_COUNT |
Cody Northrop | 983c1fa | 2015-12-29 14:42:24 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Cody Northrop | 2f865b3 | 2015-12-29 16:25:10 -0700 | [diff] [blame] | 91 | # If any options are provided, just compile those tools |
| 92 | # If no options are provided, build everything |
| 93 | INCLUDE_GLSLANG=false |
Cody Northrop | 2f865b3 | 2015-12-29 16:25:10 -0700 | [diff] [blame] | 94 | INCLUDE_SPIRV_TOOLS=false |
Cody Northrop | 26f29c0 | 2015-11-30 13:40:50 -0700 | [diff] [blame] | 95 | |
Cody Northrop | 2f865b3 | 2015-12-29 16:25:10 -0700 | [diff] [blame] | 96 | if [ "$#" == 0 ]; then |
GregF | 211374b | 2016-02-19 11:50:05 -0700 | [diff] [blame] | 97 | echo "Building glslang, spirv-tools" |
Cody Northrop | 2f865b3 | 2015-12-29 16:25:10 -0700 | [diff] [blame] | 98 | INCLUDE_GLSLANG=true |
Cody Northrop | 2f865b3 | 2015-12-29 16:25:10 -0700 | [diff] [blame] | 99 | INCLUDE_SPIRV_TOOLS=true |
| 100 | else |
| 101 | # Parse options |
| 102 | while [[ $# > 0 ]] |
| 103 | do |
| 104 | option="$1" |
Cody Northrop | 26f29c0 | 2015-11-30 13:40:50 -0700 | [diff] [blame] | 105 | |
Cody Northrop | 2f865b3 | 2015-12-29 16:25:10 -0700 | [diff] [blame] | 106 | case $option in |
| 107 | # options to specify build of glslang components |
| 108 | -g|--glslang) |
| 109 | INCLUDE_GLSLANG=true |
| 110 | echo "Building glslang ($option)" |
| 111 | ;; |
Cody Northrop | 2f865b3 | 2015-12-29 16:25:10 -0700 | [diff] [blame] | 112 | # options to specify build of spirv-tools components |
| 113 | -s|--spirv-tools) |
| 114 | INCLUDE_SPIRV_TOOLS=true |
| 115 | echo "Building spirv-tools ($option)" |
| 116 | ;; |
| 117 | *) |
| 118 | echo "Unrecognized option: $option" |
| 119 | echo "Try the following:" |
| 120 | echo " -g | --glslang # enable glslang" |
Cody Northrop | 2f865b3 | 2015-12-29 16:25:10 -0700 | [diff] [blame] | 121 | echo " -s | --spirv-tools # enable spirv-tools" |
| 122 | exit 1 |
| 123 | ;; |
| 124 | esac |
| 125 | shift |
| 126 | done |
Courtney Goeltzenleuchter | 8709496 | 2014-10-17 18:21:42 -0600 | [diff] [blame] | 127 | fi |
Cody Northrop | 26f29c0 | 2015-11-30 13:40:50 -0700 | [diff] [blame] | 128 | |
Karl Schultz | cb788b3 | 2016-09-27 18:38:02 -0600 | [diff] [blame] | 129 | if [ ${INCLUDE_GLSLANG} == "true" ]; then |
| 130 | if [ ! -d "${BASEDIR}/glslang" -o ! -d "${BASEDIR}/glslang/.git" -o -d "${BASEDIR}/glslang/.svn" ]; then |
Cody Northrop | 2f865b3 | 2015-12-29 16:25:10 -0700 | [diff] [blame] | 131 | create_glslang |
| 132 | fi |
| 133 | update_glslang |
| 134 | build_glslang |
| 135 | fi |
| 136 | |
| 137 | |
Karl Schultz | cb788b3 | 2016-09-27 18:38:02 -0600 | [diff] [blame] | 138 | if [ ${INCLUDE_SPIRV_TOOLS} == "true" ]; then |
| 139 | if [ ! -d "${BASEDIR}/spirv-tools" -o ! -d "${BASEDIR}/spirv-tools/.git" ]; then |
Cody Northrop | 983c1fa | 2015-12-29 14:42:24 -0700 | [diff] [blame] | 140 | create_spirv-tools |
| 141 | fi |
Cody Northrop | 983c1fa | 2015-12-29 14:42:24 -0700 | [diff] [blame] | 142 | update_spirv-tools |
Cody Northrop | 983c1fa | 2015-12-29 14:42:24 -0700 | [diff] [blame] | 143 | build_spirv-tools |
Cody Northrop | 26f29c0 | 2015-11-30 13:40:50 -0700 | [diff] [blame] | 144 | fi |