作者: 谢瑞阳 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.

203 rivejä
6.6 KiB

  1. #!/bin/sh
  2. #
  3. # Detects OS we're compiling on and outputs a file specified by the first
  4. # argument, which in turn gets read while processing Makefile.
  5. #
  6. # The output will set the following variables:
  7. # CC C Compiler path
  8. # CXX C++ Compiler path
  9. # PLATFORM_LDFLAGS Linker flags
  10. # PLATFORM_LIBS Libraries flags
  11. # PLATFORM_SHARED_EXT Extension for shared libraries
  12. # PLATFORM_SHARED_LDFLAGS Flags for building shared library
  13. # This flag is embedded just before the name
  14. # of the shared library without intervening spaces
  15. # PLATFORM_SHARED_CFLAGS Flags for compiling objects for shared library
  16. # PLATFORM_CCFLAGS C compiler flags
  17. # PLATFORM_CXXFLAGS C++ compiler flags. Will contain:
  18. # PLATFORM_SHARED_VERSIONED Set to 'true' if platform supports versioned
  19. # shared libraries, empty otherwise.
  20. #
  21. # The PLATFORM_CCFLAGS and PLATFORM_CXXFLAGS might include the following:
  22. #
  23. # -DLEVELDB_CSTDATOMIC_PRESENT if <cstdatomic> is present
  24. # -DLEVELDB_PLATFORM_POSIX for Posix-based platforms
  25. # -DSNAPPY if the Snappy library is present
  26. #
  27. OUTPUT=$1
  28. PREFIX=$2
  29. if test -z "$OUTPUT" || test -z "$PREFIX"; then
  30. echo "usage: $0 <output-filename> <directory_prefix>" >&2
  31. exit 1
  32. fi
  33. # Delete existing output, if it exists
  34. rm -f $OUTPUT
  35. touch $OUTPUT
  36. if test -z "$CC"; then
  37. CC=cc
  38. fi
  39. if test -z "$CXX"; then
  40. CXX=g++
  41. fi
  42. # Detect OS
  43. if test -z "$TARGET_OS"; then
  44. TARGET_OS=`uname -s`
  45. fi
  46. COMMON_FLAGS=
  47. CROSS_COMPILE=
  48. PLATFORM_CCFLAGS=
  49. PLATFORM_CXXFLAGS=
  50. PLATFORM_LDFLAGS=
  51. PLATFORM_LIBS=
  52. PLATFORM_SHARED_EXT="so"
  53. PLATFORM_SHARED_LDFLAGS="-shared -Wl,-soname -Wl,"
  54. PLATFORM_SHARED_CFLAGS="-fPIC"
  55. PLATFORM_SHARED_VERSIONED=true
  56. MEMCMP_FLAG=
  57. if [ "$CXX" = "g++" ]; then
  58. # Use libc's memcmp instead of GCC's memcmp. This results in ~40%
  59. # performance improvement on readrandom under gcc 4.4.3 on Linux/x86.
  60. MEMCMP_FLAG="-fno-builtin-memcmp"
  61. fi
  62. case "$TARGET_OS" in
  63. Darwin)
  64. PLATFORM=OS_MACOSX
  65. COMMON_FLAGS="$MEMCMP_FLAG -DOS_MACOSX"
  66. PLATFORM_SHARED_EXT=dylib
  67. [ -z "$INSTALL_PATH" ] && INSTALL_PATH=`pwd`
  68. PLATFORM_SHARED_LDFLAGS="-dynamiclib -install_name $INSTALL_PATH/"
  69. PORT_FILE=port/port_posix.cc
  70. ;;
  71. Linux)
  72. PLATFORM=OS_LINUX
  73. COMMON_FLAGS="$MEMCMP_FLAG -pthread -DOS_LINUX"
  74. PLATFORM_LDFLAGS="-pthread"
  75. PORT_FILE=port/port_posix.cc
  76. ;;
  77. SunOS)
  78. PLATFORM=OS_SOLARIS
  79. COMMON_FLAGS="$MEMCMP_FLAG -D_REENTRANT -DOS_SOLARIS"
  80. PLATFORM_LIBS="-lpthread -lrt"
  81. PORT_FILE=port/port_posix.cc
  82. ;;
  83. FreeBSD)
  84. PLATFORM=OS_FREEBSD
  85. COMMON_FLAGS="$MEMCMP_FLAG -D_REENTRANT -DOS_FREEBSD"
  86. PLATFORM_LIBS="-lpthread"
  87. PORT_FILE=port/port_posix.cc
  88. ;;
  89. NetBSD)
  90. PLATFORM=OS_NETBSD
  91. COMMON_FLAGS="$MEMCMP_FLAG -D_REENTRANT -DOS_NETBSD"
  92. PLATFORM_LIBS="-lpthread -lgcc_s"
  93. PORT_FILE=port/port_posix.cc
  94. ;;
  95. OpenBSD)
  96. PLATFORM=OS_OPENBSD
  97. COMMON_FLAGS="$MEMCMP_FLAG -D_REENTRANT -DOS_OPENBSD"
  98. PLATFORM_LDFLAGS="-pthread"
  99. PORT_FILE=port/port_posix.cc
  100. ;;
  101. DragonFly)
  102. PLATFORM=OS_DRAGONFLYBSD
  103. COMMON_FLAGS="$MEMCMP_FLAG -D_REENTRANT -DOS_DRAGONFLYBSD"
  104. PLATFORM_LIBS="-lpthread"
  105. PORT_FILE=port/port_posix.cc
  106. ;;
  107. OS_ANDROID_CROSSCOMPILE)
  108. PLATFORM=OS_ANDROID
  109. COMMON_FLAGS="$MEMCMP_FLAG -D_REENTRANT -DOS_ANDROID -DLEVELDB_PLATFORM_POSIX"
  110. PLATFORM_LDFLAGS="" # All pthread features are in the Android C library
  111. PORT_FILE=port/port_posix.cc
  112. CROSS_COMPILE=true
  113. ;;
  114. HP-UX)
  115. PLATFORM=OS_HPUX
  116. COMMON_FLAGS="$MEMCMP_FLAG -D_REENTRANT -DOS_HPUX"
  117. PLATFORM_LDFLAGS="-pthread"
  118. PORT_FILE=port/port_posix.cc
  119. # man ld: +h internal_name
  120. PLATFORM_SHARED_LDFLAGS="-shared -Wl,+h -Wl,"
  121. ;;
  122. *)
  123. echo "Unknown platform!" >&2
  124. exit 1
  125. esac
  126. # We want to make a list of all cc files within util, db, table, and helpers
  127. # except for the test and benchmark files. By default, find will output a list
  128. # of all files matching either rule, so we need to append -print to make the
  129. # prune take effect.
  130. DIRS="$PREFIX/db $PREFIX/util $PREFIX/table"
  131. set -f # temporarily disable globbing so that our patterns aren't expanded
  132. PRUNE_TEST="-name *test*.cc -prune"
  133. PRUNE_BENCH="-name *_bench.cc -prune"
  134. PRUNE_TOOL="-name leveldb_main.cc -prune"
  135. PORTABLE_FILES=`find $DIRS $PRUNE_TEST -o $PRUNE_BENCH -o $PRUNE_TOOL -o -name '*.cc' -print | sort | sed "s,^$PREFIX/,," | tr "\n" " "`
  136. set +f # re-enable globbing
  137. # The sources consist of the portable files, plus the platform-specific port
  138. # file.
  139. echo "SOURCES=$PORTABLE_FILES $PORT_FILE" >> $OUTPUT
  140. echo "MEMENV_SOURCES=helpers/memenv/memenv.cc" >> $OUTPUT
  141. if [ "$CROSS_COMPILE" = "true" ]; then
  142. # Cross-compiling; do not try any compilation tests.
  143. true
  144. else
  145. # If -std=c++0x works, use <cstdatomic>. Otherwise use port_posix.h.
  146. $CXX $CXXFLAGS -std=c++0x -x c++ - -o /dev/null 2>/dev/null <<EOF
  147. #include <cstdatomic>
  148. int main() {}
  149. EOF
  150. if [ "$?" = 0 ]; then
  151. COMMON_FLAGS="$COMMON_FLAGS -DLEVELDB_PLATFORM_POSIX -DLEVELDB_CSTDATOMIC_PRESENT"
  152. PLATFORM_CXXFLAGS="-std=c++0x"
  153. else
  154. COMMON_FLAGS="$COMMON_FLAGS -DLEVELDB_PLATFORM_POSIX"
  155. fi
  156. # Test whether Snappy library is installed
  157. # http://code.google.com/p/snappy/
  158. $CXX $CXXFLAGS -x c++ - -o /dev/null 2>/dev/null <<EOF
  159. #include <snappy.h>
  160. int main() {}
  161. EOF
  162. if [ "$?" = 0 ]; then
  163. COMMON_FLAGS="$COMMON_FLAGS -DSNAPPY"
  164. PLATFORM_LIBS="$PLATFORM_LIBS -lsnappy"
  165. fi
  166. # Test whether tcmalloc is available
  167. $CXX $CXXFLAGS -x c++ - -o /dev/null -ltcmalloc 2>/dev/null <<EOF
  168. int main() {}
  169. EOF
  170. if [ "$?" = 0 ]; then
  171. PLATFORM_LIBS="$PLATFORM_LIBS -ltcmalloc"
  172. fi
  173. fi
  174. PLATFORM_CCFLAGS="$PLATFORM_CCFLAGS $COMMON_FLAGS"
  175. PLATFORM_CXXFLAGS="$PLATFORM_CXXFLAGS $COMMON_FLAGS"
  176. echo "CC=$CC" >> $OUTPUT
  177. echo "CXX=$CXX" >> $OUTPUT
  178. echo "PLATFORM=$PLATFORM" >> $OUTPUT
  179. echo "PLATFORM_LDFLAGS=$PLATFORM_LDFLAGS" >> $OUTPUT
  180. echo "PLATFORM_LIBS=$PLATFORM_LIBS" >> $OUTPUT
  181. echo "PLATFORM_CCFLAGS=$PLATFORM_CCFLAGS" >> $OUTPUT
  182. echo "PLATFORM_CXXFLAGS=$PLATFORM_CXXFLAGS" >> $OUTPUT
  183. echo "PLATFORM_SHARED_CFLAGS=$PLATFORM_SHARED_CFLAGS" >> $OUTPUT
  184. echo "PLATFORM_SHARED_EXT=$PLATFORM_SHARED_EXT" >> $OUTPUT
  185. echo "PLATFORM_SHARED_LDFLAGS=$PLATFORM_SHARED_LDFLAGS" >> $OUTPUT
  186. echo "PLATFORM_SHARED_VERSIONED=$PLATFORM_SHARED_VERSIONED" >> $OUTPUT