]> git.lizzy.rs Git - zlib.git/blob - configure
zlib 1.2.3.1
[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"
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     CFLAGS="$SFLAGS"
188     LIBS="$SHAREDLIBV"
189     echo Building shared library $SHAREDLIBV with $CC.
190   elif test -z "$old_cc" -a -z "$old_cflags"; then
191     echo No shared library support.
192     shared=0;
193   else
194     echo Tested $CC -c $SFLAGS $test.c
195     $CC -c $SFLAGS $test.c
196     echo Tested $LDSHARED -o $test$shared_ext $test.o
197     $LDSHARED -o $test$shared_ext $test.o
198     echo 'No shared library support; try without defining CC and CFLAGS'
199     shared=0;
200   fi
201 fi
202 if test $shared -eq 0; then
203   LDSHARED="$CC"
204   echo Building static library $LIBS version $VER with $CC.
205 else
206   LDFLAGS="-L. ${SHAREDLIBV}"
207 fi
208
209 cat > $test.c <<EOF
210 #include <unistd.h>
211 int main() { return 0; }
212 EOF
213 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
214   sed < zconf.in.h "/HAVE_UNISTD_H/s%0%1%" > zconf.h
215   echo "Checking for unistd.h... Yes."
216 else
217   cp -p zconf.in.h zconf.h
218   echo "Checking for unistd.h... No."
219 fi
220
221 if test $zprefix -eq 1; then
222   sed < zconf.h "/#ifdef Z_PREFIX/s/def Z_PREFIX/ 1/" > zconf.temp.h
223   mv zconf.temp.h zconf.h
224   echo "Using z_ prefix on all symbols."
225 fi
226
227 cat > $test.c <<EOF
228 #include <stdio.h>
229 #include <stdarg.h>
230 #include "zconf.h"
231
232 int main()
233 {
234 #ifndef STDC
235   choke me
236 #endif
237
238   return 0;
239 }
240 EOF
241
242 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
243   echo "Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf()."
244
245   cat > $test.c <<EOF
246 #include <stdio.h>
247 #include <stdarg.h>
248
249 int mytest(char *fmt, ...)
250 {
251   char buf[20];
252   va_list ap;
253
254   va_start(ap, fmt);
255   vsnprintf(buf, sizeof(buf), fmt, ap);
256   va_end(ap);
257   return 0;
258 }
259
260 int main()
261 {
262   return (mytest("Hello%d\n", 1));
263 }
264 EOF
265
266   if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then
267     echo "Checking for vsnprintf() in stdio.h... Yes."
268
269     cat >$test.c <<EOF
270 #include <stdio.h>
271 #include <stdarg.h>
272
273 int mytest(char *fmt, ...)
274 {
275   int n;
276   char buf[20];
277   va_list ap;
278
279   va_start(ap, fmt);
280   n = vsnprintf(buf, sizeof(buf), fmt, ap);
281   va_end(ap);
282   return n;
283 }
284
285 int main()
286 {
287   return (mytest("Hello%d\n", 1));
288 }
289 EOF
290
291     if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
292       echo "Checking for return value of vsnprintf()... Yes."
293     else
294       CFLAGS="$CFLAGS -DHAS_vsnprintf_void"
295       echo "Checking for return value of vsnprintf()... No."
296       echo "  WARNING: apparently vsnprintf() does not return a value. zlib"
297       echo "  can build but will be open to possible string-format security"
298       echo "  vulnerabilities."
299     fi
300   else
301     CFLAGS="$CFLAGS -DNO_vsnprintf"
302     echo "Checking for vsnprintf() in stdio.h... No."
303     echo "  WARNING: vsnprintf() not found, falling back to vsprintf(). zlib"
304     echo "  can build but will be open to possible buffer-overflow security"
305     echo "  vulnerabilities."
306
307     cat >$test.c <<EOF
308 #include <stdio.h>
309 #include <stdarg.h>
310
311 int mytest(char *fmt, ...)
312 {
313   int n;
314   char buf[20];
315   va_list ap;
316
317   va_start(ap, fmt);
318   n = vsprintf(buf, fmt, ap);
319   va_end(ap);
320   return n;
321 }
322
323 int main()
324 {
325   return (mytest("Hello%d\n", 1));
326 }
327 EOF
328
329     if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
330       echo "Checking for return value of vsprintf()... Yes."
331     else
332       CFLAGS="$CFLAGS -DHAS_vsprintf_void"
333       echo "Checking for return value of vsprintf()... No."
334       echo "  WARNING: apparently vsprintf() does not return a value. zlib"
335       echo "  can build but will be open to possible string-format security"
336       echo "  vulnerabilities."
337     fi
338   fi
339 else
340   echo "Checking whether to use vs[n]printf() or s[n]printf()... using s[n]printf()."
341
342   cat >$test.c <<EOF
343 #include <stdio.h>
344
345 int mytest()
346 {
347   char buf[20];
348
349   snprintf(buf, sizeof(buf), "%s", "foo");
350   return 0;
351 }
352
353 int main()
354 {
355   return (mytest());
356 }
357 EOF
358
359   if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then
360     echo "Checking for snprintf() in stdio.h... Yes."
361
362     cat >$test.c <<EOF
363 #include <stdio.h>
364
365 int mytest()
366 {
367   char buf[20];
368
369   return snprintf(buf, sizeof(buf), "%s", "foo");
370 }
371
372 int main()
373 {
374   return (mytest());
375 }
376 EOF
377
378     if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
379       echo "Checking for return value of snprintf()... Yes."
380     else
381       CFLAGS="$CFLAGS -DHAS_snprintf_void"
382       echo "Checking for return value of snprintf()... No."
383       echo "  WARNING: apparently snprintf() 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   else
388     CFLAGS="$CFLAGS -DNO_snprintf"
389     echo "Checking for snprintf() in stdio.h... No."
390     echo "  WARNING: snprintf() not found, falling back to sprintf(). zlib"
391     echo "  can build but will be open to possible buffer-overflow security"
392     echo "  vulnerabilities."
393
394     cat >$test.c <<EOF
395 #include <stdio.h>
396
397 int mytest()
398 {
399   char buf[20];
400
401   return sprintf(buf, "%s", "foo");
402 }
403
404 int main()
405 {
406   return (mytest());
407 }
408 EOF
409
410     if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
411       echo "Checking for return value of sprintf()... Yes."
412     else
413       CFLAGS="$CFLAGS -DHAS_sprintf_void"
414       echo "Checking for return value of sprintf()... No."
415       echo "  WARNING: apparently sprintf() does not return a value. zlib"
416       echo "  can build but will be open to possible string-format security"
417       echo "  vulnerabilities."
418     fi
419   fi
420 fi
421
422 cat >$test.c <<EOF
423 #include <errno.h>
424 int main() { return 0; }
425 EOF
426 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
427   echo "Checking for errno.h... Yes."
428 else
429   echo "Checking for errno.h... No."
430   CFLAGS="$CFLAGS -DNO_ERRNO_H"
431 fi
432
433 cat > $test.c <<EOF
434 #include <sys/types.h>
435 #include <sys/mman.h>
436 #include <sys/stat.h>
437 caddr_t hello() {
438   return mmap((caddr_t)0, (off_t)0, PROT_READ, MAP_SHARED, 0, (off_t)0);
439 }
440 EOF
441 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
442   CFLAGS="$CFLAGS -DUSE_MMAP"
443   echo Checking for mmap support... Yes.
444 else
445   echo Checking for mmap support... No.
446 fi
447
448 CPP=${CPP-"$CC -E"}
449 case $CFLAGS in
450   *ASMV*)
451     if test "`nm $test.o | grep _hello`" = ""; then
452       CPP="$CPP -DNO_UNDERLINE"
453       echo Checking for underline in external names... No.
454     else
455       echo Checking for underline in external names... Yes.
456     fi;;
457 esac
458
459 rm -f $test.[co] $test $test$shared_ext
460
461 # udpate Makefile
462 sed < Makefile.in "
463 /^CC *=/s#=.*#=$CC#
464 /^CFLAGS *=/s#=.*#=$CFLAGS#
465 /^CPP *=/s#=.*#=$CPP#
466 /^LDSHARED *=/s#=.*#=$LDSHARED#
467 /^LIBS *=/s#=.*#=$LIBS#
468 /^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
469 /^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
470 /^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
471 /^AR *=/s#=.*#=$AR_RC#
472 /^RANLIB *=/s#=.*#=$RANLIB#
473 /^EXE *=/s#=.*#=$EXE#
474 /^prefix *=/s#=.*#=$prefix#
475 /^exec_prefix *=/s#=.*#=$exec_prefix#
476 /^libdir *=/s#=.*#=$libdir#
477 /^includedir *=/s#=.*#=$includedir#
478 /^mandir *=/s#=.*#=$mandir#
479 /^LDFLAGS *=/s#=.*#=$LDFLAGS#
480 " > Makefile
481
482 sed < zlib.pc.in "
483 /^CC *=/s#=.*#=$CC#
484 /^CFLAGS *=/s#=.*#=$CFLAGS#
485 /^CPP *=/s#=.*#=$CPP#
486 /^LDSHARED *=/s#=.*#=$LDSHARED#
487 /^LIBS *=/s#=.*#=$LIBS#
488 /^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
489 /^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
490 /^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
491 /^AR *=/s#=.*#=$AR_RC#
492 /^RANLIB *=/s#=.*#=$RANLIB#
493 /^EXE *=/s#=.*#=$EXE#
494 /^prefix *=/s#=.*#=$prefix#
495 /^exec_prefix *=/s#=.*#=$exec_prefix#
496 /^libdir *=/s#=.*#=$libdir#
497 /^includedir *=/s#=.*#=$includedir#
498 /^mandir *=/s#=.*#=$mandir#
499 /^LDFLAGS *=/s#=.*#=$LDFLAGS#
500 " | sed -e "
501 s/\@VERSION\@/$VER/g;
502 " > zlib.pc