Skip to the text
KDOS
Menu
kdos.dev KDOS from Scratch KDOS 0.2 · 4dd4a10 · 2026-11-30 Contents Index

38.1. gmp-6.3.0

Arbitrary-precision arithmetic library

Version 6.3.0, release 1
Shelf math — Mathematics applications and libraries: computer algebra, arbitrary precision, solvers, calculators, statistics and plotting apps
Phase 20_selfhost (Self-Hosting Bootstrap), 9 of 15 in build order
Licence LGPL-3.0-or-later OR GPL-2.0-or-later
Homepage https://gmplib.org/
Build time 0.7 SBU
Installed size 3.2 MiB in 19 files
Recipe ports/core/math/gmp/kpkgbuild

About

GMP, the GNU Multiple Precision Arithmetic Library, does arithmetic on integers, rationals and floating-point numbers of any size. It is the bottom of the compiler’s mathematics: mpfr is built on it, mpc on MPFR, and gcc uses all three to fold constant expressions while it compiles. No phase list names GMP; 20_selfhost installs it as gcc’s dependency, ahead of the compiler that is rebuilt over it. coreutils builds expr and factor against it, and gawk’s -M uses it through MPFR.

In Part III GMP is not a package: the bootstrap compiler builds a copy inside its own source tree and links it statically. This port is the shared library every later build of gcc, including the cross compilers, links instead.

Sources

Dependencies

Depends on: nothing a recipe names.

Required by (46): blender, cgal, coreutils, dnsmasq, freecell-solver, fzssh, gawk, gcc, gcc-arm-none-eabi, gcc-avr, gcc-riscv64-unknown-elf, gdb, ghc, glpk, gmsh, gnuradio, gtk-vnc, guile, john, kcalc, ledger, libbytesize, libfilezilla, libktorrent, libpoly, libqalculate, libstdcxx-arm-none-eabi, libstdcxx-riscv64-unknown-elf, luanti, mkvtoolnix, mpfr, nettle, nftables, openscad, orcaslicer, pandoc, pari, prusaslicer, python3-gmpy2, ruby, shellcheck, suitesparse, texlive, xonotic, yices2, z3.

Installation

From the repository root, inside the build container, this is the line kdosbuild runs for the port:

script/chroot/exec.sh bash -c 'source script/phases/20_selfhost/phase.env && kpkg install gmp'

What kpkg does

kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/math/gmp.

1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.

cd /ports/core/math/gmp
echo 'a3c2b80201b89e68616f4ad30bc66aee4927c3ce50e33929ca819d5c43538898  gmp-6.3.0.tar.xz' | sha256sum -c -

2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.

SRC_ROOT=/var/cache/kpkg/work/gmp
SRC=$SRC_ROOT/gmp-6.3.0
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf gmp-6.3.0.tar.xz -C "$SRC" --strip-components=1

Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.

3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:

./configure --prefix=/usr --libdir=/usr/lib --enable-cxx --enable-fat
make
make DESTDIR=$PKG install

The switches, and why each is set:

The common switches of each build system are explained in the Flag glossary.

4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/gmp, prunes what the image does not ship, lints the tree and rolls it reproducibly:

tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
    --mtime=@$SOURCE_DATE_EPOCH \
    --use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
    -cf gmp-6.3.0-1.tar.xz -C "$PKG" .

5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/gmp, and runs the triggers its paths call for.

Contents

Installed libraries: libgmp.a, libgmp.so, libgmpxx.a, libgmpxx.so.

Installed directories: /usr/share/licenses/gmp.

Short descriptions

gmp.pc GNU Multiple Precision Arithmetic Library
gmpxx.pc GNU Multiple Precision Arithmetic Library (C++ bindings)

Notes

The compiler’s own programs, cc1 and cc1plus among them, link libgmp.so, libmpfr.so and libmpc.so dynamically. A root missing any of the three, or holding one built for an incompatible ABI, has a gcc that cannot compile anything.