~jtaylor/ubuntu/oneiric/bitlbee/fix-879730

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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
#!/bin/sh

##############################
##  Configurer for BitlBee  ##
##                          ##
##  Copyright 2004 Lintux   ##
##  Copyright 2002 Lucumo   ##
##############################

prefix='/usr/local/'
bindir='$prefix/sbin/'
etcdir='$prefix/etc/bitlbee/'
mandir='$prefix/share/man/'
datadir='$prefix/share/bitlbee/'
config='/var/lib/bitlbee/'
plugindir='$prefix/lib/bitlbee/'
includedir='$prefix/include/bitlbee/'
libevent='/usr/'
pidfile='/var/run/bitlbee.pid'
ipcsocket='/var/run/bitlbee.sock'
pcdir='$prefix/lib/pkgconfig'
systemlibdirs="/lib /usr/lib /usr/local/lib"

msn=1
jabber=1
oscar=1
yahoo=1

debug=0
strip=1
gcov=0
plugins=1

events=glib
ldap=0
ssl=auto

arch=`uname -s`
cpu=`uname -m`

GLIB_MIN_VERSION=2.4

echo BitlBee configure

while [ -n "$1" ]; do
	e="`expr "X$1" : 'X--\(.*=.*\)'`"
	if [ -z "$e" ]; then
		cat<<EOF

Usage: $0 [OPTIONS]

Option		Description				Default

--prefix=...	Directories to put files in		$prefix
--bindir=...						$bindir
--etcdir=...						$etcdir
--mandir=...						$mandir
--datadir=...						$datadir
--plugindir=...						$plugindir
--pidfile=...						$pidfile
--config=...						$config
--ipcsocket=...						$ipcsocket

--msn=0/1	Disable/enable MSN part			$msn
--jabber=0/1	Disable/enable Jabber part		$jabber
--oscar=0/1	Disable/enable Oscar part (ICQ, AIM)	$oscar
--yahoo=0/1	Disable/enable Yahoo part		$yahoo

--debug=0/1	Disable/enable debugging		$debug
--strip=0/1	Disable/enable binary stripping		$strip
--gcov=0/1	Disable/enable test coverage reporting	$gcov
--plugins=0/1	Disable/enable plugins support		$plugins

--events=...	Event handler (glib, libevent)		$events
--ssl=...	SSL library to use (gnutls, nss, openssl, bogus, auto)
							$ssl

--target=...	Cross compilation target 		same as host
EOF
		exit;
	fi
	eval "$e"
	shift;
done

# Expand $prefix and get rid of double slashes
bindir=`eval echo "$bindir/" | sed 's/\/\{1,\}/\//g'`
etcdir=`eval echo "$etcdir/" | sed 's/\/\{1,\}/\//g'`
mandir=`eval echo "$mandir/" | sed 's/\/\{1,\}/\//g'`
datadir=`eval echo "$datadir/" | sed 's/\/\{1,\}/\//g'`
config=`eval echo "$config/" | sed 's/\/\{1,\}/\//g'`
plugindir=`eval echo "$plugindir/" | sed 's/\/\{1,\}/\//g'`
includedir=`eval echo "$includedir"/ | sed 's/\/\{1,\}/\//g'`
libevent=`eval echo "$libevent"/ | sed 's/\/\{1,\}/\//g'`

pidfile=`eval echo "$pidfile" | sed 's/\/\{1,\}/\//g'`
ipcsocket=`eval echo "$ipcsocket" | sed 's/\/\{1,\}/\//g'`
pcdir=`eval echo "$pcdir" | sed 's/\/\{1,\}/\//g'`

cat<<EOF>Makefile.settings
## BitlBee settings, generated by configure
PREFIX=$prefix
BINDIR=$bindir
ETCDIR=$etcdir
MANDIR=$mandir
DATADIR=$datadir
PLUGINDIR=$plugindir
CONFIG=$config
INCLUDEDIR=$includedir
PCDIR=$pcdir

TARGET=$target
ARCH=$arch
CPU=$cpu

DESTDIR=
LFLAGS=
EFLAGS=
EOF

cat<<EOF>config.h
/* BitlBee settings, generated by configure
   
   Do *NOT* use any of these defines in your code without thinking twice, most
   of them can/will be overridden at run-time */

#define CONFIG "$config"
#define ETCDIR "$etcdir"
#define VARDIR "$datadir"
#define PLUGINDIR "$plugindir"
#define PIDFILE "$pidfile"
#define IPCSOCKET "$ipcsocket"
#define ARCH "$arch"
#define CPU "$cpu"
EOF



if [ -n "$target" ]; then
	PKG_CONFIG_LIBDIR=/usr/$target/lib/pkgconfig
	export PKG_CONFIG_LIBDIR
	PATH=/usr/$target/bin:$PATH
	CC=$target-cc
	LD=$target-ld
	systemlibdirs="/usr/$target/lib"
