# lib-link.m4 serial 4 (gettext-0.12)dnl Copyright (C) 2001-2003 Free Software Foundation, Inc.dnl This file is free software, distributed under the terms of the GNUdnl General Public License. As a special exception to the GNU Generaldnl Public License, this file may be distributed as part of a programdnl that contains a configuration script generated by Autoconf, underdnl the same distribution terms as the rest of that program.dnl From Bruno Haible.dnl AC_LIB_LINKFLAGS(name [, dependencies]) searches for libname anddnl the libraries corresponding to explicit and implicit dependencies.dnl Sets and AC_SUBSTs the LIB${NAME} and LTLIB${NAME} variables anddnl augments the CPPFLAGS variable.AC_DEFUN([AC_LIB_LINKFLAGS],[AC_REQUIRE([AC_LIB_PREPARE_PREFIX])AC_REQUIRE([AC_LIB_RPATH])define([Name],[translit([$1],[./-], [___])])define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])AC_CACHE_CHECK([how to link with lib[]$1], [ac_cv_lib[]Name[]_libs], [AC_LIB_LINKFLAGS_BODY([$1], [$2])ac_cv_lib[]Name[]_libs="$LIB[]NAME"ac_cv_lib[]Name[]_ltlibs="$LTLIB[]NAME"ac_cv_lib[]Name[]_cppflags="$INC[]NAME"])LIB[]NAME="$ac_cv_lib[]Name[]_libs"LTLIB[]NAME="$ac_cv_lib[]Name[]_ltlibs"INC[]NAME="$ac_cv_lib[]Name[]_cppflags"AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME)AC_SUBST([LIB]NAME)AC_SUBST([LTLIB]NAME)dnl Also set HAVE_LIB[]NAME so that AC_LIB_HAVE_LINKFLAGS can reuse thednl results of this search when this library appears as a dependency.HAVE_LIB[]NAME=yesundefine([Name])undefine([NAME])])dnl AC_LIB_HAVE_LINKFLAGS(name, dependencies, includes, testcode)dnl searches for libname and the libraries corresponding to explicit anddnl implicit dependencies, together with the specified include files anddnl the ability to compile and link the specified testcode. If found, itdnl sets and AC_SUBSTs HAVE_LIB${NAME}=yes and the LIB${NAME} anddnl LTLIB${NAME} variables and augments the CPPFLAGS variable, anddnl #defines HAVE_LIB${NAME} to 1. Otherwise, it sets and AC_SUBSTsdnl HAVE_LIB${NAME}=no and LIB${NAME} and LTLIB${NAME} to empty.AC_DEFUN([AC_LIB_HAVE_LINKFLAGS],[AC_REQUIRE([AC_LIB_PREPARE_PREFIX])AC_REQUIRE([AC_LIB_RPATH])define([Name],[translit([$1],[./-], [___])])define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])dnl Search for lib[]Name and define LIB[]NAME, LTLIB[]NAME and INC[]NAMEdnl accordingly.AC_LIB_LINKFLAGS_BODY([$1], [$2])dnl Add $INC[]NAME to CPPFLAGS before performing the following checks,dnl because if the user has installed lib[]Name and not disabled its usednl via --without-lib[]Name-prefix, he wants to use it.ac_save_CPPFLAGS="$CPPFLAGS"AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME)AC_CACHE_CHECK([for lib[]$1], [ac_cv_lib[]Name], [ac_save_LIBS="$LIBS"LIBS="$LIBS $LIB[]NAME"AC_TRY_LINK([$3], [$4], [ac_cv_lib[]Name=yes], [ac_cv_lib[]Name=no])LIBS="$ac_save_LIBS"])if test "$ac_cv_lib[]Name" = yes; thenHAVE_LIB[]NAME=yesAC_DEFINE([HAVE_LIB]NAME, 1, [Define if you have the $1 library.])AC_MSG_CHECKING([how to link with lib[]$1])AC_MSG_RESULT([$LIB[]NAME])elseHAVE_LIB[]NAME=nodnl If $LIB[]NAME didn't lead to a usable library, we don't needdnl $INC[]NAME either.CPPFLAGS="$ac_save_CPPFLAGS"LIB[]NAME=LTLIB[]NAME=fiAC_SUBST([HAVE_LIB]NAME)AC_SUBST([LIB]NAME)AC_SUBST([LTLIB]NAME)undefine([Name])undefine([NAME])])dnl Determine the platform dependent parameters needed to use rpath:dnl libext, shlibext, hardcode_libdir_flag_spec, hardcode_libdir_separator,dnl hardcode_direct, hardcode_minus_L.AC_DEFUN([AC_LIB_RPATH],[AC_REQUIRE([AC_PROG_CC]) dnl we use $CC, $GCC, $LDFLAGSAC_REQUIRE([AC_LIB_PROG_LD]) dnl we use $LD, $with_gnu_ldAC_REQUIRE([AC_CANONICAL_HOST]) dnl we use $hostAC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT]) dnl we use $ac_aux_dirAC_CACHE_CHECK([for shared library run path origin], acl_cv_rpath, [CC="$CC" GCC="$GCC" LDFLAGS="$LDFLAGS" LD="$LD" with_gnu_ld="$with_gnu_ld" \${CONFIG_SHELL-/bin/sh} "$ac_aux_dir/config.rpath" "$host" > conftest.sh. ./conftest.shrm -f ./conftest.shacl_cv_rpath=done])wl="$acl_cv_wl"libext="$acl_cv_libext"shlibext="$acl_cv_shlibext"hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec"hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator"hardcode_direct="$acl_cv_hardcode_direct"hardcode_minus_L="$acl_cv_hardcode_minus_L"dnl Determine whether the user wants rpath handling at all.AC_ARG_ENABLE(rpath,[ --disable-rpath do not hardcode runtime library paths],:, enable_rpath=yes)])dnl AC_LIB_LINKFLAGS_BODY(name [, dependencies]) searches for libname anddnl the libraries corresponding to explicit and implicit dependencies.dnl Sets the LIB${NAME}, LTLIB${NAME} and INC${NAME} variables.AC_DEFUN([AC_LIB_LINKFLAGS_BODY],[define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])dnl By default, look in $includedir and $libdir.use_additional=yesAC_LIB_WITH_FINAL_PREFIX([eval additional_includedir=\"$includedir\"eval additional_libdir=\"$libdir\"])AC_LIB_ARG_WITH([lib$1-prefix],[ --with-lib$1-prefix[=DIR] search for lib$1 in DIR/include and DIR/lib--without-lib$1-prefix don't search for lib$1 in includedir and libdir],[if test "X$withval" = "Xno"; thenuse_additional=noelseif test "X$withval" = "X"; thenAC_LIB_WITH_FINAL_PREFIX([eval additional_includedir=\"$includedir\"eval additional_libdir=\"$libdir\"])elseadditional_includedir="$withval/include"additional_libdir="$withval/lib"fifi])dnl Search the library and its dependencies in $additional_libdir anddnl $LDFLAGS. Using breadth-first-seach.LIB[]NAME=LTLIB[]NAME=INC[]NAME=rpathdirs=ltrpathdirs=names_already_handled=names_next_round='$1 $2'while test -n "$names_next_round"; donames_this_round="$names_next_round"names_next_round=for name in $names_this_round; doalready_handled=for n in $names_already_handled; doif test "$n" = "$name"; thenalready_handled=yesbreakfidoneif test -z "$already_handled"; thennames_already_handled="$names_already_handled $name"dnl See if it was already located by an earlier AC_LIB_LINKFLAGSdnl or AC_LIB_HAVE_LINKFLAGS call.uppername=`echo "$name" | sed -e 'y|abcdefghijklmnopqrstuvwxyz./-|ABCDEFGHIJKLMNOPQRSTUVWXYZ___|'`eval value=\"\$HAVE_LIB$uppername\"if test -n "$value"; thenif test "$value" = yes; theneval value=\"\$LIB$uppername\"test -z "$value" || LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$value"eval value=\"\$LTLIB$uppername\"test -z "$value" || LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$value"elsednl An earlier call to AC_LIB_HAVE_LINKFLAGS has determineddnl that this library doesn't exist. So just drop it.:fielsednl Search the library lib$name in $additional_libdir and $LDFLAGSdnl and the already constructed $LIBNAME/$LTLIBNAME.found_dir=found_la=found_so=found_a=if test $use_additional = yes; thenif test -n "$shlibext" && test -f "$additional_libdir/lib$name.$shlibext"; thenfound_dir="$additional_libdir"found_so="$additional_libdir/lib$name.$shlibext"if test -f "$additional_libdir/lib$name.la"; thenfound_la="$additional_libdir/lib$name.la"fielseif test -f "$additional_libdir/lib$name.$libext"; thenfound_dir="$additional_libdir"found_a="$additional_libdir/lib$name.$libext"if test -f "$additional_libdir/lib$name.la"; thenfound_la="$additional_libdir/lib$name.la"fifififiif test "X$found_dir" = "X"; thenfor x in $LDFLAGS $LTLIB[]NAME; doAC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])case "$x" in-L*)dir=`echo "X$x" | sed -e 's/^X-L//'`if test -n "$shlibext" && test -f "$dir/lib$name.$shlibext"; thenfound_dir="$dir"found_so="$dir/lib$name.$shlibext"if test -f "$dir/lib$name.la"; thenfound_la="$dir/lib$name.la"fielseif test -f "$dir/lib$name.$libext"; thenfound_dir="$dir"found_a="$dir/lib$name.$libext"if test -f "$dir/lib$name.la"; thenfound_la="$dir/lib$name.la"fififi;;esacif test "X$found_dir" != "X"; thenbreakfidonefiif test "X$found_dir" != "X"; thendnl Found the library.LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$found_dir -l$name"if test "X$found_so" != "X"; thendnl Linking with a shared library. We attempt to hardcode itsdnl directory into the executable's runpath, unless it's thednl standard /usr/lib.if test "$enable_rpath" = no || test "X$found_dir" = "X/usr/lib"; thendnl No hardcoding is needed.LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"elsednl Use an explicit option to hardcode DIR into the resultingdnl binary.dnl Potentially add DIR to ltrpathdirs.dnl The ltrpathdirs will be appended to $LTLIBNAME at the end.haveit=for x in $ltrpathdirs; doif test "X$x" = "X$found_dir"; thenhaveit=yesbreakfidoneif test -z "$haveit"; thenltrpathdirs="$ltrpathdirs $found_dir"fidnl The hardcoding into $LIBNAME is system dependent.if test "$hardcode_direct" = yes; thendnl Using DIR/libNAME.so during linking hardcodes DIR into thednl resulting binary.LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"elseif test -n "$hardcode_libdir_flag_spec" && test "$hardcode_minus_L" = no; thendnl Use an explicit option to hardcode DIR into the resultingdnl binary.LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"dnl Potentially add DIR to rpathdirs.dnl The rpathdirs will be appended to $LIBNAME at the end.haveit=for x in $rpathdirs; doif test "X$x" = "X$found_dir"; thenhaveit=yesbreakfidoneif test -z "$haveit"; thenrpathdirs="$rpathdirs $found_dir"fielsednl Rely on "-L$found_dir".dnl But don't add it if it's already contained in the LDFLAGSdnl or the already constructed $LIBNAMEhaveit=for x in $LDFLAGS $LIB[]NAME; doAC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])if test "X$x" = "X-L$found_dir"; thenhaveit=yesbreakfidoneif test -z "$haveit"; thenLIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir"fiif test "$hardcode_minus_L" != no; thendnl FIXME: Not sure whether we should usednl "-L$found_dir -l$name" or "-L$found_dir $found_so"dnl here.LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"elsednl We cannot use $hardcode_runpath_var and LD_RUN_PATHdnl here, because this doesn't fit in flags passed to thednl compiler. So give up. No hardcoding. This affects onlydnl very old systems.dnl FIXME: Not sure whether we should usednl "-L$found_dir -l$name" or "-L$found_dir $found_so"dnl here.LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name"fifififielseif test "X$found_a" != "X"; thendnl Linking with a static library.LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_a"elsednl We shouldn't come here, but anyway it's good to have adnl fallback.LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir -l$name"fifidnl Assume the include files are nearby.additional_includedir=case "$found_dir" in*/lib | */lib/)basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e 's,/lib/*$,,'`additional_includedir="$basedir/include";;esacif test "X$additional_includedir" != "X"; thendnl Potentially add $additional_includedir to $INCNAME.dnl But don't add itdnl 1. if it's the standard /usr/include,dnl 2. if it's /usr/local/include and we are using GCC on Linux,dnl 3. if it's already present in $CPPFLAGS or the alreadydnl constructed $INCNAME,dnl 4. if it doesn't exist as a directory.if test "X$additional_includedir" != "X/usr/include"; thenhaveit=if test "X$additional_includedir" = "X/usr/local/include"; thenif test -n "$GCC"; thencase $host_os inlinux*) haveit=yes;;esacfifiif test -z "$haveit"; thenfor x in $CPPFLAGS $INC[]NAME; doAC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])if test "X$x" = "X-I$additional_includedir"; thenhaveit=yesbreakfidoneif test -z "$haveit"; thenif test -d "$additional_includedir"; thendnl Really add $additional_includedir to $INCNAME.INC[]NAME="${INC[]NAME}${INC[]NAME:+ }-I$additional_includedir"fififififidnl Look for dependencies.if test -n "$found_la"; thendnl Read the .la file. It defines the variablesdnl dlname, library_names, old_library, dependency_libs, current,dnl age, revision, installed, dlopen, dlpreopen, libdir.save_libdir="$libdir"case "$found_la" in*/* | *\\*) . "$found_la" ;;*) . "./$found_la" ;;esaclibdir="$save_libdir"dnl We use only dependency_libs.for dep in $dependency_libs; docase "$dep" in-L*)additional_libdir=`echo "X$dep" | sed -e 's/^X-L//'`dnl Potentially add $additional_libdir to $LIBNAME and $LTLIBNAME.dnl But don't add itdnl 1. if it's the standard /usr/lib,dnl 2. if it's /usr/local/lib and we are using GCC on Linux,dnl 3. if it's already present in $LDFLAGS or the alreadydnl constructed $LIBNAME,dnl 4. if it doesn't exist as a directory.if test "X$additional_libdir" != "X/usr/lib"; thenhaveit=if test "X$additional_libdir" = "X/usr/local/lib"; thenif test -n "$GCC"; thencase $host_os inlinux*) haveit=yes;;esacfifiif test -z "$haveit"; thenhaveit=for x in $LDFLAGS $LIB[]NAME; doAC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])if test "X$x" = "X-L$additional_libdir"; thenhaveit=yesbreakfidoneif test -z "$haveit"; thenif test -d "$additional_libdir"; thendnl Really add $additional_libdir to $LIBNAME.LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$additional_libdir"fifihaveit=for x in $LDFLAGS $LTLIB[]NAME; doAC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])if test "X$x" = "X-L$additional_libdir"; thenhaveit=yesbreakfidoneif test -z "$haveit"; thenif test -d "$additional_libdir"; thendnl Really add $additional_libdir to $LTLIBNAME.LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$additional_libdir"fifififi;;-R*)dir=`echo "X$dep" | sed -e 's/^X-R//'`if test "$enable_rpath" != no; thendnl Potentially add DIR to rpathdirs.dnl The rpathdirs will be appended to $LIBNAME at the end.haveit=for x in $rpathdirs; doif test "X$x" = "X$dir"; thenhaveit=yesbreakfidoneif test -z "$haveit"; thenrpathdirs="$rpathdirs $dir"fidnl Potentially add DIR to ltrpathdirs.dnl The ltrpathdirs will be appended to $LTLIBNAME at the end.haveit=for x in $ltrpathdirs; doif test "X$x" = "X$dir"; thenhaveit=yesbreakfidoneif test -z "$haveit"; thenltrpathdirs="$ltrpathdirs $dir"fifi;;-l*)dnl Handle this in the next round.names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'`;;*.la)dnl Handle this in the next round. Throw away the .la'sdnl directory; it is already contained in a preceding -Ldnl option.names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'`;;*)dnl Most likely an immediate library name.LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$dep"LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$dep";;esacdonefielsednl Didn't find the library; assume it is in the system directoriesdnl known to the linker and runtime loader. (All the systemdnl directories known to the linker should also be known to thednl runtime loader, otherwise the system is severely misconfigured.)LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name"LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-l$name"fififidonedoneif test "X$rpathdirs" != "X"; thenif test -n "$hardcode_libdir_separator"; thendnl Weird platform: only the last -rpath option counts, the user mustdnl pass all path elements in one option. We can arrange that for adnl single library, but not when more than one $LIBNAMEs are used.alldirs=for found_dir in $rpathdirs; doalldirs="${alldirs}${alldirs:+$hardcode_libdir_separator}$found_dir"donednl Note: hardcode_libdir_flag_spec uses $libdir and $wl.acl_save_libdir="$libdir"libdir="$alldirs"eval flag=\"$hardcode_libdir_flag_spec\"libdir="$acl_save_libdir"LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag"elsednl The -rpath options are cumulative.for found_dir in $rpathdirs; doacl_save_libdir="$libdir"libdir="$found_dir"eval flag=\"$hardcode_libdir_flag_spec\"libdir="$acl_save_libdir"LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag"donefifiif test "X$ltrpathdirs" != "X"; thendnl When using libtool, the option that works for both libraries anddnl executables is -R. The -R options are cumulative.for found_dir in $ltrpathdirs; doLTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-R$found_dir"donefi])dnl AC_LIB_APPENDTOVAR(VAR, CONTENTS) appends the elements of CONTENTS to VAR,dnl unless already present in VAR.dnl Works only for CPPFLAGS, not for LIB* variables because that sometimesdnl contains two or three consecutive elements that belong together.AC_DEFUN([AC_LIB_APPENDTOVAR],[for element in [$2]; dohaveit=for x in $[$1]; doAC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])if test "X$x" = "X$element"; thenhaveit=yesbreakfidoneif test -z "$haveit"; then[$1]="${[$1]}${[$1]:+ }$element"fidone])