* configure.ac: New switch for disabling -O2 (--disable-optimizations).
[cacao.git] / m4 / threads.m4
1 dnl m4/threads.m4
2 dnl
3 dnl Copyright (C) 2007 R. Grafl, A. Krall, C. Kruegel,
4 dnl C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 dnl E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 dnl J. Wenninger, Institut f. Computersprachen - TU Wien
7 dnl 
8 dnl This file is part of CACAO.
9 dnl 
10 dnl This program is free software; you can redistribute it and/or
11 dnl modify it under the terms of the GNU General Public License as
12 dnl published by the Free Software Foundation; either version 2, or (at
13 dnl your option) any later version.
14 dnl 
15 dnl This program is distributed in the hope that it will be useful, but
16 dnl WITHOUT ANY WARRANTY; without even the implied warranty of
17 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 dnl General Public License for more details.
19 dnl 
20 dnl You should have received a copy of the GNU General Public License
21 dnl along with this program; if not, write to the Free Software
22 dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 dnl 02110-1301, USA.
24
25
26 dnl check which thread implementation should be used
27
28 AC_DEFUN([AC_CHECK_ENABLE_THREADS],[
29 AC_MSG_CHECKING(whether to include threads support)
30 AC_ARG_ENABLE([threads],
31               [AS_HELP_STRING(--enable-threads,enable threads support (none,native) [[default=native]])],
32               [case "${enableval}" in
33                    no | none | single )
34                        ENABLE_THREADS=no
35                        ;;
36
37                    posix | pthreads )
38                        ENABLE_THREADS=posix
39                        ;;
40
41                    *)
42                        AC_MSG_ERROR($enableval is an unknown thread package)
43                        ;;
44                esac],
45                [ENABLE_THREADS=posix])
46
47 AC_MSG_RESULT(${ENABLE_THREADS})
48 AM_CONDITIONAL([ENABLE_THREADS], test x"${ENABLE_THREADS}" != "xno")
49
50 case "${ENABLE_THREADS}" in
51     no )
52         dnl no threads for boehm
53         ac_configure_args="$ac_configure_args --disable-boehm-threads"
54         ;;
55
56     posix )
57         AC_DEFINE([ENABLE_THREADS], 1, [enable threads])
58         AC_CHECK_LIB(pthread, main)
59
60         OS_FLAGS="$OS_FLAGS -D_REENTRANT"
61
62         dnl We changed OS_FLAGS, set CFLAGS again.
63         CFLAGS="$OPT_CFLAGS $ARCH_FLAGS $OS_FLAGS $CC_FLAGS"
64         CXXFLAGS="$OPT_CXXFLAGS $ARCH_FLAGS $OS_FLAGS $CXX_FLAGS"
65
66         dnl tell boehm to support threads as well
67         ac_configure_args="$ac_configure_args --enable-boehm-threads=posix"
68         ;;
69 esac
70 ])
71
72
73 AC_DEFUN([AC_CHECK_USE___THREAD],[
74 AC_ARG_ENABLE([__thread], [AS_HELP_STRING(--enable-__thread,use TLS features [[default=yes]])], [use__thread=$enableval], [use__thread=yes])
75
76 dnl Check whether the compiler supports the __thread keyword.
77 if test "x$use__thread" != xno; then
78   AC_CACHE_CHECK([for __thread], ac_cv_gcc___thread,
79   [cat > conftest.c <<\EOF
80 __thread int a = 42;
81 EOF
82   if AC_TRY_COMMAND([${CC-cc} $ARCH_CFLAGS $OPT_CFLAGS -c conftest.c >&AS_MESSAGE_LOG_FD]); then
83     ac_cv_gcc___thread=yes 
84   else
85     ac_cv_gcc___thread=no
86   fi
87   rm -f conftest*])
88   if test "$ac_cv_gcc___thread" = yes; then
89     AC_DEFINE([HAVE___THREAD], 1, [have __thread])
90   fi
91 else
92   ac_cv_gcc___thread=no
93 fi
94 ])