@@ -16,27 +16,153 @@ dnl Copyright (c) 2012-2017 Los Alamos National Security, LLC. All rights
1616dnl reserved.
1717dnl Copyright (c) 2015 Research Organization for Information Science
1818dnl and Technology (RIST). All rights reserved.
19- dnl Copyright (c) 2015-2017 Intel, Inc. All rights reserved.
19+ dnl Copyright (c) 2018 Intel, Inc. All rights reserved.
2020dnl $COPYRIGHT $
2121dnl
2222dnl Additional copyrights may follow
2323dnl
2424dnl $HEADER $
2525dnl
2626
27+ AC_DEFUN([PMIX_CC_HELPER],[
28+ PMIX_VAR_SCOPE_PUSH([pmix_prog_cc_c11_helper_tmp])
29+ AC_MSG_CHECKING([$1 ])
30+
31+ pmix_prog_cc_c11_helper_tmp= 0
32+
33+ AC_LINK_IFELSE([AC_LANG_PROGRAM([$3 ],[$4 ])],[
34+ $2 = yes
35+ pmix_prog_cc_c11_helper_tmp= 1], [$2 = no])
36+
37+ AC_DEFINE_UNQUOTED([$5 ], [$pmix_prog_cc_c11_helper_tmp ], [$6 ])
38+
39+ AC_MSG_RESULT([$$ 2])
40+ PMIX_VAR_SCOPE_POP
41+ ])
42+
43+
44+ AC_DEFUN([PMIX_PROG_CC_C11_HELPER],[
45+ PMIX_VAR_SCOPE_PUSH([pmix_prog_cc_c11_helper_CFLAGS_save pmix_prog_cc_c11_helper__Thread_local_available pmix_prog_cc_c11_helper_atomic_var_available pmix_prog_cc_c11_helper__Atomic_available pmix_prog_cc_c11_helper__static_assert_available pmix_prog_cc_c11_helper__Generic_available])
46+
47+ pmix_prog_cc_c11_helper_CFLAGS_save= $CFLAGS
48+ CFLAGS= " $CFLAGS $1 "
49+
50+ PMIX_CC_HELPER([if $CC $1 supports C11 _Thread_local], [pmix_prog_cc_c11_helper__Thread_local_available],
51+ [],[[static _Thread_local int foo = 1; ++foo; ]], [PMIX_C_HAVE__THREAD_LOCAL],
52+ [Whether C compiler supports __Thread_local])
53+
54+ PMIX_CC_HELPER([if $CC $1 supports C11 atomic variables], [pmix_prog_cc_c11_helper_atomic_var_available],
55+ [[# include <stdatomic.h>]], [[static atomic_long foo = 1;++foo;]], [PMIX_C_HAVE_ATOMIC_CONV_VAR],
56+ [Whether C compiler support atomic convenience variables in stdatomic.h])
57+
58+ PMIX_CC_HELPER([if $CC $1 supports C11 _Atomic keyword], [pmix_prog_cc_c11_helper__Atomic_available],
59+ [[# include <stdatomic.h>]],[[static _Atomic long foo = 1;++foo;]], [PMIX_C_HAVE__ATOMIC],
60+ [Whether C compiler supports __Atomic keyword])
61+
62+ PMIX_CC_HELPER([if $CC $1 supports C11 _Generic keyword], [pmix_prog_cc_c11_helper__Generic_available],
63+ [[# define FOO(x) (_Generic (x, int: 1))]], [[static int x, y; y = FOO(x);]], [PMIX_C_HAVE__GENERIC],
64+ [Whether C compiler supports __Generic keyword])
65+
66+ PMIX_CC_HELPER([if $CC $1 supports C11 _Static_assert], [pmix_prog_cc_c11_helper__static_assert_available],
67+ [[# include <stdint.h>]],[[_Static_assert(sizeof(int64_t) == 8, "WTH");]], [PMIX_C_HAVE__STATIC_ASSERT],
68+ [Whether C compiler support _Static_assert keyword])
69+
70+ dnl At this time Open MPI only needs thread local and the atomic convenience types for C11 support. These
71+ dnl will likely be required in the future.
72+ AS_IF([test " x$pmix_prog_cc_c11_helper__Thread_local_available " = " xyes" && test " x$pmix_prog_cc_c11_helper_atomic_var_available " = " xyes" ],
73+ [$2 ], [$3 ])
74+
75+ CFLAGS= $pmix_prog_cc_c11_helper_CFLAGS_save
76+
77+ PMIX_VAR_SCOPE_POP
78+ ])
79+
80+ AC_DEFUN([PMIX_PROG_CC_C11],[
81+ PMIX_VAR_SCOPE_PUSH([pmix_prog_cc_c11_flags])
82+ if test -z " $pmix_cv_c11_supported " ; then
83+ pmix_cv_c11_supported=no
84+ pmix_cv_c11_flag_required=yes
85+
86+ AC_MSG_CHECKING([if $CC requires a flag for C11])
87+
88+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
89+ # if __STDC_VERSION__ < 201112L
90+ # error "Without any CLI flags, this compiler does not support C11"
91+ # endif
92+ ]],[])],
93+ [pmix_cv_c11_flag_required= no])
94+
95+ AC_MSG_RESULT([$pmix_cv_c11_flag_required ])
96+
97+ if test " x$pmix_cv_c11_flag_required " = " xno" ; then
98+ AC_MSG_NOTICE([verifying $CC supports C11 without a flag])
99+ PMIX_PROG_CC_C11_HELPER([], [], [pmix_cv_c11_flag_required= yes])
100+ fi
101+
102+ if test " x$pmix_cv_c11_flag_required " = " xyes" ; then
103+ pmix_prog_cc_c11_flags=" -std=gnu11 -std=c11 -c11"
104+
105+ AC_MSG_NOTICE([checking if $CC supports C11 with a flag])
106+ pmix_cv_c11_flag=
107+ for flag in $( echo $pmix_prog_cc_c11_flags | tr ' ' ' \n' ) ; do
108+ PMIX_PROG_CC_C11_HELPER([$flag ],[pmix_cv_c11_flag= $flag ],[])
109+ if test " x$pmix_cv_c11_flag " ! = " x" ; then
110+ CFLAGS=" $CFLAGS $pmix_cv_c11_flag "
111+ AC_MSG_NOTICE([using $flag to enable C11 support])
112+ pmix_cv_c11_supported=yes
113+ break
114+ fi
115+ done
116+ else
117+ AC_MSG_NOTICE([no flag required for C11 support])
118+ pmix_cv_c11_supported=yes
119+ fi
120+ fi
121+
122+ PMIX_VAR_SCOPE_POP
123+ ])
124+
125+
27126# PMIX_SETUP_CC()
28127# ---------------
29128# Do everything required to setup the C compiler. Safe to AC_REQUIRE
30129# this macro.
31130AC_DEFUN([PMIX_SETUP_CC],[
131+ # AM_PROG_CC_C_O AC_REQUIREs AC_PROG_CC, so we have to be a little
132+ # careful about ordering here, and AC_REQUIRE these things so that
133+ # they get stamped out in the right order.
134+
135+ AC_REQUIRE([_PMIX_START_SETUP_CC])
136+ AC_REQUIRE([_PMIX_PROG_CC])
137+ AC_REQUIRE([AM_PROG_CC_C_O])
138+
139+ PMIX_PROG_CC_C11
140+
141+ if test $pmix_cv_c11_supported = no ; then
142+ # It is not currently an error if C11 support is not available. Uncomment the
143+ # following lines and update the warning when we require a C11 compiler.
144+ # AC_MSG_WARNING([Open MPI requires a C11 (or newer) compiler])
145+ # AC_MSG_ERROR([Aborting.])
146+ # From Open MPI 1.7 on we require a C99 compiant compiler
147+ AC_PROG_CC_C99
148+ # The result of AC_PROG_CC_C99 is stored in ac_cv_prog_cc_c99
149+ if test " x$ac_cv_prog_cc_c99 " = xno ; then
150+ AC_MSG_WARN([Open MPI requires a C99 (or newer) compiler. C11 is recommended.])
151+ AC_MSG_ERROR([Aborting.])
152+ fi
32153
33- # We require a C99 compliant compiler
34- # The result of AC_PROG_CC_C99 is stored in ac_cv_prog_cc_c99
35- if test " x$ac_cv_prog_cc_c99 " = xno ; then
36- AC_MSG_WARN([PMIx requires a C99 compiler])
37- AC_MSG_ERROR([Aborting.])
154+ # Get the correct result for C11 support flags now that the compiler flags have
155+ # changed
156+ PMIX_PROG_CC_C11_HELPER([],[],[])
38157 fi
39158
159+ # Check if compiler support __thread
160+ PMIX_VAR_SCOPE_PUSH([pmix_prog_cc__thread_available])
161+ PMIX_CC_HELPER([if $CC $1 supports __thread], [pmix_prog_cc__thread_available],
162+ [],[[static __thread int foo = 1; ++foo; ]], [PMIX_C_HAVE___THREAD],
163+ [Whether C compiler supports __thread])
164+ PMIX_VAR_SCOPE_POP
165+
40166 PMIX_C_COMPILER_VENDOR([pmix_c_vendor])
41167
42168 # Check for standard headers, needed here because needed before
@@ -59,6 +185,48 @@ AC_DEFUN([PMIX_SETUP_CC],[
59185# endif])
60186 AC_DEFINE([_GNU_SOURCE])])
61187
188+ # Do we want code coverage
189+ if test " $WANT_COVERAGE " = " 1" ; then
190+ if test " $pmix_c_vendor " = " gnu" ; then
191+ # For compilers > gcc-4.x, use --coverage for
192+ # compiling and linking to circumvent trouble with
193+ # libgcov.
194+ CFLAGS_orig=" $CFLAGS "
195+ LDFLAGS_orig=" $LDFLAGS "
196+
197+ CFLAGS=" $CFLAGS_orig --coverage"
198+ LDFLAGS=" $LDFLAGS_orig --coverage"
199+ PMIX_COVERAGE_FLAGS=
200+
201+ AC_CACHE_CHECK([if $CC supports --coverage],
202+ [pmix_cv_cc_coverage],
203+ [AC_TRY_COMPILE([], [],
204+ [pmix_cv_cc_coverage= " yes" ],
205+ [pmix_cv_cc_coverage= " no" ])])
206+
207+ if test " $pmix_cv_cc_coverage " = " yes" ; then
208+ PMIX_COVERAGE_FLAGS=" --coverage"
209+ CLEANFILES=" *.gcno ${CLEANFILES} "
210+ CONFIG_CLEAN_FILES=" *.gcda *.gcov ${CONFIG_CLEAN_FILES} "
211+ else
212+ PMIX_COVERAGE_FLAGS=" -ftest-coverage -fprofile-arcs"
213+ CLEANFILES=" *.bb *.bbg ${CLEANFILES} "
214+ CONFIG_CLEAN_FILES=" *.da *.*.gcov ${CONFIG_CLEAN_FILES} "
215+ fi
216+ CFLAGS=" $CFLAGS_orig $PMIX_COVERAGE_FLAGS "
217+ LDFLAGS=" $LDFLAGS_orig $PMIX_COVERAGE_FLAGS "
218+
219+ PMIX_FLAGS_UNIQ(CFLAGS)
220+ PMIX_FLAGS_UNIQ(LDFLAGS)
221+ AC_MSG_WARN([$PMIX_COVERAGE_FLAGS has been added to CFLAGS (--enable-coverage)])
222+
223+ WANT_DEBUG=1
224+ else
225+ AC_MSG_WARN([Code coverage functionality is currently available only with GCC])
226+ AC_MSG_ERROR([Configure: Cannot continue])
227+ fi
228+ fi
229+
62230 # Do we want debugging?
63231 if test " $WANT_DEBUG " = " 1" && test " $enable_debug_symbols " ! = " no" ; then
64232 CFLAGS=" $CFLAGS -g"
@@ -288,21 +456,13 @@ AC_DEFUN([PMIX_SETUP_CC],[
288456 PMIX_ENSURE_CONTAINS_OPTFLAGS([" $CFLAGS " ])
289457 AC_MSG_RESULT([$co_result ])
290458 CFLAGS=" $co_result "
291-
292- # #################################
293- # C compiler characteristics
294- # #################################
295- # Does the compiler support "ident"-like constructs?
296- PMIX_CHECK_IDENT([CC], [CFLAGS], [c], [C])
297-
298459])
299460
300461
301462AC_DEFUN([_PMIX_START_SETUP_CC],[
302463 pmix_show_subtitle " C compiler and preprocessor"
303464
304- AC_REQUIRE([AC_PROG_CC])
305- # $%@#!@#% AIX!! This has to be called before anything invokes the C
465+ # $%@#!@#% AIX!! This has to be called before anything invokes the C
306466 # compiler.
307467 dnl AC_AIX
308468])
@@ -314,10 +474,10 @@ AC_DEFUN([_PMIX_PROG_CC],[
314474 #
315475 PMIX_VAR_SCOPE_PUSH([pmix_cflags_save dummy pmix_cc_arvgv0])
316476 pmix_cflags_save= " $CFLAGS "
317- AC_PROG_CC_C99
477+ AC_PROG_CC
318478 BASECC= " ` basename $CC ` "
319479 CFLAGS= " $pmix_cflags_save "
320- AC_DEFINE_UNQUOTED(PMIX_CC, " $CC " , [PMIx underlying C compiler])
480+ AC_DEFINE_UNQUOTED(PMIX_CC, " $CC " , [OMPI underlying C compiler])
321481 set dummy $CC
322482 pmix_cc_argv0= [$]2
323483 PMIX_WHICH([$pmix_cc_argv0 ], [PMIX_CC_ABSOLUTE])
0 commit comments