Turn on super pedantic warnings in CLANG
[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 dnl #
73 dnl # Determine the number of system cores we have
74 dnl #
75 AC_DEFUN([AX_SYSTEM_CORES],[
76   AC_CACHE_CHECK([number of system cores], [ax_cv_system_cores],
77     [
78       AC_LANG_PUSH(C)
79       AC_TRY_RUN(
80         [
81           #include <stdio.h>
82           #include <stdint.h>
83           #ifdef _WIN32
84           #  include <windows.h>
85           #elif MACOS
86           #  include <sys/param.h>
87           #  include <sys/sysctl.h>
88           #else
89           #  include <unistd.h>
90           #endif
91
92           int main (int argc, char *argv[])
93           {
94             uint32_t count;
95
96             #ifdef WIN32
97             SYSTEM_INFO sysinfo;
98             GetSystemInfo(&sysinfo);
99
100             count = sysinfo.dwNumberOfProcessors;
101
102             #elif MACOS
103             int nm[2];
104             size_t len = 4;
105
106             nm[0] = CTL_HW;
107             nm[1] = HW_AVAILCPU;
108             sysctl(nm, 2, &count, &len, NULL, 0);
109
110             if(count < 1) {
111               nm[1] = HW_NCPU;
112               sysctl(nm, 2, &count, &len, NULL, 0);
113               if(count < 1) {
114                 count = 1;
115               }
116             }
117
118             #else
119             count = sysconf(_SC_NPROCESSORS_ONLN);
120             #endif
121
122             return count;
123           }
124         ],
125         [ax_cv_system_cores=$?],
126         [ax_cv_system_cores=$?],
127         [ax_cv_system_cores=]
128     )
129     AC_LANG_POP
130   ])
131 ])
132