1706f2543Smrg# ===========================================================================
2706f2543Smrg#             http://www.nongnu.org/autoconf-archive/ax_tls.html
3706f2543Smrg# ===========================================================================
4706f2543Smrg#
5706f2543Smrg# SYNOPSIS
6706f2543Smrg#
7706f2543Smrg#   AX_TLS
8706f2543Smrg#
9706f2543Smrg# DESCRIPTION
10706f2543Smrg#
11706f2543Smrg#   Provides a test for the compiler support of thread local storage (TLS)
12706f2543Smrg#   extensions. Defines TLS if it is found. Currently only knows about GCC
13706f2543Smrg#   and MSVC. I think SunPro uses the same as GCC, and Borland apparently
14706f2543Smrg#   supports either.
15706f2543Smrg#
16706f2543Smrg# LICENSE
17706f2543Smrg#
18706f2543Smrg#   Copyright (c) 2008 Alan Woodland <ajw05@aber.ac.uk>
19706f2543Smrg#
20706f2543Smrg#   This program is free software: you can redistribute it and/or modify it
21706f2543Smrg#   under the terms of the GNU General Public License as published by the
22706f2543Smrg#   Free Software Foundation, either version 3 of the License, or (at your
23706f2543Smrg#   option) any later version.
24706f2543Smrg#
25706f2543Smrg#   This program is distributed in the hope that it will be useful, but
26706f2543Smrg#   WITHOUT ANY WARRANTY; without even the implied warranty of
27706f2543Smrg#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
28706f2543Smrg#   Public License for more details.
29706f2543Smrg#
30706f2543Smrg#   You should have received a copy of the GNU General Public License along
31706f2543Smrg#   with this program. If not, see <http://www.gnu.org/licenses/>.
32706f2543Smrg#
33706f2543Smrg#   As a special exception, the respective Autoconf Macro's copyright owner
34706f2543Smrg#   gives unlimited permission to copy, distribute and modify the configure
35706f2543Smrg#   scripts that are the output of Autoconf when processing the Macro. You
36706f2543Smrg#   need not follow the terms of the GNU General Public License when using
37706f2543Smrg#   or distributing such scripts, even though portions of the text of the
38706f2543Smrg#   Macro appear in them. The GNU General Public License (GPL) does govern
39706f2543Smrg#   all other use of the material that constitutes the Autoconf Macro.
40706f2543Smrg#
41706f2543Smrg#   This special exception to the GPL applies to versions of the Autoconf
42706f2543Smrg#   Macro released by the Autoconf Archive. When you make and distribute a
43706f2543Smrg#   modified version of the Autoconf Macro, you may extend this special
44706f2543Smrg#   exception to the GPL to apply to your modified version as well.
45706f2543Smrg
46706f2543SmrgAC_DEFUN([AX_TLS], [
47706f2543Smrg  AC_MSG_CHECKING(for thread local storage (TLS) class)
48706f2543Smrg  AC_CACHE_VAL(ac_cv_tls, [
49706f2543Smrg    ax_tls_keywords="__thread __declspec(thread) none"
50706f2543Smrg    for ax_tls_keyword in $ax_tls_keywords; do
51706f2543Smrg       case $ax_tls_keyword in
52706f2543Smrg          none) ac_cv_tls=none ; break ;;
53706f2543Smrg          *)
54706f2543Smrg             AC_TRY_COMPILE(
55706f2543Smrg                [#include <stdlib.h>
56706f2543Smrg                 static void
57706f2543Smrg                 foo(void) {
58706f2543Smrg                 static ] $ax_tls_keyword [ int bar;
59706f2543Smrg                 exit(1);
60706f2543Smrg                 }],
61706f2543Smrg                 [],
62706f2543Smrg                 [ac_cv_tls=$ax_tls_keyword ; break],
63706f2543Smrg                 ac_cv_tls=none
64706f2543Smrg             )
65706f2543Smrg       esac
66706f2543Smrg    done
67706f2543Smrg])
68706f2543Smrg
69706f2543Smrg  if test "$ac_cv_tls" != "none"; then
70706f2543Smrg    dnl AC_DEFINE([TLS], [], [If the compiler supports a TLS storage class define it to that here])
71706f2543Smrg    AC_DEFINE_UNQUOTED([TLS], $ac_cv_tls, [If the compiler supports a TLS storage class define it to that here])
72706f2543Smrg  fi
73706f2543Smrg  AC_MSG_RESULT($ac_cv_tls)
74706f2543Smrg])
75