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