Skip to content

Commit d44e040

Browse files
Merge pull request #4822 from ggouaillardet/topic/opal_setup_cc
configury: define C11 macros once
2 parents f301cab + c9d3c81 commit d44e040

File tree

1 file changed

+46
-31
lines changed

1 file changed

+46
-31
lines changed

config/opal_setup_cc.m4

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ dnl Copyright (c) 2007-2009 Sun Microsystems, Inc. All rights reserved.
1414
dnl Copyright (c) 2008-2015 Cisco Systems, Inc. All rights reserved.
1515
dnl Copyright (c) 2012-2017 Los Alamos National Security, LLC. All rights
1616
dnl reserved.
17-
dnl Copyright (c) 2015 Research Organization for Information Science
18-
dnl and Technology (RIST). All rights reserved.
17+
dnl Copyright (c) 2015-2018 Research Organization for Information Science
18+
dnl and Technology (RIST). All rights reserved.
1919
dnl $COPYRIGHT$
2020
dnl
2121
dnl Additional copyrights may follow
@@ -24,52 +24,44 @@ dnl $HEADER$
2424
dnl
2525

2626
AC_DEFUN([OPAL_CC_HELPER],[
27-
OPAL_VAR_SCOPE_PUSH([opal_prog_cc_c11_helper_tmp])
27+
OPAL_VAR_SCOPE_PUSH([opal_cc_helper_result])
2828
AC_MSG_CHECKING([$1])
2929

30-
opal_prog_cc_c11_helper_tmp=0
30+
AC_LINK_IFELSE([AC_LANG_PROGRAM([$3],[$4])],
31+
[$2=1
32+
opal_cc_helper_result=yes],
33+
[$2=0
34+
opal_cc_helper_result=no])
3135

32-
AC_LINK_IFELSE([AC_LANG_PROGRAM([$3],[$4])],[
33-
$2=yes
34-
opal_prog_cc_c11_helper_tmp=1], [$2=no])
35-
36-
AC_DEFINE_UNQUOTED([$5], [$opal_prog_cc_c11_helper_tmp], [$6])
37-
38-
AC_MSG_RESULT([$$2])
36+
AC_MSG_RESULT([$opal_cc_helper_result])
3937
OPAL_VAR_SCOPE_POP
4038
])
4139

4240

