From 156615815cd9db9dfc55356939ec15d5d2ea5180 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Thu, 30 Nov 2023 21:31:06 -0500 Subject: [PATCH] Add a helper macro for gnulib monkey patches. Certain gnulib patches can be applied directly at m4 time, which makes it pretty simple to share between projects, and should be a bit more robust than e.g., patching conditional dependencies in bootstrap scripts. --- m4/gl-patches.m4 | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 m4/gl-patches.m4 diff --git a/m4/gl-patches.m4 b/m4/gl-patches.m4 new file mode 100644 index 0000000..5e4d3e1 --- /dev/null +++ b/m4/gl-patches.m4 @@ -0,0 +1,48 @@ +# Copyright © 2023 Nick Bowler +# +# Monkey patches for gnulib macros. +# +# License WTFPL2: Do What The Fuck You Want To Public License, version 2. +# This is free software: you are free to do what the fuck you want to. +# There is NO WARRANTY, to the extent permitted by law. + +# DX_PATCH_MACRO([macro-name], [regexp], [replacement]) +# +# Patches the definition of macro-name by replacing substrings that match +# the given regexp (a la m4_bpatsubst). +AC_DEFUN([DX_PATCH_MACRO], [m4_ifdef([$1], + [m4_define([$1], m4_bpatsubst(m4_dquote(m4_defn([$1])), [$2], [$3]))])]) + +# DX_PATCH_GNULIB +# +# Apply all the patches described below. Should be expanded before AC_INIT. +AC_DEFUN([DX_PATCH_GNULIB], + [m4_foreach_w([patch], m4_defn([_DX_GL_PATCHES]), + [m4_indir([_DX_GL_PATCH(]m4_defn([patch])[)])])]) + +m4_define([_DX_GL_PATCHES]) +m4_define([_DX_GL_PATCH], + [m4_define([_DX_GL_PATCH($1)], [$2])m4_define([_DX_GL_PATCHES], + m4_defn([_DX_GL_PATCHES])[ $1])]) + +# Patch if ! ... constructs produced by gnulib conditional dependencies +# as these fail in Solaris 10 /bin/sh. +_DX_GL_PATCH([gl-cond-deps], + [DX_PATCH_MACRO([gl_INIT], + [if ! *\(.*gnulib_enabled[^;]*\); then], + [if \1; then :; else])]) + +# Patch old versions of threadlib.m4, which have a quoting bug preventing +# correct determination of PTHREAD_IN_USE_DETECTION_HARD on Solaris 9 and +# earlier. If this is set incorrectly, libcdecl will crash on error. +_DX_GL_PATCH([gl-threadlib-solaris-fix], + [DX_PATCH_MACRO([gl_PTHREADLIB_BODY], + [solaris2\.\[1-9\]], [solaris2.@<:@1-9@:>@])]) + +# Patch old versions of threadlib to default to native Windows threads. +# This is the default behaviour in current upstream gnulib, and avoids +# pulling in extra libraries by default on MinGW. +_DX_GL_PATCH([gl-threadlib-mingw-default], + [DX_PATCH_MACRO([gl_THREADLIB_EARLY_BODY], + [\[gl_use_winpthreads_default=\]], + [[gl_use_winpthreads_default=no]])]) -- 2.43.2