#!/bin/sh # # Configuration script for Services. # # Anope (c) 2003 Anope team # Contact us at anope@zero.org # # This program is free but copyrighted software; see the file COPYING for # details. # # Based on the original code of Epona by PegSoft. # Based on the original code of Services by Andy Church. ########################################################################### # Nifty handy functions. echo2 () { $ECHO2 "$*$ECHO2SUF" # these are defined later } log () { echo >&3 "$MODE: $*" } run () { echo >&3 "$MODE: >>> $*" $* >&3 2>&3 tmp/test.c < int main() { return 0; } EOT if run $CC $CC_FLAGS tmp/test.c $CC_LIBS -o tmp/test ; then eval "HAVE_${inc2}=1" log "found $include" return 0 else eval "HAVE_${inc2}=0" log "didn't find $include" return 1 fi } test_function () { rettype="$1" func="$2" proto="$3" if [ ! "$rettype" -o ! "$func" ] ; then log "test_function: missing parameter(s)" return 1 fi if [ ! "$proto" ] ; then proto="(...)" fi func2=`echo $func | tr '[a-z]' '[A-Z]'` if [ ! "$TEST" ] ; then TEST="return 0;" fi cat >tmp/test.c <&1 ; printf 'b' 2>&1`" = "ab" ] ; then ECHO2='printf "%s"' else # oh well... ECHO2='echo' fi export ECHO2 ECHO2SUF ########################################################################### # Command-line parsing. IGNORE_CACHE= ; USER_CC= ; USER_CC_FLAGS=bonkle ; USER_CC_LFLAGS=bonkle USER_CC_LIBS= ; MYSQL_LIB_DIR=bonkle ; MYSQL_INC_DIR=bonkle export IGNORE_CACHE USER_CC USER_CC_FLAGS USER_CC_LFLAGS USER_CC_LIBS MYSQL_LIB_DIR MYSQL_INC_DIR while [ $# -gt 0 ] ; do if [ "$1" = "-ignore-cache" ] ; then IGNORE_CACHE=bonkle elif [ "$1" = "-cc" ] ; then shift USER_CC=$1 elif [ "$1" = "-cflags" ] ; then shift USER_CC_FLAGS=$1 elif [ "$1" = "-lflags" ] ; then shift USER_CC_LFLAGS=$1 elif [ "$1" = "-libs" ] ; then shift USER_CC_LIBS=$1 elif [ "$1" = "-os2" ] ; then PROGRAM=services.exe elif [ "$1" = "-with-mysql-libs" ] ; then shift MYSQL_LIB_DIR=$1 elif [ "$1" = "-with-mysql-includes" ] ; then shift MYSQL_INC_DIR=$1 else if [ "$1" != "-help" -a "$1" != "-h" -a "$1" != "--help" ]; then echo >&2 Unknown option/parameter: "$1" exitval=1 else exitval=0 fi cat >&2 <configure.log MODE=" " TEST="" export MODE TEST ########################################################################### # Search for a compiler. MODE="find_cc " echo2 "Searching for a suitable compiler... " if [ "$USER_CC" ] ; then CC="$USER_CC" echo "(supplied) using $CC." log user supplied \`"$USER_CC'" elif [ "$CC" ] ; then echo "(cached) using $CC." log cache supplied \`"$CC'" elif run gcc --version ; then echo "great, found gcc!" CC=gcc DEF_CC_FLAGS=-O2 log using \`gcc\' else echo "gcc not found." echo2 " Looking for alternatives... " echo >tmp/test.c "int main(){return 1;}" if run cc tmp/test.c -o tmp/test ; then CC=cc elif run c89 tmp/test.c -o tmp/test ; then CC=c89 else echo "no C compiler found!" echo " Use the -cc command line option to specify your C compiler." log "automatic tests failed" exit 2 fi # See if it handles ANSI. cat >tmp/test.c <tmp/test.c <tmp/test.c "int main(){return 1;}" CC_LIBS= if run $CC $CC_FLAGS tmp/test.c -lnsl -o tmp/test ; then CC_LIBS="$CC_LIBS -lnsl" echo2 "-lnsl " fi if run $CC $CC_FLAGS tmp/test.c -lsocket -o tmp/test ; then CC_LIBS="$CC_LIBS -lsocket" echo2 "-lsocket " fi if run $CC $CC_FLAGS tmp/test.c -lresolv -o tmp/test ; then CC_LIBS="$CC_LIBS -lresolv" echo2 "-lresolv " fi if run $CC $CC_FLAGS tmp/test.c -lbsd -o tmp/test ; then CC_LIBS="$CC_LIBS -lbsd" echo2 "-lbsd " fi if [ "$THREAD" = "USE_THREADS" ] ; then if run $CC $CC_FLAGS -D_REENTRANT tmp/test.c -pthread -o tmp/test ; then CC_FLAGS="$CC_FLAGS -D_REENTRANT" CC_LIBS="$CC_LIBS -pthread" echo2 "-pthread " elif run $CC $CC_FLAGS -D_REENTRANT tmp/test.c -lpthread -o tmp/test ; then CC_FLAGS="$CC_FLAGS -D_REENTRANT" CC_LIBS="$CC_LIBS -lpthread" echo2 "-lpthread " else THREAD="" echo "" echo "Configure was not able to determine how to compile Anope" echo "with threading support; disabled it." fi fi if [ "$MYSQL" = "USE_MYSQL" ] ; then if [ "$MYSQL_LIB_DIR" = bonkle ] ; then # Let's try to find it... MYSQL_LIB_DIR="`mysql_config --libs 2> /dev/null | awk '{print $1}' | sed s/-L//g | sed s/\'//g`" if [ -f "$MYSQL_LIB_DIR/libmysqlclient.so" ] ; then MYSQL_LIB_DIR="$MYSQL_LIB_DIR" elif [ -f "/usr/lib/libmysqlclient.so" ] ; then MYSQL_LIB_DIR="/usr/lib" elif [ -f "/usr/lib/mysql/libmysqlclient.so" ] ; then MYSQL_LIB_DIR="/usr/lib/mysql" elif [ -f "/usr/local/lib/mysql/libmysqlclient.so" ] ; then MYSQL_LIB_DIR="/usr/local/lib/mysql" else echo "" echo "Couldn't find default MySQL lib directory." echo "Specify your MySQL lib directory manually." echo "Run $0 with:" echo "-with-mysql-libs /path/to/libmysqlclient.so" echo "" echo "Exiting..." exit 4 fi else if [ ! -f "${MYSQL_LIB_DIR}/libmysqlclient.so" ] ; then echo "" echo "Couldn't find MySQL library files. Check" echo "that your MySQL lib directory is correct" echo "Exiting..." exit 4 else export LD_LIBRARY_PATH="${MYSQL_LIB_DIR}:${LD_LIBRARY_PATH}" MYSQL_LIBDIR_WARN="MYSQL_LIBDIR_WARN" fi fi if [ "$MYSQL_INC_DIR" = bonkle ] ; then # Same deal as before MYSQL_INC_DIR="`mysql_config --cflags 2> /dev/null | sed s/-I//g | sed s/\'//g`" if [ -d "$MYSQL_INC_DIR" ] && [ -f "$MYSQL_INC_DIR/mysql/mysql.h" ] ; then MYSQL_INC_DIR="$MYSQL_INC_DIR" elif [ -f "$MYSQL_INC_DIR/mysql.h" ] ; then MYSQL_INC_DIR="$MYSQL_INC_DIR" HAVE_MYSQL_MYSQL_H="HAVE_MYSQL_MYSQL_H" elif [ -d "/usr/include/mysql" ] && [ -f "/usr/include/mysql/mysql.h" ] ; then MYSQL_INC_DIR="/usr/include" elif [ -f "/usr/include/mysql.h" ] ; then MYSQL_INC_DIR="/usr/include" HAVE_MYSQL_MYSQL_H="HAVE_MYSQL_MYSQL_H" elif [ -d "/usr/local/include" ] && [ -f "/usr/local/include/mysql/mysql.h" ] ; then MYSQL_INC_DIR="/usr/local/include" elif [ -f "/usr/local/include/mysql.h" ] ; then MYSQL_INC_DIR="/usr/local/include" HAVE_MYSQL_MYSQL_H="HAVE_MYSQL_MYSQL_H" else echo "" echo "Couldn't find default MySQL include directory." echo "Specify your MySQL include directory manually." echo "Run $0 with:" echo "-with-mysql-includes /path/to/mysql.h" echo "" echo "Exiting..." exit 4 fi else if [ -f "${MYSQL_INC_DIR}/mysql/mysql.h" ] ; then MYSQL_INC_DIR="${MYSQL_INC_DIR}/mysql" HAVE_MYSQL_MYSQL_H="HAVE_MYSQL_MYSQL_H" elif [ -f "${MYSQL_INC_DIR}/mysql.h" ] ; then HAVE_MYSQL_MYSQL_H="HAVE_MYSQL_MYSQL_H" else echo "" echo "Couldn't find MySQL include files. Check that" echo "your MySQL include directory is correct." echo "Exiting..." exit 4 fi fi if [ "$HAVE_MYSQL_MYSQL_H" = "HAVE_MYSQL_MYSQL_H" ] ; then cat >tmp/test.c < int main(void) { return 0; } EOT else cat >tmp/test.c < int main(void) { return 0; } EOT fi if run $CC $CC_FLAGS -I$MYSQL_INC_DIR -L$MYSQL_LIB_DIR -lmysqlclient tmp/test.c ; then CC_LIBS="$CC_LIBS -L$MYSQL_LIB_DIR -lmysqlclient -lz" CC_FLAGS="$CC_FLAGS -I$MYSQL_INC_DIR" echo2 "-lmysqlclient " else echo "" echo "Unable to compile with MySQL support. Check that the include" echo "and library directories are correct." exit 4 fi fi echo "" CC_LIBS="`echo $CC_LIBS | sed 's/^ +//'`" fi if [ "$USER_CC_LIBS" ] ; then CC_LIBS="$CC_LIBS $USER_CC_LIBS" echo "Additional user-supplied libraries: $USER_CC_LIBS" log user added \`"$USER_CC_LIBS'" fi if [ "$USE_MODULES" = "USE_MODULES" ] ; then cat >tmp/test.c < int main(void) { return RTLD_LOCAL; } EOT if run $CC $CC_FLAGS tmp/test.c ; then HAS_RTLD_LOCAL="yes" echo "has RTLD_LOCAL " else echo "no RTLD_LOCAL" fi fi ########################################################################### # OS specific behaviour echo2 "Looking for OS specific needs... " if [ "$OSTYPE" != bonkle ] ; then if [ "$OSTYPE" = "LINUX20" ] ; then echo2 "(cached) Linux 2.0 or 2.1 thread handling; " fi if [ "$OSTYPE" = "LINUX22" ] ; then echo2 "(cached) Linux 2.2+ thread handling; " fi if [ "$OSTYPE" = "JAGUAR" ] ; then echo2 "(cached) Jaguar (MacOS X 10.2.x); " fi if [ "$OSTYPE" = "MACOSX" ] ; then echo2 "(cached) MacOS X (10.0.x, 10.1.x); " fi else if [ "$THREAD" = "USE_THREADS" -a `uname -s` = "Linux" ] ; then VER=`uname -r` case $VER in 2.0*|2.1*) OSTYPE="LINUX20" echo2 "Linux 2.0 or 2.1 thread handling; " ;; *) OSTYPE="LINUX22" echo2 "Linux 2.2+ thread handling; " ;; esac else if [ `uname -s` = "Darwin" ] ; then VER=`uname -r` case $VER in 6.*) OSTYPE="JAGUAR" echo2 "Jaguar (MacOS X 10.2.x); " ;; *) OSTYPE="MACOSX" echo2 "MacOS X (10.0.x, 10.1.x); " ;; esac fi fi fi echo "" ########################################################################### # See what sizes various types are. MODE="check_int16 " echo2 "Looking for a 16-bit integer type... " if [ "$TYPE_INT16" ] ; then echo "(cached) $TYPE_INT16" log "cache supplied $TYPE_INT16" else cat >tmp/test.c <tmp/test.c <tmp/test.c <tmp/test.c <tmp/test.c <tmp/test.c <tmp/test.c <tmp/test.c <&1` log "sysname: $sysname" case $sysname in Linux) CP_ALL="/bin/cp -dpr"; log "guessing: cp -dpr";; *) CP_ALL="/bin/cp -pr"; log "guessing: cp -pr";; esac if [ ! -f tmp/test2 ] ; then run cp tmp/test tmp/test2 fi if run /bin/mkdir tmp/testA && run /bin/mkdir tmp/testB && run /bin/mv tmp/test2 tmp/testA then : ; else echo "" echo "" echo "*** WHOA THERE! ***" echo "" echo "A few simple mkdir's and mv's failed!" echo "Are you out of disk space?" exit 4 fi if run $CP_ALL tmp/testA/* tmp/testB && run cmp tmp/testA/test2 tmp/testB/test2 ; then echo "$CP_ALL" log \`"$CP_ALL' works" else log \`"$CP_ALL' doesn't work" run /bin/rm -rf tmp/testB/* if run sh -c '/bin/tar -Ccf tmp/testA - . | /bin/tar -Cxf tmp/testB -' ; then echo "tar (yuck)" CP_ALL="./bin/cp-recursive -t" log "using tar" else log "tar failed(!)" echo "" echo " Neither cp nor tar work! I give up." exit 2 fi fi fi ########################################################################### # Create files. echo2 "Creating sysconf.h... " cat >sysconf.h <>sysconf.h <>sysconf.h <>sysconf.h <>sysconf.h <>sysconf.h <>sysconf.h <>sysconf.h <>sysconf.h <>sysconf.h <>sysconf.h <>sysconf.h <>sysconf.h <>sysconf.h <>sysconf.h <>sysconf.h <Makefile.inc <>Makefile.inc <>Makefile.inc <>Makefile.inc <>Makefile.inc <config.cache PROGRAM="$PROGRAM" BINDEST="$BINDEST" DATDEST="$DATDEST" INSTALL="$INSTALL" CP_ALL="$CP_ALL" RUNGROUP="$RUNGROUP" UMASK=$UMASK IRCTYPE=$IRCTYPE IRCTYPE_DEF="$IRCTYPE_DEF" IRCTYPE_DEF2="$IRCTYPE_DEF2" ENCRYPTION="$ENCRYPTION" IMPORTSUPPORT="$IMPORTSUPPORT" THREAD="$THREAD" MYSQL="$MYSQL" USE_MODULES="$USE_MODULES" MODULE_PATH="$MODULE_PATH" HAVE_MYSQL_MYSQL_H="$HAVE_MYSQL_MYSQL_H" OSTYPE="$OSTYPE" CC="$CC" CC_FLAGS="$CC_FLAGS" CC_LFLAGS="$CC_LFLAGS" CC_LIBS="$CC_LIBS" TYPE_INT16=$TYPE_INT16 TYPE_INT32=$TYPE_INT32 HAVE_STRINGS_H=$HAVE_STRINGS_H HAVE_SYS_SELECT_H=$HAVE_SYS_SELECT_H HAVE_SYS_SYSPROTO_H=$HAVE_SYS_SYSPROTO_H HAVE_GETHOSTBYNAME_R=$HAVE_GETHOSTBYNAME_R HAVE_STRERROR=$HAVE_STRERROR HAVE_SYS_ERRLIST=$HAVE_SYS_ERRLIST HAVE_SNPRINTF=$HAVE_SNPRINTF BAD_SNPRINTF=$BAD_SNPRINTF HAVE_STRICMP=$HAVE_STRICMP HAVE_STRCASECMP=$HAVE_STRCASECMP HAVE_STRDUP=$HAVE_STRDUP HAVE_STRSPN=$HAVE_STRSPN HAVE_STRSIGNAL=$HAVE_STRSIGNAL HAVE_GETTIMEOFDAY=$HAVE_GETTIMEOFDAY HAVE_SETGRENT=$HAVE_SETGRENT HAVE_UMASK=$HAVE_UMASK HAVE_FORK=$HAVE_FORK HAVE_GETHOSTBYNAME=$HAVE_GETHOSTBYNAME MISSING="$MISSING" EOT echo "done." ########################################################################### # Delete the temporary directory we created. rm -rf tmp ########################################################################### # If MYSQL is enabled and the user specified a library dir # warn to include the directory in the LD_LIBRARY_PATH if [ "$MYSQL" = "USE_MYSQL" ] && [ "$MYSQL_LIBDIR_WARN" = "MYSQL_LIBDIR_WARN" ] ; then echo "" echo "BECAUSE YOU SPECIFIED A USER DEFINED LIBRARY DIRECTORY," echo "YOU MAY NEED TO ADD $MYSQL_LIB_DIR" echo "TO YOUR LD_LIBRARY_PATH VARIABLE BEFORE RUNNING ANOPE." echo "PRESS RETURN TO CONTINUE" read foo fi cat <