beta-0.89.2
[luatex.git] / source / libs / cairo / cairo-src / build / aclocal.cairo.m4
blob44ba5fdf6f5d092db87db4c94325930673f522ff
1 dnl ==========================================================================
2 dnl
3 dnl Cairo-specific macros
4 dnl
6 dnl ==========================================================================
8 dnl Usage:
9 dnl   CAIRO_BIGENDIAN
10 dnl
11 AC_DEFUN([CAIRO_BIGENDIAN],
12 [dnl
13         case $host_os in
14                 darwin*)
15         AH_VERBATIM([X_BYTE_ORDER],
17 /* Deal with multiple architecture compiles on Mac OS X */
18 #ifdef __APPLE_CC__
19 #ifdef __BIG_ENDIAN__
20 #define WORDS_BIGENDIAN 1
21 #define FLOAT_WORDS_BIGENDIAN 1
22 #else
23 #undef WORDS_BIGENDIAN
24 #undef FLOAT_WORDS_BIGENDIAN
25 #endif
26 #endif
28                 ;;
29                 *) 
30         AC_C_BIGENDIAN
31         AX_C_FLOAT_WORDS_BIGENDIAN
32                 ;;
33         esac
36 dnl CAIRO_CHECK_FUNCS_WITH_FLAGS(FUNCTION..., CFLAGS, LIBS
37 dnl                              [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
38 dnl Like AC_CHECK_FUNCS but with additional CFLAGS and LIBS
39 dnl --------------------------------------------------------------------
40 AC_DEFUN([CAIRO_CHECK_FUNCS_WITH_FLAGS],
41 [dnl 
42         _save_cflags="$CFLAGS"
43         _save_libs="$LIBS"
44         CFLAGS="$CFLAGS $2"
45         LIBS="$LIBS $3"
46         AC_CHECK_FUNCS($1, $4, $5)
47         CFLAGS="$_save_cflags"
48         LIBS="$_save_libs"
51 dnl CAIRO_CONFIG_COMMANDS is like AC_CONFIG_COMMANDS, except that:
52 dnl
53 dnl     1) It redirects the stdout of the command to the file.
54 dnl     2) It does not recreate the file if contents didn't change.
55 dnl
56 AC_DEFUN([CAIRO_CONFIG_COMMANDS],
57 [dnl
58         AC_CONFIG_COMMANDS($1,
59         [
60                 _config_file=$1
61                 _tmp_file=cairoconf.tmp
62                 AC_MSG_NOTICE([creating $_config_file])
63                 {
64                         $2
65                 } >> "$_tmp_file" ||
66                 AC_MSG_ERROR([failed to write to $_tmp_file])
68                 if cmp -s "$_tmp_file" "$_config_file"; then
69                   AC_MSG_NOTICE([$_config_file is unchanged])
70                   rm -f "$_tmp_file"
71                 else
72                   mv "$_tmp_file" "$_config_file" ||
73                   AC_MSG_ERROR([failed to update $_config_file])
74                 fi
75         ], $3)
78 dnl CAIRO_CC_TRY_LINK_WITH_ENV_SILENT(env-setup, program,
79 dnl                                   true-action, false-action)
80 dnl
81 dnl Compile and link the program with the given environment setup.
82 dnl The global cairo_cc_flag is set to "yes" or "no" according as
83 dnl the link succeeded or not.  The link step must complete without
84 dnl warnings or errors to stderr.
85 dnl
86 dnl Perform true-action on success and false-action on failure.
87 dnl The values of CFLAGS, LIBS, LDFLAGS are saved before env-setup
88 dnl is executed and restored right before the end of the macro.
89 AC_DEFUN([CAIRO_CC_TRY_LINK_WITH_ENV_SILENT],[dnl
90         # AC_LANG_PROGRAM() produces a main() w/o args,
91         # but -Wold-style-definition doesn't like that.
92         # We need _some_ program so that we don't get
93         # warnings about empty compilation units, so always
94         # append a reasonable main().
95         _compile_program="$2"'
96                 int main(int c, char **v) { (void)c; (void)v; return 0; }'
98         _save_cflags="$CFLAGS"
99         _save_ldflags="$LDFLAGS"
100         _save_libs="$LIBS"
101         $1
102         AC_LINK_IFELSE(
103                 [AC_LANG_SOURCE([$_compile_program])],
104                 [cairo_cc_stderr=`test -f conftest.err && cat conftest.err`
105                  cairo_cc_flag=yes],
106                 [cairo_cc_stderr=`test -f conftest.err && cat conftest.err`
107                  cairo_cc_flag=no])
109         if test "x$cairo_cc_stderr" != "x"; then
110                 cairo_cc_flag=no
111         fi
113         if test "x$cairo_cc_flag" = "xyes"; then
114                 ifelse([$3], , :, [$3])
115         else
116                 ifelse([$4], , :, [$4])
117         fi
118         CFLAGS="$_save_cflags"
119         LDFLAGS="$_save_ldflags"
120         LIBS="$_save_libs"
123 dnl check compiler flags with a program and no muttering.
124 AC_DEFUN([CAIRO_CC_TRY_FLAG_SILENT],
125 [dnl     (flags..., optional program, true-action, false-action)
126         CAIRO_CC_TRY_LINK_WITH_ENV_SILENT([CFLAGS="$CFLAGS $1"],
127                                           [$2], [$3], [$4])
130 dnl find a -Werror equivalent
131 AC_DEFUN([CAIRO_CC_CHECK_WERROR],
132 [dnl
133         _test_WERROR=${WERROR+set}
134         if test "z$_test_WERROR" != zset; then
135                 WERROR=""
136                 for _werror in -Werror -errwarn; do
137                         AC_MSG_CHECKING([whether $CC supports $_werror])
138                         CAIRO_CC_TRY_FLAG_SILENT(
139                                 [$_werror],,
140                                 [WERROR="$WERROR $_werror"],
141                                 [:])
142                         AC_MSG_RESULT($cairo_cc_flag)
143                 done
144         fi
147 dnl check compiler flags possibly using -Werror if available.
148 AC_DEFUN([CAIRO_CC_TRY_FLAG],
149 [dnl     (flags..., optional program, true-action, false-action)
150         CAIRO_CC_CHECK_WERROR
151         AC_MSG_CHECKING([whether $CC supports $1])
152         CAIRO_CC_TRY_FLAG_SILENT([$WERROR $1], [$2], [$3], [$4])
153         AC_MSG_RESULT([$cairo_cc_flag])
156 dnl Usage:
157 dnl   CAIRO_CHECK_NATIVE_ATOMIC_PRIMITIVES
158 AC_DEFUN([CAIRO_CHECK_NATIVE_ATOMIC_PRIMITIVES],
159 [dnl
160         AC_CACHE_CHECK([for native atomic primitives], cairo_cv_atomic_primitives,
161         [
162                 cairo_cv_atomic_primitives="none"
164                 AC_TRY_LINK([
165 int atomic_add(int i) { return __sync_fetch_and_add (&i, 1); }
166 int atomic_cmpxchg(int i, int j, int k) { return __sync_val_compare_and_swap (&i, j, k); }
167 ], [],
168                   cairo_cv_atomic_primitives="Intel"
169                   )
171                 AC_TRY_LINK([
172 int atomic_add(int i) { return __atomic_fetch_add(&i, 1, __ATOMIC_SEQ_CST); }
173 int atomic_cmpxchg(int i, int j, int k) { return __atomic_compare_exchange_n(&i, &j, k, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); }
174 ], [],
175                    cairo_cv_atomic_primitives="cxx11"
176                    )
178                 if test "x$cairo_cv_atomic_primitives" = "xnone"; then
179                         AC_CHECK_HEADER([atomic_ops.h],
180                                         cairo_cv_atomic_primitives="libatomic-ops")
181                 fi
183                 if test "x$cairo_cv_atomic_primitives" = "xnone"; then
184                         AC_CHECK_HEADER([libkern/OSAtomic.h],
185                                         cairo_cv_atomic_primitives="OSAtomic")
186                 fi
187         ])
188         if test "x$cairo_cv_atomic_primitives" = xcxx11; then
189                 AC_DEFINE(HAVE_CXX11_ATOMIC_PRIMITIVES, 1,
190                           [Enable if your compiler supports the GCC __atomic_* atomic primitives])
191         fi
193         if test "x$cairo_cv_atomic_primitives" = xIntel; then
194                 AC_DEFINE(HAVE_INTEL_ATOMIC_PRIMITIVES, 1,
195                           [Enable if your compiler supports the Intel __sync_* atomic primitives])
196         fi
198         if test "x$cairo_cv_atomic_primitives" = "xlibatomic-ops"; then
199                 AC_DEFINE(HAVE_LIB_ATOMIC_OPS, 1,
200                           [Enable if you have libatomic-ops-dev installed])
201         fi
203         if test "x$cairo_cv_atomic_primitives" = xOSAtomic; then
204                 AC_DEFINE(HAVE_OS_ATOMIC_OPS, 1,
205                           [Enable if you have MacOS X atomic operations])
206         fi
209 dnl Usage:
210 dnl   CAIRO_CHECK_ATOMIC_OP_NEEDS_MEMORY_BARRIER
211 AC_DEFUN([CAIRO_CHECK_ATOMIC_OP_NEEDS_MEMORY_BARRIER],
212 [dnl
213         AC_CACHE_CHECK([whether atomic ops require a memory barrier], cairo_cv_atomic_op_needs_memory_barrier,
214         [
215                 case $host_cpu in
216                     i?86)       cairo_cv_atomic_op_needs_memory_barrier="no"  ;;
217                     x86_64)     cairo_cv_atomic_op_needs_memory_barrier="no"  ;;
218                     arm*)       cairo_cv_atomic_op_needs_memory_barrier="no"  ;;
219                     *)          cairo_cv_atomic_op_needs_memory_barrier="yes" ;;
220                 esac
221         ])
222         if test "x$cairo_cv_atomic_op_needs_memory_barrier" = "xyes"; then
223             AC_DEFINE_UNQUOTED(ATOMIC_OP_NEEDS_MEMORY_BARRIER, 1,
224                                [whether memory barriers are needed around atomic operations])
225         fi
228 AC_DEFUN([CAIRO_TEXT_WRAP], [m4_text_wrap([$1], [$2],, 78)])