configure 26.0 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

21 22 23 24 25 26 27 28 29 30 31 32
# get source directory
SRCDIR=`dirname $0`
if test $SRCDIR = "."; then
    ZINC=""
    ZINCOUT="-I."
    SRCDIR=""
else
    ZINC='-include zconf.h'
    ZINCOUT='-I. -I$(SRCDIR)'
    SRCDIR="$SRCDIR/"
fi

M
Mark Adler 已提交
33
# set command prefix for cross-compilation
M
Mark Adler 已提交
34
if [ -n "${CHOST}" ]; then
M
Mark Adler 已提交
35
    uname="`echo "${CHOST}" | sed -e 's/^[^-]*-\([^-]*\)$/\1/' -e 's/^[^-]*-[^-]*-\([^-]*\)$/\1/' -e 's/^[^-]*-[^-]*-\([^-]*\)-.*$/\1/'`"
M
Mark Adler 已提交
36 37 38
    CROSS_PREFIX="${CHOST}-"
fi

M
Mark Adler 已提交
39
# destination name for static library
M
Mark Adler 已提交
40
STATICLIB=libz.a
M
Mark Adler 已提交
41 42

# extract zlib version numbers from zlib.h
43 44 45 46
VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < ${SRCDIR}zlib.h`
VER3=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\\.[0-9]*\).*/\1/p' < ${SRCDIR}zlib.h`
VER2=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\)\\..*/\1/p' < ${SRCDIR}zlib.h`
VER1=`sed -n -e '/VERSION "/s/.*"\([0-9]*\)\\..*/\1/p' < ${SRCDIR}zlib.h`
M
Mark Adler 已提交
47 48

# establish commands for library building
M
Mark Adler 已提交
49
if "${CROSS_PREFIX}ar" --version >/dev/null 2>/dev/null || test $? -lt 126; then
M
Mark Adler 已提交
50
    AR=${AR-"${CROSS_PREFIX}ar"}
51
    test -n "${CROSS_PREFIX}" && echo Using ${AR} | tee -a configure.log
M
Mark Adler 已提交
52 53
else
    AR=${AR-"ar"}
54
    test -n "${CROSS_PREFIX}" && echo Using ${AR} | tee -a configure.log
M
Mark Adler 已提交
55
fi
56
ARFLAGS=${ARFLAGS-"rc"}
M
Mark Adler 已提交
57
if "${CROSS_PREFIX}ranlib" --version >/dev/null 2>/dev/null || test $? -lt 126; then
M
Mark Adler 已提交
58
    RANLIB=${RANLIB-"${CROSS_PREFIX}ranlib"}
59
    test -n "${CROSS_PREFIX}" && echo Using ${RANLIB} | tee -a configure.log
M
Mark Adler 已提交
60 61 62
else
    RANLIB=${RANLIB-"ranlib"}
fi
M
Mark Adler 已提交
63
if "${CROSS_PREFIX}nm" --version >/dev/null 2>/dev/null || test $? -lt 126; then
M
Mark Adler 已提交
64
    NM=${NM-"${CROSS_PREFIX}nm"}
65
    test -n "${CROSS_PREFIX}" && echo Using ${NM} | tee -a configure.log
M
Mark Adler 已提交
66 67 68
else
    NM=${NM-"nm"}
fi
M
Mark Adler 已提交
69 70

# set defaults before processing command line options
M
Mark Adler 已提交
71
LDCONFIG=${LDCONFIG-"ldconfig"}
M
Mark Adler 已提交
72
LDSHAREDLIBC="${LDSHAREDLIBC--lc}"
M
Mark Adler 已提交
73
ARCHS=
M
Mark Adler 已提交
74
prefix=${prefix-/usr/local}
M
Mark Adler 已提交
75 76
exec_prefix=${exec_prefix-'${prefix}'}
libdir=${libdir-'${exec_prefix}/lib'}
M
Mark Adler 已提交
77
sharedlibdir=${sharedlibdir-'${libdir}'}
M
Mark Adler 已提交
78
includedir=${includedir-'${prefix}/include'}
M
Mark Adler 已提交
79
mandir=${mandir-'${prefix}/share/man'}
M
Mark Adler 已提交
80
shared_ext='.so'
M
Mark Adler 已提交
81
shared=1
82
solo=0
83
cover=0
M
Mark Adler 已提交
84
zprefix=0
85
zconst=0
M
Mark Adler 已提交
86
build64=0
M
Mark Adler 已提交
87
gcc=0
M
Mark Adler 已提交
88 89
old_cc="$CC"
old_cflags="$CFLAGS"
90 91
OBJC='$(OBJZ) $(OBJG)'
PIC_OBJC='$(PIC_OBJZ) $(PIC_OBJG)'
M
Mark Adler 已提交
92

