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