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/$SHAREDLIBV -compatibility_version $VER2 -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 UNIX_System_V\ 4.2.0) 129 SFLAGS=${CFLAGS-"-KPIC -O"} 130 CFLAGS=${CFLAGS-"-O"} 131 LDSHARED=${LDSHARED-"cc -G"};; 132 UNIX_SV\ 4.2MP) 133 SFLAGS=${CFLAGS-"-Kconform_pic -O"} 134 CFLAGS=${CFLAGS-"-O"} 135 LDSHARED=${LDSHARED-"cc -G"};; 136 OpenUNIX\ 5) 137 SFLAGS=${CFLAGS-"-KPIC -O"} 138 CFLAGS=${CFLAGS-"-O"} 139 LDSHARED=${LDSHARED-"cc -G"};; 140 AIX*) # Courtesy of dbakker@arrayasolutions.com 141 SFLAGS=${CFLAGS-"-O -qmaxmem=8192"} 142 CFLAGS=${CFLAGS-"-O -qmaxmem=8192"} 143 LDSHARED=${LDSHARED-"xlc -G"};; 144 # send working options for other systems to support@gzip.org 145 *) SFLAGS=${CFLAGS-"-O"} 146 CFLAGS=${CFLAGS-"-O"} 147 LDSHARED=${LDSHARED-"cc -shared"};; 148 esac 149fi 150 151SHAREDLIB=${SHAREDLIB-"libz$shared_ext"} 152SHAREDLIBV=${SHAREDLIBV-"libz$shared_ext.$VER"} 153SHAREDLIBM=${SHAREDLIBM-"libz$shared_ext.$VER1"} 154 155if test $shared -eq 1; then 156 echo Checking for shared library support... 157 # we must test in two steps (cc then ld), required at least on SunOS 4.x 158 if test "`($CC -c $SFLAGS $test.c) 2>&1`" = "" && 159 test "`($LDSHARED -o $test$shared_ext $test.o) 2>&1`" = ""; then 160 CFLAGS="$SFLAGS" 161 LIBS="$SHAREDLIBV" 162 echo Building shared library $SHAREDLIBV with $CC. 163 elif test -z "$old_cc" -a -z "$old_cflags"; then 164 echo No shared library support. 165 shared=0; 166 else 167 echo 'No shared library support; try without defining CC and CFLAGS' 168 shared=0; 169 fi 170fi 171if test $shared -eq 0; then 172 LDSHARED="$CC" 173 echo Building static library $LIBS version $VER with $CC. 174else 175 LDFLAGS="-L. ${SHAREDLIBV}" 176fi 177 178cat > $test.c <<EOF 179#include <unistd.h> 180int main() { return 0; } 181EOF 182if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then 183 sed < zconf.in.h "/HAVE_UNISTD_H/s%0%1%" > zconf.h 184 echo "Checking for unistd.h... Yes." 185else 186 cp -p zconf.in.h zconf.h 187 echo "Checking for unistd.h... No." 188fi 189 190cat > $test.c <<EOF 191#include <stdio.h> 192#include <stdarg.h> 193#include "zconf.h" 194 195int main() 196{ 197#ifndef STDC 198 choke me 199#endif 200 201 return 0; 202} 203EOF 204 205if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then 206 echo "Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf()" 207 208 cat > $test.c <<EOF 209#include <stdio.h> 210#include <stdarg.h> 211 212int mytest(char *fmt, ...) 213{ 214 char buf[20]; 215 va_list ap; 216 217 va_start(ap, fmt); 218 vsnprintf(buf, sizeof(buf), fmt, ap); 219 va_end(ap); 220 return 0; 221} 222 223int main() 224{ 225 return (mytest("Hello%d\n", 1)); 226} 227EOF 228 229 if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then 230 echo "Checking for vsnprintf() in stdio.h... Yes." 231 232 cat >$test.c <<EOF 233#include <stdio.h> 234#include <stdarg.h> 235 236int mytest(char *fmt, ...) 237{ 238 int n; 239 char buf[20]; 240 va_list ap; 241 242 va_start(ap, fmt); 243 n = vsnprintf(buf, sizeof(buf), fmt, ap); 244 va_end(ap); 245 return n; 246} 247 248int main() 249{ 250 return (mytest("Hello%d\n", 1)); 251} 252EOF 253 254 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then 255 echo "Checking for return value of vsnprintf()... Yes." 256 else 257 CFLAGS="$CFLAGS -DHAS_vsnprintf_void" 258 echo "Checking for return value of vsnprintf()... No." 259 echo " WARNING: apparently vsnprintf() does not return a value. zlib" 260 echo " can build but will be open to possible string-format security" 261 echo " vulnerabilities." 262 fi 263 else 264 CFLAGS="$CFLAGS -DNO_vsnprintf" 265 echo "Checking for vsnprintf() in stdio.h... No." 266 echo " WARNING: vsnprintf() not found, falling back to vsprintf(). zlib" 267 echo " can build but will be open to possible buffer-overflow security" 268 echo " vulnerabilities." 269 270 cat >$test.c <<EOF 271#include <stdio.h> 272#include <stdarg.h> 273 274int mytest(char *fmt, ...) 275{ 276 int n; 277 char buf[20]; 278 va_list ap; 279 280 va_start(ap, fmt); 281 n = vsprintf(buf, fmt, ap); 282 va_end(ap); 283 return n; 284} 285 286int main() 287{ 288 return (mytest("Hello%d\n", 1)); 289} 290EOF 291 292 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then 293 echo "Checking for return value of vsprintf()... Yes." 294 else 295 CFLAGS="$CFLAGS -DHAS_vsprintf_void" 296 echo "Checking for return value of vsprintf()... No." 297 echo " WARNING: apparently vsprintf() does not return a value. zlib" 298 echo " can build but will be open to possible string-format security" 299 echo " vulnerabilities." 300 fi 301 fi 302else 303 echo "Checking whether to use vs[n]printf() or s[n]printf()... using s[n]printf()" 304 305 cat >$test.c <<EOF 306#include <stdio.h> 307 308int mytest() 309{ 310 char buf[20]; 311 312 snprintf(buf, sizeof(buf), "%s", "foo"); 313 return 0; 314} 315 316int main() 317{ 318 return (mytest()); 319} 320EOF 321 322 if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then 323 echo "Checking for snprintf() in stdio.h... Yes." 324 325 cat >$test.c <<EOF 326#include <stdio.h> 327 328int mytest() 329{ 330 char buf[20]; 331 332 return snprintf(buf, sizeof(buf), "%s", "foo"); 333} 334 335int main() 336{ 337 return (mytest()); 338} 339EOF 340 341 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then 342 echo "Checking for return value of snprintf()... Yes." 343 else 344 CFLAGS="$CFLAGS -DHAS_snprintf_void" 345 echo "Checking for return value of snprintf()... No." 346 echo " WARNING: apparently snprintf() does not return a value. zlib" 347 echo " can build but will be open to possible string-format security" 348 echo " vulnerabilities." 349 fi 350 else 351 CFLAGS="$CFLAGS -DNO_snprintf" 352 echo "Checking for snprintf() in stdio.h... No." 353 echo " WARNING: snprintf() not found, falling back to sprintf(). zlib" 354 echo " can build but will be open to possible buffer-overflow security" 355 echo " vulnerabilities." 356 357 cat >$test.c <<EOF 358#include <stdio.h> 359 360int mytest() 361{ 362 char buf[20]; 363 364 return sprintf(buf, "%s", "foo"); 365} 366 367int main() 368{ 369 return (mytest()); 370} 371EOF 372 373 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then 374 echo "Checking for return value of sprintf()... Yes." 375 else 376 CFLAGS="$CFLAGS -DHAS_sprintf_void" 377 echo "Checking for return value of sprintf()... No." 378 echo " WARNING: apparently sprintf() does not return a value. zlib" 379 echo " can build but will be open to possible string-format security" 380 echo " vulnerabilities." 381 fi 382 fi 383fi 384 385cat >$test.c <<EOF 386#include <errno.h> 387int main() { return 0; } 388EOF 389if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then 390 echo "Checking for errno.h... Yes." 391else 392 echo "Checking for errno.h... No." 393 CFLAGS="$CFLAGS -DNO_ERRNO_H" 394fi 395 396cat > $test.c <<EOF 397#include <sys/types.h> 398#include <sys/mman.h> 399#include <sys/stat.h> 400caddr_t hello() { 401 return mmap((caddr_t)0, (off_t)0, PROT_READ, MAP_SHARED, 0, (off_t)0); 402} 403EOF 404if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then 405 CFLAGS="$CFLAGS -DUSE_MMAP" 406 echo Checking for mmap support... Yes. 407else 408 echo Checking for mmap support... No. 409fi 410 411CPP=${CPP-"$CC -E"} 412case $CFLAGS in 413 *ASMV*) 414 if test "`nm $test.o | grep _hello`" = ""; then 415 CPP="$CPP -DNO_UNDERLINE" 416 echo Checking for underline in external names... No. 417 else 418 echo Checking for underline in external names... Yes. 419 fi;; 420esac 421 422rm -f $test.[co] $test $test$shared_ext 423 424# udpate Makefile 425sed < Makefile.in " 426/^CC *=/s#=.*#=$CC# 427/^CFLAGS *=/s#=.*#=$CFLAGS# 428/^CPP *=/s#=.*#=$CPP# 429/^LDSHARED *=/s#=.*#=$LDSHARED# 430/^LIBS *=/s#=.*#=$LIBS# 431/^SHAREDLIB *=/s#=.*#=$SHAREDLIB# 432/^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV# 433/^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM# 434/^AR *=/s#=.*#=$AR# 435/^RANLIB *=/s#=.*#=$RANLIB# 436/^EXE *=/s#=.*#=$EXE# 437/^prefix *=/s#=.*#=$prefix# 438/^exec_prefix *=/s#=.*#=$exec_prefix# 439/^libdir *=/s#=.*#=$libdir# 440/^includedir *=/s#=.*#=$includedir# 441/^mandir *=/s#=.*#=$mandir# 442/^LDFLAGS *=/s#=.*#=$LDFLAGS# 443" > Makefile 444