161.18. avr-libc-2.3.2
The C library for AVR microcontrollers
| Version | 2.3.2, release 1 |
| Shelf | embedded — Microcontroller and bare-metal development: cross toolchains, C libraries, flashers, debug probes and serial consoles |
| Phase | 41_system (System), 476 of 1047 in build order |
| Licence | BSD-3-Clause |
| Homepage | https://github.com/avrdudes/avr-libc |
| Build time | 4.2 SBU |
| Installed size | 156.4 MiB in 3559 files |
| Recipe | ports/core/embedded/avr-libc/kpkgbuild |
About
AVR-LibC is the C library for Microchip’s 8-bit AVR microcontrollers, the chips of the classic Arduino boards among them: the headers that name every register of every device, the start-up code, libc.a and libm.a for each core family, and the <avr/…> and <util/…> helpers for EEPROM, program-memory strings, interrupts, sleep modes and delays. With it gcc-avr compiles and links firmware. Like the picolibc ports for ARM and RISC-V, it is built with the cross compiler: gcc-avr is built first, without headers, so that its libgcc exists before any C library does.
Why it is in KDOS
The comment above the 3 ports from binutils-avr to avr-libc in script/phases/41_system/packages.d/embedded.txt:
The spare-parts drawer. avr-libc rather than picolibc: AVR is a Harvard machine with its own address spaces and picolibc does not target it.
Sources
avr-libc-2.3.2.tar.bz2(10.8 MiB)
sha25692eb253d30cec94f2861a82d40d0b17ad79c0d95fce32b74ffccc26a70afb150
upstream: https://github.com/avrdudes/avr-libc/releases/download/avr-libc-2_3_2-release/avr-libc-2.3.2.tar.bz2
archive copy: sources-2/embedded--avr-libc-2.3.2.tar.bz2
Dependencies
Depends on: gcc-avr, binutils-avr.
Required by: no port names it.
Patches
build.sh applies these; kpkg applies nothing by itself.
ccp-write-spm-avrtiny.patch—ccp_write_spm()inlibc/misc/ccp_write_spm.Swrites the configuration change protection signature to theCCPregister withsts. On the reduced AVRtiny core (__AVR_TINY__) the shortstsreaches only data addresses0x40to0xBF, andCCPis at I/O address0x3C, so the patch writes it there withoutand keepsstsfor every other core.
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 avr-libc'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/embedded/avr-libc.
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/embedded/avr-libc
echo '92eb253d30cec94f2861a82d40d0b17ad79c0d95fce32b74ffccc26a70afb150 avr-libc-2.3.2.tar.bz2' | 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/avr-libc
SRC=$SRC_ROOT/avr-libc-2.3.2
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf avr-libc-2.3.2.tar.bz2 -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 recipe’s helpers _tag and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
patch -p1 -i "$PORT_SRC/ccp-write-spm-avrtiny.patch"
unset CC CXX CFLAGS CXXFLAGS LDFLAGS CPPFLAGS
./configure --prefix=/usr --host=avr --build="$(./config.guess)" --disable-doc
make
make DESTDIR=$PKG install
rm -f "$PKG/usr/bin/avr-man"
The switches, and why each is set:
unset CC CXX CFLAGS CXXFLAGS LDFLAGS CPPFLAGS— Clears the tree’s native compiler and flags before configure. The phase environment names the hostgccand host flags; avr-libc’s configure checks that the compiler it is given targets AVR and stops at “Wrong C compiler found; check the PATH!” otherwise. With the variables gone,--host=avrpicksavr-gcc.--host=avr,--build— Make this a cross build for AVR. configure stops when the build and host systems are the same or the host is not an AVR.--buildis given as./config.guessreports it, the form configure’s own error message suggests.--disable-doc— The manual is off by default; the switch states it. Building it would need doxygen and fig2dev, and its man pages are made by the same pass.
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/avr-libc, 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 avr-libc-2.3.2-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/avr-libc, and runs the triggers its paths call for.
Contents
Installed directories: /usr/avr/include, /usr/avr/lib/avr25, /usr/avr/lib/avr3, /usr/avr/lib/avr31, /usr/avr/lib/avr35, /usr/avr/lib/avr4, /usr/avr/lib/avr5, /usr/avr/lib/avr51, /usr/avr/lib/avr6, /usr/avr/lib/avrtiny, /usr/avr/lib/avrxmega2, /usr/avr/lib/avrxmega3, /usr/avr/lib/avrxmega4, /usr/avr/lib/avrxmega5, /usr/avr/lib/avrxmega6, /usr/avr/lib/avrxmega7, /usr/avr/lib/double64, /usr/avr/lib/long-double32, /usr/avr/lib/tiny-stack, /usr/share/doc/avr-libc-2.3.2, /usr/share/licenses/avr-libc.
Notes
avr-man is deleted from the package. It runs man against the directory the manual would be installed in, and with the manual not built that directory does not exist.