]> err.no Git - sope/blob - libFoundation/aclocal.m4
Drop apache 1 build-dependency
[sope] / libFoundation / aclocal.m4
1 AC_SUBST(MAKE)
2 AC_SUBST(OBJC_RUNTIME)
3 AC_SUBST(OBJC_RUNTIME_FLAG)
4 AC_SUBST(BROKEN_COMPILER)
5 AC_SUBST(BROKEN_BUILTIN_APPLY)
6 AC_SUBST(NO_NESTED_FUNCTIONS)
7 AC_SUBST(PCCTS_CFLAGS)
8 AC_SUBST(HOST)dnl
9 AC_SUBST(HOST_CPU)dnl
10 AC_SUBST(HOST_VENDOR)dnl
11 AC_SUBST(HOST_OS)dnl
12 AC_SUBST(TARGET)dnl
13 AC_SUBST(TARGET_CPU)dnl
14 AC_SUBST(TARGET_VENDOR)dnl
15 AC_SUBST(TARGET_OS)dnl
16 AC_SUBST(STRUCT_ALIGNMENT)dnl
17 dnl
18 dnl
19 AC_DEFUN(AC_LANG_OBJECTIVE_C,
20 [AC_REQUIRE([AC_PROG_CC])dnl
21 define([AC_LANG], [AC_LANG_OBJECTIVE_C])dnl
22 OLD_IFS=$IFS
23 IFS=:
24 for i in $LD_LIBRARY_PATH
25 do
26   LDFLAGS="-L$i $LDFLAGS"
27 done
28 IFS=$OLD_IFS
29 LIBS="-lobjc $LIBS"
30 ac_ext=m
31 # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
32 ac_cpp='$CPP $OBJC_RUNTIME_FLAG'
33 ac_compile='${CC-cc} -c $OBJC_RUNTIME_FLAG $CFLAGS conftest.$ac_ext 1>&AC_FD_CC 2>&AC_FD_CC'
34 ac_link='${CC-cc} -o conftest $OBJC_RUNTIME_FLAG $CFLAGS $LDFLAGS conftest.$ac_ext $LIBS $OBJC_LIBS 1>&AC_FD_CC 2>&AC_FD_CC'
35 ])dnl
36 dnl
37 dnl
38 AC_DEFUN(AC_CHECK_NESTED_FUNCTIONS,
39 [AC_REQUIRE([AC_PROG_CC])dnl
40 AC_MSG_CHECKING(whether nested functions work)
41 AC_CACHE_VAL(ac_cv_nested_functions,
42 [AC_LANG_SAVE[]dnl
43 AC_LANG_OBJECTIVE_C[]
44 AC_TRY_RUN([
45 #include <stdlib.h>
46 f(void (*nested)())
47 {
48     (*nested)();
49 }
50
51 main()
52 {
53     int a = 0;
54     void nested()
55     {
56         a = 1;
57     }
58     f(nested);
59     if(a != 1)
60         exit(1);
61     exit(0);
62 }
63 ], ac_cv_nested_functions=yes, ac_cv_nested_functions=no,
64 ac_cv_nested_functions=yes)
65 AC_LANG_RESTORE[]
66 ])dnl
67 AC_MSG_RESULT(${ac_cv_nested_functions})
68 NO_NESTED_FUNCTIONS=no
69 if test $ac_cv_nested_functions = no; then
70     AC_DEFINE(NO_NESTED_FUNCTIONS)
71     NO_NESTED_FUNCTIONS=yes
72 fi
73 ])dnl
74 dnl
75 dnl
76 AC_DEFUN(AC_BROKEN_COMPILER,
77 [AC_REQUIRE([AC_PROG_CC])dnl
78 AC_MSG_CHECKING(if the Objective-C compiler crashes with nested functions)
79 AC_CACHE_VAL(ac_cv_broken_compiler,
80 [AC_LANG_SAVE[]dnl
81 AC_LANG_OBJECTIVE_C[]
82 AC_TRY_RUN([
83 #include <objc/objc.h>
84 #include <objc/Object.h>
85 #include <stdlib.h>
86
87 void f()
88 {
89     auto void h(id);
90
91     void h(id exception)
92     {
93         [Object alloc];
94         {
95             void clean(void)
96             {
97             }
98         }
99     }
100 }
101
102 void g()
103 {
104     auto void h(id);
105
106     void h(id exception)
107     {
108         [Object alloc];
109     }
110 }
111
112 main()
113 {
114     exit(0);
115 }
116 ], ac_cv_broken_compiler=no,
117 ac_cv_broken_compiler=yes,
118 ac_cv_broken_compiler=no)
119 AC_LANG_RESTORE[]
120 ])dnl
121 BROKEN_COMPILER=${ac_cv_broken_compiler}
122 if test ${ac_cv_nested_functions} = no -o ${ac_cv_broken_compiler} = yes; then
123   ac_cv_broken_compiler=yes;
124   BROKEN_COMPILER=yes;
125   AC_DEFINE(BROKEN_COMPILER)
126 fi
127 AC_MSG_RESULT(${ac_cv_broken_compiler})
128 ])dnl
129 dnl
130 dnl
131 AC_DEFUN(AC_BROKEN_BUILTIN_APPLY,
132 [AC_REQUIRE([AC_PROG_CC])dnl
133 AC_MSG_CHECKING(whether __builtin_apply and __builtin_return are broken)
134 AC_CACHE_VAL(ac_cv_broken_builtin_apply,
135 [AC_LANG_SAVE[]dnl
136 AC_LANG_OBJECTIVE_C[]
137 AC_TRY_RUN([
138 #include <objc/Object.h>
139
140 float value = 123.456;
141
142 @interface MyObject : Object
143 @end
144
145 @implementation MyObject
146 - (float)floatValue
147 {
148     return value;
149 }
150 @end
151
152 @interface Forwarder : Object
153 {
154     id object;
155 }
156 @end
157
158 @implementation Forwarder
159 - setObject:anObject
160 {
161     object = anObject;
162     return self;
163 }
164
165 - (void*)forward:(SEL)selector:(void*)argframe
166 {
167     IMP imp = [object methodFor:@selector(floatValue)];
168     void* retframe;
169     void* frame = malloc(116);
170     *(void**)frame = NULL;
171     retframe = __builtin_apply((void(*)(void))imp, frame, 0);
172     if(*(long double*)(((char*)retframe) + 8) == (long double)value)
173         exit(0);
174     exit(1);
175 }
176 @end
177
178 int main()
179 {
180     id fwd = [[[Forwarder alloc] init] setObject:[MyObject alloc]];
181     [fwd floatValue];
182     exit(0);
183     return 0; // keep compiler happy
184 }
185 ], ac_cv_broken_builtin_apply=no,
186 ac_cv_broken_builtin_apply=yes,
187 ac_cv_broken_builtin_apply=no)
188 AC_LANG_RESTORE[]
189 ])dnl
190 AC_MSG_RESULT(${ac_cv_broken_builtin_apply})
191 BROKEN_BUILTIN_APPLY=${ac_cv_broken_builtin_apply}
192 if test $BROKEN_BUILTIN_APPLY = yes; then
193     AC_DEFINE(BROKEN_BUILTIN_APPLY)
194 fi
195 ])dnl
196 dnl
197 dnl
198 AC_DEFUN(AC_CHECK_MATH_LIB,
199 [AC_REQUIRE([AC_PROG_CC])dnl
200 dnl temporary rename AC_MSG_RESULT to do nothing
201 define(old_AC_MSG_RESULT, defn([AC_MSG_RESULT]))dnl
202 define([AC_MSG_RESULT],)dnl
203 AC_CHECK_FUNC(sqrt, ,
204 [dnl On linux, to link a program that use math functions we must link with libm.a
205 LIBS="$LIBS -lm -lc"
206 ac_cv_func_sqrt=no
207 AC_TRY_LINK(, [
208 double sqrt(double);
209 sqrt(2.0);
210 ], ac_cv_func_sqrt="-lm -lc")
211 ])
212 define([AC_MSG_RESULT], defn([old_AC_MSG_RESULT]))dnl
213 undefine([old_AC_MSG_RESULT])dnl
214 AC_MSG_RESULT($ac_cv_func_sqrt)
215 ])dnl
216 dnl
217 dnl
218 AC_DEFUN(AC_STRUCT_ALIGNMENT,
219 [AC_REQUIRE([AC_PROG_CC])dnl
220 AC_MSG_CHECKING(for the C structures alignment)
221 AC_CACHE_VAL(ac_cv_struct_alignment,
222 [AC_TRY_RUN([#include <stdio.h>
223
224 struct simple {
225     double x;
226     char y;
227 } simple1;
228
229 int struct_alignment = __alignof__ (simple1);
230
231 main()
232 {
233   FILE *f=fopen("conftestval", "w");
234   if (!f) exit(1);
235   fprintf(f, "%u\n", struct_alignment);
236   exit(0);
237 }
238 ], ac_cv_struct_alignment=`cat conftestval`,
239 ac_cv_struct_alignment=0,
240 ifelse([$2], , , ac_cv_struct_alignment=$2))])dnl
241 AC_MSG_RESULT($ac_cv_struct_alignment)
242 STRUCT_ALIGNMENT=$ac_cv_struct_alignment
243 ])dnl
244 dnl
245 dnl
246 AC_DEFUN(AC_COMPILE_CHECK_SIZEOF,
247 [changequote(<<, >>)dnl 
248 dnl The name to #define. 
249 define(<<AC_TYPE_NAME>>, translit(sizeof_$1, [a-z *], [A-Z_P]))dnl 
250 dnl The cache variable name. 
251 define(<<AC_CV_NAME>>, translit(ac_cv_sizeof_$1, [ *], [_p]))dnl 
252 changequote([, ])dnl 
253 AC_MSG_CHECKING(size of $1) 
254 AC_CACHE_VAL(AC_CV_NAME, 
255 [for ac_size in 4 8 1 2 16 $2 ; do # List sizes in rough order of prevalence. 
256   AC_TRY_COMPILE([#include "confdefs.h" 
257 #include <sys/types.h> 
258 $2 
259 ], [switch (0) case 0: case (sizeof ($1) == $ac_size):;], AC_CV_NAME=$ac_size) 
260   if test x$AC_CV_NAME != x ; then break; fi 
261 done 
262 ]) 
263 if test x$AC_CV_NAME = x ; then 
264   echo "cannot determine a size for $1";
265   AC_CV_NAME=0; 
266 fi 
267 AC_MSG_RESULT($AC_CV_NAME) 
268 AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME, [The number of bytes in type $1]) 
269 undefine([AC_TYPE_NAME])dnl 
270 undefine([AC_CV_NAME])dnl 
271 ])