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