sac-su2.m4 19.7 KB
Newer Older
Pekka Pessi's avatar
Pekka Pessi committed
1 2 3 4
dnl ======================================================================
dnl su module
dnl ======================================================================

5 6
AC_DEFUN([SAC_SU])

Pekka Pessi's avatar
Pekka Pessi committed
7 8 9 10 11 12
AC_DEFUN([SAC_SOFIA_SU], [
# Beginning of SAC_SOFIA_SU

# ======================================================================
# Check for features used by su

13
dnl Define compilation options for su_configure.h
Pekka Pessi's avatar
Pekka Pessi committed
14 15 16

case "$target" in 
*-*-solaris?.* )
17
  SAC_SU_DEFINE(__EXTENSIONS__, 1, [Define to 1 in Solaris in order to get POSIX extensions.])
Pekka Pessi's avatar
Pekka Pessi committed
18 19 20 21 22 23
;;
esac

# Check includes used by su includes
AC_CHECK_HEADER(sys/types.h, 
	SAC_SU_DEFINE([SU_HAVE_SYS_TYPES], 1, 
24
		     [Define to 1 if Sofia uses sys/types.h]))
Pekka Pessi's avatar
Pekka Pessi committed
25 26 27 28 29

ax_inttypes=false
AC_CHECK_HEADER(stdint.h, [
	ax_inttypes=true
	SAC_SU_DEFINE([SU_HAVE_STDINT], 1, 
30
		     [Define to 1 if Sofia uses stdint.h])])
Pekka Pessi's avatar
Pekka Pessi committed
31 32 33
AC_CHECK_HEADER(inttypes.h,[
	ax_inttypes=true
	SAC_SU_DEFINE([SU_HAVE_INTTYPES], 1, 
34
		     [Define to 1 if Sofia uses inttypes.h])])
Pekka Pessi's avatar
Pekka Pessi committed
35 36 37 38 39

if $ax_inttypes; then : ; else 
	AC_MSG_ERROR("No <stdint.h> or <inttypes.h> found.")
fi

Martti Mela's avatar
Martti Mela committed
40
if test "x$MINGW_ENVIRONMENT" != x1 ; then
Martti Mela's avatar
Martti Mela committed
41
  AC_CHECK_HEADER(pthread.h, 
42
        HAVE_PTHREADS=1;
Pekka Pessi's avatar
Pekka Pessi committed
43
	SAC_SU_DEFINE([SU_HAVE_PTHREADS], 1, [Sofia SU uses pthreads]))
Martti Mela's avatar
Martti Mela committed
44
else
45
  HAVE_PTHREADS=1;
Martti Mela's avatar
Martti Mela committed
46 47
  SAC_SU_DEFINE([SU_HAVE_PTHREADS], 1, [Sofia SU uses pthreads])
fi
Pekka Pessi's avatar
Pekka Pessi committed
48

49
AC_ARG_ENABLE(experimental,
50
[  --enable-experimental   enable experimental features [[disabled]]],
51 52 53 54 55 56
 , enable_experimental=no)

if test $enable_experimental = yes ; then
  SAC_SU_DEFINE([SU_HAVE_EXPERIMENTAL], 1, [Enable experimental features])
fi

Pekka Pessi's avatar
Pekka Pessi committed
57
dnl ===========================================================================
Pekka Pessi's avatar
Pekka Pessi committed
58
dnl Checks for typedefs, headers, structures, and compiler characteristics.
Pekka Pessi's avatar
Pekka Pessi committed
59 60 61 62 63 64 65 66
dnl ===========================================================================

AC_REQUIRE([AC_C_CONST])
AC_REQUIRE([AC_HEADER_TIME])
AC_REQUIRE([AC_TYPE_SIZE_T])
AC_REQUIRE([AC_C_VAR_FUNC])
AC_REQUIRE([AC_C_MACRO_FUNCTION])

Pekka Pessi's avatar
Pekka Pessi committed
67
AC_REQUIRE([AC_C_INLINE])
Pekka Pessi's avatar
Pekka Pessi committed
68

69 70 71 72 73 74 75 76 77 78
AC_ARG_ENABLE(tag-cast,
[  --disable-tag-cast      cast tag values with inlined functions [[enabled]]],
 , enable_tag_cast=yes)

if test "$enable_tag_cast" = "yes"; then
    tag_cast=1
else
    tag_cast=0
fi

Pekka Pessi's avatar
Pekka Pessi committed
79 80
case "$ac_cv_c_inline" in
  yes) SAC_SU_DEFINE(su_inline, static inline, [
81
		Define to declarator for static inline functions.
Pekka Pessi's avatar
Pekka Pessi committed
82 83
	])dnl
       SAC_SU_DEFINE(SU_INLINE, inline, [
84
		Define to declarator for inline functions.
Pekka Pessi's avatar
Pekka Pessi committed
85 86
	])dnl
       SAC_SU_DEFINE(SU_HAVE_INLINE, 1, [
87
		Define to 1 if you have inline functions.
Pekka Pessi's avatar
Pekka Pessi committed
88
	])dnl
