Search
lxdream.org :: lxdream/acinclude.m4
lxdream 0.9.1
released Jun 29
Download Now
filename acinclude.m4
changeset 1212:d1117828f011
prev1211:eecdeb37934a
author nkeynes
date Sun Feb 12 16:30:26 2012 +1000 (7 years ago)
permissions -rw-r--r--
last change Add -Werror for mregparm check, so it actually fails if mregparm isn't
accepted
file annotate diff log raw
nkeynes@923
     1
# AC_CHECK_FASTCALL([if-ok],[if-notok])
nkeynes@923
     2
# Test if the compiler recognizes __attribute__((regparm(3))) - we don't 
nkeynes@923
     3
# currently check if it actually works correctly, but probably should...
nkeynes@923
     4
# -----------------------
nkeynes@923
     5
AC_DEFUN([AC_CHECK_FASTCALL], [
nkeynes@923
     6
AC_MSG_CHECKING([support for fastcall calling conventions]);
nkeynes@1212
     7
save_CFLAGS="$CFLAGS"
nkeynes@1212
     8
CFLAGS="-Werror $save_CFLAGS"
nkeynes@923
     9
AC_RUN_IFELSE([
nkeynes@923
    10
  AC_LANG_SOURCE([[
nkeynes@923
    11
int __attribute__((regparm(3))) foo(int a, int b) { return a+b; }
nkeynes@923
    12
nkeynes@923
    13
int main(int argc, char *argv[])
nkeynes@923
    14
{
nkeynes@923
    15
   return foo( 1, 2 ) == 3 ? 0 : 1;
nkeynes@923
    16
}]])], [ 
nkeynes@923
    17
   AC_MSG_RESULT([yes])
nkeynes@923
    18
   $1 ], [ 
nkeynes@923
    19
   AC_MSG_RESULT([no])
nkeynes@1199
    20
   $2 ], [
nkeynes@1199
    21
      AC_MSG_RESULT([no])
nkeynes@923
    22
   $2 ])
nkeynes@1212
    23
CFLAGS="$save_CFLAGS"
nkeynes@923
    24
])
nkeynes@923
    25
nkeynes@1147
    26
# AC_CHECK_FORCEINLINE([if-ok],[if-notok])
nkeynes@1147
    27
# Test if the compiler recognizes __attribute__((always_inline))
nkeynes@1147
    28
# -----------------------
nkeynes@1147
    29
AC_DEFUN([AC_CHECK_FORCEINLINE], [
nkeynes@1147
    30
AC_MSG_CHECKING([support for force inlining]);
nkeynes@1147
    31
AC_COMPILE_IFELSE([
nkeynes@1147
    32
  AC_LANG_SOURCE([[
nkeynes@1147
    33
static int __attribute__((always_inline)) foo(int a, int b) { return a+b; }
nkeynes@1147
    34
nkeynes@1147
    35
int main(int argc, char *argv[])
nkeynes@1147
    36
{
nkeynes@1147
    37
   return foo( 1, 2 ) == 3 ? 0 : 1;
nkeynes@1147
    38
}]])], [ 
nkeynes@1147
    39
   FORCEINLINE="__attribute__((always_inline))"
nkeynes@1147
    40
   AC_MSG_RESULT([$FORCEINLINE])
nkeynes@1147
    41
   $1 ], [ 
nkeynes@1147
    42
   FORCEINLINE=""
nkeynes@1147
    43
   AC_MSG_RESULT([no])
nkeynes@1147
    44
   $2 ])
nkeynes@1147
    45
])
nkeynes@1147
    46
nkeynes@927
    47
# AC_CHECK_FRAME_ADDRESS([if-ok],[if-notok])
nkeynes@927
    48
# Test if the compiler will let us modify the return address on the stack
nkeynes@927
    49
# via __builtin_frame_address()
nkeynes@927
    50
# -----------------------
nkeynes@927
    51
AC_DEFUN([AC_CHECK_FRAME_ADDRESS], [
nkeynes@927
    52
AC_MSG_CHECKING([if we have a working __builtin_frame_address()]);
nkeynes@927
    53
AC_RUN_IFELSE([
nkeynes@927
    54
  AC_LANG_SOURCE([[
nkeynes@927
    55
void * __attribute__((noinline)) first_arg( void *x, void *y ) { return x; }
nkeynes@927
    56
int __attribute__((noinline)) foo( int arg, void *exc )
nkeynes@927
    57
{
nkeynes@927
    58
    if( arg < 2 ) {
nkeynes@1198
    59
        *(((void * volatile *)__builtin_frame_address(0))+1) = exc;
nkeynes@927
    60
    }
nkeynes@927
    61
    return 0;
nkeynes@927
    62
}
nkeynes@927
    63
nkeynes@927
    64
int main(int argc, char *argv[])
nkeynes@927
    65
{
nkeynes@927
    66
   goto *first_arg(&&start, &&except);
nkeynes@927
    67
   
nkeynes@927
    68
start:
nkeynes@927
    69
   return foo( argc, &&except ) + 1;
nkeynes@927
    70
nkeynes@927
    71
except:
nkeynes@927
    72
   return 0;
nkeynes@927
    73
}]])], [ 
nkeynes@927
    74
   AC_MSG_RESULT([yes])
nkeynes@927
    75
   $1 ], [ 
nkeynes@927
    76
   AC_MSG_RESULT([no])
nkeynes@1199
    77
   $2 ], [
nkeynes@1199
    78
   AC_MSG_RESULT([no])
nkeynes@1199
    79
   $2 ] )
nkeynes@927
    80
])
nkeynes@927
    81
nkeynes@964
    82
# AC_CC_VERSION([if-gcc], [if-icc],[if-other])
nkeynes@964
    83
