configure 22.3 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.

16 17 18 19
echo -------------------- >> configure.log
echo $0 $* >> configure.log
date >> configure.log

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

M
Mark Adler 已提交
25
STATICLIB=libz.a
M
Mark Adler 已提交
26
VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`
M
Mark Adler 已提交
27
VER3=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\\.[0-9]*\).*/\1/p' < zlib.h`
M
Mark Adler 已提交
28 29
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 已提交
30
if "${CROSS_PREFIX}ar" --version >/dev/null 2>/dev/null || test $? -lt 126; then
M
Mark Adler 已提交
31
    AR=${AR-"${CROSS_PREFIX}ar"}
32
    test -n "${CROSS_PREFIX}" && echo Using ${AR} | tee -a configure.log
M
Mark Adler 已提交
33 34
else
    AR=${AR-"ar"}
35
    test -n "${CROSS_PREFIX}" && echo Using ${AR} | tee -a configure.log
M
Mark Adler 已提交
36
fi
37
ARFLAGS=${ARFLAGS-"rc"}
M
Mark Adler 已提交
38
if "${CROSS_PREFIX}ranlib" --version >/dev/null 2>/dev/null || test $? -lt 126; then
M
Mark Adler 已提交
39
    RANLIB=${RANLIB-"${CROSS_PREFIX}ranlib"}
40
    test -n "${CROSS_PREFIX}" && echo Using ${RANLIB} | tee -a configure.log
M
Mark Adler 已提交
41 42 43
else
    RANLIB=${RANLIB-"ranlib"}
fi
M
Mark Adler 已提交
44
if "${CROSS_PREFIX}nm" --version >/dev/null 2>/dev/null || test $? -lt 126; then
M
Mark Adler 已提交
45
    NM=${NM-"${CROSS_PREFIX}nm"}
46
    test -n "${CROSS_PREFIX}" && echo Using ${NM} | tee -a configure.log
M
Mark Adler 已提交
47 48 49
else
    NM=${NM-"nm"}
fi
M
Mark Adler 已提交
50
LDCONFIG=${LDCONFIG-"ldconfig"}
M
Mark Adler 已提交
51
LDSHAREDLIBC="${LDSHAREDLIBC--lc}"
M
Mark Adler 已提交
52
ARCHS=
M
Mark Adler 已提交
53
prefix=${prefix-/usr/local}
M
Mark Adler 已提交
54 55
exec_prefix=${exec_prefix-'${prefix}'}
libdir=${libdir-'${exec_prefix}/lib'}
M
Mark Adler 已提交
56
sharedlibdir=${sharedlibdir-'${libdir}'}
M
Mark Adler 已提交
57
includedir=${includedir-'${prefix}/include'}
M
Mark Adler 已提交
58
mandir=${mandir-'${prefix}/share/man'}
M
Mark Adler 已提交
59
shared_ext='.so'
M
Mark Adler 已提交
60
shared=1
61
solo=0
62
cover=0
M
Mark Adler 已提交
63
zprefix=0
M
Mark Adler 已提交
64
build64=0
M
Mark Adler 已提交
65
gcc=0
M
Mark Adler 已提交
66 67
old_cc="$CC"
old_cflags="$CFLAGS"
68 69
OBJC='$(OBJZ) $(OBJG)'
PIC_OBJC='$(PIC_OBJZ) $(PIC_OBJG)'
M
Mark Adler 已提交
70

M
Mark Adler 已提交
71 72
while test $# -ge 1
do
M
Mark Adler 已提交
73
case "$1" in
M
Mark Adler 已提交
74
    -h* | --help)
75 76 77 78
      echo 'usage:' | tee -a configure.log
      echo '  configure [--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
M
Mark Adler 已提交
79
        exit 0 ;;
M
Mark Adler 已提交
80 81 82
    -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 已提交
83
    --sharedlibdir=*) sharedlibdir=`echo $1 | sed 's/.*=//'`; shift ;;
