1 dnl -*- shell-script -*-
3 dnl Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
4 dnl University Research and Technology
5 dnl Corporation. All rights reserved.
6 dnl Copyright (c) 2004-2006 The University of Tennessee and The University
7 dnl of Tennessee Research Foundation. All rights
9 dnl Copyright (c) 2004-2006 High Performance Computing Center Stuttgart,
10 dnl University of Stuttgart. All rights reserved.
11 dnl Copyright (c) 2004-2005 The Regents of the University of California.
12 dnl All rights reserved.
15 dnl Additional copyrights may follow
22 # Do everything required to setup the C compiler. Safe to AC_REQUIRE
24 AC_DEFUN([OMPI_SETUP_CC],[
25 # AM_PROG_CC_C_O AC_REQUIREs AC_PROG_CC, so we have to be a little
26 # careful about ordering here, and AC_REQUIRE these things so that
27 # they get stamped out in the right order.
29 AC_REQUIRE([_OMPI_START_SETUP_CC])
30 AC_REQUIRE([_OMPI_PROG_CC])
31 AC_REQUIRE([AM_PROG_CC_C_O])
33 OMPI_C_COMPILER_VENDOR([ompi_c_vendor])
35 # GNU C and autotools are inconsistent about whether this is
36 # defined so let's make it true everywhere for now... However, IBM
37 # XL compilers on PPC Linux behave really badly when compiled with
38 # _GNU_SOURCE defined, so don't define it in that situation.
40 # Don't use AC_GNU_SOURCE because it requires that no compiler
41 # tests are done before setting it, and we need to at least do
42 # enough tests to figure out if we're using XL or not.
43 AS_IF([test "$ompi_cv_c_compiler_vendor" != "ibm"],
44 [AH_VERBATIM([_GNU_SOURCE],
45 [/* Enable GNU extensions on systems that have them. */
49 AC_DEFINE([_GNU_SOURCE])])
51 # Do we want code coverage
52 if test "$WANT_COVERAGE" = "1"; then
53 if test "$ompi_c_vendor" = "gnu" ; then
54 CLEANFILES="*.bb *.bbg *.da *.*.gcov ${CLEANFILES}"
55 AC_MSG_WARN([-fprofile-arcs -ftest-coverage has been added to CFLAGS (--enable-coverage)])
57 CFLAGS="-ftest-coverage -fprofile-arcs ${CFLAGS}"
58 WRAPPER_EXTRA_CFLAGS="-ftest-coverage -fprofile-arcs ${WRAPPER_EXTRA_CFLAGS}"
60 AC_MSG_WARN([Code coverage functionality is currently available only with GCC])
61 AC_MSG_ERROR([Configure: Cannot continue])
65 # Do we want debugging?
66 if test "$WANT_DEBUG" = "1"; then
67 if test "$ompi_c_vendor" = "gnu"; then
74 AC_MSG_WARN([-g has been added to CFLAGS (--enable-debug)])
77 # These flags are generally gcc-specific; even the
78 # gcc-impersonating compilers won't accept them.
79 OMPI_CFLAGS_BEFORE_PICKY="$CFLAGS"
80 if test "$WANT_PICKY_COMPILER" = 1 -a "$ompi_c_vendor" = "gnu" ; then
81 add="-Wall -Wundef -Wno-long-long -Wsign-compare"
82 add="$add -Wmissing-prototypes -Wstrict-prototypes"
83 add="$add -Wcomment -pedantic"
85 # see if -Wno-long-double works...
87 CFLAGS="$CFLAGS -Wno-long-double"
88 AC_CACHE_CHECK([if $CC supports -Wno-long-double],
89 [ompi_cv_cc_wno_long_double],
90 [AC_TRY_COMPILE([], [],
91 [ompi_cv_cc_wno_long_double="yes"],
92 [ompi_cv_cc_wno_long_double="no"])])
95 if test "$ompi_cv_cc_wno_long_double" = "yes" ; then
96 add="$add -Wno-long-double"
99 add="$add -Werror-implicit-function-declaration "
101 CFLAGS="$CFLAGS $add"
103 AC_MSG_WARN([$add has been added to CFLAGS (--enable-picky)])
107 # See if this version of gcc allows -finline-functions and/or
108 # -fno-strict-aliasing. Even check the gcc-impersonating compilers.
109 if test "$GCC" = "yes"; then
110 CFLAGS_orig="$CFLAGS"
112 CFLAGS="$CFLAGS_orig -finline-functions"
114 AC_CACHE_CHECK([if $CC supports -finline-functions],
115 [ompi_cv_cc_finline_functions],
116 [AC_TRY_COMPILE([], [],
117 [ompi_cv_cc_finline_functions="yes"],
118 [ompi_cv_cc_finline_functions="no"])])
119 if test "$ompi_cv_cc_finline_functions" = "yes" ; then
120 add=" -finline-functions"
122 CFLAGS="$CFLAGS_orig$add"
124 CFLAGS="$CFLAGS_orig -fno-strict-aliasing"
126 AC_CACHE_CHECK([if $CC supports -fno-strict-aliasing],
127 [ompi_cv_cc_fno_strict_aliasing],
128 [AC_TRY_COMPILE([], [],
129 [ompi_cv_cc_fno_strict_aliasing="yes"],
130 [ompi_cv_cc_fno_strict_aliasing="no"])])
131 if test "$ompi_cv_cc_fno_strict_aliasing" = "yes" ; then
132 add=" -fno-strict-aliasing"
134 CFLAGS="$CFLAGS_orig$add"
137 AC_MSG_WARN([$add has been added to CFLAGS])
141 # Try to enable restrict keyword
143 case "$ompi_c_vendor" in
145 RESTRICT_CFLAGS="-restrict"
148 RESTRICT_CFLAGS="-LANG:restrict=ON"
151 if test ! -z "$RESTRICT_CFLAGS" ; then
152 CFLAGS_orig="$CFLAGS"
153 CFLAGS="$CFLAGS_orig $RESTRICT_CFLAGS"
155 AC_CACHE_CHECK([if $CC supports $RESTRICT_CFLAGS],
156 [ompi_cv_cc_restrict_cflags],
157 [AC_TRY_COMPILE([], [],
158 [ompi_cv_cc_restrict_cflags="yes"],
159 [ompi_cv_cc_restrict_cflags="no"])])
160 if test "ompi_cv_cc_restruct_cflags" = "yes" ; then
161 add="$RESTRUCT_CFLAGS"
164 CFLAGS="${CFLAGS_orig}${add}"
166 if test "$add" != "" ; then
167 AC_MSG_WARN([$add has been added to CFLAGS])
172 # Preload the optflags for the case where the user didn't specify
173 # any. If we're using GNU compilers, use -O3 (since it GNU
174 # doesn't require all compilation units to be compiled with the
175 # same level of optimization -- selecting a high level of
176 # optimization is not prohibitive). If we're using anything else,
177 # be conservative and just use -O.
179 # Note: gcc-impersonating compilers accept -O3
180 if test "$GCC" = yes; then
186 OMPI_CHECK_OPTFLAGS("$OMPI_CFLAGS_BEFORE_PICKY")
187 OMPI_CFLAGS_BEFORE_PICKY="$co_result"
189 AC_MSG_CHECKING([for C optimization flags])
190 OMPI_CHECK_OPTFLAGS(["$CFLAGS"])
191 AC_MSG_RESULT([$co_result])
196 AC_DEFUN([_OMPI_START_SETUP_CC],[
197 ompi_show_subtitle "C compiler and preprocessor"
199 # $%@#!@#% AIX!! This has to be called before anything invokes the C
205 AC_DEFUN([_OMPI_PROG_CC],[
207 # Check for the compiler
209 ompi_cflags_save="$CFLAGS"
211 BASECC="`basename $CC`"
212 CFLAGS="$ompi_cflags_save"
213 AC_DEFINE_UNQUOTED(OMPI_CC, "$CC", [OMPI underlying C compiler])
214 OMPI_CC_ABSOLUTE="`which $CC`"
215 AC_SUBST(OMPI_CC_ABSOLUTE)