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

dnl This is in a separate file because otherwise AM_CONFIG_HEADER in
dnl SAC_SOFIA_SU confuses autoheader. If SAC_SOFIA_SU is included to a
dnl aclocal.m4 of another package, autoheader returns a spurious error and
8 9
dnl automake complains about missing
dnl libsofia-sip-ua/su/sofia-sip/su_configure.h.
Pekka Pessi's avatar
Pekka Pessi committed
10 11 12 13 14 15 16 17 18

AC_DEFUN([SAC_SOFIA_SU], [
# Beginning of SAC_SOFIA_SU

AC_REQUIRE([SAC_WITH_RT])

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

19
dnl Define compilation options for su_configure.h
Martti Mela's avatar
Martti Mela committed
20
dnl SAC_SU_DEFINE([SU_HAVE_BSDSOCK], 1, [Define as 1 if you have BSD socket interface])
Pekka Pessi's avatar
Pekka Pessi committed
21 22 23 24 25 26 27

case "$target" in 
*-*-solaris?.* )
  SAC_SU_DEFINE(__EXTENSIONS__, 1, [Define this in Solaris in order to get POSIX extensions.])
;;
esac

Pekka Pessi's avatar
Pekka Pessi committed
28 29 30 31 32 33
case "$target" in 
i?86-*-* )
  SAC_SU_DEFINE(SU_HAVE_TAGSTACK, 1, [Define this as 1 if we can use tags directly from stack.])
;;
esac

Pekka Pessi's avatar
Pekka Pessi committed
34
if false; then # Define Win32 macros
Pekka Pessi's avatar
Pekka Pessi committed
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
  AC_DEFINE([HAVE_WIN32], 1, [Define as 1 you have WIN32])
  SAC_SU_DEFINE([SU_HAVE_WINSOCK], 1, [Define as 1 you have WinSock])
  SAC_SU_DEFINE([SU_HAVE_WINSOCK2], 1, [Define as 1 you have WinSock2])
  AC_DEFINE([HAVE_FILETIME], 1, [
     Define this as 1 if you have WIN32 FILETIME type and 
     GetSystemTimeAsFileTime().])
fi

# Check includes used by su includes
AC_CHECK_HEADER(sys/types.h, 
	SAC_SU_DEFINE([SU_HAVE_SYS_TYPES], 1, 
		     [Define as 1 if Sofia uses sys/types.h]))

ax_inttypes=false
AC_CHECK_HEADER(stdint.h, [
	ax_inttypes=true
	SAC_SU_DEFINE([SU_HAVE_STDINT], 1, 
		     [Define as 1 if Sofia uses stdint.h])])
AC_CHECK_HEADER(inttypes.h,[
	ax_inttypes=true
	SAC_SU_DEFINE([SU_HAVE_INTTYPES], 1, 
		     [Define as 1 if Sofia uses inttypes.h])])

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

Martti Mela's avatar
Martti Mela committed
62
if test "x$MINGW_ENVIRONMENT" != x1 ; then
Martti Mela's avatar
Martti Mela committed
63
  AC_CHECK_HEADER(pthread.h, 
64
        HAVE_PTHREADS=1;
Pekka Pessi's avatar
Pekka Pessi committed
65
	SAC_SU_DEFINE([SU_HAVE_PTHREADS], 1, [Sofia SU uses pthreads]))
Martti Mela's avatar
Martti Mela committed
66 67 68 69 70
else
  AC_DEFINE([HAVE_PTHREAD_H], 1, [Define to 1 if you have the <pthread.h> header file.])
  AC_DEFINE([HAVE_PTHREADS], 1, [Define as 1 you have PTHREADS])
  SAC_SU_DEFINE([SU_HAVE_PTHREADS], 1, [Sofia SU uses pthreads])
fi
Pekka Pessi's avatar
Pekka Pessi committed
71 72

dnl ===========================================================================
Pekka Pessi's avatar
Pekka Pessi committed
73
dnl Checks for typedefs, headers, structures, and compiler characteristics.
Pekka Pessi's avatar
Pekka Pessi committed
74 75 76 77 78 79 80 81
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
82
AC_REQUIRE([AC_C_INLINE])
Pekka Pessi's avatar
Pekka Pessi committed
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104

