12b15cb3dSCy Schubertdnl ###################################################################### 22b15cb3dSCy Schubertdnl Common m4sh code for compiler stuff 32b15cb3dSCy SchubertAC_DEFUN([NTP_COMPILER], [ 4*f5f40dd6SCy SchubertAC_REQUIRE([AC_PROG_CC_STDC]) 5f0574f5cSXin LI 6f0574f5cSXin LIAC_USE_SYSTEM_EXTENSIONS 7f0574f5cSXin LI 8a466cc55SCy SchubertCC_NOFORMAT= 92b15cb3dSCy SchubertCFLAGS_NTP= 102b15cb3dSCy SchubertCPPFLAGS_NTP= 112b15cb3dSCy SchubertLDADD_NTP= 122b15cb3dSCy SchubertLDFLAGS_NTP= 13a466cc55SCy SchubertAC_SUBST([CC_NOFORMAT]) 142b15cb3dSCy SchubertAC_SUBST([CFLAGS_NTP]) 152b15cb3dSCy SchubertAC_SUBST([CPPFLAGS_NTP]) 162b15cb3dSCy SchubertAC_SUBST([LDADD_NTP]) 172b15cb3dSCy SchubertAC_SUBST([LDFLAGS_NTP]) 182b15cb3dSCy Schubert 192b15cb3dSCy Schubertcase "$ac_cv_prog_cc_c89" in 202b15cb3dSCy Schubert no) 212b15cb3dSCy Schubert AC_MSG_WARN([ANSI C89/ISO C90 is the minimum to compile NTP] 222b15cb3dSCy Schubert [ version 4.2.5 and higher.]) 232b15cb3dSCy Schubert ;; 242b15cb3dSCy Schubertesac 252b15cb3dSCy Schubert 262b15cb3dSCy SchubertAC_CACHE_CHECK( 272b15cb3dSCy Schubert [if $CC can handle @%:@warning], 282b15cb3dSCy Schubert [ntp_cv_cpp_warning], 292b15cb3dSCy Schubert [AC_COMPILE_IFELSE( 302b15cb3dSCy Schubert [AC_LANG_PROGRAM([[]], [[#warning foo]])], 312b15cb3dSCy Schubert [ntp_cv_cpp_warning=yes], 322b15cb3dSCy Schubert [ntp_cv_cpp_warning=no] 332b15cb3dSCy Schubert )] 342b15cb3dSCy Schubert) 352b15cb3dSCy Schubertcase "$ntp_cv_cpp_warning" in 362b15cb3dSCy Schubert no) 372b15cb3dSCy Schubert AC_DEFINE([NO_OPTION_NAME_WARNINGS], [1], 382b15cb3dSCy Schubert [Should we avoid @%:@warning on option name collisions?]) 392b15cb3dSCy Schubertesac 402b15cb3dSCy Schubert 412b15cb3dSCy SchubertAC_CACHE_CHECK( 422b15cb3dSCy Schubert [if $CC supports __attribute__((...))], 432b15cb3dSCy Schubert [ntp_cv_cc_attribute], 442b15cb3dSCy Schubert [AC_COMPILE_IFELSE( 452b15cb3dSCy Schubert [AC_LANG_PROGRAM( 462b15cb3dSCy Schubert [[]], 472b15cb3dSCy Schubert [[void foo(void) __attribute__((__noreturn__));]] 482b15cb3dSCy Schubert )], 492b15cb3dSCy Schubert [ntp_cv_cc_attribute=yes], 502b15cb3dSCy Schubert [ntp_cv_cc_attribute=no] 512b15cb3dSCy Schubert )] 522b15cb3dSCy Schubert) 532b15cb3dSCy Schubertcase "$ntp_cv_cc_attribute" in 542b15cb3dSCy Schubert yes) 552b15cb3dSCy Schubert AC_DEFINE([HAVE___ATTRIBUTE__], [], 562b15cb3dSCy Schubert [defined if C compiler supports __attribute__((...))]) 572b15cb3dSCy Schubertesac 582b15cb3dSCy SchubertAH_VERBATIM( 592b15cb3dSCy Schubert [HAVE___ATTRIBUTE___VERBATIM], 602b15cb3dSCy Schubert [ 612b15cb3dSCy Schubert /* define away __attribute__() if unsupported */ 622b15cb3dSCy Schubert #ifndef HAVE___ATTRIBUTE__ 632b15cb3dSCy Schubert # define __attribute__(x) /* empty */ 642b15cb3dSCy Schubert #endif 652b15cb3dSCy Schubert #define ISC_PLATFORM_NORETURN_PRE 662b15cb3dSCy Schubert #define ISC_PLATFORM_NORETURN_POST __attribute__((__noreturn__)) 672b15cb3dSCy Schubert ] 682b15cb3dSCy Schubert) 692b15cb3dSCy Schubert 702b15cb3dSCy Schubertcase "$GCC" in 712b15cb3dSCy Schubert yes) 722b15cb3dSCy Schubert SAVED_CFLAGS="$CFLAGS" 73a466cc55SCy Schubert CFLAGS="$SAVED_CFLAGS -Wstrict-overflow" 742b15cb3dSCy Schubert AC_CACHE_CHECK( 752b15cb3dSCy Schubert [if $CC can handle -Wstrict-overflow], 762b15cb3dSCy Schubert [ntp_cv_gcc_Wstrict_overflow], 772b15cb3dSCy Schubert [AC_COMPILE_IFELSE( 782b15cb3dSCy Schubert [AC_LANG_PROGRAM([[]], [[]])], 792b15cb3dSCy Schubert [ntp_cv_gcc_Wstrict_overflow=yes], 802b15cb3dSCy Schubert [ntp_cv_gcc_Wstrict_overflow=no] 812b15cb3dSCy Schubert ) ] 822b15cb3dSCy Schubert ) 832b15cb3dSCy Schubert # 842b15cb3dSCy Schubert # $ntp_cv_gcc_Wstrict_overflow is tested later to add the 852b15cb3dSCy Schubert # flag to CFLAGS. 862b15cb3dSCy Schubert # 872b15cb3dSCy Schubert CFLAGS="$SAVED_CFLAGS -Winit-self" 882b15cb3dSCy Schubert AC_CACHE_CHECK( 892b15cb3dSCy Schubert [if $CC can handle -Winit-self], 902b15cb3dSCy Schubert [ntp_cv_gcc_Winit_self], 912b15cb3dSCy Schubert [ 922b15cb3dSCy Schubert AC_COMPILE_IFELSE( 932b15cb3dSCy Schubert [AC_LANG_PROGRAM([[]], [[]])], 942b15cb3dSCy Schubert [ntp_cv_gcc_Winit_self=yes], 952b15cb3dSCy Schubert [ntp_cv_gcc_Winit_self=no] 962b15cb3dSCy Schubert ) 972b15cb3dSCy Schubert ] 982b15cb3dSCy Schubert ) 99a466cc55SCy Schubert # 100*f5f40dd6SCy Schubert # $ntp_cv_gcc_Winit_self is tested later to add the 101*f5f40dd6SCy Schubert # flag to CFLAGS_NTP. 102*f5f40dd6SCy Schubert # 103a466cc55SCy Schubert # libopts specifically builds a string with embedded NULs. 104a466cc55SCy Schubert # This causes a bunch of distracting warnings due to -Wformat. 105a466cc55SCy Schubert # 106*f5f40dd6SCy Schubert CFLAGS="$SAVED_CFLAGS -Wno-format -Wno-format-security" 107a466cc55SCy Schubert AC_CACHE_CHECK( 108*f5f40dd6SCy Schubert [if $CC can handle -Wno-format -Wno-format-security], 109a466cc55SCy Schubert [ntp_cv_gcc_Wno_format], 110a466cc55SCy Schubert [ 111a466cc55SCy Schubert AC_COMPILE_IFELSE( 112a466cc55SCy Schubert [AC_LANG_PROGRAM([[]], [[]])], 113a466cc55SCy Schubert [ntp_cv_gcc_Wno_format=yes], 114a466cc55SCy Schubert [ntp_cv_gcc_Wno_format=no] 115a466cc55SCy Schubert ) 116a466cc55SCy Schubert ] 117a466cc55SCy Schubert ) 118a466cc55SCy Schubert case "$ntp_cv_gcc_Wno_format" in 119*f5f40dd6SCy Schubert no) ntp_cv_gcc_Wno_format_truncation=no 120*f5f40dd6SCy Schubert ;; 121a466cc55SCy Schubert yes) 122*f5f40dd6SCy Schubert CC_NOFORMAT="-Wno-format -Wno-format-security" 123*f5f40dd6SCy Schubert CFLAGS="$SAVED_CFLAGS -Wformat -Wno-format-truncation -Werror" 124*f5f40dd6SCy Schubert AC_CACHE_CHECK( 125*f5f40dd6SCy Schubert [if $CC can handle -Wformat -Wno-format-truncation], 126*f5f40dd6SCy Schubert [ntp_cv_gcc_Wno_format_truncation], 127*f5f40dd6SCy Schubert [AC_COMPILE_IFELSE( 128*f5f40dd6SCy Schubert [AC_LANG_PROGRAM([[]], [[]])], 129*f5f40dd6SCy Schubert [ntp_cv_gcc_Wno_format_truncation=yes], 130*f5f40dd6SCy Schubert [ntp_cv_gcc_Wno_format_truncation=no] 131*f5f40dd6SCy Schubert ) ] 132*f5f40dd6SCy Schubert ) 133*f5f40dd6SCy Schubert # 134*f5f40dd6SCy Schubert # $ntp_cv_gcc_Wno_format_truncation is tested later to add the 135*f5f40dd6SCy Schubert # flag to CFLAGS. 136*f5f40dd6SCy Schubert # 137a466cc55SCy Schubert esac 138a466cc55SCy Schubert 1392b15cb3dSCy Schubert CFLAGS="$SAVED_CFLAGS" 1402b15cb3dSCy Schubert AS_UNSET([SAVED_CFLAGS]) 141*f5f40dd6SCy Schubert 1422b15cb3dSCy Schubert AC_CACHE_CHECK( 1432b15cb3dSCy Schubert [if linker supports omitting unused code and data], 1442b15cb3dSCy Schubert [ntp_cv_gc_sections_runs], 1452b15cb3dSCy Schubert [ 146*f5f40dd6SCy Schubert # NetBSD will link but likely not run with --gc-sections 147*f5f40dd6SCy Schubert # http://bugs.ntp.org/1844 148*f5f40dd6SCy Schubert # http://gnats.netbsd.org/40401 149*f5f40dd6SCy Schubert # --gc-sections causes attempt to load as linux elf, with 150*f5f40dd6SCy Schubert # wrong syscalls in place. Test a little gauntlet of 151*f5f40dd6SCy Schubert # simple stdio read code checking for errors, expecting 152*f5f40dd6SCy Schubert # enough syscall differences that the NetBSD code will 153*f5f40dd6SCy Schubert # fail even with Linux emulation working as designed. 154*f5f40dd6SCy Schubert # A shorter test could be refined by someone with access 155*f5f40dd6SCy Schubert # to a NetBSD host with Linux emulation working. 1562b15cb3dSCy Schubert origCFLAGS="$CFLAGS" 1572b15cb3dSCy Schubert CFLAGS="$CFLAGS -Wl,--gc-sections" 1582b15cb3dSCy Schubert AC_LINK_IFELSE( 1592b15cb3dSCy Schubert [AC_LANG_PROGRAM( 1602b15cb3dSCy Schubert [[ 1612b15cb3dSCy Schubert #include <stdlib.h> 1622b15cb3dSCy Schubert #include <stdio.h> 1632b15cb3dSCy Schubert ]], 1642b15cb3dSCy Schubert [[ 1652b15cb3dSCy Schubert FILE * fpC; 1662b15cb3dSCy Schubert char buf[32]; 1672b15cb3dSCy Schubert size_t cch; 1682b15cb3dSCy Schubert int read_success_once; 1692b15cb3dSCy Schubert 1702b15cb3dSCy Schubert fpC = fopen("conftest.c", "r"); 1712b15cb3dSCy Schubert if (NULL == fpC) 1722b15cb3dSCy Schubert exit(1); 1732b15cb3dSCy Schubert do { 1742b15cb3dSCy Schubert cch = fread(buf, sizeof(buf), 1, fpC); 1752b15cb3dSCy Schubert read_success_once |= (0 != cch); 1762b15cb3dSCy Schubert } while (0 != cch); 1772b15cb3dSCy Schubert if (!read_success_once) 1782b15cb3dSCy Schubert exit(2); 1792b15cb3dSCy Schubert if (!feof(fpC)) 1802b15cb3dSCy Schubert exit(3); 1812b15cb3dSCy Schubert if (0 != fclose(fpC)) 1822b15cb3dSCy Schubert exit(4); 1832b15cb3dSCy Schubert 1842b15cb3dSCy Schubert exit(EXIT_SUCCESS); 1852b15cb3dSCy Schubert ]] 1862b15cb3dSCy Schubert )], 1872b15cb3dSCy Schubert [ 1882b15cb3dSCy Schubert if test "X$cross_compiling" = "Xyes" || grep gc-sections conftest.err ; then 1892b15cb3dSCy Schubert ntp_cv_gc_sections_runs=no 1902b15cb3dSCy Schubert else 1912b15cb3dSCy Schubert ntp_cv_gc_sections_runs=no 1922b15cb3dSCy Schubert ./conftest >/dev/null 2>&1 && ntp_cv_gc_sections_runs=yes 1932b15cb3dSCy Schubert fi 1942b15cb3dSCy Schubert ], 1952b15cb3dSCy Schubert [ntp_cv_gc_sections_runs=no] 1962b15cb3dSCy Schubert ) 1972b15cb3dSCy Schubert CFLAGS="$origCFLAGS" 1982b15cb3dSCy Schubert AS_UNSET([origCFLAGS]) 1992b15cb3dSCy Schubert ] 2002b15cb3dSCy Schubert ) 2012b15cb3dSCy Schubert case "$ntp_cv_gc_sections_runs" in 2022b15cb3dSCy Schubert yes) 2032b15cb3dSCy Schubert LDADD_LIBNTP="-Wl,--gc-sections" 2042b15cb3dSCy Schubert CFLAGS_NTP="$CFLAGS_NTP -ffunction-sections -fdata-sections" 2052b15cb3dSCy Schubert ;; 2062b15cb3dSCy Schubert no) 2072b15cb3dSCy Schubert LDADD_LIBNTP= 2082b15cb3dSCy Schubert ;; 2092b15cb3dSCy Schubert esac 2102b15cb3dSCy Schubert CFLAGS_NTP="$CFLAGS_NTP -Wall" 2112b15cb3dSCy Schubert CFLAGS_NTP="$CFLAGS_NTP -Wcast-align" 2122b15cb3dSCy Schubert CFLAGS_NTP="$CFLAGS_NTP -Wcast-qual" 2132b15cb3dSCy Schubert # CFLAGS_NTP="$CFLAGS_NTP -Wconversion" 2142b15cb3dSCy Schubert # CFLAGS_NTP="$CFLAGS_NTP -Werror" 2152b15cb3dSCy Schubert # CFLAGS_NTP="$CFLAGS_NTP -Wextra" 2162b15cb3dSCy Schubert # CFLAGS_NTP="$CFLAGS_NTP -Wfloat-equal" 2172b15cb3dSCy Schubert CFLAGS_NTP="$CFLAGS_NTP -Wmissing-prototypes" 2182b15cb3dSCy Schubert CFLAGS_NTP="$CFLAGS_NTP -Wpointer-arith" 2192b15cb3dSCy Schubert CFLAGS_NTP="$CFLAGS_NTP -Wshadow" 2202b15cb3dSCy Schubert # CFLAGS_NTP="$CFLAGS_NTP -Wtraditional" 2212b15cb3dSCy Schubert # CFLAGS_NTP="$CFLAGS_NTP -Wwrite-strings" 2222b15cb3dSCy Schubert case "$ntp_cv_gcc_Winit_self" in 2232b15cb3dSCy Schubert yes) 2242b15cb3dSCy Schubert CFLAGS_NTP="$CFLAGS_NTP -Winit-self" 2252b15cb3dSCy Schubert esac 2262b15cb3dSCy Schubert case "$ntp_cv_gcc_Wstrict_overflow" in 2272b15cb3dSCy Schubert yes) 2282b15cb3dSCy Schubert CFLAGS_NTP="$CFLAGS_NTP -Wstrict-overflow" 2292b15cb3dSCy Schubert esac 230*f5f40dd6SCy Schubert case "$ntp_cv_gcc_Wno_format_truncation" in 231*f5f40dd6SCy Schubert yes) 232*f5f40dd6SCy Schubert CFLAGS_NTP="$CFLAGS_NTP -Wno-format-truncation" 233*f5f40dd6SCy Schubert esac 2342b15cb3dSCy Schubert # -W[no-]strict-prototypes might be added by NTP_OPENSSL 2352b15cb3dSCy Schubertesac 2362b15cb3dSCy Schubert 2372b15cb3dSCy SchubertNTP_OS_CFLAGS 2382b15cb3dSCy Schubert 239f0574f5cSXin LIAC_C_BIGENDIAN 240f0574f5cSXin LIAC_C_VOLATILE 241f0574f5cSXin LIAC_PROG_CPP 242f0574f5cSXin LI 2432b15cb3dSCy Schubert])dnl 2442b15cb3dSCy Schubertdnl ====================================================================== 245