there was an #include directive missing
[openmpi-llc.git] / config / ompi_setup_cc.m4
blob5c84ae8748f59cc5d580f4c55ece09af12c9f9db
1 dnl -*- shell-script -*-
2 dnl
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
8 dnl                         reserved.
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.
13 dnl $COPYRIGHT$
14 dnl 
15 dnl Additional copyrights may follow
16 dnl 
17 dnl $HEADER$
18 dnl
20 # OMPI_SETUP_CC()
21 # ---------------
22 # Do everything required to setup the C compiler.  Safe to AC_REQUIRE
23 # this macro.
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.
39     #
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.  */
46 #ifndef _GNU_SOURCE
47 # undef _GNU_SOURCE
48 #endif])
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)])
56             WANT_DEBUG=1
57             CFLAGS="-ftest-coverage -fprofile-arcs ${CFLAGS}"
58             WRAPPER_EXTRA_CFLAGS="-ftest-coverage -fprofile-arcs ${WRAPPER_EXTRA_CFLAGS}"
59         else
60             AC_MSG_WARN([Code coverage functionality is currently available only with GCC])
61             AC_MSG_ERROR([Configure: Cannot continue])
62        fi
63     fi
65     # Do we want debugging?
66     if test "$WANT_DEBUG" = "1"; then
67         if test "$ompi_c_vendor" = "gnu"; then
68             CFLAGS="$CFLAGS -g3"
69         else
70             CFLAGS="$CFLAGS -g"
71         fi
73         OMPI_UNIQ(CFLAGS)
74         AC_MSG_WARN([-g has been added to CFLAGS (--enable-debug)])
75     fi
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...
86         CFLAGS_orig="$CFLAGS"
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"])])
94         CFLAGS="$CFLAGS_orig"
95         if test "$ompi_cv_cc_wno_long_double" = "yes" ; then
96             add="$add -Wno-long-double"
97         fi
99         add="$add -Werror-implicit-function-declaration "
101         CFLAGS="$CFLAGS $add"
102         OMPI_UNIQ(CFLAGS)
103         AC_MSG_WARN([$add has been added to CFLAGS (--enable-picky)])
104         unset add
105     fi
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"
113         add=
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"
121         fi
122         CFLAGS="$CFLAGS_orig$add"
124         CFLAGS="$CFLAGS_orig -fno-strict-aliasing"
125         add=
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"
133         fi
134         CFLAGS="$CFLAGS_orig$add"
136         OMPI_UNIQ(CFLAGS)
137         AC_MSG_WARN([$add has been added to CFLAGS])
138         unset add
139     fi
141     # Try to enable restrict keyword
142     RESTRICT_CFLAGS=
143     case "$ompi_c_vendor" in
144         intel)
145             RESTRICT_CFLAGS="-restrict"
146         ;;
147         sgi)
148             RESTRICT_CFLAGS="-LANG:restrict=ON"
149         ;;
150     esac
151     if test ! -z "$RESTRICT_CFLAGS" ; then
152         CFLAGS_orig="$CFLAGS"
153         CFLAGS="$CFLAGS_orig $RESTRICT_CFLAGS"
154         add=
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"
162         fi
164         CFLAGS="${CFLAGS_orig}${add}"
165         OMPI_UNIQ([CFLAGS])
166         if test "$add" != "" ; then
167             AC_MSG_WARN([$add has been added to CFLAGS])
168         fi
169         unset add
170     fi
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.
178     #
179     # Note: gcc-impersonating compilers accept -O3
180     if test "$GCC" = yes; then
181         OPTFLAGS="-O3"
182     else
183         OPTFLAGS="-O"
184     fi
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])
192     CFLAGS="$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
200     # compiler.
201     dnl AC_AIX
205 AC_DEFUN([_OMPI_PROG_CC],[
206     #
207     # Check for the compiler
208     #
209     ompi_cflags_save="$CFLAGS"
210     AC_PROG_CC
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)