SchOS/ports/ncurses/Makefile
Nexoniarz d917798090 ports: ncurses, so zsh's line editor has a terminal to drive
zsh's configure will happily build without a terminal library -- the probe is
AC_SEARCH_LIBS, which is soft -- and produce a shell whose cursor cannot move
and whose arrow keys do nothing. ZLE is the reason to want zsh, so this comes
first.

MIT, so it combines with Apache-2.0 without conditions.

Built static, widec (which is what zsh looks for first, and the console's
UTF-8 decoder can already take), and --disable-database --with-fallbacks so
seven terminal descriptions are compiled into the library. SchOS has no
business shipping /usr/share/terminfo, and with the fallbacks the .a is
self-contained: verified that no terminfo path strings survive in the binary.

Nothing reaches sysroot/ -- a static library is not a file the OS ships -- so
`install` means into $(PREFIX). port.mk gains NCURSES beside MUSL for the
same reason MUSL is there.

tinfotest.c is the acceptance test, and asks the question the build cannot:
not "did it link" but "does terminfo work on a SchOS console". It reports
TIOCGWINSZ, initialises from the compiled-in fallback, and names every
capability ZLE binds. Anything MISSING there is a missing feature in the
shell later.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VQ7Qx8E1q1M1bbCq8QLHS2
2026-09-12 21:34:36 +02:00

115 lines
4.4 KiB
Makefile

# SPDX-License-Identifier: Apache-2.0
# ncurses -- terminal capability database and screen library, MIT:
# https://invisible-island.net/ncurses/
#
# Here because zsh's line editor is the reason to want zsh, and the line editor
# drives the terminal through tigetstr/tputs. zsh's configure will happily build
# without a terminal library -- AC_SEARCH_LIBS is soft -- and produce a shell
# whose cursor cannot move and whose arrow keys do nothing. So this comes first.
#
# Unlike every other port, nothing here reaches sysroot/. ncurses is built
# static and consumed at link time by zsh; `install` means "into $(PREFIX)".
#
# The awkward part of ncurses is that it is a library whose data is a database.
# Normally that database is ~4000 compiled terminal descriptions under
# /usr/share/terminfo, which SchOS has no business shipping. --disable-database
# plus --with-fallbacks compiles a chosen handful directly into the library, so
# the resulting .a is self-contained and the filesystem stays clean.
include ../mk/port.mk
NC_VERSION := 6.4
NC_URL := https://ftp.gnu.org/gnu/ncurses/ncurses-$(NC_VERSION).tar.gz
NC_SHA256 := 6931283d9ac87c5073f30b6290c4c75f21632bb4fc3603ac8100812bed248159
TARBALL := $(DISTDIR)/ncurses-$(NC_VERSION).tar.gz
# The terminal types compiled into the library. `linux` is what SchOS's own
# console is closest to and what TERM is set to; the rest are here so a serial
# console or an ssh client from a real machine still gets a working editor.
# Every name added is bytes in the binary, so this list is deliberately short.
NC_FALLBACKS := linux,vt100,vt102,xterm,xterm-256color,screen,dumb
# Cross-compiling ncurses needs tic and infocmp *on the host* to turn those
# names into C. Both exist here; the paths are looked up rather than written
# down because on NixOS they live in the store and move on every update.
HOST_TIC ?= $(shell command -v tic)
HOST_INFOCMP ?= $(shell command -v infocmp)
# gcc, for the same reason fastfetch uses it: -print-libgcc-file-name.
HOSTCC_NC ?= gcc
GCC_INC := $(shell $(HOSTCC_NC) -print-file-name=include)
LIBGCC := $(shell $(HOSTCC_NC) -print-libgcc-file-name)
# Split exactly as autoconf consumes them: it links a test as
# $CC $CFLAGS $LDFLAGS conftest.c $LIBS
# so crt1.o/crti.o must ride in LDFLAGS (before the object) and libc in LIBS
# (after it). libc twice -- libgcc reaches back into it, and a static link
# resolves left to right.
NC_CPPFLAGS := -nostdinc -isystem $(MUSL)/include -isystem $(GCC_INC) -D__SCHOS__
NC_CFLAGS := -O2 $(CFLAGS_BT)
NC_LDFLAGS := -static -nostdlib -L$(MUSL)/lib $(MUSL)/lib/crt1.o $(MUSL)/lib/crti.o
NC_LIBS := $(MUSL)/lib/libc.a $(LIBGCC) $(MUSL)/lib/libc.a $(MUSL)/lib/crtn.o
# ncurses builds make_hash and make_keys to run during the build, not on the
# target. In a cross build those must be compiled for the host, with the host's
# own libc -- hence a second, completely separate set of flags.
NC_BUILD_CC := $(HOSTCC_NC)
NC_CONFIGURE := \
--host=x86_64-linux-musl \
--build=x86_64-pc-linux-gnu \
--prefix=$(PREFIX) \
--disable-database \
--with-fallbacks=$(NC_FALLBACKS) \
--with-tic-path=$(HOST_TIC) \
--with-infocmp-path=$(HOST_INFOCMP) \
--without-shared --with-normal \
--enable-widec \
--enable-overwrite \
--without-cxx --without-cxx-binding \
--without-ada --without-tests --without-progs --without-manpages \
--without-debug --without-profile \
--disable-stripping \
--disable-home-terminfo \
--disable-rpath-hack
$(TARBALL): | $(DISTDIR)
curl -fsSL -o $@ $(NC_URL)
sh $(SHA256CHECK) "$(NC_SHA256)" "$@"
download: $(TARBALL)
$(SRCDIR): $(TARBALL)
mkdir -p $(PORTDIR)
tar -xzf $< -C $(PORTDIR)
mv $(PORTDIR)/ncurses-$(NC_VERSION) $@
extract: $(SRCDIR)
$(BUILDDIR)/config.status: | $(SRCDIR)
@test -n "$(HOST_TIC)" -a -n "$(HOST_INFOCMP)" || { \
echo "ncurses: host tic/infocmp not found -- install ncurses on the build host" >&2; \
exit 1; }
mkdir -p $(BUILDDIR)
cd $(BUILDDIR) && \
CC="$(HOSTCC_NC)" \
CPPFLAGS="$(NC_CPPFLAGS)" \
CFLAGS="$(NC_CFLAGS)" \
LDFLAGS="$(NC_LDFLAGS)" \
LIBS="$(NC_LIBS)" \
BUILD_CC="$(NC_BUILD_CC)" \
BUILD_CPPFLAGS= BUILD_CFLAGS= BUILD_LDFLAGS= BUILD_LIBS= \
$(SRCDIR)/configure $(NC_CONFIGURE)
$(PREFIX)/lib/libncursesw.a: $(BUILDDIR)/config.status
$(MAKE) -C $(BUILDDIR)
$(MAKE) -C $(BUILDDIR) install
build install: $(PREFIX)/lib/libncursesw.a
clean:
rm -rf $(PORTDIR)
distclean: clean
rm -f $(TARBALL)