1275793eaSopenharmony_ci#!/bin/sh
2275793eaSopenharmony_ci# configure script for zlib.
3275793eaSopenharmony_ci#
4275793eaSopenharmony_ci# Normally configure builds both a static and a shared library.
5275793eaSopenharmony_ci# If you want to build just a static library, use: ./configure --static
6275793eaSopenharmony_ci#
7275793eaSopenharmony_ci# To impose specific compiler or flags or install directory, use for example:
8275793eaSopenharmony_ci#    prefix=$HOME CC=cc CFLAGS="-O4" ./configure
9275793eaSopenharmony_ci# or for csh/tcsh users:
10275793eaSopenharmony_ci#    (setenv prefix $HOME; setenv CC cc; setenv CFLAGS "-O4"; ./configure)
11275793eaSopenharmony_ci
12275793eaSopenharmony_ci# Incorrect settings of CC or CFLAGS may prevent creating a shared library.
13275793eaSopenharmony_ci# If you have problems, try without defining CC and CFLAGS before reporting
14275793eaSopenharmony_ci# an error.
15275793eaSopenharmony_ci
16275793eaSopenharmony_ci# start off configure.log
17275793eaSopenharmony_ciecho -------------------- >> configure.log
18275793eaSopenharmony_ciecho $0 $* >> configure.log
19275793eaSopenharmony_cidate >> configure.log
20275793eaSopenharmony_ci
21275793eaSopenharmony_ci# get source directory
22275793eaSopenharmony_ciSRCDIR=`dirname $0`
23275793eaSopenharmony_ciif test $SRCDIR = "."; then
24275793eaSopenharmony_ci    ZINC=""
25275793eaSopenharmony_ci    ZINCOUT="-I."
26275793eaSopenharmony_ci    SRCDIR=""
27275793eaSopenharmony_cielse
28275793eaSopenharmony_ci    ZINC='-I. -include zconf.h'
29275793eaSopenharmony_ci    ZINCOUT='-I. -I$(SRCDIR)'
30275793eaSopenharmony_ci    SRCDIR="$SRCDIR/"
31275793eaSopenharmony_cifi
32275793eaSopenharmony_ci
33275793eaSopenharmony_ci# set command prefix for cross-compilation
34275793eaSopenharmony_ciif [ -n "${CHOST}" ]; then
35275793eaSopenharmony_ci    uname=${CHOST}
36275793eaSopenharmony_ci    mname=${CHOST}
37275793eaSopenharmony_ci    CROSS_PREFIX="${CHOST}-"
38275793eaSopenharmony_cielse
39275793eaSopenharmony_ci    mname=`(uname -a || echo unknown) 2>/dev/null`
40275793eaSopenharmony_cifi
41275793eaSopenharmony_ci
42275793eaSopenharmony_ci# destination name for static library
43275793eaSopenharmony_ciSTATICLIB=libz.a
44275793eaSopenharmony_ci
45275793eaSopenharmony_ci# extract zlib version numbers from zlib.h
46275793eaSopenharmony_ciVER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < ${SRCDIR}zlib.h`
47275793eaSopenharmony_ciVER3=`echo ${VER}|sed -n -e 's/\([0-9]\{1,\}\(\\.[0-9]\{1,\}\)\{1,2\}\).*/\1/p'`
48275793eaSopenharmony_ciVER1=`echo ${VER}|sed -n -e 's/\([0-9]\{1,\}\)\\..*/\1/p'`
49275793eaSopenharmony_ci
50275793eaSopenharmony_ci# establish commands for library building
51275793eaSopenharmony_ciif "${CROSS_PREFIX}ar" --version >/dev/null 2>/dev/null || test $? -lt 126; then
52275793eaSopenharmony_ci    AR=${AR-"${CROSS_PREFIX}ar"}
53275793eaSopenharmony_ci    test -n "${CROSS_PREFIX}" && echo Using ${AR} | tee -a configure.log
54275793eaSopenharmony_cielse
55275793eaSopenharmony_ci    AR=${AR-"ar"}
56275793eaSopenharmony_ci    test -n "${CROSS_PREFIX}" && echo Using ${AR} | tee -a configure.log
57275793eaSopenharmony_cifi
58275793eaSopenharmony_ciARFLAGS=${ARFLAGS-"rc"}
59275793eaSopenharmony_ciif "${CROSS_PREFIX}ranlib" --version >/dev/null 2>/dev/null || test $? -lt 126; then
60275793eaSopenharmony_ci    RANLIB=${RANLIB-"${CROSS_PREFIX}ranlib"}
61275793eaSopenharmony_ci    test -n "${CROSS_PREFIX}" && echo Using ${RANLIB} | tee -a configure.log
62275793eaSopenharmony_cielse
63275793eaSopenharmony_ci    RANLIB=${RANLIB-"ranlib"}
64275793eaSopenharmony_cifi
65275793eaSopenharmony_ciif "${CROSS_PREFIX}nm" --version >/dev/null 2>/dev/null || test $? -lt 126; then
66275793eaSopenharmony_ci    NM=${NM-"${CROSS_PREFIX}nm"}
67275793eaSopenharmony_ci    test -n "${CROSS_PREFIX}" && echo Using ${NM} | tee -a configure.log
68275793eaSopenharmony_cielse
69275793eaSopenharmony_ci    NM=${NM-"nm"}
70275793eaSopenharmony_cifi
71275793eaSopenharmony_ci
72275793eaSopenharmony_ci# set defaults before processing command line options
73275793eaSopenharmony_ciLDCONFIG=${LDCONFIG-"ldconfig"}
74275793eaSopenharmony_ciLDSHAREDLIBC="${LDSHAREDLIBC--lc}"
75275793eaSopenharmony_ciARCHS=
76275793eaSopenharmony_ciprefix=${prefix-/usr/local}
77275793eaSopenharmony_ciexec_prefix=${exec_prefix-'${prefix}'}
78275793eaSopenharmony_cilibdir=${libdir-'${exec_prefix}/lib'}
79275793eaSopenharmony_cisharedlibdir=${sharedlibdir-'${libdir}'}
80275793eaSopenharmony_ciincludedir=${includedir-'${prefix}/include'}
81275793eaSopenharmony_cimandir=${mandir-'${prefix}/share/man'}
82275793eaSopenharmony_cishared_ext='.so'
83275793eaSopenharmony_cishared=1
84275793eaSopenharmony_cisolo=0
85275793eaSopenharmony_cicover=0
86275793eaSopenharmony_cizprefix=0
87275793eaSopenharmony_cizconst=0
88275793eaSopenharmony_cibuild64=0
89275793eaSopenharmony_cigcc=0
90275793eaSopenharmony_ciwarn=0
91275793eaSopenharmony_cidebug=0
92275793eaSopenharmony_ciaddress=0
93275793eaSopenharmony_cimemory=0
94275793eaSopenharmony_ciold_cc="$CC"
95275793eaSopenharmony_ciold_cflags="$CFLAGS"
96275793eaSopenharmony_ciOBJC='$(OBJZ) $(OBJG)'
97275793eaSopenharmony_ciPIC_OBJC='$(PIC_OBJZ) $(PIC_OBJG)'
98275793eaSopenharmony_ci
99275793eaSopenharmony_ci# leave this script, optionally in a bad way
100275793eaSopenharmony_cileave()
101275793eaSopenharmony_ci{
102275793eaSopenharmony_ci  if test "$*" != "0"; then
103275793eaSopenharmony_ci    echo "** $0 aborting." | tee -a configure.log
104275793eaSopenharmony_ci  fi
105275793eaSopenharmony_ci  rm -rf $test.[co] $test $test$shared_ext $test.gcno $test.dSYM ./--version
106275793eaSopenharmony_ci  echo -------------------- >> configure.log
107275793eaSopenharmony_ci  echo >> configure.log
108275793eaSopenharmony_ci  echo >> configure.log
109275793eaSopenharmony_ci  exit $1
110275793eaSopenharmony_ci}
111275793eaSopenharmony_ci
112275793eaSopenharmony_ci# process command line options
113275793eaSopenharmony_ciwhile test $# -ge 1
114275793eaSopenharmony_cido
115275793eaSopenharmony_cicase "$1" in
116275793eaSopenharmony_ci    -h* | --help)
117275793eaSopenharmony_ci      echo 'usage:' | tee -a configure.log
118275793eaSopenharmony_ci      echo '  configure [--const] [--zprefix] [--prefix=PREFIX]  [--eprefix=EXPREFIX]' | tee -a configure.log
119275793eaSopenharmony_ci      echo '    [--static] [--64] [--libdir=LIBDIR] [--sharedlibdir=LIBDIR]' | tee -a configure.log
120275793eaSopenharmony_ci      echo '    [--includedir=INCLUDEDIR] [--archs="-arch i386 -arch x86_64"]' | tee -a configure.log
121275793eaSopenharmony_ci        exit 0 ;;
122275793eaSopenharmony_ci    -p*=* | --prefix=*) prefix=`echo $1 | sed 's/.*=//'`; shift ;;
123275793eaSopenharmony_ci    -e*=* | --eprefix=*) exec_prefix=`echo $1 | sed 's/.*=//'`; shift ;;
124275793eaSopenharmony_ci    -l*=* | --libdir=*) libdir=`echo $1 | sed 's/.*=//'`; shift ;;
125275793eaSopenharmony_ci    --sharedlibdir=*) sharedlibdir=`echo $1 | sed 's/.*=//'`; shift ;;
126275793eaSopenharmony_ci    -i*=* | --includedir=*) includedir=`echo $1 | sed 's/.*=//'`;shift ;;
127275793eaSopenharmony_ci    -u*=* | --uname=*) uname=`echo $1 | sed 's/.*=//'`;shift ;;
128275793eaSopenharmony_ci    -p* | --prefix) prefix="$2"; shift; shift ;;
129275793eaSopenharmony_ci    -e* | --eprefix) exec_prefix="$2"; shift; shift ;;
130275793eaSopenharmony_ci    -l* | --libdir) libdir="$2"; shift; shift ;;
131275793eaSopenharmony_ci    -i* | --includedir) includedir="$2"; shift; shift ;;
132275793eaSopenharmony_ci    -s* | --shared | --enable-shared) shared=1; shift ;;
133275793eaSopenharmony_ci    -t | --static) shared=0; shift ;;
134275793eaSopenharmony_ci    --solo) solo=1; shift ;;
135275793eaSopenharmony_ci    --cover) cover=1; shift ;;
136275793eaSopenharmony_ci    -z* | --zprefix) zprefix=1; shift ;;
137275793eaSopenharmony_ci    -6* | --64) build64=1; shift ;;
138275793eaSopenharmony_ci    -a*=* | --archs=*) ARCHS=`echo $1 | sed 's/.*=//'`; shift ;;
139275793eaSopenharmony_ci    --sysconfdir=*) echo "ignored option: --sysconfdir" | tee -a configure.log; shift ;;
140275793eaSopenharmony_ci    --localstatedir=*) echo "ignored option: --localstatedir" | tee -a configure.log; shift ;;
141275793eaSopenharmony_ci    -c* | --const) zconst=1; shift ;;
142275793eaSopenharmony_ci    -w* | --warn) warn=1; shift ;;
143275793eaSopenharmony_ci    -d* | --debug) debug=1; shift ;;
144275793eaSopenharmony_ci    --sanitize) address=1; shift ;;
145275793eaSopenharmony_ci    --address) address=1; shift ;;
146275793eaSopenharmony_ci    --memory) memory=1; shift ;;
147275793eaSopenharmony_ci    *)
148275793eaSopenharmony_ci      echo "unknown option: $1" | tee -a configure.log
149275793eaSopenharmony_ci      echo "$0 --help for help" | tee -a configure.log
150275793eaSopenharmony_ci      leave 1;;
151275793eaSopenharmony_ci    esac
152275793eaSopenharmony_cidone
153275793eaSopenharmony_ci
154275793eaSopenharmony_ci# temporary file name
155275793eaSopenharmony_citest=ztest$$
156275793eaSopenharmony_ci
157275793eaSopenharmony_ci# put arguments in log, also put test file in log if used in arguments
158275793eaSopenharmony_cishow()
159275793eaSopenharmony_ci{
160275793eaSopenharmony_ci  case "$*" in
161275793eaSopenharmony_ci    *$test.c*)
162275793eaSopenharmony_ci      echo === $test.c === >> configure.log
163275793eaSopenharmony_ci      cat $test.c >> configure.log
164275793eaSopenharmony_ci      echo === >> configure.log;;
165275793eaSopenharmony_ci  esac
166275793eaSopenharmony_ci  echo $* >> configure.log
167275793eaSopenharmony_ci}
168275793eaSopenharmony_ci
169275793eaSopenharmony_ci# check for gcc vs. cc and set compile and link flags based on the system identified by uname
170275793eaSopenharmony_cicat > $test.c <<EOF
171275793eaSopenharmony_ciextern int getchar();
172275793eaSopenharmony_ciint hello() {return getchar();}
173275793eaSopenharmony_ciEOF
174275793eaSopenharmony_ci
175275793eaSopenharmony_ciif test -z "$CC"; then
176275793eaSopenharmony_ci  echo Checking for ${CROSS_PREFIX}gcc... | tee -a configure.log
177275793eaSopenharmony_ci  if ${CROSS_PREFIX}gcc -v >/dev/null 2>&1; then
178275793eaSopenharmony_ci    cc=${CROSS_PREFIX}gcc
179275793eaSopenharmony_ci  else
180275793eaSopenharmony_ci    cc=${CROSS_PREFIX}cc
181275793eaSopenharmony_ci  fi
182275793eaSopenharmony_cielse
183275793eaSopenharmony_ci  cc=${CC}
184275793eaSopenharmony_cifi
185275793eaSopenharmony_ci
186275793eaSopenharmony_cicase "$cc" in
187275793eaSopenharmony_ci  *gcc*) gcc=1 ;;
188275793eaSopenharmony_ci  *clang*) gcc=1 ;;
189275793eaSopenharmony_ciesac
190275793eaSopenharmony_cicase `$cc -v 2>&1` in
191275793eaSopenharmony_ci  *gcc*) gcc=1 ;;
192275793eaSopenharmony_ci  *clang*) gcc=1 ;;
193275793eaSopenharmony_ciesac
194275793eaSopenharmony_ci
195275793eaSopenharmony_cishow $cc -c $test.c
196275793eaSopenharmony_ciif test "$gcc" -eq 1 && ($cc -c $test.c) >> configure.log 2>&1; then
197275793eaSopenharmony_ci  echo ... using gcc >> configure.log
198275793eaSopenharmony_ci  CC="$cc"
199275793eaSopenharmony_ci  CFLAGS="${CFLAGS--O3}"
200275793eaSopenharmony_ci  SFLAGS="${CFLAGS--O3} -fPIC"
201275793eaSopenharmony_ci  if test "$ARCHS"; then
202275793eaSopenharmony_ci    CFLAGS="${CFLAGS} ${ARCHS}"
203275793eaSopenharmony_ci    LDFLAGS="${LDFLAGS} ${ARCHS}"
204275793eaSopenharmony_ci  fi
205275793eaSopenharmony_ci  if test $build64 -eq 1; then
206275793eaSopenharmony_ci    CFLAGS="${CFLAGS} -m64"
207275793eaSopenharmony_ci    SFLAGS="${SFLAGS} -m64"
208275793eaSopenharmony_ci  fi
209275793eaSopenharmony_ci  if test "$warn" -eq 1; then
210275793eaSopenharmony_ci    if test "$zconst" -eq 1; then
211275793eaSopenharmony_ci      CFLAGS="${CFLAGS} -Wall -Wextra -Wcast-qual -DZLIB_CONST"
212275793eaSopenharmony_ci    else
213275793eaSopenharmony_ci      CFLAGS="${CFLAGS} -Wall -Wextra"
214275793eaSopenharmony_ci    fi
215275793eaSopenharmony_ci  fi
216275793eaSopenharmony_ci  if test $address -eq 1; then
217275793eaSopenharmony_ci    CFLAGS="${CFLAGS} -g -fsanitize=address -fno-omit-frame-pointer"
218275793eaSopenharmony_ci  fi
219275793eaSopenharmony_ci  if test $memory -eq 1; then
220275793eaSopenharmony_ci    CFLAGS="${CFLAGS} -g -fsanitize=memory -fno-omit-frame-pointer"
221275793eaSopenharmony_ci  fi
222275793eaSopenharmony_ci  if test $debug -eq 1; then
223275793eaSopenharmony_ci    CFLAGS="${CFLAGS} -DZLIB_DEBUG"
224275793eaSopenharmony_ci    SFLAGS="${SFLAGS} -DZLIB_DEBUG"
225275793eaSopenharmony_ci  fi
226275793eaSopenharmony_ci  if test -z "$uname"; then
227275793eaSopenharmony_ci    uname=`(uname -s || echo unknown) 2>/dev/null`
228275793eaSopenharmony_ci  fi
229275793eaSopenharmony_ci  case "$uname" in
230275793eaSopenharmony_ci  Linux* | linux* | *-linux* | GNU | GNU/* | solaris*)
231275793eaSopenharmony_ci        case "$mname" in
232275793eaSopenharmony_ci        *sparc*)
233275793eaSopenharmony_ci            LDFLAGS="${LDFLAGS} -Wl,--no-warn-rwx-segments" ;;
234275793eaSopenharmony_ci        esac
235275793eaSopenharmony_ci        LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,${SRCDIR}zlib.map"} ;;
236275793eaSopenharmony_ci  *BSD | *bsd* | DragonFly)
237275793eaSopenharmony_ci        LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,${SRCDIR}zlib.map"}
238275793eaSopenharmony_ci        LDCONFIG="ldconfig -m" ;;
239275793eaSopenharmony_ci  CYGWIN* | Cygwin* | cygwin* | *-cygwin* | OS/2*)
240275793eaSopenharmony_ci        EXE='.exe' ;;
241275793eaSopenharmony_ci  MINGW* | mingw* | *-mingw*)
242275793eaSopenharmony_ci        rm -f $test.[co] $test $test$shared_ext
243275793eaSopenharmony_ci        echo "If this doesn't work for you, try win32/Makefile.gcc." | tee -a configure.log
244275793eaSopenharmony_ci        LDSHARED=${LDSHARED-"$cc -shared"}
245275793eaSopenharmony_ci        LDSHAREDLIBC=""
246275793eaSopenharmony_ci        EXE='.exe' ;;
247275793eaSopenharmony_ci  QNX*) # This is for QNX6. I suppose that the QNX rule below is for QNX2,QNX4
248275793eaSopenharmony_ci        # (alain.bonnefoy@icbt.com)
249275793eaSopenharmony_ci        LDSHARED=${LDSHARED-"$cc -shared -Wl,-hlibz.so.1"} ;;
250275793eaSopenharmony_ci  HP-UX*)
251275793eaSopenharmony_ci        LDSHARED=${LDSHARED-"$cc -shared $SFLAGS"}
252275793eaSopenharmony_ci        case `(uname -m || echo unknown) 2>/dev/null` in
253275793eaSopenharmony_ci        ia64)
254275793eaSopenharmony_ci            shared_ext='.so'
255275793eaSopenharmony_ci            SHAREDLIB='libz.so' ;;
256275793eaSopenharmony_ci        *)
257275793eaSopenharmony_ci            shared_ext='.sl'
258275793eaSopenharmony_ci            SHAREDLIB='libz.sl' ;;
259275793eaSopenharmony_ci        esac ;;
260275793eaSopenharmony_ci  AIX*)
261275793eaSopenharmony_ci        LDFLAGS="${LDFLAGS} -Wl,-brtl" ;;
262275793eaSopenharmony_ci  Darwin* | darwin* | *-darwin*)
263275793eaSopenharmony_ci        shared_ext='.dylib'
264275793eaSopenharmony_ci        SHAREDLIB=libz$shared_ext
265275793eaSopenharmony_ci        SHAREDLIBV=libz.$VER$shared_ext
266275793eaSopenharmony_ci        SHAREDLIBM=libz.$VER1$shared_ext
267275793eaSopenharmony_ci        LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBM -compatibility_version $VER1 -current_version $VER3"}
268275793eaSopenharmony_ci        if "${CROSS_PREFIX}libtool" -V 2>&1 | grep Apple > /dev/null; then
269275793eaSopenharmony_ci            AR="${CROSS_PREFIX}libtool"
270275793eaSopenharmony_ci        elif libtool -V 2>&1 | grep Apple > /dev/null; then
271275793eaSopenharmony_ci            AR="libtool"
272275793eaSopenharmony_ci        else
273275793eaSopenharmony_ci            AR="/usr/bin/libtool"
274275793eaSopenharmony_ci        fi
275275793eaSopenharmony_ci        ARFLAGS="-o" ;;
276275793eaSopenharmony_ci  *)
277275793eaSopenharmony_ci        LDSHARED=${LDSHARED-"$cc -shared"} ;;
278275793eaSopenharmony_ci  esac
279275793eaSopenharmony_cielse
280275793eaSopenharmony_ci  # find system name and corresponding cc options
281275793eaSopenharmony_ci  CC=${CC-cc}
282275793eaSopenharmony_ci  gcc=0
283275793eaSopenharmony_ci  echo ... using $CC >> configure.log
284275793eaSopenharmony_ci  if test -z "$uname"; then
285275793eaSopenharmony_ci    uname=`(uname -sr || echo unknown) 2>/dev/null`
286275793eaSopenharmony_ci  fi
287275793eaSopenharmony_ci  case "$uname" in
288275793eaSopenharmony_ci  HP-UX*)    SFLAGS=${CFLAGS-"-O +z"}
289275793eaSopenharmony_ci             CFLAGS=${CFLAGS-"-O"}
290275793eaSopenharmony_ci#            LDSHARED=${LDSHARED-"ld -b +vnocompatwarnings"}
291275793eaSopenharmony_ci             LDSHARED=${LDSHARED-"ld -b"}
292275793eaSopenharmony_ci         case `(uname -m || echo unknown) 2>/dev/null` in
293275793eaSopenharmony_ci         ia64)
294275793eaSopenharmony_ci             shared_ext='.so'
295275793eaSopenharmony_ci             SHAREDLIB='libz.so' ;;
296275793eaSopenharmony_ci         *)
297275793eaSopenharmony_ci             shared_ext='.sl'
298275793eaSopenharmony_ci             SHAREDLIB='libz.sl' ;;
299275793eaSopenharmony_ci         esac ;;
300275793eaSopenharmony_ci  IRIX*)     SFLAGS=${CFLAGS-"-ansi -O2 -rpath ."}
301275793eaSopenharmony_ci             CFLAGS=${CFLAGS-"-ansi -O2"}
302275793eaSopenharmony_ci             LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;;
303275793eaSopenharmony_ci  OSF1\ V4*) SFLAGS=${CFLAGS-"-O -std1"}
304275793eaSopenharmony_ci             CFLAGS=${CFLAGS-"-O -std1"}
305275793eaSopenharmony_ci             LDFLAGS="${LDFLAGS} -Wl,-rpath,."
306275793eaSopenharmony_ci             LDSHARED=${LDSHARED-"cc -shared  -Wl,-soname,libz.so -Wl,-msym -Wl,-rpath,$(libdir) -Wl,-set_version,${VER}:1.0"} ;;
307275793eaSopenharmony_ci  OSF1*)     SFLAGS=${CFLAGS-"-O -std1"}
308275793eaSopenharmony_ci             CFLAGS=${CFLAGS-"-O -std1"}
309275793eaSopenharmony_ci             LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;;
310275793eaSopenharmony_ci  QNX*)      SFLAGS=${CFLAGS-"-4 -O"}
311275793eaSopenharmony_ci             CFLAGS=${CFLAGS-"-4 -O"}
312275793eaSopenharmony_ci             LDSHARED=${LDSHARED-"cc"}
313275793eaSopenharmony_ci             RANLIB=${RANLIB-"true"}
314275793eaSopenharmony_ci             AR="cc"
315275793eaSopenharmony_ci             ARFLAGS="-A" ;;
316275793eaSopenharmony_ci  SCO_SV\ 3.2*) SFLAGS=${CFLAGS-"-O3 -dy -KPIC "}
317275793eaSopenharmony_ci             CFLAGS=${CFLAGS-"-O3"}
318275793eaSopenharmony_ci             LDSHARED=${LDSHARED-"cc -dy -KPIC -G"} ;;
319275793eaSopenharmony_ci  SunOS\ 5* | solaris*)
320275793eaSopenharmony_ci         LDSHARED=${LDSHARED-"cc -G -h libz$shared_ext.$VER1"}
321275793eaSopenharmony_ci         SFLAGS=${CFLAGS-"-fast -KPIC"}
322275793eaSopenharmony_ci         CFLAGS=${CFLAGS-"-fast"}
323275793eaSopenharmony_ci         if test $build64 -eq 1; then
324275793eaSopenharmony_ci             # old versions of SunPRO/Workshop/Studio don't support -m64,
325275793eaSopenharmony_ci             # but newer ones do.  Check for it.
326275793eaSopenharmony_ci             flag64=`$CC -flags | egrep -- '^-m64'`
327275793eaSopenharmony_ci             if test x"$flag64" != x"" ; then
328275793eaSopenharmony_ci                 CFLAGS="${CFLAGS} -m64"
329275793eaSopenharmony_ci                 SFLAGS="${SFLAGS} -m64"
330275793eaSopenharmony_ci             else
331275793eaSopenharmony_ci                 case `(uname -m || echo unknown) 2>/dev/null` in
332275793eaSopenharmony_ci                   i86*)
333275793eaSopenharmony_ci                     SFLAGS="$SFLAGS -xarch=amd64"
334275793eaSopenharmony_ci                     CFLAGS="$CFLAGS -xarch=amd64" ;;
335275793eaSopenharmony_ci                   *)
336275793eaSopenharmony_ci                     SFLAGS="$SFLAGS -xarch=v9"
337275793eaSopenharmony_ci                     CFLAGS="$CFLAGS -xarch=v9" ;;
338275793eaSopenharmony_ci                 esac
339275793eaSopenharmony_ci             fi
340275793eaSopenharmony_ci         fi
341275793eaSopenharmony_ci         if test -n "$ZINC"; then
342275793eaSopenharmony_ci             ZINC='-I- -I. -I$(SRCDIR)'
343275793eaSopenharmony_ci         fi
344275793eaSopenharmony_ci         ;;
345275793eaSopenharmony_ci  SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"}
346275793eaSopenharmony_ci             CFLAGS=${CFLAGS-"-O2"}
347275793eaSopenharmony_ci             LDSHARED=${LDSHARED-"ld"} ;;
348275793eaSopenharmony_ci  SunStudio\ 9*) SFLAGS=${CFLAGS-"-fast -xcode=pic32 -xtarget=ultra3 -xarch=v9b"}
349275793eaSopenharmony_ci             CFLAGS=${CFLAGS-"-fast -xtarget=ultra3 -xarch=v9b"}
350275793eaSopenharmony_ci             LDSHARED=${LDSHARED-"cc -xarch=v9b"} ;;
351275793eaSopenharmony_ci  UNIX_System_V\ 4.2.0)
352275793eaSopenharmony_ci             SFLAGS=${CFLAGS-"-KPIC -O"}
353275793eaSopenharmony_ci             CFLAGS=${CFLAGS-"-O"}
354275793eaSopenharmony_ci             LDSHARED=${LDSHARED-"cc -G"} ;;
355275793eaSopenharmony_ci  UNIX_SV\ 4.2MP)
356275793eaSopenharmony_ci             SFLAGS=${CFLAGS-"-Kconform_pic -O"}
357275793eaSopenharmony_ci             CFLAGS=${CFLAGS-"-O"}
358275793eaSopenharmony_ci             LDSHARED=${LDSHARED-"cc -G"} ;;
359275793eaSopenharmony_ci  OpenUNIX\ 5)
360275793eaSopenharmony_ci             SFLAGS=${CFLAGS-"-KPIC -O"}
361275793eaSopenharmony_ci             CFLAGS=${CFLAGS-"-O"}
362275793eaSopenharmony_ci             LDSHARED=${LDSHARED-"cc -G"} ;;
363275793eaSopenharmony_ci  AIX*)  # Courtesy of dbakker@arrayasolutions.com
364275793eaSopenharmony_ci             SFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
365275793eaSopenharmony_ci             CFLAGS=${CFLAGS-"-O -qmaxmem=8192"}
366275793eaSopenharmony_ci             LDSHARED=${LDSHARED-"xlc -G"} ;;
367275793eaSopenharmony_ci  # send working options for other systems to zlib@gzip.org
368275793eaSopenharmony_ci  *)         SFLAGS=${CFLAGS-"-O"}
369275793eaSopenharmony_ci             CFLAGS=${CFLAGS-"-O"}
370275793eaSopenharmony_ci             LDSHARED=${LDSHARED-"cc -shared"} ;;
371275793eaSopenharmony_ci  esac
372275793eaSopenharmony_cifi
373275793eaSopenharmony_ci
374275793eaSopenharmony_ci# destination names for shared library if not defined above
375275793eaSopenharmony_ciSHAREDLIB=${SHAREDLIB-"libz$shared_ext"}
376275793eaSopenharmony_ciSHAREDLIBV=${SHAREDLIBV-"libz$shared_ext.$VER"}
377275793eaSopenharmony_ciSHAREDLIBM=${SHAREDLIBM-"libz$shared_ext.$VER1"}
378275793eaSopenharmony_ci
379275793eaSopenharmony_ciecho >> configure.log
380275793eaSopenharmony_ci
381275793eaSopenharmony_ci# define functions for testing compiler and library characteristics and logging the results
382275793eaSopenharmony_ci
383275793eaSopenharmony_cicat > $test.c <<EOF
384275793eaSopenharmony_ci#error error
385275793eaSopenharmony_ciEOF
386275793eaSopenharmony_ciif ($CC -c $CFLAGS $test.c) 2>/dev/null; then
387275793eaSopenharmony_ci  try()
388275793eaSopenharmony_ci  {
389275793eaSopenharmony_ci    show $*
390275793eaSopenharmony_ci    test "`( $* ) 2>&1 | tee -a configure.log`" = ""
391275793eaSopenharmony_ci  }
392275793eaSopenharmony_ci  echo - using any output from compiler to indicate an error >> configure.log
393275793eaSopenharmony_cielse
394275793eaSopenharmony_ci  try()
395275793eaSopenharmony_ci  {
396275793eaSopenharmony_ci    show $*
397275793eaSopenharmony_ci    got=`( $* ) 2>&1`
398275793eaSopenharmony_ci    ret=$?
399275793eaSopenharmony_ci    if test "$got" != ""; then
400275793eaSopenharmony_ci      printf "%s\n" "$got" >> configure.log
401275793eaSopenharmony_ci    fi
402275793eaSopenharmony_ci    if test $ret -ne 0; then
403275793eaSopenharmony_ci      echo "(exit code "$ret")" >> configure.log
404275793eaSopenharmony_ci    fi
405275793eaSopenharmony_ci    return $ret
406275793eaSopenharmony_ci  }
407275793eaSopenharmony_cifi
408275793eaSopenharmony_ci
409275793eaSopenharmony_citryboth()
410275793eaSopenharmony_ci{
411275793eaSopenharmony_ci  show $*
412275793eaSopenharmony_ci  got=`( $* ) 2>&1`
413275793eaSopenharmony_ci  ret=$?
414275793eaSopenharmony_ci  if test "$got" != ""; then
415275793eaSopenharmony_ci    printf "%s\n" "$got" >> configure.log
416275793eaSopenharmony_ci  fi
417275793eaSopenharmony_ci  if test $ret -ne 0; then
418275793eaSopenharmony_ci    echo "(exit code "$ret")" >> configure.log
419275793eaSopenharmony_ci    return $ret
420275793eaSopenharmony_ci  fi
421275793eaSopenharmony_ci  test "$got" = ""
422275793eaSopenharmony_ci}
423275793eaSopenharmony_ci
424275793eaSopenharmony_cicat > $test.c << EOF
425275793eaSopenharmony_ciint foo() { return 0; }
426275793eaSopenharmony_ciEOF
427275793eaSopenharmony_ciecho "Checking for obsessive-compulsive compiler options..." >> configure.log
428275793eaSopenharmony_ciif try $CC -c $CFLAGS $test.c; then
429275793eaSopenharmony_ci  :
430275793eaSopenharmony_cielse
431275793eaSopenharmony_ci  echo "Compiler error reporting is too harsh for $0 (perhaps remove -Werror)." | tee -a configure.log
432275793eaSopenharmony_ci  leave 1
433275793eaSopenharmony_cifi
434275793eaSopenharmony_ci
435275793eaSopenharmony_ciecho >> configure.log
436275793eaSopenharmony_ci
437275793eaSopenharmony_ci# see if shared library build supported
438275793eaSopenharmony_cicat > $test.c <<EOF
439275793eaSopenharmony_ciextern int getchar();
440275793eaSopenharmony_ciint hello() {return getchar();}
441275793eaSopenharmony_ciEOF
442275793eaSopenharmony_ciif test $shared -eq 1; then
443275793eaSopenharmony_ci  echo Checking for shared library support... | tee -a configure.log
444275793eaSopenharmony_ci  # we must test in two steps (cc then ld), required at least on SunOS 4.x
445275793eaSopenharmony_ci  if try $CC -c $SFLAGS $test.c &&
446275793eaSopenharmony_ci     try $LDSHARED $SFLAGS -o $test$shared_ext $test.o; then
447275793eaSopenharmony_ci    echo Building shared library $SHAREDLIBV with $CC. | tee -a configure.log
448275793eaSopenharmony_ci  elif test -z "$old_cc" -a -z "$old_cflags"; then
449275793eaSopenharmony_ci    echo No shared library support. | tee -a configure.log
450275793eaSopenharmony_ci    shared=0;
451275793eaSopenharmony_ci  else
452275793eaSopenharmony_ci    echo 'No shared library support; try without defining CC and CFLAGS' | tee -a configure.log
453275793eaSopenharmony_ci    shared=0;
454275793eaSopenharmony_ci  fi
455275793eaSopenharmony_cifi
456275793eaSopenharmony_ciif test $shared -eq 0; then
457275793eaSopenharmony_ci  LDSHARED="$CC"
458275793eaSopenharmony_ci  ALL="static"
459275793eaSopenharmony_ci  TEST="all teststatic"
460275793eaSopenharmony_ci  SHAREDLIB=""
461275793eaSopenharmony_ci  SHAREDLIBV=""
462275793eaSopenharmony_ci  SHAREDLIBM=""
463275793eaSopenharmony_ci  echo Building static library $STATICLIB version $VER with $CC. | tee -a configure.log
464275793eaSopenharmony_cielse
465275793eaSopenharmony_ci  ALL="static shared"
466275793eaSopenharmony_ci  TEST="all teststatic testshared"
467275793eaSopenharmony_cifi
468275793eaSopenharmony_ci
469275793eaSopenharmony_ciecho >> configure.log
470275793eaSopenharmony_ci
471275793eaSopenharmony_ci# check for size_t
472275793eaSopenharmony_cicat > $test.c <<EOF
473275793eaSopenharmony_ci#include <stdio.h>
474275793eaSopenharmony_ci#include <stdlib.h>
475275793eaSopenharmony_cisize_t dummy = 0;
476275793eaSopenharmony_ciEOF
477275793eaSopenharmony_ciif try $CC -c $CFLAGS $test.c; then
478275793eaSopenharmony_ci  echo "Checking for size_t... Yes." | tee -a configure.log
479275793eaSopenharmony_cielse
480275793eaSopenharmony_ci  echo "Checking for size_t... No." | tee -a configure.log
481275793eaSopenharmony_ci  # find a size_t integer type
482275793eaSopenharmony_ci  # check for long long
483275793eaSopenharmony_ci  cat > $test.c << EOF
484275793eaSopenharmony_cilong long dummy = 0;
485275793eaSopenharmony_ciEOF
486275793eaSopenharmony_ci  if try $CC -c $CFLAGS $test.c; then
487275793eaSopenharmony_ci    echo "Checking for long long... Yes." | tee -a configure.log
488275793eaSopenharmony_ci    cat > $test.c <<EOF
489275793eaSopenharmony_ci#include <stdio.h>
490275793eaSopenharmony_ciint main(void) {
491275793eaSopenharmony_ci    if (sizeof(void *) <= sizeof(int)) puts("int");
492275793eaSopenharmony_ci    else if (sizeof(void *) <= sizeof(long)) puts("long");
493275793eaSopenharmony_ci    else puts("z_longlong");
494275793eaSopenharmony_ci    return 0;
495275793eaSopenharmony_ci}
496275793eaSopenharmony_ciEOF
497275793eaSopenharmony_ci  else
498275793eaSopenharmony_ci    echo "Checking for long long... No." | tee -a configure.log
499275793eaSopenharmony_ci    cat > $test.c <<EOF
500275793eaSopenharmony_ci#include <stdio.h>
501275793eaSopenharmony_ciint main(void) {
502275793eaSopenharmony_ci    if (sizeof(void *) <= sizeof(int)) puts("int");
503275793eaSopenharmony_ci    else puts("long");
504275793eaSopenharmony_ci    return 0;
505275793eaSopenharmony_ci}
506275793eaSopenharmony_ciEOF
507275793eaSopenharmony_ci  fi
508275793eaSopenharmony_ci  if try $CC $CFLAGS -o $test $test.c; then
509275793eaSopenharmony_ci    sizet=`./$test`
510275793eaSopenharmony_ci    echo "Checking for a pointer-size integer type..." $sizet"." | tee -a configure.log
511275793eaSopenharmony_ci    CFLAGS="${CFLAGS} -DNO_SIZE_T=${sizet}"
512275793eaSopenharmony_ci    SFLAGS="${SFLAGS} -DNO_SIZE_T=${sizet}"
513275793eaSopenharmony_ci  else
514275793eaSopenharmony_ci    echo "Checking for a pointer-size integer type... not found." | tee -a configure.log
515275793eaSopenharmony_ci  fi
516275793eaSopenharmony_cifi
517275793eaSopenharmony_ci
518275793eaSopenharmony_ciecho >> configure.log
519275793eaSopenharmony_ci
520275793eaSopenharmony_ci# check for large file support, and if none, check for fseeko()
521275793eaSopenharmony_cicat > $test.c <<EOF
522275793eaSopenharmony_ci#include <sys/types.h>
523275793eaSopenharmony_cioff64_t dummy = 0;
524275793eaSopenharmony_ciEOF
525275793eaSopenharmony_ciif try $CC -c $CFLAGS -D_LARGEFILE64_SOURCE=1 $test.c; then
526275793eaSopenharmony_ci  CFLAGS="${CFLAGS} -D_LARGEFILE64_SOURCE=1"
527275793eaSopenharmony_ci  SFLAGS="${SFLAGS} -D_LARGEFILE64_SOURCE=1"
528275793eaSopenharmony_ci  ALL="${ALL} all64"
529275793eaSopenharmony_ci  TEST="${TEST} test64"
530275793eaSopenharmony_ci  echo "Checking for off64_t... Yes." | tee -a configure.log
531275793eaSopenharmony_ci  echo "Checking for fseeko... Yes." | tee -a configure.log
532275793eaSopenharmony_cielse
533275793eaSopenharmony_ci  echo "Checking for off64_t... No." | tee -a configure.log
534275793eaSopenharmony_ci  echo >> configure.log
535275793eaSopenharmony_ci  cat > $test.c <<EOF
536275793eaSopenharmony_ci#include <stdio.h>
537275793eaSopenharmony_ciint main(void) {
538275793eaSopenharmony_ci  fseeko(NULL, 0, 0);
539275793eaSopenharmony_ci  return 0;
540275793eaSopenharmony_ci}
541275793eaSopenharmony_ciEOF
542275793eaSopenharmony_ci  if try $CC $CFLAGS -o $test $test.c; then
543275793eaSopenharmony_ci    echo "Checking for fseeko... Yes." | tee -a configure.log
544275793eaSopenharmony_ci  else
545275793eaSopenharmony_ci    CFLAGS="${CFLAGS} -DNO_FSEEKO"
546275793eaSopenharmony_ci    SFLAGS="${SFLAGS} -DNO_FSEEKO"
547275793eaSopenharmony_ci    echo "Checking for fseeko... No." | tee -a configure.log
548275793eaSopenharmony_ci  fi
549275793eaSopenharmony_cifi
550275793eaSopenharmony_ci
551275793eaSopenharmony_ciecho >> configure.log
552275793eaSopenharmony_ci
553275793eaSopenharmony_ci# check for strerror() for use by gz* functions
554275793eaSopenharmony_cicat > $test.c <<EOF
555275793eaSopenharmony_ci#include <string.h>
556275793eaSopenharmony_ci#include <errno.h>
557275793eaSopenharmony_ciint main() { return strlen(strerror(errno)); }
558275793eaSopenharmony_ciEOF
559275793eaSopenharmony_ciif try $CC $CFLAGS -o $test $test.c; then
560275793eaSopenharmony_ci  echo "Checking for strerror... Yes." | tee -a configure.log
561275793eaSopenharmony_cielse
562275793eaSopenharmony_ci  CFLAGS="${CFLAGS} -DNO_STRERROR"
563275793eaSopenharmony_ci  SFLAGS="${SFLAGS} -DNO_STRERROR"
564275793eaSopenharmony_ci  echo "Checking for strerror... No." | tee -a configure.log
565275793eaSopenharmony_cifi
566275793eaSopenharmony_ci
567275793eaSopenharmony_ci# copy clean zconf.h for subsequent edits
568275793eaSopenharmony_cicp -p ${SRCDIR}zconf.h.in zconf.h
569275793eaSopenharmony_ci
570275793eaSopenharmony_ciecho >> configure.log
571275793eaSopenharmony_ci
572275793eaSopenharmony_ci# check for unistd.h and save result in zconf.h
573275793eaSopenharmony_cicat > $test.c <<EOF
574275793eaSopenharmony_ci#include <unistd.h>
575275793eaSopenharmony_ciint main() { return 0; }
576275793eaSopenharmony_ciEOF
577275793eaSopenharmony_ciif try $CC -c $CFLAGS $test.c; then
578275793eaSopenharmony_ci  sed < zconf.h "/^#ifdef HAVE_UNISTD_H.* may be/s/def HAVE_UNISTD_H\(.*\) may be/ 1\1 was/" > zconf.temp.h
579275793eaSopenharmony_ci  mv zconf.temp.h zconf.h
580275793eaSopenharmony_ci  echo "Checking for unistd.h... Yes." | tee -a configure.log
581275793eaSopenharmony_cielse
582275793eaSopenharmony_ci  echo "Checking for unistd.h... No." | tee -a configure.log
583275793eaSopenharmony_cifi
584275793eaSopenharmony_ci
585275793eaSopenharmony_ciecho >> configure.log
586275793eaSopenharmony_ci
587275793eaSopenharmony_ci# check for stdarg.h and save result in zconf.h
588275793eaSopenharmony_cicat > $test.c <<EOF
589275793eaSopenharmony_ci#include <stdarg.h>
590275793eaSopenharmony_ciint main() { return 0; }
591275793eaSopenharmony_ciEOF
592275793eaSopenharmony_ciif try $CC -c $CFLAGS $test.c; then
593275793eaSopenharmony_ci  sed < zconf.h "/^#ifdef HAVE_STDARG_H.* may be/s/def HAVE_STDARG_H\(.*\) may be/ 1\1 was/" > zconf.temp.h
594275793eaSopenharmony_ci  mv zconf.temp.h zconf.h
595275793eaSopenharmony_ci  echo "Checking for stdarg.h... Yes." | tee -a configure.log
596275793eaSopenharmony_cielse
597275793eaSopenharmony_ci  echo "Checking for stdarg.h... No." | tee -a configure.log
598275793eaSopenharmony_cifi
599275793eaSopenharmony_ci
600275793eaSopenharmony_ci# if the z_ prefix was requested, save that in zconf.h
601275793eaSopenharmony_ciif test $zprefix -eq 1; then
602275793eaSopenharmony_ci  sed < zconf.h "/#ifdef Z_PREFIX.* may be/s/def Z_PREFIX\(.*\) may be/ 1\1 was/" > zconf.temp.h
603275793eaSopenharmony_ci  mv zconf.temp.h zconf.h
604275793eaSopenharmony_ci  echo >> configure.log
605275793eaSopenharmony_ci  echo "Using z_ prefix on all symbols." | tee -a configure.log
606275793eaSopenharmony_cifi
607275793eaSopenharmony_ci
608275793eaSopenharmony_ci# if --solo compilation was requested, save that in zconf.h and remove gz stuff from object lists
609275793eaSopenharmony_ciif test $solo -eq 1; then
610275793eaSopenharmony_ci  sed '/#define ZCONF_H/a\
611275793eaSopenharmony_ci#define Z_SOLO
612275793eaSopenharmony_ci
613275793eaSopenharmony_ci' < zconf.h > zconf.temp.h
614275793eaSopenharmony_ci  mv zconf.temp.h zconf.h
615275793eaSopenharmony_ciOBJC='$(OBJZ)'
616275793eaSopenharmony_ciPIC_OBJC='$(PIC_OBJZ)'
617275793eaSopenharmony_cifi
618275793eaSopenharmony_ci
619275793eaSopenharmony_ci# if code coverage testing was requested, use older gcc if defined, e.g. "gcc-4.2" on Mac OS X
620275793eaSopenharmony_ciif test $cover -eq 1; then
621275793eaSopenharmony_ci  CFLAGS="${CFLAGS} -fprofile-arcs -ftest-coverage"
622275793eaSopenharmony_ci  if test -n "$GCC_CLASSIC"; then
623275793eaSopenharmony_ci    CC=$GCC_CLASSIC
624275793eaSopenharmony_ci  fi
625275793eaSopenharmony_cifi
626275793eaSopenharmony_ci
627275793eaSopenharmony_ciecho >> configure.log
628275793eaSopenharmony_ci
629275793eaSopenharmony_ci# conduct a series of tests to resolve eight possible cases of using "vs" or "s" printf functions
630275793eaSopenharmony_ci# (using stdarg or not), with or without "n" (proving size of buffer), and with or without a
631275793eaSopenharmony_ci# return value.  The most secure result is vsnprintf() with a return value.  snprintf() with a
632275793eaSopenharmony_ci# return value is secure as well, but then gzprintf() will be limited to 20 arguments.
633275793eaSopenharmony_cicat > $test.c <<EOF
634275793eaSopenharmony_ci#include <stdio.h>
635275793eaSopenharmony_ci#include <stdarg.h>
636275793eaSopenharmony_ci#include "zconf.h"
637275793eaSopenharmony_ciint main()
638275793eaSopenharmony_ci{
639275793eaSopenharmony_ci#ifndef STDC
640275793eaSopenharmony_ci  choke me
641275793eaSopenharmony_ci#endif
642275793eaSopenharmony_ci  return 0;
643275793eaSopenharmony_ci}
644275793eaSopenharmony_ciEOF
645275793eaSopenharmony_ciif try $CC -c $CFLAGS $test.c; then
646275793eaSopenharmony_ci  echo "Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf()." | tee -a configure.log
647275793eaSopenharmony_ci
648275793eaSopenharmony_ci  echo >> configure.log
649275793eaSopenharmony_ci  cat > $test.c <<EOF
650275793eaSopenharmony_ci#include <stdio.h>
651275793eaSopenharmony_ci#include <stdarg.h>
652275793eaSopenharmony_ciint mytest(const char *fmt, ...)
653275793eaSopenharmony_ci{
654275793eaSopenharmony_ci  char buf[20];
655275793eaSopenharmony_ci  va_list ap;
656275793eaSopenharmony_ci  va_start(ap, fmt);
657275793eaSopenharmony_ci  vsnprintf(buf, sizeof(buf), fmt, ap);
658275793eaSopenharmony_ci  va_end(ap);
659275793eaSopenharmony_ci  return 0;
660275793eaSopenharmony_ci}
661275793eaSopenharmony_ciint main()
662275793eaSopenharmony_ci{
663275793eaSopenharmony_ci  return (mytest("Hello%d\n", 1));
664275793eaSopenharmony_ci}
665275793eaSopenharmony_ciEOF
666275793eaSopenharmony_ci  if try $CC $CFLAGS -o $test $test.c; then
667275793eaSopenharmony_ci    echo "Checking for vsnprintf() in stdio.h... Yes." | tee -a configure.log
668275793eaSopenharmony_ci
669275793eaSopenharmony_ci    echo >> configure.log
670275793eaSopenharmony_ci    cat >$test.c <<EOF
671275793eaSopenharmony_ci#include <stdio.h>
672275793eaSopenharmony_ci#include <stdarg.h>
673275793eaSopenharmony_ciint mytest(const char *fmt, ...)
674275793eaSopenharmony_ci{
675275793eaSopenharmony_ci  int n;
676275793eaSopenharmony_ci  char buf[20];
677275793eaSopenharmony_ci  va_list ap;
678275793eaSopenharmony_ci  va_start(ap, fmt);
679275793eaSopenharmony_ci  n = vsnprintf(buf, sizeof(buf), fmt, ap);
680275793eaSopenharmony_ci  va_end(ap);
681275793eaSopenharmony_ci  return n;
682275793eaSopenharmony_ci}
683275793eaSopenharmony_ciint main()
684275793eaSopenharmony_ci{
685275793eaSopenharmony_ci  return (mytest("Hello%d\n", 1));
686275793eaSopenharmony_ci}
687275793eaSopenharmony_ciEOF
688275793eaSopenharmony_ci
689275793eaSopenharmony_ci    if try $CC -c $CFLAGS $test.c; then
690275793eaSopenharmony_ci      echo "Checking for return value of vsnprintf()... Yes." | tee -a configure.log
691275793eaSopenharmony_ci    else
692275793eaSopenharmony_ci      CFLAGS="$CFLAGS -DHAS_vsnprintf_void"
693275793eaSopenharmony_ci      SFLAGS="$SFLAGS -DHAS_vsnprintf_void"
694275793eaSopenharmony_ci      echo "Checking for return value of vsnprintf()... No." | tee -a configure.log
695275793eaSopenharmony_ci      echo "  WARNING: apparently vsnprintf() does not return a value. zlib" | tee -a configure.log
696275793eaSopenharmony_ci      echo "  can build but will be open to possible string-format security" | tee -a configure.log
697275793eaSopenharmony_ci      echo "  vulnerabilities." | tee -a configure.log
698275793eaSopenharmony_ci    fi
699275793eaSopenharmony_ci  else
700275793eaSopenharmony_ci    CFLAGS="$CFLAGS -DNO_vsnprintf"
701275793eaSopenharmony_ci    SFLAGS="$SFLAGS -DNO_vsnprintf"
702275793eaSopenharmony_ci    echo "Checking for vsnprintf() in stdio.h... No." | tee -a configure.log
703275793eaSopenharmony_ci    echo "  WARNING: vsnprintf() not found, falling back to vsprintf(). zlib" | tee -a configure.log
704275793eaSopenharmony_ci    echo "  can build but will be open to possible buffer-overflow security" | tee -a configure.log
705275793eaSopenharmony_ci    echo "  vulnerabilities." | tee -a configure.log
706275793eaSopenharmony_ci
707275793eaSopenharmony_ci    echo >> configure.log
708275793eaSopenharmony_ci    cat >$test.c <<EOF
709275793eaSopenharmony_ci#include <stdio.h>
710275793eaSopenharmony_ci#include <stdarg.h>
711275793eaSopenharmony_ciint mytest(const char *fmt, ...)
712275793eaSopenharmony_ci{
713275793eaSopenharmony_ci  int n;
714275793eaSopenharmony_ci  char buf[20];
715275793eaSopenharmony_ci  va_list ap;
716275793eaSopenharmony_ci  va_start(ap, fmt);
717275793eaSopenharmony_ci  n = vsprintf(buf, fmt, ap);
718275793eaSopenharmony_ci  va_end(ap);
719275793eaSopenharmony_ci  return n;
720275793eaSopenharmony_ci}
721275793eaSopenharmony_ciint main()
722275793eaSopenharmony_ci{
723275793eaSopenharmony_ci  return (mytest("Hello%d\n", 1));
724275793eaSopenharmony_ci}
725275793eaSopenharmony_ciEOF
726275793eaSopenharmony_ci
727275793eaSopenharmony_ci    if try $CC -c $CFLAGS $test.c; then
728275793eaSopenharmony_ci      echo "Checking for return value of vsprintf()... Yes." | tee -a configure.log
729275793eaSopenharmony_ci    else
730275793eaSopenharmony_ci      CFLAGS="$CFLAGS -DHAS_vsprintf_void"
731275793eaSopenharmony_ci      SFLAGS="$SFLAGS -DHAS_vsprintf_void"
732275793eaSopenharmony_ci      echo "Checking for return value of vsprintf()... No." | tee -a configure.log
733275793eaSopenharmony_ci      echo "  WARNING: apparently vsprintf() does not return a value. zlib" | tee -a configure.log
734275793eaSopenharmony_ci      echo "  can build but will be open to possible string-format security" | tee -a configure.log
735275793eaSopenharmony_ci      echo "  vulnerabilities." | tee -a configure.log
736275793eaSopenharmony_ci    fi
737275793eaSopenharmony_ci  fi
738275793eaSopenharmony_cielse
739275793eaSopenharmony_ci  echo "Checking whether to use vs[n]printf() or s[n]printf()... using s[n]printf()." | tee -a configure.log
740275793eaSopenharmony_ci
741275793eaSopenharmony_ci  echo >> configure.log
742275793eaSopenharmony_ci  cat >$test.c <<EOF
743275793eaSopenharmony_ci#include <stdio.h>
744275793eaSopenharmony_ciint mytest()
745275793eaSopenharmony_ci{
746275793eaSopenharmony_ci  char buf[20];
747275793eaSopenharmony_ci  snprintf(buf, sizeof(buf), "%s", "foo");
748275793eaSopenharmony_ci  return 0;
749275793eaSopenharmony_ci}
750275793eaSopenharmony_ciint main()
751275793eaSopenharmony_ci{
752275793eaSopenharmony_ci  return (mytest());
753275793eaSopenharmony_ci}
754275793eaSopenharmony_ciEOF
755275793eaSopenharmony_ci
756275793eaSopenharmony_ci  if try $CC $CFLAGS -o $test $test.c; then
757275793eaSopenharmony_ci    echo "Checking for snprintf() in stdio.h... Yes." | tee -a configure.log
758275793eaSopenharmony_ci
759275793eaSopenharmony_ci    echo >> configure.log
760275793eaSopenharmony_ci    cat >$test.c <<EOF
761275793eaSopenharmony_ci#include <stdio.h>
762275793eaSopenharmony_ciint mytest()
763275793eaSopenharmony_ci{
764275793eaSopenharmony_ci  char buf[20];
765275793eaSopenharmony_ci  return snprintf(buf, sizeof(buf), "%s", "foo");
766275793eaSopenharmony_ci}
767275793eaSopenharmony_ciint main()
768275793eaSopenharmony_ci{
769275793eaSopenharmony_ci  return (mytest());
770275793eaSopenharmony_ci}
771275793eaSopenharmony_ciEOF
772275793eaSopenharmony_ci
773275793eaSopenharmony_ci    if try $CC -c $CFLAGS $test.c; then
774275793eaSopenharmony_ci      echo "Checking for return value of snprintf()... Yes." | tee -a configure.log
775275793eaSopenharmony_ci    else
776275793eaSopenharmony_ci      CFLAGS="$CFLAGS -DHAS_snprintf_void"
777275793eaSopenharmony_ci      SFLAGS="$SFLAGS -DHAS_snprintf_void"
778275793eaSopenharmony_ci      echo "Checking for return value of snprintf()... No." | tee -a configure.log
779275793eaSopenharmony_ci      echo "  WARNING: apparently snprintf() does not return a value. zlib" | tee -a configure.log
780275793eaSopenharmony_ci      echo "  can build but will be open to possible string-format security" | tee -a configure.log
781275793eaSopenharmony_ci      echo "  vulnerabilities." | tee -a configure.log
782275793eaSopenharmony_ci    fi
783275793eaSopenharmony_ci  else
784275793eaSopenharmony_ci    CFLAGS="$CFLAGS -DNO_snprintf"
785275793eaSopenharmony_ci    SFLAGS="$SFLAGS -DNO_snprintf"
786275793eaSopenharmony_ci    echo "Checking for snprintf() in stdio.h... No." | tee -a configure.log
787275793eaSopenharmony_ci    echo "  WARNING: snprintf() not found, falling back to sprintf(). zlib" | tee -a configure.log
788275793eaSopenharmony_ci    echo "  can build but will be open to possible buffer-overflow security" | tee -a configure.log
789275793eaSopenharmony_ci    echo "  vulnerabilities." | tee -a configure.log
790275793eaSopenharmony_ci
791275793eaSopenharmony_ci    echo >> configure.log
792275793eaSopenharmony_ci    cat >$test.c <<EOF
793275793eaSopenharmony_ci#include <stdio.h>
794275793eaSopenharmony_ciint mytest()
795275793eaSopenharmony_ci{
796275793eaSopenharmony_ci  char buf[20];
797275793eaSopenharmony_ci  return sprintf(buf, "%s", "foo");
798275793eaSopenharmony_ci}
799275793eaSopenharmony_ciint main()
800275793eaSopenharmony_ci{
801275793eaSopenharmony_ci  return (mytest());
802275793eaSopenharmony_ci}
803275793eaSopenharmony_ciEOF
804275793eaSopenharmony_ci
805275793eaSopenharmony_ci    if try $CC -c $CFLAGS $test.c; then
806275793eaSopenharmony_ci      echo "Checking for return value of sprintf()... Yes." | tee -a configure.log
807275793eaSopenharmony_ci    else
808275793eaSopenharmony_ci      CFLAGS="$CFLAGS -DHAS_sprintf_void"
809275793eaSopenharmony_ci      SFLAGS="$SFLAGS -DHAS_sprintf_void"
810275793eaSopenharmony_ci      echo "Checking for return value of sprintf()... No." | tee -a configure.log
811275793eaSopenharmony_ci      echo "  WARNING: apparently sprintf() does not return a value. zlib" | tee -a configure.log
812275793eaSopenharmony_ci      echo "  can build but will be open to possible string-format security" | tee -a configure.log
813275793eaSopenharmony_ci      echo "  vulnerabilities." | tee -a configure.log
814275793eaSopenharmony_ci    fi
815275793eaSopenharmony_ci  fi
816275793eaSopenharmony_cifi
817275793eaSopenharmony_ci
818275793eaSopenharmony_ci# see if we can hide zlib internal symbols that are linked between separate source files
819275793eaSopenharmony_ciif test "$gcc" -eq 1; then
820275793eaSopenharmony_ci  echo >> configure.log
821275793eaSopenharmony_ci  cat > $test.c <<EOF
822275793eaSopenharmony_ci#define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
823275793eaSopenharmony_ciint ZLIB_INTERNAL foo;
824275793eaSopenharmony_ciint main()
825275793eaSopenharmony_ci{
826275793eaSopenharmony_ci  return 0;
827275793eaSopenharmony_ci}
828275793eaSopenharmony_ciEOF
829275793eaSopenharmony_ci  if tryboth $CC -c $CFLAGS $test.c; then
830275793eaSopenharmony_ci    CFLAGS="$CFLAGS -DHAVE_HIDDEN"
831275793eaSopenharmony_ci    SFLAGS="$SFLAGS -DHAVE_HIDDEN"
832275793eaSopenharmony_ci    echo "Checking for attribute(visibility) support... Yes." | tee -a configure.log
833275793eaSopenharmony_ci  else
834275793eaSopenharmony_ci    echo "Checking for attribute(visibility) support... No." | tee -a configure.log
835275793eaSopenharmony_ci  fi
836275793eaSopenharmony_cifi
837275793eaSopenharmony_ci
838275793eaSopenharmony_ci# show the results in the log
839275793eaSopenharmony_ciecho >> configure.log
840275793eaSopenharmony_ciecho ALL = $ALL >> configure.log
841275793eaSopenharmony_ciecho AR = $AR >> configure.log
842275793eaSopenharmony_ciecho ARFLAGS = $ARFLAGS >> configure.log
843275793eaSopenharmony_ciecho CC = $CC >> configure.log
844275793eaSopenharmony_ciecho CFLAGS = $CFLAGS >> configure.log
845275793eaSopenharmony_ciecho CPP = $CPP >> configure.log
846275793eaSopenharmony_ciecho EXE = $EXE >> configure.log
847275793eaSopenharmony_ciecho LDCONFIG = $LDCONFIG >> configure.log
848275793eaSopenharmony_ciecho LDFLAGS = $LDFLAGS >> configure.log
849275793eaSopenharmony_ciecho LDSHARED = $LDSHARED >> configure.log
850275793eaSopenharmony_ciecho LDSHAREDLIBC = $LDSHAREDLIBC >> configure.log
851275793eaSopenharmony_ciecho OBJC = $OBJC >> configure.log
852275793eaSopenharmony_ciecho PIC_OBJC = $PIC_OBJC >> configure.log
853275793eaSopenharmony_ciecho RANLIB = $RANLIB >> configure.log
854275793eaSopenharmony_ciecho SFLAGS = $SFLAGS >> configure.log
855275793eaSopenharmony_ciecho SHAREDLIB = $SHAREDLIB >> configure.log
856275793eaSopenharmony_ciecho SHAREDLIBM = $SHAREDLIBM >> configure.log
857275793eaSopenharmony_ciecho SHAREDLIBV = $SHAREDLIBV >> configure.log
858275793eaSopenharmony_ciecho STATICLIB = $STATICLIB >> configure.log
859275793eaSopenharmony_ciecho TEST = $TEST >> configure.log
860275793eaSopenharmony_ciecho VER = $VER >> configure.log
861275793eaSopenharmony_ciecho SRCDIR = $SRCDIR >> configure.log
862275793eaSopenharmony_ciecho exec_prefix = $exec_prefix >> configure.log
863275793eaSopenharmony_ciecho includedir = $includedir >> configure.log
864275793eaSopenharmony_ciecho libdir = $libdir >> configure.log
865275793eaSopenharmony_ciecho mandir = $mandir >> configure.log
866275793eaSopenharmony_ciecho prefix = $prefix >> configure.log
867275793eaSopenharmony_ciecho sharedlibdir = $sharedlibdir >> configure.log
868275793eaSopenharmony_ciecho uname = $uname >> configure.log
869275793eaSopenharmony_ci
870275793eaSopenharmony_ci# update Makefile with the configure results
871275793eaSopenharmony_cised < ${SRCDIR}Makefile.in "
872275793eaSopenharmony_ci/^CC *=/s#=.*#=$CC#
873275793eaSopenharmony_ci/^CFLAGS *=/s#=.*#=$CFLAGS#
874275793eaSopenharmony_ci/^SFLAGS *=/s#=.*#=$SFLAGS#
875275793eaSopenharmony_ci/^LDFLAGS *=/s#=.*#=$LDFLAGS#
876275793eaSopenharmony_ci/^LDSHARED *=/s#=.*#=$LDSHARED#
877275793eaSopenharmony_ci/^CPP *=/s#=.*#=$CPP#
878275793eaSopenharmony_ci/^STATICLIB *=/s#=.*#=$STATICLIB#
879275793eaSopenharmony_ci/^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
880275793eaSopenharmony_ci/^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
881275793eaSopenharmony_ci/^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
882275793eaSopenharmony_ci/^AR *=/s#=.*#=$AR#
883275793eaSopenharmony_ci/^ARFLAGS *=/s#=.*#=$ARFLAGS#
884275793eaSopenharmony_ci/^RANLIB *=/s#=.*#=$RANLIB#
885275793eaSopenharmony_ci/^LDCONFIG *=/s#=.*#=$LDCONFIG#
886275793eaSopenharmony_ci/^LDSHAREDLIBC *=/s#=.*#=$LDSHAREDLIBC#
887275793eaSopenharmony_ci/^EXE *=/s#=.*#=$EXE#
888275793eaSopenharmony_ci/^SRCDIR *=/s#=.*#=$SRCDIR#
889275793eaSopenharmony_ci/^ZINC *=/s#=.*#=$ZINC#
890275793eaSopenharmony_ci/^ZINCOUT *=/s#=.*#=$ZINCOUT#
891275793eaSopenharmony_ci/^prefix *=/s#=.*#=$prefix#
892275793eaSopenharmony_ci/^exec_prefix *=/s#=.*#=$exec_prefix#
893275793eaSopenharmony_ci/^libdir *=/s#=.*#=$libdir#
894275793eaSopenharmony_ci/^sharedlibdir *=/s#=.*#=$sharedlibdir#
895275793eaSopenharmony_ci/^includedir *=/s#=.*#=$includedir#
896275793eaSopenharmony_ci/^mandir *=/s#=.*#=$mandir#
897275793eaSopenharmony_ci/^OBJC *=/s#=.*#= $OBJC#
898275793eaSopenharmony_ci/^PIC_OBJC *=/s#=.*#= $PIC_OBJC#
899275793eaSopenharmony_ci/^all: */s#:.*#: $ALL#
900275793eaSopenharmony_ci/^test: */s#:.*#: $TEST#
901275793eaSopenharmony_ci" > Makefile
902275793eaSopenharmony_ci
903275793eaSopenharmony_ci# create zlib.pc with the configure results
904275793eaSopenharmony_cised < ${SRCDIR}zlib.pc.in "
905275793eaSopenharmony_ci/^CC *=/s#=.*#=$CC#
906275793eaSopenharmony_ci/^CFLAGS *=/s#=.*#=$CFLAGS#
907275793eaSopenharmony_ci/^CPP *=/s#=.*#=$CPP#
908275793eaSopenharmony_ci/^LDSHARED *=/s#=.*#=$LDSHARED#
909275793eaSopenharmony_ci/^STATICLIB *=/s#=.*#=$STATICLIB#
910275793eaSopenharmony_ci/^SHAREDLIB *=/s#=.*#=$SHAREDLIB#
911275793eaSopenharmony_ci/^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV#
912275793eaSopenharmony_ci/^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM#
913275793eaSopenharmony_ci/^AR *=/s#=.*#=$AR#
914275793eaSopenharmony_ci/^ARFLAGS *=/s#=.*#=$ARFLAGS#
915275793eaSopenharmony_ci/^RANLIB *=/s#=.*#=$RANLIB#
916275793eaSopenharmony_ci/^EXE *=/s#=.*#=$EXE#
917275793eaSopenharmony_ci/^prefix *=/s#=.*#=$prefix#
918275793eaSopenharmony_ci/^exec_prefix *=/s#=.*#=$exec_prefix#
919275793eaSopenharmony_ci/^libdir *=/s#=.*#=$libdir#
920275793eaSopenharmony_ci/^sharedlibdir *=/s#=.*#=$sharedlibdir#
921275793eaSopenharmony_ci/^includedir *=/s#=.*#=$includedir#
922275793eaSopenharmony_ci/^mandir *=/s#=.*#=$mandir#
923275793eaSopenharmony_ci/^LDFLAGS *=/s#=.*#=$LDFLAGS#
924275793eaSopenharmony_ci" | sed -e "
925275793eaSopenharmony_cis/\@VERSION\@/$VER/g;
926275793eaSopenharmony_ci" > zlib.pc
927275793eaSopenharmony_ci
928275793eaSopenharmony_ci# done
929275793eaSopenharmony_cileave 0
930