r7425: configure check to see if a compiler can handle negative enum values
[samba.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 dnl needed before AC_TRY_COMPILE
15 AC_ISC_POSIX
16
17 dnl Check if C compiler understands -c and -o at the same time
18 AC_PROG_CC_C_O
19 if eval "test \"`echo '$ac_cv_prog_cc_'${ac_cc}_c_o`\" = no"; then
20         BROKEN_CC=
21 else
22         BROKEN_CC=#
23 fi
24 AC_SUBST(BROKEN_CC)
25
26 AC_CACHE_CHECK([that the C compiler can precompile header files],samba_cv_precompiled_headers, [
27         dnl Check whether the compiler can generate precompiled headers
28         touch conftest.h
29         if ${CC-cc} conftest.h 2> /dev/null && test -f conftest.h.gch; then
30                 samba_cv_precompiled_headers=yes
31         else
32                 samba_cv_precompiled_headers=no
33         fi])
34 PCH_AVAILABLE="#"
35 if test x"$samba_cv_precompiled_headers" = x"yes"; then
36         PCH_AVAILABLE=""
37 fi
38 AC_SUBST(PCH_AVAILABLE)
39
40
41 dnl Check if the C compiler understands volatile (it should, being ANSI).
42 AC_CACHE_CHECK([that the C compiler understands volatile],samba_cv_volatile, [
43         AC_TRY_COMPILE([#include <sys/types.h>],[volatile int i = 0],
44                 samba_cv_volatile=yes,samba_cv_volatile=no)])
45 if test x"$samba_cv_volatile" = x"yes"; then
46         AC_DEFINE(HAVE_VOLATILE, 1, [Whether the C compiler understands volatile])
47 fi
48
49 ############################################
50 # check if the compiler can do immediate structures
51 AC_CACHE_CHECK([for immediate structures],samba_cv_immediate_structures, [
52     AC_TRY_COMPILE([
53 #include <stdio.h>],
54 [
55    typedef struct {unsigned x;} FOOBAR;
56    #define X_FOOBAR(x) ((FOOBAR) { x })
57    #define FOO_ONE X_FOOBAR(1)
58    FOOBAR f = FOO_ONE;   
59    static struct {
60         FOOBAR y; 
61         } f2[] = {
62                 {FOO_ONE}
63         };   
64 ],
65         samba_cv_immediate_structures=yes,samba_cv_immediate_structures=no)])
66 if test x"$samba_cv_immediate_structures" = x"yes"; then
67    AC_DEFINE(HAVE_IMMEDIATE_STRUCTURES,1,[Whether the compiler supports immediate structures])
68 fi
69
70 ############################################
71 # check if the compiler can handle negative enum values
72 AC_CACHE_CHECK([that the C compiler understands negative enum values],SMB_BUILD_CC_NEGATIVE_ENUM_VALUES, [
73     AC_TRY_COMPILE([
74 #include <stdio.h>],
75 [
76         enum negative_values { NEGATIVE_VALUE = 0xFFFFFFFF };
77 ],
78         SMB_BUILD_CC_NEGATIVE_ENUM_VALUES=yes,SMB_BUILD_CC_NEGATIVE_ENUM_VALUES=no)])
79 if test x"$SMB_BUILD_CC_NEGATIVE_ENUM_VALUES" != x"yes"; then
80         AC_MSG_WARN([using --unit-enums for pidl])
81         PIDL_ARGS="$PIDL_ARGS --uint-enums"
82 fi
83
84 AC_MSG_CHECKING([for test routines])
85 AC_TRY_RUN([#include "${srcdir-.}/build/tests/trivial.c"],
86             AC_MSG_RESULT(yes),
87             AC_MSG_ERROR([cant find test code. Aborting config]),
88             AC_MSG_WARN([cannot run when cross-compiling]))
89
90 #
91 # Check if the compiler can handle the options we selected by
92 # --enable-*developer
93 #
94 if test -n "$DEVELOPER_CFLAGS"; then
95         OLD_CFLAGS="${CFLAGS}"
96         CFLAGS="${CFLAGS} ${DEVELOPER_CFLAGS}"
97         AC_MSG_CHECKING([that the C compiler can use the DEVELOPER_CFLAGS])
98         AC_TRY_RUN([#include "${srcdir-.}/build/tests/trivial.c"],
99                 AC_MSG_RESULT(yes),
100                 DEVELOPER_CFLAGS=""; AC_MSG_RESULT(no),
101                 AC_MSG_WARN([cannot run when cross-compiling]))
102         CFLAGS="${OLD_CFLAGS}"
103 fi