The source code and dockerfile for the GSW2024 AI Lab.
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

107 lines
2.8 KiB

4 weeks ago
  1. #!/bin/bash
  2. # This script checks compatibility of user supplied CXXFLAGS with
  3. # the GMP library.
  4. # Exit code is 0 iff CXXFLAGS and GMP are compatible, o/w non-zero.
  5. # This script expects 1 arg: the CXXFLAGS used to compile GMP
  6. # Also expects that CXX and CXXFLAGS have been exported from caller.
  7. # Also expects that the ExternalLibs/ subtree has been created.
  8. if [ $# != 1 ]
  9. then
  10. echo "$0: ERROR: requires 1 arg (CXXFLAGS_FOR_GMP)"
  11. exit 1
  12. fi
  13. # Check environment variables CXX and COCOA_EXTLIB_DIR
  14. if [ -z "$CXX" ]
  15. then
  16. echo "ERROR: $0: environment variable CXX not set."
  17. exit 1
  18. fi
  19. if [ -z "$COCOA_EXTLIB_DIR" ]
  20. then
  21. echo "ERROR: $0: environment variable COCOA_EXTLIB_DIR not set."
  22. exit 1
  23. fi
  24. if [ \! "$COCOA_EXTLIB_DIR" -ef "/$COCOA_EXTLIB_DIR" ]
  25. then
  26. echo "ERROR: $0: environment variable COCOA_EXTLIB_DIR is not absolute: $COCOA_EXTLIB_DIR."
  27. exit 1
  28. fi
  29. if [ \! -d "$COCOA_EXTLIB_DIR" -o \! -d "$COCOA_EXTLIB_DIR/include" -o \! -d "$COCOA_EXTLIB_DIR/lib" ]
  30. then
  31. echo "ERROR: $0: environment variable COCOA_EXTLIB_DIR is implausible: $COCOA_EXTLIB_DIR."
  32. exit 1
  33. fi
  34. CXXFLAGS_FOR_GMP="$1"
  35. GMP_LDLIB=-lgmp
  36. if [ -f ExternalLibs/lib/libgmp-symlink.a ]
  37. then
  38. GMP_LDLIB=-lgmp-symlink
  39. fi
  40. umask 22
  41. # Create tmp directory, put C prog in it, compile and run.
  42. # TMP_DIR depends on hostname, userid, and process number to avoid unfortunate
  43. # name clashes if several people try to install CoCoALib simultaneously.
  44. TODAY=`date "+%Y-%m-%d"`
  45. TIME=`date "+%H:%M:%S"`
  46. TMP_DIR=/tmp/CoCoALib-config-$USER-$TODAY/gmp-check-cxxflags-$TIME-$$
  47. /bin/rm -rf $TMP_DIR && mkdir -p $TMP_DIR
  48. if [ $? -ne 0 ]; then
  49. echo "ERROR: $0 failed to create temporary directory \"$TMP_DIR\""
  50. exit 1
  51. fi
  52. cd $TMP_DIR
  53. cat > TestProg.c <<EOF
  54. #include "gmp.h"
  55. int main()
  56. {
  57. mpz_t A; mpz_init_set_ui(A,1);
  58. mpz_t B; mpz_init_set_ui(B,1);
  59. mpz_add(A, A, B);
  60. if (mpz_cmp_ui(A, 2) != 0)
  61. return 1;
  62. return 0;
  63. }
  64. EOF
  65. # Compile test prog using given CXX and CXXFLAGS, and GMP header and library
  66. $CXX $CXXFLAGS $CXXFLAGS_FOR_GMP TestProg.c -o TestProg -I "$COCOA_EXTLIB_DIR/include" -L"$COCOA_EXTLIB_DIR/lib" $GMP_LDLIB 2> /dev/null
  67. # Check whether compilation failed; if so, complain.
  68. if [ $? -ne 0 ]
  69. then
  70. # Deliberately leave $TMP_DIR to assist debugging.
  71. echo "ERROR: $0 failed to compile/link TestProg; command used was"
  72. echo "ERROR: $CXX $CXXFLAGS $CXXFLAGS_FOR_GMP TestProg.c -o TestProg -I \"$COCOA_EXTLIB_DIR/include\" -L\"$COCOA_EXTLIB_DIR/lib\" $GMP_LDLIB"
  73. exit 2
  74. fi
  75. # Compilation succeeded, so try running $PROG.
  76. ./TestProg 2>/dev/null
  77. # Check whether execution failed; if so, complain (probably linker problems).
  78. if [ $? -ne 0 ]
  79. then
  80. # Deliberately leave $TMP_DIR to assist debugging.
  81. echo "ERROR: $0: TestProg crashed (probably linker problem for libgmp)"
  82. exit 3
  83. fi
  84. # Clean up TMP_DIR
  85. cd # Leave TMP_DIR
  86. /bin/rm -rf $TMP_DIR
  87. exit 0