作者: 谢瑞阳 10225101483 徐翔宇 10225101535
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.

74 lines
2.2 KiB

  1. #!/bin/sh
  2. # Detects OS we're compiling on and generates build_config.mk,
  3. # which in turn gets read while processing Makefile.
  4. # build_config.mk will set the following variables:
  5. # - PORT_CFLAGS will either set:
  6. # -DLEVELDB_PLATFORM_POSIX if cstatomic is present
  7. # -DLEVELDB_PLATFORM_NOATOMIC if it is not
  8. # - PLATFORM_CFLAGS with compiler flags for the platform
  9. # - PLATFORM_LDFLAGS with linker flags for the platform
  10. # Delete existing build_config.mk
  11. rm -f build_config.mk
  12. # Detect OS
  13. case `uname -s` in
  14. Darwin)
  15. PLATFORM=OS_MACOSX
  16. echo "PLATFORM_CFLAGS=-DOS_MACOSX" >> build_config.mk
  17. echo "PLATFORM_LDFLAGS=" >> build_config.mk
  18. ;;
  19. Linux)
  20. PLATFORM=OS_LINUX
  21. echo "PLATFORM_CFLAGS=-pthread -DOS_LINUX" >> build_config.mk
  22. echo "PLATFORM_LDFLAGS=-lpthread" >> build_config.mk
  23. ;;
  24. SunOS)
  25. PLATFORM=OS_SOLARIS
  26. echo "PLATFORM_CFLAGS=-D_REENTRANT -DOS_SOLARIS" >> build_config.mk
  27. echo "PLATFORM_LDFLAGS=-lpthread -lrt" >> build_config.mk
  28. ;;
  29. FreeBSD)
  30. PLATFORM=OS_FREEBSD
  31. echo "PLATFORM_CFLAGS=-D_REENTRANT -DOS_FREEBSD" >> build_config.mk
  32. echo "PLATFORM_LDFLAGS=-lpthread" >> build_config.mk
  33. ;;
  34. *)
  35. echo "Unknown platform!"
  36. exit 1
  37. esac
  38. echo "PLATFORM=$PLATFORM" >> build_config.mk
  39. # On GCC, use libc's memcmp, not GCC's memcmp
  40. PORT_CFLAGS="-fno-builtin-memcmp"
  41. # Detect C++0x -- this determines whether we'll use port_noatomic.h
  42. # or port_posix.h by:
  43. # 1. Rrying to compile with -std=c++0x and including <cstdatomic>.
  44. # 2. If g++ returns error code, we know to use port_posix.h
  45. g++ $CFLAGS -std=c++0x -x c++ - -o /dev/null 2>/dev/null <<EOF
  46. #include <cstdatomic>
  47. int main() {}
  48. EOF
  49. if [ "$?" = 0 ]; then
  50. PORT_CFLAGS="$PORT_CFLAGS -DLEVELDB_PLATFORM_POSIX -DLEVELDB_CSTDATOMIC_PRESENT -std=c++0x"
  51. else
  52. PORT_CFLAGS="$PORT_CFLAGS -DLEVELDB_PLATFORM_POSIX"
  53. fi
  54. # Test whether Snappy library is installed
  55. # http://code.google.com/p/snappy/
  56. g++ $CFLAGS -x c++ - -o /dev/null 2>/dev/null <<EOF
  57. #include <snappy.h>
  58. int main() {}
  59. EOF
  60. if [ "$?" = 0 ]; then
  61. echo "SNAPPY=1" >> build_config.mk
  62. else
  63. echo "SNAPPY=0" >> build_config.mk
  64. fi
  65. echo "PORT_CFLAGS=$PORT_CFLAGS" >> build_config.mk