Upstream tarball 9389
[amule.git] / m4 / GeoIP.m4
blob9ff6089da2a86db571abab6427c980fc750a27cd
1 #                                               -*- Autoconf -*-
2 # This file is part of the aMule Project.
4 # Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
6 # Any parts of this program derived from the xMule, lMule or eMule project,
7 # or contributed by third-party developers are copyrighted by their
8 # respective authors.
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
25 dnl ---------------------------------------------------------------------------
26 dnl MULE_CHECK_GEOIP
27 dnl
28 dnl Checks if the GeoIP library is requested, exists, and whether it should and
29 dnl could be linked statically.
30 dnl ---------------------------------------------------------------------------
31 AC_DEFUN([MULE_CHECK_GEOIP],
33         AC_ARG_ENABLE([geoip],
34                 [AS_HELP_STRING([--enable-geoip], [compile with GeoIP IP2Country library])],
35                 [ENABLE_IP2COUNTRY=$enableval], [ENABLE_IP2COUNTRY=no])
37         AS_IF([test ${ENABLE_IP2COUNTRY:-no} = yes], [
38                 AC_ARG_WITH([geoip-headers],
39                         AS_HELP_STRING([--with-geoip-headers=DIR], [GeoIP include files location]),
40                         [GEOIP_CPPFLAGS="-I$withval"])
41                 AC_ARG_WITH([geoip-lib],
42                         AS_HELP_STRING([--with-geoip-lib=DIR], [GeoIP library location]),
43                         [GEOIP_LDFLAGS="-L$withval"])
45                 MULE_BACKUP([CPPFLAGS])
46                 MULE_APPEND([CPPFLAGS], [$GEOIP_CPPFLAGS])
47                 MULE_BACKUP([LDFLAGS])
48                 MULE_APPEND([LDFLAGS], [$GEOIP_LDFLAGS])
49                 AC_CHECK_HEADER([GeoIP.h], [
50                         AC_CHECK_LIB([GeoIP], [GeoIP_open], [
51                                 AC_DEFINE([SUPPORT_GEOIP], [1], [Define if you want GeoIP support.])
52                                 GEOIP_LIBS="-lGeoIP"
53                                 AS_IF([test x$SYS = xwin32], [MULE_APPEND([GEOIP_LIBS], [-lwsock32])])
54                                 MULE_APPEND([GEOIP_CPPFLAGS], [-DENABLE_IP2COUNTRY=1])
55                                 AC_ARG_WITH([geoip-static], AS_HELP_STRING([--with-geoip-static], [Explicitly link GeoIP statically (default=no)]),
56                                 [
57                                         AS_IF([test "$withval" != "no" -a ${enable_static:-no} = no], [
58                                                 MULE_BACKUP([LIBS])
59                                                 MULE_PREPEND([LIBS], [-Wl,-Bstatic $GEOIP_LIBS -Wl,-Bdynamic])
60                                                 AC_LINK_IFELSE([
61                                                         AC_LANG_PROGRAM([[
62                                                                 #include <GeoIP.h>
63                                                         ]], [[
64                                                                 GeoIP *g = GeoIP_new(GEOIP_STANDARD);
65                                                         ]])
66                                                 ], [
67                                                         GEOIP_LIBS="-Wl,-Bstatic $GEOIP_LIBS -Wl,-Bdynamic"
68                                                 ], [
69                                                         MULE_WARNING([Cannot link GeoIP statically, because your linker ($LD) does not support it.])
70                                                 ])
71                                                 MULE_RESTORE([LIBS])
72                                         ])
73                                 ])
74                         ], [
75                                 ENABLE_IP2COUNTRY=disabled
76                                 MULE_WARNING([GeoIP support has been disabled because the GeoIP libraries were not found])
77                         ])
78                 ], [
79                         ENABLE_IP2COUNTRY=disabled
80                         MULE_WARNING([GeoIP support has been disabled because the GeoIP header files were not found])
81                 ])
83                 MULE_RESTORE([CPPFLAGS])
84                 MULE_RESTORE([LDFLAGS])
85         ])
87 AC_SUBST([GEOIP_CPPFLAGS])dnl
88 AC_SUBST([GEOIP_LDFLAGS])dnl
89 AC_SUBST([GEOIP_LIBS])dnl