]> git.lizzy.rs Git - zlib.git/blobdiff - configure
CMake build fixes
[zlib.git] / configure
index 6b7224b42c1bc5c00c158e6e9514388d2983a3fa..52ff4a04ea899896c5ae2b69db737cc30d3a2606 100755 (executable)
--- a/configure
+++ b/configure
 # If you have problems, try without defining CC and CFLAGS before reporting
 # an error.
 
+# start off configure.log
 echo -------------------- >> configure.log
 echo $0 $* >> configure.log
 date >> configure.log
 
+# get source directory
+SRCDIR=`dirname $0`
+if test $SRCDIR = "."; then
+    ZINC=""
+    ZINCOUT="-I."
+    SRCDIR=""
+else
+    ZINC='-include zconf.h'
+    ZINCOUT='-I. -I$(SRCDIR)'
+    SRCDIR="$SRCDIR/"
+fi
+
+# set command prefix for cross-compilation
 if [ -n "${CHOST}" ]; then
     uname="`echo "${CHOST}" | sed -e 's/^[^-]*-\([^-]*\)$/\1/' -e 's/^[^-]*-[^-]*-\([^-]*\)$/\1/' -e 's/^[^-]*-[^-]*-\([^-]*\)-.*$/\1/'`"
     CROSS_PREFIX="${CHOST}-"
 fi
 
+# destination name for static library
 STATICLIB=libz.a
-VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`
-VER3=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\\.[0-9]*\).*/\1/p' < zlib.h`
-VER2=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\)\\..*/\1/p' < zlib.h`
-VER1=`sed -n -e '/VERSION "/s/.*"\([0-9]*\)\\..*/\1/p' < zlib.h`
+
+# extract zlib version numbers from zlib.h
+VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < ${SRCDIR}zlib.h`
+VER3=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\\.[0-9]*\).*/\1/p' < ${SRCDIR}zlib.h`
+VER2=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\)\\..*/\1/p' < ${SRCDIR}zlib.h`
+VER1=`sed -n -e '/VERSION "/s/.*"\([0-9]*\)\\..*/\1/p' < ${SRCDIR}zlib.h`
+
+# establish commands for library building
 if "${CROSS_PREFIX}ar" --version >/dev/null 2>/dev/null || test $? -lt 126; then
     AR=${AR-"${CROSS_PREFIX}ar"}
     test -n "${CROSS_PREFIX}" && echo Using ${AR} | tee -a configure.log
@@ -47,6 +66,8 @@ if "${CROSS_PREFIX}nm" --version >/dev/null 2>/dev/null || test $? -lt 126; then
 else
     NM=${NM-"nm"}
 fi
+
+# set defaults before processing command line options
 LDCONFIG=${LDCONFIG-"ldconfig"}
 LDSHAREDLIBC="${LDSHAREDLIBC--lc}"
 ARCHS=
@@ -61,19 +82,37 @@ shared=1
 solo=0
 cover=0
 zprefix=0
+zconst=0
 build64=0
 gcc=0
+warn=0
+debug=0
+sanitize=0
 old_cc="$CC"
 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
 case "$1" in
     -h* | --help)
       echo 'usage:' | tee -a configure.log
-      echo '  configure [--zprefix] [--prefix=PREFIX]  [--eprefix=EXPREFIX]' | tee -a configure.log
+      echo '  configure [--const] [--zprefix] [--prefix=PREFIX]  [--eprefix=EXPREFIX]' | tee -a configure.log
       echo '    [--static] [--64] [--libdir=LIBDIR] [--sharedlibdir=LIBDIR]' | tee -a configure.log
       echo '    [--includedir=INCLUDEDIR] [--archs="-arch i386 -arch x86_64"]' | tee -a configure.log
         exit 0 ;;
@@ -96,12 +135,21 @@ 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 ;;
+    -c* | --const) zconst=1; shift ;;
+    -w* | --warn) warn=1; shift ;;
+    -d* | --debug) debug=1; shift ;;
+    --sanitize) sanitize=1; shift ;;
+    *)
+      echo "unknown option: $1" | tee -a configure.log
+      echo "$0 --help for help" | tee -a configure.log
+      leave 1;;
     esac
 done
 
+# temporary file name
 test=ztest$$
 
