-
-
Notifications
You must be signed in to change notification settings - Fork 222
/
configure
executable file
·278 lines (251 loc) · 6.53 KB
/
configure
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#!/bin/bash
#
# Guess values for system-dependent variables and create Makefiles.
#
# usage message
usage()
{
cat <<_EOF
Usage: $0 [OPTION]... [VAR=VALUE]...
Configuration:
-h, --help display this help and exit
--enable-shared-mongoc link the mongoc shared library
--enable-shared-lz4 link the lz4 shared library
--enable-shared-glog link the glog shared library
--enable-gui-mod compile and link with QtGui module
--enable-debug compile with debugging information
--spec=SPEC use SPEC as QMAKESPEC
Installation directories:
--prefix=PREFIX install files in PREFIX [$PREFIX]
Fine tuning of the installation directories:
--bindir=DIR user executables [$BINDIR]
--libdir=DIR object code libraries [$LIBDIR]
--includedir=DIR C++ header files [$INCLUDEDIR]
--datadir=DIR read-only architecture-independent data [$DATADIR]
_EOF
}
# absorbs the difference of GNU sed and BSD sed
replace()
{
[ ! -f "$2" ] && return
sed -e "$1" "$2" > "$2".$$
mv -f "$2".$$ "$2"
}
# check the platform
if ! which uname >/dev/null 2>&1; then
echo "uname: command not found"
exit
fi
# default values
BASEDIR=`pwd`/`dirname $0`
KERNEL=`uname -s`
MACHINE=`uname -m`
RELEASE=`uname -r`
NPROC=`nproc 2>/dev/null`
if [ "$KERNEL" = "Darwin" ]; then
PREFIX=/usr/local
else
PREFIX=/usr
fi
BINDIR=$PREFIX/bin
LIBDIR=$PREFIX/lib
INCLUDEDIR=$PREFIX/include/treefrog
DATADIR=$PREFIX/share/treefrog
CMAKE=cmake
# parse options
while [ -n "`echo $1 | grep '-'`" ]; do
case $1 in
*=?*) optarg=`expr "X$1" : '[^=]*=\(.*\)'` ;;
*=) optarg= ;;
*) optarg=yes ;;
esac
case $1 in
--prefix=*)
PREFIX=$optarg
BINDIR=$PREFIX/bin
LIBDIR=$PREFIX/lib
INCLUDEDIR=$PREFIX/include/treefrog
DATADIR=$PREFIX/share/treefrog
;;
--bindir=*)
BINDIR=$optarg
;;
--libdir=*)
LIBDIR=$optarg
;;
--includedir=*)
INCLUDEDIR=$optarg
;;
--datadir=*)
DATADIR=$optarg
;;
--enable-debug | --enable-debug=*)
ENABLE_DEBUG=yes
;;
--enable-gui-mod | --enable-gui-mod=*)
ENABLE_GUI="use_gui=1"
;;
--enable-shared-mongoc | --enable-shared-mongoc=*)
ENABLE_SHARED_MONGOC="enable_shared_mongoc=1"
;;
--enable-shared-lz4 | --enable-shared-lz4=*)
ENABLE_SHARED_LZ4="enable_shared_lz4=1"
;;
--enable-shared-glog | --enable-shared-glog=*)
ENABLE_SHARED_GLOG="enable_shared_glog=1"
;;
--spec=*)
SPEC=$optarg
;;
--help | -help | -h | *)
usage
exit
;;
esac
shift
done
# spec
if [ "$SPEC" != "" ]; then
OPT="-spec $SPEC"
elif [ "$QMAKESPEC" != "" ]; then
OPT="-spec $QMAKESPEC"
elif [ "$KERNEL" = "Darwin" ]; then # macOS
OPT="-spec macx-clang"
elif [ "$KERNEL" = "Linux" ]; then
OPT="-spec linux-g++"
elif [ "$KERNEL" = "FreeBSD" ]; then
OPT="-spec freebsd-clang"
fi
# x64 config
if [ "$KERNEL" = "Darwin" ]; then # macOS
REL=`echo $RELEASE | tr -d '.'`
if [ "$REL" -ge 1050 ]; then
OPT="$OPT CONFIG+=x86_64"
fi
if [ "$MACHINE" = "ppc" ]; then
OPT="$OPT CONFIG+=ppc"
fi
else
if [[ "$SPEC" =~ "wasm" ]]; then
OPT=
CMAKE="emcmake cmake"
CC=emcc
AR=emar
elif [ "$MACHINE" = "x86_64" ]; then
OPT="$OPT CONFIG+=x86_64"
fi
fi
cd "$BASEDIR"
replace "s|unix:LIBS +=.*$|unix:LIBS += -Wl,-rpath,. -Wl,-rpath,$LIBDIR -L$LIBDIR -ltreefrog|" defaults/appbase.pri
replace "s|unix:INCLUDEPATH +=.*$|unix:INCLUDEPATH += $INCLUDEDIR|" defaults/appbase.pri
if [ -n "$ENABLE_DEBUG" ]; then
OPT="$OPT CONFIG+=debug"
else
OPT="$OPT CONFIG+=release"
fi
# search qmake command
if [ -z "$QMAKE" ]; then
which qmake-qt5 >/dev/null 2>&1 && QMAKE=qmake-qt5
which qmake >/dev/null 2>&1 && QMAKE=qmake
which qmake6 >/dev/null 2>&1 && QMAKE=qmake6
if [ -z "$QMAKE" ]; then
echo "qmake: command not found"
echo
exit 1
fi
fi
if ! which cmake >/dev/null 2>&1; then
echo "cmake: command not found"
echo
exit 1
fi
if [ -n "$ENABLE_SHARED_MONGOC" ] && ! which pkg-config >/dev/null 2>&1; then
echo "pkg-config: command not found"
echo
exit 1
fi
if [ -n "$ENABLE_SHARED_GLOG" ] && ! which pkg-config >/dev/null 2>&1; then
echo "pkg-config: command not found"
echo
exit 1
fi
# src
cd "$BASEDIR/src"
rm -f .qmake.stash
[ -f Makefile ] && make -k distclean >/dev/null 2>&1
$QMAKE $OPT target.path=\"$LIBDIR\" header.path=\"$INCLUDEDIR\" $ENABLE_GUI $ENABLE_SHARED_MONGOC $ENABLE_SHARED_LZ4
RET=$?
if [ $RET != 0 ]; then
echo "qmake failed"
exit $RET
fi
# tools
cd "$BASEDIR/tools"
rm -f .qmake.stash
[ -f Makefile ] && make -k distclean >/dev/null 2>&1
$QMAKE -recursive $OPT target.path=\"$BINDIR\" header.path=\"$INCLUDEDIR\" datadir=\"$DATADIR\" lib.path=\"$LIBDIR\" $ENABLE_SHARED_GLOG
RET=$?
if [ $RET != 0 ]; then
echo "qmake failed"
exit $RET
fi
# compile MongoDB files
if [ -z "$ENABLE_SHARED_MONGOC" ]; then
echo
echo -n "Compiling MongoDB driver library ... "
cd "$BASEDIR/3rdparty/mongo-driver"
find . -type d | grep CMakeFiles | xargs rm -rf
find . -type f | grep CMakeCache | xargs rm -f
find . -type f | grep Makefile | xargs rm -f
find . -type f | grep cmake_install | xargs rm -f
$CMAKE -S . -DCMAKE_BUILD_TYPE=Release -DENABLE_STATIC=ON -DENABLE_SSL=OFF -DENABLE_SNAPPY=OFF -DENABLE_ZLIB=OFF -DENABLE_ZSTD=OFF -DENABLE_SRV=OFF -DENABLE_SASL=OFF -DENABLE_SHM_COUNTERS=OFF -DENABLE_TESTS=OFF >/dev/null 2>&1
make clean >/dev/null 2>&1
make -j${NPROC} mongoc_static >/dev/null 2>&1
RET=$?
if [ $RET != 0 ]; then
echo "failed"
echo "MongoDB driver not available."
exit $RET
fi
echo "OK"
fi
# compile glog
if ! [[ "$SPEC" =~ "wasm" ]]; then
cd "$BASEDIR/3rdparty/glog"
rm -rf build
if [ -z "$ENABLE_SHARED_GLOG" ]; then
echo
echo -n "Compiling glog ... "
$CMAKE -S . -B build -G "Unix Makefiles" -DBUILD_SHARED_LIBS=OFF -DCMAKE_CXX_STANDARD=14 >/dev/null 2>&1
make -j${NPROC} -C build >/dev/null 2>&1
RET=$?
if [ $RET != 0 ]; then
make -C build
echo "failed"
echo "glog not available."
exit $RET
fi
echo "OK"
fi
fi
# compile LZ4
cd "$BASEDIR/3rdparty/lz4"
make clean >/dev/null 2>&1
if [ -z "$ENABLE_SHARED_LZ4" ]; then
echo
echo -n "Compiling LZ4 ... "
make -j${NPROC} lib >/dev/null 2>&1
RET=$?
if [ $RET != 0 ]; then
make SHELL='bash -x' lib
echo "failed"
echo "LZ4 not available."
exit $RET
fi
echo "OK"
fi
echo
echo "First, run \"make\" and \"sudo make install\" in src directory."
echo "Next, run \"make\" and \"sudo make install\" in tools directory."