lib-link.m4 31 KB

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