1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
|
#!/bin/sh
#--------------------------------------------------------------------------#
usage() {
echo "usage: configure [--prefix=<dir>][--debug]"
echo ""
echo " --prefix=<dir> specify installation prefix"
echo " --debug enable internal debugging of library"
echo
cat <<EOF
The environment variable 'CC' may be used to specify the preferred C
compiler. For example if you use a Bourne shell you could say
CC=cc ./configure
to overwrite the default C compiler search list, which is 'gcc cc'.
Similarly the environment variable CXX can be used to speficy a list of C++
compilers, for which we build special object files. Here the default search
list is 'g++ gcc CC'.
EOF
}
#--------------------------------------------------------------------------#
# setup default values
#
fmt="%-26s ..."
debug=no
prefix=/usr/local
os=unsupported
libc="libc.so"
#--------------------------------------------------------------------------#
# process command line options
#
while [ $# -gt 0 ]
do
case $1 in
-h | --help | -?)
usage
exit 0
;;
--prefix=*)
prefix=`expr $1 : '--prefix=\(.*\)'`
;;
--debug)
debug=yes
;;
*)
echo "*** configure: unknown command line option (try '-h')" 1>&2
exit 1
;;
esac
shift
done
#--------------------------------------------------------------------------#
# get version
#
printf "$fmt" "version"
version=`cat VERSION`
echo " $version"
#--------------------------------------------------------------------------#
# check if OS is supported
#
printf "$fmt" "system"
case `uname` in
SunOS )
case `uname -r` in
5.* )
os=solaris
;;
esac
;;
Linux )
os=linux
;;
esac
if [ $os = unsupported ]
then
echo
echo "*** configure: unsupported operating system" 1>&2
exit 1
fi
echo " $os"
#--------------------------------------------------------------------------#
# search for C compilers
printf "$fmt" "C compiler"
if [ "$CC" ]; then searchlist="$CC"; else searchlist="gcc cc"; fi
CC=""
compilers=""
for cc in $searchlist
do
for dir in `echo $PATH | sed -e 's,:, ,g'`
do
if [ -f $dir/$cc ]
then
[ "$CC" ] || CC="$cc"
[ "$compilers" ] && compilers="$compilers "
compilers="${compilers}$cc"
break
fi
done
done
if [ "$CC" ]
then
case $CC in
gcc) CFLAGS="-g -Wall";;
cc) CFLAGS="-g -W";;
*) CFLAGS="-g";;
esac
echo " $CC $CFLAGS"
else
echo
echo "*** configure: no C compiler found" 1>&2
exit 1
fi
#--------------------------------------------------------------------------#
# search for C++ compilers
printf "$fmt" "C++ compilers"
if [ "$CXX" ]; then searchlist="$CXX"; else searchlist="g++ gcc CC"; fi
COMPILERS=""
for cc in $searchlist
do
for dir in `echo $PATH | sed -e 's,:, ,g'`
do
if [ -f $dir/$cc ]
then
[ "$COMPILERS" ] && COMPILERS="$COMPILERS "
COMPILERS="${COMPILERS}$cc"
break
fi
done
done
if [ "$COMPILERS" ]
then
echo " $COMPILERS"
else
echo
echo "*** configure: no C++ compiler found" 1>&2
exit 1
fi
for cc in $COMPILERS
do
[ $cc = CC ] && \
echo "*** warning: CC as C++ compiler does not work properly yet" 1>&2
done
#--------------------------------------------------------------------------#
# check if installation directory exists
#
printf "$fmt" "prefix"
case "$prefix" in
/*)
;;
*)
echo
echo "*** configure: prefix '$prefix' is no absolute path name" 1>&2
exit 1
;;
esac
echo " $prefix"
#--------------------------------------------------------------------------#
# searching for real libc
printf "$fmt" "libc"
canfopen() {
tmp=/tmp/configure-ccmalloc-$$
dir=`pwd`
mkdir /tmp/configure-ccmalloc-$$ || exit 1
cd $tmp
rm -f main.c
cat <<EOF >main.c
#include <stdio.h>
#include <dlfcn.h>
#include <stdlib.h>
int main(int arc, char **argv)
{
int bl;
const char * str;
void * handle = dlopen(argv[1], RTLD_NOW);
if((str = dlerror()) != NULL) fprintf(stderr, "*** %s\n", str);
exit(str != NULL);
}
EOF
if $CC main.c -ldl 1>/dev/null 2>/dev/null
then
if ./a.out $1 1>/dev/null 2>/dev/null; then libc=$1; fi
fi
cd $dir
rm -rf $tmp
}
libc=notfound
for name in libc.so \
/lib/libc.so /usr/lib/libc.so /lib/libc.so.6* /usr/lib/libc.so.6*
do
canfopen $name
[ $libc = notfound ] || break
done
if [ $libc = notfound ]
then
echo
echo "*** configure: could not find 'libc.so'" 1>&2
exit 1
fi
echo " $libc"
#--------------------------------------------------------------------------#
printf "$fmt" "setting up directories"
for d in obj lib bin
do
if [ ! -d $d ]; then mkdir $d; fi
done
echo " done"
#--------------------------------------------------------------------------#
#
printf "$fmt" "generating src/config.h"
rm -f src/config.h
(
echo "#ifndef _config_h_INCLUDED"
[ $debug = no ] && echo "#define NDEBUG"
[ $os = solaris ] && echo "#define OS_IS_SOLARIS"
[ $os = linux ] && echo "#define OS_IS_LINUX"
cat<<-EOF
#define VERSION "$version"
#define NAME_OF_LIBC "$libc"
#if defined(OS_IS_LINUX) || defined(OS_IS_SOLARIS)
#define CAN_GET_ARGV0
#endif
#endif /* _config_h_INCLUDED */
EOF
) > src/config.h
echo " done"
#--------------------------------------------------------------------------#
#
dst=Makefile
printf "$fmt" "generation $dst"
TARGETS=""
for cc in $COMPILERS
do
[ "$TARGETS" ] && TARGETS="$TARGETS "
TARGETS="$TARGETS obj/ccmalloc-${cc}.o"
done
rm -f $dst
sed \
-e "s,@PREFIX@,$prefix,g" \
-e "s,@CC@,$CC,g" \
-e "s,@CFLAGS@,$CFLAGS,g" \
-e "s,@COMPILERS@,$COMPILERS,g" \
-e "s,@TARGETS@,$TARGETS,g" \
Makefile.in > $dst
echo >> $dst
cat >>Makefile<<EOF
#-------------------------------------------------------------------------#
# automatically generated goals for C++ static initializers
#
EOF
for cc in $COMPILERS
do
case $cc in
CC*)
CXXFLAGS="-g -noex"
;;
*)
CXXFLAGS="-g"
;;
esac
echo \
"obj/ccmalloc-${cc}.o: src/ccmalloc.cc src/config.h src/ccmalloc.h" \
>> $dst
echo " $cc -DCTORDTOR $CXXFLAGS -c -o \$@ src/ccmalloc.cc" >> $dst
echo >> $dst
done
cat >>Makefile<<EOF
#-------------------------------------------------------------------------#
install: all
./util/install bin/ccmalloc \$(PREFIX)/bin
./util/install lib/libccmalloc.a \$(PREFIX)/lib
./util/install ccmalloc.cfg \$(PREFIX)/share/ccmalloc
EOF
for cc in $COMPILERS
do
echo " ./util/install obj/ccmalloc-${cc}.o \$(PREFIX)/lib" >> $dst
done
echo " done"
|