M
Mark Adler 已提交
84 85
    -i*=* | --includedir=*) includedir=`echo $1 | sed 's/.*=//'`;shift ;;
    -u*=* | --uname=*) uname=`echo $1 | sed 's/.*=//'`;shift ;;
M
Mark Adler 已提交
86 87 88 89 90 91
    -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 ;;
92
    --solo) solo=1; shift ;;
93
    --cover) cover=1; shift ;;
M
Mark Adler 已提交
94
    -z* | --zprefix) zprefix=1; shift ;;
M
Mark Adler 已提交
95
    -6* | --64) build64=1; shift ;;
M
Mark Adler 已提交
96
    -a*=* | --archs=*) ARCHS=`echo $1 | sed 's/.*=//'`; shift ;;
97 98 99
    --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 ;;
M
Mark Adler 已提交
100 101
    esac
done
M
Mark Adler 已提交
102 103

test=ztest$$
104

105 106 107 108 109 110 111 112 113 114 115
show()
{
  case "$*" in
    *$test.c*)
      echo === $test.c === >> configure.log
      cat $test.c >> configure.log
      echo === >> configure.log;;
  esac
  echo $* >> configure.log
}

116 117 118 119 120 121
cat > $test.c <<EOF
#error error
EOF
if ($CC -c $CFLAGS $test.c) 2>/dev/null; then
  try()
  {
122 123
    show $*
    test "`( $* ) 2>&1 | tee -a configure.log`" = ""
124
  }
125
  echo - using any output from compiler to indicate an error >> configure.log
126 127 128
else
  try()
  {
129 130 131 132 133 134 135
    show $*
    ( $* ) >> configure.log 2>&1
    ret=$?
    if test $ret -ne 0; then
      echo "(exit code "$ret")" >> configure.log
    fi
    return $ret
136 137 138
  }
fi

139 140 141 142 143 144 145 146 147 148 149 150
tryboth()
{
  show $*
  got=`( $* ) 2>&1`
  ret=$?
  printf %s "$got" >> configure.log
  if test $ret -ne 0; then
    return $ret
  fi
  test "$got" = ""
}

151 152
echo >> configure.log

M
Mark Adler 已提交
153
cat > $test.c <<EOF
M
Mark Adler 已提交
154 155
extern int getchar();
int hello() {return getchar();}
M
Mark Adler 已提交
156
EOF
M
Mark Adler 已提交
157

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

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

M
Mark Adler 已提交
304 305 306 307
SHAREDLIB=${SHAREDLIB-"libz$shared_ext"}
SHAREDLIBV=${SHAREDLIBV-"libz$shared_ext.$VER"}
SHAREDLIBM=${SHAREDLIBM-"libz$shared_ext.$VER1"}

308 309
echo >> configure.log

M
Mark Adler 已提交
310
if test $shared -eq 1; then
311
  echo Checking for shared library support... | tee -a configure.log
M
Mark Adler 已提交
312
  # we must test in two steps (cc then ld), required at least on SunOS 4.x
313 314
  if try $CC -w -c $SFLAGS $test.c &&
     try $LDSHARED $SFLAGS -o $test$shared_ext $test.o; then
315
    echo Building shared library $SHAREDLIBV with $CC. | tee -a configure.log
M
Mark Adler 已提交
316
  elif test -z "$old_cc" -a -z "$old_cflags"; then
317
    echo No shared library support. | tee -a configure.log
M
Mark Adler 已提交
318
    shared=0;
M
Mark Adler 已提交
319
  else
320
    echo 'No shared library support; try without defining CC and CFLAGS' | tee -a configure.log
M
Mark Adler 已提交
321
    shared=0;
M
Mark Adler 已提交
322 323 324
  fi
fi
if test $shared -eq 0; then
M
Mark Adler 已提交
325
  LDSHARED="$CC"
M
Mark Adler 已提交
326 327
  ALL="static"
  TEST="all teststatic"
