1 Star 1 Fork 28

zhoutk / libstpool

forked from piggy_xrh / libstpool 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
configure 5.86 KB
一键复制 编辑 原始数据 按行查看 历史
piggy_xrh 提交于 2017-11-03 10:20 . 更新 configure
#!/bin/bash
#piggy_xrh@163.com
function showUsage()
{
echo "--help display this help and exit"
echo "--prefix=PREFIX install architecture-independent files in PREFIX"
echo "--enable-debug-mode enable support for running in debug mode"
echo "--host=HOST cross-compile to build programs to run on HOST [BUILD]"
}
function cacheClean()
{
rm .test .test.c -fr 2>/dev/null
}
function errExit()
{
cacheClean
exit 1
}
function beginConfig()
{
cp .help/.ospx_config $VAR_config || exit 1
}
function enableConfig()
{
echo "" >>$VAR_config
echo "#define $1 1" >>$VAR_config
}
function endConfig()
{
echo "" >>$VAR_config
echo "" >>$VAR_config
echo "#endif" >>$VAR_config
}
# reset the config
VAR_config=os/ospx_config.h
beginConfig
# set the default env
VAR_cross=
VAR_prefix=/usr
VAR_libmode=Release
VAR_strip=yes
VAR_cflags=
# clear the cache
cacheClean
options=`getopt -a -q -oh -l help,prefix:,enable-debug-mode,host: -- "$@" 2>/dev/null`
eval set -- "$options"
# parse the parameters
while [ -n "$1" ]; do
case $1 in
--help)
showUsage && exit 1;;
--prefix)
VAR_prefix=$2;
if [[ "${VAR_prefix:0:1}" != "/" ]]; then
VAR_prefix=$PWD/$VAR_prefix
fi
shift
;;
--enable-debug-mode)
VAR_libmode=debug;
VAR_strip=no;
;;
--host)
VAR_cross=$2;
shift
;;
--)
;;
?)
echo "Unsupported options: $1" && exit 1;;
esac
shift
done
# check the debug mode
if [ $VAR_libmode == "debug" ]
then
VAR_cflags+="-g -D_DEBUG -D_GNU_SOURCE -fPIC"
else
VAR_cflags+="-O2 -DNDEBUG -D_GNU_SOURCE -fPIC"
fi
# check the cross tools
if [ ! -z ${VAR_cross} ]; then
echo "checking cross tools ..."
[ -z `which ${VAR_cross}gcc` ] && echo "- no ${VAR_cross}gcc" && exit 1
[ -z `which ${VAR_cross}ar` ] && echo "- no ${VAR_cross}ar" && exit 1
[ -z `which ${VAR_cross}strip` ] && echo "- no ${VAR_cross}strip" && exit 1
echo " yes"
fi
echo "complier tools: ${VAR_corss}gcc"
# Check the os width
if [ -z ${VAR_cross} ]; then
echo -n "checking os width ..."
cat << _CODE_EOF > .test.c
#include <stdio.h>
int main()
{
return sizeof(long) == 8 ? 0 : 1;
}
_CODE_EOF
${VAR_cross}gcc .test.c -o .test && ./.test
if test $? -eq 0
then
VAR_cflags+=" -DOS_W_64 -m64"
echo " 64"
else
VAR_cflags+=" -DOS_W_32"
echo " 32"
fi
else
read -p "select the os bit width(32/64): " _W
if [ ${_W} == 64 ]; then
VAR_cflags+="-DOS_W_64 -m64"
else
VAR_cflags+="-DOS_W_32"
fi
fi
# Check <stdint.h>
echo -n "checking <stdint.h> ..."
cat << _CODE_EOF >.test.c
#include <stdint.h>
int main()
{
return 0;
}
_CODE_EOF
${VAR_cross}gcc .test.c -o .test 2>/dev/null
if test $? -eq 0
then
enableConfig HAS_STDINT_H
echo " yes"
else
echo " no"
fi
# Check pthread_rwlock
echo -n "checking pthread_rwlock ..."
cat << _CODE_EOF >.test.c
#include <pthread.h>
int main()
{
pthread_rwlock_t lock;
return 0;
}
_CODE_EOF
${VAR_cross}gcc .test.c -o .test -lpthread 2>/dev/null
if test $? -eq 0
then
enableConfig HAS_PTHREAD_RWLOCK
echo " yes"
else
echo " no"
fi
# check clock_gettime
echo -n "checking clock_gettime ..."
cat << _CODE_EOF >.test.c
#include <time.h>
int main()
{
clock_gettime(CLOCK_REALTIME, 0);
return 0;
}
_CODE_EOF
${VAR_cross}gcc .test.c -o .test -lrt 2>/dev/null
if test $? -eq 0
then
enableConfig HAS_CLOCK_GETTIME
VAR_cflags+=" -DHAS_CLOCK_GETTIME"
echo " yes"
else
echo " no"
fi
# check monotonic clock
echo -n "checking monotonic clock ..."
cat << _CODE_EOF >.test.c
#include <time.h>
int main()
{
clock_gettime(CLOCK_MONOTONIC, 0);
return 0;
}
_CODE_EOF
${VAR_cross}gcc .test.c -o .test -lrt 2>/dev/null
if test $? -eq 0
then
enableConfig HAS_CLOCK_MONOTONIC
echo " yes"
else
echo " no"
fi
# check pthread_condattr_setclock
echo -n "checking pthread_condattr_setclock ..."
cat << _CODE_EOF >.test.c
#include <pthread.h>
int main()
{
pthread_condattr_t attr;
if (!pthread_condattr_init(&attr)) {
pthread_condattr_setclock(&attr, 0);
}
return 0;
}
_CODE_EOF
${VAR_cross}gcc .test.c -o .test -lrt -lpthread 2>/dev/null
if test $? -eq 0
then
enableConfig HAS_PTHREAD_CONDATTR_SETCLOCK
echo " yes"
else
echo " no"
fi
# check pthread_attr_getinheritsched
echo -n "checking pthread_attr_getinheritsched ..."
cat << _CODE_EOF >.test.c
#include <pthread.h>
int main()
{
pthread_attr_getinheritsched(0, 0);
return 0;
}
_CODE_EOF
${VAR_cross}gcc .test.c -o .test -lpthread 2>/dev/null
if test $? -eq 0
then
enableConfig HAS_PTHREAD_ATTR_GETINHERITSCHED
echo " yes"
else
echo " no"
fi
# check sem_timedwait
echo -n "checking sem_timedwait ..."
cat << _CODE_EOF >.test.c
#include <semaphore.h>
int main()
{
sem_timedwait(0, 0);
return 0;
}
_CODE_EOF
${VAR_cross}gcc .test.c -o .test -lpthread 2>/dev/null
if test $? -eq 0
then
enableConfig HAS_SEM_TIMEDWAIT
echo " yes"
else
echo " no"
fi
# check prctl
echo -n "checking prctl ..."
cat << _CODE_EOF >.test.c
#include <sys/prctl.h>
int main()
{
prctl(PR_SET_NAME, (long)"main",0,0,0);
return 0;
}
_CODE_EOF
${VAR_cross}gcc .test.c -o .test 2>/dev/null
if test $? -eq 0
then
enableConfig HAS_PRCTL
echo " yes"
else
echo " no"
fi
# generate complier.mk
cat << _MK_EOF >complier.mk
CROSS :=$VAR_cross
CC :=\$(CROSS)gcc
CPP :=\$(CROSS)g++
AR :=\$(CROSS)ar
STRIP :=\$(CROSS)strip
ARFLAGS = -rv
STRIPFLAGS = -xX
CFLAGS = -Wall
CPPFLAGS = -Wall
_MK_EOF
# generate features.mk
echo "CFLAGS+=$VAR_cflags" >features.mk || errExit
echo -e "INSTALL_DIR=$VAR_prefix" >Makefile
echo -e "STRIP_LIB=$VAR_strip\n" >>Makefile
cat .help/.Makefile >> Makefile || errExit
echo "generate Makefile succefully."
# remove all temp files
cacheClean
endConfig
C
1
https://gitee.com/zhoutk/libstpool.git
git@gitee.com:zhoutk/libstpool.git
zhoutk
libstpool
libstpool
master

搜索帮助