fi


if [ "$debug" = "1" ]; then
	[ -z "$CFLAGS" ] && CFLAGS=-g
	echo 'DEBUG=1' >> Makefile.settings
	CFLAGS="$CFLAGS -DDEBUG"
else
	[ -z "$CFLAGS" ] && CFLAGS="-O2 -fno-strict-aliasing"
fi

echo CFLAGS=$CFLAGS >> Makefile.settings
echo CFLAGS+=-I`pwd` -I`pwd`/lib -I`pwd`/protocols -I. >> Makefile.settings

echo CFLAGS+=-DHAVE_CONFIG_H >> Makefile.settings

if [ -n "$CC" ]; then
	CC=$CC
elif type gcc > /dev/null 2> /dev/null; then
	CC=gcc
elif type cc > /dev/null 2> /dev/null; then
	CC=cc
else
	echo 'Cannot find a C compiler, aborting.'
	exit 1;
fi

echo "CC=$CC" >> Makefile.settings;

if [ -z "$LD" ]; then
	if type ld > /dev/null 2> /dev/null; then
		LD=ld
	else
		echo 'Cannot find ld, aborting.'
		exit 1;
	fi
fi

echo "LD=$LD" >> Makefile.settings

if [ -z "$PKG_CONFIG" ]; then
	PKG_CONFIG=pkg-config
fi

if $PKG_CONFIG --version > /dev/null 2>/dev/null && $PKG_CONFIG glib-2.0; then
	if $PKG_CONFIG glib-2.0 --atleast-version=$GLIB_MIN_VERSION; then
		cat<<EOF>>Makefile.settings
EFLAGS+=`$PKG_CONFIG --libs glib-2.0 gmodule-2.0`
CFLAGS+=`$PKG_CONFIG --cflags glib-2.0 gmodule-2.0`
EOF
	else
		echo
		echo 'Found glib2 '`$PKG_CONFIG glib-2.0 --modversion`', but version '$GLIB_MIN_VERSION' or newer is required.'
		exit 1
	fi
else
	echo
	echo 'Cannot find glib2 development libraries, aborting. (Install libglib2-dev?)'
	exit 1
fi

if [ "$events" = "libevent" ]; then
	if ! [ -f "${libevent}include/event.h" ]; then
		echo
		echo 'Warning: Could not find event.h, you might have to install it and/or specify'
		echo 'its location using the --libevent= argument. (Example: If event.h is in'
		echo '/usr/local/include and binaries are in /usr/local/lib: --libevent=/usr/local)'
	fi
	
	echo '#define EVENTS_LIBEVENT' >> config.h
	cat <<EOF>>Makefile.settings
EFLAGS+=-levent -L${libevent}lib
CFLAGS+=-I${libevent}include
EOF
elif [ "$events" = "glib" ]; then
	## We already use glib anyway, so this is all we need (and in fact not even this, but just to be sure...):
	echo '#define EVENTS_GLIB' >> config.h
else
	echo
	echo 'ERROR: Unknown event handler specified.'
	exit 1
fi
echo 'EVENT_HANDLER=events_'$events'.o' >> Makefile.settings

detect_gnutls()
{
	if $PKG_CONFIG --exists gnutls; then
		cat <<EOF>>Makefile.settings
EFLAGS+=`$PKG_CONFIG --libs gnutls`
CFLAGS+=`$PKG_CONFIG --cflags gnutls`
EOF
		ssl=gnutls
		ret=1
	elif libgnutls-config --version > /dev/null 2> /dev/null; then
		cat <<EOF>>Makefile.settings
EFLAGS+=`libgnutls-config --libs`
CFLAGS+=`libgnutls-config --cflags`
EOF
		
		ssl=gnutls
		ret=1;
	else
		ret=0;
	fi;
}

detect_nss()
{
	if $PKG_CONFIG --version > /dev/null 2>/dev/null && $PKG_CONFIG mozilla-nss; then
		cat<<EOF>>Makefile.settings
EFLAGS+=`$PKG_CONFIG --libs mozilla-nss`
CFLAGS+=`$PKG_CONFIG --cflags mozilla-nss`
EOF
		
		ssl=nss
		ret=1;
	else
		ret=0;
	fi;
}

detect_ldap()
{
	TMPFILE=$(mktemp)
	if $CC -o $TMPFILE -shared -lldap 2>/dev/null >/dev/null; then
		cat<<EOF>>Makefile.settings
EFLAGS+=-lldap
CFLAGS+=
EOF
		ldap=1
		rm -f $TMPFILE
		ret=1
	else
		ldap=0
		ret=0
	fi
}

