1
0
Fork 0
mirror of https://repo.or.cz/socat.git synced 2025-07-15 07:33:25 +00:00

Red Hat issue 1020203: configure checks fail with some compilers

This commit is contained in:
Gerhard Rieger 2014-03-01 15:58:06 +01:00
parent cf39583b25
commit fbb521e45e
15 changed files with 309 additions and 91 deletions

View file

@ -1,4 +1,4 @@
nl source: configure.in
dnl source: configure.in
dnl Copyright Gerhard Rieger
dnl Published under the GNU General Public License V.2, see file COPYING
@ -41,12 +41,16 @@ AC_CHECK_PROG(AR, ar, ar, gar)
# fail
AC_LANG_COMPILER_REQUIRE()
if test "$GCC" = yes; then
if test "$CC" = "gcc"; then
CFLAGS="$CFLAGS -D_GNU_SOURCE -Wall -Wno-parentheses"
ERRONWARN="-Werror -O0"
elif test "$CC" = "clang"; then
CFLAGS="$CFLAGS -D_GNU_SOURCE -Wall -Wno-parentheses"
ERRONWARN="-Werror -O0"
#elif Sun Studio
# ERRONWARN="-errwarn"
else
# Sun Studio?
ERRONWARN="-errwarn"
ERRONWARN=
fi
export CFLAGS
@ -95,6 +99,25 @@ AC_CHECK_FUNC(gethostent, , AC_CHECK_LIB(nsl, gethostent))
AC_CHECK_FUNC(setsockopt, , AC_CHECK_LIB(socket, setsockopt))
dnl Check for function prototype and in lib
dnl arg1: function name
dnl arg2: required include files beyond sysincludes.h
define(AC_CHECK_PROTOTYPE_LIB,[
AC_MSG_CHECKING(for $1 prototype)
AC_CACHE_VAL(sc_cv_have_prototype_lib_$1,
[CFLAGS1="$CFLAGS"; CFLAGS="$ERRONWARN -Wall $CFLAGS1";
AC_TRY_LINK([#include "sysincludes.h"
$2],[return(&$1==(void *)&$1);],
[sc_cv_have_prototype_lib_$1=yes],
[sc_cv_have_prototype_lib_$1=no]);
CFLAGS="$CFLAGS1"])
if test $sc_cv_have_prototype_lib_$1 = yes; then
AC_DEFINE(HAVE_PROTOTYPE_LIB_$1)
fi
AC_MSG_RESULT($sc_cv_have_prototype_lib_$1)
])
dnl Check for hstrerror prototype
AC_MSG_CHECKING(for hstrerror prototype)
AC_CACHE_VAL(sc_cv_have_prototype_hstrerror,
@ -560,7 +583,7 @@ if test -n "$WITH_FIPS"; then
fi
if test -n "$WITH_FIPS"; then
AC_MSG_NOTICE(checking for components of OpenSSL FIPS)
AC_MSG_CHECKING(for components of OpenSSL FIPS)
# first, we need to find the include file <openssl/fips.h>
AC_CACHE_VAL(sc_cv_have_openssl_fips_h,
[AC_TRY_COMPILE([#define OPENSSL_FIPS
@ -707,12 +730,26 @@ AC_PROG_GCC_TRADITIONAL
AC_FUNC_MEMCMP
AC_TYPE_SIGNAL
AC_FUNC_STRFTIME
AC_CHECK_FUNCS(putenv select poll socket strdup strerror strstr strtod strtol)
AC_CHECK_FUNCS(putenv select poll socket strtod strtol)
AC_CHECK_FUNCS(strtoul uname getpgid getsid getaddrinfo)
AC_CHECK_FUNCS(getipnodebyname setgroups inet_aton memrchr)
AC_CHECK_FUNCS(if_indextoname)
AC_CHECK_FUNCS(setgroups inet_aton)
AC_CHECK_FUNCS()
AC_CHECK_FUNCS(grantpt unlockpt ptsname)
AC_CHECK_FUNCS(grantpt unlockpt)
# GR AC_CHECK_FUNCS only checks linking, not prototype. This may lead to implicit
# function declarations and to SIGSEGV on systems with 32bit int and 64bit pointer
###################################
# check for prototype and existence of functions that return a pointer
# defines in config.h: HAVE_PROTOTYPE_LIB_$1
AC_CHECK_PROTOTYPE_LIB(strdup)
AC_CHECK_PROTOTYPE_LIB(strerror)
AC_CHECK_PROTOTYPE_LIB(strstr)
AC_CHECK_PROTOTYPE_LIB(getipnodebyname)
AC_CHECK_PROTOTYPE_LIB(memrchr)
AC_CHECK_PROTOTYPE_LIB(if_indextoname)
AC_CHECK_PROTOTYPE_LIB(ptsname)
AC_MSG_CHECKING(for long long)
@ -905,10 +942,11 @@ AC_CACHE_VAL(ac_cv_ispeed_offset,
[conftestspeedoff="conftestspeedoff.out"
AC_TRY_RUN([
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <termios.h>
#include <string.h>
main(){
int main(){
struct termios t;
FILE *f;
if ((f=fopen("$conftestspeedoff","w"))==NULL){
@ -1202,6 +1240,18 @@ if test $sc_cv_struct_in_pktinfo = 'yes'; then
AC_MSG_RESULT($sc_cv_pktinfo_ipi_spec_dst)
fi
dnl check for struct in6_pktinfo
AC_MSG_CHECKING(for struct in6_pktinfo)
AC_CACHE_VAL(sc_cv_struct_in6_pktinfo,
[AC_TRY_COMPILE([#include "sysincludes.h"],
[struct in6_pktinfo s;],
[sc_cv_struct_in6_pktinfo=yes],
[sc_cv_struct_in6_pktinfo=no])])
if test $sc_cv_struct_in6_pktinfo = yes; then
AC_DEFINE(HAVE_STRUCT_IN6_PKTINFO)
fi
AC_MSG_RESULT($sc_cv_struct_in6_pktinfo)
dnl check for ip_hl in struct ip
AC_MSG_CHECKING(for struct ip.ip_hl)
AC_CACHE_VAL(sc_cv_struct_ip_ip_hl,
@ -1304,7 +1354,9 @@ AC_MSG_RESULT($ac_cv_have_c99_snprintf)
AC_MSG_CHECKING(if printf has Z modifier)
AC_CACHE_VAL(ac_cv_have_z_modifier,
if test "$cc" = gcc; then
[AC_TRY_RUN([
#include <stdlib.h>
#include <stdio.h>
int main(void){
char s[16];
@ -1313,7 +1365,10 @@ exit(strcmp(s,"1"));
}],
[ac_cv_have_z_modifier=yes],
[ac_cv_have_z_modifier=no],
[ac_cv_have_z_modifier=no])])
[ac_cv_have_z_modifier=no])]
else ac_cv_have_z_modifier=no
fi
)
if test $ac_cv_have_z_modifier = yes; then
AC_DEFINE(HAVE_FORMAT_Z)
fi
@ -1329,10 +1384,11 @@ AC_CACHE_CHECK(shift offset of $1, $2,
conftestoffset="conftestoffset.out"
AC_TRY_RUN([
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <termios.h>
#include <string.h>
main(){
int main(){
unsigned int i,n=$1;
FILE *f;
if ((f=fopen("$conftestoffset","w"))==NULL){
@ -1365,6 +1421,116 @@ AC_SHIFT_OFFSET(TABDLY, sc_cv_sys_tabdly_shift)
AC_SHIFT_OFFSET(CSIZE, sc_cv_sys_csize_shift)
dnl Find what physical type (basic C type) is equivalent to the given type.
dnl If possible we try to compile simple test code and get no warning only with
dnl the matching type.
dnl If this method does not seem to work we run test programs that print the
dnl length and signedness of the type.
dnl do we have a -Werror option?
dnl Does the test code compile with -Werror when types fit?
CHANCE_TO_TYPECHECK=1
CFLAGS1="$CFLAGS"; CFLAGS="$ERRONWARN $(echo "$CFLAGS1" | sed -e 's@-Wall@@g')"
AC_TRY_COMPILE([#include <stdlib.h>],[int u; int v; exit(&u==&v);],,CHANCE_TO_TYPECHECK=0)
CFLAGS="$CFLAGS1"
dnl Does the test code compile without -Werror when types do not fit?
if test "$CHANCE_TO_TYPECHECK" -ne 0; then
AC_TRY_COMPILE([#include <stdlib.h>],[int u; unsigned int v; exit(&u==&v);],,CHANCE_TO_TYPECHECK=0)
fi
dnl Does the test code fail to compile with -Werror when types do not fit?
if test "$CHANCE_TO_TYPECHECK" -ne 0; then
CFLAGS1="$CFLAGS"; CFLAGS="$ERRONWARN $(echo "$CFLAGS1" | sed -e 's@-Wall@@g')"
AC_TRY_COMPILE([#include <stdlib.h>],[int u; unsigned int v; exit(&u==&v);],CHANCE_TO_TYPECHECK=0,)
CFLAGS="$CFLAGS1"
fi
if test "$CHANCE_TO_TYPECHECK" -ne 0; then
AC_MSG_NOTICE(using compile -Werror method to find basic types)
else
AC_MSG_NOTICE(using code run method to find basic types)
fi
dnl see AC_BASIC_TYPE
define(AC_BASIC_TYPE_GCC,[
AC_CACHE_CHECK(for equivalent simple type of $2, $4,
[CFLAGS1="$CFLAGS"; CFLAGS="$ERRONWARN $(echo "$CFLAGS1" | sed -e 's@-Wall@@g')"
dnl echo "echo: trying short for $2" >&2
AC_TRY_COMPILE([$1],[$2 u; short v; return(&u==&v);],
[$4="1 /* short */"],
[AC_TRY_COMPILE([$1],[$2 u; unsigned short v; return(&u==&v);],
[$4="2 /* unsigned short */"],
[AC_TRY_COMPILE([$1],[$2 u; int v; return(&u==&v);],
[$4="3 /* int */"],
[AC_TRY_COMPILE([$1],[$2 u; unsigned int v; return(&u==&v);],
[$4="4 /* unsigned int */"],
[AC_TRY_COMPILE([$1],[$2 u; long v; return(&u==&v);],
[$4="5 /* long */"],
[AC_TRY_COMPILE([$1],[$2 u; unsigned long v; return(&u==&v);],
[$4="6 /* unsigned long */"],
[AC_TRY_COMPILE([$1],[$2 u; long long v; return(&u==&v);],
[$4="7 /* long long */"],
[AC_TRY_COMPILE([$1],[$2 u; unsigned long long v; return(&u==&v);],
[$4="8 /* unsigned long long */"],
[$4="0 /* unknown, taking default */"
]) ]) ]) ]) ]) ]) ]) ])
CFLAGS="$CFLAGS1" ])
AC_DEFINE_UNQUOTED($3, ${$4})
])
dnl see AC_BASIC_TYPE
define(AC_BASIC_TYPE_OTHER,[
AC_CACHE_CHECK(for equivalent simple type of $2, $4,
[AC_TRY_RUN([
$1
int main() { return!(sizeof($2)==sizeof(short));}],
# same length as short
AC_TRY_RUN([
$1
int main() { $2 x=-1; return !(x<0);}],
[$4="1 /* short */"],
[$4="2 /* unsigned short */"]),
# length differs from short, try others
AC_TRY_RUN([
$1
int main() { return!(sizeof($2)==sizeof(int));}],
# same length as int
AC_TRY_RUN([
$1
int main() { $2 x=-1; return !(x<0);}],
[$4="3 /* int */"],
[$4="4 /* unsigned int */"]),
# length differs from int, try others
AC_TRY_RUN([
$1
int main() { return !(sizeof($2)==sizeof(long));}],
# same length as long
AC_TRY_RUN([
$1
int main() { $2 x=-1; return !(x<0);}],
[$4="5 /* long */"],
[$4="6 /* unsigned long */"] ),
# length differs from long, try others
AC_TRY_RUN([
$1
int main() { return !(sizeof($2)==sizeof(long long));}],
# same length as long long
AC_TRY_RUN([
$1
int main() { $2 x=-1; return !(x<0);}],
[$4="7 /* long long */"],
[$4="8 /* unsigned long long */"] ),
[$4="0 /* unknown */"]
)
)
)
)
])
AC_DEFINE_UNQUOTED($3, ${$4})
])
dnl find what physical type (basic C type) is equivalent to the given type.
dnl arg1: include file(s)
dnl arg2: type name
@ -1373,28 +1539,91 @@ dnl arg4: cache variable (might be constructed automatically)
dnl output values: 1..short, 2..unsigned short, 3..int, 4..u-int,
dnl 5..long, 6..u-long; others not yet supported
define(AC_BASIC_TYPE,[
AC_CACHE_CHECK(for equivalent simple type of $2, $4,
if test "$CHANCE_TO_TYPECHECK" -ne 0; then
AC_BASIC_TYPE_GCC([$1],[$2],[$3],[$4])
else
AC_BASIC_TYPE_OTHER([$1],[$2],[$3],[$4])
fi
])
dnl See AC_TYPEOF_COMPONENT
dnl This version is for compilers with -Werror or so: gcc, clang, Sun Studio?
define(AC_TYPEOF_COMPONENT_GCC,[
AC_CACHE_CHECK(for basic type of $2.$3, $5,
[CFLAGS1="$CFLAGS"; CFLAGS="$ERRONWARN $(echo "$CFLAGS1" | sed -e 's@-Wall@@g')"
AC_TRY_COMPILE([$1],[$2 u; short v; &u==&v;],
[$4="1 /* short */"],
[AC_TRY_COMPILE([$1],[$2 u; unsigned short v; &u==&v;],
[$4="2 /* unsigned short */"],
[AC_TRY_COMPILE([$1],[$2 u; int v; &u==&v;],
[$4="3 /* int */"],
[AC_TRY_COMPILE([$1],[$2 u; unsigned int v; &u==&v;],
[$4="4 /* unsigned int */"],
[AC_TRY_COMPILE([$1],[$2 u; long v; &u==&v;],
[$4="5 /* long */"],
[AC_TRY_COMPILE([$1],[$2 u; unsigned long v; &u==&v;],
[$4="6 /* unsigned long */"],
[AC_TRY_COMPILE([$1],[$2 u; long long v; &u==&v;],
[$4="7 /* long long */"],
[AC_TRY_COMPILE([$1],[$2 u; unsigned long long v; &u==&v;],
[$4="8 /* unsigned long long */"],
[$4="0 /* unknown, taking default */"
AC_TRY_COMPILE([$1],[$2 u;short v; return(&u.$3==&v);],
[$5="1 /* short */"],
[AC_TRY_COMPILE([$1],[$2 u; unsigned short v; return(&u.$3==&v);],
[$5="2 /* unsigned short */"],
[AC_TRY_COMPILE([$1],[$2 u; int v; return(&u.$3==&v);],
[$5="3 /* int */"],
[AC_TRY_COMPILE([$1],[$2 u; unsigned int v; return(&u.$3==&v);],
[$5="4 /* unsigned int */"],
[AC_TRY_COMPILE([$1],[$2 u; long v; return(&u.$3==&v);],
[$5="5 /* long */"],
[AC_TRY_COMPILE([$1],[$2 u; unsigned long v; return(&u.$3==&v);],
[$5="6 /* unsigned long */"],
[AC_TRY_COMPILE([$1],[$2 u; long long v; return(&u.$3==&v);],
[$5="7 /* long long */"],
[AC_TRY_COMPILE([$1],[$2 u; unsigned long long v; return(&u.$3==&v);],
[$5="8 /* unsigned long long */"],
[$5="0 /* unknown, taking default */"
]) ]) ]) ]) ]) ]) ]) ])
CFLAGS="$CFLAGS1" ])
AC_DEFINE_UNQUOTED($3, ${$4})
AC_DEFINE_UNQUOTED($4, ${$5})
])
dnl See AC_TYPEOF_COMPONENT
dnl This version is for compilers with no -Werror or so
define(AC_TYPEOF_COMPONENT_OTHER,[
AC_CACHE_CHECK(for basic type of $2.$3, $5,
[AC_TRY_RUN([
$1
int main() { $2 x; return!(sizeof(x.$3)==sizeof(short));}],
# same length as short
AC_TRY_RUN([
$1
int main() { $2 x; x.$3=-1; return !(x.$3<0);}],
[$5="1 /* short */"],
[$5="2 /* unsigned short */"]),
# length differs from short, try others
AC_TRY_RUN([
$1
int main() { $2 x; return!(sizeof(x.$3)==sizeof(int));}],
# same length as int
AC_TRY_RUN([
$1
int main() { $2 x; x.$3=-1; return !(x.$3<0);}],
[$5="3 /* int */"],
[$5="4 /* unsigned int */"]),
# length differs from int, try others
AC_TRY_RUN([
$1
int main() { $2 x; return !(sizeof(x.$3)==sizeof(long));}],
# same length as long
AC_TRY_RUN([
$1
int main() { $2 x; x.$3=-1; return !(x.$3<0);}],
[$5="5 /* long */"],
[$5="6 /* unsigned long */"] ),
# length differs from long, try others
AC_TRY_RUN([
$1
int main() { $2 x; return !(sizeof(x.$3)==sizeof(long long));}],
# same length as long long
AC_TRY_RUN([
$1
int main() { x $2; x.$3=-1; return !(x.$3<0);}],
[$5="7 /* long long */"],
[$5="8 /* unsigned long long */"] ),
[$5="0 /* unknown */"]
)
)
)
)
])
AC_DEFINE_UNQUOTED($4, ${$5})
])
dnl find what physical type (basic C type) describes the given struct or union
@ -1405,28 +1634,11 @@ dnl arg3: variable or component (e.g., "st_ino")
dnl arg4: output variable, values see AC_BASIC_TYPE
dnl arg5: cache variable (might be constructed automatically)
define(AC_TYPEOF_COMPONENT,[
AC_CACHE_CHECK(for basic type of $2.$3, $5,
[CFLAGS1="$CFLAGS"; CFLAGS="$ERRONWARN $(echo "$CFLAGS1" | sed -e 's@-Wall@@g')"
AC_TRY_COMPILE([$1],[$2 u;short v; &u.$3==&v;],
[$5="1 /* short */"],
[AC_TRY_COMPILE([$1],[$2 u; unsigned short v; &u.$3==&v;],
[$5="2 /* unsigned short */"],
[AC_TRY_COMPILE([$1],[$2 u; int v; &u.$3==&v;],
[$5="3 /* int */"],
[AC_TRY_COMPILE([$1],[$2 u; unsigned int v; &u.$3==&v;],
[$5="4 /* unsigned int */"],
[AC_TRY_COMPILE([$1],[$2 u; long v; &u.$3==&v;],
[$5="5 /* long */"],
[AC_TRY_COMPILE([$1],[$2 u; unsigned long v; &u.$3==&v;],
[$5="6 /* unsigned long */"],
[AC_TRY_COMPILE([$1],[$2 u; long long v; &u.$3==&v;],
[$5="7 /* long long */"],
[AC_TRY_COMPILE([$1],[$2 u; unsigned long long v; &u.$3==&v;],
[$5="8 /* unsigned long long */"],
[$5="0 /* unknown, taking default */"
]) ]) ]) ]) ]) ]) ]) ])
CFLAGS="$CFLAGS1" ])
AC_DEFINE_UNQUOTED($4, ${$5})
if test "$CHANCE_TO_TYPECHECK" -ne 0; then
AC_TYPEOF_COMPONENT_GCC([$1],[$2],[$3],[$4],[$5])
else
AC_TYPEOF_COMPONENT_OTHER([$1],[$2],[$3],[$4],[$5])
fi
])
AC_BASIC_TYPE([#include <stdlib.h>], size_t, HAVE_BASIC_SIZE_T, sc_cv_type_sizet_basic)
@ -1528,7 +1740,7 @@ AC_ARG_ENABLE(libwrap, [ --disable-libwrap disable libwrap support],
#
# check if we find the components of libwrap ("tcpd" "tcpwrappers")
if test -n "$WITH_LIBWRAP"; then
AC_MSG_NOTICE(checking for components of libwrap)
AC_MSG_CHECKING(for components of libwrap)
# first, we need to find the include file <tcpd.h>
AC_CACHE_VAL(sc_cv_have_tcpd_h,
[AC_TRY_COMPILE([#include <sys/types.h>
@ -1596,7 +1808,7 @@ fi
# check of hosts_allow_table
if test -n "$WITH_LIBWRAP"; then
AC_MSG_CHECKING(checking for hosts_allow_table)
AC_MSG_CHECKING(for hosts_allow_table)
AC_CACHE_VAL(sc_cv_have_hosts_allow_table,
[AC_TRY_COMPILE([#include <sys/types.h>
#include <tcpd.h>],[hosts_allow_table="";],