89 90 91
       SAC_SU_DEFINE_UNQUOTED(SU_INLINE_TAG_CAST, $tag_cast, [
		Define to 1 if you use inline function to cast tag values.
	])dnl
Pekka Pessi's avatar
Pekka Pessi committed
92
  ;;
Pekka Pessi's avatar
Pekka Pessi committed
93 94 95 96
  no | "" )
       SAC_SU_DEFINE(su_inline, static)dnl
       SAC_SU_DEFINE(SU_INLINE, /*inline*/)dnl
       SAC_SU_DEFINE(SU_HAVE_INLINE, 0)dnl
97
       SAC_SU_DEFINE(SU_INLINE_TAG_CAST, 0)dnl
Pekka Pessi's avatar
Pekka Pessi committed
98 99 100 101
  ;;
  *)   SAC_SU_DEFINE_UNQUOTED(su_inline, static $ac_cv_c_inline)dnl
       SAC_SU_DEFINE_UNQUOTED(SU_INLINE, $ac_cv_c_inline)dnl
       SAC_SU_DEFINE(SU_HAVE_INLINE, 1)dnl
102
       SAC_SU_DEFINE_UNQUOTED(SU_INLINE_TAG_CAST, $tag_cast)dnl
Pekka Pessi's avatar
Pekka Pessi committed
103 104 105
  ;;
esac

106
AC_ARG_ENABLE(size-compat,
107
[  --disable-size-compat   use compatibility size_t types [[enabled]]],
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
 , enable_size_compat=yes)

if test X$enable_size_compat != Xyes; then
       SAC_SU_DEFINE(SOFIA_ISIZE_T, size_t)dnl
       SAC_SU_DEFINE(ISIZE_MAX, SIZE_MAX)dnl
       SAC_SU_DEFINE(SOFIA_ISSIZE_T, ssize_t)dnl
       SAC_SU_DEFINE(ISSIZE_MAX, SSIZE_MAX)dnl
       SAC_SU_DEFINE(SOFIA_USIZE_T, size_t)dnl
       SAC_SU_DEFINE(USIZE_MAX, SIZE_MAX)dnl
else
       SAC_SU_DEFINE(SOFIA_ISIZE_T, int)dnl
       SAC_SU_DEFINE(ISIZE_MAX, INT_MAX)dnl
       SAC_SU_DEFINE(SOFIA_ISSIZE_T, int)dnl
       SAC_SU_DEFINE(ISSIZE_MAX, INT_MAX)dnl
       SAC_SU_DEFINE(SOFIA_USIZE_T, unsigned)dnl
       SAC_SU_DEFINE(USIZE_MAX, UINT_MAX)dnl
fi

126

127 128 129 130
dnl ======================================================================
dnl SAC_ENABLE_COREFOUNDATION
dnl ======================================================================
AC_ARG_ENABLE(corefoundation,
131 132
[  --enable-corefoundation 
                          compile with OSX COREFOUNDATION [[disabled]]],
133 134 135 136 137 138 139 140 141 142
 , enable_corefoundation=no)
AM_CONDITIONAL(COREFOUNDATION, test $enable_corefoundation = yes)

if test $enable_corefoundation = yes ; then
   SAC_SU_DEFINE([SU_HAVE_OSX_CF_API], 1, [
Define as 1 if you have OSX CoreFoundation interface])
   LIBS="-framework CoreFoundation -framework SystemConfiguration $LIBS"
fi


143 144 145
### ======================================================================
### Test if we have stack suitable for handling tags directly
###
146 147

