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