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