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