Fix configure check for veracity of compiler error return codes.

There were two problems before that this fixes.  One was that the
check for the compiler error return code preceded the determination
of the compiler and its options.  The other was that the checks
for compiler and library characteristics could be fooled if the
error options were set to reject K&R-style C.  configure now aborts
if the compiler produces a hard error on K&R-style C.

In addition, aborts of configure are now consistent, and remove
any temporary files.
This commit is contained in:
Mark Adler 2012-06-09 22:42:24 -07:00
parent 977e108047
commit bfac156463

143
configure vendored
View File

@ -77,6 +77,19 @@ old_cflags="$CFLAGS"
OBJC='$(OBJZ) $(OBJG)'
PIC_OBJC='$(PIC_OBJZ) $(PIC_OBJG)'
# leave this script, optionally in a bad way
leave()
{
if test "$*" != "0"; then
echo "** $0 aborting." | tee -a configure.log
fi
rm -f $test.[co] $test $test$shared_ext $test.gcno ./--version
echo -------------------- >> configure.log
echo >> configure.log
echo >> configure.log
exit $1
}
# process command line options
while test $# -ge 1
do
@ -106,13 +119,17 @@ case "$1" in
-a*=* | --archs=*) ARCHS=`echo $1 | sed 's/.*=//'`; shift ;;
--sysconfdir=*) echo "ignored option: --sysconfdir" | tee -a configure.log; shift ;;
--localstatedir=*) echo "ignored option: --localstatedir" | tee -a configure.log; shift ;;
*) echo "unknown option: $1"; echo "$0 --help for help" | tee -a configure.log; exit 1 ;;
*)
echo "unknown option: $1" | tee -a configure.log
echo "$0 --help for help" | tee -a configure.log
leave 1;;
esac
done
# define functions for testing compiler and library characteristics and logging the results
# temporary file name
test=ztest$$
# put arguments in log, also put test file in log if used in arguments
show()
{
case "$*" in
@ -124,43 +141,6 @@ show()
echo $* >> configure.log
}
cat > $test.c <<EOF
#error error
EOF
if ($CC -c $CFLAGS $test.c) 2>/dev/null; then
try()
{
show $*
test "`( $* ) 2>&1 | tee -a configure.log`" = ""
}
echo - using any output from compiler to indicate an error >> configure.log
else
try()
{
show $*
( $* ) >> configure.log 2>&1
ret=$?
if test $ret -ne 0; then
echo "(exit code "$ret")" >> configure.log
fi
return $ret
}
fi
tryboth()
{
show $*
got=`( $* ) 2>&1`
ret=$?
printf %s "$got" >> configure.log
if test $ret -ne 0; then
return $ret
fi
test "$got" = ""
}
echo >> configure.log
# check for gcc vs. cc and set compile and link flags based on the system identified by uname
cat > $test.c <<EOF
extern int getchar();
@ -179,8 +159,8 @@ case `$cc -v 2>&1` in
*gcc*) gcc=1 ;;
esac
show $cc -c $cflags $test.c
if test "$gcc" -eq 1 && ($cc -c $cflags $test.c) >> configure.log 2>&1; then
show $cc -c $test.c
if test "$gcc" -eq 1 && ($cc -c $test.c) >> configure.log 2>&1; then
echo ... using gcc >> configure.log
CC="$cc"
CFLAGS="${CFLAGS--O3} ${ARCHS}"
@ -208,7 +188,7 @@ if test "$gcc" -eq 1 && ($cc -c $cflags $test.c) >> configure.log 2>&1; then
# temporary bypass
rm -f $test.[co] $test $test$shared_ext
echo "Please use win32/Makefile.gcc instead." | tee -a configure.log
exit 1
leave 1
LDSHARED=${LDSHARED-"$cc -shared"}
LDSHAREDLIBC=""
EXE='.exe' ;;
@ -338,7 +318,59 @@ SHAREDLIBM=${SHAREDLIBM-"libz$shared_ext.$VER1"}
echo >> configure.log
# define functions for testing compiler and library characteristics and logging the results
cat > $test.c <<EOF
#error error
EOF
if ($CC -c $CFLAGS $test.c) 2>/dev/null; then
try()
{
show $*
test "`( $* ) 2>&1 | tee -a configure.log`" = ""
}
echo - using any output from compiler to indicate an error >> configure.log
else
try()
{
show $*
( $* ) >> configure.log 2>&1
ret=$?
if test $ret -ne 0; then
echo "(exit code "$ret")" >> configure.log
fi
return $ret
}
fi
tryboth()
{
show $*
got=`( $* ) 2>&1`
ret=$?
printf %s "$got" >> configure.log
if test $ret -ne 0; then
return $ret
fi
test "$got" = ""
}
cat > $test.c << EOF
int foo() { return 0; }
EOF
echo "Checking for obsessive-compulsive compiler options..." >> configure.log
if ! try $CC -c $CFLAGS $test.c; then
echo "Compiler error reporting is too harsh for $0 (perhaps remove -Werror)." | tee -a configure.log
leave 1
fi
echo >> configure.log
# see if shared library build supported
cat > $test.c <<EOF
extern int getchar();
int hello() {return getchar();}
EOF
if test $shared -eq 1; then
echo Checking for shared library support... | tee -a configure.log
# we must test in two steps (cc then ld), required at least on SunOS 4.x
@ -366,8 +398,6 @@ else
TEST="all teststatic testshared"
fi
echo >> configure.log
# check for underscores in external names for use by assembler code
CPP=${CPP-"$CC -E"}
case $CFLAGS in
@ -709,14 +739,14 @@ cat > $test.c <<EOF
#include <stdio.h>
#define is32(n,t) for(n=1,k=0;n;n<<=1,k++);if(k==32){puts(t);return 0;}
int main() {
int k;
unsigned i;
unsigned long l;
unsigned short s;
is32(i, "unsigned")
is32(l, "unsigned long")
is32(s, "unsigned short")
return 1;
int k;
unsigned i;
unsigned long l;
unsigned short s;
is32(i, "unsigned")
is32(l, "unsigned long")
is32(s, "unsigned short")
return 1;
}
EOF
Z_U4=""
@ -728,9 +758,6 @@ else
echo "Looking for a four-byte integer type... Not found." | tee -a configure.log
fi
# clean up files produced by running the compiler and linker
rm -f $test.[co] $test $test$shared_ext $test.gcno ./--version
# show the results in the log
echo >> configure.log
echo ALL = $ALL >> configure.log
@ -762,9 +789,6 @@ echo mandir = $mandir >> configure.log
echo prefix = $prefix >> configure.log
echo sharedlibdir = $sharedlibdir >> configure.log
echo uname = $uname >> configure.log
echo -------------------- >> configure.log
echo >> configure.log
echo >> configure.log
# udpate Makefile with the configure results
sed < Makefile.in "
@ -820,3 +844,6 @@ sed < zlib.pc.in "
" | sed -e "
s/\@VERSION\@/$VER/g;
" > zlib.pc
# done
leave 0