AC_CACHE_CHECK([for stack suitable for tags],[ac_cv_tagstack],[
148 149
ac_cv_tagstack=no

150
AC_RUN_IFELSE([AC_LANG_SOURCE([[
151 152 153 154 155 156
#if HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#if HAVE_STDINT_H
#include <stdint.h>
#endif
157

158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
#include <stdarg.h>

typedef void *tp;
typedef intptr_t tv;

int test1(tv l, tv h, ...)
{
  va_list ap;
  tv i, *p = &l;

  va_start(ap, h);

  if (*p++ != l || *p++ != h) return 1;

  for (i = l; i <= h; i++) {
    if (*p++ != i)
      return 1;
  }

  for (i = l; i <= h; i++) {
    if (va_arg(ap, tv) != i)
      return 1;
  }

  va_end(ap);

  return 0;
}

int main(int avc, char **av)
{
  return test1((tv)1, (tv)10,
	       (tv)1, (tv)2, (tv)3, (tv)4, (tv)5,
	       (tv)6, (tv)7, (tv)8, (tv)9, (tv)10);
}
193 194 195 196 197 198
]])],[ac_cv_tagstack=yes],[ac_cv_tagstack=no],[
case "$target" in 
i?86-*-* ) ac_cv_tagstack=yes ;;
* ) ac_cv_tagstack=no ;;
esac
])])
199 200 201 202 203 204

if test $ac_cv_tagstack = yes ; then
SAC_SU_DEFINE([SU_HAVE_TAGSTACK], 1, [
Define this as 1 if your compiler puts the variable argument list nicely in memory])
fi

205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
### ======================================================================
### Test if free(0) fails
###

AC_CACHE_CHECK([for graceful free(0)],[ac_cv_free_null],[
ac_cv_free_null=no

AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <stdlib.h>

int main(int avc, char **av)
{
	free(0);
	return 0;
}
]])],[ac_cv_free_null=yes],[ac_cv_free_null=no],[ac_cv_free_null=no])])

if test $ac_cv_free_null = yes ; then
AC_DEFINE([HAVE_FREE_NULL], 1, [
Define this as 1 if your c library does not crash with free(0)])
fi

227 228 229
dnl ======================================================================
dnl Socket features

Pekka Pessi's avatar
Pekka Pessi committed
230 231 232
AC_REQUIRE([AC_SYS_SA_LEN])
if test "$ac_cv_sa_len" = yes ;then
  SAC_SU_DEFINE([SU_HAVE_SOCKADDR_SA_LEN], 1, 
233
	        [Define to 1 if you have sa_len in struct sockaddr])
Pekka Pessi's avatar
Pekka Pessi committed
234 235
fi

236 237 238 239 240
AC_ARG_ENABLE([ip6],
[  --disable-ip6          disable IPv6 functionality [[enabled]]],,enable_ip6=yes)

if ! test no$enable_ip6 = nono ; then
AC_STRUCT_SIN6
Pekka Pessi's avatar
Pekka Pessi committed
241 242
case $ac_cv_sin6 in 
yes) SAC_SU_DEFINE(SU_HAVE_IN6, 1, [
243
	Define to 1 if you have struct sockaddr_in6]) ;;
244 245
 no) ;;
  *) AC_MSG_ERROR([Inconsistent struct sockaddr_sin6 test]) ;;
Pekka Pessi's avatar
Pekka Pessi committed
246
esac
247
fi
Pekka Pessi's avatar
Pekka Pessi committed
248

Pekka Pessi's avatar
Pekka Pessi committed
249
AC_CHECK_HEADERS([unistd.h sys/time.h])
250

251
AC_CHECK_HEADERS([fcntl.h dirent.h])
252

