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