Skip to content

Building OCaml

linuxonz edited this page Jan 12, 2024 · 40 revisions

Building OCaml

Below versions of OCaml are available in respective distributions at the time of creation of these build instructions:

  • RHEL (7.8, 7.9) have 4.05.0
  • RHEL (8.6, 8.8, 8.9) have 4.07.0
  • RHEL (9.0, 9.2, 9.3) have 4.11.1
  • SLES 12 SP5 has 4.03.0
  • SLES 15 SP5 has 4.05.0
  • Ubuntu 20.04 has 4.08.1
  • Ubuntu (22.04, 23.10) have 4.13.1

The instructions provided below specify the steps to build OCaml v5.1.1 on Linux on IBM Z for following distributions:

  • RHEL (7.8, 7.9, 8.6, 8.8, 8.9, 9.0, 9.2, 9.3)
  • SLES (12 SP5, 15 SP5)
  • Ubuntu (20.04, 22.04, 23.10)

General Notes:

  • When following the steps below please use a standard permission user unless otherwise specified.
  • A directory /<source_root>/ will be referred to in these instructions, this is a temporary writable directory anywhere you'd like to place it.

Pre-requisites

1. Ensure that GCC and GNU make are installed and up to date:

  • RHEL (7.8, 7.9)
    sudo subscription-manager repos --enable=rhel-7-server-for-system-z-devtools-rpms
    sudo yum install -y git flex bison make wget unzip tar qt5-qtbase-devel texlive devtoolset-8-gcc-c++ autoconf automake gcc awk sed diff 
    # Enable GCC 8 - The changes are not persistent and this command will need to be re-run every time a new terminal session is started.
    scl enable devtoolset-8 bash
  • RHEL (8.6, 8.8, 8.9)
    sudo yum install -y gcc make git gawk sed diffutils
  • RHEL (9.0, 9.2, 9.3)
     sudo yum install -y gcc gcc-c++ make git gawk sed diffutils binutils lbzip2 hostname tar unzip cmake curl wget vim patch tcl gettext autoconf libtool automake bzip2 zlib zlib-devel bison
    Build GCC 10.4.0 from source on RHEL 9.x
    cd /<source_root>/
    URL=https://ftp.gnu.org/gnu/gcc/gcc-10.4.0/gcc-10.4.0.tar.gz 
    curl -sSL $URL | tar xzf - || error "GCC 10.4.0"
    
    cd gcc-10.4.0
    ./contrib/download_prerequisites
    mkdir build-gcc
    cd build-gcc
    ../configure -v --with-bugurl=file:///usr/share/doc/gcc-10/README.Bugs --enable-languages=c,c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-10 --program-prefix=s390x-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libquadmath --disable-libquadmath-support --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --disable-werror --with-arch=zEC12 --with-long-double-128 --disable-multilib --enable-checking=release --build=s390x-linux-gnu --host=s390x-linux-gnu --target=s390x-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-mutex  --enable-__cxa_atexit
    make -j$(nproc)
    sudo make install
    
    sudo rm -f /usr/bin/gcc
    sudo rm -f /usr/bin/g++
    export CC=/usr/bin/s390x-linux-gnu-gcc-10
    export CXX=/usr/bin/s390x-linux-gnu-g++-10
    sudo ln -sf /usr/bin/s390x-linux-gnu-gcc-10 /usr/bin/gcc
    sudo ln -sf /usr/bin/s390x-linux-gnu-g++-10 /usr/bin/g++
  • SLES 12 SP5
    sudo zypper install -y automake gcc8 git make texinfo libtool pkg-config gcc8-c++
    sudo rm -rf /usr/bin/gcc /usr/bin/g++ /usr/bin/cc
    sudo ln -s /usr/bin/gcc-8 /usr/bin/gcc
    sudo ln -s /usr/bin/g++-8 /usr/bin/g++
    sudo ln -s /usr/bin/gcc /usr/bin/cc
  • SLES 15 SP5
    sudo zypper install -y gcc make git-core gawk sed diffutils
  • Ubuntu (20.04, 22.04, 23.10)
    sudo apt-get update
    sudo apt-get -y install gcc make git gawk sed diffutils

2. Download the OCaml source and navigate into the top-level directory:

cd /<source_root>/
git clone https://github.com/ocaml/ocaml.git
cd ocaml
git checkout 5.1.1

Build and Install

1. Configure the build by issuing this command:

./configure --enable-ocamltest

2. Build the bytecode, native-code and fast versions of OCaml compilers:

make

3. Run the test suits (Optional):

make tests

4. Install the OCaml system:

sudo make install

5. Validate installation (Optional):

ocaml --version

The output should be:

The OCaml toplevel, version 5.1.1

References

Clone this wiki locally