Adam Tkac | fded078 | 2008-03-22 11:20:54 +0000 | [diff] [blame] | 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 | *) shift;; |
| 54 | esac |
| 55 | done |
| 56 | |
| 57 | test=ztest$$ |
| 58 | cat > $test.c <<EOF |
| 59 | extern int getchar(); |
| 60 | int hello() {return getchar();} |
| 61 | EOF |
| 62 | |
| 63 | test -z "$CC" && echo Checking for gcc... |
| 64 | cc=${CC-gcc} |
| 65 | cflags=${CFLAGS-"-O3"} |
| 66 | # to force the asm version use: CFLAGS="-O3 -DASMV" ./configure |
| 67 | case "$cc" in |
| 68 | *gcc*) gcc=1;; |
| 69 | esac |
| 70 | |
| 71 | if 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 |
| 79 | else |
| 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 |
| 125 | fi |
| 126 | |
| 127 | if 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 |
| 142 | fi |
| 143 | if test $shared -eq 0; then |
| 144 | LDSHARED="$CC" |
| 145 | echo Building static library $LIBS version $VER with $CC. |
| 146 | fi |
| 147 | |
| 148 | cat > $test.c <<EOF |
| 149 | #include <unistd.h> |
| 150 | int main() { return 0; } |
| 151 | EOF |
| 152 | if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then |
| 153 | CFLAGS="$CFLAGS -DHAVE_UNISTD_H" |
| 154 | echo "Checking for unistd.h... Yes." |
| 155 | else |
| 156 | echo "Checking for unistd.h... No." |
| 157 | fi |
| 158 | |
| 159 | cat > $test.c <<EOF |
| 160 | #include <errno.h> |
| 161 | int main() { return 0; } |
| 162 | EOF |
| 163 | if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then |
| 164 | echo "Checking for errno.h... Yes." |
Adam Tkac | a6d64cb | 2008-03-27 18:13:28 +0000 | [diff] [blame] | 165 | CFLAGS="$CFLAGS -DHAVE_ERRNO_H" |
Adam Tkac | fded078 | 2008-03-22 11:20:54 +0000 | [diff] [blame] | 166 | else |
| 167 | echo "Checking for errno.h... No." |
Adam Tkac | fded078 | 2008-03-22 11:20:54 +0000 | [diff] [blame] | 168 | fi |
| 169 | |
| 170 | cat > $test.c <<EOF |
| 171 | #include <sys/types.h> |
| 172 | #include <sys/mman.h> |
| 173 | #include <sys/stat.h> |
| 174 | caddr_t hello() { |
| 175 | return mmap((caddr_t)0, (off_t)0, PROT_READ, MAP_SHARED, 0, (off_t)0); |
| 176 | } |
| 177 | EOF |
| 178 | if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then |
Adam Tkac | a6d64cb | 2008-03-27 18:13:28 +0000 | [diff] [blame] | 179 | CFLAGS="$CFLAGS -DHAVE_MMAP" |
Adam Tkac | fded078 | 2008-03-22 11:20:54 +0000 | [diff] [blame] | 180 | echo Checking for mmap support... Yes. |
| 181 | else |
| 182 | echo Checking for mmap support... No. |
| 183 | fi |
| 184 | |
| 185 | CPP=${CPP-"$CC -E"} |
| 186 | case $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;; |
| 194 | esac |
| 195 | |
| 196 | rm -f $test.[co] $test$shared_ext |
| 197 | |
| 198 | # udpate Makefile |
| 199 | sed < 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 |