#!/bin/bash C_TEMPDIR=`mktemp -d /tmp/iwear-configure.XXXXXX` PQLIBDIRS="/usr/lib/ /usr/lib/pgsql/" PQINCDIRS="/usr/include/ /usr/include/pgsql" SYSLIB="/usr/lib" BAIL=no # Set the variables if not already set if [ -z $CC ] then CC=gcc fi if [ -z $CPP ] then CPP=g++ fi function check_version # {{{ { WANTED=$1 HAVE=$2 WHAT=$3 HAVE_MAJ=`echo $HAVE | cut -d"." -f1` HAVE_MIN=`echo $HAVE | cut -d"." -f2` HAVE_REL=`echo $HAVE | cut -d"." -f3` WANT_MAJ=`echo $WANTED | cut -d"." -f1` WANT_MIN=`echo $WANTED | cut -d"." -f2` WANT_REL=`echo $WANTED | cut -d"." -f3` VERSION_OK=yes if [ $HAVE_MAJ -lt $WANT_MAJ ] then VERSION_OK=no echo "fail" echo "Your Major Version of $WHAT ($HAVE) does not match the required on $WANTED" return else if [ $HAVE_MIN -lt $WANT_MIN ] then echo "fail" echo "Your Minor Version of $WHAT ($HAVE) does not match the required on $WANTED" VERSION_OK=no return else if [ $HAVE_REL -lt $WANT_REL ] then echo "fail" echo "Your Release Version of $WHAT ($HAVE) does not match the required on $WANTED" VERSION_OK=no return fi fi fi } # }}} function toupper # {{{ { sed y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/ } # }}} function tolower # {{{ { sed y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ } # }}} # Sets BAIL=yes if the Version is wrong function check_gcc #{{{ { BAIL=no WANTED_GCC=$1 echo -en "Checking for $CC >= $WANTED_GCC ... " if [ "$FORCEGCC" == "yes" ] then echo "(skipped - user override)" return fi TEMP_C="$C_TEMPDIR/check_gcc.c" TEMP_X=`mktemp $C_TEMPDIR/check_gcc.XXXXXX` cat > $TEMP_C <&1 >> $CONFLOG rm -f $TEMP_C read GCC_OK GCC_VER < <($TEMP_X) case $GCC_OK in yes) echo "$GCC_VER (OK)" BAIL=false ;; main) echo "fail" echo "The Main Release of your $CC ($GCC_VER) does not match the required one ($WANTED_GCC)." BAIL=yes ;; minor) echo "fail" echo "The Minor Release of your $CC ($GCC_VER) does not match the required one ($WANTED_GCC)." BAIL=yes ;; patch) echo "fail" echo "The Patch Release of your $CC ($GCC_VER) does not match the required one ($WANTED_GCC)." echo "You may use --force-gcc to override this, maybe it compiles, but don't file any Bug Reports if it fails" BAIL=yes ;; *) echo "fail" echo "We were not able to compile the version check test program." echo "This probably means that your $CC does not work properly, worry about it !!!" BAIL=yes ;; esac rm -f $TEMP_X } #}}} # Sets BAIL=yes if the Version is wrong function check_gpp #{{{ { BAIL=no WANTED_GPP=$1 echo -en "Checking for $CPP >= $WANTED_GPP ... " if [ "$FORCEGPP" == "yes" ] then echo "(skipped - user override)" return fi TEMP_CPP="$C_TEMPDIR/check_gcc.cpp" TEMP_X=`mktemp $C_TEMPDIR/check_gcc.XXXXXX` cat > $TEMP_CPP < #ifndef __GNUC_PATCHLEVEL__ #define __GNUC_PATCHLEVEL__ 0 #endif int main ( void ) { const char * wanted = "$WANTED_GPP"; int main,minor,patch; sscanf(wanted,"%d.%d.%d",&main,&minor,&patch); if ( main <= __GNUC__ ) { if ( minor <= __GNUC_MINOR__ ) { if ( patch <= __GNUC_PATCHLEVEL__ ) { printf("yes "); } else { printf("patch "); } } else { printf("minor "); } } else { printf("major "); } printf("%d.%d.%d\n",__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__); return 0; } XEOF $CPP $CPPFLAGS $TEMP_CPP -o $TEMP_X 2>&1 >> $CONFLOG rm -f $TEMP_CPP read GPP_OK GPP_VER < <($TEMP_X) case $GPP_OK in yes) echo "$GPP_VER (OK)" BAIL=false ;; main) echo "fail" echo "The Main Release of your $CPP ($GPP_VER) does not match the required one ($WANTED_GPP)." BAIL=yes ;; minor) echo "fail" echo "The Minor Release of your $CPP ($GPP_VER) does not match the required one ($WANTED_GPP)." BAIL=yes ;; patch) echo "fail" echo "The Patch Release of your $CPP ($GPP_VER) does not match the required one ($WANTED_GPP)." echo "You may use --force-gpp to override this, maybe it compiles, but don't file any Bug Reports if it fails" BAIL=yes ;; *) echo "fail" echo "We were not able to compile the version check test program." echo "This probably means that your $CPP does not work properly, worry about it !!!" BAIL=yes ;; esac rm -f $TEMP_X } #}}} # Sets BAIL=yes if the Version is wrong function check_gmake #{{{ { MAKE=`which gmake` if [ -z $MAKE ] then MAKE=`which make` fi WANTED_VER=$1 WANTED_MAJOR=`echo $1 | cut -d"." -f1` WANTED_MINOR=`echo $1 | cut -d"." -f2` echo -n "Checking for GNU Make >= $WANTED_VER ... " VER=`$MAKE --version 2>/dev/null | grep GNU | head -1 | sed 's/[^0-9\.]//g'` if [ -z "$VER" ] then echo "fail" echo "This Environment is compatible with GNU Make only." echo "Please install GNU Make or provide a link called gmake within \$PATH" BAIL=yes return 1 fi VER_MAJOR=`echo $VER | cut -d"." -f1` VER_MINOR=`echo $VER | cut -d"." -f2` if [ $VER_MAJOR -lt $WANTED_MAJOR ] then echo "fail" echo "Your Major Version of $MAKE ($VER) does not match the required on $WANTED_VER" BAIL=yes return else if [ $VER_MINOR -lt $WANTED_MINOR ] then echo "fail" echo "Your Minor Version of $MAKE ($VER) does not match the required on $WANTED_VER" BAIL=yes return else echo "$VER (OK)" fi fi } #}}} # Sets $PKG_CONFIG to the pkg-config binary, leaves it empty if not present or # not to be used by user override function check_pkg_config #{{{ { PKG_CONFIG=`which pkg-config 2>/dev/null` echo -n "Checking for pkg-config ... " if [ -z "$PKG_CONFIG" ] then echo "no" else if [ "$NO_PKG_CONFIG" == "yes" ] then echo "skipped (user override)" PKG_CONFIG="" else echo "yes ($PKG_CONFIG)" fi fi } #}}} # The script needs sed sometimes function check_sed #{{{ { echo -en "Checking for sed ... " SED=`which sed 2>/dev/null` if [ -z "$SED" ] then BAIL="yes" echo "(fail) No sed in \$PATH" return fi echo "(OK)" } # }}} # Check for installation of pgsql libraries and the headers # sets PG_INCLUDE and PG_LIBDIR and BAIL if not found or version too old function check_pgsql # {{{ { WANTED_VER=$1 echo -en "Checking for PostgreSQL >= $WANTED_VER ... " PG_CONFIG=`which pg_config 2>/dev/null` if [ -z "$PG_CONFIG" ] then echo -en "(no pg_config) " TEMP_C="$C_TEMPDIR/check_libpq.c" TEMP_X=`mktemp $C_TEMPDIR/check_libpq.XXXXXX` cat > $TEMP_C <> $CONFLOG 2>&1 if [ $? == 0 ] then PG_LIBDIR="$libdir" break fi done if [ -z "$PG_LIBDIR" ] then echo "failed. Could not find directory where libpq.so lives in" BAIL=yes return fi cat > $TEMP_C < int main ( void ) { printf(PG_VERSION); return 0; } XEOF for incdir in $PQINCDIRS do # echo -e "Testing in $incdir" $CC $CFLAGS -I $incdir $TEMP_C -o $TEMP_X >> $CONFLOG 2>&1 if [ $? == 0 ] then PG_INCLUDE="$incdir" PG_VER=`$TEMP_X` break fi done if [ -z "$PG_INCLUDE" ] then echo "failed. Could not find directory where libpq-fe.h lives in" BAIL=yes return fi # PG_VER="$WANTED_VER" else PG_VER=`$PG_CONFIG --version | cut -d" " -f2-` PG_INCLUDE=`$PG_CONFIG --includedir` PG_LIBDIR=`$PG_CONFIG --libdir` fi check_version $WANTED_VER $PG_VER "PostgreSQL" if [ "$VERSION_OK" != "yes" ] then BAIL=yes return fi echo -e "$PG_VER (OK)" } # }}} function check_libpq # {{{ { echo -en "Checking for usable libpq ... " TEMP_C="$C_TEMPDIR/check_libpq.c" TEMP_X=`mktemp $C_TEMPDIR/check_libpq.XXXXXX` cat > $TEMP_C < int main ( void ) { PQconnectStart("Hello World"); return 0; } XEOF $CC $CFLAGS -I $PG_INCLUDE -L $PG_LIBDIR -lpq $TEMP_C -o $TEMP_X >> $CONFLOG 2>&1 if [ ! -x "$TEMP_X" ] then echo "fail" BAIL=yes echo "We were not able to compile the test program for libpq" fi rm -f $TEMP_C rm -f $TEMP_X echo "(OK)" } #}}} function check_strnlen # {{{ { echo -en "Checking for strnlen ... " TEMP_C="$C_TEMPDIR/check_strnlen.c" TEMP_X=`mktemp $C_TEMPDIR/check_strnlen.XXXXXX` cat > $TEMP_C < int main ( void ) { strnlen(NULL,0); } XEOF $CC $TEMP_C -o $TEMP_X >> $CONFLOG 2>&1 if [ -x "$TEMP_X" ] then HAVE_STRNLEN="yes" echo "yes" else HAVE_STRNLEN="no" echo "no" fi rm -f $TEMP_C rm -f $TEMP_X } #}}} function check_strcasestr # {{{ { echo -en "Checking for strcasestr ... " TEMP_C="$C_TEMPDIR/check_strcasestr.c" TEMP_X=`mktemp $C_TEMPDIR/check_strcasestr.XXXXXX` cat > $TEMP_C < int main ( void ) { strcasestr(NULL,NULL); } XEOF $CC $TEMP_C -o $TEMP_X >> $CONFLOG 2>&1 if [ -x "$TEMP_X" ] then HAVE_STRCASESTR="yes" echo "yes" else HAVE_STRCASESTR="no" echo "no" fi rm -f $TEMP_C rm -f $TEMP_X } #}}} function check_vasprintf # {{{ { echo -en "Checking for vasprintf ... " TEMP_C="$C_TEMPDIR/check_vasprintf.c" TEMP_X=`mktemp $C_TEMPDIR/check_vasprintf.XXXXXX` cat > $TEMP_C < #include int main ( void ) { vasprintf(NULL,0); } XEOF $CC $TEMP_C -o $TEMP_X >> $CONFLOG 2>&1 if [ -x "$TEMP_X" ] then HAVE_VASPRINTF="yes" echo "yes" else HAVE_VASPRINTF="no" echo "no" fi rm -f $TEMP_C rm -f $TEMP_X } #}}} function check_strerror_r # {{{ { echo -en "Checking for strerror_r ... " TEMP_C="$C_TEMPDIR/check_strerror_r.c" TEMP_X=`mktemp $C_TEMPDIR/check_strerror_r.XXXXXX` cat > $TEMP_C < int main ( void ) { strerror_r(0,NULL,0); } XEOF $CC $TEMP_C -o $TEMP_X >> $CONFLOG 2>&1 if [ -x "$TEMP_X" ] then HAVE_STRERROR_R="yes" echo "yes" else HAVE_STRERROR_R="no" echo "no" fi rm -f $TEMP_C rm -f $TEMP_X } #}}} function check_dlopen # {{{ { echo -en "Checking for dlopen ... " TEMP_C="$C_TEMPDIR/check_dlopen.c" TEMP_X=`mktemp $C_TEMPDIR/check_dlopen.XXXXXX` cat > $TEMP_C < #include int main ( void ) { dlopen(NULL,0); } XEOF DLLIB="none" DLLIBS="# -ldl" for dllib in $DLLIBS do dllib=`echo $dllib | sed 's/#//g'` # echo "Checking with $dllib" $CC $dllib $TEMP_C -o $TEMP_X >> $CONFLOG 2>&1 if [ -x "$TEMP_X" ] then echo "(OK) with $dllib" DLLIB=$dllib break fi done if [ "$DLLIB" == "none" ] then echo "fail. We were not able to determine how to use dlopen()" BAIL=yes fi LIBLIBS="$LIBLIBS $DLLIB" rm -f $TEMP_C rm -f $TEMP_X } #}}} function check_sdl # {{{ { echo -en "Checking for sdl ... " TEMP_C="$C_TEMPDIR/check_sdl.c" TEMP_X=`mktemp $C_TEMPDIR/check_sdl.XXXXXX` cat > $TEMP_C < int main ( void ) { int i=0; } XEOF $CC $TEMP_C -o $TEMP_X >> $CONFLOG 2>&1 if [ -x "$TEMP_X" ] then HAVE_SDL="yes" echo "yes, you have *S*D*L* installed on your great System" else HAVE_SDL="no" echo "no SDL found, please install the SDL_devel package to continue" fi rm -f $TEMP_C rm -f $TEMP_X } #}}} function check_speex # {{{ { echo -en "Checking for speex codec ... " TEMP_C="$C_TEMPDIR/check_speex.c" TEMP_X=`mktemp $C_TEMPDIR/check_speex.XXXXXX` cat > $TEMP_C < int main ( void ) { int i=0; } XEOF $CC $TEMP_C -o $TEMP_X >> $CONFLOG 2>&1 if [ -x "$TEMP_X" ] then HAVE_SDL="yes" echo "yes, you have *SPEEX* installed on your great System" else HAVE_SDL="no" echo "SPEEX-CODEC not installed, you have to install the speex_devel package to continue" fi rm -f $TEMP_C rm -f $TEMP_X } #}}} function check_doxygen #{{{ { echo -en "Checking for doxygen ... " DOXYGEN=`which doxygen 2>/dev/null` if [ -z "$DOXYGEN" ] then DOXYGEN="ls" echo "no" BAIL="yes" cat > doc/EMPTY </dev/null " else echo -e "$DOXYGEN (OK)" fi } # }}} function check_libpqxx # {{{ { WANTED_VER=$1 echo -en "Checking for usable libpqxx ... " TEMP_CPP="$C_TEMPDIR/check_libpq.cpp" TEMP_X=`mktemp $C_TEMPDIR/check_libpq.XXXXXX` cat > $TEMP_CPP < #include int main ( void ) { pqxx::connection Conn; int maj, min, rel; printf(VERSION); } XEOF $CPP $CPPFLAGS -I $PG_INCLUDE -lpqxx $TEMP_CPP -o $TEMP_X >> $CONFLOG 2>&1 if [ ! -x $TEMP_X ] then echo -e "fail" echo -e "We were not able to generate a check program, please see $CONFLOG for details" BAIL=yes return fi echo "(OK)" PQX_VER=`$TEMP_X 2>/dev/null` echo -en "Checking for libpqxx >= $WANTED_VER ... " check_version $WANTED_VER $PQX_VER "libpqxx" if [ "$VERSION_OK" != "yes" ] then BAIL=yes return fi rm -f $TEMP_CPP rm -f $TEMP_X echo -e "$PQX_VER (OK)" } #}}} function check_echo # {{{ { echo -en "Checking how to invoke echo in make ... " OUTPUT=`echo -en` if [ -z "$OUTPUT" ] then echo " with -en" ECHOEN="echo -en" else echo " plain" ECHOEN="echo" fi } # }}} # This generates the makefile from all the set variables function gen_makefile # {{{ { if [ ! -z "$C_TEMPDIR" ] then rm -rf $C_TEMPDIR fi MAKEFILE=$1 echo -e "Generating $MAKEFILE" cat > $MAKEFILE <> $MAKEFILE fi if [ ! -z "$CPPFLAGS" ] then echo -e "Overriding \$CPPFLAGS to \"$CPPFLAGS\"" echo -e "\nCPPFLAGS=$CPPFLAGS" >> $MAKEFILE fi echo -e "\nCC=$CC" >> $MAKEFILE echo -e "CPP=$CPP" >> $MAKEFILE echo -e "\nLIBNAME=$LIBNAME" >> $MAKEFILE echo -e "LIBVERSION=$VERSION" >> $MAKEFILE echo -e "PREFIX=$PREFIX" >> $MAKEFILE echo -e "SYSCONF=$SYSCONF" >> $MAKEFILE echo -e "LIBS=$LIBS" >> $MAKEFILE echo -e "LIBLIBS=$LIBLIBS" >> $MAKEFILE echo -e "INCLUDES=$INCLUDES" >> $MAKEFILE echo -e "EXTRACLEANFILES=$EXTRACLEANFILES" >> $MAKEFILE echo -e "STERILFILES=$STERILFILES" >> $MAKEFILE echo -e "STERILDIRS=$STERILDIRS" >> $MAKEFILE echo -e "LIBSEARCH=/usr/lib/" >> $MAKEFILE echo -e "DISTNAME=$DISTNAME" >> $MAKEFILE echo -e "DISTDIR=$DISTDIR" >> $MAKEFILE echo -e "DOXYGEN=$DOXYGEN" >> $MAKEFILE echo -e "ECHOEN=$ECHOEN" >> $MAKEFILE echo -e "DLLIB=$DLLIB" >> $MAKEFILE echo >> $MAKEFILE echo -en "SRCDIRS=" >> $MAKEFILE for dir in $SRCDIRS do echo -en "\$(TOPDIR)/$dir " >> $MAKEFILE done echo >> $MAKEFILE echo >> $MAKEFILE #MAINSRC=`echo -e $SRDIRS | cut -d" " -f1` if [ "$HAVE_STRCASESTR" == "no" ] then LIBFILES_src="$LIBFILES_src strcasestr.o" fi if [ "$HAVE_STRNLEN" == "no" ] then LIBFILES_src="$LIBFILES_src strnlen.o" fi if [ ! -z "$PG_INCLUDE" ] then echo "INCLUDES:=\$(INCLUDES) -I $PG_INCLUDE" >> $MAKEFILE fi for dir in $SRCDIRS do VARNAME="\$LIBFILES_$dir" eval "FILES=$VARNAME" echo -e "$VARNAME=$FILES" | sed 's/^\$//' >> $MAKEFILE done } # }}} # This generates the config.h header function gen_config # {{{ { CONFIG_H=$1 cat > $CONFIG_H <> $CONFIG_H echo -e "#define __CONFIG_H" >> $CONFIG_H echo -e "\n#define PREFIX \"$PREFIX\"" >> $CONFIG_H echo -e "\n#define SYSCONF \"$SYSCONF\"" >> $CONFIG_H echo -e "#define ARCH \"$CPU\"" >> $CONFIG_H # TODO We need to really check for gnu compatible environment echo -e "\n#ifndef _GNU_SOURCE" >> $CONFIG_H echo -e "#define _GNU_SOURCE" >> $CONFIG_H echo -e "#endif" >> $CONFIG_H if [ "$HAVE_STRNLEN" == "yes" ] then echo -e "\n#define HAVE_STRNLEN 1" >> $CONFIG_H fi if [ "$HAVE_STRCASESTR" == "yes" ] then echo -e "\n#define HAVE_STRCASESTR 1" >> $CONFIG_H fi if [ "$HAVE_VASPRINTF" == "yes" ] then echo -e "\n#define HAVE_VASPRINTF 1" >> $CONFIG_H fi if [ "$HAVE_STRERROR_R" == "yes" ] then echo -e "\n#define HAVE_STRERROR_R 1" >> $CONFIG_H fi echo -e "\n#endif" >> $CONFIG_H VPREF=`echo -e $DISTNAME | toupper` if [ ! -z "$PG_INCLUDE" ] then echo -e "#define HAVE_IWPGDB 1" >> $CONFIG_H fi read V_MAJOR V_MINOR V_RELEASE < <(echo $VERSION | sed 's/\./ /g'); echo -e "\n#ifndef ${VPREF}_MAJOR" >> $CONFIG_H echo -e "#define ${VPREF}_MAJOR $V_MAJOR" >> $CONFIG_H echo -e "#define ${VPREF}_MINOR $V_MINOR" >> $CONFIG_H echo -e "#define ${VPREF}_RELEASE $V_RELEASE" >> $CONFIG_H echo -e "#endif" >> $CONFIG_H } # }}}