dnl CF_MATH_LIB version: 11 updated: 2022/07/27 19:01:48
dnl -----------
dnl Checks for libraries.  At least one UNIX system, Apple Macintosh
dnl Rhapsody 5.5, does not have -lm.  We cannot use the simpler
dnl AC_CHECK_LIB(m,sin), because that fails for C++.
AC_DEFUN([CF_MATH_LIB],
[
AC_CACHE_CHECK(if -lm needed for math functions,
	cf_cv_need_libm,[
	AC_TRY_LINK([
		#include <stdio.h>
		#include <stdlib.h>
		#include <math.h>
	],
	[double x = rand(); printf("result = %g\\n", ]ifelse([$2],,sin(x),$2)[)],
	[cf_cv_need_libm=no],
	[cf_cv_need_libm=yes])])

if test "$cf_cv_need_libm" = yes
then

	cf_save_LIBS="$LIBS"
	LIBS="$LIBS -lm"
	AC_CACHE_CHECK(if -lm is available for math functions,
	cf_cv_have_libm,[
	AC_TRY_LINK([
		#include <stdio.h>
		#include <stdlib.h>
		#include <math.h>
	],
	[double x = rand(); printf("result = %g\\n", ]ifelse([$2],,sin(x),$2)[)],
	[cf_cv_have_libm=yes],
	[cf_cv_have_libm=no])])
	LIBS="$cf_save_LIBS"

	if test "$cf_cv_have_libm" = yes
	then
		ifelse($1,,[CF_ADD_LIB(m)],[$1=-lm])
	fi
else
	cf_cv_have_libm=yes
fi

if test "$cf_cv_have_libm" = yes
then
	AC_DEFINE(HAVE_MATH_FUNCS,1,[Define to 1 if math functions are available])
fi
])
