You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

644 lines
26 KiB

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