sac-general.m4 15 KB
Newer Older
Pekka Pessi's avatar
Pekka Pessi committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
dnl =====================================================================
dnl This file contains autoconf macros shared by Sofia modules.
dnl 
dnl Author: Pekka Pessi <Pekka.Pessi@nokia.com>
dnl 
dnl License:
dnl
dnl Copyright (c) 2001,2004 Nokia and others. All Rights Reserved.
dnl
dnl Please note that every macro contained in this file is copyrighted by
dnl its respective author, unless the macro source explicitely says
dnl otherwise. Permission has been granted, though, to use and distribute
dnl all macros under the following license, which is a modified version of
dnl the GNU General Public License version 2:
dnl 
dnl Each Autoconf macro in this file is free software; you can redistribute it
dnl and/or modify it under the terms of the GNU General Public License as
dnl published by the Free Software Foundation; either version 2, or (at your
dnl option) any later version.
dnl 
dnl They are distributed in the hope that they will be useful, but WITHOUT ANY
dnl WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
dnl FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
dnl details. (You should have received a copy of the GNU General Public License
dnl along with this program; if not, write to the Free Software Foundation,
dnl Inc., 59 Temple Place -- Suite 330, Boston, MA 02111-1307, USA.)
dnl 
dnl As a special exception, the Free Software Foundation gives unlimited
dnl permission to copy, distribute and modify the configure scripts that are
dnl the output of Autoconf. You need not follow the terms of the GNU General
dnl Public License when using or distributing such scripts, even though
dnl portions of the text of Autoconf appear in them. The GNU General Public
dnl License (GPL) does govern all other use of the material that constitutes
dnl the Autoconf program.
dnl 
dnl Certain portions of the Autoconf source text are designed to be copied
dnl (in certain cases, depending on the input) into the output of Autoconf. 
dnl We call these the "data" portions. The rest of the Autoconf source text
dnl consists of comments plus executable code that decides which of the data
dnl portions to output in any given case. We call these comments and
dnl executable code the "non-data" portions. Autoconf never copies any of
dnl the non-data portions into its output.
dnl 
dnl This special exception to the GPL applies to versions of Autoconf
dnl released by the Free Software Foundation. When you make and distribute a
dnl modified version of Autoconf, you may extend this special exception to
dnl the GPL to apply to your modified version as well, *unless* your
dnl modified version has the potential to copy into its output some of the
dnl text that was the non-data portion of the version that you started with. 
dnl (In other words, unless your change moves or copies text from the
dnl non-data portions to the data portions.) If your modification has such
dnl potential, you must delete any notice of this special exception to the
dnl GPL from your modified version.
dnl
dnl =====================================================================

AC_DEFUN([SOFIA_M4_ID], [
AC_SUBST([SOFIA_M4_ID], 
59
[$Id: sac-general.m4,v 1.5 2005/10/06 13:37:20 ppessi Exp $])])
Pekka Pessi's avatar
Pekka Pessi committed
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106

dnl ===================================================================
dnl Get host, target and build variables filled with appropriate info,
dnl and check the validity of the cache 
dnl ===================================================================

AC_DEFUN([SAC_CANONICAL_SYSTEM_CACHE_CHECK], [

dnl Get host, target and build variables filled with appropriate info.

AC_CANONICAL_SYSTEM

dnl Check to assure the cached information is valid.

AC_MSG_CHECKING(cached information)
hostcheck="$host"
AC_CACHE_VAL(ac_cv_hostcheck, [ ac_cv_hostcheck="$hostcheck" ])
if test "$ac_cv_hostcheck" != "$hostcheck"; then
  AC_MSG_RESULT(changed)
  AC_MSG_WARN(config.cache exists!)
  AC_MSG_ERROR([you must do 'make distclean' first to compile 
 for different host or different parameters.])
else
  AC_MSG_RESULT(ok)
fi

dnl SOSXXX: AC_PATH_ADJUST

])

dnl ======================================================================
dnl Check if ranlib is needed
dnl ======================================================================
AC_DEFUN([AX_PROG_RANLIB], [
AC_REQUIRE([SAC_CANONICAL_SYSTEM_CACHE_CHECK])
if test -z "$no_ranlib"; then
  AC_CHECK_TOOL([RANLIB], ranlib, ranlib)
else
  AC_SUBST([RANLIB], [":"])
fi
])

dnl ======================================================================
dnl Find C compiler
dnl ======================================================================