# Check which C compiler we're using and branch accordingly, eg to set
nkeynes@964
    84
# different optimization flags. Currently recognizes gcc and icc
nkeynes@964
    85
# ---------------
nkeynes@964
    86
AC_DEFUN([AC_CC_VERSION], [
nkeynes@985
    87
_GCC_VERSION=`$CC --version | $SED -ne '/gcc/p'`
nkeynes@964
    88
_ICC_VERSION=`$CC --version | $SED -ne '/(ICC)/p'`
nkeynes@964
    89
AC_MSG_CHECKING([CC version])
nkeynes@985
    90
if test -n "$_ICC_VERSION"; then
nkeynes@985
    91
   AC_MSG_RESULT([ICC])
nkeynes@985
    92
   [ $2 ]
nkeynes@985
    93
elif test -n "$_GCC_VERSION"; then
nkeynes@964
    94
   AC_MSG_RESULT([GCC])
nkeynes@985
    95
   [ $1 ] 
nkeynes@964
    96
else 
nkeynes@964
    97
   AC_MSG_RESULT([Unknown])
nkeynes@964
    98
   [ $3 ]
nkeynes@964
    99
fi
nkeynes@964
   100
]);
nkeynes@927
   101
nkeynes@964
   102
# AC_OBJC_VERSION([if-gcc],[if-other], [if-none])
nkeynes@964
   103
# Check which objective C compiler we're using and branch accordingly.
nkeynes@964
   104
AC_DEFUN([AC_OBJC_VERSION], [
nkeynes@964
   105
AC_MSG_CHECKING([OBJC version])
nkeynes@964
   106
if test -n "$OBJC"; then
nkeynes@964
   107
  _GOBJC_VERSION=`$OBJC --version | $SED -ne '/(GCC)/p'`
nkeynes@964
   108
  if test -n "$_GOBJC_VERSION"; then
nkeynes@964
   109
    AC_MSG_RESULT([GCC])
nkeynes@964
   110
    [ $1 ]
nkeynes@964
   111
  else 
nkeynes@964
   112
    AC_MSG_RESULT([Unknown])
nkeynes@964
   113
    [ $2 ]
nkeynes@964
   114
  fi
nkeynes@964
   115
else
nkeynes@964
   116
  AC_MSG_RESULT([None])
nkeynes@964
   117
  [ $3 ]
nkeynes@964
   118
fi
nkeynes@964
   119
]);
nkeynes@977
   120
nkeynes@1199
   121
# Check if the given C compiler flag is supported, and if so add it to CFLAGS
nkeynes@1199
   122
AC_DEFUN([AC_CHECK_CFLAG], [
nkeynes@1199
   123
AC_LANG_PUSH([C])
nkeynes@1199
   124
AC_MSG_CHECKING([if $CC supports $1])
nkeynes@1199
   125
save_CFLAGS="$CFLAGS"
nkeynes@1199
   126
CFLAGS="$1 $CFLAGS"
nkeynes@1199
   127
AC_COMPILE_IFELSE([
nkeynes@1199
   128
  AC_LANG_SOURCE([int main() { return 0; }])], [
nkeynes@1199
   129
   AC_MSG_RESULT([yes])
nkeynes@1199
   130
   $2 ], [ 
nkeynes@1199
   131
   CFLAGS="$save_CFLAGS"
nkeynes@1199
   132
   AC_MSG_RESULT([no])
nkeynes@1199
   133
   $3 ])
nkeynes@1199
   134
AC_LANG_POP([C])
nkeynes@1199
   135
])
nkeynes@1199
   136
nkeynes@1199
   137
# Check if the given OBJC compiler flag is supported, and if so add it to OBJCFLAGS
nkeynes@1199
   138
AC_DEFUN([AC_CHECK_OBJCFLAG], [
nkeynes@1199
   139
AC_LANG_PUSH([Objective C])
nkeynes@1199
   140
AC_MSG_CHECKING([if $OBJC supports $1])
nkeynes@1199
   141
save_OBJCFLAGS="$OBJCFLAGS"
nkeynes@1199
   142
OBJCFLAGS="$1 $OBJCFLAGS"
nkeynes@1199
   143
AC_COMPILE_IFELSE([
nkeynes@1199
   144
  AC_LANG_SOURCE([int main() { return 0; }])], [
nkeynes@1199
   145
   AC_MSG_RESULT([yes])
nkeynes@1199
   146
   $2 ], [ 
nkeynes@1199
   147
   OBJCFLAGS="$save_OBJCFLAGS"
nkeynes@1199
   148
   AC_MSG_RESULT([no])
nkeynes@1199
   149
   $3 ])
nkeynes@1199
   150
AC_LANG_POP([Objective C])
nkeynes@1199
   151
])
nkeynes@1199
   152
nkeynes@1199
   153
nkeynes@1199
   154
nkeynes@977
   155
# AC_HAVE_OBJC([if-present],[if-not-present])
nkeynes@977
   156
# Check if we have a working Objective-C compiler
nkeynes@977
   157
AC_DEFUN([AC_HAVE_OBJC], [
nkeynes@977
   158
AC_PROG_OBJC
nkeynes@977
   159
AC_MSG_CHECKING([for a working Objective-C compiler])
nkeynes@977
   160
AC_LANG_PUSH([Objective C])dnl
nkeynes@977
   161
_AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@interface Foo @end]], [])],
nkeynes@977
   162
   [AC_MSG_RESULT([yes])
nkeynes@977
   163
    $1 ],
nkeynes@977
   164
   [AC_MSG_RESULT([No])
nkeynes@977
   165
    $2 ]);
nkeynes@977
   166
AC_LANG_POP([Objective C])
nkeynes@977
   167
]);
.