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