]> git.lizzy.rs Git - zlib.git/blob - configure
zlib 1.2.3.4
[zlib.git] / configure
1 #!/bin/sh
2 # configure script for zlib.
3 #
4 # Normally configure builds both a static and a shared library.
5 # If you want to build just a static library, use: ./configure --static
6 #
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)
11
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
14 # an error.
15
16 STATICLIB=libz.a
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`
22 AR=${AR-"ar"}
23 AR_RC="${AR} rc"
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'}
30 shared_ext='.so'
31 shared=1
32 zprefix=0
33 gcc=0
34 old_cc="$CC"
35 old_cflags="$CFLAGS"
36
37 while test $# -ge 1
38 do
39 case "$1" in
40     -h* | --help)
41       echo 'usage:'
42       echo '  configure [--shared] [--prefix=PREFIX]  [--exec_prefix=EXPREFIX]'
43       echo '     [--libdir=LIBDIR] [--includedir=INCLUDEDIR] [--zprefix]'
44         exit 0 ;;
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 ;;
60     esac
61 done
62
63 test=ztest$$
64 cat > $test.c <<EOF
65 extern int getchar();
66 int hello() {return getchar();}
67 EOF
68
69 test -z "$CC" && echo Checking for gcc...
70 cc=${CC-gcc}
71 cflags=${CFLAGS-"-O3"}
72 # to force the asm version use: CFLAGS="-O3 -DASMV" ./configure
73 case "$cc" in
74   *gcc*) gcc=1 ;;
75 esac
76
77 if test "$gcc" -eq 1 && ($cc -c $cflags $test.c) 2>/dev/null; then
78   CC="$cc"
79   SFLAGS="${CFLAGS-"-O3"} -fPIC"
80   CFLAGS="${CFLAGS-"-O3"}"
81   if test -z "$uname"; then
82     uname=`(uname -s || echo unknown) 2>/dev/null`
83   fi
84   case "$uname" in
85   Linux | linux | GNU | GNU/*) LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map"} ;;
86   CYGWIN* | Cygwin* | cygwin* | OS/2* )
87              EXE='.exe' ;;
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"} ;;
91   HP-UX*)
92          LDSHARED=${LDSHARED-"$cc -shared $SFLAGS"}
93          case `(uname -m || echo unknown) 2>/dev/null` in
94          ia64)
95                  shared_ext='.so'
96                  SHAREDLIB='libz.so' ;;
97          *)
98                  shared_ext='.sl'
99                  SHAREDLIB='libz.sl' ;;
100          esac ;;
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"} ;;
107   esac
108 else
109   # find system name and corresponding cc options
110   CC=${CC-cc}
111   if test -z "$uname"; then
112     uname=`(uname -sr || echo unknown) 2>/dev/null`
113   fi
114   case "$uname" in
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
120          ia64)
121              shared_ext='.so'
122              SHAREDLIB='libz.so' ;;
123          *)
124              shared_ext='.sl'
125              SHAREDLIB='libz.sl' ;;
126          esac ;;
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"}
141              AR_RC="cc -A" ;;
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
147          i86*)
148              SFLAGS=${CFLAGS-"-xpentium -fast -KPIC -R."}
149              CFLAGS=${CFLAGS-"-xpentium -fast"} ;;
150          *)
151              SFLAGS=${CFLAGS-"-fast -xcg92 -KPIC -R."}
152              CFLAGS=${CFLAGS-"-fast -xcg92"} ;;
153          esac ;;
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"} ;;
164   UNIX_SV\ 4.2MP)
165              SFLAGS=${CFLAGS-"-Kconform_pic -O"}
166              CFLAGS=${CFLAGS-"-O"}
167              LDSHARED=${LDSHARED-"cc -G"} ;;
168   OpenUNIX\ 5)
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"} ;;
180   esac
181 fi
182
183 SHAREDLIB=${SHAREDLIB-"libz$shared_ext"}
184 SHAREDLIBV=${SHAREDLIBV-"libz$shared_ext.$VER"}
185 SHAREDLIBM=${SHAREDLIBM-"libz$shared_ext.$VER1"}
186
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.
195     shared=0;
196   else
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'
202     shared=0;
203   fi
204 fi
205 if test $shared -eq 0; then
206   LDSHARED="$CC"
207   ALL="static"
208   TEST="all teststatic"
209   echo Building static library $STATICLIB version $VER with $CC.
210 else
211   ALL="static shared"
212   TEST="all teststatic testshared"
213 fi
214
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
219  */
220
221 EOF
222
223 cat > $test.c <<EOF
224 #include <sys/types.h>
225 off64_t dummy = 0;
226 EOF
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"
230   ALL="${ALL} all64"
231   TEST="${TEST} test64"
232   echo "Checking for off64_t... Yes."
233   echo "Checking for fseeko... Yes."
234 else
235   echo "Checking for off64_t... No."
236   cat > $test.c <<EOF
237 #include <stdio.h>
238 int main(void) {
239   fseeko(NULL, 0, 0);
240   return 0;
241 }
242 EOF
243   if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then
244     echo "Checking for fseeko... Yes."
245   else
246     CFLAGS="${CFLAGS} -DNO_FSEEKO"
247     SFLAGS="${SFLAGS} -DNO_FSEEKO"
248     echo "Checking for fseeko... No."
249   fi
250 fi
251
252 cat > $test.c <<EOF
253 #include <unistd.h>
254 int main() { return 0; }
255 EOF
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 */
260 #ifdef VMS
261 #  include <unixio.h>   /* for off_t */
262 #endif
263 #ifndef z_off_t
264 #  define z_off_t off_t
265 #endif
266 EOF
267   echo "Checking for unistd.h... Yes."
268 else
269   echo "Checking for unistd.h... No."
270 fi
271
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."
276 fi
277
278 cat > $test.c <<EOF
279 #include <stdio.h>
280 #include <stdarg.h>
281 #include "zconf.h"
282
283 int main()
284 {
285 #ifndef STDC
286   choke me
287 #endif
288
289   return 0;
290 }
291 EOF
292
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()."
295
296   cat > $test.c <<EOF
297 #include <stdio.h>
298 #include <stdarg.h>
299
300 int mytest(char *fmt, ...)
301 {
302   char buf[20];
303   va_list ap;
304
305   va_start(ap, fmt);
306   vsnprintf(buf, sizeof(buf), fmt, ap);
307   va_end(ap);
308   return 0;
309 }
310
311 int main()
312 {
313   return (mytest("Hello%d\n", 1));
314 }
315 EOF
316
317   if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then
318     echo "Checking for vsnprintf() in stdio.h... Yes."
319
320     cat >$test.c <<EOF
321 #include <stdio.h>
322 #include <stdarg.h>
323
324 int mytest(char *fmt, ...)
325 {
326   int n;
327   char buf[20];
328   va_list ap;
329
330   va_start(ap, fmt);
331   n = vsnprintf(buf, sizeof(buf), fmt, ap);
332   va_end(ap);
333   return n;
334 }
335
336 int main()
337 {
338   return (mytest("Hello%d\n", 1));
339 }
340 EOF
341
342     if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
343       echo "Checking for return value of vsnprintf()... Yes."
344     else
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."
351     fi
352   else
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."
359
360     cat >$test.c <<EOF
361 #include <stdio.h>
362 #include <stdarg.h>
363
364 int mytest(char *fmt, ...)
365 {
366   int n;
367   char buf[20];
368   va_list ap;
369
370   va_start(ap, fmt);
371   n = vsprintf(buf, fmt, ap);
372   va_end(ap);
373   return n;
374 }
375
376 int main()
377 {
378   return (mytest("Hello%d\n", 1));
379 }
380 EOF
381
382     if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
383       echo "Checking for return value of vsprintf()... Yes."
384     else
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."
391     fi
392   fi
393 else
394   echo "Checking whether to use vs[n]printf() or s[n]printf()... using s[n]printf()."
395
396   cat >$test.c <<EOF
397 #include <stdio.h>
398
399 int mytest()
400 {
401   char buf[20];
402
403   snprintf(buf, sizeof(buf), "%s", "foo");
404   return 0;
405 }
406
407 int main()
408 {
409   return (mytest());
410 }
411 EOF
412
413   if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then
414     echo "Checking for snprintf() in stdio.h... Yes."
415
416     cat >$test.c <<EOF
417 #include <stdio.h>
418
419 int mytest()
420 {
421   char buf[20];
422
423   return snprintf(buf, sizeof(buf), "%s", "foo");
424 }
425
426 int main()
427 {
428   return (mytest());
429 }
430 EOF
431
432     if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
433       echo "Checking for return value of snprintf()... Yes."
434     else
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."
441     fi
442   else
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."
449
450     cat >$test.c <<EOF
451 #include <stdio.h>
452
453 int mytest()
454 {
455   char buf[20];
456
457   return sprintf(buf, "%s", "foo");
458 }
459
460 int main()
461 {
462   return (mytest());
463 }
464 EOF
465
466     if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
467       echo "Checking for return value of sprintf()... Yes."
468     else
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."
475     fi
476   fi
477 fi
478
479 cat >$test.c <<EOF
480 #include <errno.h>
481 int main() { return 0; }
482 EOF
483 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
484   echo "Checking for errno.h... Yes."
485 else
486   echo "Checking for errno.h... No."
487   CFLAGS="$CFLAGS -DNO_ERRNO_H"
488   SFLAGS="$SFLAGS -DNO_ERRNO_H"
489 fi
490
491 cat > $test.c <<EOF
492 #include <sys/types.h>
493 #include <sys/mman.h>
494 #include <sys/stat.h>
495 caddr_t hello() {
496   return mmap((caddr_t)0, (off_t)0, PROT_READ, MAP_SHARED, 0, (off_t)0);
497 }
498 EOF
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.
503 else
504   echo Checking for mmap support... No.
505 fi
506
507 CPP=${CPP-"$CC -E"}
508 case $CFLAGS in
509   *ASMV*)
510     if test "`nm $test.o | grep _hello`" = ""; then
511       CPP="$CPP -DNO_UNDERLINE"
512       echo Checking for underline in external names... No.
513     else
514       echo Checking for underline in external names... Yes.
515     fi ;;
516 esac
517
518 rm -f $test.[co] $test $test$shared_ext
519
520 # udpate Makefile
521 sed < Makefile.in "
522 /^CC *=/s#=.*#=$CC#
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#
542 " > Makefile
543
544 sed < zlib.pc.in "
545 /^CC *=/s#=.*#=$CC#
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#
562 " | sed -e "
563 s/\@VERSION\@/$VER/g;
564 " > zlib.pc