blob: e974d1fd799fbca5025393bcdfdcb8478067528d [file] [log] [blame]
Martin v. Löwisd372aa82006-01-03 06:44:59 +00001#!/bin/sh
Martin v. Löwisce126ed2010-07-30 20:03:17 +00002# configure script for zlib.
Martin v. Löwisd372aa82006-01-03 06:44:59 +00003#
Martin v. Löwisce126ed2010-07-30 20:03:17 +00004# Normally configure builds both a static and a shared library.
5# If you want to build just a static library, use: ./configure --static
Martin v. Löwisd372aa82006-01-03 06:44:59 +00006#
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)
Martin v. Löwisd372aa82006-01-03 06:44:59 +000011
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
Christian Heimesc20bcde2013-10-21 12:03:09 +020016# start off configure.log
17echo -------------------- >> configure.log
18echo $0 $* >> configure.log
19date >> configure.log
20
doko@ubuntu.com34e7e2e2017-01-31 13:49:48 +010021# get source directory
22SRCDIR=`dirname $0`
23if test $SRCDIR = "."; then
24 ZINC=""
25 ZINCOUT="-I."
26 SRCDIR=""
27else
28 ZINC='-include zconf.h'
29 ZINCOUT='-I. -I$(SRCDIR)'
30 SRCDIR="$SRCDIR/"
31fi
32
Christian Heimesc20bcde2013-10-21 12:03:09 +020033# set command prefix for cross-compilation
Martin v. Löwisce126ed2010-07-30 20:03:17 +000034if [ -n "${CHOST}" ]; then
Christian Heimesc20bcde2013-10-21 12:03:09 +020035 uname="`echo "${CHOST}" | sed -e 's/^[^-]*-\([^-]*\)$/\1/' -e 's/^[^-]*-[^-]*-\([^-]*\)$/\1/' -e 's/^[^-]*-[^-]*-\([^-]*\)-.*$/\1/'`"
Martin v. Löwisce126ed2010-07-30 20:03:17 +000036 CROSS_PREFIX="${CHOST}-"
37fi
38
Christian Heimesc20bcde2013-10-21 12:03:09 +020039# destination name for static library
Martin v. Löwisce126ed2010-07-30 20:03:17 +000040STATICLIB=libz.a
Christian Heimesc20bcde2013-10-21 12:03:09 +020041
42# extract zlib version numbers from zlib.h
doko@ubuntu.com34e7e2e2017-01-31 13:49:48 +010043VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < ${SRCDIR}zlib.h`
44VER3=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\\.[0-9]*\).*/\1/p' < ${SRCDIR}zlib.h`
45VER2=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\)\\..*/\1/p' < ${SRCDIR}zlib.h`
46VER1=`sed -n -e '/VERSION "/s/.*"\([0-9]*\)\\..*/\1/p' < ${SRCDIR}zlib.h`
Christian Heimesc20bcde2013-10-21 12:03:09 +020047
48# establish commands for library building
Martin v. Löwisce126ed2010-07-30 20:03:17 +000049if "${CROSS_PREFIX}ar" --version >/dev/null 2>/dev/null || test $? -lt 126; then
50 AR=${AR-"${CROSS_PREFIX}ar"}
Christian Heimesc20bcde2013-10-21 12:03:09 +020051 test -n "${CROSS_PREFIX}" && echo Using ${AR} | tee -a configure.log
Martin v. Löwisce126ed2010-07-30 20:03:17 +000052else
53 AR=${AR-"ar"}
Christian Heimesc20bcde2013-10-21 12:03:09 +020054 test -n "${CROSS_PREFIX}" && echo Using ${AR} | tee -a configure.log
Martin v. Löwisce126ed2010-07-30 20:03:17 +000055fi
Christian Heimesc20bcde2013-10-21 12:03:09 +020056ARFLAGS=${ARFLAGS-"rc"}
Martin v. Löwisce126ed2010-07-30 20:03:17 +000057if "${CROSS_PREFIX}ranlib" --version >/dev/null 2>/dev/null || test $? -lt 126; then
58 RANLIB=${RANLIB-"${CROSS_PREFIX}ranlib"}
Christian Heimesc20bcde2013-10-21 12:03:09 +020059 test -n "${CROSS_PREFIX}" && echo Using ${RANLIB} | tee -a configure.log
Martin v. Löwisce126ed2010-07-30 20:03:17 +000060else
61 RANLIB=${RANLIB-"ranlib"}
62fi
63if "${CROSS_PREFIX}nm" --version >/dev/null 2>/dev/null || test $? -lt 126; then
64 NM=${NM-"${CROSS_PREFIX}nm"}
Christian Heimesc20bcde2013-10-21 12:03:09 +020065 test -n "${CROSS_PREFIX}" && echo Using ${NM} | tee -a configure.log
Martin v. Löwisce126ed2010-07-30 20:03:17 +000066else
67 NM=${NM-"nm"}
68fi
Christian Heimesc20bcde2013-10-21 12:03:09 +020069
70# set defaults before processing command line options
Martin v. Löwisce126ed2010-07-30 20:03:17 +000071LDCONFIG=${LDCONFIG-"ldconfig"}
72LDSHAREDLIBC="${LDSHAREDLIBC--lc}"
Christian Heimesc20bcde2013-10-21 12:03:09 +020073ARCHS=
Martin v. Löwisd372aa82006-01-03 06:44:59 +000074prefix=${prefix-/usr/local}
75exec_prefix=${exec_prefix-'${prefix}'}
76libdir=${libdir-'${exec_prefix}/lib'}
Martin v. Löwisce126ed2010-07-30 20:03:17 +000077sharedlibdir=${sharedlibdir-'${libdir}'}
Martin v. Löwisd372aa82006-01-03 06:44:59 +000078includedir=${includedir-'${prefix}/include'}
79mandir=${mandir-'${prefix}/share/man'}
80shared_ext='.so'
Martin v. Löwisce126ed2010-07-30 20:03:17 +000081shared=1
Christian Heimesc20bcde2013-10-21 12:03:09 +020082solo=0
83cover=0
Martin v. Löwisce126ed2010-07-30 20:03:17 +000084zprefix=0
Christian Heimesc20bcde2013-10-21 12:03:09 +020085zconst=0
Martin v. Löwisce126ed2010-07-30 20:03:17 +000086build64=0
Martin v. Löwisd372aa82006-01-03 06:44:59 +000087gcc=0
doko@ubuntu.com34e7e2e2017-01-31 13:49:48 +010088warn=0
89debug=0
Martin v. Löwisd372aa82006-01-03 06:44:59 +000090old_cc="$CC"
91old_cflags="$CFLAGS"
Christian Heimesc20bcde2013-10-21 12:03:09 +020092OBJC='$(OBJZ) $(OBJG)'
93PIC_OBJC='$(PIC_OBJZ) $(PIC_OBJG)'
Martin v. Löwisd372aa82006-01-03 06:44:59 +000094
Christian Heimesc20bcde2013-10-21 12:03:09 +020095# leave this script, optionally in a bad way
96leave()
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
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000109while test $# -ge 1
110do
111case "$1" in
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000112 -h* | --help)
Christian Heimesc20bcde2013-10-21 12:03:09 +0200113 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
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000117 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 ;;
Christian Heimesc20bcde2013-10-21 12:03:09 +0200130 --solo) solo=1; shift ;;
131 --cover) cover=1; shift ;;
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000132 -z* | --zprefix) zprefix=1; shift ;;
133 -6* | --64) build64=1; shift ;;
Christian Heimesc20bcde2013-10-21 12:03:09 +0200134 -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 ;;
doko@ubuntu.com34e7e2e2017-01-31 13:49:48 +0100138 -w* | --warn) warn=1; shift ;;
139 -d* | --debug) debug=1; shift ;;
Christian Heimesc20bcde2013-10-21 12:03:09 +0200140 *)
141 echo "unknown option: $1" | tee -a configure.log
142 echo "$0 --help for help" | tee -a configure.log
143 leave 1;;
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000144 esac
145done
146
Christian Heimesc20bcde2013-10-21 12:03:09 +0200147# temporary file name
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000148test=ztest$$
Christian Heimesc20bcde2013-10-21 12:03:09 +0200149
150# put arguments in log, also put test file in log if used in arguments
151show()
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
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000163cat > $test.c <<EOF
164extern int getchar();
165int hello() {return getchar();}
166EOF
167
Christian Heimesc20bcde2013-10-21 12:03:09 +0200168test -z "$CC" && echo Checking for ${CROSS_PREFIX}gcc... | tee -a configure.log
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000169cc=${CC-${CROSS_PREFIX}gcc}
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000170cflags=${CFLAGS-"-O3"}
171# to force the asm version use: CFLAGS="-O3 -DASMV" ./configure
172case "$cc" in
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000173 *gcc*) gcc=1 ;;
Christian Heimesc20bcde2013-10-21 12:03:09 +0200174 *clang*) gcc=1 ;;
175esac
176case `$cc -v 2>&1` in
177 *gcc*) gcc=1 ;;
doko@ubuntu.com34e7e2e2017-01-31 13:49:48 +0100178 *clang*) gcc=1 ;;
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000179esac
180
Christian Heimesc20bcde2013-10-21 12:03:09 +0200181show $cc -c $test.c
182if test "$gcc" -eq 1 && ($cc -c $test.c) >> configure.log 2>&1; then
183 echo ... using gcc >> configure.log
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000184 CC="$cc"
doko@ubuntu.com34e7e2e2017-01-31 13:49:48 +0100185 CFLAGS="${CFLAGS--O3}"
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000186 SFLAGS="${CFLAGS--O3} -fPIC"
doko@ubuntu.com34e7e2e2017-01-31 13:49:48 +0100187 if test "$ARCHS"; then
188 CFLAGS="${CFLAGS} ${ARCHS}"
189 LDFLAGS="${LDFLAGS} ${ARCHS}"
190 fi
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000191 if test $build64 -eq 1; then
192 CFLAGS="${CFLAGS} -m64"
193 SFLAGS="${SFLAGS} -m64"
194 fi
doko@ubuntu.com34e7e2e2017-01-31 13:49:48 +0100195 if test "$warn" -eq 1; then
Christian Heimesc20bcde2013-10-21 12:03:09 +0200196 if test "$zconst" -eq 1; then
197 CFLAGS="${CFLAGS} -Wall -Wextra -Wcast-qual -pedantic -DZLIB_CONST"
198 else
199 CFLAGS="${CFLAGS} -Wall -Wextra -pedantic"
200 fi
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000201 fi
doko@ubuntu.com34e7e2e2017-01-31 13:49:48 +0100202 if test $debug -eq 1; then
203 CFLAGS="${CFLAGS} -DZLIB_DEBUG"
204 SFLAGS="${SFLAGS} -DZLIB_DEBUG"
205 fi
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000206 if test -z "$uname"; then
207 uname=`(uname -s || echo unknown) 2>/dev/null`
208 fi
209 case "$uname" in
Christian Heimesc20bcde2013-10-21 12:03:09 +0200210 Linux* | linux* | GNU | GNU/* | solaris*)
doko@ubuntu.com34e7e2e2017-01-31 13:49:48 +0100211 LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,${SRCDIR}zlib.map"} ;;
Christian Heimesc20bcde2013-10-21 12:03:09 +0200212 *BSD | *bsd* | DragonFly)
doko@ubuntu.com34e7e2e2017-01-31 13:49:48 +0100213 LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,${SRCDIR}zlib.map"}
Christian Heimesc20bcde2013-10-21 12:03:09 +0200214 LDCONFIG="ldconfig -m" ;;
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000215 CYGWIN* | Cygwin* | cygwin* | OS/2*)
216 EXE='.exe' ;;
Christian Heimesc20bcde2013-10-21 12:03:09 +0200217 MINGW* | mingw*)
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000218# temporary bypass
219 rm -f $test.[co] $test $test$shared_ext
Christian Heimesc20bcde2013-10-21 12:03:09 +0200220 echo "Please use win32/Makefile.gcc instead." | tee -a configure.log
221 leave 1
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000222 LDSHARED=${LDSHARED-"$cc -shared"}
223 LDSHAREDLIBC=""
224 EXE='.exe' ;;
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000225 QNX*) # This is for QNX6. I suppose that the QNX rule below is for QNX2,QNX4
226 # (alain.bonnefoy@icbt.com)
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000227 LDSHARED=${LDSHARED-"$cc -shared -Wl,-hlibz.so.1"} ;;
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000228 HP-UX*)
229 LDSHARED=${LDSHARED-"$cc -shared $SFLAGS"}
230 case `(uname -m || echo unknown) 2>/dev/null` in
231 ia64)
232 shared_ext='.so'
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000233 SHAREDLIB='libz.so' ;;
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000234 *)
235 shared_ext='.sl'
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000236 SHAREDLIB='libz.sl' ;;
237 esac ;;
Christian Heimesc20bcde2013-10-21 12:03:09 +0200238 Darwin* | darwin*)
239 shared_ext='.dylib'
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000240 SHAREDLIB=libz$shared_ext
241 SHAREDLIBV=libz.$VER$shared_ext
242 SHAREDLIBM=libz.$VER1$shared_ext
Christian Heimesc20bcde2013-10-21 12:03:09 +0200243 LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBM -compatibility_version $VER1 -current_version $VER3"}
244 if libtool -V 2>&1 | grep Apple > /dev/null; then
245 AR="libtool"
246 else
247 AR="/usr/bin/libtool"
248 fi
249 ARFLAGS="-o" ;;
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000250 *) LDSHARED=${LDSHARED-"$cc -shared"} ;;
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000251 esac
252else
253 # find system name and corresponding cc options
254 CC=${CC-cc}
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000255 gcc=0
Christian Heimesc20bcde2013-10-21 12:03:09 +0200256 echo ... using $CC >> configure.log
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000257 if test -z "$uname"; then
258 uname=`(uname -sr || echo unknown) 2>/dev/null`
259 fi
260 case "$uname" in
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000261 HP-UX*) SFLAGS=${CFLAGS-"-O +z"}
262 CFLAGS=${CFLAGS-"-O"}
263# LDSHARED=${LDSHARED-"ld -b +vnocompatwarnings"}
264 LDSHARED=${LDSHARED-"ld -b"}
265 case `(uname -m || echo unknown) 2>/dev/null` in
266 ia64)
267 shared_ext='.so'
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000268 SHAREDLIB='libz.so' ;;
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000269 *)
270 shared_ext='.sl'
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000271 SHAREDLIB='libz.sl' ;;
272 esac ;;
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000273 IRIX*) SFLAGS=${CFLAGS-"-ansi -O2 -rpath ."}
274 CFLAGS=${CFLAGS-"-ansi -O2"}
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000275 LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;;
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000276 OSF1\ V4*) SFLAGS=${CFLAGS-"-O -std1"}
277 CFLAGS=${CFLAGS-"-O -std1"}
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000278 LDFLAGS="${LDFLAGS} -Wl,-rpath,."
279 LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so -Wl,-msym -Wl,-rpath,$(libdir) -Wl,-set_version,${VER}:1.0"} ;;
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000280 OSF1*) SFLAGS=${CFLAGS-"-O -std1"}
281 CFLAGS=${CFLAGS-"-O -std1"}
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000282 LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;;
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000283 QNX*) SFLAGS=${CFLAGS-"-4 -O"}
284 CFLAGS=${CFLAGS-"-4 -O"}
285 LDSHARED=${LDSHARED-"cc"}
286 RANLIB=${RANLIB-"true"}
Christian Heimesc20bcde2013-10-21 12:03:09 +0200287 AR="cc"
288 ARFLAGS="-A" ;;
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000289 SCO_SV\ 3.2*) SFLAGS=${CFLAGS-"-O3 -dy -KPIC "}
290 CFLAGS=${CFLAGS-"-O3"}
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000291 LDSHARED=${LDSHARED-"cc -dy -KPIC -G"} ;;
Christian Heimesc20bcde2013-10-21 12:03:09 +0200292 SunOS\ 5* | solaris*)
293 LDSHARED=${LDSHARED-"cc -G -h libz$shared_ext.$VER1"}
294 SFLAGS=${CFLAGS-"-fast -KPIC"}
295 CFLAGS=${CFLAGS-"-fast"}
296 if test $build64 -eq 1; then
297 # old versions of SunPRO/Workshop/Studio don't support -m64,
298 # but newer ones do. Check for it.
299 flag64=`$CC -flags | egrep -- '^-m64'`
300 if test x"$flag64" != x"" ; then
301 CFLAGS="${CFLAGS} -m64"
302 SFLAGS="${SFLAGS} -m64"
303 else
304 case `(uname -m || echo unknown) 2>/dev/null` in
305 i86*)
306 SFLAGS="$SFLAGS -xarch=amd64"
307 CFLAGS="$CFLAGS -xarch=amd64" ;;
308 *)
309 SFLAGS="$SFLAGS -xarch=v9"
310 CFLAGS="$CFLAGS -xarch=v9" ;;
311 esac
312 fi
313 fi
doko@ubuntu.com34e7e2e2017-01-31 13:49:48 +0100314 if test -n "$ZINC"; then
315 ZINC='-I- -I. -I$(SRCDIR)'
316 fi
Christian Heimesc20bcde2013-10-21 12:03:09 +0200317 ;;
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000318 SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"}
319 CFLAGS=${CFLAGS-"-O2"}
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000320 LDSHARED=${LDSHARED-"ld"} ;;
321 SunStudio\ 9*) SFLAGS=${CFLAGS-"-fast -xcode=pic32 -xtarget=ultra3 -xarch=v9b"}
322 CFLAGS=${CFLAGS-"-fast -xtarget=ultra3 -xarch=v9b"}
323 LDSHARED=${LDSHARED-"cc -xarch=v9b"} ;;
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000324 UNIX_System_V\ 4.2.0)
325 SFLAGS=${CFLAGS-"-KPIC -O"}
326 CFLAGS=${CFLAGS-"-O"}
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000327 LDSHARED=${LDSHARED-"cc -G"} ;;
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000328 UNIX_SV\ 4.2MP)
329 SFLAGS=${CFLAGS-"-Kconform_pic -O"}
330 CFLAGS=${CFLAGS-"-O"}
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000331 LDSHARED=${LDSHARED-"cc -G"} ;;
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000332 OpenUNIX\ 5)
333 SFLAGS=${CFLAGS-"-KPIC -O"}
334 CFLAGS=${CFLAGS-"-O"}
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000335 LDSHARED=${LDSHARED-"cc -G"} ;;
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000336 AIX*) # Courtesy of dbakker@arrayasolutions.com
337 SFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
338 CFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000339 LDSHARED=${LDSHARED-"xlc -G"} ;;
340 # send working options for other systems to zlib@gzip.org
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000341 *) SFLAGS=${CFLAGS-"-O"}
342 CFLAGS=${CFLAGS-"-O"}
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000343 LDSHARED=${LDSHARED-"cc -shared"} ;;
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000344 esac
345fi
346
Christian Heimesc20bcde2013-10-21 12:03:09 +0200347# destination names for shared library if not defined above
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000348SHAREDLIB=${SHAREDLIB-"libz$shared_ext"}
349SHAREDLIBV=${SHAREDLIBV-"libz$shared_ext.$VER"}
350SHAREDLIBM=${SHAREDLIBM-"libz$shared_ext.$VER1"}
351
Christian Heimesc20bcde2013-10-21 12:03:09 +0200352echo >> configure.log
353
354# define functions for testing compiler and library characteristics and logging the results
355
356cat > $test.c <<EOF
357#error error
358EOF
359if ($CC -c $CFLAGS $test.c) 2>/dev/null; then
360 try()
361 {
362 show $*
363 test "`( $* ) 2>&1 | tee -a configure.log`" = ""
364 }
365 echo - using any output from compiler to indicate an error >> configure.log
366else
doko@ubuntu.com34e7e2e2017-01-31 13:49:48 +0100367 try()
368 {
369 show $*
370 ( $* ) >> configure.log 2>&1
371 ret=$?
372 if test $ret -ne 0; then
373 echo "(exit code "$ret")" >> configure.log
374 fi
375 return $ret
376 }
Christian Heimesc20bcde2013-10-21 12:03:09 +0200377fi
378
379tryboth()
380{
381 show $*
382 got=`( $* ) 2>&1`
383 ret=$?
384 printf %s "$got" >> configure.log
385 if test $ret -ne 0; then
386 return $ret
387 fi
388 test "$got" = ""
389}
390
391cat > $test.c << EOF
392int foo() { return 0; }
393EOF
394echo "Checking for obsessive-compulsive compiler options..." >> configure.log
395if try $CC -c $CFLAGS $test.c; then
396 :
397else
398 echo "Compiler error reporting is too harsh for $0 (perhaps remove -Werror)." | tee -a configure.log
399 leave 1
400fi
401
402echo >> configure.log
403
404# see if shared library build supported
405cat > $test.c <<EOF
406extern int getchar();
407int hello() {return getchar();}
408EOF
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000409if test $shared -eq 1; then
Christian Heimesc20bcde2013-10-21 12:03:09 +0200410 echo Checking for shared library support... | tee -a configure.log
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000411 # we must test in two steps (cc then ld), required at least on SunOS 4.x
Christian Heimesc20bcde2013-10-21 12:03:09 +0200412 if try $CC -w -c $SFLAGS $test.c &&
413 try $LDSHARED $SFLAGS -o $test$shared_ext $test.o; then
414 echo Building shared library $SHAREDLIBV with $CC. | tee -a configure.log
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000415 elif test -z "$old_cc" -a -z "$old_cflags"; then
Christian Heimesc20bcde2013-10-21 12:03:09 +0200416 echo No shared library support. | tee -a configure.log
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000417 shared=0;
418 else
Christian Heimesc20bcde2013-10-21 12:03:09 +0200419 echo 'No shared library support; try without defining CC and CFLAGS' | tee -a configure.log
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000420 shared=0;
421 fi
422fi
423if test $shared -eq 0; then
424 LDSHARED="$CC"
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000425 ALL="static"
426 TEST="all teststatic"
427 SHAREDLIB=""
428 SHAREDLIBV=""
429 SHAREDLIBM=""
Christian Heimesc20bcde2013-10-21 12:03:09 +0200430 echo Building static library $STATICLIB version $VER with $CC. | tee -a configure.log
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000431else
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000432 ALL="static shared"
433 TEST="all teststatic testshared"
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000434fi
435
Christian Heimesc20bcde2013-10-21 12:03:09 +0200436# check for underscores in external names for use by assembler code
437CPP=${CPP-"$CC -E"}
438case $CFLAGS in
439 *ASMV*)
440 echo >> configure.log
441 show "$NM $test.o | grep _hello"
442 if test "`$NM $test.o | grep _hello | tee -a configure.log`" = ""; then
443 CPP="$CPP -DNO_UNDERLINE"
444 echo Checking for underline in external names... No. | tee -a configure.log
445 else
446 echo Checking for underline in external names... Yes. | tee -a configure.log
447 fi ;;
448esac
449
450echo >> configure.log
451
doko@ubuntu.com34e7e2e2017-01-31 13:49:48 +0100452# check for size_t
453cat > $test.c <<EOF
454#include <stdio.h>
455#include <stdlib.h>
456size_t dummy = 0;
457EOF
458if try $CC -c $CFLAGS $test.c; then
459 echo "Checking for size_t... Yes." | tee -a configure.log
460 need_sizet=0
461else
462 echo "Checking for size_t... No." | tee -a configure.log
463 need_sizet=1
464fi
465
466echo >> configure.log
467
468# find the size_t integer type, if needed
469if test $need_sizet -eq 1; then
470 cat > $test.c <<EOF
471long long dummy = 0;
472EOF
473 if try $CC -c $CFLAGS $test.c; then
474 echo "Checking for long long... Yes." | tee -a configure.log
475 cat > $test.c <<EOF
476#include <stdio.h>
477int main(void) {
478 if (sizeof(void *) <= sizeof(int)) puts("int");
479 else if (sizeof(void *) <= sizeof(long)) puts("long");
480 else puts("z_longlong");
481 return 0;
482}
483EOF
484 else
485 echo "Checking for long long... No." | tee -a configure.log
486 cat > $test.c <<EOF
487#include <stdio.h>
488int main(void) {
489 if (sizeof(void *) <= sizeof(int)) puts("int");
490 else puts("long");
491 return 0;
492}
493EOF
494 fi
495 if try $CC $CFLAGS -o $test $test.c; then
496 sizet=`./$test`
497 echo "Checking for a pointer-size integer type..." $sizet"." | tee -a configure.log
498 else
499 echo "Failed to find a pointer-size integer type." | tee -a configure.log
500 leave 1
501 fi
502fi
503
504if test $need_sizet -eq 1; then
505 CFLAGS="${CFLAGS} -DNO_SIZE_T=${sizet}"
506 SFLAGS="${SFLAGS} -DNO_SIZE_T=${sizet}"
507fi
508
509echo >> configure.log
510
Christian Heimesc20bcde2013-10-21 12:03:09 +0200511# check for large file support, and if none, check for fseeko()
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000512cat > $test.c <<EOF
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000513#include <sys/types.h>
514off64_t dummy = 0;
515EOF
Christian Heimesc20bcde2013-10-21 12:03:09 +0200516if try $CC -c $CFLAGS -D_LARGEFILE64_SOURCE=1 $test.c; then
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000517 CFLAGS="${CFLAGS} -D_LARGEFILE64_SOURCE=1"
518 SFLAGS="${SFLAGS} -D_LARGEFILE64_SOURCE=1"
519 ALL="${ALL} all64"
520 TEST="${TEST} test64"
Christian Heimesc20bcde2013-10-21 12:03:09 +0200521 echo "Checking for off64_t... Yes." | tee -a configure.log
522 echo "Checking for fseeko... Yes." | tee -a configure.log
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000523else
Christian Heimesc20bcde2013-10-21 12:03:09 +0200524 echo "Checking for off64_t... No." | tee -a configure.log
525 echo >> configure.log
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000526 cat > $test.c <<EOF
527#include <stdio.h>
528int main(void) {
529 fseeko(NULL, 0, 0);
530 return 0;
531}
532EOF
Christian Heimesc20bcde2013-10-21 12:03:09 +0200533 if try $CC $CFLAGS -o $test $test.c; then
534 echo "Checking for fseeko... Yes." | tee -a configure.log
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000535 else
536 CFLAGS="${CFLAGS} -DNO_FSEEKO"
537 SFLAGS="${SFLAGS} -DNO_FSEEKO"
Christian Heimesc20bcde2013-10-21 12:03:09 +0200538 echo "Checking for fseeko... No." | tee -a configure.log
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000539 fi
540fi
541
Christian Heimesc20bcde2013-10-21 12:03:09 +0200542echo >> configure.log
543
544# check for strerror() for use by gz* functions
545cat > $test.c <<EOF
546#include <string.h>
547#include <errno.h>
548int main() { return strlen(strerror(errno)); }
549EOF
550if try $CC $CFLAGS -o $test $test.c; then
551 echo "Checking for strerror... Yes." | tee -a configure.log
552else
553 CFLAGS="${CFLAGS} -DNO_STRERROR"
554 SFLAGS="${SFLAGS} -DNO_STRERROR"
555 echo "Checking for strerror... No." | tee -a configure.log
556fi
557
558# copy clean zconf.h for subsequent edits
doko@ubuntu.com34e7e2e2017-01-31 13:49:48 +0100559cp -p ${SRCDIR}zconf.h.in zconf.h
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000560
Christian Heimesc20bcde2013-10-21 12:03:09 +0200561echo >> configure.log
562
563# check for unistd.h and save result in zconf.h
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000564cat > $test.c <<EOF
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000565#include <unistd.h>
566int main() { return 0; }
567EOF
Christian Heimesc20bcde2013-10-21 12:03:09 +0200568if try $CC -c $CFLAGS $test.c; then
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000569 sed < zconf.h "/^#ifdef HAVE_UNISTD_H.* may be/s/def HAVE_UNISTD_H\(.*\) may be/ 1\1 was/" > zconf.temp.h
570 mv zconf.temp.h zconf.h
Christian Heimesc20bcde2013-10-21 12:03:09 +0200571 echo "Checking for unistd.h... Yes." | tee -a configure.log
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000572else
Christian Heimesc20bcde2013-10-21 12:03:09 +0200573 echo "Checking for unistd.h... No." | tee -a configure.log
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000574fi
575
Christian Heimesc20bcde2013-10-21 12:03:09 +0200576echo >> configure.log
577
578# check for stdarg.h and save result in zconf.h
579cat > $test.c <<EOF
580#include <stdarg.h>
581int main() { return 0; }
582EOF
583if try $CC -c $CFLAGS $test.c; then
584 sed < zconf.h "/^#ifdef HAVE_STDARG_H.* may be/s/def HAVE_STDARG_H\(.*\) may be/ 1\1 was/" > zconf.temp.h
585 mv zconf.temp.h zconf.h
586 echo "Checking for stdarg.h... Yes." | tee -a configure.log
587else
588 echo "Checking for stdarg.h... No." | tee -a configure.log
589fi
590
591# if the z_ prefix was requested, save that in zconf.h
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000592if test $zprefix -eq 1; then
593 sed < zconf.h "/#ifdef Z_PREFIX.* may be/s/def Z_PREFIX\(.*\) may be/ 1\1 was/" > zconf.temp.h
594 mv zconf.temp.h zconf.h
Christian Heimesc20bcde2013-10-21 12:03:09 +0200595 echo >> configure.log
596 echo "Using z_ prefix on all symbols." | tee -a configure.log
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000597fi
598
Christian Heimesc20bcde2013-10-21 12:03:09 +0200599# if --solo compilation was requested, save that in zconf.h and remove gz stuff from object lists
600if test $solo -eq 1; then
601 sed '/#define ZCONF_H/a\
602#define Z_SOLO
603
604' < zconf.h > zconf.temp.h
605 mv zconf.temp.h zconf.h
606OBJC='$(OBJZ)'
607PIC_OBJC='$(PIC_OBJZ)'
608fi
609
610# if code coverage testing was requested, use older gcc if defined, e.g. "gcc-4.2" on Mac OS X
611if test $cover -eq 1; then
612 CFLAGS="${CFLAGS} -fprofile-arcs -ftest-coverage"
613 if test -n "$GCC_CLASSIC"; then
614 CC=$GCC_CLASSIC
615 fi
616fi
617
618echo >> configure.log
619
620# conduct a series of tests to resolve eight possible cases of using "vs" or "s" printf functions
621# (using stdarg or not), with or without "n" (proving size of buffer), and with or without a
622# return value. The most secure result is vsnprintf() with a return value. snprintf() with a
623# return value is secure as well, but then gzprintf() will be limited to 20 arguments.
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000624cat > $test.c <<EOF
625#include <stdio.h>
626#include <stdarg.h>
627#include "zconf.h"
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000628int main()
629{
630#ifndef STDC
631 choke me
632#endif
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000633 return 0;
634}
635EOF
Christian Heimesc20bcde2013-10-21 12:03:09 +0200636if try $CC -c $CFLAGS $test.c; then
637 echo "Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf()." | tee -a configure.log
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000638
Christian Heimesc20bcde2013-10-21 12:03:09 +0200639 echo >> configure.log
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000640 cat > $test.c <<EOF
641#include <stdio.h>
642#include <stdarg.h>
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000643int mytest(const char *fmt, ...)
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000644{
645 char buf[20];
646 va_list ap;
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000647 va_start(ap, fmt);
648 vsnprintf(buf, sizeof(buf), fmt, ap);
649 va_end(ap);
650 return 0;
651}
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000652int main()
653{
654 return (mytest("Hello%d\n", 1));
655}
656EOF
Christian Heimesc20bcde2013-10-21 12:03:09 +0200657 if try $CC $CFLAGS -o $test $test.c; then
658 echo "Checking for vsnprintf() in stdio.h... Yes." | tee -a configure.log
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000659
Christian Heimesc20bcde2013-10-21 12:03:09 +0200660 echo >> configure.log
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000661 cat >$test.c <<EOF
662#include <stdio.h>
663#include <stdarg.h>
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000664int mytest(const char *fmt, ...)
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000665{
666 int n;
667 char buf[20];
668 va_list ap;
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000669 va_start(ap, fmt);
670 n = vsnprintf(buf, sizeof(buf), fmt, ap);
671 va_end(ap);
672 return n;
673}
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000674int main()
675{
676 return (mytest("Hello%d\n", 1));
677}
678EOF
679
Christian Heimesc20bcde2013-10-21 12:03:09 +0200680 if try $CC -c $CFLAGS $test.c; then
681 echo "Checking for return value of vsnprintf()... Yes." | tee -a configure.log
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000682 else
683 CFLAGS="$CFLAGS -DHAS_vsnprintf_void"
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000684 SFLAGS="$SFLAGS -DHAS_vsnprintf_void"
Christian Heimesc20bcde2013-10-21 12:03:09 +0200685 echo "Checking for return value of vsnprintf()... No." | tee -a configure.log
686 echo " WARNING: apparently vsnprintf() does not return a value. zlib" | tee -a configure.log
687 echo " can build but will be open to possible string-format security" | tee -a configure.log
688 echo " vulnerabilities." | tee -a configure.log
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000689 fi
690 else
691 CFLAGS="$CFLAGS -DNO_vsnprintf"
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000692 SFLAGS="$SFLAGS -DNO_vsnprintf"
Christian Heimesc20bcde2013-10-21 12:03:09 +0200693 echo "Checking for vsnprintf() in stdio.h... No." | tee -a configure.log
694 echo " WARNING: vsnprintf() not found, falling back to vsprintf(). zlib" | tee -a configure.log
695 echo " can build but will be open to possible buffer-overflow security" | tee -a configure.log
696 echo " vulnerabilities." | tee -a configure.log
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000697
Christian Heimesc20bcde2013-10-21 12:03:09 +0200698 echo >> configure.log
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000699 cat >$test.c <<EOF
700#include <stdio.h>
701#include <stdarg.h>
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000702int mytest(const char *fmt, ...)
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000703{
704 int n;
705 char buf[20];
706 va_list ap;
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000707 va_start(ap, fmt);
708 n = vsprintf(buf, fmt, ap);
709 va_end(ap);
710 return n;
711}
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000712int main()
713{
714 return (mytest("Hello%d\n", 1));
715}
716EOF
717
Christian Heimesc20bcde2013-10-21 12:03:09 +0200718 if try $CC -c $CFLAGS $test.c; then
719 echo "Checking for return value of vsprintf()... Yes." | tee -a configure.log
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000720 else
721 CFLAGS="$CFLAGS -DHAS_vsprintf_void"
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000722 SFLAGS="$SFLAGS -DHAS_vsprintf_void"
Christian Heimesc20bcde2013-10-21 12:03:09 +0200723 echo "Checking for return value of vsprintf()... No." | tee -a configure.log
724 echo " WARNING: apparently vsprintf() does not return a value. zlib" | tee -a configure.log
725 echo " can build but will be open to possible string-format security" | tee -a configure.log
726 echo " vulnerabilities." | tee -a configure.log
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000727 fi
728 fi
729else
Christian Heimesc20bcde2013-10-21 12:03:09 +0200730 echo "Checking whether to use vs[n]printf() or s[n]printf()... using s[n]printf()." | tee -a configure.log
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000731
Christian Heimesc20bcde2013-10-21 12:03:09 +0200732 echo >> configure.log
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000733 cat >$test.c <<EOF
734#include <stdio.h>
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000735int mytest()
736{
737 char buf[20];
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000738 snprintf(buf, sizeof(buf), "%s", "foo");
739 return 0;
740}
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000741int main()
742{
743 return (mytest());
744}
745EOF
746
Christian Heimesc20bcde2013-10-21 12:03:09 +0200747 if try $CC $CFLAGS -o $test $test.c; then
748 echo "Checking for snprintf() in stdio.h... Yes." | tee -a configure.log
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000749
Christian Heimesc20bcde2013-10-21 12:03:09 +0200750 echo >> configure.log
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000751 cat >$test.c <<EOF
752#include <stdio.h>
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000753int mytest()
754{
755 char buf[20];
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000756 return snprintf(buf, sizeof(buf), "%s", "foo");
757}
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000758int main()
759{
760 return (mytest());
761}
762EOF
763
Christian Heimesc20bcde2013-10-21 12:03:09 +0200764 if try $CC -c $CFLAGS $test.c; then
765 echo "Checking for return value of snprintf()... Yes." | tee -a configure.log
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000766 else
767 CFLAGS="$CFLAGS -DHAS_snprintf_void"
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000768 SFLAGS="$SFLAGS -DHAS_snprintf_void"
Christian Heimesc20bcde2013-10-21 12:03:09 +0200769 echo "Checking for return value of snprintf()... No." | tee -a configure.log
770 echo " WARNING: apparently snprintf() does not return a value. zlib" | tee -a configure.log
771 echo " can build but will be open to possible string-format security" | tee -a configure.log
772 echo " vulnerabilities." | tee -a configure.log
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000773 fi
774 else
775 CFLAGS="$CFLAGS -DNO_snprintf"
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000776 SFLAGS="$SFLAGS -DNO_snprintf"
Christian Heimesc20bcde2013-10-21 12:03:09 +0200777 echo "Checking for snprintf() in stdio.h... No." | tee -a configure.log
778 echo " WARNING: snprintf() not found, falling back to sprintf(). zlib" | tee -a configure.log
779 echo " can build but will be open to possible buffer-overflow security" | tee -a configure.log
780 echo " vulnerabilities." | tee -a configure.log
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000781
Christian Heimesc20bcde2013-10-21 12:03:09 +0200782 echo >> configure.log
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000783 cat >$test.c <<EOF
784#include <stdio.h>
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000785int mytest()
786{
787 char buf[20];
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000788 return sprintf(buf, "%s", "foo");
789}
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000790int main()
791{
792 return (mytest());
793}
794EOF
795
Christian Heimesc20bcde2013-10-21 12:03:09 +0200796 if try $CC -c $CFLAGS $test.c; then
797 echo "Checking for return value of sprintf()... Yes." | tee -a configure.log
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000798 else
799 CFLAGS="$CFLAGS -DHAS_sprintf_void"
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000800 SFLAGS="$SFLAGS -DHAS_sprintf_void"
Christian Heimesc20bcde2013-10-21 12:03:09 +0200801 echo "Checking for return value of sprintf()... No." | tee -a configure.log
802 echo " WARNING: apparently sprintf() does not return a value. zlib" | tee -a configure.log
803 echo " can build but will be open to possible string-format security" | tee -a configure.log
804 echo " vulnerabilities." | tee -a configure.log
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000805 fi
806 fi
807fi
808
Christian Heimesc20bcde2013-10-21 12:03:09 +0200809# see if we can hide zlib internal symbols that are linked between separate source files
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000810if test "$gcc" -eq 1; then
Christian Heimesc20bcde2013-10-21 12:03:09 +0200811 echo >> configure.log
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000812 cat > $test.c <<EOF
Christian Heimesc20bcde2013-10-21 12:03:09 +0200813#define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000814int ZLIB_INTERNAL foo;
815int main()
816{
817 return 0;
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000818}
819EOF
Christian Heimesc20bcde2013-10-21 12:03:09 +0200820 if tryboth $CC -c $CFLAGS $test.c; then
821 CFLAGS="$CFLAGS -DHAVE_HIDDEN"
822 SFLAGS="$SFLAGS -DHAVE_HIDDEN"
823 echo "Checking for attribute(visibility) support... Yes." | tee -a configure.log
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000824 else
Christian Heimesc20bcde2013-10-21 12:03:09 +0200825 echo "Checking for attribute(visibility) support... No." | tee -a configure.log
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000826 fi
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000827fi
828
Christian Heimesc20bcde2013-10-21 12:03:09 +0200829# show the results in the log
830echo >> configure.log
831echo ALL = $ALL >> configure.log
832echo AR = $AR >> configure.log
833echo ARFLAGS = $ARFLAGS >> configure.log
834echo CC = $CC >> configure.log
835echo CFLAGS = $CFLAGS >> configure.log
836echo CPP = $CPP >> configure.log
837echo EXE = $EXE >> configure.log
838echo LDCONFIG = $LDCONFIG >> configure.log
839echo LDFLAGS = $LDFLAGS >> configure.log
840echo LDSHARED = $LDSHARED >> configure.log
841echo LDSHAREDLIBC = $LDSHAREDLIBC >> configure.log
842echo OBJC = $OBJC >> configure.log
843echo PIC_OBJC = $PIC_OBJC >> configure.log
844echo RANLIB = $RANLIB >> configure.log
845echo SFLAGS = $SFLAGS >> configure.log
846echo SHAREDLIB = $SHAREDLIB >> configure.log
847echo SHAREDLIBM = $SHAREDLIBM >> configure.log
848echo SHAREDLIBV = $SHAREDLIBV >> configure.log
849echo STATICLIB = $STATICLIB >> configure.log
850echo TEST = $TEST >> configure.log
851echo VER = $VER >> configure.log
852echo Z_U4 = $Z_U4 >> configure.log
doko@ubuntu.com34e7e2e2017-01-31 13:49:48 +0100853echo SRCDIR = $SRCDIR >> configure.log
Christian Heimesc20bcde2013-10-21 12:03:09 +0200854echo exec_prefix = $exec_prefix >> configure.log
855echo includedir = $includedir >> configure.log
856echo libdir = $libdir >> configure.log
857echo mandir = $mandir >> configure.log
858echo prefix = $prefix >> configure.log
859echo sharedlibdir = $sharedlibdir >> configure.log
860echo uname = $uname >> configure.log
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000861
Christian Heimesc20bcde2013-10-21 12:03:09 +0200862# udpate Makefile with the configure results
doko@ubuntu.com34e7e2e2017-01-31 13:49:48 +0100863sed < ${SRCDIR}Makefile.in "
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000864/^CC *=/s#=.*#=$CC#
865/^CFLAGS *=/s#=.*#=$CFLAGS#
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000866/^SFLAGS *=/s#=.*#=$SFLAGS#
867/^LDFLAGS *=/s#=.*#=$LDFLAGS#
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000868/^LDSHARED *=/s#=.*#=$LDSHARED#
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000869/^CPP *=/s#=.*#=$CPP#
870/^STATICLIB *=/s#=.*#=$STATICLIB#
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000871/^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
872/^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
873/^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
Christian Heimesc20bcde2013-10-21 12:03:09 +0200874/^AR *=/s#=.*#=$AR#
875/^ARFLAGS *=/s#=.*#=$ARFLAGS#
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000876/^RANLIB *=/s#=.*#=$RANLIB#
877/^LDCONFIG *=/s#=.*#=$LDCONFIG#
878/^LDSHAREDLIBC *=/s#=.*#=$LDSHAREDLIBC#
879/^EXE *=/s#=.*#=$EXE#
doko@ubuntu.com34e7e2e2017-01-31 13:49:48 +0100880/^SRCDIR *=/s#=.*#=$SRCDIR#
881/^ZINC *=/s#=.*#=$ZINC#
882/^ZINCOUT *=/s#=.*#=$ZINCOUT#
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000883/^prefix *=/s#=.*#=$prefix#
884/^exec_prefix *=/s#=.*#=$exec_prefix#
885/^libdir *=/s#=.*#=$libdir#
886/^sharedlibdir *=/s#=.*#=$sharedlibdir#
887/^includedir *=/s#=.*#=$includedir#
888/^mandir *=/s#=.*#=$mandir#
Christian Heimesc20bcde2013-10-21 12:03:09 +0200889/^OBJC *=/s#=.*#= $OBJC#
890/^PIC_OBJC *=/s#=.*#= $PIC_OBJC#
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000891/^all: */s#:.*#: $ALL#
892/^test: */s#:.*#: $TEST#
893" > Makefile
894
Christian Heimesc20bcde2013-10-21 12:03:09 +0200895# create zlib.pc with the configure results
doko@ubuntu.com34e7e2e2017-01-31 13:49:48 +0100896sed < ${SRCDIR}zlib.pc.in "
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000897/^CC *=/s#=.*#=$CC#
898/^CFLAGS *=/s#=.*#=$CFLAGS#
899/^CPP *=/s#=.*#=$CPP#
900/^LDSHARED *=/s#=.*#=$LDSHARED#
901/^STATICLIB *=/s#=.*#=$STATICLIB#
902/^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
903/^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
904/^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
Christian Heimesc20bcde2013-10-21 12:03:09 +0200905/^AR *=/s#=.*#=$AR#
906/^ARFLAGS *=/s#=.*#=$ARFLAGS#
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000907/^RANLIB *=/s#=.*#=$RANLIB#
908/^EXE *=/s#=.*#=$EXE#
909/^prefix *=/s#=.*#=$prefix#
910/^exec_prefix *=/s#=.*#=$exec_prefix#
911/^libdir *=/s#=.*#=$libdir#
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000912/^sharedlibdir *=/s#=.*#=$sharedlibdir#
Martin v. Löwisd372aa82006-01-03 06:44:59 +0000913/^includedir *=/s#=.*#=$includedir#
914/^mandir *=/s#=.*#=$mandir#
915/^LDFLAGS *=/s#=.*#=$LDFLAGS#
Martin v. Löwisce126ed2010-07-30 20:03:17 +0000916" | sed -e "
917s/\@VERSION\@/$VER/g;
918" > zlib.pc
Christian Heimesc20bcde2013-10-21 12:03:09 +0200919
920# done
921leave 0