Skip to content
Newer
Older
100755 229 lines (208 sloc) 7.28 KB
f57e233 Platform detection during build, plus compatibility patches for machi…
gabor@google.com authored
1 #!/bin/sh
a1ad4d1 Build fixes and cleanups:
Sanjay Ghemawat authored
2 #
85584d4 Added bloom filter support.
Sanjay Ghemawat authored
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.
a1ad4d1 Build fixes and cleanups:
Sanjay Ghemawat authored
5 #
85584d4 Added bloom filter support.
Sanjay Ghemawat authored
6 # The output will set the following variables:
075a35a Remove static initializer; fix endian-ness detection; fix build on
Sanjay Ghemawat authored
7 # CC C Compiler path
8 # CXX C++ Compiler path
a1ad4d1 Build fixes and cleanups:
Sanjay Ghemawat authored
9 # PLATFORM_LDFLAGS Linker flags
4076865 Small fixes.
Sanjay Ghemawat authored
10 # PLATFORM_LIBS Libraries flags
bc1ee4d build shared libraries; updated version to 1.3; add Status accessors
Sanjay Ghemawat authored
11 # PLATFORM_SHARED_EXT Extension for shared libraries
12 # PLATFORM_SHARED_LDFLAGS Flags for building shared library
4076865 Small fixes.
Sanjay Ghemawat authored
13 # This flag is embedded just before the name
14 # of the shared library without intervening spaces
bc1ee4d build shared libraries; updated version to 1.3; add Status accessors
Sanjay Ghemawat authored
15 # PLATFORM_SHARED_CFLAGS Flags for compiling objects for shared library
a1ad4d1 Build fixes and cleanups:
Sanjay Ghemawat authored
16 # PLATFORM_CCFLAGS C compiler flags
17 # PLATFORM_CXXFLAGS C++ compiler flags. Will contain:
075a35a Remove static initializer; fix endian-ness detection; fix build on
Sanjay Ghemawat authored
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 #
803d692 @cmumford Release 1.18
cmumford authored
23 # -DLEVELDB_ATOMIC_PRESENT if <atomic> is present
075a35a Remove static initializer; fix endian-ness detection; fix build on
Sanjay Ghemawat authored
24 # -DLEVELDB_PLATFORM_POSIX for Posix-based platforms
25 # -DSNAPPY if the Snappy library is present
26 #
a1ad4d1 Build fixes and cleanups:
Sanjay Ghemawat authored
27
85584d4 Added bloom filter support.
Sanjay Ghemawat authored
28 OUTPUT=$1
946e5b5 Update to leveldb 1.6
David Grogan authored
29 PREFIX=$2
30 if test -z "$OUTPUT" || test -z "$PREFIX"; then
31 echo "usage: $0 <output-filename> <directory_prefix>" >&2
85584d4 Added bloom filter support.
Sanjay Ghemawat authored
32 exit 1
33 fi
f57e233 Platform detection during build, plus compatibility patches for machi…
gabor@google.com authored
34
85584d4 Added bloom filter support.
Sanjay Ghemawat authored
35 # Delete existing output, if it exists
36 rm -f $OUTPUT
37 touch $OUTPUT
f57e233 Platform detection during build, plus compatibility patches for machi…
gabor@google.com authored
38
075a35a Remove static initializer; fix endian-ness detection; fix build on
Sanjay Ghemawat authored
39 if test -z "$CC"; then
40 CC=cc
41 fi
42
c8c5866 Makefile fixes for systems with $CXX other than g++.
Hans Wennborg authored
43 if test -z "$CXX"; then
44 CXX=g++
45 fi
46
28dad91 Release leveldb 1.10
David Grogan authored
47 if test -z "$TMPDIR"; then
48 TMPDIR=/tmp
49 fi
50
f57e233 Platform detection during build, plus compatibility patches for machi…
gabor@google.com authored
51 # Detect OS
a1ad4d1 Build fixes and cleanups:
Sanjay Ghemawat authored
52 if test -z "$TARGET_OS"; then
53 TARGET_OS=`uname -s`
54 fi
55
56 COMMON_FLAGS=
075a35a Remove static initializer; fix endian-ness detection; fix build on
Sanjay Ghemawat authored
57 CROSS_COMPILE=
a1ad4d1 Build fixes and cleanups:
Sanjay Ghemawat authored
58 PLATFORM_CCFLAGS=
59 PLATFORM_CXXFLAGS=
60 PLATFORM_LDFLAGS=
4076865 Small fixes.
Sanjay Ghemawat authored
61 PLATFORM_LIBS=
bc1ee4d build shared libraries; updated version to 1.3; add Status accessors
Sanjay Ghemawat authored
62 PLATFORM_SHARED_EXT="so"
63 PLATFORM_SHARED_LDFLAGS="-shared -Wl,-soname -Wl,"
64 PLATFORM_SHARED_CFLAGS="-fPIC"
075a35a Remove static initializer; fix endian-ness detection; fix build on
Sanjay Ghemawat authored
65 PLATFORM_SHARED_VERSIONED=true
a1ad4d1 Build fixes and cleanups:
Sanjay Ghemawat authored
66
946e5b5 Update to leveldb 1.6
David Grogan authored
67 MEMCMP_FLAG=
68 if [ "$CXX" = "g++" ]; then
69 # Use libc's memcmp instead of GCC's memcmp. This results in ~40%
70 # performance improvement on readrandom under gcc 4.4.3 on Linux/x86.
71 MEMCMP_FLAG="-fno-builtin-memcmp"
72 fi
73
a1ad4d1 Build fixes and cleanups:
Sanjay Ghemawat authored
74 case "$TARGET_OS" in
803d692 @cmumford Release 1.18
cmumford authored
75 CYGWIN_*)
76 PLATFORM=OS_LINUX
77 COMMON_FLAGS="$MEMCMP_FLAG -lpthread -DOS_LINUX -DCYGWIN"
78 PLATFORM_LDFLAGS="-lpthread"
79 PORT_FILE=port/port_posix.cc
80 ;;
f57e233 Platform detection during build, plus compatibility patches for machi…
gabor@google.com authored
81 Darwin)
82 PLATFORM=OS_MACOSX
946e5b5 Update to leveldb 1.6
David Grogan authored
83 COMMON_FLAGS="$MEMCMP_FLAG -DOS_MACOSX"
bc1ee4d build shared libraries; updated version to 1.3; add Status accessors
Sanjay Ghemawat authored
84 PLATFORM_SHARED_EXT=dylib
4076865 Small fixes.
Sanjay Ghemawat authored
85 [ -z "$INSTALL_PATH" ] && INSTALL_PATH=`pwd`
86 PLATFORM_SHARED_LDFLAGS="-dynamiclib -install_name $INSTALL_PATH/"
a1ad4d1 Build fixes and cleanups:
Sanjay Ghemawat authored
87 PORT_FILE=port/port_posix.cc
f57e233 Platform detection during build, plus compatibility patches for machi…
gabor@google.com authored
88 ;;
89 Linux)
90 PLATFORM=OS_LINUX
946e5b5 Update to leveldb 1.6
David Grogan authored
91 COMMON_FLAGS="$MEMCMP_FLAG -pthread -DOS_LINUX"
a1ad4d1 Build fixes and cleanups:
Sanjay Ghemawat authored
92 PLATFORM_LDFLAGS="-pthread"
93 PORT_FILE=port/port_posix.cc
f57e233 Platform detection during build, plus compatibility patches for machi…
gabor@google.com authored
94 ;;
95 SunOS)
96 PLATFORM=OS_SOLARIS
946e5b5 Update to leveldb 1.6
David Grogan authored
97 COMMON_FLAGS="$MEMCMP_FLAG -D_REENTRANT -DOS_SOLARIS"
4076865 Small fixes.
Sanjay Ghemawat authored
98 PLATFORM_LIBS="-lpthread -lrt"
a1ad4d1 Build fixes and cleanups:
Sanjay Ghemawat authored
99 PORT_FILE=port/port_posix.cc
f57e233 Platform detection during build, plus compatibility patches for machi…
gabor@google.com authored
100 ;;
f122c6d Adding FreeBSD support, removing Chromium files, adding benchmark.
gabor@google.com authored
101 FreeBSD)
102 PLATFORM=OS_FREEBSD
946e5b5 Update to leveldb 1.6
David Grogan authored
103 COMMON_FLAGS="$MEMCMP_FLAG -D_REENTRANT -DOS_FREEBSD"
4076865 Small fixes.
Sanjay Ghemawat authored
104 PLATFORM_LIBS="-lpthread"
a1ad4d1 Build fixes and cleanups:
Sanjay Ghemawat authored
105 PORT_FILE=port/port_posix.cc
f122c6d Adding FreeBSD support, removing Chromium files, adding benchmark.
gabor@google.com authored
106 ;;
015d26f add .gitignore; support for building on a few BSD variants
Sanjay Ghemawat authored
107 NetBSD)
108 PLATFORM=OS_NETBSD
946e5b5 Update to leveldb 1.6
David Grogan authored
109 COMMON_FLAGS="$MEMCMP_FLAG -D_REENTRANT -DOS_NETBSD"
4076865 Small fixes.
Sanjay Ghemawat authored
110 PLATFORM_LIBS="-lpthread -lgcc_s"
a1ad4d1 Build fixes and cleanups:
Sanjay Ghemawat authored
111 PORT_FILE=port/port_posix.cc
015d26f add .gitignore; support for building on a few BSD variants
Sanjay Ghemawat authored
112 ;;
113 OpenBSD)
114 PLATFORM=OS_OPENBSD
946e5b5 Update to leveldb 1.6
David Grogan authored
115 COMMON_FLAGS="$MEMCMP_FLAG -D_REENTRANT -DOS_OPENBSD"
a1ad4d1 Build fixes and cleanups:
Sanjay Ghemawat authored
116 PLATFORM_LDFLAGS="-pthread"
117 PORT_FILE=port/port_posix.cc
015d26f add .gitignore; support for building on a few BSD variants
Sanjay Ghemawat authored
118 ;;
119 DragonFly)
120 PLATFORM=OS_DRAGONFLYBSD
946e5b5 Update to leveldb 1.6
David Grogan authored
121 COMMON_FLAGS="$MEMCMP_FLAG -D_REENTRANT -DOS_DRAGONFLYBSD"
4076865 Small fixes.
Sanjay Ghemawat authored
122 PLATFORM_LIBS="-lpthread"
a1ad4d1 Build fixes and cleanups:
Sanjay Ghemawat authored
123 PORT_FILE=port/port_posix.cc
124 ;;
125 OS_ANDROID_CROSSCOMPILE)
075a35a Remove static initializer; fix endian-ness detection; fix build on
Sanjay Ghemawat authored
126 PLATFORM=OS_ANDROID
946e5b5 Update to leveldb 1.6
David Grogan authored
127 COMMON_FLAGS="$MEMCMP_FLAG -D_REENTRANT -DOS_ANDROID -DLEVELDB_PLATFORM_POSIX"
075a35a Remove static initializer; fix endian-ness detection; fix build on
Sanjay Ghemawat authored
128 PLATFORM_LDFLAGS="" # All pthread features are in the Android C library
129 PORT_FILE=port/port_posix.cc
130 CROSS_COMPILE=true
015d26f add .gitignore; support for building on a few BSD variants
Sanjay Ghemawat authored
131 ;;
946e5b5 Update to leveldb 1.6
David Grogan authored
132 HP-UX)
133 PLATFORM=OS_HPUX
134 COMMON_FLAGS="$MEMCMP_FLAG -D_REENTRANT -DOS_HPUX"
135 PLATFORM_LDFLAGS="-pthread"
136 PORT_FILE=port/port_posix.cc
137 # man ld: +h internal_name
138 PLATFORM_SHARED_LDFLAGS="-shared -Wl,+h -Wl,"
139 ;;
0cfb990 Release LevelDB 1.15
David Grogan authored
140 IOS)
141 PLATFORM=IOS
142 COMMON_FLAGS="$MEMCMP_FLAG -DOS_MACOSX"
143 [ -z "$INSTALL_PATH" ] && INSTALL_PATH=`pwd`
144 PORT_FILE=port/port_posix.cc
145 PLATFORM_SHARED_EXT=
146 PLATFORM_SHARED_LDFLAGS=
147 PLATFORM_SHARED_CFLAGS=
148 PLATFORM_SHARED_VERSIONED=
149 ;;
f57e233 Platform detection during build, plus compatibility patches for machi…
gabor@google.com authored
150 *)
075a35a Remove static initializer; fix endian-ness detection; fix build on
Sanjay Ghemawat authored
151 echo "Unknown platform!" >&2
f57e233 Platform detection during build, plus compatibility patches for machi…
gabor@google.com authored
152 exit 1
153 esac
154
a1ad4d1 Build fixes and cleanups:
Sanjay Ghemawat authored
155 # We want to make a list of all cc files within util, db, table, and helpers
156 # except for the test and benchmark files. By default, find will output a list
157 # of all files matching either rule, so we need to append -print to make the
158 # prune take effect.
946e5b5 Update to leveldb 1.6
David Grogan authored
159 DIRS="$PREFIX/db $PREFIX/util $PREFIX/table"
160
a1ad4d1 Build fixes and cleanups:
Sanjay Ghemawat authored
161 set -f # temporarily disable globbing so that our patterns aren't expanded
162 PRUNE_TEST="-name *test*.cc -prune"
163 PRUNE_BENCH="-name *_bench.cc -prune"
adbe3eb @cmumford Putting build artifacts in subdirectory.
cmumford authored
164 PRUNE_TOOL="-name leveldbutil.cc -prune"
ea2e919 added utility to dump leveldb files
Sanjay Ghemawat authored
165 PORTABLE_FILES=`find $DIRS $PRUNE_TEST -o $PRUNE_BENCH -o $PRUNE_TOOL -o -name '*.cc' -print | sort | sed "s,^$PREFIX/,," | tr "\n" " "`
946e5b5 Update to leveldb 1.6
David Grogan authored
166
a1ad4d1 Build fixes and cleanups:
Sanjay Ghemawat authored
167 set +f # re-enable globbing
f57e233 Platform detection during build, plus compatibility patches for machi…
gabor@google.com authored
168
a1ad4d1 Build fixes and cleanups:
Sanjay Ghemawat authored
169 # The sources consist of the portable files, plus the platform-specific port
170 # file.
85584d4 Added bloom filter support.
Sanjay Ghemawat authored
171 echo "SOURCES=$PORTABLE_FILES $PORT_FILE" >> $OUTPUT
172 echo "MEMENV_SOURCES=helpers/memenv/memenv.cc" >> $OUTPUT
f57e233 Platform detection during build, plus compatibility patches for machi…
gabor@google.com authored
173
075a35a Remove static initializer; fix endian-ness detection; fix build on
Sanjay Ghemawat authored
174 if [ "$CROSS_COMPILE" = "true" ]; then
a1ad4d1 Build fixes and cleanups:
Sanjay Ghemawat authored
175 # Cross-compiling; do not try any compilation tests.
176 true
f57e233 Platform detection during build, plus compatibility patches for machi…
gabor@google.com authored
177 else
28dad91 Release leveldb 1.10
David Grogan authored
178 CXXOUTPUT="${TMPDIR}/leveldb_build_detect_platform-cxx.$$"
179
803d692 @cmumford Release 1.18
cmumford authored
180 # If -std=c++0x works, use <atomic> as fallback for when memory barriers
181 # are not available.
28dad91 Release leveldb 1.10
David Grogan authored
182 $CXX $CXXFLAGS -std=c++0x -x c++ - -o $CXXOUTPUT 2>/dev/null <<EOF
803d692 @cmumford Release 1.18
cmumford authored
183 #include <atomic>
a1ad4d1 Build fixes and cleanups:
Sanjay Ghemawat authored
184 int main() {}
185 EOF
186 if [ "$?" = 0 ]; then
803d692 @cmumford Release 1.18
cmumford authored
187 COMMON_FLAGS="$COMMON_FLAGS -DLEVELDB_PLATFORM_POSIX -DLEVELDB_ATOMIC_PRESENT"
a1ad4d1 Build fixes and cleanups:
Sanjay Ghemawat authored
188 PLATFORM_CXXFLAGS="-std=c++0x"
189 else
190 COMMON_FLAGS="$COMMON_FLAGS -DLEVELDB_PLATFORM_POSIX"
191 fi
f57e233 Platform detection during build, plus compatibility patches for machi…
gabor@google.com authored
192
a1ad4d1 Build fixes and cleanups:
Sanjay Ghemawat authored
193 # Test whether Snappy library is installed
194 # http://code.google.com/p/snappy/
28dad91 Release leveldb 1.10
David Grogan authored
195 $CXX $CXXFLAGS -x c++ - -o $CXXOUTPUT 2>/dev/null <<EOF
a1ad4d1 Build fixes and cleanups:
Sanjay Ghemawat authored
196 #include <snappy.h>
197 int main() {}
f57e233 Platform detection during build, plus compatibility patches for machi…
gabor@google.com authored
198 EOF
a1ad4d1 Build fixes and cleanups:
Sanjay Ghemawat authored
199 if [ "$?" = 0 ]; then
200 COMMON_FLAGS="$COMMON_FLAGS -DSNAPPY"
4076865 Small fixes.
Sanjay Ghemawat authored
201 PLATFORM_LIBS="$PLATFORM_LIBS -lsnappy"
a1ad4d1 Build fixes and cleanups:
Sanjay Ghemawat authored
202 fi
203
204 # Test whether tcmalloc is available
28dad91 Release leveldb 1.10
David Grogan authored
205 $CXX $CXXFLAGS -x c++ - -o $CXXOUTPUT -ltcmalloc 2>/dev/null <<EOF
a1ad4d1 Build fixes and cleanups:
Sanjay Ghemawat authored
206 int main() {}
207 EOF
208 if [ "$?" = 0 ]; then
4076865 Small fixes.
Sanjay Ghemawat authored
209 PLATFORM_LIBS="$PLATFORM_LIBS -ltcmalloc"
a1ad4d1 Build fixes and cleanups:
Sanjay Ghemawat authored
210 fi
28dad91 Release leveldb 1.10
David Grogan authored
211
212 rm -f $CXXOUTPUT 2>/dev/null
f57e233 Platform detection during build, plus compatibility patches for machi…
gabor@google.com authored
213 fi
214
a1ad4d1 Build fixes and cleanups:
Sanjay Ghemawat authored
215 PLATFORM_CCFLAGS="$PLATFORM_CCFLAGS $COMMON_FLAGS"
216 PLATFORM_CXXFLAGS="$PLATFORM_CXXFLAGS $COMMON_FLAGS"
217
075a35a Remove static initializer; fix endian-ness detection; fix build on
Sanjay Ghemawat authored
218 echo "CC=$CC" >> $OUTPUT
219 echo "CXX=$CXX" >> $OUTPUT
85584d4 Added bloom filter support.
Sanjay Ghemawat authored
220 echo "PLATFORM=$PLATFORM" >> $OUTPUT
221 echo "PLATFORM_LDFLAGS=$PLATFORM_LDFLAGS" >> $OUTPUT
4076865 Small fixes.
Sanjay Ghemawat authored
222 echo "PLATFORM_LIBS=$PLATFORM_LIBS" >> $OUTPUT
85584d4 Added bloom filter support.
Sanjay Ghemawat authored
223 echo "PLATFORM_CCFLAGS=$PLATFORM_CCFLAGS" >> $OUTPUT
224 echo "PLATFORM_CXXFLAGS=$PLATFORM_CXXFLAGS" >> $OUTPUT
225 echo "PLATFORM_SHARED_CFLAGS=$PLATFORM_SHARED_CFLAGS" >> $OUTPUT
226 echo "PLATFORM_SHARED_EXT=$PLATFORM_SHARED_EXT" >> $OUTPUT
227 echo "PLATFORM_SHARED_LDFLAGS=$PLATFORM_SHARED_LDFLAGS" >> $OUTPUT
075a35a Remove static initializer; fix endian-ness detection; fix build on
Sanjay Ghemawat authored
228 echo "PLATFORM_SHARED_VERSIONED=$PLATFORM_SHARED_VERSIONED" >> $OUTPUT
Something went wrong with that request. Please try again.