提供基本的ttl测试用例
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.

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