Home | History | Annotate | Line # | Download | only in zlib
      1 #!/bin/sh
      2 # configure script for zlib.
      3 #
      4 # Normally configure builds both a static and a shared library.
      5 # If you want to build just a static library, use: ./configure --static
      6 #
      7 # To impose specific compiler or flags or install directory, use for example:
      8 #    prefix=$HOME CC=cc CFLAGS="-O4" ./configure
      9 # or for csh/tcsh users:
     10 #    (setenv prefix $HOME; setenv CC cc; setenv CFLAGS "-O4"; ./configure)
     11 
     12 # Incorrect settings of CC or CFLAGS may prevent creating a shared library.
     13 # If you have problems, try without defining CC and CFLAGS before reporting
     14 # an error.
     15 
     16 # start off configure.log
     17 echo -------------------- >> configure.log
     18 echo $0 $* >> configure.log
     19 date >> configure.log
     20 
     21 # get source directory
     22 SRCDIR=`dirname $0`
     23 if test $SRCDIR = "."; then
     24     ZINC=""
     25     ZINCOUT="-I."
     26     SRCDIR=""
     27 else
     28     ZINC='-I. -include zconf.h'
     29     ZINCOUT='-I. -I$(SRCDIR)'
     30     SRCDIR="$SRCDIR/"
     31 fi
     32 
     33 # set command prefix for cross-compilation
     34 if [ -n "${CHOST}" ]; then
     35     uname=${CHOST}
     36     mname=${CHOST}
     37     CROSS_PREFIX="${CHOST}-"
     38 else
     39     mname=`(uname -a || echo unknown) 2>/dev/null`
     40 fi
     41 
     42 # destination name for static library
     43 STATICLIB=libz.a
     44 
     45 # extract zlib version numbers from zlib.h
     46 VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < ${SRCDIR}zlib.h`
     47 VER3=`echo ${VER}|sed -n -e 's/\([0-9]\{1,\}\(\\.[0-9]\{1,\}\)\{1,2\}\).*/\1/p'`
     48 VER1=`echo ${VER}|sed -n -e 's/\([0-9]\{1,\}\)\\..*/\1/p'`
     49 
     50 # establish commands for library building
     51 if "${CROSS_PREFIX}ar" --version >/dev/null 2>/dev/null || test $? -lt 126; then
     52     AR=${AR-"${CROSS_PREFIX}ar"}
     53     test -n "${CROSS_PREFIX}" && echo Using ${AR} | tee -a configure.log
     54 else
     55     AR=${AR-"ar"}
     56     test -n "${CROSS_PREFIX}" && echo Using ${AR} | tee -a configure.log
     57 fi
     58 ARFLAGS=${ARFLAGS-"rc"}
     59 if "${CROSS_PREFIX}ranlib" --version >/dev/null 2>/dev/null || test $? -lt 126; then
     60     RANLIB=${RANLIB-"${CROSS_PREFIX}ranlib"}
     61     test -n "${CROSS_PREFIX}" && echo Using ${RANLIB} | tee -a configure.log
     62 else
     63     RANLIB=${RANLIB-"ranlib"}
     64 fi
     65 if "${CROSS_PREFIX}nm" --version >/dev/null 2>/dev/null || test $? -lt 126; then
     66     NM=${NM-"${CROSS_PREFIX}nm"}
     67     test -n "${CROSS_PREFIX}" && echo Using ${NM} | tee -a configure.log
     68 else
     69     NM=${NM-"nm"}
     70 fi
     71 
     72 # set defaults before processing command line options
     73 LDCONFIG=${LDCONFIG-"ldconfig"}
     74 LDSHAREDLIBC="${LDSHAREDLIBC--lc}"
     75 ARCHS=
     76 prefix=${prefix-/usr/local}
     77 exec_prefix=${exec_prefix-'${prefix}'}
     78 libdir=${libdir-'${exec_prefix}/lib'}
     79 sharedlibdir=${sharedlibdir-'${libdir}'}
     80 includedir=${includedir-'${prefix}/include'}
     81 mandir=${mandir-'${prefix}/share/man'}
     82 shared_ext='.so'
     83 shared=1
     84 solo=0
     85 cover=0
     86 zprefix=0
     87 zconst=0
     88 build64=0
     89 gcc=0
     90 warn=0
     91 debug=0
     92 address=0
     93 memory=0
     94 old_cc="$CC"
     95 old_cflags="$CFLAGS"
     96 OBJC='$(OBJZ) $(OBJG)'
     97 PIC_OBJC='$(PIC_OBJZ) $(PIC_OBJG)'
     98 
     99 # leave this script, optionally in a bad way
    100 leave()
    101 {
    102   if test "$*" != "0"; then
    103     echo "** $0 aborting." | tee -a configure.log
    104   fi
    105   rm -rf $test.[co] $test $test$shared_ext $test.gcno $test.dSYM ./--version
    106   echo -------------------- >> configure.log
    107   echo >> configure.log
    108   echo >> configure.log
    109   exit $1
    110 }
    111 
    112 # process command line options
    113 while test $# -ge 1
    114 do
    115 case "$1" in
    116     -h* | --help)
    117       echo 'usage:' | tee -a configure.log
    118       echo '  configure [--const] [--zprefix] [--prefix=PREFIX]  [--eprefix=EXPREFIX]' | tee -a configure.log
    119       echo '    [--static] [--64] [--libdir=LIBDIR] [--sharedlibdir=LIBDIR]' | tee -a configure.log
    120       echo '    [--includedir=INCLUDEDIR] [--archs="-arch i386 -arch x86_64"]' | tee -a configure.log
    121         exit 0 ;;
    122     -p*=* | --prefix=*) prefix=`echo $1 | sed 's/.*=//'`; shift ;;
    123     -e*=* | --eprefix=*) exec_prefix=`echo $1 | sed 's/.*=//'`; shift ;;
    124     -l*=* | --libdir=*) libdir=`echo $1 | sed 's/.*=//'`; shift ;;
    125     --sharedlibdir=*) sharedlibdir=`echo $1 | sed 's/.*=//'`; shift ;;
    126     -i*=* | --includedir=*) includedir=`echo $1 | sed 's/.*=//'`;shift ;;
    127     -u*=* | --uname=*) uname=`echo $1 | sed 's/.*=//'`;shift ;;
    128     -p* | --prefix) prefix="$2"; shift; shift ;;
    129     -e* | --eprefix) exec_prefix="$2"; shift; shift ;;
    130     -l* | --libdir) libdir="$2"; shift; shift ;;
    131     -i* | --includedir) includedir="$2"; shift; shift ;;
    132     -s* | --shared | --enable-shared) shared=1; shift ;;
    133     -t | --static) shared=0; shift ;;
    134     --solo) solo=1; shift ;;
    135     --cover) cover=1; shift ;;
    136     -z* | --zprefix) zprefix=1; shift ;;
    137     -6* | --64) build64=1; shift ;;
    138     -a*=* | --archs=*) ARCHS=`echo $1 | sed 's/.*=//'`; shift ;;
    139     --sysconfdir=*) echo "ignored option: --sysconfdir" | tee -a configure.log; shift ;;
    140     --localstatedir=*) echo "ignored option: --localstatedir" | tee -a configure.log; shift ;;
    141     -c* | --const) zconst=1; shift ;;
    142     -w* | --warn) warn=1; shift ;;
    143     -d* | --debug) debug=1; shift ;;
    144     --sanitize) address=1; shift ;;
    145     --address) address=1; shift ;;
    146     --memory) memory=1; shift ;;
    147     *)
    148       echo "unknown option: $1" | tee -a configure.log
    149       echo "$0 --help for help" | tee -a configure.log
    150       leave 1;;
    151     esac
    152 done
    153 
    154 # temporary file name
    155 test=ztest$$
    156 
    157 # put arguments in log, also put test file in log if used in arguments
    158 show()
    159 {
    160   case "$*" in
    161     *$test.c*)
    162       echo === $test.c === >> configure.log
    163       cat $test.c >> configure.log
    164       echo === >> configure.log;;
    165   esac
    166   echo $* >> configure.log
    167 }
    168 
    169 # check for gcc vs. cc and set compile and link flags based on the system identified by uname
    170 cat > $test.c <<EOF
    171 extern int getchar();
    172 int hello() {return getchar();}
    173 EOF
    174 
    175 if test -z "$CC"; then
    176   echo Checking for ${CROSS_PREFIX}gcc... | tee -a configure.log
    177   if ${CROSS_PREFIX}gcc -v >/dev/null 2>&1; then
    178     cc=${CROSS_PREFIX}gcc
    179   else
    180     cc=${CROSS_PREFIX}cc
    181   fi
    182 else
    183   cc=${CC}
    184 fi
    185 
    186 case "$cc" in
    187   *gcc*) gcc=1 ;;
    188   *clang*) gcc=1 ;;
    189 esac
    190 case `$cc -v 2>&1` in
    191   *gcc*) gcc=1 ;;
    192   *clang*) gcc=1 ;;
    193 esac
    194 
    195 show $cc -c $test.c
    196 if test "$gcc" -eq 1 && ($cc -c $test.c) >> configure.log 2>&1; then
    197   echo ... using gcc >> configure.log
    198   CC="$cc"
    199   CFLAGS="${CFLAGS--O3}"
    200   SFLAGS="${CFLAGS--O3} -fPIC"
    201   if test "$ARCHS"; then
    202     CFLAGS="${CFLAGS} ${ARCHS}"
    203     LDFLAGS="${LDFLAGS} ${ARCHS}"
    204   fi
    205   if test $build64 -eq 1; then
    206     CFLAGS="${CFLAGS} -m64"
    207     SFLAGS="${SFLAGS} -m64"
    208   fi
    209   if test "$warn" -eq 1; then
    210     if test "$zconst" -eq 1; then
    211       CFLAGS="${CFLAGS} -Wall -Wextra -Wcast-qual -DZLIB_CONST"
    212     else
    213       CFLAGS="${CFLAGS} -Wall -Wextra"
    214     fi
    215   fi
    216   if test $address -eq 1; then
    217     CFLAGS="${CFLAGS} -g -fsanitize=address -fno-omit-frame-pointer"
    218   fi
    219   if test $memory -eq 1; then
    220     CFLAGS="${CFLAGS} -g -fsanitize=memory -fno-omit-frame-pointer"
    221   fi
    222   if test $debug -eq 1; then
    223     CFLAGS="${CFLAGS} -DZLIB_DEBUG"
    224     SFLAGS="${SFLAGS} -DZLIB_DEBUG"
    225   fi
    226   if test -z "$uname"; then
    227     uname=`(uname -s || echo unknown) 2>/dev/null`
    228   fi
    229   case "$uname" in
    230   Linux* | linux* | *-linux* | GNU | GNU/* | solaris*)
    231         case "$mname" in
    232         *sparc*)
    233             LDFLAGS="${LDFLAGS} -Wl,--no-warn-rwx-segments" ;;
    234         esac
    235         LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,${SRCDIR}zlib.map"} ;;
    236   *BSD | *bsd* | DragonFly)
    237         LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,${SRCDIR}zlib.map"}
    238         LDCONFIG="ldconfig -m" ;;
    239   CYGWIN* | Cygwin* | cygwin* | *-cygwin* | OS/2*)
    240         EXE='.exe' ;;
    241   MINGW* | mingw* | *-mingw*)
    242         rm -f $test.[co] $test $test$shared_ext
    243         echo "If this doesn't work for you, try win32/Makefile.gcc." | tee -a configure.log
    244         LDSHARED=${LDSHARED-"$cc -shared"}
    245         LDSHAREDLIBC=""
    246         EXE='.exe' ;;
    247   QNX*) # This is for QNX6. I suppose that the QNX rule below is for QNX2,QNX4
    248         # (alain.bonnefoy (at] icbt.com)
    249         LDSHARED=${LDSHARED-"$cc -shared -Wl,-hlibz.so.1"} ;;
    250   HP-UX*)
    251         LDSHARED=${LDSHARED-"$cc -shared $SFLAGS"}
    252         case `(uname -m || echo unknown) 2>/dev/null` in
    253         ia64)
    254             shared_ext='.so'
    255             SHAREDLIB='libz.so' ;;
    256         *)
    257             shared_ext='.sl'
    258             SHAREDLIB='libz.sl' ;;
    259         esac ;;
    260   AIX*)
    261         LDFLAGS="${LDFLAGS} -Wl,-brtl" ;;
    262   Darwin* | darwin* | *-darwin*)
    263         shared_ext='.dylib'
    264         SHAREDLIB=libz$shared_ext
    265         SHAREDLIBV=libz.$VER$shared_ext
    266         SHAREDLIBM=libz.$VER1$shared_ext
    267         LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBM -compatibility_version $VER1 -current_version $VER3"}
    268         if "${CROSS_PREFIX}libtool" -V 2>&1 | grep Apple > /dev/null; then
    269             AR="${CROSS_PREFIX}libtool"
    270         elif libtool -V 2>&1 | grep Apple > /dev/null; then
    271             AR="libtool"
    272         else
    273             AR="/usr/bin/libtool"
    274         fi
    275         ARFLAGS="-o" ;;
    276   *)
    277         LDSHARED=${LDSHARED-"$cc -shared"} ;;
    278   esac
    279 else
    280   # find system name and corresponding cc options
    281   CC=${CC-cc}
    282   gcc=0
    283   echo ... using $CC >> configure.log
    284   if test -z "$uname"; then
    285     uname=`(uname -sr || echo unknown) 2>/dev/null`
    286   fi
    287   case "$uname" in
    288   HP-UX*)    SFLAGS=${CFLAGS-"-O +z"}
    289              CFLAGS=${CFLAGS-"-O"}
    290 #            LDSHARED=${LDSHARED-"ld -b +vnocompatwarnings"}
    291              LDSHARED=${LDSHARED-"ld -b"}
    292          case `(uname -m || echo unknown) 2>/dev/null` in
    293          ia64)
    294              shared_ext='.so'
    295              SHAREDLIB='libz.so' ;;
    296          *)
    297              shared_ext='.sl'
    298              SHAREDLIB='libz.sl' ;;
    299          esac ;;
    300   IRIX*)     SFLAGS=${CFLAGS-"-ansi -O2 -rpath ."}
    301              CFLAGS=${CFLAGS-"-ansi -O2"}
    302              LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;;
    303   OSF1\ V4*) SFLAGS=${CFLAGS-"-O -std1"}
    304              CFLAGS=${CFLAGS-"-O -std1"}
    305              LDFLAGS="${LDFLAGS} -Wl,-rpath,."
    306              LDSHARED=${LDSHARED-"cc -shared  -Wl,-soname,libz.so -Wl,-msym -Wl,-rpath,$(libdir) -Wl,-set_version,${VER}:1.0"} ;;
    307   OSF1*)     SFLAGS=${CFLAGS-"-O -std1"}
    308              CFLAGS=${CFLAGS-"-O -std1"}
    309              LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;;
    310   QNX*)      SFLAGS=${CFLAGS-"-4 -O"}
    311              CFLAGS=${CFLAGS-"-4 -O"}
    312              LDSHARED=${LDSHARED-"cc"}
    313              RANLIB=${RANLIB-"true"}
    314              AR="cc"
    315              ARFLAGS="-A" ;;
    316   SCO_SV\ 3.2*) SFLAGS=${CFLAGS-"-O3 -dy -KPIC "}
    317              CFLAGS=${CFLAGS-"-O3"}
    318              LDSHARED=${LDSHARED-"cc -dy -KPIC -G"} ;;
    319   SunOS\ 5* | solaris*)
    320          LDSHARED=${LDSHARED-"cc -G -h libz$shared_ext.$VER1"}
    321          SFLAGS=${CFLAGS-"-fast -KPIC"}
    322          CFLAGS=${CFLAGS-"-fast"}
    323          if test $build64 -eq 1; then
    324              # old versions of SunPRO/Workshop/Studio don't support -m64,
    325              # but newer ones do.  Check for it.
    326              flag64=`$CC -flags | egrep -- '^-m64'`
    327              if test x"$flag64" != x"" ; then
    328                  CFLAGS="${CFLAGS} -m64"
    329                  SFLAGS="${SFLAGS} -m64"
    330              else
    331                  case `(uname -m || echo unknown) 2>/dev/null` in
    332                    i86*)
    333                      SFLAGS="$SFLAGS -xarch=amd64"
    334                      CFLAGS="$CFLAGS -xarch=amd64" ;;
    335                    *)
    336                      SFLAGS="$SFLAGS -xarch=v9"
    337                      CFLAGS="$CFLAGS -xarch=v9" ;;
    338                  esac
    339              fi
    340          fi
    341          if test -n "$ZINC"; then
    342              ZINC='-I- -I. -I$(SRCDIR)'
    343          fi
    344          ;;
    345   SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"}
    346              CFLAGS=${CFLAGS-"-O2"}
    347              LDSHARED=${LDSHARED-"ld"} ;;
    348   SunStudio\ 9*) SFLAGS=${CFLAGS-"-fast -xcode=pic32 -xtarget=ultra3 -xarch=v9b"}
    349              CFLAGS=${CFLAGS-"-fast -xtarget=ultra3 -xarch=v9b"}
    350              LDSHARED=${LDSHARED-"cc -xarch=v9b"} ;;
    351   UNIX_System_V\ 4.2.0)
    352              SFLAGS=${CFLAGS-"-KPIC -O"}
    353              CFLAGS=${CFLAGS-"-O"}
    354              LDSHARED=${LDSHARED-"cc -G"} ;;
    355   UNIX_SV\ 4.2MP)
    356              SFLAGS=${CFLAGS-"-Kconform_pic -O"}
    357              CFLAGS=${CFLAGS-"-O"}
    358              LDSHARED=${LDSHARED-"cc -G"} ;;
    359   OpenUNIX\ 5)
    360              SFLAGS=${CFLAGS-"-KPIC -O"}
    361              CFLAGS=${CFLAGS-"-O"}
    362              LDSHARED=${LDSHARED-"cc -G"} ;;
    363   AIX*)  # Courtesy of dbakker (at] arrayasolutions.com
    364              SFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
    365              CFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
    366              LDSHARED=${LDSHARED-"xlc -G"} ;;
    367   # send working options for other systems to zlib (at] gzip.org
    368   *)         SFLAGS=${CFLAGS-"-O"}
    369              CFLAGS=${CFLAGS-"-O"}
    370              LDSHARED=${LDSHARED-"cc -shared"} ;;
    371   esac
    372 fi
    373 
    374 # destination names for shared library if not defined above
    375 SHAREDLIB=${SHAREDLIB-"libz$shared_ext"}
    376 SHAREDLIBV=${SHAREDLIBV-"libz$shared_ext.$VER"}
    377 SHAREDLIBM=${SHAREDLIBM-"libz$shared_ext.$VER1"}
    378 
    379 echo >> configure.log
    380 
    381 # define functions for testing compiler and library characteristics and logging the results
    382 
    383 cat > $test.c <<EOF
    384 #error error
    385 EOF
    386 if ($CC -c $CFLAGS $test.c) 2>/dev/null; then
    387   try()
    388   {
    389     show $*
    390     test "`( $* ) 2>&1 | tee -a configure.log`" = ""
    391   }
    392   echo - using any output from compiler to indicate an error >> configure.log
    393 else
    394   try()
    395   {
    396     show $*
    397     got=`( $* ) 2>&1`
    398     ret=$?
    399     if test "$got" != ""; then
    400       printf "%s\n" "$got" >> configure.log
    401     fi
    402     if test $ret -ne 0; then
    403       echo "(exit code "$ret")" >> configure.log
    404     fi
    405     return $ret
    406   }
    407 fi
    408 
    409 tryboth()
    410 {
    411   show $*
    412   got=`( $* ) 2>&1`
    413   ret=$?
    414   if test "$got" != ""; then
    415     printf "%s\n" "$got" >> configure.log
    416   fi
    417   if test $ret -ne 0; then
    418     echo "(exit code "$ret")" >> configure.log
    419     return $ret
    420   fi
    421   test "$got" = ""
    422 }
    423 
    424 cat > $test.c << EOF
    425 int foo() { return 0; }
    426 EOF
    427 echo "Checking for obsessive-compulsive compiler options..." >> configure.log
    428 if try $CC -c $CFLAGS $test.c; then
    429   :
    430 else
    431   echo "Compiler error reporting is too harsh for $0 (perhaps remove -Werror)." | tee -a configure.log
    432   leave 1
    433 fi
    434 
    435 echo >> configure.log
    436 
    437 # see if shared library build supported
    438 cat > $test.c <<EOF
    439 extern int getchar();
    440 int hello() {return getchar();}
    441 EOF
    442 if test $shared -eq 1; then
    443   echo Checking for shared library support... | tee -a configure.log
    444   # we must test in two steps (cc then ld), required at least on SunOS 4.x
    445   if try $CC -c $SFLAGS $test.c &&
    446      try $LDSHARED $SFLAGS -o $test$shared_ext $test.o; then
    447     echo Building shared library $SHAREDLIBV with $CC. | tee -a configure.log
    448   elif test -z "$old_cc" -a -z "$old_cflags"; then
    449     echo No shared library support. | tee -a configure.log
    450     shared=0;
    451   else
    452     echo 'No shared library support; try without defining CC and CFLAGS' | tee -a configure.log
    453     shared=0;
    454   fi
    455 fi
    456 if test $shared -eq 0; then
    457   LDSHARED="$CC"
    458   ALL="static"
    459   TEST="all teststatic"
    460   SHAREDLIB=""
    461   SHAREDLIBV=""
    462   SHAREDLIBM=""
    463   echo Building static library $STATICLIB version $VER with $CC. | tee -a configure.log
    464 else
    465   ALL="static shared"
    466   TEST="all teststatic testshared"
    467 fi
    468 
    469 echo >> configure.log
    470 
    471 # check for size_t
    472 cat > $test.c <<EOF
    473 #include <stdio.h>
    474 #include <stdlib.h>
    475 size_t dummy = 0;
    476 EOF
    477 if try $CC -c $CFLAGS $test.c; then
    478   echo "Checking for size_t... Yes." | tee -a configure.log
    479 else
    480   echo "Checking for size_t... No." | tee -a configure.log
    481   # find a size_t integer type
    482   # check for long long
    483   cat > $test.c << EOF
    484 long long dummy = 0;
    485 EOF
    486   if try $CC -c $CFLAGS $test.c; then
    487     echo "Checking for long long... Yes." | tee -a configure.log
    488     cat > $test.c <<EOF
    489 #include <stdio.h>
    490 int main(void) {
    491     if (sizeof(void *) <= sizeof(int)) puts("int");
    492     else if (sizeof(void *) <= sizeof(long)) puts("long");
    493     else puts("z_longlong");
    494     return 0;
    495 }
    496 EOF
    497   else
    498     echo "Checking for long long... No." | tee -a configure.log
    499     cat > $test.c <<EOF
    500 #include <stdio.h>
    501 int main(void) {
    502     if (sizeof(void *) <= sizeof(int)) puts("int");
    503     else puts("long");
    504     return 0;
    505 }
    506 EOF
    507   fi
    508   if try $CC $CFLAGS -o $test $test.c; then
    509     sizet=`./$test`
    510     echo "Checking for a pointer-size integer type..." $sizet"." | tee -a configure.log
    511     CFLAGS="${CFLAGS} -DNO_SIZE_T=${sizet}"
    512     SFLAGS="${SFLAGS} -DNO_SIZE_T=${sizet}"
    513   else
    514     echo "Checking for a pointer-size integer type... not found." | tee -a configure.log
    515   fi
    516 fi
    517 
    518 echo >> configure.log
    519 
    520 # check for large file support, and if none, check for fseeko()
    521 cat > $test.c <<EOF
    522 #include <sys/types.h>
    523 off64_t dummy = 0;
    524 EOF
    525 if try $CC -c $CFLAGS -D_LARGEFILE64_SOURCE=1 $test.c; then
    526   CFLAGS="${CFLAGS} -D_LARGEFILE64_SOURCE=1"
    527   SFLAGS="${SFLAGS} -D_LARGEFILE64_SOURCE=1"
    528   ALL="${ALL} all64"
    529   TEST="${TEST} test64"
    530   echo "Checking for off64_t... Yes." | tee -a configure.log
    531   echo "Checking for fseeko... Yes." | tee -a configure.log
    532 else
    533   echo "Checking for off64_t... No." | tee -a configure.log
    534   echo >> configure.log
    535   cat > $test.c <<EOF
    536 #include <stdio.h>
    537 int main(void) {
    538   fseeko(NULL, 0, 0);
    539   return 0;
    540 }
    541 EOF
    542   if try $CC $CFLAGS -o $test $test.c; then
    543     echo "Checking for fseeko... Yes." | tee -a configure.log
    544   else
    545     CFLAGS="${CFLAGS} -DNO_FSEEKO"
    546     SFLAGS="${SFLAGS} -DNO_FSEEKO"
    547     echo "Checking for fseeko... No." | tee -a configure.log
    548   fi
    549 fi
    550 
    551 echo >> configure.log
    552 
    553 # check for strerror() for use by gz* functions
    554 cat > $test.c <<EOF
    555 #include <string.h>
    556 #include <errno.h>
    557 int main() { return strlen(strerror(errno)); }
    558 EOF
    559 if try $CC $CFLAGS -o $test $test.c; then
    560   echo "Checking for strerror... Yes." | tee -a configure.log
    561 else
    562   CFLAGS="${CFLAGS} -DNO_STRERROR"
    563   SFLAGS="${SFLAGS} -DNO_STRERROR"
    564   echo "Checking for strerror... No." | tee -a configure.log
    565 fi
    566 
    567 # copy clean zconf.h for subsequent edits
    568 cp -p ${SRCDIR}zconf.h.in zconf.h
    569 
    570 echo >> configure.log
    571 
    572 # check for unistd.h and save result in zconf.h
    573 cat > $test.c <<EOF
    574 #include <unistd.h>
    575 int main() { return 0; }
    576 EOF
    577 if try $CC -c $CFLAGS $test.c; then
    578   sed < zconf.h "/^#ifdef HAVE_UNISTD_H.* may be/s/def HAVE_UNISTD_H\(.*\) may be/ 1\1 was/" > zconf.temp.h
    579   mv zconf.temp.h zconf.h
    580   echo "Checking for unistd.h... Yes." | tee -a configure.log
    581 else
    582   echo "Checking for unistd.h... No." | tee -a configure.log
    583 fi
    584 
    585 echo >> configure.log
    586 
    587 # check for stdarg.h and save result in zconf.h
    588 cat > $test.c <<EOF
    589 #include <stdarg.h>
    590 int main() { return 0; }
    591 EOF
    592 if try $CC -c $CFLAGS $test.c; then
    593   sed < zconf.h "/^#ifdef HAVE_STDARG_H.* may be/s/def HAVE_STDARG_H\(.*\) may be/ 1\1 was/" > zconf.temp.h
    594   mv zconf.temp.h zconf.h
    595   echo "Checking for stdarg.h... Yes." | tee -a configure.log
    596 else
    597   echo "Checking for stdarg.h... No." | tee -a configure.log
    598 fi
    599 
    600 # if the z_ prefix was requested, save that in zconf.h
    601 if test $zprefix -eq 1; then
    602   sed < zconf.h "/#ifdef Z_PREFIX.* may be/s/def Z_PREFIX\(.*\) may be/ 1\1 was/" > zconf.temp.h
    603   mv zconf.temp.h zconf.h
    604   echo >> configure.log
    605   echo "Using z_ prefix on all symbols." | tee -a configure.log
    606 fi
    607 
    608 # if --solo compilation was requested, save that in zconf.h and remove gz stuff from object lists
    609 if test $solo -eq 1; then
    610   sed '/#define ZCONF_H/a\
    611 #define Z_SOLO
    612 
    613 ' < zconf.h > zconf.temp.h
    614   mv zconf.temp.h zconf.h
    615 OBJC='$(OBJZ)'
    616 PIC_OBJC='$(PIC_OBJZ)'
    617 fi
    618 
    619 # if code coverage testing was requested, use older gcc if defined, e.g. "gcc-4.2" on Mac OS X
    620 if test $cover -eq 1; then
    621   CFLAGS="${CFLAGS} -fprofile-arcs -ftest-coverage"
    622   if test -n "$GCC_CLASSIC"; then
    623     CC=$GCC_CLASSIC
    624   fi
    625 fi
    626 
    627 echo >> configure.log
    628 
    629 # conduct a series of tests to resolve eight possible cases of using "vs" or "s" printf functions
    630 # (using stdarg or not), with or without "n" (proving size of buffer), and with or without a
    631 # return value.  The most secure result is vsnprintf() with a return value.  snprintf() with a
    632 # return value is secure as well, but then gzprintf() will be limited to 20 arguments.
    633 cat > $test.c <<EOF
    634 #include <stdio.h>
    635 #include <stdarg.h>
    636 #include "zconf.h"
    637 int main()
    638 {
    639 #ifndef STDC
    640   choke me
    641 #endif
    642   return 0;
    643 }
    644 EOF
    645 if try $CC -c $CFLAGS $test.c; then
    646   echo "Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf()." | tee -a configure.log
    647 
    648   echo >> configure.log
    649   cat > $test.c <<EOF
    650 #include <stdio.h>
    651 #include <stdarg.h>
    652 int mytest(const char *fmt, ...)
    653 {
    654   char buf[20];
    655   va_list ap;
    656   va_start(ap, fmt);
    657   vsnprintf(buf, sizeof(buf), fmt, ap);
    658   va_end(ap);
    659   return 0;
    660 }
    661 int main()
    662 {
    663   return (mytest("Hello%d\n", 1));
    664 }
    665 EOF
    666   if try $CC $CFLAGS -o $test $test.c; then
    667     echo "Checking for vsnprintf() in stdio.h... Yes." | tee -a configure.log
    668 
    669     echo >> configure.log
    670     cat >$test.c <<EOF
    671 #include <stdio.h>
    672 #include <stdarg.h>
    673 int mytest(const char *fmt, ...)
    674 {
    675   int n;
    676   char buf[20];
    677   va_list ap;
    678   va_start(ap, fmt);
    679   n = vsnprintf(buf, sizeof(buf), fmt, ap);
    680   va_end(ap);
    681   return n;
    682 }
    683 int main()
    684 {
    685   return (mytest("Hello%d\n", 1));
    686 }
    687 EOF
    688 
    689     if try $CC -c $CFLAGS $test.c; then
    690       echo "Checking for return value of vsnprintf()... Yes." | tee -a configure.log
    691     else
    692       CFLAGS="$CFLAGS -DHAS_vsnprintf_void"
    693       SFLAGS="$SFLAGS -DHAS_vsnprintf_void"
    694       echo "Checking for return value of vsnprintf()... No." | tee -a configure.log
    695       echo "  WARNING: apparently vsnprintf() does not return a value. zlib" | tee -a configure.log
    696       echo "  can build but will be open to possible string-format security" | tee -a configure.log
    697       echo "  vulnerabilities." | tee -a configure.log
    698     fi
    699   else
    700     CFLAGS="$CFLAGS -DNO_vsnprintf"
    701     SFLAGS="$SFLAGS -DNO_vsnprintf"
    702     echo "Checking for vsnprintf() in stdio.h... No." | tee -a configure.log
    703     echo "  WARNING: vsnprintf() not found, falling back to vsprintf(). zlib" | tee -a configure.log
    704     echo "  can build but will be open to possible buffer-overflow security" | tee -a configure.log
    705     echo "  vulnerabilities." | tee -a configure.log
    706 
    707     echo >> configure.log
    708     cat >$test.c <<EOF
    709 #include <stdio.h>
    710 #include <stdarg.h>
    711 int mytest(const char *fmt, ...)
    712 {
    713   int n;
    714   char buf[20];
    715   va_list ap;
    716   va_start(ap, fmt);
    717   n = vsprintf(buf, fmt, ap);
    718   va_end(ap);
    719   return n;
    720 }
    721 int main()
    722 {
    723   return (mytest("Hello%d\n", 1));
    724 }
    725 EOF
    726 
    727     if try $CC -c $CFLAGS $test.c; then
    728       echo "Checking for return value of vsprintf()... Yes." | tee -a configure.log
    729     else
    730       CFLAGS="$CFLAGS -DHAS_vsprintf_void"
    731       SFLAGS="$SFLAGS -DHAS_vsprintf_void"
    732       echo "Checking for return value of vsprintf()... No." | tee -a configure.log
    733       echo "  WARNING: apparently vsprintf() does not return a value. zlib" | tee -a configure.log
    734       echo "  can build but will be open to possible string-format security" | tee -a configure.log
    735       echo "  vulnerabilities." | tee -a configure.log
    736     fi
    737   fi
    738 else
    739   echo "Checking whether to use vs[n]printf() or s[n]printf()... using s[n]printf()." | tee -a configure.log
    740 
    741   echo >> configure.log
    742   cat >$test.c <<EOF
    743 #include <stdio.h>
    744 int mytest()
    745 {
    746   char buf[20];
    747   snprintf(buf, sizeof(buf), "%s", "foo");
    748   return 0;
    749 }
    750 int main()
    751 {
    752   return (mytest());
    753 }
    754 EOF
    755 
    756   if try $CC $CFLAGS -o $test $test.c; then
    757     echo "Checking for snprintf() in stdio.h... Yes." | tee -a configure.log
    758 
    759     echo >> configure.log
    760     cat >$test.c <<EOF
    761 #include <stdio.h>
    762 int mytest()
    763 {
    764   char buf[20];
    765   return snprintf(buf, sizeof(buf), "%s", "foo");
    766 }
    767 int main()
    768 {
    769   return (mytest());
    770 }
    771 EOF
    772 
    773     if try $CC -c $CFLAGS $test.c; then
    774       echo "Checking for return value of snprintf()... Yes." | tee -a configure.log
    775     else
    776       CFLAGS="$CFLAGS -DHAS_snprintf_void"
    777       SFLAGS="$SFLAGS -DHAS_snprintf_void"
    778       echo "Checking for return value of snprintf()... No." | tee -a configure.log
    779       echo "  WARNING: apparently snprintf() does not return a value. zlib" | tee -a configure.log
    780       echo "  can build but will be open to possible string-format security" | tee -a configure.log
    781       echo "  vulnerabilities." | tee -a configure.log
    782     fi
    783   else
    784     CFLAGS="$CFLAGS -DNO_snprintf"
    785     SFLAGS="$SFLAGS -DNO_snprintf"
    786     echo "Checking for snprintf() in stdio.h... No." | tee -a configure.log
    787     echo "  WARNING: snprintf() not found, falling back to sprintf(). zlib" | tee -a configure.log
    788     echo "  can build but will be open to possible buffer-overflow security" | tee -a configure.log
    789     echo "  vulnerabilities." | tee -a configure.log
    790 
    791     echo >> configure.log
    792     cat >$test.c <<EOF
    793 #include <stdio.h>
    794 int mytest()
    795 {
    796   char buf[20];
    797   return sprintf(buf, "%s", "foo");
    798 }
    799 int main()
    800 {
    801   return (mytest());
    802 }
    803 EOF
    804 
    805     if try $CC -c $CFLAGS $test.c; then
    806       echo "Checking for return value of sprintf()... Yes." | tee -a configure.log
    807     else
    808       CFLAGS="$CFLAGS -DHAS_sprintf_void"
    809       SFLAGS="$SFLAGS -DHAS_sprintf_void"
    810       echo "Checking for return value of sprintf()... No." | tee -a configure.log
    811       echo "  WARNING: apparently sprintf() does not return a value. zlib" | tee -a configure.log
    812       echo "  can build but will be open to possible string-format security" | tee -a configure.log
    813       echo "  vulnerabilities." | tee -a configure.log
    814     fi
    815   fi
    816 fi
    817 
    818 # see if we can hide zlib internal symbols that are linked between separate source files
    819 if test "$gcc" -eq 1; then
    820   echo >> configure.log
    821   cat > $test.c <<EOF
    822 #define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
    823 int ZLIB_INTERNAL foo;
    824 int main()
    825 {
    826   return 0;
    827 }
    828 EOF
    829   if tryboth $CC -c $CFLAGS $test.c; then
    830     CFLAGS="$CFLAGS -DHAVE_HIDDEN"
    831     SFLAGS="$SFLAGS -DHAVE_HIDDEN"
    832     echo "Checking for attribute(visibility) support... Yes." | tee -a configure.log
    833   else
    834     echo "Checking for attribute(visibility) support... No." | tee -a configure.log
    835   fi
    836 fi
    837 
    838 # show the results in the log
    839 echo >> configure.log
    840 echo ALL = $ALL >> configure.log
    841 echo AR = $AR >> configure.log
    842 echo ARFLAGS = $ARFLAGS >> configure.log
    843 echo CC = $CC >> configure.log
    844 echo CFLAGS = $CFLAGS >> configure.log
    845 echo CPP = $CPP >> configure.log
    846 echo EXE = $EXE >> configure.log
    847 echo LDCONFIG = $LDCONFIG >> configure.log
    848 echo LDFLAGS = $LDFLAGS >> configure.log
    849 echo LDSHARED = $LDSHARED >> configure.log
    850 echo LDSHAREDLIBC = $LDSHAREDLIBC >> configure.log
    851 echo OBJC = $OBJC >> configure.log
    852 echo PIC_OBJC = $PIC_OBJC >> configure.log
    853 echo RANLIB = $RANLIB >> configure.log
    854 echo SFLAGS = $SFLAGS >> configure.log
    855 echo SHAREDLIB = $SHAREDLIB >> configure.log
    856 echo SHAREDLIBM = $SHAREDLIBM >> configure.log
    857 echo SHAREDLIBV = $SHAREDLIBV >> configure.log
    858 echo STATICLIB = $STATICLIB >> configure.log
    859 echo TEST = $TEST >> configure.log
    860 echo VER = $VER >> configure.log
    861 echo SRCDIR = $SRCDIR >> configure.log
    862 echo exec_prefix = $exec_prefix >> configure.log
    863 echo includedir = $includedir >> configure.log
    864 echo libdir = $libdir >> configure.log
    865 echo mandir = $mandir >> configure.log
    866 echo prefix = $prefix >> configure.log
    867 echo sharedlibdir = $sharedlibdir >> configure.log
    868 echo uname = $uname >> configure.log
    869 
    870 # update Makefile with the configure results
    871 sed < ${SRCDIR}Makefile.in "
    872 /^CC *=/s#=.*#=$CC#
    873 /^CFLAGS *=/s#=.*#=$CFLAGS#
    874 /^SFLAGS *=/s#=.*#=$SFLAGS#
    875 /^LDFLAGS *=/s#=.*#=$LDFLAGS#
    876 /^LDSHARED *=/s#=.*#=$LDSHARED#
    877 /^CPP *=/s#=.*#=$CPP#
    878 /^STATICLIB *=/s#=.*#=$STATICLIB#
    879 /^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
    880 /^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
    881 /^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
    882 /^AR *=/s#=.*#=$AR#
    883 /^ARFLAGS *=/s#=.*#=$ARFLAGS#
    884 /^RANLIB *=/s#=.*#=$RANLIB#
    885 /^LDCONFIG *=/s#=.*#=$LDCONFIG#
    886 /^LDSHAREDLIBC *=/s#=.*#=$LDSHAREDLIBC#
    887 /^EXE *=/s#=.*#=$EXE#
    888 /^SRCDIR *=/s#=.*#=$SRCDIR#
    889 /^ZINC *=/s#=.*#=$ZINC#
    890 /^ZINCOUT *=/s#=.*#=$ZINCOUT#
    891 /^prefix *=/s#=.*#=$prefix#
    892 /^exec_prefix *=/s#=.*#=$exec_prefix#
    893 /^libdir *=/s#=.*#=$libdir#
    894 /^sharedlibdir *=/s#=.*#=$sharedlibdir#
    895 /^includedir *=/s#=.*#=$includedir#
    896 /^mandir *=/s#=.*#=$mandir#
    897 /^OBJC *=/s#=.*#= $OBJC#
    898 /^PIC_OBJC *=/s#=.*#= $PIC_OBJC#
    899 /^all: */s#:.*#: $ALL#
    900 /^test: */s#:.*#: $TEST#
    901 " > Makefile
    902 
    903 # create zlib.pc with the configure results
    904 sed < ${SRCDIR}zlib.pc.in "
    905 /^CC *=/s#=.*#=$CC#
    906 /^CFLAGS *=/s#=.*#=$CFLAGS#
    907 /^CPP *=/s#=.*#=$CPP#
    908 /^LDSHARED *=/s#=.*#=$LDSHARED#
    909 /^STATICLIB *=/s#=.*#=$STATICLIB#
    910 /^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
    911 /^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
    912 /^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
    913 /^AR *=/s#=.*#=$AR#
    914 /^ARFLAGS *=/s#=.*#=$ARFLAGS#
    915 /^RANLIB *=/s#=.*#=$RANLIB#
    916 /^EXE *=/s#=.*#=$EXE#
    917 /^prefix *=/s#=.*#=$prefix#
    918 /^exec_prefix *=/s#=.*#=$exec_prefix#
    919 /^libdir *=/s#=.*#=$libdir#
    920 /^sharedlibdir *=/s#=.*#=$sharedlibdir#
    921 /^includedir *=/s#=.*#=$includedir#
    922 /^mandir *=/s#=.*#=$mandir#
    923 /^LDFLAGS *=/s#=.*#=$LDFLAGS#
    924 " | sed -e "
    925 s/\@VERSION\@/$VER/g;
    926 " > zlib.pc
    927 
    928 # done
    929 leave 0
    930