configure 21.8 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
echo >> configure.log

M
Mark Adler 已提交
141
cat > $test.c <<EOF
M
Mark Adler 已提交
142 143
extern int getchar();
int hello() {return getchar();}
M
Mark Adler 已提交
144
EOF
M
Mark Adler 已提交
145

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

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

M
Mark Adler 已提交
292 293 294 295
SHAREDLIB=${SHAREDLIB-"libz$shared_ext"}
SHAREDLIBV=${SHAREDLIBV-"libz$shared_ext.$VER"}
SHAREDLIBM=${SHAREDLIBM-"libz$shared_ext.$VER1"}

296 297
echo >> configure.log

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

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

M
Mark Adler 已提交
370
cp -p zconf.h.in zconf.h
M
Mark Adler 已提交
371

372 373
echo >> configure.log

M
Mark Adler 已提交
374 375 376 377
cat > $test.c <<EOF
#include <unistd.h>
int main() { return 0; }
EOF
378
if try $CC -c $CFLAGS $test.c; then
M
Mark Adler 已提交
379
  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 已提交
380
  mv zconf.temp.h zconf.h
381
  echo "Checking for unistd.h... Yes." | tee -a configure.log
M
Mark Adler 已提交
382
else
383
  echo "Checking for unistd.h... No." | tee -a configure.log
M
Mark Adler 已提交
384 385
fi

386 387
echo >> configure.log

M
Mark Adler 已提交
388 389 390 391
cat > $test.c <<EOF
#include <stdarg.h>
int main() { return 0; }
EOF
392
if try $CC -c $CFLAGS $test.c; then
M
Mark Adler 已提交
393 394
  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
395
  echo "Checking for stdarg.h... Yes." | tee -a configure.log
M
Mark Adler 已提交
396
else
397
  echo "Checking for stdarg.h... No." | tee -a configure.log
M
Mark Adler 已提交
398 399
fi

M
Mark Adler 已提交
400
if test $zprefix -eq 1; then
M
Mark Adler 已提交
401
  sed < zconf.h "/#ifdef Z_PREFIX.* may be/s/def Z_PREFIX\(.*\) may be/ 1\1 was/" > zconf.temp.h
M
Mark Adler 已提交
402
  mv zconf.temp.h zconf.h
403 404
  echo >> configure.log
  echo "Using z_ prefix on all symbols." | tee -a configure.log
M
Mark Adler 已提交
405 406
fi

407 408 409 410 411 412 413 414 415 416
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

417 418 419 420
if test $cover -eq 1; then
  CFLAGS="${CFLAGS} -fprofile-arcs -ftest-coverage"
fi

421 422
echo >> configure.log

M
Mark Adler 已提交
423
cat > $test.c <<EOF
M
Mark Adler 已提交
424
#include <stdio.h>
M
Mark Adler 已提交
425 426
#include <stdarg.h>
#include "zconf.h"
M
Mark Adler 已提交
427
int main()
M
Mark Adler 已提交
428 429 430 431 432 433 434 435
{
#ifndef STDC
  choke me
#endif
  return 0;
}
EOF

436
if try $CC -c $CFLAGS $test.c; then
437
  echo "Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf()." | tee -a configure.log
M
Mark Adler 已提交
438

439
  echo >> configure.log
M
Mark Adler 已提交
440 441 442
  cat > $test.c <<EOF
