78.5. libbsd-0.12.2
Functions commonly found on BSD systems, such as strlcpy()
| Version | 0.12.2, release 2 |
| Shelf | base-libs — Low-level C libraries that the base system links |
| Phase | 41_system (System), 191 of 1047 in build order |
| Licence | BSD-3-Clause AND BSD-2-Clause AND ISC AND MIT AND Beerware |
| Homepage | https://libbsd.freedesktop.org |
| Build time | 0.2 SBU |
| Installed size | 719.5 KiB in 273 files |
| Recipe | ports/core/base-libs/libbsd/kpkgbuild |
About
libbsd provides functions and headers found on the BSDs and missing from the Linux C libraries — strlcpy(), reallocarray(), arc4random(), setproctitle(), <sys/queue.h>, <sys/tree.h> and the rest — so that software written for them builds unchanged. In KDOS, samba and its talloc, tdb and tevent, xwayland, libICE, libXdmcp, libtirpc, netcat, zeromq and others link it. Its hash functions come from libmd.
Sources
libbsd-0.12.2.tar.xz(435.6 KiB)
sha256b88cc9163d0c652aaf39a99991d974ddba1c3a9711db8f1b5838af2a14731014
upstream: https://libbsd.freedesktop.org/releases/libbsd-0.12.2.tar.xz
archive copy: sources-1/base-libs--libbsd-0.12.2.tar.xz
Dependencies
Depends on: libmd.
Required by (13): bsd-games, f2fs-tools, libICE, libtirpc, libXdmcp, nbdkit, netcat, samba, talloc, tdb, tevent, xwayland, zeromq.
Patches
build.sh applies these; kpkg applies nothing by itself.
sys-cdefs-no-self-include.patch— Not applied to the source but to the installed copy at$PKG/usr/include/sys/cdefs.h(see the note below): it comments out that file’s own#include <sys/cdefs.h>. There the file is itself<sys/cdefs.h>, and the include, which comes before its include guard, would include itself without end.
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/41_system/phase.env && kpkg install libbsd'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/base-libs/libbsd.
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/base-libs/libbsd
echo 'b88cc9163d0c652aaf39a99991d974ddba1c3a9711db8f1b5838af2a14731014 libbsd-0.12.2.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/libbsd
SRC=$SRC_ROOT/libbsd-0.12.2
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf libbsd-0.12.2.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:
export CFLAGS="$CFLAGS -Doff64_t=off_t"
./configure --prefix=/usr
make
make DESTDIR=$PKG install
mkdir -p $PKG/usr/include/sys
cp $PKG/usr/include/bsd/sys/cdefs.h $PKG/usr/include/sys/
cp $PKG/usr/include/bsd/sys/queue.h $PKG/usr/include/sys/
cp $PKG/usr/include/bsd/sys/tree.h $PKG/usr/include/sys/
patch -d "$PKG" -p0 -i "$PORT_SRC/sys-cdefs-no-self-include.patch"
The switches, and why each is set:
CFLAGS="$CFLAGS -Doff64_t=off_t"— Definesoff64_tasoff_tfor the whole build. musl defines nooff64_t, and itsoff_tis 64 bits, so the two name the same type. No source file in this release namesoff64_t(funopen.cusesoff_t), so the definition changes nothing in what is compiled.
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/libbsd, 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 libbsd-0.12.2-2.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/libbsd, and runs the triggers its paths call for.
Contents
Installed libraries: libbsd.a, libbsd.so.
Installed directories: /usr/include/bsd, /usr/share/licenses/libbsd.
Short descriptions
libbsd.pc |
Utility functions from BSD systems |
libbsd-overlay.pc |
Utility functions from BSD systems (overlay) |
Notes
- Three headers are copied into
/usr/include/sys. musl has no<sys/cdefs.h>,<sys/queue.h>or<sys/tree.h>, which a good deal of BSD-derived code includes by those names.build.shcopies libbsd’s versions of the three from/usr/include/bsd/systo/usr/include/sysafter the install, so they resolve as system headers; the patch then makes the copiedcdefs.hsafe in that place.