253
AC_CHECK_HEADERS([winsock2.h], [
254 255 256
  AC_DEFINE([HAVE_WIN32], 1, [Define to 1 you have WIN32])
  SAC_SU_DEFINE([SU_HAVE_WINSOCK], 1, [Define to 1 you have WinSock])
  SAC_SU_DEFINE([SU_HAVE_WINSOCK2], 1, [Define to 1 you have WinSock2])
257
  SAC_SU_DEFINE([SU_HAVE_SOCKADDR_STORAGE], 1, 
258
      [Define to 1 if you have struct sockaddr_storage])
Martti Mela's avatar
Martti Mela committed
259
  AC_DEFINE([HAVE_ADDRINFO], 1,
260
      [Define to 1 if you have addrinfo structure.])
Martti Mela's avatar
Martti Mela committed
261
  AC_DEFINE([HAVE_GETADDRINFO], 1,
262
      [Define to 1 if you have addrinfo structure.])
Martti Mela's avatar
Martti Mela committed
263
  AC_DEFINE([HAVE_FREEADDRINFO], 1,
264
      [Define to 1 if you have addrinfo structure.])
Martti Mela's avatar
Martti Mela committed
265
  SAC_SU_DEFINE([SU_HAVE_ADDRINFO], 1,
266
      [Define to 1 if you have addrinfo structure.])
267
  AC_CHECK_HEADERS([windef.h ws2tcpip.h])
Martti Mela's avatar
Martti Mela committed
268 269
  AC_CHECK_HEADERS([iphlpapi.h], [
    AC_DEFINE([HAVE_INTERFACE_INFO_EX], 1, [
270
       Define to 1 if you have WIN32 INTERFACE_INFO_EX type.])
Martti Mela's avatar
Martti Mela committed
271
    AC_DEFINE([HAVE_SIO_ADDRESS_LIST_QUERY], 1, [
272
       Define to 1 if you have WIN32 WSAIoctl SIO_ADDRESS_LIST_QUERY.])
Martti Mela's avatar
Martti Mela committed
273 274 275 276 277
  ], [], [#if HAVE_WINDEF_H
#include <windef.h>
#include <winbase.h>
#endif
  ])
278
  AC_DEFINE([HAVE_FILETIME], 1, [
279
     Define to 1 if you have WIN32 FILETIME type and 
280
     GetSystemTimeAsFileTime().])
281 282
],[
dnl no winsock2
283

284
SAC_SU_DEFINE([SU_HAVE_BSDSOCK], 1, [Define to 1 if you have BSD socket interface])
285
AC_CHECK_HEADERS([sys/socket.h sys/ioctl.h sys/filio.h sys/sockio.h \
286
		  sys/select.h sys/epoll.h sys/devpoll.h])
287
AC_CHECK_HEADERS([netinet/in.h arpa/inet.h netdb.h \
288
                  net/if.h net/if_types.h ifaddr.h netpacket/packet.h],,,
289 290 291
		[
#include <sys/types.h>
#include <sys/socket.h>])
292

293 294 295 296 297
AC_CHECK_DECL([MSG_TRUNC],
AC_DEFINE([HAVE_MSG_TRUNC],1,[Define to 1 if you have MSG_TRUNC flag]),,[
#include <sys/types.h>
#include <sys/socket.h>])

298 299 300 301 302 303 304 305 306 307
AC_CHECK_DECL([SO_RCVBUFFORCE],
AC_DEFINE([HAVE_SO_RCVBUFFORCE],1,[Define to 1 if you have socket option SO_RCVBUFFORCE]),,[
#include <sys/types.h>
#include <sys/socket.h>])

AC_CHECK_DECL([SO_SNDBUFFORCE],
AC_DEFINE([HAVE_SO_SNDBUFFORCE],1,[Define to 1 if you have socket option SO_SNDBUFFORCE]),,[
#include <sys/types.h>
#include <sys/socket.h>])

308 309 310 311 312 313 314 315 316 317 318 319
AC_CHECK_DECL([IP_ADD_MEMBERSHIP],
AC_DEFINE([HAVE_IP_ADD_MEMBERSHIP],1,[Define to 1 if you have IP_ADD_MEMBERSHIP]),,[
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>])

AC_CHECK_DECL([IP_MULTICAST_LOOP],
AC_DEFINE([HAVE_IP_MULTICAST_LOOP],1,[Define to 1 if you have IP_MULTICAST_LOOP]),,[
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>])

320 321 322 323 324 325 326
AC_CHECK_DECL([IP_MTU_DISCOVER],
AC_DEFINE([HAVE_IP_MTU_DISCOVER],1,
[Define to 1 if you have IP_MTU_DISCOVER]),,[
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>])

327 328 329 330 331 332 333 334 335 336 337 338
AC_CACHE_CHECK([for struct addrinfo],
[ac_cv_struct_addrinfo],[
ac_cv_struct_addrinfo=no
if test "$ac_cv_header_sys_socket_h" = yes; then
  AC_EGREP_HEADER([struct.+addrinfo], [netdb.h], [
  ac_cv_struct_addrinfo=yes])
else
  ac_cv_struct_addrinfo='sys/socket.h missing'
fi])

if test "$ac_cv_struct_addrinfo" = yes; then
  SAC_SU_DEFINE([SU_HAVE_ADDRINFO], 1, 
339
    [Define to 1 if you have struct addrinfo.])
340
fi
341

Pekka Pessi's avatar
Pekka Pessi committed
342 343 344 345 346 347 348 349 350 351 352
AC_CACHE_CHECK([for struct sockaddr_storage],
[ac_cv_struct_sockaddr_storage],[
ac_cv_struct_sockaddr_storage=no
if test "$ac_cv_header_sys_socket_h" = yes; then
  AC_EGREP_HEADER([struct.+sockaddr_storage], [sys/socket.h], [
  ac_cv_struct_sockaddr_storage=yes])
else
  ac_cv_struct_sockaddr_storage='sys/socket.h missing'
fi])
if test "$ac_cv_struct_sockaddr_storage" = yes; then
  SAC_SU_DEFINE(SU_HAVE_SOCKADDR_STORAGE, 1, 
353
    [Define to 1 if you have struct sockaddr_storage])
Pekka Pessi's avatar
Pekka Pessi committed
354 355 356 357 358 359
fi

AC_CACHE_CHECK([for field ifr_index in struct ifreq],
[ac_cv_struct_ifreq_ifr_index],[
ac_cv_struct_ifreq_ifr_index=no
if test "1${ac_cv_header_arpa_inet_h}2${ac_cv_header_netdb_h}3${ac_cv_header_sys_socket_h}4${ac_cv_header_net_if_h}" = 1yes2yes3yes4yes; then
360
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
Pekka Pessi's avatar
Pekka Pessi committed
361 362 363
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/socket.h>
364
#include <net/if.h>]], [[
Pekka Pessi's avatar
Pekka Pessi committed
365
struct ifreq ifreq; int index; index = ifreq.ifr_index;
366
]])],[ac_cv_struct_ifreq_ifr_index=yes],[])
Pekka Pessi's avatar
Pekka Pessi committed
367 368 369 370 371 372
else
  ac_cv_struct_ifreq_ifr_index='net/if.h missing'
fi # arpa/inet.h && netdb.h && sys/socket.h && net/if.h
])
if test "$ac_cv_struct_ifreq_ifr_index" = yes ; then
  :
373
  AC_DEFINE(HAVE_IFR_INDEX, 1, [Define to 1 if you have ifr_index in <net/if.h>])
Pekka Pessi's avatar
Pekka Pessi committed
374 375 376 377 378
else
AC_CACHE_CHECK([for field ifr_ifindex in struct ifreq],
[ac_cv_struct_ifreq_ifr_ifindex],[
ac_cv_struct_ifreq_ifr_ifindex=no
if test "1${ac_cv_header_arpa_inet_h}2${ac_cv_header_netdb_h}3${ac_cv_header_sys_socket_h}4${ac_cv_header_net_if_h}" = 1yes2yes3yes4yes; then
379
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
Pekka Pessi's avatar
Pekka Pessi committed
380 381 382
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/socket.h>
383
#include <net/if.h>]], [[
Pekka Pessi's avatar
Pekka Pessi committed
384
struct ifreq ifreq; int index; index = ifreq.ifr_ifindex;
385
]])],[ac_cv_struct_ifreq_ifr_ifindex=yes],[])
Pekka Pessi's avatar
Pekka Pessi committed
386 387 388
else
  ac_cv_struct_ifreq_ifr_ifindex='net/if.h missing'
fi # arpa/inet.h && netdb.h && sys/socket.h && net/if.h
389
])
Pekka Pessi's avatar
Pekka Pessi committed
390 391
if test "$ac_cv_struct_ifreq_ifr_ifindex" = yes; then
  :
