summaryrefslogtreecommitdiff
path: root/build
diff options
context:
space:
mode:
Diffstat (limited to 'build')
-rw-r--r--build/ax-pthread.m4283
-rw-r--r--build/configure.ac.pthread251
2 files changed, 251 insertions, 283 deletions
diff --git a/build/ax-pthread.m4 b/build/ax-pthread.m4
deleted file mode 100644
index bdae4771..00000000
--- 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@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 00000000..93c967a7
--- /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=""
+])