#include <stdio.h>
#include <stdarg.h>
M
Mark Adler 已提交
443
int mytest(const char *fmt, ...)
M
Mark Adler 已提交
444 445 446 447 448 449 450 451 452 453 454 455 456
{
  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
457
  if try $CC $CFLAGS -o $test $test.c; then
458
    echo "Checking for vsnprintf() in stdio.h... Yes." | tee -a configure.log
M
Mark Adler 已提交
459

460
    echo >> configure.log
M
Mark Adler 已提交
461 462 463
    cat >$test.c <<EOF
#include <stdio.h>
#include <stdarg.h>
M
Mark Adler 已提交
464
int mytest(const char *fmt, ...)
M
Mark Adler 已提交
465
{
M
Mark Adler 已提交
466
  int n;
M
Mark Adler 已提交
467 468 469
  char buf[20];
  va_list ap;
  va_start(ap, fmt);
M
Mark Adler 已提交
470
  n = vsnprintf(buf, sizeof(buf), fmt, ap);
M
Mark Adler 已提交
471
  va_end(ap);
M
Mark Adler 已提交
472
  return n;
M
Mark Adler 已提交
473 474 475 476 477 478 479
}
int main()
{
  return (mytest("Hello%d\n", 1));
}
EOF

480
    if try $CC -c $CFLAGS $test.c; then
481
      echo "Checking for return value of vsnprintf()... Yes." | tee -a configure.log
M
Mark Adler 已提交
482 483
    else
      CFLAGS="$CFLAGS -DHAS_vsnprintf_void"
M
Mark Adler 已提交
484
      SFLAGS="$SFLAGS -DHAS_vsnprintf_void"
485 486 487 488
      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 已提交
489 490 491
    fi
  else
    CFLAGS="$CFLAGS -DNO_vsnprintf"
M
Mark Adler 已提交
492
    SFLAGS="$SFLAGS -DNO_vsnprintf"
493 494 495 496
    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 已提交
497

498
    echo >> configure.log
M
Mark Adler 已提交
499 500 501
    cat >$test.c <<EOF
#include <stdio.h>
#include <stdarg.h>
M
Mark Adler 已提交
502
int mytest(const char *fmt, ...)
M
Mark Adler 已提交
503
{
M
Mark Adler 已提交
504
  int n;
M
Mark Adler 已提交
505 506 507
  char buf[20];
  va_list ap;
  va_start(ap, fmt);
M
Mark Adler 已提交
508
  n = vsprintf(buf, fmt, ap);
M
Mark Adler 已提交
509
  va_end(ap);
M
Mark Adler 已提交
510
  return n;
M
Mark Adler 已提交
511
}
M
Mark Adler 已提交
512
int main()
M
Mark Adler 已提交
513 514 515 516 517
{
  return (mytest("Hello%d\n", 1));
}
EOF

518
    if try $CC -c $CFLAGS $test.c; then
519
      echo "Checking for return value of vsprintf()... Yes." | tee -a configure.log
M
Mark Adler 已提交
520 521
    else
      CFLAGS="$CFLAGS -DHAS_vsprintf_void"
M
Mark Adler 已提交
522
      SFLAGS="$SFLAGS -DHAS_vsprintf_void"
523 524 525 526
      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 已提交
527 528 529
    fi
  fi
else
530
  echo "Checking whether to use vs[n]printf() or s[n]printf()... using s[n]printf()." | tee -a configure.log
M
Mark Adler 已提交
531

532
  echo >> configure.log
M
Mark Adler 已提交
533 534
  cat >$test.c <<EOF
#include <stdio.h>
M
Mark Adler 已提交
535
int mytest()
M
Mark Adler 已提交
536 537 538 539 540
{
  char buf[20];
  snprintf(buf, sizeof(buf), "%s", "foo");
  return 0;
}
M
Mark Adler 已提交
541
int main()
M
Mark Adler 已提交
542 543 544 545 546
{
  return (mytest());
}
EOF

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

550
    echo >> configure.log
M
Mark Adler 已提交
551 552
    cat >$test.c <<EOF
#include <stdio.h>
M
Mark Adler 已提交
553
int mytest()
M
Mark Adler 已提交
554 555
{
  char buf[20];
M
Mark Adler 已提交
556
  return snprintf(buf, sizeof(buf), "%s", "foo");
M
Mark Adler 已提交
557
}
M
Mark Adler 已提交
558
int main()
M
Mark Adler 已提交
559 560 561 562 563
{
  return (mytest());
}
EOF

564
    if try $CC -c $CFLAGS $test.c; then
565
      echo "Checking for return value of snprintf()... Yes." | tee -a configure.log
M
Mark Adler 已提交
566 567
    else
      CFLAGS="$CFLAGS -DHAS_snprintf_void"
M
Mark Adler 已提交
568
      SFLAGS="$SFLAGS -DHAS_snprintf_void"
569 570 571 572
      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 已提交
573 574 575
    fi
  else
    CFLAGS="$CFLAGS -DNO_snprintf"
M
Mark Adler 已提交
576
    SFLAGS="$SFLAGS -DNO_snprintf"
577 578 579 580
    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 已提交
581

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

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

M
Mark Adler 已提交
609
if test "$gcc" -eq 1; then
610
  echo >> configure.log
M
Mark Adler 已提交
611 612 613 614 615 616 617
  cat > $test.c <<EOF
#if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33)
#  define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
#else
#  define ZLIB_INTERNAL
#endif
int ZLIB_INTERNAL foo;
M
Mark Adler 已提交
618 619 620 621 622
int main()
{
  return 0;
}
EOF
623
  if try $CC -c $CFLAGS $test.c; then
624
    echo "Checking for attribute(visibility) support... Yes." | tee -a configure.log
M
Mark Adler 已提交
625 626 627
  else
    CFLAGS="$CFLAGS -DNO_VIZ"
    SFLAGS="$SFLAGS -DNO_VIZ"
628
    echo "Checking for attribute(visibility) support... No." | tee -a configure.log
M
Mark Adler 已提交
629
  fi
M
Mark Adler 已提交
630 631
fi

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

634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667
# 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 已提交
668 669
# udpate Makefile
sed < Makefile.in "
M
Mark Adler 已提交
670 671
/^CC *=/s#=.*#=$CC#
/^CFLAGS *=/s#=.*#=$CFLAGS#
M
Mark Adler 已提交
672
/^SFLAGS *=/s#=.*#=$SFLAGS#
M
Mark Adler 已提交
673
/^LDFLAGS *=/s#=.*#=$LDFLAGS#
M
Mark Adler 已提交
674
/^LDSHARED *=/s#=.*#=$LDSHARED#
M
Mark Adler 已提交
675
/^CPP *=/s#=.*#=$CPP#
M
Mark Adler 已提交
676
/^STATICLIB *=/s#=.*#=$STATICLIB#
M
Mark Adler 已提交
677 678 679
/^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
/^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
/^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
680 681
/^AR *=/s#=.*#=$AR#
/^ARFLAGS *=/s#=.*#=$ARFLAGS#
M
Mark Adler 已提交
682
/^RANLIB *=/s#=.*#=$RANLIB#
M
Mark Adler 已提交
683 684
/^LDCONFIG *=/s#=.*#=$LDCONFIG#
/^LDSHAREDLIBC *=/s#=.*#=$LDSHAREDLIBC#
M
Mark Adler 已提交
685
/^EXE *=/s#=.*#=$EXE#
M
Mark Adler 已提交
686 687 688
/^prefix *=/s#=.*#=$prefix#
/^exec_prefix *=/s#=.*#=$exec_prefix#
/^libdir *=/s#=.*#=$libdir#
M
Mark Adler 已提交
689
/^sharedlibdir *=/s#=.*#=$sharedlibdir#
M
Mark Adler 已提交
690 691
/^includedir *=/s#=.*#=$includedir#
/^mandir *=/s#=.*#=$mandir#
692 693
/^OBJC *=/s#=.*#= $OBJC#
/^PIC_OBJC *=/s#=.*#= $PIC_OBJC#
M
Mark Adler 已提交
694 695
/^all: */s#:.*#: $ALL#
/^test: */s#:.*#: $TEST#
M
Mark Adler 已提交
696
" > Makefile
M
Mark Adler 已提交
697 698 699 700 701 702

sed < zlib.pc.in "
/^CC *=/s#=.*#=$CC#
/^CFLAGS *=/s#=.*#=$CFLAGS#
/^CPP *=/s#=.*#=$CPP#
/^LDSHARED *=/s#=.*#=$LDSHARED#
M
Mark Adler 已提交
703
/^STATICLIB *=/s#=.*#=$STATICLIB#
M
Mark Adler 已提交
704 705 706
/^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
/^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
/^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
707 708
/^AR *=/s#=.*#=$AR#
/^ARFLAGS *=/s#=.*#=$ARFLAGS#
M
Mark Adler 已提交
709 710 711 712 713
/^RANLIB *=/s#=.*#=$RANLIB#
/^EXE *=/s#=.*#=$EXE#
/^prefix *=/s#=.*#=$prefix#
/^exec_prefix *=/s#=.*#=$exec_prefix#
/^libdir *=/s#=.*#=$libdir#
M
Mark Adler 已提交
714
/^sharedlibdir *=/s#=.*#=$sharedlibdir#
M
Mark Adler 已提交
715 716 717 718 719 720
/^includedir *=/s#=.*#=$includedir#
/^mandir *=/s#=.*#=$mandir#
/^LDFLAGS *=/s#=.*#=$LDFLAGS#
" | sed -e "
s/\@VERSION\@/$VER/g;
" > zlib.pc