blob: 06dca16948aa564d1d7f7ac73b7412e6e29caf95 [file] [log] [blame]
Courtney Goeltzenleuchter87094962014-10-17 18:21:42 -06001#!/bin/bash
Cody Northrop983c1fa2015-12-29 14:42:24 -07002# Update source for glslang, LunarGLASS, spirv-tools
Courtney Goeltzenleuchter87094962014-10-17 18:21:42 -06003
Cody Northropa8ac1352015-05-12 16:23:59 -06004set -e
5
Cody Northrop0abc48e2016-12-02 09:10:20 -07006if [[ $(uname) == "Linux" ]]; then
7 CURRENT_DIR="$(dirname "$(readlink -f ${BASH_SOURCE[0]})")"
Cody Northrop3d76d482016-12-02 09:28:42 -07008 CORE_COUNT=$(nproc || echo 4)
Cody Northrop0abc48e2016-12-02 09:10:20 -07009elif [[ $(uname) == "Darwin" ]]; then
Michael Jurka3859b212016-12-19 16:31:43 +010010 CURRENT_DIR="$(dirname "$(python -c 'import os,sys;print(os.path.realpath(sys.argv[1]))' ${BASH_SOURCE[0]})")"
Cody Northrop3d76d482016-12-02 09:28:42 -070011 CORE_COUNT=$(sysctl -n hw.ncpu || echo 4)
Cody Northrop0abc48e2016-12-02 09:10:20 -070012fi
Cody Northrop3d76d482016-12-02 09:28:42 -070013echo CORE_COUNT=$CORE_COUNT
Cody Northrop0abc48e2016-12-02 09:10:20 -070014
Mark Lobodzinskia9d7bfa2016-11-22 08:02:59 -070015REVISION_DIR="$CURRENT_DIR/external_revisions"
Mark Lobodzinski22008362016-11-18 13:20:36 -070016
Mark Lobodzinskia9d7bfa2016-11-22 08:02:59 -070017GLSLANG_REVISION=$(cat "${REVISION_DIR}/glslang_revision")
18SPIRV_TOOLS_REVISION=$(cat "${REVISION_DIR}/spirv-tools_revision")
19SPIRV_HEADERS_REVISION=$(cat "${REVISION_DIR}/spirv-headers_revision")
Karl Schultzcb788b32016-09-27 18:38:02 -060020echo "GLSLANG_REVISION=${GLSLANG_REVISION}"
21echo "SPIRV_TOOLS_REVISION=${SPIRV_TOOLS_REVISION}"
22echo "SPIRV_HEADERS_REVISION=${SPIRV_HEADERS_REVISION}"
Courtney Goeltzenleuchter90a6f4b2014-10-29 17:50:15 -060023
Mark Lobodzinskia9d7bfa2016-11-22 08:02:59 -070024BUILDDIR=${CURRENT_DIR}
25BASEDIR="$BUILDDIR/external"
Courtney Goeltzenleuchter87094962014-10-17 18:21:42 -060026
27function create_glslang () {
Karl Schultzcb788b32016-09-27 18:38:02 -060028 rm -rf "${BASEDIR}"/glslang
29 echo "Creating local glslang repository (${BASEDIR}/glslang)."
30 mkdir -p "${BASEDIR}"/glslang
31 cd "${BASEDIR}"/glslang
Peter Lohrmann5d93b0d2016-02-16 15:20:58 -080032 git clone https://github.com/KhronosGroup/glslang.git .
Karl Schultzcb788b32016-09-27 18:38:02 -060033 git checkout ${GLSLANG_REVISION}
Courtney Goeltzenleuchter87094962014-10-17 18:21:42 -060034}
35
36function update_glslang () {
Karl Schultzcb788b32016-09-27 18:38:02 -060037 echo "Updating ${BASEDIR}/glslang"
38 cd "${BASEDIR}"/glslang
Cody Northrop139ec4f2015-07-08 09:53:03 -060039 git fetch --all
Karl Schultzcb788b32016-09-27 18:38:02 -060040 git checkout --force ${GLSLANG_REVISION}
Courtney Goeltzenleuchter87094962014-10-17 18:21:42 -060041}
42
Cody Northrop983c1fa2015-12-29 14:42:24 -070043function create_spirv-tools () {
Karl Schultzcb788b32016-09-27 18:38:02 -060044 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 Lohrmann5d93b0d2016-02-16 15:20:58 -080048 git clone https://github.com/KhronosGroup/SPIRV-Tools.git .
Karl Schultzcb788b32016-09-27 18:38:02 -060049 git checkout ${SPIRV_TOOLS_REVISION}
50 mkdir -p "${BASEDIR}"/spirv-tools/external/spirv-headers
51 cd "${BASEDIR}"/spirv-tools/external/spirv-headers
GregF264d7a72016-06-17 12:26:49 -060052 git clone https://github.com/KhronosGroup/SPIRV-Headers .
Karl Schultzcb788b32016-09-27 18:38:02 -060053 git checkout ${SPIRV_HEADERS_REVISION}
Cody Northrop983c1fa2015-12-29 14:42:24 -070054}
55
56function update_spirv-tools () {
Karl Schultzcb788b32016-09-27 18:38:02 -060057 echo "Updating ${BASEDIR}/spirv-tools"
58 cd "${BASEDIR}"/spirv-tools
Cody Northrop983c1fa2015-12-29 14:42:24 -070059 git fetch --all
Karl Schultzcb788b32016-09-27 18:38:02 -060060 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
GregF264d7a72016-06-17 12:26:49 -060064 git clone https://github.com/KhronosGroup/SPIRV-Headers .
65 else
Karl Schultzcb788b32016-09-27 18:38:02 -060066 cd "${BASEDIR}"/spirv-tools/external/spirv-headers
GregF264d7a72016-06-17 12:26:49 -060067 git fetch --all
GregF264d7a72016-06-17 12:26:49 -060068 fi
Karl Schultzcb788b32016-09-27 18:38:02 -060069 git checkout ${SPIRV_HEADERS_REVISION}
Cody Northrop983c1fa2015-12-29 14:42:24 -070070}
71
Courtney Goeltzenleuchter87094962014-10-17 18:21:42 -060072function build_glslang () {
Karl Schultzcb788b32016-09-27 18:38:02 -060073 echo "Building ${BASEDIR}/glslang"
74 cd "${BASEDIR}"/glslang
Courtney Goeltzenleuchter87094962014-10-17 18:21:42 -060075 mkdir -p build
76 cd build
77 cmake -D CMAKE_BUILD_TYPE=Release ..
Cody Northrop3d76d482016-12-02 09:28:42 -070078 make -j $CORE_COUNT
Courtney Goeltzenleuchter87094962014-10-17 18:21:42 -060079 make install
80}
81
Cody Northrop983c1fa2015-12-29 14:42:24 -070082function build_spirv-tools () {
Karl Schultzcb788b32016-09-27 18:38:02 -060083 echo "Building ${BASEDIR}/spirv-tools"
84 cd "${BASEDIR}"/spirv-tools
Cody Northrop983c1fa2015-12-29 14:42:24 -070085 mkdir -p build
86 cd build
87 cmake -D CMAKE_BUILD_TYPE=Release ..
Cody Northrop3d76d482016-12-02 09:28:42 -070088 make -j $CORE_COUNT
Cody Northrop983c1fa2015-12-29 14:42:24 -070089}
90
Cody Northrop2f865b32015-12-29 16:25:10 -070091# If any options are provided, just compile those tools
92# If no options are provided, build everything
93INCLUDE_GLSLANG=false
Cody Northrop2f865b32015-12-29 16:25:10 -070094INCLUDE_SPIRV_TOOLS=false
Cody Northrop26f29c02015-11-30 13:40:50 -070095
Cody Northrop2f865b32015-12-29 16:25:10 -070096if [ "$#" == 0 ]; then
GregF211374b2016-02-19 11:50:05 -070097 echo "Building glslang, spirv-tools"
Cody Northrop2f865b32015-12-29 16:25:10 -070098 INCLUDE_GLSLANG=true
Cody Northrop2f865b32015-12-29 16:25:10 -070099 INCLUDE_SPIRV_TOOLS=true
100else
101 # Parse options
102 while [[ $# > 0 ]]
103 do
104 option="$1"
Cody Northrop26f29c02015-11-30 13:40:50 -0700105
Cody Northrop2f865b32015-12-29 16:25:10 -0700106 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 Northrop2f865b32015-12-29 16:25:10 -0700112 # 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 Northrop2f865b32015-12-29 16:25:10 -0700121 echo " -s | --spirv-tools # enable spirv-tools"
122 exit 1
123 ;;
124 esac
125 shift
126 done
Courtney Goeltzenleuchter87094962014-10-17 18:21:42 -0600127fi
Cody Northrop26f29c02015-11-30 13:40:50 -0700128
Karl Schultzcb788b32016-09-27 18:38:02 -0600129if [ ${INCLUDE_GLSLANG} == "true" ]; then
130 if [ ! -d "${BASEDIR}/glslang" -o ! -d "${BASEDIR}/glslang/.git" -o -d "${BASEDIR}/glslang/.svn" ]; then
Cody Northrop2f865b32015-12-29 16:25:10 -0700131 create_glslang
132 fi
133 update_glslang
134 build_glslang
135fi
136
137
Karl Schultzcb788b32016-09-27 18:38:02 -0600138if [ ${INCLUDE_SPIRV_TOOLS} == "true" ]; then
139 if [ ! -d "${BASEDIR}/spirv-tools" -o ! -d "${BASEDIR}/spirv-tools/.git" ]; then
Cody Northrop983c1fa2015-12-29 14:42:24 -0700140 create_spirv-tools
141 fi
Cody Northrop983c1fa2015-12-29 14:42:24 -0700142 update_spirv-tools
Cody Northrop983c1fa2015-12-29 14:42:24 -0700143 build_spirv-tools
Cody Northrop26f29c02015-11-30 13:40:50 -0700144fi