55.1. mpdecimal-4.0.1
Correctly rounded arbitrary precision decimal floating point arithmetic — the library behind Python's decimal module
| Version | 4.0.1, release 1 |
| Shelf | math — Mathematics applications and libraries: computer algebra, arbitrary precision, solvers, calculators, statistics and plotting apps |
| Phase | 30_foundation (Build Foundation), 30 of 127 in build order |
| Licence | BSD-2-Clause |
| Homepage | https://www.bytereef.org/mpdecimal/ |
| Build time | 0.2 SBU |
| Installed size | 762.2 KiB in 17 files |
| Recipe | ports/core/math/mpdecimal/kpkgbuild |
About
mpdecimal is a C library for arbitrary-precision decimal floating-point arithmetic, rounded correctly: a complete implementation of IBM’s General Decimal Arithmetic Specification. It installs libmpdec, the C library, and libmpdec++, a C++ wrapper around it, with a .pc file for each.
In KDOS it exists for one consumer: the python3 port links its _decimal module, the C implementation of Python’s decimal, against libmpdec. CPython carries a copy of the library in its own source tree, Modules/_decimal/libmpdec; python3 is configured with --with-system-libmpdec so that the module uses this port’s shared library instead. This port is built with upstream’s defaults: its configure line names only the prefix.
Sources
mpdecimal-4.0.1.tar.gz(308.9 KiB)
sha25696d33abb4bb0070c7be0fed4246cd38416188325f820468214471938545b1ac8
upstream: https://www.bytereef.org/software/mpdecimal/releases/mpdecimal-4.0.1.tar.gz
archive copy: sources-3/math--mpdecimal-4.0.1.tar.gz
Dependencies
Depends on: nothing a recipe names.
Required by (1): python3.
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/30_foundation/phase.env && kpkg install mpdecimal'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/math/mpdecimal.
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/mpdecimal
echo '96d33abb4bb0070c7be0fed4246cd38416188325f820468214471938545b1ac8 mpdecimal-4.0.1.tar.gz' | 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/mpdecimal
SRC=$SRC_ROOT/mpdecimal-4.0.1
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf mpdecimal-4.0.1.tar.gz -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
make
make DESTDIR=$PKG install
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/mpdecimal, 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 mpdecimal-4.0.1-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/mpdecimal, and runs the triggers its paths call for.
Contents
Installed libraries: libmpdec++.a, libmpdec++.so, libmpdec.a, libmpdec.so.
Installed directories: /usr/share/doc/mpdecimal, /usr/share/licenses/mpdecimal.
Short descriptions
libmpdec.pc |
C library for decimal floating point arithmetic |
libmpdec++.pc |
C++ library for decimal floating point arithmetic |
Notes
python3’s configure does not stop when it cannot find this library. It warns, “no system libmpdec found; falling back to bundled libmpdec”, and compiles the copy from its own source into _decimal. A python3 built without this port installed first therefore still works, but carries the bundled copy, and the build does not fail. The depends line of python3 names mpdecimal, so the phase installs it first; to confirm a build used it, check that _decimal’s .so under /usr/lib/python3.*/lib-dynload has a NEEDED entry naming libmpdec (readelf -d).