]> git.lizzy.rs Git - zlib.git/blob - configure
zlib 1.2.3.8
[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 build64=0
34 gcc=0
35 old_cc="$CC"
36 old_cflags="$CFLAGS"
37
38 while test $# -ge 1
39 do
40 case "$1" in
41     -h* | --help)
42       echo 'usage:'
43       echo '  configure [--zprefix] [--prefix=PREFIX]  [--eprefix=EXPREFIX]'
44       echo '    [--static] [--64] [--libdir=LIBDIR] [--includedir=INCLUDEDIR]'
45         exit 0 ;;
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 ;;
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   if test $build64 -eq 1; then
84     CFLAGS="${CFLAGS} -m64"
85     SFLAGS="${SFLAGS} -m64"
86   fi
87   if test "${ZLIBGCCWARN}" = "YES"; then
88     CFLAGS="${CFLAGS} -Wall -Wextra -pedantic"
89   fi
90   if test -z "$uname"; then
91     uname=`(uname -s || echo unknown) 2>/dev/null`
92   fi
93   case "$uname" in
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* )
96              EXE='.exe' ;;
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"} ;;
100   HP-UX*)
101          LDSHARED=${LDSHARED-"$cc -shared $SFLAGS"}
102          case `(uname -m || echo unknown) 2>/dev/null` in
103          ia64)
104                  shared_ext='.so'
105                  SHAREDLIB='libz.so' ;;
106          *)
107                  shared_ext='.sl'
108                  SHAREDLIB='libz.sl' ;;
109          esac ;;
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"} ;;
116   esac
117 else
118   # find system name and corresponding cc options
119   CC=${CC-cc}
120   if test -z "$uname"; then
121     uname=`(uname -sr || echo unknown) 2>/dev/null`
122   fi
123   case "$uname" in
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
129          ia64)
130              shared_ext='.so'
131              SHAREDLIB='libz.so' ;;
132          *)
133              shared_ext='.sl'
134              SHAREDLIB='libz.sl' ;;
135          esac ;;
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"}
150              AR_RC="cc -A" ;;
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
156          i86*)
157              SFLAGS=${CFLAGS-"-xpentium -fast -KPIC -R."}
158              CFLAGS=${CFLAGS-"-xpentium -fast"} ;;
159          *)
160              SFLAGS=${CFLAGS-"-fast -xcg92 -KPIC -R."}
161              CFLAGS=${CFLAGS-"-fast -xcg92"} ;;
162          esac ;;
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"} ;;
173   UNIX_SV\ 4.2MP)
174              SFLAGS=${CFLAGS-"-Kconform_pic -O"}
175              CFLAGS=${CFLAGS-"-O"}
176              LDSHARED=${LDSHARED-"cc -G"} ;;
177   OpenUNIX\ 5)
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"} ;;
189   esac
190 fi
191
192 SHAREDLIB=${SHAREDLIB-"libz$shared_ext"}
193 SHAREDLIBV=${SHAREDLIBV-"libz$shared_ext.$VER"}
194 SHAREDLIBM=${SHAREDLIBM-"libz$shared_ext.$VER1"}
195
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.
204     shared=0;
205   else
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'
211     shared=0;
212   fi
213 fi
214 if test $shared -eq 0; then
215   LDSHARED="$CC"
216   ALL="static"
217   TEST="all teststatic"
218   echo Building static library $STATICLIB version $VER with $CC.
219 else
220   ALL="static shared"
221   TEST="all teststatic testshared"
222 fi
223
224 cat > $test.c <<EOF
225 #include <sys/types.h>
226 off64_t dummy = 0;
227 EOF
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"
231   ALL="${ALL} all64"
232   TEST="${TEST} test64"
233   echo "Checking for off64_t... Yes."
234   echo "Checking for fseeko... Yes."
235 else
236   echo "Checking for off64_t... No."
237   cat > $test.c <<EOF
238 #include <stdio.h>
239 int main(void) {
240   fseeko(NULL, 0, 0);
241   return 0;
242 }
243 EOF
244   if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then
245     echo "Checking for fseeko... Yes."
246   else
247     CFLAGS="${CFLAGS} -DNO_FSEEKO"
248     SFLAGS="${SFLAGS} -DNO_FSEEKO"
249     echo "Checking for fseeko... No."
250   fi
251 fi
252
253 cp -p zconf.in.h zconf.h
254
255 cat > $test.c <<EOF
256 #include <unistd.h>
257 int main() { return 0; }
258 EOF
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."
263 else
264   echo "Checking for unistd.h... No."
265 fi
266
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."
271 fi
272
273 cat > $test.c <<EOF
274 #include <stdio.h>
275 #include <stdarg.h>
276 #include "zconf.h"
277
278 int main()
279 {
280 #ifndef STDC
281   choke me
282 #endif
283
284   return 0;
285 }
286 EOF
287
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()."
290
291   cat > $test.c <<EOF
292 #include <stdio.h>
293 #include <stdarg.h>
294
295 int mytest(const char *fmt, ...)
296 {
297   char buf[20];
298   va_list ap;
299
300   va_start(ap, fmt);
301   vsnprintf(buf, sizeof(buf), fmt, ap);
302   va_end(ap);
303   return 0;
304 }
305
306 int main()
307 {
308   return (mytest("Hello%d\n", 1));
309 }
310 EOF
311
312   if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then
313     echo "Checking for vsnprintf() in stdio.h... Yes."
314
315     cat >$test.c <<EOF
316 #include <stdio.h>
317 #include <stdarg.h>
318
319 int mytest(char *fmt, ...)
320 {
321   int n;
322   char buf[20];
323   va_list ap;
324
325   va_start(ap, fmt);
326   n = vsnprintf(buf, sizeof(buf), fmt, ap);
327   va_end(ap);
328   return n;
329 }
330
331 int main()
332 {
333   return (mytest("Hello%d\n", 1));
334 }
335 EOF
336
337     if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
338       echo "Checking for return value of vsnprintf()... Yes."
339     else
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."
346     fi
347   else
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."
354
355     cat >$test.c <<EOF
356 #include <stdio.h>
357 #include <stdarg.h>
358
359 int mytest(const char *fmt, ...)
360 {
361   int n;
362   char buf[20];
363   va_list ap;
364
365   va_start(ap, fmt);
366   n = vsprintf(buf, fmt, ap);
367   va_end(ap);
368   return n;
369 }
370
371 int main()
372 {
373   return (mytest("Hello%d\n", 1));
374 }
375 EOF
376
377     if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
378       echo "Checking for return value of vsprintf()... Yes."
379     else
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."
386     fi
387   fi
388 else
389   echo "Checking whether to use vs[n]printf() or s[n]printf()... using s[n]printf()."
390
391   cat >$test.c <<EOF
392 #include <stdio.h>
393
394 int mytest()
395 {
396   char buf[20];
397
398   snprintf(buf, sizeof(buf), "%s", "foo");
399   return 0;
400 }
401
402 int main()
403 {
404   return (mytest());
405 }
406 EOF
407
408   if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then
409     echo "Checking for snprintf() in stdio.h... Yes."
410
411     cat >$test.c <<EOF
412 #include <stdio.h>
413
414 int mytest()
415 {
416   char buf[20];
417
418   return snprintf(buf, sizeof(buf), "%s", "foo");
419 }
420
421 int main()
422 {
423   return (mytest());
424 }
425 EOF
426
427     if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
428       echo "Checking for return value of snprintf()... Yes."
429     else
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."
436     fi
437   else
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."
444
445     cat >$test.c <<EOF
446 #include <stdio.h>
447
448 int mytest()
449 {
450   char buf[20];
451
452   return sprintf(buf, "%s", "foo");
453 }
454
455 int main()
456 {
457   return (mytest());
458 }
459 EOF
460
461     if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
462       echo "Checking for return value of sprintf()... Yes."
463     else
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."
470     fi
471   fi
472 fi
473
474 cat >$test.c <<EOF
475 #include <errno.h>
476 int main() { return 0; }
477 EOF
478 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
479   echo "Checking for errno.h... Yes."
480 else
481   echo "Checking for errno.h... No."
482   CFLAGS="$CFLAGS -DNO_ERRNO_H"
483   SFLAGS="$SFLAGS -DNO_ERRNO_H"
484 fi
485
486 CPP=${CPP-"$CC -E"}
487 case $CFLAGS in
488   *ASMV*)
489     if test "`nm $test.o | grep _hello`" = ""; then
490       CPP="$CPP -DNO_UNDERLINE"
491       echo Checking for underline in external names... No.
492     else
493       echo Checking for underline in external names... Yes.
494     fi ;;
495 esac
496
497 rm -f $test.[co] $test $test$shared_ext
498
499 # udpate Makefile
500 sed < Makefile.in "
501 /^CC *=/s#=.*#=$CC#
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#
521 " > Makefile
522
523 sed < zlib.pc.in "
524 /^CC *=/s#=.*#=$CC#
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#
541 " | sed -e "
542 s/\@VERSION\@/$VER/g;
543 " > zlib.pc