| 1 |
dnl Checks for libcsplit required headers and functions |
| 2 |
dnl |
| 3 |
dnl Version: 20240513 |
| 4 |
|
| 5 |
dnl Function to detect if libcsplit is available |
| 6 |
dnl ac_libcsplit_dummy is used to prevent AC_CHECK_LIB adding unnecessary -l<library> arguments |
| 7 |
AC_DEFUN([AX_LIBCSPLIT_CHECK_LIB], |
| 8 |
[AS_IF( |
| 9 |
[test "x$ac_cv_enable_shared_libs" = xno || test "x$ac_cv_with_libcsplit" = xno], |
| 10 |
[ac_cv_libcsplit=no], |
| 11 |
[ac_cv_libcsplit=check |
| 12 |
dnl Check if the directory provided as parameter exists |
| 13 |
dnl For both --with-libcsplit which returns "yes" and --with-libcsplit= which returns "" |
| 14 |
dnl treat them as auto-detection. |
| 15 |
AS_IF( |
| 16 |
[test "x$ac_cv_with_libcsplit" != x && test "x$ac_cv_with_libcsplit" != xauto-detect && test "x$ac_cv_with_libcsplit" != xyes], |
| 17 |
[AX_CHECK_LIB_DIRECTORY_EXISTS([libcsplit])], |
| 18 |
[dnl Check for a pkg-config file |
| 19 |
AS_IF( |
| 20 |
[test "x$cross_compiling" != "xyes" && test "x$PKGCONFIG" != "x"], |
| 21 |
[PKG_CHECK_MODULES( |
| 22 |
[libcsplit], |
| 23 |
[libcsplit >= 20120701], |
| 24 |
[ac_cv_libcsplit=yes], |
| 25 |
[ac_cv_libcsplit=check]) |
| 26 |
]) |
| 27 |
AS_IF( |
| 28 |
[test "x$ac_cv_libcsplit" = xyes && test "x$ac_cv_enable_wide_character_type" != xno], |
| 29 |
[AC_CACHE_CHECK( |
| 30 |
[whether libcsplit/features.h defines LIBCSPLIT_HAVE_WIDE_CHARACTER_TYPE as 1], |
| 31 |
[ac_cv_header_libcsplit_features_h_have_wide_character_type], |
| 32 |
[AC_LANG_PUSH(C) |
| 33 |
AC_COMPILE_IFELSE( |
| 34 |
[AC_LANG_PROGRAM( |
| 35 |
[[#include <libcsplit/features.h>]], |
| 36 |
[[#if !defined( LIBCSPLIT_HAVE_WIDE_CHARACTER_TYPE ) || ( LIBCSPLIT_HAVE_WIDE_CHARACTER_TYPE != 1 ) |
| 37 |
#error LIBCSPLIT_HAVE_WIDE_CHARACTER_TYPE not defined |
| 38 |
#endif]] )], |
| 39 |
[ac_cv_header_libcsplit_features_h_have_wide_character_type=yes], |
| 40 |
[ac_cv_header_libcsplit_features_h_have_wide_character_type=no]) |
| 41 |
AC_LANG_POP(C)], |
| 42 |
[ac_cv_header_libcsplit_features_h_have_wide_character_type=no]) |
| 43 |
|
| 44 |
AS_IF( |
| 45 |
[test "x$ac_cv_header_libcsplit_features_h_have_wide_character_type" = xno], |
| 46 |
[ac_cv_libcsplit=no]) |
| 47 |
]) |
| 48 |
AS_IF( |
| 49 |
[test "x$ac_cv_libcsplit" = xyes], |
| 50 |
[ac_cv_libcsplit_CPPFLAGS="$pkg_cv_libcsplit_CFLAGS" |
| 51 |
ac_cv_libcsplit_LIBADD="$pkg_cv_libcsplit_LIBS"]) |
| 52 |
]) |
| 53 |
|
| 54 |
AS_IF( |
| 55 |
[test "x$ac_cv_libcsplit" = xcheck], |
| 56 |
[dnl Check for headers |
| 57 |
AC_CHECK_HEADERS([libcsplit.h]) |
| 58 |
|
| 59 |
AS_IF( |
| 60 |
[test "x$ac_cv_header_libcsplit_h" = xno], |
| 61 |
[ac_cv_libcsplit=no], |
| 62 |
[ac_cv_libcsplit=yes |
| 63 |
|
| 64 |
AX_CHECK_LIB_FUNCTIONS( |
| 65 |
[libcsplit], |
| 66 |
[csplit], |
| 67 |
[[libcsplit_get_version], |
| 68 |
[libcsplit_narrow_string_split], |
| 69 |
[libcsplit_narrow_split_string_free], |
| 70 |
[libcsplit_narrow_split_string_get_string], |
| 71 |
[libcsplit_narrow_split_string_get_number_of_segments], |
| 72 |
[libcsplit_narrow_split_string_get_segment_by_index], |
| 73 |
[libcsplit_narrow_split_string_set_segment_by_index]]) |
| 74 |
|
| 75 |
dnl Wide string functions |
| 76 |
AS_IF( |
| 77 |
[test "x$ac_cv_enable_wide_character_type" != xno], |
| 78 |
[AX_CHECK_LIB_FUNCTIONS( |
| 79 |
[libcsplit], |
| 80 |
[csplit], |
| 81 |
[[libcsplit_wide_string_split], |
| 82 |
[libcsplit_wide_split_string_free], |
| 83 |
[libcsplit_wide_split_string_get_string], |
| 84 |
[libcsplit_wide_split_string_get_number_of_segments], |
| 85 |
[libcsplit_wide_split_string_get_segment_by_index], |
| 86 |
[libcsplit_wide_split_string_set_segment_by_index]]) |
| 87 |
]) |
| 88 |
|
| 89 |
ac_cv_libcsplit_LIBADD="-lcsplit"]) |
| 90 |
]) |
| 91 |
|
| 92 |
AX_CHECK_LIB_DIRECTORY_MSG_ON_FAILURE([libcsplit]) |
| 93 |
]) |
| 94 |
|
| 95 |
AS_IF( |
| 96 |
[test "x$ac_cv_libcsplit" = xyes], |
| 97 |
[AC_DEFINE( |
| 98 |
[HAVE_LIBCSPLIT], |
| 99 |
[1], |
| 100 |
[Define to 1 if you have the `csplit' library (-lcsplit).]) |
| 101 |
]) |
| 102 |
|
| 103 |
AS_IF( |
| 104 |
[test "x$ac_cv_libcsplit" = xyes], |
| 105 |
[AC_SUBST( |
| 106 |
[HAVE_LIBCSPLIT], |
| 107 |
[1]) ], |
| 108 |
[AC_SUBST( |
| 109 |
[HAVE_LIBCSPLIT], |
| 110 |
[0]) |
| 111 |
]) |
| 112 |
]) |
| 113 |
|
| 114 |
dnl Function to detect if libcsplit dependencies are available |
| 115 |
AC_DEFUN([AX_LIBCSPLIT_CHECK_LOCAL], |
| 116 |
[dnl No additional checks. |
| 117 |
|
| 118 |
ac_cv_libcsplit_CPPFLAGS="-I../libcsplit -I\$(top_srcdir)/libcsplit"; |
| 119 |
ac_cv_libcsplit_LIBADD="../libcsplit/libcsplit.la"; |
| 120 |
|
| 121 |
ac_cv_libcsplit=local |
| 122 |
]) |
| 123 |
|
| 124 |
dnl Function to detect how to enable libcsplit |
| 125 |
AC_DEFUN([AX_LIBCSPLIT_CHECK_ENABLE], |
| 126 |
[AX_COMMON_ARG_WITH( |
| 127 |
[libcsplit], |
| 128 |
[libcsplit], |
| 129 |
[search for libcsplit in includedir and libdir or in the specified DIR, or no if to use local version], |
| 130 |
[auto-detect], |
| 131 |
[DIR]) |
| 132 |
|
| 133 |
dnl Check for a shared library version |
| 134 |
AX_LIBCSPLIT_CHECK_LIB |
| 135 |
|
| 136 |
dnl Check if the dependencies for the local library version |
| 137 |
AS_IF( |
| 138 |
[test "x$ac_cv_libcsplit" != xyes], |
| 139 |
[AX_LIBCSPLIT_CHECK_LOCAL |
| 140 |
|
| 141 |
AC_DEFINE( |
| 142 |
[HAVE_LOCAL_LIBCSPLIT], |
| 143 |
[1], |
| 144 |
[Define to 1 if the local version of libcsplit is used.]) |
| 145 |
AC_SUBST( |
| 146 |
[HAVE_LOCAL_LIBCSPLIT], |
| 147 |
[1]) |
| 148 |
]) |
| 149 |
|
| 150 |
AM_CONDITIONAL( |
| 151 |
[HAVE_LOCAL_LIBCSPLIT], |
| 152 |
[test "x$ac_cv_libcsplit" = xlocal]) |
| 153 |
AS_IF( |
| 154 |
[test "x$ac_cv_libcsplit_CPPFLAGS" != "x"], |
| 155 |
[AC_SUBST( |
| 156 |
[LIBCSPLIT_CPPFLAGS], |
| 157 |
[$ac_cv_libcsplit_CPPFLAGS]) |
| 158 |
]) |
| 159 |
AS_IF( |
| 160 |
[test "x$ac_cv_libcsplit_LIBADD" != "x"], |
| 161 |
[AC_SUBST( |
| 162 |
[LIBCSPLIT_LIBADD], |
| 163 |
[$ac_cv_libcsplit_LIBADD]) |
| 164 |
]) |
| 165 |
|
| 166 |
AS_IF( |
| 167 |
[test "x$ac_cv_libcsplit" = xyes], |
| 168 |
[AC_SUBST( |
| 169 |
[ax_libcsplit_pc_libs_private], |
| 170 |
[-lcsplit]) |
| 171 |
]) |
| 172 |
|
| 173 |
AS_IF( |
| 174 |
[test "x$ac_cv_libcsplit" = xyes], |
| 175 |
[AC_SUBST( |
| 176 |
[ax_libcsplit_spec_requires], |
| 177 |
[libcsplit]) |
| 178 |
AC_SUBST( |
| 179 |
[ax_libcsplit_spec_build_requires], |
| 180 |
[libcsplit-devel]) |
| 181 |
]) |
| 182 |
]) |
| 183 |
|