AC_DEFUN([AX_TOOL_CC], [
107
AC_REQUIRE([SAC_CANONICAL_SYSTEM_CACHE_CHECK])
Pekka Pessi's avatar
Pekka Pessi committed
108
AC_BEFORE([$0], [AC_PROG_CPP])dnl
109

Pekka Pessi's avatar
Pekka Pessi committed
110 111 112 113 114 115 116 117 118 119
AC_CHECK_TOOL(CC, gcc, gcc)
if test -z "$CC"; then
  AC_CHECK_TOOL(CC, cc, cc, , , /usr/ucb/cc)
  if test -z "$CC"; then
    case "`uname -s`" in
    *win32* | *WIN32* ) AC_CHECK_PROG(CC, cl, cl) ;;
    esac
  fi
  test -z "$CC" && AC_MSG_ERROR([no acceptable cc found in \$PATH])
fi
120

Pekka Pessi's avatar
Pekka Pessi committed
121 122
AC_PROG_CC

123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
#
# Wall
#
AC_CACHE_CHECK([for maximum warnings compiler flag],
  ac_cv_cwflag,
[case "${CC-cc}" in
  *gcc*) ac_cv_cwflag=-Wall;;
  *)	case "$host" in
    *irix*)	ac_cv_cwflag=-fullwarn ;;
    *solaris*)  ac_cv_cwflag="-erroff=%none,E_END_OF_LOOP_CODE_NOT_REACHED -xCC"
	        ;;
    *)		ac_cv_cwflag=;;
		esac 
  ;;
esac])
CFLAGS="$CFLAGS $ac_cv_cwflag"
AC_SUBST([CWFLAG], [$ac_cv_cwflag])

Pekka Pessi's avatar
Pekka Pessi committed
141 142 143 144 145 146
#
# GCoverage
#
AC_ARG_ENABLE(coverage,
[  --enable-coverage       compile test-coverage (disabled)],
 , enable_coverage=no)
147

Pekka Pessi's avatar
Pekka Pessi committed
148 149 150 151 152 153 154 155 156
if test X$enable_coverage != Xno ; then
case "${CC-cc}" in
  *gcc*) 
	CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage" 
	;;
  *) AC_MSG_ERROR([--enable-coverage requires gcc])
esac
fi

157 158
AM_CONDITIONAL([ENABLE_COVERAGE], test X$enable_coverage != Xno)

Pekka Pessi's avatar
Pekka Pessi committed
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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 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 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 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 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
AC_SUBST([MOSTLYCLEANFILES], "*.bb *.bbg *.da *.[hc].gcov")
])

dnl ======================================================================
dnl Check for sockaddr_in6
dnl ======================================================================
AC_DEFUN([AC_STRUCT_SIN6], [
AC_CACHE_CHECK([for sockaddr_in6],
  ac_cv_sin6,
[AC_EGREP_HEADER(struct sockaddr_in6, netinet/in.h, 
  ac_cv_sin6=yes, ac_cv_sin6=no)])
if test $ac_cv_sin6 = yes ;then
	AC_DEFINE([HAVE_SIN6], 1, 
		[Define this as 1 if you have IPv6 structures and constants])
fi
])

dnl ======================================================================
dnl Check for sa_len in struct sockaddr
dnl ======================================================================
AC_DEFUN([AC_SYS_SA_LEN], [
AC_CACHE_CHECK([for sa_len],
  ac_cv_sa_len,
[AC_TRY_COMPILE([#include <sys/types.h>
#include <sys/socket.h>], [int main(void) {
 struct sockaddr t;t.sa_len = 0;}],
  ac_cv_sa_len=yes,ac_cv_sa_len=no)])
if test "$ac_cv_sa_len" = yes ;then
	AC_DEFINE([HAVE_SA_LEN], 1, 
		[Define this as 1 if you have sa_len in struct sockaddr])
fi
])

dnl ======================================================================
dnl Check for MSG_NOSIGNAL flag
dnl ======================================================================
AC_DEFUN([AC_FLAG_MSG_NOSIGNAL], [
AC_REQUIRE([AC_PROG_CC])
AC_CACHE_CHECK([for MSG_NOSIGNAL], 
  ac_cv_flag_msg_nosignal, [
AC_TRY_COMPILE([
#include <sys/types.h>
#include <sys/socket.h>], [
int main() {
  int flags = MSG_NOSIGNAL;
}
], ac_cv_flag_msg_nosignal=yes, ac_cv_flag_msg_nosignal=no)])
if test "$ac_cv_flag_msg_nosignal" = yes ; then
	AC_DEFINE([HAVE_MSG_NOSIGNAL], 1,
		[Define this as 1 if you have MSG_NOSIGNAL flag for send()]) 
fi
])dnl

