1717# See the License for the specific language governing permissions and
1818# limitations under the License.
1919
20- if [ " $1 " == " --auto-install-gcc " ] || [ " $1 " == " --auto-install-g++ " ] ; then AUTO_INSTALL_GCC =true ; shift ; fi
21- printf " AUTO_INSTALL_GCC =%s\n" " ${AUTO_INSTALL_GCC } "
20+ if [ " $1 " == " --auto-install-deps " ] ; then AUTO_INSTALL_DEPS =true ; shift ; fi
21+ printf " AUTO_INSTALL_DEPS =%s\n" " ${AUTO_INSTALL_DEPS } "
2222
2323mkdir -p ../resources
2424# compile jvector_simd_check.cpp as x86-64
3939# Desired minimum GCC version
4040MIN_GCC_VERSION=11
4141
42- if ! command -v g++ & > /dev/null; then
43- if [ " $AUTO_INSTALL_GCC " == " true" ]
44- then
42+ # Ensures $1 (a command) is available. If not and AUTO_INSTALL_DEPS=true, runs
43+ # the Ubuntu apt/pip install given in $2; otherwise prints $2 as a hint and exits.
44+ # Usage: require_cmd <cmd> <ubuntu-install-cmd>
45+ require_cmd () {
46+ local cmd=" $1 " ubuntu_install=" $2 "
47+ if command -v " ${cmd} " & > /dev/null; then return ; fi
48+ if [ " ${AUTO_INSTALL_DEPS} " == " true" ]; then
4549 LSB_RELEASE=$( lsb_release --id --short)
4650 printf " LSB_RELEASE=%s\n" " ${LSB_RELEASE} "
47- if [ " ${LSB_RELEASE} " == " Ubuntu" ]
48- then sudo apt update && sudo apt install -y g++
49- else printf " distribution %s needs a g++ install command in %s\n" " ${LSB_RELEASE} " " ${0} " ; exit 2
51+ if [ " ${LSB_RELEASE} " == " Ubuntu" ]; then
52+ eval " sudo apt-get update && ${ubuntu_install} "
53+ else
54+ printf " distribution %s needs a '%s' install command in %s\n" " ${LSB_RELEASE} " " ${cmd} " " ${0} " ; exit 2
5055 fi
5156 else
52- echo " g++ is not installed. Please install g++ 11+ to build supporting native libraries."
53- exit 2
57+ printf " '%s' is not installed. To install it, run: %s\n" " ${cmd} " " ${ubuntu_install} " ; exit 2
5458 fi
55- fi
59+ }
60+
61+ require_cmd g++ " sudo apt-get install -y g++"
62+ require_cmd meson " sudo apt-get install -y meson"
63+ require_cmd ninja " sudo apt-get install -y ninja-build"
5664
5765# Check g++ version
5866CURRENT_GPP_VERSION=$( g++ -dumpversion)
@@ -63,16 +71,6 @@ if [ "$(printf '%s\n' "$MIN_GCC_VERSION" "$CURRENT_GPP_VERSION" | sort -V | head
6371 exit 1
6472fi
6573
66- # Check meson and ninja are available
67- if ! command -v meson & > /dev/null; then
68- echo " meson is not installed. Please install it: pip install meson or sudo apt install meson"
69- exit 2
70- fi
71- if ! command -v ninja & > /dev/null; then
72- echo " ninja is not installed. Please install it: sudo apt install ninja-build"
73- exit 2
74- fi
75-
7674BUILD_DIR=" build"
7775rm -rf ../resources/libjvector.so
7876
0 commit comments