392
  AC_DEFINE(HAVE_IFR_IFINDEX, 1, [Define to 1 if you have ifr_ifindex in <net/if.h>])
Pekka Pessi's avatar
Pekka Pessi committed
393 394 395
fi

fi # ifr_index in struct ifreq
396

Pekka Pessi's avatar
Pekka Pessi committed
397
dnl SIOGCIFCONF & struct ifconf
Pekka Pessi's avatar
Pekka Pessi committed
398 399 400 401 402 403 404 405 406
AC_CACHE_CHECK([for struct ifconf],
[ac_cv_struct_ifconf],[
ac_cv_struct_ifconf=no
if test "$ac_cv_header_net_if_h" = yes; then
  AC_EGREP_HEADER(struct.+ifconf, net/if.h, ac_cv_struct_ifconf=yes)
else
  ac_cv_struct_ifconf='net/if.h missing'
fi])
if test "$ac_cv_struct_ifconf" = yes; then
407
  AC_DEFINE(HAVE_IFCONF, 1, [Define to 1 if you have SIOCGIFCONF])
Pekka Pessi's avatar
Pekka Pessi committed
408
fi
Pekka Pessi's avatar
Pekka Pessi committed
409

Pekka Pessi's avatar
Pekka Pessi committed
410 411 412 413
AC_CACHE_CHECK([for ioctl SIOCGIFNUM],
[ac_cv_ioctl_siocgifnum],[
ac_cv_ioctl_siocgifnum=no
if test "$ac_cv_header_sys_sockio_h" = yes; then
Pekka Pessi's avatar
Pekka Pessi committed
414 415 416 417 418
AC_EGREP_CPP(yes, [
#include <sys/sockio.h>
#ifdef SIOCGIFNUM
  yes
#endif
Pekka Pessi's avatar
Pekka Pessi committed
419 420 421 422 423 424
], [ac_cv_ioctl_siocgifnum=yes])
else
  ac_cv_ioctl_siocgifnum='sys/sockio.h missing'
fi])
if test "$ac_cv_ioctl_siocgifnum" = yes; then
  HAVE_IFNUM=1
