check-math-lib.m4 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. # check-math-lib.m4 serial 4
  2. dnl Copyright (C) 2007, 2009-2023 Free Software Foundation, Inc.
  3. dnl This file is free software; the Free Software Foundation
  4. dnl gives unlimited permission to copy and/or distribute it,
  5. dnl with or without modifications, as long as this notice is preserved.
  6. dnl
  7. dnl gl_CHECK_MATH_LIB (VARIABLE, EXPRESSION [, EXTRA-CODE])
  8. dnl
  9. dnl Sets the shell VARIABLE according to the libraries needed by EXPRESSION
  10. dnl to compile and link: to the empty string if no extra libraries are needed,
  11. dnl to "-lm" if -lm is needed, or to "missing" if it does not compile and
  12. dnl link either way.
  13. dnl
  14. dnl Example: gl_CHECK_MATH_LIB([ROUNDF_LIBM], [x = roundf (x);])
  15. AC_DEFUN([gl_CHECK_MATH_LIB], [
  16. save_LIBS=$LIBS
  17. $1=missing
  18. for libm in "" "-lm"; do
  19. LIBS="$save_LIBS $libm"
  20. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  21. #ifndef __NO_MATH_INLINES
  22. # define __NO_MATH_INLINES 1 /* for glibc */
  23. #endif
  24. #include <math.h>
  25. $3
  26. double x;]],
  27. [$2])],
  28. [$1=$libm
  29. break])
  30. done
  31. LIBS=$save_LIBS
  32. ])