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