425
  AC_DEFINE(HAVE_IFNUM, 1, [Define to 1 if you have SIOCGIFNUM ioctl])
Pekka Pessi's avatar
Pekka Pessi committed
426 427 428 429
else
  HAVE_IFNUM=0
fi

430 431
]) dnl AC_CHECK_HEADERS([winsock2.h ... ])

432

433 434 435 436
# ===========================================================================
# Checks for libraries
# ===========================================================================

437 438 439 440 441 442 443 444
AC_CHECK_LIB(pthread, pthread_create)
AC_CHECK_LIB(socket, socketpair,,,-lnsl)

AC_ARG_WITH(rt,  
[  --with-rt               use POSIX realtime library [[used by default]]])
if test "${with_rt}" != no; then
	AC_SEARCH_LIBS(clock_gettime, rt)
        AC_CHECK_FUNCS([clock_gettime clock_getcpuclockid])
445 446 447 448
        AC_CHECK_DECL([CLOCK_MONOTONIC],
AC_DEFINE([HAVE_CLOCK_MONOTONIC], 1,
[Define to 1 if you have CLOCK_MONOTONIC]),,[
#include <time.h>])
449
fi
Pekka Pessi's avatar
Pekka Pessi committed
450

451 452 453 454 455 456 457 458
# No GLib path explicitly defined, use pkg-config
AC_ARG_WITH(glib,
[  --with-glib=version     use GLib (default=2.0)], [
case "$with_glib" in 
yes | "" ) with_glib=2.0 ;;
esac
], [with_glib=2.0])

Martti Mela's avatar
Martti Mela committed
459
AC_ARG_WITH(glib-dir,
460 461
[  --with-glib-dir=PREFIX  explicitly define GLib path],, 
 with_glib_dir="pkg-config")
Martti Mela's avatar
Martti Mela committed
462

463
if test "$with_glib" = no || test "$with_glib_dir" = "no" ; then
Martti Mela's avatar
Martti Mela committed
464

465
  : # No glib
Martti Mela's avatar
Martti Mela committed
466

467
elif test "$with_glib_dir" = "pkg-config" ; then 
Martti Mela's avatar
Martti Mela committed
468

469
  PKG_CHECK_MODULES(GLIB, glib-$with_glib, [HAVE_GLIB=yes], [HAVE_GLIB=no])
Martti Mela's avatar
Martti Mela committed
470

471
else # GLib path is explicitly defined 
Martti Mela's avatar
Martti Mela committed
472

473 474 475
  gprefix=$with_glib_dir
  GLIB_VERSION="$with_glib"
  GLIBXXX=glib-$with_glib
Martti Mela's avatar
Martti Mela committed
476

477 478 479 480 481 482
  if test "$gprefix" = "yes" ; then 
    for gprefix in /usr /usr/local /opt/$GLIBXXX
    do
  	test -d $gprefix/include/$GLIBXXX && break
    done
  fi
Martti Mela's avatar
Martti Mela committed
483

484 485 486 487 488 489
  if ! test -d $gprefix/include/$GLIBXXX ; then
    AC_MSG_ERROR("No $GLIBXXX in --with-glib=$with_glib_dir")
  else
    exec_gprefix=${gprefix}
    glibdir=${exec_gprefix}/lib
    gincludedir=${gprefix}/include
Martti Mela's avatar
Martti Mela committed
490

491 492
    # glib_genmarshal=glib-genmarshal
    # glib_mkenums=glib-mkenums
493

494 495 496 497 498 499 500 501 502
    HAVE_GLIB=yes
    
    if test "x$MINGW_ENVIRONMENT" = x1 ; then
      GLIB_LIBS="${glibdir}/lib$GLIBXXX.dll.a ${glibdir}/libintl.a ${glibdir}/libiconv.a"
    else
      GLIB_LIBS="-L${glibdir} -l$GLIBXXX -lintl -liconv"
    fi
    GLIB_CFLAGS="-I${gincludedir}/$GLIBXXX -I${glibdir}/$GLIBXXX/include"
  fi
503

504
fi # GLib path is explicitly defined 
505

506
if test "x$HAVE_GLIB" = xyes ; then
507
  SAC_COMMA_APPEND([SOFIA_GLIB_PKG_REQUIRES],[glib-2.0])
508 509
fi

510
AM_CONDITIONAL([HAVE_GLIB], [test "x$HAVE_GLIB" = xyes])
511 512 513
AC_SUBST([GLIB_LIBS])
AC_SUBST([GLIB_CFLAGS])
AC_SUBST([GLIB_VERSION])
514
AC_SUBST([SOFIA_GLIB_PKG_REQUIRES])
Martti Mela's avatar
Martti Mela committed
515

Pekka Pessi's avatar
Pekka Pessi committed
516 517 518 519
# ===========================================================================
# Checks for library functions.
# ===========================================================================

520 521 522 523 524 525 526
AC_SEARCH_LIBS(socket, xnet socket)
AC_SEARCH_LIBS(inet_ntop, socket nsl)
dnl AC_SEARCH_LIBS(inet_pton, socket nsl)
AC_SEARCH_LIBS(getipnodebyname, xnet socket nsl)
AC_SEARCH_LIBS(gethostbyname, xnet nsl)
AC_SEARCH_LIBS(getaddrinfo, xnet socket nsl)

527 528
AC_FUNC_ALLOCA

529
AC_CHECK_FUNCS([gettimeofday strerror random initstate tcsetattr flock \
530
                socketpair gethostname gethostbyname getipnodebyname \
531
                poll epoll_create kqueue select if_nameindex \
532
		signal alarm \
533 534 535
	        getaddrinfo getnameinfo freeaddrinfo gai_strerror getifaddrs \
                getline getdelim getpass])
# getline getdelim getpass are _GNU_SOURCE stuff
536

537
if test $ac_cv_func_poll = yes ; then
538
  SAC_SU_DEFINE([SU_HAVE_POLL], 1, [Define to 1 if you have poll().])
539
fi
Pekka Pessi's avatar
Pekka Pessi committed
540

541 542
if test $ac_cv_func_epoll_create = yes && test $ac_cv_header_sys_epoll_h = yes
then
543 544 545
  AC_DEFINE([HAVE_EPOLL], 1, [Define to 1 if you have epoll interface.])
fi

546 547
if test $ac_cv_func_if_nameindex = yes ; then
  SAC_SU_DEFINE([SU_HAVE_IF_NAMEINDEX], 1, 
548
    [Define to 1 if you have if_nameindex().])
549
fi
Pekka Pessi's avatar
Pekka Pessi committed
550

551
SAC_REPLACE_FUNCS([memmem memccpy memspn memcspn strcasestr strtoull \
552
		   inet_ntop inet_pton poll])
Pekka Pessi's avatar
Pekka Pessi committed
553

554 555 556 557 558 559 560 561
if test $ac_cv_func_signal = yes ; then
AC_CHECK_DECL([SIGPIPE], [
AC_DEFINE([HAVE_SIGPIPE], 1, [Define to 1 if you have SIGPIPE])],,[
#include <signal.h>
])
dnl add SIGHUP SIGQUIT if needed
fi

562 563 564 565 566
# ===========================================================================
# Check how to implement su_port
# ===========================================================================

AC_ARG_ENABLE(poll-port,
567 568 569
[  --disable-poll-port     disable su_poll_port [[enabled]]
                          Use this option in systems emulating poll with select],
 , enable_poll_port=maybe)
570

571
if test $enable_poll_port = maybe ; then
572 573 574
  if test $ac_cv_func_poll = yes ; then
    AC_DEFINE([HAVE_POLL_PORT], 1, [Define to 1 if you use poll in su_port.])
  fi
575 576
elif test $enable_poll_port = yes ; then
    AC_DEFINE([HAVE_POLL_PORT], 1, [Define to 1 if you use poll in su_port.])
577
fi
Pekka Pessi's avatar
Pekka Pessi committed
578

579 580 581 582 583 584
# ===========================================================================
# Check pthread_rwlock_unlock()
# ===========================================================================

AC_DEFUN([AC_DEFINE_HAVE_PTHREAD_RWLOCK],[dnl
AC_DEFINE([HAVE_PTHREAD_RWLOCK], 1,[
585
Define to 1 if you have working pthread_rwlock_t implementation.
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604

   A  thread  may hold multiple concurrent read locks on rwlock - that is,
   successfully call the pthread_rwlock_rdlock() function  n  times.  If
   so,  the  application  shall  ensure that the thread performs matching
   unlocks - that is, it  calls  the  pthread_rwlock_unlock()  function  n
   times.
])])

if test x$HAVE_PTHREADS = x1 ; then

AC_RUN_IFELSE([
#define _XOPEN_SOURCE (500)

#include <pthread.h>

pthread_rwlock_t rw;

int main()
{
605
  pthread_rwlock_init(&rw, NULL);
606 607 608
  pthread_rwlock_rdlock(&rw);
  pthread_rwlock_rdlock(&rw);
  pthread_rwlock_unlock(&rw);
609 610
  /* pthread_rwlock_trywrlock() should fail (not return 0) */
  return pthread_rwlock_trywrlock(&rw) != 0 ? 0  : 1;
611 612 613 614 615 616 617
}
],[AC_DEFINE_HAVE_PTHREAD_RWLOCK],[
AC_MSG_WARN([Recursive pthread_rwlock_rdlock() does not work!!! ])
],[AC_DEFINE_HAVE_PTHREAD_RWLOCK])

fi

Pekka Pessi's avatar
Pekka Pessi committed
618 619 620 621 622
# ===========================================================================
# Check IPv6 addresss configuration
# ===========================================================================
case "$target" in
 *-*-linux*) AC_DEFINE([HAVE_PROC_NET_IF_INET6], 1, 
623
	[Define to 1 if you have /proc/net/if_inet6 control file]) ;;
