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