Search
lxdream.org :: lxdream/acinclude.m4
lxdream 0.9.1
released Jun 29
Download Now
filename acinclude.m4
changeset 1200:3b2097efa97d
prev1199:62d0a21fac1c
next1211:eecdeb37934a
author nkeynes
date Wed Dec 21 17:13:08 2011 +1000 (8 years ago)
permissions -rw-r--r--
last change Setup configure to detect/manage 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
]);
nkeynes@1200
   165
nkeynes@1200
   166
nkeynes@1200
   167
nkeynes@1200
   168
AC_DEFUN([AC_PROG_CC_FOR_BUILD], [dnl
nkeynes@1200
   169
AC_REQUIRE([AC_PROG_CC])dnl
nkeynes@1200
   170
AC_REQUIRE([AC_PROG_CPP])dnl
nkeynes@1200
   171
AC_REQUIRE([AC_EXEEXT])dnl
nkeynes@1200
   172
AC_REQUIRE([AC_CANONICAL_HOST])dnl
nkeynes@1200
   173
dnl
nkeynes@1200
   174
ac_main_cc="$CC"
nkeynes@1200
   175
test -n "$build_alias" && ac_build_tool_prefix=$build_alias-
nkeynes@1200
   176
nkeynes@1200
   177
pushdef([cross_compiling], [#])dnl
nkeynes@1200
   178
dnl If main compiler works and CC_FOR_BUILD is unset, use the main compiler
nkeynes@1200
   179
if test -z "$CC_FOR_BUILD"; then
nkeynes@1200
   180
    AC_RUN_IFELSE([int main(){return 0;}], [CC_FOR_BUILD="$CC"], [],[])
nkeynes@1200
   181
fi
nkeynes@1200
   182
dnl Use the standard macros, but make them use other variable names
nkeynes@1200
   183
dnl
nkeynes@1200
   184
pushdef([ac_cv_prog_CPP], ac_cv_build_prog_CPP)dnl
nkeynes@1200
   185
pushdef([ac_cv_prog_gcc], ac_cv_build_prog_gcc)dnl
nkeynes@1200
   186
pushdef([ac_cv_prog_cc_works], ac_cv_build_prog_cc_works)dnl
nkeynes@1200
   187
pushdef([ac_cv_prog_cc_cross], ac_cv_build_prog_cc_cross)dnl
nkeynes@1200
   188
pushdef([ac_cv_prog_cc_g], ac_cv_build_prog_cc_g)dnl
nkeynes@1200
   189
pushdef([ac_cv_exeext], ac_cv_build_exeext)dnl
nkeynes@1200
   190
pushdef([ac_cv_objext], ac_cv_build_objext)dnl
nkeynes@1200
   191
pushdef([ac_exeext], ac_build_exeext)dnl
nkeynes@1200
   192
pushdef([ac_objext], ac_build_objext)dnl
nkeynes@1200
   193
pushdef([CC], CC_FOR_BUILD)dnl
nkeynes@1200
   194
pushdef([CPP], CPP_FOR_BUILD)dnl
nkeynes@1200
   195
pushdef([CFLAGS], CFLAGS_FOR_BUILD)dnl
nkeynes@1200
   196
pushdef([CPPFLAGS], CPPFLAGS_FOR_BUILD)dnl
nkeynes@1200
   197
pushdef([host], build)dnl
nkeynes@1200
   198
pushdef([host_alias], build_alias)dnl
nkeynes@1200
   199
pushdef([host_cpu], build_cpu)dnl
nkeynes@1200
   200
pushdef([host_vendor], build_vendor)dnl
nkeynes@1200
   201
pushdef([host_os], build_os)dnl
nkeynes@1200
   202
pushdef([ac_tool_prefix], ac_build_tool_prefix)dnl
nkeynes@1200
   203
pushdef([ac_cv_host], ac_cv_build)dnl
nkeynes@1200
   204
pushdef([ac_cv_host_alias], ac_cv_build_alias)dnl
nkeynes@1200
   205
pushdef([ac_cv_host_cpu], ac_cv_build_cpu)dnl
nkeynes@1200
   206
pushdef([ac_cv_host_vendor], ac_cv_build_vendor)dnl
nkeynes@1200
   207
pushdef([ac_cv_host_os], ac_cv_build_os)dnl
nkeynes@1200
   208
pushdef([ac_cpp], ac_build_cpp)dnl
nkeynes@1200
   209
pushdef([ac_compile], ac_build_compile)dnl
nkeynes@1200
   210
pushdef([ac_link], ac_build_link)dnl
nkeynes@1200
   211
nkeynes@1200
   212
AC_PROG_CC
nkeynes@1200
   213
AC_PROG_CPP
nkeynes@1200
   214
AC_EXEEXT
nkeynes@1200
   215
nkeynes@1200
   216
dnl Restore the old definitions
nkeynes@1200
   217
dnl
nkeynes@1200
   218
popdef([ac_link])dnl
nkeynes@1200
   219
popdef([ac_compile])dnl
nkeynes@1200
   220
popdef([ac_cpp])dnl
nkeynes@1200
   221
popdef([ac_cv_host_os])dnl
nkeynes@1200
   222
popdef([ac_cv_host_vendor])dnl
nkeynes@1200
   223
popdef([ac_cv_host_cpu])dnl
nkeynes@1200
   224
popdef([ac_cv_host_alias])dnl
nkeynes@1200
   225
popdef([ac_cv_host])dnl
nkeynes@1200
   226
popdef([ac_tool_prefix])dnl
nkeynes@1200
   227
popdef([host_os])dnl
nkeynes@1200
   228
popdef([host_vendor])dnl
nkeynes@1200
   229
popdef([host_cpu])dnl
nkeynes@1200
   230
popdef([host_alias])dnl
nkeynes@1200
   231
popdef([host])dnl
nkeynes@1200
   232
popdef([CPPFLAGS])dnl
nkeynes@1200
   233
popdef([CFLAGS])dnl
nkeynes@1200
   234
popdef([CPP])dnl
nkeynes@1200
   235
popdef([CC])dnl
nkeynes@1200
   236
popdef([ac_objext])dnl
nkeynes@1200
   237
popdef([ac_exeext])dnl
nkeynes@1200
   238
popdef([ac_cv_objext])dnl
nkeynes@1200
   239
popdef([ac_cv_exeext])dnl
nkeynes@1200
   240
popdef([ac_cv_prog_cc_g])dnl
nkeynes@1200
   241
popdef([ac_cv_prog_cc_works])dnl
nkeynes@1200
   242
popdef([ac_cv_prog_cc_cross])dnl
nkeynes@1200
   243
popdef([ac_cv_prog_gcc])dnl
nkeynes@1200
   244
popdef([ac_cv_prog_CPP])dnl
nkeynes@1200
   245
popdef([cross_compiling])dnl
nkeynes@1200
   246
nkeynes@1200
   247
dnl Finally, set Makefile variables
nkeynes@1200
   248
dnl
nkeynes@1200
   249
BUILD_EXEEXT=$ac_build_exeext
nkeynes@1200
   250
BUILD_OBJEXT=$ac_build_objext
nkeynes@1200
   251
AC_SUBST(BUILD_EXEEXT)dnl
nkeynes@1200
   252
AC_SUBST(BUILD_OBJEXT)dnl
nkeynes@1200
   253
AC_SUBST([CFLAGS_FOR_BUILD])dnl
nkeynes@1200
   254
AC_SUBST([CPPFLAGS_FOR_BUILD])dnl
nkeynes@1200
   255
])
.