loader:Fix build warnings
[platform/upstream/Vulkan-LoaderAndValidationLayers.git] / update_external_sources.sh
1 #!/bin/bash
2 # Update source for glslang
3
4 set -e
5
6 if [[ $(uname) == "Linux" || $(uname) =~ "CYGWIN" ]]; then
7     CURRENT_DIR="$(dirname "$(readlink -f ${BASH_SOURCE[0]})")"
8     CORE_COUNT=$(nproc || echo 4)
9 elif [[ $(uname) == "Darwin" ]]; then
10     CURRENT_DIR="$(dirname "$(python -c 'import os,sys;print(os.path.realpath(sys.argv[1]))' ${BASH_SOURCE[0]})")"
11     CORE_COUNT=$(sysctl -n hw.ncpu || echo 4)
12 fi
13 echo CURRENT_DIR=$CURRENT_DIR
14 echo CORE_COUNT=$CORE_COUNT
15
16 REVISION_DIR="$CURRENT_DIR/external_revisions"
17
18 git submodule update --init --recursive
19
20 # Use tr -d to remove line endings
21 GLSLANG_GITURL=$(cat "${REVISION_DIR}/glslang_giturl" | tr -d "\n\r")
22 GLSLANG_REVISION=$(cat "${REVISION_DIR}/glslang_revision" | tr -d "\n\r")
23
24 echo "GLSLANG_GITURL=${GLSLANG_GITURL}"
25 echo "GLSLANG_REVISION=${GLSLANG_REVISION}"
26
27 BUILDDIR=${CURRENT_DIR}
28 BASEDIR="$BUILDDIR/external"
29
30 function create_glslang () {
31    rm -rf "${BASEDIR}"/glslang
32    echo "Creating local glslang repository (${BASEDIR}/glslang)."
33    mkdir -p "${BASEDIR}"/glslang
34    cd "${BASEDIR}"/glslang
35    git clone ${GLSLANG_GITURL} .
36    git checkout ${GLSLANG_REVISION}
37    ./update_glslang_sources.py
38 }
39
40 function update_glslang () {
41    echo "Updating ${BASEDIR}/glslang"
42    cd "${BASEDIR}"/glslang
43    git fetch --all
44    git checkout --force ${GLSLANG_REVISION}
45    ./update_glslang_sources.py
46 }
47
48 function build_glslang () {
49    echo "Building ${BASEDIR}/glslang"
50    cd "${BASEDIR}"/glslang
51    mkdir -p build
52    cd build
53    cmake -D CMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=install ..
54    make -j $CORE_COUNT
55    make install
56 }
57
58 function create_moltenvk () {
59    rm -rf "${BASEDIR}"/MoltenVK
60    echo "Creating local MoltenVK repository (${BASEDIR}/MoltenVK)."
61    mkdir -p "${BASEDIR}"/MoltenVK
62    cd "${BASEDIR}"/MoltenVK
63    git clone --recurse-submodules https://github.com/KhronosGroup/MoltenVK.git "${BASEDIR}"/MoltenVK
64 }
65
66 function update_moltenvk () {
67    echo "Updating ${BASEDIR}/MoltenVK"
68    cd "${BASEDIR}"/MoltenVK
69    git pull
70 }
71
72 function build_moltenvk () {
73    echo "Building ${BASEDIR}/MoltenVK"
74    cd "${BASEDIR}"/MoltenVK
75    ./fetchDependencies --v-lvl-root "${BUILDDIR}" --glslang-root "${BASEDIR}/glslang"
76    xcodebuild -project MoltenVKPackaging.xcodeproj \
77     GCC_PREPROCESSOR_DEFINITIONS='$GCC_PREPROCESSOR_DEFINITIONS MVK_LOGGING_ENABLED=0' \
78     -scheme "MoltenVK (Release)" build
79 }
80
81 INCLUDE_GLSLANG=false
82 INCLUDE_MOLTENVK=false
83 NO_SYNC=false
84 NO_BUILD=false
85 USE_IMPLICIT_COMPONENT_LIST=true
86
87 # Parse options
88 while [[ $# > 0 ]]
89 do
90   option="$1"
91
92   case $option in
93       # options to specify build of glslang components
94       -g|--glslang)
95       INCLUDE_GLSLANG=true
96       USE_IMPLICIT_COMPONENT_LIST=false
97       echo "Building glslang ($option)"
98       ;;
99       # options to specify build of moltenvk components
100       -m|--moltenvk)
101       if [[ $(uname) == "Darwin" ]]; then
102         INCLUDE_MOLTENVK=true
103         USE_IMPLICIT_COMPONENT_LIST=false
104         echo "Building MoltenVK ($option)"
105       fi
106       ;;
107       # options to specify build of spirv-tools components
108       -s|--spirv-tools)
109       echo "($option) is deprecated and is no longer necessary"
110       ;;
111       # option to specify skipping sync from git
112       --no-sync)
113       NO_SYNC=true
114       echo "Skipping sync ($option)"
115       ;;
116       # option to specify skipping build
117       --no-build)
118       NO_BUILD=true
119       echo "Skipping build ($option)"
120       ;;
121       *)
122       echo "Unrecognized option: $option"
123       echo "Usage: update_external_sources.sh [options]"
124       echo "  Available options:"
125       echo "    -g | --glslang      # enable glslang component"
126       if [[ $(uname) == "Darwin" ]]; then
127         echo "    -m | --moltenvk     # enable moltenvk component"
128       fi
129       echo "    --no-sync           # skip sync from git"
130       echo "    --no-build          # skip build"
131       echo "  If any component enables are provided, only those components are enabled."
132       echo "  If no component enables are provided, all components are enabled."
133       echo "  Sync uses git to pull a specific revision."
134       echo "  Build configures CMake, builds Release."
135       exit 1
136       ;;
137   esac
138   shift
139 done
140
141 if [ ${USE_IMPLICIT_COMPONENT_LIST} == "true" ]; then
142   echo "Building glslang"
143   INCLUDE_GLSLANG=true
144   if [[ $(uname) == "Darwin" ]]; then
145     echo "Building MoltenVK"
146     INCLUDE_MOLTENVK=true
147   fi
148 fi
149
150 if [ ${INCLUDE_GLSLANG} == "true" ]; then
151   if [ ${NO_SYNC} == "false" ]; then
152     if [ ! -d "${BASEDIR}/glslang" -o ! -d "${BASEDIR}/glslang/.git" -o -d "${BASEDIR}/glslang/.svn" ]; then
153        create_glslang
154     fi
155     update_glslang
156   fi
157   if [ ${NO_BUILD} == "false" ]; then
158     build_glslang
159   fi
160 fi
161
162 if [ ${INCLUDE_MOLTENVK} == "true" ]; then
163   if [ ${NO_SYNC} == "false" ]; then
164     if [ ! -d "${BASEDIR}/MoltenVK" -o ! -d "${BASEDIR}/MoltenVK/.git" ]; then
165       create_moltenvk
166     fi
167     update_moltenvk
168   fi
169   if [ ${NO_BUILD} == "false" ]; then
170     echo "Building moltenvk"
171     build_moltenvk
172   fi
173 fi
174