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