1 dnl ==========================================================================
3 dnl Cairo-specific macros
6 dnl ==========================================================================
11 AC_DEFUN([CAIRO_BIGENDIAN],
15 AH_VERBATIM([X_BYTE_ORDER],
17 /* Deal with multiple architecture compiles on Mac OS X */
20 #define WORDS_BIGENDIAN 1
21 #define FLOAT_WORDS_BIGENDIAN 1
23 #undef WORDS_BIGENDIAN
24 #undef FLOAT_WORDS_BIGENDIAN
31 AX_C_FLOAT_WORDS_BIGENDIAN
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],
42 _save_cflags="$CFLAGS"
46 AC_CHECK_FUNCS($1, $4, $5)
47 CFLAGS="$_save_cflags"
51 dnl CAIRO_CONFIG_COMMANDS is like AC_CONFIG_COMMANDS, except that:
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.
56 AC_DEFUN([CAIRO_CONFIG_COMMANDS],
58 AC_CONFIG_COMMANDS($1,
61 _tmp_file=cairoconf.tmp
62 AC_MSG_NOTICE([creating $_config_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])
72 mv "$_tmp_file" "$_config_file" ||
73 AC_MSG_ERROR([failed to update $_config_file])
78 dnl CAIRO_CC_TRY_LINK_WITH_ENV_SILENT(env-setup, program,
79 dnl true-action, false-action)
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.
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"
103 [AC_LANG_SOURCE([$_compile_program])],
104 [cairo_cc_stderr=`test -f conftest.err && cat conftest.err`
106 [cairo_cc_stderr=`test -f conftest.err && cat conftest.err`
109 if test "x$cairo_cc_stderr" != "x"; then
113 if test "x$cairo_cc_flag" = "xyes"; then
114 ifelse([$3], , :, [$3])
116 ifelse([$4], , :, [$4])
118 CFLAGS="$_save_cflags"
119 LDFLAGS="$_save_ldflags"
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"],
130 dnl find a -Werror equivalent
131 AC_DEFUN([CAIRO_CC_CHECK_WERROR],
133 _test_WERROR=${WERROR+set}
134 if test "z$_test_WERROR" != zset; then
136 for _werror in -Werror -errwarn; do
137 AC_MSG_CHECKING([whether $CC supports $_werror])
138 CAIRO_CC_TRY_FLAG_SILENT(
140 [WERROR="$WERROR $_werror"],
142 AC_MSG_RESULT($cairo_cc_flag)
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])
157 dnl CAIRO_CHECK_NATIVE_ATOMIC_PRIMITIVES
158 AC_DEFUN([CAIRO_CHECK_NATIVE_ATOMIC_PRIMITIVES],
160 AC_CACHE_CHECK([for native atomic primitives], cairo_cv_atomic_primitives,
162 cairo_cv_atomic_primitives="none"
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); }
168 cairo_cv_atomic_primitives="Intel"
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); }
175 cairo_cv_atomic_primitives="cxx11"
178 if test "x$cairo_cv_atomic_primitives" = "xnone"; then
179 AC_CHECK_HEADER([atomic_ops.h],
180 cairo_cv_atomic_primitives="libatomic-ops")
183 if test "x$cairo_cv_atomic_primitives" = "xnone"; then
184 AC_CHECK_HEADER([libkern/OSAtomic.h],
185 cairo_cv_atomic_primitives="OSAtomic")
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])
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])
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])
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])
210 dnl CAIRO_CHECK_ATOMIC_OP_NEEDS_MEMORY_BARRIER
211 AC_DEFUN([CAIRO_CHECK_ATOMIC_OP_NEEDS_MEMORY_BARRIER],
213 AC_CACHE_CHECK([whether atomic ops require a memory barrier], cairo_cv_atomic_op_needs_memory_barrier,
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" ;;
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])
228 AC_DEFUN([CAIRO_TEXT_WRAP], [m4_text_wrap([$1], [$2],, 78)])