1*735d6239SKiyoung Kim# lib-link.m4 serial 4 (gettext-0.12) 2*735d6239SKiyoung Kimdnl Copyright (C) 2001-2003 Free Software Foundation, Inc. 3*735d6239SKiyoung Kimdnl This file is free software, distributed under the terms of the GNU 4*735d6239SKiyoung Kimdnl General Public License. As a special exception to the GNU General 5*735d6239SKiyoung Kimdnl Public License, this file may be distributed as part of a program 6*735d6239SKiyoung Kimdnl that contains a configuration script generated by Autoconf, under 7*735d6239SKiyoung Kimdnl the same distribution terms as the rest of that program. 8*735d6239SKiyoung Kim 9*735d6239SKiyoung Kimdnl From Bruno Haible. 10*735d6239SKiyoung Kim 11*735d6239SKiyoung Kimdnl AC_LIB_LINKFLAGS(name [, dependencies]) searches for libname and 12*735d6239SKiyoung Kimdnl the libraries corresponding to explicit and implicit dependencies. 13*735d6239SKiyoung Kimdnl Sets and AC_SUBSTs the LIB${NAME} and LTLIB${NAME} variables and 14*735d6239SKiyoung Kimdnl augments the CPPFLAGS variable. 15*735d6239SKiyoung KimAC_DEFUN([AC_LIB_LINKFLAGS], 16*735d6239SKiyoung Kim[ 17*735d6239SKiyoung Kim AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) 18*735d6239SKiyoung Kim AC_REQUIRE([AC_LIB_RPATH]) 19*735d6239SKiyoung Kim define([Name],[translit([$1],[./-], [___])]) 20*735d6239SKiyoung Kim define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-], 21*735d6239SKiyoung Kim [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) 22*735d6239SKiyoung Kim AC_CACHE_CHECK([how to link with lib[]$1], [ac_cv_lib[]Name[]_libs], [ 23*735d6239SKiyoung Kim AC_LIB_LINKFLAGS_BODY([$1], [$2]) 24*735d6239SKiyoung Kim ac_cv_lib[]Name[]_libs="$LIB[]NAME" 25*735d6239SKiyoung Kim ac_cv_lib[]Name[]_ltlibs="$LTLIB[]NAME" 26*735d6239SKiyoung Kim ac_cv_lib[]Name[]_cppflags="$INC[]NAME" 27*735d6239SKiyoung Kim ]) 28*735d6239SKiyoung Kim LIB[]NAME="$ac_cv_lib[]Name[]_libs" 29*735d6239SKiyoung Kim LTLIB[]NAME="$ac_cv_lib[]Name[]_ltlibs" 30*735d6239SKiyoung Kim INC[]NAME="$ac_cv_lib[]Name[]_cppflags" 31*735d6239SKiyoung Kim AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME) 32*735d6239SKiyoung Kim AC_SUBST([LIB]NAME) 33*735d6239SKiyoung Kim AC_SUBST([LTLIB]NAME) 34*735d6239SKiyoung Kim dnl Also set HAVE_LIB[]NAME so that AC_LIB_HAVE_LINKFLAGS can reuse the 35*735d6239SKiyoung Kim dnl results of this search when this library appears as a dependency. 36*735d6239SKiyoung Kim HAVE_LIB[]NAME=yes 37*735d6239SKiyoung Kim undefine([Name]) 38*735d6239SKiyoung Kim undefine([NAME]) 39*735d6239SKiyoung Kim]) 40*735d6239SKiyoung Kim 41*735d6239SKiyoung Kimdnl AC_LIB_HAVE_LINKFLAGS(name, dependencies, includes, testcode) 42*735d6239SKiyoung Kimdnl searches for libname and the libraries corresponding to explicit and 43*735d6239SKiyoung Kimdnl implicit dependencies, together with the specified include files and 44*735d6239SKiyoung Kimdnl the ability to compile and link the specified testcode. If found, it 45*735d6239SKiyoung Kimdnl sets and AC_SUBSTs HAVE_LIB${NAME}=yes and the LIB${NAME} and 46*735d6239SKiyoung Kimdnl LTLIB${NAME} variables and augments the CPPFLAGS variable, and 47*735d6239SKiyoung Kimdnl #defines HAVE_LIB${NAME} to 1. Otherwise, it sets and AC_SUBSTs 48*735d6239SKiyoung Kimdnl HAVE_LIB${NAME}=no and LIB${NAME} and LTLIB${NAME} to empty. 49*735d6239SKiyoung KimAC_DEFUN([AC_LIB_HAVE_LINKFLAGS], 50*735d6239SKiyoung Kim[ 51*735d6239SKiyoung Kim AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) 52*735d6239SKiyoung Kim AC_REQUIRE([AC_LIB_RPATH]) 53*735d6239SKiyoung Kim define([Name],[translit([$1],[./-], [___])]) 54*735d6239SKiyoung Kim define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-], 55*735d6239SKiyoung Kim [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) 56*735d6239SKiyoung Kim 57*735d6239SKiyoung Kim dnl Search for lib[]Name and define LIB[]NAME, LTLIB[]NAME and INC[]NAME 58*735d6239SKiyoung Kim dnl accordingly. 59*735d6239SKiyoung Kim AC_LIB_LINKFLAGS_BODY([$1], [$2]) 60*735d6239SKiyoung Kim 61*735d6239SKiyoung Kim dnl Add $INC[]NAME to CPPFLAGS before performing the following checks, 62*735d6239SKiyoung Kim dnl because if the user has installed lib[]Name and not disabled its use 63*735d6239SKiyoung Kim dnl via --without-lib[]Name-prefix, he wants to use it. 64*735d6239SKiyoung Kim ac_save_CPPFLAGS="$CPPFLAGS" 65*735d6239SKiyoung Kim AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME) 66*735d6239SKiyoung Kim 67*735d6239SKiyoung Kim AC_CACHE_CHECK([for lib[]$1], [ac_cv_lib[]Name], [ 68*735d6239SKiyoung Kim ac_save_LIBS="$LIBS" 69*735d6239SKiyoung Kim LIBS="$LIBS $LIB[]NAME" 70*735d6239SKiyoung Kim AC_TRY_LINK([$3], [$4], [ac_cv_lib[]Name=yes], [ac_cv_lib[]Name=no]) 71*735d6239SKiyoung Kim LIBS="$ac_save_LIBS" 72*735d6239SKiyoung Kim ]) 73*735d6239SKiyoung Kim if test "$ac_cv_lib[]Name" = yes; then 74*735d6239SKiyoung Kim HAVE_LIB[]NAME=yes 75*735d6239SKiyoung Kim AC_DEFINE([HAVE_LIB]NAME, 1, [Define if you have the $1 library.]) 76*735d6239SKiyoung Kim AC_MSG_CHECKING([how to link with lib[]$1]) 77*735d6239SKiyoung Kim AC_MSG_RESULT([$LIB[]NAME]) 78*735d6239SKiyoung Kim else 79*735d6239SKiyoung Kim HAVE_LIB[]NAME=no 80*735d6239SKiyoung Kim dnl If $LIB[]NAME didn't lead to a usable library, we don't need 81*735d6239SKiyoung Kim dnl $INC[]NAME either. 82*735d6239SKiyoung Kim CPPFLAGS="$ac_save_CPPFLAGS" 83*735d6239SKiyoung Kim LIB[]NAME= 84*735d6239SKiyoung Kim LTLIB[]NAME= 85*735d6239SKiyoung Kim fi 86*735d6239SKiyoung Kim AC_SUBST([HAVE_LIB]NAME) 87*735d6239SKiyoung Kim AC_SUBST([LIB]NAME) 88*735d6239SKiyoung Kim AC_SUBST([LTLIB]NAME) 89*735d6239SKiyoung Kim undefine([Name]) 90*735d6239SKiyoung Kim undefine([NAME]) 91*735d6239SKiyoung Kim]) 92*735d6239SKiyoung Kim 93*735d6239SKiyoung Kimdnl Determine the platform dependent parameters needed to use rpath: 94*735d6239SKiyoung Kimdnl libext, shlibext, hardcode_libdir_flag_spec, hardcode_libdir_separator, 95*735d6239SKiyoung Kimdnl hardcode_direct, hardcode_minus_L. 96*735d6239SKiyoung KimAC_DEFUN([AC_LIB_RPATH], 97*735d6239SKiyoung Kim[ 98*735d6239SKiyoung Kim AC_REQUIRE([AC_PROG_CC]) dnl we use $CC, $GCC, $LDFLAGS 99*735d6239SKiyoung Kim AC_REQUIRE([AC_LIB_PROG_LD]) dnl we use $LD, $with_gnu_ld 100*735d6239SKiyoung Kim AC_REQUIRE([AC_CANONICAL_HOST]) dnl we use $host 101*735d6239SKiyoung Kim AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT]) dnl we use $ac_aux_dir 102*735d6239SKiyoung Kim AC_CACHE_CHECK([for shared library run path origin], acl_cv_rpath, [ 103*735d6239SKiyoung Kim CC="$CC" GCC="$GCC" LDFLAGS="$LDFLAGS" LD="$LD" with_gnu_ld="$with_gnu_ld" \ 104*735d6239SKiyoung Kim ${CONFIG_SHELL-/bin/sh} "$ac_aux_dir/config.rpath" "$host" > conftest.sh 105*735d6239SKiyoung Kim . ./conftest.sh 106*735d6239SKiyoung Kim rm -f ./conftest.sh 107*735d6239SKiyoung Kim acl_cv_rpath=done 108*735d6239SKiyoung Kim ]) 109*735d6239SKiyoung Kim wl="$acl_cv_wl" 110*735d6239SKiyoung Kim libext="$acl_cv_libext" 111*735d6239SKiyoung Kim shlibext="$acl_cv_shlibext" 112*735d6239SKiyoung Kim hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec" 113*735d6239SKiyoung Kim hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator" 114*735d6239SKiyoung Kim hardcode_direct="$acl_cv_hardcode_direct" 115*735d6239SKiyoung Kim hardcode_minus_L="$acl_cv_hardcode_minus_L" 116*735d6239SKiyoung Kim dnl Determine whether the user wants rpath handling at all. 117*735d6239SKiyoung Kim AC_ARG_ENABLE(rpath, 118*735d6239SKiyoung Kim [ --disable-rpath do not hardcode runtime library paths], 119*735d6239SKiyoung Kim :, enable_rpath=yes) 120*735d6239SKiyoung Kim]) 121*735d6239SKiyoung Kim 122*735d6239SKiyoung Kimdnl AC_LIB_LINKFLAGS_BODY(name [, dependencies]) searches for libname and 123*735d6239SKiyoung Kimdnl the libraries corresponding to explicit and implicit dependencies. 124*735d6239SKiyoung Kimdnl Sets the LIB${NAME}, LTLIB${NAME} and INC${NAME} variables. 125*735d6239SKiyoung KimAC_DEFUN([AC_LIB_LINKFLAGS_BODY], 126*735d6239SKiyoung Kim[ 127*735d6239SKiyoung Kim define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-], 128*735d6239SKiyoung Kim [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) 129*735d6239SKiyoung Kim dnl By default, look in $includedir and $libdir. 130*735d6239SKiyoung Kim use_additional=yes 131*735d6239SKiyoung Kim AC_LIB_WITH_FINAL_PREFIX([ 132*735d6239SKiyoung Kim eval additional_includedir=\"$includedir\" 133*735d6239SKiyoung Kim eval additional_libdir=\"$libdir\" 134*735d6239SKiyoung Kim ]) 135*735d6239SKiyoung Kim AC_LIB_ARG_WITH([lib$1-prefix], 136*735d6239SKiyoung Kim[ --with-lib$1-prefix[=DIR] search for lib$1 in DIR/include and DIR/lib 137*735d6239SKiyoung Kim --without-lib$1-prefix don't search for lib$1 in includedir and libdir], 138*735d6239SKiyoung Kim[ 139*735d6239SKiyoung Kim if test "X$withval" = "Xno"; then 140*735d6239SKiyoung Kim use_additional=no 141*735d6239SKiyoung Kim else 142*735d6239SKiyoung Kim if test "X$withval" = "X"; then 143*735d6239SKiyoung Kim AC_LIB_WITH_FINAL_PREFIX([ 144*735d6239SKiyoung Kim eval additional_includedir=\"$includedir\" 145*735d6239SKiyoung Kim eval additional_libdir=\"$libdir\" 146*735d6239SKiyoung Kim ]) 147*735d6239SKiyoung Kim else 148*735d6239SKiyoung Kim additional_includedir="$withval/include" 149*735d6239SKiyoung Kim additional_libdir="$withval/lib" 150*735d6239SKiyoung Kim fi 151*735d6239SKiyoung Kim fi 152*735d6239SKiyoung Kim]) 153*735d6239SKiyoung Kim dnl Search the library and its dependencies in $additional_libdir and 154*735d6239SKiyoung Kim dnl $LDFLAGS. Using breadth-first-seach. 155*735d6239SKiyoung Kim LIB[]NAME= 156*735d6239SKiyoung Kim LTLIB[]NAME= 157*735d6239SKiyoung Kim INC[]NAME= 158*735d6239SKiyoung Kim rpathdirs= 159*735d6239SKiyoung Kim ltrpathdirs= 160*735d6239SKiyoung Kim names_already_handled= 161*735d6239SKiyoung Kim names_next_round='$1 $2' 162*735d6239SKiyoung Kim while test -n "$names_next_round"; do 163*735d6239SKiyoung Kim names_this_round="$names_next_round" 164*735d6239SKiyoung Kim names_next_round= 165*735d6239SKiyoung Kim for name in $names_this_round; do 166*735d6239SKiyoung Kim already_handled= 167*735d6239SKiyoung Kim for n in $names_already_handled; do 168*735d6239SKiyoung Kim if test "$n" = "$name"; then 169*735d6239SKiyoung Kim already_handled=yes 170*735d6239SKiyoung Kim break 171*735d6239SKiyoung Kim fi 172*735d6239SKiyoung Kim done 173*735d6239SKiyoung Kim if test -z "$already_handled"; then 174*735d6239SKiyoung Kim names_already_handled="$names_already_handled $name" 175*735d6239SKiyoung Kim dnl See if it was already located by an earlier AC_LIB_LINKFLAGS 176*735d6239SKiyoung Kim dnl or AC_LIB_HAVE_LINKFLAGS call. 177*735d6239SKiyoung Kim uppername=`echo "$name" | sed -e 'y|abcdefghijklmnopqrstuvwxyz./-|ABCDEFGHIJKLMNOPQRSTUVWXYZ___|'` 178*735d6239SKiyoung Kim eval value=\"\$HAVE_LIB$uppername\" 179*735d6239SKiyoung Kim if test -n "$value"; then 180*735d6239SKiyoung Kim if test "$value" = yes; then 181*735d6239SKiyoung Kim eval value=\"\$LIB$uppername\" 182*735d6239SKiyoung Kim test -z "$value" || LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$value" 183*735d6239SKiyoung Kim eval value=\"\$LTLIB$uppername\" 184*735d6239SKiyoung Kim test -z "$value" || LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$value" 185*735d6239SKiyoung Kim else 186*735d6239SKiyoung Kim dnl An earlier call to AC_LIB_HAVE_LINKFLAGS has determined 187*735d6239SKiyoung Kim dnl that this library doesn't exist. So just drop it. 188*735d6239SKiyoung Kim : 189*735d6239SKiyoung Kim fi 190*735d6239SKiyoung Kim else 191*735d6239SKiyoung Kim dnl Search the library lib$name in $additional_libdir and $LDFLAGS 192*735d6239SKiyoung Kim dnl and the already constructed $LIBNAME/$LTLIBNAME. 193*735d6239SKiyoung Kim found_dir= 194*735d6239SKiyoung Kim found_la= 195*735d6239SKiyoung Kim found_so= 196*735d6239SKiyoung Kim found_a= 197*735d6239SKiyoung Kim if test $use_additional = yes; then 198*735d6239SKiyoung Kim if test -n "$shlibext" && test -f "$additional_libdir/lib$name.$shlibext"; then 199*735d6239SKiyoung Kim found_dir="$additional_libdir" 200*735d6239SKiyoung Kim found_so="$additional_libdir/lib$name.$shlibext" 201*735d6239SKiyoung Kim if test -f "$additional_libdir/lib$name.la"; then 202*735d6239SKiyoung Kim found_la="$additional_libdir/lib$name.la" 203*735d6239SKiyoung Kim fi 204*735d6239SKiyoung Kim else 205*735d6239SKiyoung Kim if test -f "$additional_libdir/lib$name.$libext"; then 206*735d6239SKiyoung Kim found_dir="$additional_libdir" 207*735d6239SKiyoung Kim found_a="$additional_libdir/lib$name.$libext" 208*735d6239SKiyoung Kim if test -f "$additional_libdir/lib$name.la"; then 209*735d6239SKiyoung Kim found_la="$additional_libdir/lib$name.la" 210*735d6239SKiyoung Kim fi 211*735d6239SKiyoung Kim fi 212*735d6239SKiyoung Kim fi 213*735d6239SKiyoung Kim fi 214*735d6239SKiyoung Kim if test "X$found_dir" = "X"; then 215*735d6239SKiyoung Kim for x in $LDFLAGS $LTLIB[]NAME; do 216*735d6239SKiyoung Kim AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) 217*735d6239SKiyoung Kim case "$x" in 218*735d6239SKiyoung Kim -L*) 219*735d6239SKiyoung Kim dir=`echo "X$x" | sed -e 's/^X-L//'` 220*735d6239SKiyoung Kim if test -n "$shlibext" && test -f "$dir/lib$name.$shlibext"; then 221*735d6239SKiyoung Kim found_dir="$dir" 222*735d6239SKiyoung Kim found_so="$dir/lib$name.$shlibext" 223*735d6239SKiyoung Kim if test -f "$dir/lib$name.la"; then 224*735d6239SKiyoung Kim found_la="$dir/lib$name.la" 225*735d6239SKiyoung Kim fi 226*735d6239SKiyoung Kim else 227*735d6239SKiyoung Kim if test -f "$dir/lib$name.$libext"; then 228*735d6239SKiyoung Kim found_dir="$dir" 229*735d6239SKiyoung Kim found_a="$dir/lib$name.$libext" 230*735d6239SKiyoung Kim if test -f "$dir/lib$name.la"; then 231*735d6239SKiyoung Kim found_la="$dir/lib$name.la" 232*735d6239SKiyoung Kim fi 233*735d6239SKiyoung Kim fi 234*735d6239SKiyoung Kim fi 235*735d6239SKiyoung Kim ;; 236*735d6239SKiyoung Kim esac 237*735d6239SKiyoung Kim if test "X$found_dir" != "X"; then 238*735d6239SKiyoung Kim break 239*735d6239SKiyoung Kim fi 240*735d6239SKiyoung Kim done 241*735d6239SKiyoung Kim fi 242*735d6239SKiyoung Kim if test "X$found_dir" != "X"; then 243*735d6239SKiyoung Kim dnl Found the library. 244*735d6239SKiyoung Kim LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$found_dir -l$name" 245*735d6239SKiyoung Kim if test "X$found_so" != "X"; then 246*735d6239SKiyoung Kim dnl Linking with a shared library. We attempt to hardcode its 247*735d6239SKiyoung Kim dnl directory into the executable's runpath, unless it's the 248*735d6239SKiyoung Kim dnl standard /usr/lib. 249*735d6239SKiyoung Kim if test "$enable_rpath" = no || test "X$found_dir" = "X/usr/lib"; then 250*735d6239SKiyoung Kim dnl No hardcoding is needed. 251*735d6239SKiyoung Kim LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" 252*735d6239SKiyoung Kim else 253*735d6239SKiyoung Kim dnl Use an explicit option to hardcode DIR into the resulting 254*735d6239SKiyoung Kim dnl binary. 255*735d6239SKiyoung Kim dnl Potentially add DIR to ltrpathdirs. 256*735d6239SKiyoung Kim dnl The ltrpathdirs will be appended to $LTLIBNAME at the end. 257*735d6239SKiyoung Kim haveit= 258*735d6239SKiyoung Kim for x in $ltrpathdirs; do 259*735d6239SKiyoung Kim if test "X$x" = "X$found_dir"; then 260*735d6239SKiyoung Kim haveit=yes 261*735d6239SKiyoung Kim break 262*735d6239SKiyoung Kim fi 263*735d6239SKiyoung Kim done 264*735d6239SKiyoung Kim if test -z "$haveit"; then 265*735d6239SKiyoung Kim ltrpathdirs="$ltrpathdirs $found_dir" 266*735d6239SKiyoung Kim fi 267*735d6239SKiyoung Kim dnl The hardcoding into $LIBNAME is system dependent. 268*735d6239SKiyoung Kim if test "$hardcode_direct" = yes; then 269*735d6239SKiyoung Kim dnl Using DIR/libNAME.so during linking hardcodes DIR into the 270*735d6239SKiyoung Kim dnl resulting binary. 271*735d6239SKiyoung Kim LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" 272*735d6239SKiyoung Kim else 273*735d6239SKiyoung Kim if test -n "$hardcode_libdir_flag_spec" && test "$hardcode_minus_L" = no; then 274*735d6239SKiyoung Kim dnl Use an explicit option to hardcode DIR into the resulting 275*735d6239SKiyoung Kim dnl binary. 276*735d6239SKiyoung Kim LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" 277*735d6239SKiyoung Kim dnl Potentially add DIR to rpathdirs. 278*735d6239SKiyoung Kim dnl The rpathdirs will be appended to $LIBNAME at the end. 279*735d6239SKiyoung Kim haveit= 280*735d6239SKiyoung Kim for x in $rpathdirs; do 281*735d6239SKiyoung Kim if test "X$x" = "X$found_dir"; then 282*735d6239SKiyoung Kim haveit=yes 283*735d6239SKiyoung Kim break 284*735d6239SKiyoung Kim fi 285*735d6239SKiyoung Kim done 286*735d6239SKiyoung Kim if test -z "$haveit"; then 287*735d6239SKiyoung Kim rpathdirs="$rpathdirs $found_dir" 288*735d6239SKiyoung Kim fi 289*735d6239SKiyoung Kim else 290*735d6239SKiyoung Kim dnl Rely on "-L$found_dir". 291*735d6239SKiyoung Kim dnl But don't add it if it's already contained in the LDFLAGS 292*735d6239SKiyoung Kim dnl or the already constructed $LIBNAME 293*735d6239SKiyoung Kim haveit= 294*735d6239SKiyoung Kim for x in $LDFLAGS $LIB[]NAME; do 295*735d6239SKiyoung Kim AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) 296*735d6239SKiyoung Kim if test "X$x" = "X-L$found_dir"; then 297*735d6239SKiyoung Kim haveit=yes 298*735d6239SKiyoung Kim break 299*735d6239SKiyoung Kim fi 300*735d6239SKiyoung Kim done 301*735d6239SKiyoung Kim if test -z "$haveit"; then 302*735d6239SKiyoung Kim LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir" 303*735d6239SKiyoung Kim fi 304*735d6239SKiyoung Kim if test "$hardcode_minus_L" != no; then 305*735d6239SKiyoung Kim dnl FIXME: Not sure whether we should use 306*735d6239SKiyoung Kim dnl "-L$found_dir -l$name" or "-L$found_dir $found_so" 307*735d6239SKiyoung Kim dnl here. 308*735d6239SKiyoung Kim LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" 309*735d6239SKiyoung Kim else 310*735d6239SKiyoung Kim dnl We cannot use $hardcode_runpath_var and LD_RUN_PATH 311*735d6239SKiyoung Kim dnl here, because this doesn't fit in flags passed to the 312*735d6239SKiyoung Kim dnl compiler. So give up. No hardcoding. This affects only 313*735d6239SKiyoung Kim dnl very old systems. 314*735d6239SKiyoung Kim dnl FIXME: Not sure whether we should use 315*735d6239SKiyoung Kim dnl "-L$found_dir -l$name" or "-L$found_dir $found_so" 316*735d6239SKiyoung Kim dnl here. 317*735d6239SKiyoung Kim LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name" 318*735d6239SKiyoung Kim fi 319*735d6239SKiyoung Kim fi 320*735d6239SKiyoung Kim fi 321*735d6239SKiyoung Kim fi 322*735d6239SKiyoung Kim else 323*735d6239SKiyoung Kim if test "X$found_a" != "X"; then 324*735d6239SKiyoung Kim dnl Linking with a static library. 325*735d6239SKiyoung Kim LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_a" 326*735d6239SKiyoung Kim else 327*735d6239SKiyoung Kim dnl We shouldn't come here, but anyway it's good to have a 328*735d6239SKiyoung Kim dnl fallback. 329*735d6239SKiyoung Kim LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir -l$name" 330*735d6239SKiyoung Kim fi 331*735d6239SKiyoung Kim fi 332*735d6239SKiyoung Kim dnl Assume the include files are nearby. 333*735d6239SKiyoung Kim additional_includedir= 334*735d6239SKiyoung Kim case "$found_dir" in 335*735d6239SKiyoung Kim */lib | */lib/) 336*735d6239SKiyoung Kim basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e 's,/lib/*$,,'` 337*735d6239SKiyoung Kim additional_includedir="$basedir/include" 338*735d6239SKiyoung Kim ;; 339*735d6239SKiyoung Kim esac 340*735d6239SKiyoung Kim if test "X$additional_includedir" != "X"; then 341*735d6239SKiyoung Kim dnl Potentially add $additional_includedir to $INCNAME. 342*735d6239SKiyoung Kim dnl But don't add it 343*735d6239SKiyoung Kim dnl 1. if it's the standard /usr/include, 344*735d6239SKiyoung Kim dnl 2. if it's /usr/local/include and we are using GCC on Linux, 345*735d6239SKiyoung Kim dnl 3. if it's already present in $CPPFLAGS or the already 346*735d6239SKiyoung Kim dnl constructed $INCNAME, 347*735d6239SKiyoung Kim dnl 4. if it doesn't exist as a directory. 348*735d6239SKiyoung Kim if test "X$additional_includedir" != "X/usr/include"; then 349*735d6239SKiyoung Kim haveit= 350*735d6239SKiyoung Kim if test "X$additional_includedir" = "X/usr/local/include"; then 351*735d6239SKiyoung Kim if test -n "$GCC"; then 352*735d6239SKiyoung Kim case $host_os in 353*735d6239SKiyoung Kim linux*) haveit=yes;; 354*735d6239SKiyoung Kim esac 355*735d6239SKiyoung Kim fi 356*735d6239SKiyoung Kim fi 357*735d6239SKiyoung Kim if test -z "$haveit"; then 358*735d6239SKiyoung Kim for x in $CPPFLAGS $INC[]NAME; do 359*735d6239SKiyoung Kim AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) 360*735d6239SKiyoung Kim if test "X$x" = "X-I$additional_includedir"; then 361*735d6239SKiyoung Kim haveit=yes 362*735d6239SKiyoung Kim break 363*735d6239SKiyoung Kim fi 364*735d6239SKiyoung Kim done 365*735d6239SKiyoung Kim if test -z "$haveit"; then 366*735d6239SKiyoung Kim if test -d "$additional_includedir"; then 367*735d6239SKiyoung Kim dnl Really add $additional_includedir to $INCNAME. 368*735d6239SKiyoung Kim INC[]NAME="${INC[]NAME}${INC[]NAME:+ }-I$additional_includedir" 369*735d6239SKiyoung Kim fi 370*735d6239SKiyoung Kim fi 371*735d6239SKiyoung Kim fi 372*735d6239SKiyoung Kim fi 373*735d6239SKiyoung Kim fi 374*735d6239SKiyoung Kim dnl Look for dependencies. 375*735d6239SKiyoung Kim if test -n "$found_la"; then 376*735d6239SKiyoung Kim dnl Read the .la file. It defines the variables 377*735d6239SKiyoung Kim dnl dlname, library_names, old_library, dependency_libs, current, 378*735d6239SKiyoung Kim dnl age, revision, installed, dlopen, dlpreopen, libdir. 379*735d6239SKiyoung Kim save_libdir="$libdir" 380*735d6239SKiyoung Kim case "$found_la" in 381*735d6239SKiyoung Kim */* | *\\*) . "$found_la" ;; 382*735d6239SKiyoung Kim *) . "./$found_la" ;; 383*735d6239SKiyoung Kim esac 384*735d6239SKiyoung Kim libdir="$save_libdir" 385*735d6239SKiyoung Kim dnl We use only dependency_libs. 386*735d6239SKiyoung Kim for dep in $dependency_libs; do 387*735d6239SKiyoung Kim case "$dep" in 388*735d6239SKiyoung Kim -L*) 389*735d6239SKiyoung Kim additional_libdir=`echo "X$dep" | sed -e 's/^X-L//'` 390*735d6239SKiyoung Kim dnl Potentially add $additional_libdir to $LIBNAME and $LTLIBNAME. 391*735d6239SKiyoung Kim dnl But don't add it 392*735d6239SKiyoung Kim dnl 1. if it's the standard /usr/lib, 393*735d6239SKiyoung Kim dnl 2. if it's /usr/local/lib and we are using GCC on Linux, 394*735d6239SKiyoung Kim dnl 3. if it's already present in $LDFLAGS or the already 395*735d6239SKiyoung Kim dnl constructed $LIBNAME, 396*735d6239SKiyoung Kim dnl 4. if it doesn't exist as a directory. 397*735d6239SKiyoung Kim if test "X$additional_libdir" != "X/usr/lib"; then 398*735d6239SKiyoung Kim haveit= 399*735d6239SKiyoung Kim if test "X$additional_libdir" = "X/usr/local/lib"; then 400*735d6239SKiyoung Kim if test -n "$GCC"; then 401*735d6239SKiyoung Kim case $host_os in 402*735d6239SKiyoung Kim linux*) haveit=yes;; 403*735d6239SKiyoung Kim esac 404*735d6239SKiyoung Kim fi 405*735d6239SKiyoung Kim fi 406*735d6239SKiyoung Kim if test -z "$haveit"; then 407*735d6239SKiyoung Kim haveit= 408*735d6239SKiyoung Kim for x in $LDFLAGS $LIB[]NAME; do 409*735d6239SKiyoung Kim AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) 410*735d6239SKiyoung Kim if test "X$x" = "X-L$additional_libdir"; then 411*735d6239SKiyoung Kim haveit=yes 412*735d6239SKiyoung Kim break 413*735d6239SKiyoung Kim fi 414*735d6239SKiyoung Kim done 415*735d6239SKiyoung Kim if test -z "$haveit"; then 416*735d6239SKiyoung Kim if test -d "$additional_libdir"; then 417*735d6239SKiyoung Kim dnl Really add $additional_libdir to $LIBNAME. 418*735d6239SKiyoung Kim LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$additional_libdir" 419*735d6239SKiyoung Kim fi 420*735d6239SKiyoung Kim fi 421*735d6239SKiyoung Kim haveit= 422*735d6239SKiyoung Kim for x in $LDFLAGS $LTLIB[]NAME; do 423*735d6239SKiyoung Kim AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) 424*735d6239SKiyoung Kim if test "X$x" = "X-L$additional_libdir"; then 425*735d6239SKiyoung Kim haveit=yes 426*735d6239SKiyoung Kim break 427*735d6239SKiyoung Kim fi 428*735d6239SKiyoung Kim done 429*735d6239SKiyoung Kim if test -z "$haveit"; then 430*735d6239SKiyoung Kim if test -d "$additional_libdir"; then 431*735d6239SKiyoung Kim dnl Really add $additional_libdir to $LTLIBNAME. 432*735d6239SKiyoung Kim LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$additional_libdir" 433*735d6239SKiyoung Kim fi 434*735d6239SKiyoung Kim fi 435*735d6239SKiyoung Kim fi 436*735d6239SKiyoung Kim fi 437*735d6239SKiyoung Kim ;; 438*735d6239SKiyoung Kim -R*) 439*735d6239SKiyoung Kim dir=`echo "X$dep" | sed -e 's/^X-R//'` 440*735d6239SKiyoung Kim if test "$enable_rpath" != no; then 441*735d6239SKiyoung Kim dnl Potentially add DIR to rpathdirs. 442*735d6239SKiyoung Kim dnl The rpathdirs will be appended to $LIBNAME at the end. 443*735d6239SKiyoung Kim haveit= 444*735d6239SKiyoung Kim for x in $rpathdirs; do 445*735d6239SKiyoung Kim if test "X$x" = "X$dir"; then 446*735d6239SKiyoung Kim haveit=yes 447*735d6239SKiyoung Kim break 448*735d6239SKiyoung Kim fi 449*735d6239SKiyoung Kim done 450*735d6239SKiyoung Kim if test -z "$haveit"; then 451*735d6239SKiyoung Kim rpathdirs="$rpathdirs $dir" 452*735d6239SKiyoung Kim fi 453*735d6239SKiyoung Kim dnl Potentially add DIR to ltrpathdirs. 454*735d6239SKiyoung Kim dnl The ltrpathdirs will be appended to $LTLIBNAME at the end. 455*735d6239SKiyoung Kim haveit= 456*735d6239SKiyoung Kim for x in $ltrpathdirs; do 457*735d6239SKiyoung Kim if test "X$x" = "X$dir"; then 458*735d6239SKiyoung Kim haveit=yes 459*735d6239SKiyoung Kim break 460*735d6239SKiyoung Kim fi 461*735d6239SKiyoung Kim done 462*735d6239SKiyoung Kim if test -z "$haveit"; then 463*735d6239SKiyoung Kim ltrpathdirs="$ltrpathdirs $dir" 464*735d6239SKiyoung Kim fi 465*735d6239SKiyoung Kim fi 466*735d6239SKiyoung Kim ;; 467*735d6239SKiyoung Kim -l*) 468*735d6239SKiyoung Kim dnl Handle this in the next round. 469*735d6239SKiyoung Kim names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'` 470*735d6239SKiyoung Kim ;; 471*735d6239SKiyoung Kim *.la) 472*735d6239SKiyoung Kim dnl Handle this in the next round. Throw away the .la's 473*735d6239SKiyoung Kim dnl directory; it is already contained in a preceding -L 474*735d6239SKiyoung Kim dnl option. 475*735d6239SKiyoung Kim names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'` 476*735d6239SKiyoung Kim ;; 477*735d6239SKiyoung Kim *) 478*735d6239SKiyoung Kim dnl Most likely an immediate library name. 479*735d6239SKiyoung Kim LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$dep" 480*735d6239SKiyoung Kim LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$dep" 481*735d6239SKiyoung Kim ;; 482*735d6239SKiyoung Kim esac 483*735d6239SKiyoung Kim done 484*735d6239SKiyoung Kim fi 485*735d6239SKiyoung Kim else 486*735d6239SKiyoung Kim dnl Didn't find the library; assume it is in the system directories 487*735d6239SKiyoung Kim dnl known to the linker and runtime loader. (All the system 488*735d6239SKiyoung Kim dnl directories known to the linker should also be known to the 489*735d6239SKiyoung Kim dnl runtime loader, otherwise the system is severely misconfigured.) 490*735d6239SKiyoung Kim LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name" 491*735d6239SKiyoung Kim LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-l$name" 492*735d6239SKiyoung Kim fi 493*735d6239SKiyoung Kim fi 494*735d6239SKiyoung Kim fi 495*735d6239SKiyoung Kim done 496*735d6239SKiyoung Kim done 497*735d6239SKiyoung Kim if test "X$rpathdirs" != "X"; then 498*735d6239SKiyoung Kim if test -n "$hardcode_libdir_separator"; then 499*735d6239SKiyoung Kim dnl Weird platform: only the last -rpath option counts, the user must 500*735d6239SKiyoung Kim dnl pass all path elements in one option. We can arrange that for a 501*735d6239SKiyoung Kim dnl single library, but not when more than one $LIBNAMEs are used. 502*735d6239SKiyoung Kim alldirs= 503*735d6239SKiyoung Kim for found_dir in $rpathdirs; do 504*735d6239SKiyoung Kim alldirs="${alldirs}${alldirs:+$hardcode_libdir_separator}$found_dir" 505*735d6239SKiyoung Kim done 506*735d6239SKiyoung Kim dnl Note: hardcode_libdir_flag_spec uses $libdir and $wl. 507*735d6239SKiyoung Kim acl_save_libdir="$libdir" 508*735d6239SKiyoung Kim libdir="$alldirs" 509*735d6239SKiyoung Kim eval flag=\"$hardcode_libdir_flag_spec\" 510*735d6239SKiyoung Kim libdir="$acl_save_libdir" 511*735d6239SKiyoung Kim LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag" 512*735d6239SKiyoung Kim else 513*735d6239SKiyoung Kim dnl The -rpath options are cumulative. 514*735d6239SKiyoung Kim for found_dir in $rpathdirs; do 515*735d6239SKiyoung Kim acl_save_libdir="$libdir" 516*735d6239SKiyoung Kim libdir="$found_dir" 517*735d6239SKiyoung Kim eval flag=\"$hardcode_libdir_flag_spec\" 518*735d6239SKiyoung Kim libdir="$acl_save_libdir" 519*735d6239SKiyoung Kim LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag" 520*735d6239SKiyoung Kim done 521*735d6239SKiyoung Kim fi 522*735d6239SKiyoung Kim fi 523*735d6239SKiyoung Kim if test "X$ltrpathdirs" != "X"; then 524*735d6239SKiyoung Kim dnl When using libtool, the option that works for both libraries and 525*735d6239SKiyoung Kim dnl executables is -R. The -R options are cumulative. 526*735d6239SKiyoung Kim for found_dir in $ltrpathdirs; do 527*735d6239SKiyoung Kim LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-R$found_dir" 528*735d6239SKiyoung Kim done 529*735d6239SKiyoung Kim fi 530*735d6239SKiyoung Kim]) 531*735d6239SKiyoung Kim 532*735d6239SKiyoung Kimdnl AC_LIB_APPENDTOVAR(VAR, CONTENTS) appends the elements of CONTENTS to VAR, 533*735d6239SKiyoung Kimdnl unless already present in VAR. 534*735d6239SKiyoung Kimdnl Works only for CPPFLAGS, not for LIB* variables because that sometimes 535*735d6239SKiyoung Kimdnl contains two or three consecutive elements that belong together. 536*735d6239SKiyoung KimAC_DEFUN([AC_LIB_APPENDTOVAR], 537*735d6239SKiyoung Kim[ 538*735d6239SKiyoung Kim for element in [$2]; do 539*735d6239SKiyoung Kim haveit= 540*735d6239SKiyoung Kim for x in $[$1]; do 541*735d6239SKiyoung Kim AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) 542*735d6239SKiyoung Kim if test "X$x" = "X$element"; then 543*735d6239SKiyoung Kim haveit=yes 544*735d6239SKiyoung Kim break 545*735d6239SKiyoung Kim fi 546*735d6239SKiyoung Kim done 547*735d6239SKiyoung Kim if test -z "$haveit"; then 548*735d6239SKiyoung Kim [$1]="${[$1]}${[$1]:+ }$element" 549*735d6239SKiyoung Kim fi 550*735d6239SKiyoung Kim done 551*735d6239SKiyoung Kim]) 552