r9494: Add ac-archive macro for checking GCC options. Use this to add to
[ira/wip.git] / source4 / build / m4 / check_cc.m4
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
7
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/])
12 fi
13
14 AC_C_INLINE
15
16 dnl needed before AC_TRY_COMPILE
17 AC_ISC_POSIX
18
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=#
25 fi
26 AC_SUBST(BROKEN_CC)
27
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=""
39 fi
40 AC_SUBST(PCH_AVAILABLE)
41
42
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])
49 fi
50
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>],
56 [
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         };   
66 ],
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])
70 fi
71
72 ############################################
73 # check if the compiler handles c99 struct initialization
74 AC_CACHE_CHECK([for c99 struct initialization],samba_cv_c99_struct_initialization, [
75     AC_TRY_COMPILE([
76 #include <stdio.h>],
77 [
78    struct foo {
79        int x;
80        char y;
81    } ;
82    struct foo bar = {
83         .y = 'X',
84         .x = 1
85    };    
86 ],
87         samba_cv_c99_struct_initialization=yes,samba_cv_c99_struct_initialization=no)])
88 if test x"$samba_cv_c99_struct_initialization" != x"yes"; then
89         AC_MSG_WARN([C compiler does not support c99 struct initialization!])
90         AC_MSG_ERROR([Please Install gcc from http://gcc.gnu.org/])
91 fi
92
93 ############################################
94 # check if the compiler can handle negative enum values
95 AC_CACHE_CHECK([that the C compiler understands negative enum values],SMB_BUILD_CC_NEGATIVE_ENUM_VALUES, [
96     AC_TRY_COMPILE([
97 #include <stdio.h>],
98 [
99         enum negative_values { NEGATIVE_VALUE = 0xFFFFFFFF };
100 ],
101         SMB_BUILD_CC_NEGATIVE_ENUM_VALUES=yes,SMB_BUILD_CC_NEGATIVE_ENUM_VALUES=no)])
102 if test x"$SMB_BUILD_CC_NEGATIVE_ENUM_VALUES" != x"yes"; then
103         AC_MSG_WARN([using --unit-enums for pidl])
104         PIDL_ARGS="$PIDL_ARGS --uint-enums"
105 fi
106
107 AC_MSG_CHECKING([for test routines])
108 AC_TRY_RUN([#include "${srcdir-.}/build/tests/trivial.c"],
109             AC_MSG_RESULT(yes),
110             AC_MSG_ERROR([cant find test code. Aborting config]),
111             AC_MSG_WARN([cannot run when cross-compiling]))
112
113 #
114 # Check if the compiler can handle the options we selected by
115 # --enable-*developer
116 #
117 if test -n "$DEVELOPER_CFLAGS"; then
118         OLD_CFLAGS="${CFLAGS}"
119         CFLAGS="${CFLAGS} ${DEVELOPER_CFLAGS}"
120         AC_MSG_CHECKING([that the C compiler can use the DEVELOPER_CFLAGS])
121         AC_TRY_RUN([#include "${srcdir-.}/build/tests/trivial.c"],
122                 AC_MSG_RESULT(yes),
123                 DEVELOPER_CFLAGS=""; AC_MSG_RESULT(no))
124         CFLAGS="${OLD_CFLAGS}"
125 fi
126
127 # allow for --with-hostcc=gcc
128 AC_ARG_WITH(hostcc,[  --with-hostcc=compiler    choose host compiler],[HOSTCC=$withval],[HOSTCC=$CC])
129 AC_SUBST(HOSTCC)