|
| 1 | +dnl Check for MAXMIND Libraries |
| 2 | +dnl CHECK_MAXMIND(ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]) |
| 3 | +dnl Sets: |
| 4 | +dnl MAXMIND_CFLAGS |
| 5 | +dnl MAXMIND_LDADD |
| 6 | +dnl MAXMIND_LDFLAGS |
| 7 | +dnl MAXMIND_LIBS |
| 8 | +dnl MAXMIND_VERSION |
| 9 | + |
| 10 | +AC_DEFUN([PROG_MAXMIND], [ |
| 11 | +
|
| 12 | +
|
| 13 | +# Needed if pkg-config will be used. |
| 14 | +AC_REQUIRE([PKG_PROG_PKG_CONFIG]) |
| 15 | +
|
| 16 | +
|
| 17 | +# Possible names for the maxmind library/package (pkg-config) |
| 18 | +MAXMIND_POSSIBLE_LIB_NAMES="libmaxminddb maxminddb maxmind" |
| 19 | +
|
| 20 | +# Possible extensions for the library |
| 21 | +MAXMIND_POSSIBLE_EXTENSIONS="so la sl dll dylib" |
| 22 | +
|
| 23 | +# Possible paths (if pkg-config was not found, proceed with the file lookup) |
| 24 | +MAXMIND_POSSIBLE_PATHS="/usr/local/libmaxmind /usr/local/maxmind /usr/local /opt/libmaxmind /opt/maxmind /opt /usr /opt/local/include /opt/local /usr/lib /usr/local/lib /usr/lib64 /usr" |
| 25 | +
|
| 26 | +# Variables to be set by this very own script. |
| 27 | +MAXMIND_VERSION="" |
| 28 | +MAXMIND_CFLAGS="" |
| 29 | +MAXMIND_CPPFLAGS="" |
| 30 | +MAXMIND_LDADD="" |
| 31 | +MAXMIND_LDFLAGS="" |
| 32 | +
|
| 33 | +AC_ARG_WITH( |
| 34 | + maxmind, |
| 35 | + AS_HELP_STRING( |
| 36 | + [--with-maxmind=PATH], |
| 37 | + [Path to MaxMind (including headers). Use 'no' to disable MaxMind support.] |
| 38 | + ) |
| 39 | +) |
| 40 | +
|
| 41 | +# AS_HELP_STRING( |
| 42 | +# [--without-maxmind], |
| 43 | +# [Complete dsiables MaxMind support] |
| 44 | +# ) |
| 45 | +
|
| 46 | +
|
| 47 | +if test "x${with_maxmind}" == "xno"; then |
| 48 | + AC_DEFINE(HAVE_MAXMIND, 0, [Support for MaxMind was disabled by the utilization of --without-maxmind or --with-maxmind=no]) |
| 49 | + AC_MSG_NOTICE([Support for MaxMind was disabled by the utilization of --without-maxmind or --with-maxmind=no]) |
| 50 | + MAXMIND_DISABLED=yes |
| 51 | +else |
| 52 | + if test "x${with_maxmind}" == "xyes"; then |
| 53 | + MAXMIND_MANDATORY=yes |
| 54 | + AC_MSG_NOTICE([MaxMind support was marked as mandatory by the utilization of --with-maxmind=yes]) |
| 55 | + fi |
| 56 | +# for x in ${MAXMIND_POSSIBLE_LIB_NAMES}; do |
| 57 | +# CHECK_FOR_MAXMIND_AT(${x}) |
| 58 | +# if test -n "${MAXMIND_VERSION}"; then |
| 59 | +# break |
| 60 | +# fi |
| 61 | +# done |
| 62 | +
|
| 63 | +# if test "x${with_maxmind}" != "xyes" or test "x${with_maxmind}" == "xyes"; then |
| 64 | + if test "x${with_maxmind}" == "x" || test "x${with_maxmind}" == "xyes"; then |
| 65 | + # Nothing about MaxMind was informed, using the pkg-config to figure things out. |
| 66 | + if test -n "${PKG_CONFIG}"; then |
| 67 | + MAXMIND_PKG_NAME="" |
| 68 | + for x in ${MAXMIND_POSSIBLE_LIB_NAMES}; do |
| 69 | + if ${PKG_CONFIG} --exists ${x}; then |
| 70 | + MAXMIND_PKG_NAME="$x" |
| 71 | + break |
| 72 | + fi |
| 73 | + done |
| 74 | + fi |
| 75 | + AC_MSG_NOTICE([Nothing about MaxMind was informed during the configure phase. Trying to detect it on the platform...]) |
| 76 | + if test -n "${MAXMIND_PKG_NAME}"; then |
| 77 | + # Package was found using the pkg-config scripts |
| 78 | + MAXMIND_VERSION="`${PKG_CONFIG} ${MAXMIND_PKG_NAME} --modversion`" |
| 79 | + MAXMIND_CFLAGS="`${PKG_CONFIG} ${MAXMIND_PKG_NAME} --cflags`" |
| 80 | + MAXMIND_LDADD="`${PKG_CONFIG} ${MAXMIND_PKG_NAME} --libs-only-l`" |
| 81 | + MAXMIND_LDFLAGS="`${PKG_CONFIG} ${MAXMIND_PKG_NAME} --libs-only-L --libs-only-other`" |
| 82 | + MAXMIND_DISPLAY="${MAXMIND_LDADD}" |
| 83 | + else |
| 84 | + # If pkg-config did not find anything useful, go over file lookup. |
| 85 | + for x in ${MAXMIND_POSSIBLE_PATHS}; do |
| 86 | + CHECK_FOR_MAXMIND_AT(${x}) |
| 87 | + if test -n "${MAXMIND_VERSION}"; then |
| 88 | + break |
| 89 | + fi |
| 90 | + done |
| 91 | + fi |
| 92 | + fi |
| 93 | + if test "x${with_maxmind}" != "x"; then |
| 94 | + # An specific path was informed, lets check. |
| 95 | + MAXMIND_MANDATORY=yes |
| 96 | + CHECK_FOR_MAXMIND_AT(${with_maxmind}) |
| 97 | + fi |
| 98 | +# fi |
| 99 | +fi |
| 100 | +
|
| 101 | +if test -z "${MAXMIND_DISPLAY}"; then |
| 102 | + if test -z "${MAXMIND_MANDATORY}"; then |
| 103 | + if test -z "${MAXMIND_DISABLED}"; then |
| 104 | + AC_MSG_NOTICE([MaxMind library was not found]) |
| 105 | + MAXMIND_FOUND=0 |
| 106 | + else |
| 107 | + MAXMIND_FOUND=2 |
| 108 | + fi |
| 109 | + else |
| 110 | + AC_MSG_ERROR([MaxMind was explicit requested but it was not found]) |
| 111 | + MAXMIND_FOUND=-1 |
| 112 | + fi |
| 113 | +else |
| 114 | + MAXMIND_FOUND=1 |
| 115 | + AC_MSG_NOTICE([using MaxMind v${MAXMIND_VERSION}]) |
| 116 | + MAXMIND_CFLAGS="-DWITH_MAXMIND ${MAXMIND_CFLAGS}" |
| 117 | + if ! test "x$MAXMIND_CFLAGS" = "x"; then |
| 118 | + MAXMIND_DISPLAY="${MAXMIND_DISPLAY}, ${MAXMIND_CFLAGS}" |
| 119 | + fi |
| 120 | + AC_SUBST(MAXMIND_VERSION) |
| 121 | + AC_SUBST(MAXMIND_LDADD) |
| 122 | + AC_SUBST(MAXMIND_LIBS) |
| 123 | + AC_SUBST(MAXMIND_LDFLAGS) |
| 124 | + AC_SUBST(MAXMIND_CFLAGS) |
| 125 | + AC_SUBST(MAXMIND_DISPLAY) |
| 126 | +fi |
| 127 | +
|
| 128 | +
|
| 129 | +
|
| 130 | +AC_SUBST(MAXMIND_FOUND) |
| 131 | +
|
| 132 | +]) # AC_DEFUN [PROG_MAXMIND] |
| 133 | +
|
| 134 | +
|
| 135 | +AC_DEFUN([CHECK_FOR_MAXMIND_AT], [ |
| 136 | + path=$1 |
| 137 | + for y in ${MAXMIND_POSSIBLE_EXTENSIONS}; do |
| 138 | + for z in ${MAXMIND_POSSIBLE_LIB_NAMES}; do |
| 139 | + if test -e "${path}/${z}.${y}"; then |
| 140 | + maxmind_lib_path="${path}/" |
| 141 | + maxmind_lib_name="${z}" |
| 142 | + maxmind_lib_file="${maxmind_lib_path}/${z}.${y}" |
| 143 | + break |
| 144 | + fi |
| 145 | + if test -e "${path}/lib${z}.${y}"; then |
| 146 | + maxmind_lib_path="${path}/" |
| 147 | + maxmind_lib_name="${z}" |
| 148 | + maxmind_lib_file="${maxmind_lib_path}/lib${z}.${y}" |
| 149 | + break |
| 150 | + fi |
| 151 | + if test -e "${path}/lib/lib${z}.${y}"; then |
| 152 | + maxmind_lib_path="${path}/lib/" |
| 153 | + maxmind_lib_name="${z}" |
| 154 | + maxmind_lib_file="${maxmind_lib_path}/lib${z}.${y}" |
| 155 | + break |
| 156 | + fi |
| 157 | + if test -e "${path}/lib64/lib${z}.${y}"; then |
| 158 | + maxmind_lib_path="${path}/lib64/" |
| 159 | + maxmind_lib_name="${z}" |
| 160 | + maxmind_lib_file="${maxmind_lib_path}/lib${z}.${y}" |
| 161 | + break |
| 162 | + fi |
| 163 | + if test -e "${path}/lib/x86_64-linux-gnu/lib${z}.${y}"; then |
| 164 | + maxmind_lib_path="${path}/lib/x86_64-linux-gnu/" |
| 165 | + maxmind_lib_name="${z}" |
| 166 | + maxmind_lib_file="${maxmind_lib_path}/lib${z}.${y}" |
| 167 | + break |
| 168 | + fi |
| 169 | + done |
| 170 | + if test -n "$maxmind_lib_path"; then |
| 171 | + break |
| 172 | + fi |
| 173 | + done |
| 174 | + if test -e "${path}/include/maxminddb.h"; then |
| 175 | + maxmind_inc_path="${path}/include" |
| 176 | + elif test -e "${path}/maxminddb.h"; then |
| 177 | + maxmind_inc_path="${path}" |
| 178 | + fi |
| 179 | +
|
| 180 | +
|
| 181 | + if test -n "${maxmind_inc_path}" -a -n "${maxmind_lib_path}"; then |
| 182 | +
|
| 183 | + AC_MSG_NOTICE([MaxMind headers found at: ${maxmind_inc_path}]) |
| 184 | + AC_MSG_NOTICE([MaxMind library found at: ${maxmind_lib_file}]) |
| 185 | + fi |
| 186 | +
|
| 187 | + if test -n "${maxmind_lib_path}" -a -n "${maxmind_inc_path}"; then |
| 188 | + # TODO: Compile a piece of code to check the version. |
| 189 | + MAXMIND_CFLAGS="-I${maxmind_inc_path}" |
| 190 | + MAXMIND_LDADD="-l${maxmind_lib_name}" |
| 191 | + MAXMIND_LDFLAGS="-L${maxmind_lib_path}" |
| 192 | + MAXMIND_DISPLAY="${maxmind_lib_file}, ${maxmind_inc_path}" |
| 193 | + fi |
| 194 | +]) # AC_DEFUN [CHECK_FOR_MAXMIND_AT] |
0 commit comments