Permalink
Fetching contributors…
Cannot retrieve contributors at this time
executable file 241 lines (219 sloc) 7.1 KB
#!/bin/bash
# Simple configuration script for people who expect such a script to exist.
# Please do not convert istatd to autotools. We will likely not accept such
# a conversion. Thanks for your interest in istatd, and good luck!
set -e
set -o nounset
rm -f makevars.config
rm -f config.h
# Find Python version 2.
# If this fails, you need to create appropriate aliases or symlinks for
# testing to work!
/usr/bin/env python -V
/usr/bin/env python2 -V
if curl --help >/dev/null 2>&1; then echo "Found curl in path."; else
echo "You need to install the command-line tool 'curl'."
exit 1
fi
if cat /dev/null | zlib-flate -compress; then echo "Found zlib-flate in path."; else
echo "You need to install the command-line tool 'zlib-flate'."
echo "On debian systems run 'sudo apt-get install qpdf'"
exit 1
fi
echo "# makevars.config for istatd generated on " `date` > makevars.config
BOOST_SYSTEM=""
BOOST_FILESYSTEM=""
BOOST_THREAD=""
BOOST_IOSTREAMS=""
STATGRAB=""
LIBRT=""
DESTDIR=""
USR_PREFIX=""
VAR_PREFIX=""
ETC_PREFIX=""
while [ $# -gt 0 ]; do
case $1 in
--boost_system)
shift
BOOST_SYSTEM="$1"
;;
--boost_filesystem)
shift
BOOST_FILESYSTEM="$1"
;;
--boost_thread)
shift
BOOST_THREAD="$1"
;;
--boost_iostreams)
shift
BOOST_IOSTREAMS="$1"
;;
--statgrab)
shift
STATGRAB="$1"
;;
--librt)
shift
LIBRT="$1"
;;
--prefix)
shift
DESTDIR="$1"
;;
--usr-prefix)
shift
USR_PREFIX="$1"
;;
--var-prefix)
shift
VAR_PREFIX="$1"
;;
--etc-prefix)
shift
ETC_PREFIX="$1"
;;
*)
echo "Options:"
echo "--boost_system -lboost_system-mt What is the boost_system library name?"
echo "--boost_filesystem -lboost_filesystem-mt What is the boost_filesystem library name?"
echo "--boost_thread -lboost_thread-mt What is the boost_thread library name?"
echo "--boost_iostreams -lboost_iostreams-mt What is the boost_iostreams library name?"
echo "--statgrab -lstatgrab What is the statgrab library name?"
echo "--librt -lrt What is the librt library name (if any)?"
echo "--prefix / What is the root of the install?"
echo "--usr-prefix /usr What is the '/usr' directory for executables?"
echo "--var-prefix /var What is the '/var' directory for database data?"
echo "--etc-prefix /etc What is the '/etc/ directory for rc.d scripts?"
echo "No equal sign for option values."
exit 1
;;
esac
shift
done
# see if we need to install boost
if [ ! -d /usr/include/boost -a ! -d /usr/local/include/boost ]; then
echo "You need to install libboost-all-dev for your distribution."
exit 1
fi
if [ ! -r /usr/include/statgrab.h -a ! -r /usr/local/include/statgrab.h ]; then
echo "You need to install libstatgrab-dev for your distribution, or "
echo "download and install it from source. See README.md"
exit 1
fi
function findone() {
libs=$*
mkdir -p tmp
fn=tmp/tt$$.c
echo "int main() { return 0; }" > "$fn"
for i in $libs; do
if gcc -o tmp/tt "$fn" $i > /dev/null 2>&1; then
echo -n $i
rm -rf tmp
return
fi
done
}
# boost_system is a pain across versions
if [ -z "$BOOST_SYSTEM" ]; then
BOOST_SYSTEM=`findone -lboost_system -lboost_system-mt`
if [ -z "$BOOST_SYSTEM" ]; then
echo "Cannot find boost_system-mt.so (or boost_system.so)"
echo "Specify it with --boost_system or install libboost-all-dev."
echo "Ubuntu users can also use ./install-boost-dev.sh as root"
exit 1
fi
fi
# boost_filesystem is also somewhat a pain
if [ -z "$BOOST_FILESYSTEM" ]; then
BOOST_FILESYSTEM=`findone -lboost_filesystem -lboost_filesystem-mt`
if [ -z "$BOOST_FILESYSTEM" ]; then
echo "Cannot find boost_filesystem-mt.so (or boost_filesystem.so)"
echo "Specify it with --boost_filesystem or install libboost-all-dev."
exit 1
fi
fi
# RHEL can't find boost_thread on its own.
if [ -z "$BOOST_THREAD" ]; then
BOOST_THREAD=`findone -lboost_thread -lboost_thread-mt`
if [ -z "$BOOST_THREAD" ]; then
echo "Cannot find boost_thread-mt.so (or boost_thread.so)"
echo "Specify it with --boost_thread or install libboost-all-dev."
exit 1
fi
fi
if [ -z "$BOOST_IOSTREAMS" ]; then
BOOST_IOSTREAMS=`findone -lboost_iostreams -lboost_iostreams-mt`
if [ -z "$BOOST_IOSTREAMS" ]; then
echo "Cannot find boost_iostreams-mt.so (or boost_iostreams.so)"
echo "Specify it with --boost_iostreams or install libboost-all-dev."
exit 1
fi
fi
if [ -z "$STATGRAB" ]; then
STATGRAB=`findone -lstatgrab`
if [ -z "$STATGRAB" ]; then
echo "Cannot find libstatgrab.so"
echo "Specify it with --statgrab or install libstatgrab-dev."
echo "Or try https://github.com/imvu-open/libstatgrab"
exit 1
fi
fi
if [ -z "$LIBRT" ]; then
mkdir -p tmp
fn=tmp/tt$$.c
echo "#include <time.h>" > "$fn"
echo "int main() { (void)clock_gettime(0, NULL); }" >> "$fn"
if gcc -o tmp/tt "$fn" > /dev/null 2>&1; then
LIBRT=""
else
LIBRT="-lrt"
fi
rm -rf tmp
fi
if [ ! -z "$BOOST_SYSTEM" ]; then
echo "BOOST_SYSTEM=$BOOST_SYSTEM" >> makevars.config
fi
if [ ! -z "$BOOST_FILESYSTEM" ]; then
echo "BOOST_FILESYSTEM=$BOOST_FILESYSTEM" >> makevars.config
fi
if [ ! -z "$BOOST_THREAD" ]; then
echo "BOOST_THREAD=$BOOST_THREAD" >> makevars.config
fi
if [ ! -z "$BOOST_IOSTREAMS" ]; then
echo "BOOST_IOSTREAMS=$BOOST_IOSTREAMS" >> makevars.config
fi
if [ ! -z "$STATGRAB" ]; then
echo "STATGRAB=$STATGRAB" >> makevars.config
fi
if [ ! -z "$LIBRT" ]; then
echo "LIBRT=$LIBRT" >> makevars.config
fi
if [ ! -z "$DESTDIR" ]; then
echo "DESTDIR=$DESTDIR" >> makevars.config
fi
if [ ! -z "$USR_PREFIX" ]; then
echo "USR_PREFIX=$USR_PREFIX" >> makevars.config
fi
if [ ! -z "$VAR_PREFIX" ]; then
echo "VAR_PREFIX=$VAR_PREFIX" >> makevars.config
fi
if [ ! -z "$ETC_PREFIX" ]; then
echo "ETC_PREFIX=$ETC_PREFIX" >> makevars.config
fi
echo "checking for libstatgrab interface version"
echo "/* config.h generated by configure script */" >> config.h
echo "" >> config.h
mkdir -p tmp
fn=tmp/sg.c
echo "#include <statgrab.h>" > "$fn"
echo "int main() { sg_get_cpu_percents(); }" >> "$fn"
if ! gcc -o tmp/sg.o -c "$fn" > /dev/null 2>&1; then
echo "libstatgrab 0.17 interface doesn't work, assuming 0.90"
echo "#define LIBSTATGRAB_API_0_90" >> config.h
else
echo "found libstatgrab 0.17 interface"
echo "#define LIBSTATGRAB_API_0_17" >> config.h
fi
rm -rf tmp
echo "All done"