93 94 95 96 97 98 99 100 101 102 103 104 105
# 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 已提交
106
# process command line options
M
Mark Adler 已提交
107 108
while test $# -ge 1
do
M
Mark Adler 已提交
109
case "$1" in
M
Mark Adler 已提交
110
    -h* | --help)
111
      echo 'usage:' | tee -a configure.log
112
      echo '  configure [--const] [--zprefix] [--prefix=PREFIX]  [--eprefix=EXPREFIX]' | tee -a configure.log
113 114
      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 已提交
115
        exit 0 ;;
M
Mark Adler 已提交
116 117 118
    -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 已提交
119
    --sharedlibdir=*) sharedlibdir=`echo $1 | sed 's/.*=//'`; shift ;;
M
Mark Adler 已提交
120 121
    -i*=* | --includedir=*) includedir=`echo $1 | sed 's/.*=//'`;shift ;;
    -u*=* | --uname=*) uname=`echo $1 | sed 's/.*=//'`;shift ;;
M
Mark Adler 已提交
122 123 124 125 126 127
    -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 ;;
128
    --solo) solo=1; shift ;;
129
    --cover) cover=1; shift ;;
M
Mark Adler 已提交
130
    -z* | --zprefix) zprefix=1; shift ;;
M
Mark Adler 已提交
131
    -6* | --64) build64=1; shift ;;
M
Mark Adler 已提交
132
    -a*=* | --archs=*) ARCHS=`echo $1 | sed 's/.*=//'`; shift ;;
133 134
    --sysconfdir=*) echo "ignored option: --sysconfdir" | tee -a configure.log; shift ;;
    --localstatedir=*) echo "ignored option: --localstatedir" | tee -a configure.log; shift ;;
135
    -c* | --const) zconst=1; shift ;;
136 137 138 139
    *)
      echo "unknown option: $1" | tee -a configure.log
      echo "$0 --help for help" | tee -a configure.log
      leave 1;;
M
Mark Adler 已提交
140 141
    esac
done
M
Mark Adler 已提交
142

143
# temporary file name
M
Mark Adler 已提交
144
test=ztest$$
145

146
# put arguments in log, also put test file in log if used in arguments
147 148 149 150 151 152 153 154 155 156 157
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 已提交
158
# check for gcc vs. cc and set compile and link flags based on the system identified by uname
M
Mark Adler 已提交
159
cat > $test.c <<EOF
M
Mark Adler 已提交
160 161
extern int getchar();
int hello() {return getchar();}
M
Mark Adler 已提交
162
EOF
M
Mark Adler 已提交
163

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

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

M
Mark Adler 已提交
335
# destination names for shared library if not defined above
M
Mark Adler 已提交
336 337 338 339
SHAREDLIB=${SHAREDLIB-"libz$shared_ext"}
SHAREDLIBV=${SHAREDLIBV-"libz$shared_ext.$VER"}
SHAREDLIBM=${SHAREDLIBM-"libz$shared_ext.$VER1"}

340 341
echo >> configure.log

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

M
Mark Adler 已提交
424
# check for underscores in external names for use by assembler code
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
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 已提交
440
# check for large file support, and if none, check for fseeko()
M
Mark Adler 已提交
441 442 443 444
cat > $test.c <<EOF
#include <sys/types.h>
off64_t dummy = 0;
EOF
445
if try $CC -c $CFLAGS -D_LARGEFILE64_SOURCE=1 $test.c; then
M
Mark Adler 已提交
446 447
  CFLAGS="${CFLAGS} -D_LARGEFILE64_SOURCE=1"
  SFLAGS="${SFLAGS} -D_LARGEFILE64_SOURCE=1"
M
Mark Adler 已提交
448 449
  ALL="${ALL} all64"
  TEST="${TEST} test64"
450 451
  echo "Checking for off64_t... Yes." | tee -a configure.log
  echo "Checking for fseeko... Yes." | tee -a configure.log
M
Mark Adler 已提交
452
else
453 454
  echo "Checking for off64_t... No." | tee -a configure.log
  echo >> configure.log
M
Mark Adler 已提交
455 456 457 458 459 460 461
  cat > $test.c <<EOF
#include <stdio.h>
int main(void) {
  fseeko(NULL, 0, 0);
  return 0;
}
EOF
462
  if try $CC $CFLAGS -o $test $test.c; then
