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'}
43 echo ' configure [--zprefix] [--prefix=PREFIX] [--eprefix=EXPREFIX]'
44 echo ' [--static] [--64] [--libdir=LIBDIR] [--includedir=INCLUDEDIR]'
46 -p*=* | --prefix=*) prefix=`echo $1 | sed 's/[-a-z_]*=//'`; shift ;;
47 -e*=* | --eprefix=*) exec_prefix=`echo $1 | sed 's/[-a-z_]*=//'`; shift ;;
48 -l*=* | --libdir=*) libdir=`echo $1 | sed 's/[-a-z_]*=//'`; shift ;;
49 -i*=* | --includedir=*) includedir=`echo $1 | sed 's/[-a-z_]*=//'`;shift ;;
50 -u*=* | --uname=*) uname=`echo $1 | sed 's/[-a-z_]*=//'`;shift ;;
51 -p* | --prefix) prefix="$2"; shift; shift ;;
52 -e* | --eprefix) exec_prefix="$2"; shift; shift ;;
53 -l* | --libdir) libdir="$2"; shift; shift ;;
54 -i* | --includedir) includedir="$2"; shift; shift ;;
55 -s* | --shared | --enable-shared) shared=1; shift ;;
56 -t | --static) shared=0; shift ;;
57 -z* | --zprefix) zprefix=1; shift ;;
58 -6* | --64) build64=1; shift ;;
59 --sysconfdir=*) echo "ignored option: --sysconfdir"; shift ;;
60 --localstatedir=*) echo "ignored option: --localstatedir"; shift ;;
61 *) echo "unknown option: $1"; echo "$0 --help for help"; exit 1 ;;
68 int hello() {return getchar();}
71 test -z "$CC" && echo Checking for gcc...
73 cflags=${CFLAGS-"-O3"}
74 # to force the asm version use: CFLAGS="-O3 -DASMV" ./configure
79 if test "$gcc" -eq 1 && ($cc -c $cflags $test.c) 2>/dev/null; then
81 SFLAGS="${CFLAGS-"-O3"} -fPIC"
82 CFLAGS="${CFLAGS-"-O3"}"
83 if test $build64 -eq 1; then
84 CFLAGS="${CFLAGS} -m64"
85 SFLAGS="${SFLAGS} -m64"
87 if test "${ZLIBGCCWARN}" = "YES"; then
88 CFLAGS="${CFLAGS} -Wall -Wextra -pedantic"
90 if test -z "$uname"; then
91 uname=`(uname -s || echo unknown) 2>/dev/null`
94 Linux | linux | GNU | GNU/* | *BSD | DragonFly) LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map"} ;;
95 CYGWIN* | Cygwin* | cygwin* | OS/2* )
97 QNX*) # This is for QNX6. I suppose that the QNX rule below is for QNX2,QNX4
98 # (alain.bonnefoy@icbt.com)
99 LDSHARED=${LDSHARED-"$cc -shared -Wl,-hlibz.so.1"} ;;
101 LDSHARED=${LDSHARED-"$cc -shared $SFLAGS"}
102 case `(uname -m || echo unknown) 2>/dev/null` in
105 SHAREDLIB='libz.so' ;;
108 SHAREDLIB='libz.sl' ;;
110 Darwin*) shared_ext='.dylib'
111 SHAREDLIB=libz$shared_ext
112 SHAREDLIBV=libz.$VER$shared_ext
113 SHAREDLIBM=libz.$VER1$shared_ext
114 LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBM -compatibility_version $VER1 -current_version $VER3"} ;;
115 *) LDSHARED=${LDSHARED-"$cc -shared"} ;;
118 # find system name and corresponding cc options
120 if test -z "$uname"; then
121 uname=`(uname -sr || echo unknown) 2>/dev/null`
124 HP-UX*) SFLAGS=${CFLAGS-"-O +z"}
125 CFLAGS=${CFLAGS-"-O"}
126 # LDSHARED=${LDSHARED-"ld -b +vnocompatwarnings"}
127 LDSHARED=${LDSHARED-"ld -b"}
128 case `(uname -m || echo unknown) 2>/dev/null` in
131 SHAREDLIB='libz.so' ;;
134 SHAREDLIB='libz.sl' ;;
136 IRIX*) SFLAGS=${CFLAGS-"-ansi -O2 -rpath ."}
137 CFLAGS=${CFLAGS-"-ansi -O2"}
138 LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;;
139 OSF1\ V4*) SFLAGS=${CFLAGS-"-O -std1"}
140 CFLAGS=${CFLAGS-"-O -std1"}
141 LDFLAGS="${LDFLAGS} -Wl,-rpath,."
142 LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so -Wl,-msym -Wl,-rpath,$(libdir) -Wl,-set_version,${VER}:1.0"} ;;
143 OSF1*) SFLAGS=${CFLAGS-"-O -std1"}
144 CFLAGS=${CFLAGS-"-O -std1"}
145 LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;;
146 QNX*) SFLAGS=${CFLAGS-"-4 -O"}
147 CFLAGS=${CFLAGS-"-4 -O"}
148 LDSHARED=${LDSHARED-"cc"}
149 RANLIB=${RANLIB-"true"}
151 SCO_SV\ 3.2*) SFLAGS=${CFLAGS-"-O3 -dy -KPIC "}
152 CFLAGS=${CFLAGS-"-O3"}
153 LDSHARED=${LDSHARED-"cc -dy -KPIC -G"} ;;
154 SunOS\ 5*) LDSHARED=${LDSHARED-"cc -G"}
155 case `(uname -m || echo unknown) 2>/dev/null` in
157 SFLAGS=${CFLAGS-"-xpentium -fast -KPIC -R."}
158 CFLAGS=${CFLAGS-"-xpentium -fast"} ;;
160 SFLAGS=${CFLAGS-"-fast -xcg92 -KPIC -R."}
161 CFLAGS=${CFLAGS-"-fast -xcg92"} ;;
163 SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"}
164 CFLAGS=${CFLAGS-"-O2"}
165 LDSHARED=${LDSHARED-"ld"} ;;
166 SunStudio\ 9*) SFLAGS=${CFLAGS-"-fast -xcode=pic32 -xtarget=ultra3 -xarch=v9b"}
167 CFLAGS=${CFLAGS-"-fast -xtarget=ultra3 -xarch=v9b"}
168 LDSHARED=${LDSHARED-"cc -xarch=v9b"} ;;
169 UNIX_System_V\ 4.2.0)
170 SFLAGS=${CFLAGS-"-KPIC -O"}
171 CFLAGS=${CFLAGS-"-O"}
172 LDSHARED=${LDSHARED-"cc -G"} ;;
174 SFLAGS=${CFLAGS-"-Kconform_pic -O"}
175 CFLAGS=${CFLAGS-"-O"}
176 LDSHARED=${LDSHARED-"cc -G"} ;;
178 SFLAGS=${CFLAGS-"-KPIC -O"}
179 CFLAGS=${CFLAGS-"-O"}
180 LDSHARED=${LDSHARED-"cc -G"} ;;
181 AIX*) # Courtesy of dbakker@arrayasolutions.com
182 SFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
183 CFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
184 LDSHARED=${LDSHARED-"xlc -G"} ;;
185 # send working options for other systems to zlib@gzip.org
186 *) SFLAGS=${CFLAGS-"-O"}
187 CFLAGS=${CFLAGS-"-O"}
188 LDSHARED=${LDSHARED-"cc -shared"} ;;
192 SHAREDLIB=${SHAREDLIB-"libz$shared_ext"}
193 SHAREDLIBV=${SHAREDLIBV-"libz$shared_ext.$VER"}
194 SHAREDLIBM=${SHAREDLIBM-"libz$shared_ext.$VER1"}
196 if test $shared -eq 1; then
197 echo Checking for shared library support...
198 # we must test in two steps (cc then ld), required at least on SunOS 4.x
199 if test "`($CC -w -c $SFLAGS $test.c) 2>&1`" = "" &&
200 test "`($LDSHARED $SFLAGS -o $test$shared_ext $test.o) 2>&1`" = ""; then
201 echo Building shared library $SHAREDLIBV with $CC.
202 elif test -z "$old_cc" -a -z "$old_cflags"; then
203 echo No shared library support.
206 echo Tested $CC -w -c $SFLAGS $test.c
207 $CC -w -c $SFLAGS $test.c
208 echo Tested $LDSHARED $SFLAGS -o $test$shared_ext $test.o
209 $LDSHARED $SFLAGS -o $test$shared_ext $test.o
210 echo 'No shared library support; try without defining CC and CFLAGS'
214 if test $shared -eq 0; then
217 TEST="all teststatic"
218 echo Building static library $STATICLIB version $VER with $CC.
221 TEST="all teststatic testshared"
225 #include <sys/types.h>
228 if test "`($CC -c $CFLAGS -D_LARGEFILE64_SOURCE=1 $test.c) 2>&1`" = ""; then
229 CFLAGS="${CFLAGS} -D_LARGEFILE64_SOURCE=1"
230 SFLAGS="${SFLAGS} -D_LARGEFILE64_SOURCE=1"
232 TEST="${TEST} test64"
233 echo "Checking for off64_t... Yes."
234 echo "Checking for fseeko... Yes."
236 echo "Checking for off64_t... No."
244 if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then
245 echo "Checking for fseeko... Yes."
247 CFLAGS="${CFLAGS} -DNO_FSEEKO"
248 SFLAGS="${SFLAGS} -DNO_FSEEKO"
249 echo "Checking for fseeko... No."
253 cp -p zconf.in.h zconf.h
257 int main() { return 0; }
259 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
260 sed < zconf.h "/#ifdef HAVE_UNISTD_H/s/def HAVE_UNISTD_H/ 1/" > zconf.temp.h
261 mv zconf.temp.h zconf.h
262 echo "Checking for unistd.h... Yes."
264 echo "Checking for unistd.h... No."
267 if test $zprefix -eq 1; then
268 sed < zconf.h "/#ifdef Z_PREFIX/s/def Z_PREFIX/ 1/" > zconf.temp.h
269 mv zconf.temp.h zconf.h
270 echo "Using z_ prefix on all symbols."
288 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
289 echo "Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf()."
295 int mytest(const char *fmt, ...)
301 vsnprintf(buf, sizeof(buf), fmt, ap);
308 return (mytest("Hello%d\n", 1));
312 if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then
313 echo "Checking for vsnprintf() in stdio.h... Yes."
319 int mytest(char *fmt, ...)
326 n = vsnprintf(buf, sizeof(buf), fmt, ap);
333 return (mytest("Hello%d\n", 1));
337 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
338 echo "Checking for return value of vsnprintf()... Yes."
340 CFLAGS="$CFLAGS -DHAS_vsnprintf_void"
341 SFLAGS="$SFLAGS -DHAS_vsnprintf_void"
342 echo "Checking for return value of vsnprintf()... No."
343 echo " WARNING: apparently vsnprintf() does not return a value. zlib"
344 echo " can build but will be open to possible string-format security"
345 echo " vulnerabilities."
348 CFLAGS="$CFLAGS -DNO_vsnprintf"
349 SFLAGS="$SFLAGS -DNO_vsnprintf"
350 echo "Checking for vsnprintf() in stdio.h... No."
351 echo " WARNING: vsnprintf() not found, falling back to vsprintf(). zlib"
352 echo " can build but will be open to possible buffer-overflow security"
353 echo " vulnerabilities."
359 int mytest(const char *fmt, ...)
366 n = vsprintf(buf, fmt, ap);
373 return (mytest("Hello%d\n", 1));
377 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
378 echo "Checking for return value of vsprintf()... Yes."
380 CFLAGS="$CFLAGS -DHAS_vsprintf_void"
381 SFLAGS="$SFLAGS -DHAS_vsprintf_void"
382 echo "Checking for return value of vsprintf()... No."
383 echo " WARNING: apparently vsprintf() does not return a value. zlib"
384 echo " can build but will be open to possible string-format security"
385 echo " vulnerabilities."
389 echo "Checking whether to use vs[n]printf() or s[n]printf()... using s[n]printf()."
398 snprintf(buf, sizeof(buf), "%s", "foo");
408 if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then
409 echo "Checking for snprintf() in stdio.h... Yes."
418 return snprintf(buf, sizeof(buf), "%s", "foo");
427 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
428 echo "Checking for return value of snprintf()... Yes."
430 CFLAGS="$CFLAGS -DHAS_snprintf_void"
431 SFLAGS="$SFLAGS -DHAS_snprintf_void"
432 echo "Checking for return value of snprintf()... No."
433 echo " WARNING: apparently snprintf() does not return a value. zlib"
434 echo " can build but will be open to possible string-format security"
435 echo " vulnerabilities."
438 CFLAGS="$CFLAGS -DNO_snprintf"
439 SFLAGS="$SFLAGS -DNO_snprintf"
440 echo "Checking for snprintf() in stdio.h... No."
441 echo " WARNING: snprintf() not found, falling back to sprintf(). zlib"
442 echo " can build but will be open to possible buffer-overflow security"
443 echo " vulnerabilities."
452 return sprintf(buf, "%s", "foo");
461 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
462 echo "Checking for return value of sprintf()... Yes."
464 CFLAGS="$CFLAGS -DHAS_sprintf_void"
465 SFLAGS="$SFLAGS -DHAS_sprintf_void"
466 echo "Checking for return value of sprintf()... No."
467 echo " WARNING: apparently sprintf() does not return a value. zlib"
468 echo " can build but will be open to possible string-format security"
469 echo " vulnerabilities."
476 int main() { return 0; }
478 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
479 echo "Checking for errno.h... Yes."
481 echo "Checking for errno.h... No."
482 CFLAGS="$CFLAGS -DNO_ERRNO_H"
483 SFLAGS="$SFLAGS -DNO_ERRNO_H"
489 if test "`nm $test.o | grep _hello`" = ""; then
490 CPP="$CPP -DNO_UNDERLINE"
491 echo Checking for underline in external names... No.
493 echo Checking for underline in external names... Yes.
497 rm -f $test.[co] $test $test$shared_ext
502 /^CFLAGS *=/s#=.*#=$CFLAGS#
503 /^SFLAGS *=/s#=.*#=$SFLAGS#
504 /^LDFLAGS *=/s#=.*#=$LDFLAGS#
505 /^LDSHARED *=/s#=.*#=$LDSHARED#
506 /^CPP *=/s#=.*#=$CPP#
507 /^STATICLIB *=/s#=.*#=$STATICLIB#
508 /^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
509 /^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
510 /^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
511 /^AR *=/s#=.*#=$AR_RC#
512 /^RANLIB *=/s#=.*#=$RANLIB#
513 /^EXE *=/s#=.*#=$EXE#
514 /^prefix *=/s#=.*#=$prefix#
515 /^exec_prefix *=/s#=.*#=$exec_prefix#
516 /^libdir *=/s#=.*#=$libdir#
517 /^includedir *=/s#=.*#=$includedir#
518 /^mandir *=/s#=.*#=$mandir#
519 /^all: */s#:.*#: $ALL#
520 /^test: */s#:.*#: $TEST#
525 /^CFLAGS *=/s#=.*#=$CFLAGS#
526 /^CPP *=/s#=.*#=$CPP#
527 /^LDSHARED *=/s#=.*#=$LDSHARED#
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 /^LDFLAGS *=/s#=.*#=$LDFLAGS#
542 s/\@VERSION\@/$VER/g;