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