File: configure

package info (click to toggle)
ccmalloc 0.4.0-9
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 488 kB
  • ctags: 446
  • sloc: ansic: 4,493; sh: 523; makefile: 105; cpp: 89
file content (377 lines) | stat: -rwxr-xr-x 7,418 bytes parent folder | download
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
#!/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

#--------------------------------------------------------------------------#
# 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 | GNU/kFreeBSD )
    os=linux
    ;;
  FreeBSD )
    os=freebsd
    ;;
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

tmp=/tmp/configure-ccmalloc-findlibc-$$
dir=`pwd`
mkdir /tmp/configure-ccmalloc-findlibc-$$ || 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

case $os in
  freebsd )
    LIB=""
    ;;
  * )
    LIB="-ldl"
    ;;
esac

libc=notfound
if $CC main.c $LIB 1>/dev/null 2>/dev/null
then
  libc="`ldd ./a.out | awk '/libc/{print $3}'`"
  if ./a.out "$libc" 1>/dev/null 2>/dev/null
  then 
    libc="$libc"
  else
    libc=notfound
  fi
fi
cd $dir
rm -rf $tmp

if [ "$libc" = notfound ]
then
  echo
  echo "*** configure: could not find 'libc.so'" 1>&2
  exit 1
fi

echo " $libc"

#--------------------------------------------------------------------------#

printf "$fmt" atexit

tmp=/tmp/configure-ccmalloc-atexit-$$
dir=`pwd`
mkdir /tmp/configure-ccmalloc-atexit-$$ || exit 1
cd $tmp
rm -f main.c

cat <<EOF >main.c
#include <stdlib.h>
#include <stdio.h>
void foo() { printf ("yes\n"); }
int main(void)
{
  atexit(foo);
  exit(0);
}
EOF

atexit=no
if $CC main.c 1>/dev/null 2>/dev/null
then
  [ "`./a.out`" = yes ] && atexit=yes
fi
cd $dir
rm -rf $tmp

echo " $atexit"

#--------------------------------------------------------------------------#

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"
[ $atexit = yes ] && echo "#define HAVE_ATEXIT"
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" "generating $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,@VERSION@,$version,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

cat >>Makefile<<EOF

#-------------------------------------------------------------------------#

uninstall:
	rm -f \$(PREFIX)/bin/ccmalloc
	rm -f \$(PREFIX)/lib/libccmalloc.a
	rm -f \$(PREFIX)/share/ccmalloc/ccmalloc.cfg
EOF

for cc in $COMPILERS
do
echo "	rm -f \$(PREFIX)/lib/ccmalloc-${cc}.o " >> $dst
done

echo " done"