1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677
|
dnl -*- autoconf -*-
dnl
dnl Copyright (c) 2022 Amazon.com, Inc. or its affiliates. All Rights reserved.
dnl Copyright (c) 2022 Nanook Consulting. All rights reserved.
dnl $COPYRIGHT$
dnl
dnl Additional copyrights may follow
dnl
dnl $HEADER$
dnl OAC_CHECK_PACKAGE: Search for the availability of a package
dnl
dnl 1 -> package name
dnl 2 -> prefix value
dnl 3 -> headers (space separated list)
dnl 4 -> libraries (space separated list)
dnl 5 -> function name
dnl 6 -> action if found
dnl 7 -> action if not found
dnl
dnl OAC_CHECK_PACKAGE has an argument length problem. Technically, M4
dnl macros may only have 9 arguments, as argument values must be in the
dnl form of $X, where X is a single digit. This means we do some argument
dnl compression (life would be easier if the libraries and headers were
dnl split into primary and support) and use the M4 environment for passing
dnl some infrequently used arguments.
dnl
dnl OAC_CHECK_PACKAGE tries to find the correct CPPFLAGS, LDFLAGS, and libraries
dnl to use a particular package. It then verifies that the header is available
dnl via AC_CHECK_HEADERS and that the function specified is available via
dnl AC_CHECK_FUNC using the specified flags. To find the flags and libraries,
dnl OAC_CHECK_PACKAGE follows a 4 step search path:
dnl
dnl 1. If <package name>.pc is available to package config, the package config
dnl data is used.
dnl 2. If a OMPI-style wrapper compiler is found, the information from the
dnl wrapper compiler is used (NOTE: THIS IS OFF BY DEFAULT)
dnl 3. If with_<package> and/or with_<package>_libdir are specified, the
dnl filesystem is examined to look for the specified header and library
dnl in the specified path.
dnl 4. We try to find the specified header and function with no change
dnl in CPPFLAGS or LDFLAGS and adding the specified libraries to LIBS.
dnl
dnl It is the responsibility of the caller to register arguments of the form
dnl with-<package name>, with-<package name>-libdir, and with-package name>-incdir.
dnl All three are optional, nothing will break if the caller doesn't specify them
dnl (and indeed, if the package being searched for isn't libnl3, it's likely the
dnl with-<package name>-incdir is a complete waste of energy).
dnl
dnl By default, OAC_CHECK_PACKAGE will use <package name> for the module name to specify
dnl to pkg-config, meaning there is a <package name>.pc in the filesystem. If a
dnl different module name should be used, add a macro to the M4 environment named
dnl <package name>_pkgconfig_module with the value of the pkgconfig module name
dnl to use. For example, if the libevent module name is libevent_core, you could
dnl specify:
dnl
dnl m4_define([libevent_pkgconfig_module], [libevent_core])
dnl
dnl Similarly, by default, OAC_CHECK_PACKAGE will use <package name>cc for the name
dnl of the wrapper compiler to investigate. This can be modified with the
dnl <package name>_wrapper_compiler macro in the m4 environment.
dnl
dnl Using pkg-config is on by default and using the wrapper compilers is off by
dnl default. The use of either can be controlled by setting the SHELL environment
dnl variables <package name>_USE_PKG_CONFIG and <package name>_USE_WRAPPER_COMPILER
dnl to 0 (to explicitly disable) or 1 (to explicitly enable).
dnl
dnl On return, <action if found> will be evaluated if it appears that the package is
dnl available. <action if not found> will be evaluated if it appears that the package
dnl is not available. If it appears the package is available, the following SHELL
dnl environment variables will be set:
dnl
dnl <prefix>_CPPFLAGS - CPPFLAGS to add when compiling sources depending on the package
dnl <prefix>_LDFLAGS - LDFLAGS to add when linking against the package
dnl <prefix>_STATIC_LDFLAGS - LDFLAGS to add when linking against the package when
dnl building a statically linked executable.
dnl <prefix>_LIBS - Libraries to link to access the package
dnl <prefix>_STATIC_LIBS - Libraries to link to access the package when building a
dnl statically linked executable.
dnl <prefix>_PC_MODULES - Module name of the pkgconfig module used to generate
dnl the build information. Will be unset by OAC_CHECK_PACKAGE
dnl if pkg-config was not used to configure the package. Note
dnl that there is no need for a STATIC_PC_MODULES option,
dnl as that functionality is built into pkgconfig modules
dnl directly.
dnl <prefix>_SUMMARY - A summary of the check package output, suitable for inclusion
dnl in a configure summary table. Will start with yes/no.
dnl <prefix>_DETECT_METHOD - The method used to find the right flags. Will be one of
dnl 'pkg-config', 'wrapper compiler', or empty string
dnl
dnl Note that STATIC_LIBS and STATIC_LDFLAGS should not be added to
dnl LIBS and LDFLAGS unnecessarily. Even if the library being built
dnl is being built as a static library, that does not mean adding
dnl STATIC_LIBS to LIBS is the right call. Only when the executable
dnl is only linked against static libraries should STATIC_LIBS be
dnl added to LIBS.
AC_DEFUN([OAC_CHECK_PACKAGE],[
# ****************************** START CHECK PACKAGE FOR $1 ******************************
AC_REQUIRE([_OAC_CHECK_PACKAGE_STATIC_CHECK])
OAC_ASSERT_LITERAL([$1])dnl
OAC_ASSERT_LITERAL([$2])dnl
OAC_VAR_SCOPE_PUSH([check_package_$2_save_CPPFLAGS check_package_$2_save_LDFLAGS check_package_$2_save_LIBS check_package_happy check_package_have_flags check_package_prefix check_package_libdir check_package_incdir check_package_pcfilename])
check_package_$2_save_CPPFLAGS="${CPPFLAGS}"
check_package_$2_save_LDFLAGS="${LDFLAGS}"
check_package_$2_save_LIBS="${LIBS}"
$2_CPPFLAGS=
$2_LDFLAGS=
$2_STATIC_LDFLAGS=
$2_LIBS=
$2_STATIC_LIBS=
AS_UNSET([$2_PC_MODULES])
check_package_happy=1
check_package_have_flags=0
check_package_type=
# build a sane environment
AS_IF([test "$with_$1" = "no"],
[AC_MSG_NOTICE([Package $1 disabled by user])
check_package_happy=0],
[test "${with_$1}" = "yes"],
[check_package_prefix=],
[check_package_prefix="${with_$1}"])
check_package_libdir=
AS_IF([test "${with_$1_libdir}" = "no" -o "${with_$1_libdir}" = "yes"],
[AC_MSG_ERROR(["yes" or "no" are not valid arguments for --with-$1-libdir])],
[test -n "${with_$1_libdir}"],
[check_package_libdir="${with_$1_libdir}"])
check_package_incdir=
AS_IF([test "${with_$1_incdir}" = "no" -o "${with_$1_incdir}" = "yes"],
[AC_MSG_ERROR(["yes" or "no" are not valid arguments for --with-$1-incdir])],
[test -n "${with_$1_incdir}"],
[check_package_incdir="${with_$1_incdir}"])
AS_IF([test ${check_package_happy} -eq 1 -a ${check_package_have_flags} -eq 0],
[_OAC_CHECK_PACKAGE_PKGCONFIG([$1], [$2],
[check_package_type="pkg-config"
check_package_have_flags=1])])
AS_IF([test ${check_package_happy} -eq 1 -a ${check_package_have_flags} -eq 0],
[_OAC_CHECK_PACKAGE_WRAPPER_COMPILER([$1], [$2],
[check_package_type="wrapper compiler"
check_package_have_flags=1])])
AS_IF([test ${check_package_happy} -eq 1 -a ${check_package_have_flags} -eq 0],
[_OAC_CHECK_PACKAGE_GENERIC([$1], [$2], [$3], [$4],
[check_package_type=""
check_package_have_flags=1])])
AS_IF([test ${check_package_have_flags} -eq 0], [check_package_happy=0])
AS_IF([test ${check_package_happy} -eq 1 -a "${oac_cv_check_package_static_linker_flag}" = "yes"],
[AC_MSG_NOTICE([Copying STATIC_LIBS and STATIC_LDFLAGS to LIBS and LDFLAGS because static linking])
OAC_APPEND([$2_LDFLAGS], [${$2_STATIC_LDFLAGS}])
OAC_APPEND([$2_LIBS], [${$2_STATIC_LIBS}])])
AS_IF([test ${check_package_happy} -eq 1],
[_OAC_CHECK_PACKAGE_VERIFY([$1], [$2], [$3], [$5],
[check_package_happy=1], [check_package_happy=0])])
$2_DETECT_METHOD="${check_package_type}"
AS_IF([test -n "${check_package_type}"],
[check_package_type="${check_package_type}: "])
AS_IF([test ${check_package_happy} -eq 1],
[AS_IF([test -z "${check_package_prefix}"],
[$2_SUMMARY="yes (${check_package_type}default search paths)"],
[$2_SUMMARY="yes (${check_package_type}${check_package_prefix})"])
$6],
[AS_IF([test "${with_$1}" = "no"],
[$2_SUMMARY="no (explicitly disabled)"],
[$2_SUMMARY="no (not found)"])
AS_UNSET([$2_CPPFLAGS])
AS_UNSET([$2_LDFLAGS])
AS_UNSET([$2_STATIC_LDFLAGS])
AS_UNSET([$2_LIBS])
AS_UNSET([$2_STATIC_LIBS])
$7])
CPPFLAGS="${check_package_$2_save_CPPFLAGS}"
LDFLAGS="${check_package_$2_save_LDFLAGS}"
LIBS="${check_package_$2_save_LIBS}"
OAC_VAR_SCOPE_POP
# ****************************** END CHECK PACKAGE FOR $1 ******************************
])
dnl Retrieve arguments from pkg-config file
dnl
dnl 1 -> package name
dnl 2 -> prefix
dnl 3 -> pcfile name (may be full path)
dnl 4 -> action if found
dnl 5 -> action if not found
dnl
dnl Read pkgconfig module $3 and set build variables based on return
dnl value. Results are cached based on the value in $1, even if the
dnl pkgconfig module name ($3) changes and that this macro is expanded
dnl inside OAC_CHECK_PACKAGE, which can pollute the results cache.
dnl
dnl On return, <action if found> will be evaluated if it appears that
dnl the pkg-config data is available. <action if not found> will be
dnl evaluated if it appears that the package is not available. If it
dnl appears the package is available, the following SHELL environment
dnl variables will be set:
dnl
dnl <prefix>_CPPFLAGS - CPPFLAGS to add when compiling sources depending on the package
dnl <prefix>_LDFLAGS - LDFLAGS to add when linking against the package
dnl <prefix>_STATIC_LDFLAGS - LDFLAGS to add when linking against the package when
dnl building a statically linked executable.
dnl <prefix>_LIBS - Libraries to link to access the package
dnl <prefix>_STATIC_LIBS - Libraries to link to access the package when building a
dnl statically linked executable.
dnl <prefix>_PC_MODULES - Module name of the pkgconfig module used to generate
dnl the build information. Will be unset by OAC_CHECK_PACKAGE
dnl if pkg-config was not used to configure the package. Note
dnl that there is no need for a STATIC_PC_MODULES option,
dnl as that functionality is built into pkgconfig modules
dnl directly.
AC_DEFUN([OAC_CHECK_PACKAGE_PARSE_PKGCONFIG], [
AC_REQUIRE([_OAC_CHECK_PACKAGE_PKGCONFIG_INIT])
OAC_VAR_SCOPE_PUSH([check_package_pkgconfig_internal_result])
AC_CACHE_CHECK([if $1 pkg-config module exists],
[oac_cv_check_package_$1_pkg_config_exists],
[_OAC_CHECK_PACKAGE_PKGCONFIG_RUN([$3], [--exists], [check_package_pkgconfig_internal_result],
[$2_PC_MODULES=$3
oac_cv_check_package_$1_pkg_config_exists=yes],
[oac_cv_check_package_$1_pkg_config_exists=no])])
# if pkg-config --exists works, but getting one of the standard flags fails, we consider
# that a hard failure. It should not happen, outside of a weird system configuration
# issue where we're probably not going to like the results anyway.
AS_IF([test "${oac_cv_check_package_$1_pkg_config_exists}" = "yes"],
[AC_CACHE_CHECK([for $1 pkg-config cflags],
[oac_cv_check_package_$1_pkg_config_cppflags],
[_OAC_CHECK_PACKAGE_PKGCONFIG_RUN([$3], [--cflags],
[oac_cv_check_package_$1_pkg_config_cppflags], [],
[AC_MSG_RESULT([error])
AC_MSG_ERROR([An error occurred retrieving $1 cppflags from pkg-config])])])
$2_CPPFLAGS="${oac_cv_check_package_$1_pkg_config_cppflags}"
AC_CACHE_CHECK([for $1 pkg-config ldflags],
[oac_cv_check_package_$1_pkg_config_ldflags],
[_OAC_CHECK_PACKAGE_PKGCONFIG_RUN([$3], [--libs-only-L --libs-only-other],
[oac_cv_check_package_$1_pkg_config_ldflags], [],
[AC_MSG_RESULT([error])
AC_MSG_ERROR([An error occurred retrieving $1 ldflags from pkg-config])])])
$2_LDFLAGS="${oac_cv_check_package_$1_pkg_config_ldflags}"
AC_CACHE_CHECK([for $1 pkg-config static ldflags],
[oac_cv_check_package_$1_pkg_config_static_ldflags],
[_OAC_CHECK_PACKAGE_PKGCONFIG_RUN([$3], [--static --libs-only-L --libs-only-other],
[oac_cv_check_package_$1_pkg_config_static_ldflags], [],
[AC_MSG_RESULT([error])
AC_MSG_ERROR([An error occurred retrieving $1 static ldflags from pkg-config])])])
$2_STATIC_LDFLAGS="${oac_cv_check_package_$1_pkg_config_static_ldflags}"
AC_CACHE_CHECK([for $1 pkg-config libs],
[oac_cv_check_package_$1_pkg_config_libs],
[_OAC_CHECK_PACKAGE_PKGCONFIG_RUN([$3], [--libs-only-l],
[oac_cv_check_package_$1_pkg_config_libs], [],
[AC_MSG_RESULT([error])
AC_MSG_ERROR([An error occurred retrieving $1 libs from pkg-config])])])
$2_LIBS="${oac_cv_check_package_$1_pkg_config_libs}"
AC_CACHE_CHECK([for $1 pkg-config static libs],
[oac_cv_check_package_$1_pkg_config_static_libs],
[_OAC_CHECK_PACKAGE_PKGCONFIG_RUN([$3], [--static --libs-only-l],
[oac_cv_check_package_$1_pkg_config_static_libs], [],
[AC_MSG_RESULT([error])
AC_MSG_ERROR([An error occurred retrieving $1 libs from pkg-config])])])
$2_STATIC_LIBS="${oac_cv_check_package_$1_pkg_config_static_libs}"
$4])
OAC_VAR_SCOPE_POP
])
dnl Invalidate generic cached results (should rarely be needed)
dnl
dnl 1 -> package name
dnl 2 -> prefix value
dnl 3 -> headers (space separated list)
dnl 4 -> function name
dnl
dnl Rarely, packages change linking or in some other way make it
dnl difficult to determine all the correct arguments for
dnl OAC_CHECK_PACKAGE in one try. The TM interface is a good example
dnl of this, which has changed the name of the library (or its
dnl dependencies) throughout the years. Because OAC_CHECK_PACKAGE
dnl makes heavy use of caching (yay!), it is generally not useful to
dnl call OAC_CHECK_PACKAGE multiple times with the same package name,
dnl but different arguments. This macro may be expanded between calls
dnl to invalidate the caching for the generic (no pkg-config or
dnl wrapper config found) case.
AC_DEFUN([OAC_CHECK_PACKAGE_INVALIDATE_GENERIC_CACHE], [
OAC_VAR_SCOPE_PUSH([check_package_verify_search_header])
dnl today, all we cache in the generic case is the header and func libs
check_package_verify_search_header=`echo "$3" | cut -f1 -d' '`
AS_UNSET([ac_cv_header_]AS_TR_SH([${check_package_verify_search_header}]))
AS_UNSET([ac_cv_func_$4])
OAC_VAR_SCOPE_POP
])
dnl OAC_CHECK_PACKAGE_VERIFY_COMMANDS - macros to expand during
dnl verification we have a working package
dnl
dnl 1 -> macro name (must be double quoted)
dnl
dnl If extra verification is required (such as the libnl1 vs. libnl3 disaster),
dnl callers (like the libnl verification code) can register a hook for
dnl every time OAC_CHECK_PACKAGE verifies that a package actually links. This
dnl check will only be run after it is verified that the header can be found
dnl and that the function specified is found when linking.
dnl
dnl The macro specified must take 6 arguments:
dnl 1 -> package name
dnl 2 -> prefix
dnl 3 -> headers (space separated list)
dnl 4 -> function name
dnl 5 -> action if found
dnl 6 -> action if not found
dnl
dnl The CPPFLAGS / LDFLAGS / LIBS can be retrieved via ${$2_CPPFLAGS},
dnl ${$2_LDFLAGS}, and ${$2_LIBS}, respectively.
dnl
dnl Note that, because M4 really likes to expand macro names, the argument
dnl to OAC_CHECK_PACKAGE_VERIFY_COMMANDS must be overquoted. That is,
dnl if the macro name to be called is LIBNL_PACKAGE_VERIFY, the call to
dnl register should be:
dnl
dnl OAC_CHECK_PACKAGE_VERIFY_COMMANDS([[LIBNL_PACKAGE_VERIFY]])
dnl
dnl If you see the macro being invoked without arguments, that almost certainly
dnl means you forgot to double quote.
AC_DEFUN([OAC_CHECK_PACKAGE_VERIFY_COMMANDS],
[m4_append([OAC_CHECK_PACKAGE_VERIFY_COMMAND_LIST], m4_dquote([$1]), [,])])
dnl ************************************* INTERNAL HELPER *************************************
AC_DEFUN([_OAC_CHECK_PACKAGE_STATIC_CHECK],
[OAC_LINKER_STATIC_CHECK([oac_cv_check_package_static_linker_flag=yes],
[oac_cv_check_package_static_linker_flag=no])])
dnl ************************************* PKG-CONFIG *************************************
dnl no arguments; here for an AC_REQUIRE to set $PKG_CONFIG
AC_DEFUN([_OAC_CHECK_PACKAGE_PKGCONFIG_INIT],
[AC_CHECK_PROG([PKG_CONFIG], [pkg-config], [pkg-config])])
dnl 1 -> package
dnl 2 -> prefix
dnl 3 -> action if found flags
AC_DEFUN([_OAC_CHECK_PACKAGE_PKGCONFIG], [
m4_ifdef([$1_pkgconfig_module],
[m4_define([pcname], [$1_pkgconfig_module])],
[m4_define([pcname], [$1])])
AS_IF([test "${$1_USE_PKG_CONFIG}" != "0"],
[# search for the package using pkg-config. If the user provided a
# --with-$1 or --with-$1-libdir argument, be explicit about where
# we look for the pkg-config file, so we don't find the wrong one.
# If they specified --with-$1 only, we look in
# prefix/lib64/pkgconfig and if we don't find a file there, assume
# prefix/lib is the right answer.
AC_CACHE_CHECK([for $1 pkg-config name],
[oac_cv_check_package_$1_pcfilename],
[oac_cv_check_package_$1_pcfilename="pcname"
AS_IF([test -n "${check_package_libdir}"],
[oac_cv_check_package_$1_pcfilename="${check_package_libdir}/pkgconfig/pcname.pc"],
[test -z "${check_package_prefix}"],
[oac_cv_check_package_$1_pcfilename="pcname"],
[test -r "${check_package_prefix}/lib/pkgconfig/pcname.pc" -a -r "${check_package_prefix}/lib64/pkgconfig/pcname.pc"],
[AS_IF([test ! -L "${check_package_prefix}/lib" &&
test ! -L "${check_package_prefix}/lib64"],
[AC_MSG_ERROR([Found pcname in both ${check_package_prefix}/lib/pkgconfig and
${check_package_prefix}/lib64/pkgconfig. This is confusing. Please add --with-$1-libdir=PATH
to configure to help disambiguate.])],
[check_package_cv_$1_pcfilename="${check_package_prefix}/lib/pkgconfig/pcname.pc"])],
[test -r "${check_package_prefix}/lib64/pkgconfig/pcname.pc"],
[oac_cv_check_package_$1_pcfilename="${check_package_prefix}/lib64/pkgconfig/pcname.pc"],
[oac_cv_check_package_$1_pcfilename="${check_package_prefix}/lib/pkgconfig/pcname.pc"])])
OAC_CHECK_PACKAGE_PARSE_PKGCONFIG([$1], [$2], [${oac_cv_check_package_$1_pcfilename}], [$3])])
])
dnl 1 -> pc module/filename
dnl 2 -> argument string
dnl 3 -> result assignment string
dnl 4 -> action if found
dnl 5 -> action if not found
AC_DEFUN([_OAC_CHECK_PACKAGE_PKGCONFIG_RUN], [
OAC_VAR_SCOPE_PUSH([check_package_pkgconfig_run_results check_package_pkgconfig_run_happy])
check_package_pkgconfig_run_happy=no
AS_IF([test -n "${PKG_CONFIG}"],
[OAC_LOG_COMMAND([check_package_pkgconfig_run_results=`${PKG_CONFIG} $2 $1 2>&1`],
[AS_VAR_COPY([$3], [check_package_pkgconfig_run_results])
check_package_pkgconfig_run_happy=yes])
OAC_LOG_MSG([pkg-config output: ${check_package_pkgconfig_run_results}], [1])])
AS_IF([test "${check_package_pkgconfig_run_happy}" = "yes"], [$4], [$5])
OAC_VAR_SCOPE_POP
])
dnl ************************************* WRAPPER COMPILERS *************************************
dnl 1 -> package name
dnl 2 -> prefix
dnl 3 -> action if found flags
dnl
dnl wrapper compiler is off by default; must be explicitly enabled
AC_DEFUN([_OAC_CHECK_PACKAGE_WRAPPER_COMPILER], [
m4_ifdef([$1_wrapper_compiler],
[m4_define([wrapper_compiler_name], [$1_wrapper_compiler])],
[m4_define([wrapper_compiler_name], [$1cc])])
AS_IF([test "${$1_USE_WRAPPER_COMPILER}" = "1"],
[# search for the package using wrapper compilers. If the user
# provided a --with-$1 argument, be explicit about where we look
# for the compiler, so we don't find the wrong one.
AC_CACHE_CHECK([for $1 wrapper compiler],
[oac_cv_check_package_$1_wrapper_compiler],
[AS_IF([test -z "${check_package_prefix}"],
[oac_cv_check_package_$1_wrapper_compiler="wrapper_compiler_name"],
[oac_cv_check_package_$1_wrapper_compiler="${check_package_prefix}/bin/wrapper_compiler_name"])])
_OAC_CHECK_PACKAGE_WRAPPER_INTERNAL([$1], [$2], [${oac_cv_check_package_$1_wrapper_compiler}], [$3])])
])
dnl 1 -> package name
dnl 2 -> prefix
dnl 2 -> wrapper compiler
dnl 3 -> action if found flag
AC_DEFUN([_OAC_CHECK_PACKAGE_WRAPPER_INTERNAL], [
OAC_VAR_SCOPE_PUSH([check_package_wrapper_internal_result check_package_wrapper_internal_tmp])
AC_CACHE_CHECK([if $1 wrapper compiler works],
[oac_cv_check_package_$1_wrapper_compiler_works],
[_OAC_CHECK_PACKAGE_WRAPPER_RUN([$3], [--showme:version], [check_package_wrapper_internal_result],
[oac_cv_check_package_$1_wrapper_compiler_works=yes],
[oac_cv_check_package_$1_wrapper_compiler_works=no])])
# if wrapper --showme:version works, but getting one of the standard flags fails, we consider
# that a hard failure. It should not happen, outside of a weird system configuration
# issue where we're probably not going to like the results anyway.
AS_IF([test ${oac_cv_check_package_$1_wrapper_compiler_works} = "yes"],
[AC_CACHE_CHECK([for $1 wrapper compiler cppflags],
[oac_cv_check_package_$1_wrapper_compiler_cppflags],
[_OAC_CHECK_PACKAGE_WRAPPER_RUN([$3], [--showme:incdirs],
[check_package_wrapper_internal_result],
[for check_package_wrapper_internal_tmp in ${check_package_wrapper_internal_result} ; do
OAC_APPEND([oac_cv_check_package_$1_wrapper_compiler_cppflags], ["-I${check_package_wrapper_internal_tmp}"])
done],
[AC_MSG_RESULT([error])
AC_MSG_ERROR([An error occurred retrieving $1 cppflags from wrapper compiler])])])
$2_CPPFLAGS="${oac_cv_check_package_$1_wrapper_compiler_cppflags}"
AC_CACHE_CHECK([for $1 wrapper compiler ldflags],
[oac_cv_check_package_$1_wrapper_compiler_ldflags],
[_OAC_CHECK_PACKAGE_WRAPPER_RUN([$3], [--showme:libdirs],
[check_package_wrapper_internal_result],
[for check_package_wrapper_internal_tmp in ${check_package_wrapper_internal_result} ; do
OAC_APPEND([oac_cv_check_package_$1_wrapper_compiler_ldflags], ["-L${check_package_wrapper_internal_tmp}"])
done],
[AC_MSG_RESULT([error])
AC_MSG_ERROR([An error occurred retrieving $1 ldflags from wrapper compiler])])])
$2_LDFLAGS="${oac_cv_check_package_$1_wrapper_compiler_ldflags}"
AC_CACHE_CHECK([for $1 wrapper compiler static ldflags],
[oac_cv_check_package_$1_wrapper_compiler_static_ldflags],
[_OAC_CHECK_PACKAGE_WRAPPER_RUN([$3], [--showme:libdirs_static],
[check_package_wrapper_internal_result],
[for check_package_wrapper_internal_tmp in ${check_package_wrapper_internal_result} ; do
OAC_APPEND([oac_cv_check_package_$1_wrapper_compiler_static_ldflags], ["-L${check_package_wrapper_internal_tmp}"])
done],
[AC_MSG_RESULT([error])
AC_MSG_ERROR([An error occurred retrieving $1 static ldflags from wrapper compiler])])])
$2_STATIC_LDFLAGS="${oac_cv_check_package_$1_wrapper_compiler_static_ldflags}"
AC_CACHE_CHECK([for $1 wrapper compiler libs],
[oac_cv_check_package_$1_wrapper_compiler_libs],
[_OAC_CHECK_PACKAGE_WRAPPER_RUN([$3], [--showme:libs],
[check_package_wrapper_internal_result],
[for check_package_wrapper_internal_tmp in ${check_package_wrapper_internal_result} ; do
OAC_APPEND([oac_cv_check_package_$1_wrapper_compiler_libs], ["-l${check_package_wrapper_internal_tmp}"])
done],
[AC_MSG_RESULT([error])
AC_MSG_ERROR([An error occurred retrieving $1 libs from wrapper compiler])])])
$2_LIBS="$oac_cv_check_package_$1_wrapper_compiler_libs"
AC_CACHE_CHECK([for $1 wrapper compiler static libs],
[oac_cv_check_package_$1_wrapper_compiler_static_libs],
[_OAC_CHECK_PACKAGE_WRAPPER_RUN([$3], [--showme:libs_static],
[check_package_wrapper_internal_result],
[for check_package_wrapper_internal_tmp in ${check_package_wrapper_internal_result} ; do
OAC_APPEND([oac_cv_check_package_$1_wrapper_compiler_static_libs], ["-l${check_package_wrapper_internal_tmp}"])
done],
[AC_MSG_RESULT([error])
AC_MSG_ERROR([An error occurred retrieving $1 static libs from wrapper compiler])])])
$2_STATIC_LIBS="${oac_cv_check_package_$1_wrapper_compiler_static_libs}"
$4])
OAC_VAR_SCOPE_POP
])
dnl 1 -> wrapper compiler
dnl 2 -> argument string
dnl 3 -> result assignment string
dnl 4 -> action if found
dnl 5 -> action if failed
AC_DEFUN([_OAC_CHECK_PACKAGE_WRAPPER_RUN], [
OAC_VAR_SCOPE_PUSH([check_package_wrapper_run_results])
OAC_LOG_COMMAND([check_package_wrapper_run_results=`$1 $2 2>&1`],
[AS_VAR_COPY([$3], [check_package_wrapper_run_results])
$4],
[$5])
OAC_LOG_MSG([wrapper output: ${check_package_wrapper_run_results}], [1])
OAC_VAR_SCOPE_POP
])
dnl ************************************* GENERIC GUESSING *************************************
dnl 1 -> package name
dnl 2 -> prefix
dnl 3 -> headers (space separated list)
dnl 4 -> libraries (space separated list)
dnl 5 -> action if found flags
AC_DEFUN([_OAC_CHECK_PACKAGE_GENERIC], [
OAC_VAR_SCOPE_PUSH([check_package_generic_happy check_package_generic_lib])
check_package_generic_happy=0
AS_IF([test -n "${check_package_prefix}"],
[_OAC_CHECK_PACKAGE_GENERIC_PREFIX([$1], [$2], [$3], [$4], [check_package_generic_happy=1])],
[AC_MSG_NOTICE([Searching for $1 in default search paths])
$1_CPPFLAGS=
$1_LDFLAGS=
check_package_generic_happy=1])
AS_IF([test ${check_package_generic_happy} -eq 1],
[for check_package_generic_lib in $4 ; do
check_package_generic_lib=`echo ${check_package_generic_lib} | sed -e 's/^-l//'`
OAC_APPEND([$2_LIBS], ["-l${check_package_generic_lib}"])
OAC_APPEND([$2_STATIC_LIBS], ["-l${check_package_generic_lib}"])
done
AC_MSG_CHECKING([for $1 cppflags])
AC_MSG_RESULT([$$2_CPPFLAGS])
AC_MSG_CHECKING([for $1 ldflags])
AC_MSG_RESULT([$$2_LDFLAGS])
AC_MSG_CHECKING([for $1 libs])
AC_MSG_RESULT([$$2_LIBS])
AC_MSG_CHECKING([for $1 static libs])
AC_MSG_RESULT([$$2_STATIC_LIBS])
$5])
OAC_VAR_SCOPE_POP
])
dnl 1 -> package name
dnl 2 -> prefix
dnl 3 -> headers (space separated list)
dnl 4 -> libraries (space separated list)
dnl 5 -> action if found flags
AC_DEFUN([_OAC_CHECK_PACKAGE_GENERIC_PREFIX], [
OAC_VAR_SCOPE_PUSH([check_package_generic_search_header check_package_generic_search_lib check_package_generic_incdir])
check_package_generic_search_header=`echo "$3" | cut -f1 -d' '`
check_package_generic_search_lib=`echo "$4" | cut -f1 -d' ' | sed -e 's/^-l//'`
check_package_generic_prefix_happy=0
AS_IF([test -n "${check_package_incdir}"],
[check_package_generic_incdir="${check_package_incdir}"],
[check_package_generic_incdir="${check_package_prefix}/include"])
AC_MSG_CHECKING([for $1 header at ${check_package_generic_incdir}])
AS_IF([test -r ${check_package_generic_incdir}/${check_package_generic_search_header}],
[check_package_generic_prefix_happy=1
$2_CPPFLAGS="-I${check_package_generic_incdir}"
AC_MSG_RESULT([found])],
[AC_MSG_RESULT([not found])])
AS_IF([test ${check_package_generic_prefix_happy} -eq 1],
[check_package_generic_prefix_happy=0
AS_IF([test -n "${check_package_libdir}"],
[AC_MSG_CHECKING([for $1 library (${check_package_generic_search_lib}) in ${check_package_libdir}])
ls ${check_package_libdir}/lib${check_package_generic_search_lib}.* 1>&/dev/null 2>&1
AS_IF([test $? -eq 0],
[check_package_generic_prefix_happy=1
$2_LDFLAGS="-L${check_package_libdir}"
AC_MSG_RESULT([found])],
[AC_MSG_RESULT([not found])])],
[check_package_generic_prefix_lib=0
check_package_generic_prefix_lib64=0
ls ${check_package_prefix}/lib/lib${check_package_generic_search_lib}.* 1>&/dev/null 2>&1
AS_IF([test $? -eq 0], [check_package_generic_prefix_lib=1])
ls ${check_package_prefix}/lib64/lib${check_package_generic_search_lib}.* 1>&/dev/null 2>&1
AS_IF([test $? -eq 0], [check_package_generic_prefix_lib64=1])
AC_MSG_CHECKING([for $1 library (${check_package_generic_search_lib}) in ${check_package_prefix}])
AS_IF([test ${check_package_generic_prefix_lib} -eq 1 -a ${check_package_generic_prefix_lib64} -eq 1],
[AS_IF([test ! -L "${check_package_prefix}/lib" &&
test ! -L "${check_package_prefix}/lib64"],
[AC_MSG_ERROR([Found library $check_package_generic_search_lib in both ${check_package_prefix}/lib and
${check_package_prefix}/lib64. This has confused configure. Please add --with-$1-libdir=PATH to configure to help
disambiguate.])],
[check_package_generic_prefix_happy=1
$2_LDFLAGS=-L${check_package_prefix}/lib
AC_MSG_RESULT([found -- lib])])],
[test ${check_package_generic_prefix_lib} -eq 1],
[check_package_generic_prefix_happy=1
$2_LDFLAGS=-L${check_package_prefix}/lib
AC_MSG_RESULT([found -- lib])],
[test $check_package_generic_prefix_lib64 -eq 1],
[check_package_generic_prefix_happy=1
$2_LDFLAGS=-L${check_package_prefix}/lib64
AC_MSG_RESULT([found -- lib64])],
[AC_MSG_RESULT([not found])])])])
AS_IF([test ${check_package_generic_prefix_happy} -eq 1], [$5])
OAC_VAR_SCOPE_POP
])
dnl ************************************* OPERATIONAL CHECK *************************************
dnl 1 -> package name
dnl 2 -> prefix
dnl 3 -> headers (space separated list)
dnl 4 -> function name
dnl 5 -> action if found
dnl 6 -> action if not found
AC_DEFUN([_OAC_CHECK_PACKAGE_VERIFY],[
OAC_VAR_SCOPE_PUSH([check_package_verify_search_header check_package_verify_happy])
check_package_verify_search_header=`echo "$3" | cut -f1 -d' '`
OAC_APPEND([CPPFLAGS], [${$2_CPPFLAGS}])
OAC_APPEND([LDFLAGS], [${$2_LDFLAGS}])
OAC_APPEND([LIBS], [${$2_LIBS}])
check_package_verify_happy=1
AS_IF([test ${check_package_verify_happy} -eq 1],
[AC_CHECK_HEADER([${check_package_verify_search_header}],
[check_package_verify_happy=1], [check_package_verify_happy=0])])
dnl Note that we use AC_CHEC_FUNC here instead of AC_CHECK_LIB, because we're pretty sure we've
dnl found the library already (and have added it to LIBS). Now we're just trying to verify
dnl that the library we found contains the bits we need.
AS_IF([test ${check_package_verify_happy} -eq 1],
[AC_CHECK_FUNC([$4], [check_package_verify_happy=1], [check_package_verify_happy=0])])
m4_ifdef([OAC_CHECK_PACKAGE_VERIFY_COMMAND_LIST],
[m4_foreach([list_item], [OAC_CHECK_PACKAGE_VERIFY_COMMAND_LIST],
[AS_IF([test ${check_package_verify_happy} -eq 1],
[m4_apply(m4_unquote([list_item]), [[$1], [$2], [$3], [$4],
[check_package_verify_happy=1],
[check_package_verify_happy=0]])])])])
AS_IF([test ${check_package_verify_happy} -eq 1],
[$5], [$6])
OAC_VAR_SCOPE_POP
])
|