jpayne@68: # lib-link.m4 serial 34 jpayne@68: dnl Copyright (C) 2001-2024 Free Software Foundation, Inc. jpayne@68: dnl This file is free software; the Free Software Foundation jpayne@68: dnl gives unlimited permission to copy and/or distribute it, jpayne@68: dnl with or without modifications, as long as this notice is preserved. jpayne@68: jpayne@68: dnl From Bruno Haible. jpayne@68: jpayne@68: AC_PREREQ([2.61]) jpayne@68: jpayne@68: dnl AC_LIB_LINKFLAGS(name [, dependencies]) searches for libname and jpayne@68: dnl the libraries corresponding to explicit and implicit dependencies. jpayne@68: dnl Sets and AC_SUBSTs the LIB${NAME} and LTLIB${NAME} variables and jpayne@68: dnl augments the CPPFLAGS variable. jpayne@68: dnl Sets and AC_SUBSTs the LIB${NAME}_PREFIX variable to nonempty if libname jpayne@68: dnl was found in ${LIB${NAME}_PREFIX}/$acl_libdirstem. jpayne@68: AC_DEFUN([AC_LIB_LINKFLAGS], jpayne@68: [ jpayne@68: AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) jpayne@68: AC_REQUIRE([AC_LIB_RPATH]) jpayne@68: pushdef([Name],[m4_translit([$1],[./+-], [____])]) jpayne@68: pushdef([NAME],[m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./+-], jpayne@68: [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])]) jpayne@68: AC_CACHE_CHECK([how to link with lib[]$1], [ac_cv_lib[]Name[]_libs], [ jpayne@68: AC_LIB_LINKFLAGS_BODY([$1], [$2]) jpayne@68: ac_cv_lib[]Name[]_libs="$LIB[]NAME" jpayne@68: ac_cv_lib[]Name[]_ltlibs="$LTLIB[]NAME" jpayne@68: ac_cv_lib[]Name[]_cppflags="$INC[]NAME" jpayne@68: ac_cv_lib[]Name[]_prefix="$LIB[]NAME[]_PREFIX" jpayne@68: ]) jpayne@68: LIB[]NAME="$ac_cv_lib[]Name[]_libs" jpayne@68: LTLIB[]NAME="$ac_cv_lib[]Name[]_ltlibs" jpayne@68: INC[]NAME="$ac_cv_lib[]Name[]_cppflags" jpayne@68: LIB[]NAME[]_PREFIX="$ac_cv_lib[]Name[]_prefix" jpayne@68: AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME) jpayne@68: AC_SUBST([LIB]NAME) jpayne@68: AC_SUBST([LTLIB]NAME) jpayne@68: AC_SUBST([LIB]NAME[_PREFIX]) jpayne@68: dnl Also set HAVE_LIB[]NAME so that AC_LIB_HAVE_LINKFLAGS can reuse the jpayne@68: dnl results of this search when this library appears as a dependency. jpayne@68: HAVE_LIB[]NAME=yes jpayne@68: popdef([NAME]) jpayne@68: popdef([Name]) jpayne@68: ]) jpayne@68: jpayne@68: dnl AC_LIB_HAVE_LINKFLAGS(name, dependencies, includes, testcode, [missing-message]) jpayne@68: dnl searches for libname and the libraries corresponding to explicit and jpayne@68: dnl implicit dependencies, together with the specified include files and jpayne@68: dnl the ability to compile and link the specified testcode. The missing-message jpayne@68: dnl defaults to 'no' and may contain additional hints for the user. jpayne@68: dnl If found, it sets and AC_SUBSTs HAVE_LIB${NAME}=yes and the LIB${NAME} jpayne@68: dnl and LTLIB${NAME} variables and augments the CPPFLAGS variable, and jpayne@68: dnl #defines HAVE_LIB${NAME} to 1. Otherwise, it sets and AC_SUBSTs jpayne@68: dnl HAVE_LIB${NAME}=no and LIB${NAME} and LTLIB${NAME} to empty. jpayne@68: dnl Sets and AC_SUBSTs the LIB${NAME}_PREFIX variable to nonempty if libname jpayne@68: dnl was found in ${LIB${NAME}_PREFIX}/$acl_libdirstem. jpayne@68: AC_DEFUN([AC_LIB_HAVE_LINKFLAGS], jpayne@68: [ jpayne@68: AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) jpayne@68: AC_REQUIRE([AC_LIB_RPATH]) jpayne@68: pushdef([Name],[m4_translit([$1],[./+-], [____])]) jpayne@68: pushdef([NAME],[m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./+-], jpayne@68: [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])]) jpayne@68: jpayne@68: dnl Search for lib[]Name and define LIB[]NAME, LTLIB[]NAME and INC[]NAME jpayne@68: dnl accordingly. jpayne@68: AC_LIB_LINKFLAGS_BODY([$1], [$2]) jpayne@68: jpayne@68: dnl Add $INC[]NAME to CPPFLAGS before performing the following checks, jpayne@68: dnl because if the user has installed lib[]Name and not disabled its use jpayne@68: dnl via --without-lib[]Name-prefix, he wants to use it. jpayne@68: acl_saved_CPPFLAGS="$CPPFLAGS" jpayne@68: AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME) jpayne@68: jpayne@68: AC_CACHE_CHECK([for lib[]$1], [ac_cv_lib[]Name], [ jpayne@68: acl_saved_LIBS="$LIBS" jpayne@68: dnl If $LIB[]NAME contains some -l options, add it to the end of LIBS, jpayne@68: dnl because these -l options might require -L options that are present in jpayne@68: dnl LIBS. -l options benefit only from the -L options listed before it. jpayne@68: dnl Otherwise, add it to the front of LIBS, because it may be a static jpayne@68: dnl library that depends on another static library that is present in LIBS. jpayne@68: dnl Static libraries benefit only from the static libraries listed after jpayne@68: dnl it. jpayne@68: case " $LIB[]NAME" in jpayne@68: *" -l"*) LIBS="$LIBS $LIB[]NAME" ;; jpayne@68: *) LIBS="$LIB[]NAME $LIBS" ;; jpayne@68: esac jpayne@68: AC_LINK_IFELSE( jpayne@68: [AC_LANG_PROGRAM([[$3]], [[$4]])], jpayne@68: [ac_cv_lib[]Name=yes], jpayne@68: [ac_cv_lib[]Name='m4_if([$5], [], [no], [[$5]])']) jpayne@68: LIBS="$acl_saved_LIBS" jpayne@68: ]) jpayne@68: if test "$ac_cv_lib[]Name" = yes; then jpayne@68: HAVE_LIB[]NAME=yes jpayne@68: AC_DEFINE([HAVE_LIB]NAME, 1, [Define if you have the lib][$1 library.]) jpayne@68: AC_MSG_CHECKING([how to link with lib[]$1]) jpayne@68: AC_MSG_RESULT([$LIB[]NAME]) jpayne@68: else jpayne@68: HAVE_LIB[]NAME=no jpayne@68: dnl If $LIB[]NAME didn't lead to a usable library, we don't need jpayne@68: dnl $INC[]NAME either. jpayne@68: CPPFLAGS="$acl_saved_CPPFLAGS" jpayne@68: LIB[]NAME= jpayne@68: LTLIB[]NAME= jpayne@68: LIB[]NAME[]_PREFIX= jpayne@68: fi jpayne@68: AC_SUBST([HAVE_LIB]NAME) jpayne@68: AC_SUBST([LIB]NAME) jpayne@68: AC_SUBST([LTLIB]NAME) jpayne@68: AC_SUBST([LIB]NAME[_PREFIX]) jpayne@68: popdef([NAME]) jpayne@68: popdef([Name]) jpayne@68: ]) jpayne@68: jpayne@68: dnl Determine the platform dependent parameters needed to use rpath: jpayne@68: dnl acl_libext, jpayne@68: dnl acl_shlibext, jpayne@68: dnl acl_libname_spec, jpayne@68: dnl acl_library_names_spec, jpayne@68: dnl acl_hardcode_libdir_flag_spec, jpayne@68: dnl acl_hardcode_libdir_separator, jpayne@68: dnl acl_hardcode_direct, jpayne@68: dnl acl_hardcode_minus_L. jpayne@68: AC_DEFUN([AC_LIB_RPATH], jpayne@68: [ jpayne@68: dnl Complain if config.rpath is missing. jpayne@68: AC_REQUIRE_AUX_FILE([config.rpath]) jpayne@68: AC_REQUIRE([AC_PROG_CC]) dnl we use $CC, $GCC, $LDFLAGS jpayne@68: AC_REQUIRE([AC_LIB_PROG_LD]) dnl we use $LD, $with_gnu_ld jpayne@68: AC_REQUIRE([AC_CANONICAL_HOST]) dnl we use $host jpayne@68: AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT]) dnl we use $ac_aux_dir jpayne@68: AC_CACHE_CHECK([for shared library run path origin], [acl_cv_rpath], [ jpayne@68: CC="$CC" GCC="$GCC" LDFLAGS="$LDFLAGS" LD="$LD" with_gnu_ld="$with_gnu_ld" \ jpayne@68: ${CONFIG_SHELL-/bin/sh} "$ac_aux_dir/config.rpath" "$host" > conftest.sh jpayne@68: . ./conftest.sh jpayne@68: rm -f ./conftest.sh jpayne@68: acl_cv_rpath=done jpayne@68: ]) jpayne@68: wl="$acl_cv_wl" jpayne@68: acl_libext="$acl_cv_libext" jpayne@68: acl_shlibext="$acl_cv_shlibext" jpayne@68: acl_libname_spec="$acl_cv_libname_spec" jpayne@68: acl_library_names_spec="$acl_cv_library_names_spec" jpayne@68: acl_hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec" jpayne@68: acl_hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator" jpayne@68: acl_hardcode_direct="$acl_cv_hardcode_direct" jpayne@68: acl_hardcode_minus_L="$acl_cv_hardcode_minus_L" jpayne@68: dnl Determine whether the user wants rpath handling at all. jpayne@68: AC_ARG_ENABLE([rpath], jpayne@68: [ --disable-rpath do not hardcode runtime library paths], jpayne@68: :, enable_rpath=yes) jpayne@68: ]) jpayne@68: jpayne@68: dnl AC_LIB_FROMPACKAGE(name, package) jpayne@68: dnl declares that libname comes from the given package. The configure file jpayne@68: dnl will then not have a --with-libname-prefix option but a jpayne@68: dnl --with-package-prefix option. Several libraries can come from the same jpayne@68: dnl package. This declaration must occur before an AC_LIB_LINKFLAGS or similar jpayne@68: dnl macro call that searches for libname. jpayne@68: AC_DEFUN([AC_LIB_FROMPACKAGE], jpayne@68: [ jpayne@68: pushdef([NAME],[m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./+-], jpayne@68: [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])]) jpayne@68: define([acl_frompackage_]NAME, [$2]) jpayne@68: popdef([NAME]) jpayne@68: pushdef([PACK],[$2]) jpayne@68: pushdef([PACKUP],[m4_translit(PACK,[abcdefghijklmnopqrstuvwxyz./+-], jpayne@68: [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])]) jpayne@68: define([acl_libsinpackage_]PACKUP, jpayne@68: m4_ifdef([acl_libsinpackage_]PACKUP, [m4_defn([acl_libsinpackage_]PACKUP)[, ]],)[lib$1]) jpayne@68: popdef([PACKUP]) jpayne@68: popdef([PACK]) jpayne@68: ]) jpayne@68: jpayne@68: dnl AC_LIB_LINKFLAGS_BODY(name [, dependencies]) searches for libname and jpayne@68: dnl the libraries corresponding to explicit and implicit dependencies. jpayne@68: dnl Sets the LIB${NAME}, LTLIB${NAME} and INC${NAME} variables. jpayne@68: dnl Also, sets the LIB${NAME}_PREFIX variable to nonempty if libname was found jpayne@68: dnl in ${LIB${NAME}_PREFIX}/$acl_libdirstem. jpayne@68: AC_DEFUN([AC_LIB_LINKFLAGS_BODY], jpayne@68: [ jpayne@68: AC_REQUIRE([AC_LIB_PREPARE_MULTILIB]) jpayne@68: pushdef([NAME],[m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./+-], jpayne@68: [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])]) jpayne@68: pushdef([PACK],[m4_ifdef([acl_frompackage_]NAME, [acl_frompackage_]NAME, lib[$1])]) jpayne@68: pushdef([PACKUP],[m4_translit(PACK,[abcdefghijklmnopqrstuvwxyz./+-], jpayne@68: [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])]) jpayne@68: pushdef([PACKLIBS],[m4_ifdef([acl_frompackage_]NAME, [acl_libsinpackage_]PACKUP, lib[$1])]) jpayne@68: dnl By default, look in $includedir and $libdir. jpayne@68: use_additional=yes jpayne@68: AC_LIB_WITH_FINAL_PREFIX([ jpayne@68: eval additional_includedir=\"$includedir\" jpayne@68: eval additional_libdir=\"$libdir\" jpayne@68: eval additional_libdir2=\"$exec_prefix/$acl_libdirstem2\" jpayne@68: eval additional_libdir3=\"$exec_prefix/$acl_libdirstem3\" jpayne@68: ]) jpayne@68: AC_ARG_WITH(PACK[-prefix], jpayne@68: [[ --with-]]PACK[[-prefix[=DIR] search for ]]PACKLIBS[[ in DIR/include and DIR/lib jpayne@68: --without-]]PACK[[-prefix don't search for ]]PACKLIBS[[ in includedir and libdir]], jpayne@68: [ jpayne@68: if test "X$withval" = "Xno"; then jpayne@68: use_additional=no jpayne@68: else jpayne@68: if test "X$withval" = "X"; then jpayne@68: AC_LIB_WITH_FINAL_PREFIX([ jpayne@68: eval additional_includedir=\"$includedir\" jpayne@68: eval additional_libdir=\"$libdir\" jpayne@68: eval additional_libdir2=\"$exec_prefix/$acl_libdirstem2\" jpayne@68: eval additional_libdir3=\"$exec_prefix/$acl_libdirstem3\" jpayne@68: ]) jpayne@68: else jpayne@68: additional_includedir="$withval/include" jpayne@68: additional_libdir="$withval/$acl_libdirstem" jpayne@68: additional_libdir2="$withval/$acl_libdirstem2" jpayne@68: additional_libdir3="$withval/$acl_libdirstem3" jpayne@68: fi jpayne@68: fi jpayne@68: ]) jpayne@68: if test "X$additional_libdir2" = "X$additional_libdir"; then jpayne@68: additional_libdir2= jpayne@68: fi jpayne@68: if test "X$additional_libdir3" = "X$additional_libdir"; then jpayne@68: additional_libdir3= jpayne@68: fi jpayne@68: dnl Search the library and its dependencies in $additional_libdir and jpayne@68: dnl $LDFLAGS. Use breadth-first search. jpayne@68: LIB[]NAME= jpayne@68: LTLIB[]NAME= jpayne@68: INC[]NAME= jpayne@68: LIB[]NAME[]_PREFIX= jpayne@68: dnl HAVE_LIB${NAME} is an indicator that LIB${NAME}, LTLIB${NAME} have been jpayne@68: dnl computed. So it has to be reset here. jpayne@68: HAVE_LIB[]NAME= jpayne@68: rpathdirs= jpayne@68: ltrpathdirs= jpayne@68: names_already_handled= jpayne@68: names_next_round='$1 $2' jpayne@68: while test -n "$names_next_round"; do jpayne@68: names_this_round="$names_next_round" jpayne@68: names_next_round= jpayne@68: for name in $names_this_round; do jpayne@68: already_handled= jpayne@68: for n in $names_already_handled; do jpayne@68: if test "$n" = "$name"; then jpayne@68: already_handled=yes jpayne@68: break jpayne@68: fi jpayne@68: done jpayne@68: if test -z "$already_handled"; then jpayne@68: names_already_handled="$names_already_handled $name" jpayne@68: dnl See if it was already located by an earlier AC_LIB_LINKFLAGS jpayne@68: dnl or AC_LIB_HAVE_LINKFLAGS call. jpayne@68: uppername=`echo "$name" | sed -e 'y|abcdefghijklmnopqrstuvwxyz./+-|ABCDEFGHIJKLMNOPQRSTUVWXYZ____|'` jpayne@68: eval value=\"\$HAVE_LIB$uppername\" jpayne@68: if test -n "$value"; then jpayne@68: if test "$value" = yes; then jpayne@68: eval value=\"\$LIB$uppername\" jpayne@68: test -z "$value" || LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$value" jpayne@68: eval value=\"\$LTLIB$uppername\" jpayne@68: test -z "$value" || LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$value" jpayne@68: else jpayne@68: dnl An earlier call to AC_LIB_HAVE_LINKFLAGS has determined jpayne@68: dnl that this library doesn't exist. So just drop it. jpayne@68: : jpayne@68: fi jpayne@68: else jpayne@68: dnl Search the library lib$name in $additional_libdir and $LDFLAGS jpayne@68: dnl and the already constructed $LIBNAME/$LTLIBNAME. jpayne@68: found_dir= jpayne@68: found_la= jpayne@68: found_so= jpayne@68: found_a= jpayne@68: eval libname=\"$acl_libname_spec\" # typically: libname=lib$name jpayne@68: if test -n "$acl_shlibext"; then jpayne@68: shrext=".$acl_shlibext" # typically: shrext=.so jpayne@68: else jpayne@68: shrext= jpayne@68: fi jpayne@68: if test $use_additional = yes; then jpayne@68: for additional_libdir_variable in additional_libdir additional_libdir2 additional_libdir3; do jpayne@68: if test "X$found_dir" = "X"; then jpayne@68: eval dir=\$$additional_libdir_variable jpayne@68: if test -n "$dir"; then jpayne@68: dnl The same code as in the loop below: jpayne@68: dnl First look for a shared library. jpayne@68: if test -n "$acl_shlibext"; then jpayne@68: if test -f "$dir/$libname$shrext" && acl_is_expected_elfclass < "$dir/$libname$shrext"; then jpayne@68: found_dir="$dir" jpayne@68: found_so="$dir/$libname$shrext" jpayne@68: else jpayne@68: if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then jpayne@68: ver=`(cd "$dir" && \ jpayne@68: for f in "$libname$shrext".*; do echo "$f"; done \ jpayne@68: | sed -e "s,^$libname$shrext\\\\.,," \ jpayne@68: | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \ jpayne@68: | sed 1q ) 2>/dev/null` jpayne@68: if test -n "$ver" && test -f "$dir/$libname$shrext.$ver" && acl_is_expected_elfclass < "$dir/$libname$shrext.$ver"; then jpayne@68: found_dir="$dir" jpayne@68: found_so="$dir/$libname$shrext.$ver" jpayne@68: fi jpayne@68: else jpayne@68: eval library_names=\"$acl_library_names_spec\" jpayne@68: for f in $library_names; do jpayne@68: if test -f "$dir/$f" && acl_is_expected_elfclass < "$dir/$f"; then jpayne@68: found_dir="$dir" jpayne@68: found_so="$dir/$f" jpayne@68: break jpayne@68: fi jpayne@68: done jpayne@68: fi jpayne@68: fi jpayne@68: fi jpayne@68: dnl Then look for a static library. jpayne@68: if test "X$found_dir" = "X"; then jpayne@68: if test -f "$dir/$libname.$acl_libext" && ${AR-ar} -p "$dir/$libname.$acl_libext" | acl_is_expected_elfclass; then jpayne@68: found_dir="$dir" jpayne@68: found_a="$dir/$libname.$acl_libext" jpayne@68: fi jpayne@68: fi jpayne@68: if test "X$found_dir" != "X"; then jpayne@68: if test -f "$dir/$libname.la"; then jpayne@68: found_la="$dir/$libname.la" jpayne@68: fi jpayne@68: fi jpayne@68: fi jpayne@68: fi jpayne@68: done jpayne@68: fi jpayne@68: if test "X$found_dir" = "X"; then jpayne@68: for x in $LDFLAGS $LTLIB[]NAME; do jpayne@68: AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) jpayne@68: case "$x" in jpayne@68: -L*) jpayne@68: dir=`echo "X$x" | sed -e 's/^X-L//'` jpayne@68: dnl First look for a shared library. jpayne@68: if test -n "$acl_shlibext"; then jpayne@68: if test -f "$dir/$libname$shrext" && acl_is_expected_elfclass < "$dir/$libname$shrext"; then jpayne@68: found_dir="$dir" jpayne@68: found_so="$dir/$libname$shrext" jpayne@68: else jpayne@68: if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then jpayne@68: ver=`(cd "$dir" && \ jpayne@68: for f in "$libname$shrext".*; do echo "$f"; done \ jpayne@68: | sed -e "s,^$libname$shrext\\\\.,," \ jpayne@68: | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \ jpayne@68: | sed 1q ) 2>/dev/null` jpayne@68: if test -n "$ver" && test -f "$dir/$libname$shrext.$ver" && acl_is_expected_elfclass < "$dir/$libname$shrext.$ver"; then jpayne@68: found_dir="$dir" jpayne@68: found_so="$dir/$libname$shrext.$ver" jpayne@68: fi jpayne@68: else jpayne@68: eval library_names=\"$acl_library_names_spec\" jpayne@68: for f in $library_names; do jpayne@68: if test -f "$dir/$f" && acl_is_expected_elfclass < "$dir/$f"; then jpayne@68: found_dir="$dir" jpayne@68: found_so="$dir/$f" jpayne@68: break jpayne@68: fi jpayne@68: done jpayne@68: fi jpayne@68: fi jpayne@68: fi jpayne@68: dnl Then look for a static library. jpayne@68: if test "X$found_dir" = "X"; then jpayne@68: if test -f "$dir/$libname.$acl_libext" && ${AR-ar} -p "$dir/$libname.$acl_libext" | acl_is_expected_elfclass; then jpayne@68: found_dir="$dir" jpayne@68: found_a="$dir/$libname.$acl_libext" jpayne@68: fi jpayne@68: fi jpayne@68: if test "X$found_dir" != "X"; then jpayne@68: if test -f "$dir/$libname.la"; then jpayne@68: found_la="$dir/$libname.la" jpayne@68: fi jpayne@68: fi jpayne@68: ;; jpayne@68: esac jpayne@68: if test "X$found_dir" != "X"; then jpayne@68: break jpayne@68: fi jpayne@68: done jpayne@68: fi jpayne@68: if test "X$found_dir" != "X"; then jpayne@68: dnl Found the library. jpayne@68: LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$found_dir -l$name" jpayne@68: if test "X$found_so" != "X"; then jpayne@68: dnl Linking with a shared library. We attempt to hardcode its jpayne@68: dnl directory into the executable's runpath, unless it's the jpayne@68: dnl standard /usr/lib. jpayne@68: if test "$enable_rpath" = no \ jpayne@68: || test "X$found_dir" = "X/usr/$acl_libdirstem" \ jpayne@68: || test "X$found_dir" = "X/usr/$acl_libdirstem2" \ jpayne@68: || test "X$found_dir" = "X/usr/$acl_libdirstem3"; then jpayne@68: dnl No hardcoding is needed. jpayne@68: LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" jpayne@68: else jpayne@68: dnl Use an explicit option to hardcode DIR into the resulting jpayne@68: dnl binary. jpayne@68: dnl Potentially add DIR to ltrpathdirs. jpayne@68: dnl The ltrpathdirs will be appended to $LTLIBNAME at the end. jpayne@68: haveit= jpayne@68: for x in $ltrpathdirs; do jpayne@68: if test "X$x" = "X$found_dir"; then jpayne@68: haveit=yes jpayne@68: break jpayne@68: fi jpayne@68: done jpayne@68: if test -z "$haveit"; then jpayne@68: ltrpathdirs="$ltrpathdirs $found_dir" jpayne@68: fi jpayne@68: dnl The hardcoding into $LIBNAME is system dependent. jpayne@68: if test "$acl_hardcode_direct" = yes; then jpayne@68: dnl Using DIR/libNAME.so during linking hardcodes DIR into the jpayne@68: dnl resulting binary. jpayne@68: LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" jpayne@68: else jpayne@68: if test -n "$acl_hardcode_libdir_flag_spec" && test "$acl_hardcode_minus_L" = no; then jpayne@68: dnl Use an explicit option to hardcode DIR into the resulting jpayne@68: dnl binary. jpayne@68: LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" jpayne@68: dnl Potentially add DIR to rpathdirs. jpayne@68: dnl The rpathdirs will be appended to $LIBNAME at the end. jpayne@68: haveit= jpayne@68: for x in $rpathdirs; do jpayne@68: if test "X$x" = "X$found_dir"; then jpayne@68: haveit=yes jpayne@68: break jpayne@68: fi jpayne@68: done jpayne@68: if test -z "$haveit"; then jpayne@68: rpathdirs="$rpathdirs $found_dir" jpayne@68: fi jpayne@68: else jpayne@68: dnl Rely on "-L$found_dir". jpayne@68: dnl But don't add it if it's already contained in the LDFLAGS jpayne@68: dnl or the already constructed $LIBNAME jpayne@68: haveit= jpayne@68: for x in $LDFLAGS $LIB[]NAME; do jpayne@68: AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) jpayne@68: if test "X$x" = "X-L$found_dir"; then jpayne@68: haveit=yes jpayne@68: break jpayne@68: fi jpayne@68: done jpayne@68: if test -z "$haveit"; then jpayne@68: LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir" jpayne@68: fi jpayne@68: if test "$acl_hardcode_minus_L" != no; then jpayne@68: dnl FIXME: Not sure whether we should use jpayne@68: dnl "-L$found_dir -l$name" or "-L$found_dir $found_so" jpayne@68: dnl here. jpayne@68: LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" jpayne@68: else jpayne@68: dnl We cannot use $acl_hardcode_runpath_var and LD_RUN_PATH jpayne@68: dnl here, because this doesn't fit in flags passed to the jpayne@68: dnl compiler. So give up. No hardcoding. This affects only jpayne@68: dnl very old systems. jpayne@68: dnl FIXME: Not sure whether we should use jpayne@68: dnl "-L$found_dir -l$name" or "-L$found_dir $found_so" jpayne@68: dnl here. jpayne@68: LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name" jpayne@68: fi jpayne@68: fi jpayne@68: fi jpayne@68: fi jpayne@68: else jpayne@68: if test "X$found_a" != "X"; then jpayne@68: dnl Linking with a static library. jpayne@68: LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_a" jpayne@68: else jpayne@68: dnl We shouldn't come here, but anyway it's good to have a jpayne@68: dnl fallback. jpayne@68: LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir -l$name" jpayne@68: fi jpayne@68: fi jpayne@68: dnl Assume the include files are nearby. jpayne@68: additional_includedir= jpayne@68: case "$found_dir" in jpayne@68: */$acl_libdirstem | */$acl_libdirstem/) jpayne@68: basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem/"'*$,,'` jpayne@68: if test "$name" = '$1'; then jpayne@68: LIB[]NAME[]_PREFIX="$basedir" jpayne@68: fi jpayne@68: additional_includedir="$basedir/include" jpayne@68: ;; jpayne@68: */$acl_libdirstem2 | */$acl_libdirstem2/) jpayne@68: basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem2/"'*$,,'` jpayne@68: if test "$name" = '$1'; then jpayne@68: LIB[]NAME[]_PREFIX="$basedir" jpayne@68: fi jpayne@68: additional_includedir="$basedir/include" jpayne@68: ;; jpayne@68: */$acl_libdirstem3 | */$acl_libdirstem3/) jpayne@68: basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem3/"'*$,,'` jpayne@68: if test "$name" = '$1'; then jpayne@68: LIB[]NAME[]_PREFIX="$basedir" jpayne@68: fi jpayne@68: additional_includedir="$basedir/include" jpayne@68: ;; jpayne@68: esac jpayne@68: if test "X$additional_includedir" != "X"; then jpayne@68: dnl Potentially add $additional_includedir to $INCNAME. jpayne@68: dnl But don't add it jpayne@68: dnl 1. if it's the standard /usr/include, jpayne@68: dnl 2. if it's /usr/local/include and we are using GCC on Linux, jpayne@68: dnl 3. if it's already present in $CPPFLAGS or the already jpayne@68: dnl constructed $INCNAME, jpayne@68: dnl 4. if it doesn't exist as a directory. jpayne@68: if test "X$additional_includedir" != "X/usr/include"; then jpayne@68: haveit= jpayne@68: if test "X$additional_includedir" = "X/usr/local/include"; then jpayne@68: if test -n "$GCC"; then jpayne@68: case $host_os in jpayne@68: linux* | gnu* | k*bsd*-gnu) haveit=yes;; jpayne@68: esac jpayne@68: fi jpayne@68: fi jpayne@68: if test -z "$haveit"; then jpayne@68: for x in $CPPFLAGS $INC[]NAME; do jpayne@68: AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) jpayne@68: if test "X$x" = "X-I$additional_includedir"; then jpayne@68: haveit=yes jpayne@68: break jpayne@68: fi jpayne@68: done jpayne@68: if test -z "$haveit"; then jpayne@68: if test -d "$additional_includedir"; then jpayne@68: dnl Really add $additional_includedir to $INCNAME. jpayne@68: INC[]NAME="${INC[]NAME}${INC[]NAME:+ }-I$additional_includedir" jpayne@68: fi jpayne@68: fi jpayne@68: fi jpayne@68: fi jpayne@68: fi jpayne@68: dnl Look for dependencies. jpayne@68: if test -n "$found_la"; then jpayne@68: dnl Read the .la file. It defines the variables jpayne@68: dnl dlname, library_names, old_library, dependency_libs, current, jpayne@68: dnl age, revision, installed, dlopen, dlpreopen, libdir. jpayne@68: saved_libdir="$libdir" jpayne@68: case "$found_la" in jpayne@68: */* | *\\*) . "$found_la" ;; jpayne@68: *) . "./$found_la" ;; jpayne@68: esac jpayne@68: libdir="$saved_libdir" jpayne@68: dnl We use only dependency_libs. jpayne@68: for dep in $dependency_libs; do jpayne@68: case "$dep" in jpayne@68: -L*) jpayne@68: dependency_libdir=`echo "X$dep" | sed -e 's/^X-L//'` jpayne@68: dnl Potentially add $dependency_libdir to $LIBNAME and $LTLIBNAME. jpayne@68: dnl But don't add it jpayne@68: dnl 1. if it's the standard /usr/lib, jpayne@68: dnl 2. if it's /usr/local/lib and we are using GCC on Linux, jpayne@68: dnl 3. if it's already present in $LDFLAGS or the already jpayne@68: dnl constructed $LIBNAME, jpayne@68: dnl 4. if it doesn't exist as a directory. jpayne@68: if test "X$dependency_libdir" != "X/usr/$acl_libdirstem" \ jpayne@68: && test "X$dependency_libdir" != "X/usr/$acl_libdirstem2" \ jpayne@68: && test "X$dependency_libdir" != "X/usr/$acl_libdirstem3"; then jpayne@68: haveit= jpayne@68: if test "X$dependency_libdir" = "X/usr/local/$acl_libdirstem" \ jpayne@68: || test "X$dependency_libdir" = "X/usr/local/$acl_libdirstem2" \ jpayne@68: || test "X$dependency_libdir" = "X/usr/local/$acl_libdirstem3"; then jpayne@68: if test -n "$GCC"; then jpayne@68: case $host_os in jpayne@68: linux* | gnu* | k*bsd*-gnu) haveit=yes;; jpayne@68: esac jpayne@68: fi jpayne@68: fi jpayne@68: if test -z "$haveit"; then jpayne@68: haveit= jpayne@68: for x in $LDFLAGS $LIB[]NAME; do jpayne@68: AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) jpayne@68: if test "X$x" = "X-L$dependency_libdir"; then jpayne@68: haveit=yes jpayne@68: break jpayne@68: fi jpayne@68: done jpayne@68: if test -z "$haveit"; then jpayne@68: if test -d "$dependency_libdir"; then jpayne@68: dnl Really add $dependency_libdir to $LIBNAME. jpayne@68: LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$dependency_libdir" jpayne@68: fi jpayne@68: fi jpayne@68: haveit= jpayne@68: for x in $LDFLAGS $LTLIB[]NAME; do jpayne@68: AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) jpayne@68: if test "X$x" = "X-L$dependency_libdir"; then jpayne@68: haveit=yes jpayne@68: break jpayne@68: fi jpayne@68: done jpayne@68: if test -z "$haveit"; then jpayne@68: if test -d "$dependency_libdir"; then jpayne@68: dnl Really add $dependency_libdir to $LTLIBNAME. jpayne@68: LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$dependency_libdir" jpayne@68: fi jpayne@68: fi jpayne@68: fi jpayne@68: fi jpayne@68: ;; jpayne@68: -R*) jpayne@68: dir=`echo "X$dep" | sed -e 's/^X-R//'` jpayne@68: if test "$enable_rpath" != no; then jpayne@68: dnl Potentially add DIR to rpathdirs. jpayne@68: dnl The rpathdirs will be appended to $LIBNAME at the end. jpayne@68: haveit= jpayne@68: for x in $rpathdirs; do jpayne@68: if test "X$x" = "X$dir"; then jpayne@68: haveit=yes jpayne@68: break jpayne@68: fi jpayne@68: done jpayne@68: if test -z "$haveit"; then jpayne@68: rpathdirs="$rpathdirs $dir" jpayne@68: fi jpayne@68: dnl Potentially add DIR to ltrpathdirs. jpayne@68: dnl The ltrpathdirs will be appended to $LTLIBNAME at the end. jpayne@68: haveit= jpayne@68: for x in $ltrpathdirs; do jpayne@68: if test "X$x" = "X$dir"; then jpayne@68: haveit=yes jpayne@68: break jpayne@68: fi jpayne@68: done jpayne@68: if test -z "$haveit"; then jpayne@68: ltrpathdirs="$ltrpathdirs $dir" jpayne@68: fi jpayne@68: fi jpayne@68: ;; jpayne@68: -l*) jpayne@68: dnl Handle this in the next round. jpayne@68: dnl But on GNU systems, ignore -lc options, because jpayne@68: dnl - linking with libc is the default anyway, jpayne@68: dnl - linking with libc.a may produce an error jpayne@68: dnl "/usr/bin/ld: dynamic STT_GNU_IFUNC symbol `strcmp' with pointer equality in `/usr/lib/libc.a(strcmp.o)' can not be used when making an executable; recompile with -fPIE and relink with -pie" jpayne@68: dnl or may produce an executable that always crashes, see jpayne@68: dnl . jpayne@68: dep=`echo "X$dep" | sed -e 's/^X-l//'` jpayne@68: if test "X$dep" != Xc \ jpayne@68: || case $host_os in jpayne@68: linux* | gnu* | k*bsd*-gnu) false ;; jpayne@68: *) true ;; jpayne@68: esac; then jpayne@68: names_next_round="$names_next_round $dep" jpayne@68: fi jpayne@68: ;; jpayne@68: *.la) jpayne@68: dnl Handle this in the next round. Throw away the .la's jpayne@68: dnl directory; it is already contained in a preceding -L jpayne@68: dnl option. jpayne@68: names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'` jpayne@68: ;; jpayne@68: *) jpayne@68: dnl Most likely an immediate library name. jpayne@68: LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$dep" jpayne@68: LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$dep" jpayne@68: ;; jpayne@68: esac jpayne@68: done jpayne@68: fi jpayne@68: else jpayne@68: dnl Didn't find the library; assume it is in the system directories jpayne@68: dnl known to the linker and runtime loader. (All the system jpayne@68: dnl directories known to the linker should also be known to the jpayne@68: dnl runtime loader, otherwise the system is severely misconfigured.) jpayne@68: LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name" jpayne@68: LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-l$name" jpayne@68: fi jpayne@68: fi jpayne@68: fi jpayne@68: done jpayne@68: done jpayne@68: if test "X$rpathdirs" != "X"; then jpayne@68: if test -n "$acl_hardcode_libdir_separator"; then jpayne@68: dnl Weird platform: only the last -rpath option counts, the user must jpayne@68: dnl pass all path elements in one option. We can arrange that for a jpayne@68: dnl single library, but not when more than one $LIBNAMEs are used. jpayne@68: alldirs= jpayne@68: for found_dir in $rpathdirs; do jpayne@68: alldirs="${alldirs}${alldirs:+$acl_hardcode_libdir_separator}$found_dir" jpayne@68: done jpayne@68: dnl Note: acl_hardcode_libdir_flag_spec uses $libdir and $wl. jpayne@68: acl_saved_libdir="$libdir" jpayne@68: libdir="$alldirs" jpayne@68: eval flag=\"$acl_hardcode_libdir_flag_spec\" jpayne@68: libdir="$acl_saved_libdir" jpayne@68: LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag" jpayne@68: else jpayne@68: dnl The -rpath options are cumulative. jpayne@68: for found_dir in $rpathdirs; do jpayne@68: acl_saved_libdir="$libdir" jpayne@68: libdir="$found_dir" jpayne@68: eval flag=\"$acl_hardcode_libdir_flag_spec\" jpayne@68: libdir="$acl_saved_libdir" jpayne@68: LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag" jpayne@68: done jpayne@68: fi jpayne@68: fi jpayne@68: if test "X$ltrpathdirs" != "X"; then jpayne@68: dnl When using libtool, the option that works for both libraries and jpayne@68: dnl executables is -R. The -R options are cumulative. jpayne@68: for found_dir in $ltrpathdirs; do jpayne@68: LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-R$found_dir" jpayne@68: done jpayne@68: fi jpayne@68: popdef([PACKLIBS]) jpayne@68: popdef([PACKUP]) jpayne@68: popdef([PACK]) jpayne@68: popdef([NAME]) jpayne@68: ]) jpayne@68: jpayne@68: dnl AC_LIB_APPENDTOVAR(VAR, CONTENTS) appends the elements of CONTENTS to VAR, jpayne@68: dnl unless already present in VAR. jpayne@68: dnl Works only for CPPFLAGS, not for LIB* variables because that sometimes jpayne@68: dnl contains two or three consecutive elements that belong together. jpayne@68: AC_DEFUN([AC_LIB_APPENDTOVAR], jpayne@68: [ jpayne@68: for element in [$2]; do jpayne@68: haveit= jpayne@68: for x in $[$1]; do jpayne@68: AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) jpayne@68: if test "X$x" = "X$element"; then jpayne@68: haveit=yes jpayne@68: break jpayne@68: fi jpayne@68: done jpayne@68: if test -z "$haveit"; then jpayne@68: [$1]="${[$1]}${[$1]:+ }$element" jpayne@68: fi jpayne@68: done jpayne@68: ]) jpayne@68: jpayne@68: dnl For those cases where a variable contains several -L and -l options jpayne@68: dnl referring to unknown libraries and directories, this macro determines the jpayne@68: dnl necessary additional linker options for the runtime path. jpayne@68: dnl AC_LIB_LINKFLAGS_FROM_LIBS([LDADDVAR], [LIBSVALUE], [USE-LIBTOOL]) jpayne@68: dnl sets LDADDVAR to linker options needed together with LIBSVALUE. jpayne@68: dnl If USE-LIBTOOL evaluates to non-empty, linking with libtool is assumed, jpayne@68: dnl otherwise linking without libtool is assumed. jpayne@68: AC_DEFUN([AC_LIB_LINKFLAGS_FROM_LIBS], jpayne@68: [ jpayne@68: AC_REQUIRE([AC_LIB_RPATH]) jpayne@68: AC_REQUIRE([AC_LIB_PREPARE_MULTILIB]) jpayne@68: $1= jpayne@68: if test "$enable_rpath" != no; then jpayne@68: if test -n "$acl_hardcode_libdir_flag_spec" && test "$acl_hardcode_minus_L" = no; then jpayne@68: dnl Use an explicit option to hardcode directories into the resulting jpayne@68: dnl binary. jpayne@68: rpathdirs= jpayne@68: next= jpayne@68: for opt in $2; do jpayne@68: if test -n "$next"; then jpayne@68: dir="$next" jpayne@68: dnl No need to hardcode the standard /usr/lib. jpayne@68: if test "X$dir" != "X/usr/$acl_libdirstem" \ jpayne@68: && test "X$dir" != "X/usr/$acl_libdirstem2" \ jpayne@68: && test "X$dir" != "X/usr/$acl_libdirstem3"; then jpayne@68: rpathdirs="$rpathdirs $dir" jpayne@68: fi jpayne@68: next= jpayne@68: else jpayne@68: case $opt in jpayne@68: -L) next=yes ;; jpayne@68: -L*) dir=`echo "X$opt" | sed -e 's,^X-L,,'` jpayne@68: dnl No need to hardcode the standard /usr/lib. jpayne@68: if test "X$dir" != "X/usr/$acl_libdirstem" \ jpayne@68: && test "X$dir" != "X/usr/$acl_libdirstem2" \ jpayne@68: && test "X$dir" != "X/usr/$acl_libdirstem3"; then jpayne@68: rpathdirs="$rpathdirs $dir" jpayne@68: fi jpayne@68: next= ;; jpayne@68: *) next= ;; jpayne@68: esac jpayne@68: fi jpayne@68: done jpayne@68: if test "X$rpathdirs" != "X"; then jpayne@68: if test -n ""$3""; then jpayne@68: dnl libtool is used for linking. Use -R options. jpayne@68: for dir in $rpathdirs; do jpayne@68: $1="${$1}${$1:+ }-R$dir" jpayne@68: done jpayne@68: else jpayne@68: dnl The linker is used for linking directly. jpayne@68: if test -n "$acl_hardcode_libdir_separator"; then jpayne@68: dnl Weird platform: only the last -rpath option counts, the user jpayne@68: dnl must pass all path elements in one option. jpayne@68: alldirs= jpayne@68: for dir in $rpathdirs; do jpayne@68: alldirs="${alldirs}${alldirs:+$acl_hardcode_libdir_separator}$dir" jpayne@68: done jpayne@68: acl_saved_libdir="$libdir" jpayne@68: libdir="$alldirs" jpayne@68: eval flag=\"$acl_hardcode_libdir_flag_spec\" jpayne@68: libdir="$acl_saved_libdir" jpayne@68: $1="$flag" jpayne@68: else jpayne@68: dnl The -rpath options are cumulative. jpayne@68: for dir in $rpathdirs; do jpayne@68: acl_saved_libdir="$libdir" jpayne@68: libdir="$dir" jpayne@68: eval flag=\"$acl_hardcode_libdir_flag_spec\" jpayne@68: libdir="$acl_saved_libdir" jpayne@68: $1="${$1}${$1:+ }$flag" jpayne@68: done jpayne@68: fi jpayne@68: fi jpayne@68: fi jpayne@68: fi jpayne@68: fi jpayne@68: AC_SUBST([$1]) jpayne@68: ])