Fixed building issues after merge
[cascardo/gnio.git] / configure.ac
1 AC_INIT(gnio/ginetaddress.h)
2
3 AM_INIT_AUTOMAKE(gnio, 0.0.1)
4 AM_CONFIG_HEADER(config.h)
5         
6 AM_SANITY_CHECK
7
8 AC_C_CONST
9 AC_ISC_POSIX
10 AC_PROG_CC
11 AC_PROG_CPP
12 AC_PROG_INSTALL
13 AC_PROG_LN_S
14 AC_PROG_MAKE_SET
15 AM_DISABLE_STATIC
16 AM_PROG_LIBTOOL
17 AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
18 AM_PROG_CC_C_O
19
20 AC_TYPE_PID_T
21 AC_TYPE_SIGNAL
22 AC_TYPE_SIZE_T
23 AC_TYPE_UID_T
24
25 AH_VERBATIM([_GNU_SOURCE],
26 [/* Enable GNU extensions on systems that have them.  */
27 #ifndef _GNU_SOURCE
28 #  define _GNU_SOURCE
29 #endif])
30         
31 saved_CFLAGS=$CFLAGS
32 AC_CHECK_MEMBERS([struct stat.st_mtimensec, struct stat.st_mtim.tv_nsec, struct stat.st_atimensec, struct stat.st_atim.tv_nsec, struct stat.st_ctimensec, struct stat.st_ctim.tv_nsec])
33 CFLAGS=$saved_CFLAGS
34
35 LIBTOOL_EXPORT_OPTIONS='-export-symbols-regex "^[[^_]].*"'
36 AC_SUBST(LIBTOOL_EXPORT_OPTIONS)
37                         
38 GTK_DOC_CHECK
39 DISTCHECK_CONFIGURE_FLAGS="--enable-gtk-doc"
40 AC_SUBST(DISTCHECK_CONFIGURE_FLAGS)
41
42 PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.13.8 gthread-2.0 gobject-2.0 gmodule-no-export-2.0 gio-unix-2.0
43                         gio-2.0)
44 AC_SUBST(GLIB_CFLAGS)
45 AC_SUBST(GLIB_LIBS)
46
47 PKG_CHECK_MODULES(GTHREAD, gthread-2.0)
48
49 GETTEXT_PACKAGE=gnio
50 AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [The gettext domain name])
51 AC_SUBST(GETTEXT_PACKAGE)
52
53 AM_GLIB_GNU_GETTEXT
54
55 AC_CHECK_FUNC(getaddrinfo_a)
56 AC_CHECK_FUNC(gethostbyname_r)
57
58 dnl ==========================================================================
59         
60 dnl Globally define_GNU_SOURCE and therefore enable the GNU extensions
61 AC_DEFINE(_GNU_SOURCE, 1, [Enable GNU Extensions])
62
63 AC_CHECK_HEADERS([sys/sockio.h sys/param.h ifaddrs.h])
64
65 AM_CONDITIONAL(WIN32, [echo "$host" | grep -qE '^.*-.*-mingw.*$'])
66
67 case "$host" in
68   *-*-mingw*)
69     AC_DEFINE(HAVE_IPV6, 1, [Define to 1 if IPv6 is potentially available])
70     AC_DEFINE(HAVE_GETADDRINFO, 1, [Define if the system provides getaddrinfo(2)])
71     AC_DEFINE(HAVE_GETADDRINFO_THREADSAFE, 1,   [Define if getaddrinfo is threadsafe])
72     AC_DEFINE(HAVE_SOCKADDR_STORAGE,1,[Whether you have struct sockaddr_storage])
73     ;;
74   *)
75     AC_MSG_CHECKING([for linux/netlink.h])
76     AC_TRY_CPP([#include <linux/netlink.h>],
77            [
78              AC_MSG_RESULT(yes)
79                  AC_DEFINE(HAVE_LINUX_NETLINK_H, 1,
80                [Define if linux/netlink.h header exists])
81                ],[
82                  AC_MSG_RESULT(no)
83                ])
84
85     AC_CHECK_MEMBER([struct sockaddr.sa_len],
86                 AC_DEFINE(HAVE_SOCKADDR_SA_LEN, 1,
87                   [Define if struct sockaddr has sa_len field]),,
88                 [#include <sys/types.h>
89                  #include <sys/socket.h>])
90
91     AC_MSG_CHECKING([for struct sockaddr_storage])
92     AC_TRY_COMPILE([ #include <sys/types.h>
93     #include <sys/socket.h>], [struct sockaddr_storage s; s],
94       have_sockaddr_storage=yes, have_sockaddr_storage=no)
95     if test "$have_sockaddr_storage" = yes; then
96       AC_DEFINE(HAVE_SOCKADDR_STORAGE,1,[Whether you have struct sockaddr_storage])
97       AC_MSG_RESULT(yes)
98     else
99       AC_MSG_RESULT(no)
100     fi
101
102     # Check for IPv6 support on unix
103     # (will be done at runtime on win32)
104     AC_MSG_CHECKING([for IPv6 availability])
105     AC_TRY_LINK([ #include <sys/types.h>
106                   #include <sys/socket.h>
107                   #include <netinet/in.h> ],
108                 [ struct sockaddr_in6 s;
109                   struct in6_addr t=in6addr_any;
110                   int i=AF_INET6;
111                   s;
112                   t.s6_addr[0] = 0; ],
113                 [
114                   AC_DEFINE(HAVE_IPV6, 1, [Define to 1 if IPv6 is potentially available])
115                   AC_MSG_RESULT(yes)
116                 ],
117                 [
118                   AC_DEFINE(HAVE_IPV6, 0, [Define to 1 if IPv6 is potentially available])
119                   AC_MSG_RESULT(no)
120                 ]
121     )
122     # Most of this code checks for variants of gethostbyname().  For
123     # simplicity and curiosity, we check for all variants, though only one
124     # working variant is needed.
125
126     # Look for getifaddrs()
127     AC_CHECK_FUNC(getifaddrs, AC_DEFINE(HAVE_GETIFADDRS, 1,
128         [Define if getifaddrs() is available]))
129
130
131     # The user may be able to tell us if a function is thread-safe.  We
132     # know of no good way to test this programaticly.
133
134     # On some systems, getaddrinfo() is thread-safe
135     AC_ARG_ENABLE(threadsafe_getaddrinfo,
136               AC_HELP_STRING([--enable-threadsafe-getaddrinfo],
137                              [assume getaddrinfo() is threadsafe]))
138
139     # On some systems, gethostbyname() is thread-safe
140     AC_ARG_ENABLE(threadsafe_gethostbyname,
141               AC_HELP_STRING([--enable-threadsafe-gethostbyname],
142                              [assume gethostbyname() is threadsafe]))
143
144
145     # Look for getaddrinfo().  If we have that, we don't need
146     # gethostbyname().  We assume if the system has getaddrinfo(), they
147     # have getnameinfo().
148     AC_CHECK_FUNC(getaddrinfo, 
149      [ # have getaddrinfo()
150       HAVE_GETADDRINFO=yes
151       AC_DEFINE(HAVE_GETADDRINFO, 1,
152         [Define if getaddrinfo() is available])
153       # Check for threadsafe getaddrinfo()
154       AC_MSG_CHECKING([for threadsafe getaddrinfo()])
155       if test "x$enable_threadsafe_getaddrinfo" = "xyes" ; then
156         HAVE_GETADDRINFO_THREADSAFE=yes
157         AC_MSG_RESULT(yes)
158         AC_DEFINE(HAVE_GETADDRINFO_THREADSAFE, 1,
159         [Define if getaddrinfo is threadsafe])
160       else
161         AC_MSG_RESULT(no)
162         # If there is no threadsafe getaddrinfo, use a Glib mutex.
163         if test "x$GTHREAD_CFLAGS" != "x"; then
164           AC_DEFINE(HAVE_GETADDRINFO_GLIB_MUTEX, 1,
165                     [Define if getaddrinfo requires a mutex for thread-safety])
166         HAVE_GETADDRINFO_GLIB_MUTEX=yes
167         else
168         AC_MSG_WARN([
169
170     You do not have a thread-safe getaddrinfo() or GLib threads.
171     Calls to getaddrinfo() may
172     not be thread-safe.  This build of GNIO could malfunction if used in
173     programs that use threads.  If your system has a thread-safe version
174     of getaddrinfo(), pass the option --enable-threadsafe-getaddrinfo
175     to configure.  The function's manpage may be able to tell you whether
176     it is thread-safe or not.
177
178     ])
179         fi
180       fi
181      ],
182      [  # no getaddrinfo()
183       AC_MSG_RESULT(no)
184      ])
185     # Check if the user told use gethostbyname() is thread-safe.
186     AC_MSG_CHECKING([for threadsafe gethostbyname()])
187     if test "x$enable_threadsafe_gethostbyname" = "xyes" ; then
188       AC_MSG_RESULT(yes)
189       AC_DEFINE(HAVE_GETHOSTBYNAME_THREADSAFE, 1, 
190         [Define if gethostbyname is threadsafe])
191       HAVE_GETHOSTBYNAME_THREADSAFE=yes
192     else
193       AC_MSG_RESULT(no)
194     fi
195
196     # Look for a gethostbyname_r() we can use.  We assume that if the
197     # system has gethostbyname_r(), they also have gethostbyaddr_r().
198
199     # First, look for the glibc varient
200     AC_MSG_CHECKING([for glibc gethostbyname_r])
201     AC_TRY_LINK([#include <netdb.h>],
202             [struct hostent result_buf;
203              char buf[1024];
204              struct hostent *result;
205              int h_erropp;
206
207              gethostbyname_r("localhost",
208                              &result_buf,
209                              buf,
210                              sizeof(buf),
211                              &result,
212                              &h_erropp);],
213              [AC_MSG_RESULT([yes])
214               AC_DEFINE(HAVE_GETHOSTBYNAME_R_GLIBC, 1,
215                  [Define if glibc variant of gethostbyname() is available])
216               HAVE_GETHOSTBYNAME_R=yes],
217              [AC_MSG_RESULT([no])])
218     # Whups, maybe we're on Solaris or Irix
219     AC_MSG_CHECKING([for Solaris/Irix gethostbyname_r])
220     AC_TRY_LINK([#include <netdb.h>],
221             [struct hostent result;
222              char buf[1024];
223              int h_errnop;
224
225              gethostbyname_r("localhost",
226                              &result,
227                              buf,
228                              sizeof(buf),
229                              &h_errnop);],
230             [AC_MSG_RESULT([yes])
231              AC_DEFINE(HAVE_GETHOSTBYNAME_R_SOLARIS, 1,
232                     [Define if Solaris variant of gethostbyname() is available])
233              HAVE_GETHOSTBYNAME_R=yes],
234             [AC_MSG_RESULT([no])])
235
236     # Or not.  Perhaps we're on HP-UX?
237     AC_MSG_CHECKING([for HP-UX gethostbyname_r])
238     AC_TRY_LINK([#include <netdb.h>],
239             [struct hostent result;
240              char buf[1024];
241
242              gethostbyname_r("localhost",
243                              &result,
244                              buf);],
245             [AC_MSG_RESULT([yes])
246              AC_DEFINE(HAVE_GETHOSTBYNAME_R_HPUX, 1,
247                    [Define if HPUX variant of gethostbyname() is available])
248              HAVE_GETHOSTBYNAME_R=yes],
249             [AC_MSG_RESULT([no])])
250     # If there is no gethostbyname_r, use Glib threads.
251     if test -z "$HAVE_GETHOSTBYNAME_THREADSAFE" -a -z "$HAVE_GETHOSTBYNAME_R" -a "$GTHREAD_CFLAGS"; then
252         AC_DEFINE(HAVE_GETHOSTBYNAME_R_GLIB_MUTEX, 1,
253                     [Define if gethostbyname requires a mutex for thread-safety])
254         HAVE_GETHOSTBYNAME_R=yes
255     fi
256
257     # Duh-oh.  We don't have _any_ thread-safety, so warn the builder
258     if test -z "$HAVE_GETADDRINFO_THREADSAFE" -a -z "$HAVE_GETHOSTBYNAME_THREADSAFE" -a -z "$HAVE_GETHOSTBYNAME_R"; then
259         AC_MSG_WARN([
260
261     You do not have a thread-safe gethostbyname_r() or GLib threads.
262     Calls to gethostbyname() (called by the GOIO address functions) may
263     not be thread-safe.  This build of GOIO could malfunction if used in
264     programs that use threads.  If your system has a thread-safe version
265     of gethostbyname(), pass the option --enable-threadsafe-gethostbyname
266     to configure.  The function's manpage may be able to tell you whether
267     it is thread-safe or not.
268
269     ])
270     fi
271     ;;
272 esac
273
274
275 dnl ==========================================================================
276         
277 AC_DEFINE(_FILE_OFFSET_BITS, 64, [Enable LFS])
278                        
279 dnl ==========================================================================
280
281 AC_PATH_PROG(GLIB_GENMARSHAL, glib-genmarshal)
282
283 dnl ==========================================================================
284 dnl Turn on the additional warnings last, so -Werror doesn't affect other tests.
285
286 AC_ARG_ENABLE(more-warnings,
287 [  --enable-more-warnings  Maximum compiler warnings],
288 set_more_warnings="$enableval",[
289 if test -f $srcdir/CVSVERSION; then
290         is_cvs_version=true
291         set_more_warnings=yes
292 else
293         set_more_warnings=no
294 fi
295 ])
296 AC_MSG_CHECKING(for more warnings, including -Werror)
297 if test "$GCC" = "yes" -a "$set_more_warnings" != "no"; then
298         AC_MSG_RESULT(yes)
299         CFLAGS="\
300         -Wall \
301         -Wchar-subscripts -Wmissing-declarations -Wmissing-prototypes \
302         -Wnested-externs -Wpointer-arith \
303         -Wcast-align -Wsign-compare \
304         $CFLAGS"
305
306         for option in -Wno-strict-aliasing -Wno-sign-compare; do
307                 SAVE_CFLAGS="$CFLAGS"
308                 CFLAGS="$CFLAGS $option"
309                 AC_MSG_CHECKING([whether gcc understands $option])
310                 AC_TRY_COMPILE([], [],
311                         has_option=yes,
312                         has_option=no,)
313                 if test $has_option = no; then
314                         CFLAGS="$SAVE_CFLAGS"
315                 fi
316                 AC_MSG_RESULT($has_option)
317                 unset has_option
318                 unset SAVE_CFLAGS
319         done
320         unset option
321 else
322         AC_MSG_RESULT(no)
323 fi
324                                
325 AC_OUTPUT([
326 Makefile
327 gnio/Makefile
328 test/Makefile
329 ])
330
331 echo 
332 echo "gnio configuration summary:"
333 echo "
334 "