lib-link.m4 31 KB

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