r8533: improve --help output
[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 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 can handle negative enum values
74 AC_CACHE_CHECK([that the C compiler understands negative enum values],SMB_BUILD_CC_NEGATIVE_ENUM_VALUES, [
75     AC_TRY_COMPILE([
76 #include <stdio.h>],
77 [
78         enum negative_values { NEGATIVE_VALUE = 0xFFFFFFFF };
79 ],
80         SMB_BUILD_CC_NEGATIVE_ENUM_VALUES=yes,SMB_BUILD_CC_NEGATIVE_ENUM_VALUES=no)])
81 if test x"$SMB_BUILD_CC_NEGATIVE_ENUM_VALUES" != x"yes"; then
82         AC_MSG_WARN([using --unit-enums for pidl])
83         PIDL_ARGS="$PIDL_ARGS --uint-enums"
84 fi
85
86 AC_MSG_CHECKING([for test routines])
87 AC_TRY_RUN([#include "${srcdir-.}/build/tests/trivial.c"],
88             AC_MSG_RESULT(yes),
89             AC_MSG_ERROR([cant find test code. Aborting config]),
90             AC_MSG_WARN([cannot run when cross-compiling]))
91
92 #
93 # Check if the compiler can handle the options we selected by
94 # --enable-*developer
95 #
96 if test -n "$DEVELOPER_CFLAGS"; then
97         OLD_CFLAGS="${CFLAGS}"
98         CFLAGS="${CFLAGS} ${DEVELOPER_CFLAGS}"
99         AC_MSG_CHECKING([that the C compiler can use the DEVELOPER_CFLAGS])
100         AC_TRY_RUN([#include "${srcdir-.}/build/tests/trivial.c"],
101                 AC_MSG_RESULT(yes),
102                 DEVELOPER_CFLAGS=""; AC_MSG_RESULT(no),
103                 AC_MSG_WARN([cannot run when cross-compiling]))
104         CFLAGS="${OLD_CFLAGS}"
105 fi
106
107 # allow for --with-hostcc=gcc
108 AC_ARG_WITH(hostcc,[  --with-hostcc=compiler    choose host compiler],[HOSTCC=$withval],[HOSTCC=$CC])
109 AC_SUBST(HOSTCC)