+# put arguments in log, also put test file in log if used in arguments
 show()
 {
   case "$*" in
@@ -113,81 +161,67 @@ 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();
 int hello() {return getchar();}
 EOF
 
-test -z "$CC" && echo Checking for ${CROSS_PREFIX}gcc... | tee -a configure.log
-cc=${CC-${CROSS_PREFIX}gcc}
+if test -z "$CC"; then
+  echo Checking for ${CROSS_PREFIX}gcc... | tee -a configure.log
+  if ${CROSS_PREFIX}gcc -v >/dev/null 2>&1; then
+    cc=${CROSS_PREFIX}gcc
+  else
+    cc=${CROSS_PREFIX}cc
+  fi
+fi
 cflags=${CFLAGS-"-O3"}
 # to force the asm version use: CFLAGS="-O3 -DASMV" ./configure
 case "$cc" in
   *gcc*) gcc=1 ;;
+  *clang*) gcc=1 ;;
 esac
 case `$cc -v 2>&1` in
   *gcc*) gcc=1 ;;
+  *clang*) 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}"
+  CFLAGS="${CFLAGS--O3}"
   SFLAGS="${CFLAGS--O3} -fPIC"
-  LDFLAGS="${LDFLAGS} ${ARCHS}"
+  if test "$ARCHS"; then
+    CFLAGS="${CFLAGS} ${ARCHS}"
+    LDFLAGS="${LDFLAGS} ${ARCHS}"
+  fi
   if test $build64 -eq 1; then
     CFLAGS="${CFLAGS} -m64"
     SFLAGS="${SFLAGS} -m64"
   fi
