1dnl Checks for libcpath required headers and functions 2dnl 3dnl Version: 20190308 4 5dnl Function to detect if libcpath is available 6dnl ac_libcpath_dummy is used to prevent AC_CHECK_LIB adding unnecessary -l<library> arguments 7AC_DEFUN([AX_LIBCPATH_CHECK_LIB], 8 [AS_IF( 9 [test "x$ac_cv_enable_shared_libs" = xno || test "x$ac_cv_with_libcpath" = xno], 10 [ac_cv_libcpath=no], 11 [ac_cv_libcpath=check 12 dnl Check if the directory provided as parameter exists 13 AS_IF( 14 [test "x$ac_cv_with_libcpath" != x && test "x$ac_cv_with_libcpath" != xauto-detect], 15 [AS_IF( 16 [test -d "$ac_cv_with_libcpath"], 17 [CFLAGS="$CFLAGS -I${ac_cv_with_libcpath}/include" 18 LDFLAGS="$LDFLAGS -L${ac_cv_with_libcpath}/lib"], 19 [AC_MSG_FAILURE( 20 [no such directory: $ac_cv_with_libcpath], 21 [1]) 22 ]) 23 ], 24 [dnl Check for a pkg-config file 25 AS_IF( 26 [test "x$cross_compiling" != "xyes" && test "x$PKGCONFIG" != "x"], 27 [PKG_CHECK_MODULES( 28 [libcpath], 29 [libcpath >= 20180716], 30 [ac_cv_libcpath=yes], 31 [ac_cv_libcpath=check]) 32 ]) 33 AS_IF( 34 [test "x$ac_cv_libcpath" = xyes && test "x$ac_cv_enable_wide_character_type" != xno], 35 [AC_CACHE_CHECK( 36 [whether libcpath/features.h defines LIBCPATH_HAVE_WIDE_CHARACTER_TYPE as 1], 37 [ac_cv_header_libcpath_features_h_have_wide_character_type], 38 [AC_LANG_PUSH(C) 39 AC_COMPILE_IFELSE( 40 [AC_LANG_PROGRAM( 41 [[#include <libcpath/features.h>]], 42 [[#if !defined( LIBCPATH_HAVE_WIDE_CHARACTER_TYPE ) || ( LIBCPATH_HAVE_WIDE_CHARACTER_TYPE != 1 ) 43#error LIBCPATH_HAVE_WIDE_CHARACTER_TYPE not defined 44#endif]] )], 45 [ac_cv_header_libcpath_features_h_have_wide_character_type=yes], 46 [ac_cv_header_libcpath_features_h_have_wide_character_type=no]) 47 AC_LANG_POP(C)], 48 [ac_cv_header_libcpath_features_h_have_wide_character_type=no]) 49 50 AS_IF( 51 [test "x$ac_cv_header_libcpath_features_h_have_wide_character_type" = xno], 52 [ac_cv_libcpath=no]) 53 ]) 54 AS_IF( 55 [test "x$ac_cv_libcpath" = xyes], 56 [ac_cv_libcpath_CPPFLAGS="$pkg_cv_libcpath_CFLAGS" 57 ac_cv_libcpath_LIBADD="$pkg_cv_libcpath_LIBS"]) 58 ]) 59 60 AS_IF( 61 [test "x$ac_cv_libcpath" = xcheck], 62 [dnl Check for headers 63 AC_CHECK_HEADERS([libcpath.h]) 64 65 AS_IF( 66 [test "x$ac_cv_header_libcpath_h" = xno], 67 [ac_cv_libcpath=no], 68 [dnl Check for the individual functions 69 ac_cv_libcpath=yes 70 71 AC_CHECK_LIB( 72 cpath, 73 libcpath_get_version, 74 [ac_cv_libcpath_dummy=yes], 75 [ac_cv_libcpath=no]) 76 77 dnl Path functions 78 AC_CHECK_LIB( 79 cpath, 80 libcpath_path_change_directory, 81 [ac_cv_libcpath_dummy=yes], 82 [ac_cv_libcpath=no]) 83 AC_CHECK_LIB( 84 cpath, 85 libcpath_path_get_current_working_directory, 86 [ac_cv_libcpath_dummy=yes], 87 [ac_cv_libcpath=no]) 88 AC_CHECK_LIB( 89 cpath, 90 libcpath_path_get_full_path, 91 [ac_cv_libcpath_dummy=yes], 92 [ac_cv_libcpath=no]) 93 AC_CHECK_LIB( 94 cpath, 95 libcpath_path_get_sanitized_filename, 96 [ac_cv_libcpath_dummy=yes], 97 [ac_cv_libcpath=no]) 98 AC_CHECK_LIB( 99 cpath, 100 libcpath_path_get_sanitized_path, 101 [ac_cv_libcpath_dummy=yes], 102 [ac_cv_libcpath=no]) 103 AC_CHECK_LIB( 104 cpath, 105 libcpath_path_join, 106 [ac_cv_libcpath_dummy=yes], 107 [ac_cv_libcpath=no]) 108 AC_CHECK_LIB( 109 cpath, 110 libcpath_path_make_directory, 111 [ac_cv_libcpath_dummy=yes], 112 [ac_cv_libcpath=no]) 113 114 AS_IF( 115 [test "x$ac_cv_enable_wide_character_type" != xno], 116 [AC_CHECK_LIB( 117 cpath, 118 libcpath_path_change_directory_wide, 119 [ac_cv_libcpath_dummy=yes], 120 [ac_cv_libcpath=no]) 121 AC_CHECK_LIB( 122 cpath, 123 libcpath_path_get_current_working_directory_wide, 124 [ac_cv_libcpath_dummy=yes], 125 [ac_cv_libcpath=no]) 126 AC_CHECK_LIB( 127 cpath, 128 libcpath_path_get_full_path_wide, 129 [ac_cv_libcpath_dummy=yes], 130 [ac_cv_libcpath=no]) 131 AC_CHECK_LIB( 132 cpath, 133 libcpath_path_get_sanitized_filename_wide, 134 [ac_cv_libcpath_dummy=yes], 135 [ac_cv_libcpath=no]) 136 AC_CHECK_LIB( 137 cpath, 138 libcpath_path_get_sanitized_path_wide, 139 [ac_cv_libcpath_dummy=yes], 140 [ac_cv_libcpath=no]) 141 AC_CHECK_LIB( 142 cpath, 143 libcpath_path_join_wide, 144 [ac_cv_libcpath_dummy=yes], 145 [ac_cv_libcpath=no]) 146 AC_CHECK_LIB( 147 cpath, 148 libcpath_path_make_directory_wide, 149 [ac_cv_libcpath_dummy=yes], 150 [ac_cv_libcpath=no]) 151 ]) 152 153 ac_cv_libcpath_LIBADD="-lcpath"]) 154 ]) 155 AS_IF( 156 [test "x$ac_cv_with_libcpath" != x && test "x$ac_cv_with_libcpath" != xauto-detect && test "x$ac_cv_libcpath" != xyes], 157 [AC_MSG_FAILURE( 158 [unable to find supported libcpath in directory: $ac_cv_with_libcpath], 159 [1]) 160 ]) 161 ]) 162 163 AS_IF( 164 [test "x$ac_cv_libcpath" = xyes], 165 [AC_DEFINE( 166 [HAVE_LIBCPATH], 167 [1], 168 [Define to 1 if you have the `cpath' library (-lcpath).]) 169 ]) 170 171 AS_IF( 172 [test "x$ac_cv_libcpath" = xyes], 173 [AC_SUBST( 174 [HAVE_LIBCPATH], 175 [1]) ], 176 [AC_SUBST( 177 [HAVE_LIBCPATH], 178 [0]) 179 ]) 180 ]) 181 182dnl Function to detect if mkdir is available 183dnl Also checks how to use mkdir 184AC_DEFUN([AX_LIBCPATH_CHECK_FUNC_MKDIR], 185 [AC_CHECK_FUNCS([mkdir]) 186 187 AS_IF( 188 [test "x$ac_cv_func_mkdir" = xyes], 189 [AC_MSG_CHECKING( 190 [how to use mkdir]) 191 192 SAVE_CFLAGS="$CFLAGS" 193 CFLAGS="$CFLAGS -Wall -Werror" 194 AC_LANG_PUSH(C) 195 196 AC_LINK_IFELSE( 197 [AC_LANG_PROGRAM( 198 [[#include <sys/stat.h> 199#include <sys/types.h>]], 200 [[mkdir( "", 0 )]] )], 201 [AC_MSG_RESULT( 202 [with additional mode argument]) 203 ac_cv_cv_mkdir_mode=yes], 204 [ac_cv_cv_mkdir_mode=no]) 205 206 AS_IF( 207 [test "x$ac_cv_cv_mkdir_mode" = xno], 208 [AC_LINK_IFELSE( 209 [AC_LANG_PROGRAM( 210 [[#include <io.h>]], 211 [[mkdir( "" )]] )], 212 [AC_MSG_RESULT( 213 [with single argument]) 214 ac_cv_cv_mkdir=yes], 215 [ac_cv_cv_mkdir=no]) 216 ]) 217 218 AC_LANG_POP(C) 219 CFLAGS="$SAVE_CFLAGS" 220 221 AS_IF( 222 [test "x$ac_cv_cv_mkdir_mode" = xno && test "x$ac_cv_cv_mkdir" = xno], 223 [AC_MSG_WARN( 224 [unknown]) 225 ac_cv_func_mkdir=no]) 226 227 AS_IF( 228 [test "x$ac_cv_func_mkdir" = xyes], 229 [AC_DEFINE( 230 [HAVE_MKDIR], 231 [1], 232 [Define to 1 if you have the mkdir function.]) 233 ]) 234 235 AS_IF( 236 [test "x$ac_cv_cv_mkdir_mode" = xyes], 237 [AC_DEFINE( 238 [HAVE_MKDIR_MODE], 239 [1], 240 [Define to 1 if you have the mkdir function with a second mode argument.]) 241 ]) 242 ]) 243 244 AS_IF( 245 [test "x$ac_cv_func_mkdir" = xno], 246 [AC_MSG_FAILURE( 247 [Missing function: mkdir], 248 [1]) 249 ]) 250 ]) 251 252dnl Function to detect if libcpath dependencies are available 253AC_DEFUN([AX_LIBCPATH_CHECK_LOCAL], 254 [dnl Headers included in libcpath/libcpath_path.h 255 AC_CHECK_HEADERS([errno.h sys/stat.h sys/syslimits.h]) 256 257 dnl Path functions used in libcpath/libcpath_path.h 258 AC_CHECK_FUNCS([chdir getcwd]) 259 260 AS_IF( 261 [test "x$ac_cv_func_chdir" != xyes], 262 [AC_MSG_FAILURE( 263 [Missing functions: chdir], 264 [1]) 265 ]) 266 267 AS_IF( 268 [test "x$ac_cv_func_getcwd" != xyes], 269 [AC_MSG_FAILURE( 270 [Missing functions: getcwd], 271 [1]) 272 ]) 273 274 AX_LIBCPATH_CHECK_FUNC_MKDIR 275 276 ac_cv_libcpath_CPPFLAGS="-I../libcpath"; 277 ac_cv_libcpath_LIBADD="../libcpath/libcpath.la"; 278 279 ac_cv_libcpath=local 280 ]) 281 282dnl Function to detect how to enable libcpath 283AC_DEFUN([AX_LIBCPATH_CHECK_ENABLE], 284 [AX_COMMON_ARG_WITH( 285 [libcpath], 286 [libcpath], 287 [search for libcpath in includedir and libdir or in the specified DIR, or no if to use local version], 288 [auto-detect], 289 [DIR]) 290 291 dnl Check for a shared library version 292 AX_LIBCPATH_CHECK_LIB 293 294 dnl Check if the dependencies for the local library version 295 AS_IF( 296 [test "x$ac_cv_libcpath" != xyes], 297 [AX_LIBCPATH_CHECK_LOCAL 298 299 AC_DEFINE( 300 [HAVE_LOCAL_LIBCPATH], 301 [1], 302 [Define to 1 if the local version of libcpath is used.]) 303 AC_SUBST( 304 [HAVE_LOCAL_LIBCPATH], 305 [1]) 306 ]) 307 308 AM_CONDITIONAL( 309 [HAVE_LOCAL_LIBCPATH], 310 [test "x$ac_cv_libcpath" = xlocal]) 311 AS_IF( 312 [test "x$ac_cv_libcpath_CPPFLAGS" != "x"], 313 [AC_SUBST( 314 [LIBCPATH_CPPFLAGS], 315 [$ac_cv_libcpath_CPPFLAGS]) 316 ]) 317 AS_IF( 318 [test "x$ac_cv_libcpath_LIBADD" != "x"], 319 [AC_SUBST( 320 [LIBCPATH_LIBADD], 321 [$ac_cv_libcpath_LIBADD]) 322 ]) 323 324 AS_IF( 325 [test "x$ac_cv_libcpath" = xyes], 326 [AC_SUBST( 327 [ax_libcpath_pc_libs_private], 328 [-lcpath]) 329 ]) 330 331 AS_IF( 332 [test "x$ac_cv_libcpath" = xyes], 333 [AC_SUBST( 334 [ax_libcpath_spec_requires], 335 [libcpath]) 336 AC_SUBST( 337 [ax_libcpath_spec_build_requires], 338 [libcpath-devel]) 339 ]) 340 ]) 341 342