Fix a false-negative in MMX check
[platform/upstream/pixman.git] / configure.ac
1 dnl  Copyright 2005 Red Hat, Inc.
2 dnl 
3 dnl  Permission to use, copy, modify, distribute, and sell this software and its
4 dnl  documentation for any purpose is hereby granted without fee, provided that
5 dnl  the above copyright notice appear in all copies and that both that
6 dnl  copyright notice and this permission notice appear in supporting
7 dnl  documentation, and that the name of Red Hat not be used in
8 dnl  advertising or publicity pertaining to distribution of the software without
9 dnl  specific, written prior permission.  Red Hat makes no
10 dnl  representations about the suitability of this software for any purpose.  It
11 dnl  is provided "as is" without express or implied warranty.
12 dnl 
13 dnl  RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
14 dnl  INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
15 dnl  EVENT SHALL RED HAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
16 dnl  CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
17 dnl  DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 dnl  TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 dnl  PERFORMANCE OF THIS SOFTWARE.
20 dnl
21 dnl Process this file with autoconf to create configure.
22
23 AC_PREREQ([2.57])
24
25 #   Pixman versioning scheme
26 #
27 #   - The version in git has an odd MICRO version number
28 #
29 #   - Released versions, both development and stable, have an
30 #     even MICRO version number
31 #
32 #   - Released development versions have an odd MINOR number
33 #
34 #   - Released stable versions have an even MINOR number
35 #
36 #   - Versions that break ABI must have a new MAJOR number
37 #
38 #   - If you break the ABI, then at least this must be done:
39 #
40 #        - increment MAJOR
41 #
42 #        - In the first development release where you break ABI, find
43 #          all instances of "pixman-n" and change them to pixman-(n+1)
44 #
45 #          This needs to be done at least in 
46 #                    configure.ac
47 #                    all Makefile.am's
48 #                    pixman-n.pc.in
49 #
50 #      This ensures that binary incompatible versions can be installed
51 #      in parallel.  See http://www106.pair.com/rhp/parallel.html for
52 #      more information
53 #
54
55 m4_define([pixman_major], 0)
56 m4_define([pixman_minor], 25)
57 m4_define([pixman_micro], 3)
58
59 m4_define([pixman_version],[pixman_major.pixman_minor.pixman_micro])
60
61 AC_INIT(pixman, pixman_version, [pixman@lists.freedesktop.org], pixman)
62 AM_INIT_AUTOMAKE([foreign dist-bzip2])
63
64 # Suppress verbose compile lines
65 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
66
67 AM_CONFIG_HEADER(config.h)
68
69 AC_CANONICAL_HOST
70
71 test_CFLAGS=${CFLAGS+set} # We may override autoconf default CFLAGS.
72
73 AC_PROG_CC
74 AM_PROG_AS
75 AC_PROG_LIBTOOL
76 AC_CHECK_FUNCS([getisax])
77 AC_C_BIGENDIAN
78 AC_C_INLINE
79
80 dnl PIXMAN_LINK_WITH_ENV(env-setup, program, true-action, false-action)
81 dnl
82 dnl Compiles and links the given program in the environment setup by env-setup
83 dnl and executes true-action on success and false-action on failure.
84 AC_DEFUN([PIXMAN_LINK_WITH_ENV],[dnl
85         save_CFLAGS="$CFLAGS"
86         save_LDFLAGS="$LDFLAGS"
87         save_LIBS="$LIBS"
88         CFLAGS=""
89         LDFLAGS=""
90         LIBS=""
91         $1
92         AC_LINK_IFELSE(
93                 [AC_LANG_SOURCE([$2])],
94                 [pixman_cc_stderr=`test -f conftest.err && cat conftest.err`
95                  pixman_cc_flag=yes],
96                 [pixman_cc_stderr=`test -f conftest.err && cat conftest.err`
97                  pixman_cc_flag=no])
98
99         if test "x$pixman_cc_stderr" != "x"; then
100                 pixman_cc_flag=no
101         fi
102
103         if test "x$pixman_cc_flag" = "xyes"; then
104                 ifelse([$3], , :, [$3])
105         else
106                 ifelse([$4], , :, [$4])
107         fi
108         CFLAGS="$save_CFLAGS"
109         LDFLAGS="$save_LDFLAGS"
110         LIBS="$save_LIBS"
111 ])
112
113 dnl Find a -Werror for catching warnings.
114 WERROR=
115 for w in -Werror -errwarn; do
116     if test "z$WERROR" = "z"; then
117         AC_MSG_CHECKING([whether the compiler supports $w])
118         PIXMAN_LINK_WITH_ENV(
119                 [CFLAGS=$w],
120                 [int main(int c, char **v) { (void)c; (void)v; return 0; }],
121                 [WERROR=$w; yesno=yes], [yesno=no])
122         AC_MSG_RESULT($yesno)
123     fi
124 done
125
126 dnl PIXMAN_CHECK_CFLAG(flag, [program])
127 dnl  Adds flag to CFLAGS if the given program links without warnings or errors.
128 AC_DEFUN([PIXMAN_CHECK_CFLAG], [dnl
129         AC_MSG_CHECKING([whether the compiler supports $1])
130         PIXMAN_LINK_WITH_ENV(
131                 [CFLAGS="$WERROR $1"],
132                 [$2
133                  int main(int c, char **v) { (void)c; (void)v; return 0; }
134                 ],
135                 [_yesno=yes],
136                 [_yesno=no])
137         if test "x$_yesno" = xyes; then
138            CFLAGS="$CFLAGS $1"
139         fi
140         AC_MSG_RESULT($_yesno)
141 ])
142
143 AC_CHECK_SIZEOF(long)
144
145 # Checks for Sun Studio compilers
146 AC_CHECK_DECL([__SUNPRO_C], [SUNCC="yes"], [SUNCC="no"])
147 AC_CHECK_DECL([__amd64], [AMD64_ABI="yes"], [AMD64_ABI="no"])
148
149 # Default CFLAGS to -O -g rather than just the -g from AC_PROG_CC
150 # if we're using Sun Studio and neither the user nor a config.site
151 # has set CFLAGS.
152 if test $SUNCC = yes &&                 \
153    test "x$test_CFLAGS" = "x" &&        \
154    test "$CFLAGS" = "-g"
155 then
156   CFLAGS="-O -g"
157 fi
158
159
160 # We ignore pixman_major in the version here because the major version should
161 # always be encoded in the actual library name. Ie., the soname is:
162 #
163 #      pixman-$(pixman_major).0.minor.micro
164 #
165 m4_define([lt_current], [pixman_minor])
166 m4_define([lt_revision], [pixman_micro])
167 m4_define([lt_age], [pixman_minor])
168
169 LT_VERSION_INFO="lt_current:lt_revision:lt_age"
170
171 PIXMAN_VERSION_MAJOR=pixman_major()
172 AC_SUBST(PIXMAN_VERSION_MAJOR)
173 PIXMAN_VERSION_MINOR=pixman_minor()
174 AC_SUBST(PIXMAN_VERSION_MINOR)
175 PIXMAN_VERSION_MICRO=pixman_micro()
176 AC_SUBST(PIXMAN_VERSION_MICRO)
177
178 AC_SUBST(LT_VERSION_INFO)
179
180 # Check for dependencies
181
182 PIXMAN_CHECK_CFLAG([-Wall])
183 PIXMAN_CHECK_CFLAG([-fno-strict-aliasing])
184
185 AC_PATH_PROG(PERL, perl, no)
186 if test "x$PERL" = xno; then
187     AC_MSG_ERROR([Perl is required to build pixman.])
188 fi
189 AC_SUBST(PERL)
190
191 dnl =========================================================================
192 dnl OpenMP for the test suite?
193 dnl
194
195 # Check for OpenMP support only when autoconf support that (require autoconf >=2.62)
196 OPENMP_CFLAGS=
197 m4_ifdef([AC_OPENMP], [AC_OPENMP])
198
199 if test "x$enable_openmp" = "xyes" && test "x$ac_cv_prog_c_openmp" = "xunsupported" ; then
200   AC_MSG_WARN([OpenMP support requested but found unsupported])
201 fi
202
203 dnl May not fail to link without -Wall -Werror added
204 dnl So try to link only when openmp is supported
205 dnl ac_cv_prog_c_openmp is not defined when --disable-openmp is used
206 if test "x$ac_cv_prog_c_openmp" != "xunsupported" && test "x$ac_cv_prog_c_openmp" != "x"; then
207   m4_define([openmp_test_program],[dnl
208   #include <stdio.h>
209
210   extern unsigned int lcg_seed;
211   #pragma omp threadprivate(lcg_seed)
212   unsigned int lcg_seed;
213
214   unsigned function(unsigned a, unsigned b)
215   {
216         lcg_seed ^= b;
217         return ((a + b) ^ a ) + lcg_seed;
218   }
219
220   int main(int argc, char **argv)
221   {
222         int i;
223         int n1 = 0, n2 = argc;
224         unsigned checksum = 0;
225         int verbose = argv != NULL;
226         unsigned (*test_function)(unsigned, unsigned);
227         test_function = function;
228         #pragma omp parallel for reduction(+:checksum) default(none) \
229                                         shared(n1, n2, test_function, verbose)
230         for (i = n1; i < n2; i++)
231         {
232                 unsigned crc = test_function (i, 0);
233                 if (verbose)
234                         printf ("%d: %08X\n", i, crc);
235                 checksum += crc;
236         }
237         printf("%u\n", checksum);
238         return 0;
239   }
240   ])
241
242   PIXMAN_LINK_WITH_ENV(
243         [CFLAGS="$OPENMP_CFLAGS" LDFLAGS="$OPENMP_CFLAGS"],
244         [openmp_test_program],
245         [have_openmp=yes],
246         [have_openmp=no])
247   if test "x$have_openmp" = "xyes" ; then
248     AC_DEFINE(USE_OPENMP, 1, [use OpenMP in the test suite])
249   fi
250 fi
251 AC_SUBST(OPENMP_CFLAGS)
252
253 dnl =========================================================================
254 dnl -fvisibility stuff
255
256 PIXMAN_CHECK_CFLAG([-fvisibility=hidden], [dnl
257 #if defined(__GNUC__) && (__GNUC__ >= 4)
258 #ifdef _WIN32
259 #error Have -fvisibility but it is ignored and generates a warning
260 #endif
261 #else
262 #error Need GCC 4.0 for visibility
263 #endif
264 ])
265
266 PIXMAN_CHECK_CFLAG([-xldscope=hidden], [dnl
267 #if defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
268 #else
269 #error Need Sun Studio 8 for visibility
270 #endif
271 ])
272
273 dnl ===========================================================================
274 dnl Check for MMX
275
276 if test "x$MMX_CFLAGS" = "x" ; then
277    if test "x$SUNCC" = "xyes"; then
278       # Sun Studio doesn't have an -xarch=mmx flag, so we have to use sse
279       # but if we're building 64-bit, mmx & sse support is on by default and
280       # -xarch=sse throws an error instead
281       if test "$AMD64_ABI" = "no" ; then
282          MMX_CFLAGS="-xarch=sse"
283       fi
284    else
285       MMX_CFLAGS="-mmmx -Winline"
286    fi
287 fi
288
289 have_mmx_intrinsics=no
290 AC_MSG_CHECKING(whether to use MMX intrinsics)
291 xserver_save_CFLAGS=$CFLAGS
292 CFLAGS="$MMX_CFLAGS $CFLAGS"
293 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
294 #if defined(__GNUC__) && (__GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 4))
295 #error "Need GCC >= 3.4 for MMX intrinsics"
296 #endif
297 #include <mmintrin.h>
298 int main () {
299     __m64 v = _mm_cvtsi32_si64 (1);
300     __m64 w;
301     signed char x = 0;
302
303     /* Some versions of clang will choke on K */
304     asm ("pshufw %2, %1, %0\n\t"
305         : "=y" (w)
306         : "y" (v), "K" (x)
307     );
308
309     return _mm_cvtsi64_si32 (v);
310 }]])], have_mmx_intrinsics=yes)
311 CFLAGS=$xserver_save_CFLAGS
312
313 AC_ARG_ENABLE(mmx,
314    [AC_HELP_STRING([--disable-mmx],
315                    [disable x86 MMX fast paths])],
316    [enable_mmx=$enableval], [enable_mmx=auto])
317
318 if test $enable_mmx = no ; then
319    have_mmx_intrinsics=disabled
320 fi
321
322 if test $have_mmx_intrinsics = yes ; then
323    AC_DEFINE(USE_X86_MMX, 1, [use x86 MMX compiler intrinsics])
324 else
325    MMX_CFLAGS=
326 fi
327
328 AC_MSG_RESULT($have_mmx_intrinsics)
329 if test $enable_mmx = yes && test $have_mmx_intrinsics = no ; then
330    AC_MSG_ERROR([x86 MMX intrinsics not detected])
331 fi
332
333 AM_CONDITIONAL(USE_X86_MMX, test $have_mmx_intrinsics = yes)
334
335 dnl ===========================================================================
336 dnl Check for SSE2
337
338 if test "x$SSE2_CFLAGS" = "x" ; then
339    if test "x$SUNCC" = "xyes"; then
340       # SSE2 is enabled by default in the Sun Studio 64-bit environment
341       if test "$AMD64_ABI" = "no" ; then
342          SSE2_CFLAGS="-xarch=sse2"
343       fi
344    else
345       SSE2_CFLAGS="-msse2 -Winline"
346    fi
347 fi
348
349 have_sse2_intrinsics=no
350 AC_MSG_CHECKING(whether to use SSE2 intrinsics)
351 xserver_save_CFLAGS=$CFLAGS
352 CFLAGS="$SSE2_CFLAGS $CFLAGS"
353
354 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
355 #if defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
356 #   if !defined(__amd64__) && !defined(__x86_64__)
357 #      error "Need GCC >= 4.2 for SSE2 intrinsics on x86"
358 #   endif
359 #endif
360 #include <mmintrin.h>
361 #include <xmmintrin.h>
362 #include <emmintrin.h>
363 int main () {
364     __m128i a = _mm_set1_epi32 (0), b = _mm_set1_epi32 (0), c;
365         c = _mm_xor_si128 (a, b);
366     return 0;
367 }]])], have_sse2_intrinsics=yes)
368 CFLAGS=$xserver_save_CFLAGS
369
370 AC_ARG_ENABLE(sse2,
371    [AC_HELP_STRING([--disable-sse2],
372                    [disable SSE2 fast paths])],
373    [enable_sse2=$enableval], [enable_sse2=auto])
374
375 if test $enable_sse2 = no ; then
376    have_sse2_intrinsics=disabled
377 fi
378
379 if test $have_sse2_intrinsics = yes ; then
380    AC_DEFINE(USE_SSE2, 1, [use SSE2 compiler intrinsics])
381 fi
382
383 AC_MSG_RESULT($have_sse2_intrinsics)
384 if test $enable_sse2 = yes && test $have_sse2_intrinsics = no ; then
385    AC_MSG_ERROR([SSE2 intrinsics not detected])
386 fi
387
388 AM_CONDITIONAL(USE_SSE2, test $have_sse2_intrinsics = yes)
389
390 dnl ===========================================================================
391 dnl Other special flags needed when building code using MMX or SSE instructions
392 case $host_os in
393    solaris*)
394       # When building 32-bit binaries, apply a mapfile to ensure that the
395       # binaries aren't flagged as only able to run on MMX+SSE capable CPUs
396       # since they check at runtime before using those instructions.
397       # Not all linkers grok the mapfile format so we check for that first.
398       if test "$AMD64_ABI" = "no" ; then
399          use_hwcap_mapfile=no
400          AC_MSG_CHECKING(whether to use a hardware capability map file)
401          hwcap_save_LDFLAGS="$LDFLAGS"
402          HWCAP_LDFLAGS='-Wl,-M,$(srcdir)/solaris-hwcap.mapfile'
403          LDFLAGS="$LDFLAGS -Wl,-M,pixman/solaris-hwcap.mapfile"
404          AC_LINK_IFELSE([AC_LANG_SOURCE([[int main() { return 0; }]])],
405                         use_hwcap_mapfile=yes,
406                         HWCAP_LDFLAGS="")
407          LDFLAGS="$hwcap_save_LDFLAGS"
408          AC_MSG_RESULT($use_hwcap_mapfile)
409       fi
410       if test "x$MMX_LDFLAGS" = "x" ; then
411          MMX_LDFLAGS="$HWCAP_LDFLAGS"
412       fi
413       if test "x$SSE2_LDFLAGS" = "x" ; then
414          SSE2_LDFLAGS="$HWCAP_LDFLAGS"
415       fi
416       ;;
417 esac
418
419 AC_SUBST(IWMMXT_CFLAGS)
420 AC_SUBST(MMX_CFLAGS)
421 AC_SUBST(MMX_LDFLAGS)
422 AC_SUBST(SSE2_CFLAGS)
423 AC_SUBST(SSE2_LDFLAGS)
424
425 dnl ===========================================================================
426 dnl Check for VMX/Altivec
427 if test -n "`$CC -v 2>&1 | grep version | grep Apple`"; then
428     VMX_CFLAGS="-faltivec"
429 else
430     VMX_CFLAGS="-maltivec -mabi=altivec"
431 fi
432
433 have_vmx_intrinsics=no
434 AC_MSG_CHECKING(whether to use VMX/Altivec intrinsics)
435 xserver_save_CFLAGS=$CFLAGS
436 CFLAGS="$VMX_CFLAGS $CFLAGS"
437 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
438 #if defined(__GNUC__) && (__GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 4))
439 #error "Need GCC >= 3.4 for sane altivec support"
440 #endif
441 #include <altivec.h>
442 int main () {
443     vector unsigned int v = vec_splat_u32 (1);
444     v = vec_sub (v, v);
445     return 0;
446 }]])], have_vmx_intrinsics=yes)
447 CFLAGS=$xserver_save_CFLAGS
448
449 AC_ARG_ENABLE(vmx,
450    [AC_HELP_STRING([--disable-vmx],
451                    [disable VMX fast paths])],
452    [enable_vmx=$enableval], [enable_vmx=auto])
453
454 if test $enable_vmx = no ; then
455    have_vmx_intrinsics=disabled
456 fi
457
458 if test $have_vmx_intrinsics = yes ; then
459    AC_DEFINE(USE_VMX, 1, [use VMX compiler intrinsics])
460 else
461    VMX_CFLAGS=
462 fi
463
464 AC_MSG_RESULT($have_vmx_intrinsics)
465 if test $enable_vmx = yes && test $have_vmx_intrinsics = no ; then
466    AC_MSG_ERROR([VMX intrinsics not detected])
467 fi
468
469 AC_SUBST(VMX_CFLAGS)
470
471 AM_CONDITIONAL(USE_VMX, test $have_vmx_intrinsics = yes)
472
473 dnl ==========================================================================
474 dnl Check if assembler is gas compatible and supports ARM SIMD instructions
475 have_arm_simd=no
476 AC_MSG_CHECKING(whether to use ARM SIMD assembler)
477 xserver_save_CFLAGS=$CFLAGS
478 CFLAGS="-x assembler-with-cpp $CFLAGS"
479 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
480 .text
481 .arch armv6
482 .object_arch armv4
483 .arm
484 .altmacro
485 #ifndef __ARM_EABI__
486 #error EABI is required (to be sure that calling conventions are compatible)
487 #endif
488 pld [r0]
489 uqadd8 r0, r0, r0]])], have_arm_simd=yes)
490 CFLAGS=$xserver_save_CFLAGS
491
492 AC_ARG_ENABLE(arm-simd,
493    [AC_HELP_STRING([--disable-arm-simd],
494                    [disable ARM SIMD fast paths])],
495    [enable_arm_simd=$enableval], [enable_arm_simd=auto])
496
497 if test $enable_arm_simd = no ; then
498    have_arm_simd=disabled
499 fi
500
501 if test $have_arm_simd = yes ; then
502    AC_DEFINE(USE_ARM_SIMD, 1, [use ARM SIMD assembly optimizations])
503 fi
504
505 AM_CONDITIONAL(USE_ARM_SIMD, test $have_arm_simd = yes)
506
507 AC_MSG_RESULT($have_arm_simd)
508 if test $enable_arm_simd = yes && test $have_arm_simd = no ; then
509    AC_MSG_ERROR([ARM SIMD intrinsics not detected])
510 fi
511
512 dnl ==========================================================================
513 dnl Check if assembler is gas compatible and supports NEON instructions
514 have_arm_neon=no
515 AC_MSG_CHECKING(whether to use ARM NEON assembler)
516 xserver_save_CFLAGS=$CFLAGS
517 CFLAGS="-x assembler-with-cpp $CFLAGS"
518 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
519 .text
520 .fpu neon
521 .arch armv7a
522 .object_arch armv4
523 .eabi_attribute 10, 0
524 .arm
525 .altmacro
526 #ifndef __ARM_EABI__
527 #error EABI is required (to be sure that calling conventions are compatible)
528 #endif
529 pld [r0]
530 vmovn.u16 d0, q0]])], have_arm_neon=yes)
531 CFLAGS=$xserver_save_CFLAGS
532
533 AC_ARG_ENABLE(arm-neon,
534    [AC_HELP_STRING([--disable-arm-neon],
535                    [disable ARM NEON fast paths])],
536    [enable_arm_neon=$enableval], [enable_arm_neon=auto])
537
538 if test $enable_arm_neon = no ; then
539    have_arm_neon=disabled
540 fi
541
542 if test $have_arm_neon = yes ; then
543    AC_DEFINE(USE_ARM_NEON, 1, [use ARM NEON assembly optimizations])
544 fi
545
546 AM_CONDITIONAL(USE_ARM_NEON, test $have_arm_neon = yes)
547
548 AC_MSG_RESULT($have_arm_neon)
549 if test $enable_arm_neon = yes && test $have_arm_neon = no ; then
550    AC_MSG_ERROR([ARM NEON intrinsics not detected])
551 fi
552
553 dnl ===========================================================================
554 dnl Check for IWMMXT
555
556 if test "x$IWMMXT_CFLAGS" = "x" ; then
557    IWMMXT_CFLAGS="-march=iwmmxt -flax-vector-conversions -Winline"
558 fi
559
560 have_iwmmxt_intrinsics=no
561 AC_MSG_CHECKING(whether to use ARM IWMMXT intrinsics)
562 xserver_save_CFLAGS=$CFLAGS
563 CFLAGS="$IWMMXT_CFLAGS $CFLAGS"
564 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
565 #ifndef __arm__
566 #error "IWMMXT is only available on ARM"
567 #endif
568 #if defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6))
569 #error "Need GCC >= 4.6 for IWMMXT intrinsics"
570 #endif
571 #include <mmintrin.h>
572 int main () {
573         union {
574                 __m64 v;
575                 char c[8];
576         } a = { .c = {1, 2, 3, 4, 5, 6, 7, 8} };
577         int b = 4;
578         __m64 c = _mm_srli_si64 (a.v, b);
579 }]])], have_iwmmxt_intrinsics=yes)
580 CFLAGS=$xserver_save_CFLAGS
581
582 AC_ARG_ENABLE(arm-iwmmxt,
583    [AC_HELP_STRING([--disable-arm-iwmmxt],
584                    [disable ARM IWMMXT fast paths])],
585    [enable_iwmmxt=$enableval], [enable_iwmmxt=auto])
586
587 if test $enable_iwmmxt = no ; then
588    have_iwmmxt_intrinsics=disabled
589 fi
590
591 if test $have_iwmmxt_intrinsics = yes ; then
592    AC_DEFINE(USE_ARM_IWMMXT, 1, [use ARM IWMMXT compiler intrinsics])
593 else
594    IWMMXT_CFLAGS=
595 fi
596
597 AC_MSG_RESULT($have_iwmmxt_intrinsics)
598 if test $enable_iwmmxt = yes && test $have_iwmmxt_intrinsics = no ; then
599    AC_MSG_ERROR([IWMMXT intrinsics not detected])
600 fi
601
602 AM_CONDITIONAL(USE_ARM_IWMMXT, test $have_iwmmxt_intrinsics = yes)
603
604 dnl ==========================================================================
605 dnl Check if assembler is gas compatible and supports MIPS DSPr2 instructions
606
607 have_mips_dspr2=no
608 AC_MSG_CHECKING(whether to use MIPS DSPr2 assembler)
609 xserver_save_CFLAGS=$CFLAGS
610 CFLAGS="-mdspr2 $CFLAGS"
611
612 AC_COMPILE_IFELSE([[
613 #if !(defined(__mips__) &&  __mips_isa_rev >= 2)
614 #error MIPS DSPr2 is currently only available on MIPS32r2 platforms.
615 #endif
616 int
617 main ()
618 {
619     int c = 0, a = 0, b = 0;
620     __asm__ __volatile__ (
621         "precr.qb.ph %[c], %[a], %[b]          \n\t"
622         : [c] "=r" (c)
623         : [a] "r" (a), [b] "r" (b)
624     );
625     return c;
626 }]], have_mips_dspr2=yes)
627 CFLAGS=$xserver_save_CFLAGS
628
629 AC_ARG_ENABLE(mips-dspr2,
630    [AC_HELP_STRING([--disable-mips-dspr2],
631                    [disable MIPS DSPr2 fast paths])],
632    [enable_mips_dspr2=$enableval], [enable_mips_dspr2=auto])
633
634 if test $enable_mips_dspr2 = no ; then
635    have_mips_dspr2=disabled
636 fi
637
638 if test $have_mips_dspr2 = yes ; then
639    AC_DEFINE(USE_MIPS_DSPR2, 1, [use MIPS DSPr2 assembly optimizations])
640 fi
641
642 AM_CONDITIONAL(USE_MIPS_DSPR2, test $have_mips_dspr2 = yes)
643
644 AC_MSG_RESULT($have_mips_dspr2)
645 if test $enable_mips_dspr2 = yes && test $have_mips_dspr2 = no ; then
646    AC_MSG_ERROR([MIPS DSPr2 instructions not detected])
647 fi
648
649 dnl =========================================================================================
650 dnl Check for GNU-style inline assembly support
651
652 have_gcc_inline_asm=no
653 AC_MSG_CHECKING(whether to use GNU-style inline assembler)
654 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
655 int main () {
656     /* Most modern architectures have a NOP instruction, so this is a fairly generic test. */
657         asm volatile ( "\tnop\n" : : : "cc", "memory" );
658     return 0;
659 }]])], have_gcc_inline_asm=yes)
660
661 AC_ARG_ENABLE(gcc-inline-asm,
662    [AC_HELP_STRING([--disable-gcc-inline-asm],
663                    [disable GNU-style inline assembler])],
664    [enable_gcc_inline_asm=$enableval], [enable_gcc_inline_asm=auto])
665
666 if test $enable_gcc_inline_asm = no ; then
667    have_gcc_inline_asm=disabled
668 fi
669
670 if test $have_gcc_inline_asm = yes ; then
671    AC_DEFINE(USE_GCC_INLINE_ASM, 1, [use GNU-style inline assembler])
672 fi
673
674 AC_MSG_RESULT($have_gcc_inline_asm)
675 if test $enable_gcc_inline_asm = yes && test $have_gcc_inline_asm = no ; then
676    AC_MSG_ERROR([GNU-style inline assembler not detected])
677 fi
678
679 AM_CONDITIONAL(USE_GCC_INLINE_ASM, test $have_gcc_inline_asm = yes)
680
681 dnl ==============================================
682 dnl Static test programs
683
684 AC_ARG_ENABLE(static-testprogs,
685    [AC_HELP_STRING([--enable-static-testprogs],
686                    [build test programs as static binaries [default=no]])],
687    [enable_static_testprogs=$enableval], [enable_static_testprogs=no])
688
689 TESTPROGS_EXTRA_LDFLAGS=
690 if test "x$enable_static_testprogs" = "xyes" ; then
691    TESTPROGS_EXTRA_LDFLAGS="-all-static"
692 fi
693 AC_SUBST(TESTPROGS_EXTRA_LDFLAGS)
694
695 dnl ==============================================
696 dnl Timers
697
698 AC_ARG_ENABLE(timers,
699    [AC_HELP_STRING([--enable-timers],
700                    [enable TIMER_BEGIN and TIMER_END macros [default=no]])],
701    [enable_timers=$enableval], [enable_timers=no])
702
703 if test $enable_timers = yes ; then 
704    AC_DEFINE(PIXMAN_TIMERS, 1, [enable TIMER_BEGIN/TIMER_END macros])
705 fi
706 AC_SUBST(PIXMAN_TIMERS)
707
708 dnl ===================================
709 dnl GTK+
710
711 AC_ARG_ENABLE(gtk,
712    [AC_HELP_STRING([--enable-gtk],
713                    [enable tests using GTK+ [default=auto]])],
714    [enable_gtk=$enableval], [enable_gtk=auto])
715
716 PKG_PROG_PKG_CONFIG
717
718 if test $enable_gtk = yes ; then
719    AC_CHECK_LIB([pixman-1], [pixman_version_string])
720    PKG_CHECK_MODULES(GTK, [gtk+-2.0 pixman-1])
721 fi
722
723 if test $enable_gtk = auto ; then
724    AC_CHECK_LIB([pixman-1], [pixman_version_string], [enable_gtk=auto], [enable_gtk=no])
725 fi
726
727 if test $enable_gtk = auto ; then
728    PKG_CHECK_MODULES(GTK, [gtk+-2.0 pixman-1], [enable_gtk=yes], [enable_gtk=no])
729 fi
730
731 AM_CONDITIONAL(HAVE_GTK, [test "x$enable_gtk" = xyes])
732
733 AC_SUBST(GTK_CFLAGS)
734 AC_SUBST(GTK_LIBS)
735 AC_SUBST(DEP_CFLAGS)
736 AC_SUBST(DEP_LIBS)
737
738 dnl =====================================
739 dnl posix_memalign, sigaction, alarm, gettimeofday
740
741 AC_CHECK_FUNC(posix_memalign, have_posix_memalign=yes, have_posix_memalign=no)
742 if test x$have_posix_memalign = xyes; then
743    AC_DEFINE(HAVE_POSIX_MEMALIGN, 1, [Whether we have posix_memalign()])
744 fi
745
746 AC_CHECK_FUNC(sigaction, have_sigaction=yes, have_sigaction=no)
747 if test x$have_sigaction = xyes; then
748    AC_DEFINE(HAVE_SIGACTION, 1, [Whether we have sigaction()])
749 fi
750
751 AC_CHECK_FUNC(alarm, have_alarm=yes, have_alarm=no)
752 if test x$have_alarm = xyes; then
753    AC_DEFINE(HAVE_ALARM, 1, [Whether we have alarm()])
754 fi
755
756 AC_CHECK_HEADER([sys/mman.h],
757    [AC_DEFINE(HAVE_SYS_MMAN_H, [1], [Define to 1 if we have <sys/mman.h>])])
758
759 AC_CHECK_FUNC(mmap, have_mmap=yes, have_mmap=no)
760 if test x$have_mmap = xyes; then
761    AC_DEFINE(HAVE_MMAP, 1, [Whether we have mmap()])
762 fi
763
764 AC_CHECK_FUNC(mprotect, have_mprotect=yes, have_mprotect=no)
765 if test x$have_mprotect = xyes; then
766    AC_DEFINE(HAVE_MPROTECT, 1, [Whether we have mprotect()])
767 fi
768
769 AC_CHECK_FUNC(getpagesize, have_getpagesize=yes, have_getpagesize=no)
770 if test x$have_getpagesize = xyes; then
771    AC_DEFINE(HAVE_GETPAGESIZE, 1, [Whether we have getpagesize()])
772 fi
773
774 AC_CHECK_HEADER([fenv.h],
775    [AC_DEFINE(HAVE_FENV_H, [1], [Define to 1 if we have <fenv.h>])])
776
777 AC_CHECK_LIB(m, feenableexcept, have_feenableexcept=yes, have_feenableexcept=no)
778 if test x$have_feenableexcept = xyes; then
779    AC_DEFINE(HAVE_FEENABLEEXCEPT, 1, [Whether we have feenableexcept()])
780 fi
781
782 AC_CHECK_FUNC(gettimeofday, have_gettimeofday=yes, have_gettimeofday=no)
783 AC_CHECK_HEADER(sys/time.h, have_sys_time_h=yes, have_sys_time_h=no)
784 if test x$have_gettimeofday = xyes && test x$have_sys_time_h = xyes; then
785    AC_DEFINE(HAVE_GETTIMEOFDAY, 1, [Whether we have gettimeofday()])
786 fi
787
788 dnl =====================================
789 dnl Thread local storage
790
791 AC_MSG_CHECKING(for thread local storage (TLS) support)
792 AC_CACHE_VAL(ac_cv_tls, [
793     ac_cv_tls=none
794     keywords="__thread __declspec(thread)"
795     for kw in $keywords ; do
796         AC_TRY_COMPILE([
797 #if defined(__MINGW32__) && !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
798 #error This MinGW version has broken __thread support
799 #endif
800 #ifdef __OpenBSD__
801 #error OpenBSD has broken __thread support
802 #endif
803
804 int $kw test;], [], ac_cv_tls=$kw)
805     done
806 ])
807 AC_MSG_RESULT($ac_cv_tls)
808
809 if test "$ac_cv_tls" != "none"; then
810     AC_DEFINE_UNQUOTED([TLS], $pixman_tls, [The compiler supported TLS storage class])
811 fi
812
813 dnl
814 dnl posix tls
815 dnl
816
817 m4_define([pthread_test_program],AC_LANG_SOURCE([[dnl
818 #include <stdlib.h>
819 #include <pthread.h>
820
821 static pthread_once_t once_control = PTHREAD_ONCE_INIT;
822 static pthread_key_t key;
823
824 static void
825 make_key (void)
826 {
827     pthread_key_create (&key, NULL);
828 }
829
830 int
831 main ()
832 {
833     void *value = NULL;
834
835     if (pthread_once (&once_control, make_key) != 0)
836     {
837         value = NULL;
838     }
839     else
840     {
841         value = pthread_getspecific (key);
842         if (!value)
843         {
844             value = malloc (100);
845             pthread_setspecific (key, value);
846         }
847     }
848     return 0;
849 }
850 ]]))
851
852 AC_DEFUN([PIXMAN_CHECK_PTHREAD],[dnl
853     if test "z$support_for_pthread_setspecific" != "zyes"; then
854         PIXMAN_LINK_WITH_ENV(
855                 [$1], [pthread_test_program],
856                 [PTHREAD_CFLAGS="$CFLAGS"
857                  PTHREAD_LIBS="$LIBS"
858                  PTHREAD_LDFLAGS="$LDFLAGS"
859                  support_for_pthread_setspecific=yes])
860     fi
861 ])
862
863 if test $ac_cv_tls = none ; then
864     support_for_pthread_setspecific=no
865
866     AC_MSG_CHECKING(for pthread_setspecific)
867
868     PIXMAN_CHECK_PTHREAD([CFLAGS="-D_REENTRANT"; LIBS="-lpthread"])
869     PIXMAN_CHECK_PTHREAD([CFLAGS="-pthread"; LDFLAGS="-pthread"])
870     PIXMAN_CHECK_PTHREAD([CFLAGS="-D_REENTRANT"; LDFLAGS="-lroot"])
871     
872     if test $support_for_pthread_setspecific = yes; then
873         CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
874         AC_DEFINE([HAVE_PTHREAD_SETSPECIFIC], [], [Whether pthread_setspecific() is supported])
875     fi
876
877     AC_MSG_RESULT($support_for_pthread_setspecific);
878 fi
879
880 AC_SUBST(TOOLCHAIN_SUPPORTS__THREAD)
881 AC_SUBST(HAVE_PTHREAD_SETSPECIFIC)
882 AC_SUBST(PTHREAD_LDFLAGS)
883 AC_SUBST(PTHREAD_LIBS)
884
885 dnl =====================================
886 dnl __attribute__((constructor))
887
888 support_for_attribute_constructor=no
889
890 AC_MSG_CHECKING(for __attribute__((constructor)))
891 AC_LINK_IFELSE([AC_LANG_SOURCE([[
892 #if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7))
893 /* attribute 'constructor' is supported since gcc 2.7, but some compilers
894  * may only pretend to be gcc, so let's try to actually use it
895  */
896 static int x = 1;
897 static void __attribute__((constructor)) constructor_function () { x = 0; }
898 int main (void) { return x; }
899 #else
900 #error not gcc or gcc version is older than 2.7
901 #endif
902 ]])], support_for_attribute_constructor=yes)
903
904 if test x$support_for_attribute_constructor = xyes; then
905    AC_DEFINE([TOOLCHAIN_SUPPORTS_ATTRIBUTE_CONSTRUCTOR],
906              [],[Whether the tool chain supports __attribute__((constructor))])
907 fi
908
909 AC_MSG_RESULT($support_for_attribute_constructor)
910 AC_SUBST(TOOLCHAIN_SUPPORTS_ATTRIBUTE_CONSTRUCTOR)
911
912 dnl ==================
913 dnl libpng
914
915 AC_ARG_ENABLE(libpng, AS_HELP_STRING([--enable-libpng], [Build support for libpng (default: auto)]),
916                       [have_libpng=$enableval], [have_libpng=auto])
917
918 case x$have_libpng in
919         xyes) PKG_CHECK_MODULES(PNG, [libpng]) ;;
920         xno) ;;
921         *) PKG_CHECK_MODULES(PNG, [libpng], have_libpng=yes, have_libpng=no) ;;
922 esac
923
924 if test x$have_libpng = xyes; then
925     AC_DEFINE([HAVE_LIBPNG], [1], [Whether we have libpng])
926 fi
927
928 AC_SUBST(HAVE_LIBPNG)
929
930 AC_OUTPUT([pixman-1.pc
931            pixman-1-uninstalled.pc
932            Makefile
933            pixman/Makefile
934            pixman/pixman-version.h
935            demos/Makefile
936            test/Makefile])
937
938 m4_if(m4_eval(pixman_minor % 2), [1], [
939    echo
940    echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
941    echo
942    echo "      Thanks for testing this development snapshot of pixman. Please"
943    echo "      report any problems you find, either by sending email to "
944    echo
945    echo "          pixman@lists.freedesktop.org"
946    echo
947    echo "      or by filing a bug at "
948    echo
949    echo "          https://bugs.freedesktop.org/enter_bug.cgi?product=pixman "
950    echo
951    echo "      If you are looking for a stable release of pixman, please note "
952    echo "      that stable releases have _even_ minor version numbers. Ie., "
953    echo "      pixman-0.]m4_eval(pixman_minor & ~1)[.x are stable releases, whereas pixman-$PIXMAN_VERSION_MAJOR.$PIXMAN_VERSION_MINOR.$PIXMAN_VERSION_MICRO is a "
954    echo "      development snapshot that may contain bugs and experimental "
955    echo "      features. "
956    echo 
957    echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
958    echo
959 ])