作者: 韩晨旭 10225101440 李畅 10225102463
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.

145 lines
4.5 KiB

  1. #!/bin/sh
  2. #
  3. # Detects OS we're compiling on and generates build_config.mk,
  4. # which in turn gets read while processing Makefile.
  5. #
  6. # build_config.mk will set the following variables:
  7. # PLATFORM_LDFLAGS Linker flags
  8. # PLATFORM_CCFLAGS C compiler flags
  9. # PLATFORM_CXXFLAGS C++ compiler flags. Will contain:
  10. # -DLEVELDB_PLATFORM_POSIX if cstdatomic is present
  11. # -DLEVELDB_PLATFORM_NOATOMIC if it is not
  12. SCRIPT_DIR=`dirname $0`
  13. # Delete existing build_config.mk
  14. rm -f build_config.mk
  15. touch build_config.mk
  16. if test -z "$CXX"; then
  17. CXX=g++
  18. fi
  19. # Detect OS
  20. if test -z "$TARGET_OS"; then
  21. TARGET_OS=`uname -s`
  22. fi
  23. COMMON_FLAGS=
  24. PLATFORM_CCFLAGS=
  25. PLATFORM_CXXFLAGS=
  26. PLATFORM_LDFLAGS=
  27. # On GCC, we pick libc's memcmp over GCC's memcmp via -fno-builtin-memcmp
  28. case "$TARGET_OS" in
  29. Darwin)
  30. PLATFORM=OS_MACOSX
  31. COMMON_FLAGS="-fno-builtin-memcmp -DOS_MACOSX"
  32. PORT_FILE=port/port_posix.cc
  33. ;;
  34. Linux)
  35. PLATFORM=OS_LINUX
  36. COMMON_FLAGS="-fno-builtin-memcmp -pthread -DOS_LINUX"
  37. PLATFORM_LDFLAGS="-pthread"
  38. PORT_FILE=port/port_posix.cc
  39. ;;
  40. SunOS)
  41. PLATFORM=OS_SOLARIS
  42. COMMON_FLAGS="-fno-builtin-memcmp -D_REENTRANT -DOS_SOLARIS"
  43. PLATFORM_LDFLAGS="-lpthread -lrt"
  44. PORT_FILE=port/port_posix.cc
  45. ;;
  46. FreeBSD)
  47. PLATFORM=OS_FREEBSD
  48. COMMON_FLAGS="-fno-builtin-memcmp -D_REENTRANT -DOS_FREEBSD"
  49. PLATFORM_LDFLAGS="-lpthread"
  50. PORT_FILE=port/port_posix.cc
  51. ;;
  52. NetBSD)
  53. PLATFORM=OS_NETBSD
  54. COMMON_FLAGS="-fno-builtin-memcmp -D_REENTRANT -DOS_NETBSD"
  55. PLATFORM_LDFLAGS="-lpthread -lgcc_s"
  56. PORT_FILE=port/port_posix.cc
  57. ;;
  58. OpenBSD)
  59. PLATFORM=OS_OPENBSD
  60. COMMON_FLAGS="-fno-builtin-memcmp -D_REENTRANT -DOS_OPENBSD"
  61. PLATFORM_LDFLAGS="-pthread"
  62. PORT_FILE=port/port_posix.cc
  63. ;;
  64. DragonFly)
  65. PLATFORM=OS_DRAGONFLYBSD
  66. COMMON_FLAGS="-fno-builtin-memcmp -D_REENTRANT -DOS_DRAGONFLYBSD"
  67. PLATFORM_LDFLAGS="-lpthread"
  68. PORT_FILE=port/port_posix.cc
  69. ;;
  70. OS_ANDROID_CROSSCOMPILE)
  71. PLATFORM="$TARGET_OS"
  72. COMMON_FLAGS=""
  73. PLATFORM_LDFLAGS=""
  74. PORT_FILE=port/port_android.cc
  75. ;;
  76. *)
  77. echo "Unknown platform!"
  78. exit 1
  79. esac
  80. # We want to make a list of all cc files within util, db, table, and helpers
  81. # except for the test and benchmark files. By default, find will output a list
  82. # of all files matching either rule, so we need to append -print to make the
  83. # prune take effect.
  84. DIRS="$SCRIPT_DIR/util $SCRIPT_DIR/db $SCRIPT_DIR/table"
  85. set -f # temporarily disable globbing so that our patterns aren't expanded
  86. PRUNE_TEST="-name *test*.cc -prune"
  87. PRUNE_BENCH="-name *_bench.cc -prune"
  88. PORTABLE_FILES=`find $DIRS $PRUNE_TEST -o $PRUNE_BENCH -o -name '*.cc' -print | sort | tr "\n" " "`
  89. set +f # re-enable globbing
  90. # The sources consist of the portable files, plus the platform-specific port
  91. # file.
  92. echo "SOURCES=$PORTABLE_FILES $PORT_FILE" >> build_config.mk
  93. echo "MEMENV_SOURCES=helpers/memenv/memenv.cc" >> build_config.mk
  94. if [ "$PLATFORM" = "OS_ANDROID_CROSSCOMPILE" ]; then
  95. # Cross-compiling; do not try any compilation tests.
  96. true
  97. else
  98. # If -std=c++0x works, use <cstdatomic>. Otherwise use port_posix.h.
  99. $CXX $CFLAGS -std=c++0x -x c++ - -o /dev/null 2>/dev/null <<EOF
  100. #include <cstdatomic>
  101. int main() {}
  102. EOF
  103. if [ "$?" = 0 ]; then
  104. COMMON_FLAGS="$COMMON_FLAGS -DLEVELDB_PLATFORM_POSIX -DLEVELDB_CSTDATOMIC_PRESENT"
  105. PLATFORM_CXXFLAGS="-std=c++0x"
  106. else
  107. COMMON_FLAGS="$COMMON_FLAGS -DLEVELDB_PLATFORM_POSIX"
  108. fi
  109. # Test whether Snappy library is installed
  110. # http://code.google.com/p/snappy/
  111. $CXX $CFLAGS -x c++ - -o /dev/null 2>/dev/null <<EOF
  112. #include <snappy.h>
  113. int main() {}
  114. EOF
  115. if [ "$?" = 0 ]; then
  116. COMMON_FLAGS="$COMMON_FLAGS -DSNAPPY"
  117. PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -lsnappy"
  118. fi
  119. # Test whether tcmalloc is available
  120. $CXX $CFLAGS -x c++ - -o /dev/null -ltcmalloc 2>/dev/null <<EOF
  121. int main() {}
  122. EOF
  123. if [ "$?" = 0 ]; then
  124. PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -ltcmalloc"
  125. fi
  126. fi
  127. PLATFORM_CCFLAGS="$PLATFORM_CCFLAGS $COMMON_FLAGS"
  128. PLATFORM_CXXFLAGS="$PLATFORM_CXXFLAGS $COMMON_FLAGS"
  129. echo "PLATFORM=$PLATFORM" >> build_config.mk
  130. echo "PLATFORM_LDFLAGS=$PLATFORM_LDFLAGS" >> build_config.mk
  131. echo "PLATFORM_CCFLAGS=$PLATFORM_CCFLAGS" >> build_config.mk
  132. echo "PLATFORM_CXXFLAGS=$PLATFORM_CXXFLAGS" >> build_config.mk