lib-prefix.m4 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. # lib-prefix.m4 serial 5 (gettext-0.15)
  2. dnl Copyright (C) 2001-2005 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 a variable acl_libdirstem, containing
  151. dnl the basename of the libdir, either "lib" or "lib64".
  152. AC_DEFUN([AC_LIB_PREPARE_MULTILIB],
  153. [
  154. dnl There is no formal standard regarding lib and lib64. The current
  155. dnl practice is that on a system supporting 32-bit and 64-bit instruction
  156. dnl sets or ABIs, 64-bit libraries go under $prefix/lib64 and 32-bit
  157. dnl libraries go under $prefix/lib. We determine the compiler's default
  158. dnl mode by looking at the compiler's library search path. If at least
  159. dnl of its elements ends in /lib64 or points to a directory whose absolute
  160. dnl pathname ends in /lib64, we assume a 64-bit ABI. Otherwise we use the
  161. dnl default, namely "lib".
  162. acl_libdirstem=lib
  163. searchpath=`(LC_ALL=C $CC -print-search-dirs) 2>/dev/null | sed -n -e 's,^libraries: ,,p' | sed -e 's,^=,,'`
  164. if test -n "$searchpath"; then
  165. acl_save_IFS="${IFS= }"; IFS=":"
  166. for searchdir in $searchpath; do
  167. if test -d "$searchdir"; then
  168. case "$searchdir" in
  169. */lib64/ | */lib64 ) acl_libdirstem=lib64 ;;
  170. *) searchdir=`cd "$searchdir" && pwd`
  171. case "$searchdir" in
  172. */lib64 ) acl_libdirstem=lib64 ;;
  173. esac ;;
  174. esac
  175. fi
  176. done
  177. IFS="$acl_save_IFS"
  178. fi
  179. ])