1 2AC_DEFUN([SAH_CHECK_LIB],[ 3 alib="$1" 4 # check to see if it is in our static list 5 for slib in ${STATIC_LIB_LIST}; do 6 lib_is_static="no" 7 tmp_pattern=`echo s/x${slib}// | sed 's/\*/.*/'` 8 if test -z "`echo x${alib} | sed ${tmp_pattern}`" 9 then 10 SAH_STATIC_LIB_REQUIRED(${alib},[$2],[ 11 lib_is_static="yes" 12 sah_lib_last="${sah_static_lib_last}" 13 $3 14 ],[$4],[$5]) 15 break; 16 fi 17 done 18 if test "${lib_is_static}" = "no" ; then 19 SAH_DYNAMIC_LIB_REQUIRED(${alib},[$2],[ 20 sah_lib_last="${sah_dynamic_lib_last}" 21 $3 22 ],[$4], [$5]) 23 fi 24]) 25 26 27 28AC_DEFUN([SAH_CHECK_LDFLAG],[ 29 sv_ldflags="${LDFLAGS}" 30 AC_MSG_CHECKING(if compiler works with $1 flag) 31 LDFLAGS="${LDFLAGS} $1" 32 AC_LINK_IFELSE([ 33 AC_LANG_PROGRAM([[ 34 #define CONFIG_TEST 35 int foo() {return 1;} 36 ]], 37 [ return foo(); ])], 38 [ 39 AC_MSG_RESULT(yes) 40 $2 41 ], 42 [ 43 AC_MSG_RESULT(no) 44 LDFLAGS="${sv_ldflags}" 45 $3 46 ] 47 ) 48]) 49 50AC_DEFUN([SAH_LINKAGE_FLAGS],[ 51 if test "${disable_static_linkage}" = "yes" 52 then 53 ld_static_option="" 54 ld_dynamic_option="" 55 LD_EXPORT_DYNAMIC="" 56 else 57 if test -z "${ld_static_option}" && test -z "${using_libtool}" 58 then 59 AC_MSG_CHECKING([if we are using libtool]) 60 if test "x$lt_cv_path_LD" != "x" ; then 61 AC_MSG_RESULT(yes) 62 using_libtool=yes 63 ld_static_option="-static-libtool-libs" 64 else 65 AC_MSG_RESULT(no) 66 using_libtool=no 67 case $target in 68 *linux* | *solaris* | *cygwin* ) 69 AC_MSG_CHECKING([${CC} flags for static linkage ...]) 70 ld_static_option="-Wl,-Bstatic" 71 AC_MSG_RESULT($ld_static_option) 72 AC_MSG_CHECKING([${CC} flags for dynamic linkage ...]) 73 ld_dynamic_option="-Wl,-Bdynamic" 74 AC_MSG_RESULT($ld_dynamic_option) 75 ;; 76 *darwin* ) 77 AC_MSG_CHECKING([${CC} flags for static linkage ...]) 78 ld_static_option="-static" 79 AC_MSG_RESULT($ld_static_option) 80 AC_MSG_CHECKING([${CC} flags for dynamic linkage ...]) 81 ld_dynamic_option="-dynamic" 82 AC_MSG_RESULT($ld_dynamic_option) 83 ;; 84 *) 85 if test -z "${dummy_ld_variable_gfdsahjf}" 86 then 87 dummy_ld_variable_gfdsahjf="been there done that" 88 AC_MSG_CHECKING([${CC} flags for static linkage ...]) 89 AC_MSG_RESULT(unknown) 90 AC_MSG_CHECKING([${CC} flags for dynamic linkage ...]) 91 AC_MSG_RESULT(unknown) 92 fi 93 ;; 94 esac 95 AC_MSG_CHECKING([${CC} flags for exporting dynamic symbols from an executable ...]) 96 case $target in 97 *cygwin*) 98 LD_EXPORT_DYNAMIC="-Wl,--export-all-symbols" 99 AC_MSG_RESULT(${LD_EXPORT_DYNAMIC}) 100 ;; 101 *linux*) 102 AC_MSG_RESULT(-rdynamic) 103 LD_EXPORT_DYNAMIC="-rdynamic" 104 ;; 105 *) 106 AC_MSG_RESULT(none required) 107 LD_EXPORT_DYNAMIC= 108 ;; 109 esac 110 fi 111 fi 112 fi 113 if test -z "${LIBEXT}"; 114 then 115 SAH_LIBEXT 116 fi 117 if test -z "${DLLEXT}"; 118 then 119 SAH_DLLEXT 120 fi 121 AC_SUBST(LD_EXPORT_DYNAMIC) 122]) 123 124 125# use this function in order to find a library that we require to be static. 126# we will check in the following order.... 127# 1) files named lib{name}.a 128# 2) files named {name}.a 129# 3) linking with the static flags "$STATIC_FLAGS -l{name}" 130AC_DEFUN([SAH_STATIC_LIB_REQUIRED],[ 131SAH_LINKAGE_FLAGS 132# upercase the library name for our definition 133ac_uc_defn=HAVE_LIB`echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g' \ 134 -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` 135# Build our cache variable names 136STATIC_LIB_LIST="${STATIC_LIB_LIST} $1" 137varname=`echo sah_cv_static_lib_$1_$2 | $as_tr_sh` 138var2=`echo sah_cv_static_lib_$1_fopen | $as_tr_sh` 139if test "$2" != "fopen" ; then 140 tmp_msg="for $2 in static library $1" 141else 142 tmp_msg="for static library $1" 143fi 144AC_CACHE_CHECK([$tmp_msg], 145 [$varname], 146[ 147 tmp_res="no" 148# 149# check if we want to actually do all this. 150 if test "${disable_static_linkage}" = "yes" 151 then 152 sah_static_checklibs="-l$1" 153 else 154 sah_static_checklibs="lib$1.${LIBEXT} $1.${LIBEXT} -l$1" 155 fi 156 if test "${using_libtool}" = "yes" ; then 157 ac_sv_link="$ac_link" 158 ac_link="./libtool --mode=link ${ac_link}" 159 sah_static_checklibs="lib$1.la $1.la ${sah_static_checklibs}" 160 fi 161 sah_save_libs="${LIBS}" 162 for libname in ${sah_static_checklibs} 163 do 164 SAH_FIND_STATIC_LIB(${libname}) 165dnl if test -z "`echo $tmp_lib_name | grep \\.la$`" ; then 166 if test -n "${tmp_lib_name}" 167 then 168 LIBS="${tmp_lib_name} $5 ${sah_save_libs}" 169 AC_LINK_IFELSE([ 170 AC_LANG_PROGRAM([[ 171 #define CONFIG_TEST 1 172 #ifdef __cplusplus 173 extern "C" { 174 #endif 175 char $2 (); 176 #ifdef __cplusplus 177 } 178 #endif 179 ]], 180 [ $2 (); ])], 181 [ 182 tmp_res="${tmp_lib_name}" 183 ] 184 ) 185 fi 186dnl else 187dnl tmp_res="-l$1" 188dnl fi 189 if test "${tmp_res}" != "no" 190 then 191 break 192 fi 193 done 194 LIBS="${sah_save_libs}" 195 eval ${varname}='"'${tmp_res}'"' 196 eval ${var2}='"'${tmp_res}'"' 197 ]) 198 if test "${using_libtool}" = "yes" ; then 199 ac_link="$ac_sv_link" 200 fi 201# 202# save the result for use by the caller 203sah_static_lib_last="`eval echo '${'$varname'}'`" 204# 205if test "${sah_static_lib_last}" != "no" 206then 207 LIBS="${sah_static_lib_last} ${LIBS}" 208 AC_DEFINE_UNQUOTED([$ac_uc_defn], [1], 209 [Define to 1 if the $1 library has the function $2] 210 ) 211 $3 212else 213 $4 214 echo > /dev/null 215fi 216]) 217 218# use this function in order to find a library that we require to be dynamic. 219# we will check in the following order.... 220# 1) linking with the dynamic flags "$DYNAMIC_FLAGS -l{name}" 221# 2) linking with no flags "-l{name}" 222AC_DEFUN([SAH_DYNAMIC_LIB_REQUIRED],[ 223SAH_LINKAGE_FLAGS 224# upercase the library name for our definition 225ac_uc_defn=HAVE_LIB`echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g' \ 226 -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` 227# Build our cache variable names 228DYNAMIC_LIB_LIST="${DYNAMIC_LIB_LIST} $1" 229varname=`echo sah_cv_dynamic_lib_$1_$2 | $as_tr_sh` 230var2=`echo sah_cv_dynamic_lib_$1_fopen | $as_tr_sh` 231if test "$2" != "fopen" ; then 232 tmp_msg="for $2 in dynamic library $1" 233else 234 tmp_msg="for dynamic library $1" 235fi 236AC_CACHE_CHECK([$tmp_msg], 237 [$varname], 238[ 239 tmp_res="no" 240# 241# check if we want to actually do all this. 242 if test "${disable_static_linkage}" = "yes" 243 then 244 sah_dynamic_checklibs="-l$1 -l$1.${DLLEXT}" 245 else 246 sah_dynamic_checklibs="-l$1" 247 fi 248 if test "${using_libtool}" = "yes" ; then 249 ac_sv_link="$ac_link" 250 ac_link="./libtool --mode=link ${ac_link}" 251 sah_dynamic_checklibs="lib$1.la $1.la ${sah_dynamic_checklibs}" 252 fi 253 sah_save_libs="${LIBS}" 254 for libname in ${sah_dynamic_checklibs} 255 do 256 tmp_lib_name="${libname}" 257 LIBS="${ld_dynamic_option} ${tmp_lib_name} $5 ${sah_save_libs}" 258 AC_LINK_IFELSE([ 259 AC_LANG_PROGRAM([[ 260 #define CONFIG_TEST 1 261 #ifdef __cplusplus 262 extern "C" { 263 #endif 264 char $2 (); 265 #ifdef __cplusplus 266 } 267 #endif 268 ]], 269 [ $2 (); ]) 270 ], 271 [ 272 tmp_res="${ld_dynamic_option} ${tmp_lib_name}" 273 ]) 274 if test "${tmp_res}" = "no" 275 then 276 tmp_lib_name="${libname}" 277 LIBS="${tmp_lib_name} ${sah_save_libs}" 278 AC_LINK_IFELSE([ 279 AC_LANG_PROGRAM([[ 280 #define CONFIG_TEST 1 281 #ifdef __cplusplus 282 extern "C" { 283 #endif 284 char $2 (); 285 #ifdef __cplusplus 286 } 287 #endif 288 ]], 289 [ $2 (); ]) 290 ], 291 [ 292 tmp_res="${tmp_lib_name}" 293 ]) 294 fi 295 done 296 if test "${using_libtool}" = "yes" ; then 297 ac_link="${ac_sv_link}" 298 fi 299 LIBS="${sah_save_libs}" 300 eval ${varname}='"'${tmp_res}'"' 301 eval ${var2}='"'${tmp_res}'"' 302]) 303# 304# save the result for use by the caller 305sah_dynamic_lib_last="`eval echo '${'$varname'}'`" 306# 307if test "${sah_dynamic_lib_last}" != "no" 308then 309 LIBS="${sah_dynamic_lib_last} ${LIBS}" 310 AC_DEFINE_UNQUOTED([$ac_uc_defn], [1], 311 [Define to 1 if the $1 library has the function $2] 312 ) 313 $3 314else 315 $4 316 echo > /dev/null 317fi 318]) 319 320AC_DEFUN([SAH_STATIC_LIB],[ 321 SAH_STATIC_LIB_REQUIRED([$1],[$2]) 322 sah_lib_last="${sah_static_lib_last}" 323 if test "${sah_lib_last}" = "no" ; then 324 SAH_DYNAMIC_LIB_REQUIRED([$1],[$2]) 325 sah_lib_last=${sah_dynamic_lib_last} 326 fi 327 if test "${sah_lib_last}" != "no" ; then 328 $3 329 echo > /dev/null 330 else 331 $4 332 echo > /dev/null 333 fi 334]) 335 336AC_DEFUN([SAH_DYNAMIC_LIB],[ 337 SAH_DYNAMIC_LIB_REQUIRED([$1],[$2]) 338 sah_lib_last="${sah_dynamic_lib_last}" 339 if test "${sah_lib_last}" = "no" ; then 340 SAH_STATIC_LIB_REQUIRED([$1],[$2]) 341 sah_lib_last=${sah_static_lib_last} 342 fi 343 if test "${sah_lib_last}" != "no" ; then 344 $3 345 echo > /dev/null 346 else 347 $4 348 echo > /dev/null 349 fi 350]) 351 352#The SAH_FIND_STATIC_LIB macro searches the LD_LIBRARY_PATH or equivalent 353#in order to find a static version of the library being loaded. 354AC_DEFUN([SAH_FIND_STATIC_LIB],[ 355# libtool sets up the variable shlibpath_var which holds the name of the 356# LIB_PATH variable. We also want to strip the sparcv9 and 64s from the 357# path, because we'll add them again later 358strip_pattern="s/sparcv9//g; s/lib64/lib/g; s/lib\/64/lib/g" 359tmp_libpath=`eval echo '${'$shlibpath_var'}' | sed "${strip_pattern}"` 360 361# in cygwin, the DLLs are in the path, but the static libraries are elsewhere. 362# Here's an educated guess. 363if test "${shlibpath_var}" = "PATH" 364then 365 tmp_libpath=`echo ${PATH} | sed 's/\/bin/\/lib/g'` 366 tmp_libpath="${tmp_libpath}:${PATH}" 367fi 368 369 370 371gcc_version=`${CC} -v 2>&1 | grep "gcc version" | $AWK '{print $[]3}'` 372 373 374for gcc_host in `${CC} -v 2>&1 | grep host` --host=${ac_cv_target} 375do 376 if test -n "`echo x$gcc_host | grep x--host=`" 377 then 378 gcc_host="`echo $gcc_host | sed 's/--host=//'`" 379 break 380 fi 381done 382 383for dirs in `${CC} -v 2>&1 | grep prefix` --prefix=/usr/local 384do 385 if test -n "`echo x$dirs | grep x--prefix=`" 386 then 387 gcc_prefix="`echo $dirs | sed 's/--prefix=//'`" 388 gcc_specs=`${CC} -v 2>&1 | grep specs | $AWK '{print $[]4}' | sed 's/\/specs//'` 389 tmp_libpath="${gcc_specs}:${gcc_prefix}/lib:${gcc_prefix}/lib/gcc-lib/${gcc_host}/${gcc_version}:${tmp_libpath}" 390 break 391 fi 392done 393 394mydir=`pwd` 395tmpgcc_libpath= 396 397for dirs in `${CC} -print-search-dirs 2>&1 | grep libraries | sed -e 's/:/ /g' -e 's/=/ /g'` 398do 399 if test -d $dirs/. && cd $dirs 2>&1 >/dev/null ; then 400 nowdir=`pwd` 401 if test -n "${tmpgcc_libpath}" ; then 402 tmpgcc_libpath="${tmpgcc_libpath}:${nowdir}" 403 else 404 tmpgcc_libpath="${dirs}" 405 fi 406 fi 407 cd $mydir 408done 409cd $mydir 410if test -n "${tmpgcc_libpath}" ; then 411 tmp_libpath="${tmpgcc_libpath}:${tmp_libpath}" 412fi 413 414# now lets add any directories in LIBS or LDFLAGS 415tmp_more_dirs=`echo $LIBS $LDFLAGS | $AWK '{for (i=1;i<(NF+1);i++) { printf("x%s\n",$[]i); }}' | grep x-L | sed 's/x-L//' | $AWK '{printf("%s:",$[]1);}'` 416tmp_libpath="${tmp_more_dirs}${tmp_libpath}" 417 418 419# Put machine/arch specific tweaks to the libpath here. 420if test -z "${COMPILER_MODEL_BITS}" 421then 422 SAH_DEFAULT_BITNESS 423fi 424case $target in 425 x86_64-*-linux*) 426 if test -n "${COMPILER_MODEL_BITS}" 427 then 428 tmp_pattern="s/\/lib/\/lib${COMPILER_MODEL_BITS}/g" 429 tmp_pattern_b="s/${COMPILER_MODEL_BITS}${COMPILER_MODEL_BITS}/${COMPILER_MODEL_BITS}/g" 430 abcd_q=`echo ${tmp_libpath} | sed ${tmp_pattern} | sed ${tmp_pattern_b} ` 431 case ${COMPILER_MODEL_BITS} in 432 32) 433 gcc_host_dirs=`echo ${gcc_prefix}/lib/gcc*/i[3456]86*linux*/${gcc_version}` 434 ;; 435 64) 436 gcc_host_dirs=`echo ${gcc_prefix}/lib/gcc-lib/x86_64*linux*/${gcc_version}` 437 ;; 438 esac 439 tmp_libpath="${abcd_q}:${tmp_libpath}" 440 for tmp_dir in ${gcc_host_dirs} 441 do 442 tmp_libpath="${tmp_dir}:${tmp_libpath}" 443 done 444 fi 445 ;; 446 sparc*-sun-solaris*) 447 if test -n "${COMPILER_MODEL_BITS}" 448 then 449 tmp_pattern="s/\/lib/\/lib\/${COMPILER_MODEL_BITS}/g" 450 tmp_pattern_b="s/${COMPILER_MODEL_BITS}\/${COMPILER_MODEL_BITS}/${COMPILER_MODEL_BITS}/g" 451 abcd_q=`echo ${tmp_libpath} | sed ${tmp_pattern} | sed ${tmp_pattern_b}` 452 case ${COMPILER_MODEL_BITS} in 453 64) 454 tmp_arch="sparcv9" 455 ;; 456 32) 457 tmp_arch= 458 ;; 459 esac 460 abcd_r= 461 for tmp_dir in `echo ${tmp_libpath} | sed 's/\:/ /g'` 462 do 463 abcd_r="${abcd_r}:${tmp_dir}/${tmp_arch}" 464 done 465 tmp_libpath="${abcd_r}:${abcd_q}:${tmp_libpath}" 466 fi 467 ;; 468 *) 469 echo > /dev/null 470 ;; 471esac 472 473 474if test -n "`echo x$1 | grep x-l`" 475then 476 # in the -l case, don't search, just use the ld_static_option (usually 477 # -Wl,-B static 478 tmp_lib_name="${ld_static_option} $1" 479else 480 # we also want to check the system config files for library dirs. 481 tmp_dir_list= 482 if test -e /etc/ld.so.conf 483 then 484 tmp_dir_list=`cat /etc/ld.so.conf` 485 else 486 if test -e /var/ld/ld.config 487 then 488 tmp_dir_list=`cat /var/ld/ld.config` 489 fi 490 fi 491 492 ## add library-paths from LDFLAGS to beginning of lib-path 493 ldflags_path=`echo $LDFLAGS | sed 's/-l[[^ ]]*//g' | sed 's/-L\([[^ ]]*\)/:\1/g' | sed 's/[[ ]]*//g'` 494 495 tmp_dir_list=`echo ${ldflags_path}:${tmp_libpath}:/lib:/usr/lib:/usr/ucb/lib:/usr/local/lib:/opt/misc/lib:${tmp_dir_list} | $AWK -F: '{for (i=1;i<(NF+1);i++) { print $[]i; }}'` 496 497 tmp_lib_name= 498 # now that we know where we are looking, find our library 499 for tmp_dir in $tmp_dir_list 500 do 501 if test -e $tmp_dir/$1 502 then 503 tmp_lib_name=${tmp_dir}/$1 504 break 505 fi 506 done 507fi 508]) 509