42.4. flex-2.6.4
Lexical analyser generator
| Version | 2.6.4, release 1 |
| Shelf | toolchain — The native compilers, the linker, the C library, and the LLVM family |
| Phase | 30_foundation (Build Foundation), 22 of 127 in build order |
| Licence | BSD-3-Clause-flex |
| Homepage | https://github.com/westes/flex |
| Build time | 0.2 SBU |
| Installed size | 816.5 KiB in 19 files |
| Recipe | ports/core/toolchain/flex/kpkgbuild |
About
flex is a fast lexical analyser generator: from a set of regular expressions and actions it writes a C scanner. It is the free implementation of lex. It installs flex, flex++, the FlexLexer.h header for C++ scanners, and libfl, which supplies a default main and yywrap for scanners that do not define their own.
In KDOS it is a build-time tool for many ports, most of them the same ones that need bison: linux, mesa, nftables, pam, doxygen, wireshark and others.
Why it is in KDOS
The comment above the 24 ports from fortify-headers to musl-utils in script/phases/30_foundation/packages.txt is quoted in The build foundation.
Sources
flex-2.6.4.tar.gz(1.4 MiB)
sha256e87aae032bf07c26f85ac0ed3250998c37621d95f8bd748b31f15b33c45ee995
upstream: https://github.com/westes/flex/releases/download/v2.6.4/flex-2.6.4.tar.gz
archive copy: sources-4/toolchain--flex-2.6.4.tar.gz
Dependencies
Depends on: m4.
Required by (60): acpica, avrdude, bcc, binutils-arm-none-eabi, binutils-avr, binutils-riscv64-unknown-elf, bpftrace, ccid, chromium, digikam, doxygen, dtc, gnumeric, gobject-introspection, graphviz, gstreamer, iptables, ispc, iverilog, kdevelop-pg-qt, kholidays, kopeninghours, kosmindoormap, kseexpr, lasem, libcue, libnl, libnslog, libpcap, linux, lm-sensors, mesa, mesa-opencl, motif, netpbm, nftables, ngspice, nsgenbind, octave, openscad, pam, pcsc-lite, perf, powerman, qgis, qt6-qtwebengine, qucs-s, sdcc, solid, thrift, vala, verilator, vice, wcslib, webkitgtk, webkitgtk6, wine, wireshark, xmlto, yosys.
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 flex'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/toolchain/flex.
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/toolchain/flex
echo 'e87aae032bf07c26f85ac0ed3250998c37621d95f8bd748b31f15b33c45ee995 flex-2.6.4.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/flex
SRC=$SRC_ROOT/flex-2.6.4
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf flex-2.6.4.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 --disable-nls
make
make DESTDIR=$PKG install
ln -s flex $PKG/usr/bin/lex
ln -s flex.1 $PKG/usr/share/man/man1/lex.1
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/flex, 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 flex-2.6.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/flex, and runs the triggers its paths call for.
Contents
Installed programs: flex, flex++, lex.
Installed libraries: libfl.a, libfl.so.
Installed directories: /usr/share/doc/flex, /usr/share/licenses/flex.
Short descriptions
flex |
the fast lexical analyser generator |
Notes
build.sh adds lex as a link to flex, and lex.1 as a link to flex.1. flex’s own install makes neither. GNU make’s built-in rules and many makefiles call the scanner generator lex (make’s default is LEX = lex), and without the link such a build finds no command.
Like Bison, flex runs m4 as it generates a scanner, by the absolute path configure found, /usr/bin/m4, so m4 is a run-time dependency.