lib-link.m4 32 KB

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