case "$ac_cv_c_inline" in
  yes) SAC_SU_DEFINE(su_inline, static inline, [
		Define this as declarator for static inline functions.
	])dnl
       SAC_SU_DEFINE(SU_INLINE, inline, [
		Define this as declarator for inline functions.
	])dnl
       SAC_SU_DEFINE(SU_HAVE_INLINE, 1, [
		Define this as 1 if you have inline functions.
	])dnl
  ;;
  no)  SAC_SU_DEFINE(su_inline, static)dnl
       SAC_SU_DEFINE(SU_INLINE)dnl
       SAC_SU_DEFINE(SU_HAVE_INLINE)dnl
  ;;
  *)   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
  ;;
esac

Pekka Pessi's avatar
Pekka Pessi committed
105 106 107 108 109 110 111
AC_REQUIRE([AC_SYS_SA_LEN])
if test "$ac_cv_sa_len" = yes ;then
  SAC_SU_DEFINE([SU_HAVE_SOCKADDR_SA_LEN], 1, 
	        [Define this as 1 if you have sa_len in struct sockaddr])
fi

AC_REQUIRE([AC_STRUCT_SIN6])
Pekka Pessi's avatar
Pekka Pessi committed
112 113
case $ac_cv_sin6 in 
yes) SAC_SU_DEFINE(SU_HAVE_IN6, 1, [
114 115 116
	Define this as 1 if you have struct sockaddr_in6]) ;;
 no) ;;
  *) AC_MSG_ERROR([Inconsistent struct sockaddr_sin6 test]) ;;
Pekka Pessi's avatar
Pekka Pessi committed
117 118
esac

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

Martti Mela's avatar
Martti Mela committed
121 122 123 124 125
AC_CHECK_HEADERS([winsock2.h ws2tcpip.h], [
  SAC_SU_DEFINE([SU_HAVE_WINSOCK], 1, [Define as 1 you have WinSock])
  SAC_SU_DEFINE([SU_HAVE_WINSOCK2], 1, [Define as 1 you have WinSock2])
  SAC_SU_DEFINE(SU_HAVE_SOCKADDR_STORAGE, 1, 
      [Define this as 1 if you have struct sockaddr_storage])
Martti Mela's avatar
Martti Mela committed
126 127 128 129 130 131 132 133
  AC_DEFINE([HAVE_ADDRINFO], 1,
      [Define this as 1 if you have addrinfo structure.])
  AC_DEFINE([HAVE_GETADDRINFO], 1,
      [Define this as 1 if you have addrinfo structure.])
  AC_DEFINE([HAVE_FREEADDRINFO], 1,
      [Define this as 1 if you have addrinfo structure.])
  SAC_SU_DEFINE([SU_HAVE_ADDRINFO], 1,
      [Define this as 1 if you have addrinfo structure.])
Martti Mela's avatar
Martti Mela committed
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
  SAC_SU_DEFINE([SU_HAVE_GETADDRINFO], 1,
      [Define this as 1 if you have getaddrinfo() function.])
  AC_CHECK_HEADERS([windef.h])
  AC_CHECK_HEADERS([iphlpapi.h], [
    AC_DEFINE([HAVE_INTERFACE_INFO_EX], 1, [
       Define this as 1 if you have WIN32 INTERFACE_INFO_EX type.])
    AC_DEFINE([HAVE_SIO_ADDRESS_LIST_QUERY], 1, [
       Define this as 1 if you have WIN32 WSAIoctl SIO_ADDRESS_LIST_QUERY.])
  ], [], [#if HAVE_WINDEF_H
#include <windef.h>
#include <winbase.h>
#endif
  ])
], [
  AC_CHECK_HEADERS([sys/socket.h sys/ioctl.h sys/filio.h sys/sockio.h])
  AC_CHECK_HEADERS([netinet/in.h arpa/inet.h netdb.h net/if.h net/if_types.h], [], [
  SAC_SU_DEFINE([SU_HAVE_BSDSOCK], 1, [Define as 1 if you have BSD socket interface])
151

Pekka Pessi's avatar
Pekka Pessi committed
152 153 154 155 156 157 158 159 160 161 162 163 164 165
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, 
    [Define this as 1 if you have struct sockaddr_storage])
fi

Martti Mela's avatar
Martti Mela committed
166 167 168 169 170 171 172 173
  # Test for getaddrinfo(), getnameinfo(), freeaddrinfo() and gai_strerror()
  AC_CHECK_FUNC([getaddrinfo],[
	  SAC_SU_DEFINE([SU_HAVE_GETADDRINFO], 1, [
  	Define this as 1 if you have getaddrinfo() function.
	  ])])
  ])
])

