1#!/bin/sh 2# configure script for zlib. This script is needed only if 3# you wish to build a shared library and your system supports them, 4# of if you need special compiler, flags or install directory. 5# Otherwise, you can just use directly "make test; make install" 6# 7# To create a shared library, use "configure --shared"; by default a static 8# library is created. If the primitive shared library support provided here 9# does not work, use ftp://prep.ai.mit.edu/pub/gnu/libtool-*.tar.gz 10# 11# To impose specific compiler or flags or install directory, use for example: 12# prefix=$HOME CC=cc CFLAGS="-O4" ./configure 13# or for csh/tcsh users: 14# (setenv prefix $HOME; setenv CC cc; setenv CFLAGS "-O4"; ./configure) 15# LDSHARED is the command to be used to create a shared library 16 17# Incorrect settings of CC or CFLAGS may prevent creating a shared library. 18# If you have problems, try without defining CC and CFLAGS before reporting 19# an error. 20 21LIBS=libz.a 22LDFLAGS="-L. ${LIBS}" 23VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h` 24VER2=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\)\\..*/\1/p' < zlib.h` 25VER1=`sed -n -e '/VERSION "/s/.*"\([0-9]*\)\\..*/\1/p' < zlib.h` 26AR=${AR-"ar rc"} 27RANLIB=${RANLIB-"ranlib"} 28prefix=${prefix-/usr/local} 29exec_prefix=${exec_prefix-'${prefix}'} 30libdir=${libdir-'${exec_prefix}/lib'} 31includedir=${includedir-'${prefix}/include'} 32mandir=${mandir-'${prefix}/share/man'} 33shared_ext='.so' 34shared=0 35gcc=0 36old_cc="$CC" 37old_cflags="$CFLAGS" 38 39while test $# -ge 1 40do 41case "$1" in 42 -h* | --h*) 43 echo 'usage:' 44 echo ' configure [--shared] [--prefix=PREFIX] [--exec_prefix=EXPREFIX]' 45 echo ' [--libdir=LIBDIR] [--includedir=INCLUDEDIR]' 46 exit 0;; 47 -p*=* | --p*=*) prefix=`echo $1 | sed 's/[-a-z_]*=//'`; shift;; 48 -e*=* | --e*=*) exec_prefix=`echo $1 | sed 's/[-a-z_]*=//'`; shift;; 49 -l*=* | --libdir=*) libdir=`echo $1 | sed 's/[-a-z_]*=//'`; shift;; 50 -i*=* | --includedir=*) includedir=`echo $1 | sed 's/[-a-z_]*=//'`;shift;; 51 -p* | --p*) prefix="$2"; shift; shift;; 52 -e* | --e*) exec_prefix="$2"; shift; shift;; 53 -l* | --l*) libdir="$2"; shift; shift;; 54 -i* | --i*) includedir="$2"; shift; shift;; 55 -s* | --s*) shared=1; shift;; 56 *) echo "unknown option: $1"; echo "$0 --help for help"; exit 1;; 57 esac 58done 59 60test=ztest$$ 61cat > $test.c <<EOF 62extern int getchar(); 63int hello() {return getchar();} 64EOF 65 66test -z "$CC" && echo Checking for gcc... 67cc=${CC-gcc} 68cflags=${CFLAGS-"-O3"} 69# to force the asm version use: CFLAGS="-O3 -DASMV" ./configure 70case "$cc" in 71 *gcc*) gcc=1;; 72esac 73 74if test "$gcc" -eq 1 && ($cc -c $cflags $test.c) 2>/dev/null; then 75 CC="$cc" 76 SFLAGS=${CFLAGS-"-fPIC -O3"} 77 CFLAGS="$cflags" 78 case `(uname -s || echo unknown) 2>/dev/null` in 79 Linux | linux | GNU | GNU/*) LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1"};; 80 CYGWIN* | Cygwin* | cygwin* | OS/2* ) 81 EXE='.exe';; 82 QNX*) # This is for QNX6. I suppose that the QNX rule below is for QNX2,QNX4 83 # (alain.bonnefoy@icbt.com) 84 LDSHARED=${LDSHARED-"$cc -shared -Wl,-hlibz.so.1"};; 85 HP-UX*) LDSHARED=${LDSHARED-"$cc -shared $SFLAGS"} 86 shared_ext='.sl' 87 SHAREDLIB='libz.sl';; 88 Darwin*) shared_ext='.dylib' 89 SHAREDLIB=libz$shared_ext 90 SHAREDLIBV=libz.$VER$shared_ext 91 SHAREDLIBM=libz.$VER1$shared_ext 92 LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBM -compatibility_version $VER1 -current_version $VER"};; 93 *) LDSHARED=${LDSHARED-"$cc -shared"};; 94 esac 95else 96 # find system name and corresponding cc options 97 CC=${CC-cc} 98 case `(uname -sr || echo unknown) 2>/dev/null` in 99 HP-UX*) SFLAGS=${CFLAGS-"-O +z"} 100 CFLAGS=${CFLAGS-"-O"} 101# LDSHARED=${LDSHARED-"ld -b +vnocompatwarnings"} 102 LDSHARED=${LDSHARED-"ld -b"} 103 shared_ext='.sl' 104 SHAREDLIB='libz.sl';; 105 IRIX*) SFLAGS=${CFLAGS-"-ansi -O2 -rpath ."} 106 CFLAGS=${CFLAGS-"-ansi -O2"} 107 LDSHARED=${LDSHARED-"cc -shared"};; 108 OSF1\ V4*) SFLAGS=${CFLAGS-"-O -std1"} 109 CFLAGS=${CFLAGS-"-O -std1"} 110 LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so -Wl,-msym -Wl,-rpath,$(libdir) -Wl,-set_version,${VER}:1.0"};; 111 OSF1*) SFLAGS=${CFLAGS-"-O -std1"} 112 CFLAGS=${CFLAGS-"-O -std1"} 113 LDSHARED=${LDSHARED-"cc -shared"};; 114 QNX*) SFLAGS=${CFLAGS-"-4 -O"} 115 CFLAGS=${CFLAGS-"-4 -O"} 116 LDSHARED=${LDSHARED-"cc"} 117 RANLIB=${RANLIB-"true"} 118 AR="cc -A";; 119 SCO_SV\ 3.2*) SFLAGS=${CFLAGS-"-O3 -dy -KPIC "} 120 CFLAGS=${CFLAGS-"-O3"} 121 LDSHARED=${LDSHARED-"cc -dy -KPIC -G"};; 122 SunOS\ 5*) SFLAGS=${CFLAGS-"-fast -xcg89 -KPIC -R."} 123 CFLAGS=${CFLAGS-"-fast -xcg89"} 124 LDSHARED=${LDSHARED-"cc -G"};; 125 SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"} 126 CFLAGS=${CFLAGS-"-O2"} 127 LDSHARED=${LDSHARED-"ld"};; 128 SunStudio\ 9*) SFLAGS=${CFLAGS-"-DUSE_MMAP -fast -xcode=pic32 -xtarget=ultra3 -xarch=v9b"} 129 CFLAGS=${CFLAGS-"-DUSE_MMAP -fast -xtarget=ultra3 -xarch=v9b"} 130 LDSHARED=${LDSHARED-"cc -xarch=v9b"};; 131 UNIX_System_V\ 4.2.0) 132 SFLAGS=${CFLAGS-"-KPIC -O"} 133 CFLAGS=${CFLAGS-"-O"} 134 LDSHARED=${LDSHARED-"cc -G"};; 135 UNIX_SV\ 4.2MP) 136 SFLAGS=${CFLAGS-"-Kconform_pic -O"} 137 CFLAGS=${CFLAGS-"-O"} 138 LDSHARED=${LDSHARED-"cc -G"};; 139 OpenUNIX\ 5) 140 SFLAGS=${CFLAGS-"-KPIC -O"} 141 CFLAGS=${CFLAGS-"-O"} 142 LDSHARED=${LDSHARED-"cc -G"};; 143 AIX*) # Courtesy of dbakker@arrayasolutions.com 144 SFLAGS=${CFLAGS-"-O -qmaxmem=8192"} 145 CFLAGS=${CFLAGS-"-O -qmaxmem=8192"} 146 LDSHARED=${LDSHARED-"xlc -G"};; 147 # send working options for other systems to support@gzip.org 148 *) SFLAGS=${CFLAGS-"-O"} 149 CFLAGS=${CFLAGS-"-O"} 150 LDSHARED=${LDSHARED-"cc -shared"};; 151 esac 152fi 153 154SHAREDLIB=${SHAREDLIB-"libz$shared_ext"} 155SHAREDLIBV=${SHAREDLIBV-"libz$shared_ext.$VER"} 156SHAREDLIBM=${SHAREDLIBM-"libz$shared_ext.$VER1"} 157 158if test $shared -eq 1; then 159 echo Checking for shared library support... 160 # we must test in two steps (cc then ld), required at least on SunOS 4.x 161 if test "`($CC -c $SFLAGS $test.c) 2>&1`" = "" && 162 test "`($LDSHARED -o $test$shared_ext $test.o) 2>&1`" = ""; then 163 CFLAGS="$SFLAGS" 164 LIBS="$SHAREDLIBV" 165 echo Building shared library $SHAREDLIBV with $CC. 166 elif test -z "$old_cc" -a -z "$old_cflags"; then 167 echo No shared library support. 168 shared=0; 169 else 170 echo 'No shared library support; try without defining CC and CFLAGS' 171 shared=0; 172 fi 173fi 174if test $shared -eq 0; then 175 LDSHARED="$CC" 176 echo Building static library $LIBS version $VER with $CC. 177else 178 LDFLAGS="-L. ${SHAREDLIBV}" 179fi 180 181cat > $test.c <<EOF 182#include <unistd.h> 183int main() { return 0; } 184EOF 185if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then 186 sed < zconf.in.h "/HAVE_UNISTD_H/s%0%1%" > zconf.h 187 echo "Checking for unistd.h... Yes." 188else 189 cp -p zconf.in.h zconf.h 190 echo "Checking for unistd.h... No." 191fi 192 193cat > $test.c <<EOF 194#include <stdio.h> 195#include <stdarg.h> 196#include "zconf.h" 197 198int main() 199{ 200#ifndef STDC 201 choke me 202#endif 203 204 return 0; 205} 206EOF 207 208if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then 209 echo "Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf()" 210 211 cat > $test.c <<EOF 212#include <stdio.h> 213#include <stdarg.h> 214 215int mytest(char *fmt, ...) 216{ 217 char buf[20]; 218 va_list ap; 219 220 va_start(ap, fmt); 221 vsnprintf(buf, sizeof(buf), fmt, ap); 222 va_end(ap); 223 return 0; 224} 225 226int main() 227{ 228 return (mytest("Hello%d\n", 1)); 229} 230EOF 231 232 if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then 233 echo "Checking for vsnprintf() in stdio.h... Yes." 234 235 cat >$test.c <<EOF 236#include <stdio.h> 237#include <stdarg.h> 238 239int mytest(char *fmt, ...) 240{ 241 int n; 242 char buf[20]; 243 va_list ap; 244 245 va_start(ap, fmt); 246 n = vsnprintf(buf, sizeof(buf), fmt, ap); 247 va_end(ap); 248 return n; 249} 250 251int main() 252{ 253 return (mytest("Hello%d\n", 1)); 254} 255EOF 256 257 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then 258 echo "Checking for return value of vsnprintf()... Yes." 259 else 260 CFLAGS="$CFLAGS -DHAS_vsnprintf_void" 261 echo "Checking for return value of vsnprintf()... No." 262 echo " WARNING: apparently vsnprintf() does not return a value. zlib" 263 echo " can build but will be open to possible string-format security" 264 echo " vulnerabilities." 265 fi 266 else 267 CFLAGS="$CFLAGS -DNO_vsnprintf" 268 echo "Checking for vsnprintf() in stdio.h... No." 269 echo " WARNING: vsnprintf() not found, falling back to vsprintf(). zlib" 270 echo " can build but will be open to possible buffer-overflow security" 271 echo " vulnerabilities." 272 273 cat >$test.c <<EOF 274#include <stdio.h> 275#include <stdarg.h> 276 277int mytest(char *fmt, ...) 278{ 279 int n; 280 char buf[20]; 281 va_list ap; 282 283 va_start(ap, fmt); 284 n = vsprintf(buf, fmt, ap); 285 va_end(ap); 286 return n; 287} 288 289int main() 290{ 291 return (mytest("Hello%d\n", 1)); 292} 293EOF 294 295 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then 296 echo "Checking for return value of vsprintf()... Yes." 297 else 298 CFLAGS="$CFLAGS -DHAS_vsprintf_void" 299 echo "Checking for return value of vsprintf()... No." 300 echo " WARNING: apparently vsprintf() does not return a value. zlib" 301 echo " can build but will be open to possible string-format security" 302 echo " vulnerabilities." 303 fi 304 fi 305else 306 echo "Checking whether to use vs[n]printf() or s[n]printf()... using s[n]printf()" 307 308 cat >$test.c <<EOF 309#include <stdio.h> 310 311int mytest() 312{ 313 char buf[20]; 314 315 snprintf(buf, sizeof(buf), "%s", "foo"); 316 return 0; 317} 318 319int main() 320{ 321 return (mytest()); 322} 323EOF 324 325 if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then 326 echo "Checking for snprintf() in stdio.h... Yes." 327 328 cat >$test.c <<EOF 329#include <stdio.h> 330 331int mytest() 332{ 333 char buf[20]; 334 335 return snprintf(buf, sizeof(buf), "%s", "foo"); 336} 337 338int main() 339{ 340 return (mytest()); 341} 342EOF 343 344 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then 345 echo "Checking for return value of snprintf()... Yes." 346 else 347 CFLAGS="$CFLAGS -DHAS_snprintf_void" 348 echo "Checking for return value of snprintf()... No." 349 echo " WARNING: apparently snprintf() does not return a value. zlib" 350 echo " can build but will be open to possible string-format security" 351 echo " vulnerabilities." 352 fi 353 else 354 CFLAGS="$CFLAGS -DNO_snprintf" 355 echo "Checking for snprintf() in stdio.h... No." 356 echo " WARNING: snprintf() not found, falling back to sprintf(). zlib" 357 echo " can build but will be open to possible buffer-overflow security" 358 echo " vulnerabilities." 359 360 cat >$test.c <<EOF 361#include <stdio.h> 362 363int mytest() 364{ 365 char buf[20]; 366 367 return sprintf(buf, "%s", "foo"); 368} 369 370int main() 371{ 372 return (mytest()); 373} 374EOF 375 376 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then 377 echo "Checking for return value of sprintf()... Yes." 378 else 379 CFLAGS="$CFLAGS -DHAS_sprintf_void" 380 echo "Checking for return value of sprintf()... No." 381 echo " WARNING: apparently sprintf() does not return a value. zlib" 382 echo " can build but will be open to possible string-format security" 383 echo " vulnerabilities." 384 fi 385 fi 386fi 387 388cat >$test.c <<EOF 389#include <errno.h> 390int main() { return 0; } 391EOF 392if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then 393 echo "Checking for errno.h... Yes." 394else 395 echo "Checking for errno.h... No." 396 CFLAGS="$CFLAGS -DNO_ERRNO_H" 397fi 398 399cat > $test.c <<EOF 400#include <sys/types.h> 401#include <sys/mman.h> 402#include <sys/stat.h> 403caddr_t hello() { 404 return mmap((caddr_t)0, (off_t)0, PROT_READ, MAP_SHARED, 0, (off_t)0); 405} 406EOF 407if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then 408 CFLAGS="$CFLAGS -DUSE_MMAP" 409 echo Checking for mmap support... Yes. 410else 411 echo Checking for mmap support... No. 412fi 413 414CPP=${CPP-"$CC -E"} 415case $CFLAGS in 416 *ASMV*) 417 if test "`nm $test.o | grep _hello`" = ""; then 418 CPP="$CPP -DNO_UNDERLINE" 419 echo Checking for underline in external names... No. 420 else 421 echo Checking for underline in external names... Yes. 422 fi;; 423esac 424 425rm -f $test.[co] $test $test$shared_ext 426 427# udpate Makefile 428sed < Makefile.in " 429/^CC *=/s#=.*#=$CC# 430/^CFLAGS *=/s#=.*#=$CFLAGS# 431/^CPP *=/s#=.*#=$CPP# 432/^LDSHARED *=/s#=.*#=$LDSHARED# 433/^LIBS *=/s#=.*#=$LIBS# 434/^SHAREDLIB *=/s#=.*#=$SHAREDLIB# 435/^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV# 436/^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM# 437/^AR *=/s#=.*#=$AR# 438/^RANLIB *=/s#=.*#=$RANLIB# 439/^EXE *=/s#=.*#=$EXE# 440/^prefix *=/s#=.*#=$prefix# 441/^exec_prefix *=/s#=.*#=$exec_prefix# 442/^libdir *=/s#=.*#=$libdir# 443/^includedir *=/s#=.*#=$includedir# 444/^mandir *=/s#=.*#=$mandir# 445/^LDFLAGS *=/s#=.*#=$LDFLAGS# 446" > Makefile 447