M
Mark Adler 已提交
328 329 330
  SHAREDLIB=""
  SHAREDLIBV=""
  SHAREDLIBM=""
331
  echo Building static library $STATICLIB version $VER with $CC. | tee -a configure.log
M
Mark Adler 已提交
332
else
M
Mark Adler 已提交
333 334
  ALL="static shared"
  TEST="all teststatic testshared"
M
Mark Adler 已提交
335 336
fi

337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
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 已提交
352 353 354 355
cat > $test.c <<EOF
#include <sys/types.h>
off64_t dummy = 0;
EOF
356
if try $CC -c $CFLAGS -D_LARGEFILE64_SOURCE=1 $test.c; then
M
Mark Adler 已提交
357 358
  CFLAGS="${CFLAGS} -D_LARGEFILE64_SOURCE=1"
  SFLAGS="${SFLAGS} -D_LARGEFILE64_SOURCE=1"
M
Mark Adler 已提交
359 360
  ALL="${ALL} all64"
  TEST="${TEST} test64"
361 362
  echo "Checking for off64_t... Yes." | tee -a configure.log
  echo "Checking for fseeko... Yes." | tee -a configure.log
M
Mark Adler 已提交
363
else
364 365
  echo "Checking for off64_t... No." | tee -a configure.log
  echo >> configure.log
M
Mark Adler 已提交
366 367 368 369 370 371 372
  cat > $test.c <<EOF
#include <stdio.h>
int main(void) {
  fseeko(NULL, 0, 0);
  return 0;
}
EOF
373
  if try $CC $CFLAGS -o $test $test.c; then
374
    echo "Checking for fseeko... Yes." | tee -a configure.log
M
Mark Adler 已提交
375 376 377
  else
    CFLAGS="${CFLAGS} -DNO_FSEEKO"
    SFLAGS="${SFLAGS} -DNO_FSEEKO"
378
    echo "Checking for fseeko... No." | tee -a configure.log
M
Mark Adler 已提交
379
  fi
M
Mark Adler 已提交
380
fi
M
Mark Adler 已提交
381

M
Mark Adler 已提交
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
echo >> configure.log

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 已提交
397
cp -p zconf.h.in zconf.h
M
Mark Adler 已提交
398

399 400
echo >> configure.log

M
Mark Adler 已提交
401 402 403 404
cat > $test.c <<EOF
#include <unistd.h>
int main() { return 0; }
EOF
405
if try $CC -c $CFLAGS $test.c; then
M
Mark Adler 已提交
406
  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 已提交
407
  mv zconf.temp.h zconf.h
408
  echo "Checking for unistd.h... Yes." | tee -a configure.log
M
Mark Adler 已提交
409
else
410
  echo "Checking for unistd.h... No." | tee -a configure.log
M
Mark Adler 已提交
411 412
fi

413 414
echo >> configure.log

M
Mark Adler 已提交
415 416 417 418
cat > $test.c <<EOF
#include <stdarg.h>
int main() { return 0; }
EOF
419
if try $CC -c $CFLAGS $test.c; then
M
Mark Adler 已提交
420 421
  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
422
  echo "Checking for stdarg.h... Yes." | tee -a configure.log
M
Mark Adler 已提交
423
else
424
  echo "Checking for stdarg.h... No." | tee -a configure.log
M
Mark Adler 已提交
425 426
fi

M
Mark Adler 已提交
427
if test $zprefix -eq 1; then
M
Mark Adler 已提交
428
  sed < zconf.h "/#ifdef Z_PREFIX.* may be/s/def Z_PREFIX\(.*\) may be/ 1\1 was/" > zconf.temp.h
M
Mark Adler 已提交
429
  mv zconf.temp.h zconf.h
430 431
  echo >> configure.log
  echo "Using z_ prefix on all symbols." | tee -a configure.log
M
Mark Adler 已提交
432 433
fi

434 435 436 437 438 439 440 441 442 443
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

444 445
if test $cover -eq 1; then
  CFLAGS="${CFLAGS} -fprofile-arcs -ftest-coverage"
