Skip to content

Instantly share code, notes, and snippets.

@EStog
Last active September 27, 2021 01:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EStog/28e290e2d1fc04e649a4461f69ff6e06 to your computer and use it in GitHub Desktop.
Save EStog/28e290e2d1fc04e649a4461f69ff6e06 to your computer and use it in GitHub Desktop.
Bash script to install from source SWI-Prolog in Opensuse
#!/usr/bin/env bash
# Author: Ernesto Soto Gómez <https://github.com/EStog>
# This script install the stable version of SWI-Prolog in Opensuse.
# - If it is executed in root mode it is installed in /usr/local; If not,
# it is installed in $HOME.
# - An option BUILD_TYPE may be given as an environment variable to specify
# "Debug" or "Release" build type. It defaults to Release.
# - INSTALL_DEPS may be may be specified as a flag to install dependencies.
# It is not set by default.
# - DOWNLOAD may be specified as a flag to download source from github.
# if it is not specified you must run the script inside the source folder.
# By default it is not set.
# - USE_PGO may be specified as a flag to use PGO optimization.
# - BUILD_DOCS may be specified as a flag to build documentation.
# By default it is not set.
# - Aditional arguments are passed to cmake.
# - All changes are done in current working directory.
# Adapted from instructions at:
# https://www.swi-prolog.org/build/Redhat.html
# https://www.swi-prolog.org/build/Debian.html
# https://www.swi-prolog.org/build/unix.html
# https://www.swi-prolog.org/build/prerequisites.html
# https://github.com/SWI-Prolog/swipl/blob/master/CMAKE.md
# Tested in Opensuse 15.2 for SWI-Prolog 8.2.4.
if [ ${INSTALL_DEPS} ]; then
echo
echo Installing dependencies...
echo
sudo zypper install \
cmake ninja libunwind gperftools-devel freetype-devel gmp-devel \
java-1_8_0-openjdk-devel javapackages-tools libICE-devel libjpeg-turbo \
libSM-devel libX11-devel libXaw-devel libXext-devel libXft-devel \
libXinerama-devel libXmu-devel libXpm-devel libXrender-devel libXt-devel \
ncurses-devel openssl-devel pkgconfig readline-devel libedit-devel \
unixODBC-devel zlib-devel uuid-devel libarchive-devel libyaml-devel rpm-devel \
libunwind-devel texlive-scheme-full fontconfig-devel pkg-config autoconf make \
perl gcc libqt5-qtbase-devel
fi
if [ $DOWNLOAD ]; then
echo
echo Downloading sources to current working directory...
echo
git clone https://github.com/SWI-Prolog/swipl.git || exit 1
cd swipl
git submodule update --init || exit 1
cd swipl
fi
mkdir build
cd build
if [ -f ${INSTALL_PREFIX} ]; then
if [ $(whoami) != root ]
then INSTALL_PREFIX=$HOME/.local
else INSTALL_PREFIX=/usr/local
fi
fi
if [ -f ${BUILD_TYPE} ]; then
BUILD_TYPE=Release;
fi;
echo
echo Building type ${BUILD_TYPE}...
echo
cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
-DBUILD_PDF_DOCUMENTATION=${BUILD_DOCS} $@ \
-G Ninja .. || exit 1
if [ ${USE_PGO} ]; then
echo
echo Using PGO optimization...
echo
../scripts/pgo-compile.sh || exit 1
fi
( ninja && ctest -j 8 ) || exit 1
echo
echo installing on ${INSTALL_PREFIX}...
echo
ninja install || exit 1
echo
echo Please, add ${INSTALL_PREFIX}/bin to your path if you wish to execute swipl directly from console
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment