forked from xubingyue/Humble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mk.sh
247 lines (207 loc) · 5.12 KB
/
mk.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
#!/bin/sh
#***********************************************
# File Name : mk
# Description: make file
# Make By :lqf/[email protected]
# Date Time :2011/06/15
#***********************************************
UsAge="UsAge:\"./mk.sh\" or \"./mk.sh x64\" or \"./mk.sh clean\""
X64=$1
OSNAME=`uname`
#############################################
#业务处理文件路径
LIBDIR=""
#生成程序的名称
PROGRAMNAME="Humble"
#############################################
#Humble文件夹
HumbleDir="HBase HBase/event2 HBase/rijndael HBase/RSAEuro HBase/uchardet HBase/uchardet/LangModels HBase/zlib HBase/redisrand"
HumbleDir=$HumbleDir" HBase/lpeg HBase/lua5.3 HBase/luabridge HBase/luacjson HBase/mysql HBase/luasql HBase/pbc HBase/luaserialize HBase/luasocket HBase/lsnapshot"
HumbleDir=$HumbleDir" Humble"
#main函数所在文件夹
MAINDIR="Humble"
#main函数所在文件
MAINFILE="Humble.cpp"
#结果存放路径
RSTPATH="Bin"
if [ "$X64" = "x64" ]
then
RSTPATH="BinX64"
fi
#附加包含库
INCLUDELIB="-lrt -ldl -lpthread"
INCLUDELIB=$INCLUDELIB" -levent_core -levent_extra -levent_pthreads -lmysqlclient"
#中间库文件名
LIBNAME="HumbleLib"
#不参与编译的文件,MAINFILE+其他
EXCEPTL=$MAINFILE" "
MAKEFILEPATH=`pwd`
LIBPATH="-L$MAKEFILEPATH/$RSTPATH"
ARCH="ar -rv"
INCLUDEPATH=""
OBJFILE=""
CFLAGS="-Wall -march=native"
CFLAGS=$CFLAGS" -Os -Wno-strict-aliasing"
if [ "$X64" = "x64" ]
then
CFLAGS=$CFLAGS" -m64"
fi
CC="gcc"
GCC="g++"
LIBDIR=$HumbleDir" "$LIBDIR
GetIncludePath()
{
for EachSub in $LIBDIR
do
INCLUDEPATH=$INCLUDEPATH" -I$MAKEFILEPATH/$EachSub"
done
echo ---------------------Dir---------------------------
echo $LIBDIR
echo ---------------------Include Dir---------------------------
echo $INCLUDEPATH
}
IsExcePTL()
{
for EachExec in $EXCEPTL
do
if [ "$EachExec" = "$1" ]
then
return 1
fi
done
return 0
}
Make()
{
for EachSub in $LIBDIR
do
echo ---------------------$EachSub---------------------------
cd $EachSub
if [ "$?" != "0" ]
then
exit 1
fi
SourceFile=`ls *.cpp 2>/dev/null`
for EachFile in $SourceFile
do
IsExcePTL $EachFile
if [ "$?" = "0" ]
then
echo "$GCC $CFLAGS -c $EachFile"
$GCC $CFLAGS -c $EachFile $INCLUDEPATH
if [ "$?" != "0" ]
then
echo "---------------------Error---------------------"
exit 1
fi
fi
done
SourceFile=`ls *.c 2>/dev/null`
for EachFile in $SourceFile
do
IsExcePTL $EachFile
if [ "$?" = "0" ]
then
echo "$CC $CFLAGS -c $EachFile"
$CC $CFLAGS -c $EachFile $INCLUDEPATH
if [ "$?" != "0" ]
then
echo "---------------------Error---------------------"
exit 1
fi
fi
done
RstFile=`ls *.o 2>/dev/null`
for EachFile in $RstFile
do
if [ -f "$MAKEFILEPATH/$EachFile" ]
then
rm -rf $MAKEFILEPATH/$EachFile
fi
mv $EachFile $MAKEFILEPATH>/dev/null
done
cd $MAKEFILEPATH
done
echo ---------------------Make .a file---------------------------
cd $MAKEFILEPATH
OBJFILE=`ls *.o 2>/dev/null`
echo "$ARCH lib$LIBNAME.a `echo $OBJFILE`"
$ARCH lib$LIBNAME.a `echo $OBJFILE`
rm -rf *.o
mv lib$LIBNAME.a $RSTPATH
}
Clean()
{
rm -rf *.o
for EachSub in $LIBDIR
do
rm -rf $MAKEFILEPATH/$EachSub/*.o
done
cd $RSTPATH
echo "start rm lib$LIBNAME.a"
rm -rf lib$LIBNAME.a
echo "start rm $PROGRAMNAME"
rm -rf $PROGRAMNAME
cd $MAKEFILEPATH
}
while [ 1 = 1 ]
do
if [ $# -eq 1 ]
then
if [ "$1" = "clean" ]
then
Clean
exit 0
fi
if [ "$1" = "x64" ]
then
break
fi
echo "$UsAge"
exit 1
elif [ $# -gt 1 ]
then
echo "$UsAge"
exit 1
else
break
fi
done
GetIncludePath
Make
#编译mian函数
if [ "$PROGRAMNAME" = "$SPACE" ]
then
exit 0
fi
echo ---------------------cp lib---------------------------
cd $RSTPATH
if [ -f "libevent_pthreads.a" ]
then
rm -rf libevent_pthreads.a
fi
if [ -f "libevent_extra.a" ]
then
rm -rf libevent_extra.a
fi
if [ -f "libevent_core.a" ]
then
rm -rf libevent_core.a
fi
alias cp="cp -f"
cp libevent_pthreads_$OSNAME.a libevent_pthreads.a
cp libevent_extra_$OSNAME.a libevent_extra.a
cp libevent_core_$OSNAME.a libevent_core.a
cd $MAKEFILEPATH/$MAINDIR
echo ---------------------Make program file---------------------------
echo "Include lib is:$INCLUDELIB"
echo "$GCC $CFLAGS -o $PROGRAMNAME $MAINFILE $LIBPATH $LIBAPP -l$LIBNAME $INCLUDELIB"
$GCC $CFLAGS -o $PROGRAMNAME $MAINFILE $LIBPATH $LIBAPP -l$LIBNAME $INCLUDELIB $INCLUDEPATH
if [ "$?" != "0" ]
then
echo "---------------------Error---------------------"
exit 1
fi
mv $PROGRAMNAME $MAKEFILEPATH/$RSTPATH
cd $MAKEFILEPATH
exit 0