154 lines
4.8 KiB
Bash
Executable File
154 lines
4.8 KiB
Bash
Executable File
#!/bin/bash
|
|
# ============================================================================
|
|
# DarkForge Linux — Phase 3, Chapter 8.5: Glibc (Final, Native)
|
|
# ============================================================================
|
|
# Purpose: Build and install the final glibc for the target system.
|
|
# This is the CRITICAL step that brings the system from cross-compiled
|
|
# to fully native. All subsequent packages will link against this glibc.
|
|
# Includes locale generation, timezone setup, and NSS configuration.
|
|
# Inputs: /sources/glibc-2.43.tar.xz, /sources/glibc-fhs-1.patch
|
|
# Outputs: /usr/lib/libc.so.6, /usr/include/c++/, locales, timezone data
|
|
# Ref: LFS 13.0 §8.5 — CRITICAL SECTION
|
|
# ============================================================================
|
|
|
|
set -euo pipefail
|
|
source /sources/toolchain-scripts/100-chroot-env.sh
|
|
|
|
PACKAGE="glibc"
|
|
VERSION="2.43"
|
|
|
|
echo "=== Building ${PACKAGE}-${VERSION} (Phase 3, CRITICAL) ==="
|
|
|
|
pkg_extract "${PACKAGE}-${VERSION}.tar.xz"
|
|
cd "${PACKAGE}-${VERSION}"
|
|
|
|
# Apply FHS (Filesystem Hierarchy Standard) patch
|
|
# This ensures certain programs install to /usr/sbin instead of /sbin
|
|
echo ">>> Applying glibc-fhs-1.patch..."
|
|
patch -Np1 -i ../glibc-fhs-1.patch
|
|
|
|
# Create the build directory
|
|
mkdir -v build
|
|
cd build
|
|
|
|
# Configure glibc for native compilation on the target system
|
|
# --enable-kernel=5.4: Require kernel 5.4+ (we're running 6.19.8)
|
|
# --disable-nscd: We don't need the Name Service Cache Daemon
|
|
# --disable-timezone-tools: We'll set timezone manually
|
|
# --with-headers: Point to the kernel headers we installed in Phase 0
|
|
echo ">>> Configuring glibc..."
|
|
../configure \
|
|
--prefix=/usr \
|
|
--disable-werror \
|
|
--enable-kernel=5.4 \
|
|
--enable-stack-protector=strong \
|
|
--with-headers=/usr/include \
|
|
--disable-nscd \
|
|
--disable-timezone-tools
|
|
|
|
# Build glibc
|
|
echo ">>> Building glibc (this takes a while)..."
|
|
make
|
|
|
|
# Install glibc
|
|
echo ">>> Installing glibc..."
|
|
make DESTDIR=/ install
|
|
|
|
# ============================================================================
|
|
# Locale Generation — CRITICAL for UTF-8 support
|
|
# ============================================================================
|
|
echo ""
|
|
echo ">>> Generating locale data..."
|
|
|
|
# Create the en_US.UTF-8 locale (essential for development and user systems)
|
|
# This step creates binary locale files that programs use for character handling
|
|
localedef -i en_US -f UTF-8 en_US.UTF-8
|
|
|
|
# Verify locale was created
|
|
if locale -a | grep -q en_US.UTF-8; then
|
|
echo "PASS: en_US.UTF-8 locale created"
|
|
else
|
|
echo "FAIL: Could not create en_US.UTF-8 locale"
|
|
exit 1
|
|
fi
|
|
|
|
# ============================================================================
|
|
# Timezone Setup
|
|
# ============================================================================
|
|
echo ""
|
|
echo ">>> Setting up timezone data..."
|
|
|
|
# The timezone database is kept in /usr/share/zoneinfo
|
|
# Default to UTC (can be overridden during system installation)
|
|
# Copy the timezone file and create the symlink
|
|
if [ -f /usr/share/zoneinfo/UTC ]; then
|
|
ln -sfv ../usr/share/zoneinfo/UTC /etc/localtime
|
|
echo "PASS: Timezone symlink created (UTC)"
|
|
else
|
|
echo "FAIL: /usr/share/zoneinfo/UTC not found"
|
|
exit 1
|
|
fi
|
|
|
|
# ============================================================================
|
|
# Create /etc/nsswitch.conf — Critical for name service resolution
|
|
# ============================================================================
|
|
echo ""
|
|
echo ">>> Creating /etc/nsswitch.conf..."
|
|
|
|
cat > /etc/nsswitch.conf << 'NSS_EOF'
|
|
# Begin /etc/nsswitch.conf
|
|
# This file is used by the name service switch functionality in glibc
|
|
# It controls how hostname lookups, user/group lookups, etc. are resolved
|
|
|
|
passwd: files
|
|
group: files
|
|
shadow: files
|
|
|
|
hosts: files dns
|
|
networks: files
|
|
protocols: files
|
|
services: files
|
|
ethers: files
|
|
rpc: files
|
|
|
|
# End /etc/nsswitch.conf
|
|
NSS_EOF
|
|
|
|
echo "PASS: /etc/nsswitch.conf created"
|
|
|
|
# ============================================================================
|
|
# Verify glibc installation
|
|
# ============================================================================
|
|
echo ""
|
|
echo ">>> Running glibc sanity checks..."
|
|
|
|
# Test 1: Verify libc.so.6 is present
|
|
if [ -f /usr/lib/libc.so.6 ]; then
|
|
echo "PASS: /usr/lib/libc.so.6 exists"
|
|
else
|
|
echo "FAIL: /usr/lib/libc.so.6 NOT FOUND"
|
|
exit 1
|
|
fi
|
|
|
|
# Test 2: Verify we can call ldd
|
|
if ldd --version &>/dev/null; then
|
|
echo "PASS: ldd works"
|
|
else
|
|
echo "FAIL: ldd is broken"
|
|
exit 1
|
|
fi
|
|
|
|
# Test 3: Run a simple C program to test libc
|
|
echo "int main() { return 0; }" > /tmp/test.c
|
|
gcc /tmp/test.c -o /tmp/test
|
|
/tmp/test
|
|
echo "PASS: Basic C program execution works"
|
|
rm -f /tmp/test /tmp/test.c
|
|
|
|
cd ..
|
|
pkg_cleanup "${PACKAGE}-${VERSION}"
|
|
|
|
echo ""
|
|
echo "=== ${PACKAGE}-${VERSION} complete ==="
|
|
echo "=== CRITICAL: glibc is now native on the target system ==="
|