Pekka Pessi's avatar
Pekka Pessi committed
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
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
AC_TRY_COMPILE([#include <sys/types.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/socket.h>
#include <net/if.h>], [
struct ifreq ifreq; int index; index = ifreq.ifr_index;
], [ac_cv_struct_ifreq_ifr_index=yes])
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
  :
  AC_DEFINE(HAVE_IFR_INDEX, 1, [Define this as 1 if you have ifr_index in <net/if.h>])
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
AC_TRY_COMPILE([#include <sys/types.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/socket.h>
#include <net/if.h>], [
struct ifreq ifreq; int index; index = ifreq.ifr_ifindex;
], ac_cv_struct_ifreq_ifr_ifindex=yes)
else
  ac_cv_struct_ifreq_ifr_ifindex='net/if.h missing'
fi # arpa/inet.h && netdb.h && sys/socket.h && net/if.h
207
])
Pekka Pessi's avatar
Pekka Pessi committed
208 209 210 211 212 213
if test "$ac_cv_struct_ifreq_ifr_ifindex" = yes; then
  :
  AC_DEFINE(HAVE_IFR_IFINDEX, 1, [Define this as 1 if you have ifr_ifindex in <net/if.h>])
fi

fi # ifr_index in struct ifreq
214

Pekka Pessi's avatar
Pekka Pessi committed
215
dnl SIOGCIFCONF & struct ifconf
Pekka Pessi's avatar
Pekka Pessi committed
216 217 218 219 220 221 222 223 224 225 226
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
  AC_DEFINE(HAVE_IFCONF, 1, [Define this as 1 if you have SIOCGIFCONF])
fi
Pekka Pessi's avatar
Pekka Pessi committed
227

Pekka Pessi's avatar
Pekka Pessi committed
228 229 230 231
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
232 233 234 235 236
AC_EGREP_CPP(yes, [
#include <sys/sockio.h>
#ifdef SIOCGIFNUM
  yes
#endif
Pekka Pessi's avatar
Pekka Pessi committed
237 238 239 240 241 242 243 244 245 246 247
], [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
  AC_DEFINE(HAVE_IFNUM, 1, [Define this as 1 if you have SIOCGIFNUM ioctl])
else
  HAVE_IFNUM=0
fi

248 249 250 251
# ===========================================================================
# Checks for libraries
# ===========================================================================

Pekka Pessi's avatar
Pekka Pessi committed
252 253
SAC_CHECK_SU_LIBS

Martti Mela's avatar
Martti Mela committed
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
AC_ARG_WITH(glib-dir,
[  --with-glib-dir=PREFIX  explicitly define GLib path],
  glib_dir="$withval", glib_dir="no")

#check if GLib path is explicitly defined 
if test X$glib_dir != Xno ; then

gprefix=$glib_dir
exec_gprefix=${gprefix}
glibdir=${exec_gprefix}/lib
gincludedir=${gprefix}/include

# glib_genmarshal=glib-genmarshal
# gobject_query=gobject-query
# glib_mkenums=glib-mkenums

# GLIB_LIBS="-L${glibdir} -lglib-2.0 -lintl -liconv"
GLIB_LIBS="-L${glibdir} ${glibdir}/libglib-2.0.dll.a ${glibdir}/libintl.a ${glibdir}/libiconv.a"
GLIB_CFLAGS="-I${gincludedir}/glib-2.0 -I${glibdir}/glib-2.0/include"

# how the hell should I know?
GLIB_VERSION="2.0"

SAC_SU_DEFINE([SU_HAVE_GLIB], 1, [Define as 1 if you have >= glib-2.0])
HAVE_GLIB=yes

AC_SUBST(GLIB_LIBS)
AC_SUBST(GLIB_CFLAGS)

else

# No GLib path explicitly defined, use pkg-config
286 287 288 289 290 291 292
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])

293 294
if test X$with_glib != Xno ; then 