RESOLV_TESTCODE='
#include <arpa/nameser.h>
#include <resolv.h> 

int main()
{
	ns_initparse( NULL, 0, NULL );
	ns_parserr( NULL, ns_s_an, 0, NULL );
}
'

detect_resolv_dynamic()
{
	echo "$RESOLV_TESTCODE" | $CC -o /dev/null -x c - -lresolv >/dev/null 2>/dev/null
	if [ "$?" = "0" ]; then
		echo 'EFLAGS+=-lresolv' >> Makefile.settings
		return 0
	fi

	return 1
}

detect_resolv_static()
{
	for i in $systemlibdirs; do
		if [ -f $i/libresolv.a ]; then
			echo "$RESOLV_TESTCODE" | $CC -o /dev/null -x c - -Wl,$i/libresolv.a >/dev/null 2>/dev/null
			if [ "$?" = "0" ]; then
				echo 'EFLAGS+='$i'/libresolv.a' >> Makefile.settings
				return 0
			fi
		fi
	done

	return 1
}

if [ "$ssl" = "auto" ]; then
	detect_gnutls
	if [ "$ret" = "0" ]; then
		detect_nss
	fi
elif [ "$ssl" = "gnutls" ]; then
	detect_gnutls
elif [ "$ssl" = "nss" ]; then
	detect_nss
elif [ "$ssl" = "sspi" ]; then
	echo
elif [ "$ssl" = "openssl" ]; then
	echo
	echo 'No detection code exists for OpenSSL. Make sure that you have a complete'
	echo 'install of OpenSSL (including devel/header files) before reporting'
	echo 'compilation problems.'
	echo
	echo 'Also, keep in mind that the OpenSSL is, according to some people, not'
	echo 'completely GPL-compatible. Using GnuTLS or NSS is recommended and better'
	echo 'supported by us. However, on many BSD machines, OpenSSL can be considered'
	echo 'part of the operating system, which makes it GPL-compatible.'
	echo
	echo 'For more info, see: http://www.openssl.org/support/faq.html#LEGAL2'
	echo '                    http://www.gnome.org/~markmc/openssl-and-the-gpl.html'
	echo
	echo 'Please note that distributing a BitlBee binary which links to OpenSSL is'
	echo 'probably illegal. If you want to create and distribute a binary BitlBee'
	echo 'package, you really should use GnuTLS or NSS instead.'
	echo
	echo 'Also, the OpenSSL license requires us to say this:'
	echo ' *    "This product includes software developed by the OpenSSL Project'
	echo ' *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"'
	
	echo 'EFLAGS+=-lssl -lcrypto' >> Makefile.settings
	
	ret=1
elif [ "$ssl" = "bogus" ]; then
	echo
	echo 'Using bogus SSL code. This means some features will not work properly.'
	
	## Yes, you, at the console! How can you authenticate if you don't have any SSL!?
	if [ "$msn" = "1" ]; then
		echo
		echo 'Real SSL support is necessary for MSN authentication, will build without'
		echo 'MSN protocol support.'
		msn=0
	fi
	
	ret=1
else
	echo
	echo 'ERROR: Unknown SSL library specified.'
	exit 1
fi

if [ "$ret" = "0" ]; then
	echo
	echo 'ERROR: Could not find a suitable SSL library (GnuTLS, libnss or OpenSSL).'
	echo '       Please note that this script doesn'\''t have detection code for OpenSSL,'
	echo '       so if you want to use that, you have to select it by hand. If you don'\''t'
	echo '       need SSL support, you can select the "bogus" SSL library. (--ssl=bogus)'
	
	exit 1
fi;

echo 'SSL_CLIENT=ssl_'$ssl'.o' >> Makefile.settings

if detect_resolv_dynamic || detect_resolv_static; then
	echo '#define HAVE_RESOLV_A' >> config.h
fi

STORAGES="text xml"

if [ "$ldap" = "auto" ]; then
	detect_ldap
fi

if [ "$ldap" = 0 ]; then
	echo "#undef WITH_LDAP" >> config.h
elif [ "$ldap" = 1 ]; then
	echo
	echo 'LDAP support is a work in progress and does NOT work AT ALL right now.'
	echo
	exit 1
	
	echo "#define WITH_LDAP 1" >> config.h
	STORAGES="$STORAGES ldap"
fi

for i in $STORAGES; do
	STORAGE_OBJS="$STORAGE_OBJS storage_$i.o"
done
echo "STORAGE_OBJS="$STORAGE_OBJS >> Makefile.settings

if [ "$strip" = 0 ]; then
	echo "STRIP=\# skip strip" >> Makefile.settings;
