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