Pekka Pessi's avatar
Pekka Pessi committed
624 625
esac

626
AC_CONFIG_HEADERS([libsofia-sip-ua/su/sofia-sip/su_configure.h])
627 628

# End of SAC_SOFIA_SU
Pekka Pessi's avatar
Pekka Pessi committed
629 630
])

631 632 633 634 635
dnl
dnl Append a value $2 to a variable, separating values with comma
dnl
AC_DEFUN([SAC_COMMA_APPEND],[$1="`test -n "$$1" && echo "$$1, "`$2"])

Pekka Pessi's avatar
Pekka Pessi committed
636 637 638 639 640
# SAC_SU_DEFINE(VARIABLE, [VALUE], [DESCRIPTION])
# -------------------------------------------
# Set VARIABLE to VALUE, verbatim, or 1.  Remember the value
# and if VARIABLE is affected the same VALUE, do nothing, else
# die.  The third argument is used by autoheader.
641

Pekka Pessi's avatar
Pekka Pessi committed
642 643 644 645 646 647 648 649 650 651 652 653 654 655
m4_define([SAC_SU_DEFINE],[
cat >>confdefs.h <<\_AXEOF
[@%:@define] $1 m4_if($#, 2, [$2], $#, 3, [$2], 1)
_AXEOF
])

# SAC_SU_DEFINE_UNQUOTED(VARIABLE, [VALUE], [DESCRIPTION])
# ----------------------------------------------------
# Similar, but perform shell substitutions $ ` \ once on VALUE.
m4_define([SAC_SU_DEFINE_UNQUOTED],[
cat >>confdefs.h <<_ACEOF
[@%:@define] $1 m4_if($#, 2, [$2], $#, 3, [$2], 1)
_ACEOF
])
656 657

AC_DEFUN([SAC_REPLACE_FUNCS],[dnl
658
AC_CHECK_FUNCS([$1],ifelse([$2], , :,[$2]),[dnl
659 660 661 662 663 664 665 666
case "$REPLACE_LIBADD" in
    "$ac_func.lo"   | \
  *" $ac_func.lo"   | \
    "$ac_func.lo "* | \
  *" $ac_func.lo "* ) ;;
  *) REPLACE_LIBADD="$REPLACE_LIBADD $ac_func.lo" ;;
esac])
AC_SUBST([REPLACE_LIBADD])
667
ifelse([$3], , :, [$3])
668
])