ax_check_pcre2.m4 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. # ===========================================================================
  2. # https://www.gnu.org/software/autoconf-archive/ax_check_pcre2.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_CHECK_PCRE2([bits], [action-if-found], [action-if-not-found])
  8. #
  9. # DESCRIPTION
  10. #
  11. # Search for an installed libpcre2-8 library. If nothing was specified
  12. # when calling configure, it searches first in /usr/local and then in
  13. # /usr, /opt/local and /sw. If the --with-pcre2=DIR is specified, it will
  14. # try to find it in DIR/include/pcre2.h and DIR/lib/libpcre2-8. If
  15. # --without-pcre2 is specified, the library is not searched at all.
  16. #
  17. # If 'bits' is empty or '8', PCRE2 8-bit character support is checked
  18. # only. If 'bits' contains '16', PCRE2 8-bit and 16-bit character support
  19. # are checked. If 'bits' contains '32', PCRE2 8-bit and 32-bit character
  20. # support are checked. When 'bits' contains both '16' and '32', PCRE2
  21. # 8-bit, 16-bit, and 32-bit character support is checked.
  22. #
  23. # If either the header file (pcre2.h), or the library (libpcre2-8) is not
  24. # found, or the specified PCRE2 character bit width is not supported,
  25. # shell commands 'action-if-not-found' is run. If 'action-if-not-found' is
  26. # not specified, the configuration exits on error, asking for a valid
  27. # PCRE2 installation directory or --without-pcre2.
  28. #
  29. # If both header file and library are found, and the specified PCRE2 bit
  30. # widths are supported, shell commands 'action-if-found' is run. If
  31. # 'action-if-found' is not specified, the default action appends
  32. # '-I${PCRE2_HOME}/include' to CPFLAGS, appends '-L$PCRE2_HOME}/lib' to
  33. # LDFLAGS, prepends '-lpcre2-8' to LIBS, and calls AC_DEFINE(HAVE_PCRE2).
  34. # You should use autoheader to include a definition for this symbol in a
  35. # config.h file. Sample usage in a C/C++ source is as follows:
  36. #
  37. # #ifdef HAVE_PCRE2
  38. # #define PCRE2_CODE_UNIT_WIDTH 8
  39. # #include <pcre2.h>
  40. # #endif /* HAVE_PCRE2 */
  41. #
  42. # LICENSE
  43. #
  44. # Copyright (c) 2020 Robert van Engelen <engelen@acm.org>
  45. #
  46. # This program is free software; you can redistribute it and/or modify it
  47. # under the terms of the GNU General Public License as published by the
  48. # Free Software Foundation; either version 2 of the License, or (at your
  49. # option) any later version.
  50. #
  51. # This program is distributed in the hope that it will be useful, but
  52. # WITHOUT ANY WARRANTY; without even the implied warranty of
  53. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  54. # Public License for more details.
  55. #
  56. # You should have received a copy of the GNU General Public License along
  57. # with this program. If not, see <https://www.gnu.org/licenses/>.
  58. #
  59. # As a special exception, the respective Autoconf Macro's copyright owner
  60. # gives unlimited permission to copy, distribute and modify the configure
  61. # scripts that are the output of Autoconf when processing the Macro. You
  62. # need not follow the terms of the GNU General Public License when using
  63. # or distributing such scripts, even though portions of the text of the
  64. # Macro appear in them. The GNU General Public License (GPL) does govern
  65. # all other use of the material that constitutes the Autoconf Macro.
  66. #
  67. # This special exception to the GPL applies to versions of the Autoconf
  68. # Macro released by the Autoconf Archive. When you make and distribute a
  69. # modified version of the Autoconf Macro, you may extend this special
  70. # exception to the GPL to apply to your modified version as well.
  71. #serial 2
  72. AC_DEFUN([AX_CHECK_PCRE2],
  73. #
  74. # Handle user hints
  75. #
  76. [AC_MSG_CHECKING(if PCRE2 is wanted)
  77. pcre2_places="/usr/local /usr /opt/local /sw"
  78. AC_ARG_WITH([pcre2],
  79. [ --with-pcre2=DIR root directory path of PCRE2 installation @<:@defaults to
  80. /usr/local or /usr if not found in /usr/local@:>@
  81. --without-pcre2 to disable PCRE2 usage completely],
  82. [if test "$withval" != "no" ; then
  83. AC_MSG_RESULT(yes)
  84. if test -d "$withval"
  85. then
  86. pcre2_places="$withval $pcre2_places"
  87. else
  88. AC_MSG_WARN([Sorry, $withval does not exist, checking usual places])
  89. fi
  90. else
  91. pcre2_places=""
  92. AC_MSG_RESULT(no)
  93. fi],
  94. [AC_MSG_RESULT(yes)])
  95. #
  96. # Locate PCRE2, if wanted
  97. #
  98. if test -n "${pcre2_places}"
  99. then
  100. # check the user supplied or any other more or less 'standard' place:
  101. # Most UNIX systems : /usr/local and /usr
  102. # MacPorts / Fink on OSX : /opt/local respectively /sw
  103. for PCRE2_HOME in ${pcre2_places} ; do
  104. if test -f "${PCRE2_HOME}/include/pcre2.h"; then break; fi
  105. PCRE2_HOME=""
  106. done
  107. PCRE2_OLD_LDFLAGS=$LDFLAGS
  108. PCRE2_OLD_CPPFLAGS=$CPPFLAGS
  109. if test -n "${PCRE2_HOME}"; then
  110. LDFLAGS="$LDFLAGS -L${PCRE2_HOME}/lib"
  111. CPPFLAGS="$CPPFLAGS -I${PCRE2_HOME}/include"
  112. fi
  113. AC_LANG_PUSH([C])
  114. AC_CHECK_LIB([pcre2-8], [pcre2_compile_8], [pcre2_cv_libpcre2=yes], [pcre2_cv_libpcre2=no])
  115. AC_CHECK_HEADER([pcre2.h], [pcre2_cv_pcre2_h=yes], [pcre2_cv_pcre2_h=no], [#define PCRE2_CODE_UNIT_WIDTH 8])
  116. case "$1" in
  117. *16*)
  118. AC_CHECK_LIB([pcre2-16], [pcre2_compile_16], [pcre2_cv_libpcre2_16=yes], [pcre2_cv_libpcre2_16=no])
  119. AC_CHECK_HEADER([pcre2.h], [pcre2_cv_pcre2_16_h=yes], [pcre2_cv_pcre2_16_h=no], [#define PCRE2_CODE_UNIT_WIDTH 16])
  120. if test "$pcre2_cv_libpcre2_16" = "no" || test "$pcre2_cv_pcre2_16_h" = "no"; then
  121. pcre2_cv_libpcre2=no
  122. fi
  123. ;;
  124. esac
  125. case "$1" in
  126. *32*)
  127. AC_CHECK_LIB([pcre2-32], [pcre2_compile_32], [pcre2_cv_libpcre2_32=yes], [pcre2_cv_libpcre2_32=no])
  128. AC_CHECK_HEADER([pcre2.h], [pcre2_cv_pcre2_32_h=yes], [pcre2_cv_pcre2_32_h=no], [#define PCRE2_CODE_UNIT_WIDTH 32])
  129. if test "$pcre2_cv_libpcre2_32" = "no" || test "$pcre2_cv_pcre2_32_h" = "no"; then
  130. pcre2_cv_libpcre2=no
  131. fi
  132. esac
  133. AC_LANG_POP([C])
  134. if test "$pcre2_cv_libpcre2" = "yes" && test "$pcre2_cv_pcre2_h" = "yes"
  135. then
  136. #
  137. # If both library and header were found, action-if-found
  138. #
  139. m4_ifblank([$2],[
  140. CPPFLAGS="$CPPFLAGS -I${PCRE2_HOME}/include"
  141. LDFLAGS="$LDFLAGS -L${PCRE2_HOME}/lib"
  142. LIBS="-lpcre2-8 $LIBS"
  143. AC_DEFINE([HAVE_PCRE2], [1],
  144. [Define to 1 if you have `PCRE2' library (-lpcre2-$1)])
  145. ],[
  146. # Restore variables
  147. LDFLAGS="$PCRE2_OLD_LDFLAGS"
  148. CPPFLAGS="$PCRE2_OLD_CPPFLAGS"
  149. $2
  150. ])
  151. else
  152. #
  153. # If either header or library was not found, action-if-not-found
  154. #
  155. m4_default([$3],[
  156. AC_MSG_ERROR([either specify a valid PCRE2 installation with --with-pcre2=DIR or disable PCRE2 usage with --without-pcre2])
  157. ])
  158. fi
  159. fi
  160. ])