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
16 if [ -n "${CHOST}" ]; then
17 uname="$(echo "${CHOST}" | sed -e 's/^[^-]*-\([^-]*\)$/\1/' -e 's/^[^-]*-[^-]*-\([^-]*\)$/\1/' -e 's/^[^-]*-[^-]*-\([^-]*\)-.*$/\1/')"
18 CROSS_PREFIX="${CHOST}-"
22 LDFLAGS="${LDFLAGS} -L. ${STATICLIB}"
23 VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`
24 VER3=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\\.[0-9]*\).*/\1/p' < zlib.h`
25 VER2=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\)\\..*/\1/p' < zlib.h`
26 VER1=`sed -n -e '/VERSION "/s/.*"\([0-9]*\)\\..*/\1/p' < zlib.h`
27 if "${CROSS_PREFIX}ar" --version >/dev/null 2>/dev/null || test $? -lt 126; then
28 AR=${AR-"${CROSS_PREFIX}ar"}
29 test -n "${CROSS_PREFIX}" && echo Using ${AR}
32 test -n "${CROSS_PREFIX}" && echo Using ${AR}
35 if "${CROSS_PREFIX}ranlib" --version >/dev/null 2>/dev/null || test $? -lt 126; then
36 RANLIB=${RANLIB-"${CROSS_PREFIX}ranlib"}
37 test -n "${CROSS_PREFIX}" && echo Using ${RANLIB}
39 RANLIB=${RANLIB-"ranlib"}
41 if "${CROSS_PREFIX}nm" --version >/dev/null 2>/dev/null || test $? -lt 126; then
42 NM=${NM-"${CROSS_PREFIX}nm"}
43 test -n "${CROSS_PREFIX}" && echo Using ${NM}
47 LDCONFIG=${LDCONFIG-"ldconfig"}
48 LDSHAREDLIBC="${LDSHAREDLIBC--lc}"
49 prefix=${prefix-/usr/local}
50 exec_prefix=${exec_prefix-'${prefix}'}
51 libdir=${libdir-'${exec_prefix}/lib'}
52 sharedlibdir=${sharedlibdir-'${libdir}'}
53 includedir=${includedir-'${prefix}/include'}
54 mandir=${mandir-'${prefix}/share/man'}
68 echo ' configure [--zprefix] [--prefix=PREFIX] [--eprefix=EXPREFIX]'
69 echo ' [--static] [--64] [--libdir=LIBDIR] [--sharedlibdir=LIBDIR]'
70 echo ' [--includedir=INCLUDEDIR]'
72 -p*=* | --prefix=*) prefix=`echo $1 | sed 's/.*=//'`; shift ;;
73 -e*=* | --eprefix=*) exec_prefix=`echo $1 | sed 's/.*=//'`; shift ;;
74 -l*=* | --libdir=*) libdir=`echo $1 | sed 's/.*=//'`; shift ;;
75 --sharedlibdir=*) sharedlibdir=`echo $1 | sed 's/.*=//'`; shift ;;
76 -i*=* | --includedir=*) includedir=`echo $1 | sed 's/.*=//'`;shift ;;
77 -u*=* | --uname=*) uname=`echo $1 | sed 's/.*=//'`;shift ;;
78 -p* | --prefix) prefix="$2"; shift; shift ;;
79 -e* | --eprefix) exec_prefix="$2"; shift; shift ;;
80 -l* | --libdir) libdir="$2"; shift; shift ;;
81 -i* | --includedir) includedir="$2"; shift; shift ;;
82 -s* | --shared | --enable-shared) shared=1; shift ;;
83 -t | --static) shared=0; shift ;;
84 -z* | --zprefix) zprefix=1; shift ;;
85 -6* | --64) build64=1; shift ;;
86 --sysconfdir=*) echo "ignored option: --sysconfdir"; shift ;;
87 --localstatedir=*) echo "ignored option: --localstatedir"; shift ;;
88 *) echo "unknown option: $1"; echo "$0 --help for help"; exit 1 ;;
95 int hello() {return getchar();}
98 test -z "$CC" && echo Checking for ${CROSS_PREFIX}gcc...
99 cc=${CC-${CROSS_PREFIX}gcc}
100 cflags=${CFLAGS-"-O3"}
101 # to force the asm version use: CFLAGS="-O3 -DASMV" ./configure
106 if test "$gcc" -eq 1 && ($cc -c $cflags $test.c) 2>/dev/null; then
108 SFLAGS="${CFLAGS--O3} -fPIC"
109 CFLAGS="${CFLAGS--O3}"
110 if test $build64 -eq 1; then
111 CFLAGS="${CFLAGS} -m64"
112 SFLAGS="${SFLAGS} -m64"
114 if test "${ZLIBGCCWARN}" = "YES"; then
115 CFLAGS="${CFLAGS} -Wall -Wextra -pedantic"
117 if test -z "$uname"; then
118 uname=`(uname -s || echo unknown) 2>/dev/null`
121 Linux* | linux* | GNU | GNU/* | *BSD | DragonFly) LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map"} ;;
122 CYGWIN* | Cygwin* | cygwin* | OS/2*)
126 rm -f $test.[co] $test $test$shared_ext
127 echo "Please use win32/Makefile.gcc instead."
129 LDSHARED=${LDSHARED-"$cc -shared"}
132 QNX*) # This is for QNX6. I suppose that the QNX rule below is for QNX2,QNX4
133 # (alain.bonnefoy@icbt.com)
134 LDSHARED=${LDSHARED-"$cc -shared -Wl,-hlibz.so.1"} ;;
136 LDSHARED=${LDSHARED-"$cc -shared $SFLAGS"}
137 case `(uname -m || echo unknown) 2>/dev/null` in
140 SHAREDLIB='libz.so' ;;
143 SHAREDLIB='libz.sl' ;;
145 Darwin*) shared_ext='.dylib'
146 SHAREDLIB=libz$shared_ext
147 SHAREDLIBV=libz.$VER$shared_ext
148 SHAREDLIBM=libz.$VER1$shared_ext
149 LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBM -compatibility_version $VER1 -current_version $VER3"} ;;
150 *) LDSHARED=${LDSHARED-"$cc -shared"} ;;
153 # find system name and corresponding cc options
156 if test -z "$uname"; then
157 uname=`(uname -sr || echo unknown) 2>/dev/null`
160 HP-UX*) SFLAGS=${CFLAGS-"-O +z"}
161 CFLAGS=${CFLAGS-"-O"}
162 # LDSHARED=${LDSHARED-"ld -b +vnocompatwarnings"}
163 LDSHARED=${LDSHARED-"ld -b"}
164 case `(uname -m || echo unknown) 2>/dev/null` in
167 SHAREDLIB='libz.so' ;;
170 SHAREDLIB='libz.sl' ;;
172 IRIX*) SFLAGS=${CFLAGS-"-ansi -O2 -rpath ."}
173 CFLAGS=${CFLAGS-"-ansi -O2"}
174 LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;;
175 OSF1\ V4*) SFLAGS=${CFLAGS-"-O -std1"}
176 CFLAGS=${CFLAGS-"-O -std1"}
177 LDFLAGS="${LDFLAGS} -Wl,-rpath,."
178 LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so -Wl,-msym -Wl,-rpath,$(libdir) -Wl,-set_version,${VER}:1.0"} ;;
179 OSF1*) SFLAGS=${CFLAGS-"-O -std1"}
180 CFLAGS=${CFLAGS-"-O -std1"}
181 LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;;
182 QNX*) SFLAGS=${CFLAGS-"-4 -O"}
183 CFLAGS=${CFLAGS-"-4 -O"}
184 LDSHARED=${LDSHARED-"cc"}
185 RANLIB=${RANLIB-"true"}
187 SCO_SV\ 3.2*) SFLAGS=${CFLAGS-"-O3 -dy -KPIC "}
188 CFLAGS=${CFLAGS-"-O3"}
189 LDSHARED=${LDSHARED-"cc -dy -KPIC -G"} ;;
190 SunOS\ 5*) LDSHARED=${LDSHARED-"cc -G"}
191 case `(uname -m || echo unknown) 2>/dev/null` in
193 SFLAGS=${CFLAGS-"-xpentium -fast -KPIC -R."}
194 CFLAGS=${CFLAGS-"-xpentium -fast"} ;;
196 SFLAGS=${CFLAGS-"-fast -xcg92 -KPIC -R."}
197 CFLAGS=${CFLAGS-"-fast -xcg92"} ;;
199 SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"}
200 CFLAGS=${CFLAGS-"-O2"}
201 LDSHARED=${LDSHARED-"ld"} ;;
202 SunStudio\ 9*) SFLAGS=${CFLAGS-"-fast -xcode=pic32 -xtarget=ultra3 -xarch=v9b"}
203 CFLAGS=${CFLAGS-"-fast -xtarget=ultra3 -xarch=v9b"}
204 LDSHARED=${LDSHARED-"cc -xarch=v9b"} ;;
205 UNIX_System_V\ 4.2.0)
206 SFLAGS=${CFLAGS-"-KPIC -O"}
207 CFLAGS=${CFLAGS-"-O"}
208 LDSHARED=${LDSHARED-"cc -G"} ;;
210 SFLAGS=${CFLAGS-"-Kconform_pic -O"}
211 CFLAGS=${CFLAGS-"-O"}
212 LDSHARED=${LDSHARED-"cc -G"} ;;
214 SFLAGS=${CFLAGS-"-KPIC -O"}
215 CFLAGS=${CFLAGS-"-O"}
216 LDSHARED=${LDSHARED-"cc -G"} ;;
217 AIX*) # Courtesy of dbakker@arrayasolutions.com
218 SFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
219 CFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
220 LDSHARED=${LDSHARED-"xlc -G"} ;;
221 # send working options for other systems to zlib@gzip.org
222 *) SFLAGS=${CFLAGS-"-O"}
223 CFLAGS=${CFLAGS-"-O"}
224 LDSHARED=${LDSHARED-"cc -shared"} ;;
228 SHAREDLIB=${SHAREDLIB-"libz$shared_ext"}
229 SHAREDLIBV=${SHAREDLIBV-"libz$shared_ext.$VER"}
230 SHAREDLIBM=${SHAREDLIBM-"libz$shared_ext.$VER1"}
232 if test $shared -eq 1; then
233 echo Checking for shared library support...
234 # we must test in two steps (cc then ld), required at least on SunOS 4.x
235 if test "`($CC -w -c $SFLAGS $test.c) 2>&1`" = "" &&
236 test "`($LDSHARED $SFLAGS -o $test$shared_ext $test.o) 2>&1`" = ""; then
237 echo Building shared library $SHAREDLIBV with $CC.
238 elif test -z "$old_cc" -a -z "$old_cflags"; then
239 echo No shared library support.
242 echo Tested $CC -w -c $SFLAGS $test.c
243 $CC -w -c $SFLAGS $test.c
244 echo Tested $LDSHARED $SFLAGS -o $test$shared_ext $test.o
245 $LDSHARED $SFLAGS -o $test$shared_ext $test.o
246 echo 'No shared library support; try without defining CC and CFLAGS'
250 if test $shared -eq 0; then
253 TEST="all teststatic"
257 echo Building static library $STATICLIB version $VER with $CC.
260 TEST="all teststatic testshared"
264 #include <sys/types.h>
267 if test "`($CC -c $CFLAGS -D_LARGEFILE64_SOURCE=1 $test.c) 2>&1`" = ""; then
268 CFLAGS="${CFLAGS} -D_LARGEFILE64_SOURCE=1"
269 SFLAGS="${SFLAGS} -D_LARGEFILE64_SOURCE=1"
271 TEST="${TEST} test64"
272 echo "Checking for off64_t... Yes."
273 echo "Checking for fseeko... Yes."
275 echo "Checking for off64_t... No."
283 if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then
284 echo "Checking for fseeko... Yes."
286 CFLAGS="${CFLAGS} -DNO_FSEEKO"
287 SFLAGS="${SFLAGS} -DNO_FSEEKO"
288 echo "Checking for fseeko... No."
292 cp -p zconf.h.in zconf.h
296 int main() { return 0; }
298 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
299 sed < zconf.h "/^#ifdef HAVE_UNISTD_H.* may be/s/def HAVE_UNISTD_H\(.*\) may be/ 1\1 was/" > zconf.temp.h
300 mv zconf.temp.h zconf.h
301 echo "Checking for unistd.h... Yes."
303 echo "Checking for unistd.h... No."
306 if test $zprefix -eq 1; then
307 sed < zconf.h "/#ifdef Z_PREFIX.* may be/s/def Z_PREFIX\(.*\) may be/ 1\1 was/" > zconf.temp.h
308 mv zconf.temp.h zconf.h
309 echo "Using z_ prefix on all symbols."
327 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
328 echo "Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf()."
334 int mytest(const char *fmt, ...)
340 vsnprintf(buf, sizeof(buf), fmt, ap);
347 return (mytest("Hello%d\n", 1));
351 if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then
352 echo "Checking for vsnprintf() in stdio.h... Yes."
358 int mytest(const char *fmt, ...)
365 n = vsnprintf(buf, sizeof(buf), fmt, ap);
372 return (mytest("Hello%d\n", 1));
376 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
377 echo "Checking for return value of vsnprintf()... Yes."
379 CFLAGS="$CFLAGS -DHAS_vsnprintf_void"
380 SFLAGS="$SFLAGS -DHAS_vsnprintf_void"
381 echo "Checking for return value of vsnprintf()... No."
382 echo " WARNING: apparently vsnprintf() does not return a value. zlib"
383 echo " can build but will be open to possible string-format security"
384 echo " vulnerabilities."
387 CFLAGS="$CFLAGS -DNO_vsnprintf"
388 SFLAGS="$SFLAGS -DNO_vsnprintf"
389 echo "Checking for vsnprintf() in stdio.h... No."
390 echo " WARNING: vsnprintf() not found, falling back to vsprintf(). zlib"
391 echo " can build but will be open to possible buffer-overflow security"
392 echo " vulnerabilities."
398 int mytest(const char *fmt, ...)
405 n = vsprintf(buf, fmt, ap);
412 return (mytest("Hello%d\n", 1));
416 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
417 echo "Checking for return value of vsprintf()... Yes."
419 CFLAGS="$CFLAGS -DHAS_vsprintf_void"
420 SFLAGS="$SFLAGS -DHAS_vsprintf_void"
421 echo "Checking for return value of vsprintf()... No."
422 echo " WARNING: apparently vsprintf() does not return a value. zlib"
423 echo " can build but will be open to possible string-format security"
424 echo " vulnerabilities."
428 echo "Checking whether to use vs[n]printf() or s[n]printf()... using s[n]printf()."
437 snprintf(buf, sizeof(buf), "%s", "foo");
447 if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then
448 echo "Checking for snprintf() in stdio.h... Yes."
457 return snprintf(buf, sizeof(buf), "%s", "foo");
466 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
467 echo "Checking for return value of snprintf()... Yes."
469 CFLAGS="$CFLAGS -DHAS_snprintf_void"
470 SFLAGS="$SFLAGS -DHAS_snprintf_void"
471 echo "Checking for return value of snprintf()... No."
472 echo " WARNING: apparently snprintf() does not return a value. zlib"
473 echo " can build but will be open to possible string-format security"
474 echo " vulnerabilities."
477 CFLAGS="$CFLAGS -DNO_snprintf"
478 SFLAGS="$SFLAGS -DNO_snprintf"
479 echo "Checking for snprintf() in stdio.h... No."
480 echo " WARNING: snprintf() not found, falling back to sprintf(). zlib"
481 echo " can build but will be open to possible buffer-overflow security"
482 echo " vulnerabilities."
491 return sprintf(buf, "%s", "foo");
500 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
501 echo "Checking for return value of sprintf()... Yes."
503 CFLAGS="$CFLAGS -DHAS_sprintf_void"
504 SFLAGS="$SFLAGS -DHAS_sprintf_void"
505 echo "Checking for return value of sprintf()... No."
506 echo " WARNING: apparently sprintf() does not return a value. zlib"
507 echo " can build but will be open to possible string-format security"
508 echo " vulnerabilities."
513 if test "$gcc" -eq 1; then
515 #if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33)
516 # define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
518 # define ZLIB_INTERNAL
520 int ZLIB_INTERNAL foo;
526 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
527 echo "Checking for attribute(visibility) support... Yes."
529 CFLAGS="$CFLAGS -DNO_VIZ"
530 SFLAGS="$SFLAGS -DNO_VIZ"
531 echo "Checking for attribute(visibility) support... No."
538 if test "`$NM $test.o | grep _hello`" = ""; then
539 CPP="$CPP -DNO_UNDERLINE"
540 echo Checking for underline in external names... No.
542 echo Checking for underline in external names... Yes.
546 rm -f $test.[co] $test $test$shared_ext
551 /^CFLAGS *=/s#=.*#=$CFLAGS#
552 /^SFLAGS *=/s#=.*#=$SFLAGS#
553 /^LDFLAGS *=/s#=.*#=$LDFLAGS#
554 /^LDSHARED *=/s#=.*#=$LDSHARED#
555 /^CPP *=/s#=.*#=$CPP#
556 /^STATICLIB *=/s#=.*#=$STATICLIB#
557 /^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
558 /^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
559 /^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
560 /^AR *=/s#=.*#=$AR_RC#
561 /^RANLIB *=/s#=.*#=$RANLIB#
562 /^LDCONFIG *=/s#=.*#=$LDCONFIG#
563 /^LDSHAREDLIBC *=/s#=.*#=$LDSHAREDLIBC#
564 /^EXE *=/s#=.*#=$EXE#
565 /^prefix *=/s#=.*#=$prefix#
566 /^exec_prefix *=/s#=.*#=$exec_prefix#
567 /^libdir *=/s#=.*#=$libdir#
568 /^sharedlibdir *=/s#=.*#=$sharedlibdir#
569 /^includedir *=/s#=.*#=$includedir#
570 /^mandir *=/s#=.*#=$mandir#
571 /^all: */s#:.*#: $ALL#
572 /^test: */s#:.*#: $TEST#
577 /^CFLAGS *=/s#=.*#=$CFLAGS#
578 /^CPP *=/s#=.*#=$CPP#
579 /^LDSHARED *=/s#=.*#=$LDSHARED#
580 /^STATICLIB *=/s#=.*#=$STATICLIB#
581 /^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
582 /^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
583 /^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
584 /^AR *=/s#=.*#=$AR_RC#
585 /^RANLIB *=/s#=.*#=$RANLIB#
586 /^EXE *=/s#=.*#=$EXE#
587 /^prefix *=/s#=.*#=$prefix#
588 /^exec_prefix *=/s#=.*#=$exec_prefix#
589 /^libdir *=/s#=.*#=$libdir#
590 /^sharedlibdir *=/s#=.*#=$sharedlibdir#
591 /^includedir *=/s#=.*#=$includedir#
592 /^mandir *=/s#=.*#=$mandir#
593 /^LDFLAGS *=/s#=.*#=$LDFLAGS#
595 s/\@VERSION\@/$VER/g;