Skip to content

Commit daa8b6d

Browse files
committed
Fix static build on Linux with ncurses
When compiling our static ncurses, we need to have a valid TERMINFO variable, so that the fallback terminfo database can be retrieved. This must be a terminfo database in the newer, hashed format (hex directories), as required by ncurses >= 6.1. Normally, that's what you get when installing terminfo on Linux. On MinGW, it's also available, but sometimes in a weird directory.
1 parent 15e06b1 commit daa8b6d

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

Makefile

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,32 @@ WIN_CMOCKA_DIR = vendor/cmocka-$(WIN_CMOCKA_VERSION)
4343
package win32.package package_common utest win32.utest static
4444

4545

46+
define TERMINFO_SCRIPT
47+
#!/usr/bin/env bash
48+
49+
# Script to determine a value for TERMINFO and echo it on stdout
50+
51+
declare -r TERMINFO_FALLBACK=/mnt/c/MinGW/lib/terminfo
52+
53+
if [[ -n $${TERMINFO} && -d $${TERMINFO}/78 ]]; then
54+
echo "Modern terminfo database found." >&2
55+
echo $${TERMINFO}
56+
else
57+
echo "WARNING: Terminfo database not found or outdated." >&2
58+
if [[ -d $${TERMINFO_FALLBACK}/78 ]]; then
59+
echo "Using $${TERMINFO_FALLBACK} as fallback." >&2
60+
echo $${TERMINFO_FALLBACK}
61+
else
62+
echo "ERROR: Fallback unavailable. " >&2
63+
echo -n "Find a terminfo database that uses a hashed structure " >&2
64+
echo "(hexadecimal numbers as directories, not single letters). " >&2
65+
echo "Set its path in the TERMINFO_FALLBACK variable near the top of the root Makefile." >&2
66+
exit 1
67+
fi
68+
fi
69+
endef
70+
71+
4672
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
4773
# Build
4874
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -124,10 +150,17 @@ vendor/libncurses-$(LIBNCURSES_VERSION).tar.gz: | vendor
124150
curl -L https://invisible-mirror.net/archives/ncurses/ncurses-$(LIBNCURSES_VERSION).tar.gz --output $@
125151

126152
$(LIBNCURSES_DIR)/lib/libncurses.a: vendor/libncurses-$(LIBNCURSES_VERSION).tar.gz
153+
@echo TERMINFO=${TERMINFO}
127154
tar -C vendor -xzf vendor/libncurses-$(LIBNCURSES_VERSION).tar.gz
128-
cd $(LIBNCURSES_DIR) ; ./configure --enable-static ; $(MAKE)
155+
cd $(LIBNCURSES_DIR) ; ./configure --enable-static --enable-termcap; $(MAKE)
156+
157+
export TERMINFO_SCRIPT
158+
$(OUT_DIR)/terminfo-check.sh: | $(OUT_DIR)
159+
echo "$$TERMINFO_SCRIPT" > $@
129160

130-
static: infomsg replaceinfos $(LIBUNISTRING_DIR)/lib/.libs/libunistring.a $(PCRE2_DIR)/.libs/libpcre2-32.a $(LIBNCURSES_DIR)/lib/libncurses.a
161+
static: infomsg replaceinfos $(LIBUNISTRING_DIR)/lib/.libs/libunistring.a $(PCRE2_DIR)/.libs/libpcre2-32.a $(OUT_DIR)/terminfo-check.sh
162+
TERMINFO=`$(OUT_DIR)/terminfo-check.sh` \
163+
$(MAKE) LIBNCURSES_DIR=$(LIBNCURSES_DIR) LIBNCURSES_VERSION=$(LIBNCURSES_VERSION) $(LIBNCURSES_DIR)/lib/libncurses.a
131164
$(MAKE) -C src BOXES_PLATFORM=static LEX=$(BX_LEX) YACC=$(BX_YACC) LIBUNISTRING_DIR=$(LIBUNISTRING_DIR) \
132165
PCRE2_DIR=$(PCRE2_DIR) LIBNCURSES_DIR=$(LIBNCURSES_DIR) LIBNCURSES_WIN_INCLUDE=$(LIBNCURSES_WIN_INCLUDE) $@
133166

0 commit comments

Comments
 (0)