Building a testdir of module 'term-style-control' on CentOS 7, NetBSD, OpenBSD, I see a link error:
gcc -std=gnu11 -Wno-error -Wno-error -g -O2 -L/home/bruno/inst-x86_64-64/lib -Wl,-rpath,/home/bruno/inst-x86_64-64/lib -o test-term-style-control-hello test-term-style-control-hello.o libtests.a ../gllib/libgnu.a libtests.a ../gllib/libgnu.a libtests.a ../gllib/libgnu.a(term-style-control.o): In function `stopping_signal_handler': /home/bruno/testdir4/build-64/gllib/../../gllib/term-style-control.c:783: undefined reference to `pthread_kill' ../gllib/libgnu.a(term-style-control.o): In function `fatal_signal_handler': /home/bruno/testdir4/build-64/gllib/../../gllib/term-style-control.c:749: undefined reference to `pthread_kill' collect2: error: ld returned 1 exit status make[4]: *** [test-term-style-control-hello] Error 1 This patch fixes it. 2026-05-18 Bruno Haible <[email protected]> term-style-control: Make multithread-safe, part 6: Link dependencies. * m4/pthread_kill.m4: New file. * modules/term-style-control (Files): Add it. (configure.ac): Invoke gl_FUNC_PTHREAD_KILL. (Link): Add $(PTHREAD_SIGMASK_LIB) and $(PTHREAD_KILL_LIB). * modules/term-style-control-tests (Makefile.am): Link test-term-style-control-hello and test-term-style-control-yes with $(PTHREAD_SIGMASK_LIB) and $(PTHREAD_KILL_LIB). diff --git a/m4/pthread_kill.m4 b/m4/pthread_kill.m4 new file mode 100644 index 0000000000..8730f89aa8 --- /dev/null +++ b/m4/pthread_kill.m4 @@ -0,0 +1,50 @@ +# pthread_kill.m4 +# serial 1 +dnl Copyright (C) 2026 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. +dnl This file is offered as-is, without any warranty. + +dnl Set PTHREAD_KILL_LIB. +AC_DEFUN([gl_FUNC_PTHREAD_KILL], +[ + AC_REQUIRE([gl_PTHREADLIB]) + + AC_CHECK_FUNCS_ONCE([pthread_kill]) + + PTHREAD_KILL_LIB= + if test $ac_cv_func_pthread_kill = yes; then + dnl pthread_kill is available without -lpthread. + : + else + if test -n "$LIBPMULTITHREAD"; then + AC_CACHE_CHECK([for pthread_kill in $LIBPMULTITHREAD], + [gl_cv_func_pthread_kill_in_LIBPMULTITHREAD], + [gl_saved_LIBS="$LIBS" + LIBS="$LIBS $LIBPMULTITHREAD" + AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[#include <pthread.h> + #include <signal.h> + ]], + [[return pthread_kill (pthread_self (), SIGINT);]]) + ], + [gl_cv_func_pthread_kill_in_LIBPMULTITHREAD=yes], + [gl_cv_func_pthread_kill_in_LIBPMULTITHREAD=no]) + LIBS="$gl_saved_LIBS" + ]) + if test $gl_cv_func_pthread_kill_in_LIBPMULTITHREAD = yes; then + dnl pthread_kill is available with -pthread or -lpthread. + PTHREAD_KILL_LIB="$LIBPMULTITHREAD" + else + dnl pthread_kill is not available at all. + : + fi + else + dnl pthread_kill is not available at all. + : + fi + fi + AC_SUBST([PTHREAD_KILL_LIB]) +]) diff --git a/modules/term-style-control b/modules/term-style-control index 402c558e4f..8a8c0df680 100644 --- a/modules/term-style-control +++ b/modules/term-style-control @@ -5,6 +5,7 @@ Files: lib/term-style-control.h lib/term-style-control.c m4/tcgetattr.m4 +m4/pthread_kill.m4 Depends-on: bool @@ -25,6 +26,7 @@ configure.ac: AC_REQUIRE([AC_C_INLINE]) gl_HAVE_TCGETATTR AC_CHECK_HEADERS_ONCE([pthread.h]) +gl_FUNC_PTHREAD_KILL Makefile.am: lib_SOURCES += term-style-control.c @@ -34,6 +36,8 @@ Include: Link: $(LIBTHREAD) +$(PTHREAD_SIGMASK_LIB) +$(PTHREAD_KILL_LIB) $(LTLIBINTL) when linking with libtool, $(LIBINTL) otherwise License: diff --git a/modules/term-style-control-tests b/modules/term-style-control-tests index b1efef3e3e..8f05eedf69 100644 --- a/modules/term-style-control-tests +++ b/modules/term-style-control-tests @@ -17,6 +17,6 @@ Makefile.am: TESTS += test-term-style-control-hello check_PROGRAMS += test-term-style-control-hello noinst_PROGRAMS += test-term-style-control-yes test-term-style-control-yes-mt -test_term_style_control_hello_LDADD = $(LDADD) @LIBINTL@ $(LIBTHREAD) -test_term_style_control_yes_LDADD = $(LDADD) @LIBINTL@ $(LIBTHREAD) +test_term_style_control_hello_LDADD = $(LDADD) @LIBINTL@ $(LIBTHREAD) $(PTHREAD_SIGMASK_LIB) $(PTHREAD_KILL_LIB) +test_term_style_control_yes_LDADD = $(LDADD) @LIBINTL@ $(LIBTHREAD) $(PTHREAD_SIGMASK_LIB) $(PTHREAD_KILL_LIB) test_term_style_control_yes_mt_LDADD = $(LDADD) @LIBINTL@ $(LIBMULTITHREAD) $(NANOSLEEP_LIB)