dnl ======================================================================
dnl Check for MSG_ERRQUEUE flag
dnl ======================================================================
AC_DEFUN([AC_SYS_MSG_ERRQUEUE], [
AC_REQUIRE([AC_PROG_CC])
AC_CACHE_CHECK([for MSG_ERRQUEUE], 
  ac_cv_flag_msg_errqueue, [
AC_TRY_COMPILE([
#include <sys/types.h>
#include <sys/socket.h>], [
int main() {
  int flags = MSG_ERRQUEUE;
}
], ac_cv_flag_msg_errqueue=yes, ac_cv_flag_msg_errqueue=no)])
if test "$ac_cv_flag_msg_errqueue" = yes; then
	AC_DEFINE([HAVE_MSG_ERRQUEUE], 1,
		[Define this as 1 if you have MSG_ERRQUEUE flag for send()]) 
fi
])dnl

dnl ======================================================================
dnl Check for IP_RECVERR option
dnl ======================================================================
AC_DEFUN([AC_SYS_IP_RECVERR], [
AC_REQUIRE([AC_PROG_CC])
AC_CACHE_CHECK([for IP_RECVERR], 
  ac_cv_sys_ip_recverr, [
AC_TRY_COMPILE([
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
], [
  int one = 1;
  int s = 0;
  setsockopt(s, SOL_IP, IP_RECVERR, &one, sizeof(one));
], ac_cv_sys_ip_recverr=yes,
ac_cv_sys_ip_recverr=no)])
if test "$ac_cv_sys_ip_recverr" = yes ; then
	AC_DEFINE([HAVE_IP_RECVERR], 1, 
		[Define this as 1 if you have IP_RECVERR in <netinet/in.h>])
fi
])dnl

dnl ======================================================================
dnl Check for IPV6_RECVERR option
dnl ======================================================================
AC_DEFUN([AC_SYS_IPV6_RECVERR], [
AC_REQUIRE([AC_PROG_CC])
AC_CACHE_CHECK([for IPV6_RECVERR], 
  ac_cv_sys_ipv6_recverr, [
AC_TRY_COMPILE([
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
], [
  int one = 1;
  int s = 0;
  setsockopt(s, SOL_IPV6, IPV6_RECVERR, &one, sizeof(one));
], ac_cv_sys_ipv6_recverr=yes, ac_cv_sys_ipv6_recverr=no)])
if test "$ac_cv_sys_ipv6_recverr" = yes ; then
	AC_DEFINE([HAVE_IPV6_RECVERR], 1,
		[Define this as 1 if you have IPV6_RECVERR in <netinet/in6.h>])
fi
])dnl

