-
Notifications
You must be signed in to change notification settings - Fork 87
/
make.sh
executable file
·328 lines (294 loc) · 8.22 KB
/
make.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
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
ENABLE_STATIC_LIB=0
ENABLE_SHARED_LIB=1
TARGET_PREFIX=$DESTDIR/usr
TARGET_CONF_PATH=$DESTDIR/etc/fdir
module=''
exclude=''
jni_file=''
start=1
for arg do
case "$arg" in
--module=*)
module=${arg#--module=}
start=$(expr $start + 1)
;;
--exclude=*)
exclude=${arg#--exclude=}
start=$(expr $start + 1)
;;
--jni=*)
jni_file=${arg#--jni=}
start=$(expr $start + 1)
;;
esac
done
index=$start
eval param1="\$$index"
index=$(expr $index + 1)
eval param2="\$$index"
DEBUG_FLAG=0
PRELOAD_WITH_CAPI=1
arch=$(uname -r | awk -F '.' '{print $NF;}')
if [ "$arch" = "x86_64" ]; then
PRELOAD_WITH_PAPI=1
else
PRELOAD_WITH_PAPI=0
fi
export CC=gcc
CFLAGS='-Wall'
GCC_VERSION=$(gcc -dM -E - < /dev/null | grep -w __GNUC__ | awk '{print $NF;}')
if [ -n "$GCC_VERSION" ] && [ $GCC_VERSION -ge 7 ]; then
CFLAGS="$CFLAGS -Wformat-truncation=0 -Wformat-overflow=0"
fi
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE"
if [ "$PRELOAD_WITH_CAPI" = "1" ]; then
CFLAGS="$CFLAGS -DFCFS_PRELOAD_WITH_CAPI"
fi
if [ "$PRELOAD_WITH_PAPI" = "1" ]; then
CFLAGS="$CFLAGS -DFCFS_PRELOAD_WITH_PAPI"
fi
if [ "$DEBUG_FLAG" = "1" ]; then
CFLAGS="$CFLAGS -g -DDEBUG_FLAG"
else
CFLAGS="$CFLAGS -g -O3"
fi
if [ -f /usr/include/fastcommon/_os_define.h ]; then
OS_BITS=$(grep -F OS_BITS /usr/include/fastcommon/_os_define.h | awk '{print $NF;}')
elif [ -f /usr/local/include/fastcommon/_os_define.h ]; then
OS_BITS=$(grep -F OS_BITS /usr/local/include/fastcommon/_os_define.h | awk '{print $NF;}')
else
OS_BITS=64
fi
uname=$(uname)
LIB_VERSION=
if [ "$OS_BITS" -eq 64 ]; then
if [ $uname = 'Linux' ]; then
osname=$(cat /etc/os-release | grep -w NAME | awk -F '=' '{print $2;}' | \
awk -F '"' '{if (NF==3) {print $2} else {print $1}}' | awk '{print $1}')
if [ $osname = 'Ubuntu' -o $osname = 'Debian' ]; then
LIB_VERSION=lib
else
LIB_VERSION=lib64
fi
else
LIB_VERSION=lib
fi
else
LIB_VERSION=lib
fi
LIBS=''
if [ "$uname" = "Linux" ]; then
if [ "$OS_BITS" -eq 64 ]; then
LIBS="$LIBS -L/usr/lib64"
else
LIBS="$LIBS -L/usr/lib"
fi
CFLAGS="$CFLAGS"
elif [ "$uname" = "FreeBSD" ] || [ "$uname" = "Darwin" ]; then
LIBS="$LIBS -L/usr/lib"
CFLAGS="$CFLAGS"
if [ "$uname" = "Darwin" ]; then
CFLAGS="$CFLAGS -DDARWIN"
TARGET_PREFIX=$TARGET_PREFIX/local
fi
elif [ "$uname" = "SunOS" ]; then
LIBS="$LIBS -L/usr/lib"
CFLAGS="$CFLAGS -D_THREAD_SAFE"
LIBS="$LIBS -lsocket -lnsl -lresolv"
elif [ "$uname" = "AIX" ]; then
LIBS="$LIBS -L/usr/lib"
CFLAGS="$CFLAGS -D_THREAD_SAFE"
elif [ "$uname" = "HP-UX" ]; then
LIBS="$LIBS -L/usr/lib"
CFLAGS="$CFLAGS"
fi
have_pthread=0
if [ -f /usr/lib/libpthread.so ] || [ -f /usr/local/lib/libpthread.so ] || [ -f /lib64/libpthread.so ] || [ -f /usr/lib64/libpthread.so ] || [ -f /usr/lib/libpthread.a ] || [ -f /usr/local/lib/libpthread.a ] || [ -f /lib64/libpthread.a ] || [ -f /usr/lib64/libpthread.a ]; then
LIBS="$LIBS -lpthread"
have_pthread=1
elif [ "$uname" = "HP-UX" ]; then
lib_path="/usr/lib/hpux$OS_BITS"
if [ -f $lib_path/libpthread.so ]; then
LIBS="-L$lib_path -lpthread"
have_pthread=1
fi
elif [ "$uname" = "FreeBSD" ]; then
if [ -f /usr/lib/libc_r.so ]; then
line=$(nm -D /usr/lib/libc_r.so | grep -F pthread_create | grep -w T)
if [ $? -eq 0 ]; then
LIBS="$LIBS -lc_r"
have_pthread=1
fi
elif [ -f /lib64/libc_r.so ]; then
line=$(nm -D /lib64/libc_r.so | grep -F pthread_create | grep -w T)
if [ $? -eq 0 ]; then
LIBS="$LIBS -lc_r"
have_pthread=1
fi
elif [ -f /usr/lib64/libc_r.so ]; then
line=$(nm -D /usr/lib64/libc_r.so | grep -F pthread_create | grep -w T)
if [ $? -eq 0 ]; then
LIBS="$LIBS -lc_r"
have_pthread=1
fi
fi
fi
if [ $have_pthread -eq 0 ] && [ "$uname" != "Darwin" ]; then
/sbin/ldconfig -p | grep -F libpthread.so > /dev/null
if [ $? -eq 0 ]; then
LIBS="$LIBS -lpthread"
else
echo -E 'Require pthread lib, please check!'
exit 2
fi
fi
sed_replace()
{
sed_cmd=$1
filename=$2
if [ "$uname" = "FreeBSD" ] || [ "$uname" = "Darwin" ]; then
sed -i "" "$sed_cmd" $filename
else
sed -i "$sed_cmd" $filename
fi
}
replace_makefile()
{
cp Makefile.in Makefile
sed_replace "s#\\\$(CFLAGS)#$CFLAGS#g" Makefile
sed_replace "s#\\\$(LIBS)#$LIBS#g" Makefile
sed_replace "s#\\\$(TARGET_PREFIX)#$TARGET_PREFIX#g" Makefile
sed_replace "s#\\\$(LIB_VERSION)#$LIB_VERSION#g" Makefile
sed_replace "s#\\\$(TARGET_CONF_PATH)#$TARGET_CONF_PATH#g" Makefile
sed_replace "s#\\\$(ENABLE_STATIC_LIB)#$ENABLE_STATIC_LIB#g" Makefile
sed_replace "s#\\\$(ENABLE_SHARED_LIB)#$ENABLE_SHARED_LIB#g" Makefile
}
base_path=$(pwd)
cd src/include/fastcfs/
for subdir in api vote; do
link=$(readlink $subdir)
if [ $? -ne 0 ] || [ "$link" != "../../$subdir" -a "$link" != "../../$subdir/" ]; then
ln -sf ../../$subdir $subdir
fi
done
cd $base_path
if [ -z $module ] || [ "$module" = 'auth_server' -o "$module" = 'authserver' ]; then
if [ "x$exclude" != 'xauth_server' -a "x$exclude" != 'xauthserver' ]; then
cd $base_path/src/auth/server
replace_makefile
make $param1 $param2
fi
fi
if [ -z $module ] || [ "$module" = 'auth_client' -o "$module" = 'authclient' ]; then
if [ "x$exclude" != 'xauth_client' -a "x$exclude" != 'xauthclient' ] && [ "x$exclude" != 'xclient' ]; then
cd $base_path/src/auth/client
replace_makefile
make $param1 $param2
cd $base_path/src/auth/client/tools
replace_makefile
make $param1 $param2
fi
fi
if [ -z $module ] || [ "$module" = 'vote_server' -o "$module" = 'voteserver' ]; then
if [ "x$exclude" != 'xvote_server' -a "x$exclude" != 'xvoteserver' ]; then
cd $base_path/src/vote/server
replace_makefile
make $param1 $param2
fi
fi
if [ -z $module ] || [ "$module" = 'vote_client' -o "$module" = 'voteclient' ]; then
if [ "x$exclude" != 'xvote_client' -a "x$exclude" != 'xvoteclient' ] && [ "x$exclude" != 'xclient' ]; then
cd $base_path/src/vote/client
replace_makefile
make $param1 $param2
cd $base_path/src/vote/client/tools
replace_makefile
make $param1 $param2
fi
fi
if [ -z $module ] || [ "$module" = 'api' ] || [ "$module" = 'fuseclient' -o "$module" = 'fuse_client' ]; then
if [ "x$exclude" != 'xapi' ]; then
cd $base_path/src/api
replace_makefile
make $param1 $param2
cd tests || exit
replace_makefile
make $param1 $param2
fi
fi
if [ "$uname" = "Linux" ]; then
if [ -z $module ] || [ "$module" = 'preload' ]; then
if [ "x$exclude" != 'xpreload' ]; then
cd $base_path/src/preload
replace_makefile
make $param1 $param2
fi
fi
fi
if [ -z $module ] || [ "$module" = 'tools' ]; then
if [ "x$exclude" != 'xtools' ]; then
cd $base_path/src/tools
replace_makefile
make $param1 $param2
fi
fi
if [ "$uname" = "Linux" ]; then
if [ -z $module ] || [ "$module" = 'fuse_client' -o "$module" = 'fuseclient' ]; then
if [ "x$exclude" != 'xfuse_client' -a "x$exclude" != 'xfuseclient' ]; then
cd $base_path/src/fuse
replace_makefile
make $param1 $param2
fi
fi
fi
if [ "$module" = 'jni' ]; then
if [ ! -z $JAVA_HOME ]; then
path=$JAVA_HOME
elif [ ! -z $jni_file ]; then
if [ -d $jni_file ]; then
path=$jni_file
else
path=$(dirname $jni_file)
fi
else
if [ -d /Library ]; then
path=/Library
else
path=/usr/lib
fi
fi
files=$(find $path -name jni.h 2>/dev/null | grep '/include/jni.h$')
if [ -z "$files" ]; then
files=$(locate jni.h | grep '/include/jni.h$')
if [ -z "$files" ]; then
echo "can't locate jni.h, please install java SDK first."
exit 2
fi
fi
count=$(echo "$files" | wc -l)
if [ $count -eq 1 ]; then
filename=$files
else
i=0
for file in $files; do
i=$(expr $i + 1)
echo "$i. $file"
done
printf "please input the correct file no.: "
read n
if [ -z "$n" ]; then
echo "invalid file no."
exit 2
fi
filename=$(echo "$files" | head -n $n | tail -n 1)
fi
INCLUDES=
path=$(dirname $filename)
for d in $(find $path -type d); do
INCLUDES="$INCLUDES -I$d"
done
cd $base_path/src/java/jni
replace_makefile
sed_replace "s#\\\$(INCLUDES)#$INCLUDES#g" Makefile
make $param1 $param2
fi