8.11. ncurses stage 2 6.6-20260418
Rebuild ncurses in the final target environment so curses libraries, terminfo data, and package metadata match the completed userspace.
Input assumption: ncurses-6.6-20260418.tgz is already present in /sources from the chapter 4 source staging step.
Source URL: https://invisible-mirror.net/archives/ncurses/current/ncurses-6.6-20260418.tgz
Upstream build note: the upstream INSTALL file and ./configure --help document the standard ./configure, make, and make install flow, plus the wide-character, shared-library, C++ binding, manpage-format, stripping, and pkg-config file switches used below.
Licenses:
- X11-style (ncurses)
Dependencies:
- musl (libc)
- awk
- make
- pkgconf
ncurses is a terminal handling library and terminfo toolkit. we need it to provide final target curses interfaces, terminal capability data, and pkg-config metadata for later software.
Extract and Enter the Source Tree
Remove any previous extracted ncurses tree before unpacking. ncurses generates build-time table sources such as ncurses/comp_captab.c and include/hashsize.h; stale copies from an earlier failed or cross build can be newer than the unpacked sources and break the final build.
cd /sources
rm -rf ncurses-6.6-20260418
tar -xf ncurses-6.6-20260418.tgz
cd ncurses-6.6-20260418
Configure ncurses
lbi_configure \
--with-manpage-format=normal \
--with-shared \
--without-normal \
--without-cxx-binding \
--without-debug \
--without-ada \
--enable-widec \
--disable-stripping \
--enable-pc-files \
--with-pkg-config-libdir=/system/libraries/pkgconfig \
AWK=awk
Pre-generate ncurses capability tables
ncurses generates include/hashsize.h from the capability tables in include/Caps and include/Caps-ncurses. In this target environment, the make frontend can mis-generate that file as a zero-entry table, which then creates an empty ncurses/comp_captab.c and fails with term.h and comp_captab.c disagree.
Replace the hash-size generator with an equivalent awk implementation, then pre-generate the capability tables before the full build. This keeps the main build from compiling a zero-entry comp_captab.c.
cat > include/MKhashsize.sh <<'EOF'
#!/bin/sh
echo "/*"
echo " * hashsize.h -- hash and token table constants"
echo " */"
awk '
/^[ #]/ { next }
/^$/ { next }
/^capalias/ { next }
/^infoalias/ { next }
/^userdef/ { next }
/^used_by/ { next }
{ ++n }
END {
print ""
printf "#define CAPTABSIZE\t%d\n", n
printf "#define HASHTABSIZE\t(%d * 2)\n", n
}
' "$@"
EOF
chmod +x include/MKhashsize.sh
sh include/MKhashsize.sh include/Caps include/Caps-ncurses > include/hashsize.h
captabsize=$(sed -n 's/^#define[[:space:]]*CAPTABSIZE[[:space:]]*//p' include/hashsize.h)
test "$captabsize" -gt 0
rm -f ncurses/comp_captab.c ncurses/comp_userdefs.c
make -C include sources
make -C ncurses make_hash
(
cd ncurses
sh -e ./tinfo/MKcaptab.sh \
awk \
1 \
./tinfo/MKcaptab.awk \
../include/Caps \
../include/Caps-ncurses \
> comp_captab.c
sh -e ./tinfo/MKuserdefs.sh \
awk \
1 \
../include/Caps \
../include/Caps-ncurses \
> comp_userdefs.c
)
Build ncurses
make $LWI_MAKE_FLAGS
Install ncurses
make install
Post-install Compatibility Adjustments
ln -sf libncursesw.so /system/libraries/libncurses.so
sed -e 's/^#if.*XOPEN.*$/#if 1/' \
-i '' /system/headers/curses.h
/sources if you do not plan to rebuild ncurses again.
Command Explanations
rm -rf ncurses-...: Removes stale generated files before rebuilding ncurses.lbi_configure: Configures ncurses with the book's install layout.--with-shared,--without-normal, and--enable-widec: Build shared wide-character ncurses libraries for the final target.--without-cxx-binding,--without-debug, and--without-ada: Skip optional bindings and debug outputs not needed here.cat > include/MKhashsize.sh: Replaces a generated helper script so hash table constants are produced consistently in this target build.make -j1: Builds serially to avoid ncurses generated-file races.make install: Installs ncurses into the target filesystem.ln -sf libncursesw.so ... libncurses.so: Provides the conventional ncurses library name.sed ... curses.h: Exposes X/Open declarations expected by later packages.