|
1 #!/bin/sh |
|
2 # configure script for zlib. This script is needed only if |
|
3 # you wish to build a shared library and your system supports them, |
|
4 # of if you need special compiler, flags or install directory. |
|
5 # Otherwise, you can just use directly "make test; make install" |
|
6 # |
|
7 # To create a shared library, use "configure --shared"; by default a static |
|
8 # library is created. If the primitive shared library support provided here |
|
9 # does not work, use ftp://prep.ai.mit.edu/pub/gnu/libtool-*.tar.gz |
|
10 # |
|
11 # To impose specific compiler or flags or install directory, use for example: |
|
12 # prefix=$HOME CC=cc CFLAGS="-O4" ./configure |
|
13 # or for csh/tcsh users: |
|
14 # (setenv prefix $HOME; setenv CC cc; setenv CFLAGS "-O4"; ./configure) |
|
15 # LDSHARED is the command to be used to create a shared library |
|
16 |
|
17 # Incorrect settings of CC or CFLAGS may prevent creating a shared library. |
|
18 # If you have problems, try without defining CC and CFLAGS before reporting |
|
19 # an error. |
|
20 |
|
21 LIBS=libz.a |
|
22 LDFLAGS="-L. ${LIBS}" |
|
23 VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h` |
|
24 VER2=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\)\\..*/\1/p' < zlib.h` |
|
25 VER1=`sed -n -e '/VERSION "/s/.*"\([0-9]*\)\\..*/\1/p' < zlib.h` |
|
26 AR=${AR-"ar rc"} |
|
27 RANLIB=${RANLIB-"ranlib"} |
|
28 prefix=${prefix-/usr/local} |
|
29 exec_prefix=${exec_prefix-'${prefix}'} |
|
30 libdir=${libdir-'${exec_prefix}/lib'} |
|
31 includedir=${includedir-'${prefix}/include'} |
|
32 mandir=${mandir-'${prefix}/share/man'} |
|
33 shared_ext='.so' |
|
34 shared=0 |
|
35 gcc=0 |
|
36 old_cc="$CC" |
|
37 old_cflags="$CFLAGS" |
|
38 |
|
39 while test $# -ge 1 |
|
40 do |
|
41 case "$1" in |
|
42 -h* | --h*) |
|
43 echo 'usage:' |
|
44 echo ' configure [--shared] [--prefix=PREFIX] [--exec_prefix=EXPREFIX]' |
|
45 echo ' [--libdir=LIBDIR] [--includedir=INCLUDEDIR]' |
|
46 exit 0;; |
|
47 -p*=* | --p*=*) prefix=`echo $1 | sed 's/[-a-z_]*=//'`; shift;; |
|
48 -e*=* | --e*=*) exec_prefix=`echo $1 | sed 's/[-a-z_]*=//'`; shift;; |
|
49 -l*=* | --libdir=*) libdir=`echo $1 | sed 's/[-a-z_]*=//'`; shift;; |
|
50 -i*=* | --includedir=*) includedir=`echo $1 | sed 's/[-a-z_]*=//'`;shift;; |
|
51 -p* | --p*) prefix="$2"; shift; shift;; |
|
52 -e* | --e*) exec_prefix="$2"; shift; shift;; |
|
53 -l* | --l*) libdir="$2"; shift; shift;; |
|
54 -i* | --i*) includedir="$2"; shift; shift;; |
|
55 -s* | --s*) shared=1; shift;; |
|
56 *) echo "unknown option: $1"; echo "$0 --help for help"; exit 1;; |
|
57 esac |
|
58 done |
|
59 |
|
60 test=ztest$$ |
|
61 cat > $test.c <<EOF |
|
62 extern int getchar(); |
|
63 int hello() {return getchar();} |
|
64 EOF |
|
65 |
|
66 test -z "$CC" && echo Checking for gcc... |
|
67 cc=${CC-gcc} |
|
68 cflags=${CFLAGS-"-O3"} |
|
69 # to force the asm version use: CFLAGS="-O3 -DASMV" ./configure |
|
70 case "$cc" in |
|
71 *gcc*) gcc=1;; |
|
72 esac |
|
73 |
|
74 if test "$gcc" -eq 1 && ($cc -c $cflags $test.c) 2>/dev/null; then |
|
75 CC="$cc" |
|
76 SFLAGS=${CFLAGS-"-fPIC -O3"} |
|
77 CFLAGS="$cflags" |
|
78 case `(uname -s || echo unknown) 2>/dev/null` in |
|
79 Linux | linux | GNU | GNU/*) LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1"};; |
|
80 CYGWIN* | Cygwin* | cygwin* | OS/2* ) |
|
81 EXE='.exe';; |
|
82 QNX*) # This is for QNX6. I suppose that the QNX rule below is for QNX2,QNX4 |
|
83 # (alain.bonnefoy@icbt.com) |
|
84 LDSHARED=${LDSHARED-"$cc -shared -Wl,-hlibz.so.1"};; |
|
85 HP-UX*) |
|
86 LDSHARED=${LDSHARED-"$cc -shared $SFLAGS"} |
|
87 case `(uname -m || echo unknown) 2>/dev/null` in |
|
88 ia64) |
|
89 shared_ext='.so' |
|
90 SHAREDLIB='libz.so';; |
|
91 *) |
|
92 shared_ext='.sl' |
|
93 SHAREDLIB='libz.sl';; |
|
94 esac;; |
|
95 Darwin*) shared_ext='.dylib' |
|
96 SHAREDLIB=libz$shared_ext |
|
97 SHAREDLIBV=libz.$VER$shared_ext |
|
98 SHAREDLIBM=libz.$VER1$shared_ext |
|
99 LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBM -compatibility_version $VER1 -current_version $VER"};; |
|
100 *) LDSHARED=${LDSHARED-"$cc -shared"};; |
|
101 esac |
|
102 else |
|
103 # find system name and corresponding cc options |
|
104 CC=${CC-cc} |
|
105 case `(uname -sr || echo unknown) 2>/dev/null` in |
|
106 HP-UX*) SFLAGS=${CFLAGS-"-O +z"} |
|
107 CFLAGS=${CFLAGS-"-O"} |
|
108 # LDSHARED=${LDSHARED-"ld -b +vnocompatwarnings"} |
|
109 LDSHARED=${LDSHARED-"ld -b"} |
|
110 case `(uname -m || echo unknown) 2>/dev/null` in |
|
111 ia64) |
|
112 shared_ext='.so' |
|
113 SHAREDLIB='libz.so';; |
|
114 *) |
|
115 shared_ext='.sl' |
|
116 SHAREDLIB='libz.sl';; |
|
117 esac;; |
|
118 IRIX*) SFLAGS=${CFLAGS-"-ansi -O2 -rpath ."} |
|
119 CFLAGS=${CFLAGS-"-ansi -O2"} |
|
120 LDSHARED=${LDSHARED-"cc -shared"};; |
|
121 OSF1\ V4*) SFLAGS=${CFLAGS-"-O -std1"} |
|
122 CFLAGS=${CFLAGS-"-O -std1"} |
|
123 LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so -Wl,-msym -Wl,-rpath,$(libdir) -Wl,-set_version,${VER}:1.0"};; |
|
124 OSF1*) SFLAGS=${CFLAGS-"-O -std1"} |
|
125 CFLAGS=${CFLAGS-"-O -std1"} |
|
126 LDSHARED=${LDSHARED-"cc -shared"};; |
|
127 QNX*) SFLAGS=${CFLAGS-"-4 -O"} |
|
128 CFLAGS=${CFLAGS-"-4 -O"} |
|
129 LDSHARED=${LDSHARED-"cc"} |
|
130 RANLIB=${RANLIB-"true"} |
|
131 AR="cc -A";; |
|
132 SCO_SV\ 3.2*) SFLAGS=${CFLAGS-"-O3 -dy -KPIC "} |
|
133 CFLAGS=${CFLAGS-"-O3"} |
|
134 LDSHARED=${LDSHARED-"cc -dy -KPIC -G"};; |
|
135 SunOS\ 5*) SFLAGS=${CFLAGS-"-fast -xcg89 -KPIC -R."} |
|
136 CFLAGS=${CFLAGS-"-fast -xcg89"} |
|
137 LDSHARED=${LDSHARED-"cc -G"};; |
|
138 SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"} |
|
139 CFLAGS=${CFLAGS-"-O2"} |
|
140 LDSHARED=${LDSHARED-"ld"};; |
|
141 SunStudio\ 9*) SFLAGS=${CFLAGS-"-DUSE_MMAP -fast -xcode=pic32 -xtarget=ultra3 -xarch=v9b"} |
|
142 CFLAGS=${CFLAGS-"-DUSE_MMAP -fast -xtarget=ultra3 -xarch=v9b"} |
|
143 LDSHARED=${LDSHARED-"cc -xarch=v9b"};; |
|
144 UNIX_System_V\ 4.2.0) |
|
145 SFLAGS=${CFLAGS-"-KPIC -O"} |
|
146 CFLAGS=${CFLAGS-"-O"} |
|
147 LDSHARED=${LDSHARED-"cc -G"};; |
|
148 UNIX_SV\ 4.2MP) |
|
149 SFLAGS=${CFLAGS-"-Kconform_pic -O"} |
|
150 CFLAGS=${CFLAGS-"-O"} |
|
151 LDSHARED=${LDSHARED-"cc -G"};; |
|
152 OpenUNIX\ 5) |
|
153 SFLAGS=${CFLAGS-"-KPIC -O"} |
|
154 CFLAGS=${CFLAGS-"-O"} |
|
155 LDSHARED=${LDSHARED-"cc -G"};; |
|
156 AIX*) # Courtesy of dbakker@arrayasolutions.com |
|
157 SFLAGS=${CFLAGS-"-O -qmaxmem=8192"} |
|
158 CFLAGS=${CFLAGS-"-O -qmaxmem=8192"} |
|
159 LDSHARED=${LDSHARED-"xlc -G"};; |
|
160 # send working options for other systems to support@gzip.org |
|
161 *) SFLAGS=${CFLAGS-"-O"} |
|
162 CFLAGS=${CFLAGS-"-O"} |
|
163 LDSHARED=${LDSHARED-"cc -shared"};; |
|
164 esac |
|
165 fi |
|
166 |
|
167 SHAREDLIB=${SHAREDLIB-"libz$shared_ext"} |
|
168 SHAREDLIBV=${SHAREDLIBV-"libz$shared_ext.$VER"} |
|
169 SHAREDLIBM=${SHAREDLIBM-"libz$shared_ext.$VER1"} |
|
170 |
|
171 if test $shared -eq 1; then |
|
172 echo Checking for shared library support... |
|
173 # we must test in two steps (cc then ld), required at least on SunOS 4.x |
|
174 if test "`($CC -c $SFLAGS $test.c) 2>&1`" = "" && |
|
175 test "`($LDSHARED -o $test$shared_ext $test.o) 2>&1`" = ""; then |
|
176 CFLAGS="$SFLAGS" |
|
177 LIBS="$SHAREDLIBV" |
|
178 echo Building shared library $SHAREDLIBV with $CC. |
|
179 elif test -z "$old_cc" -a -z "$old_cflags"; then |
|
180 echo No shared library support. |
|
181 shared=0; |
|
182 else |
|
183 echo 'No shared library support; try without defining CC and CFLAGS' |
|
184 shared=0; |
|
185 fi |
|
186 fi |
|
187 if test $shared -eq 0; then |
|
188 LDSHARED="$CC" |
|
189 echo Building static library $LIBS version $VER with $CC. |
|
190 else |
|
191 LDFLAGS="-L. ${SHAREDLIBV}" |
|
192 fi |
|
193 |
|
194 cat > $test.c <<EOF |
|
195 #include <unistd.h> |
|
196 int main() { return 0; } |
|
197 EOF |
|
198 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then |
|
199 sed < zconf.in.h "/HAVE_UNISTD_H/s%0%1%" > zconf.h |
|
200 echo "Checking for unistd.h... Yes." |
|
201 else |
|
202 cp -p zconf.in.h zconf.h |
|
203 echo "Checking for unistd.h... No." |
|
204 fi |
|
205 |
|
206 cat > $test.c <<EOF |
|
207 #include <stdio.h> |
|
208 #include <stdarg.h> |
|
209 #include "zconf.h" |
|
210 |
|
211 int main() |
|
212 { |
|
213 #ifndef STDC |
|
214 choke me |
|
215 #endif |
|
216 |
|
217 return 0; |
|
218 } |
|
219 EOF |
|
220 |
|
221 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then |
|
222 echo "Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf()" |
|
223 |
|
224 cat > $test.c <<EOF |
|
225 #include <stdio.h> |
|
226 #include <stdarg.h> |
|
227 |
|
228 int mytest(char *fmt, ...) |
|
229 { |
|
230 char buf[20]; |
|
231 va_list ap; |
|
232 |
|
233 va_start(ap, fmt); |
|
234 vsnprintf(buf, sizeof(buf), fmt, ap); |
|
235 va_end(ap); |
|
236 return 0; |
|
237 } |
|
238 |
|
239 int main() |
|
240 { |
|
241 return (mytest("Hello%d\n", 1)); |
|
242 } |
|
243 EOF |
|
244 |
|
245 if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then |
|
246 echo "Checking for vsnprintf() in stdio.h... Yes." |
|
247 |
|
248 cat >$test.c <<EOF |
|
249 #include <stdio.h> |
|
250 #include <stdarg.h> |
|
251 |
|
252 int mytest(char *fmt, ...) |
|
253 { |
|
254 int n; |
|
255 char buf[20]; |
|
256 va_list ap; |
|
257 |
|
258 va_start(ap, fmt); |
|
259 n = vsnprintf(buf, sizeof(buf), fmt, ap); |
|
260 va_end(ap); |
|
261 return n; |
|
262 } |
|
263 |
|
264 int main() |
|
265 { |
|
266 return (mytest("Hello%d\n", 1)); |
|
267 } |
|
268 EOF |
|
269 |
|
270 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then |
|
271 echo "Checking for return value of vsnprintf()... Yes." |
|
272 else |
|
273 CFLAGS="$CFLAGS -DHAS_vsnprintf_void" |
|
274 echo "Checking for return value of vsnprintf()... No." |
|
275 echo " WARNING: apparently vsnprintf() does not return a value. zlib" |
|
276 echo " can build but will be open to possible string-format security" |
|
277 echo " vulnerabilities." |
|
278 fi |
|
279 else |
|
280 CFLAGS="$CFLAGS -DNO_vsnprintf" |
|
281 echo "Checking for vsnprintf() in stdio.h... No." |
|
282 echo " WARNING: vsnprintf() not found, falling back to vsprintf(). zlib" |
|
283 echo " can build but will be open to possible buffer-overflow security" |
|
284 echo " vulnerabilities." |
|
285 |
|
286 cat >$test.c <<EOF |
|
287 #include <stdio.h> |
|
288 #include <stdarg.h> |
|
289 |
|
290 int mytest(char *fmt, ...) |
|
291 { |
|
292 int n; |
|
293 char buf[20]; |
|
294 va_list ap; |
|
295 |
|
296 va_start(ap, fmt); |
|
297 n = vsprintf(buf, fmt, ap); |
|
298 va_end(ap); |
|
299 return n; |
|
300 } |
|
301 |
|
302 int main() |
|
303 { |
|
304 return (mytest("Hello%d\n", 1)); |
|
305 } |
|
306 EOF |
|
307 |
|
308 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then |
|
309 echo "Checking for return value of vsprintf()... Yes." |
|
310 else |
|
311 CFLAGS="$CFLAGS -DHAS_vsprintf_void" |
|
312 echo "Checking for return value of vsprintf()... No." |
|
313 echo " WARNING: apparently vsprintf() does not return a value. zlib" |
|
314 echo " can build but will be open to possible string-format security" |
|
315 echo " vulnerabilities." |
|
316 fi |
|
317 fi |
|
318 else |
|
319 echo "Checking whether to use vs[n]printf() or s[n]printf()... using s[n]printf()" |
|
320 |
|
321 cat >$test.c <<EOF |
|
322 #include <stdio.h> |
|
323 |
|
324 int mytest() |
|
325 { |
|
326 char buf[20]; |
|
327 |
|
328 snprintf(buf, sizeof(buf), "%s", "foo"); |
|
329 return 0; |
|
330 } |
|
331 |
|
332 int main() |
|
333 { |
|
334 return (mytest()); |
|
335 } |
|
336 EOF |
|
337 |
|
338 if test "`($CC $CFLAGS -o $test $test.c) 2>&1`" = ""; then |
|
339 echo "Checking for snprintf() in stdio.h... Yes." |
|
340 |
|
341 cat >$test.c <<EOF |
|
342 #include <stdio.h> |
|
343 |
|
344 int mytest() |
|
345 { |
|
346 char buf[20]; |
|
347 |
|
348 return snprintf(buf, sizeof(buf), "%s", "foo"); |
|
349 } |
|
350 |
|
351 int main() |
|
352 { |
|
353 return (mytest()); |
|
354 } |
|
355 EOF |
|
356 |
|
357 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then |
|
358 echo "Checking for return value of snprintf()... Yes." |
|
359 else |
|
360 CFLAGS="$CFLAGS -DHAS_snprintf_void" |
|
361 echo "Checking for return value of snprintf()... No." |
|
362 echo " WARNING: apparently snprintf() does not return a value. zlib" |
|
363 echo " can build but will be open to possible string-format security" |
|
364 echo " vulnerabilities." |
|
365 fi |
|
366 else |
|
367 CFLAGS="$CFLAGS -DNO_snprintf" |
|
368 echo "Checking for snprintf() in stdio.h... No." |
|
369 echo " WARNING: snprintf() not found, falling back to sprintf(). zlib" |
|
370 echo " can build but will be open to possible buffer-overflow security" |
|
371 echo " vulnerabilities." |
|
372 |
|
373 cat >$test.c <<EOF |
|
374 #include <stdio.h> |
|
375 |
|
376 int mytest() |
|
377 { |
|
378 char buf[20]; |
|
379 |
|
380 return sprintf(buf, "%s", "foo"); |
|
381 } |
|
382 |
|
383 int main() |
|
384 { |
|
385 return (mytest()); |
|
386 } |
|
387 EOF |
|
388 |
|
389 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then |
|
390 echo "Checking for return value of sprintf()... Yes." |
|
391 else |
|
392 CFLAGS="$CFLAGS -DHAS_sprintf_void" |
|
393 echo "Checking for return value of sprintf()... No." |
|
394 echo " WARNING: apparently sprintf() does not return a value. zlib" |
|
395 echo " can build but will be open to possible string-format security" |
|
396 echo " vulnerabilities." |
|
397 fi |
|
398 fi |
|
399 fi |
|
400 |
|
401 cat >$test.c <<EOF |
|
402 #include <errno.h> |
|
403 int main() { return 0; } |
|
404 EOF |
|
405 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then |
|
406 echo "Checking for errno.h... Yes." |
|
407 else |
|
408 echo "Checking for errno.h... No." |
|
409 CFLAGS="$CFLAGS -DNO_ERRNO_H" |
|
410 fi |
|
411 |
|
412 cat > $test.c <<EOF |
|
413 #include <sys/types.h> |
|
414 #include <sys/mman.h> |
|
415 #include <sys/stat.h> |
|
416 caddr_t hello() { |
|
417 return mmap((caddr_t)0, (off_t)0, PROT_READ, MAP_SHARED, 0, (off_t)0); |
|
418 } |
|
419 EOF |
|
420 if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then |
|
421 CFLAGS="$CFLAGS -DUSE_MMAP" |
|
422 echo Checking for mmap support... Yes. |
|
423 else |
|
424 echo Checking for mmap support... No. |
|
425 fi |
|
426 |
|
427 CPP=${CPP-"$CC -E"} |
|
428 case $CFLAGS in |
|
429 *ASMV*) |
|
430 if test "`nm $test.o | grep _hello`" = ""; then |
|
431 CPP="$CPP -DNO_UNDERLINE" |
|
432 echo Checking for underline in external names... No. |
|
433 else |
|
434 echo Checking for underline in external names... Yes. |
|
435 fi;; |
|
436 esac |
|
437 |
|
438 rm -f $test.[co] $test $test$shared_ext |
|
439 |
|
440 # udpate Makefile |
|
441 sed < Makefile.in " |
|
442 /^CC *=/s#=.*#=$CC# |
|
443 /^CFLAGS *=/s#=.*#=$CFLAGS# |
|
444 /^CPP *=/s#=.*#=$CPP# |
|
445 /^LDSHARED *=/s#=.*#=$LDSHARED# |
|
446 /^LIBS *=/s#=.*#=$LIBS# |
|
447 /^SHAREDLIB *=/s#=.*#=$SHAREDLIB# |
|
448 /^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV# |
|
449 /^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM# |
|
450 /^AR *=/s#=.*#=$AR# |
|
451 /^RANLIB *=/s#=.*#=$RANLIB# |
|
452 /^EXE *=/s#=.*#=$EXE# |
|
453 /^prefix *=/s#=.*#=$prefix# |
|
454 /^exec_prefix *=/s#=.*#=$exec_prefix# |
|
455 /^libdir *=/s#=.*#=$libdir# |
|
456 /^includedir *=/s#=.*#=$includedir# |
|
457 /^mandir *=/s#=.*#=$mandir# |
|
458 /^LDFLAGS *=/s#=.*#=$LDFLAGS# |
|
459 " > Makefile |