-  if test "${ZLIBGCCWARN}" = "YES"; then
-    CFLAGS="${CFLAGS} -Wall -Wextra -pedantic"
+  if test "$warn" -eq 1; then
+    if test "$zconst" -eq 1; then
+      CFLAGS="${CFLAGS} -Wall -Wextra -Wcast-qual -pedantic -DZLIB_CONST"
+    else
+      CFLAGS="${CFLAGS} -Wall -Wextra -pedantic"
+    fi
+  fi
+  if test $sanitize -eq 1; then
+    CFLAGS="${CFLAGS} -fsanitize=address"
+  fi
+  if test $debug -eq 1; then
+    CFLAGS="${CFLAGS} -DZLIB_DEBUG"
+    SFLAGS="${SFLAGS} -DZLIB_DEBUG"
   fi
   if test -z "$uname"; then
     uname=`(uname -s || echo unknown) 2>/dev/null`
   fi
   case "$uname" in
   Linux* | linux* | GNU | GNU/* | solaris*)
-        LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map"} ;;
+        LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,${SRCDIR}zlib.map"} ;;
   *BSD | *bsd* | DragonFly)
-        LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map"}
+        LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,${SRCDIR}zlib.map"}
         LDCONFIG="ldconfig -m" ;;
   CYGWIN* | Cygwin* | cygwin* | OS/2*)
         EXE='.exe' ;;
@@ -195,7 +229,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' ;;
@@ -218,7 +252,11 @@ if test "$gcc" -eq 1 && ($cc -c $cflags $test.c) >> configure.log 2>&1; then
              SHAREDLIBV=libz.$VER$shared_ext
              SHAREDLIBM=libz.$VER1$shared_ext
              LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBM -compatibility_version $VER1 -current_version $VER3"}
-             AR="libtool"
+             if libtool -V 2>&1 | grep Apple > /dev/null; then
+                 AR="libtool"
+             else
+                 AR="/usr/bin/libtool"
+             fi
              ARFLAGS="-o" ;;
   *)             LDSHARED=${LDSHARED-"$cc -shared"} ;;
   esac
@@ -263,15 +301,31 @@ else
              CFLAGS=${CFLAGS-"-O3"}
              LDSHARED=${LDSHARED-"cc -dy -KPIC -G"} ;;
   SunOS\ 5* | solaris*)
-         LDSHARED=${LDSHARED-"cc -G"}
-         case `(uname -m || echo unknown) 2>/dev/null` in
-         i86*)
-             SFLAGS=${CFLAGS-"-xpentium -fast -KPIC -R."}
-             CFLAGS=${CFLAGS-"-xpentium -fast"} ;;
-         *)
-             SFLAGS=${CFLAGS-"-fast -xcg92 -KPIC -R."}
-             CFLAGS=${CFLAGS-"-fast -xcg92"} ;;
-         esac ;;
+         LDSHARED=${LDSHARED-"cc -G -h libz$shared_ext.$VER1"}
+         SFLAGS=${CFLAGS-"-fast -KPIC"}
+         CFLAGS=${CFLAGS-"-fast"}
+         if test $build64 -eq 1; then
+             # old versions of SunPRO/Workshop/Studio don't support -m64,
+             # but newer ones do.  Check for it.
+             flag64=`$CC -flags | egrep -- '^-m64'`
+             if test x"$flag64" != x"" ; then
+                 CFLAGS="${CFLAGS} -m64"
+                 SFLAGS="${SFLAGS} -m64"
+             else
+                 case `(uname -m || echo unknown) 2>/dev/null` in
+                   i86*)
+                     SFLAGS="$SFLAGS -xarch=amd64"
+                     CFLAGS="$CFLAGS -xarch=amd64" ;;
+                   *)
+                     SFLAGS="$SFLAGS -xarch=v9"
+                     CFLAGS="$CFLAGS -xarch=v9" ;;
+                 esac
+             fi
+         fi
+         if test -n "$ZINC"; then
+             ZINC='-I- -I. -I$(SRCDIR)'
+         fi
+         ;;
   SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"}
              CFLAGS=${CFLAGS-"-O2"}
              LDSHARED=${LDSHARED-"ld"} ;;
@@ -301,12 +355,74 @@ else
   esac
 fi
 
+# destination names for shared library if not defined above
 SHAREDLIB=${SHAREDLIB-"libz$shared_ext"}
 SHAREDLIBV=${SHAREDLIBV-"libz$shared_ext.$VER"}
 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 $*
+    got=`( $* ) 2>&1`
+    ret=$?
+    if test "$got" != ""; then
+      printf "%s\n" "$got" >> configure.log
+    fi
+    if test $ret -ne 0; then
+      echo "(exit code "$ret")" >> configure.log
+    fi
+    return $ret
+  }
+fi
+
+tryboth()
+{
+  show $*
+  got=`( $* ) 2>&1`
+  ret=$?
+  if test "$got" != ""; then
+    printf "%s\n" "$got" >> configure.log
+  fi
+  if test $ret -ne 0; then
+    echo "(exit code "$ret")" >> configure.log
+    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
+  :
+else
+  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
@@ -334,6 +450,7 @@ else
   TEST="all teststatic testshared"
 fi
 
+# check for underscores in external names for use by assembler code
 CPP=${CPP-"$CC -E"}
 case $CFLAGS in
   *ASMV*)
@@ -349,6 +466,56 @@ esac
 
 echo >> configure.log
 
+# check for size_t
+cat > $test.c <<EOF
+#include <stdio.h>
+#include <stdlib.h>
+size_t dummy = 0;
+EOF
+if try $CC -c $CFLAGS $test.c; then
+  echo "Checking for size_t... Yes." | tee -a configure.log
+else
+  echo "Checking for size_t... No." | tee -a configure.log
+  # find a size_t integer type
+  # check for long long
+  cat > $test.c << EOF
+long long dummy = 0;
+EOF
+  if try $CC -c $CFLAGS $test.c; then
+    echo "Checking for long long... Yes." | tee -a configure.log
+    cat > $test.c <<EOF
+#include <stdio.h>
+int main(void) {
+    if (sizeof(void *) <= sizeof(int)) puts("int");
+    else if (sizeof(void *) <= sizeof(long)) puts("long");
+    else puts("z_longlong");
+    return 0;
+}
+EOF
+  else
+    echo "Checking for long long... No." | tee -a configure.log
+    cat > $test.c <<EOF
+#include <stdio.h>
+int main(void) {
+    if (sizeof(void *) <= sizeof(int)) puts("int");
+    else puts("long");
+    return 0;
+}
+EOF
+  fi
+  if try $CC $CFLAGS -o $test $test.c; then
+    sizet=`./$test`
+    echo "Checking for a pointer-size integer type..." $sizet"." | tee -a configure.log
+    CFLAGS="${CFLAGS} -DNO_SIZE_T=${sizet}"
+    SFLAGS="${SFLAGS} -DNO_SIZE_T=${sizet}"
+  else
+    echo "Checking for a pointer-size integer type... not found." | tee -a configure.log
+  fi
+fi
+
+echo >> configure.log
+
+# check for large file support, and if none, check for fseeko()
 cat > $test.c <<EOF
 #include <sys/types.h>
 off64_t dummy = 0;
@@ -381,6 +548,7 @@ fi
 
 echo >> configure.log
 
+# check for strerror() for use by gz* functions
 cat > $test.c <<EOF
 #include <string.h>
 #include <errno.h>
@@ -394,10 +562,12 @@ else
   echo "Checking for strerror... No." | tee -a configure.log
 fi
 
-cp -p zconf.h.in zconf.h
+# copy clean zconf.h for subsequent edits
+cp -p ${SRCDIR}zconf.h.in zconf.h
 
 echo >> configure.log
 
+# check for unistd.h and save result in zconf.h
 cat > $test.c <<EOF
 #include <unistd.h>
 int main() { return 0; }
@@ -412,6 +582,7 @@ fi
 
 echo >> configure.log
 
+# check for stdarg.h and save result in zconf.h
 cat > $test.c <<EOF
 #include <stdarg.h>
 int main() { return 0; }
@@ -424,6 +595,7 @@ else
   echo "Checking for stdarg.h... No." | tee -a configure.log
 fi
 
+# if the z_ prefix was requested, save that in zconf.h
 if test $zprefix -eq 1; then
   sed < zconf.h "/#ifdef Z_PREFIX.* may be/s/def Z_PREFIX\(.*\) may be/ 1\1 was/" > zconf.temp.h
   mv zconf.temp.h zconf.h
@@ -431,6 +603,7 @@ if test $zprefix -eq 1; then
   echo "Using z_ prefix on all symbols." | tee -a configure.log
 fi
 
+# if --solo compilation was requested, save that in zconf.h and remove gz stuff from object lists
 if test $solo -eq 1; then
   sed '/#define ZCONF_H/a\
 #define Z_SOLO
@@ -441,6 +614,7 @@ OBJC='$(OBJZ)'
 PIC_OBJC='$(PIC_OBJZ)'
 fi
 
+# if code coverage testing was requested, use older gcc if defined, e.g. "gcc-4.2" on Mac OS X
 if test $cover -eq 1; then
   CFLAGS="${CFLAGS} -fprofile-arcs -ftest-coverage"
   if test -n "$GCC_CLASSIC"; then
@@ -450,6 +624,10 @@ fi
 
 echo >> configure.log
 
+# conduct a series of tests to resolve eight possible cases of using "vs" or "s" printf functions
+# (using stdarg or not), with or without "n" (proving size of buffer), and with or without a
+# return value.  The most secure result is vsnprintf() with a return value.  snprintf() with a
+# return value is secure as well, but then gzprintf() will be limited to 20 arguments.
 cat > $test.c <<EOF
 #include <stdio.h>
 #include <stdarg.h>
@@ -635,6 +813,7 @@ EOF
   fi
 fi
 
+# see if we can hide zlib internal symbols that are linked between separate source files
 if test "$gcc" -eq 1; then
   echo >> configure.log
   cat > $test.c <<EOF
@@ -654,8 +833,6 @@ EOF
   fi
 fi
 
-rm -f $test.[co] $test $test$shared_ext $test.gcno
-
 # show the results in the log
 echo >> configure.log
 echo ALL = $ALL >> configure.log
@@ -679,6 +856,7 @@ echo SHAREDLIBV = $SHAREDLIBV >> configure.log
 echo STATICLIB = $STATICLIB >> configure.log
 echo TEST = $TEST >> configure.log
 echo VER = $VER >> configure.log
+echo SRCDIR = $SRCDIR >> configure.log
 echo exec_prefix = $exec_prefix >> configure.log
 echo includedir = $includedir >> configure.log
 echo libdir = $libdir >> configure.log
@@ -686,12 +864,9 @@ 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
-sed < Makefile.in "
+# udpate Makefile with the configure results
+sed < ${SRCDIR}Makefile.in "
 /^CC *=/s#=.*#=$CC#
 /^CFLAGS *=/s#=.*#=$CFLAGS#
 /^SFLAGS *=/s#=.*#=$SFLAGS#
@@ -708,6 +883,9 @@ sed < Makefile.in "
 /^LDCONFIG *=/s#=.*#=$LDCONFIG#
 /^LDSHAREDLIBC *=/s#=.*#=$LDSHAREDLIBC#
 /^EXE *=/s#=.*#=$EXE#
+/^SRCDIR *=/s#=.*#=$SRCDIR#
+/^ZINC *=/s#=.*#=$ZINC#
+/^ZINCOUT *=/s#=.*#=$ZINCOUT#
 /^prefix *=/s#=.*#=$prefix#
 /^exec_prefix *=/s#=.*#=$exec_prefix#
 /^libdir *=/s#=.*#=$libdir#
@@ -720,7 +898,8 @@ sed < Makefile.in "
 /^test: */s#:.*#: $TEST#
 " > Makefile
 
-sed < zlib.pc.in "
+# create zlib.pc with the configure results
+sed < ${SRCDIR}zlib.pc.in "
 /^CC *=/s#=.*#=$CC#
 /^CFLAGS *=/s#=.*#=$CFLAGS#
 /^CPP *=/s#=.*#=$CPP#
@@ -743,3 +922,6 @@ sed < zlib.pc.in "
 " | sed -e "
 s/\@VERSION\@/$VER/g;
 " > zlib.pc
+
+# done
+leave 0