]> git.lizzy.rs Git - zlib.git/blob - configure
zlib 1.2.3.2
[zlib.git] / configure
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
21 LIBS=libz.a
22 LDFLAGS="-L. ${LIBS}"
23 VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`
24 VER2=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\)\\..*/\1/p' < zlib.h`
25 VER1=`sed -n -e '/VERSION "/s/.*"\([0-9]*\)\\..*/\1/p' < zlib.h`
26 AR=${AR-"ar"}
27 AR_RC="${AR} rc"
28 RANLIB=${RANLIB-"ranlib"}
29 prefix=${prefix-/usr/local}
30 exec_prefix=${exec_prefix-'${prefix}'}
31 libdir=${libdir-'${exec_prefix}/lib'}
32 includedir=${includedir-'${prefix}/include'}
33 mandir=${mandir-'${prefix}/share/man'}
34 shared_ext='.so'
35 shared=0
36 zprefix=0
37 gcc=0
38 old_cc="$CC"
39 old_cflags="$CFLAGS"
40
41 while test $# -ge 1
42 do
43 case "$1" in
44     -h* | --help)
45       echo 'usage:'
46       echo '  configure [--shared] [--prefix=PREFIX]  [--exec_prefix=EXPREFIX]'
47       echo '     [--libdir=LIBDIR] [--includedir=INCLUDEDIR] [--zprefix]'
48         exit 0;;
49     -p*=* | --prefix=*) prefix=`echo $1 | sed 's/[-a-z_]*=//'`; shift;;
50     -e*=* | --eprefix=*) exec_prefix=`echo $1 | sed 's/[-a-z_]*=//'`; shift;;
51     -l*=* | --libdir=*) libdir=`echo $1 | sed 's/[-a-z_]*=//'`; shift;;
52     -i*=* | --includedir=*) includedir=`echo $1 | sed 's/[-a-z_]*=//'`;shift;;
53     -p* | --prefix) prefix="$2"; shift; shift;;
54     -e* | --eprefix) exec_prefix="$2"; shift; shift;;
55     -l* | --libdir) libdir="$2"; shift; shift;;
56     -i* | --includedir) includedir="$2"; shift; shift;;
57     -s* | --shared | --enable-shared) shared=1; shift;;
58     -z* | --zprefix) zprefix=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;;
62     esac
63 done
64
65 test=ztest$$
66 cat > $test.c <<EOF
67 extern int getchar();
68 int hello() {return getchar();}
69 EOF
70
71 test -z "$CC" && echo Checking for gcc...
72 cc=${CC-gcc}
73 cflags=${CFLAGS-"-O3"}
74 # to force the asm version use: CFLAGS="-O3 -DASMV" ./configure
75 case "$cc" in
76   *gcc*) gcc=1;;
77 esac
78
79 if test "$gcc" -eq 1 && ($cc -c $cflags $test.c) 2>/dev/null; then
80   CC="$cc"
81   SFLAGS="${CFLAGS-"-O3"} -fPIC"
82   CFLAGS="${CFLAGS-"-O3"}"
83   case `(uname -s || echo unknown) 2>/dev/null` in
84   Linux | linux | GNU | GNU/*) LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map"};;
85   CYGWIN* | Cygwin* | cygwin* | OS/2* )
86              EXE='.exe';;
87   QNX*)  # This is for QNX6. I suppose that the QNX rule below is for QNX2,QNX4
88          # (alain.bonnefoy@icbt.com)
89                  LDSHARED=${LDSHARED-"$cc -shared -Wl,-hlibz.so.1"};;
90   HP-UX*)
91          LDSHARED=${LDSHARED-"$cc -shared $SFLAGS"}
92          case `(uname -m || echo unknown) 2>/dev/null` in
93          ia64)
94                  shared_ext='.so'
95                  SHAREDLIB='libz.so';;
96          *)
97                  shared_ext='.sl'
98                  SHAREDLIB='libz.sl';;
99          esac;;
100   Darwin*)   shared_ext='.dylib'
101              SHAREDLIB=libz$shared_ext
102              SHAREDLIBV=libz.$VER$shared_ext
103              SHAREDLIBM=libz.$VER1$shared_ext
104              LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBM -compatibility_version $VER1 -current_version $VER"};;
105   *)             LDSHARED=${LDSHARED-"$cc -shared"};;
106   esac
107 else
108   # find system name and corresponding cc options
109   CC=${CC-cc}
110   case `(uname -sr || echo unknown) 2>/dev/null` in
111   HP-UX*)    SFLAGS=${CFLAGS-"-O +z"}
112              CFLAGS=${CFLAGS-"-O"}
113 #            LDSHARED=${LDSHARED-"ld -b +vnocompatwarnings"}
114              LDSHARED=${LDSHARED-"ld -b"}
115          case `(uname -m || echo unknown) 2>/dev/null` in
116          ia64)
117              shared_ext='.so'
118              SHAREDLIB='libz.so';;
119          *)
120              shared_ext='.sl'
121              SHAREDLIB='libz.sl';;
122          esac;;
123   IRIX*)     SFLAGS=${CFLAGS-"-ansi -O2 -rpath ."}
124              CFLAGS=${CFLAGS-"-ansi -O2"}
125              LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"};;
126   OSF1\ V4*) SFLAGS=${CFLAGS-"-O -std1"}
127              CFLAGS=${CFLAGS-"-O -std1"}
128              LDSHARED=${LDSHARED-"cc -shared  -Wl,-soname,libz.so -Wl,-msym -Wl,-rpath,$(libdir) -Wl,-set_version,${VER}:1.0"};;
129   OSF1*)     SFLAGS=${CFLAGS-"-O -std1"}
130              CFLAGS=${CFLAGS-"-O -std1"}
131              LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"};;
132   QNX*)      SFLAGS=${CFLAGS-"-4 -O"}
133              CFLAGS=${CFLAGS-"-4 -O"}
134              LDSHARED=${LDSHARED-"cc"}
135              RANLIB=${RANLIB-"true"}
136              AR_RC="cc -A";;
137   SCO_SV\ 3.2*) SFLAGS=${CFLAGS-"-O3 -dy -KPIC "}
138              CFLAGS=${CFLAGS-"-O3"}
139              LDSHARED=${LDSHARED-"cc -dy -KPIC -G"};;
140   SunOS\ 5*) LDSHARED=${LDSHARED-"cc -G"}
141          case `(uname -m || echo unknown) 2>/dev/null` in
142          i86*)
143              SFLAGS=${CFLAGS-"-xpentium -fast -KPIC -R."}
144              CFLAGS=${CFLAGS-"-xpentium -fast"};;
145          *)
146              SFLAGS=${CFLAGS-"-fast -xcg92 -KPIC -R."}
147              CFLAGS=${CFLAGS-"-fast -xcg92"};;
148          esac;;
149   SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"}
150              CFLAGS=${CFLAGS-"-O2"}
151              LDSHARED=${LDSHARED-"ld"};;
152   SunStudio\ 9*) SFLAGS=${CFLAGS-"-DUSE_MMAP -fast -xcode=pic32 -xtarget=ultra3 -xarch=v9b"}
153              CFLAGS=${CFLAGS-"-DUSE_MMAP -fast -xtarget=ultra3 -xarch=v9b"}
154              LDSHARED=${LDSHARED-"cc -xarch=v9b"};;
155   UNIX_System_V\ 4.2.0)
156              SFLAGS=${CFLAGS-"-KPIC -O"}
157              CFLAGS=${CFLAGS-"-O"}
158              LDSHARED=${LDSHARED-"cc -G"};;
159   UNIX_SV\ 4.2MP)
160              SFLAGS=${CFLAGS-"-Kconform_pic -O"}
161              CFLAGS=${CFLAGS-"-O"}
162              LDSHARED=${LDSHARED-"cc -G"};;
163   OpenUNIX\ 5)
164              SFLAGS=${CFLAGS-"-KPIC -O"}
165              CFLAGS=${CFLAGS-"-O"}
166              LDSHARED=${LDSHARED-"cc -G"};;
167   AIX*)  # Courtesy of dbakker@arrayasolutions.com
168              SFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
169              CFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
170              LDSHARED=${LDSHARED-"xlc -G"};;
171   # send working options for other systems to support@gzip.org
172   *)         SFLAGS=${CFLAGS-"-O"}
173              CFLAGS=${CFLAGS-"-O"}
174              LDSHARED=${LDSHARED-"cc -shared"};;
175   esac
176 fi
177
178 SHAREDLIB=${SHAREDLIB-"libz$shared_ext"}
179 SHAREDLIBV=${SHAREDLIBV-"libz$shared_ext.$VER"}
180 SHAREDLIBM=${SHAREDLIBM-"libz$shared_ext.$VER1"}
181
182 if test $shared -eq 1; then
183   echo Checking for shared library support...
184   # we must test in two steps (cc then ld), required at least on SunOS 4.x
185   if test "`($CC -c $SFLAGS $test.c) 2>&1`" = "" &&
186      test "`($LDSHARED -o $test$shared_ext $test.o) 2>&1`" = ""; then
187     LIBS="$LIBS $SHAREDLIBV"
188     echo Building shared library $SHAREDLIBV with $CC.
189   elif test -z "$old_cc" -a -z "$old_cflags"; then
190     echo No shared library support.
191     shared=0;
192   else
193     echo Tested $CC -c $SFLAGS $test.c
194     $CC -c $SFLAGS $test.c
195     echo Tested $LDSHARED -o $test$shared_ext $test.o
196     $LDSHARED -o $test$shared_ext $test.o
197     echo 'No shared library support; try without defining CC and CFLAGS'
198     shared=0;
199   fi
200 fi
201 if test $shared -eq 0; then
202   LDSHARED="$CC"
203   echo Building static library $LIBS version $VER with $CC.
204 fi
205
206 cat > zlibdefs.h << EOF
207 /* zlibdefs.h -- compile-time definitions for the zlib compression library
208  * Copyright (C) 1995-2006 Jean-loup Gailly.
209  * For conditions of distribution and use, see copyright notice in zlib.h
210  */
211
212 EOF
213
214 cat > $test.c <<EOF
215 #include <sys/types.h>
216 off64_t dummy = 0;
217 EOF
218 if test "`($CC -c $CFLAGS -D_LARGEFILE64_SOURCE $test.c) 2>&1`" = ""; then
219   cat >> zlibdefs.h <<EOF
220 #define z_off_t off64_t
221 EOF
222   CFLAGS="${CFLAGS} -D_LARGEFILE64_SOURCE"
223   SFLAGS="${SFLAGS} -D_LARGEFILE64_SOURCE"
224   echo "Checking for off64_t... Yes."
225 else
226   echo "Checking for off64_t... No."
227 fi
228
229 cat > $test.c <<EOF
230 #include <unistd.h>
231 int main() { return 0; }
232 EOF
233 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
234   cat >> zlibdefs.h <<EOF
235 #include <sys/types.h>  /* for off_t */
236 #include <unistd.h>     /* for SEEK_* and off_t */
237 #ifdef VMS
238 #  include <unixio.h>   /* for off_t */
239 #endif
240 #ifndef z_off_t
241 #  define z_off_t off_t
242 #endif
243 EOF
244   echo "Checking for unistd.h... Yes."
245 else
246   echo "Checking for unistd.h... No."
247 fi
248
249 if test $zprefix -eq 1; then
250   sed < zconf.h "/#ifdef Z_PREFIX/s/def Z_PREFIX/ 1/" > zconf.temp.h
251   mv zconf.temp.h zconf.h
252   echo "Using z_ prefix on all symbols."
253 fi
254
255 cat > $test.c <<EOF
256 #include <stdio.h>
257 #include <stdarg.h>
258 #include "zconf.h"
259
260 int main()
261 {
262 #ifndef STDC
263   choke me
264 #endif
265
266   return 0;
267 }
268 EOF
269
270 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
271   echo "Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf()."
272
273   cat > $test.c <<EOF
274 #include <stdio.h>
275 #include <stdarg.h>
276
277 int mytest(char *fmt, ...)
278 {
279   char buf[20];
280   va_list ap;
281
282   va_start(ap, fmt);
283   vsnprintf(buf, sizeof(buf), fmt, ap);
284   va_end(ap);
285   return 0;
286 }
287
288 int main()
289 {
290   return (mytest("Hello%d\n", 1));
291 }
292 EOF
293
294   if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then
295     echo "Checking for vsnprintf() in stdio.h... Yes."
296
297     cat >$test.c <<EOF
298 #include <stdio.h>
299 #include <stdarg.h>
300
301 int mytest(char *fmt, ...)
302 {
303   int n;
304   char buf[20];
305   va_list ap;
306
307   va_start(ap, fmt);
308   n = vsnprintf(buf, sizeof(buf), fmt, ap);
309   va_end(ap);
310   return n;
311 }
312
313 int main()
314 {
315   return (mytest("Hello%d\n", 1));
316 }
317 EOF
318
319     if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
320       echo "Checking for return value of vsnprintf()... Yes."
321     else
322       CFLAGS="$CFLAGS -DHAS_vsnprintf_void"
323       echo "Checking for return value of vsnprintf()... No."
324       echo "  WARNING: apparently vsnprintf() does not return a value. zlib"
325       echo "  can build but will be open to possible string-format security"
326       echo "  vulnerabilities."
327     fi
328   else
329     CFLAGS="$CFLAGS -DNO_vsnprintf"
330     echo "Checking for vsnprintf() in stdio.h... No."
331     echo "  WARNING: vsnprintf() not found, falling back to vsprintf(). zlib"
332     echo "  can build but will be open to possible buffer-overflow security"
333     echo "  vulnerabilities."
334
335     cat >$test.c <<EOF
336 #include <stdio.h>
337 #include <stdarg.h>
338
339 int mytest(char *fmt, ...)
340 {
341   int n;
342   char buf[20];
343   va_list ap;
344
345   va_start(ap, fmt);
346   n = vsprintf(buf, fmt, ap);
347   va_end(ap);
348   return n;
349 }
350
351 int main()
352 {
353   return (mytest("Hello%d\n", 1));
354 }
355 EOF
356
357     if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
358       echo "Checking for return value of vsprintf()... Yes."
359     else
360       CFLAGS="$CFLAGS -DHAS_vsprintf_void"
361       echo "Checking for return value of vsprintf()... No."
362       echo "  WARNING: apparently vsprintf() does not return a value. zlib"
363       echo "  can build but will be open to possible string-format security"
364       echo "  vulnerabilities."
365     fi
366   fi
367 else
368   echo "Checking whether to use vs[n]printf() or s[n]printf()... using s[n]printf()."
369
370   cat >$test.c <<EOF
371 #include <stdio.h>
372
373 int mytest()
374 {
375   char buf[20];
376
377   snprintf(buf, sizeof(buf), "%s", "foo");
378   return 0;
379 }
380
381 int main()
382 {
383   return (mytest());
384 }
385 EOF
386
387   if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then
388     echo "Checking for snprintf() in stdio.h... Yes."
389
390     cat >$test.c <<EOF
391 #include <stdio.h>
392
393 int mytest()
394 {
395   char buf[20];
396
397   return snprintf(buf, sizeof(buf), "%s", "foo");
398 }
399
400 int main()
401 {
402   return (mytest());
403 }
404 EOF
405
406     if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
407       echo "Checking for return value of snprintf()... Yes."
408     else
409       CFLAGS="$CFLAGS -DHAS_snprintf_void"
410       echo "Checking for return value of snprintf()... No."
411       echo "  WARNING: apparently snprintf() does not return a value. zlib"
412       echo "  can build but will be open to possible string-format security"
413       echo "  vulnerabilities."
414     fi
415   else
416     CFLAGS="$CFLAGS -DNO_snprintf"
417     echo "Checking for snprintf() in stdio.h... No."
418     echo "  WARNING: snprintf() not found, falling back to sprintf(). zlib"
419     echo "  can build but will be open to possible buffer-overflow security"
420     echo "  vulnerabilities."
421
422     cat >$test.c <<EOF
423 #include <stdio.h>
424
425 int mytest()
426 {
427   char buf[20];
428
429   return sprintf(buf, "%s", "foo");
430 }
431
432 int main()
433 {
434   return (mytest());
435 }
436 EOF
437
438     if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
439       echo "Checking for return value of sprintf()... Yes."
440     else
441       CFLAGS="$CFLAGS -DHAS_sprintf_void"
442       echo "Checking for return value of sprintf()... No."
443       echo "  WARNING: apparently sprintf() does not return a value. zlib"
444       echo "  can build but will be open to possible string-format security"
445       echo "  vulnerabilities."
446     fi
447   fi
448 fi
449
450 cat >$test.c <<EOF
451 #include <errno.h>
452 int main() { return 0; }
453 EOF
454 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
455   echo "Checking for errno.h... Yes."
456 else
457   echo "Checking for errno.h... No."
458   CFLAGS="$CFLAGS -DNO_ERRNO_H"
459 fi
460
461 cat > $test.c <<EOF
462 #include <sys/types.h>
463 #include <sys/mman.h>
464 #include <sys/stat.h>
465 caddr_t hello() {
466   return mmap((caddr_t)0, (off_t)0, PROT_READ, MAP_SHARED, 0, (off_t)0);
467 }
468 EOF
469 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
470   CFLAGS="$CFLAGS -DUSE_MMAP"
471   echo Checking for mmap support... Yes.
472 else
473   echo Checking for mmap support... No.
474 fi
475
476 CPP=${CPP-"$CC -E"}
477 case $CFLAGS in
478   *ASMV*)
479     if test "`nm $test.o | grep _hello`" = ""; then
480       CPP="$CPP -DNO_UNDERLINE"
481       echo Checking for underline in external names... No.
482     else
483       echo Checking for underline in external names... Yes.
484     fi;;
485 esac
486
487 rm -f $test.[co] $test $test$shared_ext
488
489 # udpate Makefile
490 sed < Makefile.in "
491 /^CC *=/s#=.*#=$CC#
492 /^CFLAGS *=/s#=.*#=$CFLAGS#
493 /^SFLAGS *=/s#=.*#=$SFLAGS#
494 /^CPP *=/s#=.*#=$CPP#
495 /^LDSHARED *=/s#=.*#=$LDSHARED#
496 /^LIBS *=/s#=.*#=$LIBS#
497 /^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
498 /^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
499 /^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
500 /^AR *=/s#=.*#=$AR_RC#
501 /^RANLIB *=/s#=.*#=$RANLIB#
502 /^EXE *=/s#=.*#=$EXE#
503 /^prefix *=/s#=.*#=$prefix#
504 /^exec_prefix *=/s#=.*#=$exec_prefix#
505 /^libdir *=/s#=.*#=$libdir#
506 /^includedir *=/s#=.*#=$includedir#
507 /^mandir *=/s#=.*#=$mandir#
508 /^LDFLAGS *=/s#=.*#=$LDFLAGS#
509 " > Makefile
510
511 sed < zlib.pc.in "
512 /^CC *=/s#=.*#=$CC#
513 /^CFLAGS *=/s#=.*#=$CFLAGS#
514 /^CPP *=/s#=.*#=$CPP#
515 /^LDSHARED *=/s#=.*#=$LDSHARED#
516 /^LIBS *=/s#=.*#=$LIBS#
517 /^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
518 /^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
519 /^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
520 /^AR *=/s#=.*#=$AR_RC#
521 /^RANLIB *=/s#=.*#=$RANLIB#
522 /^EXE *=/s#=.*#=$EXE#
523 /^prefix *=/s#=.*#=$prefix#
524 /^exec_prefix *=/s#=.*#=$exec_prefix#
525 /^libdir *=/s#=.*#=$libdir#
526 /^includedir *=/s#=.*#=$includedir#
527 /^mandir *=/s#=.*#=$mandir#
528 /^LDFLAGS *=/s#=.*#=$LDFLAGS#
529 " | sed -e "
530 s/\@VERSION\@/$VER/g;
531 " > zlib.pc