Upstream tarball 9913
[amule.git] / m4 / GeoIP.m4
blobc76f1306a2b55014aee7101cade1782732abee08
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])
50                 AC_CHECK_HEADER([GeoIP.h], [
51                         AS_IF([test x$SYS = xwin32], [
52                                 AC_MSG_CHECKING([for WinSock library needed by GeoIP])
53                                 # Actually, we might not need any if GeoIP is linked as a .dll
54                                 # - but that's even harder to check for
55                                 AC_COMPILE_IFELSE([
56                                         AC_LANG_PROGRAM([[
57                                                 #include <GeoIP.h>
58                                                 #ifdef _WINSOCK2_H
59                                                         I do know it's not the best approach, but at least works with MinGW stock headers.
60                                                         (tested with w32api-3.12)
61                                                 #endif
62                                         ]])
63                                 ], [
64                                         GEOIP_WINSOCK_LIB="-lwsock32"
65                                 ], [
66                                         GEOIP_WINSOCK_LIB="-lws2_32"
67                                 ])
68                                 AC_MSG_RESULT([$GEOIP_WINSOCK_LIB])
69                         ])
70                         AC_CHECK_LIB([GeoIP], [GeoIP_open], [
71                                 AC_DEFINE([SUPPORT_GEOIP], [1], [Define if you want GeoIP support.])
72                                 GEOIP_LIBS="-lGeoIP"
73                                 AS_IF([test x$SYS = xwin32], [MULE_APPEND([GEOIP_LIBS], [$GEOIP_WINSOCK_LIB])])
74                                 MULE_APPEND([GEOIP_CPPFLAGS], [-DENABLE_IP2COUNTRY=1])
75                                 AC_ARG_WITH([geoip-static], AS_HELP_STRING([--with-geoip-static], [Explicitly link GeoIP statically (default=no)]),
76                                 [
77                                         AS_IF([test "$withval" != "no" -a ${enable_static:-no} = no], [
78                                                 MULE_BACKUP([LIBS])
79                                                 MULE_PREPEND([LIBS], [-Wl,-Bstatic $GEOIP_LIBS -Wl,-Bdynamic])
80                                                 AC_LINK_IFELSE([
81                                                         AC_LANG_PROGRAM([[
82                                                                 #include <GeoIP.h>
83                                                         ]], [[
84                                                                 GeoIP *g = GeoIP_new(GEOIP_STANDARD);
85                                                         ]])
86                                                 ], [
87                                                         GEOIP_LIBS="-Wl,-Bstatic $GEOIP_LIBS -Wl,-Bdynamic"
88                                                 ], [
89                                                         MULE_WARNING([Cannot link GeoIP statically, because your linker ($LD) does not support it.])
90                                                 ])
91                                                 MULE_RESTORE([LIBS])
92                                         ])
93                                 ])
94                         ], [
95                                 ENABLE_IP2COUNTRY=disabled
96                                 MULE_WARNING([GeoIP support has been disabled because the GeoIP libraries were not found])
97                         ], [${GEOIP_WINSOCK_LIB:-}])
98                 ], [
99                         ENABLE_IP2COUNTRY=disabled
100                         MULE_WARNING([GeoIP support has been disabled because the GeoIP header files were not found])
101                 ])
103                 MULE_RESTORE([CPPFLAGS])
104                 MULE_RESTORE([LDFLAGS])
105         ])
107 AC_SUBST([GEOIP_CPPFLAGS])dnl
108 AC_SUBST([GEOIP_LDFLAGS])dnl
109 AC_SUBST([GEOIP_LIBS])dnl