dnl ======================================================================
dnl Version of AC_CHECK_HEADER with a list of alternative locations
dnl ======================================================================
dnl AX_CHECK_HEADER_IN(HEADER-FILE, 
dnl         LIST-OF-PATHS, [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
AC_DEFUN([AX_CHECK_HEADER_IN], [
ax_safe=`echo "$1" | sed 'y%./+-%__p_%'`
AC_MSG_CHECKING([for $1])
AC_CACHE_VAL(ax_cv_header_$ax_safe,
   [eval ax_cv_header_$ax_safe="no"
    for ax_path in yes $2
    do
	old_CPPFLAGS="$CPPFLAGS"
       	test "$ax_path" != "yes" && CPPFLAGS="-I$ax_path $CPPFLAGS"
      	AC_TRY_CPP([#include <$1>], 
	 [eval ax_cv_header_$ax_safe="$ax_path";
	  CPPFLAGS="$old_CPPFLAGS";
          break],
	 CPPFLAGS="$old_CPPFLAGS"
	 )
   done
])

if eval "test \"`echo '$ax_cv_header_'$ax_safe`\" != no"; then
   if eval 'test "$ax_cv_header_'$ax_safe'" != "yes"'
   then
     eval ax_path='"$ax_cv_header_'$ax_safe'"'
     CPPFLAGS="-I$ax_path $CPPFLAGS"
   else
     unset ax_path
   fi 
   AC_MSG_RESULT([yes${ax_path+ (in $ax_path)}])
   ifelse([$3], , :, [$3])
else
   AC_MSG_RESULT(no)
   ifelse([$4], , , [$4])dnl
fi
])

dnl AX_CHECK_HEADERS_IN(HEADER-FILE..., 
dnl                 LIST-OF-PATHS [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
AC_DEFUN([AX_CHECK_HEADERS_IN],
[for ax_hdr in $1
do
AX_CHECK_HEADER_IN($ax_hdr, $2,
[ ax_tr_hdr=HAVE_`echo $ax_hdr | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'`
  AC_DEFINE_UNQUOTED($ax_tr_hdr, 1, [Define 1 if you have the <$ax_hdr> header file])
  $3], $4)dnl
done
])

dnl ======================================================================
dnl @synopsis AC_C_VAR_FUNC
dnl
dnl This macro tests if the C compiler supports the C99 standard
dnl __func__ indentifier.
dnl
dnl The new C99 standard for the C language stipulates that the
dnl identifier __func__ shall be implictly declared by the compiler
dnl as if, immediately following the opening brace of each function
dnl definition, the declaration
dnl
dnl     static const char __func__[] = "function-name";
dnl
dnl appeared, where function-name is the name of the function where
dnl the __func__ identifier is used.
dnl
dnl @author Christopher Currie <christopher@currie.com>
dnl @author Pekka Pessi <Pekka.Pessi@nokia.com>
dnl ======================================================================

AC_DEFUN([AC_C_VAR_FUNC],
[AC_REQUIRE([AC_PROG_CC])
AC_CACHE_CHECK(whether $CC recognizes __func__, ac_cv_c_var_func,
AC_TRY_COMPILE(,
[int main() {
char *s = __func__;
}],
ac_cv_c_var_func=yes, ac_cv_c_var_func=no))
if test $ac_cv_c_var_func = "yes"; then
AC_DEFINE([HAVE_FUNC], 1, [Define as 1 if the C compiler supports __func__]) 
fi
])dnl

AC_DEFUN([AC_C_MACRO_FUNCTION],
[AC_REQUIRE([AC_PROG_CC])
AC_CACHE_CHECK(whether $CC recognizes __FUNCTION__, ac_cv_c_macro_function,
AC_TRY_COMPILE(,
[int main() {
char *s = __FUNCTION__;
}], ac_cv_c_macro_function=yes, ac_cv_c_macro_function=no))
if test $ac_cv_c_macro_function = "yes"; then
AC_DEFINE([HAVE_FUNCTION], 1, [Define as 1 if the C compiler supports __FUNCTION__]) 
fi
])dnl

dnl ======================================================================
dnl AC_C_INLINE_DEFINE
dnl ======================================================================
AC_DEFUN([AC_C_INLINE_DEFINE], [
AC_C_INLINE
case "$ac_cv_c_inline" in *inline* | yes) 
	AC_DEFINE([HAVE_INLINE], 1, [Define this as 1 if you have inlining compiler]) ;; 
esac
])

dnl ======================================================================
dnl AC_C_KEYWORD_STRUCT
dnl ======================================================================
AC_DEFUN([AC_C_KEYWORD_STRUCT], [
AC_REQUIRE([AC_PROG_CC])
AC_CACHE_CHECK(whether $CC recognizes field names in struct initialization, ac_cv_c_keyword_struct,
AC_TRY_COMPILE(,
[int main() {
  struct { int foo; char *bar; } test = { foo: 1, bar: "bar" };
  return 0;
}],
ac_cv_c_keyword_struct=yes, ac_cv_c_keyword_struct=no))
if test $ac_cv_c_keyword_struct = "yes"; then
AC_DEFINE([HAVE_STRUCT_KEYWORDS], 1, [
Define this as 1 if your CC supports C99 struct initialization]) 
fi
])

dnl ======================================================================
dnl autoconf-version
dnl should be removed after automake conversion is finished
dnl ======================================================================

AC_DEFUN([AC_AUTOCONF_PARAM], 
[
if autoconf --version | fgrep '2.13' > /dev/null ; then
    AUTOCONF_PARAM="-l"
else
    AUTOCONF_PARAM="-I"
fi
AC_SUBST(AUTOCONF_PARAM)
])

dnl ======================================================================
dnl SAC_ENABLE_NDEBUG
dnl ======================================================================
AC_DEFUN([SAC_ENABLE_NDEBUG],[
AC_ARG_ENABLE(ndebug,
[  --enable-ndebug             compile with NDEBUG (disabled)],
 , enable_ndebug=no)
AM_CONDITIONAL(NDEBUG, test x$enable_ndebug = yes)
])
425

Pekka Pessi's avatar
Pekka Pessi committed
426 427 428 429 430 431 432 433 434 435 436 437 438
dnl ======================================================================
dnl SAC_ENABLE_EXPENSIVE_CHECKS
dnl ======================================================================
AC_DEFUN([SAC_ENABLE_EXPENSIVE_CHECKS],[
AC_ARG_ENABLE(expensive-checks,
[  --enable-expensive-checks   run also expensive checks (disabled)],
 , enable_expensive_checks=no)
if test $enable_expensive_checks != no; then
AC_SUBST([TESTS_ENVIRONMENT], [EXPENSIVE_CHECKS=1])
fi
AM_CONDITIONAL(EXPENSIVE_CHECKS, test x$enable_expensive_checks != no)
])

439 440 441 442 443 444 445 446 447 448
dnl ======================================================================
dnl SAC_GNU_SOURCE 
dnl ======================================================================
AC_DEFUN([SAC_GNU_SOURCE],[
AH_VERBATIM([_GNU_SOURCE],
[/* Enable GNU extensions on systems that have them.  */
#ifndef _GNU_SOURCE
# define _GNU_SOURCE 1
#endif])])