Fix detection of free/openbsd. From Alexis Ballier.
[platform/upstream/libffi.git] / configure.ac
1 dnl Process this with autoconf to create configure
2
3 AC_PREREQ(2.59)
4
5 AC_INIT([libffi], [3.0.9rc1], [http://gcc.gnu.org/bugs.html])
6 AC_CONFIG_HEADERS([fficonfig.h])
7
8 AC_CANONICAL_SYSTEM
9 target_alias=${target_alias-$host_alias}
10
11 . ${srcdir}/configure.host
12
13 AM_INIT_AUTOMAKE
14
15 # The same as in boehm-gc and libstdc++. Have to borrow it from there.
16 # We must force CC to /not/ be precious variables; otherwise
17 # the wrong, non-multilib-adjusted value will be used in multilibs.
18 # As a side effect, we have to subst CFLAGS ourselves.
19
20 m4_rename([_AC_ARG_VAR_PRECIOUS],[real_PRECIOUS])
21 m4_define([_AC_ARG_VAR_PRECIOUS],[])
22 AC_PROG_CC
23 m4_rename([real_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
24
25 AC_SUBST(CFLAGS)
26
27 AM_PROG_AS
28 AM_PROG_CC_C_O
29 AC_PROG_LIBTOOL
30
31 AM_MAINTAINER_MODE
32
33 AC_CHECK_HEADERS(sys/mman.h)
34 AC_CHECK_FUNCS(mmap)
35 AC_FUNC_MMAP_BLACKLIST
36
37 dnl The -no-testsuite modules omit the test subdir.
38 AM_CONDITIONAL(TESTSUBDIR, test -d $srcdir/testsuite)
39
40 TARGETDIR="unknown"
41 case "$host" in
42   alpha*-*-*)
43         TARGET=ALPHA; TARGETDIR=alpha;
44         # Support 128-bit long double, changable via command-line switch.
45         HAVE_LONG_DOUBLE='defined(__LONG_DOUBLE_128__)'
46         ;;
47
48   arm*-*-*)
49         TARGET=ARM; TARGETDIR=arm
50         ;;
51
52   avr32-*-*)
53         TARGET=AVR32; TARGETDIR=avr32
54         ;;
55
56   amd64-*-freebsd*)
57         TARGET=X86_64; TARGETDIR=x86
58         ;;
59
60   amd64-*-freebsd*)
61         TARGET=X86_64; TARGETDIR=x86
62         ;;
63
64   cris-*-*)
65         TARGET=LIBFFI_CRIS; TARGETDIR=cris
66         ;;
67
68   frv-*-*)
69         TARGET=FRV; TARGETDIR=frv
70         ;;
71
72   hppa*-*-linux* | parisc*-*-linux*)
73         TARGET=PA_LINUX; TARGETDIR=pa
74         ;;
75   hppa*64-*-hpux*)
76         TARGET=PA64_HPUX; TARGETDIR=pa
77         ;;
78   hppa*-*-hpux*)
79         TARGET=PA_HPUX; TARGETDIR=pa
80         ;;
81
82   i?86-*-freebsd* | i?86-*-openbsd*)
83         TARGET=X86_FREEBSD; TARGETDIR=x86
84         ;;
85   i?86-win32* | i?86-*-cygwin* | i?86-*-mingw*)
86         TARGET=X86_WIN32; TARGETDIR=x86
87         ;;
88   i?86-*-darwin*)
89         TARGET=X86_DARWIN; TARGETDIR=x86
90         ;;
91   i?86-*-solaris2.1[[0-9]]*)
92         TARGET=X86_64; TARGETDIR=x86
93         ;;
94   i?86-*-*)
95         TARGET=X86; TARGETDIR=x86
96         ;;
97
98   ia64*-*-*)
99         TARGET=IA64; TARGETDIR=ia64
100         ;;
101
102   m32r*-*-*)
103         TARGET=M32R; TARGETDIR=m32r
104         ;;
105
106   m68k-*-*)
107         TARGET=M68K; TARGETDIR=m68k
108         ;;
109
110   mips-sgi-irix5.* | mips-sgi-irix6.*)
111         TARGET=MIPS; TARGETDIR=mips
112         ;;
113   mips*-*-linux*)
114         TARGET=MIPS; TARGETDIR=mips
115         ;;
116
117   powerpc*-*-linux* | powerpc-*-sysv*)
118         TARGET=POWERPC; TARGETDIR=powerpc
119         ;;
120   powerpc-*-beos*)
121         TARGET=POWERPC; TARGETDIR=powerpc
122         ;;
123   powerpc-*-darwin*)
124         TARGET=POWERPC_DARWIN; TARGETDIR=powerpc
125         ;;
126   powerpc-*-aix* | rs6000-*-aix*)
127         TARGET=POWERPC_AIX; TARGETDIR=powerpc
128         ;;
129   powerpc-*-freebsd*)
130         TARGET=POWERPC_FREEBSD; TARGETDIR=powerpc
131         ;;
132   powerpc*-*-rtems*)
133         TARGET=POWERPC; TARGETDIR=powerpc
134         ;;
135
136   s390-*-* | s390x-*-*)
137         TARGET=S390; TARGETDIR=s390
138         ;;
139
140   sh-*-* | sh[[34]]*-*-*)
141         TARGET=SH; TARGETDIR=sh
142         ;;
143   sh64-*-* | sh5*-*-*)
144         TARGET=SH64; TARGETDIR=sh64
145         ;;
146
147   sparc*-*-*)
148         TARGET=SPARC; TARGETDIR=sparc
149         ;;
150
151   x86_64-*-darwin*)
152         TARGET=X86_DARWIN; TARGETDIR=x86
153         ;;
154
155   x86_64-*-cygwin* | x86_64-*-mingw*)
156         TARGET=X86_WIN64; TARGETDIR=x86
157         ;;
158
159   x86_64-*-*)
160         TARGET=X86_64; TARGETDIR=x86
161         ;;
162 esac
163
164 AC_SUBST(AM_RUNTESTFLAGS)
165
166 if test $TARGETDIR = unknown; then
167   AC_MSG_ERROR(["libffi has not been ported to $host."])
168 fi
169
170 AM_CONDITIONAL(MIPS, test x$TARGET = xMIPS)
171 AM_CONDITIONAL(SPARC, test x$TARGET = xSPARC)
172 AM_CONDITIONAL(X86, test x$TARGET = xX86)
173 AM_CONDITIONAL(X86_FREEBSD, test x$TARGET = xX86_FREEBSD)
174 AM_CONDITIONAL(X86_WIN32, test x$TARGET = xX86_WIN32)
175 AM_CONDITIONAL(X86_WIN64, test x$TARGET = xX86_WIN64)
176 AM_CONDITIONAL(X86_DARWIN, test x$TARGET = xX86_DARWIN)
177 AM_CONDITIONAL(ALPHA, test x$TARGET = xALPHA)
178 AM_CONDITIONAL(IA64, test x$TARGET = xIA64)
179 AM_CONDITIONAL(M32R, test x$TARGET = xM32R)
180 AM_CONDITIONAL(M68K, test x$TARGET = xM68K)
181 AM_CONDITIONAL(POWERPC, test x$TARGET = xPOWERPC)
182 AM_CONDITIONAL(POWERPC_AIX, test x$TARGET = xPOWERPC_AIX)
183 AM_CONDITIONAL(POWERPC_DARWIN, test x$TARGET = xPOWERPC_DARWIN)
184 AM_CONDITIONAL(POWERPC_FREEBSD, test x$TARGET = xPOWERPC_FREEBSD)
185 AM_CONDITIONAL(ARM, test x$TARGET = xARM)
186 AM_CONDITIONAL(AVR32, test x$TARGET = xAVR32)
187 AM_CONDITIONAL(LIBFFI_CRIS, test x$TARGET = xLIBFFI_CRIS)
188 AM_CONDITIONAL(FRV, test x$TARGET = xFRV)
189 AM_CONDITIONAL(S390, test x$TARGET = xS390)
190 AM_CONDITIONAL(X86_64, test x$TARGET = xX86_64)
191 AM_CONDITIONAL(SH, test x$TARGET = xSH)
192 AM_CONDITIONAL(SH64, test x$TARGET = xSH64)
193 AM_CONDITIONAL(PA_LINUX, test x$TARGET = xPA_LINUX)
194 AM_CONDITIONAL(PA_HPUX, test x$TARGET = xPA_HPUX)
195 AM_CONDITIONAL(PA64_HPUX, test x$TARGET = xPA64_HPUX)
196
197 AC_HEADER_STDC
198 AC_CHECK_FUNCS(memcpy)
199 AC_FUNC_ALLOCA
200
201 AC_CHECK_SIZEOF(double)
202 AC_CHECK_SIZEOF(long double)
203
204 # Also AC_SUBST this variable for ffi.h.
205 if test -z "$HAVE_LONG_DOUBLE"; then
206   HAVE_LONG_DOUBLE=0
207   if test $ac_cv_sizeof_double != $ac_cv_sizeof_long_double; then
208     if test $ac_cv_sizeof_long_double != 0; then
209       HAVE_LONG_DOUBLE=1
210       AC_DEFINE(HAVE_LONG_DOUBLE, 1, [Define if you have the long double type and it is bigger than a double])
211     fi
212   fi
213 fi
214 AC_SUBST(HAVE_LONG_DOUBLE)
215
216 AC_C_BIGENDIAN
217
218 AC_CACHE_CHECK([assembler .cfi pseudo-op support],
219     libffi_cv_as_cfi_pseudo_op, [
220     libffi_cv_as_cfi_pseudo_op=unknown
221     AC_TRY_COMPILE([asm (".cfi_startproc\n\t.cfi_endproc");],,
222                    [libffi_cv_as_cfi_pseudo_op=yes],
223                    [libffi_cv_as_cfi_pseudo_op=no])
224 ])
225 if test "x$libffi_cv_as_cfi_pseudo_op" = xyes; then
226     AC_DEFINE(HAVE_AS_CFI_PSEUDO_OP, 1,
227               [Define if your assembler supports .cfi_* directives.])
228 fi
229
230 if test x$TARGET = xSPARC; then
231     AC_CACHE_CHECK([assembler and linker support unaligned pc related relocs],
232         libffi_cv_as_sparc_ua_pcrel, [
233         save_CFLAGS="$CFLAGS"
234         save_LDFLAGS="$LDFLAGS"
235         CFLAGS="$CFLAGS -fpic"
236         LDFLAGS="$LDFLAGS -shared"
237         AC_TRY_LINK([asm (".text; foo: nop; .data; .align 4; .byte 0; .uaword %r_disp32(foo); .text");],,
238                     [libffi_cv_as_sparc_ua_pcrel=yes],
239                     [libffi_cv_as_sparc_ua_pcrel=no])
240         CFLAGS="$save_CFLAGS"
241         LDFLAGS="$save_LDFLAGS"])
242     if test "x$libffi_cv_as_sparc_ua_pcrel" = xyes; then
243         AC_DEFINE(HAVE_AS_SPARC_UA_PCREL, 1,
244                   [Define if your assembler and linker support unaligned PC relative relocs.])
245     fi
246
247     AC_CACHE_CHECK([assembler .register pseudo-op support],
248        libffi_cv_as_register_pseudo_op, [
249        libffi_cv_as_register_pseudo_op=unknown
250        # Check if we have .register
251        AC_TRY_COMPILE([asm (".register %g2, #scratch");],,
252                        [libffi_cv_as_register_pseudo_op=yes],
253                        [libffi_cv_as_register_pseudo_op=no])
254     ])
255     if test "x$libffi_cv_as_register_pseudo_op" = xyes; then
256        AC_DEFINE(HAVE_AS_REGISTER_PSEUDO_OP, 1,
257                [Define if your assembler supports .register.])
258     fi
259 fi
260
261 if test x$TARGET = xX86 || test x$TARGET = xX86_WIN32 || test x$TARGET = xX86_64; then
262     AC_CACHE_CHECK([assembler supports pc related relocs],
263         libffi_cv_as_x86_pcrel, [
264         libffi_cv_as_x86_pcrel=yes
265         echo '.text; foo: nop; .data; .long foo-.; .text' > conftest.s
266         if $CC $CFLAGS -c conftest.s 2>&1 | grep -i warning > /dev/null; then
267             libffi_cv_as_x86_pcrel=no
268         fi
269         ])
270     if test "x$libffi_cv_as_x86_pcrel" = xyes; then
271         AC_DEFINE(HAVE_AS_X86_PCREL, 1,
272                   [Define if your assembler supports PC relative relocs.])
273     fi
274 fi
275
276 AC_CACHE_CHECK([whether .eh_frame section should be read-only],
277     libffi_cv_ro_eh_frame, [
278         libffi_cv_ro_eh_frame=no
279         echo 'extern void foo (void); void bar (void) { foo (); foo (); }' > conftest.c
280         if $CC $CFLAGS -S -fpic -fexceptions -o conftest.s conftest.c > /dev/null 2>&1; then
281             if grep '.section.*eh_frame.*"a"' conftest.s > /dev/null; then
282                 libffi_cv_ro_eh_frame=yes
283             elif grep '.section.*eh_frame.*#alloc' conftest.c \
284                  | grep -v '#write' > /dev/null; then
285                 libffi_cv_ro_eh_frame=yes
286             fi
287         fi
288         rm -f conftest.*
289     ])
290 if test "x$libffi_cv_ro_eh_frame" = xyes; then
291     AC_DEFINE(HAVE_RO_EH_FRAME, 1,
292               [Define if .eh_frame sections should be read-only.])
293     AC_DEFINE(EH_FRAME_FLAGS, "a",
294               [Define to the flags needed for the .section .eh_frame directive.])
295 else
296     AC_DEFINE(EH_FRAME_FLAGS, "aw",
297               [Define to the flags needed for the .section .eh_frame directive.])
298 fi
299
300 AC_CACHE_CHECK([for __attribute__((visibility("hidden")))],
301     libffi_cv_hidden_visibility_attribute, [
302         echo 'int __attribute__ ((visibility ("hidden"))) foo (void) { return 1; }' > conftest.c
303         libffi_cv_hidden_visibility_attribute=no
304         if AC_TRY_COMMAND(${CC-cc} -Werror -S conftest.c -o conftest.s 1>&AS_MESSAGE_LOG_FD); then
305             if grep '\.hidden.*foo' conftest.s >/dev/null; then
306                 libffi_cv_hidden_visibility_attribute=yes
307             fi
308         fi
309         rm -f conftest.*
310     ])
311 if test $libffi_cv_hidden_visibility_attribute = yes; then
312     AC_DEFINE(HAVE_HIDDEN_VISIBILITY_ATTRIBUTE, 1,
313               [Define if __attribute__((visibility("hidden"))) is supported.])
314 fi
315
316 AH_BOTTOM([
317 #ifdef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE
318 #ifdef LIBFFI_ASM
319 #define FFI_HIDDEN(name) .hidden name
320 #else
321 #define FFI_HIDDEN __attribute__ ((visibility ("hidden")))
322 #endif
323 #else
324 #ifdef LIBFFI_ASM
325 #define FFI_HIDDEN(name)
326 #else
327 #define FFI_HIDDEN
328 #endif
329 #endif
330 ])
331
332 AC_SUBST(TARGET)
333 AC_SUBST(TARGETDIR)
334
335 AC_SUBST(SHELL)
336
337 AC_ARG_ENABLE(debug,
338 [  --enable-debug          debugging mode],
339   if test "$enable_debug" = "yes"; then
340     AC_DEFINE(FFI_DEBUG, 1, [Define this if you want extra debugging.])
341   fi)
342
343 AC_ARG_ENABLE(structs,
344 [  --disable-structs       omit code for struct support],
345   if test "$enable_structs" = "no"; then
346     AC_DEFINE(FFI_NO_STRUCTS, 1, [Define this is you do not want support for aggregate types.])
347   fi)
348
349 AC_ARG_ENABLE(raw-api,
350 [  --disable-raw-api       make the raw api unavailable],
351   if test "$enable_raw_api" = "no"; then
352     AC_DEFINE(FFI_NO_RAW_API, 1, [Define this is you do not want support for the raw API.])
353   fi)
354
355 AC_ARG_ENABLE(purify-safety,
356 [  --enable-purify-safety  purify-safe mode],
357   if test "$enable_purify_safety" = "yes"; then
358     AC_DEFINE(USING_PURIFY, 1, [Define this if you are using Purify and want to suppress spurious messages.])
359   fi)
360
361 if test -n "$with_cross_host" &&
362    test x"$with_cross_host" != x"no"; then
363   toolexecdir='$(exec_prefix)/$(target_alias)'
364   toolexeclibdir='$(toolexecdir)/lib'
365 else
366   toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
367   toolexeclibdir='$(libdir)'
368 fi
369 multi_os_directory=`$CC -print-multi-os-directory`
370 case $multi_os_directory in
371   .) ;; # Avoid trailing /.
372   *) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
373 esac
374 AC_SUBST(toolexecdir)
375 AC_SUBST(toolexeclibdir)
376
377 if test "${multilib}" = "yes"; then
378   multilib_arg="--enable-multilib"
379 else
380   multilib_arg=
381 fi
382
383 AC_CONFIG_COMMANDS(include, [test -d include || mkdir include])
384 AC_CONFIG_COMMANDS(src, [
385 test -d src || mkdir src
386 test -d src/$TARGETDIR || mkdir src/$TARGETDIR
387 ], [TARGETDIR="$TARGETDIR"])
388
389 AC_CONFIG_LINKS(include/ffitarget.h:src/$TARGETDIR/ffitarget.h)
390
391 AC_CONFIG_FILES(include/Makefile include/ffi.h Makefile testsuite/Makefile man/Makefile libffi.pc)
392
393 AC_OUTPUT