#!/bin/bash # ============================================================================ # DarkForge Linux — Phase 3, Chapter 8.16: Flex # ============================================================================ # Purpose: Build and install flex, the fast lexical scanner generator. # Flex is used by many build tools and programs that parse text. # It's a key component of the build toolchain for parsing source code. # Inputs: /sources/flex-2.6.4.tar.gz # Outputs: /usr/bin/flex, /usr/lib/libfl.so # Ref: LFS 13.0 §8.16 # ============================================================================ set -euo pipefail source /sources/toolchain-scripts/100-chroot-env.sh PACKAGE="flex" VERSION="2.6.4" echo "=== Building ${PACKAGE}-${VERSION} (Phase 3) ===" pkg_extract "${PACKAGE}-${VERSION}.tar.gz" cd "${PACKAGE}-${VERSION}" # Configure flex for the target system # --disable-static: Build only shared libraries ./configure --prefix=/usr \ --disable-static \ --docdir=/usr/share/doc/flex-${VERSION} # Build flex make # Run tests (optional but recommended) # Note: Some tests may fail on heavily optimized builds, which is acceptable make check || true # Install flex make install # Create symlink for lex (many programs expect 'lex' to be available) # Flex is a modern replacement for the classic lex tool ln -sv flex /usr/bin/lex # Verify installation if [ -x /usr/bin/flex ]; then echo "PASS: flex binary installed" else echo "FAIL: flex binary not found" exit 1 fi if [ -f /usr/lib/libfl.so ]; then echo "PASS: libfl.so installed" else echo "FAIL: libfl.so not found" exit 1 fi # Test flex echo "%%" | /usr/bin/flex > /dev/null && echo "PASS: flex works correctly" pkg_cleanup "${PACKAGE}-${VERSION}" echo "=== ${PACKAGE}-${VERSION} complete ==="