configure 26.2 KB
Newer Older
M
Mark Adler 已提交
1
#!/bin/sh
M
Mark Adler 已提交
2
# configure script for zlib.
M
Mark Adler 已提交
3
#
M
Mark Adler 已提交
4 5
# Normally configure builds both a static and a shared library.
# If you want to build just a static library, use: ./configure --static
M
Mark Adler 已提交
6
#
M
Mark Adler 已提交
7 8 9 10 11
# To impose specific compiler or flags or install directory, use for example:
#    prefix=$HOME CC=cc CFLAGS="-O4" ./configure
# or for csh/tcsh users:
#    (setenv prefix $HOME; setenv CC cc; setenv CFLAGS "-O4"; ./configure)

M
Mark Adler 已提交
12 13 14 15
# Incorrect settings of CC or CFLAGS may prevent creating a shared library.
# If you have problems, try without defining CC and CFLAGS before reporting
# an error.

M
Mark Adler 已提交
16
# start off configure.log
17 18 19 20
echo -------------------- >> configure.log
echo $0 $* >> configure.log
date >> configure.log

M
Mark Adler 已提交
21
# set command prefix for cross-compilation
M
Mark Adler 已提交
22
if [ -n "${CHOST}" ]; then
M
Mark Adler 已提交
23
    uname="`echo "${CHOST}" | sed -e 's/^[^-]*-\([^-]*\)$/\1/' -e 's/^[^-]*-[^-]*-\([^-]*\)$/\1/' -e 's/^[^-]*-[^-]*-\([^-]*\)-.*$/\1/'`"
M
Mark Adler 已提交
24 25 26
    CROSS_PREFIX="${CHOST}-"
fi

M
Mark Adler 已提交
27
# destination name for static library
M
Mark Adler 已提交
28
STATICLIB=libz.a
M
Mark Adler 已提交
29 30

