]> git.lizzy.rs Git - zlib.git/blob - configure
Cleaner check for whether libtool is Apple or not on Darwin.
[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 # start off configure.log
17 echo -------------------- >> configure.log
18 echo $0 $* >> configure.log
19 date >> configure.log
20
21 # set command prefix for cross-compilation
22 if [ -n "${CHOST}" ]; then
23     uname="`echo "${CHOST}" | sed -e 's/^[^-]*-\([^-]*\)$/\1/' -e 's/^[^-]*-[^-]*-\([^-]*\)$/\1/' -e 's/^[^-]*-[^-]*-\([^-]*\)-.*$/\1/'`"
24     CROSS_PREFIX="${CHOST}-"
25 fi
26
27 # destination name for static library
28 STATICLIB=libz.a
29
30 # extract zlib version numbers from zlib.h
31 VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`
32 VER3=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\\.[0-9]*\).*/\1/p' < zlib.h`
33 VER2=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\)\\..*/\1/p' < zlib.h`
34 VER1=`sed -n -e '/VERSION "/s/.*"\([0-9]*\)\\..*/\1/p' < zlib.h`
35
36 # establish commands for library building
37 if "${CROSS_PREFIX}ar" --version >/dev/null 2>/dev/null || test $? -lt 126; then
38     AR=${AR-"${CROSS_PREFIX}ar"}
39     test -n "${CROSS_PREFIX}" && echo Using ${AR} | tee -a configure.log
40 else
41     AR=${AR-"ar"}
42     test -n "${CROSS_PREFIX}" && echo Using ${AR} | tee -a configure.log
43 fi
44 ARFLAGS=${ARFLAGS-"rc"}
45 if "${CROSS_PREFIX}ranlib" --version >/dev/null 2>/dev/null || test $? -lt 126; then
46     RANLIB=${RANLIB-"${CROSS_PREFIX}ranlib"}
47     test -n "${CROSS_PREFIX}" && echo Using ${RANLIB} | tee -a configure.log
48 else
49     RANLIB=${RANLIB-"ranlib"}
50 fi
51 if "${CROSS_PREFIX}nm" --version >/dev/null 2>/dev/null || test $? -lt 126; then
52     NM=${NM-"${CROSS_PREFIX}nm"}
53     test -n "${CROSS_PREFIX}" && echo Using ${NM} | tee -a configure.log
54 else
55     NM=${NM-"nm"}
56 fi
57
58 # set defaults before processing command line options
59 LDCONFIG=${LDCONFIG-"ldconfig"}
60 LDSHAREDLIBC="${LDSHAREDLIBC--lc}"
61 ARCHS=
62 prefix=${prefix-/usr/local}
63 exec_prefix=${exec_prefix-'${prefix}'}
64 libdir=${libdir-'${exec_prefix}/lib'}
65 sharedlibdir=${sharedlibdir-'${libdir}'}
66 includedir=${includedir-'${prefix}/include'}
67 mandir=${mandir-'${prefix}/share/man'}
68 shared_ext='.so'
69 shared=1
70 solo=0
71 cover=0
72 zprefix=0
73 build64=0
74 gcc=0
75 old_cc="$CC"
76 old_cflags="$CFLAGS"
77 OBJC='$(OBJZ) $(OBJG)'
78 PIC_OBJC='$(PIC_OBJZ) $(PIC_OBJG)'
79
80 # process command line options
81 while test $# -ge 1
82 do
83 case "$1" in
84     -h* | --help)
85       echo 'usage:' | tee -a configure.log
86       echo '  configure [--zprefix] [--prefix=PREFIX]  [--eprefix=EXPREFIX]' | tee -a configure.log
87       echo '    [--static] [--64] [--libdir=LIBDIR] [--sharedlibdir=LIBDIR]' | tee -a configure.log
88       echo '    [--includedir=INCLUDEDIR] [--archs="-arch i386 -arch x86_64"]' | tee -a configure.log
89         exit 0 ;;
90     -p*=* | --prefix=*) prefix=`echo $1 | sed 's/.*=//'`; shift ;;
91     -e*=* | --eprefix=*) exec_prefix=`echo $1 | sed 's/.*=//'`; shift ;;
92     -l*=* | --libdir=*) libdir=`echo $1 | sed 's/.*=//'`; shift ;;
93     --sharedlibdir=*) sharedlibdir=`echo $1 | sed 's/.*=//'`; shift ;;
94     -i*=* | --includedir=*) includedir=`echo $1 | sed 's/.*=//'`;shift ;;
95     -u*=* | --uname=*) uname=`echo $1 | sed 's/.*=//'`;shift ;;
96     -p* | --prefix) prefix="$2"; shift; shift ;;
97     -e* | --eprefix) exec_prefix="$2"; shift; shift ;;
98     -l* | --libdir) libdir="$2"; shift; shift ;;
99     -i* | --includedir) includedir="$2"; shift; shift ;;
100     -s* | --shared | --enable-shared) shared=1; shift ;;
101     -t | --static) shared=0; shift ;;
102     --solo) solo=1; shift ;;
103     --cover) cover=1; shift ;;
104     -z* | --zprefix) zprefix=1; shift ;;
105     -6* | --64) build64=1; shift ;;
106     -a*=* | --archs=*) ARCHS=`echo $1 | sed 's/.*=//'`; shift ;;
107     --sysconfdir=*) echo "ignored option: --sysconfdir" | tee -a configure.log; shift ;;
108     --localstatedir=*) echo "ignored option: --localstatedir" | tee -a configure.log; shift ;;
109     *) echo "unknown option: $1"; echo "$0 --help for help" | tee -a configure.log; exit 1 ;;
110     esac
111 done
112
113 # define functions for testing compiler and library characteristics and logging the results
114 test=ztest$$
115
116 show()
117 {
118   case "$*" in
119     *$test.c*)
120       echo === $test.c === >> configure.log
121       cat $test.c >> configure.log
122       echo === >> configure.log;;
123   esac
124   echo $* >> configure.log
125 }
126
127 cat > $test.c <<EOF
128 #error error
129 EOF
130 if ($CC -c $CFLAGS $test.c) 2>/dev/null; then
131   try()
132   {
133     show $*
134     test "`( $* ) 2>&1 | tee -a configure.log`" = ""
135   }
136   echo - using any output from compiler to indicate an error >> configure.log
137 else
138   try()
139   {
140     show $*
141     ( $* ) >> configure.log 2>&1
142     ret=$?
143     if test $ret -ne 0; then
144       echo "(exit code "$ret")" >> configure.log
145     fi
146     return $ret
147   }
148 fi
149
150 tryboth()
151 {
152   show $*
153   got=`( $* ) 2>&1`
154   ret=$?
155   printf %s "$got" >> configure.log
156   if test $ret -ne 0; then
157     return $ret
158   fi
159   test "$got" = ""
160 }
161
162 echo >> configure.log
163
164 # check for gcc vs. cc and set compile and link flags based on the system identified by uname
165 cat > $test.c <<EOF
166 extern int getchar();
167 int hello() {return getchar();}
168 EOF
169
170 test -z "$CC" && echo Checking for ${CROSS_PREFIX}gcc... | tee -a configure.log
171 cc=${CC-${CROSS_PREFIX}gcc}
172 cflags=${CFLAGS-"-O3"}
173 # to force the asm version use: CFLAGS="-O3 -DASMV" ./configure
174 case "$cc" in
175   *gcc*) gcc=1 ;;
176   *clang*) gcc=1 ;;
177 esac
178 case `$cc -v 2>&1` in
179   *gcc*) gcc=1 ;;
180 esac
181
182 show $cc -c $cflags $test.c
183 if test "$gcc" -eq 1 && ($cc -c $cflags $test.c) >> configure.log 2>&1; then
184   echo ... using gcc >> configure.log
185   CC="$cc"
186   CFLAGS="${CFLAGS--O3} ${ARCHS}"
187   SFLAGS="${CFLAGS--O3} -fPIC"
188   LDFLAGS="${LDFLAGS} ${ARCHS}"
189   if test $build64 -eq 1; then
190     CFLAGS="${CFLAGS} -m64"
191     SFLAGS="${SFLAGS} -m64"
192   fi
193   if test "${ZLIBGCCWARN}" = "YES"; then
194     CFLAGS="${CFLAGS} -Wall -Wextra -pedantic"
195   fi
196   if test -z "$uname"; then
197     uname=`(uname -s || echo unknown) 2>/dev/null`
198   fi
199   case "$uname" in
200   Linux* | linux* | GNU | GNU/* | solaris*)
201         LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map"} ;;
202   *BSD | *bsd* | DragonFly)
203         LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map"}
204         LDCONFIG="ldconfig -m" ;;
205   CYGWIN* | Cygwin* | cygwin* | OS/2*)
206         EXE='.exe' ;;
207   MINGW* | mingw*)
208 # temporary bypass
209         rm -f $test.[co] $test $test$shared_ext
210         echo "Please use win32/Makefile.gcc instead." | tee -a configure.log
211         exit 1
212         LDSHARED=${LDSHARED-"$cc -shared"}
213         LDSHAREDLIBC=""
214         EXE='.exe' ;;
215   QNX*)  # This is for QNX6. I suppose that the QNX rule below is for QNX2,QNX4
216          # (alain.bonnefoy@icbt.com)
217                  LDSHARED=${LDSHARED-"$cc -shared -Wl,-hlibz.so.1"} ;;
218   HP-UX*)
219          LDSHARED=${LDSHARED-"$cc -shared $SFLAGS"}
220          case `(uname -m || echo unknown) 2>/dev/null` in
221          ia64)
222                  shared_ext='.so'
223                  SHAREDLIB='libz.so' ;;
224          *)
225                  shared_ext='.sl'
226                  SHAREDLIB='libz.sl' ;;
227          esac ;;
228   Darwin* | darwin*)
229              shared_ext='.dylib'
230              SHAREDLIB=libz$shared_ext
231              SHAREDLIBV=libz.$VER$shared_ext
232              SHAREDLIBM=libz.$VER1$shared_ext
233              LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBM -compatibility_version $VER1 -current_version $VER3"}
234              if libtool -V 2>&1 | grep Apple > /dev/null; then
235                  AR="libtool"
236              else
237                  AR="/usr/bin/libtool"
238              fi
239              ARFLAGS="-o" ;;
240   *)             LDSHARED=${LDSHARED-"$cc -shared"} ;;
241   esac
242 else
243   # find system name and corresponding cc options
244   CC=${CC-cc}
245   gcc=0
246   echo ... using $CC >> configure.log
247   if test -z "$uname"; then
248     uname=`(uname -sr || echo unknown) 2>/dev/null`
249   fi
250   case "$uname" in
251   HP-UX*)    SFLAGS=${CFLAGS-"-O +z"}
252              CFLAGS=${CFLAGS-"-O"}
253 #            LDSHARED=${LDSHARED-"ld -b +vnocompatwarnings"}
254              LDSHARED=${LDSHARED-"ld -b"}
255          case `(uname -m || echo unknown) 2>/dev/null` in
256          ia64)
257              shared_ext='.so'
258              SHAREDLIB='libz.so' ;;
259          *)
260              shared_ext='.sl'
261              SHAREDLIB='libz.sl' ;;
262          esac ;;
263   IRIX*)     SFLAGS=${CFLAGS-"-ansi -O2 -rpath ."}
264              CFLAGS=${CFLAGS-"-ansi -O2"}
265              LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;;
266   OSF1\ V4*) SFLAGS=${CFLAGS-"-O -std1"}
267              CFLAGS=${CFLAGS-"-O -std1"}
268              LDFLAGS="${LDFLAGS} -Wl,-rpath,."
269              LDSHARED=${LDSHARED-"cc -shared  -Wl,-soname,libz.so -Wl,-msym -Wl,-rpath,$(libdir) -Wl,-set_version,${VER}:1.0"} ;;
270   OSF1*)     SFLAGS=${CFLAGS-"-O -std1"}
271              CFLAGS=${CFLAGS-"-O -std1"}
272              LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;;
273   QNX*)      SFLAGS=${CFLAGS-"-4 -O"}
274              CFLAGS=${CFLAGS-"-4 -O"}
275              LDSHARED=${LDSHARED-"cc"}
276              RANLIB=${RANLIB-"true"}
277              AR="cc"
278              ARFLAGS="-A" ;;
279   SCO_SV\ 3.2*) SFLAGS=${CFLAGS-"-O3 -dy -KPIC "}
280              CFLAGS=${CFLAGS-"-O3"}
281              LDSHARED=${LDSHARED-"cc -dy -KPIC -G"} ;;
282   SunOS\ 5* | solaris*)
283          LDSHARED=${LDSHARED-"cc -G -h libz$shared_ext.$VER1"}
284          SFLAGS=${CFLAGS-"-fast -KPIC"}
285          CFLAGS=${CFLAGS-"-fast"}
286          if test $build64 -eq 1; then
287              # old versions of SunPRO/Workshop/Studio don't support -m64,
288              # but newer ones do.  Check for it.
289              flag64=`$CC -flags | egrep -- '^-m64'`
290              if test x"$flag64" != x"" ; then
291                  CFLAGS="${CFLAGS} -m64"
292                  SFLAGS="${SFLAGS} -m64"
293              else
294                  case `(uname -m || echo unknown) 2>/dev/null` in
295                    i86*)
296                      SFLAGS="$SFLAGS -xarch=amd64"
297                      CFLAGS="$CFLAGS -xarch=amd64" ;;
298                    *)
299                      SFLAGS="$SFLAGS -xarch=v9"
300                      CFLAGS="$CFLAGS -xarch=v9" ;;
301                  esac
302              fi
303          fi
304          ;;
305   SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"}
306              CFLAGS=${CFLAGS-"-O2"}
307              LDSHARED=${LDSHARED-"ld"} ;;
308   SunStudio\ 9*) SFLAGS=${CFLAGS-"-fast -xcode=pic32 -xtarget=ultra3 -xarch=v9b"}
309              CFLAGS=${CFLAGS-"-fast -xtarget=ultra3 -xarch=v9b"}
310              LDSHARED=${LDSHARED-"cc -xarch=v9b"} ;;
311   UNIX_System_V\ 4.2.0)
312              SFLAGS=${CFLAGS-"-KPIC -O"}
313              CFLAGS=${CFLAGS-"-O"}
314              LDSHARED=${LDSHARED-"cc -G"} ;;
315   UNIX_SV\ 4.2MP)
316              SFLAGS=${CFLAGS-"-Kconform_pic -O"}
317              CFLAGS=${CFLAGS-"-O"}
318              LDSHARED=${LDSHARED-"cc -G"} ;;
319   OpenUNIX\ 5)
320              SFLAGS=${CFLAGS-"-KPIC -O"}
321              CFLAGS=${CFLAGS-"-O"}
322              LDSHARED=${LDSHARED-"cc -G"} ;;
323   AIX*)  # Courtesy of dbakker@arrayasolutions.com
324              SFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
325              CFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
326              LDSHARED=${LDSHARED-"xlc -G"} ;;
327   # send working options for other systems to zlib@gzip.org
328   *)         SFLAGS=${CFLAGS-"-O"}
329              CFLAGS=${CFLAGS-"-O"}
330              LDSHARED=${LDSHARED-"cc -shared"} ;;
331   esac
332 fi
333
334 # destination names for shared library if not defined above
335 SHAREDLIB=${SHAREDLIB-"libz$shared_ext"}
336 SHAREDLIBV=${SHAREDLIBV-"libz$shared_ext.$VER"}
337 SHAREDLIBM=${SHAREDLIBM-"libz$shared_ext.$VER1"}
338
339 echo >> configure.log
340
341 # see if shared library build supported
342 if test $shared -eq 1; then
343   echo Checking for shared library support... | tee -a configure.log
344   # we must test in two steps (cc then ld), required at least on SunOS 4.x
345   if try $CC -w -c $SFLAGS $test.c &&
346      try $LDSHARED $SFLAGS -o $test$shared_ext $test.o; then
347     echo Building shared library $SHAREDLIBV with $CC. | tee -a configure.log
348   elif test -z "$old_cc" -a -z "$old_cflags"; then
349     echo No shared library support. | tee -a configure.log
350     shared=0;
351   else
352     echo 'No shared library support; try without defining CC and CFLAGS' | tee -a configure.log
353     shared=0;
354   fi
355 fi
356 if test $shared -eq 0; then
357   LDSHARED="$CC"
358   ALL="static"
359   TEST="all teststatic"
360   SHAREDLIB=""
361   SHAREDLIBV=""
362   SHAREDLIBM=""
363   echo Building static library $STATICLIB version $VER with $CC. | tee -a configure.log
364 else
365   ALL="static shared"
366   TEST="all teststatic testshared"
367 fi
368
369 echo >> configure.log
370
371 # check for underscores in external names for use by assembler code
372 CPP=${CPP-"$CC -E"}
373 case $CFLAGS in
374   *ASMV*)
375     echo >> configure.log
376     show "$NM $test.o | grep _hello"
377     if test "`$NM $test.o | grep _hello | tee -a configure.log`" = ""; then
378       CPP="$CPP -DNO_UNDERLINE"
379       echo Checking for underline in external names... No. | tee -a configure.log
380     else
381       echo Checking for underline in external names... Yes. | tee -a configure.log
382     fi ;;
383 esac
384
385 echo >> configure.log
386
387 # check for large file support, and if none, check for fseeko()
388 cat > $test.c <<EOF
389 #include <sys/types.h>
390 off64_t dummy = 0;
391 EOF
392 if try $CC -c $CFLAGS -D_LARGEFILE64_SOURCE=1 $test.c; then
393   CFLAGS="${CFLAGS} -D_LARGEFILE64_SOURCE=1"
394   SFLAGS="${SFLAGS} -D_LARGEFILE64_SOURCE=1"
395   ALL="${ALL} all64"
396   TEST="${TEST} test64"
397   echo "Checking for off64_t... Yes." | tee -a configure.log
398   echo "Checking for fseeko... Yes." | tee -a configure.log
399 else
400   echo "Checking for off64_t... No." | tee -a configure.log
401   echo >> configure.log
402   cat > $test.c <<EOF
403 #include <stdio.h>
404 int main(void) {
405   fseeko(NULL, 0, 0);
406   return 0;
407 }
408 EOF
409   if try $CC $CFLAGS -o $test $test.c; then
410     echo "Checking for fseeko... Yes." | tee -a configure.log
411   else
412     CFLAGS="${CFLAGS} -DNO_FSEEKO"
413     SFLAGS="${SFLAGS} -DNO_FSEEKO"
414     echo "Checking for fseeko... No." | tee -a configure.log
415   fi
416 fi
417
418 echo >> configure.log
419
420 # check for strerror() for use by gz* functions
421 cat > $test.c <<EOF
422 #include <string.h>
423 #include <errno.h>
424 int main() { return strlen(strerror(errno)); }
425 EOF
426 if try $CC $CFLAGS -o $test $test.c; then
427   echo "Checking for strerror... Yes." | tee -a configure.log
428 else
429   CFLAGS="${CFLAGS} -DNO_STRERROR"
430   SFLAGS="${SFLAGS} -DNO_STRERROR"
431   echo "Checking for strerror... No." | tee -a configure.log
432 fi
433
434 # copy clean zconf.h for subsequent edits
435 cp -p zconf.h.in zconf.h
436
437 echo >> configure.log
438
439 # check for unistd.h and save result in zconf.h
440 cat > $test.c <<EOF
441 #include <unistd.h>
442 int main() { return 0; }
443 EOF
444 if try $CC -c $CFLAGS $test.c; then
445   sed < zconf.h "/^#ifdef HAVE_UNISTD_H.* may be/s/def HAVE_UNISTD_H\(.*\) may be/ 1\1 was/" > zconf.temp.h
446   mv zconf.temp.h zconf.h
447   echo "Checking for unistd.h... Yes." | tee -a configure.log
448 else
449   echo "Checking for unistd.h... No." | tee -a configure.log
450 fi
451
452 echo >> configure.log
453
454 # check for stdarg.h and save result in zconf.h
455 cat > $test.c <<EOF
456 #include <stdarg.h>
457 int main() { return 0; }
458 EOF
459 if try $CC -c $CFLAGS $test.c; then
460   sed < zconf.h "/^#ifdef HAVE_STDARG_H.* may be/s/def HAVE_STDARG_H\(.*\) may be/ 1\1 was/" > zconf.temp.h
461   mv zconf.temp.h zconf.h
462   echo "Checking for stdarg.h... Yes." | tee -a configure.log
463 else
464   echo "Checking for stdarg.h... No." | tee -a configure.log
465 fi
466
467 # if the z_ prefix was requested, save that in zconf.h
468 if test $zprefix -eq 1; then
469   sed < zconf.h "/#ifdef Z_PREFIX.* may be/s/def Z_PREFIX\(.*\) may be/ 1\1 was/" > zconf.temp.h
470   mv zconf.temp.h zconf.h
471   echo >> configure.log
472   echo "Using z_ prefix on all symbols." | tee -a configure.log
473 fi
474
475 # if --solo compilation was requested, save that in zconf.h and remove gz stuff from object lists
476 if test $solo -eq 1; then
477   sed '/#define ZCONF_H/a\
478 #define Z_SOLO
479
480 ' < zconf.h > zconf.temp.h
481   mv zconf.temp.h zconf.h
482 OBJC='$(OBJZ)'
483 PIC_OBJC='$(PIC_OBJZ)'
484 fi
485
486 # if code coverage testing was requested, use older gcc if defined, e.g. "gcc-4.2" on Mac OS X
487 if test $cover -eq 1; then
488   CFLAGS="${CFLAGS} -fprofile-arcs -ftest-coverage"
489   if test -n "$GCC_CLASSIC"; then
490     CC=$GCC_CLASSIC
491   fi
492 fi
493
494 echo >> configure.log
495
496 # conduct a series of tests to resolve eight possible cases of using "vs" or "s" printf functions
497 # (using stdarg or not), with or without "n" (proving size of buffer), and with or without a
498 # return value.  The most secure result is vsnprintf() with a return value.  snprintf() with a
499 # return value is secure as well, but then gzprintf() will be limited to 20 arguments.
500 cat > $test.c <<EOF
501 #include <stdio.h>
502 #include <stdarg.h>
503 #include "zconf.h"
504 int main()
505 {
506 #ifndef STDC
507   choke me
508 #endif
509   return 0;
510 }
511 EOF
512 if try $CC -c $CFLAGS $test.c; then
513   echo "Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf()." | tee -a configure.log
514
515   echo >> configure.log
516   cat > $test.c <<EOF
517 #include <stdio.h>
518 #include <stdarg.h>
519 int mytest(const char *fmt, ...)
520 {
521   char buf[20];
522   va_list ap;
523   va_start(ap, fmt);
524   vsnprintf(buf, sizeof(buf), fmt, ap);
525   va_end(ap);
526   return 0;
527 }
528 int main()
529 {
530   return (mytest("Hello%d\n", 1));
531 }
532 EOF
533   if try $CC $CFLAGS -o $test $test.c; then
534     echo "Checking for vsnprintf() in stdio.h... Yes." | tee -a configure.log
535
536     echo >> configure.log
537     cat >$test.c <<EOF
538 #include <stdio.h>
539 #include <stdarg.h>
540 int mytest(const char *fmt, ...)
541 {
542   int n;
543   char buf[20];
544   va_list ap;
545   va_start(ap, fmt);
546   n = vsnprintf(buf, sizeof(buf), fmt, ap);
547   va_end(ap);
548   return n;
549 }
550 int main()
551 {
552   return (mytest("Hello%d\n", 1));
553 }
554 EOF
555
556     if try $CC -c $CFLAGS $test.c; then
557       echo "Checking for return value of vsnprintf()... Yes." | tee -a configure.log
558     else
559       CFLAGS="$CFLAGS -DHAS_vsnprintf_void"
560       SFLAGS="$SFLAGS -DHAS_vsnprintf_void"
561       echo "Checking for return value of vsnprintf()... No." | tee -a configure.log
562       echo "  WARNING: apparently vsnprintf() does not return a value. zlib" | tee -a configure.log
563       echo "  can build but will be open to possible string-format security" | tee -a configure.log
564       echo "  vulnerabilities." | tee -a configure.log
565     fi
566   else
567     CFLAGS="$CFLAGS -DNO_vsnprintf"
568     SFLAGS="$SFLAGS -DNO_vsnprintf"
569     echo "Checking for vsnprintf() in stdio.h... No." | tee -a configure.log
570     echo "  WARNING: vsnprintf() not found, falling back to vsprintf(). zlib" | tee -a configure.log
571     echo "  can build but will be open to possible buffer-overflow security" | tee -a configure.log
572     echo "  vulnerabilities." | tee -a configure.log
573
574     echo >> configure.log
575     cat >$test.c <<EOF
576 #include <stdio.h>
577 #include <stdarg.h>
578 int mytest(const char *fmt, ...)
579 {
580   int n;
581   char buf[20];
582   va_list ap;
583   va_start(ap, fmt);
584   n = vsprintf(buf, fmt, ap);
585   va_end(ap);
586   return n;
587 }
588 int main()
589 {
590   return (mytest("Hello%d\n", 1));
591 }
592 EOF
593
594     if try $CC -c $CFLAGS $test.c; then
595       echo "Checking for return value of vsprintf()... Yes." | tee -a configure.log
596     else
597       CFLAGS="$CFLAGS -DHAS_vsprintf_void"
598       SFLAGS="$SFLAGS -DHAS_vsprintf_void"
599       echo "Checking for return value of vsprintf()... No." | tee -a configure.log
600       echo "  WARNING: apparently vsprintf() does not return a value. zlib" | tee -a configure.log
601       echo "  can build but will be open to possible string-format security" | tee -a configure.log
602       echo "  vulnerabilities." | tee -a configure.log
603     fi
604   fi
605 else
606   echo "Checking whether to use vs[n]printf() or s[n]printf()... using s[n]printf()." | tee -a configure.log
607
608   echo >> configure.log
609   cat >$test.c <<EOF
610 #include <stdio.h>
611 int mytest()
612 {
613   char buf[20];
614   snprintf(buf, sizeof(buf), "%s", "foo");
615   return 0;
616 }
617 int main()
618 {
619   return (mytest());
620 }
621 EOF
622
623   if try $CC $CFLAGS -o $test $test.c; then
624     echo "Checking for snprintf() in stdio.h... Yes." | tee -a configure.log
625
626     echo >> configure.log
627     cat >$test.c <<EOF
628 #include <stdio.h>
629 int mytest()
630 {
631   char buf[20];
632   return snprintf(buf, sizeof(buf), "%s", "foo");
633 }
634 int main()
635 {
636   return (mytest());
637 }
638 EOF
639
640     if try $CC -c $CFLAGS $test.c; then
641       echo "Checking for return value of snprintf()... Yes." | tee -a configure.log
642     else
643       CFLAGS="$CFLAGS -DHAS_snprintf_void"
644       SFLAGS="$SFLAGS -DHAS_snprintf_void"
645       echo "Checking for return value of snprintf()... No." | tee -a configure.log
646       echo "  WARNING: apparently snprintf() does not return a value. zlib" | tee -a configure.log
647       echo "  can build but will be open to possible string-format security" | tee -a configure.log
648       echo "  vulnerabilities." | tee -a configure.log
649     fi
650   else
651     CFLAGS="$CFLAGS -DNO_snprintf"
652     SFLAGS="$SFLAGS -DNO_snprintf"
653     echo "Checking for snprintf() in stdio.h... No." | tee -a configure.log
654     echo "  WARNING: snprintf() not found, falling back to sprintf(). zlib" | tee -a configure.log
655     echo "  can build but will be open to possible buffer-overflow security" | tee -a configure.log
656     echo "  vulnerabilities." | tee -a configure.log
657
658     echo >> configure.log
659     cat >$test.c <<EOF
660 #include <stdio.h>
661 int mytest()
662 {
663   char buf[20];
664   return sprintf(buf, "%s", "foo");
665 }
666 int main()
667 {
668   return (mytest());
669 }
670 EOF
671
672     if try $CC -c $CFLAGS $test.c; then
673       echo "Checking for return value of sprintf()... Yes." | tee -a configure.log
674     else
675       CFLAGS="$CFLAGS -DHAS_sprintf_void"
676       SFLAGS="$SFLAGS -DHAS_sprintf_void"
677       echo "Checking for return value of sprintf()... No." | tee -a configure.log
678       echo "  WARNING: apparently sprintf() does not return a value. zlib" | tee -a configure.log
679       echo "  can build but will be open to possible string-format security" | tee -a configure.log
680       echo "  vulnerabilities." | tee -a configure.log
681     fi
682   fi
683 fi
684
685 # see if we can hide zlib internal symbols that are linked between separate source files
686 if test "$gcc" -eq 1; then
687   echo >> configure.log
688   cat > $test.c <<EOF
689 #define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
690 int ZLIB_INTERNAL foo;
691 int main()
692 {
693   return 0;
694 }
695 EOF
696   if tryboth $CC -c $CFLAGS $test.c; then
697     CFLAGS="$CFLAGS -DHAVE_HIDDEN"
698     SFLAGS="$SFLAGS -DHAVE_HIDDEN"
699     echo "Checking for attribute(visibility) support... Yes." | tee -a configure.log
700   else
701     echo "Checking for attribute(visibility) support... No." | tee -a configure.log
702   fi
703 fi
704
705 echo >> configure.log
706
707 # find a four-byte unsiged integer type for crc calculations
708 cat > $test.c <<EOF
709 #include <stdio.h>
710 #define is32(n,t) for(n=1,k=0;n;n<<=1,k++);if(k==32){puts(t);return 0;}
711 int main() {
712     int k;
713     unsigned i;
714     unsigned long l;
715     unsigned short s;
716     is32(i, "unsigned")
717     is32(l, "unsigned long")
718     is32(s, "unsigned short")
719     return 1;
720 }
721 EOF
722 Z_U4=""
723 if try $CC $CFLAGS $test.c -o $test && Z_U4=`./$test` && test -n "$Z_U4"; then
724   sed < zconf.h "/#define Z_U4/s/\/\* \.\/configure may/#define Z_U4 $Z_U4   \/* .\/configure put the/" > zconf.temp.h
725   mv zconf.temp.h zconf.h
726   echo "Looking for a four-byte integer type... Found." | tee -a configure.log
727 else
728   echo "Looking for a four-byte integer type... Not found." | tee -a configure.log
729 fi
730
731 # clean up files produced by running the compiler and linker
732 rm -f $test.[co] $test $test$shared_ext $test.gcno
733
734 # show the results in the log
735 echo >> configure.log
736 echo ALL = $ALL >> configure.log
737 echo AR = $AR >> configure.log
738 echo ARFLAGS = $ARFLAGS >> configure.log
739 echo CC = $CC >> configure.log
740 echo CFLAGS = $CFLAGS >> configure.log
741 echo CPP = $CPP >> configure.log
742 echo EXE = $EXE >> configure.log
743 echo LDCONFIG = $LDCONFIG >> configure.log
744 echo LDFLAGS = $LDFLAGS >> configure.log
745 echo LDSHARED = $LDSHARED >> configure.log
746 echo LDSHAREDLIBC = $LDSHAREDLIBC >> configure.log
747 echo OBJC = $OBJC >> configure.log
748 echo PIC_OBJC = $PIC_OBJC >> configure.log
749 echo RANLIB = $RANLIB >> configure.log
750 echo SFLAGS = $SFLAGS >> configure.log
751 echo SHAREDLIB = $SHAREDLIB >> configure.log
752 echo SHAREDLIBM = $SHAREDLIBM >> configure.log
753 echo SHAREDLIBV = $SHAREDLIBV >> configure.log
754 echo STATICLIB = $STATICLIB >> configure.log
755 echo TEST = $TEST >> configure.log
756 echo VER = $VER >> configure.log
757 echo Z_U4 = $Z_U4 >> configure.log
758 echo exec_prefix = $exec_prefix >> configure.log
759 echo includedir = $includedir >> configure.log
760 echo libdir = $libdir >> configure.log
761 echo mandir = $mandir >> configure.log
762 echo prefix = $prefix >> configure.log
763 echo sharedlibdir = $sharedlibdir >> configure.log
764 echo uname = $uname >> configure.log
765 echo -------------------- >> configure.log
766 echo >> configure.log
767 echo >> configure.log
768
769 # udpate Makefile with the configure results
770 sed < Makefile.in "
771 /^CC *=/s#=.*#=$CC#
772 /^CFLAGS *=/s#=.*#=$CFLAGS#
773 /^SFLAGS *=/s#=.*#=$SFLAGS#
774 /^LDFLAGS *=/s#=.*#=$LDFLAGS#
775 /^LDSHARED *=/s#=.*#=$LDSHARED#
776 /^CPP *=/s#=.*#=$CPP#
777 /^STATICLIB *=/s#=.*#=$STATICLIB#
778 /^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
779 /^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
780 /^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
781 /^AR *=/s#=.*#=$AR#
782 /^ARFLAGS *=/s#=.*#=$ARFLAGS#
783 /^RANLIB *=/s#=.*#=$RANLIB#
784 /^LDCONFIG *=/s#=.*#=$LDCONFIG#
785 /^LDSHAREDLIBC *=/s#=.*#=$LDSHAREDLIBC#
786 /^EXE *=/s#=.*#=$EXE#
787 /^prefix *=/s#=.*#=$prefix#
788 /^exec_prefix *=/s#=.*#=$exec_prefix#
789 /^libdir *=/s#=.*#=$libdir#
790 /^sharedlibdir *=/s#=.*#=$sharedlibdir#
791 /^includedir *=/s#=.*#=$includedir#
792 /^mandir *=/s#=.*#=$mandir#
793 /^OBJC *=/s#=.*#= $OBJC#
794 /^PIC_OBJC *=/s#=.*#= $PIC_OBJC#
795 /^all: */s#:.*#: $ALL#
796 /^test: */s#:.*#: $TEST#
797 " > Makefile
798
799 # create zlib.pc with the configure results
800 sed < zlib.pc.in "
801 /^CC *=/s#=.*#=$CC#
802 /^CFLAGS *=/s#=.*#=$CFLAGS#
803 /^CPP *=/s#=.*#=$CPP#
804 /^LDSHARED *=/s#=.*#=$LDSHARED#
805 /^STATICLIB *=/s#=.*#=$STATICLIB#
806 /^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
807 /^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
808 /^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
809 /^AR *=/s#=.*#=$AR#
810 /^ARFLAGS *=/s#=.*#=$ARFLAGS#
811 /^RANLIB *=/s#=.*#=$RANLIB#
812 /^EXE *=/s#=.*#=$EXE#
813 /^prefix *=/s#=.*#=$prefix#
814 /^exec_prefix *=/s#=.*#=$exec_prefix#
815 /^libdir *=/s#=.*#=$libdir#
816 /^sharedlibdir *=/s#=.*#=$sharedlibdir#
817 /^includedir *=/s#=.*#=$includedir#
818 /^mandir *=/s#=.*#=$mandir#
819 /^LDFLAGS *=/s#=.*#=$LDFLAGS#
820 " | sed -e "
821 s/\@VERSION\@/$VER/g;
822 " > zlib.pc