|
| 1 | +dnl Check for RE2 Libraries |
| 2 | +dnl CHECK_RE2(ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]) |
| 3 | + |
| 4 | +AC_DEFUN([PROG_RE2], [ |
| 5 | +
|
| 6 | +# Needed if pkg-config will be used. |
| 7 | +AC_REQUIRE([PKG_PROG_PKG_CONFIG]) |
| 8 | +
|
| 9 | +# Possible names for the re2 library/package (pkg-config) |
| 10 | +RE2_POSSIBLE_LIB_NAMES="re2" |
| 11 | +
|
| 12 | +# Possible extensions for the library |
| 13 | +RE2_POSSIBLE_EXTENSIONS="so la sl dll dylib" |
| 14 | +
|
| 15 | +# Possible paths (if pkg-config was not found, proceed with the file lookup) |
| 16 | +RE2_POSSIBLE_PATHS="/usr/lib /usr/local/lib /usr/local/libre2 /usr/local/re2 /usr/local /opt/libre2 /opt/re2 /opt /usr /usr/lib64" |
| 17 | +
|
| 18 | +# Variables to be set by this very own script. |
| 19 | +RE2_VERSION="" |
| 20 | +RE2_CFLAGS="" |
| 21 | +RE2_CPPFLAGS="" |
| 22 | +RE2_LDADD="" |
| 23 | +RE2_LDFLAGS="" |
| 24 | +
|
| 25 | +AC_ARG_WITH( |
| 26 | + re2, |
| 27 | + AC_HELP_STRING( |
| 28 | + [--with-re2=PATH], |
| 29 | + [Path to re2 prefix or config script] |
| 30 | + ) |
| 31 | +) |
| 32 | +
|
| 33 | +if test "x${with_re2}" == "xno"; then |
| 34 | + AC_DEFINE(HAVE_GEOIP, 0, [Support for RE2 was disabled by the utilization of --without-re2 or --with-re2=no]) |
| 35 | + AC_MSG_NOTICE([Support for RE2 was disabled by the utilization of --without-re2 or --with-re2=no]) |
| 36 | + RE2_DISABLED=yes |
| 37 | +else |
| 38 | + if test "x${with_re2}" == "xyes"; then |
| 39 | + RE2_MANDATORY=yes |
| 40 | + AC_MSG_NOTICE([RE2 support was marked as mandatory by the utilization of --with-re2=yes]) |
| 41 | + fi |
| 42 | +# for x in ${RE2_POSSIBLE_LIB_NAMES}; do |
| 43 | +# CHECK_FOR_RE2_AT(${x}) |
| 44 | +# if test -n "${RE2_VERSION}"; then |
| 45 | +# break |
| 46 | +# fi |
| 47 | +# done |
| 48 | +
|
| 49 | +# if test "x${with_re2}" != "xyes" or test "x${with_re2}" == "xyes"; then |
| 50 | + if test "x${with_re2}" == "x" || test "x${with_re2}" == "xyes"; then |
| 51 | + # Nothing about GeoIP was informed, using the pkg-config to figure things out. |
| 52 | + if test -n "${PKG_CONFIG}"; then |
| 53 | + RE2_PKG_NAME="" |
| 54 | + for x in ${RE2_POSSIBLE_LIB_NAMES}; do |
| 55 | + if ${PKG_CONFIG} --exists ${x}; then |
| 56 | + RE2_PKG_NAME="$x" |
| 57 | + break |
| 58 | + fi |
| 59 | + done |
| 60 | + fi |
| 61 | + AC_MSG_NOTICE([Nothing about GeoIP was informed during the configure phase. Trying to detect it on the platform...]) |
| 62 | + if test -n "${RE2_PKG_NAME}"; then |
| 63 | + # Package was found using the pkg-config scripts |
| 64 | + RE2_VERSION="`${PKG_CONFIG} ${RE2_PKG_NAME} --modversion`" |
| 65 | + RE2_CFLAGS="`${PKG_CONFIG} ${RE2_PKG_NAME} --cflags`" |
| 66 | + RE2_LDADD="`${PKG_CONFIG} ${RE2_PKG_NAME} --libs-only-l`" |
| 67 | + RE2_LDFLAGS="`${PKG_CONFIG} ${RE2_PKG_NAME} --libs-only-L --libs-only-other`" |
| 68 | + RE2_DISPLAY="${RE2_LDADD}, ${RE2_CFLAGS}" |
| 69 | + else |
| 70 | + # If pkg-config did not find anything useful, go over file lookup. |
| 71 | + for x in ${RE2_POSSIBLE_LIB_NAMES}; do |
| 72 | + CHECK_FOR_RE2_AT(${x}) |
| 73 | + if test -n "${RE2_VERSION}"; then |
| 74 | + break |
| 75 | + fi |
| 76 | + done |
| 77 | + fi |
| 78 | + fi |
| 79 | + if test "x${with_re2}" != "x"; then |
| 80 | + # An specific path was informed, lets check. |
| 81 | + RE2_MANDATORY=yes |
| 82 | + CHECK_FOR_RE2_AT(${with_re2}) |
| 83 | + fi |
| 84 | +# fi |
| 85 | +fi |
| 86 | +
|
| 87 | +if test -z "${RE2_LDADD}"; then |
| 88 | + if test -z "${RE2_MANDATORY}"; then |
| 89 | + if test -z "${RE2_DISABLED}"; then |
| 90 | + AC_MSG_NOTICE([RE2 library was not found]) |
| 91 | + RE2_FOUND=0 |
| 92 | + else |
| 93 | + RE2_FOUND=2 |
| 94 | + fi |
| 95 | + else |
| 96 | + AC_MSG_ERROR([RE2 was explicitly referenced but it was not found]) |
| 97 | + RE2_FOUND=-1 |
| 98 | + fi |
| 99 | +else |
| 100 | + RE2_FOUND=1 |
| 101 | + AC_MSG_NOTICE([using RE2 v${RE2_VERSION}]) |
| 102 | + RE2_CFLAGS="-DWITH_RE2 ${RE2_CFLAGS}" |
| 103 | + RE2_DISPLAY="${RE2_LDADD}, ${RE2_CFLAGS}" |
| 104 | + AC_SUBST(RE2_VERSION) |
| 105 | + AC_SUBST(RE2_LDADD) |
| 106 | + AC_SUBST(RE2_LIBS) |
| 107 | + AC_SUBST(RE2_LDFLAGS) |
| 108 | + AC_SUBST(RE2_CFLAGS) |
| 109 | + AC_SUBST(RE2_DISPLAY) |
| 110 | +fi |
| 111 | +
|
| 112 | +
|
| 113 | +
|
| 114 | +AC_SUBST(RE2_FOUND) |
| 115 | +
|
| 116 | +]) # AC_DEFUN [PROG_RE2] |
| 117 | + |
| 118 | + |
| 119 | +AC_DEFUN([CHECK_FOR_RE2_AT], [ |
| 120 | + path=$1 |
| 121 | + for y in ${RE2_POSSIBLE_EXTENSIONS}; do |
| 122 | + for z in ${RE2_POSSIBLE_LIB_NAMES}; do |
| 123 | + if test -e "${path}/${z}.${y}"; then |
| 124 | + re2_lib_path="${path}/" |
| 125 | + re2_lib_name="${z}" |
| 126 | + re2_lib_file="${re2_lib_path}/${z}.${y}" |
| 127 | + break |
| 128 | + fi |
| 129 | + if test -e "${path}/lib${z}.${y}"; then |
| 130 | + re2_lib_path="${path}/" |
| 131 | + re2_lib_name="${z}" |
| 132 | + re2_lib_file="${re2_lib_path}/lib${z}.${y}" |
| 133 | + break |
| 134 | + fi |
| 135 | + if test -e "${path}/lib/lib${z}.${y}"; then |
| 136 | + re2_lib_path="${path}/lib/" |
| 137 | + re2_lib_name="${z}" |
| 138 | + re2_lib_file="${re2_lib_path}/lib${z}.${y}" |
| 139 | + break |
| 140 | + fi |
| 141 | + if test -e "${path}/lib/x86_64-linux-gnu/lib${z}.${y}"; then |
| 142 | + re2_lib_path="${path}/lib/x86_64-linux-gnu/" |
| 143 | + re2_lib_name="${z}" |
| 144 | + re2_lib_file="${re2_lib_path}/lib${z}.${y}" |
| 145 | + break |
| 146 | + fi |
| 147 | + done |
| 148 | + if test -n "$re2_lib_path"; then |
| 149 | + break |
| 150 | + fi |
| 151 | + done |
| 152 | + if test -e "${path}/include/re2_parse.h"; then |
| 153 | + re2_inc_path="${path}/include" |
| 154 | + elif test -e "${path}/re2_parse.h"; then |
| 155 | + re2_inc_path="${path}" |
| 156 | + elif test -e "${path}/include/re2/re2_parse.h"; then |
| 157 | + re2_inc_path="${path}/include" |
| 158 | + fi |
| 159 | +
|
| 160 | + if test -n "${re2_lib_path}"; then |
| 161 | + AC_MSG_NOTICE([RE2 library found at: ${re2_lib_file}]) |
| 162 | + fi |
| 163 | +
|
| 164 | + if test -n "${re2_inc_path}"; then |
| 165 | + AC_MSG_NOTICE([RE2 headers found at: ${re2_inc_path}]) |
| 166 | + fi |
| 167 | +
|
| 168 | + if test -n "${re2_lib_path}" -a -n "${re2_inc_path}"; then |
| 169 | + # TODO: Compile a piece of code to check the version. |
| 170 | + RE2_CFLAGS="-I${re2_inc_path}" |
| 171 | + RE2_LDADD="-l${re2_lib_name}" |
| 172 | + RE2_LDFLAGS="-L${re2_lib_path}" |
| 173 | + RE2_DISPLAY="${re2_lib_file}, ${re2_inc_path}" |
| 174 | + fi |
| 175 | +]) # AC_DEFUN [CHECK_FOR_RE2_AT] |
0 commit comments