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