lib-link.m4 32 KB

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