-
Notifications
You must be signed in to change notification settings - Fork 8
/
build_detect_platform
78 lines (68 loc) · 2.28 KB
/
build_detect_platform
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/sh
# Detects OS we're compiling on and generates build_config.mk,
# which in turn gets read while processing Makefile.
# build_config.mk will set the following variables:
# - PORT_CFLAGS will either set:
# -DLEVELDB_PLATFORM_POSIX if cstatomic is present
# -DLEVELDB_PLATFORM_NOATOMIC if it is not
# - PLATFORM_CFLAGS with compiler flags for the platform
# - PLATFORM_LDFLAGS with linker flags for the platform
# Delete existing build_config.mk
rm -f build_config.mk
if test -z "$CXX"; then
CXX=g++
fi
# Detect OS
case `uname -s` in
Darwin)
PLATFORM=OS_MACOSX
echo "PLATFORM_CFLAGS=-DOS_MACOSX" >> build_config.mk
echo "PLATFORM_LDFLAGS=" >> build_config.mk
;;
Linux)
PLATFORM=OS_LINUX
echo "PLATFORM_CFLAGS=-pthread -DOS_LINUX" >> build_config.mk
echo "PLATFORM_LDFLAGS=-pthread" >> build_config.mk
;;
SunOS)
PLATFORM=OS_SOLARIS
echo "PLATFORM_CFLAGS=-D_REENTRANT -DOS_SOLARIS" >> build_config.mk
echo "PLATFORM_LDFLAGS=-lpthread -lrt" >> build_config.mk
;;
FreeBSD)
PLATFORM=OS_FREEBSD
echo "PLATFORM_CFLAGS=-D_REENTRANT -DOS_FREEBSD" >> build_config.mk
echo "PLATFORM_LDFLAGS=-lpthread" >> build_config.mk
;;
*)
echo "Unknown platform!"
exit 1
esac
echo "PLATFORM=$PLATFORM" >> build_config.mk
# On GCC, use libc's memcmp, not GCC's memcmp
PORT_CFLAGS="-fno-builtin-memcmp"
# Detect C++0x -- this determines whether we'll use port_noatomic.h
# or port_posix.h by:
# 1. Rrying to compile with -std=c++0x and including <cstdatomic>.
# 2. If $CXX returns error code, we know to use port_posix.h
$CXX $CFLAGS -std=c++0x -x c++ - -o /dev/null 2>/dev/null <<EOF
#include <cstdatomic>
int main() {}
EOF
if [ "$?" = 0 ]; then
PORT_CFLAGS="$PORT_CFLAGS -DLEVELDB_PLATFORM_POSIX -DLEVELDB_CSTDATOMIC_PRESENT -std=c++0x"
else
PORT_CFLAGS="$PORT_CFLAGS -DLEVELDB_PLATFORM_POSIX"
fi
# Test whether Snappy library is installed
# http://code.google.com/p/snappy/
$CXX $CFLAGS -x c++ - -o /dev/null 2>/dev/null <<EOF
#include <snappy.h>
int main() {}
EOF
if [ "$?" = 0 ]; then
echo "SNAPPY=1" >> build_config.mk
else
echo "SNAPPY=0" >> build_config.mk
fi
echo "PORT_CFLAGS=$PORT_CFLAGS" >> build_config.mk