4341
AC_DEFUN([OPAL_PROG_CC_C11_HELPER],[
44-
OPAL_VAR_SCOPE_PUSH([opal_prog_cc_c11_helper_CFLAGS_save opal_prog_cc_c11_helper__Thread_local_available opal_prog_cc_c11_helper_atomic_var_available opal_prog_cc_c11_helper__Atomic_available opal_prog_cc_c11_helper__static_assert_available opal_prog_cc_c11_helper__Generic_available])
42+
OPAL_VAR_SCOPE_PUSH([opal_prog_cc_c11_helper_CFLAGS_save])
4543

4644
opal_prog_cc_c11_helper_CFLAGS_save=$CFLAGS
4745
CFLAGS="$CFLAGS $1"
4846

4947
OPAL_CC_HELPER([if $CC $1 supports C11 _Thread_local], [opal_prog_cc_c11_helper__Thread_local_available],
50-
[],[[static _Thread_local int foo = 1;++foo;]], [OPAL_C_HAVE__THREAD_LOCAL],
51-
[Whether C compiler supports __Thread_local])
48+
[],[[static _Thread_local int foo = 1;++foo;]])
5249

5350
OPAL_CC_HELPER([if $CC $1 supports C11 atomic variables], [opal_prog_cc_c11_helper_atomic_var_available],
54-
[[#include <stdatomic.h>]], [[static atomic_long foo = 1;++foo;]], [OPAL_C_HAVE_ATOMIC_CONV_VAR],
55-
[Whether C compiler support atomic convenience variables in stdatomic.h])
51+
[[#include <stdatomic.h>]], [[static atomic_long foo = 1;++foo;]])
5652

5753
OPAL_CC_HELPER([if $CC $1 supports C11 _Atomic keyword], [opal_prog_cc_c11_helper__Atomic_available],
58-
[[#include <stdatomic.h>]],[[static _Atomic long foo = 1;++foo;]], [OPAL_C_HAVE__ATOMIC],
59-
[Whether C compiler supports __Atomic keyword])
54+
[[#include <stdatomic.h>]],[[static _Atomic long foo = 1;++foo;]])
6055

6156
OPAL_CC_HELPER([if $CC $1 supports C11 _Generic keyword], [opal_prog_cc_c11_helper__Generic_available],
62-
[[#define FOO(x) (_Generic (x, int: 1))]], [[static int x, y; y = FOO(x);]], [OPAL_C_HAVE__GENERIC],
63-
[Whether C compiler supports __Generic keyword])
57+
[[#define FOO(x) (_Generic (x, int: 1))]], [[static int x, y; y = FOO(x);]])
6458

6559
OPAL_CC_HELPER([if $CC $1 supports C11 _Static_assert], [opal_prog_cc_c11_helper__static_assert_available],
66-
[[#include <stdint.h>]],[[_Static_assert(sizeof(int64_t) == 8, "WTH");]], [OPAL_C_HAVE__STATIC_ASSERT],
67-
[Whether C compiler support _Static_assert keyword])
60+
[[#include <stdint.h>]],[[_Static_assert(sizeof(int64_t) == 8, "WTH");]])
6861

69-
dnl At this time Open MPI only needs thread local and the atomic convenience types for C11 support. These
70-
dnl will likely be required in the future.
71-
AS_IF([test "x$opal_prog_cc_c11_helper__Thread_local_available" = "xyes" && test "x$opal_prog_cc_c11_helper_atomic_var_available" = "xyes"],
72-
[$2], [$3])
62+
AS_IF([test $opal_prog_cc_c11_helper__Thread_local_available -eq 1 && test $opal_prog_cc_c11_helper_atomic_var_available -eq 1],
63+
[$2],
64+
[$3])
7365

7466
CFLAGS=$opal_prog_cc_c11_helper_CFLAGS_save
7567

@@ -135,6 +127,8 @@ AC_DEFUN([OPAL_SETUP_CC],[
135127
AC_REQUIRE([_OPAL_PROG_CC])
136128
AC_REQUIRE([AM_PROG_CC_C_O])
137129

130+
OPAL_VAR_SCOPE_PUSH([opal_prog_cc_c11_helper__Thread_local_available opal_prog_cc_c11_helper_atomic_var_available opal_prog_cc_c11_helper__Atomic_available opal_prog_cc_c11_helper__static_assert_available opal_prog_cc_c11_helper__Generic_available opal_prog_cc__thread_available])
131+
138132
# AC_PROG_CC_C99 changes CC (instead of CFLAGS) so save CC (without c99
139133
# flags) for use in our wrappers.
140134
WRAPPER_CC="$CC"
@@ -157,15 +151,35 @@ AC_DEFUN([OPAL_SETUP_CC],[
157151

158152
# Get the correct result for C11 support flags now that the compiler flags have
159153
# changed
160-
OPAL_PROG_CC_C11_HELPER([],[],[])
154+
OPAL_PROG_CC_C11_HELPER([], [], [])
161155
fi
162156

163157
# Check if compiler support __thread
164-
OPAL_VAR_SCOPE_PUSH([opal_prog_cc__thread_available])
165158
OPAL_CC_HELPER([if $CC $1 supports __thread], [opal_prog_cc__thread_available],
166-
[],[[static __thread int foo = 1;++foo;]], [OPAL_C_HAVE___THREAD],
167-
[Whether C compiler supports __thread])
168-
OPAL_VAR_SCOPE_POP
159+
[],[[static __thread int foo = 1;++foo;]])
160+
161+
OPAL_CC_HELPER([if $CC $1 supports C11 _Thread_local], [opal_prog_cc_c11_helper__Thread_local_available],
162+
[],[[static _Thread_local int foo = 1;++foo;]])
163+
164+
dnl At this time Open MPI only needs thread local and the atomic convenience types for C11 support. These
165+
dnl will likely be required in the future.
166+
AC_DEFINE_UNQUOTED([OPAL_C_HAVE__THREAD_LOCAL], [$opal_prog_cc_c11_helper__Thread_local_available],
167+
[Whether C compiler supports __Thread_local])
168+
169+
AC_DEFINE_UNQUOTED([OPAL_C_HAVE_ATOMIC_CONV_VAR], [$opal_prog_cc_c11_helper_atomic_var_available],
170+
[Whether C compiler support atomic convenience variables in stdatomic.h])
171+
172+
AC_DEFINE_UNQUOTED([OPAL_C_HAVE__ATOMIC], [$opal_prog_cc_c11_helper__Atomic_available],
173+
[Whether C compiler supports __Atomic keyword])
174+
175+
AC_DEFINE_UNQUOTED([OPAL_C_HAVE__GENERIC], [$opal_prog_cc_c11_helper__Generic_available],
176+
[Whether C compiler supports __Generic keyword])
177+
178+
AC_DEFINE_UNQUOTED([OPAL_C_HAVE__STATIC_ASSERT], [$opal_prog_cc_c11_helper__static_assert_available],
179+
[Whether C compiler support _Static_assert keyword])
180+
181+
AC_DEFINE_UNQUOTED([OPAL_C_HAVE___THREAD], [$opal_prog_cc__thread_available],
182+
[Whether C compiler supports __thread])
169183

170184
OPAL_C_COMPILER_VENDOR([opal_c_vendor])
171185

@@ -462,6 +476,7 @@ AC_DEFUN([OPAL_SETUP_CC],[
462476
OPAL_ENSURE_CONTAINS_OPTFLAGS(["$CFLAGS"])
463477
AC_MSG_RESULT([$co_result])
464478
CFLAGS="$co_result"
479+
OPAL_VAR_SCOPE_POP
465480
])
466481

467482

0 commit comments

Comments
 (0)