mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 05:45:59 +03:00
Improves the libgeoip detection during configure
This commit is contained in:
parent
283c8c818d
commit
21cae53d47
@ -7,156 +7,180 @@ dnl GEOIP_LDFLAGS
|
|||||||
dnl GEOIP_LIBS
|
dnl GEOIP_LIBS
|
||||||
dnl GEOIP_VERSION
|
dnl GEOIP_VERSION
|
||||||
|
|
||||||
AC_DEFUN([PROG_GEOIP],
|
AC_DEFUN([PROG_GEOIP], [
|
||||||
[dnl
|
|
||||||
|
|
||||||
|
|
||||||
|
# Needed if pkg-config will be used.
|
||||||
AC_REQUIRE([PKG_PROG_PKG_CONFIG])
|
AC_REQUIRE([PKG_PROG_PKG_CONFIG])
|
||||||
|
|
||||||
GEOIP_CONFIG=""
|
|
||||||
|
# Possible names for the geoip library/package (pkg-config)
|
||||||
|
GEOIP_POSSIBLE_LIB_NAMES="geoip2 geoip GeoIP"
|
||||||
|
|
||||||
|
# Possible extensions for the library
|
||||||
|
GEOIP_POSSIBLE_EXTENSIONS="so la sl dll dylib"
|
||||||
|
|
||||||
|
# Possible paths (if pkg-config was not found, proceed with the file lookup)
|
||||||
|
GEOIP_POSSIBLE_PATHS="/usr/local/libgeoip /usr/local/geoip /usr/local /opt/libgeoip /opt/geoip /opt /usr /opt/local/include /opt/local /usr/lib /usr/local/lib /usr/lib64"
|
||||||
|
|
||||||
|
# Variables to be set by this very own script.
|
||||||
GEOIP_VERSION=""
|
GEOIP_VERSION=""
|
||||||
GEOIP_CFLAGS=""
|
GEOIP_CFLAGS=""
|
||||||
GEOIP_CPPFLAGS=""
|
GEOIP_CPPFLAGS=""
|
||||||
GEOIP_LDADD=""
|
GEOIP_LDADD=""
|
||||||
GEOIP_LDFLAGS=""
|
GEOIP_LDFLAGS=""
|
||||||
GEOIP_CONFIG=${PKG_CONFIG}
|
|
||||||
GEOIP_PKGNAMES="geoip2 geoip GeoIP"
|
|
||||||
GEOIP_SONAMES="so la sl dll dylib"
|
|
||||||
|
|
||||||
AC_ARG_WITH(
|
AC_ARG_WITH(
|
||||||
geoip,
|
geoip,
|
||||||
[AC_HELP_STRING([--with-geoip=PATH],[Path to geoip prefix or config script])]
|
AS_HELP_STRING(
|
||||||
,, with_geoip=yes)
|
[--with-geoip=PATH],
|
||||||
|
[Path to GeoIP (including headers). Use 'no' to disable GeoIP support.]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
AS_CASE(["${with_geoip}"],
|
# AS_HELP_STRING(
|
||||||
[no], [test_paths=],
|
# [--without-geoip],
|
||||||
[yes], [test_paths="/usr/local/libgeoip /usr/local/geoip /usr/local /opt/libgeoip /opt/geoip /opt /usr /opt/local/include /opt/local /usr/lib /usr/local/lib /usr/lib64"],
|
# [Complete dsiables GeoIP support]
|
||||||
[test_paths="${with_geoip}"])
|
# )
|
||||||
|
|
||||||
AS_IF([test "x${test_paths}" != "x"], [
|
|
||||||
AC_MSG_CHECKING([for libgeoip config script])
|
if test "x${with_geoip}" == "xno"; then
|
||||||
for x in ${test_paths}; do
|
AC_DEFINE(HAVE_GEOIP, 0, [Support for GeoIP was disabled by the utilization of --without-geoip or --with-geoip=no])
|
||||||
dnl # Determine if the script was specified and use it directly
|
AC_MSG_NOTICE([Support for GeoIP was disabled by the utilization of --without-geoip or --with-geoip=no])
|
||||||
if test ! -d "$x" -a -e "$x"; then
|
GEOIP_DISABLED=yes
|
||||||
GEOIP_CONFIG=$x
|
else
|
||||||
break
|
if test "x${with_geoip}" == "xyes"; then
|
||||||
|
GEOIP_MANDATORY=yes
|
||||||
|
AC_MSG_NOTICE([GeoIP support was marked as mandatory by the utilization of --with-geoip=yes])
|
||||||
fi
|
fi
|
||||||
|
# for x in ${GEOIP_POSSIBLE_LIB_NAMES}; do
|
||||||
|
# CHECK_FOR_GEOIP_AT(${x})
|
||||||
|
# if test -n "${GEOIP_VERSION}"; then
|
||||||
|
# break
|
||||||
|
# fi
|
||||||
|
# done
|
||||||
|
|
||||||
dnl # Try known config script names/locations
|
# if test "x${with_geoip}" != "xyes" or test "x${with_geoip}" == "xyes"; then
|
||||||
for y in $GEOIP_CONFIG; do
|
if test "x${with_geoip}" == "x" || test "x${with_geoip}" == "xyes"; then
|
||||||
if test -e "${x}/bin/${y}"; then
|
# Nothing about GeoIP was informed, using the pkg-config to figure things out.
|
||||||
GEOIP_CONFIG="${x}/bin/${y}"
|
if test -n "${PKG_CONFIG}"; then
|
||||||
geoip_config="${GEOIP_CONFIG}"
|
GEOIP_PKG_NAME=""
|
||||||
break
|
for x in ${GEOIP_POSSIBLE_LIB_NAMES}; do
|
||||||
elif test -e "${x}/${y}"; then
|
if ${PKG_CONFIG} --exists ${x}; then
|
||||||
GEOIP_CONFIG="${x}/${y}"
|
GEOIP_PKG_NAME="$x"
|
||||||
geoip_config="${GEOIP_CONFIG}"
|
break
|
||||||
break
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
AC_MSG_NOTICE([Nothing about GeoIP was informed during the configure phase. Trying to detect it on the platform...])
|
||||||
|
if test -n "${GEOIP_PKG_NAME}"; then
|
||||||
|
# Package was found using the pkg-config scripts
|
||||||
|
GEOIP_VERSION="`${PKG_CONFIG} ${GEOIP_PKG_NAME} --modversion`"
|
||||||
|
GEOIP_CFLAGS="`${PKG_CONFIG} ${GEOIP_PKG_NAME} --cflags`"
|
||||||
|
GEOIP_LDADD="`${PKG_CONFIG} ${GEOIP_PKG_NAME} --libs-only-l`"
|
||||||
|
GEOIP_LDFLAGS="`${PKG_CONFIG} ${GEOIP_PKG_NAME} --libs-only-L --libs-only-other`"
|
||||||
|
GEOIP_DISPLAY="${GEOIP_LDADD}, ${GEOIP_CFLAGS}"
|
||||||
|
else
|
||||||
|
# If pkg-config did not find anything useful, go over file lookup.
|
||||||
|
for x in ${GEOIP_POSSIBLE_LIB_NAMES}; do
|
||||||
|
CHECK_FOR_GEOIP_AT(${x})
|
||||||
|
if test -n "${GEOIP_VERSION}"; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
if test "x${with_geoip}" != "x"; then
|
||||||
if test -n "${geoip_config}"; then
|
# An specific path was informed, lets check.
|
||||||
break
|
GEOIP_MANDATORY=yes
|
||||||
fi
|
CHECK_FOR_GEOIP_AT(${with_geoip})
|
||||||
done
|
|
||||||
|
|
||||||
dnl # Try known package names
|
|
||||||
if test -n "${GEOIP_CONFIG}"; then
|
|
||||||
GEOIP_PKGNAME=""
|
|
||||||
for x in ${GEOIP_PKGNAMES}; do
|
|
||||||
if ${GEOIP_CONFIG} --exists ${x}; then
|
|
||||||
GEOIP_PKGNAME="$x"
|
|
||||||
break
|
|
||||||
fi
|
fi
|
||||||
done
|
# fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test -n "${GEOIP_PKGNAME}"; then
|
if test -z "${GEOIP_CFLAGS}"; then
|
||||||
AC_MSG_RESULT([${GEOIP_CONFIG}])
|
if test -z "${GEOIP_MANDATORY}"; then
|
||||||
GEOIP_VERSION="`${GEOIP_CONFIG} ${GEOIP_PKGNAME} --modversion`"
|
if test -z "${GEOIP_DISABLED}"; then
|
||||||
if test "$verbose_output" -eq 1; then AC_MSG_NOTICE(geoip VERSION: $GEOIP_VERSION); fi
|
AC_MSG_NOTICE([GeoIP library was not found])
|
||||||
GEOIP_CFLAGS="`${GEOIP_CONFIG} ${GEOIP_PKGNAME} --cflags`"
|
GEOIP_FOUND=0
|
||||||
if test "$verbose_output" -eq 1; then AC_MSG_NOTICE(geoip CFLAGS: $GEOIP_CFLAGS); fi
|
else
|
||||||
GEOIP_LDADD="`${GEOIP_CONFIG} ${GEOIP_PKGNAME} --libs-only-l`"
|
GEOIP_FOUND=2
|
||||||
if test "$verbose_output" -eq 1; then AC_MSG_NOTICE(geoip LDADD: $GEOIP_LDADD); fi
|
fi
|
||||||
GEOIP_LDFLAGS="`${GEOIP_CONFIG} ${GEOIP_PKGNAME} --libs-only-L --libs-only-other`"
|
else
|
||||||
if test "$verbose_output" -eq 1; then AC_MSG_NOTICE(geoip LDFLAGS: $GEOIP_LDFLAGS); fi
|
AC_MSG_ERROR([GeoIP was explicit requested but it was not found])
|
||||||
|
GEOIP_FOUND=-1
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
AC_MSG_RESULT([no])
|
GEOIP_FOUND=1
|
||||||
|
AC_MSG_NOTICE([using GeoIP v${GEOIP_VERSION}])
|
||||||
|
GEOIP_CFLAGS="-DWITH_GEOIP ${GEOIP_CFLAGS}"
|
||||||
|
AC_SUBST(GEOIP_VERSION)
|
||||||
|
AC_SUBST(GEOIP_LDADD)
|
||||||
|
AC_SUBST(GEOIP_LIBS)
|
||||||
|
AC_SUBST(GEOIP_LDFLAGS)
|
||||||
|
AC_SUBST(GEOIP_CFLAGS)
|
||||||
|
AC_SUBST(GEOIP_DISPLAY)
|
||||||
|
fi
|
||||||
|
|
||||||
dnl Hack to just try to find the lib and include
|
|
||||||
AC_MSG_CHECKING([for geoip install])
|
|
||||||
for x in ${test_paths}; do
|
AC_SUBST(GEOIP_FOUND)
|
||||||
for y in ${GEOIP_SONAMES}; do
|
|
||||||
for z in ${GEOIP_PKGNAMES}; do
|
]) # AC_DEFUN [PROG_GEOIP]
|
||||||
if test -e "${x}/${z}.${y}"; then
|
|
||||||
geoip_lib_path="${x}/"
|
|
||||||
geoip_lib_name="${z}"
|
AC_DEFUN([CHECK_FOR_GEOIP_AT], [
|
||||||
break
|
path=$1
|
||||||
fi
|
for y in ${GEOIP_POSSIBLE_EXTENSIONS}; do
|
||||||
if test -e "${x}/lib${z}.${y}"; then
|
for z in ${GEOIP_POSSIBLE_LIB_NAMES}; do
|
||||||
geoip_lib_path="${x}/"
|
if test -e "${path}/${z}.${y}"; then
|
||||||
geoip_lib_name="${z}"
|
geoip_lib_path="${path}/"
|
||||||
break
|
geoip_lib_name="${z}"
|
||||||
fi
|
geoip_lib_file="${geoip_lib_path}/${z}.${y}"
|
||||||
done
|
|
||||||
if test -n "$geoip_lib_path"; then
|
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
if test -e "${path}/lib${z}.${y}"; then
|
||||||
if test -n "$geoip_lib_path"; then
|
geoip_lib_path="${path}/"
|
||||||
break
|
geoip_lib_name="${z}"
|
||||||
fi
|
geoip_lib_file="${geoip_lib_path}/lib${z}.${y}"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
if test -e "${path}/lib/lib${z}.${y}"; then
|
||||||
|
geoip_lib_path="${path}/lib/"
|
||||||
|
geoip_lib_name="${z}"
|
||||||
|
geoip_lib_file="${geoip_lib_path}/lib${z}.${y}"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
if test -e "${path}/lib/x86_64-linux-gnu/lib${z}.${y}"; then
|
||||||
|
geoip_lib_path="${path}/lib/x86_64-linux-gnu/"
|
||||||
|
geoip_lib_name="${z}"
|
||||||
|
geoip_lib_file="${geoip_lib_path}/lib${z}.${y}"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if test -n "$geoip_lib_path"; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
for x in ${test_paths}; do
|
if test -e "${path}/include/GeoIPCity.h"; then
|
||||||
if test -e "${x}/include/GeoIPCity.h"; then
|
geoip_inc_path="${path}/include"
|
||||||
geoip_inc_path="${x}/include"
|
elif test -e "${path}/GeoIPCity.h"; then
|
||||||
break
|
geoip_inc_path="${path}"
|
||||||
elif test -e "${x}/GeoIPCity.h"; then
|
fi
|
||||||
geoip_inc_path="${x}"
|
|
||||||
break
|
if test -n "${geoip_lib_path}"; then
|
||||||
fi
|
AC_MSG_NOTICE([GeoIP library found at: ${geoip_lib_file}])
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test -n "${geoip_inc_path}"; then
|
||||||
|
AC_MSG_NOTICE([GeoIP headers found at: ${geoip_inc_path}])
|
||||||
|
fi
|
||||||
|
|
||||||
dnl # Check some sub-paths as well
|
|
||||||
for geoip_pkg_name in ${geoip_lib_name} ${GEOIP_PKGNAMES}; do
|
|
||||||
if test -e "${x}/include/${geoip_pkg_name}/GeoIPCity.h"; then
|
|
||||||
geoip_inc_path="${x}/include"
|
|
||||||
break
|
|
||||||
elif test -e "${x}/${geoip_pkg_name}/GeoIPCity.h"; then
|
|
||||||
geoip_inc_path="${x}"
|
|
||||||
break
|
|
||||||
else
|
|
||||||
geoip_inc_path=""
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
if test -n "$geoip_inc_path"; then
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
if test -n "${geoip_lib_path}" -a -n "${geoip_inc_path}"; then
|
if test -n "${geoip_lib_path}" -a -n "${geoip_inc_path}"; then
|
||||||
GEOIP_CONFIG=""
|
# TODO: Compile a piece of code to check the version.
|
||||||
AC_MSG_RESULT([${geoip_lib_path} ${geoip_inc_path}])
|
|
||||||
GEOIP_VERSION="2"
|
|
||||||
GEOIP_CFLAGS="-I${geoip_inc_path}"
|
GEOIP_CFLAGS="-I${geoip_inc_path}"
|
||||||
GEOIP_LDADD="-l${geoip_lib_name}"
|
GEOIP_LDADD="-l${geoip_lib_name}"
|
||||||
GEOIP_LDFLAGS="-L${geoip_lib_path}"
|
GEOIP_LDFLAGS="-L${geoip_lib_path}"
|
||||||
else
|
GEOIP_DISPLAY="${geoip_lib_file}, ${geoip_inc_path}"
|
||||||
GEOIP_VERSION=""
|
|
||||||
AC_MSG_RESULT([no])
|
|
||||||
fi
|
fi
|
||||||
fi
|
]) # AC_DEFUN [CHECK_FOR_GEOIP_AT]
|
||||||
|
|
||||||
])
|
|
||||||
|
|
||||||
GEOIP_LIBS=${GEOIP_LDADD}
|
|
||||||
AC_SUBST(GEOIP_CFLAGS)
|
|
||||||
AC_SUBST(GEOIP_VERSION)
|
|
||||||
AC_SUBST(GEOIP_LDADD)
|
|
||||||
AC_SUBST(GEOIP_LIBS)
|
|
||||||
AC_SUBST(GEOIP_LDFLAGS)
|
|
||||||
if test -z "${GEOIP_VERSION}"; then
|
|
||||||
ifelse([$2], , AC_MSG_ERROR([*** geoip library not found]), $2)
|
|
||||||
else
|
|
||||||
AC_MSG_NOTICE([using geoip v${GEOIP_VERSION}])
|
|
||||||
GEOIP_CFLAGS="-DWITH_GEOIP ${GEOIP_CFLAGS}"
|
|
||||||
ifelse([$1], , , $1)
|
|
||||||
fi
|
|
||||||
])
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user