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