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.

95 lines
2.3 KiB

2 months ago
  1. #! /bin/bash
  2. # This script prints out the -m*** flags used for compiling GMP
  3. # (or exits with code 1 if an error occurred).
  4. # Assumes that env variables CXX and COCOA_EXTLIB_DIR are set.
  5. if [ $# != 0 ]
  6. then
  7. echo "ERROR: $0 expects no arguments"
  8. exit 1
  9. fi
  10. # Check environment variables CXX and COCOA_EXTLIB_DIR
  11. if [ -z "$CXX" ]
  12. then
  13. echo "ERROR: $0: environment variable CXX not set."
  14. exit 1
  15. fi
  16. if [ -z "$COCOA_EXTLIB_DIR" ]
  17. then
  18. echo "ERROR: $0: environment variable COCOA_EXTLIB_DIR not set."
  19. exit 1
  20. fi
  21. if [ \! "$COCOA_EXTLIB_DIR" -ef "/$COCOA_EXTLIB_DIR" ]
  22. then
  23. echo "ERROR: $0: environment variable COCOA_EXTLIB_DIR is not absolute: $COCOA_EXTLIB_DIR."
  24. exit 1
  25. fi
  26. if [ \! -d "$COCOA_EXTLIB_DIR" -o \! -d "$COCOA_EXTLIB_DIR/include" -o \! -d "$COCOA_EXTLIB_DIR/lib" ]
  27. then
  28. echo "ERROR: $0: environment variable COCOA_EXTLIB_DIR is implausible: $COCOA_EXTLIB_DIR."
  29. exit 1
  30. fi
  31. # Below we create a small C++ program for printing out the GMP compilation flags.
  32. TODAY=`date "+%Y-%m-%d"`
  33. TIME=`date "+%H:%M:%S"`
  34. TMP_DIR=/tmp/CoCoALib-config-$USER-$TODAY/gmp-cxx-flags-$TIME-$$
  35. /bin/rm -rf $TMP_DIR && mkdir -p $TMP_DIR
  36. if [ $? -ne 0 ]; then
  37. echo "ERROR: $0 failed to create temporary directory \"$TMP_DIR\""
  38. exit 1
  39. fi
  40. cd $TMP_DIR
  41. cat > prog.C <<EOF
  42. #include "gmp.h"
  43. #include <iostream>
  44. int main()
  45. {
  46. std::cout << __GMP_CFLAGS << std::endl;
  47. }
  48. EOF
  49. $CXX -I "$COCOA_EXTLIB_DIR/include" prog.C -o prog 2> /dev/null
  50. GMP_CXXFLAGS=`./prog`
  51. if [ $? -ne 0 ]
  52. then
  53. # Deliberately leave $TMP_DIR to assist debugging.
  54. echo "ERROR: $0: test program crashed!"
  55. exit 1
  56. fi
  57. # GMP_CXXFLAGS contains all the compilation flags used when building GMP.
  58. # We pick out just the compilation options which begin with -m
  59. COCOALIB_CXXFLAGS=
  60. for opt in $GMP_CXXFLAGS
  61. do
  62. case $opt in
  63. ( -m* )
  64. COCOALIB_CXXFLAGS="$COCOALIB_CXXFLAGS $opt";;
  65. esac
  66. done
  67. #######################################################
  68. # Check that these GMP CXXFLAGS actually work (they may not if the gmp.h and libgmp.a
  69. # have been copied from another machine, e.g. installing via "brew" on MacOSX)
  70. # See redmine 975.
  71. $CXX $COCOALIB_CXXFLAGS -I "$COCOA_EXTLIB_DIR/include" prog.C -o prog 2> /dev/null
  72. if [ $? -ne 0 ]
  73. then
  74. COCOALIB_CXXFLAGS=""
  75. fi
  76. # Clean up TMP_DIR
  77. cd # Leave TMP_DIR
  78. /bin/rm -rf $TMP_DIR
  79. echo $COCOALIB_CXXFLAGS