Skip to content

Commit afee2b7

Browse files
committed
Add _OPAL_CHECK_SPECIFIC_*FLAGS to check compiler flags.
Instead of assuming some flags are only available with the 'gnu' compiler, add a check to add them as available. Do the same for CFLAGS and CXX flags. Signed-off-by: Austen Lauria <[email protected]>
1 parent 68bf9cc commit afee2b7

File tree

4 files changed

+177
-257
lines changed

4 files changed

+177
-257
lines changed

config/opal_check_cflags.m4

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
dnl -*- shell-script -*-
2+
dnl
3+
dnl Copyright (c) 2021 IBM Corporation. All rights reserved.
4+
dnl
5+
dnl $COPYRIGHT$
6+
dnl
7+
dnl Additional copyrights may follow
8+
dnl
9+
dnl $HEADER$
10+
dnl
11+
12+
AC_DEFUN([_OPAL_CFLAGS_FAIL_SEARCH],[
13+
AC_REQUIRE([AC_PROG_GREP])
14+
if test -s conftest.err ; then
15+
$GREP -iq $1 conftest.err
16+
if test "$?" = "0" ; then
17+
opal_cv_cc_[$2]=0
18+
fi
19+
fi
20+
])
21+
22+
AC_DEFUN([_OPAL_CHECK_SPECIFIC_CFLAGS], [
23+
AC_MSG_CHECKING(if $CC supports ([$1]))
24+
CFLAGS_orig=$CFLAGS
25+
CFLAGS="$CFLAGS $1"
26+
AC_CACHE_VAL(opal_cv_cc_[$2], [
27+
AC_TRY_COMPILE([], [$3],
28+
[
29+
opal_cv_cc_[$2]=1
30+
_OPAL_CFLAGS_FAIL_SEARCH("ignored\|not recognized\|not supported\|not compatible\|unrecognized\|unknown", [$2])
31+
],
32+
opal_cv_cc_[$2]=1
33+
_OPAL_CFLAGS_FAIL_SEARCH("ignored\|not recognized\|not supported\|not compatible\|unrecognized\|unknown\|error", [$2])
34+
)])
35+
if test "$opal_cv_cc_[$2]" = "0" ; then
36+
CFLAGS="$CFLAGS_orig"
37+
AC_MSG_RESULT([no])
38+
else
39+
AC_MSG_RESULT([yes])
40+
fi
41+
])
42+
43+
AC_DEFUN([_OPAL_CXXFLAGS_FAIL_SEARCH],[
44+
AC_REQUIRE([AC_PROG_GREP])
45+
if test -s conftest.err ; then
46+
$GREP -iq $1 conftest.err
47+
if test "$?" = "0" ; then
48+
opal_cv_cxx_[$2]=0
49+
fi
50+
fi
51+
])
52+
53+
AC_DEFUN([_OPAL_CHECK_SPECIFIC_CXXFLAGS], [
54+
AC_MSG_CHECKING(if $CXX supports ([$1]))
55+
CXXFLAGS_orig=$CXXFLAGS
56+
CXXFLAGS="$CXXFLAGS $1"
57+
AC_CACHE_VAL(opal_cv_cxx_[$2], [
58+
AC_TRY_COMPILE([], [$3],
59+
[
60+
opal_cv_cxx_[$2]=1
61+
_OPAL_CXXFLAGS_FAIL_SEARCH("ignored\|not recognized\|not supported\|not compatible\|unrecognized\|unknown", [$2])
62+
],
63+
opal_cv_cxx_[$2]=1
64+
_OPAL_CXXFLAGS_FAIL_SEARCH("ignored\|not recognized\|not supported\|not compatible\|unrecognized\|unknown\|error", [$2])
65+
)])
66+
if test "$opal_cv_cxx_[$2]" = "0" ; then
67+
CXXFLAGS="$CXXFLAGS_orig"
68+
AC_MSG_RESULT([no])
69+
else
70+
AC_MSG_RESULT([yes])
71+
fi
72+
])

