]> git.draconx.ca Git - dxcommon.git/blob - m4/gl-patches.m4
Add a helper macro for gnulib monkey patches.
[dxcommon.git] / m4 / gl-patches.m4
1 # Copyright © 2023 Nick Bowler
2 #
3 # Monkey patches for gnulib macros.
4 #
5 # License WTFPL2: Do What The Fuck You Want To Public License, version 2.
6 # This is free software: you are free to do what the fuck you want to.
7 # There is NO WARRANTY, to the extent permitted by law.
8
9 # DX_PATCH_MACRO([macro-name], [regexp], [replacement])
10 #
11 # Patches the definition of macro-name by replacing substrings that match
12 # the given regexp (a la m4_bpatsubst).
13 AC_DEFUN([DX_PATCH_MACRO], [m4_ifdef([$1],
14   [m4_define([$1], m4_bpatsubst(m4_dquote(m4_defn([$1])), [$2], [$3]))])])
15
16 # DX_PATCH_GNULIB
17 #
18 # Apply all the patches described below.  Should be expanded before AC_INIT.
19 AC_DEFUN([DX_PATCH_GNULIB],
20   [m4_foreach_w([patch], m4_defn([_DX_GL_PATCHES]),
21     [m4_indir([_DX_GL_PATCH(]m4_defn([patch])[)])])])
22
23 m4_define([_DX_GL_PATCHES])
24 m4_define([_DX_GL_PATCH],
25   [m4_define([_DX_GL_PATCH($1)], [$2])m4_define([_DX_GL_PATCHES],
26     m4_defn([_DX_GL_PATCHES])[ $1])])
27
28 # Patch if ! ... constructs produced by gnulib conditional dependencies
29 # as these fail in Solaris 10 /bin/sh.
30 _DX_GL_PATCH([gl-cond-deps],
31   [DX_PATCH_MACRO([gl_INIT],
32     [if ! *\(.*gnulib_enabled[^;]*\); then],
33     [if \1; then :; else])])
34
35 # Patch old versions of threadlib.m4, which have a quoting bug preventing
36 # correct determination of PTHREAD_IN_USE_DETECTION_HARD on Solaris 9 and
37 # earlier.  If this is set incorrectly, libcdecl will crash on error.
38 _DX_GL_PATCH([gl-threadlib-solaris-fix],
39   [DX_PATCH_MACRO([gl_PTHREADLIB_BODY],
40     [solaris2\.\[1-9\]], [solaris2.@<:@1-9@:>@])])
41
42 # Patch old versions of threadlib to default to native Windows threads.
43 # This is the default behaviour in current upstream gnulib, and avoids
44 # pulling in extra libraries by default on MinGW.
45 _DX_GL_PATCH([gl-threadlib-mingw-default],
46   [DX_PATCH_MACRO([gl_THREADLIB_EARLY_BODY],
47     [\[gl_use_winpthreads_default=\]],
48     [[gl_use_winpthreads_default=no]])])