463
    echo "Checking for fseeko... Yes." | tee -a configure.log
M
Mark Adler 已提交
464 465 466
  else
    CFLAGS="${CFLAGS} -DNO_FSEEKO"
    SFLAGS="${SFLAGS} -DNO_FSEEKO"
467
    echo "Checking for fseeko... No." | tee -a configure.log
M
Mark Adler 已提交
468
  fi
M
Mark Adler 已提交
469
fi
M
Mark Adler 已提交
470

M
Mark Adler 已提交
471 472
echo >> configure.log

M
Mark Adler 已提交
473
# check for strerror() for use by gz* functions
M
Mark Adler 已提交
474 475 476 477 478 479 480 481 482 483 484 485 486
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 已提交
487
# copy clean zconf.h for subsequent edits
488
cp -p ${SRCDIR}zconf.h.in zconf.h
M
Mark Adler 已提交
489

490 491
echo >> configure.log

M
Mark Adler 已提交
492
# check for unistd.h and save result in zconf.h
M
Mark Adler 已提交
493 494 495 496
cat > $test.c <<EOF
#include <unistd.h>
int main() { return 0; }
EOF
497
if try $CC -c $CFLAGS $test.c; then
M
Mark Adler 已提交
498
  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 已提交
499
  mv zconf.temp.h zconf.h
500
  echo "Checking for unistd.h... Yes." | tee -a configure.log
M
Mark Adler 已提交
501
else
502
  echo "Checking for unistd.h... No." | tee -a configure.log
M
Mark Adler 已提交
503 504
fi

505 506
echo >> configure.log

M
Mark Adler 已提交
507
# check for stdarg.h and save result in zconf.h
M
Mark Adler 已提交
508 509 510 511
cat > $test.c <<EOF
#include <stdarg.h>
int main() { return 0; }
EOF
512
if try $CC -c $CFLAGS $test.c; then
M
Mark Adler 已提交
513 514
  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
515
  echo "Checking for stdarg.h... Yes." | tee -a configure.log
M
Mark Adler 已提交
516
else
517
  echo "Checking for stdarg.h... No." | tee -a configure.log
M
Mark Adler 已提交
518 519
fi

M
Mark Adler 已提交
520
# if the z_ prefix was requested, save that in zconf.h
M
Mark Adler 已提交
521
if test $zprefix -eq 1; then
M
Mark Adler 已提交
522
  sed < zconf.h "/#ifdef Z_PREFIX.* may be/s/def Z_PREFIX\(.*\) may be/ 1\1 was/" > zconf.temp.h
M
Mark Adler 已提交
523
  mv zconf.temp.h zconf.h
524 525
  echo >> configure.log
  echo "Using z_ prefix on all symbols." | tee -a configure.log
M
Mark Adler 已提交
526 527
fi

M
Mark Adler 已提交
528
# if --solo compilation was requested, save that in zconf.h and remove gz stuff from object lists
529 530 531 532 533 534 535 536 537 538
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 已提交
539
# if code coverage testing was requested, use older gcc if defined, e.g. "gcc-4.2" on Mac OS X
540 541
if test $cover -eq 1; then
  CFLAGS="${CFLAGS} -fprofile-arcs -ftest-coverage"
542 543 544
  if test -n "$GCC_CLASSIC"; then
    CC=$GCC_CLASSIC
  fi
545 546
fi

547 548
echo >> configure.log

M
Mark Adler 已提交
549 550 551 552
# 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 已提交
553
cat > $test.c <<EOF
M
Mark Adler 已提交
554
#include <stdio.h>
M
Mark Adler 已提交
555 556
#include <stdarg.h>
#include "zconf.h"
M
Mark Adler 已提交
557
int main()
M
Mark Adler 已提交
558 559 560 561 562 563 564
{
#ifndef STDC
  choke me
#endif
  return 0;
}
EOF
565
if try $CC -c $CFLAGS $test.c; then
566
  echo "Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf()." | tee -a configure.log
M
Mark Adler 已提交
567

568
  echo >> configure.log
M
Mark Adler 已提交
569 570 571
  cat > $test.c <<EOF
