Files
darkforge/toolchain/scripts/007-ncurses.sh
2026-03-20 11:41:05 +01:00

71 lines
2.1 KiB
Bash
Executable File

#!/bin/bash
# ============================================================================
# DarkForge Linux — Phase 0, Chapter 6: Ncurses
# ============================================================================
# Purpose: Cross-compile the ncurses library (terminal handling). Required
# by bash, many TUI programs, and the installer.
# Inputs: ${LFS}/sources/ncurses.tar.gz (unversioned tarball from mirror)
# Outputs: ncurses libraries and tic utility in ${LFS}/usr/
# Assumes: Cross-toolchain (Ch.5) complete
# Ref: LFS 13.0 §6.3
# ============================================================================
set -euo pipefail
source "${LFS}/sources/darkforge-env.sh"
PACKAGE="ncurses"
SRCDIR="${LFS}/sources"
echo "=== Building ${PACKAGE} (Temporary Tool) ==="
cd "${SRCDIR}"
# The mirror provides ncurses.tar.gz (unversioned). Auto-detect the
# directory name inside the tarball.
tar -xf ncurses.tar.gz
NCDIR=$(find . -maxdepth 1 -type d -name 'ncurses-*' | head -1)
if [ -z "${NCDIR}" ]; then
echo "ERROR: Could not find ncurses-* directory after extraction"
exit 1
fi
VERSION="${NCDIR#./ncurses-}"
echo " Detected version: ${VERSION}"
cd "${NCDIR}"
# First, build the tic program that runs on the host
# This is needed to create the terminal database during install
sed -i s/mawk// configure
mkdir build
pushd build
../configure
make -C include
make -C progs tic
popd
# Now cross-compile ncurses for the target
./configure \
--prefix=/usr \
--host="${LFS_TGT}" \
--build="$(./config.guess)" \
--mandir=/usr/share/man \
--with-manpage-format=normal \
--with-shared \
--without-normal \
--with-cxx-shared \
--without-debug \
--without-ada \
--disable-stripping
make
make DESTDIR="${LFS}" TIC_PATH="$(pwd)/build/progs/tic" install
# Fix library so that it can be found by linker
ln -sv libncursesw.so "${LFS}/usr/lib/libncurses.so"
# Create pkg-config compatibility for programs that look for -lncurses
sed -e 's/^#if.*XOPEN.*$/#if 1/' -i "${LFS}/usr/include/curses.h"
cd "${SRCDIR}"
rm -rf "${NCDIR}"
echo "=== ${PACKAGE}-${VERSION} complete ==="