lib-link.m4 31 KB

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