lib-prefix.m4 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. # lib-prefix.m4 serial 7 (gettext-0.18)
  2. dnl Copyright (C) 2001-2005, 2008-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. dnl AC_LIB_ARG_WITH is synonymous to AC_ARG_WITH in autoconf-2.13, and
  8. dnl similar to AC_ARG_WITH in autoconf 2.52...2.57 except that is doesn't
  9. dnl require excessive bracketing.
  10. ifdef([AC_HELP_STRING],
  11. [AC_DEFUN([AC_LIB_ARG_WITH], [AC_ARG_WITH([$1],[[$2]],[$3],[$4])])],
  12. [AC_DEFUN([AC_][LIB_ARG_WITH], [AC_ARG_WITH([$1],[$2],[$3],[$4])])])
  13. dnl AC_LIB_PREFIX adds to the CPPFLAGS and LDFLAGS the flags that are needed
  14. dnl to access previously installed libraries. The basic assumption is that
  15. dnl a user will want packages to use other packages he previously installed
  16. dnl with the same --prefix option.
  17. dnl This macro is not needed if only AC_LIB_LINKFLAGS is used to locate
  18. dnl libraries, but is otherwise very convenient.
  19. AC_DEFUN([AC_LIB_PREFIX],
  20. [
  21. AC_BEFORE([$0], [AC_LIB_LINKFLAGS])
  22. AC_REQUIRE([AC_PROG_CC])
  23. AC_REQUIRE([AC_CANONICAL_HOST])
  24. AC_REQUIRE([AC_LIB_PREPARE_MULTILIB])
  25. AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
  26. dnl By default, look in $includedir and $libdir.
  27. use_additional=yes
  28. AC_LIB_WITH_FINAL_PREFIX([
  29. eval additional_includedir=\"$includedir\"
  30. eval additional_libdir=\"$libdir\"
  31. ])
  32. AC_LIB_ARG_WITH([lib-prefix],
  33. [ --with-lib-prefix[=DIR] search for libraries in DIR/include and DIR/lib
  34. --without-lib-prefix don't search for libraries in includedir and libdir],
  35. [
  36. if test "X$withval" = "Xno"; then
  37. use_additional=no
  38. else
  39. if test "X$withval" = "X"; then
  40. AC_LIB_WITH_FINAL_PREFIX([
  41. eval additional_includedir=\"$includedir\"
  42. eval additional_libdir=\"$libdir\"
  43. ])
  44. else
  45. additional_includedir="$withval/include"
  46. additional_libdir="$withval/$acl_libdirstem"
  47. fi
  48. fi
  49. ])
  50. if test $use_additional = yes; then
  51. dnl Potentially add $additional_includedir to $CPPFLAGS.
  52. dnl But don't add it
  53. dnl 1. if it's the standard /usr/include,
  54. dnl 2. if it's already present in $CPPFLAGS,
  55. dnl 3. if it's /usr/local/include and we are using GCC on Linux,
  56. dnl 4. if it doesn't exist as a directory.
  57. if test "X$additional_includedir" != "X/usr/include"; then
  58. haveit=
  59. for x in $CPPFLAGS; do
  60. AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
  61. if test "X$x" = "X-I$additional_includedir"; then
  62. haveit=yes
  63. break
  64. fi
  65. done
  66. if test -z "$haveit"; then
  67. if test "X$additional_includedir" = "X/usr/local/include"; then
  68. if test -n "$GCC"; then
  69. case $host_os in
  70. linux* | gnu* | k*bsd*-gnu) haveit=yes;;
  71. esac
  72. fi
  73. fi
  74. if test -z "$haveit"; then
  75. if test -d "$additional_includedir"; then
  76. dnl Really add $additional_includedir to $CPPFLAGS.
  77. CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }-I$additional_includedir"
  78. fi
  79. fi
  80. fi
  81. fi
  82. dnl Potentially add $additional_libdir to $LDFLAGS.
  83. dnl But don't add it
  84. dnl 1. if it's the standard /usr/lib,
  85. dnl 2. if it's already present in $LDFLAGS,
  86. dnl 3. if it's /usr/local/lib and we are using GCC on Linux,
  87. dnl 4. if it doesn't exist as a directory.
  88. if test "X$additional_libdir" != "X/usr/$acl_libdirstem"; then
  89. haveit=
  90. for x in $LDFLAGS; do
  91. AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
  92. if test "X$x" = "X-L$additional_libdir"; then
  93. haveit=yes
  94. break
  95. fi
  96. done
  97. if test -z "$haveit"; then
  98. if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem"; then
  99. if test -n "$GCC"; then
  100. case $host_os in
  101. linux*) haveit=yes;;
  102. esac
  103. fi
  104. fi
  105. if test -z "$haveit"; then
  106. if test -d "$additional_libdir"; then
  107. dnl Really add $additional_libdir to $LDFLAGS.
  108. LDFLAGS="${LDFLAGS}${LDFLAGS:+ }-L$additional_libdir"
  109. fi
  110. fi
  111. fi
  112. fi
  113. fi
  114. ])
  115. dnl AC_LIB_PREPARE_PREFIX creates variables acl_final_prefix,
  116. dnl acl_final_exec_prefix, containing the values to which $prefix and
  117. dnl $exec_prefix will expand at the end of the configure script.
  118. AC_DEFUN([AC_LIB_PREPARE_PREFIX],
  119. [
  120. dnl Unfortunately, prefix and exec_prefix get only finally determined
  121. dnl at the end of configure.
  122. if test "X$prefix" = "XNONE"; then
  123. acl_final_prefix="$ac_default_prefix"
  124. else
  125. acl_final_prefix="$prefix"
  126. fi
  127. if test "X$exec_prefix" = "XNONE"; then
  128. acl_final_exec_prefix='${prefix}'
  129. else
  130. acl_final_exec_prefix="$exec_prefix"
  131. fi
  132. acl_save_prefix="$prefix"
  133. prefix="$acl_final_prefix"
  134. eval acl_final_exec_prefix=\"$acl_final_exec_prefix\"
  135. prefix="$acl_save_prefix"
  136. ])
  137. dnl AC_LIB_WITH_FINAL_PREFIX([statement]) evaluates statement, with the
  138. dnl variables prefix and exec_prefix bound to the values they will have
  139. dnl at the end of the configure script.
  140. AC_DEFUN([AC_LIB_WITH_FINAL_PREFIX],
  141. [
  142. acl_save_prefix="$prefix"
  143. prefix="$acl_final_prefix"
  144. acl_save_exec_prefix="$exec_prefix"
  145. exec_prefix="$acl_final_exec_prefix"
  146. $1
  147. exec_prefix="$acl_save_exec_prefix"
  148. prefix="$acl_save_prefix"
  149. ])
  150. dnl AC_LIB_PREPARE_MULTILIB creates
  151. dnl - a variable acl_libdirstem, containing the basename of the libdir, either
  152. dnl "lib" or "lib64" or "lib/64",
  153. dnl - a variable acl_libdirstem2, as a secondary possible value for
  154. dnl acl_libdirstem, either the same as acl_libdirstem or "lib/sparcv9" or
  155. dnl "lib/amd64".
  156. AC_DEFUN([AC_LIB_PREPARE_MULTILIB],
  157. [
  158. dnl There is no formal standard regarding lib and lib64.
  159. dnl On glibc systems, the current practice is that on a system supporting
  160. dnl 32-bit and 64-bit instruction sets or ABIs, 64-bit libraries go under
  161. dnl $prefix/lib64 and 32-bit libraries go under $prefix/lib. We determine
  162. dnl the compiler's default mode by looking at the compiler's library search
  163. dnl path. If at least one of its elements ends in /lib64 or points to a
  164. dnl directory whose absolute pathname ends in /lib64, we assume a 64-bit ABI.
  165. dnl Otherwise we use the default, namely "lib".
  166. dnl On Solaris systems, the current practice is that on a system supporting
  167. dnl 32-bit and 64-bit instruction sets or ABIs, 64-bit libraries go under
  168. dnl $prefix/lib/64 (which is a symlink to either $prefix/lib/sparcv9 or
  169. dnl $prefix/lib/amd64) and 32-bit libraries go under $prefix/lib.
  170. AC_REQUIRE([AC_CANONICAL_HOST])
  171. acl_libdirstem=lib
  172. acl_libdirstem2=
  173. case "$host_os" in
  174. solaris*)
  175. dnl See Solaris 10 Software Developer Collection > Solaris 64-bit Developer's Guide > The Development Environment
  176. dnl <http://docs.sun.com/app/docs/doc/816-5138/dev-env?l=en&a=view>.
  177. dnl "Portable Makefiles should refer to any library directories using the 64 symbolic link."
  178. dnl But we want to recognize the sparcv9 or amd64 subdirectory also if the
  179. dnl symlink is missing, so we set acl_libdirstem2 too.
  180. AC_CACHE_CHECK([for 64-bit host], [gl_cv_solaris_64bit],
  181. [AC_EGREP_CPP([sixtyfour bits], [
  182. #ifdef _LP64
  183. sixtyfour bits
  184. #endif
  185. ], [gl_cv_solaris_64bit=yes], [gl_cv_solaris_64bit=no])
  186. ])
  187. if test $gl_cv_solaris_64bit = yes; then
  188. acl_libdirstem=lib/64
  189. case "$host_cpu" in
  190. sparc*) acl_libdirstem2=lib/sparcv9 ;;
  191. i*86 | x86_64) acl_libdirstem2=lib/amd64 ;;
  192. esac
  193. fi
  194. ;;
  195. *)
  196. searchpath=`(LC_ALL=C $CC -print-search-dirs) 2>/dev/null | sed -n -e 's,^libraries: ,,p' | sed -e 's,^=,,'`
  197. if test -n "$searchpath"; then
  198. acl_save_IFS="${IFS= }"; IFS=":"
  199. for searchdir in $searchpath; do
  200. if test -d "$searchdir"; then
  201. case "$searchdir" in
  202. */lib64/ | */lib64 ) acl_libdirstem=lib64 ;;
  203. */../ | */.. )
  204. # Better ignore directories of this form. They are misleading.
  205. ;;
  206. *) searchdir=`cd "$searchdir" && pwd`
  207. case "$searchdir" in
  208. */lib64 ) acl_libdirstem=lib64 ;;
  209. esac ;;
  210. esac
  211. fi
  212. done
  213. IFS="$acl_save_IFS"
  214. fi
  215. ;;
  216. esac
  217. test -n "$acl_libdirstem2" || acl_libdirstem2="$acl_libdirstem"
  218. ])