else
	if [ "$debug" = 1 ]; then
		echo
		echo 'Stripping binaries does not make sense when debugging. Stripping disabled.'
		echo 'STRIP=\# skip strip' >> Makefile.settings
		strip=0;
	elif [ -n "$STRIP" ]; then
		echo "STRIP=$STRIP" >> Makefile.settings;
	elif type strip > /dev/null 2> /dev/null; then
		echo "STRIP=strip" >> Makefile.settings;
	else
		echo
		echo 'No strip utility found, cannot remove unnecessary parts from executable.'
		echo 'STRIP=\# skip strip' >> Makefile.settings
		strip=0;
	fi;
fi

if [ "$gcov" = "1" ]; then
	echo "CFLAGS+=--coverage" >> Makefile.settings
	echo "EFLAGS+=--coverage" >> Makefile.settings
fi

if [ "$plugins" = 0 ]; then
	echo '#undef WITH_PLUGINS' >> config.h
else
	echo '#define WITH_PLUGINS' >> config.h
fi

echo
if [ -z "$BITLBEE_VERSION" -a -d .bzr ] && type bzr > /dev/null 2> /dev/null; then
	nick=`bzr nick`
	if [ -n "$nick" -a "$nick" != "bitlbee" ]; then
		nick="-$nick"
	else
		nick=""
	fi
	rev=`bzr revno`
	echo 'Using bzr revision #'$rev' as version number'
	BITLBEE_VERSION=\"bzr$nick-$rev\"
fi

if [ -n "$BITLBEE_VERSION" ]; then
	echo 'Spoofing version number: '$BITLBEE_VERSION
	echo '#undef BITLBEE_VERSION' >> config.h
	echo '#define BITLBEE_VERSION '$BITLBEE_VERSION >> config.h
	echo
fi

cat <<EOF>bitlbee.pc
prefix=$prefix
includedir=$includedir

Name: bitlbee
Description: IRC to IM gateway
Requires: glib-2.0
Version: $BITLBEE_VERSION
Libs:
Cflags: -I\${includedir}

EOF

protocols=''
protoobjs=''

if [ "$msn" = 0 ]; then
	echo '#undef WITH_MSN' >> config.h
else
	echo '#define WITH_MSN' >> config.h
	protocols=$protocols'msn '
	protoobjs=$protoobjs'msn_mod.o '
fi

if [ "$jabber" = 0 ]; then
	echo '#undef WITH_JABBER' >> config.h
else
	echo '#define WITH_JABBER' >> config.h
	protocols=$protocols'jabber '
	protoobjs=$protoobjs'jabber_mod.o '
fi

if [ "$oscar" = 0 ]; then
	echo '#undef WITH_OSCAR' >> config.h
else
	echo '#define WITH_OSCAR' >> config.h
	protocols=$protocols'oscar '
	protoobjs=$protoobjs'oscar_mod.o '
fi

if [ "$yahoo" = 0 ]; then
	echo '#undef WITH_YAHOO' >> config.h
else
	echo '#define WITH_YAHOO' >> config.h
	protocols=$protocols'yahoo '
	protoobjs=$protoobjs'yahoo_mod.o '
fi

if [ "$protocols" = "PROTOCOLS = " ]; then
	echo "Warning: You haven't selected any communication protocol to compile!"
	echo "         BitlBee will run, but you will be unable to connect to IM servers!"
fi

echo "PROTOCOLS = $protocols" >> Makefile.settings
echo "PROTOOBJS = $protoobjs" >> Makefile.settings

echo Architecture: $arch
case "$arch" in
Linux )
;;
GNU/* )
;;
*BSD )
;;
Darwin )
;;
IRIX )
;;
SunOS )
	echo 'EFLAGS+=-lresolv -lnsl -lsocket' >> Makefile.settings
	echo 'STRIP=\# skip strip' >> Makefile.settings
;;
AIX )
	echo 'EFLAGS+=-Wl,-brtl' >> Makefile.settings
;;
CYGWIN* )
	echo 'Cygwin is not officially supported.'
;;
Windows )
;;
* )
	echo 'We haven'\''t tested BitlBee on many platforms yet, yours is untested. YMMV.'
	echo 'Please report any problems at http://bugs.bitlbee.org/.'
;;
esac

if [ -n "$target" ]; then
	echo "Cross-compiling for: $target"
fi

echo
echo 'Configuration done:'

if [ "$debug" = "1" ]; then
	echo '  Debugging enabled.'
else
	echo '  Debugging disabled.'
fi

if [ "$strip" = "1" ]; then
	echo '  Binary stripping enabled.'
else
	echo '  Binary stripping disabled.'
fi

echo '  Using event handler: '$events
echo '  Using SSL library: '$ssl
echo '  Building with these storage backends: '$STORAGES

if [ -n "$protocols" ]; then
	echo '  Building with these protocols:' $protocols
else
	echo '  Building without IM-protocol support. We wish you a lot of fun...'
fi