1dnl Process this with autoconf to create configure
2
3AC_PREREQ(2.64)
4
5AC_INIT([libffi], [3.0.11], [http://gcc.gnu.org/bugs.html])
6AC_CONFIG_HEADERS([fficonfig.h])
7
8AM_ENABLE_MULTILIB(, ..)
9
10AC_CANONICAL_SYSTEM
11target_alias=${target_alias-$host_alias}
12
13. ${srcdir}/configure.host
14
15AM_INIT_AUTOMAKE([no-dist])
16
17# See if makeinfo has been installed and is modern enough
18# that we can use it.
19ACX_CHECK_PROG_VER([MAKEINFO], [makeinfo], [--version],
20                   [GNU texinfo.* \([0-9][0-9.]*\)],
21                   [4.[4-9]*|4.[1-9][0-9]*|[5-9]*|[1-9][0-9]*])
22AM_CONDITIONAL(BUILD_INFO, test $gcc_cv_prog_makeinfo_modern = "yes")
23
24# We would like our source tree to be readonly. However when releases or
25# pre-releases are generated, the flex/bison generated files as well as the
26# various formats of manuals need to be included along with the rest of the
27# sources.  Therefore we have --enable-generated-files-in-srcdir to do
28# just that.
29AC_MSG_CHECKING(generated-files-in-srcdir)
30AC_ARG_ENABLE(generated-files-in-srcdir,
31AS_HELP_STRING([--enable-generated-files-in-srcdir],
32 [put copies of generated files in source dir intended for creating source tarballs for users without texinfo bison or flex]),
33[case "$enableval" in
34 yes) enable_generated_files_in_srcdir=yes ;;
35 no)  enable_generated_files_in_srcdir=no ;;
36 *)   AC_MSG_ERROR([Unknown argument to enable/disable version-specific libs]);;
37 esac],
38[enable_generated_files_in_srcdir=no])
39AC_MSG_RESULT($enable_generated_files_in_srcdir)
40AM_CONDITIONAL(GENINSRC, test "$enable_generated_files_in_srcdir" = yes)
41
42# The same as in boehm-gc and libstdc++. Have to borrow it from there.
43# We must force CC to /not/ be precious variables; otherwise
44# the wrong, non-multilib-adjusted value will be used in multilibs.
45# As a side effect, we have to subst CFLAGS ourselves.
46
47m4_rename([_AC_ARG_VAR_PRECIOUS],[real_PRECIOUS])
48m4_define([_AC_ARG_VAR_PRECIOUS],[])
49AC_PROG_CC
50m4_rename_force([real_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
51
52AC_SUBST(CFLAGS)
53
54AM_PROG_AS
55AM_PROG_CC_C_O
56AC_PROG_LIBTOOL
57
58AM_MAINTAINER_MODE
59
60AC_CHECK_HEADERS(sys/mman.h)
61AC_CHECK_FUNCS(mmap)
62AC_FUNC_MMAP_BLACKLIST
63
64dnl The -no-testsuite modules omit the test subdir.
65AM_CONDITIONAL(TESTSUBDIR, test -d $srcdir/testsuite)
66
67TARGETDIR="unknown"
68HAVE_LONG_DOUBLE_VARIANT=0
69case "$host" in
70  aarch64*-*-*)
71	TARGET=AARCH64; TARGETDIR=aarch64
72	;;
73
74  alpha*-*-*)
75	TARGET=ALPHA; TARGETDIR=alpha;
76	# Support 128-bit long double, changeable via command-line switch.
77	HAVE_LONG_DOUBLE='defined(__LONG_DOUBLE_128__)'
78	;;
79
80  arm*-*-*)
81	TARGET=ARM; TARGETDIR=arm
82	;;
83
84  amd64-*-freebsd* | amd64-*-openbsd*)
85	TARGET=X86_64; TARGETDIR=x86
86  	;;
87
88  amd64-*-freebsd*)
89	TARGET=X86_64; TARGETDIR=x86
90	;;
91
92  avr32*-*-*)
93	TARGET=AVR32; TARGETDIR=avr32
94	;;
95
96  bfin*)
97  	TARGET=BFIN; TARGETDIR=bfin
98  	;;
99
100  cris-*-*)
101	TARGET=LIBFFI_CRIS; TARGETDIR=cris
102	;;
103
104  frv-*-*)
105	TARGET=FRV; TARGETDIR=frv
106	;;
107
108  hppa*-*-linux* | parisc*-*-linux* | hppa*-*-openbsd*)
109	TARGET=PA_LINUX; TARGETDIR=pa
110	;;
111  hppa*64-*-hpux*)
112	TARGET=PA64_HPUX; TARGETDIR=pa
113	;;
114  hppa*-*-hpux*)
115	TARGET=PA_HPUX; TARGETDIR=pa
116	;;
117
118  i?86-*-freebsd* | i?86-*-openbsd*)
119	TARGET=X86_FREEBSD; TARGETDIR=x86
120	;;
121  i?86-win32* | i?86-*-cygwin* | i?86-*-mingw* | i?86-*-os2* | i?86-*-interix*)
122	TARGET=X86_WIN32; TARGETDIR=x86
123	# All mingw/cygwin/win32 builds require -no-undefined for sharedlib.
124	# We must also check with_cross_host to decide if this is a native
125	# or cross-build and select where to install dlls appropriately.
126	if test -n "$with_cross_host" &&
127	   test x"$with_cross_host" != x"no"; then
128	  AM_LTLDFLAGS='-no-undefined -bindir "$(toolexeclibdir)"';
129	else
130	  AM_LTLDFLAGS='-no-undefined -bindir "$(bindir)"';
131	fi
132	;;
133  i?86-*-darwin*)
134	TARGET=X86_DARWIN; TARGETDIR=x86
135	;;
136  i?86-*-solaris2.1[[0-9]]*)
137	TARGET=X86_64; TARGETDIR=x86
138	;;
139  i?86-*-*)
140	TARGET=X86_64; TARGETDIR=x86
141	;;
142
143  ia64*-*-*)
144	TARGET=IA64; TARGETDIR=ia64
145	;;
146
147  m32r*-*-*)
148	TARGET=M32R; TARGETDIR=m32r
149	;;
150
151  m68k-*-*)
152	TARGET=M68K; TARGETDIR=m68k
153	;;
154
155  mips-sgi-irix5.* | mips-sgi-irix6.* | mips*-*-rtems*)
156	TARGET=MIPS; TARGETDIR=mips
157	;;
158  mips*-*-linux* | mips*-*-openbsd*)
159	# Support 128-bit long double for NewABI.
160	HAVE_LONG_DOUBLE='defined(__mips64)'
161	TARGET=MIPS; TARGETDIR=mips
162	;;
163
164  powerpc*-*-linux* | powerpc-*-sysv*)
165	TARGET=POWERPC; TARGETDIR=powerpc
166	HAVE_LONG_DOUBLE_VARIANT=1
167	;;
168  powerpc-*-amigaos*)
169	TARGET=POWERPC; TARGETDIR=powerpc
170	;;
171  powerpc-*-beos*)
172	TARGET=POWERPC; TARGETDIR=powerpc
173	;;
174  powerpc-*-darwin* | powerpc64-*-darwin*)
175	TARGET=POWERPC_DARWIN; TARGETDIR=powerpc
176	;;
177  powerpc-*-aix* | rs6000-*-aix*)
178	TARGET=POWERPC_AIX; TARGETDIR=powerpc
179	;;
180  powerpc-*-freebsd* | powerpc-*-openbsd*)
181	TARGET=POWERPC_FREEBSD; TARGETDIR=powerpc
182	HAVE_LONG_DOUBLE_VARIANT=1
183	;;
184  powerpc64-*-freebsd*)
185	TARGET=POWERPC; TARGETDIR=powerpc
186	;;
187  powerpc*-*-rtems*)
188	TARGET=POWERPC; TARGETDIR=powerpc
189	;;
190
191  s390-*-* | s390x-*-*)
192	TARGET=S390; TARGETDIR=s390
193	;;
194
195  sh-*-* | sh[[34]]*-*-*)
196	TARGET=SH; TARGETDIR=sh
197	;;
198  sh64-*-* | sh5*-*-*)
199	TARGET=SH64; TARGETDIR=sh64
200	;;
201
202  sparc*-*-*)
203	TARGET=SPARC; TARGETDIR=sparc
204	;;
205
206  tile*-*)
207        TARGET=TILE; TARGETDIR=tile
208        ;;
209
210  x86_64-*-darwin*)
211	TARGET=X86_DARWIN; TARGETDIR=x86
212	;;
213
214  x86_64-*-cygwin* | x86_64-*-mingw*)
215	TARGET=X86_WIN64; TARGETDIR=x86
216	# All mingw/cygwin/win32 builds require -no-undefined for sharedlib.
217	# We must also check with_cross_host to decide if this is a native
218	# or cross-build and select where to install dlls appropriately.
219	if test -n "$with_cross_host" &&
220	   test x"$with_cross_host" != x"no"; then
221	  AM_LTLDFLAGS='-no-undefined -bindir "$(toolexeclibdir)"';
222	else
223	  AM_LTLDFLAGS='-no-undefined -bindir "$(bindir)"';
224	fi
225	;;
226
227  x86_64-*-*)
228	TARGET=X86_64; TARGETDIR=x86
229	;;
230esac
231
232AC_SUBST(AM_RUNTESTFLAGS)
233AC_SUBST(AM_LTLDFLAGS)
234
235if test $TARGETDIR = unknown; then
236  AC_MSG_ERROR(["libffi has not been ported to $host."])
237fi
238
239AM_CONDITIONAL(MIPS, test x$TARGET = xMIPS)
240AM_CONDITIONAL(BFIN, test x$TARGET = xBFIN)
241AM_CONDITIONAL(SPARC, test x$TARGET = xSPARC)
242AM_CONDITIONAL(X86, test x$TARGET = xX86)
243AM_CONDITIONAL(X86_FREEBSD, test x$TARGET = xX86_FREEBSD)
244AM_CONDITIONAL(X86_WIN32, test x$TARGET = xX86_WIN32)
245AM_CONDITIONAL(X86_WIN64, test x$TARGET = xX86_WIN64)
246AM_CONDITIONAL(X86_DARWIN, test x$TARGET = xX86_DARWIN)
247AM_CONDITIONAL(ALPHA, test x$TARGET = xALPHA)
248AM_CONDITIONAL(IA64, test x$TARGET = xIA64)
249AM_CONDITIONAL(M32R, test x$TARGET = xM32R)
250AM_CONDITIONAL(M68K, test x$TARGET = xM68K)
251AM_CONDITIONAL(POWERPC, test x$TARGET = xPOWERPC)
252AM_CONDITIONAL(POWERPC_AIX, test x$TARGET = xPOWERPC_AIX)
253AM_CONDITIONAL(POWERPC_DARWIN, test x$TARGET = xPOWERPC_DARWIN)
254AM_CONDITIONAL(POWERPC_FREEBSD, test x$TARGET = xPOWERPC_FREEBSD)
255AM_CONDITIONAL(AARCH64, test x$TARGET = xAARCH64)
256AM_CONDITIONAL(ARM, test x$TARGET = xARM)
257AM_CONDITIONAL(AVR32, test x$TARGET = xAVR32)
258AM_CONDITIONAL(LIBFFI_CRIS, test x$TARGET = xLIBFFI_CRIS)
259AM_CONDITIONAL(FRV, test x$TARGET = xFRV)
260AM_CONDITIONAL(S390, test x$TARGET = xS390)
261AM_CONDITIONAL(X86_64, test x$TARGET = xX86_64)
262AM_CONDITIONAL(SH, test x$TARGET = xSH)
263AM_CONDITIONAL(SH64, test x$TARGET = xSH64)
264AM_CONDITIONAL(PA_LINUX, test x$TARGET = xPA_LINUX)
265AM_CONDITIONAL(PA_HPUX, test x$TARGET = xPA_HPUX)
266AM_CONDITIONAL(PA64_HPUX, test x$TARGET = xPA64_HPUX)
267AM_CONDITIONAL(TILE, test x$TARGET = xTILE)
268
269AC_HEADER_STDC
270AC_CHECK_FUNCS(memcpy)
271AC_FUNC_ALLOCA
272
273AC_CHECK_SIZEOF(double)
274AC_CHECK_SIZEOF(long double)
275
276# Also AC_SUBST this variable for ffi.h.
277if test -z "$HAVE_LONG_DOUBLE"; then
278  HAVE_LONG_DOUBLE=0
279  if test $ac_cv_sizeof_long_double != 0; then
280    if test $HAVE_LONG_DOUBLE_VARIANT != 0; then
281      AC_DEFINE(HAVE_LONG_DOUBLE_VARIANT, 1, [Define if you support more than one size of the long double type])
282      HAVE_LONG_DOUBLE=1
283    else
284      if test $ac_cv_sizeof_double != $ac_cv_sizeof_long_double; then
285        HAVE_LONG_DOUBLE=1
286        AC_DEFINE(HAVE_LONG_DOUBLE, 1, [Define if you have the long double type and it is bigger than a double])
287      fi
288    fi
289  fi
290fi
291AC_SUBST(HAVE_LONG_DOUBLE)
292AC_SUBST(HAVE_LONG_DOUBLE_VARIANT)
293
294AC_C_BIGENDIAN
295
296GCC_AS_CFI_PSEUDO_OP
297
298if test x$TARGET = xSPARC; then
299    AC_CACHE_CHECK([assembler and linker support unaligned pc related relocs],
300	libffi_cv_as_sparc_ua_pcrel, [
301	save_CFLAGS="$CFLAGS"
302	save_LDFLAGS="$LDFLAGS"
303	CFLAGS="$CFLAGS -fpic"
304	LDFLAGS="$LDFLAGS -shared"
305	AC_TRY_LINK([asm (".text; foo: nop; .data; .align 4; .byte 0; .uaword %r_disp32(foo); .text");],,
306		    [libffi_cv_as_sparc_ua_pcrel=yes],
307		    [libffi_cv_as_sparc_ua_pcrel=no])
308	CFLAGS="$save_CFLAGS"
309	LDFLAGS="$save_LDFLAGS"])
310    if test "x$libffi_cv_as_sparc_ua_pcrel" = xyes; then
311	AC_DEFINE(HAVE_AS_SPARC_UA_PCREL, 1,
312		  [Define if your assembler and linker support unaligned PC relative relocs.])
313    fi
314
315    AC_CACHE_CHECK([assembler .register pseudo-op support],
316       libffi_cv_as_register_pseudo_op, [
317       libffi_cv_as_register_pseudo_op=unknown
318       # Check if we have .register
319       AC_TRY_COMPILE([asm (".register %g2, #scratch");],,
320		       [libffi_cv_as_register_pseudo_op=yes],
321		       [libffi_cv_as_register_pseudo_op=no])
322    ])
323    if test "x$libffi_cv_as_register_pseudo_op" = xyes; then
324       AC_DEFINE(HAVE_AS_REGISTER_PSEUDO_OP, 1,
325	       [Define if your assembler supports .register.])
326    fi
327fi
328
329if test x$TARGET = xX86 || test x$TARGET = xX86_WIN32 || test x$TARGET = xX86_64; then
330    AC_CACHE_CHECK([assembler supports pc related relocs],
331	libffi_cv_as_x86_pcrel, [
332	libffi_cv_as_x86_pcrel=yes
333	echo '.text; foo: nop; .data; .long foo-.; .text' > conftest.s
334	if $CC $CFLAGS -c conftest.s 2>&1 | $EGREP -i 'illegal|warning' > /dev/null; then
335	    libffi_cv_as_x86_pcrel=no
336	fi
337	])
338    if test "x$libffi_cv_as_x86_pcrel" = xyes; then
339	AC_DEFINE(HAVE_AS_X86_PCREL, 1,
340		  [Define if your assembler supports PC relative relocs.])
341    fi
342
343    AC_CACHE_CHECK([assembler .ascii pseudo-op support],
344       libffi_cv_as_ascii_pseudo_op, [
345       libffi_cv_as_ascii_pseudo_op=unknown
346       # Check if we have .ascii
347       AC_TRY_COMPILE([asm (".ascii \\"string\\"");],,
348		       [libffi_cv_as_ascii_pseudo_op=yes],
349		       [libffi_cv_as_ascii_pseudo_op=no])
350    ])
351    if test "x$libffi_cv_as_ascii_pseudo_op" = xyes; then
352       AC_DEFINE(HAVE_AS_ASCII_PSEUDO_OP, 1,
353	       [Define if your assembler supports .ascii.])
354    fi
355
356    AC_CACHE_CHECK([assembler .string pseudo-op support],
357       libffi_cv_as_string_pseudo_op, [
358       libffi_cv_as_string_pseudo_op=unknown
359       # Check if we have .string
360       AC_TRY_COMPILE([asm (".string \\"string\\"");],,
361		       [libffi_cv_as_string_pseudo_op=yes],
362		       [libffi_cv_as_string_pseudo_op=no])
363    ])
364    if test "x$libffi_cv_as_string_pseudo_op" = xyes; then
365       AC_DEFINE(HAVE_AS_STRING_PSEUDO_OP, 1,
366	       [Define if your assembler supports .string.])
367    fi
368fi
369
370# On PaX enable kernels that have MPROTECT enable we can't use PROT_EXEC.
371AC_ARG_ENABLE(pax_emutramp,
372  [  --enable-pax_emutramp       enable pax emulated trampolines, for we can't use PROT_EXEC],
373  if test "$enable_pax_emutramp" = "yes"; then
374    AC_DEFINE(FFI_MMAP_EXEC_EMUTRAMP_PAX, 1,
375      [Define this if you want to enable pax emulated trampolines])
376  fi)
377
378FFI_EXEC_TRAMPOLINE_TABLE=0
379case "$target" in
380     *arm*-apple-darwin*)
381       FFI_EXEC_TRAMPOLINE_TABLE=1
382       AC_DEFINE(FFI_EXEC_TRAMPOLINE_TABLE, 1,
383                 [Cannot use PROT_EXEC on this target, so, we revert to
384                   alternative means])
385     ;;
386     *-apple-darwin1* | *-*-freebsd* | *-*-kfreebsd* | *-*-openbsd* | *-pc-solaris*)
387       AC_DEFINE(FFI_MMAP_EXEC_WRIT, 1,
388                 [Cannot use malloc on this target, so, we revert to
389                   alternative means])
390     ;;
391esac
392AM_CONDITIONAL(FFI_EXEC_TRAMPOLINE_TABLE, test x$FFI_EXEC_TRAMPOLINE_TABLE = x1)
393AC_SUBST(FFI_EXEC_TRAMPOLINE_TABLE)
394
395if test x$TARGET = xX86_64; then
396    AC_CACHE_CHECK([assembler supports unwind section type],
397	libffi_cv_as_x86_64_unwind_section_type, [
398	libffi_cv_as_x86_64_unwind_section_type=yes
399	echo '.section .eh_frame,"a",@unwind' > conftest.s
400	if $CC $CFLAGS -c conftest.s 2>&1 | grep -i warning > /dev/null; then
401	    libffi_cv_as_x86_64_unwind_section_type=no
402	fi
403	])
404    if test "x$libffi_cv_as_x86_64_unwind_section_type" = xyes; then
405	AC_DEFINE(HAVE_AS_X86_64_UNWIND_SECTION_TYPE, 1,
406		  [Define if your assembler supports unwind section type.])
407    fi
408fi
409
410if test "x$GCC" = "xyes"; then
411  AC_CACHE_CHECK([whether .eh_frame section should be read-only],
412      libffi_cv_ro_eh_frame, [
413  	libffi_cv_ro_eh_frame=no
414  	echo 'extern void foo (void); void bar (void) { foo (); foo (); }' > conftest.c
415  	if $CC $CFLAGS -S -fpic -fexceptions -o conftest.s conftest.c > /dev/null 2>&1; then
416  	    if grep '.section.*eh_frame.*"a"' conftest.s > /dev/null; then
417  		libffi_cv_ro_eh_frame=yes
418  	    elif grep '.section.*eh_frame.*#alloc' conftest.c \
419  		 | grep -v '#write' > /dev/null; then
420  		libffi_cv_ro_eh_frame=yes
421  	    fi
422  	fi
423  	rm -f conftest.*
424      ])
425  if test "x$libffi_cv_ro_eh_frame" = xyes; then
426      AC_DEFINE(HAVE_RO_EH_FRAME, 1,
427  	      [Define if .eh_frame sections should be read-only.])
428      AC_DEFINE(EH_FRAME_FLAGS, "a",
429  	      [Define to the flags needed for the .section .eh_frame directive.  ])
430  else
431      AC_DEFINE(EH_FRAME_FLAGS, "aw",
432  	      [Define to the flags needed for the .section .eh_frame directive.  ])
433  fi
434
435  AC_CACHE_CHECK([for __attribute__((visibility("hidden")))],
436      libffi_cv_hidden_visibility_attribute, [
437  	echo 'int __attribute__ ((visibility ("hidden"))) foo (void) { return 1  ; }' > conftest.c
438  	libffi_cv_hidden_visibility_attribute=no
439  	if AC_TRY_COMMAND(${CC-cc} -Werror -S conftest.c -o conftest.s 1>&AS_MESSAGE_LOG_FD); then
440  	    if grep '\.hidden.*foo' conftest.s >/dev/null; then
441  		libffi_cv_hidden_visibility_attribute=yes
442  	    fi
443  	fi
444  	rm -f conftest.*
445      ])
446  if test $libffi_cv_hidden_visibility_attribute = yes; then
447      AC_DEFINE(HAVE_HIDDEN_VISIBILITY_ATTRIBUTE, 1,
448  	      [Define if __attribute__((visibility("hidden"))) is supported.])
449  fi
450fi
451
452AH_BOTTOM([
453#ifdef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE
454#ifdef LIBFFI_ASM
455#define FFI_HIDDEN(name) .hidden name
456#else
457#define FFI_HIDDEN __attribute__ ((visibility ("hidden")))
458#endif
459#else
460#ifdef LIBFFI_ASM
461#define FFI_HIDDEN(name)
462#else
463#define FFI_HIDDEN
464#endif
465#endif
466])
467
468AC_SUBST(TARGET)
469AC_SUBST(TARGETDIR)
470
471AC_SUBST(SHELL)
472
473AC_ARG_ENABLE(debug,
474[  --enable-debug          debugging mode],
475  if test "$enable_debug" = "yes"; then
476    AC_DEFINE(FFI_DEBUG, 1, [Define this if you want extra debugging.])
477  fi)
478AM_CONDITIONAL(FFI_DEBUG, test "$enable_debug" = "yes")
479
480AC_ARG_ENABLE(structs,
481[  --disable-structs       omit code for struct support],
482  if test "$enable_structs" = "no"; then
483    AC_DEFINE(FFI_NO_STRUCTS, 1, [Define this is you do not want support for aggregate types.])
484  fi)
485
486AC_ARG_ENABLE(raw-api,
487[  --disable-raw-api       make the raw api unavailable],
488  if test "$enable_raw_api" = "no"; then
489    AC_DEFINE(FFI_NO_RAW_API, 1, [Define this is you do not want support for the raw API.])
490  fi)
491
492AC_ARG_ENABLE(purify-safety,
493[  --enable-purify-safety  purify-safe mode],
494  if test "$enable_purify_safety" = "yes"; then
495    AC_DEFINE(USING_PURIFY, 1, [Define this if you are using Purify and want to suppress spurious messages.])
496  fi)
497
498if test -n "$with_cross_host" &&
499   test x"$with_cross_host" != x"no"; then
500  toolexecdir='$(exec_prefix)/$(target_alias)'
501  toolexeclibdir='$(toolexecdir)/lib'
502else
503  toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
504  toolexeclibdir='$(libdir)'
505fi
506multi_os_directory=`$CC -print-multi-os-directory`
507case $multi_os_directory in
508  .) ;; # Avoid trailing /.
509  *) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
510esac
511AC_SUBST(toolexecdir)
512AC_SUBST(toolexeclibdir)
513
514if test "${multilib}" = "yes"; then
515  multilib_arg="--enable-multilib"
516else
517  multilib_arg=
518fi
519
520AC_CONFIG_COMMANDS(include, [test -d include || mkdir include])
521AC_CONFIG_COMMANDS(src, [
522test -d src || mkdir src
523test -d src/$TARGETDIR || mkdir src/$TARGETDIR
524], [TARGETDIR="$TARGETDIR"])
525
526AC_CONFIG_LINKS(include/ffitarget.h:src/$TARGETDIR/ffitarget.h)
527
528AC_CONFIG_FILES(include/Makefile include/ffi.h Makefile testsuite/Makefile man/Makefile)
529
530AC_OUTPUT
531