1 dnl ######################################################################
2 dnl Common m4sh code for compiler stuff
3 AC_DEFUN([NTP_COMPILER], [
5 AC_USE_SYSTEM_EXTENSIONS
7 # Ralf Wildenhues: With per-target flags we need CC_C_O
8 # AM_PROG_CC_C_O supersets AC_PROG_CC_C_O
10 AC_PROG_GCC_TRADITIONAL
11 AC_REQUIRE([AC_PROG_CC_STDC])
12 dnl AC_REQUIRE([AC_PROG_CC_C89])
13 dnl AC_REQUIRE([AC_PROG_CC_C99])
19 AC_SUBST([CFLAGS_NTP])
20 AC_SUBST([CPPFLAGS_NTP])
22 AC_SUBST([LDFLAGS_NTP])
24 case "$ac_cv_prog_cc_c89" in
26 AC_MSG_WARN([ANSI C89/ISO C90 is the minimum to compile NTP]
27 [ version 4.2.5 and higher.])
32 [if $CC can handle @%:@warning],
35 [AC_LANG_PROGRAM([[]], [[#warning foo]])],
36 [ntp_cv_cpp_warning=yes],
37 [ntp_cv_cpp_warning=no]
40 case "$ntp_cv_cpp_warning" in
42 AC_DEFINE([NO_OPTION_NAME_WARNINGS], [1],
43 [Should we avoid @%:@warning on option name collisions?])
47 [if $CC supports __attribute__((...))],
48 [ntp_cv_cc_attribute],
52 [[void foo(void) __attribute__((__noreturn__));]]
54 [ntp_cv_cc_attribute=yes],
55 [ntp_cv_cc_attribute=no]
58 case "$ntp_cv_cc_attribute" in
60 AC_DEFINE([HAVE___ATTRIBUTE__], [],
61 [defined if C compiler supports __attribute__((...))])
64 [HAVE___ATTRIBUTE___VERBATIM],
66 /* define away __attribute__() if unsupported */
67 #ifndef HAVE___ATTRIBUTE__
68 # define __attribute__(x) /* empty */
70 #define ISC_PLATFORM_NORETURN_PRE
71 #define ISC_PLATFORM_NORETURN_POST __attribute__((__noreturn__))
77 SAVED_CFLAGS="$CFLAGS"
78 CFLAGS="$CFLAGS -Wstrict-overflow"
80 [if $CC can handle -Wstrict-overflow],
81 [ntp_cv_gcc_Wstrict_overflow],
83 [AC_LANG_PROGRAM([[]], [[]])],
84 [ntp_cv_gcc_Wstrict_overflow=yes],
85 [ntp_cv_gcc_Wstrict_overflow=no]
89 # $ntp_cv_gcc_Wstrict_overflow is tested later to add the
92 CFLAGS="$SAVED_CFLAGS -Winit-self"
94 [if $CC can handle -Winit-self],
95 [ntp_cv_gcc_Winit_self],
98 [AC_LANG_PROGRAM([[]], [[]])],
99 [ntp_cv_gcc_Winit_self=yes],
100 [ntp_cv_gcc_Winit_self=no]
104 CFLAGS="$SAVED_CFLAGS"
105 AS_UNSET([SAVED_CFLAGS])
107 # $ntp_cv_gcc_Winit_self is tested later to add the
108 # flag to CFLAGS_NTP.
111 [if linker supports omitting unused code and data],
112 [ntp_cv_gc_sections_runs],
114 dnl NetBSD will link but likely not run with --gc-sections
115 dnl http://bugs.ntp.org/1844
116 dnl http://gnats.netbsd.org/40401
117 dnl --gc-sections causes attempt to load as linux elf, with
118 dnl wrong syscalls in place. Test a little gauntlet of
119 dnl simple stdio read code checking for errors, expecting
120 dnl enough syscall differences that the NetBSD code will
121 dnl fail even with Linux emulation working as designed.
122 dnl A shorter test could be refined by someone with access
123 dnl to a NetBSD host with Linux emulation working.
125 CFLAGS="$CFLAGS -Wl,--gc-sections"
136 int read_success_once;
138 fpC = fopen("conftest.c", "r");
142 cch = fread(buf, sizeof(buf), 1, fpC);
143 read_success_once |= (0 != cch);
145 if (!read_success_once)
149 if (0 != fclose(fpC))
156 if test "X$cross_compiling" = "Xyes" || grep gc-sections conftest.err ; then
157 ntp_cv_gc_sections_runs=no
159 ntp_cv_gc_sections_runs=no
160 ./conftest >/dev/null 2>&1 && ntp_cv_gc_sections_runs=yes
163 [ntp_cv_gc_sections_runs=no]
166 AS_UNSET([origCFLAGS])
169 case "$ntp_cv_gc_sections_runs" in
171 LDADD_LIBNTP="-Wl,--gc-sections"
172 CFLAGS_NTP="$CFLAGS_NTP -ffunction-sections -fdata-sections"
178 CFLAGS_NTP="$CFLAGS_NTP -Wall"
179 CFLAGS_NTP="$CFLAGS_NTP -Wcast-align"
180 CFLAGS_NTP="$CFLAGS_NTP -Wcast-qual"
181 # CFLAGS_NTP="$CFLAGS_NTP -Wconversion"
182 # CFLAGS_NTP="$CFLAGS_NTP -Werror"
183 # CFLAGS_NTP="$CFLAGS_NTP -Wextra"
184 # CFLAGS_NTP="$CFLAGS_NTP -Wfloat-equal"
185 CFLAGS_NTP="$CFLAGS_NTP -Wmissing-prototypes"
186 CFLAGS_NTP="$CFLAGS_NTP -Wpointer-arith"
187 CFLAGS_NTP="$CFLAGS_NTP -Wshadow"
188 # CFLAGS_NTP="$CFLAGS_NTP -Wtraditional"
189 # CFLAGS_NTP="$CFLAGS_NTP -Wwrite-strings"
190 case "$ntp_cv_gcc_Winit_self" in
192 CFLAGS_NTP="$CFLAGS_NTP -Winit-self"
194 case "$ntp_cv_gcc_Wstrict_overflow" in
196 CFLAGS_NTP="$CFLAGS_NTP -Wstrict-overflow"
198 # -W[no-]strict-prototypes might be added by NTP_OPENSSL
208 dnl ======================================================================