ntp_compiler.m4 revision 275970
1dnl ###################################################################### 2dnl Common m4sh code for compiler stuff 3AC_DEFUN([NTP_COMPILER], [ 4AC_REQUIRE([AC_PROG_CC_C89]) 5 6CFLAGS_NTP= 7CPPFLAGS_NTP= 8LDADD_NTP= 9LDFLAGS_NTP= 10AC_SUBST([CFLAGS_NTP]) 11AC_SUBST([CPPFLAGS_NTP]) 12AC_SUBST([LDADD_NTP]) 13AC_SUBST([LDFLAGS_NTP]) 14 15case "$ac_cv_prog_cc_c89" in 16 no) 17 AC_MSG_WARN([ANSI C89/ISO C90 is the minimum to compile NTP] 18 [ version 4.2.5 and higher.]) 19 ;; 20esac 21 22AC_CACHE_CHECK( 23 [if $CC can handle @%:@warning], 24 [ntp_cv_cpp_warning], 25 [AC_COMPILE_IFELSE( 26 [AC_LANG_PROGRAM([[]], [[#warning foo]])], 27 [ntp_cv_cpp_warning=yes], 28 [ntp_cv_cpp_warning=no] 29 )] 30) 31case "$ntp_cv_cpp_warning" in 32 no) 33 AC_DEFINE([NO_OPTION_NAME_WARNINGS], [1], 34 [Should we avoid @%:@warning on option name collisions?]) 35esac 36 37AC_CACHE_CHECK( 38 [if $CC supports __attribute__((...))], 39 [ntp_cv_cc_attribute], 40 [AC_COMPILE_IFELSE( 41 [AC_LANG_PROGRAM( 42 [[]], 43 [[void foo(void) __attribute__((__noreturn__));]] 44 )], 45 [ntp_cv_cc_attribute=yes], 46 [ntp_cv_cc_attribute=no] 47 )] 48) 49case "$ntp_cv_cc_attribute" in 50 yes) 51 AC_DEFINE([HAVE___ATTRIBUTE__], [], 52 [defined if C compiler supports __attribute__((...))]) 53esac 54AH_VERBATIM( 55 [HAVE___ATTRIBUTE___VERBATIM], 56 [ 57 /* define away __attribute__() if unsupported */ 58 #ifndef HAVE___ATTRIBUTE__ 59 # define __attribute__(x) /* empty */ 60 #endif 61 #define ISC_PLATFORM_NORETURN_PRE 62 #define ISC_PLATFORM_NORETURN_POST __attribute__((__noreturn__)) 63 ] 64) 65 66case "$GCC" in 67 yes) 68 SAVED_CFLAGS="$CFLAGS" 69 CFLAGS="$CFLAGS -Wstrict-overflow" 70 AC_CACHE_CHECK( 71 [if $CC can handle -Wstrict-overflow], 72 [ntp_cv_gcc_Wstrict_overflow], 73 [AC_COMPILE_IFELSE( 74 [AC_LANG_PROGRAM([[]], [[]])], 75 [ntp_cv_gcc_Wstrict_overflow=yes], 76 [ntp_cv_gcc_Wstrict_overflow=no] 77 ) ] 78 ) 79 # 80 # $ntp_cv_gcc_Wstrict_overflow is tested later to add the 81 # flag to CFLAGS. 82 # 83 CFLAGS="$SAVED_CFLAGS -Winit-self" 84 AC_CACHE_CHECK( 85 [if $CC can handle -Winit-self], 86 [ntp_cv_gcc_Winit_self], 87 [ 88 AC_COMPILE_IFELSE( 89 [AC_LANG_PROGRAM([[]], [[]])], 90 [ntp_cv_gcc_Winit_self=yes], 91 [ntp_cv_gcc_Winit_self=no] 92 ) 93 ] 94 ) 95 CFLAGS="$SAVED_CFLAGS" 96 AS_UNSET([SAVED_CFLAGS]) 97 # 98 # $ntp_cv_gcc_Winit_self is tested later to add the 99 # flag to CFLAGS_NTP. 100 # 101 AC_CACHE_CHECK( 102 [if linker supports omitting unused code and data], 103 [ntp_cv_gc_sections_runs], 104 [ 105 dnl NetBSD will link but likely not run with --gc-sections 106 dnl http://bugs.ntp.org/1844 107 dnl http://gnats.netbsd.org/40401 108 dnl --gc-sections causes attempt to load as linux elf, with 109 dnl wrong syscalls in place. Test a little gauntlet of 110 dnl simple stdio read code checking for errors, expecting 111 dnl enough syscall differences that the NetBSD code will 112 dnl fail even with Linux emulation working as designed. 113 dnl A shorter test could be refined by someone with access 114 dnl to a NetBSD host with Linux emulation working. 115 origCFLAGS="$CFLAGS" 116 CFLAGS="$CFLAGS -Wl,--gc-sections" 117 AC_LINK_IFELSE( 118 [AC_LANG_PROGRAM( 119 [[ 120 #include <stdlib.h> 121 #include <stdio.h> 122 ]], 123 [[ 124 FILE * fpC; 125 char buf[32]; 126 size_t cch; 127 int read_success_once; 128 129 fpC = fopen("conftest.c", "r"); 130 if (NULL == fpC) 131 exit(1); 132 do { 133 cch = fread(buf, sizeof(buf), 1, fpC); 134 read_success_once |= (0 != cch); 135 } while (0 != cch); 136 if (!read_success_once) 137 exit(2); 138 if (!feof(fpC)) 139 exit(3); 140 if (0 != fclose(fpC)) 141 exit(4); 142 143 exit(EXIT_SUCCESS); 144 ]] 145 )], 146 [ 147 if test "X$cross_compiling" = "Xyes" || grep gc-sections conftest.err ; then 148 ntp_cv_gc_sections_runs=no 149 else 150 ntp_cv_gc_sections_runs=no 151 ./conftest >/dev/null 2>&1 && ntp_cv_gc_sections_runs=yes 152 fi 153 ], 154 [ntp_cv_gc_sections_runs=no] 155 ) 156 CFLAGS="$origCFLAGS" 157 AS_UNSET([origCFLAGS]) 158 ] 159 ) 160 case "$ntp_cv_gc_sections_runs" in 161 yes) 162 LDADD_LIBNTP="-Wl,--gc-sections" 163 CFLAGS_NTP="$CFLAGS_NTP -ffunction-sections -fdata-sections" 164 ;; 165 no) 166 LDADD_LIBNTP= 167 ;; 168 esac 169 CFLAGS_NTP="$CFLAGS_NTP -Wall" 170 CFLAGS_NTP="$CFLAGS_NTP -Wcast-align" 171 CFLAGS_NTP="$CFLAGS_NTP -Wcast-qual" 172 # CFLAGS_NTP="$CFLAGS_NTP -Wconversion" 173 # CFLAGS_NTP="$CFLAGS_NTP -Werror" 174 # CFLAGS_NTP="$CFLAGS_NTP -Wextra" 175 # CFLAGS_NTP="$CFLAGS_NTP -Wfloat-equal" 176 CFLAGS_NTP="$CFLAGS_NTP -Wmissing-prototypes" 177 CFLAGS_NTP="$CFLAGS_NTP -Wpointer-arith" 178 CFLAGS_NTP="$CFLAGS_NTP -Wshadow" 179 # CFLAGS_NTP="$CFLAGS_NTP -Wtraditional" 180 # CFLAGS_NTP="$CFLAGS_NTP -Wwrite-strings" 181 case "$ntp_cv_gcc_Winit_self" in 182 yes) 183 CFLAGS_NTP="$CFLAGS_NTP -Winit-self" 184 esac 185 case "$ntp_cv_gcc_Wstrict_overflow" in 186 yes) 187 CFLAGS_NTP="$CFLAGS_NTP -Wstrict-overflow" 188 esac 189 # -W[no-]strict-prototypes might be added by NTP_OPENSSL 190esac 191 192NTP_OS_CFLAGS 193 194])dnl 195dnl ====================================================================== 196