#!/bin/false # vim:ft=sh # Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2012 # # This file is part of roard a part of RoarAudio, # a cross-platform sound system for both, home and professional use. # See README for details. # # This file is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3 # as published by the Free Software Foundation. # # RoarAudio is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this software; see the file COPYING. If not, write to # the Free Software Foundation, 51 Franklin Street, Fifth Floor, # Boston, MA 02110-1301, USA. test_libroar() { _min="$1" [ "$_min" = '' ] && _min='current' echo -n "checking for version of roaraudio... " if roar-config --compare-versions current ge "$_min" then echo "`roar-config --version`, good" return 0 else _ver="`roar-config --version 2> /dev/null`" if [ "$_ver" = '' ] then echo "unknown. bad." else echo "$_ver, too old (minimum required: $_min)" fi return 1 fi } test_pkgversion() { echo -n "checking for version of this package... " VERSION=`head -n 1 ChangeLog | cut -d' ' -f2` echo "$VERSION" return 0 } test_buildstamp() { echo -n "checking for build stamp of this package... " BUILD_STAMP="`date -u +'%F %X'` (`id -un`@`uname -n`)" echo "$BUILD_STAMP" return 0 } test_cc() { echo -n "checking for C compiler... " if [ "$CC" != '' ] then echo $CC return 0 else CC=$(which gcc cc 2> /dev/null | grep ^/ | head -n 1) if [ "$CC" = '' ] then echo 'none' exit 1; fi echo $CC return 0 fi } test_ranlib() { echo -n "checking for ranlib... " if [ "$RANLIB" != '' ] then echo $RANLIB return 0 else _guess=`echo $CC | sed 's/[gp]*cc\(-.*\)*//'` RANLIB=$(which ${_guess}ranlib ranlib 2> /dev/null | grep ^/ | head -n 1) if [ "$RANLIB" = '' ] then echo 'none' return 1 fi echo $RANLIB return 0 fi } test_pkgconfig() { echo -n "checking for pkg-config... " PKG_CONFIG=$(which pkg-config false 2> /dev/null | grep ^/ | head -n 1) if $PKG_CONFIG --help > /dev/null 2> /dev/null then echo $PKG_CONFIG return 0 else echo no return 1 fi } test_sysname() { echo -n "checking for sysname... " SYSNAME=$(uname -s) echo "$SYSNAME" return 0 } test_crosscompile() { echo -n 'checking if we cross compile... ' if $CROSS_COMPILE then echo yes echo -n "checking for exec helper... " if [ "$EXEC_HELPER" = '' ] then if $TARGET_WIN32 then EXEC_HELPER=$(which wine 2> /dev/null | grep ^/ | head -n 1) if [ "$EXEC_HELPER" = '' ] then echo 'none (please install wine)' else echo "$EXEC_HELPER" fi else echo 'none (unknown)' fi else echo "$EXEC_HELPER" fi echo -n "checking for sysname of target... " if $TARGET_CYGWIN then SYSNAME=cygwin elif $TARGET_WIN32 then SYSNAME=win32 else SYSNAME=unknown fi echo "$SYSNAME" return 0 else echo no return 1 fi } test_wextra() { # Check for -Wextra #Wextra echo -n "checking if compiler supports -Wextra... " echo 'int main (void) { return 0; }' > $TF_C if $CCTF -Wextra 2> /dev/null; then echo yes Wextra=true return 0 else echo no Wextra=false return 1 fi } test_cp_v() { echo -n 'checking if cp supports -v... ' if cp -v --help > /dev/null 2> /dev/null then echo "cp_v=-v" >&4 echo yes return 0 else echo "cp_v=" >&4 echo no return 1 fi } test_bin_format() { echo -n "checking for binary format... " echo "TEST BIN FORMAT:" >&5 { echo "#include " echo echo "int main (void) {" echo " char buf[512];" echo " size_t len;" echo echo " len = fread(buf, 1, sizeof(buf), stdin);" echo " if ( len < 4 )" echo " return 1;" echo echo " if ( buf[0] == '\\177' && buf[1] == 'E' && buf[2] == 'L' && buf[3] == 'F' ) {" echo " printf(\"ELF%c\", (char)10);" echo " return 0;" echo " }" echo echo " if ( buf[0] == 'M' && buf[1] == 'Z' ) {" echo " printf(\"MZ%c\", (char)10);" echo " return 0;" echo " }" echo echo " return 1;" echo "}" } > $TF_C echo "--- BEGIN OF CODE BLOCK ---" >&5 cat $TF_C >&5 echo "--- END OF CODE BLOCK ---" >&5 echo "BIN FORMAT() HAS COMPILER/LINKER OUTPUT:" >&5 echo "--- BEGIN OF CHILD OUTPUT BLOCK ---" >&5 $CCTF >&5 2>&5; R=$? echo "--- END OF CHILD OUTPUT BLOCK ---" >&5 if [ "$R" = '0' ] then BIN_FORMAT=`$EXEC_HELPER $TF_E < $TF_E 2> /dev/null` R=$? if [ "$R" = '0' ] then echo "$BIN_FORMAT" echo "BIN FORMAT() IS '$BIN_FORMAT'" >&5 return 0 else BIN_FORMAT=unknown echo 'unknown' echo "BIN FORMAT() NOT KNOWN" >&5 return 1 fi else BIN_FORMAT=unknown echo 'unknown' echo "BIN FORMAT() NOT KNOWN" >&5 return 1 fi } test_linkdeps() { if [ "$LINK_DEPS" = 'auto' ] then if [ "$BIN_FORMAT" = 'ELF' ] then LINK_DEPS='indirect' else LINK_DEPS='full' fi fi echo "LINK_DEPS=$LINK_DEPS" >&4 echo "checking for linkage model... $LINK_DEPS" return 0 } test_lib () { _have_libs=false _have_headers=false _defs='' echo > $TF_C $NEED_GNU_SOURCE && _defs="$_defs -D_GNU_SOURCE" name="$1" last_tested_object="$name" echo -n "checking for $name... " echo "TEST LIB: $name" >&5 shift; if [ "$infotext" = '' ] then _info='' else _info=" ($infotext)" fi LIBS='' while [ "$1" != '--' ] do echo "LIB($name) HAS LIB INFO: $1" >&5 case "$1" in 'c'|'-lc') :; # no need to do anything ;; '-'*) LIBS="$LIBS $1" _have_libs=true ;; *) LIBS="$LIBS -l$1" _have_libs=true ;; esac shift; done shift; echo "LIB($name) IS TESTED USING LIBS: $LIBS" >&5 while [ "$1" != '' ] do _h="$1"; shift; _envname=`echo "$_h" | to_escaped` eval "_t=\$libname_$_envname" echo "LIB($name) DEPENDS ON $_h($_envname) with state '$_t'" >&5 if [ "$_t" = 'false' ] then echo "// not including <$_h> as it was tested as not present" >> $TF_C else echo "#include <$_h>" >> $TF_C _have_headers=true fi done echo 'int main (void) { return 0; }' >> $TF_C if [ "$_have_libs" = 'false' -a "$_have_headers" = 'false' ] then echo "no (nothing left to test)$_info" echo "LIB($name) HAS NOTHING TO TEST" >&5 return 1 fi echo "LIB($name) IS TESTED USING TEST CODE:" >&5 echo "--- BEGIN OF CODE BLOCK ---" >&5 cat $TF_C >&5 echo "--- END OF CODE BLOCK ---" >&5 echo "LIB($name) HAS COMPILER/LINKER OUTPUT:" >&5 echo "--- BEGIN OF CHILD OUTPUT BLOCK ---" >&5 $CCTF $_defs $LIBS >&5 2>&5; R=$? echo "--- END OF CHILD OUTPUT BLOCK ---" >&5 if [ "$R" = '0' ] then echo "yes$_info" echo "LIB($name) WAS FOUND" >&5 else echo "no$_info" echo "LIB($name) NOT FOUND" >&5 fi return $R } test_lib_defmake () { def="$1" subdir="$2" shift shift name="$1" lib="$2" shift echo "TEST LIB: $name" >&5 [ "$subdir" = '%' ] && subdir='' envlib=`echo "$lib" | cut -d/ -f1 | to_escaped` envname=`echo "$name" | to_escaped` if [ "$envlib" = 'c' ] then envlib="$envname" fi echo "LIB($name) HAS envlib='$envlib', envname='$envname'" >&5 if [ "$lib" != '--' ] then echo "EVAL: _no=\$no_lib_$envlib" >&5 eval _no="\$no_lib_$envlib"; $MINIMAL && _no='XXX' if [ "$_no" != '' ] then echo "checking for $name... disabled by user" echo "LIB($name) IS DISABLED BY USER" >&5 [ "$subdir" != '' ] && \ echo "subdir_$subdir=" >&4 echo "lib_$envlib=" >&4 return; fi fi lib="$lib/" libn=`echo $lib | cut -d/ -f1` is_fatal=`echo $lib | cut -d/ -f2` lib="$libn" # echo "is_fatal(i)=$is_fatal" >&5 if [ "$is_fatal" = '' -o "$is_fatal" = 'no' -o "$is_fatal" = 'false' ] then is_fatal=false else is_fatal=true shift; # maybe we have a pkg name, not a lib fi echo "LIB($name) HAS FATAL FLAG SET TO $is_fatal" >&5 # echo "is_fatal(b)=$is_fatal" >&5 LIBS=$($PKG_CONFIG --silence-errors --cflags --libs $lib 2> /dev/null) if [ "$?" != '0' ] then if $is_fatal then echo "checking for $name... no (fatal config errors)" echo "LIB($name) HAS FATAL ERRORS" >&5 echo "LIB($name) NOT FOUND" >&5 [ "$subdir" != '' ] && \ echo "subdir_$subdir=" >&4 echo "lib_$envlib=" >&4 return fi LIBS="-l$lib" fi echo "LIB($name) HAS LIBS: $LIBS" >&5 if test_lib "$name" $LIBS "$@" then subdir_var='subdir_'"`echo $subdir | to_escaped`" echo "#define $def" >&3 [ "$subdir" != '' ] && \ echo "$subdir_var=$subdir" >&4 [ "$lib" != 'c' ] && \ echo "lib_$envlib=$LIBS" >&4 if [ "$lib" != 'c' ] then eval "lib_$envlib='$LIBS'" else echo "LIB($name) SETS libname_$envname=true" >&5 eval "libname_$envname=true" fi return 0 else [ "$subdir" != '' ] && \ echo "subdir_$subdir=" >&4 [ "$lib" != 'c' ] && \ echo "lib_$envlib=" >&4 echo "LIB($name) SETS libname_$envname=false" >&5 eval "libname_$envname=false" return 1 fi echo >&5 echo >&5 } test_tool_defmake () { DEF="$1" NAME="$2" shift; shift; echo -n "checking for $NAME... " echo "TEST TOOL: $NAME" >&5 if $RUNTIME_DETECT then echo "$1 (runtime detect)" echo "TOOL($NAME) WILL BE RUNTIME DETECTED" >&5 echo "#define $DEF "\""$1"\" >&3 return 0 elif $MINIMAL then echo "disabled by user (minimalstic build)" echo "TOOL($NAME) IS DISABLED BY USER" >&5 return 1 else LIST=$(which "$@" 2> /dev/null | grep ^/ | head -n 1) if [ "$LIST" = '' ] then echo 'no' echo "TOOL($NAME) NOT FOUND" >&5 return 1 else echo $LIST echo "#define $DEF "\""$LIST"\" >&3 echo "TOOL($NAME) IS AT $LIST" >&5 return 0 fi fi } test_func_defmake () { _defs='' DEF="$1" NAME="$2" shift; shift; echo -n "checking for $NAME()... " CALL="$1" shift; $NEED_GNU_SOURCE && _defs="$_defs -D_GNU_SOURCE" if [ "$infotext" = '' ] then _info='' else _info=" ($infotext)" fi LIBS='' _funcname=`echo "$NAME" | to_escaped` while [ "$1" != '--' ] do case "$1" in 'c'|'-lc') :; # no need to do anything ;; '-'*) LIBS="$LIBS $1" ;; *) LIBS="-l$1" ;; esac shift; done shift; # skip '--' echo "TEST FUNCTION: $NAME" >&5 { while [ "$1" != '' ] do _h="$1"; shift; _envname=`echo "$_h" | to_escaped` eval "_t=\$libname_$_envname" echo "LIB($name) DEPENDS ON $_h($_envname) with state '$_t'" >&5 if [ "$_t" = 'false' ] then echo "// not including <$_h> as it was tested as not present" else echo "#include <$_h>" fi done echo 'int main (void) {' echo " $CALL;" echo ' return 0;' echo '}' } > $TF_C echo "--- BEGIN OF CODE BLOCK ---" >&5 cat $TF_C >&5 echo "--- END OF CODE BLOCK ---" >&5 echo "FUNCTION($NAME) HAS COMPILER/LINKER OUTPUT:" >&5 echo "--- BEGIN OF CHILD OUTPUT BLOCK ---" >&5 $CCTF $_defs $LIBS >&5 2>&5; R=$? echo "--- END OF CHILD OUTPUT BLOCK ---" >&5 if [ "$R" = '0' ] then eval funcname_$_funcname=true echo "#define $DEF" >&3 echo "FUNCTION($NAME) IS OK" >&5 echo "yes$_info" return 0 else eval funcname_$_funcname=false echo "FUNCTION($NAME) IS NOT OK" >&5 echo "no$_info" return 1 fi } test_const_defmake () { DEF="$1" NAME="$2" shift; shift; echo -n "checking for constant $NAME... " TYPE="$1" CONST="$2" shift; shift; LIBS='' while [ "$1" != '--' ] do case "$1" in 'c'|'-lc') :; # no need to do anything ;; '-'*) LIBS="$LIBS $1" ;; *) LIBS="-l$1" ;; esac shift; done shift; # skip '--' echo "TEST CONST: $NAME" >&5 { while [ "$1" != '' ] do _h="$1"; shift; _envname=`echo "$_h" | to_escaped` eval "_t=\$libname_$_envname" echo "LIB($name) DEPENDS ON $_h($_envname) with state '$_t'" >&5 if [ "$_t" = 'false' ] then echo "// not including <$_h> as it was tested as not present" else echo "#include <$_h>" fi done case "$TYPE" in ':int') _type='int' ;; ':float') _type='float' ;; ':ptr') _type='void *' ;; *) _type="$TYPE" ;; esac echo 'int main (void) {' echo " $_type x;" echo " x = ($_type)$CONST;" echo ' return 0;' echo '}' } > $TF_C echo "--- BEGIN OF CODE BLOCK ---" >&5 cat $TF_C >&5 echo "--- END OF CODE BLOCK ---" >&5 echo "CONST($NAME) HAS COMPILER/LINKER OUTPUT:" >&5 echo "--- BEGIN OF CHILD OUTPUT BLOCK ---" >&5 $CCTF $LIBS >&5 2>&5; R=$? echo "--- END OF CHILD OUTPUT BLOCK ---" >&5 if [ "$R" = '0' ] then echo "#define $DEF" >&3 echo "CONST($NAME) IS OK" >&5 echo yes return 0 else echo "CONST($NAME) IS NOT OK" >&5 echo no return 1 fi } test_var_defmake () { DEF="$1" NAME="$2" shift; shift; echo -n "checking for global variable $NAME... " TYPE="$1" VAR="$2" shift; shift; LIBS='' while [ "$1" != '--' ] do case "$1" in 'c'|'-lc') :; # no need to do anything ;; '-'*) LIBS="$LIBS $1" ;; *) LIBS="-l$1" ;; esac shift; done shift; # skip '--' echo "TEST VAR: $NAME" >&5 { while [ "$1" != '' ] do _h="$1"; shift; _envname=`echo "$_h" | to_escaped` eval "_t=\$libname_$_envname" echo "LIB($name) DEPENDS ON $_h($_envname) with state '$_t'" >&5 if [ "$_t" = 'false' ] then echo "// not including <$_h> as it was tested as not present" else echo "#include <$_h>" fi done case "$TYPE" in ':int') _type='int' ;; ':float') _type='float' ;; ':ptr') _type='void *' ;; *) _type="$TYPE" ;; esac echo 'int main (void) {' echo " $_type x;" echo " x = ($_type)$VAR;" echo " $VAR = x;" echo ' return 0;' echo '}' } > $TF_C echo "--- BEGIN OF CODE BLOCK ---" >&5 cat $TF_C >&5 echo "--- END OF CODE BLOCK ---" >&5 echo "VAR($NAME) HAS COMPILER/LINKER OUTPUT:" >&5 echo "--- BEGIN OF CHILD OUTPUT BLOCK ---" >&5 $CCTF $LIBS >&5 2>&5; R=$? echo "--- END OF CHILD OUTPUT BLOCK ---" >&5 if [ "$R" = '0' ] then echo "#define $DEF" >&3 echo "VAR($NAME) IS OK" >&5 echo yes return 0 else echo "VAR($NAME) IS NOT OK" >&5 echo no return 1 fi } test_version () { DEF="$1" NAME="$2" PKGNAME="$3" echo -n "checking for version of $NAME... " _ver=$($PKG_CONFIG --modversion $PKGNAME 2> /dev/null) if [ "$_ver" = '' ] then _ver=unknown fi echo $_ver _ver_def=$(echo $_ver | to_escaped | to_upper) echo "#define ${DEF}_$_ver_def" >&3 echo "$_ver" | if grep '^[0-9]*\.[0-9]*\.[0-9]*$' > /dev/null then _ver_vdef=$(echo "$_ver" | sed 's/^\([0-9]*\)\.\([0-9]*\)\.\([0-9]\)*$/_ROAR_MKVERSION(\1, \2, \3)/') echo "#define ${DEF} $_ver_vdef" >&3 else echo "#define ${DEF} 0" >&3 fi return 0 } test_type () { DEF="$1" NAME="$2" INITVAL="$3" DASHDASH="$4" shift; shift; if [ "$#" -ge '2' ] then shift; shift; fi HEADERS="stdint.h string.h unistd.h sys/types.h $*" #including headers here let #them get checked for presence. [ "$INITVAL" = '' ] && INITVAL='0' echo -n "checking for type $NAME... " echo "TEST TYPE: $NAME" >&5 echo "// type test for type $NAME" > $TF_C # need a clean file, write something for _h in $HEADERS do _envname=`echo "$_h" | to_escaped` eval "_t=\$libname_$_envname" echo "TYPE($NAME) DEPENDS ON $_h($_envname) with state '$_t'" >&5 if [ "$_t" = 'false' ] then echo "// not including <$_h> as it was tested as not present" >> $TF_C else echo "#include <$_h>" >> $TF_C fi done echo "int main (void) { $NAME _var = $INITVAL; return 0; }" >> $TF_C echo "--- BEGIN OF CODE BLOCK ---" >&5 cat $TF_C >&5 echo "--- END OF CODE BLOCK ---" >&5 echo "TYPE($NAME) HAS COMPILER/LINKER OUTPUT:" >&5 echo "--- BEGIN OF CHILD OUTPUT BLOCK ---" >&5 $CCTF >&5 2>&5; R=$? echo "--- END OF CHILD OUTPUT BLOCK ---" >&5 if [ "$R" = '0' ] then echo "#define $DEF" >&3 echo 'ok' echo "TYPE($NAME) IS OK" >&5 return 0 else echo 'not found' echo "TYPE($NAME) NOT FOUND" >&5 return 1 fi } test_pa_type () { DEF="$1" NAME="$2" TYPE="$3" V0="$4" V1="$5" TEST="$6" shift; shift; shift; shift; shift; shift; HEADER="$*" RS='%s' case "$TYPE" in 'type') MSG="checking for type of $NAME()... " ;; 'args:'*) MSG="checking for argument types of $NAME()... " RS=`echo "$TYPE" | cut -d: -f2` ;; esac; echo -n "$MSG" echo '#include ' > $TF_C for _h in $HEADERS do echo "#include <$_h>" >> $TF_C done echo '#include ' >> $TF_C echo 'int main (void) { return 0; }' >> $TF_C echo "$TEST" >> $TF_C if $CCTF 2> /dev/null; then R="$V0" else R="$V1" fi echo "#define $DEF $R" >&3 printf "$RS\n" "$R" return 0 } test_winsock() { test_lib_defmake ${ROAR_BUILDSYSTEM_DEFPREFIX}HAVE_LIBWSOCK32 % WinSockP0 wsock32 -- winsock2.h test_lib_defmake ${ROAR_BUILDSYSTEM_DEFPREFIX}HAVE_LIBWS2_32 % WinSockP1 ws2_32 -- winsock2.h echo 'NETLIBS += $(lib_wsock32) $(lib_ws2_32)' >&4 return 0 } test_netlibs() { __old_MINIMAL=$MINIMAL MINIMAL=false test_winsock MINIMAL=$__old_MINIMAL return 0 } test_pthread() { echo -n 'checking for -pthread... ' echo '#include ' > $TF_C echo 'int main (void) { pthread_self(); return 0; }' >> $TF_C if $CCTF -pthread 2> /dev/null; then echo "#define ${ROAR_BUILDSYSTEM_DEFPREFIX}HAVE_CC_PTHREAD_OPTION" >&3 echo 'opt_pthread=-pthread' >&4 echo 'pthread=$(opt_pthread)' >&4 echo yes _ret=0 else echo 'opt_pthread=' >&4 echo 'pthread=$(lib_pthread)' >&4 echo no test_lib_defmake ${ROAR_BUILDSYSTEM_DEFPREFIX}HAVE_LIBPTHREAD % libpthread pthread -- pthread.h _ret=$? fi [ "$_ret" = '0' ] && echo "#define ${ROAR_BUILDSYSTEM_DEFPREFIX}HAVE_PTHREAD" >&3 return $_ret } #ll