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.
6 # The output will set the following variables:
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.
21 # The PLATFORM_CCFLAGS and PLATFORM_CXXFLAGS might include the following:
23 # -DLEVELDB_ATOMIC_PRESENT if <atomic> is present
24 # -DLEVELDB_PLATFORM_POSIX for Posix-based platforms
25 # -DSNAPPY if the Snappy library is present
30 if test -z "$OUTPUT" ||
test -z "$PREFIX"; then
31 echo "usage: $0 <output-filename> <directory_prefix>" >&2
35 # Delete existing output, if it exists
39 if test -z "$CC"; then
43 if test -z "$CXX"; then
47 if test -z "$TMPDIR"; then
52 if test -z "$TARGET_OS"; then
62 PLATFORM_SHARED_EXT
="so"
63 PLATFORM_SHARED_LDFLAGS
="-shared -Wl,-soname -Wl,"
64 PLATFORM_SHARED_CFLAGS
="-fPIC"
65 PLATFORM_SHARED_VERSIONED
=true
69 if [ "$CXX" = "g++" ]; then
70 # Use libc's memcmp instead of GCC's memcmp. This results in ~40%
71 # performance improvement on readrandom under gcc 4.4.3 on Linux/x86.
72 MEMCMP_FLAG
="-fno-builtin-memcmp"
78 COMMON_FLAGS
="$MEMCMP_FLAG -lpthread -DOS_LINUX -DCYGWIN"
79 PLATFORM_LDFLAGS
="-lpthread"
80 PORT_FILE
=port
/port_posix.cc
81 PORT_SSE_FILE
=port
/port_posix_sse.cc
85 COMMON_FLAGS
="$MEMCMP_FLAG -DOS_MACOSX"
86 PLATFORM_SHARED_EXT
=dylib
87 [ -z "$INSTALL_PATH" ] && INSTALL_PATH
=`pwd`
88 PLATFORM_SHARED_LDFLAGS
="-dynamiclib -install_name $INSTALL_PATH/"
89 PORT_FILE
=port
/port_posix.cc
90 PORT_SSE_FILE
=port
/port_posix_sse.cc
94 COMMON_FLAGS
="$MEMCMP_FLAG -pthread -DOS_LINUX"
95 PLATFORM_LDFLAGS
="-pthread"
96 PORT_FILE
=port
/port_posix.cc
97 PORT_SSE_FILE
=port
/port_posix_sse.cc
101 COMMON_FLAGS
="$MEMCMP_FLAG -D_REENTRANT -DOS_SOLARIS"
102 PLATFORM_LIBS
="-lpthread -lrt"
103 PORT_FILE
=port
/port_posix.cc
104 PORT_SSE_FILE
=port
/port_posix_sse.cc
108 COMMON_FLAGS
="$MEMCMP_FLAG -D_REENTRANT -DOS_FREEBSD"
109 PLATFORM_LIBS
="-lpthread"
110 PORT_FILE
=port
/port_posix.cc
111 PORT_SSE_FILE
=port
/port_posix_sse.cc
115 COMMON_FLAGS
="$MEMCMP_FLAG -D_REENTRANT -DOS_KFREEBSD"
116 PLATFORM_LIBS
="-lpthread"
117 PORT_FILE
=port
/port_posix.cc
121 COMMON_FLAGS
="$MEMCMP_FLAG -D_REENTRANT -DOS_NETBSD"
122 PLATFORM_LIBS
="-lpthread -lgcc_s"
123 PORT_FILE
=port
/port_posix.cc
124 PORT_SSE_FILE
=port
/port_posix_sse.cc
128 COMMON_FLAGS
="$MEMCMP_FLAG -D_REENTRANT -DOS_OPENBSD"
129 PLATFORM_LDFLAGS
="-pthread"
130 PORT_FILE
=port
/port_posix.cc
131 PORT_SSE_FILE
=port
/port_posix_sse.cc
134 PLATFORM
=OS_DRAGONFLYBSD
135 COMMON_FLAGS
="$MEMCMP_FLAG -D_REENTRANT -DOS_DRAGONFLYBSD"
136 PLATFORM_LIBS
="-lpthread"
137 PORT_FILE
=port
/port_posix.cc
138 PORT_SSE_FILE
=port
/port_posix_sse.cc
140 OS_ANDROID_CROSSCOMPILE
)
142 COMMON_FLAGS
="$MEMCMP_FLAG -D_REENTRANT -DOS_ANDROID -DLEVELDB_PLATFORM_POSIX"
143 PLATFORM_LDFLAGS
="" # All pthread features are in the Android C library
144 PORT_FILE
=port
/port_posix.cc
145 PORT_SSE_FILE
=port
/port_posix_sse.cc
150 COMMON_FLAGS
="$MEMCMP_FLAG -D_REENTRANT -DOS_HPUX"
151 PLATFORM_LDFLAGS
="-pthread"
152 PORT_FILE
=port
/port_posix.cc
153 PORT_SSE_FILE
=port
/port_posix_sse.cc
154 # man ld: +h internal_name
155 PLATFORM_SHARED_LDFLAGS
="-shared -Wl,+h -Wl,"
159 COMMON_FLAGS
="$MEMCMP_FLAG -DOS_MACOSX"
160 [ -z "$INSTALL_PATH" ] && INSTALL_PATH
=`pwd`
161 PORT_FILE
=port
/port_posix.cc
162 PORT_SSE_FILE
=port
/port_posix_sse.cc
164 PLATFORM_SHARED_LDFLAGS
=
165 PLATFORM_SHARED_CFLAGS
=
166 PLATFORM_SHARED_VERSIONED
=
168 OS_WINDOWS_CROSSCOMPILE | NATIVE_WINDOWS
)
170 COMMON_FLAGS
="-fno-builtin-memcmp -D_REENTRANT -DOS_WINDOWS -DLEVELDB_PLATFORM_WINDOWS -DWINVER=0x0500 -D__USE_MINGW_ANSI_STDIO=1"
171 PLATFORM_SOURCES
="util/env_win.cc"
172 PLATFORM_LIBS
="-lshlwapi"
173 PORT_FILE
=port
/port_win.cc
177 echo "Unknown platform!" >&2
181 # We want to make a list of all cc files within util, db, table, and helpers
182 # except for the test and benchmark files. By default, find will output a list
183 # of all files matching either rule, so we need to append -print to make the
185 DIRS
="$PREFIX/db $PREFIX/util $PREFIX/table"
187 set -f # temporarily disable globbing so that our patterns aren't expanded
188 PRUNE_TEST
="-name *test*.cc -prune"
189 PRUNE_BENCH
="-name *_bench.cc -prune"
190 PRUNE_TOOL
="-name leveldbutil.cc -prune"
191 PORTABLE_FILES
=`find $DIRS $PRUNE_TEST -o $PRUNE_BENCH -o $PRUNE_TOOL -o -name '*.cc' -print | sort | sed "s,^$PREFIX/,," | tr "\n" " "`
193 set +f
# re-enable globbing
195 # The sources consist of the portable files, plus the platform-specific port
197 echo "SOURCES=$PORTABLE_FILES $PORT_FILE $PORT_SSE_FILE" >> $OUTPUT
198 echo "MEMENV_SOURCES=helpers/memenv/memenv.cc" >> $OUTPUT
200 if [ "$CROSS_COMPILE" = "true" ]; then
201 # Cross-compiling; do not try any compilation tests.
204 CXXOUTPUT
="${TMPDIR}/leveldb_build_detect_platform-cxx.$$"
206 # If -std=c++0x works, use <atomic> as fallback for when memory barriers
208 $CXX $CXXFLAGS -std=c
++0x
-x c
++ - -o $CXXOUTPUT 2>/dev
/null
<<EOF
212 if [ "$?" = 0 ]; then
213 COMMON_FLAGS
="$COMMON_FLAGS -DLEVELDB_PLATFORM_POSIX -DLEVELDB_ATOMIC_PRESENT"
214 PLATFORM_CXXFLAGS
="-std=c++0x"
216 COMMON_FLAGS
="$COMMON_FLAGS -DLEVELDB_PLATFORM_POSIX"
219 # Test whether tcmalloc is available
220 $CXX $CXXFLAGS -x c
++ - -o $CXXOUTPUT -ltcmalloc 2>/dev
/null
<<EOF
223 if [ "$?" = 0 ]; then
224 PLATFORM_LIBS
="$PLATFORM_LIBS -ltcmalloc"
227 rm -f $CXXOUTPUT 2>/dev
/null
229 # Test if gcc SSE 4.2 is supported
230 $CXX $CXXFLAGS -x c
++ - -o $CXXOUTPUT -msse4.2
2>/dev
/null
<<EOF
233 if [ "$?" = 0 ]; then
234 PLATFORM_SSEFLAGS
="-msse4.2"
237 rm -f $CXXOUTPUT 2>/dev
/null
240 # Use the SSE 4.2 CRC32C intrinsics iff runtime checks indicate compiler supports them.
241 if [ -n "$PLATFORM_SSEFLAGS" ]; then
242 PLATFORM_SSEFLAGS
="$PLATFORM_SSEFLAGS -DLEVELDB_PLATFORM_POSIX_SSE"
245 PLATFORM_CCFLAGS
="$PLATFORM_CCFLAGS $COMMON_FLAGS"
246 PLATFORM_CXXFLAGS
="$PLATFORM_CXXFLAGS $COMMON_FLAGS"
248 echo "CC=$CC" >> $OUTPUT
249 echo "CXX=$CXX" >> $OUTPUT
250 echo "PLATFORM=$PLATFORM" >> $OUTPUT
251 echo "PLATFORM_LDFLAGS=$PLATFORM_LDFLAGS" >> $OUTPUT
252 echo "PLATFORM_LIBS=$PLATFORM_LIBS" >> $OUTPUT
253 echo "PLATFORM_CCFLAGS=$PLATFORM_CCFLAGS" >> $OUTPUT
254 echo "PLATFORM_CXXFLAGS=$PLATFORM_CXXFLAGS" >> $OUTPUT
255 echo "PLATFORM_SSEFLAGS=$PLATFORM_SSEFLAGS" >> $OUTPUT
256 echo "PLATFORM_SHARED_CFLAGS=$PLATFORM_SHARED_CFLAGS" >> $OUTPUT
257 echo "PLATFORM_SHARED_EXT=$PLATFORM_SHARED_EXT" >> $OUTPUT
258 echo "PLATFORM_SHARED_LDFLAGS=$PLATFORM_SHARED_LDFLAGS" >> $OUTPUT
259 echo "PLATFORM_SHARED_VERSIONED=$PLATFORM_SHARED_VERSIONED" >> $OUTPUT