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