find_apr.m4 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. dnl -------------------------------------------------------- -*- autoconf -*-
  2. dnl Licensed to the Apache Software Foundation (ASF) under one or more
  3. dnl contributor license agreements. See the NOTICE file distributed with
  4. dnl this work for additional information regarding copyright ownership.
  5. dnl The ASF licenses this file to You under the Apache License, Version 2.0
  6. dnl (the "License"); you may not use this file except in compliance with
  7. dnl the License. You may obtain a copy of the License at
  8. dnl
  9. dnl http://www.apache.org/licenses/LICENSE-2.0
  10. dnl
  11. dnl Unless required by applicable law or agreed to in writing, software
  12. dnl distributed under the License is distributed on an "AS IS" BASIS,
  13. dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. dnl See the License for the specific language governing permissions and
  15. dnl limitations under the License.
  16. dnl
  17. dnl find_apr.m4 : locate the APR include files and libraries
  18. dnl
  19. dnl This macro file can be used by applications to find and use the APR
  20. dnl library. It provides a standardized mechanism for using APR. It supports
  21. dnl embedding APR into the application source, or locating an installed
  22. dnl copy of APR.
  23. dnl
  24. dnl APR_FIND_APR(srcdir, builddir, implicit-install-check, acceptable-majors,
  25. dnl detailed-check)
  26. dnl
  27. dnl where srcdir is the location of the bundled APR source directory, or
  28. dnl empty if source is not bundled.
  29. dnl
  30. dnl where builddir is the location where the bundled APR will will be built,
  31. dnl or empty if the build will occur in the srcdir.
  32. dnl
  33. dnl where implicit-install-check set to 1 indicates if there is no
  34. dnl --with-apr option specified, we will look for installed copies.
  35. dnl
  36. dnl where acceptable-majors is a space separated list of acceptable major
  37. dnl version numbers. Often only a single major version will be acceptable.
  38. dnl If multiple versions are specified, and --with-apr=PREFIX or the
  39. dnl implicit installed search are used, then the first (leftmost) version
  40. dnl in the list that is found will be used. Currently defaults to [0 1].
  41. dnl
  42. dnl where detailed-check is an M4 macro which sets the apr_acceptable to
  43. dnl either "yes" or "no". The macro will be invoked for each installed
  44. dnl copy of APR found, with the apr_config variable set appropriately.
  45. dnl Only installed copies of APR which are considered acceptable by
  46. dnl this macro will be considered found. If no installed copies are
  47. dnl considered acceptable by this macro, apr_found will be set to either
  48. dnl either "no" or "reconfig".
  49. dnl
  50. dnl Sets the following variables on exit:
  51. dnl
  52. dnl apr_found : "yes", "no", "reconfig"
  53. dnl
  54. dnl apr_config : If the apr-config tool exists, this refers to it. If
  55. dnl apr_found is "reconfig", then the bundled directory
  56. dnl should be reconfigured *before* using apr_config.
  57. dnl
  58. dnl Note: this macro file assumes that apr-config has been installed; it
  59. dnl is normally considered a required part of an APR installation.
  60. dnl
  61. dnl If a bundled source directory is available and needs to be (re)configured,
  62. dnl then apr_found is set to "reconfig". The caller should reconfigure the
  63. dnl (passed-in) source directory, placing the result in the build directory,
  64. dnl as appropriate.
  65. dnl
  66. dnl If apr_found is "yes" or "reconfig", then the caller should use the
  67. dnl value of apr_config to fetch any necessary build/link information.
  68. dnl
  69. AC_DEFUN([APR_FIND_APR], [
  70. apr_found="no"
  71. if test "$target_os" = "os2-emx"; then
  72. # Scripts don't pass test -x on OS/2
  73. TEST_X="test -f"
  74. else
  75. TEST_X="test -x"
  76. fi
  77. ifelse([$4], [], [
  78. ifdef(AC_WARNING,AC_WARNING([$0: missing argument 4 (acceptable-majors): Defaulting to APR 0.x then APR 1.x]))
  79. acceptable_majors="0 1"],
  80. [acceptable_majors="$4"])
  81. apr_temp_acceptable_apr_config=""
  82. for apr_temp_major in $acceptable_majors
  83. do
  84. case $apr_temp_major in
  85. 0)
  86. apr_temp_acceptable_apr_config="$apr_temp_acceptable_apr_config apr-config"
  87. ;;
  88. *)
  89. apr_temp_acceptable_apr_config="$apr_temp_acceptable_apr_config apr-$apr_temp_major-config"
  90. ;;
  91. esac
  92. done
  93. AC_MSG_CHECKING(for APR)
  94. AC_ARG_WITH(apr,
  95. [ --with-apr=PATH prefix for installed APR or the full path to
  96. apr-config],
  97. [
  98. if test "$withval" = "no" || test "$withval" = "yes"; then
  99. AC_MSG_ERROR([--with-apr requires a directory or file to be provided])
  100. fi
  101. for apr_temp_apr_config_file in $apr_temp_acceptable_apr_config
  102. do
  103. for lookdir in "$withval/bin" "$withval"
  104. do
  105. if $TEST_X "$lookdir/$apr_temp_apr_config_file"; then
  106. apr_config="$lookdir/$apr_temp_apr_config_file"
  107. ifelse([$5], [], [], [
  108. apr_acceptable="yes"
  109. $5
  110. if test "$apr_acceptable" != "yes"; then
  111. AC_MSG_WARN([Found APR in $apr_config, but we think it is considered unacceptable])
  112. continue
  113. fi])
  114. apr_found="yes"
  115. break 2
  116. fi
  117. done
  118. done
  119. if test "$apr_found" != "yes" && $TEST_X "$withval" && $withval --help > /dev/null 2>&1 ; then
  120. apr_config="$withval"
  121. ifelse([$5], [], [apr_found="yes"], [
  122. apr_acceptable="yes"
  123. $5
  124. if test "$apr_acceptable" = "yes"; then
  125. apr_found="yes"
  126. fi])
  127. fi
  128. dnl if --with-apr is used, it is a fatal error for its argument
  129. dnl to be invalid
  130. if test "$apr_found" != "yes"; then
  131. AC_MSG_ERROR([the --with-apr parameter is incorrect. It must specify an install prefix, a build directory, or an apr-config file.])
  132. fi
  133. ],[
  134. dnl If we allow installed copies, check those before using bundled copy.
  135. if test -n "$3" && test "$3" = "1"; then
  136. for apr_temp_apr_config_file in $apr_temp_acceptable_apr_config
  137. do
  138. if $apr_temp_apr_config_file --help > /dev/null 2>&1 ; then
  139. apr_config="$apr_temp_apr_config_file"
  140. ifelse([$5], [], [], [
  141. apr_acceptable="yes"
  142. $5
  143. if test "$apr_acceptable" != "yes"; then
  144. AC_MSG_WARN([skipped APR at $apr_config, version not acceptable])
  145. continue
  146. fi])
  147. apr_found="yes"
  148. break
  149. else
  150. dnl look in some standard places
  151. for lookdir in /usr /usr/local /usr/local/apr /opt/apr; do
  152. if $TEST_X "$lookdir/bin/$apr_temp_apr_config_file"; then
  153. apr_config="$lookdir/bin/$apr_temp_apr_config_file"
  154. ifelse([$5], [], [], [
  155. apr_acceptable="yes"
  156. $5
  157. if test "$apr_acceptable" != "yes"; then
  158. AC_MSG_WARN([skipped APR at $apr_config, version not acceptable])
  159. continue
  160. fi])
  161. apr_found="yes"
  162. break 2
  163. fi
  164. done
  165. fi
  166. done
  167. fi
  168. dnl if we have not found anything yet and have bundled source, use that
  169. if test "$apr_found" = "no" && test -d "$1"; then
  170. apr_temp_abs_srcdir="`cd $1 && pwd`"
  171. apr_found="reconfig"
  172. apr_bundled_major="`sed -n '/#define.*APR_MAJOR_VERSION/s/^[^0-9]*\([0-9]*\).*$/\1/p' \"$1/include/apr_version.h\"`"
  173. case $apr_bundled_major in
  174. "")
  175. AC_MSG_ERROR([failed to find major version of bundled APR])
  176. ;;
  177. 0)
  178. apr_temp_apr_config_file="apr-config"
  179. ;;
  180. *)
  181. apr_temp_apr_config_file="apr-$apr_bundled_major-config"
  182. ;;
  183. esac
  184. if test -n "$2"; then
  185. apr_config="$2/$apr_temp_apr_config_file"
  186. else
  187. apr_config="$1/$apr_temp_apr_config_file"
  188. fi
  189. fi
  190. ])
  191. AC_MSG_RESULT($apr_found)
  192. ])