• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1
2##------------------------------------------------------------##
3#
4# The multiple-architecture stuff in this file is pretty
5# cryptic.  Read docs/internals/multiple-architectures.txt
6# for at least a partial explanation of what is going on.
7#
8##------------------------------------------------------------##
9
10# Process this file with autoconf to produce a configure script.
11AC_INIT([Valgrind],[3.8.0.SVN],[valgrind-users@lists.sourceforge.net])
12AC_CONFIG_SRCDIR(coregrind/m_main.c)
13AC_CONFIG_HEADERS([config.h])
14AM_INIT_AUTOMAKE([foreign])
15
16AM_MAINTAINER_MODE
17
18#----------------------------------------------------------------------------
19# Checks for various programs.
20#----------------------------------------------------------------------------
21CFLAGS="-Wno-long-long $CFLAGS"
22
23AC_PROG_LN_S
24AC_PROG_CC
25AM_PROG_CC_C_O
26AC_PROG_CPP
27AC_PROG_CXX
28# AC_PROG_OBJC apparently causes problems on older Linux distros (eg. with
29# autoconf 2.59).  If we ever have any Objective-C code in the Valgrind code
30# base (eg. most likely as Darwin-specific tests) we'll need one of the
31# following:
32# - put AC_PROG_OBJC in a Darwin-specific part of this file
33# - Use AC_PROG_OBJC here and up the minimum autoconf version
34# - Use the following, which is apparently equivalent:
35#     m4_ifdef([AC_PROG_OBJC],
36#        [AC_PROG_OBJC],
37#        [AC_CHECK_TOOL([OBJC], [gcc])
38#         AC_SUBST([OBJC])
39#         AC_SUBST([OBJCFLAGS])
40#        ])
41AC_PROG_RANLIB
42# provide a very basic definition for AC_PROG_SED if it's not provided by
43# autoconf (as e.g. in autoconf 2.59).
44m4_ifndef([AC_PROG_SED],
45          [AC_DEFUN([AC_PROG_SED],
46                    [AC_ARG_VAR([SED])
47                     AC_CHECK_PROGS([SED],[gsed sed])])])
48AC_PROG_SED
49
50# If no AR variable was specified, look up the name of the archiver. Otherwise
51# do not touch the AR variable.
52if test "x$AR" = "x"; then
53  AC_PATH_PROGS([AR], [`echo $LD | $SED 's/ld$/ar/'` "ar"], [ar])
54fi
55AC_ARG_VAR([AR],[Archiver command])
56
57# Check for the compiler support
58if test "${GCC}" != "yes" ; then
59   AC_MSG_ERROR([Valgrind relies on GCC to be compiled])
60fi
61
62# figure out where perl lives
63AC_PATH_PROG(PERL, perl)
64
65# figure out where gdb lives
66AC_PATH_PROG(GDB, gdb, "/no/gdb/was/found/at/configure/time")
67AC_DEFINE_UNQUOTED(GDB_PATH, "$GDB", [path to GDB])
68
69# some older automake's don't have it so try something on our own
70ifdef([AM_PROG_AS],[AM_PROG_AS],
71[
72AS="${CC}"
73AC_SUBST(AS)
74
75ASFLAGS=""
76AC_SUBST(ASFLAGS)
77])
78
79
80# Check if 'diff' supports -u (universal diffs) and use it if possible.
81
82AC_MSG_CHECKING([for diff -u])
83AC_SUBST(DIFF)
84
85# Comparing two identical files results in 0.
86tmpfile="tmp-xxx-yyy-zzz"
87touch $tmpfile;
88if diff -u $tmpfile $tmpfile ; then
89    AC_MSG_RESULT([yes])
90    DIFF="diff -u"
91else
92    AC_MSG_RESULT([no])
93    DIFF="diff"
94fi
95rm $tmpfile
96
97
98# We don't want gcc < 3.0
99AC_MSG_CHECKING([for a supported version of gcc])
100
101# Try to get the gcc version, sed-ing out some unexpected stuff
102# that appears with the default gcc on OSX 10.6 and 10.7 respectively.
103# Without this, the version number comes out as 686, 10 or 11 :-(
104#
105# i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3)
106# i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)
107#
108[gcc_version=`${CC} --version \
109             | head -n 1 \
110             | $SED 's/i686-apple-darwin9//' \
111             | $SED 's/i686-apple-darwin10//' \
112             | $SED 's/i686-apple-darwin11//' \
113             | $SED 's/^[^0-9]*\([0-9.]*\).*$/\1/'`]
114
115is_clang="notclang"
116if test "x`${CC} --version | head -n 1 | $SED 's/\(clang\) version.*/\1/'`" = "xclang" ; then
117   is_clang="clang"
118fi
119
120case "${is_clang}-${gcc_version}" in
121     notclang-3.*)
122	AC_MSG_RESULT([ok (${gcc_version})])
123	;;
124     notclang-4.*)
125	AC_MSG_RESULT([ok (${gcc_version})])
126	;;
127     clang-2.9)
128	AC_MSG_RESULT([ok (clang-${gcc_version})])
129	;;
130     *)
131	AC_MSG_RESULT([no (${gcc_version})])
132	AC_MSG_ERROR([please use gcc >= 3.0 or clang >= 2.9])
133	;;
134esac
135
136AC_PROG_EGREP
137AC_DEFINE_UNQUOTED(EGREP_PATH, "$EGREP", [path to egrep])
138
139AC_PATH_PROG(STRINGS, strings)
140AC_DEFINE_UNQUOTED(STRINGS_PATH, "$STRINGS", [path to strings])
141
142AC_PATH_PROG(SH, sh)
143AC_DEFINE_UNQUOTED(SH_PATH, "$SH", [path to sh])
144
145#----------------------------------------------------------------------------
146# Arch/OS/platform tests.
147#----------------------------------------------------------------------------
148# We create a number of arch/OS/platform-related variables.  We prefix them
149# all with "VGCONF_" which indicates that they are defined at
150# configure-time, and distinguishes them from the VGA_*/VGO_*/VGP_*
151# variables used when compiling C files.
152
153AC_CANONICAL_HOST
154
155AC_MSG_CHECKING([for a supported CPU])
156
157# ARCH_MAX reflects the most that this CPU can do: for example if it
158# is a 64-bit capable PowerPC, then it must be set to ppc64 and not ppc32.
159# Ditto for amd64.  It is used for more configuration below, but is not used
160# outside this file.
161case "${host_cpu}" in
162     i?86)
163	AC_MSG_RESULT([ok (${host_cpu})])
164        ARCH_MAX="x86"
165        ;;
166
167     x86_64)
168        AC_MSG_RESULT([ok (${host_cpu})])
169        ARCH_MAX="amd64"
170        ;;
171
172     powerpc64)
173        AC_MSG_RESULT([ok (${host_cpu})])
174        ARCH_MAX="ppc64"
175        ;;
176
177     powerpc)
178        # On Linux this means only a 32-bit capable CPU.
179        AC_MSG_RESULT([ok (${host_cpu})])
180        ARCH_MAX="ppc32"
181        ;;
182
183     s390x)
184        AC_MSG_RESULT([ok (${host_cpu})])
185        ARCH_MAX="s390x"
186        ;;
187
188     armv7*)
189	AC_MSG_RESULT([ok (${host_cpu})])
190	ARCH_MAX="arm"
191	;;
192
193     *)
194	AC_MSG_RESULT([no (${host_cpu})])
195	AC_MSG_ERROR([Unsupported host architecture. Sorry])
196	;;
197esac
198
199#----------------------------------------------------------------------------
200
201# Sometimes it's convenient to subvert the bi-arch build system and
202# just have a single build even though the underlying platform is
203# capable of both.  Hence handle --enable-only64bit and
204# --enable-only32bit.  Complain if both are issued :-)
205# [Actually, if either of these options are used, I think both get built,
206# but only one gets installed.  So if you use an in-place build, both can be
207# used. --njn]
208
209# Check if a 64-bit only build has been requested
210AC_CACHE_CHECK([for a 64-bit only build], vg_cv_only64bit,
211   [AC_ARG_ENABLE(only64bit,
212      [  --enable-only64bit      do a 64-bit only build],
213      [vg_cv_only64bit=$enableval],
214      [vg_cv_only64bit=no])])
215
216# Check if a 32-bit only build has been requested
217AC_CACHE_CHECK([for a 32-bit only build], vg_cv_only32bit,
218   [AC_ARG_ENABLE(only32bit,
219      [  --enable-only32bit      do a 32-bit only build],
220      [vg_cv_only32bit=$enableval],
221      [vg_cv_only32bit=no])])
222
223# Stay sane
224if test x$vg_cv_only64bit = xyes -a x$vg_cv_only32bit = xyes; then
225   AC_MSG_ERROR(
226      [Nonsensical: both --enable-only64bit and --enable-only32bit.])
227fi
228
229#----------------------------------------------------------------------------
230
231# VGCONF_OS is the primary build OS, eg. "linux".  It is passed in to
232# compilation of many C files via -VGO_$(VGCONF_OS) and
233# -VGP_$(VGCONF_ARCH_PRI)_$(VGCONF_OS).
234AC_MSG_CHECKING([for a supported OS])
235AC_SUBST(VGCONF_OS)
236
237DEFAULT_SUPP=""
238
239case "${host_os}" in
240     *linux*)
241	AC_MSG_RESULT([ok (${host_os})])
242        VGCONF_OS="linux"
243
244        # Ok, this is linux. Check the kernel version
245        AC_MSG_CHECKING([for the kernel version])
246
247        kernel=`uname -r`
248
249        case "${kernel}" in
250             2.6.*|3.*)
251        	    AC_MSG_RESULT([2.6.x/3.x family (${kernel})])
252        	    AC_DEFINE([KERNEL_2_6], 1, [Define to 1 if you're using Linux 2.6.x or Linux 3.x])
253        	    ;;
254
255             2.4.*)
256        	    AC_MSG_RESULT([2.4 family (${kernel})])
257        	    AC_DEFINE([KERNEL_2_4], 1, [Define to 1 if you're using Linux 2.4.x])
258        	    ;;
259
260             *)
261        	    AC_MSG_RESULT([unsupported (${kernel})])
262        	    AC_MSG_ERROR([Valgrind works on kernels 2.4, 2.6])
263        	    ;;
264        esac
265
266        ;;
267
268     *darwin*)
269        AC_MSG_RESULT([ok (${host_os})])
270        VGCONF_OS="darwin"
271        AC_DEFINE([DARWIN_10_5], 100500, [DARWIN_VERS value for Mac OS X 10.5])
272        AC_DEFINE([DARWIN_10_6], 100600, [DARWIN_VERS value for Mac OS X 10.6])
273        AC_DEFINE([DARWIN_10_7], 100700, [DARWIN_VERS value for Mac OS X 10.7])
274
275	AC_MSG_CHECKING([for the kernel version])
276	kernel=`uname -r`
277
278        # Nb: for Darwin we set DEFAULT_SUPP here.  That's because Darwin
279        # has only one relevant version, the OS version. The `uname` check
280        # is a good way to get that version (i.e. "Darwin 9.6.0" is Mac OS
281        # X 10.5.6, and "Darwin 10.x" is Mac OS X 10.6.x Snow Leopard,
282        # and possibly "Darwin 11.x" is Mac OS X 10.7.x Lion),
283        # and we don't know of an macros similar to __GLIBC__ to get that info.
284        #
285        # XXX: `uname -r` won't do the right thing for cross-compiles, but
286        # that's not a problem yet.
287        #
288        # jseward 21 Sept 2011: I seriously doubt whether V 3.7.0 will work
289        # on OS X 10.5.x; I haven't tested yet, and only plan to test 3.7.0
290        # on 10.6.8 and 10.7.1.  Although tempted to delete the configure
291        # time support for 10.5 (the 9.* pattern just below), I'll leave it
292        # in for now, just in case anybody wants to give it a try.  But I'm
293        # assuming that 3.7.0 is a Snow Leopard and Lion-only release.
294	case "${kernel}" in
295	     9.*)
296		  AC_MSG_RESULT([Darwin 9.x (${kernel}) / Mac OS X 10.5 Leopard])
297		  AC_DEFINE([DARWIN_VERS], DARWIN_10_5, [Darwin / Mac OS X version])
298		  DEFAULT_SUPP="darwin9.supp ${DEFAULT_SUPP}"
299		  DEFAULT_SUPP="darwin9-drd.supp ${DEFAULT_SUPP}"
300		  ;;
301	     10.*)
302		  AC_MSG_RESULT([Darwin 10.x (${kernel}) / Mac OS X 10.6 Snow Leopard])
303		  AC_DEFINE([DARWIN_VERS], DARWIN_10_6, [Darwin / Mac OS X version])
304		  DEFAULT_SUPP="darwin10.supp ${DEFAULT_SUPP}"
305		  DEFAULT_SUPP="darwin10-drd.supp ${DEFAULT_SUPP}"
306		  ;;
307	     11.*)
308		  AC_MSG_RESULT([Darwin 11.x (${kernel}) / Mac OS X 10.7 Lion])
309		  AC_DEFINE([DARWIN_VERS], DARWIN_10_7, [Darwin / Mac OS X version])
310                  # FIXME: change these to xx11.supp
311		  DEFAULT_SUPP="darwin11.supp ${DEFAULT_SUPP}"
312		  DEFAULT_SUPP="darwin10-drd.supp ${DEFAULT_SUPP}"
313		  ;;
314             *)
315		  AC_MSG_RESULT([unsupported (${kernel})])
316		  AC_MSG_ERROR([Valgrind works on Darwin 10.x and 11.x (Mac OS X 10.6/7)])
317		  ;;
318	esac
319        ;;
320
321     *)
322	AC_MSG_RESULT([no (${host_os})])
323	AC_MSG_ERROR([Valgrind is operating system specific. Sorry.])
324	;;
325esac
326
327#----------------------------------------------------------------------------
328
329# If we are building on a 64 bit platform test to see if the system
330# supports building 32 bit programs and disable 32 bit support if it
331# does not support building 32 bit programs
332
333case "$ARCH_MAX-$VGCONF_OS" in
334     amd64-linux|ppc64-linux)
335        AC_MSG_CHECKING([for 32 bit build support])
336        safe_CFLAGS=$CFLAGS
337        CFLAGS="-m32"
338        AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
339          return 0;
340        ]])], [
341        AC_MSG_RESULT([yes])
342        ], [
343        vg_cv_only64bit="yes"
344        AC_MSG_RESULT([no])
345        ])
346        CFLAGS=$safe_CFLAGS;;
347esac
348
349if test x$vg_cv_only64bit = xyes -a x$vg_cv_only32bit = xyes; then
350   AC_MSG_ERROR(
351      [--enable-only32bit was specified but system does not support 32 bit builds])
352fi
353
354#----------------------------------------------------------------------------
355
356# VGCONF_ARCH_PRI is the arch for the primary build target, eg. "amd64".  By
357# default it's the same as ARCH_MAX.  But if, say, we do a build on an amd64
358# machine, but --enable-only32bit has been requested, then ARCH_MAX (see
359# above) will be "amd64" since that reflects the most that this cpu can do,
360# but VGCONF_ARCH_PRI will be downgraded to "x86", since that reflects the
361# arch corresponding to the primary build (VGCONF_PLATFORM_PRI_CAPS).  It is
362# passed in to compilation of many C files via -VGA_$(VGCONF_ARCH_PRI) and
363# -VGP_$(VGCONF_ARCH_PRI)_$(VGCONF_OS).
364AC_SUBST(VGCONF_ARCH_PRI)
365
366# VGCONF_ARCH_SEC is the arch for the secondary build target, eg. "x86".
367# It is passed in to compilation of many C files via -VGA_$(VGCONF_ARCH_SEC)
368# and -VGP_$(VGCONF_ARCH_SEC)_$(VGCONF_OS), if there is a secondary target.
369# It is empty if there is no secondary target.
370AC_SUBST(VGCONF_ARCH_SEC)
371
372# VGCONF_PLATFORM_PRI_CAPS is the primary build target, eg. "AMD64_LINUX".
373# The entire system, including regression and performance tests, will be
374# built for this target.  The "_CAPS" indicates that the name is in capital
375# letters, and it also uses '_' rather than '-' as a separator, because it's
376# used to create various Makefile variables, which are all in caps by
377# convention and cannot contain '-' characters.  This is in contrast to
378# VGCONF_ARCH_PRI and VGCONF_OS which are not in caps.
379AC_SUBST(VGCONF_PLATFORM_PRI_CAPS)
380
381# VGCONF_PLATFORM_SEC_CAPS is the secondary build target, if there is one.
382# Valgrind and tools will also be built for this target, but not the
383# regression or performance tests.
384#
385# By default, the primary arch is the same as the "max" arch, as commented
386# above (at the definition of ARCH_MAX).  We may choose to downgrade it in
387# the big case statement just below here, in the case where we're building
388# on a 64 bit machine but have been requested only to do a 32 bit build.
389AC_SUBST(VGCONF_PLATFORM_SEC_CAPS)
390
391AC_MSG_CHECKING([for a supported CPU/OS combination])
392
393# NB.  The load address for a given platform may be specified in more
394# than one place, in some cases, depending on whether we're doing a biarch,
395# 32-bit only or 64-bit only build.  eg see case for amd64-linux below.
396# Be careful to give consistent values in all subcases.  Also, all four
397# valt_load_addres_{pri,sec}_{norml,inner} values must always be set,
398# even if it is to "0xUNSET".
399#
400case "$ARCH_MAX-$VGCONF_OS" in
401     x86-linux)
402        VGCONF_ARCH_PRI="x86"
403        VGCONF_ARCH_SEC=""
404	VGCONF_PLATFORM_PRI_CAPS="X86_LINUX"
405	VGCONF_PLATFORM_SEC_CAPS=""
406        valt_load_address_pri_norml="0x38000000"
407        valt_load_address_pri_inner="0x28000000"
408        valt_load_address_sec_norml="0xUNSET"
409        valt_load_address_sec_inner="0xUNSET"
410        AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
411	;;
412     amd64-linux)
413        valt_load_address_sec_norml="0xUNSET"
414        valt_load_address_sec_inner="0xUNSET"
415	if test x$vg_cv_only64bit = xyes; then
416           VGCONF_ARCH_PRI="amd64"
417           VGCONF_ARCH_SEC=""
418	   VGCONF_PLATFORM_PRI_CAPS="AMD64_LINUX"
419	   VGCONF_PLATFORM_SEC_CAPS=""
420           valt_load_address_pri_norml="0x38000000"
421           valt_load_address_pri_inner="0x28000000"
422	elif test x$vg_cv_only32bit = xyes; then
423	   VGCONF_ARCH_PRI="x86"
424           VGCONF_ARCH_SEC=""
425	   VGCONF_PLATFORM_PRI_CAPS="X86_LINUX"
426	   VGCONF_PLATFORM_SEC_CAPS=""
427           valt_load_address_pri_norml="0x38000000"
428           valt_load_address_pri_inner="0x28000000"
429	else
430           VGCONF_ARCH_PRI="amd64"
431           VGCONF_ARCH_SEC="x86"
432	   VGCONF_PLATFORM_PRI_CAPS="AMD64_LINUX"
433	   VGCONF_PLATFORM_SEC_CAPS="X86_LINUX"
434           valt_load_address_pri_norml="0x38000000"
435           valt_load_address_pri_inner="0x28000000"
436           valt_load_address_sec_norml="0x38000000"
437           valt_load_address_sec_inner="0x28000000"
438	fi
439        AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
440	;;
441     ppc32-linux)
442        VGCONF_ARCH_PRI="ppc32"
443        VGCONF_ARCH_SEC=""
444	VGCONF_PLATFORM_PRI_CAPS="PPC32_LINUX"
445	VGCONF_PLATFORM_SEC_CAPS=""
446        valt_load_address_pri_norml="0x38000000"
447        valt_load_address_pri_inner="0x28000000"
448        valt_load_address_sec_norml="0xUNSET"
449        valt_load_address_sec_inner="0xUNSET"
450        AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
451	;;
452     ppc64-linux)
453        valt_load_address_sec_norml="0xUNSET"
454        valt_load_address_sec_inner="0xUNSET"
455	if test x$vg_cv_only64bit = xyes; then
456	   VGCONF_ARCH_PRI="ppc64"
457           VGCONF_ARCH_SEC=""
458	   VGCONF_PLATFORM_PRI_CAPS="PPC64_LINUX"
459	   VGCONF_PLATFORM_SEC_CAPS=""
460           valt_load_address_pri_norml="0x38000000"
461           valt_load_address_pri_inner="0x28000000"
462	elif test x$vg_cv_only32bit = xyes; then
463	   VGCONF_ARCH_PRI="ppc32"
464           VGCONF_ARCH_SEC=""
465	   VGCONF_PLATFORM_PRI_CAPS="PPC32_LINUX"
466	   VGCONF_PLATFORM_SEC_CAPS=""
467           valt_load_address_pri_norml="0x38000000"
468           valt_load_address_pri_inner="0x28000000"
469	else
470	   VGCONF_ARCH_PRI="ppc64"
471           VGCONF_ARCH_SEC="ppc32"
472	   VGCONF_PLATFORM_PRI_CAPS="PPC64_LINUX"
473	   VGCONF_PLATFORM_SEC_CAPS="PPC32_LINUX"
474           valt_load_address_pri_norml="0x38000000"
475           valt_load_address_pri_inner="0x28000000"
476           valt_load_address_sec_norml="0x38000000"
477           valt_load_address_sec_inner="0x28000000"
478	fi
479        AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
480	;;
481     # Darwin gets identified as 32-bit even when it supports 64-bit.
482     # (Not sure why, possibly because 'uname' returns "i386"?)  Just about
483     # all Macs support both 32-bit and 64-bit, so we just build both.  If
484     # someone has a really old 32-bit only machine they can (hopefully?)
485     # build with --enable-only32bit.  See bug 243362.
486     x86-darwin|amd64-darwin)
487        ARCH_MAX="amd64"
488        valt_load_address_sec_norml="0xUNSET"
489        valt_load_address_sec_inner="0xUNSET"
490	if test x$vg_cv_only64bit = xyes; then
491           VGCONF_ARCH_PRI="amd64"
492           VGCONF_ARCH_SEC=""
493	   VGCONF_PLATFORM_PRI_CAPS="AMD64_DARWIN"
494	   VGCONF_PLATFORM_SEC_CAPS=""
495           valt_load_address_pri_norml="0x138000000"
496           valt_load_address_pri_inner="0x128000000"
497	elif test x$vg_cv_only32bit = xyes; then
498           VGCONF_ARCH_PRI="x86"
499           VGCONF_ARCH_SEC=""
500	   VGCONF_PLATFORM_PRI_CAPS="X86_DARWIN"
501	   VGCONF_PLATFORM_SEC_CAPS=""
502	   VGCONF_ARCH_PRI_CAPS="x86"
503           valt_load_address_pri_norml="0x38000000"
504           valt_load_address_pri_inner="0x28000000"
505	else
506           VGCONF_ARCH_PRI="amd64"
507           VGCONF_ARCH_SEC="x86"
508	   VGCONF_PLATFORM_PRI_CAPS="AMD64_DARWIN"
509	   VGCONF_PLATFORM_SEC_CAPS="X86_DARWIN"
510           valt_load_address_pri_norml="0x138000000"
511           valt_load_address_pri_inner="0x128000000"
512           valt_load_address_sec_norml="0x38000000"
513           valt_load_address_sec_inner="0x28000000"
514	fi
515        AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
516	;;
517     arm-linux)
518	VGCONF_ARCH_PRI="arm"
519	VGCONF_PLATFORM_PRI_CAPS="ARM_LINUX"
520	VGCONF_PLATFORM_SEC_CAPS=""
521	valt_load_address_pri_norml="0x38000000"
522	valt_load_address_pri_inner="0x28000000"
523        valt_load_address_sec_norml="0xUNSET"
524        valt_load_address_sec_inner="0xUNSET"
525	AC_MSG_RESULT([ok (${host_cpu}-${host_os})])
526	;;
527     s390x-linux)
528        VGCONF_ARCH_PRI="s390x"
529        VGCONF_ARCH_SEC=""
530        VGCONF_PLATFORM_PRI_CAPS="S390X_LINUX"
531        VGCONF_PLATFORM_SEC_CAPS=""
532        # we want to have the generated code close to the dispatcher
533        valt_load_address_pri_norml="0x401000000"
534        valt_load_address_pri_inner="0x410000000"
535        valt_load_address_sec_norml="0xUNSET"
536        valt_load_address_sec_inner="0xUNSET"
537        AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
538        ;;
539    *)
540        VGCONF_ARCH_PRI="unknown"
541        VGCONF_ARCH_SEC="unknown"
542	VGCONF_PLATFORM_PRI_CAPS="UNKNOWN"
543	VGCONF_PLATFORM_SEC_CAPS="UNKNOWN"
544        valt_load_address_pri_norml="0xUNSET"
545        valt_load_address_pri_inner="0xUNSET"
546        valt_load_address_sec_norml="0xUNSET"
547        valt_load_address_sec_inner="0xUNSET"
548        AC_MSG_RESULT([no (${ARCH_MAX}-${VGCONF_OS})])
549        AC_MSG_ERROR([Valgrind is platform specific. Sorry. Please consider doing a port.])
550        ;;
551esac
552
553#----------------------------------------------------------------------------
554
555# Set up VGCONF_ARCHS_INCLUDE_<arch>.  Either one or two of these become
556# defined.
557AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_X86,
558               test x$VGCONF_PLATFORM_PRI_CAPS = xX86_LINUX \
559                 -o x$VGCONF_PLATFORM_SEC_CAPS = xX86_LINUX \
560                 -o x$VGCONF_PLATFORM_PRI_CAPS = xX86_DARWIN \
561                 -o x$VGCONF_PLATFORM_SEC_CAPS = xX86_DARWIN )
562AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_AMD64,
563               test x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_LINUX \
564                 -o x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_DARWIN )
565AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_PPC32,
566               test x$VGCONF_PLATFORM_PRI_CAPS = xPPC32_LINUX \
567                 -o x$VGCONF_PLATFORM_SEC_CAPS = xPPC32_LINUX )
568AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_PPC64,
569               test x$VGCONF_PLATFORM_PRI_CAPS = xPPC64_LINUX )
570AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_ARM,
571               test x$VGCONF_PLATFORM_PRI_CAPS = xARM_LINUX )
572AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_S390X,
573               test x$VGCONF_PLATFORM_PRI_CAPS = xS390X_LINUX )
574
575# Set up VGCONF_PLATFORMS_INCLUDE_<platform>.  Either one or two of these
576# become defined.
577AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_X86_LINUX,
578               test x$VGCONF_PLATFORM_PRI_CAPS = xX86_LINUX \
579                 -o x$VGCONF_PLATFORM_SEC_CAPS = xX86_LINUX)
580AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_AMD64_LINUX,
581               test x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_LINUX)
582AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_PPC32_LINUX,
583               test x$VGCONF_PLATFORM_PRI_CAPS = xPPC32_LINUX \
584                 -o x$VGCONF_PLATFORM_SEC_CAPS = xPPC32_LINUX)
585AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_PPC64_LINUX,
586               test x$VGCONF_PLATFORM_PRI_CAPS = xPPC64_LINUX)
587AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_ARM_LINUX,
588               test x$VGCONF_PLATFORM_PRI_CAPS = xARM_LINUX)
589AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_S390X_LINUX,
590               test x$VGCONF_PLATFORM_PRI_CAPS = xS390X_LINUX \
591                 -o x$VGCONF_PLATFORM_SEC_CAPS = xS390X_LINUX)
592
593AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_X86_DARWIN,
594               test x$VGCONF_PLATFORM_PRI_CAPS = xX86_DARWIN \
595                 -o x$VGCONF_PLATFORM_SEC_CAPS = xX86_DARWIN)
596AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_AMD64_DARWIN,
597               test x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_DARWIN)
598
599
600# Similarly, set up VGCONF_OS_IS_<os>.  Exactly one of these becomes defined.
601# Relies on the assumption that the primary and secondary targets are
602# for the same OS, so therefore only necessary to test the primary.
603AM_CONDITIONAL(VGCONF_OS_IS_LINUX,
604               test x$VGCONF_PLATFORM_PRI_CAPS = xX86_LINUX \
605                 -o x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_LINUX \
606                 -o x$VGCONF_PLATFORM_PRI_CAPS = xPPC32_LINUX \
607                 -o x$VGCONF_PLATFORM_PRI_CAPS = xPPC64_LINUX \
608                 -o x$VGCONF_PLATFORM_PRI_CAPS = xARM_LINUX \
609                 -o x$VGCONF_PLATFORM_PRI_CAPS = xS390X_LINUX)
610AM_CONDITIONAL(VGCONF_OS_IS_DARWIN,
611               test x$VGCONF_PLATFORM_PRI_CAPS = xX86_DARWIN \
612                 -o x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_DARWIN)
613
614
615# Sometimes, in the Makefile.am files, it's useful to know whether or not
616# there is a secondary target.
617AM_CONDITIONAL(VGCONF_HAVE_PLATFORM_SEC,
618               test x$VGCONF_PLATFORM_SEC_CAPS != x)
619
620
621#----------------------------------------------------------------------------
622# Inner Valgrind?
623#----------------------------------------------------------------------------
624
625# Check if this should be built as an inner Valgrind, to be run within
626# another Valgrind.  Choose the load address accordingly.
627AC_SUBST(VALT_LOAD_ADDRESS_PRI)
628AC_SUBST(VALT_LOAD_ADDRESS_SEC)
629AC_CACHE_CHECK([for use as an inner Valgrind], vg_cv_inner,
630   [AC_ARG_ENABLE(inner,
631      [  --enable-inner          enables self-hosting],
632      [vg_cv_inner=$enableval],
633      [vg_cv_inner=no])])
634if test "$vg_cv_inner" = yes; then
635    AC_DEFINE([ENABLE_INNER], 1, [configured to run as an inner Valgrind])
636    VALT_LOAD_ADDRESS_PRI=$valt_load_address_pri_inner
637    VALT_LOAD_ADDRESS_SEC=$valt_load_address_sec_inner
638else
639    VALT_LOAD_ADDRESS_PRI=$valt_load_address_pri_norml
640    VALT_LOAD_ADDRESS_SEC=$valt_load_address_sec_norml
641fi
642
643
644#----------------------------------------------------------------------------
645# Extra fine-tuning of installation directories
646#----------------------------------------------------------------------------
647AC_ARG_WITH(tmpdir,
648   [  --with-tmpdir=PATH      Specify path for temporary files],
649   tmpdir="$withval",
650   tmpdir="/tmp")
651AC_DEFINE_UNQUOTED(VG_TMPDIR, "$tmpdir", [Temporary files directory])
652
653
654#----------------------------------------------------------------------------
655# Libc and suppressions
656#----------------------------------------------------------------------------
657# This variable will collect the suppression files to be used.
658AC_SUBST(DEFAULT_SUPP)
659
660AC_CHECK_HEADER([features.h])
661
662if test x$ac_cv_header_features_h = xyes; then
663  rm -f conftest.$ac_ext
664  cat <<_ACEOF >conftest.$ac_ext
665#include <features.h>
666#if defined(__GNU_LIBRARY__) && defined(__GLIBC__) && defined(__GLIBC_MINOR__)
667glibc version is: __GLIBC__ __GLIBC_MINOR__
668#endif
669_ACEOF
670  GLIBC_VERSION="`$CPP conftest.$ac_ext | $SED -n 's/^glibc version is: //p' | $SED 's/ /./g'`"
671fi
672
673# not really a version check
674AC_EGREP_CPP([DARWIN_LIBC], [
675#include <sys/cdefs.h>
676#if defined(__DARWIN_VERS_1050)
677  DARWIN_LIBC
678#endif
679],
680GLIBC_VERSION="darwin")
681
682# not really a version check
683AC_EGREP_CPP([BIONIC_LIBC], [
684#if defined(__ANDROID__)
685  BIONIC_LIBC
686#endif
687],
688GLIBC_VERSION="bionic")
689
690
691AC_MSG_CHECKING([the GLIBC_VERSION version])
692
693case "${GLIBC_VERSION}" in
694     2.2)
695	AC_MSG_RESULT(2.2 family)
696	AC_DEFINE([GLIBC_2_2], 1, [Define to 1 if you're using glibc 2.2.x])
697	DEFAULT_SUPP="glibc-2.2.supp ${DEFAULT_SUPP}"
698	DEFAULT_SUPP="glibc-2.2-LinuxThreads-helgrind.supp ${DEFAULT_SUPP}"
699	DEFAULT_SUPP="glibc-2.X-drd.supp ${DEFAULT_SUPP}"
700	;;
701
702     2.3)
703	AC_MSG_RESULT(2.3 family)
704	AC_DEFINE([GLIBC_2_3], 1, [Define to 1 if you're using glibc 2.3.x])
705	DEFAULT_SUPP="glibc-2.3.supp ${DEFAULT_SUPP}"
706	DEFAULT_SUPP="glibc-2.34567-NPTL-helgrind.supp ${DEFAULT_SUPP}"
707	DEFAULT_SUPP="glibc-2.X-drd.supp ${DEFAULT_SUPP}"
708	;;
709
710     2.4)
711	AC_MSG_RESULT(2.4 family)
712	AC_DEFINE([GLIBC_2_4], 1, [Define to 1 if you're using glibc 2.4.x])
713	DEFAULT_SUPP="glibc-2.4.supp ${DEFAULT_SUPP}"
714	DEFAULT_SUPP="glibc-2.34567-NPTL-helgrind.supp ${DEFAULT_SUPP}"
715	DEFAULT_SUPP="glibc-2.X-drd.supp ${DEFAULT_SUPP}"
716	;;
717
718     2.5)
719	AC_MSG_RESULT(2.5 family)
720	AC_DEFINE([GLIBC_2_5], 1, [Define to 1 if you're using glibc 2.5.x])
721	DEFAULT_SUPP="glibc-2.5.supp ${DEFAULT_SUPP}"
722	DEFAULT_SUPP="glibc-2.34567-NPTL-helgrind.supp ${DEFAULT_SUPP}"
723	DEFAULT_SUPP="glibc-2.X-drd.supp ${DEFAULT_SUPP}"
724	;;
725     2.6)
726	AC_MSG_RESULT(2.6 family)
727	AC_DEFINE([GLIBC_2_6], 1, [Define to 1 if you're using glibc 2.6.x])
728	DEFAULT_SUPP="glibc-2.6.supp ${DEFAULT_SUPP}"
729	DEFAULT_SUPP="glibc-2.34567-NPTL-helgrind.supp ${DEFAULT_SUPP}"
730	DEFAULT_SUPP="glibc-2.X-drd.supp ${DEFAULT_SUPP}"
731	;;
732     2.7)
733	AC_MSG_RESULT(2.7 family)
734	AC_DEFINE([GLIBC_2_7], 1, [Define to 1 if you're using glibc 2.7.x])
735	DEFAULT_SUPP="glibc-2.X.supp ${DEFAULT_SUPP}"
736	DEFAULT_SUPP="glibc-2.34567-NPTL-helgrind.supp ${DEFAULT_SUPP}"
737	DEFAULT_SUPP="glibc-2.X-drd.supp ${DEFAULT_SUPP}"
738	;;
739     2.8)
740	AC_MSG_RESULT(2.8 family)
741	AC_DEFINE([GLIBC_2_8], 1, [Define to 1 if you're using glibc 2.8.x])
742	DEFAULT_SUPP="glibc-2.X.supp ${DEFAULT_SUPP}"
743	DEFAULT_SUPP="glibc-2.34567-NPTL-helgrind.supp ${DEFAULT_SUPP}"
744	DEFAULT_SUPP="glibc-2.X-drd.supp ${DEFAULT_SUPP}"
745	;;
746     2.9)
747	AC_MSG_RESULT(2.9 family)
748	AC_DEFINE([GLIBC_2_9], 1, [Define to 1 if you're using glibc 2.9.x])
749	DEFAULT_SUPP="glibc-2.X.supp ${DEFAULT_SUPP}"
750	DEFAULT_SUPP="glibc-2.34567-NPTL-helgrind.supp ${DEFAULT_SUPP}"
751	DEFAULT_SUPP="glibc-2.X-drd.supp ${DEFAULT_SUPP}"
752	;;
753     2.10)
754	AC_MSG_RESULT(2.10 family)
755	AC_DEFINE([GLIBC_2_10], 1, [Define to 1 if you're using glibc 2.10.x])
756	DEFAULT_SUPP="glibc-2.X.supp ${DEFAULT_SUPP}"
757	DEFAULT_SUPP="glibc-2.34567-NPTL-helgrind.supp ${DEFAULT_SUPP}"
758	DEFAULT_SUPP="glibc-2.X-drd.supp ${DEFAULT_SUPP}"
759	;;
760     2.11)
761	AC_MSG_RESULT(2.11 family)
762	AC_DEFINE([GLIBC_2_11], 1, [Define to 1 if you're using glibc 2.11.x])
763	DEFAULT_SUPP="glibc-2.X.supp ${DEFAULT_SUPP}"
764	DEFAULT_SUPP="glibc-2.34567-NPTL-helgrind.supp ${DEFAULT_SUPP}"
765	DEFAULT_SUPP="glibc-2.X-drd.supp ${DEFAULT_SUPP}"
766        ;;
767     2.12)
768	AC_MSG_RESULT(2.12 family)
769	AC_DEFINE([GLIBC_2_12], 1, [Define to 1 if you're using glibc 2.12.x])
770	DEFAULT_SUPP="glibc-2.X.supp ${DEFAULT_SUPP}"
771	DEFAULT_SUPP="glibc-2.34567-NPTL-helgrind.supp ${DEFAULT_SUPP}"
772	DEFAULT_SUPP="glibc-2.X-drd.supp ${DEFAULT_SUPP}"
773	;;
774     2.13)
775	AC_MSG_RESULT(2.13 family)
776	AC_DEFINE([GLIBC_2_13], 1, [Define to 1 if you're using glibc 2.13.x])
777	DEFAULT_SUPP="glibc-2.X.supp ${DEFAULT_SUPP}"
778	DEFAULT_SUPP="glibc-2.34567-NPTL-helgrind.supp ${DEFAULT_SUPP}"
779	DEFAULT_SUPP="glibc-2.X-drd.supp ${DEFAULT_SUPP}"
780	;;
781     2.14)
782	AC_MSG_RESULT(2.14 family)
783	AC_DEFINE([GLIBC_2_14], 1, [Define to 1 if you're using glibc 2.14.x])
784	DEFAULT_SUPP="glibc-2.X.supp ${DEFAULT_SUPP}"
785	DEFAULT_SUPP="glibc-2.34567-NPTL-helgrind.supp ${DEFAULT_SUPP}"
786	DEFAULT_SUPP="glibc-2.X-drd.supp ${DEFAULT_SUPP}"
787	;;
788     darwin)
789	AC_MSG_RESULT(Darwin)
790	AC_DEFINE([DARWIN_LIBC], 1, [Define to 1 if you're using Darwin])
791	# DEFAULT_SUPP set by kernel version check above.
792	;;
793     bionic)
794	AC_MSG_RESULT(Bionic)
795	AC_DEFINE([BIONIC_LIBC], 1, [Define to 1 if you're using Bionic])
796	DEFAULT_SUPP="bionic.supp ${DEFAULT_SUPP}"
797	;;
798
799     *)
800	AC_MSG_RESULT([unsupported version ${GLIBC_VERSION}])
801	AC_MSG_ERROR([Valgrind requires glibc version 2.2 - 2.14])
802	AC_MSG_ERROR([or Darwin libc])
803	;;
804esac
805
806AC_SUBST(GLIBC_VERSION)
807
808if test x$ac_cv_header_features_h = xyes; then
809  rm -f conftest.$ac_ext
810  cat <<_ACEOF >conftest.$ac_ext
811#include <features.h>
812#if defined(__GNU_LIBRARY__) && defined(__GLIBC__) && defined(__GLIBC_MINOR__)
813glibc major version is: __GLIBC__
814#endif
815_ACEOF
816  GLIBC_MAJOR="`$CPP conftest.$ac_ext | $SED -n 's/^glibc major version is: //p'`"
817fi
818
819AC_MSG_CHECKING([the GLIBC_MAJOR version])
820
821case "${GLIBC_MAJOR}" in
822     2)
823	AC_MSG_RESULT(2.X family)
824	AC_DEFINE([GLIBC_2_X], 1, [Define to 1 if you're using glibc 2.x.x])
825	DEFAULT_SUPP="glibc-X.X.supp ${DEFAULT_SUPP}"
826	;;
827     *)
828	;;
829esac
830
831AC_SUBST(GLIBC_MAJOR)
832
833
834# Add default suppressions for the X client libraries.  Make no
835# attempt to detect whether such libraries are installed on the
836# build machine (or even if any X facilities are present); just
837# add the suppressions antidisirregardless.
838DEFAULT_SUPP="xfree-4.supp ${DEFAULT_SUPP}"
839DEFAULT_SUPP="xfree-3.supp ${DEFAULT_SUPP}"
840
841# Add glibc and X11 suppressions for exp-sgcheck
842DEFAULT_SUPP="exp-sgcheck.supp ${DEFAULT_SUPP}"
843
844
845#----------------------------------------------------------------------------
846# Platform variants?
847#----------------------------------------------------------------------------
848
849# Normally the PLAT = (ARCH, OS) characterisation of the platform is enough.
850# But there are times where we need a bit more control.  The motivating
851# and currently only case is Android: this is almost identical to arm-linux,
852# but not quite.  So this introduces the concept of platform variant tags,
853# which get passed in the compile as -DVGPV_<arch>_<os>_<variant> along
854# with the main -DVGP_<arch>_<os> definition.
855#
856# In almost all cases, the <variant> bit is "vanilla".  But for Android
857# it is "android" instead.
858#
859# Consequently (eg), plain arm-linux would build with
860#
861#   -DVGP_arm_linux -DVGPV_arm_linux_vanilla
862#
863# whilst an Android build would have
864#
865#   -DVGP_arm_linux -DVGPV_arm_linux_android
866#
867# The setup of the platform variant is pushed relatively far down this
868# file in order that we can inspect any of the variables set above.
869
870# In the normal case ..
871VGCONF_PLATVARIANT="vanilla"
872
873# Android on ARM ?
874if test "$VGCONF_ARCH_PRI-$VGCONF_OS" = "arm-linux" \
875        -a "$GLIBC_VERSION" = "bionic";
876then
877   VGCONF_PLATVARIANT="android"
878fi
879
880AC_SUBST(VGCONF_PLATVARIANT)
881
882
883# FIXME: do we also want to define automake variables
884# VGCONF_PLATVARIANT_IS_<WHATEVER>, where WHATEVER is (currently)
885# VANILLA or ANDROID ?  This would be in the style of VGCONF_ARCHS_INCLUDE,
886# VGCONF_PLATFORMS_INCLUDE and VGCONF_OS_IS above?  Could easily enough
887# do that.  Problem is that we can't do and-ing in Makefile.am's, but
888# that's what we'd need to do to use this, since what we'd want to write
889# is something like
890#
891# VGCONF_PLATFORMS_INCLUDE_ARM_LINUX && VGCONF_PLATVARIANT_IS_ANDROID
892#
893# Hmm.  Can't think of a nice clean solution to this.
894
895AM_CONDITIONAL(VGCONF_PLATVARIANT_IS_VANILLA,
896               test x$VGCONF_PLATVARIANT = xvanilla)
897AM_CONDITIONAL(VGCONF_PLATVARIANT_IS_ANDROID,
898               test x$VGCONF_PLATVARIANT = xandroid)
899
900
901#----------------------------------------------------------------------------
902# Checking for various library functions and other definitions
903#----------------------------------------------------------------------------
904
905# Check for CLOCK_MONOTONIC
906
907AC_MSG_CHECKING([for CLOCK_MONOTONIC])
908
909AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
910#include <time.h>
911]], [[
912  struct timespec t;
913  clock_gettime(CLOCK_MONOTONIC, &t);
914  return 0;
915]])], [
916AC_MSG_RESULT([yes])
917AC_DEFINE([HAVE_CLOCK_MONOTONIC], 1,
918          [Define to 1 if you have the `CLOCK_MONOTONIC' constant.])
919], [
920AC_MSG_RESULT([no])
921])
922
923
924# Check for PTHREAD_RWLOCK_T
925
926AC_MSG_CHECKING([for pthread_rwlock_t])
927
928AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
929#define _GNU_SOURCE
930#include <pthread.h>
931]], [[
932  pthread_rwlock_t rwl;
933]])], [
934AC_MSG_RESULT([yes])
935AC_DEFINE([HAVE_PTHREAD_RWLOCK_T], 1,
936          [Define to 1 if you have the `pthread_rwlock_t' type.])
937], [
938AC_MSG_RESULT([no])
939])
940
941
942# Check for PTHREAD_MUTEX_ADAPTIVE_NP
943
944AC_MSG_CHECKING([for PTHREAD_MUTEX_ADAPTIVE_NP])
945
946AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
947#define _GNU_SOURCE
948#include <pthread.h>
949]], [[
950  return (PTHREAD_MUTEX_ADAPTIVE_NP);
951]])], [
952AC_MSG_RESULT([yes])
953AC_DEFINE([HAVE_PTHREAD_MUTEX_ADAPTIVE_NP], 1,
954          [Define to 1 if you have the `PTHREAD_MUTEX_ADAPTIVE_NP' constant.])
955], [
956AC_MSG_RESULT([no])
957])
958
959
960# Check for PTHREAD_MUTEX_ERRORCHECK_NP
961
962AC_MSG_CHECKING([for PTHREAD_MUTEX_ERRORCHECK_NP])
963
964AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
965#define _GNU_SOURCE
966#include <pthread.h>
967]], [[
968  return (PTHREAD_MUTEX_ERRORCHECK_NP);
969]])], [
970AC_MSG_RESULT([yes])
971AC_DEFINE([HAVE_PTHREAD_MUTEX_ERRORCHECK_NP], 1,
972          [Define to 1 if you have the `PTHREAD_MUTEX_ERRORCHECK_NP' constant.])
973], [
974AC_MSG_RESULT([no])
975])
976
977
978# Check for PTHREAD_MUTEX_RECURSIVE_NP
979
980AC_MSG_CHECKING([for PTHREAD_MUTEX_RECURSIVE_NP])
981
982AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
983#define _GNU_SOURCE
984#include <pthread.h>
985]], [[
986  return (PTHREAD_MUTEX_RECURSIVE_NP);
987]])], [
988AC_MSG_RESULT([yes])
989AC_DEFINE([HAVE_PTHREAD_MUTEX_RECURSIVE_NP], 1,
990          [Define to 1 if you have the `PTHREAD_MUTEX_RECURSIVE_NP' constant.])
991], [
992AC_MSG_RESULT([no])
993])
994
995
996# Check for PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
997
998AC_MSG_CHECKING([for PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP])
999
1000AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1001#define _GNU_SOURCE
1002#include <pthread.h>
1003]], [[
1004  pthread_mutex_t m = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
1005  return 0;
1006]])], [
1007AC_MSG_RESULT([yes])
1008AC_DEFINE([HAVE_PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP], 1,
1009          [Define to 1 if you have the `PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP' constant.])
1010], [
1011AC_MSG_RESULT([no])
1012])
1013
1014
1015# Check whether pthread_mutex_t has a member called __m_kind.
1016
1017AC_CHECK_MEMBER([pthread_mutex_t.__m_kind],
1018	        [AC_DEFINE([HAVE_PTHREAD_MUTEX_T__M_KIND],
1019		           1,
1020			   [Define to 1 if pthread_mutex_t has a member called __m_kind.])
1021                ],
1022		[],
1023		[#include <pthread.h>])
1024
1025
1026# Check whether pthread_mutex_t has a member called __data.__kind.
1027
1028AC_CHECK_MEMBER([pthread_mutex_t.__data.__kind],
1029                [AC_DEFINE([HAVE_PTHREAD_MUTEX_T__DATA__KIND],
1030		          1,
1031			  [Define to 1 if pthread_mutex_t has a member __data.__kind.])
1032                ],
1033		[],
1034		[#include <pthread.h>])
1035
1036
1037# does this compiler support -maltivec and does it have the include file
1038# <altivec.h> ?
1039
1040AC_MSG_CHECKING([for Altivec])
1041
1042safe_CFLAGS=$CFLAGS
1043CFLAGS="-maltivec"
1044
1045AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1046#include <altivec.h>
1047]], [[
1048  vector unsigned int v;
1049]])], [
1050ac_have_altivec=yes
1051AC_MSG_RESULT([yes])
1052AC_DEFINE([HAS_ALTIVEC], 1,
1053          [Define to 1 if gcc/as can do Altivec.])
1054], [
1055ac_have_altivec=no
1056AC_MSG_RESULT([no])
1057])
1058CFLAGS=$safe_CFLAGS
1059
1060AM_CONDITIONAL([HAS_ALTIVEC], [test x$ac_have_altivec = xyes])
1061
1062
1063# Check that both: the compiler supports -mvsx and that the assembler
1064# understands VSX instructions.  If either of those doesn't work,
1065# conclude that we can't do VSX.  NOTE: basically this is a kludge
1066# in that it conflates two things that should be separate -- whether
1067# the compiler understands the flag vs whether the assembler
1068# understands the opcodes.  This really ought to be cleaned up
1069# and done properly, like it is for x86/x86_64.
1070
1071AC_MSG_CHECKING([for VSX])
1072
1073safe_CFLAGS=$CFLAGS
1074CFLAGS="-mvsx"
1075
1076AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1077#include <altivec.h>
1078]], [[
1079  vector unsigned int v;
1080  __asm__ __volatile__("xsmaddadp 32, 32, 33" ::: "memory","cc");
1081]])], [
1082ac_have_vsx=yes
1083AC_MSG_RESULT([yes])
1084], [
1085ac_have_vsx=no
1086AC_MSG_RESULT([no])
1087])
1088CFLAGS=$safe_CFLAGS
1089
1090AM_CONDITIONAL(HAS_VSX, test x$ac_have_vsx = xyes)
1091
1092
1093# Check for pthread_create@GLIBC2.0
1094AC_MSG_CHECKING([for pthread_create@GLIBC2.0()])
1095
1096safe_CFLAGS=$CFLAGS
1097CFLAGS="-lpthread"
1098AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1099extern int pthread_create_glibc_2_0(void*, const void*,
1100                                    void *(*)(void*), void*);
1101__asm__(".symver pthread_create_glibc_2_0, pthread_create@GLIBC_2.0");
1102]], [[
1103#ifdef __powerpc__
1104/*
1105 * Apparently on PowerPC linking this program succeeds and generates an
1106 * executable with the undefined symbol pthread_create@GLIBC_2.0.
1107 */
1108#error This test does not work properly on PowerPC.
1109#else
1110  pthread_create_glibc_2_0(0, 0, 0, 0);
1111#endif
1112  return 0;
1113]])], [
1114ac_have_pthread_create_glibc_2_0=yes
1115AC_MSG_RESULT([yes])
1116AC_DEFINE([HAVE_PTHREAD_CREATE_GLIBC_2_0], 1,
1117          [Define to 1 if you have the `pthread_create@glibc2.0' function.])
1118], [
1119ac_have_pthread_create_glibc_2_0=no
1120AC_MSG_RESULT([no])
1121])
1122CFLAGS=$safe_CFLAGS
1123
1124AM_CONDITIONAL(HAVE_PTHREAD_CREATE_GLIBC_2_0,
1125	       test x$ac_have_pthread_create_glibc_2_0 = xyes)
1126
1127
1128# Check for eventfd_t, eventfd() and eventfd_read()
1129AC_MSG_CHECKING([for eventfd()])
1130
1131AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1132#include <sys/eventfd.h>
1133]], [[
1134  eventfd_t ev;
1135  int fd;
1136
1137  fd = eventfd(5, 0);
1138  eventfd_read(fd, &ev);
1139  return 0;
1140]])], [
1141AC_MSG_RESULT([yes])
1142AC_DEFINE([HAVE_EVENTFD], 1,
1143          [Define to 1 if you have the `eventfd' function.])
1144AC_DEFINE([HAVE_EVENTFD_READ], 1,
1145          [Define to 1 if you have the `eventfd_read' function.])
1146], [
1147AC_MSG_RESULT([no])
1148])
1149
1150
1151#----------------------------------------------------------------------------
1152# Checking for supported compiler flags.
1153#----------------------------------------------------------------------------
1154
1155# does this compiler support -m32 ?
1156AC_MSG_CHECKING([if gcc accepts -m32])
1157
1158safe_CFLAGS=$CFLAGS
1159CFLAGS="-m32"
1160
1161AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
1162  return 0;
1163]])], [
1164FLAG_M32="-m32"
1165AC_MSG_RESULT([yes])
1166], [
1167FLAG_M32=""
1168AC_MSG_RESULT([no])
1169])
1170CFLAGS=$safe_CFLAGS
1171
1172AC_SUBST(FLAG_M32)
1173
1174
1175# does this compiler support -m64 ?
1176AC_MSG_CHECKING([if gcc accepts -m64])
1177
1178safe_CFLAGS=$CFLAGS
1179CFLAGS="-m64"
1180
1181AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
1182  return 0;
1183]])], [
1184FLAG_M64="-m64"
1185AC_MSG_RESULT([yes])
1186], [
1187FLAG_M64=""
1188AC_MSG_RESULT([no])
1189])
1190CFLAGS=$safe_CFLAGS
1191
1192AC_SUBST(FLAG_M64)
1193
1194
1195# does this compiler support -mmmx ?
1196AC_MSG_CHECKING([if gcc accepts -mmmx])
1197
1198safe_CFLAGS=$CFLAGS
1199CFLAGS="-mmmx"
1200
1201AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
1202  return 0;
1203]])], [
1204FLAG_MMMX="-mmmx"
1205AC_MSG_RESULT([yes])
1206], [
1207FLAG_MMMX=""
1208AC_MSG_RESULT([no])
1209])
1210CFLAGS=$safe_CFLAGS
1211
1212AC_SUBST(FLAG_MMMX)
1213
1214
1215# does this compiler support -msse ?
1216AC_MSG_CHECKING([if gcc accepts -msse])
1217
1218safe_CFLAGS=$CFLAGS
1219CFLAGS="-msse"
1220
1221AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
1222  return 0;
1223]])], [
1224FLAG_MSSE="-msse"
1225AC_MSG_RESULT([yes])
1226], [
1227FLAG_MSSE=""
1228AC_MSG_RESULT([no])
1229])
1230CFLAGS=$safe_CFLAGS
1231
1232AC_SUBST(FLAG_MSSE)
1233
1234
1235# does this compiler support -mpreferred-stack-boundary=2 ?
1236AC_MSG_CHECKING([if gcc accepts -mpreferred-stack-boundary])
1237
1238safe_CFLAGS=$CFLAGS
1239CFLAGS="-mpreferred-stack-boundary=2"
1240
1241AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
1242  return 0;
1243]])], [
1244PREFERRED_STACK_BOUNDARY="-mpreferred-stack-boundary=2"
1245AC_MSG_RESULT([yes])
1246], [
1247PREFERRED_STACK_BOUNDARY=""
1248AC_MSG_RESULT([no])
1249])
1250CFLAGS=$safe_CFLAGS
1251
1252AC_SUBST(PREFERRED_STACK_BOUNDARY)
1253
1254
1255# does this compiler support -Wno-pointer-sign ?
1256AC_MSG_CHECKING([if gcc accepts -Wno-pointer-sign])
1257
1258safe_CFLAGS=$CFLAGS
1259CFLAGS="-Wno-pointer-sign"
1260
1261AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
1262  return 0;
1263]])], [
1264no_pointer_sign=yes
1265AC_MSG_RESULT([yes])
1266], [
1267no_pointer_sign=no
1268AC_MSG_RESULT([no])
1269])
1270CFLAGS=$safe_CFLAGS
1271
1272if test x$no_pointer_sign = xyes; then
1273  CFLAGS="$CFLAGS -Wno-pointer-sign"
1274fi
1275
1276
1277# does this compiler support -Wno-empty-body ?
1278
1279AC_MSG_CHECKING([if gcc accepts -Wno-empty-body])
1280
1281safe_CFLAGS=$CFLAGS
1282CFLAGS="-Wno-empty-body"
1283
1284AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
1285  return 0;
1286]])], [
1287AC_SUBST([FLAG_W_NO_EMPTY_BODY], [-Wno-empty-body])
1288AC_MSG_RESULT([yes])
1289], [
1290AC_SUBST([FLAG_W_NO_EMPTY_BODY], [])
1291AC_MSG_RESULT([no])
1292])
1293CFLAGS=$safe_CFLAGS
1294
1295
1296# does this compiler support -Wno-format-zero-length ?
1297
1298AC_MSG_CHECKING([if gcc accepts -Wno-format-zero-length])
1299
1300safe_CFLAGS=$CFLAGS
1301CFLAGS="-Wno-format-zero-length"
1302
1303AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
1304  return 0;
1305]])], [
1306AC_SUBST([FLAG_W_NO_FORMAT_ZERO_LENGTH], [-Wno-format-zero-length])
1307AC_MSG_RESULT([yes])
1308], [
1309AC_SUBST([FLAG_W_NO_FORMAT_ZERO_LENGTH], [])
1310AC_MSG_RESULT([no])
1311])
1312CFLAGS=$safe_CFLAGS
1313
1314
1315# does this compiler support -Wno-nonnull ?
1316
1317AC_MSG_CHECKING([if gcc accepts -Wno-nonnull])
1318
1319safe_CFLAGS=$CFLAGS
1320CFLAGS="-Wno-nonnull"
1321
1322AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
1323  return 0;
1324]])], [
1325AC_SUBST([FLAG_W_NO_NONNULL], [-Wno-nonnull])
1326AC_MSG_RESULT([yes])
1327], [
1328AC_SUBST([FLAG_W_NO_NONNULL], [])
1329AC_MSG_RESULT([no])
1330])
1331CFLAGS=$safe_CFLAGS
1332
1333
1334# does this compiler support -Wno-overflow ?
1335
1336AC_MSG_CHECKING([if gcc accepts -Wno-overflow])
1337
1338safe_CFLAGS=$CFLAGS
1339CFLAGS="-Wno-overflow"
1340
1341AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
1342  return 0;
1343]])], [
1344AC_SUBST([FLAG_W_NO_OVERFLOW], [-Wno-overflow])
1345AC_MSG_RESULT([yes])
1346], [
1347AC_SUBST([FLAG_W_NO_OVERFLOW], [])
1348AC_MSG_RESULT([no])
1349])
1350CFLAGS=$safe_CFLAGS
1351
1352
1353# does this compiler support -Wno-uninitialized ?
1354
1355AC_MSG_CHECKING([if gcc accepts -Wno-uninitialized])
1356
1357safe_CFLAGS=$CFLAGS
1358CFLAGS="-Wno-uninitialized"
1359
1360AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
1361  return 0;
1362]])], [
1363AC_SUBST([FLAG_W_NO_UNINITIALIZED], [-Wno-uninitialized])
1364AC_MSG_RESULT([yes])
1365], [
1366AC_SUBST([FLAG_W_NO_UNINITIALIZED], [])
1367AC_MSG_RESULT([no])
1368])
1369CFLAGS=$safe_CFLAGS
1370
1371
1372# does this compiler support -Wextra or the older -W ?
1373
1374AC_MSG_CHECKING([if gcc accepts -Wextra or -W])
1375
1376safe_CFLAGS=$CFLAGS
1377CFLAGS="-Wextra"
1378
1379AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
1380  return 0;
1381]])], [
1382AC_SUBST([FLAG_W_EXTRA], [-Wextra])
1383AC_MSG_RESULT([-Wextra])
1384], [
1385  CFLAGS="-W"
1386  AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[ ]], [[
1387    return 0;
1388  ]]), [
1389  AC_SUBST([FLAG_W_EXTRA], [-W])
1390  AC_MSG_RESULT([-W])
1391  ], [
1392  AC_SUBST([FLAG_W_EXTRA], [])
1393  AC_MSG_RESULT([not supported])
1394  ])
1395])
1396CFLAGS=$safe_CFLAGS
1397
1398
1399# does this compiler support -fno-stack-protector ?
1400AC_MSG_CHECKING([if gcc accepts -fno-stack-protector])
1401
1402safe_CFLAGS=$CFLAGS
1403CFLAGS="-fno-stack-protector"
1404
1405AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
1406  return 0;
1407]])], [
1408no_stack_protector=yes
1409FLAG_FNO_STACK_PROTECTOR="-fno-stack-protector"
1410AC_MSG_RESULT([yes])
1411], [
1412no_stack_protector=no
1413FLAG_FNO_STACK_PROTECTOR=""
1414AC_MSG_RESULT([no])
1415])
1416CFLAGS=$safe_CFLAGS
1417
1418AC_SUBST(FLAG_FNO_STACK_PROTECTOR)
1419
1420if test x$no_stack_protector = xyes; then
1421  CFLAGS="$CFLAGS -fno-stack-protector"
1422fi
1423
1424
1425# does this compiler support --param inline-unit-growth=... ?
1426
1427AC_MSG_CHECKING([if gcc accepts --param inline-unit-growth])
1428
1429safe_CFLAGS=$CFLAGS
1430CFLAGS="--param inline-unit-growth=900"
1431
1432AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
1433  return 0;
1434]])], [
1435AC_SUBST([FLAG_UNLIMITED_INLINE_UNIT_GROWTH],
1436         ["--param inline-unit-growth=900"])
1437AC_MSG_RESULT([yes])
1438], [
1439AC_SUBST([FLAG_UNLIMITED_INLINE_UNIT_GROWTH], [""])
1440AC_MSG_RESULT([no])
1441])
1442CFLAGS=$safe_CFLAGS
1443
1444
1445# does the linker support -Wl,--build-id=none ?  Note, it's
1446# important that we test indirectly via whichever C compiler
1447# is selected, rather than testing /usr/bin/ld or whatever
1448# directly.
1449
1450AC_MSG_CHECKING([if the linker accepts -Wl,--build-id=none])
1451
1452safe_CFLAGS=$CFLAGS
1453CFLAGS="-Wl,--build-id=none"
1454
1455AC_LINK_IFELSE(
1456[AC_LANG_PROGRAM([ ], [return 0;])],
1457[
1458  AC_SUBST([FLAG_NO_BUILD_ID], ["-Wl,--build-id=none"])
1459  AC_MSG_RESULT([yes])
1460], [
1461  AC_SUBST([FLAG_NO_BUILD_ID], [""])
1462  AC_MSG_RESULT([no])
1463])
1464CFLAGS=$safe_CFLAGS
1465
1466
1467# does the ppc assembler support "mtocrf" et al?
1468AC_MSG_CHECKING([if ppc32/64 as supports mtocrf/mfocrf])
1469
1470AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
1471__asm__ __volatile__("mtocrf 4,0");
1472__asm__ __volatile__("mfocrf 0,4");
1473]])], [
1474ac_have_as_ppc_mftocrf=yes
1475AC_MSG_RESULT([yes])
1476], [
1477ac_have_as_ppc_mftocrf=no
1478AC_MSG_RESULT([no])
1479])
1480if test x$ac_have_as_ppc_mftocrf = xyes ; then
1481  AC_DEFINE(HAVE_AS_PPC_MFTOCRF, 1, [Define to 1 if as supports mtocrf/mfocrf.])
1482fi
1483
1484
1485CFLAGS=$safe_CFLAGS
1486
1487# does the x86/amd64 assembler understand SSE3 instructions?
1488# Note, this doesn't generate a C-level symbol.  It generates a
1489# automake-level symbol (BUILD_SSE3_TESTS), used in test Makefile.am's
1490AC_MSG_CHECKING([if x86/amd64 assembler speaks SSE3])
1491
1492AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
1493  do { long long int x;
1494     __asm__ __volatile__("fisttpq (%0)" : :"r"(&x) ); }
1495  while (0)
1496]])], [
1497ac_have_as_sse3=yes
1498AC_MSG_RESULT([yes])
1499], [
1500ac_have_as_sse3=no
1501AC_MSG_RESULT([no])
1502])
1503
1504AM_CONDITIONAL(BUILD_SSE3_TESTS, test x$ac_have_as_sse3 = xyes)
1505
1506
1507# Ditto for SSSE3 instructions (note extra S)
1508# Note, this doesn't generate a C-level symbol.  It generates a
1509# automake-level symbol (BUILD_SSSE3_TESTS), used in test Makefile.am's
1510AC_MSG_CHECKING([if x86/amd64 assembler speaks SSSE3])
1511
1512AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
1513  do { long long int x;
1514   __asm__ __volatile__(
1515      "pabsb (%0),%%xmm7" : : "r"(&x) : "xmm7" ); }
1516  while (0)
1517]])], [
1518ac_have_as_ssse3=yes
1519AC_MSG_RESULT([yes])
1520], [
1521ac_have_as_ssse3=no
1522AC_MSG_RESULT([no])
1523])
1524
1525AM_CONDITIONAL(BUILD_SSSE3_TESTS, test x$ac_have_as_ssse3 = xyes)
1526
1527
1528# does the x86/amd64 assembler understand the PCLMULQDQ instruction?
1529# Note, this doesn't generate a C-level symbol.  It generates a
1530# automake-level symbol (BUILD_PCLMULQDQ_TESTS), used in test Makefile.am's
1531AC_MSG_CHECKING([if x86/amd64 assembler supports 'pclmulqdq'])
1532AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
1533  do {
1534   __asm__ __volatile__(
1535      "pclmulqdq \$17,%%xmm6,%%xmm7" : : : "xmm6", "xmm7" ); }
1536  while (0)
1537]])], [
1538ac_have_as_pclmulqdq=yes
1539AC_MSG_RESULT([yes])
1540], [
1541ac_have_as_pclmulqdq=no
1542AC_MSG_RESULT([no])
1543])
1544
1545AM_CONDITIONAL(BUILD_PCLMULQDQ_TESTS, test x$ac_have_as_pclmulqdq = xyes)
1546
1547
1548# does the x86/amd64 assembler understand the LZCNT instruction?
1549# Note, this doesn't generate a C-level symbol.  It generates a
1550# automake-level symbol (BUILD_LZCNT_TESTS), used in test Makefile.am's
1551AC_MSG_CHECKING([if x86/amd64 assembler supports 'lzcnt'])
1552
1553AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
1554  do {
1555      __asm__ __volatile__("lzcnt %rax,%rax");
1556  } while (0)
1557]])], [
1558  ac_have_as_lzcnt=yes
1559  AC_MSG_RESULT([yes])
1560], [
1561  ac_have_as_lzcnt=no
1562  AC_MSG_RESULT([no])
1563])
1564
1565AM_CONDITIONAL([BUILD_LZCNT_TESTS], [test x$ac_have_as_lzcnt = xyes])
1566
1567
1568# does the x86/amd64 assembler understand SSE 4.2 instructions?
1569# Note, this doesn't generate a C-level symbol.  It generates a
1570# automake-level symbol (BUILD_SSE42_TESTS), used in test Makefile.am's
1571AC_MSG_CHECKING([if x86/amd64 assembler speaks SSE4.2])
1572
1573AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
1574  do { long long int x;
1575   __asm__ __volatile__(
1576      "crc32q %%r15,%%r15" : : : "r15" ); }
1577  while (0)
1578]])], [
1579ac_have_as_sse42=yes
1580AC_MSG_RESULT([yes])
1581], [
1582ac_have_as_sse42=no
1583AC_MSG_RESULT([no])
1584])
1585
1586AM_CONDITIONAL(BUILD_SSE42_TESTS, test x$ac_have_as_sse42 = xyes)
1587
1588
1589# XXX JRS 2010 Oct 13: what is this for?  For sure, we don't need this
1590# when building the tool executables.  I think we should get rid of it.
1591#
1592# Check for TLS support in the compiler and linker
1593AC_LINK_IFELSE([AC_LANG_PROGRAM([[static __thread int foo;]],
1594                                [[return foo;]])],
1595                               [vg_cv_linktime_tls=yes],
1596                               [vg_cv_linktime_tls=no])
1597# Native compilation: check whether running a program using TLS succeeds.
1598# Linking only is not sufficient -- e.g. on Red Hat 7.3 linking TLS programs
1599# succeeds but running programs using TLS fails.
1600# Cross-compiling: check whether linking a program using TLS succeeds.
1601AC_CACHE_CHECK([for TLS support], vg_cv_tls,
1602	       [AC_ARG_ENABLE(tls, [  --enable-tls            platform supports TLS],
1603		[vg_cv_tls=$enableval],
1604               	[AC_RUN_IFELSE([AC_LANG_PROGRAM([[static __thread int foo;]],
1605                                                [[return foo;]])],
1606                               [vg_cv_tls=yes],
1607                               [vg_cv_tls=no],
1608                               [vg_cv_tls=$vg_cv_linktime_tls])])])
1609
1610if test "$vg_cv_tls" = yes; then
1611AC_DEFINE([HAVE_TLS], 1, [can use __thread to define thread-local variables])
1612fi
1613
1614
1615#----------------------------------------------------------------------------
1616# Checks for C header files.
1617#----------------------------------------------------------------------------
1618
1619AC_HEADER_STDC
1620AC_CHECK_HEADERS([       \
1621        asm/unistd.h     \
1622        endian.h         \
1623        mqueue.h         \
1624        sys/endian.h     \
1625        sys/epoll.h      \
1626        sys/eventfd.h    \
1627        sys/klog.h       \
1628        sys/poll.h       \
1629        sys/signal.h     \
1630        sys/signalfd.h   \
1631        sys/syscall.h    \
1632        sys/time.h       \
1633        sys/types.h      \
1634        ])
1635
1636# Verify whether the <linux/futex.h> header is usable.
1637AC_MSG_CHECKING([if <linux/futex.h> is usable])
1638
1639AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1640#include <linux/futex.h>
1641]], [[
1642  return FUTEX_WAIT;
1643]])], [
1644AC_DEFINE([HAVE_USABLE_LINUX_FUTEX_H], 1,
1645          [Define to 1 if you have a usable <linux/futex.h> header file.])
1646AC_MSG_RESULT([yes])
1647], [
1648AC_MSG_RESULT([no])
1649])
1650
1651#----------------------------------------------------------------------------
1652# Checks for typedefs, structures, and compiler characteristics.
1653#----------------------------------------------------------------------------
1654AC_TYPE_UID_T
1655AC_TYPE_OFF_T
1656AC_TYPE_SIZE_T
1657AC_HEADER_TIME
1658
1659
1660#----------------------------------------------------------------------------
1661# Checks for library functions.
1662#----------------------------------------------------------------------------
1663AC_FUNC_MEMCMP
1664AC_FUNC_MMAP
1665
1666AC_CHECK_LIB([pthread], [pthread_create])
1667AC_CHECK_LIB([rt], [clock_gettime])
1668
1669AC_CHECK_FUNCS([     \
1670        clock_gettime\
1671        epoll_create \
1672        epoll_pwait  \
1673        klogctl      \
1674        mallinfo     \
1675        memchr       \
1676        memset       \
1677        mkdir        \
1678        mremap       \
1679        ppoll        \
1680        pthread_barrier_init       \
1681        pthread_condattr_setclock  \
1682        pthread_mutex_timedlock    \
1683        pthread_rwlock_timedrdlock \
1684        pthread_rwlock_timedwrlock \
1685        pthread_spin_lock          \
1686        pthread_yield              \
1687        readlinkat   \
1688        semtimedop   \
1689        signalfd     \
1690        sigwaitinfo  \
1691        strchr       \
1692        strdup       \
1693        strpbrk      \
1694        strrchr      \
1695        strstr       \
1696        syscall      \
1697        utimensat    \
1698        ])
1699
1700# AC_CHECK_LIB adds any library found to the variable LIBS, and links these
1701# libraries with any shared object and/or executable. This is NOT what we
1702# want for e.g. vgpreload_core-x86-linux.so
1703LIBS=""
1704
1705AM_CONDITIONAL([HAVE_PTHREAD_BARRIER],
1706               [test x$ac_cv_func_pthread_barrier_init = xyes])
1707AM_CONDITIONAL([HAVE_PTHREAD_MUTEX_TIMEDLOCK],
1708               [test x$ac_cv_func_pthread_mutex_timedlock = xyes])
1709AM_CONDITIONAL([HAVE_PTHREAD_SPINLOCK],
1710               [test x$ac_cv_func_pthread_spin_lock = xyes])
1711
1712
1713#----------------------------------------------------------------------------
1714# MPI checks
1715#----------------------------------------------------------------------------
1716# Do we have a useable MPI setup on the primary and/or secondary targets?
1717# On Linux, by default, assumes mpicc and -m32/-m64
1718# Note: this is a kludge in that it assumes the specified mpicc
1719# understands -m32/-m64 regardless of what is specified using
1720# --with-mpicc=.
1721MPI_CC="mpicc"
1722
1723mflag_primary=
1724if test x$VGCONF_PLATFORM_PRI_CAPS = xX86_LINUX \
1725     -o x$VGCONF_PLATFORM_PRI_CAPS = xPPC32_LINUX \
1726     -o x$VGCONF_PLATFORM_PRI_CAPS = xARM_LINUX ; then
1727  mflag_primary=$FLAG_M32
1728elif test x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_LINUX \
1729       -o x$VGCONF_PLATFORM_PRI_CAPS = xPPC64_LINUX \
1730       -o x$VGCONF_PLATFORM_PRI_CAPS = xS390X_LINUX ; then
1731  mflag_primary=$FLAG_M64
1732fi
1733
1734mflag_secondary=
1735if test x$VGCONF_PLATFORM_SEC_CAPS = xX86_LINUX \
1736     -o x$VGCONF_PLATFORM_SEC_CAPS = xPPC32_LINUX ; then
1737  mflag_secondary=$FLAG_M32
1738fi
1739
1740
1741AC_ARG_WITH(mpicc,
1742   [  --with-mpicc=           Specify name of MPI2-ised C compiler],
1743   MPI_CC=$withval
1744)
1745AC_SUBST(MPI_CC)
1746
1747## See if MPI_CC works for the primary target
1748##
1749AC_MSG_CHECKING([primary target for usable MPI2-compliant C compiler and mpi.h])
1750saved_CC=$CC
1751saved_CFLAGS=$CFLAGS
1752CC=$MPI_CC
1753CFLAGS=$mflag_primary
1754AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1755#include <mpi.h>
1756#include <stdio.h>
1757]], [[
1758  int r = MPI_Init(NULL,NULL);
1759  r |= MPI_Type_get_contents( MPI_INT, 0,0,0, NULL,NULL,NULL );
1760  return r;
1761]])], [
1762ac_have_mpi2_pri=yes
1763AC_MSG_RESULT([yes, $MPI_CC])
1764], [
1765ac_have_mpi2_pri=no
1766AC_MSG_RESULT([no])
1767])
1768CC=$saved_CC
1769CFLAGS=$saved_CFLAGS
1770AM_CONDITIONAL(BUILD_MPIWRAP_PRI, test x$ac_have_mpi2_pri = xyes)
1771
1772## See if MPI_CC works for the secondary target.  Complication: what if
1773## there is no secondary target?  We need this to then fail.
1774## Kludge this by making MPI_CC something which will surely fail in
1775## such a case.
1776##
1777AC_MSG_CHECKING([secondary target for usable MPI2-compliant C compiler and mpi.h])
1778saved_CC=$CC
1779saved_CFLAGS=$CFLAGS
1780if test x$VGCONF_PLATFORM_SEC_CAPS = x ; then
1781  CC="$MPI_CC this will surely fail"
1782else
1783  CC=$MPI_CC
1784fi
1785CFLAGS=$mflag_secondary
1786AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1787#include <mpi.h>
1788#include <stdio.h>
1789]], [[
1790  int r = MPI_Init(NULL,NULL);
1791  r |= MPI_Type_get_contents( MPI_INT, 0,0,0, NULL,NULL,NULL );
1792  return r;
1793]])], [
1794ac_have_mpi2_sec=yes
1795AC_MSG_RESULT([yes, $MPI_CC])
1796], [
1797ac_have_mpi2_sec=no
1798AC_MSG_RESULT([no])
1799])
1800CC=$saved_CC
1801CFLAGS=$saved_CFLAGS
1802AM_CONDITIONAL(BUILD_MPIWRAP_SEC, test x$ac_have_mpi2_sec = xyes)
1803
1804
1805#----------------------------------------------------------------------------
1806# Other library checks
1807#----------------------------------------------------------------------------
1808# There now follow some tests for Boost, and OpenMP.  These
1809# tests are present because Drd has some regression tests that use
1810# these packages.  All regression test programs all compiled only
1811# for the primary target.  And so it is important that the configure
1812# checks that follow, use the correct -m32 or -m64 flag for the
1813# primary target (called $mflag_primary).  Otherwise, we can end up
1814# in a situation (eg) where, on amd64-linux, the test for Boost checks
1815# for usable 64-bit Boost facilities, but because we are doing a 32-bit
1816# only build (meaning, the primary target is x86-linux), the build
1817# of the regtest programs that use Boost fails, because they are
1818# build as 32-bit (IN THIS EXAMPLE).
1819#
1820# Hence: ALWAYS USE $mflag_primary FOR CONFIGURE TESTS FOR FACILITIES
1821# NEEDED BY THE REGRESSION TEST PROGRAMS.
1822
1823
1824# Check whether the boost library 1.35 or later has been installed.
1825# The Boost.Threads library has undergone a major rewrite in version 1.35.0.
1826
1827AC_MSG_CHECKING([for boost])
1828
1829AC_LANG(C++)
1830safe_CXXFLAGS=$CXXFLAGS
1831CXXFLAGS="-lboost_thread-mt $mflag_primary"
1832
1833AC_LINK_IFELSE([AC_LANG_SOURCE([
1834#include <boost/thread.hpp>
1835static void thread_func(void)
1836{ }
1837int main(int argc, char** argv)
1838{
1839  boost::thread t(thread_func);
1840  return 0;
1841}
1842])],
1843[
1844ac_have_boost_1_35=yes
1845AC_SUBST([BOOST_CFLAGS], [])
1846AC_SUBST([BOOST_LIBS], ["${CXXFLAGS}"])
1847AC_MSG_RESULT([yes])
1848], [
1849ac_have_boost_1_35=no
1850AC_MSG_RESULT([no])
1851])
1852
1853CXXFLAGS=$safe_CXXFLAGS
1854AC_LANG(C)
1855
1856AM_CONDITIONAL([HAVE_BOOST_1_35], [test x$ac_have_boost_1_35 = xyes])
1857
1858
1859# does this compiler support -fopenmp, does it have the include file
1860# <omp.h> and does it have libgomp ?
1861
1862AC_MSG_CHECKING([for OpenMP])
1863
1864safe_CFLAGS=$CFLAGS
1865CFLAGS="-fopenmp $mflag_primary"
1866
1867AC_LINK_IFELSE([AC_LANG_SOURCE([
1868#include <omp.h>
1869int main(int argc, char** argv)
1870{
1871  omp_set_dynamic(0);
1872  return 0;
1873}
1874])],
1875[
1876ac_have_openmp=yes
1877AC_MSG_RESULT([yes])
1878], [
1879ac_have_openmp=no
1880AC_MSG_RESULT([no])
1881])
1882CFLAGS=$safe_CFLAGS
1883
1884AM_CONDITIONAL([HAVE_OPENMP], [test x$ac_have_openmp = xyes])
1885
1886
1887# does this compiler have built-in functions for atomic memory access ?
1888AC_MSG_CHECKING([if gcc supports __sync_bool_compare_and_swap])
1889
1890safe_CFLAGS=$CFLAGS
1891CFLAGS="$mflag_primary"
1892
1893AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
1894  int variable = 1;
1895  return (__sync_bool_compare_and_swap(&variable, 1, 2)
1896          && __sync_add_and_fetch(&variable, 1) ? 1 : 0)
1897]])], [
1898  ac_have_builtin_atomic=yes
1899  AC_MSG_RESULT([yes])
1900  AC_DEFINE(HAVE_BUILTIN_ATOMIC, 1, [Define to 1 if gcc supports __sync_bool_compare_and_swap() and __sync_add_and_fetch()])
1901], [
1902  ac_have_builtin_atomic=no
1903  AC_MSG_RESULT([no])
1904])
1905
1906CFLAGS=$safe_CFLAGS
1907
1908AM_CONDITIONAL([HAVE_BUILTIN_ATOMIC], [test x$ac_have_builtin_atomic = xyes])
1909
1910# does g++ have built-in functions for atomic memory access ?
1911AC_MSG_CHECKING([if g++ supports __sync_bool_compare_and_swap])
1912
1913safe_CXXFLAGS=$CXXFLAGS
1914CXXFLAGS="$mflag_primary"
1915
1916AC_LANG_PUSH(C++)
1917AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
1918  int variable = 1;
1919  return (__sync_bool_compare_and_swap(&variable, 1, 2)
1920          && __sync_add_and_fetch(&variable, 1) ? 1 : 0)
1921]])], [
1922  ac_have_builtin_atomic_cxx=yes
1923  AC_MSG_RESULT([yes])
1924  AC_DEFINE(HAVE_BUILTIN_ATOMIC_CXX, 1, [Define to 1 if g++ supports __sync_bool_compare_and_swap() and __sync_add_and_fetch()])
1925], [
1926  ac_have_builtin_atomic_cxx=no
1927  AC_MSG_RESULT([no])
1928])
1929AC_LANG_POP(C++)
1930
1931CXXFLAGS=$safe_CXXFLAGS
1932
1933AM_CONDITIONAL([HAVE_BUILTIN_ATOMIC_CXX], [test x$ac_have_builtin_atomic_cxx = xyes])
1934
1935#----------------------------------------------------------------------------
1936# Ok.  We're done checking.
1937#----------------------------------------------------------------------------
1938
1939# Nb: VEX/Makefile is generated from Makefile.vex.in.
1940AC_CONFIG_FILES([
1941   Makefile
1942   VEX/Makefile:Makefile.vex.in
1943   valgrind.spec
1944   valgrind.pc
1945   glibc-2.X.supp
1946   glibc-X.X.supp
1947   docs/Makefile
1948   tests/Makefile
1949   tests/vg_regtest
1950   perf/Makefile
1951   perf/vg_perf
1952   gdbserver_tests/Makefile
1953   include/Makefile
1954   auxprogs/Makefile
1955   mpi/Makefile
1956   coregrind/Makefile
1957   memcheck/Makefile
1958   memcheck/tests/Makefile
1959   memcheck/tests/amd64/Makefile
1960   memcheck/tests/x86/Makefile
1961   memcheck/tests/linux/Makefile
1962   memcheck/tests/darwin/Makefile
1963   memcheck/tests/amd64-linux/Makefile
1964   memcheck/tests/x86-linux/Makefile
1965   memcheck/tests/ppc32/Makefile
1966   memcheck/tests/ppc64/Makefile
1967   memcheck/perf/Makefile
1968   cachegrind/Makefile
1969   cachegrind/tests/Makefile
1970   cachegrind/tests/x86/Makefile
1971   cachegrind/cg_annotate
1972   cachegrind/cg_diff
1973   callgrind/Makefile
1974   callgrind/callgrind_annotate
1975   callgrind/callgrind_control
1976   callgrind/tests/Makefile
1977   helgrind/Makefile
1978   helgrind/tests/Makefile
1979   massif/Makefile
1980   massif/tests/Makefile
1981   massif/perf/Makefile
1982   massif/ms_print
1983   lackey/Makefile
1984   lackey/tests/Makefile
1985   none/Makefile
1986   none/tests/Makefile
1987   none/tests/amd64/Makefile
1988   none/tests/ppc32/Makefile
1989   none/tests/ppc64/Makefile
1990   none/tests/x86/Makefile
1991   none/tests/arm/Makefile
1992   none/tests/s390x/Makefile
1993   none/tests/linux/Makefile
1994   none/tests/darwin/Makefile
1995   none/tests/x86-linux/Makefile
1996   exp-sgcheck/Makefile
1997   exp-sgcheck/tests/Makefile
1998   drd/Makefile
1999   drd/scripts/download-and-build-splash2
2000   drd/tests/Makefile
2001   exp-bbv/Makefile
2002   exp-bbv/tests/Makefile
2003   exp-bbv/tests/x86/Makefile
2004   exp-bbv/tests/x86-linux/Makefile
2005   exp-bbv/tests/amd64-linux/Makefile
2006   exp-bbv/tests/ppc32-linux/Makefile
2007   exp-bbv/tests/arm-linux/Makefile
2008   exp-dhat/Makefile
2009   exp-dhat/tests/Makefile
2010])
2011AC_CONFIG_FILES([coregrind/link_tool_exe_linux],
2012                [chmod +x coregrind/link_tool_exe_linux])
2013AC_CONFIG_FILES([coregrind/link_tool_exe_darwin],
2014                [chmod +x coregrind/link_tool_exe_darwin])
2015AC_OUTPUT
2016
2017cat<<EOF
2018
2019         Maximum build arch: ${ARCH_MAX}
2020         Primary build arch: ${VGCONF_ARCH_PRI}
2021       Secondary build arch: ${VGCONF_ARCH_SEC}
2022                   Build OS: ${VGCONF_OS}
2023       Primary build target: ${VGCONF_PLATFORM_PRI_CAPS}
2024     Secondary build target: ${VGCONF_PLATFORM_SEC_CAPS}
2025           Platform variant: ${VGCONF_PLATVARIANT}
2026      Primary -DVGPV string: -DVGPV_${VGCONF_ARCH_PRI}_${VGCONF_OS}_${VGCONF_PLATVARIANT}=1
2027         Default supp files: ${DEFAULT_SUPP}
2028
2029EOF
2030