446 447 448
  if test -n "$GCC_CLASSIC"; then
    CC=$GCC_CLASSIC
  fi
449 450
fi

451 452
echo >> configure.log

M
Mark Adler 已提交
453
cat > $test.c <<EOF
M
Mark Adler 已提交
454
#include <stdio.h>
M
Mark Adler 已提交
455 456
#include <stdarg.h>
#include "zconf.h"
M
Mark Adler 已提交
457
int main()
M
Mark Adler 已提交
458 459 460 461 462 463 464
{
#ifndef STDC
  choke me
#endif
  return 0;
}
EOF
465
if try $CC -c $CFLAGS $test.c; then
466
  echo "Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf()." | tee -a configure.log
M
Mark Adler 已提交
467

468
  echo >> configure.log
M
Mark Adler 已提交
469 470 471
  cat > $test.c <<EOF
#include <stdio.h>
#include <stdarg.h>
M
Mark Adler 已提交
472
int mytest(const char *fmt, ...)
M
Mark Adler 已提交
473 474 475 476 477 478 479 480 481 482 483 484 485
{
  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
486
  if try $CC $CFLAGS -o $test $test.c; then
487
    echo "Checking for vsnprintf() in stdio.h... Yes." | tee -a configure.log
M
Mark Adler 已提交
488

489
    echo >> configure.log
M
Mark Adler 已提交
490 491 492
    cat >$test.c <<EOF
#include <stdio.h>
#include <stdarg.h>
M
Mark Adler 已提交
493
int mytest(const char *fmt, ...)
M
Mark Adler 已提交
494
{
M
Mark Adler 已提交
495
  int n;
M
Mark Adler 已提交
496 497 498
  char buf[20];
  va_list ap;
  va_start(ap, fmt);
M
Mark Adler 已提交
499
  n = vsnprintf(buf, sizeof(buf), fmt, ap);
M
Mark Adler 已提交
500
  va_end(ap);
M
Mark Adler 已提交
501
  return n;
M
Mark Adler 已提交
502 503 504 505 506 507 508
}
int main()
{
  return (mytest("Hello%d\n", 1));
}
EOF

509
    if try $CC -c $CFLAGS $test.c; then
510
      echo "Checking for return value of vsnprintf()... Yes." | tee -a configure.log
M
Mark Adler 已提交
511 512
    else
      CFLAGS="$CFLAGS -DHAS_vsnprintf_void"
M
Mark Adler 已提交
513
      SFLAGS="$SFLAGS -DHAS_vsnprintf_void"
514 515 516 517
      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 已提交
518 519 520
    fi
  else
    CFLAGS="$CFLAGS -DNO_vsnprintf"
M
Mark Adler 已提交
521
    SFLAGS="$SFLAGS -DNO_vsnprintf"
522 523 524 525
    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 已提交
526

527
    echo >> configure.log
M
Mark Adler 已提交
528 529 530
    cat >$test.c <<EOF
#include <stdio.h>
#include <stdarg.h>
M
Mark Adler 已提交
531
int mytest(const char *fmt, ...)
M
Mark Adler 已提交
532
{
M
Mark Adler 已提交
533
  int n;
M
Mark Adler 已提交
534 535 536
  char buf[20];
  va_list ap;
  va_start(ap, fmt);
M
Mark Adler 已提交
537
  n = vsprintf(buf, fmt, ap);
M
Mark Adler 已提交
538
  va_end(ap);
M
Mark Adler 已提交
539
  return n;
M
Mark Adler 已提交
540
}
M
Mark Adler 已提交
541
int main()
M
Mark Adler 已提交
542 543 544 545 546
{
  return (mytest("Hello%d\n", 1));
}
EOF

547
    if try $CC -c $CFLAGS $test.c; then
548
      echo "Checking for return value of vsprintf()... Yes." | tee -a configure.log
M
Mark Adler 已提交
549 550
    else
      CFLAGS="$CFLAGS -DHAS_vsprintf_void"
M
Mark Adler 已提交
551
      SFLAGS="$SFLAGS -DHAS_vsprintf_void"
552 553 554 555
      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 已提交
556 557 558
    fi
  fi
else
559
  echo "Checking whether to use vs[n]printf() or s[n]printf()... using s[n]printf()." | tee -a configure.log
M
Mark Adler 已提交
560

561
  echo >> configure.log
M
Mark Adler 已提交
562 563
  cat >$test.c <<EOF
#include <stdio.h>
M
Mark Adler 已提交
564
int mytest()
M
Mark Adler 已提交
565 566 567 568 569
{
  char buf[20];
  snprintf(buf, sizeof(buf), "%s", "foo");
  return 0;
}
M
Mark Adler 已提交
570
int main()
M
Mark Adler 已提交
571 572 573 574 575
{
  return (mytest());
}
EOF

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

579
    echo >> configure.log
M
Mark Adler 已提交
580 581
    cat >$test.c <<EOF
#include <stdio.h>
M
Mark Adler 已提交
582
int mytest()
M
Mark Adler 已提交
583 584
{
  char buf[20];
M
Mark Adler 已提交
585
  return snprintf(buf, sizeof(buf), "%s", "foo");
M
Mark Adler 已提交
586
}
M
Mark Adler 已提交
587
int main()
M
Mark Adler 已提交
588 589 590 591 592
{
  return (mytest());
}
EOF

593
    if try $CC -c $CFLAGS $test.c; then
594
      echo "Checking for return value of snprintf()... Yes." | tee -a configure.log
M
Mark Adler 已提交
595 596
    else
      CFLAGS="$CFLAGS -DHAS_snprintf_void"
M
Mark Adler 已提交
597
      SFLAGS="$SFLAGS -DHAS_snprintf_void"
598 599 600 601
      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 已提交
602 603 604
    fi
  else
    CFLAGS="$CFLAGS -DNO_snprintf"
M
Mark Adler 已提交
605
    SFLAGS="$SFLAGS -DNO_snprintf"
606 607 608 609
    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 已提交
610

611
    echo >> configure.log
M
Mark Adler 已提交
612 613
    cat >$test.c <<EOF
#include <stdio.h>
M
Mark Adler 已提交
614
int mytest()
M
Mark Adler 已提交
615 616
{
  char buf[20];
M
Mark Adler 已提交
617
  return sprintf(buf, "%s", "foo");
M
Mark Adler 已提交
618
}
M
Mark Adler 已提交
619
int main()
M
Mark Adler 已提交
620 621 622 623 624
{
  return (mytest());
}
EOF

625
    if try $CC -c $CFLAGS $test.c; then
626
      echo "Checking for return value of sprintf()... Yes." | tee -a configure.log
M
Mark Adler 已提交
627 628
    else
      CFLAGS="$CFLAGS -DHAS_sprintf_void"
M
Mark Adler 已提交
629
      SFLAGS="$SFLAGS -DHAS_sprintf_void"
630 631 632 633
      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 已提交
634 635 636 637
    fi
  fi
fi

M
Mark Adler 已提交
638
if test "$gcc" -eq 1; then
639
  echo >> configure.log
M
Mark Adler 已提交
640
  cat > $test.c <<EOF
641
#define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
M
Mark Adler 已提交
642
int ZLIB_INTERNAL foo;
M
Mark Adler 已提交
643 644 645 646 647
int main()
{
  return 0;
}
EOF
648
  if tryboth $CC -c $CFLAGS $test.c; then
649 650
    CFLAGS="$CFLAGS -DHAVE_HIDDEN"
    SFLAGS="$SFLAGS -DHAVE_HIDDEN"
651
    echo "Checking for attribute(visibility) support... Yes." | tee -a configure.log
M
Mark Adler 已提交
652
  else
653
    echo "Checking for attribute(visibility) support... No." | tee -a configure.log
M
Mark Adler 已提交
654
  fi
M
Mark Adler 已提交
655 656
fi

657
rm -f $test.[co] $test $test$shared_ext $test.gcno
M
Mark Adler 已提交
658

659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692
# 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
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
echo -------------------- >> configure.log
echo >> configure.log
echo >> configure.log

M
Mark Adler 已提交
693 694
# udpate Makefile
sed < Makefile.in "
M
Mark Adler 已提交
695 696
/^CC *=/s#=.*#=$CC#
/^CFLAGS *=/s#=.*#=$CFLAGS#
M
Mark Adler 已提交
697
/^SFLAGS *=/s#=.*#=$SFLAGS#
M
Mark Adler 已提交
698
/^LDFLAGS *=/s#=.*#=$LDFLAGS#
M
Mark Adler 已提交
699
/^LDSHARED *=/s#=.*#=$LDSHARED#
M
Mark Adler 已提交
700
/^CPP *=/s#=.*#=$CPP#
M
Mark Adler 已提交
701
/^STATICLIB *=/s#=.*#=$STATICLIB#
M
Mark Adler 已提交
702 703 704
/^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
/^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
/^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
705 706
/^AR *=/s#=.*#=$AR#
/^ARFLAGS *=/s#=.*#=$ARFLAGS#
M
Mark Adler 已提交
707
/^RANLIB *=/s#=.*#=$RANLIB#
M
Mark Adler 已提交
708 709
/^LDCONFIG *=/s#=.*#=$LDCONFIG#
/^LDSHAREDLIBC *=/s#=.*#=$LDSHAREDLIBC#
M
Mark Adler 已提交
710
/^EXE *=/s#=.*#=$EXE#
M
Mark Adler 已提交
711 712 713
/^prefix *=/s#=.*#=$prefix#
/^exec_prefix *=/s#=.*#=$exec_prefix#
/^libdir *=/s#=.*#=$libdir#
M
Mark Adler 已提交
714
/^sharedlibdir *=/s#=.*#=$sharedlibdir#
M
Mark Adler 已提交
715 716
/^includedir *=/s#=.*#=$includedir#
/^mandir *=/s#=.*#=$mandir#
717 718
/^OBJC *=/s#=.*#= $OBJC#
/^PIC_OBJC *=/s#=.*#= $PIC_OBJC#
M
Mark Adler 已提交
719 720
/^all: */s#:.*#: $ALL#
/^test: */s#:.*#: $TEST#
M
Mark Adler 已提交
721
" > Makefile
M
Mark Adler 已提交
722 723 724 725 726 727

sed < zlib.pc.in "
/^CC *=/s#=.*#=$CC#
/^CFLAGS *=/s#=.*#=$CFLAGS#
/^CPP *=/s#=.*#=$CPP#
/^LDSHARED *=/s#=.*#=$LDSHARED#
M
Mark Adler 已提交
728
/^STATICLIB *=/s#=.*#=$STATICLIB#
M
Mark Adler 已提交
729 730 731
/^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
/^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
/^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
732 733
/^AR *=/s#=.*#=$AR#
/^ARFLAGS *=/s#=.*#=$ARFLAGS#
M
Mark Adler 已提交
734 735 736 737 738
/^RANLIB *=/s#=.*#=$RANLIB#
/^EXE *=/s#=.*#=$EXE#
/^prefix *=/s#=.*#=$prefix#
/^exec_prefix *=/s#=.*#=$exec_prefix#
/^libdir *=/s#=.*#=$libdir#
M
Mark Adler 已提交
739
/^sharedlibdir *=/s#=.*#=$sharedlibdir#
M
Mark Adler 已提交
740 741 742 743 744 745
/^includedir *=/s#=.*#=$includedir#
/^mandir *=/s#=.*#=$mandir#
/^LDFLAGS *=/s#=.*#=$LDFLAGS#
" | sed -e "
s/\@VERSION\@/$VER/g;
" > zlib.pc