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