2 # configure script for zlib.
4 # Normally configure builds both a static and a shared library.
5 # If you want to build just a static library, use: ./configure --static
7 # To impose specific compiler or flags or install directory, use for example:
8 # prefix=$HOME CC=cc CFLAGS="-O4" ./configure
9 # or for csh/tcsh users:
10 # (setenv prefix $HOME; setenv CC cc; setenv CFLAGS "-O4"; ./configure)
12 # Incorrect settings of CC or CFLAGS may prevent creating a shared library.
13 # If you have problems, try without defining CC and CFLAGS before reporting
17 LDFLAGS="${LDFLAGS} -L. ${STATICLIB}"
18 VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`
19 VER3=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\\.[0-9]*\)\\..*/\1/p' < zlib.h`
20 VER2=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\)\\..*/\1/p' < zlib.h`
21 VER1=`sed -n -e '/VERSION "/s/.*"\([0-9]*\)\\..*/\1/p' < zlib.h`
24 RANLIB=${RANLIB-"ranlib"}
25 prefix=${prefix-/usr/local}
26 exec_prefix=${exec_prefix-'${prefix}'}
27 libdir=${libdir-'${exec_prefix}/lib'}
28 includedir=${includedir-'${prefix}/include'}
29 mandir=${mandir-'${prefix}/share/man'}
42 echo ' configure [--shared] [--prefix=PREFIX] [--exec_prefix=EXPREFIX]'
43 echo ' [--libdir=LIBDIR] [--includedir=INCLUDEDIR] [--zprefix]'
45 -p*=* | --prefix=*) prefix=`echo $1 | sed 's/[-a-z_]*=//'`; shift ;;
46 -e*=* | --eprefix=*) exec_prefix=`echo $1 | sed 's/[-a-z_]*=//'`; shift ;;
47 -l*=* | --libdir=*) libdir=`echo $1 | sed 's/[-a-z_]*=//'`; shift ;;
48 -i*=* | --includedir=*) includedir=`echo $1 | sed 's/[-a-z_]*=//'`;shift ;;
49 -u*=* | --uname=*) uname=`echo $1 | sed 's/[-a-z_]*=//'`;shift ;;
50 -p* | --prefix) prefix="$2"; shift; shift ;;
51 -e* | --eprefix) exec_prefix="$2"; shift; shift ;;
52 -l* | --libdir) libdir="$2"; shift; shift ;;
53 -i* | --includedir) includedir="$2"; shift; shift ;;
54 -s* | --shared | --enable-shared) shared=1; shift ;;
55 -t | --static) shared=0; shift ;;
56 -z* | --zprefix) zprefix=1; shift ;;
57 --sysconfdir=*) echo "ignored option: --sysconfdir"; shift ;;
58 --localstatedir=*) echo "ignored option: --localstatedir"; shift ;;
59 *) echo "unknown option: $1"; echo "$0 --help for help"; exit 1 ;;
66 int hello() {return getchar();}
69 test -z "$CC" && echo Checking for gcc...
71 cflags=${CFLAGS-"-O3"}
72 # to force the asm version use: CFLAGS="-O3 -DASMV" ./configure
77 if test "$gcc" -eq 1 && ($cc -c $cflags $test.c) 2>/dev/null; then
79 SFLAGS="${CFLAGS-"-O3"} -fPIC"
80 CFLAGS="${CFLAGS-"-O3"}"
81 if test -z "$uname"; then
82 uname=`(uname -s || echo unknown) 2>/dev/null`
85 Linux | linux | GNU | GNU/*) LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map"} ;;
86 CYGWIN* | Cygwin* | cygwin* | OS/2* )
88 QNX*) # This is for QNX6. I suppose that the QNX rule below is for QNX2,QNX4
89 # (alain.bonnefoy@icbt.com)
90 LDSHARED=${LDSHARED-"$cc -shared -Wl,-hlibz.so.1"} ;;
92 LDSHARED=${LDSHARED-"$cc -shared $SFLAGS"}
93 case `(uname -m || echo unknown) 2>/dev/null` in
96 SHAREDLIB='libz.so' ;;
99 SHAREDLIB='libz.sl' ;;
101 Darwin*) shared_ext='.dylib'
102 SHAREDLIB=libz$shared_ext
103 SHAREDLIBV=libz.$VER$shared_ext
104 SHAREDLIBM=libz.$VER1$shared_ext
105 LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBM -compatibility_version $VER1 -current_version $VER3"} ;;
106 *) LDSHARED=${LDSHARED-"$cc -shared"} ;;
109 # find system name and corresponding cc options
111 if test -z "$uname"; then
112 uname=`(uname -sr || echo unknown) 2>/dev/null`
115 HP-UX*) SFLAGS=${CFLAGS-"-O +z"}
116 CFLAGS=${CFLAGS-"-O"}
117 # LDSHARED=${LDSHARED-"ld -b +vnocompatwarnings"}
118 LDSHARED=${LDSHARED-"ld -b"}
119 case `(uname -m || echo unknown) 2>/dev/null` in
122 SHAREDLIB='libz.so' ;;
125 SHAREDLIB='libz.sl' ;;
127 IRIX*) SFLAGS=${CFLAGS-"-ansi -O2 -rpath ."}
128 CFLAGS=${CFLAGS-"-ansi -O2"}
129 LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;;
130 OSF1\ V4*) SFLAGS=${CFLAGS-"-O -std1"}
131 CFLAGS=${CFLAGS-"-O -std1"}
132 LDFLAGS="${LDFLAGS} -Wl,-rpath,."
133 LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so -Wl,-msym -Wl,-rpath,$(libdir) -Wl,-set_version,${VER}:1.0"} ;;
134 OSF1*) SFLAGS=${CFLAGS-"-O -std1"}
135 CFLAGS=${CFLAGS-"-O -std1"}
136 LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;;
137 QNX*) SFLAGS=${CFLAGS-"-4 -O"}
138 CFLAGS=${CFLAGS-"-4 -O"}
139 LDSHARED=${LDSHARED-"cc"}
140 RANLIB=${RANLIB-"true"}
142 SCO_SV\ 3.2*) SFLAGS=${CFLAGS-"-O3 -dy -KPIC "}
143 CFLAGS=${CFLAGS-"-O3"}
144 LDSHARED=${LDSHARED-"cc -dy -KPIC -G"} ;;
145 SunOS\ 5*) LDSHARED=${LDSHARED-"cc -G"}
146 case `(uname -m || echo unknown) 2>/dev/null` in
148 SFLAGS=${CFLAGS-"-xpentium -fast -KPIC -R."}
149 CFLAGS=${CFLAGS-"-xpentium -fast"} ;;
151 SFLAGS=${CFLAGS-"-fast -xcg92 -KPIC -R."}
152 CFLAGS=${CFLAGS-"-fast -xcg92"} ;;
154 SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"}
155 CFLAGS=${CFLAGS-"-O2"}
156 LDSHARED=${LDSHARED-"ld"} ;;
157 SunStudio\ 9*) SFLAGS=${CFLAGS-"-DUSE_MMAP -fast -xcode=pic32 -xtarget=ultra3 -xarch=v9b"}
158 CFLAGS=${CFLAGS-"-DUSE_MMAP -fast -xtarget=ultra3 -xarch=v9b"}
159 LDSHARED=${LDSHARED-"cc -xarch=v9b"} ;;
160 UNIX_System_V\ 4.2.0)
161 SFLAGS=${CFLAGS-"-KPIC -O"}
162 CFLAGS=${CFLAGS-"-O"}
163 LDSHARED=${LDSHARED-"cc -G"} ;;
165 SFLAGS=${CFLAGS-"-Kconform_pic -O"}
166 CFLAGS=${CFLAGS-"-O"}
167 LDSHARED=${LDSHARED-"cc -G"} ;;
169 SFLAGS=${CFLAGS-"-KPIC -O"}
170 CFLAGS=${CFLAGS-"-O"}
171 LDSHARED=${LDSHARED-"cc -G"} ;;
172 AIX*) # Courtesy of dbakker@arrayasolutions.com
173 SFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
174 CFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
175 LDSHARED=${LDSHARED-"xlc -G"} ;;
176 # send working options for other systems to support@gzip.org
177 *) SFLAGS=${CFLAGS-"-O"}
178 CFLAGS=${CFLAGS-"-O"}
179 LDSHARED=${LDSHARED-"cc -shared"} ;;
183 SHAREDLIB=${SHAREDLIB-"libz$shared_ext"}
184 SHAREDLIBV=${SHAREDLIBV-"libz$shared_ext.$VER"}
185 SHAREDLIBM=${SHAREDLIBM-"libz$shared_ext.$VER1"}
187 if test $shared -eq 1; then
188 echo Checking for shared library support...
189 # we must test in two steps (cc then ld), required at least on SunOS 4.x
190 if test "`($CC -w -c $SFLAGS $test.c) 2>&1`" = "" &&
191 test "`($LDSHARED -o $test$shared_ext $test.o) 2>&1`" = ""; then
192 echo Building shared library $SHAREDLIBV with $CC.
193 elif test -z "$old_cc" -a -z "$old_cflags"; then
194 echo No shared library support.
197 echo Tested $CC -w -c $SFLAGS $test.c
198 $CC -w -c $SFLAGS $test.c
199 echo Tested $LDSHARED -o $test$shared_ext $test.o
200 $LDSHARED -o $test$shared_ext $test.o
201 echo 'No shared library support; try without defining CC and CFLAGS'
205 if test $shared -eq 0; then
208 TEST="all teststatic"
209 echo Building static library $STATICLIB version $VER with $CC.
212 TEST="all teststatic testshared"
215 cat > zlibdefs.h << EOF
216 /* zlibdefs.h -- compile-time definitions for the zlib compression library
217 * Copyright (C) 1995-2006 Jean-loup Gailly.
218 * For conditions of distribution and use, see copyright notice in zlib.h
224 #include <sys/types.h>
227 if test "`($CC -c $CFLAGS -D_LARGEFILE64_SOURCE=1 $test.c) 2>&1`" = ""; then
228 CFLAGS="${CFLAGS} -D_LARGEFILE64_SOURCE=1"
229 SFLAGS="${SFLAGS} -D_LARGEFILE64_SOURCE=1"
231 TEST="${TEST} test64"
232 echo "Checking for off64_t... Yes."
233 echo "Checking for fseeko... Yes."
235 echo "Checking for off64_t... No."
243 if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then
244 echo "Checking for fseeko... Yes."
246 CFLAGS="${CFLAGS} -DNO_FSEEKO"
247 SFLAGS="${SFLAGS} -DNO_FSEEKO"
248 echo "Checking for fseeko... No."
254 int main() { return 0; }
256 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
257 cat >> zlibdefs.h <<EOF
258 #include <sys/types.h> /* for off_t */
259 #include <unistd.h> /* for SEEK_* and off_t */
261 # include <unixio.h> /* for off_t */
264 # define z_off_t off_t
267 echo "Checking for unistd.h... Yes."
269 echo "Checking for unistd.h... No."
272 if test $zprefix -eq 1; then
273 sed < zconf.h "/#ifdef Z_PREFIX/s/def Z_PREFIX/ 1/" > zconf.temp.h
274 mv zconf.temp.h zconf.h
275 echo "Using z_ prefix on all symbols."
293 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
294 echo "Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf()."
300 int mytest(char *fmt, ...)
306 vsnprintf(buf, sizeof(buf), fmt, ap);
313 return (mytest("Hello%d\n", 1));
317 if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then
318 echo "Checking for vsnprintf() in stdio.h... Yes."
324 int mytest(char *fmt, ...)
331 n = vsnprintf(buf, sizeof(buf), fmt, ap);
338 return (mytest("Hello%d\n", 1));
342 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
343 echo "Checking for return value of vsnprintf()... Yes."
345 CFLAGS="$CFLAGS -DHAS_vsnprintf_void"
346 SFLAGS="$SFLAGS -DHAS_vsnprintf_void"
347 echo "Checking for return value of vsnprintf()... No."
348 echo " WARNING: apparently vsnprintf() does not return a value. zlib"
349 echo " can build but will be open to possible string-format security"
350 echo " vulnerabilities."
353 CFLAGS="$CFLAGS -DNO_vsnprintf"
354 SFLAGS="$SFLAGS -DNO_vsnprintf"
355 echo "Checking for vsnprintf() in stdio.h... No."
356 echo " WARNING: vsnprintf() not found, falling back to vsprintf(). zlib"
357 echo " can build but will be open to possible buffer-overflow security"
358 echo " vulnerabilities."
364 int mytest(char *fmt, ...)
371 n = vsprintf(buf, fmt, ap);
378 return (mytest("Hello%d\n", 1));
382 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
383 echo "Checking for return value of vsprintf()... Yes."
385 CFLAGS="$CFLAGS -DHAS_vsprintf_void"
386 SFLAGS="$SFLAGS -DHAS_vsprintf_void"
387 echo "Checking for return value of vsprintf()... No."
388 echo " WARNING: apparently vsprintf() does not return a value. zlib"
389 echo " can build but will be open to possible string-format security"
390 echo " vulnerabilities."
394 echo "Checking whether to use vs[n]printf() or s[n]printf()... using s[n]printf()."
403 snprintf(buf, sizeof(buf), "%s", "foo");
413 if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then
414 echo "Checking for snprintf() in stdio.h... Yes."
423 return snprintf(buf, sizeof(buf), "%s", "foo");
432 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
433 echo "Checking for return value of snprintf()... Yes."
435 CFLAGS="$CFLAGS -DHAS_snprintf_void"
436 SFLAGS="$SFLAGS -DHAS_snprintf_void"
437 echo "Checking for return value of snprintf()... No."
438 echo " WARNING: apparently snprintf() does not return a value. zlib"
439 echo " can build but will be open to possible string-format security"
440 echo " vulnerabilities."
443 CFLAGS="$CFLAGS -DNO_snprintf"
444 SFLAGS="$SFLAGS -DNO_snprintf"
445 echo "Checking for snprintf() in stdio.h... No."
446 echo " WARNING: snprintf() not found, falling back to sprintf(). zlib"
447 echo " can build but will be open to possible buffer-overflow security"
448 echo " vulnerabilities."
457 return sprintf(buf, "%s", "foo");
466 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
467 echo "Checking for return value of sprintf()... Yes."
469 CFLAGS="$CFLAGS -DHAS_sprintf_void"
470 SFLAGS="$SFLAGS -DHAS_sprintf_void"
471 echo "Checking for return value of sprintf()... No."
472 echo " WARNING: apparently sprintf() does not return a value. zlib"
473 echo " can build but will be open to possible string-format security"
474 echo " vulnerabilities."
481 int main() { return 0; }
483 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
484 echo "Checking for errno.h... Yes."
486 echo "Checking for errno.h... No."
487 CFLAGS="$CFLAGS -DNO_ERRNO_H"
488 SFLAGS="$SFLAGS -DNO_ERRNO_H"
492 #include <sys/types.h>
493 #include <sys/mman.h>
494 #include <sys/stat.h>
496 return mmap((caddr_t)0, (off_t)0, PROT_READ, MAP_SHARED, 0, (off_t)0);
499 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
500 CFLAGS="$CFLAGS -DUSE_MMAP"
501 SFLAGS="$SFLAGS -DUSE_MMAP"
502 echo Checking for mmap support... Yes.
504 echo Checking for mmap support... No.
510 if test "`nm $test.o | grep _hello`" = ""; then
511 CPP="$CPP -DNO_UNDERLINE"
512 echo Checking for underline in external names... No.
514 echo Checking for underline in external names... Yes.
518 rm -f $test.[co] $test $test$shared_ext
523 /^CFLAGS *=/s#=.*#=$CFLAGS#
524 /^SFLAGS *=/s#=.*#=$SFLAGS#
525 /^LDFLAGS *=/s#=.*#=$LDFLAGS#
526 /^LDSHARED *=/s#=.*#=$LDSHARED#
527 /^CPP *=/s#=.*#=$CPP#
528 /^STATICLIB *=/s#=.*#=$STATICLIB#
529 /^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
530 /^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
531 /^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
532 /^AR *=/s#=.*#=$AR_RC#
533 /^RANLIB *=/s#=.*#=$RANLIB#
534 /^EXE *=/s#=.*#=$EXE#
535 /^prefix *=/s#=.*#=$prefix#
536 /^exec_prefix *=/s#=.*#=$exec_prefix#
537 /^libdir *=/s#=.*#=$libdir#
538 /^includedir *=/s#=.*#=$includedir#
539 /^mandir *=/s#=.*#=$mandir#
540 /^all: */s#:.*#: $ALL#
541 /^test: */s#:.*#: $TEST#
546 /^CFLAGS *=/s#=.*#=$CFLAGS#
547 /^CPP *=/s#=.*#=$CPP#
548 /^LDSHARED *=/s#=.*#=$LDSHARED#
549 /^STATICLIB *=/s#=.*#=$STATICLIB#
550 /^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
551 /^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
552 /^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
553 /^AR *=/s#=.*#=$AR_RC#
554 /^RANLIB *=/s#=.*#=$RANLIB#
555 /^EXE *=/s#=.*#=$EXE#
556 /^prefix *=/s#=.*#=$prefix#
557 /^exec_prefix *=/s#=.*#=$exec_prefix#
558 /^libdir *=/s#=.*#=$libdir#
559 /^includedir *=/s#=.*#=$includedir#
560 /^mandir *=/s#=.*#=$mandir#
561 /^LDFLAGS *=/s#=.*#=$LDFLAGS#
563 s/\@VERSION\@/$VER/g;