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