config/opal_config_asm.m4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ dnl Copyright (c) 2017 Amazon.com, Inc. or its affiliates. All Rights
1919
dnl reserved.
2020
dnl Copyright (c) 2020 Google, LLC. All rights reserved.
2121
dnl Copyright (c) 2020 Intel, Inc. All rights reserved.
22+
dnl Copyright (c) 2021 IBM Corporation. All rights reserved.
2223
dnl $COPYRIGHT$
2324
dnl
2425
dnl Additional copyrights may follow
@@ -1086,6 +1087,7 @@ dnl
10861087
dnl #################################################################
10871088
AC_DEFUN([OPAL_CONFIG_ASM],[
10881089
AC_REQUIRE([OPAL_SETUP_CC])
1090+
AC_REQUIRE([OPAL_SETUP_CXX])
10891091
AC_REQUIRE([AM_PROG_AS])
10901092
10911093
AC_ARG_ENABLE([c11-atomics],[AC_HELP_STRING([--enable-c11-atomics],

config/opal_setup_cc.m4

Lines changed: 52 additions & 170 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ AC_DEFUN([OPAL_SETUP_CC],[
161161

162162
OPAL_CHECK_CC_IQUOTE
163163

164+
OPAL_C_COMPILER_VENDOR([opal_c_vendor])
165+
164166
if test $opal_cv_c11_supported = no ; then
165167
# It is not currently an error if C11 support is not available. Uncomment the
166168
# following lines and update the warning when we require a C11 compiler.
@@ -206,7 +208,6 @@ AC_DEFUN([OPAL_SETUP_CC],[
206208
AC_DEFINE_UNQUOTED([OPAL_C_HAVE___THREAD], [$opal_prog_cc__thread_available],
207209
[Whether C compiler supports __thread])
208210

209-
OPAL_C_COMPILER_VENDOR([opal_c_vendor])
210211

211212
# Check for standard headers, needed here because needed before
212213
# the types checks.
@@ -244,47 +245,34 @@ AC_DEFUN([OPAL_SETUP_CC],[
244245

245246
# Do we want code coverage
246247
if test "$WANT_COVERAGE" = "1"; then
247-
if test "$opal_c_vendor" = "gnu" ; then
248-
# For compilers > gcc-4.x, use --coverage for
249-
# compiling and linking to circumvent trouble with
250-
# libgcov.
251-
CFLAGS_orig="$CFLAGS"
252-
LDFLAGS_orig="$LDFLAGS"
253-
254-
CFLAGS="$CFLAGS_orig --coverage"
255-
LDFLAGS="$LDFLAGS_orig --coverage"
256-
OPAL_COVERAGE_FLAGS=
257-
258-
AC_CACHE_CHECK([if $CC supports --coverage],
259-
[opal_cv_cc_coverage],
260-
[AC_TRY_COMPILE([], [],
261-
[opal_cv_cc_coverage="yes"],
262-
[opal_cv_cc_coverage="no"])])
263-
264-
if test "$opal_cv_cc_coverage" = "yes" ; then
265-
OPAL_COVERAGE_FLAGS="--coverage"
266-
CLEANFILES="*.gcno ${CLEANFILES}"
267-
CONFIG_CLEAN_FILES="*.gcda *.gcov ${CONFIG_CLEAN_FILES}"
268-
else
269-
OPAL_COVERAGE_FLAGS="-ftest-coverage -fprofile-arcs"
270-
CLEANFILES="*.bb *.bbg ${CLEANFILES}"
271-
CONFIG_CLEAN_FILES="*.da *.*.gcov ${CONFIG_CLEAN_FILES}"
272-
fi
273-
CFLAGS="$CFLAGS_orig $OPAL_COVERAGE_FLAGS"
274-
LDFLAGS="$LDFLAGS_orig $OPAL_COVERAGE_FLAGS"
275-
OPAL_WRAPPER_FLAGS_ADD([CFLAGS], [$OPAL_COVERAGE_FLAGS])
276-
OPAL_WRAPPER_FLAGS_ADD([LDFLAGS], [$OPAL_COVERAGE_FLAGS])
277-
278-
OPAL_FLAGS_UNIQ(CFLAGS)
279-
OPAL_FLAGS_UNIQ(LDFLAGS)
248+
# For compilers > gcc-4.x, use --coverage for
249+
# compiling and linking to circumvent trouble with
250+
# libgcov.
251+
LDFLAGS_orig="$LDFLAGS"
252+
LDFLAGS="$LDFLAGS_orig --coverage"
253+
OPAL_COVERAGE_FLAGS=
254+
255+
_OPAL_CHECK_SPECIFIC_CFLAGS(--coverage, coverage)
256+
if test "$opal_cv_cc_coverage" = "1" ; then
257+
OPAL_COVERAGE_FLAGS="--coverage"
258+
CLEANFILES="*.gcno ${CLEANFILES}"
259+
CONFIG_CLEAN_FILES="*.gcda *.gcov ${CONFIG_CLEAN_FILES}"
280260
AC_MSG_WARN([$OPAL_COVERAGE_FLAGS has been added to CFLAGS (--enable-coverage)])
281-
282-
WANT_DEBUG=1
283261
else
284-
AC_MSG_WARN([Code coverage functionality is currently available only with GCC])
285-
AC_MSG_ERROR([Configure: Cannot continue])
286-
fi
287-
fi
262+
_OPAL_CHECK_SPECIFIC_CFLAGS(-ftest-coverage, ftest_coverage)
263+
_OPAL_CHECK_SPECIFIC_CFLAGS(-fprofile-arcs, fprofile_arcs)
264+
if test "$opal_cv_cc_ftest_coverage" = "0" || test "opal_cv_cc_fprofile_arcs" = "0" ; then
265+
AC_MSG_WARN([Code coverage functionality is not currently available with $CC])
266+
AC_MSG_ERROR([Configure: Cannot continue])
267+
fi
268+
CLEANFILES="*.bb *.bbg ${CLEANFILES}"
269+
OPAL_COVERAGE_FLAGS="-ftest-coverage -fprofile-arcs"
270+
fi
271+
OPAL_FLAGS_UNIQ(CFLAGS)
272+
OPAL_FLAGS_UNIQ(LDFLAGS)
273+
WANT_DEBUG=1
274+
fi
275+
288276

289277
# Do we want debugging?
290278
if test "$WANT_DEBUG" = "1" && test "$enable_debug_symbols" != "no" ; then
@@ -299,120 +287,29 @@ AC_DEFUN([OPAL_SETUP_CC],[
299287
OPAL_CFLAGS_BEFORE_PICKY="$CFLAGS"
300288

301289
if test $WANT_PICKY_COMPILER -eq 1; then
302-
CFLAGS_orig=$CFLAGS
303-
add=
304-
305-
# These flags are likely GCC-specific (or, more specifically,
306-
# we don't have general tests for each one, and we know they
307-
# work with all versions of GCC that we have used throughout
308-
# the years, so we'll keep them limited just to GCC).
309-
if test "$opal_c_vendor" = "gnu" ; then
310-
add="$add -Wall -Wundef -Wno-long-long -Wsign-compare"
311-
add="$add -Wmissing-prototypes -Wstrict-prototypes"
312-
add="$add -Wcomment -pedantic"
313-
fi
314-
315-
# see if -Wno-long-double works...
316-
# Starting with GCC-4.4, the compiler complains about not
317-
# knowing -Wno-long-double, only if -Wstrict-prototypes is set, too.
318-
#
319-
# Actually, this is not real fix, as GCC will pass on any -Wno- flag,
320-
# have fun with the warning: -Wno-britney
321-
CFLAGS="$CFLAGS_orig $add -Wno-long-double -Wstrict-prototypes"
322-
323-
AC_CACHE_CHECK([if $CC supports -Wno-long-double],
324-
[opal_cv_cc_wno_long_double],
325-
[AC_TRY_COMPILE([], [],
326-
[
327-
dnl So -Wno-long-double did not produce any errors...
328-
dnl We will try to extract a warning regarding
329-
dnl unrecognized or ignored options
330-
AC_TRY_COMPILE([], [long double test;],
331-
[
332-
opal_cv_cc_wno_long_double="yes"
333-
if test -s conftest.err ; then
334-
dnl Yes, it should be "ignor", in order to catch ignoring and ignore
335-
for i in unknown invalid ignor unrecognized 'not supported'; do
336-
$GREP -iq $i conftest.err
337-
if test "$?" = "0" ; then
338-
opal_cv_cc_wno_long_double="no"
339-
break;
340-
fi
341-
done
342-
fi
343-
],
344-
[opal_cv_cc_wno_long_double="no"])],
345-
[opal_cv_cc_wno_long_double="no"])
346-
])
347-
348-
if test "$opal_cv_cc_wno_long_double" = "yes" ; then
349-
add="$add -Wno-long-double"
350-
fi
351-
352-
# Per above, we know that this flag works with GCC / haven't
353-
# really tested it elsewhere.
354-
if test "$opal_c_vendor" = "gnu" ; then
355-
add="$add -Werror-implicit-function-declaration "
356-
fi
357-
358-
CFLAGS="$CFLAGS_orig $add"
359-
OPAL_FLAGS_UNIQ(CFLAGS)
360-
AC_MSG_WARN([$add has been added to CFLAGS (--enable-picky)])
361-
unset add
290+
_OPAL_CHECK_SPECIFIC_CFLAGS(-Wundef, Wundef)
291+
_OPAL_CHECK_SPECIFIC_CFLAGS(-Wno-long-long, Wno_long_long, int main() { long long x; })
292+
_OPAL_CHECK_SPECIFIC_CFLAGS(-Wsign-compare, Wsign_compare)
293+
_OPAL_CHECK_SPECIFIC_CFLAGS(-Wmissing-prototypes, Wmissing_prototypes)
294+
_OPAL_CHECK_SPECIFIC_CFLAGS(-Wstrict-prototypes, Wstrict_prototypes)
295+
_OPAL_CHECK_SPECIFIC_CFLAGS(-Wcomment, Wcomment)
296+
_OPAL_CHECK_SPECIFIC_CFLAGS(-Werror-implicit-function-declaration, Werror_implicit_function_declaration)
297+
_OPAL_CHECK_SPECIFIC_CFLAGS(-Wno-long-double, Wno_long_double, int main() { long double x; })
298+
_OPAL_CHECK_SPECIFIC_CFLAGS(-fno-strict-aliasing, fno_strict_aliasing, int main() { long double x; })
299+
_OPAL_CHECK_SPECIFIC_CFLAGS(-pedantic, pedantic)
300+
_OPAL_CHECK_SPECIFIC_CFLAGS(-Wall, Wall)
362301
fi
363302

364-
# See if this version of gcc allows -finline-functions and/or
365-
# -fno-strict-aliasing. Even check the gcc-impersonating compilers.
366-
if test "$GCC" = "yes"; then
367-
CFLAGS_orig="$CFLAGS"
368-
369-
# Note: Some versions of clang (at least >= 3.5 -- perhaps
370-
# older versions, too?) and xlc with -g (v16.1, perhaps older)
371-
# will *warn* about -finline-functions, but still allow it.
372-
# This is very annoying, so check for that warning, too.
373-
# The clang warning looks like this:
374-
# clang: warning: optimization flag '-finline-functions' is not supported
375-
# clang: warning: argument unused during compilation: '-finline-functions'
376-
# the xlc warning looks like this:
377-
# warning: "-qinline" is not compatible with "-g". "-qnoinline" is being set.
378-
CFLAGS="$CFLAGS_orig -finline-functions"
379-
add=
380-
AC_CACHE_CHECK([if $CC supports -finline-functions],
381-
[opal_cv_cc_finline_functions],
382-
[AC_TRY_COMPILE([], [],
383-
[opal_cv_cc_finline_functions="yes"
384-
if test -s conftest.err ; then
385-
for i in unused 'not supported\|not compatible' ; do
386-
if $GREP -iq "$i" conftest.err; then
387-
opal_cv_cc_finline_functions="no"
388-
break;
389-
fi
390-
done
391-
fi
392-
],
393-
[opal_cv_cc_finline_functions="no"])])
394-
if test "$opal_cv_cc_finline_functions" = "yes" ; then
395-
add=" -finline-functions"
396-
fi
397-
CFLAGS="$CFLAGS_orig$add"
398-
399-
CFLAGS_orig="$CFLAGS"
400-
CFLAGS="$CFLAGS_orig -fno-strict-aliasing"
401-
add=
402-
AC_CACHE_CHECK([if $CC supports -fno-strict-aliasing],
403-
[opal_cv_cc_fno_strict_aliasing],
404-
[AC_TRY_COMPILE([], [],
405-
[opal_cv_cc_fno_strict_aliasing="yes"],
406-
[opal_cv_cc_fno_strict_aliasing="no"])])
407-
if test "$opal_cv_cc_fno_strict_aliasing" = "yes" ; then
408-
add=" -fno-strict-aliasing"
409-
fi
410-
CFLAGS="$CFLAGS_orig$add"
411-
412-
OPAL_FLAGS_UNIQ(CFLAGS)
413-
AC_MSG_WARN([$add has been added to CFLAGS])
414-
unset add
415-
fi
303+
# Note: Some versions of clang (at least >= 3.5 -- perhaps
304+
# older versions, too?) and xlc with -g (v16.1, perhaps older)
305+
# will *warn* about -finline-functions, but still allow it.
306+
# This is very annoying, so check for that warning, too.
307+
# The clang warning looks like this:
308+
# clang: warning: optimization flag '-finline-functions' is not supported
309+
# clang: warning: argument unused during compilation: '-finline-functions'
310+
# the xlc warning looks like this:
311+
# warning: "-qinline" is not compatible with "-g". "-qnoinline" is being set.
312+
_OPAL_CHECK_SPECIFIC_CFLAGS(-finline-functions, finline_functions)
416313

417314
# Try to enable restrict keyword
418315
RESTRICT_CFLAGS=
@@ -425,24 +322,7 @@ AC_DEFUN([OPAL_SETUP_CC],[
425322
;;
426323
esac
427324
if test ! -z "$RESTRICT_CFLAGS" ; then
428-
CFLAGS_orig="$CFLAGS"
429-
CFLAGS="$CFLAGS_orig $RESTRICT_CFLAGS"
430-
add=
431-
AC_CACHE_CHECK([if $CC supports $RESTRICT_CFLAGS],
432-
[opal_cv_cc_restrict_cflags],
433-
[AC_TRY_COMPILE([], [],
434-
[opal_cv_cc_restrict_cflags="yes"],
435-
[opal_cv_cc_restrict_cflags="no"])])
436-
if test "$opal_cv_cc_restrict_cflags" = "yes" ; then
437-
add=" $RESTRICT_CFLAGS"
438-
fi
439-
440-
CFLAGS="${CFLAGS_orig}${add}"
441-
OPAL_FLAGS_UNIQ([CFLAGS])
442-
if test "$add" != "" ; then
443-
AC_MSG_WARN([$add has been added to CFLAGS])
444-
fi
445-
unset add
325+
_OPAL_CHECK_SPECIFIC_CFLAGS($RESTRICT_CFLAGS, restrict)
446326
fi
447327

448328
# see if the C compiler supports __builtin_expect
@@ -518,6 +398,8 @@ AC_DEFUN([OPAL_SETUP_CC],[
518398
OPAL_ENSURE_CONTAINS_OPTFLAGS(["$CFLAGS"])
519399
AC_MSG_RESULT([$co_result])
520400
CFLAGS="$co_result"
401+
OPAL_FLAGS_UNIQ([CFLAGS])
402+
AC_MSG_RESULT(CFLAGS result: $CFLAGS)
521403
OPAL_VAR_SCOPE_POP
522404
])
523405

0 commit comments

Comments
 (0)