* m4/threadlib.m4: Refactor by prefering AS_CASE to case, " to ', $(...) to `, [[...]] to changequote, and #-to-newline to #-with-]. That way, Emacs commands recognize the sexps here. Omit some unnecessary quotes. --- ChangeLog | 6 ++ m4/threadlib.m4 | 183 ++++++++++++++++++++++-------------------------- 2 files changed, 89 insertions(+), 100 deletions(-)
diff --git a/ChangeLog b/ChangeLog index 84c5fecf1b..6a432b7950 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2025-04-27 Paul Eggert <egg...@cs.ucla.edu> + threadlib: make m4 work better with Emacs + * m4/threadlib.m4: Refactor by prefering AS_CASE to case, " to ', + $(...) to `, [[...]] to changequote, and #-to-newline to #-with-]. + That way, Emacs commands recognize the sexps here. + Omit some unnecessary quotes. + manywarnings: omit -Wdisabled-optimization * m4/manywarnings.m4 (gl_MANYWARN_ALL_GCC): Remove -Wdisabled-optimization, as this is a warning about the diff --git a/m4/threadlib.m4 b/m4/threadlib.m4 index 8f9a7d4b98..66fb542846 100644 --- a/m4/threadlib.m4 +++ b/m4/threadlib.m4 @@ -1,5 +1,5 @@ # threadlib.m4 -# serial 42 +# serial 43 dnl Copyright (C) 2005-2025 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -57,24 +57,22 @@ AC_DEFUN([gl_ANYTHREADLIB_EARLY] [ AC_REQUIRE([AC_CANONICAL_HOST]) if test -z "$gl_anythreadlib_early_done"; then - case "$host_os" in - osf*) - # On OSF/1, the compiler needs the flag -D_REENTRANT so that it + AS_CASE([$host_os], + [osf*], + [# On OSF/1, the compiler needs the flag -D_REENTRANT so that it # groks <pthread.h>. cc also understands the flag -pthread, but - # we don't use it because 1. gcc-2.95 doesn't understand -pthread, + # we do not use it because 1. gcc-2.95 does not understand -pthread, # 2. putting a flag into CPPFLAGS that has an effect on the linker # causes the AC_LINK_IFELSE test below to succeed unexpectedly, # leading to wrong values of LIBTHREAD and LTLIBTHREAD. CPPFLAGS="$CPPFLAGS -D_REENTRANT" - ;; - esac + ]) # Some systems optimize for single-threaded programs by default, and # need special flags to disable these optimizations. For example, the - # definition of 'errno' in <errno.h>. - case "$host_os" in - aix* | freebsd*) CPPFLAGS="$CPPFLAGS -D_THREAD_SAFE" ;; - solaris*) CPPFLAGS="$CPPFLAGS -D_REENTRANT" ;; - esac + # definition of errno in <errno.h>. + AS_CASE([$host_os], + [aix* | freebsd*], [CPPFLAGS="$CPPFLAGS -D_THREAD_SAFE"], + [solaris*], [CPPFLAGS="$CPPFLAGS -D_REENTRANT"]) gl_anythreadlib_early_done=done fi ]) @@ -86,21 +84,23 @@ AC_DEFUN([gl_WEAK_SYMBOLS] AC_REQUIRE([AC_CANONICAL_HOST]) AC_CACHE_CHECK([whether imported symbols can be declared weak], [gl_cv_have_weak], - [case "$host_os" in - cygwin* | mingw* | windows*) + [AS_CASE([$host_os], + [cygwin* | mingw* | windows*], + [ dnl On Cygwin 3.2.0 with gcc 10.2, and likewise on mingw 10.0.0 with dnl gcc 11.3, the test below would succeed, but programs that use dnl pthread_in_use() with weak symbol references crash miserably at dnl runtime. gl_cv_have_weak="guessing no" - ;; - *) + ], + [ gl_cv_have_weak=no dnl First, test whether the compiler accepts it syntactically. AC_LINK_IFELSE( [AC_LANG_PROGRAM( [[extern void xyzzy (); -#pragma weak xyzzy]], +#pragma weak xyzzy + ]], [[xyzzy();]])], [gl_cv_have_weak=maybe]) if test $gl_cv_have_weak = maybe; then @@ -127,19 +127,18 @@ AC_DEFUN([gl_WEAK_SYMBOLS] [gl_cv_have_weak="guessing no"]) ]) fi - ;; - esac - dnl But when linking statically, weak symbols don't work. - case " $LDFLAGS " in - *" -static "*) gl_cv_have_weak=no ;; - esac + ]) + dnl But when linking statically, weak symbols do not work. + AS_CASE([" $LDFLAGS "], + [*" -static "*], [gl_cv_have_weak=no]) dnl Test for a bug in FreeBSD 11: A link error occurs when using a weak dnl symbol and linking against a shared library that has a dependency on dnl the shared library that defines the symbol. - case "$gl_cv_have_weak" in - *yes) - case "$host_os" in - freebsd* | dragonfly* | midnightbsd*) + AS_CASE([$gl_cv_have_weak], + [*yes], + [AS_CASE([$host_os], + [freebsd* | dragonfly* | midnightbsd*], + [ : > conftest1.c $CC $CPPFLAGS $CFLAGS $LDFLAGS -fPIC -shared -o libempty.so conftest1.c -lpthread >&AS_MESSAGE_LOG_FD 2>&1 cat <<EOF > conftest2.c @@ -153,17 +152,13 @@ AC_DEFUN([gl_WEAK_SYMBOLS] $CC $CPPFLAGS $CFLAGS $LDFLAGS -o conftest conftest2.c libempty.so >&AS_MESSAGE_LOG_FD 2>&1 \ || gl_cv_have_weak=no rm -f conftest1.c libempty.so conftest2.c conftest - ;; - esac - ;; - esac + ])]) ]) - case "$gl_cv_have_weak" in - *yes) + AS_CASE([$gl_cv_have_weak], + [*yes], [ AC_DEFINE([HAVE_WEAK_SYMBOLS], [1], [Define to 1 if the compiler and linker support weak declarations of symbols.]) - ;; - esac + ]) ]) dnl ============================================================================ @@ -194,7 +189,7 @@ AC_DEFUN([gl_PTHREADLIB_BODY] LIBPTHREAD= LIBPMULTITHREAD= # On OSF/1, the compiler needs the flag -pthread or -D_REENTRANT so that - # it groks <pthread.h>. It's added above, in gl_ANYTHREADLIB_EARLY. + # it groks <pthread.h>. It is added above, in gl_ANYTHREADLIB_EARLY. AC_CHECK_HEADER([pthread.h], [gl_have_pthread_h=yes], [gl_have_pthread_h=no]) if test "$gl_have_pthread_h" = yes; then @@ -209,7 +204,7 @@ AC_DEFUN([gl_PTHREADLIB_BODY] # needs -pthread for some reason. See: # https://lists.gnu.org/r/bug-gnulib/2014-09/msg00023.html saved_LIBS="$LIBS" - for gl_pthread in '' '-pthread'; do + for gl_pthread in "" "-pthread"; do LIBS="$LIBS $gl_pthread" AC_LINK_IFELSE( [AC_LANG_PROGRAM( @@ -231,8 +226,7 @@ AC_DEFUN([gl_PTHREADLIB_BODY] gl_pthread_in_glibc=no # On Linux with glibc >= 2.34, libc contains the fully functional # pthread functions. - case "$host_os" in - linux*) + AS_CASE([$host_os], [linux*], [ AC_EGREP_CPP([Lucky user], [#include <features.h> #ifdef __GNU_LIBRARY__ @@ -243,8 +237,7 @@ AC_DEFUN([gl_PTHREADLIB_BODY] ], [gl_pthread_in_glibc=yes], []) - ;; - esac + ]) echo "$as_me:__oline__: gl_pthread_in_glibc=$gl_pthread_in_glibc" >&AS_MESSAGE_LOG_FD # Test for libpthread by looking for pthread_kill. (Not pthread_self, @@ -263,13 +256,12 @@ AC_DEFUN([gl_PTHREADLIB_BODY] # pthread_create will actually create a thread. # On Solaris 10 or newer, this test is no longer needed, because # libc contains the fully functional pthread functions. - case "$host_os" in -changequote(,)dnl - solaris | solaris2.[1-9] | solaris2.[1-9].* | hpux*) -changequote([,])dnl + AS_CASE([$host_os], + [[solaris | solaris2.[1-9] | solaris2.[1-9].* | hpux*]], + [ AC_DEFINE([PTHREAD_IN_USE_DETECTION_HARD], [1], [Define if the pthread_in_use() detection is hard.]) - esac + ]) fi ], [dnl This is needed on FreeBSD 5.2.1. @@ -309,7 +301,8 @@ AC_DEFUN([gl_PTHREADLIB_BODY] dnl On some systems, sched_yield is in librt, rather than in libpthread. AC_LINK_IFELSE( [AC_LANG_PROGRAM( - [[#include <sched.h>]], + [[#include <sched.h> + ]], [[sched_yield ();]])], [SCHED_YIELD_LIB= ], @@ -354,24 +347,26 @@ AC_DEFUN([gl_STDTHREADLIB_BODY] if test -z "$gl_stdthreadlib_body_done"; then AC_CHECK_HEADERS_ONCE([threads.h]) - case "$host_os" in - mingw* | windows*) + AS_CASE([$host_os], + [mingw* | windows*], + [ LIBSTDTHREAD= - ;; - *) + ], + [ gl_PTHREADLIB_BODY if test $ac_cv_header_threads_h = yes; then dnl glibc >= 2.29 has thrd_create in libpthread. dnl FreeBSD >= 10 has thrd_create in libstdthreads; this library depends - dnl on libpthread (for the symbol 'pthread_mutexattr_gettype'). + dnl on libpthread (for the symbol pthread_mutexattr_gettype). dnl glibc >= 2.34, AIX >= 7.1, and Solaris >= 11.4 have thrd_create in dnl libc. - gl_CHECK_FUNCS_ANDROID([thrd_create], [[#include <threads.h>]]) + gl_CHECK_FUNCS_ANDROID([thrd_create], [[#include <threads.h> + ]]) if test $ac_cv_func_thrd_create = yes; then LIBSTDTHREAD= else AC_CHECK_LIB([stdthreads], [thrd_create], [ - LIBSTDTHREAD='-lstdthreads -lpthread' + LIBSTDTHREAD="-lstdthreads -lpthread" ], [ dnl Guess that thrd_create is in libpthread. LIBSTDTHREAD="$LIBPMULTITHREAD" @@ -381,8 +376,7 @@ AC_DEFUN([gl_STDTHREADLIB_BODY] dnl Libraries needed by thrd.c, mtx.c, cnd.c, tss.c. LIBSTDTHREAD="$LIBPMULTITHREAD $SCHED_YIELD_LIB" fi - ;; - esac + ]) AC_SUBST([LIBSTDTHREAD]) AC_MSG_CHECKING([whether ISO C threads API is available]) @@ -405,7 +399,7 @@ AC_DEFUN([gl_STDTHREADLIB] dnl Tests for a multithreading library to be used. dnl If the configure.ac contains a definition of the gl_THREADLIB_DEFAULT_NO dnl (it must be placed before the invocation of gl_THREADLIB_EARLY!), then the -dnl default is 'no', otherwise it is system dependent. In both cases, the user +dnl default is "no", otherwise it is system dependent. In both cases, the user dnl can change the choice through the options --enable-threads=choice or dnl --disable-threads. dnl Defines at most one of the macros USE_ISOC_THREADS, USE_POSIX_THREADS, @@ -450,7 +444,7 @@ AC_DEFUN([gl_THREADLIB_EARLY_BODY] m4_ifdef([gl_THREADLIB_DEFAULT_NO], [m4_divert_text([DEFAULTS], [gl_use_threads_default=no])], [m4_divert_text([DEFAULTS], [gl_use_threads_default=])]) - dnl gl_use_winpthreads_default defaults to 'no', because in mingw 10, like + dnl gl_use_winpthreads_default defaults to "no", because in mingw 10, like dnl in mingw 5, the use of libwinpthread still makes test-pthread-tss crash. m4_divert_text([DEFAULTS], [gl_use_winpthreads_default=no]) AC_ARG_ENABLE([threads], @@ -460,32 +454,25 @@ AC_DEFUN([gl_THREADLIB_EARLY_BODY] [if test -n "$gl_use_threads_default"; then gl_use_threads="$gl_use_threads_default" else -changequote(,)dnl - case "$host_os" in + AS_CASE([$host_os], dnl Disable multithreading by default on OSF/1, because it interferes dnl with fork()/exec(): When msgexec is linked with -lpthread, its dnl child process gets an endless segmentation fault inside execvp(). - osf*) gl_use_threads=no ;; + [osf*], [gl_use_threads=no], dnl Disable multithreading by default on Cygwin 1.5.x, because it has dnl bugs that lead to endless loops or crashes. See dnl <https://cygwin.com/ml/cygwin/2009-08/msg00283.html>. - cygwin*) - case `uname -r` in - 1.[0-5].*) gl_use_threads=no ;; - *) gl_use_threads=yes ;; - esac - ;; + [cygwin*], + [AS_CASE([$(uname -r)], + [[1.[0-5].*]], [gl_use_threads=no], + [gl_use_threads=yes])], dnl Obey gl_AVOID_WINPTHREAD on mingw. - mingw* | windows*) - case "$gl_use_winpthreads_default" in - yes) gl_use_threads=posix ;; - no) gl_use_threads=windows ;; - *) gl_use_threads=yes ;; - esac - ;; - *) gl_use_threads=yes ;; - esac -changequote([,])dnl + [mingw* | windows*], + [AS_CASE([$gl_use_winpthreads_default], + [yes], [gl_use_threads=posix], + [no], [gl_use_threads=windows], + [gl_use_threads=yes])], + [gl_use_threads=yes]) fi ]) if test "$gl_use_threads" = yes \ @@ -510,13 +497,13 @@ AC_DEFUN([gl_THREADLIB_BODY] if test "$gl_use_threads" != no; then dnl Check whether the compiler and linker support weak declarations. gl_WEAK_SYMBOLS - if case "$gl_cv_have_weak" in *yes) true;; *) false;; esac; then + AS_CASE([$gl_cv_have_weak], [*yes], [ dnl If we use weak symbols to implement pthread_in_use / pth_in_use / dnl thread_in_use, we also need to test whether the ISO C 11 thrd_create dnl facility is in use. AC_CHECK_HEADERS_ONCE([threads.h]) : - fi + ]) if test "$gl_use_threads" = isoc || test "$gl_use_threads" = isoc+posix; then AC_CHECK_HEADERS_ONCE([threads.h]) gl_have_isoc_threads="$ac_cv_header_threads_h" @@ -529,7 +516,7 @@ AC_DEFUN([gl_THREADLIB_BODY] LIBMULTITHREAD=$LIBPMULTITHREAD LTLIBMULTITHREAD=$LIBPMULTITHREAD if test $gl_pthread_api = yes; then if test "$gl_use_threads" = isoc+posix && test "$gl_have_isoc_threads" = yes; then - gl_threads_api='isoc+posix' + gl_threads_api=isoc+posix AC_DEFINE([USE_ISOC_AND_POSIX_THREADS], [1], [Define if the combination of the ISO C and POSIX multithreading APIs can be used.]) LIBTHREAD= LTLIBTHREAD= @@ -541,22 +528,23 @@ AC_DEFUN([gl_THREADLIB_BODY] AC_DEFINE([USE_POSIX_THREADS_FROM_LIBC], [1], [Define if references to the POSIX multithreading library are satisfied by libc.]) else - if case "$gl_cv_have_weak" in *yes) true;; *) false;; esac; then + AS_CASE([$gl_cv_have_weak], [*yes], + [ AC_DEFINE([USE_POSIX_THREADS_WEAK], [1], [Define if references to the POSIX multithreading library should be made weak.]) LIBTHREAD= LTLIBTHREAD= - else - case "$host_os" in - freebsd* | dragonfly* | midnightbsd*) + ], + [AS_CASE([$host_os], + [freebsd* | dragonfly* | midnightbsd*], + [ if test "x$LIBTHREAD" != "x$LIBMULTITHREAD"; then - dnl If weak symbols can't tell whether pthread_create(), pthread_key_create() + dnl If weak symbols cannot tell whether + dnl pthread_create(), dnl pthread_key_create() dnl etc. will succeed, we need a runtime test. AC_DEFINE([PTHREAD_IN_USE_DETECTION_HARD], [1], [Define if the pthread_in_use() detection is hard.]) fi - ;; - esac - fi + ])]) fi fi fi @@ -572,19 +560,14 @@ AC_DEFUN([gl_THREADLIB_BODY] fi fi if test $gl_threads_api = none; then - case "$gl_use_threads" in - yes | windows | win32) # The 'win32' is for backward compatibility. - if { case "$host_os" in - mingw* | windows*) true;; - *) false;; - esac - }; then + # The "win32" is for backward compatibility. + AS_CASE([$gl_use_threads], [yes | windows | win32], + [AS_CASE([$host_os], [mingw* | windows*], + [ gl_threads_api=windows AC_DEFINE([USE_WINDOWS_THREADS], [1], [Define if the native Windows multithreading API can be used.]) - fi - ;; - esac + ])]) fi else dnl "$gl_use_threads" is "no". @@ -610,7 +593,7 @@ AC_DEFUN([gl_THREADLIB] dnl ------------------ dnl Sets the gl_THREADLIB default so that threads are not used by default. dnl The user can still override it at installation time, by using the -dnl configure option '--enable-threads'. +dnl configure option "--enable-threads". AC_DEFUN([gl_DISABLE_THREADS], [ m4_divert_text([INIT_PREPARE], [gl_use_threads_default=no]) @@ -622,7 +605,7 @@ AC_DEFUN([gl_DISABLE_THREADS] dnl Sets the gl_THREADLIB default so that on mingw, a dependency to the dnl libwinpthread DLL (mingw-w64 winpthreads library) is avoided. dnl The user can still override it at installation time, by using the -dnl configure option '--enable-threads=posix'. +dnl configure option "--enable-threads=posix". dnl As of 2023, this is now the default. AC_DEFUN([gl_AVOID_WINPTHREAD], [ -- 2.49.0