93 行
2.9 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. if test -z "$CXX"; then
  13. CXX=g++
  14. fi
  15. # Detect OS
  16. case `uname -s` in
  17. Darwin)
  18. PLATFORM=OS_MACOSX
  19. echo "PLATFORM_CFLAGS=-DOS_MACOSX" >> build_config.mk
  20. echo "PLATFORM_LDFLAGS=" >> build_config.mk
  21. ;;
  22. Linux)
  23. PLATFORM=OS_LINUX
  24. echo "PLATFORM_CFLAGS=-pthread -DOS_LINUX" >> build_config.mk
  25. echo "PLATFORM_LDFLAGS=-pthread" >> build_config.mk
  26. ;;
  27. SunOS)
  28. PLATFORM=OS_SOLARIS
  29. echo "PLATFORM_CFLAGS=-D_REENTRANT -DOS_SOLARIS" >> build_config.mk
  30. echo "PLATFORM_LDFLAGS=-lpthread -lrt" >> build_config.mk
  31. ;;
  32. FreeBSD)
  33. PLATFORM=OS_FREEBSD
  34. echo "PLATFORM_CFLAGS=-D_REENTRANT -DOS_FREEBSD" >> build_config.mk
  35. echo "PLATFORM_LDFLAGS=-lpthread" >> build_config.mk
  36. ;;
  37. NetBSD)
  38. PLATFORM=OS_NETBSD
  39. echo "PLATFORM_CFLAGS=-D_REENTRANT -DOS_NETBSD" >> build_config.mk
  40. echo "PLATFORM_LDFLAGS=-lpthread -lgcc_s" >> build_config.mk
  41. ;;
  42. OpenBSD)
  43. PLATFORM=OS_OPENBSD
  44. echo "PLATFORM_CFLAGS=-D_REENTRANT -DOS_OPENBSD" >> build_config.mk
  45. echo "PLATFORM_LDFLAGS=-pthread" >> build_config.mk
  46. ;;
  47. DragonFly)
  48. PLATFORM=OS_DRAGONFLYBSD
  49. echo "PLATFORM_CFLAGS=-D_REENTRANT -DOS_DRAGONFLYBSD" >> build_config.mk
  50. echo "PLATFORM_LDFLAGS=-lpthread" >> build_config.mk
  51. ;;
  52. *)
  53. echo "Unknown platform!"
  54. exit 1
  55. esac
  56. echo "PLATFORM=$PLATFORM" >> build_config.mk
  57. # On GCC, use libc's memcmp, not GCC's memcmp
  58. PORT_CFLAGS="-fno-builtin-memcmp"
  59. # Detect C++0x -- this determines whether we'll use port_noatomic.h
  60. # or port_posix.h by:
  61. # 1. Rrying to compile with -std=c++0x and including <cstdatomic>.
  62. # 2. If $CXX returns error code, we know to use port_posix.h
  63. $CXX $CFLAGS -std=c++0x -x c++ - -o /dev/null 2>/dev/null <<EOF
  64. #include <cstdatomic>
  65. int main() {}
  66. EOF
  67. if [ "$?" = 0 ]; then
  68. PORT_CFLAGS="$PORT_CFLAGS -DLEVELDB_PLATFORM_POSIX -DLEVELDB_CSTDATOMIC_PRESENT -std=c++0x"
  69. else
  70. PORT_CFLAGS="$PORT_CFLAGS -DLEVELDB_PLATFORM_POSIX"
  71. fi
  72. # Test whether Snappy library is installed
  73. # http://code.google.com/p/snappy/
  74. $CXX $CFLAGS -x c++ - -o /dev/null 2>/dev/null <<EOF
  75. #include <snappy.h>
  76. int main() {}
  77. EOF
  78. if [ "$?" = 0 ]; then
  79. echo "SNAPPY=1" >> build_config.mk
  80. else
  81. echo "SNAPPY=0" >> build_config.mk
  82. fi
  83. echo "PORT_CFLAGS=$PORT_CFLAGS" >> build_config.mk