don't truncate at 1K
[freeradius.git] / m4 / ax_cc.m4
1 dnl #
2 dnl # check if were compiling with CLANG, autoconf GCC macro identifies CLANG as GCC
3 dnl #
4 AC_DEFUN([AX_CC_IS_CLANG],[
5   AC_CACHE_CHECK([if compiler is clang], [ax_cv_cc_clang],[
6
7   AC_COMPILE_IFELSE(
8     [AC_LANG_PROGRAM([], [[
9     #ifndef __clang__
10          not clang
11     #endif
12     ]])],
13     [ax_cv_cc_clang=yes],
14     [ax_cv_cc_clang=no])
15   ])
16 ])
17
18 AC_DEFUN([AX_CC_QUNUSED_ARGUMENTS_FLAG],[
19   AC_CACHE_CHECK([for the compiler flag "-Qunused-arguments"], [ax_cv_cc_qunused_arguments_flag],[
20
21     CFLAGS_SAVED=$CFLAGS
22     CFLAGS="$CFLAGS -Werror -Qunused-arguments -foobar"
23
24     AC_LANG_PUSH(C)
25     AC_TRY_COMPILE(
26       [],
27       [return 0;],
28       [ax_cv_cc_qunused_arguments_flag="yes"],
29       [ax_cv_cc_qunused_arguments_flag="no"])
30     AC_LANG_POP
31
32     CFLAGS="$CFLAGS_SAVED"
33   ])
34 ])
35
36 AC_DEFUN([AX_CC_WEVERYTHING_FLAG],[
37   AC_CACHE_CHECK([for the compiler flag "-Weverything"], [ax_cv_cc_weverything_flag],[
38
39     CFLAGS_SAVED=$CFLAGS
40     CFLAGS="$CFLAGS -Werror -Weverything -Wno-unused-macros -Wno-unreachable-code-return"
41
42     AC_LANG_PUSH(C)
43     AC_TRY_COMPILE(
44       [],
45       [return 0;],
46       [ax_cv_cc_weverything_flag="yes"],
47       [ax_cv_cc_weverything_flag="no"])
48     AC_LANG_POP
49
50     CFLAGS="$CFLAGS_SAVED"
51   ])
52 ])
53
54 AC_DEFUN([AX_CC_WDOCUMENTATION_FLAG],[
55   AC_CACHE_CHECK([for the compiler flag "-Wdocumentation"], [ax_cv_cc_wdocumentation_flag],[
56
57     CFLAGS_SAVED=$CFLAGS
58     CFLAGS="$CFLAGS -Werror -Wdocumentation"
59
60     AC_LANG_PUSH(C)
61     AC_TRY_COMPILE(
62       [],
63       [return 0;],
64       [ax_cv_cc_wdocumentation_flag="yes"],
65       [ax_cv_cc_wdocumentation_flag="no"])
66     AC_LANG_POP
67
68     CFLAGS="$CFLAGS_SAVED"
69   ])
70 ])
71
72 AC_DEFUN([AX_CC_PTHREAD_FLAG],[
73   AC_CACHE_CHECK([for the compiler flag "-pthread"], [ax_cv_cc_pthread_flag],[
74
75     CFLAGS_SAVED=$CFLAGS
76     CFLAGS="$CFLAGS -Werror -pthread"
77
78     AC_LANG_PUSH(C)
79     AC_TRY_COMPILE(
80       [],
81       [return 0;],
82       [ax_cv_cc_pthread_flag="yes"],
83       [ax_cv_cc_pthread_flag="no"])
84     AC_LANG_POP
85
86     CFLAGS="$CFLAGS_SAVED"
87   ])
88 ])
89
90 dnl #
91 dnl # Determine the number of system cores we have
92 dnl #
93 AC_DEFUN([AX_SYSTEM_CORES],[
94   AC_CACHE_CHECK([number of system cores], [ax_cv_system_cores],
95     [
96       AC_LANG_PUSH(C)
97       AC_TRY_RUN(
98         [
99           #include <stdio.h>
100           #include <stdint.h>
101           #ifdef _WIN32
102           #  include <windows.h>
103           #elif MACOS
104           #  include <sys/param.h>
105           #  include <sys/sysctl.h>
106           #else
107           #  include <unistd.h>
108           #endif
109
110           int main (int argc, char *argv[])
111           {
112             uint32_t count;
113
114             #ifdef WIN32
115             SYSTEM_INFO sysinfo;
116             GetSystemInfo(&sysinfo);
117
118             count = sysinfo.dwNumberOfProcessors;
119
120             #elif MACOS
121             int nm[2];
122             size_t len = 4;
123
124             nm[0] = CTL_HW;
125             nm[1] = HW_AVAILCPU;
126             sysctl(nm, 2, &count, &len, NULL, 0);
127
128             if(count < 1) {
129               nm[1] = HW_NCPU;
130               sysctl(nm, 2, &count, &len, NULL, 0);
131               if(count < 1) {
132                 count = 1;
133               }
134             }
135
136             #else
137             count = sysconf(_SC_NPROCESSORS_ONLN);
138             #endif
139
140             return count;
141           }
142         ],
143         [ax_cv_system_cores=$?],
144         [ax_cv_system_cores=$?],
145         [ax_cv_system_cores=]
146     )
147     AC_LANG_POP
148   ])
149 ])
150