1 dnl ######################################################################
2 dnl Common m4sh code for compiler stuff
3 AC_DEFUN([NTP_COMPILER], [
4 AC_REQUIRE([AC_PROG_CC_C89])
5 AC_REQUIRE([AC_PROG_CC_C99])
11 AC_SUBST([CFLAGS_NTP])
12 AC_SUBST([CPPFLAGS_NTP])
14 AC_SUBST([LDFLAGS_NTP])
16 case "$ac_cv_prog_cc_c89" in
18 AC_MSG_WARN([ANSI C89/ISO C90 is the minimum to compile NTP]
19 [ version 4.2.5 and higher.])
24 [if $CC can handle @%:@warning],
27 [AC_LANG_PROGRAM([[]], [[#warning foo]])],
28 [ntp_cv_cpp_warning=yes],
29 [ntp_cv_cpp_warning=no]
32 case "$ntp_cv_cpp_warning" in
34 AC_DEFINE([NO_OPTION_NAME_WARNINGS], [1],
35 [Should we avoid @%:@warning on option name collisions?])
39 [if $CC supports __attribute__((...))],
40 [ntp_cv_cc_attribute],
44 [[void foo(void) __attribute__((__noreturn__));]]
46 [ntp_cv_cc_attribute=yes],
47 [ntp_cv_cc_attribute=no]
50 case "$ntp_cv_cc_attribute" in
52 AC_DEFINE([HAVE___ATTRIBUTE__], [],
53 [defined if C compiler supports __attribute__((...))])
56 [HAVE___ATTRIBUTE___VERBATIM],
58 /* define away __attribute__() if unsupported */
59 #ifndef HAVE___ATTRIBUTE__
60 # define __attribute__(x) /* empty */
62 #define ISC_PLATFORM_NORETURN_PRE
63 #define ISC_PLATFORM_NORETURN_POST __attribute__((__noreturn__))
69 SAVED_CFLAGS="$CFLAGS"
70 CFLAGS="$CFLAGS -Wstrict-overflow"
72 [if $CC can handle -Wstrict-overflow],
73 [ntp_cv_gcc_Wstrict_overflow],
75 [AC_LANG_PROGRAM([[]], [[]])],
76 [ntp_cv_gcc_Wstrict_overflow=yes],
77 [ntp_cv_gcc_Wstrict_overflow=no]
81 # $ntp_cv_gcc_Wstrict_overflow is tested later to add the
84 CFLAGS="$SAVED_CFLAGS -Winit-self"
86 [if $CC can handle -Winit-self],
87 [ntp_cv_gcc_Winit_self],
90 [AC_LANG_PROGRAM([[]], [[]])],
91 [ntp_cv_gcc_Winit_self=yes],
92 [ntp_cv_gcc_Winit_self=no]
96 CFLAGS="$SAVED_CFLAGS"
97 AS_UNSET([SAVED_CFLAGS])
99 # $ntp_cv_gcc_Winit_self is tested later to add the
100 # flag to CFLAGS_NTP.
103 [if linker supports omitting unused code and data],
104 [ntp_cv_gc_sections_runs],
106 dnl NetBSD will link but likely not run with --gc-sections
107 dnl http://bugs.ntp.org/1844
108 dnl http://gnats.netbsd.org/40401
109 dnl --gc-sections causes attempt to load as linux elf, with
110 dnl wrong syscalls in place. Test a little gauntlet of
111 dnl simple stdio read code checking for errors, expecting
112 dnl enough syscall differences that the NetBSD code will
113 dnl fail even with Linux emulation working as designed.
114 dnl A shorter test could be refined by someone with access
115 dnl to a NetBSD host with Linux emulation working.
117 CFLAGS="$CFLAGS -Wl,--gc-sections"
128 int read_success_once;
130 fpC = fopen("conftest.c", "r");
134 cch = fread(buf, sizeof(buf), 1, fpC);
135 read_success_once |= (0 != cch);
137 if (!read_success_once)
141 if (0 != fclose(fpC))
148 if test "X$cross_compiling" = "Xyes" || grep gc-sections conftest.err ; then
149 ntp_cv_gc_sections_runs=no
151 ntp_cv_gc_sections_runs=no
152 ./conftest >/dev/null 2>&1 && ntp_cv_gc_sections_runs=yes
155 [ntp_cv_gc_sections_runs=no]
158 AS_UNSET([origCFLAGS])
161 case "$ntp_cv_gc_sections_runs" in
163 LDADD_LIBNTP="-Wl,--gc-sections"
164 CFLAGS_NTP="$CFLAGS_NTP -ffunction-sections -fdata-sections"
170 CFLAGS_NTP="$CFLAGS_NTP -Wall"
171 CFLAGS_NTP="$CFLAGS_NTP -Wcast-align"
172 CFLAGS_NTP="$CFLAGS_NTP -Wcast-qual"
173 # CFLAGS_NTP="$CFLAGS_NTP -Wconversion"
174 # CFLAGS_NTP="$CFLAGS_NTP -Werror"
175 # CFLAGS_NTP="$CFLAGS_NTP -Wextra"
176 # CFLAGS_NTP="$CFLAGS_NTP -Wfloat-equal"
177 CFLAGS_NTP="$CFLAGS_NTP -Wmissing-prototypes"
178 CFLAGS_NTP="$CFLAGS_NTP -Wpointer-arith"
179 CFLAGS_NTP="$CFLAGS_NTP -Wshadow"
180 # CFLAGS_NTP="$CFLAGS_NTP -Wtraditional"
181 # CFLAGS_NTP="$CFLAGS_NTP -Wwrite-strings"
182 case "$ntp_cv_gcc_Winit_self" in
184 CFLAGS_NTP="$CFLAGS_NTP -Winit-self"
186 case "$ntp_cv_gcc_Wstrict_overflow" in
188 CFLAGS_NTP="$CFLAGS_NTP -Wstrict-overflow"
190 # -W[no-]strict-prototypes might be added by NTP_OPENSSL
196 dnl ======================================================================