2014-09-25 08:45:13 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
function platform() {
|
|
|
|
local __resultvar=$1
|
2014-10-29 10:38:21 +00:00
|
|
|
if [[ -f "/etc/redhat-release" ]]; then
|
2014-09-25 08:45:13 +00:00
|
|
|
eval $__resultvar="centos"
|
2014-11-12 05:34:59 +00:00
|
|
|
elif [[ -f "/etc/lsb-release" ]]; then
|
2014-09-25 08:45:13 +00:00
|
|
|
eval $__resultvar="ubuntu"
|
|
|
|
elif [[ -f "/etc/pf.conf" ]]; then
|
|
|
|
eval $__resultvar="darwin"
|
2014-11-12 19:15:17 +00:00
|
|
|
elif [[ -f "/bin/freebsd-version" ]]; then
|
|
|
|
eval $__resultvar="freebsd"
|
2014-09-25 08:45:13 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2014-11-12 05:34:59 +00:00
|
|
|
function distro() {
|
|
|
|
local __resultvar=$2
|
|
|
|
if [[ $1 = "centos" ]]; then
|
|
|
|
eval $__resultvar="centos"`cat /etc/redhat-release | awk '{print $3}'`
|
|
|
|
elif [[ $1 = "ubuntu" ]]; then
|
|
|
|
eval $__resultvar=`cat /etc/*-release | grep DISTRIB_CODENAME | awk -F '=' '{print $2}'`
|
|
|
|
elif [[ $1 = "darwin" ]]; then
|
|
|
|
eval $__resultvar=`sw_vers -productVersion | awk -F '.' '{print $1 "." $2}'`
|
2014-11-12 19:15:17 +00:00
|
|
|
elif [[ $1 = "freebsd" ]]; then
|
2014-11-12 19:50:14 +00:00
|
|
|
eval $__resultvar=`freebsd-version | awk -F '-' '{print $1}'`
|
2014-11-12 05:34:59 +00:00
|
|
|
else
|
|
|
|
eval $__resultvar="unknown_version"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2014-09-25 08:45:13 +00:00
|
|
|
function threads() {
|
|
|
|
local __resultvar=$1
|
|
|
|
platform OS
|
2014-11-04 06:22:47 +00:00
|
|
|
if [[ $TRAVIS_ENV = true ]]; then
|
|
|
|
log "running in travis"
|
2014-11-04 10:04:39 +00:00
|
|
|
eval $__resultvar=2
|
2014-11-04 06:22:47 +00:00
|
|
|
elif [ $OS = "centos" ] || [ $OS = "ubuntu" ]; then
|
2014-09-25 08:45:13 +00:00
|
|
|
eval $__resultvar=`cat /proc/cpuinfo | grep processor | wc -l`
|
|
|
|
elif [[ $OS = "darwin" ]]; then
|
|
|
|
eval $__resultvar=`sysctl hw.ncpu | awk '{print $2}'`
|
2014-11-12 19:15:17 +00:00
|
|
|
elif [[ $OS = "freebsd" ]]; then
|
|
|
|
eval $__resultvar=`sysctl -n kern.smp.cpus`
|
2014-09-25 08:45:13 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function log() {
|
|
|
|
echo "[+] $1"
|
|
|
|
}
|
|
|
|
|
|
|
|
function fatal() {
|
|
|
|
echo "[!] $1"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_cxx() {
|
|
|
|
export CXX=$1
|
|
|
|
export CMAKE_CXX_COMPILER=$1
|
|
|
|
}
|
|
|
|
|
|
|
|
function add_cxx_flag() {
|
|
|
|
export CXXFLAGS="$CXXFLAGS $1"
|
|
|
|
export CMAKE_CXX_FLAGS="$CMAKE_CXX_FLAGS $1"
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_cc() {
|
|
|
|
export CC=$1
|
|
|
|
export CMAKE_C_COMPILER=$1
|
|
|
|
}
|
2014-10-03 08:02:58 +00:00
|
|
|
|
|
|
|
function contains_element() {
|
|
|
|
local e
|
|
|
|
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
|
|
|
|
return 1
|
|
|
|
}
|
2014-11-12 05:34:59 +00:00
|
|
|
|