1dnl TiMidity++ -- MIDI to WAVE converter and player 2dnl Copyright (C) 1999-2002 Masanao Izumo <mo@goice.co.jp> 3dnl Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi> 4dnl 5dnl This program is free software; you can redistribute it and/or modify 6dnl it under the terms of the GNU General Public License as published by 7dnl the Free Software Foundation; either version 2 of the License, or 8dnl (at your option) any later version. 9dnl 10dnl This program is distributed in the hope that it will be useful, 11dnl but WITHOUT ANY WARRANTY; without even the implied warranty of 12dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13dnl GNU General Public License for more details. 14dnl 15dnl You should have received a copy of the GNU General Public License 16dnl along with this program; if not, write to the Free Software 17dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 19dnl MY_DEFINE(VARIABLE) 20AC_DEFUN([MY_DEFINE], 21[cat >> confdefs.h <<EOF 22[#define] $1 1 23EOF 24]) 25 26dnl CONFIG_INTERFACE(package,macro_name,interface_id,help 27dnl $1 $2 $3 $4 28dnl action-if-yes-or-dynamic, 29dnl $5 30dnl action-if-yes,action-if-dynamic,action-if-no) 31dnl $6 $7 $8 32AC_DEFUN([CONFIG_INTERFACE], 33[AC_ARG_ENABLE($1,[$4], 34[case "x$enable_$1" in xyes|xdynamic) $5 ;; esac]) 35case "x$enable_$1" in 36xyes) 37 MY_DEFINE(IA_$2) 38 AM_CONDITIONAL(ENABLE_$2, true) 39 $6 40 ;; 41xdynamic) 42 dynamic_targets="$dynamic_targets if_$1.\$(so)" 43 $7 44 ;; 45*) 46 $8 47 ;; 48esac 49AC_SUBST($3_so_libs) 50]) 51 52dnl CHECK_DLSYM_UNDERSCORE([ACTION-IF-NEED [, ACTION IF-NOT-NEED]]) 53dnl variable input: 54dnl CC CFLAGS CPPFLAGS LDFLAGS LIBS SHCFLAGS SHLD SHLDFLAGS 55dnl ac_cv_header_dlfcn_h lib_dl_opt so 56AC_DEFUN([CHECK_DLSYM_UNDERSCORE], 57[dnl Check if dlsym need a leading underscore 58AC_MSG_CHECKING([whether your dlsym() needs a leading underscore]) 59AC_CACHE_VAL(timidity_cv_func_dlsym_underscore, 60[case "$ac_cv_header_dlfcn_h" in 61yes) i_dlfcn=define;; 62*) i_dlfcn=undef;; 63esac 64cat > dyna.c <<EOM 65fred () { } 66EOM 67 68cat > fred.c <<EOM 69#include <stdio.h> 70#$i_dlfcn I_DLFCN 71#ifdef I_DLFCN 72#include <dlfcn.h> /* the dynamic linker include file for Sunos/Solaris */ 73#else 74#include <sys/types.h> 75#include <nlist.h> 76#include <link.h> 77#endif 78 79extern int fred() ; 80 81main() 82{ 83 void * handle ; 84 void * symbol ; 85#ifndef RTLD_LAZY 86 int mode = 1 ; 87#else 88 int mode = RTLD_LAZY ; 89#endif 90 handle = dlopen("./dyna.$so", mode) ; 91 if (handle == NULL) { 92 printf ("1\n") ; 93 fflush (stdout) ; 94 exit(0); 95 } 96 symbol = dlsym(handle, "fred") ; 97 if (symbol == NULL) { 98 /* try putting a leading underscore */ 99 symbol = dlsym(handle, "_fred") ; 100 if (symbol == NULL) { 101 printf ("2\n") ; 102 fflush (stdout) ; 103 exit(0); 104 } 105 printf ("3\n") ; 106 } 107 else 108 printf ("4\n") ; 109 fflush (stdout) ; 110 exit(0); 111} 112EOM 113: Call the object file tmp-dyna.o in case dlext=o. 114if ${CC-cc} $CFLAGS $SHCFLAGS $CPPFLAGS -c dyna.c > /dev/null 2>&1 && 115 mv dyna.o tmp-dyna.o > /dev/null 2>&1 && 116 $SHLD $SHLDFLAGS -o dyna.$so tmp-dyna.o > /dev/null 2>&1 && 117 ${CC-cc} -o fred $CFLAGS $CPPFLAGS $LDFLAGS fred.c $LIBS $lib_dl_opt > /dev/null 2>&1; then 118 xxx=`./fred` 119 case $xxx in 120 1) AC_MSG_WARN(Test program failed using dlopen. Perhaps you should not use dynamic loading.) 121 ;; 122 2) AC_MSG_WARN(Test program failed using dlsym. Perhaps you should not use dynamic loading.) 123 ;; 124 3) timidity_cv_func_dlsym_underscore=yes 125 ;; 126 4) timidity_cv_func_dlsym_underscore=no 127 ;; 128 esac 129else 130 AC_MSG_WARN(I can't compile and run the test program.) 131fi 132rm -f dyna.c dyna.o dyna.$so tmp-dyna.o fred.c fred.o fred 133]) 134case "x$timidity_cv_func_dlsym_underscore" in 135xyes) [$1] 136 AC_MSG_RESULT(yes) 137 ;; 138xno) [$2] 139 AC_MSG_RESULT(no) 140 ;; 141esac 142]) 143 144 145dnl contains program from perl5 146dnl CONTAINS_INIT() 147AC_DEFUN([CONTAINS_INIT], 148[dnl Some greps do not return status, grrr. 149AC_MSG_CHECKING([whether grep returns status]) 150echo "grimblepritz" >grimble 151if grep blurfldyick grimble >/dev/null 2>&1 ; then 152 contains="./contains" 153elif grep grimblepritz grimble >/dev/null 2>&1 ; then 154 contains=grep 155else 156 contains="./contains" 157fi 158rm -f grimble 159dnl the following should work in any shell 160case "$contains" in 161grep) AC_MSG_RESULT(yes) 162 ;; 163./contains) 164 AC_MSG_RESULT(AGH! Grep doesn't return a status. Attempting remedial action.) 165 cat >./contains <<'EOSS' 166grep "[$]1" "[$]2" >.greptmp && cat .greptmp && test -s .greptmp 167EOSS 168 chmod +x "./contains" 169 ;; 170esac 171]) 172 173dnl CONTAINS(word,filename,action-if-found,action-if-not-found) 174AC_DEFUN([CONTAINS], 175[if $contains "^[$1]"'[$]' $2 >/dev/null 2>&1; then 176 [$3] 177else 178 [$4] 179fi 180]) 181 182dnl SET_UNIQ_WORDS(shell-variable,words...) 183AC_DEFUN([SET_UNIQ_WORDS], 184[rm -f wordtmp >/dev/null 2>&1 185val='' 186for f in $2; do 187 CONTAINS([$f],wordtmp,:,[echo $f >>wordtmp; val="$val $f"]) 188done 189$1="$val" 190rm -f wordtmp >/dev/null 2>&1 191]) 192 193 194dnl WAPI_CHECK_FUNC(FUNCTION, INCLUDES, TEST-BODY, 195 [ACTION-FI-FOUND [, ACTION-IF-NOT-FOUND]]) 196AC_DEFUN([WAPI_CHECK_FUNC], 197[AC_MSG_CHECKING(for $1) 198AC_CACHE_VAL(wapi_cv_func_$1, 199[AC_TRY_LINK([#include <windows.h> 200$2 201], [$3], 202wapi_cv_func_$1=yes, wapi_cv_func_$1=no)]) 203if eval "test \"`echo '$wapi_cv_func_'$1`\" = yes"; then 204 AC_MSG_RESULT(yes) 205 ifelse([$4], , :, [$4]) 206else 207 AC_MSG_RESULT(no) 208ifelse([$5], , , [$5 209])dnl 210fi 211]) 212 213dnl WAPI_CHECK_LIB(LIBRARY, FUNCTION, 214dnl INCLUDES, TEST-BODY 215dnl [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND 216dnl [, OTHER-LIBRARIES]]]) 217AC_DEFUN([WAPI_CHECK_LIB], 218[AC_MSG_CHECKING([for $2 in -l$1]) 219ac_lib_var=`echo $1['_']$2 | sed 'y%./+-%__p_%'` 220AC_CACHE_VAL(wapi_cv_lib_$ac_lib_var, 221[ac_save_LIBS="$LIBS" 222LIBS="-l$1 $7 $LIBS" 223AC_TRY_LINK([#include <windows.h> 224$3 225], [$4], 226eval "wapi_cv_lib_$ac_lib_var=yes", 227eval "wapi_cv_lib_$ac_lib_var=no") 228LIBS="$ac_save_LIBS" 229])dnl 230if eval "test \"`echo '$wapi_cv_lib_'$ac_lib_var`\" = yes"; then 231 AC_MSG_RESULT(yes) 232 ifelse([$5], ,LIBS="-l$1 $LIBS", [$5]) 233else 234 AC_MSG_RESULT(no) 235ifelse([$6], , , [$6 236])dnl 237fi 238]) 239 240dnl EXTRACT_CPPFLAGS(CPPFLAGS-to-append,others-to-append,FLAGS) 241AC_DEFUN([EXTRACT_CPPFLAGS], 242[for f in $3; do 243 case ".$f" in 244 .-I?*|.-D?*) $1="[$]$1 $f" ;; 245 *) $2="[$]$2 $f" ;; 246 esac 247done 248]) 249 250 251dnl CHECK_COMPILER_OPTION(OPTIONS [, ACTION-IF-SUCCEED [, ACTION-IF-FAILED]]) 252AC_DEFUN([CHECK_COMPILER_OPTION], 253[AC_MSG_CHECKING([whether -$1 option is recognized]) 254ac_ccoption=`echo $1 | sed 'y%./+-%__p_%'` 255AC_CACHE_VAL(timidity_cv_ccoption_$ac_ccoption, 256[cat > conftest.$ac_ext <<EOF 257int main() {return 0;} 258EOF 259if ${CC-cc} $LDFLAGS $CFLAGS -o conftest${ac_exeext} -$1 conftest.$ac_ext > conftest.out 2>&1; then 260 if test -s conftest.out; then 261 eval "timidity_cv_ccoption_$ac_ccoption=no" 262 else 263 eval "timidity_cv_ccoption_$ac_ccoption=yes" 264 fi 265else 266 eval "timidity_cv_ccoption_$ac_ccoption=no" 267fi 268]) 269if eval "test \"`echo '$timidity_cv_ccoption_'$ac_ccoption`\" = yes"; then 270 AC_MSG_RESULT(yes) 271 ifelse([$2], , , [$2 272]) 273else 274 AC_MSG_RESULT(no) 275ifelse([$3], , , [$3 276]) 277fi 278]) 279 280 281dnl MY_SEARCH_LIBS(FUNCTION, LIBRARIES [, ACTION-IF-FOUND 282dnl [, ACTION-IF-NOT-FOUND [, OTHER-LIBRARIES]]]) 283dnl Search for a library defining FUNC, if it's not already available. 284 285AC_DEFUN([MY_SEARCH_LIBS], 286[AC_CACHE_CHECK([for library containing $1], [timidity_cv_search_$1], 287[ac_func_search_save_LIBS="$LIBS" 288timidity_cv_search_$1="no" 289for i in $2; do 290 LIBS="$i $5 $ac_func_search_save_LIBS" 291 AC_TRY_LINK_FUNC([$1], [timidity_cv_search_$1="$i"; break]) 292done 293LIBS="$ac_func_search_save_LIBS"]) 294if test "$timidity_cv_search_$1" != "no"; then 295 $3 296else : 297 $4 298fi]) 299