# extract zlib version numbers from zlib.h
M
Mark Adler 已提交
31
VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`
M
Mark Adler 已提交
32
VER3=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\\.[0-9]*\).*/\1/p' < zlib.h`
M
Mark Adler 已提交
33 34
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`
M
Mark Adler 已提交
35 36

# establish commands for library building
M
Mark Adler 已提交
37
if "${CROSS_PREFIX}ar" --version >/dev/null 2>/dev/null || test $? -lt 126; then
M
Mark Adler 已提交
38
    AR=${AR-"${CROSS_PREFIX}ar"}
39
    test -n "${CROSS_PREFIX}" && echo Using ${AR} | tee -a configure.log
M
Mark Adler 已提交
40 41
else
    AR=${AR-"ar"}
42
    test -n "${CROSS_PREFIX}" && echo Using ${AR} | tee -a configure.log
M
Mark Adler 已提交
43
fi
44
ARFLAGS=${ARFLAGS-"rc"}
M
Mark Adler 已提交
45
if "${CROSS_PREFIX}ranlib" --version >/dev/null 2>/dev/null || test $? -lt 126; then
M
Mark Adler 已提交
46
    RANLIB=${RANLIB-"${CROSS_PREFIX}ranlib"}
47
    test -n "${CROSS_PREFIX}" && echo Using ${RANLIB} | tee -a configure.log
M
Mark Adler 已提交
48 49 50
else
    RANLIB=${RANLIB-"ranlib"}
fi
M
Mark Adler 已提交
51
if "${CROSS_PREFIX}nm" --version >/dev/null 2>/dev/null || test $? -lt 126; then
M
Mark Adler 已提交
52
    NM=${NM-"${CROSS_PREFIX}nm"}
53
    test -n "${CROSS_PREFIX}" && echo Using ${NM} | tee -a configure.log
M
Mark Adler 已提交
54 55 56
else
    NM=${NM-"nm"}
fi
M
Mark Adler 已提交
57 58

# set defaults before processing command line options
M
Mark Adler 已提交
59
LDCONFIG=${LDCONFIG-"ldconfig"}
M
Mark Adler 已提交
60
LDSHAREDLIBC="${LDSHAREDLIBC--lc}"
M
Mark Adler 已提交
61
ARCHS=
M
Mark Adler 已提交
62
prefix=${prefix-/usr/local}
M
Mark Adler 已提交
63 64
exec_prefix=${exec_prefix-'${prefix}'}
libdir=${libdir-'${exec_prefix}/lib'}
M
Mark Adler 已提交
65
sharedlibdir=${sharedlibdir-'${libdir}'}
M
Mark Adler 已提交
66
includedir=${includedir-'${prefix}/include'}
M
Mark Adler 已提交
67
mandir=${mandir-'${prefix}/share/man'}
M
Mark Adler 已提交
68
shared_ext='.so'
M
Mark Adler 已提交
69
shared=1
70
solo=0
71
cover=0
M
Mark Adler 已提交
72
zprefix=0
73
zconst=0
M
Mark Adler 已提交
74
build64=0
M
Mark Adler 已提交
75
gcc=0
M
Mark Adler 已提交
76 77
old_cc="$CC"
old_cflags="$CFLAGS"
78 79
OBJC='$(OBJZ) $(OBJG)'
PIC_OBJC='$(PIC_OBJZ) $(PIC_OBJG)'
M
Mark Adler 已提交
80

81 82 83 84 85 86 87 88 89 90 91 92 93
# 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
}

M
Mark Adler 已提交
94
# process command line options
M
Mark Adler 已提交
95 96
while test $# -ge 1
do
M
Mark Adler 已提交
97
case "$1" in
M
Mark Adler 已提交
98
    -h* | --help)
99
      echo 'usage:' | tee -a configure.log
100
      echo '  configure [--const] [--zprefix] [--prefix=PREFIX]  [--eprefix=EXPREFIX]' | tee -a configure.log
101 102
      echo '    [--static] [--64] [--libdir=LIBDIR] [--sharedlibdir=LIBDIR]' | tee -a configure.log
      echo '    [--includedir=INCLUDEDIR] [--archs="-arch i386 -arch x86_64"]' | tee -a configure.log
M
Mark Adler 已提交
103
        exit 0 ;;
M
Mark Adler 已提交
104 105 106
    -p*=* | --prefix=*) prefix=`echo $1 | sed 's/.*=//'`; shift ;;
    -e*=* | --eprefix=*) exec_prefix=`echo $1 | sed 's/.*=//'`; shift ;;
    -l*=* | --libdir=*) libdir=`echo $1 | sed 's/.*=//'`; shift ;;
M
Mark Adler 已提交
107
    --sharedlibdir=*) sharedlibdir=`echo $1 | sed 's/.*=//'`; shift ;;
M
Mark Adler 已提交
108 109
    -i*=* | --includedir=*) includedir=`echo $1 | sed 's/.*=//'`;shift ;;
    -u*=* | --uname=*) uname=`echo $1 | sed 's/.*=//'`;shift ;;
M
Mark Adler 已提交
110 111 112 113 114 115
    -p* | --prefix) prefix="$2"; shift; shift ;;
    -e* | --eprefix) exec_prefix="$2"; shift; shift ;;
    -l* | --libdir) libdir="$2"; shift; shift ;;
    -i* | --includedir) includedir="$2"; shift; shift ;;
    -s* | --shared | --enable-shared) shared=1; shift ;;
    -t | --static) shared=0; shift ;;
116
    --solo) solo=1; shift ;;
117
    --cover) cover=1; shift ;;
M
Mark Adler 已提交
118
    -z* | --zprefix) zprefix=1; shift ;;
M
Mark Adler 已提交
119
    -6* | --64) build64=1; shift ;;
M
Mark Adler 已提交
120
    -a*=* | --archs=*) ARCHS=`echo $1 | sed 's/.*=//'`; shift ;;
121 122
    --sysconfdir=*) echo "ignored option: --sysconfdir" | tee -a configure.log; shift ;;
    --localstatedir=*) echo "ignored option: --localstatedir" | tee -a configure.log; shift ;;
123
    -c* | --const) zconst=1; shift ;;
124 125 126 127
    *)
      echo "unknown option: $1" | tee -a configure.log
      echo "$0 --help for help" | tee -a configure.log
      leave 1;;
M
Mark Adler 已提交
128 129
    esac
done
M
Mark Adler 已提交
130

131
# temporary file name
M
Mark Adler 已提交
132
test=ztest$$
133

134
# put arguments in log, also put test file in log if used in arguments
135 136 137 138 139 140 141 142 143 144 145
show()
{
  case "$*" in
    *$test.c*)
      echo === $test.c === >> configure.log
      cat $test.c >> configure.log
      echo === >> configure.log;;
  esac
  echo $* >> configure.log
}

M
Mark Adler 已提交
146
# check for gcc vs. cc and set compile and link flags based on the system identified by uname
M
Mark Adler 已提交
147
cat > $test.c <<EOF
M
Mark Adler 已提交
148 149
extern int getchar();
int hello() {return getchar();}
M
Mark Adler 已提交
150
EOF
M
Mark Adler 已提交
151

152
test -z "$CC" && echo Checking for ${CROSS_PREFIX}gcc... | tee -a configure.log
M
Mark Adler 已提交
153
cc=${CC-${CROSS_PREFIX}gcc}
M
Mark Adler 已提交
154
cflags=${CFLAGS-"-O3"}
M
Mark Adler 已提交
155
# to force the asm version use: CFLAGS="-O3 -DASMV" ./configure
M
Mark Adler 已提交
156
case "$cc" in
M
Mark Adler 已提交
157
  *gcc*) gcc=1 ;;
M
Mark Adler 已提交
158
  *clang*) gcc=1 ;;
M
Mark Adler 已提交
159
esac
M
Mark Adler 已提交
160 161 162
case `$cc -v 2>&1` in
  *gcc*) gcc=1 ;;
esac
M
Mark Adler 已提交
163

164 165
show $cc -c $test.c
if test "$gcc" -eq 1 && ($cc -c $test.c) >> configure.log 2>&1; then
166
  echo ... using gcc >> configure.log
M
Mark Adler 已提交
167
  CC="$cc"
M
Mark Adler 已提交
168
  CFLAGS="${CFLAGS--O3} ${ARCHS}"
M
Mark Adler 已提交
169
  SFLAGS="${CFLAGS--O3} -fPIC"
M
Mark Adler 已提交
170
  LDFLAGS="${LDFLAGS} ${ARCHS}"
M
Mark Adler 已提交
171 172 173 174
  if test $build64 -eq 1; then
    CFLAGS="${CFLAGS} -m64"
    SFLAGS="${SFLAGS} -m64"
  fi
M
Mark Adler 已提交
175
  if test "${ZLIBGCCWARN}" = "YES"; then
176 177 178 179 180
    if test "$zconst" -eq 1; then
      CFLAGS="${CFLAGS} -Wall -Wextra -Wcast-qual -pedantic -DZLIB_CONST"
    else
      CFLAGS="${CFLAGS} -Wall -Wextra -pedantic"
    fi
M
Mark Adler 已提交
181
  fi
M
Mark Adler 已提交
182
  if test -z "$uname"; then
M
Mark Adler 已提交
183 184 185
    uname=`(uname -s || echo unknown) 2>/dev/null`
  fi
  case "$uname" in
186
  Linux* | linux* | GNU | GNU/* | solaris*)
M
Mark Adler 已提交
187
        LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map"} ;;
188 189 190
  *BSD | *bsd* | DragonFly)
        LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map"}
        LDCONFIG="ldconfig -m" ;;
M
Mark Adler 已提交
191 192
  CYGWIN* | Cygwin* | cygwin* | OS/2*)
        EXE='.exe' ;;
M
Mark Adler 已提交
193
  MINGW* | mingw*)
M
Mark Adler 已提交
194 195
# temporary bypass
        rm -f $test.[co] $test $test$shared_ext
196
        echo "Please use win32/Makefile.gcc instead." | tee -a configure.log
197
        leave 1
M
Mark Adler 已提交
198
        LDSHARED=${LDSHARED-"$cc -shared"}
M
Mark Adler 已提交
199 200
        LDSHAREDLIBC=""
        EXE='.exe' ;;
M
Mark Adler 已提交
201 202
  QNX*)  # This is for QNX6. I suppose that the QNX rule below is for QNX2,QNX4
         # (alain.bonnefoy@icbt.com)
M
Mark Adler 已提交
203
                 LDSHARED=${LDSHARED-"$cc -shared -Wl,-hlibz.so.1"} ;;
M
Mark Adler 已提交
204 205 206 207 208
  HP-UX*)
         LDSHARED=${LDSHARED-"$cc -shared $SFLAGS"}
         case `(uname -m || echo unknown) 2>/dev/null` in
         ia64)
                 shared_ext='.so'
M
Mark Adler 已提交
209
                 SHAREDLIB='libz.so' ;;
M
Mark Adler 已提交
210
         *)
M
Mark Adler 已提交
211
                 shared_ext='.sl'
M
Mark Adler 已提交
212 213
                 SHAREDLIB='libz.sl' ;;
         esac ;;
M
Mark Adler 已提交
214 215
  Darwin* | darwin*)
             shared_ext='.dylib'
M
Mark Adler 已提交
216 217 218
             SHAREDLIB=libz$shared_ext
             SHAREDLIBV=libz.$VER$shared_ext
             SHAREDLIBM=libz.$VER1$shared_ext
M
Mark Adler 已提交
219
             LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBM -compatibility_version $VER1 -current_version $VER3"}
220
             if libtool -V 2>&1 | grep Apple > /dev/null; then
221 222 223 224
                 AR="libtool"
             else
                 AR="/usr/bin/libtool"
             fi
225
             ARFLAGS="-o" ;;
M
Mark Adler 已提交
226
  *)             LDSHARED=${LDSHARED-"$cc -shared"} ;;
M
Mark Adler 已提交
227
  esac
M
Mark Adler 已提交
228 229 230
else
  # find system name and corresponding cc options
  CC=${CC-cc}
M
Mark Adler 已提交
231
  gcc=0
232
  echo ... using $CC >> configure.log
M
Mark Adler 已提交
233
  if test -z "$uname"; then
M
Mark Adler 已提交
234 235 236
    uname=`(uname -sr || echo unknown) 2>/dev/null`
  fi
  case "$uname" in
M
Mark Adler 已提交
237
  HP-UX*)    SFLAGS=${CFLAGS-"-O +z"}
M
Mark Adler 已提交
238 239 240
             CFLAGS=${CFLAGS-"-O"}
#            LDSHARED=${LDSHARED-"ld -b +vnocompatwarnings"}
             LDSHARED=${LDSHARED-"ld -b"}
M
Mark Adler 已提交
241 242 243
         case `(uname -m || echo unknown) 2>/dev/null` in
         ia64)
             shared_ext='.so'
M
Mark Adler 已提交
244
             SHAREDLIB='libz.so' ;;
M
Mark Adler 已提交
245
         *)
M
Mark Adler 已提交
246
             shared_ext='.sl'
M
Mark Adler 已提交
247 248
             SHAREDLIB='libz.sl' ;;
         esac ;;
M
Mark Adler 已提交
249
  IRIX*)     SFLAGS=${CFLAGS-"-ansi -O2 -rpath ."}
M
Mark Adler 已提交
250
             CFLAGS=${CFLAGS-"-ansi -O2"}
M
Mark Adler 已提交
251
             LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;;
M
Mark Adler 已提交
252
  OSF1\ V4*) SFLAGS=${CFLAGS-"-O -std1"}
M
Mark Adler 已提交
253
             CFLAGS=${CFLAGS-"-O -std1"}
M
Mark Adler 已提交
254 255
             LDFLAGS="${LDFLAGS} -Wl,-rpath,."
             LDSHARED=${LDSHARED-"cc -shared  -Wl,-soname,libz.so -Wl,-msym -Wl,-rpath,$(libdir) -Wl,-set_version,${VER}:1.0"} ;;
M
Mark Adler 已提交
256
  OSF1*)     SFLAGS=${CFLAGS-"-O -std1"}
M
Mark Adler 已提交
257
             CFLAGS=${CFLAGS-"-O -std1"}
M
Mark Adler 已提交
258
             LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;;
M
Mark Adler 已提交
259 260
  QNX*)      SFLAGS=${CFLAGS-"-4 -O"}
             CFLAGS=${CFLAGS-"-4 -O"}
M
Mark Adler 已提交
261
             LDSHARED=${LDSHARED-"cc"}
M
Mark Adler 已提交
262
             RANLIB=${RANLIB-"true"}
263 264
             AR="cc"
             ARFLAGS="-A" ;;
M
Mark Adler 已提交
265
  SCO_SV\ 3.2*) SFLAGS=${CFLAGS-"-O3 -dy -KPIC "}
M
Mark Adler 已提交
266
             CFLAGS=${CFLAGS-"-O3"}
M
Mark Adler 已提交
267
             LDSHARED=${LDSHARED-"cc -dy -KPIC -G"} ;;
M
Mark Adler 已提交
268
  SunOS\ 5* | solaris*)
269
         LDSHARED=${LDSHARED-"cc -G -h libz$shared_ext.$VER1"}
270
         SFLAGS=${CFLAGS-"-fast -KPIC"}
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
         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
         ;;
M
Mark Adler 已提交
291
  SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"}
M
Mark Adler 已提交
292
             CFLAGS=${CFLAGS-"-O2"}
M
Mark Adler 已提交
293
             LDSHARED=${LDSHARED-"ld"} ;;
M
Mark Adler 已提交
294 295
  SunStudio\ 9*) SFLAGS=${CFLAGS-"-fast -xcode=pic32 -xtarget=ultra3 -xarch=v9b"}
             CFLAGS=${CFLAGS-"-fast -xtarget=ultra3 -xarch=v9b"}
M
Mark Adler 已提交
296
             LDSHARED=${LDSHARED-"cc -xarch=v9b"} ;;
M
Mark Adler 已提交
297 298 299
  UNIX_System_V\ 4.2.0)
             SFLAGS=${CFLAGS-"-KPIC -O"}
             CFLAGS=${CFLAGS-"-O"}
M
Mark Adler 已提交
300
             LDSHARED=${LDSHARED-"cc -G"} ;;
M
Mark Adler 已提交
301
  UNIX_SV\ 4.2MP)
M
Mark Adler 已提交
302 303
             SFLAGS=${CFLAGS-"-Kconform_pic -O"}
             CFLAGS=${CFLAGS-"-O"}
M
Mark Adler 已提交
304
             LDSHARED=${LDSHARED-"cc -G"} ;;
M
Mark Adler 已提交
305 306 307
  OpenUNIX\ 5)
             SFLAGS=${CFLAGS-"-KPIC -O"}
             CFLAGS=${CFLAGS-"-O"}
M
Mark Adler 已提交
308
             LDSHARED=${LDSHARED-"cc -G"} ;;
M
Mark Adler 已提交
309
  AIX*)  # Courtesy of dbakker@arrayasolutions.com
M
Mark Adler 已提交
310 311
             SFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
             CFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
M
Mark Adler 已提交
312
             LDSHARED=${LDSHARED-"xlc -G"} ;;
M
Mark Adler 已提交
313
  # send working options for other systems to zlib@gzip.org
M
Mark Adler 已提交
314
  *)         SFLAGS=${CFLAGS-"-O"}
M
Mark Adler 已提交
315
             CFLAGS=${CFLAGS-"-O"}
M
Mark Adler 已提交
316
             LDSHARED=${LDSHARED-"cc -shared"} ;;
M
Mark Adler 已提交
317 318 319
  esac
fi

M
Mark Adler 已提交
320
# destination names for shared library if not defined above
M
Mark Adler 已提交
321 322 323 324
SHAREDLIB=${SHAREDLIB-"libz$shared_ext"}
SHAREDLIBV=${SHAREDLIBV-"libz$shared_ext.$VER"}
SHAREDLIBM=${SHAREDLIBM-"libz$shared_ext.$VER1"}

325 326
echo >> configure.log

327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
# 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

M
Mark Adler 已提交
375
# see if shared library build supported
376 377 378 379
cat > $test.c <<EOF
extern int getchar();
int hello() {return getchar();}
EOF
M
Mark Adler 已提交
380
if test $shared -eq 1; then
381
  echo Checking for shared library support... | tee -a configure.log
M
Mark Adler 已提交
382
  # we must test in two steps (cc then ld), required at least on SunOS 4.x
383 384
  if try $CC -w -c $SFLAGS $test.c &&
     try $LDSHARED $SFLAGS -o $test$shared_ext $test.o; then
385
    echo Building shared library $SHAREDLIBV with $CC. | tee -a configure.log
M
Mark Adler 已提交
386
  elif test -z "$old_cc" -a -z "$old_cflags"; then
387
    echo No shared library support. | tee -a configure.log
M
Mark Adler 已提交
388
    shared=0;
M
Mark Adler 已提交
389
  else
390
    echo 'No shared library support; try without defining CC and CFLAGS' | tee -a configure.log
M
Mark Adler 已提交
391
    shared=0;
M
Mark Adler 已提交
392 393 394
  fi
fi
if test $shared -eq 0; then
M
Mark Adler 已提交
395
  LDSHARED="$CC"
M
Mark Adler 已提交
396 397
  ALL="static"
  TEST="all teststatic"
M
Mark Adler 已提交
398 399 400
  SHAREDLIB=""
  SHAREDLIBV=""
  SHAREDLIBM=""
401
  echo Building static library $STATICLIB version $VER with $CC. | tee -a configure.log
M
Mark Adler 已提交
402
else
M
Mark Adler 已提交
403 404
  ALL="static shared"
  TEST="all teststatic testshared"
M
Mark Adler 已提交
405 406
fi

M
Mark Adler 已提交
407
# check for underscores in external names for use by assembler code
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
CPP=${CPP-"$CC -E"}
case $CFLAGS in
  *ASMV*)
    echo >> configure.log
    show "$NM $test.o | grep _hello"
    if test "`$NM $test.o | grep _hello | tee -a configure.log`" = ""; then
      CPP="$CPP -DNO_UNDERLINE"
      echo Checking for underline in external names... No. | tee -a configure.log
    else
      echo Checking for underline in external names... Yes. | tee -a configure.log
    fi ;;
esac

echo >> configure.log

M
Mark Adler 已提交
423
# check for large file support, and if none, check for fseeko()
M
Mark Adler 已提交
424 425 426 427
cat > $test.c <<EOF
#include <sys/types.h>
off64_t dummy = 0;
EOF
428
if try $CC -c $CFLAGS -D_LARGEFILE64_SOURCE=1 $test.c; then
M
Mark Adler 已提交
429 430
  CFLAGS="${CFLAGS} -D_LARGEFILE64_SOURCE=1"
  SFLAGS="${SFLAGS} -D_LARGEFILE64_SOURCE=1"
M
Mark Adler 已提交
431 432
  ALL="${ALL} all64"
  TEST="${TEST} test64"
433 434
  echo "Checking for off64_t... Yes." | tee -a configure.log
  echo "Checking for fseeko... Yes." | tee -a configure.log
M
Mark Adler 已提交
435
else
436 437
  echo "Checking for off64_t... No." | tee -a configure.log
  echo >> configure.log
M
Mark Adler 已提交
438 439 440 441 442 443 444
  cat > $test.c <<EOF
#include <stdio.h>
int main(void) {
  fseeko(NULL, 0, 0);
  return 0;
}
EOF
445
  if try $CC $CFLAGS -o $test $test.c; then
446
    echo "Checking for fseeko... Yes." | tee -a configure.log
M
Mark Adler 已提交
447 448 449
  else
    CFLAGS="${CFLAGS} -DNO_FSEEKO"
    SFLAGS="${SFLAGS} -DNO_FSEEKO"
450
    echo "Checking for fseeko... No." | tee -a configure.log
M
Mark Adler 已提交
451
  fi
M
Mark Adler 已提交
452
fi
M
Mark Adler 已提交
453

M
Mark Adler 已提交
454 455
echo >> configure.log

M
Mark Adler 已提交
456
# check for strerror() for use by gz* functions
M
Mark Adler 已提交
457 458 459 460 461 462 463 464 465 466 467 468 469
cat > $test.c <<EOF
#include <string.h>
#include <errno.h>
int main() { return strlen(strerror(errno)); }
EOF
if try $CC $CFLAGS -o $test $test.c; then
  echo "Checking for strerror... Yes." | tee -a configure.log
else
  CFLAGS="${CFLAGS} -DNO_STRERROR"
  SFLAGS="${SFLAGS} -DNO_STRERROR"
  echo "Checking for strerror... No." | tee -a configure.log
fi

M
Mark Adler 已提交
470
# copy clean zconf.h for subsequent edits
M
Mark Adler 已提交
471
cp -p zconf.h.in zconf.h
M
Mark Adler 已提交
472

473 474
echo >> configure.log

M
Mark Adler 已提交
475
# check for unistd.h and save result in zconf.h
M
Mark Adler 已提交
476 477 478 479
cat > $test.c <<EOF
#include <unistd.h>
int main() { return 0; }
EOF
480
if try $CC -c $CFLAGS $test.c; then
M
Mark Adler 已提交
481
  sed < zconf.h "/^#ifdef HAVE_UNISTD_H.* may be/s/def HAVE_UNISTD_H\(.*\) may be/ 1\1 was/" > zconf.temp.h
M
Mark Adler 已提交
482
  mv zconf.temp.h zconf.h
483
  echo "Checking for unistd.h... Yes." | tee -a configure.log
M
Mark Adler 已提交
484
else
485
  echo "Checking for unistd.h... No." | tee -a configure.log
M
Mark Adler 已提交
486 487
fi

488 489
echo >> configure.log

M
Mark Adler 已提交
490
# check for stdarg.h and save result in zconf.h
M
Mark Adler 已提交
491 492 493 494
cat > $test.c <<EOF
#include <stdarg.h>
int main() { return 0; }
EOF
495
if try $CC -c $CFLAGS $test.c; then
M
Mark Adler 已提交
496 497
  sed < zconf.h "/^#ifdef HAVE_STDARG_H.* may be/s/def HAVE_STDARG_H\(.*\) may be/ 1\1 was/" > zconf.temp.h
  mv zconf.temp.h zconf.h
498
  echo "Checking for stdarg.h... Yes." | tee -a configure.log
M
Mark Adler 已提交
499
else
500
  echo "Checking for stdarg.h... No." | tee -a configure.log
M
Mark Adler 已提交
501 502
fi

M
Mark Adler 已提交
503
# if the z_ prefix was requested, save that in zconf.h
M
Mark Adler 已提交
504
if test $zprefix -eq 1; then
M
Mark Adler 已提交
505
  sed < zconf.h "/#ifdef Z_PREFIX.* may be/s/def Z_PREFIX\(.*\) may be/ 1\1 was/" > zconf.temp.h
M
Mark Adler 已提交
506
  mv zconf.temp.h zconf.h
507 508
  echo >> configure.log
  echo "Using z_ prefix on all symbols." | tee -a configure.log
M
Mark Adler 已提交
509 510
fi

M
Mark Adler 已提交
511
# if --solo compilation was requested, save that in zconf.h and remove gz stuff from object lists
512 513 514 515 516 517 518 519 520 521
if test $solo -eq 1; then
  sed '/#define ZCONF_H/a\
#define Z_SOLO

' < zconf.h > zconf.temp.h
  mv zconf.temp.h zconf.h
OBJC='$(OBJZ)'
PIC_OBJC='$(PIC_OBJZ)'
fi

M
Mark Adler 已提交
522
# if code coverage testing was requested, use older gcc if defined, e.g. "gcc-4.2" on Mac OS X
523 524
if test $cover -eq 1; then
  CFLAGS="${CFLAGS} -fprofile-arcs -ftest-coverage"
525 526 527
  if test -n "$GCC_CLASSIC"; then
    CC=$GCC_CLASSIC
  fi
528 529
fi

530 531
echo >> configure.log

M
Mark Adler 已提交
532 533 534 535
# 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.
M
Mark Adler 已提交
536
cat > $test.c <<EOF
M
Mark Adler 已提交
537
#include <stdio.h>
M
Mark Adler 已提交
538 539
#include <stdarg.h>
#include "zconf.h"
M
Mark Adler 已提交
540
int main()
M
Mark Adler 已提交
541 542 543 544 545 546 547
{
#ifndef STDC
  choke me
#endif
  return 0;
}
EOF
548
if try $CC -c $CFLAGS $test.c; then
549
  echo "Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf()." | tee -a configure.log
M
Mark Adler 已提交
550

551
  echo >> configure.log
M
Mark Adler 已提交
552 553 554
  cat > $test.c <<EOF
#include <stdio.h>
#include <stdarg.h>
M
Mark Adler 已提交
555
int mytest(const char *fmt, ...)
M
Mark Adler 已提交
556 557 558 559 560 561 562 563 564 565 566 567 568
{
  char buf[20];
  va_list ap;
  va_start(ap, fmt);
  vsnprintf(buf, sizeof(buf), fmt, ap);
  va_end(ap);
  return 0;
}
int main()
{
  return (mytest("Hello%d\n", 1));
}
EOF
569
  if try $CC $CFLAGS -o $test $test.c; then
570
    echo "Checking for vsnprintf() in stdio.h... Yes." | tee -a configure.log
M
Mark Adler 已提交
571

572
    echo >> configure.log
M
Mark Adler 已提交
573 574 575
    cat >$test.c <<EOF
#include <stdio.h>
#include <stdarg.h>
M
Mark Adler 已提交
576
int mytest(const char *fmt, ...)
M
Mark Adler 已提交
577
{
M
Mark Adler 已提交
578
  int n;
M
Mark Adler 已提交
579 580 581
  char buf[20];
  va_list ap;
  va_start(ap, fmt);
M
Mark Adler 已提交
582
  n = vsnprintf(buf, sizeof(buf), fmt, ap);
M
Mark Adler 已提交
583
  va_end(ap);
M
Mark Adler 已提交
584
  return n;
M
Mark Adler 已提交
585 586 587 588 589 590 591
}
int main()
{
  return (mytest("Hello%d\n", 1));
}
EOF

592
    if try $CC -c $CFLAGS $test.c; then
593
      echo "Checking for return value of vsnprintf()... Yes." | tee -a configure.log
M
Mark Adler 已提交
594 595
    else
      CFLAGS="$CFLAGS -DHAS_vsnprintf_void"
M
Mark Adler 已提交
596
      SFLAGS="$SFLAGS -DHAS_vsnprintf_void"
597 598 599 600
      echo "Checking for return value of vsnprintf()... No." | tee -a configure.log
      echo "  WARNING: apparently vsnprintf() does not return a value. zlib" | tee -a configure.log
      echo "  can build but will be open to possible string-format security" | tee -a configure.log
      echo "  vulnerabilities." | tee -a configure.log
M
Mark Adler 已提交
601 602 603
    fi
  else
    CFLAGS="$CFLAGS -DNO_vsnprintf"
M
Mark Adler 已提交
604
    SFLAGS="$SFLAGS -DNO_vsnprintf"
605 606 607 608
    echo "Checking for vsnprintf() in stdio.h... No." | tee -a configure.log
    echo "  WARNING: vsnprintf() not found, falling back to vsprintf(). zlib" | tee -a configure.log
    echo "  can build but will be open to possible buffer-overflow security" | tee -a configure.log
    echo "  vulnerabilities." | tee -a configure.log
M
Mark Adler 已提交
609

610
    echo >> configure.log
M
Mark Adler 已提交
611 612 613
    cat >$test.c <<EOF
#include <stdio.h>
#include <stdarg.h>
M
Mark Adler 已提交
614
int mytest(const char *fmt, ...)
M
Mark Adler 已提交
615
{
M
Mark Adler 已提交
616
  int n;
M
Mark Adler 已提交
617 618 619
  char buf[20];
  va_list ap;
  va_start(ap, fmt);
M
Mark Adler 已提交
620
  n = vsprintf(buf, fmt, ap);
M
Mark Adler 已提交
621
  va_end(ap);
M
Mark Adler 已提交
622
  return n;
M
Mark Adler 已提交
623
}
M
Mark Adler 已提交
624
int main()
M
Mark Adler 已提交
625 626 627 628 629
{
  return (mytest("Hello%d\n", 1));
}
EOF

630
    if try $CC -c $CFLAGS $test.c; then
631
      echo "Checking for return value of vsprintf()... Yes." | tee -a configure.log
M
Mark Adler 已提交
632 633
    else
      CFLAGS="$CFLAGS -DHAS_vsprintf_void"
M
Mark Adler 已提交
634
      SFLAGS="$SFLAGS -DHAS_vsprintf_void"
635 636 637 638
      echo "Checking for return value of vsprintf()... No." | tee -a configure.log
      echo "  WARNING: apparently vsprintf() does not return a value. zlib" | tee -a configure.log
      echo "  can build but will be open to possible string-format security" | tee -a configure.log
      echo "  vulnerabilities." | tee -a configure.log
M
Mark Adler 已提交
639 640 641
    fi
  fi
else
642
  echo "Checking whether to use vs[n]printf() or s[n]printf()... using s[n]printf()." | tee -a configure.log
M
Mark Adler 已提交
643

644
  echo >> configure.log
M
Mark Adler 已提交
645 646
  cat >$test.c <<EOF
#include <stdio.h>
M
Mark Adler 已提交
647
int mytest()
M
Mark Adler 已提交
648 649 650 651 652
{
  char buf[20];
  snprintf(buf, sizeof(buf), "%s", "foo");
  return 0;
}
M
Mark Adler 已提交
653
int main()
M
Mark Adler 已提交
654 655 656 657 658
{
  return (mytest());
}
EOF

659
  if try $CC $CFLAGS -o $test $test.c; then
660
    echo "Checking for snprintf() in stdio.h... Yes." | tee -a configure.log
M
Mark Adler 已提交
661

662
    echo >> configure.log
M
Mark Adler 已提交
663 664
    cat >$test.c <<EOF
#include <stdio.h>
M
Mark Adler 已提交
665
int mytest()
M
Mark Adler 已提交
666 667
{
  char buf[20];
M
Mark Adler 已提交
668
  return snprintf(buf, sizeof(buf), "%s", "foo");
M
Mark Adler 已提交
669
}
M
Mark Adler 已提交
670
int main()
M
Mark Adler 已提交
671 672 673 674 675
{
  return (mytest());
}
EOF

676
    if try $CC -c $CFLAGS $test.c; then
677
      echo "Checking for return value of snprintf()... Yes." | tee -a configure.log
M
Mark Adler 已提交
678 679
    else
      CFLAGS="$CFLAGS -DHAS_snprintf_void"
M
Mark Adler 已提交
680
      SFLAGS="$SFLAGS -DHAS_snprintf_void"
681 682 683 684
      echo "Checking for return value of snprintf()... No." | tee -a configure.log
      echo "  WARNING: apparently snprintf() does not return a value. zlib" | tee -a configure.log
      echo "  can build but will be open to possible string-format security" | tee -a configure.log
      echo "  vulnerabilities." | tee -a configure.log
M
Mark Adler 已提交
685 686 687
    fi
  else
    CFLAGS="$CFLAGS -DNO_snprintf"
M
Mark Adler 已提交
688
    SFLAGS="$SFLAGS -DNO_snprintf"
689 690 691 692
    echo "Checking for snprintf() in stdio.h... No." | tee -a configure.log
    echo "  WARNING: snprintf() not found, falling back to sprintf(). zlib" | tee -a configure.log
    echo "  can build but will be open to possible buffer-overflow security" | tee -a configure.log
    echo "  vulnerabilities." | tee -a configure.log
M
Mark Adler 已提交
693

694
    echo >> configure.log
M
Mark Adler 已提交
695 696
    cat >$test.c <<EOF
#include <stdio.h>
M
Mark Adler 已提交
697
int mytest()
M
Mark Adler 已提交
698 699
{
  char buf[20];
M
Mark Adler 已提交
700
  return sprintf(buf, "%s", "foo");
M
Mark Adler 已提交
701
}
M
Mark Adler 已提交
702
int main()
M
Mark Adler 已提交
703 704 705 706 707
{
  return (mytest());
}
EOF

708
    if try $CC -c $CFLAGS $test.c; then
709
      echo "Checking for return value of sprintf()... Yes." | tee -a configure.log
M
Mark Adler 已提交
710 711
    else
      CFLAGS="$CFLAGS -DHAS_sprintf_void"
M
Mark Adler 已提交
712
      SFLAGS="$SFLAGS -DHAS_sprintf_void"
713 714 715 716
      echo "Checking for return value of sprintf()... No." | tee -a configure.log
      echo "  WARNING: apparently sprintf() does not return a value. zlib" | tee -a configure.log
      echo "  can build but will be open to possible string-format security" | tee -a configure.log
      echo "  vulnerabilities." | tee -a configure.log
M
Mark Adler 已提交
717 718 719 720
    fi
  fi
fi

M
Mark Adler 已提交
721
# see if we can hide zlib internal symbols that are linked between separate source files
M
Mark Adler 已提交
722
if test "$gcc" -eq 1; then
723
  echo >> configure.log
M
Mark Adler 已提交
724
  cat > $test.c <<EOF
725
#define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
M
Mark Adler 已提交
726
int ZLIB_INTERNAL foo;
M
Mark Adler 已提交
727 728 729 730 731
int main()
{
  return 0;
}
EOF
732
  if tryboth $CC -c $CFLAGS $test.c; then
733 734
    CFLAGS="$CFLAGS -DHAVE_HIDDEN"
    SFLAGS="$SFLAGS -DHAVE_HIDDEN"
735
    echo "Checking for attribute(visibility) support... Yes." | tee -a configure.log
M
Mark Adler 已提交
736
  else
737
    echo "Checking for attribute(visibility) support... No." | tee -a configure.log
M
Mark Adler 已提交
738
  fi
M
Mark Adler 已提交
739 740
fi

741 742 743 744 745 746 747
echo >> configure.log

# find a four-byte unsiged integer type for crc calculations
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() {
748 749 750 751 752 753 754 755
  int k;
  unsigned i;
  unsigned long l;
  unsigned short s;
  is32(i, "unsigned")
  is32(l, "unsigned long")
  is32(s, "unsigned short")
  return 1;
756 757 758
}
EOF
Z_U4=""
759
if try $CC $CFLAGS $test.c -o $test && Z_U4=`./$test` && test -n "$Z_U4"; then
760 761 762 763 764 765 766
  sed < zconf.h "/#define Z_U4/s/\/\* \.\/configure may/#define Z_U4 $Z_U4   \/* .\/configure put the/" > zconf.temp.h
  mv zconf.temp.h zconf.h
  echo "Looking for a four-byte integer type... Found." | tee -a configure.log
else
  echo "Looking for a four-byte integer type... Not found." | tee -a configure.log
fi

767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789
# show the results in the log
echo >> configure.log
echo ALL = $ALL >> configure.log
echo AR = $AR >> configure.log
echo ARFLAGS = $ARFLAGS >> configure.log
echo CC = $CC >> configure.log
echo CFLAGS = $CFLAGS >> configure.log
echo CPP = $CPP >> configure.log
echo EXE = $EXE >> configure.log
echo LDCONFIG = $LDCONFIG >> configure.log
echo LDFLAGS = $LDFLAGS >> configure.log
echo LDSHARED = $LDSHARED >> configure.log
echo LDSHAREDLIBC = $LDSHAREDLIBC >> configure.log
echo OBJC = $OBJC >> configure.log
echo PIC_OBJC = $PIC_OBJC >> configure.log
echo RANLIB = $RANLIB >> configure.log
echo SFLAGS = $SFLAGS >> configure.log
echo SHAREDLIB = $SHAREDLIB >> configure.log
echo SHAREDLIBM = $SHAREDLIBM >> configure.log
echo SHAREDLIBV = $SHAREDLIBV >> configure.log
echo STATICLIB = $STATICLIB >> configure.log
echo TEST = $TEST >> configure.log
echo VER = $VER >> configure.log
790
echo Z_U4 = $Z_U4 >> configure.log
791 792 793 794 795 796 797 798
echo exec_prefix = $exec_prefix >> configure.log
echo includedir = $includedir >> configure.log
echo libdir = $libdir >> configure.log
echo mandir = $mandir >> configure.log
echo prefix = $prefix >> configure.log
echo sharedlibdir = $sharedlibdir >> configure.log
echo uname = $uname >> configure.log

M
Mark Adler 已提交
799
# udpate Makefile with the configure results
M
Mark Adler 已提交
800
sed < Makefile.in "
M
Mark Adler 已提交
801 802
/^CC *=/s#=.*#=$CC#
/^CFLAGS *=/s#=.*#=$CFLAGS#
M
Mark Adler 已提交
803
/^SFLAGS *=/s#=.*#=$SFLAGS#
M
Mark Adler 已提交
804
/^LDFLAGS *=/s#=.*#=$LDFLAGS#
M
Mark Adler 已提交
805
/^LDSHARED *=/s#=.*#=$LDSHARED#
M
Mark Adler 已提交
806
/^CPP *=/s#=.*#=$CPP#
M
Mark Adler 已提交
807
/^STATICLIB *=/s#=.*#=$STATICLIB#
M
Mark Adler 已提交
808 809 810
/^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
/^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
/^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
811 812
/^AR *=/s#=.*#=$AR#
/^ARFLAGS *=/s#=.*#=$ARFLAGS#
M
Mark Adler 已提交
813
/^RANLIB *=/s#=.*#=$RANLIB#
M
Mark Adler 已提交
814 815
/^LDCONFIG *=/s#=.*#=$LDCONFIG#
/^LDSHAREDLIBC *=/s#=.*#=$LDSHAREDLIBC#
M
Mark Adler 已提交
816
/^EXE *=/s#=.*#=$EXE#
M
Mark Adler 已提交
817 818 819
/^prefix *=/s#=.*#=$prefix#
/^exec_prefix *=/s#=.*#=$exec_prefix#
/^libdir *=/s#=.*#=$libdir#
M
Mark Adler 已提交
820
/^sharedlibdir *=/s#=.*#=$sharedlibdir#
M
Mark Adler 已提交
821 822
/^includedir *=/s#=.*#=$includedir#
/^mandir *=/s#=.*#=$mandir#
823 824
/^OBJC *=/s#=.*#= $OBJC#
/^PIC_OBJC *=/s#=.*#= $PIC_OBJC#
M
Mark Adler 已提交
825 826
/^all: */s#:.*#: $ALL#
/^test: */s#:.*#: $TEST#
M
Mark Adler 已提交
827
" > Makefile
M
Mark Adler 已提交
828

M
Mark Adler 已提交
829
# create zlib.pc with the configure results
M
Mark Adler 已提交
830 831 832 833 834
sed < zlib.pc.in "
/^CC *=/s#=.*#=$CC#
/^CFLAGS *=/s#=.*#=$CFLAGS#
/^CPP *=/s#=.*#=$CPP#
/^LDSHARED *=/s#=.*#=$LDSHARED#
M
Mark Adler 已提交
835
/^STATICLIB *=/s#=.*#=$STATICLIB#
M
Mark Adler 已提交
836 837 838
/^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
/^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
/^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
839 840
/^AR *=/s#=.*#=$AR#
/^ARFLAGS *=/s#=.*#=$ARFLAGS#
M
Mark Adler 已提交
841 842 843 844 845
/^RANLIB *=/s#=.*#=$RANLIB#
/^EXE *=/s#=.*#=$EXE#
/^prefix *=/s#=.*#=$prefix#
/^exec_prefix *=/s#=.*#=$exec_prefix#
/^libdir *=/s#=.*#=$libdir#
M
Mark Adler 已提交
846
/^sharedlibdir *=/s#=.*#=$sharedlibdir#
M
Mark Adler 已提交
847 848 849 850 851 852
/^includedir *=/s#=.*#=$includedir#
/^mandir *=/s#=.*#=$mandir#
/^LDFLAGS *=/s#=.*#=$LDFLAGS#
" | sed -e "
s/\@VERSION\@/$VER/g;
" > zlib.pc
853 854 855

# done
leave 0