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

62.6. ghc-9.12.4

The Glasgow Haskell Compiler, its libraries and GHCi

Version 9.12.4, release 1
Shelf lang — Language implementations, plus the modules of any language that has no module shelf of its own
Phase 31_compilers (Compilers), 20 of 22 in build order
Licence BSD-3-Clause
Homepage https://www.haskell.org/ghc/
Build time 44.9 SBU
Installed size 952.9 MiB in 4755 files
Recipe ports/core/lang/ghc/kpkgbuild

About

This port is the Glasgow Haskell Compiler, GHC, with GHCi, its boot libraries and the tools it ships (ghc-pkg, haddock, hsc2hs, hpc, runghc). The ports built with it are cabal-install and the two Haskell programs built with both: pandoc, which renders this book and which openjdk and ripgrep-all depend on, and shellcheck.

GHC is written in Haskell, so the build starts from a bootstrap seed: upstream’s statically linked GHC for Alpine, the second source = line. The seed is installed into a scratch prefix under $SRC_ROOT/seed, compiles Hadrian (GHC’s build system) and GHC’s first stage, and is then left behind; the first stage compiles the second, which is what ships. Hadrian’s own Hackage dependencies come from the vendor bundle, the third sha256 = line, so nothing is downloaded during the build (see The Haskell bundle).

Hadrian does not install. Its binary-dist-dir target lays out a binary distribution under _build/bindist, and that distribution’s own configure and make install put it into $PKG, which is how upstream’s release tarballs are installed too.

Sources

Dependencies

Depends on: gcc, gmp, libffi, ncurses, python3, python3-sphinx, autoconf, automake.

Required by (3): cabal-install, pandoc, shellcheck.

Optional, off in KDOS

These switches in build.sh turn off a feature whose library is a port here. The recipe may turn each off on purpose, or because the library was not yet a port when the recipe was written; this list cannot tell which.

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/31_compilers/phase.env && kpkg install ghc'

What kpkg does

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

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/lang/ghc
echo '02d1ee5080acf00e135b93b238f09015b06ff27254cde59669cf57c42c2bee43  ghc-9.12.4.tar.xz' | sha256sum -c -
echo '9928e01d2f49b7b75b2a4f1c37cf5de31cdcf68cd063cc3b3a010aa4d99f3962  ghc-9.10.3-x86_64-alpine3_12-linux-static.tar.xz' | sha256sum -c -
echo '1108bc8401e74b49f71d7dd237c8b1fbfdd5d55cbcdd11ec9a9e6a6eb87d9d1f  ghc-vendor-9.12.4.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/ghc
SRC=$SRC_ROOT/ghc-9.12.4
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf ghc-9.12.4.tar.xz -C "$SRC" --strip-components=1
tar --no-same-permissions --warning=no-unknown-keyword -xf ghc-9.10.3-x86_64-alpine3_12-linux-static.tar.xz -C "$SRC_ROOT"

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 recipe’s helpers _seed, _seedarch, hsplan, vendordir and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:

_seedghc="$SRC_ROOT/seed/bin/ghc"
(
	cd "$SRC_ROOT/ghc-$_seed-x86_64-unknown-linux"
	./configure --prefix="$SRC_ROOT/seed"
	make install
)

tar xf "$PORT_SRC/$name-vendor-$version.tar.xz" -C "$SRC_ROOT"
mkdir -p hadrian/bootstrap/_build/tarballs
for f in "$SRC_ROOT"/vendor/*.tar.gz; do
	cp "$f" hadrian/bootstrap/_build/tarballs/
done
for f in "$SRC_ROOT"/vendor/*.cabal; do
	b=${f##*/}
	cp "$f" "hadrian/bootstrap/_build/tarballs/${b%-*}.cabal"
done
(
	cd hadrian/bootstrap
	python3 bootstrap.py -w "$_seedghc" -d "$hsplan" --no-archive
)
_hadrian="$SRC/hadrian/bootstrap/_build/bin/hadrian"

./configure \
	--prefix=/usr \
	--build=x86_64-unknown-linux \
	--host=x86_64-unknown-linux \
	--target=x86_64-unknown-linux \
	--with-system-libffi \
	--disable-ld-override \
	--disable-numa \
	CONF_GCC_LINKER_OPTS_STAGE2="-Wl,-z,now" \
	GHC="$_seedghc"

"$_hadrian" -j"$KDOS_JOBS" \
	--flavour=release+no_profiled_libs \
	--docs=no-haddocks \
	--docs=no-sphinx-pdfs \
	--docs=no-sphinx-html \
	binary-dist-dir

cd _build/bindist/ghc-$version-x86_64-unknown-linux
./configure --prefix=/usr --with-system-libffi --disable-ld-override \
	CONF_GCC_LINKER_OPTS_STAGE2="-Wl,-z,now"
make install DESTDIR="$PKG"
rmdir "$PKG/usr/share/doc/ghc-$version"

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/ghc, 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 ghc-9.12.4-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/ghc, and runs the triggers its paths call for.

Contents

Installed programs: ghc, ghc-9.12.4, ghc-pkg, ghc-pkg-9.12.4, ghci, ghci-9.12.4, haddock, haddock-ghc-9.12.4, hp2ps, hp2ps-ghc-9.12.4, hpc, hpc-ghc-9.12.4, hsc2hs, hsc2hs-ghc-9.12.4, runghc, runghc-9.12.4, runhaskell, runhaskell-9.12.4.

Installed directories: /usr/lib/ghc-9.12.4, /usr/share/doc/x86_64-linux-ghc-9.12.4-inplace, /usr/share/licenses/ghc, /usr/share/x86_64-linux-ghc-9.12.4-inplace.

Short descriptions

ghc the Glasgow Haskell Compiler

Notes

rmdir, not rm -r, removes /usr/share/doc/ghc-<version>, the directory the binary distribution creates for the documentation that is not built. It fails, and fails the build, if anything was installed into it, so a change that brings documentation back shows up here.

The plan named by hsplan is solved for the seed’s GHC version: bootstrap.py takes each package the plan marks as coming with GHC from the seed’s own package database, at exactly the version the plan names, and stops when the seed has another. A new seed therefore needs a plan for it in the GHC source, and the vendor bundle is generated again from that plan by ports/fetch.

The seed’s archive unpacks as ghc-<seed>-x86_64-unknown-linux, not under the name of the file it came in, and its configure and make install run inside that directory.