作者: 谢瑞阳 10225101483 徐翔宇 10225101535
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

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