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.

83 lines
2.2 KiB

3 months ago
  1. #!/bin/bash
  2. # This script gets the version number of GMP.
  3. # Assumes that env variable CXX is set, and that a link to GMP header file is in $COCOA_EXTLIB_DIR/include
  4. # if there is no system default GMP.
  5. # If an error occurs, exit code is non-zero (& mesg is printed on stderr).
  6. # Otherwise exit code is zero, and output is version number (e.g. 6.0.1)
  7. if [ "$#" != 0 ]
  8. then
  9. echo "$0: ERROR: expects no args"
  10. exit 1
  11. fi
  12. if [ -z "$CXX" ]
  13. then
  14. echo "$0: ERROR: shell variable CXX must be set to a C++ compiler compatible with GMP"
  15. exit 1
  16. fi
  17. if [ -z "$COCOA_EXTLIB_DIR" ]
  18. then
  19. echo "ERROR: $0: environment variable COCOA_EXTLIB_DIR not set."
  20. exit 1
  21. fi
  22. if [ \! "$COCOA_EXTLIB_DIR" -ef "/$COCOA_EXTLIB_DIR" ]
  23. then
  24. echo "ERROR: $0: environment variable COCOA_EXTLIB_DIR is not absolute: $COCOA_EXTLIB_DIR."
  25. exit 1
  26. fi
  27. if [ \! -d "$COCOA_EXTLIB_DIR" -o \! -d "$COCOA_EXTLIB_DIR/include" -o \! -d "$COCOA_EXTLIB_DIR/lib" ]
  28. then
  29. echo "ERROR: $0: environment variable COCOA_EXTLIB_DIR is implausible: $COCOA_EXTLIB_DIR."
  30. exit 1
  31. fi
  32. # Get version number from the header file; we (ab)use the compiler.
  33. umask 22
  34. TODAY=`date "+%Y-%m-%d"`
  35. TIME=`date "+%H:%M:%S"`
  36. TMP_DIR=/tmp/CoCoALib-config-$USER-$TODAY/gmp-version-$TIME-$$
  37. /bin/rm -rf $TMP_DIR && mkdir -p $TMP_DIR
  38. if [ $? -ne 0 ]; then
  39. echo "ERROR: $0 failed to create temporary directory \"$TMP_DIR\""
  40. exit 1
  41. fi
  42. cd $TMP_DIR
  43. cat > TestProg.C <<EOF
  44. #include "gmp.h"
  45. #include <iostream>
  46. int main()
  47. {
  48. std::cout << __GNU_MP_VERSION << "." << __GNU_MP_VERSION_MINOR << "." << __GNU_MP_VERSION_PATCHLEVEL << std::endl;
  49. }
  50. EOF
  51. # Use c++ compiler specified in CXX; no need to specify libgmp as all info is in header file!!
  52. $CXX -I "$COCOA_EXTLIB_DIR/include" TestProg.C -o TestProg 2> /dev/null
  53. # Check whether compilation failed; if so, complain.
  54. if [ $? -ne 0 ]
  55. then
  56. echo "ERROR: $0: unable to determine version of GMP library" > /dev/stderr
  57. echo "ERROR: $0: (compilation failed in gmp-version.sh)" > /dev/stderr
  58. exit 1
  59. fi
  60. # Compilation succeeded, so run $PROG which will print out the version.
  61. GMP_LIB_VERSION=`./TestProg`
  62. # Clean up TMP_DIR
  63. cd # Leave TMP_DIR
  64. /bin/rm -rf $TMP_DIR
  65. # If we get here, all tests have passed, so print version number and exit with code 0.
  66. echo $GMP_LIB_VERSION