blob: a19ff2e80dfac4497ef4f5e3ca9437e31333aba6 [file] [log] [blame]
Adam Tkacfded0782008-03-22 11:20:54 +00001#!/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
21LIBS=libz.a
22SHAREDLIB=libz.so
23VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`
24AR=${AR-"ar rc"}
25RANLIB=${RANLIB-"ranlib"}
26prefix=${prefix-/usr/local}
27exec_prefix=${exec_prefix-'${prefix}'}
28libdir=${libdir-'${exec_prefix}/lib'}
29includedir=${includedir-'${prefix}/include'}
30shared_ext='.so'
31shared=0
32gcc=0
33old_cc="$CC"
34old_cflags="$CFLAGS"
35
36while test $# -ge 1
37do
38case "$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 *) shift;;
54 esac
55done
56
57test=ztest$$
58cat > $test.c <<EOF
59extern int getchar();
60int hello() {return getchar();}
61EOF
62
63test -z "$CC" && echo Checking for gcc...
64cc=${CC-gcc}
65cflags=${CFLAGS-"-O3"}
66# to force the asm version use: CFLAGS="-O3 -DASMV" ./configure
67case "$cc" in
68 *gcc*) gcc=1;;
69esac
70
71if test "$gcc" -eq 1 && ($cc -c $cflags $test.c) 2>/dev/null; then
72 CC="$cc"
73 SFLAGS=${CFLAGS-"-fPIC -O3"}
74 CFLAGS="$cflags"
75 case `(uname -s || echo unknown) 2>/dev/null` in
76 Linux | linux) LDSHARED=${LDSHARED-"gcc -shared -Wl,-soname,libz.so.1"};;
77 *) LDSHARED=${LDSHARED-"gcc -shared"};;
78 esac
79else
80 # find system name and corresponding cc options
81 CC=${CC-cc}
82 case `(uname -sr || echo unknown) 2>/dev/null` in
83 HP-UX*) SFLAGS=${CFLAGS-"-O +z"}
84 CFLAGS=${CFLAGS-"-O"}
85# LDSHARED=${LDSHARED-"ld -b +vnocompatwarnings"}
86 LDSHARED=${LDSHARED-"ld -b"}
87 shared_ext='.sl'
88 SHAREDLIB='libz.sl';;
89 IRIX*) SFLAGS=${CFLAGS-"-ansi -O2 -rpath ."}
90 CFLAGS=${CFLAGS-"-ansi -O2"}
91 LDSHARED=${LDSHARED-"cc -shared"};;
92 OSF1\ V4*) SFLAGS=${CFLAGS-"-O -std1"}
93 CFLAGS=${CFLAGS-"-O -std1"}
94 LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,$SHAREDLIB -Wl,-msym -Wl,-rpath,$(libdir) -Wl,-set_version,${VER}:1.0"};;
95 OSF1*) SFLAGS=${CFLAGS-"-O -std1"}
96 CFLAGS=${CFLAGS-"-O -std1"}
97 LDSHARED=${LDSHARED-"cc -shared"};;
98 QNX*) SFLAGS=${CFLAGS-"-4 -O"}
99 CFLAGS=${CFLAGS-"-4 -O"}
100 LDSHARED=${LDSHARED-"cc"}
101 RANLIB=${RANLIB-"true"}
102 AR="cc -A";;
103 SCO_SV\ 3.2*) SFLAGS=${CFLAGS-"-O3 -dy -KPIC "}
104 CFLAGS=${CFLAGS-"-O3"}
105 LDSHARED=${LDSHARED-"cc -dy -KPIC -G"};;
106 SunOS\ 5*) SFLAGS=${CFLAGS-"-fast -xcg89 -KPIC -R."}
107 CFLAGS=${CFLAGS-"-fast -xcg89"}
108 LDSHARED=${LDSHARED-"cc -G"};;
109 SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"}
110 CFLAGS=${CFLAGS-"-O2"}
111 LDSHARED=${LDSHARED-"ld"};;
112 UNIX_System_V\ 4.2.0)
113 SFLAGS=${CFLAGS-"-KPIC -O"}
114 CFLAGS=${CFLAGS-"-O"}
115 LDSHARED=${LDSHARED-"cc -G"};;
116 UNIX_SV\ 4.2MP)
117 SFLAGS=${CFLAGS-"-Kconform_pic -O"}
118 CFLAGS=${CFLAGS-"-O"}
119 LDSHARED=${LDSHARED-"cc -G"};;
120 # send working options for other systems to support@gzip.org
121 *) SFLAGS=${CFLAGS-"-O"}
122 CFLAGS=${CFLAGS-"-O"}
123 LDSHARED=${LDSHARED-"cc -shared"};;
124 esac
125fi
126
127if test $shared -eq 1; then
128 echo Checking for shared library support...
129 # we must test in two steps (cc then ld), required at least on SunOS 4.x
130 if test "`($CC -c $SFLAGS $test.c) 2>&1`" = "" &&
131 test "`($LDSHARED -o $test$shared_ext $test.o) 2>&1`" = ""; then
132 CFLAGS="$SFLAGS"
133 LIBS="$SHAREDLIB.$VER"
134 echo Building shared library $SHAREDLIB.$VER with $CC.
135 elif test -z "$old_cc" -a -z "$old_cflags"; then
136 echo No shared library suppport.
137 shared=0;
138 else
139 echo 'No shared library suppport; try without defining CC and CFLAGS'
140 shared=0;
141 fi
142fi
143if test $shared -eq 0; then
144 LDSHARED="$CC"
145 echo Building static library $LIBS version $VER with $CC.
146fi
147
148cat > $test.c <<EOF
149#include <unistd.h>
150int main() { return 0; }
151EOF
152if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
153 CFLAGS="$CFLAGS -DHAVE_UNISTD_H"
154 echo "Checking for unistd.h... Yes."
155else
156 echo "Checking for unistd.h... No."
157fi
158
159cat > $test.c <<EOF
160#include <errno.h>
161int main() { return 0; }
162EOF
163if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
164 echo "Checking for errno.h... Yes."
Adam Tkaca6d64cb2008-03-27 18:13:28 +0000165 CFLAGS="$CFLAGS -DHAVE_ERRNO_H"
Adam Tkacfded0782008-03-22 11:20:54 +0000166else
167 echo "Checking for errno.h... No."
Adam Tkacfded0782008-03-22 11:20:54 +0000168fi
169
170cat > $test.c <<EOF
171#include <sys/types.h>
172#include <sys/mman.h>
173#include <sys/stat.h>
174caddr_t hello() {
175 return mmap((caddr_t)0, (off_t)0, PROT_READ, MAP_SHARED, 0, (off_t)0);
176}
177EOF
178if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
Adam Tkaca6d64cb2008-03-27 18:13:28 +0000179 CFLAGS="$CFLAGS -DHAVE_MMAP"
Adam Tkacfded0782008-03-22 11:20:54 +0000180 echo Checking for mmap support... Yes.
181else
182 echo Checking for mmap support... No.
183fi
184
185CPP=${CPP-"$CC -E"}
186case $CFLAGS in
187 *ASMV*)
188 if test "`nm $test.o | grep _hello`" = ""; then
189 CPP="$CPP -DNO_UNDERLINE"
190 echo Checking for underline in external names... No.
191 else
192 echo Checking for underline in external names... Yes.
193 fi;;
194esac
195
196rm -f $test.[co] $test$shared_ext
197
198# udpate Makefile
199sed < Makefile.in "
200/^CC *=/s%=.*%=$CC%
201/^CFLAGS *=/s%=.*%=$CFLAGS%
202/^CPP *=/s%=.*%=$CPP%
203/^LDSHARED *=/s%=.*%=$LDSHARED%
204/^LIBS *=/s%=.*%=$LIBS%
205/^SHAREDLIB *=/s%=.*%=$SHAREDLIB%
206/^AR *=/s%=.*%=$AR%
207/^RANLIB *=/s%=.*%=$RANLIB%
208/^VER *=/s%=.*%=$VER%
209/^prefix *=/s%=.*%=$prefix%
210/^exec_prefix *=/s%=.*%=$exec_prefix%
211/^libdir *=/s%=.*%=$libdir%
212/^includedir *=/s%=.*%=$includedir%
213" > Makefile