Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: enforce minimum versions of libgmp based on arch and platform #92

Merged
merged 3 commits into from
Oct 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 48 additions & 28 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,9 @@ else
CXXFLAGS_overridden=no
fi

AC_PROG_CXX

AM_PROG_CC_C_O
AC_PROG_CC

AC_PROG_CC_C99
if test x"$ac_cv_prog_cc_c99" = x"no"; then
AC_MSG_ERROR([c99 compiler support required])
fi
AC_PROG_CXX

dnl By default, libtool for mingw refuses to link static libs into a dll for
dnl fear of mixing pic/non-pic objects, and import/export complications. Since
Expand Down Expand Up @@ -153,15 +148,56 @@ AC_DEFINE([GMP], [2], [Backend based on GNU Multiple Precision library.])
AC_DEFINE([GMP_SEC], [3], [Backend based on GNU Multiple Precision library, but using constant-time code.])

AC_DEFUN([GMP_CHECK],[
if test x"$has_gmp" != x"yes"; then
AC_REQUIRE([AC_PROG_CC])

CPPFLAGS_TEMP="$CPPFLAGS"
CPPFLAGS="$GMP_CPPFLAGS $CPPFLAGS"
LIBS_TEMP="$LIBS"
LIBS="$GMP_LDFLAGS $LIBS"
AC_CHECK_HEADER(gmp.h,[AC_CHECK_LIB(gmp, __gmpz_init,[has_gmp=yes; GMP_LIBS="-lgmp";])])

AC_CHECK_HEADER(
gmp.h,
[AC_CHECK_LIB(gmp, __gmpz_init, [], [gmp_fail_reason="libgmp not found or unusable"; has_gmp=no;])],
[gmp_fail_reason="gmp header not found"; has_gmp=no;]
)

if test x"$has_gmp" != x"no"; then
# Proper support for macOS aarch64 was introduced in 6.3.0, but LTS distros
# like Ubuntu 20.04 (focal) use 6.2.0, so, the minimum supported version is
# determined by platform and architecture.
case $host in
*darwin*)
case $host_cpu in
aarch*)
gmp_major_version=6
gmp_minor_version=3
;;
esac
;;
*)
gmp_major_version=6
gmp_minor_version=2
;;
esac
AC_MSG_CHECKING([gmp version >= $gmp_major_version.$gmp_minor_version])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[[@%:@include <gmp.h>]],
[[
@%:@if __GNU_MP_VERSION < $gmp_major_version || __GNU_MP_VERSION_MINOR < $gmp_minor_version
@%:@error Unsupported GMP version
@%:@endif]])],
[AC_MSG_RESULT([yes]); GMP_LIBS="-lgmp"; has_gmp=yes;],
[AC_MSG_RESULT([no]); gmp_fail_reason="unsupported gmp version"; has_gmp=no;]
)
fi

if test x"$want_backend" = x"gmp" && test x"$has_gmp" = x"no"; then
AC_MSG_ERROR([$gmp_fail_reason])
fi

CPPFLAGS="$CPPFLAGS_TEMP"
LIBS="$LIBS_TEMP"
fi
])

AC_ARG_WITH([backend],
Expand Down Expand Up @@ -193,32 +229,16 @@ if test x"$want_backend" = x"auto"; then
else
GMP_CHECK
if test x"$has_gmp" = x"yes"; then
case $host in
*darwin*)
case $host_cpu in
aarch*)
want_backend=easy
;;
*)
want_backend=gmp
;;
esac
;;
*)
want_backend=gmp
;;
esac
want_backend=gmp
else
want_backend=easy
fi
fi
else
case $want_backend in
gmp)
dnl GMP_CHECK will report the reason if and why the backend cannot be used.
GMP_CHECK
if test x"$has_gmp" != x"yes"; then
AC_MSG_ERROR([gmp backend explicitly requested but libgmp not available])
fi
;;
easy)
;;
Expand Down
Loading