1dnl Checks for common headers and functions 2dnl 3dnl Version: 20170903 4 5dnl Function to test if a certain feature was enabled 6AC_DEFUN([AX_COMMON_ARG_ENABLE], 7[ 8 AC_ARG_ENABLE( 9 [$1], 10 [AS_HELP_STRING( 11 [--enable-$1], 12 [$3 [default=$4]])], 13 [ac_cv_enable_$2=$enableval], 14 [ac_cv_enable_$2=$4])dnl 15 16 AC_CACHE_CHECK( 17 [whether to enable $3], 18 [ac_cv_enable_$2], 19 [ac_cv_enable_$2=$4])dnl 20]) 21 22dnl Function to test if the location of a certain feature was provided 23AC_DEFUN([AX_COMMON_ARG_WITH], 24[ 25 AC_ARG_WITH( 26 [$1], 27 [AS_HELP_STRING( 28 [--with-$1[[=$5]]], 29 [$3 [default=$4]])], 30 [ac_cv_with_$2=$withval], 31 [ac_cv_with_$2=$4])dnl 32 33 AC_CACHE_CHECK( 34 [whether to use $3], 35 [ac_cv_with_$2], 36 [ac_cv_with_$2=$4])dnl 37]) 38 39dnl Function to detect whether WINAPI support should be enabled 40AC_DEFUN([AX_COMMON_CHECK_ENABLE_WINAPI], 41[ 42 AX_COMMON_ARG_ENABLE( 43 [winapi], 44 [winapi], 45 [enable WINAPI support for cross-compilation], 46 [auto-detect]) 47 48 AS_IF( 49 [test "x$ac_cv_enable_winapi" = xauto-detect], 50 [ac_common_check_winapi_target_string="$target" 51 52 AS_IF( 53 [test "x$ac_common_check_winapi_target_string" = x], 54 [ac_common_check_winapi_target_string="$host"]) 55 56 AS_CASE( 57 [$ac_common_check_winapi_target_string], 58 [*mingw*],[AC_MSG_NOTICE( 59 [detected MinGW enabling WINAPI support for cross-compilation]) 60 ac_cv_enable_winapi=yes], 61 [*],[ac_cv_enable_winapi=no]) 62 ]) 63]) 64 65dnl Function to detect whether static executables support should be enabled 66AC_DEFUN([AX_COMMON_CHECK_ENABLE_STATIC_EXECUTABLES], 67[ 68 AX_COMMON_ARG_ENABLE( 69 [static-executables], 70 [static_executables], 71 [build static executables (binaries)], 72 [no]) 73 74 AS_IF( 75 [test "x$ac_cv_enable_static_executables" != xno], 76 [STATIC_LDFLAGS="-all-static"; 77 78 AC_SUBST( 79 [STATIC_LDFLAGS]) 80 81 ac_cv_enable_static_executables=yes]) 82]) 83 84dnl Function to detect whether static executables support should be enabled 85AC_DEFUN([AX_COMMON_CHECK_ENABLE_WIDE_CHARACTER_TYPE], 86[ 87 AX_COMMON_ARG_ENABLE( 88 [wide-character-type], 89 [wide_character_type], 90 [enable wide character type support], 91 [no]) 92]) 93 94dnl Function to detect whether verbose output should be enabled 95AC_DEFUN([AX_COMMON_CHECK_ENABLE_VERBOSE_OUTPUT], 96[ 97 AX_COMMON_ARG_ENABLE( 98 [verbose-output], 99 [verbose_output], 100 [enable verbose output], 101 [no]) 102 103 AS_IF( 104 [test "x$ac_cv_enable_verbose_output" != xno ], 105 [AC_DEFINE( 106 [HAVE_VERBOSE_OUTPUT], 107 [1], 108 [Define to 1 if verbose output should be used.]) 109 110 ac_cv_enable_verbose_output=yes]) 111]) 112 113dnl Function to detect whether debug output should be enabled 114AC_DEFUN([AX_COMMON_CHECK_ENABLE_DEBUG_OUTPUT], 115[ 116 AX_COMMON_ARG_ENABLE( 117 [debug-output], 118 [debug_output], 119 [enable debug output], 120 [no]) 121 122 AS_IF( 123 [test "x$ac_cv_enable_debug_output" != xno ], 124 [AC_DEFINE( 125 [HAVE_DEBUG_OUTPUT], 126 [1], 127 [Define to 1 if debug output should be used.]) 128 129 ac_cv_enable_debug_output=yes]) 130]) 131 132dnl Function to detect whether printf conversion specifier "%jd" is available 133AC_DEFUN([AX_COMMON_CHECK_FUNC_PRINTF_JD], 134[ 135 AC_MSG_CHECKING( 136 [whether printf supports the conversion specifier "%jd"]) 137 138 SAVE_CFLAGS="$CFLAGS" 139 CFLAGS="$CFLAGS -Wall -Werror" 140 AC_LANG_PUSH(C) 141 142 dnl First try to see if compilation and linkage without a parameter succeeds 143 AC_LINK_IFELSE( 144 [AC_LANG_PROGRAM( 145 [[#include <stdio.h>]], 146 [[printf( "%jd" ); ]] )], 147 [ac_cv_cv_have_printf_jd=no], 148 [ac_cv_cv_have_printf_jd=yes]) 149 150 dnl Second try to see if compilation and linkage with a parameter succeeds 151 AS_IF( 152 [test "x$ac_cv_cv_have_printf_jd" = xyes], 153 [AC_LINK_IFELSE( 154 [AC_LANG_PROGRAM( 155 [[#include <sys/types.h> 156#include <stdio.h>]], 157 [[printf( "%jd", (off_t) 10 ); ]] )], 158 [ac_cv_cv_have_printf_jd=yes], 159 [ac_cv_cv_have_printf_jd=no]) 160 ]) 161 162 dnl Third try to see if the program runs correctly 163 AS_IF( 164 [test "x$ac_cv_cv_have_printf_jd" = xyes], 165 [AC_RUN_IFELSE( 166 [AC_LANG_PROGRAM( 167 [[#include <sys/types.h> 168#include <stdio.h>]], 169 [[char string[ 3 ]; 170if( snprintf( string, 3, "%jd", (off_t) 10 ) < 0 ) return( 1 ); 171if( ( string[ 0 ] != '1' ) || ( string[ 1 ] != '0' ) ) return( 1 ); ]] )], 172 [ac_cv_cv_have_printf_jd=yes], 173 [ac_cv_cv_have_printf_jd=no], 174 [ac_cv_cv_have_printf_jd=undetermined]) 175 ]) 176 177 AC_LANG_POP(C) 178 CFLAGS="$SAVE_CFLAGS" 179 180 AS_IF( 181 [test "x$ac_cv_cv_have_printf_jd" = xyes], 182 [AC_MSG_RESULT( 183 [yes]) 184 AC_DEFINE( 185 [HAVE_PRINTF_JD], 186 [1], 187 [Define to 1 whether printf supports the conversion specifier "%jd".]) ], 188 [AC_MSG_RESULT( 189 [$ac_cv_cv_have_printf_jd]) 190 ]) 191]) 192 193dnl Function to detect whether printf conversion specifier "%zd" is available 194AC_DEFUN([AX_COMMON_CHECK_FUNC_PRINTF_ZD], 195[ 196 AC_MSG_CHECKING( 197 [whether printf supports the conversion specifier "%zd"]) 198 199 SAVE_CFLAGS="$CFLAGS" 200 CFLAGS="$CFLAGS -Wall -Werror" 201 AC_LANG_PUSH(C) 202 203 dnl First try to see if compilation and linkage without a parameter succeeds 204 AC_LINK_IFELSE( 205 [AC_LANG_PROGRAM( 206 [[#include <stdio.h>]], 207 [[printf( "%zd" ); ]] )], 208 [ac_cv_cv_have_printf_zd=no], 209 [ac_cv_cv_have_printf_zd=yes]) 210 211 dnl Second try to see if compilation and linkage with a parameter succeeds 212 AS_IF( 213 [test "x$ac_cv_cv_have_printf_zd" = xyes], 214 [AC_LINK_IFELSE( 215 [AC_LANG_PROGRAM( 216 [[#include <sys/types.h> 217#include <stdio.h>]], 218 [[printf( "%zd", (size_t) 10 ); ]] )], 219 [ac_cv_cv_have_printf_zd=yes], 220 [ac_cv_cv_have_printf_zd=no]) 221 ]) 222 223 dnl Third try to see if the program runs correctly 224 AS_IF( 225 [test "x$ac_cv_cv_have_printf_zd" = xyes], 226 [AC_RUN_IFELSE( 227 [AC_LANG_PROGRAM( 228 [[#include <sys/types.h> 229#include <stdio.h>]], 230 [[char string[ 3 ]; 231if( snprintf( string, 3, "%zd", (size_t) 10 ) < 0 ) return( 1 ); 232if( ( string[ 0 ] != '1' ) || ( string[ 1 ] != '0' ) ) return( 1 ); ]] )], 233 [ac_cv_cv_have_printf_zd=yes], 234 [ac_cv_cv_have_printf_zd=no], 235 [ac_cv_cv_have_printf_zd=undetermined]) 236 ]) 237 238 AC_LANG_POP(C) 239 CFLAGS="$SAVE_CFLAGS" 240 241 AS_IF( 242 [test "x$ac_cv_cv_have_printf_zd" = xyes], 243 [AC_MSG_RESULT( 244 [yes]) 245 AC_DEFINE( 246 [HAVE_PRINTF_ZD], 247 [1], 248 [Define to 1 whether printf supports the conversion specifier "%zd".]) ], 249 [AC_MSG_RESULT( 250 [$ac_cv_cv_have_printf_zd]) 251 ]) 252]) 253 254dnl Function to detect if common dependencies are available 255AC_DEFUN([AX_COMMON_CHECK_LOCAL], 256[ 257 dnl Headers included in common/common.h 258 AS_IF( 259 [test "x$ac_cv_enable_winapi" = xyes], 260 [AC_CHECK_HEADERS([windows.h]) 261 262 AS_IF( 263 [test "x$ac_cv_header_windows_h" = xno], 264 [AC_MSG_FAILURE( 265 [Missing header: windows.h header is required to compile with winapi support], 266 [1]) 267 ]) 268 ]) 269 270 AS_IF( 271 [test "x$ac_cv_enable_winapi" = xno], 272 [AC_CHECK_HEADERS([libintl.h]) 273 ]) 274 275 dnl Headers included in common/types.h 276 AC_CHECK_HEADERS([limits.h]) 277 278 dnl Headers included in common/memory.h and common/narrow_string.h 279 AC_CHECK_HEADERS([stdlib.h string.h]) 280 281 dnl Headers included in common/wide_string.h 282 AC_CHECK_HEADERS([wchar.h wctype.h]) 283 284 dnl File stream functions used in common/file_stream.h 285 AC_CHECK_FUNCS([fclose feof fgets fopen fread fseeko fseeko64 fwrite vfprintf]) 286 287 AS_IF( 288 [test "x$ac_cv_func_fclose" != xyes], 289 [AC_MSG_FAILURE( 290 [Missing function: fclose], 291 [1]) 292 ]) 293 294 AS_IF( 295 [test "x$ac_cv_func_feof" != xyes], 296 [AC_MSG_FAILURE( 297 [Missing function: feof], 298 [1]) 299 ]) 300 301 AS_IF( 302 [test "x$ac_cv_func_fgets" != xyes], 303 [AC_MSG_FAILURE( 304 [Missing function: fgets], 305 [1]) 306 ]) 307 308 AS_IF( 309 [test "x$ac_cv_func_fopen" != xyes], 310 [AC_MSG_FAILURE( 311 [Missing function: fopen], 312 [1]) 313 ]) 314 315 AS_IF( 316 [test "x$ac_cv_func_fread" != xyes], 317 [AC_MSG_FAILURE( 318 [Missing function: fread], 319 [1]) 320 ]) 321 322 AS_IF( 323 [test "x$ac_cv_func_fseeko" != xyes && test "x$ac_cv_func_fseeko64" != xyes], 324 [AC_MSG_FAILURE( 325 [Missing function: fseeko and fseeko64], 326 [1]) 327 ]) 328 329 AS_IF( 330 [test "x$ac_cv_func_fwrite" != xyes], 331 [AC_MSG_FAILURE( 332 [Missing function: fwrite], 333 [1]) 334 ]) 335 336 AS_IF( 337 [test "x$ac_cv_func_vfprintf" != xyes], 338 [AC_MSG_FAILURE( 339 [Missing function: vfprintf], 340 [1]) 341 ]) 342 343 AS_IF( 344 [test "x$ac_cv_enable_wide_character_type" != xno], 345 [AC_CHECK_FUNCS([fgetws]) 346 347 AS_IF( 348 [test "x$ac_cv_func_fgetws" != xyes], 349 [AC_MSG_FAILURE( 350 [Missing function: fgetws], 351 [1]) 352 ]) 353 ]) 354 355 dnl Memory functions used in common/memory.h 356 AC_CHECK_FUNCS([free malloc memcmp memcpy memset realloc]) 357 358 AS_IF( 359 [test "x$ac_cv_func_free" != xyes], 360 [AC_MSG_FAILURE( 361 [Missing function: free], 362 [1]) 363 ]) 364 365 AS_IF( 366 [test "x$ac_cv_func_malloc" != xyes], 367 [AC_MSG_FAILURE( 368 [Missing function: malloc], 369 [1]) 370 ]) 371 372 AS_IF( 373 [test "x$ac_cv_func_memcmp" != xyes], 374 [AC_MSG_FAILURE( 375 [Missing function: memcmp], 376 [1]) 377 ]) 378 379 AS_IF( 380 [test "x$ac_cv_func_memcpy" != xyes], 381 [AC_MSG_FAILURE( 382 [Missing function: memcpy], 383 [1]) 384 ]) 385 386 AS_IF( 387 [test "x$ac_cv_func_memset" != xyes], 388 [AC_MSG_FAILURE( 389 [Missing function: memset], 390 [1]) 391 ]) 392 393 AS_IF( 394 [test "x$ac_cv_func_realloc" != xyes], 395 [AC_MSG_FAILURE( 396 [Missing function: realloc], 397 [1]) 398 ]) 399 400 dnl Narrow character string functions used in common/narrow_string.h 401 AC_CHECK_FUNCS([memchr memrchr snprintf sscanf strcasecmp strchr strlen strncasecmp strncmp strncpy strnicmp strrchr strstr vsnprintf]) 402 403 AS_IF( 404 [test "x$ac_cv_func_memchr" != xyes && test "x$ac_cv_func_strchr" != xyes], 405 [AC_MSG_FAILURE( 406 [Missing functions: memchr and strchr], 407 [1]) 408 ]) 409 410 AS_IF( 411 [test "x$ac_cv_func_memcmp" != xyes && test "x$ac_cv_func_strncmp" != xyes], 412 [AC_MSG_FAILURE( 413 [Missing functions: memcmp and strncmp], 414 [1]) 415 ]) 416 417 AS_IF( 418 [test "x$ac_cv_func_memcpy" != xyes && test "x$ac_cv_func_strncpy" != xyes], 419 [AC_MSG_FAILURE( 420 [Missing functions: memcpy and strncpy], 421 [1]) 422 ]) 423 424 AS_IF( 425 [test "x$ac_cv_func_memrchr" = xyes], 426 [AC_CHECK_DECLS([memrchr]) 427 428 AS_IF( 429 [test "x$ac_cv_decl_memrchr" != xyes], 430 [ac_cv_func_memrchr=no]) 431 ]) 432 433 AS_IF( 434 [test "x$ac_cv_func_memrchr" != xyes && test "x$ac_cv_func_strrchr" != xyes], 435 [AC_MSG_FAILURE( 436 [Missing functions: strrchr and memrchr], 437 [1]) 438 ]) 439 440 AS_IF( 441 [test "x$ac_cv_func_snprintf" != xyes], 442 [AC_MSG_FAILURE( 443 [Missing function: snprintf], 444 [1]) 445 ]) 446 447 AS_IF( 448 [test "x$ac_cv_func_sscanf" != xyes], 449 [AC_MSG_FAILURE( 450 [Missing function: sscanf], 451 [1]) 452 ]) 453 454 AS_IF( 455 [test "x$ac_cv_func_strlen" != xyes], 456 [AC_MSG_FAILURE( 457 [Missing function: strlen], 458 [1]) 459 ]) 460 461 AS_IF( 462 [test "x$ac_cv_func_strcasecmp" != xyes && test "x$ac_cv_func_strncasecmp" != xyes && test "x$ac_cv_func_strnicmp" != xyes], 463 [AC_MSG_FAILURE( 464 [Missing functions: strncasecmp, strcasecmp and strnicmp], 465 [1]) 466 ]) 467 468 AS_IF( 469 [test "x$ac_cv_func_strstr" != xyes], 470 [AC_MSG_FAILURE( 471 [Missing function: strstr], 472 [1]) 473 ]) 474 475 AS_IF( 476 [test "x$ac_cv_func_vsnprintf" != xyes], 477 [AC_MSG_FAILURE( 478 [Missing function: vsnprintf], 479 [1]) 480 ]) 481 482 dnl Wide character string functions used in common/wide_string.h 483 AS_IF( 484 [test "x$ac_cv_enable_wide_character_type" != xno], 485 [AC_CHECK_FUNCS([swprintf towlower wcscasecmp wcschr wcslen wcsncasecmp wcsncmp wcsncpy wcsnicmp wcsrchr wcsstr wmemchr wmemcmp wmemcpy wmemrchr]) 486 487 AS_IF( 488 [test "x$ac_cv_func_swprintf" != xyes], 489 [AC_MSG_FAILURE( 490 [Missing function: swprintf], 491 [1]) 492 ]) 493 494 AS_IF( 495 [test "x$ac_cv_func_wmemchr" != xyes && test "x$ac_cv_func_wcschr" != xyes], 496 [AC_MSG_FAILURE( 497 [Missing functions: wmemchr and wcschr], 498 [1]) 499 ]) 500 501 AS_IF( 502 [test "x$ac_cv_func_wmemcmp" != xyes && test "x$ac_cv_func_wcsncmp" != xyes], 503 [AC_MSG_FAILURE( 504 [Missing functions: wmemcmp and wcsncmp], 505 [1]) 506 ]) 507 508 AS_IF( 509 [test "x$ac_cv_func_wmemcpy" != xyes && test "x$ac_cv_func_wcsncpy" != xyes], 510 [AC_MSG_FAILURE( 511 [Missing functions: wmemcpy and wcsncpy], 512 [1]) 513 ]) 514 515 AS_IF( 516 [test "x$ac_cv_func_wmemrchr" != xyes && test "x$ac_cv_func_wcsrchr" != xyes], 517 [AC_MSG_FAILURE( 518 [Missing functions: wmemrchr and wcsrchr], 519 [1]) 520 ]) 521 522 AS_IF( 523 [test "x$ac_cv_func_wcslen" != xyes], 524 [AC_MSG_FAILURE( 525 [Missing function: wcslen], 526 [1]) 527 ]) 528 529 AS_IF( 530 [test "x$ac_cv_func_wcsncasecmp" != xyes && test "x$ac_cv_func_wcscasecmp" != xyes && test "x$ac_cv_func_wcsnicmp" != xyes && test "x$ac_cv_func_towlower" != xyes], 531 [AC_MSG_FAILURE( 532 [Missing functions: wcsncasecmp, wcscasecmp, wcsnicmp and towlower], 533 [1]) 534 ]) 535 536 AS_IF( 537 [test "x$ac_cv_func_wcsstr" != xyes], 538 [AC_MSG_FAILURE( 539 [Missing function: wcsstr], 540 [1]) 541 ]) 542 ]) 543 544 dnl Check for printf conversion specifier support 545 AX_COMMON_CHECK_FUNC_PRINTF_JD 546 AX_COMMON_CHECK_FUNC_PRINTF_ZD 547]) 548 549