forked from ideawu/ssdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·153 lines (136 loc) · 3.34 KB
/
build.sh
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/sh
BASE_DIR=`pwd`
JEMALLOC_PATH="$BASE_DIR/deps/jemalloc-3.3.1"
LEVELDB_PATH="$BASE_DIR/deps/leveldb-1.14.0"
SNAPPY_PATH="$BASE_DIR/deps/snappy-1.1.0"
if test -z "$TARGET_OS"; then
TARGET_OS=`uname -s`
fi
if test -z "$MAKE"; then
MAKE=make
fi
if test -z "$CC"; then
CC=gcc
fi
if test -z "$CXX"; then
CXX=g++
fi
case "$TARGET_OS" in
Darwin)
#PLATFORM_CLIBS="-pthread"
#PLATFORM_CFLAGS=""
;;
Linux)
PLATFORM_CLIBS="-pthread"
;;
OS_ANDROID_CROSSCOMPILE)
PLATFORM_CLIBS="-pthread"
SNAPPY_HOST="--host=i386-linux"
;;
CYGWIN_*)
PLATFORM_CLIBS="-lpthread"
;;
SunOS)
PLATFORM_CLIBS="-lpthread -lrt"
;;
FreeBSD)
PLATFORM_CLIBS="-lpthread"
MAKE=gmake
;;
NetBSD)
PLATFORM_CLIBS="-lpthread -lgcc_s"
;;
OpenBSD)
PLATFORM_CLIBS="-pthread"
;;
DragonFly)
PLATFORM_CLIBS="-lpthread"
;;
HP-UX)
PLATFORM_CLIBS="-pthread"
;;
*)
echo "Unknown platform!" >&2
exit 1
esac
DIR=`pwd`
cd $SNAPPY_PATH
if [ ! -f Makefile ]; then
echo ""
echo "##### building snappy... #####"
./configure $SNAPPY_HOST
# FUCK! snappy compilation doesn't work on some linux!
find . | xargs touch
make
echo "##### building snappy finished #####"
echo ""
fi
cd "$DIR"
case "$TARGET_OS" in
CYGWIN*|FreeBSD|OS_ANDROID_CROSSCOMPILE)
echo "not using jemalloc on $TARGET_OS"
;;
*)
DIR=`pwd`
cd $JEMALLOC_PATH
if [ ! -f Makefile ]; then
echo ""
echo "##### building jemalloc... #####"
./configure
make
echo "##### building jemalloc finished #####"
echo ""
fi
cd "$DIR"
;;
esac
rm -f src/version.h
echo "#ifndef SSDB_DEPS_H" >> src/version.h
echo "#ifndef SSDB_VERSION" >> src/version.h
echo "#define SSDB_VERSION \"`cat version`\"" >> src/version.h
echo "#endif" >> src/version.h
echo "#endif" >> src/version.h
case "$TARGET_OS" in
CYGWIN*|FreeBSD)
;;
OS_ANDROID_CROSSCOMPILE)
echo "#define OS_ANDROID 1" >> src/version.h
;;
*)
echo "#include <stdlib.h>" >> src/version.h
echo "#include <jemalloc/jemalloc.h>" >> src/version.h
;;
esac
rm -f build_config.mk
echo CC=$CC >> build_config.mk
echo CXX=$CXX >> build_config.mk
echo "MAKE=$MAKE" >> build_config.mk
echo "LEVELDB_PATH=$LEVELDB_PATH" >> build_config.mk
echo "JEMALLOC_PATH=$JEMALLOC_PATH" >> build_config.mk
echo "SNAPPY_PATH=$SNAPPY_PATH" >> build_config.mk
echo "CFLAGS=" >> build_config.mk
echo "CFLAGS = -DNDEBUG -D__STDC_FORMAT_MACROS -Wall -O2 -Wno-sign-compare" >> build_config.mk
echo "CFLAGS += ${PLATFORM_CFLAGS}" >> build_config.mk
echo "CFLAGS += -I \"$LEVELDB_PATH/include\"" >> build_config.mk
echo "CLIBS=" >> build_config.mk
echo "CLIBS += ${PLATFORM_CLIBS}" >> build_config.mk
echo "CLIBS += \"$LEVELDB_PATH/libleveldb.a\"" >> build_config.mk
echo "CLIBS += \"$SNAPPY_PATH/.libs/libsnappy.a\"" >> build_config.mk
case "$TARGET_OS" in
CYGWIN*|FreeBSD|OS_ANDROID_CROSSCOMPILE)
;;
*)
echo "CLIBS += \"$JEMALLOC_PATH/lib/libjemalloc.a\"" >> build_config.mk
echo "CFLAGS += -I \"$JEMALLOC_PATH/include\"" >> build_config.mk
;;
esac
if test -z "$TMPDIR"; then
TMPDIR=/tmp
fi
g++ -x c++ - -o $TMPDIR/ssdb_build_test.$$ 2>/dev/null <<EOF
#include <unordered_map>
int main() {}
EOF
if [ "$?" = 0 ]; then
echo "CFLAGS += -DNEW_MAC" >> build_config.mk
fi