-
Notifications
You must be signed in to change notification settings - Fork 202
/
configure
executable file
·309 lines (288 loc) · 12.8 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
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
#!/bin/bash
#
# Copyright (C) Niklaus F.Schen.
#
# test system type
sysname=`uname -s`
#installation path
if ! case $sysname in MINGW*) false;; esac; then
install_path=$HOME/libmelon
cc="gcc"
else
install_path=`echo "/usr/local/melon"`
cc="cc"
fi
#get all parameters
for param in $@
do
if [ $param == "--help" ]; then
echo -e "\nMelon platform."
echo "Copyright (C) Niklaus F.Schen."
echo "Options:"
echo -e "\t--prefix=INSTALL_PATH"
echo -e "\t--cc=C compiler"
exit 0
fi
param_prefix=`echo $param|cut -d '=' -f 1`
param_suffix=`echo $param|cut -d '=' -f 2`
if [ $param_prefix == "--prefix" ]; then
install_path=$param_suffix
fi
if [ $param_prefix == "--cc" ]; then
cc=$param_suffix
fi
done
#output installation path
echo -e "Installation Path \t[$install_path]"
echo -e "#include <stdio.h>\nint main(int argc, char *argv[]) {printf(\"%s\", argv[1]);return 0;}" > .path_generator.c
$cc -o path_generator .path_generator.c
realpath=`./path_generator $install_path`
nullpath=`./path_generator /dev/null`
confpath=`./path_generator $realpath/conf/melon.conf`
tmpfilepath=`./path_generator $realpath/tmp`
pidpath=`./path_generator $realpath/logs/melon.pid`
logpath=`./path_generator $realpath/logs/melon.log`
if ! case $sysname in MINGW*) false;; esac; then
melanglibpath=`./path_generator $HOME/lib/melang`
melangdylibpath=`./path_generator $HOME/lib/melang_dynamic`
else
melanglibpath=`./path_generator /usr/local/lib/melang`
melangdylibpath=`./path_generator /usr/local/lib/melang_dynamic`
fi
rm -f path_generator .path_generator.c
#build path.c & h
echo -e "\n/*\n * Copyright (C) Niklaus F.Schen.\n */" > include/mln_path.h
echo -e "#ifndef __MLN_PATH_H\n#define __MLN_PATH_H" >> include/mln_path.h
echo -e "\ntypedef enum {\n m_p_install,\n m_p_conf,\n m_p_tmpfile,\n m_p_pid,\n m_p_log,\n m_p_null,\n m_p_melang_lib,\n m_p_melang_dylib\n} mln_path_type_t;" >> include/mln_path.h
echo -e "\ntypedef char *(*mln_path_hook_t)(void);" >> include/mln_path.h
echo -e "\nextern char *mln_path(void);" >> include/mln_path.h
echo -e "\nextern char *mln_path_null(void);" >> include/mln_path.h
echo -e "\nextern char *mln_path_melang_lib(void);" >> include/mln_path.h
echo -e "\nextern char *mln_path_melang_dylib(void);" >> include/mln_path.h
echo -e "\nextern char *mln_path_conf(void);" >> include/mln_path.h
echo -e "\nextern char *mln_path_tmpfile(void);" >> include/mln_path.h
echo -e "\nextern char *mln_path_pid(void);" >> include/mln_path.h
echo -e "\nextern char *mln_path_log(void);" >> include/mln_path.h
echo -e "\nextern void mln_path_hook_set(mln_path_type_t type, mln_path_hook_t hook);" >> include/mln_path.h
echo -e "\n#endif\n" >> include/mln_path.h
echo -e "\n/*\n * Copyright (C) Niklaus F.Schen.\n */" > src/mln_path.c
echo "#include <stdio.h>" >> src/mln_path.c
echo "#include \"mln_path.h\"" >> src/mln_path.c
echo -e "\nstatic char install_path[] = \"$realpath\";" >> src/mln_path.c
echo -e "\nstatic char conf_path[] = \"$confpath\";" >> src/mln_path.c
echo -e "\nstatic char tmpfile_path[] = \"$tmpfilepath\";" >> src/mln_path.c
echo -e "\nstatic char pid_path[] = \"$pidpath\";" >> src/mln_path.c
echo -e "\nstatic char log_path[] = \"$logpath\";" >> src/mln_path.c
echo -e "\nstatic char null_path[] = \"$nullpath\";" >> src/mln_path.c
echo -e "\nstatic char melang_lib_path[] = \"$melanglibpath\";" >> src/mln_path.c
echo -e "\nstatic char melang_dylib_path[] = \"$melangdylibpath\";" >> src/mln_path.c
echo -e "\nstatic mln_path_hook_t _install_path = NULL;" >> src/mln_path.c
echo -e "\nstatic mln_path_hook_t _null_path = NULL;" >> src/mln_path.c
echo -e "\nstatic mln_path_hook_t _melang_lib_path = NULL;" >> src/mln_path.c
echo -e "\nstatic mln_path_hook_t _melang_dylib_path = NULL;" >> src/mln_path.c
echo -e "\nstatic mln_path_hook_t _conf_path = NULL;" >> src/mln_path.c
echo -e "\nstatic mln_path_hook_t _tmpfile_path = NULL;" >> src/mln_path.c
echo -e "\nstatic mln_path_hook_t _pid_path = NULL;" >> src/mln_path.c
echo -e "\nstatic mln_path_hook_t _log_path = NULL;" >> src/mln_path.c
echo -e "\nvoid mln_path_hook_set(mln_path_type_t type, mln_path_hook_t hook)\n{" >> src/mln_path.c
echo -e " switch (type) {\n" >> src/mln_path.c
echo -e " case m_p_install:\n _install_path = hook;\n break;" >> src/mln_path.c
echo -e " case m_p_conf:\n _conf_path = hook;\n break;" >> src/mln_path.c
echo -e " case m_p_tmpfile:\n _tmpfile_path = hook;\n break;" >> src/mln_path.c
echo -e " case m_p_pid:\n _pid_path = hook;\n break;" >> src/mln_path.c
echo -e " case m_p_log:\n _log_path = hook;\n break;" >> src/mln_path.c
echo -e " case m_p_null:\n _null_path = hook;\n break;" >> src/mln_path.c
echo -e " case m_p_melang_lib:\n _melang_lib_path = hook;\n break;" >> src/mln_path.c
echo -e " case m_p_melang_dylib:\n _melang_dylib_path = hook;\n break;" >> src/mln_path.c
echo -e " default:\n break;" >> src/mln_path.c
echo -e " }" >> src/mln_path.c
echo -e "}" >> src/mln_path.c
echo -e "\nchar *mln_path(void)\n{" >> src/mln_path.c
echo " return _install_path == NULL? install_path: _install_path();" >> src/mln_path.c
echo "}" >> src/mln_path.c
echo -e "\nchar *mln_path_conf(void)\n{" >> src/mln_path.c
echo " return _conf_path == NULL? conf_path: _conf_path();" >> src/mln_path.c
echo "}" >> src/mln_path.c
echo -e "\nchar *mln_path_tmpfile(void)\n{" >> src/mln_path.c
echo " return _tmpfile_path == NULL? tmpfile_path: _tmpfile_path();" >> src/mln_path.c
echo "}" >> src/mln_path.c
echo -e "\nchar *mln_path_pid(void)\n{" >> src/mln_path.c
echo " return _pid_path == NULL? pid_path: _pid_path();" >> src/mln_path.c
echo "}" >> src/mln_path.c
echo -e "\nchar *mln_path_log(void)\n{" >> src/mln_path.c
echo " return _log_path == NULL? log_path: _log_path();" >> src/mln_path.c
echo "}" >> src/mln_path.c
echo -e "\nchar *mln_path_null(void)\n{" >> src/mln_path.c
echo " return _null_path == NULL? null_path: _null_path();" >> src/mln_path.c
echo "}" >> src/mln_path.c
echo -e "\nchar *mln_path_melang_lib(void)\n{" >> src/mln_path.c
echo " return _melang_lib_path == NULL? melang_lib_path: _melang_lib_path();" >> src/mln_path.c
echo "}" >> src/mln_path.c
echo -e "\nchar *mln_path_melang_dylib(void)\n{" >> src/mln_path.c
echo " return _melang_dylib_path == NULL? melang_dylib_path: _melang_dylib_path();" >> src/mln_path.c
echo "}" >> src/mln_path.c
# build makefile content
echo "# " > Makefile
echo "# Copyright (C) Niklaus F.Schen." >> Makefile
echo "# " >> Makefile
echo -e "CC\t\t= $cc" >> Makefile
gccver=`gcc -dumpversion|cut -d '.' -f 1`
if [ $sysname != 'Darwin' -a "$?" == "0" -a $gccver -ge 11 ]; then
echo -e "FLAGS\t\t= -Iinclude -c -Wall -ggdb -Werror -O2 -fPIC" >> Makefile
else
echo -e "FLAGS\t\t= -Iinclude -c -Wall -ggdb -Werror -O3 -fPIC" >> Makefile
fi
if ! case $sysname in MINGW*) false;; esac; then
echo -e "MELONSO\t\t= libmelon.dll" >> Makefile
echo -e "MELONA\t\t= libmelon.lib" >> Makefile
else
echo -e "MELONSO\t\t= libmelon.so" >> Makefile
echo -e "MELONA\t\t= libmelon.a" >> Makefile
fi
echo -e "OBJS\t\t= \\" >> Makefile
hasDot=`ls -l src/|grep "\.\."`
cnt=2
if [ -z $hasDot ]; then
cnt=0
fi
sum=`ls -l src/|wc -l`
for path in `find . -name "*.c"`
do
fname=`basename $path`
objname=`echo $fname | cut -d '.' -f 1`".o"
echo -n " objs/"$objname >> Makefile
if [ $cnt -lt $sum ]; then
echo " \\" >> Makefile
fi
let cnt+=1 > /dev/null
done
echo "" >> Makefile
echo -e ".PHONY :\tcompile modules install clean" >> Makefile
echo "compile: MKDIR \$(OBJS) \$(MELONSO) \$(MELONA)" >> Makefile
echo "clean:" >> Makefile
echo -e "\trm -fr objs lib Makefile" >> Makefile
echo "MKDIR :" >> Makefile
echo -e "\ttest -d objs || mkdir objs" >> Makefile
echo -e "\ttest -d lib || mkdir lib" >> Makefile
echo "\$(MELONA) : \$(OBJS)" >> Makefile
echo -e "\tar -r lib/\$(MELONA) \$(OBJS)" >> Makefile
echo "\$(MELONSO) : \$(OBJS)" >> Makefile
if [ $sysname = 'Linux' ]; then
echo -e "\t\$(CC) -o lib/\$(MELONSO) \$(OBJS) -ggdb -Wall -lpthread -Llib/ -ldl -shared -fPIC" >> Makefile
elif ! case $sysname in MINGW*) false;; esac; then
echo -e "\t\$(CC) -o lib/\$(MELONSO) \$(OBJS) -ggdb -Wall -lpthread -lWs2_32 -Llib/ -shared -fPIC" >> Makefile
else
echo -e "\t\$(CC) -o lib/\$(MELONSO) \$(OBJS) -ggdb -Wall -lpthread -Llib/ -lc -shared -fPIC" >> Makefile
fi
echo "install:" >> Makefile
echo -e "\ttest -d $melanglibpath || mkdir -p $melanglibpath" >> Makefile
echo -e "\ttest -d $install_path || mkdir -p $install_path" >> Makefile
echo -e "\tcp -fr lib $install_path" >> Makefile
echo -e "\tcp -fr include $install_path" >> Makefile
echo -e "\ttest -d $install_path/conf || cp -fr conf $install_path" >> Makefile
for fname in `find . -name "*.c"`
do
objname=`basename $fname | cut -d '.' -f 1`".o"
echo -n "objs/$objname :" >> Makefile
for header in `cpp -MM -MG $fname 2> /dev/null`
do
suffix=`echo $header | cut -d '.' -f 2`
if [ $suffix = 'c' ]; then
echo -n $header >> Makefile
echo -n " " >> Makefile
continue
fi
if [ $suffix != 'h' ]; then
continue
fi
test -e include/$header && echo -n "include/$header " >> Makefile
done
echo "" >> Makefile
test $fname = "./src/mln_event.c"
if [ $? -eq 0 ]; then
#test event system call
echo "#include<stdio.h>
#include<sys/epoll.h>
int main(void){epoll_create(10);return 0;}" > ev_test.c
cc -o ev_test ev_test.c 2>/dev/null
if [ "$?" == "0" ]; then
echo -e "event\t\t\t[EPOLL]"
echo -e "\t\$(CC) \$(FLAGS) -o \$@ $fname -DMLN_EPOLL" >> Makefile
rm -f ev_test ev_test.c
continue
fi
echo "#include<stdio.h>
#include<sys/types.h>
#include<sys/event.h>
#include<sys/time.h>
int main(void){kqueue();return 0;}" > ev_test.c
cc -o ev_test ev_test.c 2>/dev/null
if [ "$?" == "0" ]; then
echo -e "event\t\t\t[KQUEUE]"
echo -e "\t\$(CC) \$(FLAGS) -o \$@ $fname -DMLN_KQUEUE" >> Makefile
rm -f ev_test ev_test.c
continue
fi
rm -f ev_test ev_test.c
echo -e "event\t\t\t[SELECT]"
echo -e "\t\$(CC) \$(FLAGS) -o \$@ $fname -DMLN_SELECT" >> Makefile
continue
fi
test $fname = "./src/mln_connection.c"
if [ $? -eq 0 ]; then
sendfile=0
#test sendfile
echo "#include <sys/sendfile.h>
int main(void){sendfile(1,0,0,1);return 0;}" > sendfile_test.c
cc -o sendfile_test sendfile_test.c 2>/dev/null
if [ "$?" == "0" ]; then
sendfile=1
echo -e "sendfile\t\t[support]"
else
echo -e "sendfile\t\t[NOT support]"
fi
rm -f sendfile_test sendfile_test.c
#test writev
echo -e "#include <stdio.h>\n#include <sys/uio.h>" > writev_test.c
echo "int main(void){writev(0,NULL,0);return 0;}" >> writev_test.c
cc -o writev_test writev_test.c 2>/dev/null
if [ "$?" == "0" ]; then
echo -e "writev\t\t\t[support]"
if [ $sendfile -eq "1" ]; then
echo -e "\t\$(CC) \$(FLAGS) -o \$@ $fname -DMLN_SENDFILE -DMLN_WRITEV" >> Makefile
else
echo -e "\t\$(CC) \$(FLAGS) -o \$@ $fname -DMLN_WRITEV" >> Makefile
fi
else
echo -e "writev\t\t\t[NOT support]"
if [ $sendfile -eq "1" ]; then
echo -e "\t\$(CC) \$(FLAGS) -o \$@ $fname -DMLN_SENDFILE" >> Makefile
else
echo -e "\t\$(CC) \$(FLAGS) -o \$@ $fname" >> Makefile
fi
fi
rm -f writev_test writev_test.c
continue
fi
test $fname = "./src/mln_thread_pool.c"
if [ $? -eq 0 ]; then
unix98=0
#test __USE_UNIX98
echo -e "#ifndef __USE_UNIX98\n#define __USE_UNIX98\n#endif\n#include <pthread.h>\n" > unix98_test.c
echo "int main(void){pthread_setconcurrency(0);return 0;}" >> unix98_test.c
cc -o unix98_test unix98_test.c -lpthread 2>/dev/null
if [ "$?" == "0" ]; then
echo -e "__USE_UNIX98\t\t[support]"
echo -e "\t\$(CC) \$(FLAGS) -o \$@ $fname -DMLN_USE_UNIX98" >> Makefile
else
echo -e "__USE_UNIX98\t\t[not support]"
echo -e "\t\$(CC) \$(FLAGS) -o \$@ $fname" >> Makefile
fi
rm -fr unix98_test unix98_test.c
continue
fi
echo -e "\t\$(CC) \$(FLAGS) -o \$@ $fname" >> Makefile
done
#generate conf file
sed -e "s#{{ROOT}}#${realpath}#g" conf/melon.conf.template > conf/melon.conf
echo "Configure done!"