[cairo-commit] 4 commits - build/aclocal.cairo.m4 build/ax-pthread.m4 build/configure.ac.noversion build/configure.ac.pthread build/configure.ac.warnings configure.ac test/cairo-test.c test/cairo-test-trace.c test/Makefile.am util/cairo-sphinx util/cairo-trace
M. Joonas Pihlaja
joonas at kemper.freedesktop.org
Sun Jul 11 11:44:22 PDT 2010
build/aclocal.cairo.m4 | 52 +++----
build/ax-pthread.m4 | 283 ------------------------------------------
build/configure.ac.noversion | 13 +
build/configure.ac.pthread | 253 +++++++++++++++++++++++++++++++++++++
build/configure.ac.warnings | 2
configure.ac | 47 ++----
test/Makefile.am | 16 --
test/cairo-test-trace.c | 10 -
test/cairo-test.c | 6
util/cairo-sphinx/Makefile.am | 3
util/cairo-sphinx/sphinx.c | 4
util/cairo-trace/Makefile.am | 4
12 files changed, 331 insertions(+), 362 deletions(-)
New commits:
commit 3f1d7de8e1620ad385930477b63454107dd8ffd3
Author: M Joonas Pihlaja <jpihlaja at cc.helsinki.fi>
Date: Sun Jul 11 17:29:07 2010 +0300
build: Fix regression provoked by newer autoconf and dodgy configuring.
We're not supposed to be redefining PACKAGE_VERSION, PACKAGE_...
from the configure generated confdefs.h. This patch rudely adds
paper over the problem. The compiler warnings are a problem for
us since our checking of various compiler flags assumes that
no news is good news, and that any warning messages are due
to the flags under test. The regression appears when using
an autoconf >= 2.64, at least, but not with 2.61.
The same issue appears in the pthread test because our conftest
unconditionally #defines _GNU_SOURCE, but autoconf ends up doing
that in the confdefs.h.
diff --git a/build/configure.ac.noversion b/build/configure.ac.noversion
index 1e14548..18c4bd5 100644
--- a/build/configure.ac.noversion
+++ b/build/configure.ac.noversion
@@ -5,8 +5,19 @@ dnl
dnl Disable autoconf's version macros. We try hard to not rebuild the entire
dnl library just because version changed. The PACKAGE_VERSION* stuff in
dnl config.h is negating all the effort.
+dnl
+dnl We're not actually supposed to be doing this, and indeed adding the
+dnl AC_DEFINEs below causes confdefs.h to contain duplicate incompatible
+dnl #defines for the same PACKAGE_* symbols. Those are provoking warnings
+dnl from the compiler, and that throws our CAIRO_TRY_LINK_*_ checks off,
+dnl because they think that there's something wrong with some flag they're
+dnl testing rather than confdefs.h! So let's do the gross thing and puke
+dnl into confdefs.h some #undefs.
+echo '#undef PACKAGE_VERSION' >>confdefs.h
+echo '#undef PACKAGE_STRING' >>confdefs.h
+echo '#undef PACKAGE_NAME' >>confdefs.h
+echo '#undef PACKAGE_TARNAME' >>confdefs.h
AC_DEFINE(PACKAGE_VERSION, [USE_cairo_version_OR_cairo_version_string_INSTEAD])
AC_DEFINE(PACKAGE_STRING, [USE_cairo_version_OR_cairo_version_string_INSTEAD])
AC_DEFINE(PACKAGE_NAME, [USE_cairo_INSTEAD])
AC_DEFINE(PACKAGE_TARNAME, [USE_cairo_INSTEAD])
-
diff --git a/build/configure.ac.pthread b/build/configure.ac.pthread
index 93c967a..b25d6b7 100644
--- a/build/configure.ac.pthread
+++ b/build/configure.ac.pthread
@@ -46,7 +46,9 @@ dnl A program to test all the pthread features we need to be able to
dnl compile libcairo itself. We could test the features independently,
dnl but we need all of them anyway.
m4_define([libcairo_pthread_program],[dnl
+#ifndef _GNU_SOURCE
#define _GNU_SOURCE /* for PTHREAD_MUTEX_INITIALIZER under linux */
+#endif
#include <pthread.h>
pthread_mutex_t test_mutex_initializer = PTHREAD_MUTEX_INITIALIZER;
commit fca8977219b857e2e61dd86ac39ae9f40086f306
Author: M Joonas Pihlaja <jpihlaja at cc.helsinki.fi>
Date: Sun Jun 27 03:03:17 2010 +0300
build: Rework pthread detection.
Use two levels of pthread support: a minimal level used to
build cairo itself, and a full level to build threaded apps
which want to use cairo. The minimal level tries to use
pthread stubs from libc if possible, but falls back to the
full level if that's not possible. We use CFLAGS=-D_REENTRANT
LIBS=-lpthread to find a real pthread library since that seems
to work on every unix-like test box we can get our hands on.
diff --git a/build/ax-pthread.m4 b/build/ax-pthread.m4
deleted file mode 100644
index bdae477..0000000
--- a/build/ax-pthread.m4
+++ /dev/null
@@ -1,283 +0,0 @@
-# ===========================================================================
-# http://www.gnu.org/software/autoconf-archive/ax_pthread.html
-# ===========================================================================
-#
-# SYNOPSIS
-#
-# AX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
-#
-# DESCRIPTION
-#
-# This macro figures out how to build C programs using POSIX threads. It
-# sets the PTHREAD_LIBS output variable to the threads library and linker
-# flags, and the PTHREAD_CFLAGS output variable to any special C compiler
-# flags that are needed. (The user can also force certain compiler
-# flags/libs to be tested by setting these environment variables.)
-#
-# Also sets PTHREAD_CC to any special C compiler that is needed for
-# multi-threaded programs (defaults to the value of CC otherwise). (This
-# is necessary on AIX to use the special cc_r compiler alias.)
-#
-# NOTE: You are assumed to not only compile your program with these flags,
-# but also link it with them as well. e.g. you should link with
-# $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS
-#
-# If you are only building threads programs, you may wish to use these
-# variables in your default LIBS, CFLAGS, and CC:
-#
-# LIBS="$PTHREAD_LIBS $LIBS"
-# CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
-# CC="$PTHREAD_CC"
-#
-# In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant
-# has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to that name
-# (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
-#
-# ACTION-IF-FOUND is a list of shell commands to run if a threads library
-# is found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it
-# is not found. If ACTION-IF-FOUND is not specified, the default action
-# will define HAVE_PTHREAD.
-#
-# Please let the authors know if this macro fails on any platform, or if
-# you have any other suggestions or comments. This macro was based on work
-# by SGJ on autoconf scripts for FFTW (http://www.fftw.org/) (with help
-# from M. Frigo), as well as ac_pthread and hb_pthread macros posted by
-# Alejandro Forero Cuervo to the autoconf macro repository. We are also
-# grateful for the helpful feedback of numerous users.
-#
-# LICENSE
-#
-# Copyright (c) 2008 Steven G. Johnson <stevenj at alum.mit.edu>
-#
-# This program is free software: you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by the
-# Free Software Foundation, either version 3 of the License, or (at your
-# option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
-# Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program. If not, see <http://www.gnu.org/licenses/>.
-#
-# As a special exception, the respective Autoconf Macro's copyright owner
-# gives unlimited permission to copy, distribute and modify the configure
-# scripts that are the output of Autoconf when processing the Macro. You
-# need not follow the terms of the GNU General Public License when using
-# or distributing such scripts, even though portions of the text of the
-# Macro appear in them. The GNU General Public License (GPL) does govern
-# all other use of the material that constitutes the Autoconf Macro.
-#
-# This special exception to the GPL applies to versions of the Autoconf
-# Macro released by the Autoconf Archive. When you make and distribute a
-# modified version of the Autoconf Macro, you may extend this special
-# exception to the GPL to apply to your modified version as well.
-
-#serial 7
-
-AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD])
-AC_DEFUN([AX_PTHREAD], [
-AC_REQUIRE([AC_CANONICAL_HOST])
-AC_LANG_SAVE
-AC_LANG_C
-ax_pthread_ok=no
-
-# We used to check for pthread.h first, but this fails if pthread.h
-# requires special compiler flags (e.g. on True64 or Sequent).
-# It gets checked for in the link test anyway.
-
-# First of all, check if the user has set any of the PTHREAD_LIBS,
-# etcetera environment variables, and if threads linking works using
-# them:
-if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
- save_CFLAGS="$CFLAGS"
- CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
- save_LIBS="$LIBS"
- LIBS="$PTHREAD_LIBS $LIBS"
- AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
- AC_TRY_LINK_FUNC(pthread_join, ax_pthread_ok=yes)
- AC_MSG_RESULT($ax_pthread_ok)
- if test x"$ax_pthread_ok" = xno; then
- PTHREAD_LIBS=""
- PTHREAD_CFLAGS=""
- fi
- LIBS="$save_LIBS"
- CFLAGS="$save_CFLAGS"
-fi
-
-# We must check for the threads library under a number of different
-# names; the ordering is very important because some systems
-# (e.g. DEC) have both -lpthread and -lpthreads, where one of the
-# libraries is broken (non-POSIX).
-
-# Create a list of thread flags to try. Items starting with a "-" are
-# C compiler flags, and other items are library names, except for "none"
-# which indicates that we try without any flags at all, and "pthread-config"
-# which is a program returning the flags for the Pth emulation library.
-
-ax_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
-
-# The ordering *is* (sometimes) important. Some notes on the
-# individual items follow:
-
-# pthreads: AIX (must check this before -lpthread)
-# none: in case threads are in libc; should be tried before -Kthread and
-# other compiler flags to prevent continual compiler warnings
-# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
-# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
-# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
-# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
-# -pthreads: Solaris/gcc
-# -mthreads: Mingw32/gcc, Lynx/gcc
-# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
-# doesn't hurt to check since this sometimes defines pthreads too;
-# also defines -D_REENTRANT)
-# ... -mt is also the pthreads flag for HP/aCC
-# pthread: Linux, etcetera
-# --thread-safe: KAI C++
-# pthread-config: use pthread-config program (for GNU Pth library)
-
-case "${host_cpu}-${host_os}" in
- *solaris*)
-
- # On Solaris (at least, for some versions), libc contains stubbed
- # (non-functional) versions of the pthreads routines, so link-based
- # tests will erroneously succeed. (We need to link with -pthreads/-mt/
- # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
- # a function called by this macro, so we could check for that, but
- # who knows whether they'll stub that too in a future libc.) So,
- # we'll just look for -pthreads and -lpthread first:
-
- ax_pthread_flags="-pthreads pthread -mt -pthread $ax_pthread_flags"
- ;;
-
- *-darwin*)
- acx_pthread_flags="-pthread $acx_pthread_flags"
- ;;
-esac
-
-if test x"$ax_pthread_ok" = xno; then
-for flag in $ax_pthread_flags; do
-
- case $flag in
- none)
- AC_MSG_CHECKING([whether pthreads work without any flags])
- ;;
-
- -*)
- AC_MSG_CHECKING([whether pthreads work with $flag])
- PTHREAD_CFLAGS="$flag"
- ;;
-
- pthread-config)
- AC_CHECK_PROG(ax_pthread_config, pthread-config, yes, no)
- if test x"$ax_pthread_config" = xno; then continue; fi
- PTHREAD_CFLAGS="`pthread-config --cflags`"
- PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
- ;;
-
- *)
- AC_MSG_CHECKING([for the pthreads library -l$flag])
- PTHREAD_LIBS="-l$flag"
- ;;
- esac
-
- save_LIBS="$LIBS"
- save_CFLAGS="$CFLAGS"
- LIBS="$PTHREAD_LIBS $LIBS"
- CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
-
- # Check for various functions. We must include pthread.h,
- # since some functions may be macros. (On the Sequent, we
- # need a special flag -Kthread to make this header compile.)
- # We check for pthread_join because it is in -lpthread on IRIX
- # while pthread_create is in libc. We check for pthread_attr_init
- # due to DEC craziness with -lpthreads. We check for
- # pthread_cleanup_push because it is one of the few pthread
- # functions on Solaris that doesn't have a non-functional libc stub.
- # We try pthread_create on general principles.
- AC_TRY_LINK([#include <pthread.h>
- static void routine(void* a) {a=0;}
- static void* start_routine(void* a) {return a;}],
- [pthread_t th; pthread_attr_t attr;
- pthread_join(th, 0);
- pthread_attr_init(&attr);
- pthread_cleanup_push(routine, 0);
- pthread_create(&th,0,start_routine,0);
- pthread_cleanup_pop(0); ],
- [ax_pthread_ok=yes])
-
- LIBS="$save_LIBS"
- CFLAGS="$save_CFLAGS"
-
- AC_MSG_RESULT($ax_pthread_ok)
- if test "x$ax_pthread_ok" = xyes; then
- break;
- fi
-
- PTHREAD_LIBS=""
- PTHREAD_CFLAGS=""
-done
-fi
-
-# Various other checks:
-if test "x$ax_pthread_ok" = xyes; then
- save_LIBS="$LIBS"
- LIBS="$PTHREAD_LIBS $LIBS"
- save_CFLAGS="$CFLAGS"
- CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
-
- # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
- AC_MSG_CHECKING([for joinable pthread attribute])
- attr_name=unknown
- for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
- AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;],
- [attr_name=$attr; break])
- done
- AC_MSG_RESULT($attr_name)
- if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
- AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
- [Define to necessary symbol if this constant
- uses a non-standard name on your system.])
- fi
-
- AC_MSG_CHECKING([if more special flags are required for pthreads])
- flag=no
- case "${host_cpu}-${host_os}" in
- *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
- *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
- esac
- AC_MSG_RESULT(${flag})
- if test "x$flag" != xno; then
- PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
- fi
-
- LIBS="$save_LIBS"
- CFLAGS="$save_CFLAGS"
-
- # More AIX lossage: must compile with xlc_r or cc_r
- if test x"$GCC" != xyes; then
- AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC})
- else
- PTHREAD_CC=$CC
- fi
-else
- PTHREAD_CC="$CC"
-fi
-
-AC_SUBST(PTHREAD_LIBS)
-AC_SUBST(PTHREAD_CFLAGS)
-AC_SUBST(PTHREAD_CC)
-
-# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
-if test x"$ax_pthread_ok" = xyes; then
- ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])
- :
-else
- ax_pthread_ok=no
- $2
-fi
-AC_LANG_RESTORE
-])dnl AX_PTHREAD
diff --git a/build/configure.ac.pthread b/build/configure.ac.pthread
new file mode 100644
index 0000000..93c967a
--- /dev/null
+++ b/build/configure.ac.pthread
@@ -0,0 +1,251 @@
+dnl Defines the macro CAIRO_CONFIGURE_PTHREAD to find a suitable
+dnl pthread implementation. There are two levels of pthread conformance
+dnl we are looking for:
+dnl
+dnl a) A minimal level denoted by -DCAIRO_HAS_PTHREAD=1: This level
+dnl requires mutex and recursive mutexattr support. If possible we try
+dnl to use weakly linked stubs from libc over the real pthread library.
+dnl This level is required by the cairo library proper. If the user
+dnl invokes configure with dnlenable-pthread=yes or
+dnl dnlenable-pthread=always then we avoid trying to use weak stubs.
+dnl
+dnl b) A full level denoted by -DCAIRO_HAS_REAL_PTHREAD=1: This level
+dnl requires full support from a real pthread library, including thread
+dnl creation, joins, thread attribtues, etc. This level is required by
+dnl multithreaded applications using cairo, such as the test suite
+dnl binaries and cairo utilities.
+dnl
+dnl Usage:
+dnl CAIRO_ENABLE(pthread, pthread, <default yes|no|auto|always>,
+dnl [CAIRO_CONFIGURE_PTHREAD])
+dnl
+dnl This should be invoked near the end of configure.ac so that
+dnl the pthread specific CFLAGS and LIBS end up at the front
+dnl of CAIRO_CFLAGS and CAIRO_LIBS dnl this helps ensure that we
+dnl really do get non-weak symbols from the actual pthread library
+dnl rather than possible stubs in other libraries.
+dnl
+dnl The user can override the choices made by
+dnl CAIRO_CONFIGURE_PTHREAD by using dnlenable-pthread=yes and
+dnl giving PTHREAD_CFLAGS and PTHREAD_LIBS to configure.
+dnl
+dnl Sets environment variables:
+dnl use_pthread="yes" | "no (<errmsg>)"
+dnl have_pthread="yes" | "no (<errmsg)"
+dnl have_real_pthread="yes" | "no (<errmsg)"
+dnl pthread_{CFLAGS,LIBS,REQUIRES}
+dnl real_pthread_{CFLAGS,LIBS}
+dnl
+dnl Autoconfigured defines in config.h (conditional):
+dnl CAIRO_HAS_PTHREAD
+dnl CAIRO_HAS_REAL_PTHREAD
+dnl
+
+dnl -----------------------------------------------------------------------
+dnl A program to test all the pthread features we need to be able to
+dnl compile libcairo itself. We could test the features independently,
+dnl but we need all of them anyway.
+m4_define([libcairo_pthread_program],[dnl
+#define _GNU_SOURCE /* for PTHREAD_MUTEX_INITIALIZER under linux */
+#include <pthread.h>
+
+pthread_mutex_t test_mutex_initializer = PTHREAD_MUTEX_INITIALIZER;
+int test_mutex (void)
+{
+ int x = 0;
+ pthread_mutex_t mutex;
+ x |= pthread_mutex_init (&mutex, NULL);
+ x |= pthread_mutex_lock (&mutex);
+ x |= pthread_mutex_unlock (&mutex);
+ x |= pthread_mutex_destroy (&mutex);
+ return 0;
+}
+
+int test_mutex_attr (void)
+{
+ int x = 0;
+ pthread_mutexattr_t attr;
+ pthread_mutex_t mutex;
+ x |= pthread_mutexattr_init (&attr);
+ x |= pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
+ x |= pthread_mutex_init (&mutex, &attr);
+ x |= pthread_mutex_lock (&mutex);
+ x |= pthread_mutex_unlock (&mutex);
+ x |= pthread_mutex_destroy (&mutex);
+ x |= pthread_mutexattr_destroy (&attr);
+ return x;
+}])
+
+dnl -----------------------------------------------------------------------
+dnl A program to test all the features we want to be able to run the test
+dnl suite or other thready cairo applications that want real threads.
+m4_define([testsuite_pthread_program],[dnl
+libcairo_pthread_program
+
+pthread_once_t once_control = PTHREAD_ONCE_INIT;
+void test_once_init (void) {}
+int test_once (void)
+{
+ return pthread_once (&once_control, test_once_init);
+}
+
+pthread_key_t test_specific_key;
+int test_specific (void)
+{
+ int x = 0;
+ x |= pthread_key_create (&test_specific_key, NULL);
+ x |= pthread_setspecific (test_specific_key, NULL);
+ x |= pthread_getspecific (test_specific_key) != NULL;
+ return x;
+}
+
+void cleaner (void *arg) { (void)arg; }
+
+void *
+test_thread_main (void *arg)
+{
+ pthread_cleanup_push (cleaner, arg)
+ pthread_exit (arg);
+ pthread_cleanup_pop (1);
+ return arg;
+}
+
+int
+test_threads (void)
+{
+ int x = 0;
+ pthread_t thread;
+ pthread_attr_t attr;
+ void *arg = NULL;
+ x |= pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
+ x |= pthread_create (&thread, &attr, test_thread_main, arg);
+ x |= pthread_equal (pthread_self(), thread);
+ x |= pthread_join (thread, &arg);
+ x |= pthread_attr_destroy (&attr);
+ return x;
+}])
+
+dnl -----------------------------------------------------------------------
+
+dnl CAIRO_CHECK_PTHREAD(tag, cflags, libs, program, true-action, false-action)
+dnl Set <tag>_{CFLAGS,LIBS} to {<cflags>,<libs>} if we can compile and link
+dnl <program> with the given flags and libs. Execute <true-action> on
+dnl success and <false-action> on failure.
+AC_DEFUN([CAIRO_CHECK_PTHREAD],[dnl
+ CAIRO_CC_TRY_LINK_WITH_ENV_SILENT(
+ [CFLAGS="$2";
+ LIBS="$3"],
+ [$4],
+ [$1_CFLAGS="$CFLAGS";
+ $1_LIBS="$LIBS";
+ $5],
+ [$1_CFLAGS="";
+ $1_LIBS="";
+ $6])
+])
+
+dnl CAIRO_CONFIGURE_PTHREADS(): Look for pthreads.
+dnl
+dnl If the user specifies PTHREAD_CFLAGS and PTHREAD_LIBS then we use
+dnl those. Otherwise we try CFLAGS=-D_REENTRANT and LIBS=-lpthread for
+dnl full pthread support, and look for stubs in libc for the minimal
+dnl pthread support.
+dnl
+dnl CFLAGS=-D_REENTRANT LIBS=-lpthread has been tested to work on:
+dnl
+dnl Solaris 9 (5.9) Sun C 5.8 Patch 121015-04 2007/01/10
+dnl OpenSolaris (5.11) Sun C 5.9 Patch 124868-08 2008/11/25
+dnl OpenSolaris (5.11) clang version 1.1 (trunk 90017)
+dnl Tru64/OSF1 V5.1 Compaq C V6.5-003
+dnl Mac OS X 10.5.5 gcc 4.0.1 (Apple Inc. build 5465)
+dnl Mac OS X 10.6 gcc 4.2.1 (Apple Inc. build 5659)
+dnl FreeBSD 7.2 gcc 4.2
+dnl OpenBSD 4.5 gcc 3.3.5 (propolice)
+dnl Debian Linux (Etch) gcc 4.3
+dnl
+dnl Thread support is also in various libcs directly, so often using no
+dnl flags at all works as well, but unfortunately Solaris 9 has
+dnl practically _all_ of libpthread stubbed out in libc, so we cannot
+dnl distinguish between a working libpthread and a stubbed out one by a
+dnl link-only test.
+dnl
+dnl We also explicitly do not link to pthread-stubs or whatever other
+dnl third-party stubs library, since that forces cairo clients to be
+dnl extra careful when giving both libcairo and libpthread on the
+dnl command line: the user would have to use "-lpthread -lcairo" rather
+dnl than the more common "-lcairo -lpthread" to not accidentally use
+dnl stubs pulled in by libcairo everywhere in the application. We
+dnl might also need to have a way to teach pkg-config about library
+dnl ordering constraints which aren't actual dependencies, and at this
+dnl point it just starts doing my head in.
+dnl
+dnl If your unix-like doesn't work with the secret handshake
+dnl -D_REENTRANT -lpthread and you can actually compile the rest of
+dnl cairo just fine otherwise, please take a moment complain loudly
+dnl to the cairo mailing list!
+dnl
+AC_DEFUN([CAIRO_CONFIGURE_PTHREAD],[dnl
+ dnl Try to use the user's PTHREAD_LIBS/CFLAGS
+ dnl if they're available.
+ if test "x$PTHREAD_CFLAGS" = "x"; then
+ PTHREAD_CFLAGS="-D_REENTRANT"
+ fi
+ if test "x$PTHREAD_LIBS" = "x"; then
+ PTHREAD_LIBS="-lpthread"
+ fi
+
+ dnl First try to find the real pthreads.
+ CAIRO_CHECK_PTHREAD(
+ [real_pthread], [$PTHREAD_CFLAGS], [$PTHREAD_LIBS],
+ [testsuite_pthread_program],
+ [have_real_pthread=yes],
+ [have_real_pthread=no])
+ if test "x$have_real_pthread" != "xyes"; then
+ dnl Give -pthread a go.
+ CAIRO_CHECK_PTHREAD(
+ [real_pthread], [-pthread], [],
+ [testsuite_pthread_program],
+ [have_real_pthread=yes],
+ [have_real_pthread="no (can't link with -lpthread or -pthread)"])
+ fi
+ PTHREAD_CFLAGS=
+ PTHREAD_LIBS=
+
+ dnl Check if we can use libc's stubs in libcairo.
+ dnl Only do this if the user hasn't explicitly enabled
+ dnl pthreads, but is relying on automatic configuration.
+ have_pthread="no"
+ if test "x$enable_pthread" != "xyes"; then
+ CAIRO_CHECK_PTHREAD(
+ [pthread], [-D_REENTRANT], [],
+ [libcairo_pthread_program],
+ [have_pthread=yes],
+ [])
+ fi
+
+ dnl Default to using the real pthreads for libcairo.
+ if test "x$have_pthread" != "xyes"; then
+ have_pthread="$have_real_pthread";
+ pthread_CFLAGS="$real_pthread_CFLAGS";
+ pthread_LIBS="$real_pthread_LIBS";
+ fi
+
+ dnl Tell autoconf about the results.
+ if test "x$have_real_pthread" = "xyes"; then
+ AC_DEFINE([CAIRO_HAS_REAL_PTHREAD], 1,
+ [Define to 1 if we have full pthread support])
+ fi
+ if test "x$have_pthread" = "xyes"; then
+ AC_DEFINE([CAIRO_HAS_PTHREAD], 1,
+ [Define to 1 f we have minimal pthread support])
+ fi
+
+ dnl Make sure we scored some pthreads.
+ if test "x$use_pthread" = "xyes" -a "x$have_pthread" != "xyes"; then
+ AC_MSG_ERROR([pthread requested but not found])
+ fi
+
+ dnl Set the output variables for CAIRO_ENABLE.
+ use_pthread="$have_pthread"
+ pthread_REQUIRES=""
+])
diff --git a/configure.ac b/configure.ac
index ee59224..cb66294 100644
--- a/configure.ac
+++ b/configure.ac
@@ -28,37 +28,11 @@ m4_include(build/configure.ac.warnings) dnl checks for compiler warning
m4_include(build/configure.ac.system) dnl checks for system functions, headers, libs
m4_include(build/configure.ac.analysis) dnl checks for analysis tools (lcov, etc)
m4_include(build/configure.ac.noversion) dnl disable builtin libtool versioning
+m4_include(build/configure.ac.pthread) dnl checks for pthreads
AC_CACHE_SAVE
dnl ===========================================================================
-AC_ARG_ENABLE(pthread,
- AS_HELP_STRING([--disable-pthread],
- [Do not use pthread]),
- [use_pthread=$enableval], [use_pthread=auto])
-
-have_pthread=no
-if test "x$use_pthread" != "xno"; then
- pthread_REQUIRES="pthread"
- PKG_CHECK_MODULES(PTHREAD, $pthread_REQUIRES,
- [use_pthread=yes; have_pthread=yes],
- [AX_PTHREAD([use_pthread=yes;
- have_pthread=yes
- ], [use_pthread="no (requires $pthread_REQUIRES)"])])
- if test "x$have_pthread" = "xyes"; then
- AC_DEFINE([CAIRO_HAS_PTHREAD], 1, [Define to 1 if we have pthread support])
- fi
-fi
-AM_CONDITIONAL(HAVE_PTHREAD, test "x$have_pthread" = "xyes")
-if test "x$have_pthread" = xno -a "x$use_pthread" = xyes; then
- AC_MSG_ERROR([pthread requested but not found])
-fi
-CAIRO_CFLAGS="$CAIRO_CFLAGS $PTHREAD_CFLAGS"
-CAIRO_LDFLAGS="$PTHREAD_CFLAGS $CAIRO_LDFLAGS"
-CAIRO_LIBS="$CAIRO_LIBS $PTHREAD_LIBS"
-
-dnl ===========================================================================
-
AC_CHECK_LIB(z, compress,
[AC_CHECK_HEADER(zlib.h, [
have_libz=yes
@@ -662,6 +636,22 @@ dnl ===========================================================================
CAIRO_ENABLE_FONT_BACKEND(user, user, always)
dnl ===========================================================================
+dnl
+dnl This needs to be last on our list of features so that the pthread libs and flags
+dnl gets prefixed in front of everything else in CAIRO_{CFLAGS,LIBS}.
+dnl
+have_real_pthread=no
+have_pthread=no
+CAIRO_ENABLE(pthread, pthread, auto, [CAIRO_CONFIGURE_PTHREAD])
+AM_CONDITIONAL(HAVE_REAL_PTHREAD, test "x$use_pthread" = "xyes" -a "x$have_real_pthread" = "xyes")
+AM_CONDITIONAL(HAVE_PTHREAD, test "x$use_pthread" = "xyes")
+AC_SUBST(pthread_CFLAGS)
+AC_SUBST(pthread_LIBS)
+AC_SUBST(real_pthread_CFLAGS)
+AC_SUBST(real_pthread_LIBS)
+
+
+dnl ===========================================================================
dnl Default to quick testing during development, but force a full test before
dnl release
@@ -715,8 +705,9 @@ esac
CAIRO_ENABLE(trace, cairo-trace, auto, [
if test "x$have_ld_preload" != "xyes" -o \
"x$have_libz" != "xyes" -o \
+ "x$have_real_pthread" != "xyes" -o \
"x$have_dlsym" != "xyes"; then
- use_trace="no (requires dynamic linker and zlib)"
+ use_trace="no (requires dynamic linker and zlib and real pthreads)"
fi
])
diff --git a/test/Makefile.am b/test/Makefile.am
index a66e010..54815f7 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -6,7 +6,7 @@ SUBDIRS=pdiff .
# Then we have a collection of tests that are only run if certain
# features are compiled into cairo
-if HAVE_PTHREAD
+if HAVE_REAL_PTHREAD
test_sources += $(pthread_test_sources)
endif
@@ -81,8 +81,9 @@ cairo_test_suite_SOURCES = \
$(cairo_test_suite_headers) \
$(test_sources) \
cairo-test-constructors.c
-cairo_test_suite_CFLAGS = $(AM_CFLAGS)
+cairo_test_suite_CFLAGS = $(AM_CFLAGS) $(real_pthread_CFLAGS)
cairo_test_suite_LDADD = \
+ $(real_pthread_LIBS) \
$(top_builddir)/test/pdiff/libpdiff.la \
$(top_builddir)/boilerplate/libcairoboilerplate.la \
$(top_builddir)/src/libcairo.la \
@@ -95,10 +96,6 @@ if BUILD_ANY2PPM
cairo_test_suite_DEPENDENCIES += \
any2ppm
endif
-if HAVE_PTHREAD
-cairo_test_suite_CFLAGS += -pthread
-cairo_test_suite_LDADD += -lpthread
-endif
if HAVE_SHM
EXTRA_PROGRAMS += cairo-test-trace
@@ -106,18 +103,15 @@ cairo_test_trace_SOURCES = \
cairo-test-trace.c \
buffer-diff.c \
buffer-diff.h
-cairo_test_trace_CFLAGS = $(AM_CFLAGS)
+cairo_test_trace_CFLAGS = $(AM_CFLAGS) $(real_pthread_CFLAGS)
cairo_test_trace_LDADD = \
+ $(real_pthread_LIBS) \
$(top_builddir)/test/pdiff/libpdiff.la \
$(top_builddir)/util/cairo-script/libcairo-script-interpreter.la \
$(top_builddir)/boilerplate/libcairoboilerplate.la \
$(top_builddir)/src/libcairo.la \
$(CAIRO_LDADD) \
$(SHM_LIBS)
-if HAVE_PTHREAD
-cairo_test_trace_CFLAGS += -pthread
-cairo_test_trace_LDADD += -lpthread
-endif
cairo_test_trace_DEPENDENCIES = \
$(top_builddir)/test/pdiff/libpdiff.la \
$(top_builddir)/util/cairo-script/libcairo-script-interpreter.la \
diff --git a/test/cairo-test-trace.c b/test/cairo-test-trace.c
index 77ee84b..1564319 100644
--- a/test/cairo-test-trace.c
+++ b/test/cairo-test-trace.c
@@ -82,7 +82,7 @@
#include <sys/un.h>
#include <errno.h>
#include <assert.h>
-#if CAIRO_HAS_PTHREAD
+#if CAIRO_HAS_REAL_PTHREAD
#include <pthread.h>
#endif
@@ -162,7 +162,7 @@ struct surface_tag {
};
static const cairo_user_data_key_t surface_tag;
-#if CAIRO_HAS_PTHREAD
+#if CAIRO_HAS_REAL_PTHREAD
#define tr_die(t) t->is_recording ? pthread_exit(NULL) : exit(1)
#else
#define tr_die(t) exit(1)
@@ -245,7 +245,7 @@ send_recording_surface (test_runner_t *tr,
int width, int height,
struct context_closure *closure)
{
-#if CAIRO_HAS_PTHREAD
+#if CAIRO_HAS_REAL_PTHREAD
const struct request_image rq = {
closure->id,
closure->start_line,
@@ -591,7 +591,7 @@ spawn_target (const char *socket_path,
exit (0);
}
-#if CAIRO_HAS_PTHREAD
+#if CAIRO_HAS_REAL_PTHREAD
static void
cleanup_recorder (void *arg)
{
@@ -1274,7 +1274,7 @@ _test_trace (test_trace_t *test,
s = slaves = xcalloc (2*test->num_targets + 1, sizeof (struct slave));
-#if CAIRO_HAS_PTHREAD
+#if CAIRO_HAS_REAL_PTHREAD
/* set-up a recording-surface to reconstruct errors */
slave = spawn_recorder (socket_path, trace);
if (slave < 0) {
diff --git a/test/cairo-test.c b/test/cairo-test.c
index 5b80ba1..69af6ba 100644
--- a/test/cairo-test.c
+++ b/test/cairo-test.c
@@ -47,7 +47,7 @@
#if HAVE_FCFINI
#include <fontconfig/fontconfig.h>
#endif
-#if CAIRO_HAS_PTHREAD
+#if CAIRO_HAS_REAL_PTHREAD
#include <pthread.h>
#endif
#if HAVE_SYS_STAT_H
@@ -1832,7 +1832,7 @@ _cairo_test_context_run (cairo_test_context_t *ctx)
return ret;
}
-#if CAIRO_HAS_PTHREAD
+#if CAIRO_HAS_REAL_PTHREAD
typedef struct _cairo_test_thread {
pthread_t thread;
cairo_test_context_t *ctx;
@@ -1867,7 +1867,7 @@ cairo_test_expecting (const cairo_test_t *test)
_cairo_test_init (&ctx, NULL, test, test->name);
printf ("%s\n", test->description);
-#if CAIRO_HAS_PTHREAD
+#if CAIRO_HAS_REAL_PTHREAD
num_threads = 0;
if (getenv ("CAIRO_TEST_NUM_THREADS"))
num_threads = atoi (getenv ("CAIRO_TEST_NUM_THREADS"));
diff --git a/util/cairo-sphinx/Makefile.am b/util/cairo-sphinx/Makefile.am
index 85368df..b25bd23 100644
--- a/util/cairo-sphinx/Makefile.am
+++ b/util/cairo-sphinx/Makefile.am
@@ -16,8 +16,9 @@ cairo_sphinx_la_LIBADD = -ldl
cairo_sphinx_SOURCES = sphinx.c
cairo_sphinx_CPPFLAGS = $(AM_CPPFLAGS) -DLIBDIR="\"$(cairolibdir)\""
-cairo_sphinx_CFLAGS = $(CAIRO_CFLAGS) $(glib_CFLAGS)
+cairo_sphinx_CFLAGS = $(CAIRO_CFLAGS) $(real_pthread_CFLAGS) $(glib_CFLAGS)
cairo_sphinx_LDADD = \
+ $(real_pthread_LIBS) \
$(top_builddir)/util/cairo-script/libcairo-script-interpreter.la \
$(top_builddir)/boilerplate/libcairoboilerplate.la \
$(top_builddir)/src/libcairo.la \
diff --git a/util/cairo-sphinx/sphinx.c b/util/cairo-sphinx/sphinx.c
index 067f816..40d6776 100644
--- a/util/cairo-sphinx/sphinx.c
+++ b/util/cairo-sphinx/sphinx.c
@@ -23,6 +23,10 @@
#include <glib.h> /* for checksumming */
+#ifndef CAIRO_HAS_REAL_PTHREAD
+# error "cairo-sphinx needs real pthreads"
+#endif
+
#define DATA_SIZE (256 << 20)
#define SHM_PATH_XXX "/shmem-cairo-sphinx"
diff --git a/util/cairo-trace/Makefile.am b/util/cairo-trace/Makefile.am
index a792cc6..3278abe 100644
--- a/util/cairo-trace/Makefile.am
+++ b/util/cairo-trace/Makefile.am
@@ -10,10 +10,10 @@ AM_CPPFLAGS = -I$(top_srcdir)/src \
libcairo_trace_la_SOURCES = trace.c
libcairo_trace_la_CPPFLAGS = -DCAIRO_TRACE_OUTDIR="\"$(cairooutdir)\"" \
$(AM_CPPFLAGS)
-libcairo_trace_la_CFLAGS = $(CAIRO_CFLAGS)
+libcairo_trace_la_CFLAGS = $(CAIRO_CFLAGS) $(real_pthread_CFLAGS)
libcairo_trace_la_LDFLAGS = -no-undefined
-libcairo_trace_la_LIBADD = -lz $(PTHREAD_LIBS)
+libcairo_trace_la_LIBADD = $(real_pthread_LIBS) -lz
if CAIRO_HAS_DL
libcairo_trace_la_LIBADD += -ldl
endif
commit 47c35e5e86a3c99fc39afe2e13a7c92d5247ee1e
Author: M Joonas Pihlaja <jpihlaja at cc.helsinki.fi>
Date: Sun Jun 27 01:14:03 2010 +0300
build: Purge CAIRO_CC_TRY_LINK_FLAG.
Use CAIRO_CC_TRY_FLAG instead in the one place where we used
CAIRO_CC_TRY_LINK_FLAG and make the build system one macro
smaller.
diff --git a/build/aclocal.cairo.m4 b/build/aclocal.cairo.m4
index 0b68677..592e168 100644
--- a/build/aclocal.cairo.m4
+++ b/build/aclocal.cairo.m4
@@ -153,27 +153,6 @@ AC_DEFUN([CAIRO_CC_TRY_FLAG],
AC_MSG_RESULT([$cairo_cc_flag])
])
-dnl check compiler/ld flags
-AC_DEFUN([CAIRO_CC_TRY_LINK_FLAG],
-[dnl
- CAIRO_CC_CHECK_WERROR
- AC_MSG_CHECKING([whether $CC supports $1])
-
- _save_cflags="$CFLAGS"
- CFLAGS="$CFLAGS $WERROR $1"
- AC_LINK_IFELSE([int main(void){ return 0;} ],
- [cairo_cc_flag=yes],
- [cairo_cc_flag=no])
- CFLAGS="$_save_cflags"
-
- if test "x$cairo_cc_flag" = "xyes"; then
- ifelse([$2], , :, [$2])
- else
- ifelse([$3], , :, [$3])
- fi
- AC_MSG_RESULT([$cairo_cc_flag])
-])
-
dnl Usage:
dnl CAIRO_CHECK_NATIVE_ATOMIC_PRIMITIVES
AC_DEFUN([CAIRO_CHECK_NATIVE_ATOMIC_PRIMITIVES],
diff --git a/build/configure.ac.warnings b/build/configure.ac.warnings
index 2f5745f..b225ac8 100644
--- a/build/configure.ac.warnings
+++ b/build/configure.ac.warnings
@@ -81,7 +81,7 @@ AC_DEFINE_UNQUOTED([WARN_UNUSED_RESULT], [$cairo_cv_warn_unused_result],
dnl check linker flags
AC_CACHE_CHECK([how to allow undefined symbols in shared libraries used by test suite], cairo_cv_test_undefined_ldflags,
- [CAIRO_CC_TRY_LINK_FLAG([-Wl,--allow-shlib-undefined],
+ [CAIRO_CC_TRY_FLAG([-Wl,--allow-shlib-undefined], [],
[cairo_cv_test_undefined_ldflags="-Wl,--allow-shlib-undefined]")])
CAIRO_TEST_UNDEFINED_LDFLAGS="$cairo_cv_test_undefined_ldflags"
AC_SUBST(CAIRO_TEST_UNDEFINED_LDFLAGS)
commit d2f5592e0e0d316cfc40ec676ee6e7f4e2a699fb
Author: M Joonas Pihlaja <jpihlaja at cc.helsinki.fi>
Date: Sun Jun 27 01:11:13 2010 +0300
build: Factor out a more pliable CAIRO_CC_TRY_LINK_WITH_ENV_SILENT.
Introduce a new CAIRO_CC_TRY_LINK_WITH_ENV_SILENT macro for running
generic link tests with arbitrary CFLAGS/LIBS/LDFLAGS and no muttering
of autoconf messages. Rewrite the previous CAIRO_CC_TRY_FLAG in terms
of it.
diff --git a/build/aclocal.cairo.m4 b/build/aclocal.cairo.m4
index f271ccf..0b68677 100644
--- a/build/aclocal.cairo.m4
+++ b/build/aclocal.cairo.m4
@@ -75,10 +75,18 @@ AC_DEFUN([CAIRO_CONFIG_COMMANDS],
], $3)
])
-dnl check compiler flags with a program and no muttering.
-AC_DEFUN([CAIRO_CC_TRY_FLAG_SILENT],
-[dnl (flags..., optional program, true-action, false-action)
-
+dnl CAIRO_CC_TRY_LINK_WITH_ENV_SILENT(env-setup, program,
+dnl true-action, false-action)
+dnl
+dnl Compile and link the program with the given environment setup.
+dnl The global cairo_cc_flag is set to "yes" or "no" according as
+dnl the link succeeded or not. The link step must complete without
+dnl warnings or errors to stderr.
+dnl
+dnl Perform true-action on success and false-action on failure.
+dnl The values of CFLAGS, LIBS, LDFLAGS are saved before env-setup
+dnl is executed and restored right before the end of the macro.
+AC_DEFUN([CAIRO_CC_TRY_LINK_WITH_ENV_SILENT],[dnl
# AC_LANG_PROGRAM() produces a main() w/o args,
# but -Wold-style-definition doesn't like that.
# We need _some_ program so that we don't get
@@ -88,14 +96,15 @@ AC_DEFUN([CAIRO_CC_TRY_FLAG_SILENT],
int main(int c, char **v) { (void)c; (void)v; return 0; }'
_save_cflags="$CFLAGS"
- CFLAGS="$CFLAGS $1"
+ _save_ldflags="$LDFLAGS"
+ _save_libs="$LIBS"
+ $1
AC_LINK_IFELSE(
[$_compile_program],
[cairo_cc_stderr=`test -f conftest.err && cat conftest.err`
cairo_cc_flag=yes],
[cairo_cc_stderr=`test -f conftest.err && cat conftest.err`
cairo_cc_flag=no])
- CFLAGS="$_save_cflags"
if test "x$cairo_cc_stderr" != "x"; then
cairo_cc_flag=no
@@ -106,6 +115,16 @@ AC_DEFUN([CAIRO_CC_TRY_FLAG_SILENT],
else
ifelse([$4], , :, [$4])
fi
+ CFLAGS="$_save_cflags"
+ LDFLAGS="$_save_ldflags"
+ LIBS="$_save_libs"
+])
+
+dnl check compiler flags with a program and no muttering.
+AC_DEFUN([CAIRO_CC_TRY_FLAG_SILENT],
+[dnl (flags..., optional program, true-action, false-action)
+ CAIRO_CC_TRY_LINK_WITH_ENV_SILENT([CFLAGS="$CFLAGS $1"],
+ [$2], [$3], [$4])
])
dnl find a -Werror equivalent
More information about the cairo-commit
mailing list