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