10225501448 李度 10225101546 陈胤遒 10215501422 高宇菲
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.

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