1 Star 1 Fork 11

sunwf/melon

forked from Gitee 极速下载/melon 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
configure 13.96 KB
一键复制 编辑 原始数据 按行查看 历史
#!/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"
tcc="gcc"
else
install_path=`echo "/usr/local/melon"`
cc="cc"
tcc="cc"
fi
#wasm flag
wasm=0
#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"
echo -e "\t--enable-wasm"
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
if [ $param_prefix == "--enable-wasm" ]; then
wasm=1
fi
done
#wasm
if [ $wasm -eq 1 ]; then
echo -e "Webassembly\t\t[enable]"
#llvm
llvm_flag=""
$cc --help|grep LLVM > /dev/null 2>&1
if [ $? -ne 0 ]; then
llvm_flag="--llvm-lto 1"
fi
fi
if [[ "$install_path" == ~* ]]; then
install_path=$HOME/${install_path:1}
fi
#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
$tcc -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
if [ $wasm -eq 1 ]; then
echo -e "CC\t\t= emcc" >> Makefile
else
echo -e "CC\t\t= $cc" >> Makefile
fi
gccver=`gcc -dumpversion|cut -d '.' -f 1`
if [ $wasm -eq 1 ]; then
echo -e "FLAGS\t\t= -Iinclude -c -g -O3 $llvm_flag -s -mmutable-globals -mnontrapping-fptoint -msign-ext -Wemcc" >> Makefile
elif [ $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
if [ $wasm -eq 0 ]; then
echo -e "MELONSO\t\t= libmelon.dll" >> Makefile
fi
echo -e "MELONA\t\t= libmelon.lib" >> Makefile
else
if [ $wasm -eq 0 ]; then
echo -e "MELONSO\t\t= libmelon.so" >> Makefile
fi
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 install clean" >> Makefile
if [ $wasm -eq 1 ]; then
echo "compile: MKDIR \$(OBJS) \$(MELONA)" >> Makefile
else
echo "compile: MKDIR \$(OBJS) \$(MELONSO) \$(MELONA)" >> Makefile
fi
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
if [ $wasm -eq 1 ]; then
echo -e "\temar rcs lib/\$(MELONA) \$(OBJS)" >> Makefile
else
echo -e "\tar -r lib/\$(MELONA) \$(OBJS)" >> Makefile
fi
if [ $wasm -eq 0 ]; then
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
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
echo -e "\ttest -d $melanglibpath/trace || cp -fr trace $melanglibpath" >> 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
if [ $wasm -eq 1 ]; then
echo -e "\t\$(CC) \$(FLAGS) -o \$@ $fname" >> Makefile
continue
fi
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 sendfile & writev
test $fname = "./src/mln_connection.c"
if [ $? -eq 0 ]; then
sendfile=0
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 __USE_UNIX98
test $fname = "./src/mln_thread_pool.c"
if [ $? -eq 0 ]; then
unix98=0
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!"
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C/C++
1
https://gitee.com/backJ/melon.git
git@gitee.com:backJ/melon.git
backJ
melon
melon
master

搜索帮助