less icon indicating copy to clipboard operation
less copied to clipboard

lesstest doesn't build properly on systems with split ncurses libraries

Open awilfox opened this issue 7 months ago • 4 comments

Since TERMLIB is hardcoded to be -lncurses in lesstest/Makefile:

gcc -O2 -ggdb -mcpu=970 -mtune=power9 -g  -o lesstest display.o env.o lesstest.o parse.o pipeline.o log.o run.o term.o wchar.o -lncurses 
/usr/lib/gcc/powerpc64-foxkit-linux-musl/13.3.0/../../../../powerpc64-foxkit-linux-musl/bin/ld: display.o: in function `display_screen':
/home/awilcox/Code/awilfox/system-next/system/less/src/less-678/lesstest/display.c:86:(.text+0x494): undefined reference to `tgoto'
/usr/lib/gcc/powerpc64-foxkit-linux-musl/13.3.0/../../../../powerpc64-foxkit-linux-musl/bin/ld: term.o: in function `setup_mode':
/home/awilcox/Code/awilfox/system-next/system/less/src/less-678/lesstest/term.c:83:(.text+0x38): undefined reference to `tgetstr'
/usr/lib/gcc/powerpc64-foxkit-linux-musl/13.3.0/../../../../powerpc64-foxkit-linux-musl/bin/ld: /home/awilcox/Code/awilfox/system-next/system/less/src/less-678/lesstest/term.c:85:(.text+0x54): undefined reference to `tgetstr'
/usr/lib/gcc/powerpc64-foxkit-linux-musl/13.3.0/../../../../powerpc64-foxkit-linux-musl/bin/ld: /home/awilcox/Code/awilfox/system-next/system/less/src/less-678/lesstest/term.c:85:(.text+0xa4): undefined reference to `tgetstr'
/usr/lib/gcc/powerpc64-foxkit-linux-musl/13.3.0/../../../../powerpc64-foxkit-linux-musl/bin/ld: /home/awilcox/Code/awilfox/system-next/system/less/src/less-678/lesstest/term.c:86:(.text+0xc4): undefined reference to `tgetstr'
/usr/lib/gcc/powerpc64-foxkit-linux-musl/13.3.0/../../../../powerpc64-foxkit-linux-musl/bin/ld: term.o: in function `setup_term':
/home/awilcox/Code/awilfox/system-next/system/less/src/less-678/lesstest/term.c:102:(.text+0x2e4): undefined reference to `tgetent'
/usr/lib/gcc/powerpc64-foxkit-linux-musl/13.3.0/../../../../powerpc64-foxkit-linux-musl/bin/ld: term.o: in function `ltgetstr':
/home/awilcox/Code/awilfox/system-next/system/less/src/less-678/lesstest/term.c:91:(.text+0x394): undefined reference to `tgetstr'
/usr/lib/gcc/powerpc64-foxkit-linux-musl/13.3.0/../../../../powerpc64-foxkit-linux-musl/bin/ld: /home/awilcox/Code/awilfox/system-next/system/less/src/less-678/lesstest/term.c:91:(.text+0x3c8): undefined reference to `tgetstr'
/usr/lib/gcc/powerpc64-foxkit-linux-musl/13.3.0/../../../../powerpc64-foxkit-linux-musl/bin/ld: /home/awilcox/Code/awilfox/system-next/system/less/src/less-678/lesstest/term.c:91:(.text+0x3ec): undefined reference to `tgetstr'
/usr/lib/gcc/powerpc64-foxkit-linux-musl/13.3.0/../../../../powerpc64-foxkit-linux-musl/bin/ld: /home/awilcox/Code/awilfox/system-next/system/less/src/less-678/lesstest/term.c:91:(.text+0x410): undefined reference to `tgetstr'
/usr/lib/gcc/powerpc64-foxkit-linux-musl/13.3.0/../../../../powerpc64-foxkit-linux-musl/bin/ld: /home/awilcox/Code/awilfox/system-next/system/less/src/less-678/lesstest/term.c:91:(.text+0x434): undefined reference to `tgetstr'
/usr/lib/gcc/powerpc64-foxkit-linux-musl/13.3.0/../../../../powerpc64-foxkit-linux-musl/bin/ld: term.o:/home/awilcox/Code/awilfox/system-next/system/less/src/less-678/lesstest/term.c:91: more undefined references to `tgetstr' follow
/usr/lib/gcc/powerpc64-foxkit-linux-musl/13.3.0/../../../../powerpc64-foxkit-linux-musl/bin/ld: term.o: in function `setup_term':
/home/awilcox/Code/awilfox/system-next/system/less/src/less-678/lesstest/term.c:102:(.text+0x83c): undefined reference to `tgetent'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:13: lesstest] Error 1

Changing it to -ltinfow works for me, but then of course it will break on systems without the split.

awilfox avatar May 31 '25 21:05 awilfox

htop's solution https://github.com/htop-dev/htop/blob/c292c232060e2e40c5b0351a16b1ad3493d9a88a/configure.ac#L669

polluks avatar Jun 02 '25 08:06 polluks

The problem is that the lesstest Makefile is not generated by autoconf. When I originally wrote lesstest, I was thinking that lesstest would be used only by developers working on the less code, and it wouldn't be much burden for the developer to need to edit the Makefile for their system. So I just used a static Makefile. But it would be better to automate this. Either lesstest should have its own configure.ac, or it should somehow import the settings from the main Makefile which is autoconf-generated.

gwsw avatar Jun 02 '25 16:06 gwsw

https://github.com/gwsw/less/pull/412

thesamesam avatar Jun 06 '25 01:06 thesamesam

Well, there's still the issue that #412 doesn't help if the system doesn't have pkg-config. I'm thinking of something like this, which uses whatever library was selected by autoconf for the main Makefile, and only depends on the existence of grep and sed.

diff --git a/lesstest/Makefile b/lesstest/Makefile
index 8ac00b6..f19f3e1 100644
--- a/lesstest/Makefile
+++ b/lesstest/Makefile
@@ -1,7 +1,7 @@
 CC ?= gcc
 CFLAGS ?= -Wall -O2
 LDFLAGS ?=
-TERMLIB = -lncurses
+TERMLIB = $(shell ( grep '^LIBS *=' ../Makefile 2>/dev/null || grep '^LIBS *=' ../obj/Makefile ) | sed 's/LIBS *=//')
 srcdir ?= .
 
 all: lesstest lt_screen 

gwsw avatar Jun 06 '25 04:06 gwsw

Fixed in 83bef2bbc3d4f2ca519a9f3973e2513adff44295.

gwsw avatar Jul 02 '25 19:07 gwsw