r10071: Configure checks for IRIX build environment. Test whether we can
[Samba.git] / source / build / m4 / check_cc.m4
blobab934f328beec76b01378a0ae62dc69021c8dce4
1 dnl SMB Build Environment CC Checks
2 dnl -------------------------------------------------------
3 dnl  Copyright (C) Stefan (metze) Metzmacher 2004
4 dnl  Released under the GNU GPL
5 dnl -------------------------------------------------------
6 dnl
8 AC_PROG_CC
9 if test x"$CC" = x""; then
10         AC_MSG_WARN([No c compiler was not found!])
11         AC_MSG_ERROR([Please Install gcc from http://gcc.gnu.org/])
14 AC_C_INLINE
16 dnl needed before AC_TRY_COMPILE
17 AC_ISC_POSIX
19 dnl Check if C compiler understands -c and -o at the same time
20 AC_PROG_CC_C_O
21 if eval "test \"`echo '$ac_cv_prog_cc_'${ac_cc}_c_o`\" = no"; then
22         BROKEN_CC=
23 else
24         BROKEN_CC=#
26 AC_SUBST(BROKEN_CC)
28 AC_CACHE_CHECK([that the C compiler can precompile header files],samba_cv_precompiled_headers, [
29         dnl Check whether the compiler can generate precompiled headers
30         touch conftest.h
31         if ${CC-cc} conftest.h 2> /dev/null && test -f conftest.h.gch; then
32                 samba_cv_precompiled_headers=yes
33         else
34                 samba_cv_precompiled_headers=no
35         fi])
36 PCH_AVAILABLE="#"
37 if test x"$samba_cv_precompiled_headers" = x"yes"; then
38         PCH_AVAILABLE=""
40 AC_SUBST(PCH_AVAILABLE)
43 dnl Check if the C compiler understands volatile (it should, being ANSI).
44 AC_CACHE_CHECK([that the C compiler understands volatile],samba_cv_volatile, [
45         AC_TRY_COMPILE([#include <sys/types.h>],[volatile int i = 0],
46                 samba_cv_volatile=yes,samba_cv_volatile=no)])
47 if test x"$samba_cv_volatile" = x"yes"; then
48         AC_DEFINE(HAVE_VOLATILE, 1, [Whether the C compiler understands volatile])
51 ############################################
52 # check if the compiler can do immediate structures
53 AC_CACHE_CHECK([for immediate structures],samba_cv_immediate_structures, [
54     AC_TRY_COMPILE([
55 #include <stdio.h>],
57    typedef struct {unsigned x;} FOOBAR;
58    #define X_FOOBAR(x) ((FOOBAR) { x })
59    #define FOO_ONE X_FOOBAR(1)
60    FOOBAR f = FOO_ONE;   
61    static struct {
62         FOOBAR y; 
63         } f2[] = {
64                 {FOO_ONE}
65         };   
67         samba_cv_immediate_structures=yes,samba_cv_immediate_structures=no)])
68 if test x"$samba_cv_immediate_structures" = x"yes"; then
69    AC_DEFINE(HAVE_IMMEDIATE_STRUCTURES,1,[Whether the compiler supports immediate structures])
72 ############################################
73 # check if the compiler handles c99 struct initialization
74 AC_DEFUN([SMB_CC_SUPPORTS_C99_STRUCT_INIT],
76 AC_MSG_CHECKING(for c99 struct initialization)
77 AC_TRY_COMPILE([
78     #include <stdio.h>],
79     [
80        struct foo {
81            int x;
82            char y;
83        } ;
84        struct foo bar = {
85             .y = 'X',
86             .x = 1
87        };        
88     ],
89 [AC_MSG_RESULT(yes); $1],[AC_MSG_RESULT(no); $2])
92 SMB_CC_SUPPORTS_C99_STRUCT_INIT(samba_cv_c99_struct_initialization=yes,
93                     samba_cv_c99_struct_initialization=no)
95 if test x"$samba_cv_c99_struct_initialization" != x"yes"; then
96         # We might need to add some flags to CC to get c99 behaviour.
97         AX_CFLAGS_IRIX_OPTION(-c99, CFLAGS)
98         SMB_CC_SUPPORTS_C99_STRUCT_INIT(samba_cv_c99_struct_initialization=yes,
99                             samba_cv_c99_struct_initialization=no)
102 if test x"$samba_cv_c99_struct_initialization" != x"yes"; then
103         AC_MSG_WARN([C compiler does not support c99 struct initialization!])
104         AC_MSG_ERROR([Please Install gcc from http://gcc.gnu.org/])
107 ############################################
108 # check if the compiler can handle negative enum values
109 AC_CACHE_CHECK([that the C compiler understands negative enum values],SMB_BUILD_CC_NEGATIVE_ENUM_VALUES, [
110     AC_TRY_COMPILE([
111 #include <stdio.h>],
113         enum negative_values { NEGATIVE_VALUE = 0xFFFFFFFF };
115         SMB_BUILD_CC_NEGATIVE_ENUM_VALUES=yes,SMB_BUILD_CC_NEGATIVE_ENUM_VALUES=no)])
116 if test x"$SMB_BUILD_CC_NEGATIVE_ENUM_VALUES" != x"yes"; then
117         AC_MSG_WARN([using --unit-enums for pidl])
118         PIDL_ARGS="$PIDL_ARGS --uint-enums"
121 AC_MSG_CHECKING([for test routines])
122 AC_TRY_RUN([#include "${srcdir-.}/build/tests/trivial.c"],
123             AC_MSG_RESULT(yes),
124             AC_MSG_ERROR([cant find test code. Aborting config]),
125             AC_MSG_WARN([cannot run when cross-compiling]))
128 # Check if the compiler can handle the options we selected by
129 # --enable-*developer
131 if test -n "$DEVELOPER_CFLAGS"; then
132         OLD_CFLAGS="${CFLAGS}"
133         CFLAGS="${CFLAGS} ${DEVELOPER_CFLAGS}"
134         AC_MSG_CHECKING([that the C compiler can use the DEVELOPER_CFLAGS])
135         AC_TRY_RUN([#include "${srcdir-.}/build/tests/trivial.c"],
136                 AC_MSG_RESULT(yes),
137                 DEVELOPER_CFLAGS=""; AC_MSG_RESULT(no))
138         CFLAGS="${OLD_CFLAGS}"
141 # allow for --with-hostcc=gcc
142 AC_ARG_WITH(hostcc,[  --with-hostcc=compiler    choose host compiler],[HOSTCC=$withval],[HOSTCC=$CC])
143 AC_SUBST(HOSTCC)
145 AC_PATH_PROG(GCOV,gcov)