You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
2.8 KiB

2 months ago
  1. #! /bin/sh
  2. # Script assumes that CXX and CXXFLAGS are set.
  3. # This script tests whether CXX can compile with gmp (and gmpxx)
  4. # by just adding -lgmp (and -lgmpxx) as flags.
  5. # The check entails compiling very simple source files.
  6. # Exit code is non-zero if "-lgmp" does not work (or an error occurs).
  7. # Exit code is 0 if "-lgmp" works; output is "GMPXX" if -lgmpxx works,
  8. # otherwise "GMP" if just -lgmp works.
  9. if [ -z "$CXX" ]
  10. then
  11. echo "$0: ERROR: environment variable CXX not set."
  12. exit 1
  13. fi
  14. # Now create a temp dir in which to work:
  15. # I use a temp dir so all junk created by the compiler can be removed
  16. # simply by removing the directory -- also I do not need to worry about
  17. # stomping on existing files.
  18. umask 22
  19. TODAY=`date "+%Y-%m-%d"`
  20. TIME=`date "+%H:%M:%S"`
  21. TMP_DIR=/tmp/CoCoALib-config-$USER-$TODAY/gmp-try-default-$TIME-$$
  22. /bin/rm -rf $TMP_DIR && mkdir -p $TMP_DIR
  23. if [ $? -ne 0 ]; then
  24. echo "ERROR: $0 failed to create temporary directory \"$TMP_DIR\""
  25. exit 1
  26. fi
  27. cd $TMP_DIR
  28. # Here is the simple source code we shall use to test for gmp:
  29. cat > TestGMP.C <<EOF
  30. #include "gmp.h"
  31. #include <iostream>
  32. int main()
  33. {
  34. mpz_t i;
  35. mpz_init(i);
  36. mpz_set_si(i, 12345);
  37. std::cout << __GNU_MP_VERSION << "." << __GNU_MP_VERSION_MINOR << "." << __GNU_MP_VERSION_PATCHLEVEL << std::endl;
  38. mpz_clear(i);
  39. }
  40. EOF
  41. # Here is the simple source code we shall use to test for gmpxx:
  42. cat > TestGMPXX.C <<EOF
  43. #include "gmpxx.h"
  44. #include <iostream>
  45. int main()
  46. {
  47. mpz_class i(12345);
  48. std::cout << __GNU_MP_VERSION << "." << __GNU_MP_VERSION_MINOR << "." << __GNU_MP_VERSION_PATCHLEVEL << std::endl;
  49. }
  50. EOF
  51. # Try different architectures (in case we're on a 32/64 bit platform)
  52. DYN_LINK=ok
  53. for ARCHFLAG in "" "-m64" "-m32"
  54. do
  55. # Try plain GMP
  56. $CXX $ARCHFLAG $CXXFLAGS TestGMP.C -o TestGMP -lgmp > /dev/null 2>&1
  57. if [ $? -ne 0 -o \! -f TestGMP -o \! -x TestGMP ]
  58. then
  59. # compilation failed so try next ARCHFLAG
  60. continue;
  61. fi
  62. ./TestGMP > /dev/null 2>&1
  63. if [ $? -ne 0 ]
  64. then
  65. DYN_LINK="arch=$ARCHFLAG"
  66. continue;
  67. fi
  68. # Default GMP worked, now try GMPXX
  69. $CXX $ARCHFLAG $CXXFLAGS TestGMPXX.C -o TestGMPXX -lgmpxx -lgmp > /dev/null 2>&1
  70. if [ $? -ne 0 ]
  71. then
  72. # GMPXX compilation failed, so we have only GMP
  73. echo GMP
  74. fi
  75. # GMPXX compilation passed, so check it runs.
  76. ./TestGMPXX > /dev/null 2>&1
  77. if [ $? -ne 0 ]
  78. then
  79. # Test prog did not run: accept just GMP (or should it give error???)
  80. echo GMP
  81. else
  82. # We have both GMP and GMPXX
  83. echo GMPXX
  84. fi
  85. # Clean-up TMP_DIR
  86. cd # leave TMP_DIR
  87. /bin/rm -rf $TMP_DIR
  88. exit 0
  89. done
  90. if [ DYN_LINK -ne "ok" ]
  91. then
  92. echo "Problem with GMP dynamic library ($DYN_LINK); perhaps run ldconfig?"
  93. exit 2
  94. fi
  95. # No default GMP installation found
  96. echo "No default GMP installation (with CXXFLAGS=\"$CXXFLAGS\")"
  97. exit 1