#include <stdio.h>
#include <stdarg.h>
M
Mark Adler 已提交
572
int mytest(const char *fmt, ...)
M
Mark Adler 已提交
573 574 575 576 577 578 579 580 581 582 583 584 585
{
  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
586
  if try $CC $CFLAGS -o $test $test.c; then
587
    echo "Checking for vsnprintf() in stdio.h... Yes." | tee -a configure.log
M
Mark Adler 已提交
588

589
    echo >> configure.log
M
Mark Adler 已提交
590 591 592
    cat >$test.c <<EOF
#include <stdio.h>
#include <stdarg.h>
M
Mark Adler 已提交
593
int mytest(const char *fmt, ...)
M
Mark Adler 已提交
594
{
M
Mark Adler 已提交
595
  int n;
M
Mark Adler 已提交
596 597 598
  char buf[20];
  va_list ap;
  va_start(ap, fmt);
M
Mark Adler 已提交
599
  n = vsnprintf(buf, sizeof(buf), fmt, ap);
M
Mark Adler 已提交
600
  va_end(ap);
M
Mark Adler 已提交
601
  return n;
M
Mark Adler 已提交
602 603 604 605 606 607 608
}
int main()
{
  return (mytest("Hello%d\n", 1));
}
EOF

609
    if try $CC -c $CFLAGS $test.c; then
610
      echo "Checking for return value of vsnprintf()... Yes." | tee -a configure.log
M
Mark Adler 已提交
611 612
    else
      CFLAGS="$CFLAGS -DHAS_vsnprintf_void"
M
Mark Adler 已提交
613
      SFLAGS="$SFLAGS -DHAS_vsnprintf_void"
614 615 616 617
      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 已提交
618 619 620
    fi
  else
    CFLAGS="$CFLAGS -DNO_vsnprintf"
M
Mark Adler 已提交
621
    SFLAGS="$SFLAGS -DNO_vsnprintf"
622 623 624 625
    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 已提交
626

627
    echo >> configure.log
M
Mark Adler 已提交
628 629 630
    cat >$test.c <<EOF
#include <stdio.h>
#include <stdarg.h>
M
Mark Adler 已提交
631
int mytest(const char *fmt, ...)
M
Mark Adler 已提交
632
{
M
Mark Adler 已提交
633
  int n;
M
Mark Adler 已提交
634 635 636
  char buf[20];
  va_list ap;
  va_start(ap, fmt);
M
Mark Adler 已提交
637
  n = vsprintf(buf, fmt, ap);
M
Mark Adler 已提交
638
  va_end(ap);
M
Mark Adler 已提交
639
  return n;
M
Mark Adler 已提交
640
}
M
Mark Adler 已提交
641
int main()
M
Mark Adler 已提交
642 643 644 645 646
{
  return (mytest("Hello%d\n", 1));
}
EOF

647
    if try $CC -c $CFLAGS $test.c; then
648
      echo "Checking for return value of vsprintf()... Yes." | tee -a configure.log
M
Mark Adler 已提交
649 650
    else
      CFLAGS="$CFLAGS -DHAS_vsprintf_void"
M
Mark Adler 已提交
651
      SFLAGS="$SFLAGS -DHAS_vsprintf_void"
652 653 654 655
      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 已提交
656 657 658
    fi
  fi
else
659
  echo "Checking whether to use vs[n]printf() or s[n]printf()... using s[n]printf()." | tee -a configure.log
M
Mark Adler 已提交
660

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

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

679
    echo >> configure.log
M
Mark Adler 已提交
680 681
    cat >$test.c <<EOF
#include <stdio.h>
M
Mark Adler 已提交
682
int mytest()
M
Mark Adler 已提交
683 684
{
  char buf[20];
M
Mark Adler 已提交
685
  return snprintf(buf, sizeof(buf), "%s", "foo");
M
Mark Adler 已提交
686
}
M
Mark Adler 已提交
687
int main()
M
Mark Adler 已提交
688 689 690 691 692
{
  return (mytest());
}
EOF

693
    if try $CC -c $CFLAGS $test.c; then
694
      echo "Checking for return value of snprintf()... Yes." | tee -a configure.log
M
Mark Adler 已提交
695 696
    else
      CFLAGS="$CFLAGS -DHAS_snprintf_void"
M
Mark Adler 已提交
697
      SFLAGS="$SFLAGS -DHAS_snprintf_void"
698 699 700 701
      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 已提交
702 703 704
    fi
  else
    CFLAGS="$CFLAGS -DNO_snprintf"
M
Mark Adler 已提交
705
    SFLAGS="$SFLAGS -DNO_snprintf"
706 707 708 709
    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 已提交
710

711
    echo >> configure.log
M
Mark Adler 已提交
712 713
    cat >$test.c <<EOF
#include <stdio.h>
M
Mark Adler 已提交
714
int mytest()
M
Mark Adler 已提交
715 716
{
  char buf[20];
M
Mark Adler 已提交
717
  return sprintf(buf, "%s", "foo");
M
Mark Adler 已提交
718
}
M
Mark Adler 已提交
719
int main()
M
Mark Adler 已提交
720 721 722 723 724
{
  return (mytest());
}
EOF

725
    if try $CC -c $CFLAGS $test.c; then
726
      echo "Checking for return value of sprintf()... Yes." | tee -a configure.log
M
Mark Adler 已提交
727 728
    else
      CFLAGS="$CFLAGS -DHAS_sprintf_void"
M
Mark Adler 已提交
729
      SFLAGS="$SFLAGS -DHAS_sprintf_void"
730 731 732 733
      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 已提交
734 735 736 737
    fi
  fi
fi

M
Mark Adler 已提交
738
# see if we can hide zlib internal symbols that are linked between separate source files
M
Mark Adler 已提交
739
if test "$gcc" -eq 1; then
740
  echo >> configure.log
M
Mark Adler 已提交
741
  cat > $test.c <<EOF
742
#define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
M
Mark Adler 已提交
743
int ZLIB_INTERNAL foo;
M
Mark Adler 已提交
744 745 746 747 748
int main()
{
  return 0;
}
EOF
749
  if tryboth $CC -c $CFLAGS $test.c; then
750 751
    CFLAGS="$CFLAGS -DHAVE_HIDDEN"
    SFLAGS="$SFLAGS -DHAVE_HIDDEN"
752
    echo "Checking for attribute(visibility) support... Yes." | tee -a configure.log
M
Mark Adler 已提交
753
  else
754
    echo "Checking for attribute(visibility) support... No." | tee -a configure.log
M
Mark Adler 已提交
755
  fi
M
Mark Adler 已提交
756 757
fi

758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780
# 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
781
echo Z_U4 = $Z_U4 >> configure.log
782
echo SRCDIR = $SRCDIR >> configure.log
783 784 785 786 787 788 789 790
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 已提交
791
# udpate Makefile with the configure results
792
sed < ${SRCDIR}Makefile.in "
M
Mark Adler 已提交
793 794
/^CC *=/s#=.*#=$CC#
/^CFLAGS *=/s#=.*#=$CFLAGS#
M
Mark Adler 已提交
795
/^SFLAGS *=/s#=.*#=$SFLAGS#
M
Mark Adler 已提交
796
/^LDFLAGS *=/s#=.*#=$LDFLAGS#
M
Mark Adler 已提交
797
/^LDSHARED *=/s#=.*#=$LDSHARED#
M
Mark Adler 已提交
798
/^CPP *=/s#=.*#=$CPP#
M
Mark Adler 已提交
799
/^STATICLIB *=/s#=.*#=$STATICLIB#
M
Mark Adler 已提交
800 801 802
/^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
/^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
/^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
803 804
/^AR *=/s#=.*#=$AR#
/^ARFLAGS *=/s#=.*#=$ARFLAGS#
M
Mark Adler 已提交
805
/^RANLIB *=/s#=.*#=$RANLIB#
M
Mark Adler 已提交
806 807
/^LDCONFIG *=/s#=.*#=$LDCONFIG#
/^LDSHAREDLIBC *=/s#=.*#=$LDSHAREDLIBC#
M
Mark Adler 已提交
808
/^EXE *=/s#=.*#=$EXE#
809 810 811
/^SRCDIR *=/s#=.*#=$SRCDIR#
/^ZINC *=/s#=.*#=$ZINC#
/^ZINCOUT *=/s#=.*#=$ZINCOUT#
M
Mark Adler 已提交
812 813 814
/^prefix *=/s#=.*#=$prefix#
/^exec_prefix *=/s#=.*#=$exec_prefix#
/^libdir *=/s#=.*#=$libdir#
M
Mark Adler 已提交
815
/^sharedlibdir *=/s#=.*#=$sharedlibdir#
M
Mark Adler 已提交
816 817
/^includedir *=/s#=.*#=$includedir#
/^mandir *=/s#=.*#=$mandir#
818 819
/^OBJC *=/s#=.*#= $OBJC#
/^PIC_OBJC *=/s#=.*#= $PIC_OBJC#
M
Mark Adler 已提交
820 821
/^all: */s#:.*#: $ALL#
/^test: */s#:.*#: $TEST#
M
Mark Adler 已提交
822
" > Makefile
M
Mark Adler 已提交
823

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

# done
leave 0