295 296 297 298 299
PKG_CHECK_MODULES(GLIB, glib-$with_glib, [dnl
SAC_SU_DEFINE([SU_HAVE_GLIB], 1, [Define as 1 if you have >= glib-2.0])
HAVE_GLIB=yes
])

Martti Mela's avatar
Martti Mela committed
300
fi
301 302
fi

303 304 305 306 307
AM_CONDITIONAL([HAVE_GLIB], [test "x$HAVE_GLIB" != x])
AC_SUBST(GLIB_LIBS)
AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_VERSION)

Martti Mela's avatar
Martti Mela committed
308

Pekka Pessi's avatar
Pekka Pessi committed
309 310 311 312
# ===========================================================================
# Checks for library functions.
# ===========================================================================

313 314 315
AC_CHECK_FUNCS([gettimeofday strerror random initstate tcsetattr flock alarm])
AC_CHECK_FUNCS([socketpair gethostname getipnodebyname poll epoll])
AC_CHECK_FUNCS([getaddrinfo getnameinfo freeaddrinfo gai_strerror getifaddrs])
Pekka Pessi's avatar
Pekka Pessi committed
316 317

# _GNU_SOURCE stuff
318
AC_CHECK_FUNCS([getline getdelim getpass])
Pekka Pessi's avatar
Pekka Pessi committed
319 320 321 322

AC_REQUIRE([SAC_WITH_RT])

if test "${with_rt}" != no; then
323
    AC_CHECK_FUNCS([clock_gettime clock_getcpuclockid])
Pekka Pessi's avatar
Pekka Pessi committed
324 325
fi

Martti Mela's avatar
Martti Mela committed
326
SAC_REPLACE_FUNCS(memmem memccpy memspn memcspn strcasestr strtoull inet_ntop inet_pton)
Pekka Pessi's avatar
Pekka Pessi committed
327 328 329 330 331 332 333 334 335 336 337

AC_CHECK_FUNC([poll], 
	SAC_SU_DEFINE([SU_HAVE_POLL], 1, [
	Define this as 1 if you have poll() function.
	]))

AC_CHECK_FUNC([if_nameindex], 
	SAC_SU_DEFINE([SU_HAVE_IF_NAMEINDEX], 1, [
	Define this as 1 if you have if_nameindex() function.
	]))

338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
# ===========================================================================
# Check pthread_rwlock_unlock()
# ===========================================================================

AC_DEFUN([AC_DEFINE_HAVE_PTHREAD_RWLOCK],[dnl
AC_DEFINE([HAVE_PTHREAD_RWLOCK], 1,[
Define this as 1 if you have working pthread_rwlock_t implementation.

   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()
{
364
  pthread_rwlock_init(&rw, NULL);
365 366 367
  pthread_rwlock_rdlock(&rw);
  pthread_rwlock_rdlock(&rw);
  pthread_rwlock_unlock(&rw);
368 369
  /* pthread_rwlock_trywrlock() should fail (not return 0) */
  return pthread_rwlock_trywrlock(&rw) != 0 ? 0  : 1;
370 371 372 373 374 375 376
}
],[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
377 378 379 380 381 382 383 384 385 386 387 388
# ===========================================================================
# Check IPv6 addresss configuration
# ===========================================================================
case "$target" in
 *-*-linux*) AC_DEFINE([HAVE_PROC_NET_IF_INET6], 1, 
	[Define this as 1 if you have /proc/net/if_inet6 control file]) ;;
esac

# ===========================================================================
# Check for partial su distibutions
# ===========================================================================

389
if test -r ${srcdir}/libsofia-sip-ua/su/sofia-sip/su_wait.h ; then
Pekka Pessi's avatar
Pekka Pessi committed
390
  AC_DEFINE(HAVE_SU_WAIT_H, 1, 
391
            [Define to 1 if you have the <sofia-sip/su_wait.h> header file.])
Pekka Pessi's avatar
Pekka Pessi committed
392 393
fi

394
AM_CONFIG_HEADER([libsofia-sip-ua/su/sofia-sip/su_configure.h])
Pekka Pessi's avatar
Pekka Pessi committed
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
])

# 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.
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
])
416 417

AC_DEFUN([SAC_REPLACE_FUNCS],[dnl
418
AC_CHECK_FUNCS($1,ifelse([$2], , :, [$2]),[dnl
419 420 421 422 423 424 425 426
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])
427
ifelse([$3], , :, [$3])
428
])