Some shells don't support the '+=' concatenation operator.
[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_WDOCUMENTATION_FLAG],[
37   AC_CACHE_CHECK([for the compiler flag "-Wdocumentation"], [ax_cv_cc_wdocumentation_flag],[
38
39     CFLAGS_SAVED=$CFLAGS
40     CFLAGS="$CFLAGS -Werror -Wdocumentation"
41
42     AC_LANG_PUSH(C)
43     AC_TRY_COMPILE(
44       [],
45       [return 0;],
46       [ax_cv_cc_wdocumentation_flag="yes"],
47       [ax_cv_cc_wdocumentation_flag="no"])
48     AC_LANG_POP
49
50     CFLAGS="$CFLAGS_SAVED"
51   ])
52 ])
53
54 dnl #
55 dnl # Determine the number of system cores we have
56 dnl #
57 AC_DEFUN([AX_SYSTEM_CORES],[
58   AC_CACHE_CHECK([number of system cores], [ax_cv_system_cores],
59     [
60       AC_LANG_PUSH(C)
61       AC_TRY_RUN(
62         [
63           #include <stdio.h>
64           #include <stdint.h>
65           #ifdef _WIN32
66           #  include <windows.h>
67           #elif MACOS
68           #  include <sys/param.h>
69           #  include <sys/sysctl.h>
70           #else
71           #  include <unistd.h>
72           #endif
73           
74           int main (int argc, char *argv[])
75           {
76             uint32_t count;
77             
78             #ifdef WIN32
79             SYSTEM_INFO sysinfo;
80             GetSystemInfo(&sysinfo);
81       
82             count = sysinfo.dwNumberOfProcessors;
83             
84             #elif MACOS
85             int nm[2];
86             size_t len = 4;
87       
88             nm[0] = CTL_HW;
89             nm[1] = HW_AVAILCPU;
90             sysctl(nm, 2, &count, &len, NULL, 0);
91       
92             if(count < 1) {
93               nm[1] = HW_NCPU;
94               sysctl(nm, 2, &count, &len, NULL, 0);
95               if(count < 1) {
96                 count = 1;
97               }
98             }
99             
100             #else
101             count = sysconf(_SC_NPROCESSORS_ONLN);
102             #endif
103
104             return count;
105           }
106         ],
107         [ax_cv_system_cores=$?],
108         [ax_cv_system_cores=$?],
109         [ax_cv_system_cores=]
110     )
111     AC_LANG_POP
112   ])
113 ])
114