1275970Scydnl ###################################################################### 2275970Scydnl Common m4sh code for compiler stuff 3275970ScyAC_DEFUN([NTP_COMPILER], [ 4275970Scy 5316722SdelphijAC_USE_SYSTEM_EXTENSIONS 6316722Sdelphij 7316722Sdelphij# Ralf Wildenhues: With per-target flags we need CC_C_O 8316722Sdelphij# AM_PROG_CC_C_O supersets AC_PROG_CC_C_O 9316722SdelphijAM_PROG_CC_C_O 10316722SdelphijAC_PROG_GCC_TRADITIONAL 11316722SdelphijAC_REQUIRE([AC_PROG_CC_STDC]) 12316722Sdelphijdnl AC_REQUIRE([AC_PROG_CC_C89]) 13316722Sdelphijdnl AC_REQUIRE([AC_PROG_CC_C99]) 14316722Sdelphij 15275970ScyCFLAGS_NTP= 16275970ScyCPPFLAGS_NTP= 17275970ScyLDADD_NTP= 18275970ScyLDFLAGS_NTP= 19275970ScyAC_SUBST([CFLAGS_NTP]) 20275970ScyAC_SUBST([CPPFLAGS_NTP]) 21275970ScyAC_SUBST([LDADD_NTP]) 22275970ScyAC_SUBST([LDFLAGS_NTP]) 23275970Scy 24275970Scycase "$ac_cv_prog_cc_c89" in 25275970Scy no) 26275970Scy AC_MSG_WARN([ANSI C89/ISO C90 is the minimum to compile NTP] 27275970Scy [ version 4.2.5 and higher.]) 28275970Scy ;; 29275970Scyesac 30275970Scy 31275970ScyAC_CACHE_CHECK( 32275970Scy [if $CC can handle @%:@warning], 33275970Scy [ntp_cv_cpp_warning], 34275970Scy [AC_COMPILE_IFELSE( 35275970Scy [AC_LANG_PROGRAM([[]], [[#warning foo]])], 36275970Scy [ntp_cv_cpp_warning=yes], 37275970Scy [ntp_cv_cpp_warning=no] 38275970Scy )] 39275970Scy) 40275970Scycase "$ntp_cv_cpp_warning" in 41275970Scy no) 42275970Scy AC_DEFINE([NO_OPTION_NAME_WARNINGS], [1], 43275970Scy [Should we avoid @%:@warning on option name collisions?]) 44275970Scyesac 45275970Scy 46275970ScyAC_CACHE_CHECK( 47275970Scy [if $CC supports __attribute__((...))], 48275970Scy [ntp_cv_cc_attribute], 49275970Scy [AC_COMPILE_IFELSE( 50275970Scy [AC_LANG_PROGRAM( 51275970Scy [[]], 52275970Scy [[void foo(void) __attribute__((__noreturn__));]] 53275970Scy )], 54275970Scy [ntp_cv_cc_attribute=yes], 55275970Scy [ntp_cv_cc_attribute=no] 56275970Scy )] 57275970Scy) 58275970Scycase "$ntp_cv_cc_attribute" in 59275970Scy yes) 60275970Scy AC_DEFINE([HAVE___ATTRIBUTE__], [], 61275970Scy [defined if C compiler supports __attribute__((...))]) 62275970Scyesac 63275970ScyAH_VERBATIM( 64275970Scy [HAVE___ATTRIBUTE___VERBATIM], 65275970Scy [ 66275970Scy /* define away __attribute__() if unsupported */ 67275970Scy #ifndef HAVE___ATTRIBUTE__ 68275970Scy # define __attribute__(x) /* empty */ 69275970Scy #endif 70275970Scy #define ISC_PLATFORM_NORETURN_PRE 71275970Scy #define ISC_PLATFORM_NORETURN_POST __attribute__((__noreturn__)) 72275970Scy ] 73275970Scy) 74275970Scy 75275970Scycase "$GCC" in 76275970Scy yes) 77275970Scy SAVED_CFLAGS="$CFLAGS" 78275970Scy CFLAGS="$CFLAGS -Wstrict-overflow" 79275970Scy AC_CACHE_CHECK( 80275970Scy [if $CC can handle -Wstrict-overflow], 81275970Scy [ntp_cv_gcc_Wstrict_overflow], 82275970Scy [AC_COMPILE_IFELSE( 83275970Scy [AC_LANG_PROGRAM([[]], [[]])], 84275970Scy [ntp_cv_gcc_Wstrict_overflow=yes], 85275970Scy [ntp_cv_gcc_Wstrict_overflow=no] 86275970Scy ) ] 87275970Scy ) 88275970Scy # 89275970Scy # $ntp_cv_gcc_Wstrict_overflow is tested later to add the 90275970Scy # flag to CFLAGS. 91275970Scy # 92275970Scy CFLAGS="$SAVED_CFLAGS -Winit-self" 93275970Scy AC_CACHE_CHECK( 94275970Scy [if $CC can handle -Winit-self], 95275970Scy [ntp_cv_gcc_Winit_self], 96275970Scy [ 97275970Scy AC_COMPILE_IFELSE( 98275970Scy [AC_LANG_PROGRAM([[]], [[]])], 99275970Scy [ntp_cv_gcc_Winit_self=yes], 100275970Scy [ntp_cv_gcc_Winit_self=no] 101275970Scy ) 102275970Scy ] 103275970Scy ) 104275970Scy CFLAGS="$SAVED_CFLAGS" 105275970Scy AS_UNSET([SAVED_CFLAGS]) 106275970Scy # 107275970Scy # $ntp_cv_gcc_Winit_self is tested later to add the 108275970Scy # flag to CFLAGS_NTP. 109275970Scy # 110275970Scy AC_CACHE_CHECK( 111275970Scy [if linker supports omitting unused code and data], 112275970Scy [ntp_cv_gc_sections_runs], 113275970Scy [ 114275970Scy dnl NetBSD will link but likely not run with --gc-sections 115275970Scy dnl http://bugs.ntp.org/1844 116275970Scy dnl http://gnats.netbsd.org/40401 117275970Scy dnl --gc-sections causes attempt to load as linux elf, with 118275970Scy dnl wrong syscalls in place. Test a little gauntlet of 119275970Scy dnl simple stdio read code checking for errors, expecting 120275970Scy dnl enough syscall differences that the NetBSD code will 121275970Scy dnl fail even with Linux emulation working as designed. 122275970Scy dnl A shorter test could be refined by someone with access 123275970Scy dnl to a NetBSD host with Linux emulation working. 124275970Scy origCFLAGS="$CFLAGS" 125275970Scy CFLAGS="$CFLAGS -Wl,--gc-sections" 126275970Scy AC_LINK_IFELSE( 127275970Scy [AC_LANG_PROGRAM( 128275970Scy [[ 129275970Scy #include <stdlib.h> 130275970Scy #include <stdio.h> 131275970Scy ]], 132275970Scy [[ 133275970Scy FILE * fpC; 134275970Scy char buf[32]; 135275970Scy size_t cch; 136275970Scy int read_success_once; 137275970Scy 138275970Scy fpC = fopen("conftest.c", "r"); 139275970Scy if (NULL == fpC) 140275970Scy exit(1); 141275970Scy do { 142275970Scy cch = fread(buf, sizeof(buf), 1, fpC); 143275970Scy read_success_once |= (0 != cch); 144275970Scy } while (0 != cch); 145275970Scy if (!read_success_once) 146275970Scy exit(2); 147275970Scy if (!feof(fpC)) 148275970Scy exit(3); 149275970Scy if (0 != fclose(fpC)) 150275970Scy exit(4); 151275970Scy 152275970Scy exit(EXIT_SUCCESS); 153275970Scy ]] 154275970Scy )], 155275970Scy [ 156275970Scy if test "X$cross_compiling" = "Xyes" || grep gc-sections conftest.err ; then 157275970Scy ntp_cv_gc_sections_runs=no 158275970Scy else 159275970Scy ntp_cv_gc_sections_runs=no 160275970Scy ./conftest >/dev/null 2>&1 && ntp_cv_gc_sections_runs=yes 161275970Scy fi 162275970Scy ], 163275970Scy [ntp_cv_gc_sections_runs=no] 164275970Scy ) 165275970Scy CFLAGS="$origCFLAGS" 166275970Scy AS_UNSET([origCFLAGS]) 167275970Scy ] 168275970Scy ) 169275970Scy case "$ntp_cv_gc_sections_runs" in 170275970Scy yes) 171275970Scy LDADD_LIBNTP="-Wl,--gc-sections" 172275970Scy CFLAGS_NTP="$CFLAGS_NTP -ffunction-sections -fdata-sections" 173275970Scy ;; 174275970Scy no) 175275970Scy LDADD_LIBNTP= 176275970Scy ;; 177275970Scy esac 178275970Scy CFLAGS_NTP="$CFLAGS_NTP -Wall" 179275970Scy CFLAGS_NTP="$CFLAGS_NTP -Wcast-align" 180275970Scy CFLAGS_NTP="$CFLAGS_NTP -Wcast-qual" 181275970Scy # CFLAGS_NTP="$CFLAGS_NTP -Wconversion" 182275970Scy # CFLAGS_NTP="$CFLAGS_NTP -Werror" 183275970Scy # CFLAGS_NTP="$CFLAGS_NTP -Wextra" 184275970Scy # CFLAGS_NTP="$CFLAGS_NTP -Wfloat-equal" 185275970Scy CFLAGS_NTP="$CFLAGS_NTP -Wmissing-prototypes" 186275970Scy CFLAGS_NTP="$CFLAGS_NTP -Wpointer-arith" 187275970Scy CFLAGS_NTP="$CFLAGS_NTP -Wshadow" 188275970Scy # CFLAGS_NTP="$CFLAGS_NTP -Wtraditional" 189275970Scy # CFLAGS_NTP="$CFLAGS_NTP -Wwrite-strings" 190275970Scy case "$ntp_cv_gcc_Winit_self" in 191275970Scy yes) 192275970Scy CFLAGS_NTP="$CFLAGS_NTP -Winit-self" 193275970Scy esac 194275970Scy case "$ntp_cv_gcc_Wstrict_overflow" in 195275970Scy yes) 196275970Scy CFLAGS_NTP="$CFLAGS_NTP -Wstrict-overflow" 197275970Scy esac 198275970Scy # -W[no-]strict-prototypes might be added by NTP_OPENSSL 199275970Scyesac 200275970Scy 201275970ScyNTP_OS_CFLAGS 202275970Scy 203316722SdelphijAC_C_BIGENDIAN 204316722SdelphijAC_C_VOLATILE 205316722SdelphijAC_PROG_CPP 206316722Sdelphij 207275970Scy])dnl 208275970Scydnl ====================================================================== 209