331.1. ledger-3.4.1
Double-entry accounting over a plain-text journal
| Version | 3.4.1, release 1 |
| Shelf | office — Office suites, word processors, spreadsheets, presentations, accounting and finance, and office-format import libraries |
| Phase | 44_apps (Applications), 310 of 422 in build order |
| Licence | BSD-3-Clause |
| Homepage | https://ledger-cli.org/ |
| Build time | 6.1 SBU |
| Installed size | 6.2 MiB in 108 files |
| Recipe | ports/core/office/ledger/kpkgbuild |
About
Ledger is double-entry accounting on a plain-text journal. Transactions are lines typed into a text file, which can live under version control, and ledger only reads that file and prints balances, registers and reports from it; nothing is stored anywhere else. Given a journal (-f, LEDGER_FILE or ~/.ledger) and no command, ledger opens an interactive prompt.
Why it is in KDOS
The comment above it in script/phases/44_apps/packages.d/office.txt:
The ledger IS a text file and the program only reads it. The data survives the tool, which is not true of any accounting app with a database.
Sources
ledger-3.4.1.tar.gz(798.0 KiB)
sha2561cf012cdc8445cab0efc445064ef9b2d3f46ed0165dae803c40fe3d2b23fdaad
upstream: https://github.com/ledger/ledger/archive/refs/tags/v3.4.1.tar.gz
archive copy: sources-3/office--ledger-3.4.1.tar.gz
Dependencies
Depends on: cmake, ninja, pkgconf, boost, gmp, mpfr, util-linux, libedit, icu, texinfo, gpgmepp.
Required by: no port names it.
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.
-DUSE_PYTHON=OFF, line 23: python3 (explained with the switches below)
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/44_apps/phase.env && kpkg install ledger'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/office/ledger.
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/office/ledger
echo '1cf012cdc8445cab0efc445064ef9b2d3f46ed0165dae803c40fe3d2b23fdaad ledger-3.4.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/ledger
SRC=$SRC_ROOT/ledger-3.4.1
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf ledger-3.4.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:
export CXXFLAGS="$CXXFLAGS -I$SRC/lib/utfcpp/v4/source"
mkdir -p build && cd build
cmake .. -G Ninja \
-DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_INSTALL_LIBDIR=lib \
-DCMAKE_SKIP_INSTALL_RPATH=ON \
-DBUILD_DOCS=ON \
-DBUILD_WEB_DOCS=OFF \
-DUSE_PYTHON=OFF \
-DUSE_GPGME=ON \
-DBUILD_LIBRARY=ON \
-DBOOST_REGEX_UNICODE_RUNS=1
grep -q '^#define HAVE_EDIT 1' system.hh \
|| { echo "ledger: libedit missing" >&2; exit 1; }
ninja
ninja doc
DESTDIR=$PKG ninja install
install -Dm644 "$PKG/usr/share/contrib/ledger-completion.bash" \
"$PKG/usr/share/bash-completion/completions/ledger"
rm -f "$PKG/usr/share/contrib/ledger-completion.bash"
rm -rf "$PKG/usr/share/contrib/non-profit-audit-reports/tests"
install -d "$PKG/usr/share/ledger"
mv "$PKG/usr/share/contrib" "$PKG/usr/share/ledger/contrib"
install -d "$PKG/usr/share/applications"
cat > "$PKG/usr/share/applications/ledger.desktop" <<'EOF'
[Desktop Entry]
Type=Application
Name=Accounting
GenericName=Accounting
Comment=Double-entry accounting from a plain-text ledger
Exec=ledger
Icon=office-chart-line
Terminal=true
NoDisplay=true
Categories=Office;Finance;
Keywords=account;ledger;finance;money;
EOF
chmod 644 "$PKG/usr/share/applications/ledger.desktop"
The switches, and why each is set:
-I$SRC/lib/utfcpp/v4/source— added toCXXFLAGS: the copy of utfcpp, the UTF-8 header library, that ledger carries underlib/utfcpp. With it on every compile, the unit tests undertest/unitbuild; without it they fail on'utf8' has not been declaredafter the library itself has compiled.-DCMAKE_SKIP_INSTALL_RPATH=ON— the programs andlibledgerare installed without a run path; everything is in/usr/lib.-DBUILD_DOCS=ON— build the Info manual,ledger3.info, withmakeinfofrom texinfo.-DBUILD_WEB_DOCS=OFFleaves out its HTML and plain-text versions.-DUSE_PYTHON=OFF— no Python bridge through Boost.Python. It is upstream’s default. Boost is still required: the configure asks for its date_time, filesystem, iostreams, regex and unit-test libraries.-DUSE_GPGME=ON— read a journal that gpg has encrypted, through gpgmepp. Off by upstream’s default.-DBUILD_LIBRARY=ON— build and installlibledgeras a shared library beside the program. It is upstream’s default.-DBOOST_REGEX_UNICODE_RUNS=1— the result of a configure probe, set instead of probed. The probe decides whether ledger matches through Boost.Regex’s ICU side, and it assigns a narrow string literal to astd::basic_string<uint32_t>, which the tree’s GCC refuses to compile; it would answer no, and case-insensitive matching of non-ASCII account and payee names would fall back to bytes. boost is built with ICU, so with the result set,bal активыmatchesАктивы:Банк, and an ICU that went missing fails the link instead.
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/ledger, 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 ledger-3.4.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/ledger, and runs the triggers its paths call for.
Contents
Installed programs: ledger.
Installed libraries: libledger.so.
Installed directories: /usr/include/ledger, /usr/share/ledger, /usr/share/licenses/ledger.
Short descriptions
ledger |
Command-line, double-entry account reporting tool |
Notes
The line editor is probed, not chosen by an option: the configure takes libedit when it finds it and readline otherwise, so the line editing of the interactive prompt would depend on what the build root happened to hold. build.sh checks the generated system.hh for HAVE_EDIT and stops when libedit was not found.
ninja doc runs before the install: the documentation target is not part of the default build, and the install rule names the .info file whether or not it was built.
After the install, build.sh moves upstream’s contrib directory from /usr/share/contrib to /usr/share/ledger/contrib, takes its bash completion out to /usr/share/bash-completion/completions/ledger, and drops the test data of the non-profit audit reports. The desktop entry is KDOS’s own, with Terminal=true and NoDisplay=true: ledger with no journal exits at once, so Start does not list it, and it runs from a prompt with -f.