source: configure

Last change on this file was 684aca2, checked in by Jelmer Vernooij <jelmer@…>, at 2024-07-03T07:58:38Z

Replace libgcrypt-configure with pkg-config

libgcrypt-configure has been dropped in favour of pkg-config in the
latest releases.

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1070905

  • Property mode set to 100755
File size: 25.9 KB
RevLine 
[b7d3cc34]1#!/bin/sh
2
3##############################
4##  Configurer for BitlBee  ##
5##                          ##
6##  Copyright 2004 Lintux   ##
7##  Copyright 2002 Lucumo   ##
8##############################
9
[612b49d]10# shellcheck disable=SC2016,SC2164,SC2181
[59c9fa4d]11prefix='/usr/local/'
12bindir='$prefix/bin/'
13sbindir='$prefix/sbin/'
14etcdir='$prefix/etc/bitlbee/'
15mandir='$prefix/share/man/'
16datadir='$prefix/share/bitlbee/'
17config='/var/lib/bitlbee/'
18libdir='$prefix/lib/'
19plugindir='$prefix/lib/bitlbee/'
20includedir='$prefix/include/bitlbee/'
21systemdsystemunitdir=''
22sysusersdir=''
23libevent='/usr/'
24pidfile='/var/run/bitlbee.pid'
25ipcsocket=''
26pcdir='$prefix/lib/pkgconfig'
[25b80e9c]27systemlibdirs="/lib64 /usr/lib64 /usr/local/lib64 /lib /usr/lib /usr/local/lib"
[59c9fa4d]28sysroot=''
[b7d3cc34]29
[612b49d]30configure_args="$*"
[2f8e3ca]31
[04e2a05]32# Set these to default-on to let it be overriden by either the user or purple
33#
34# If the user sets one of these to 1, purple won't disable them.
35# Otherwise, if it's still default-on, it gets included in normal builds,
36# but not purple ones.
37jabber="default-on"
38
[1b221e0]39twitter=1
[04dc563]40purple=0
[b7d3cc34]41
[65d0dfd]42verbose=0
[a85a8ab]43doc=1
[b7d3cc34]44debug=0
[2a1c27f]45strip=0
[66b9e86e]46gcov=0
[e2472dd]47asan=0
[2abfbc5]48plugins=1
[04f0c10]49otr=0
[85cf37f]50
51events=glib
[da0202a]52external_json_parser=auto
[b7d3cc34]53ssl=auto
54
[a6005da]55pam=0
[50bb490]56ldap=0
[a6005da]57
[7281ad1]58pie=1
59
[8ca172f]60systemd=auto
61
[21f450c]62arch=$(uname -s)
[0d753ff]63arch_rel=$(uname -r)
[21f450c]64
[3a547ee]65GLIB_MIN_VERSION=2.32
[670204f]66
[0d753ff]67# Cygwin, Darwin and SunOS < 5.11 do not support PIC/PIE
[25c4c78]68case "$arch" in
[a85a8ab]69        CYGWIN* )
70                pie=0;;
71        Darwin )
72                pie=0;;
[0d753ff]73        SunOS )
74                if [ "$arch_rel" = "5.10" ]; then
[cc0ad0a]75                        pie=0
[0d753ff]76                fi
[cc0ad0a]77                ;;
[25c4c78]78esac
79
[70ec7ab]80get_version() {
[612b49d]81        REAL_BITLBEE_VERSION=$(grep '^#define BITLBEE_VERSION ' "$srcdir/bitlbee.h" | sed 's/.*\"\(.*\)\".*/\1/')
[041777e]82
83        if [ -n "$BITLBEE_VERSION" ]; then
84                # environment variable already set to something to spoof it
85                # don't replace it with the git stuff
86                return
87        fi
88
[70ec7ab]89        BITLBEE_VERSION=$REAL_BITLBEE_VERSION
90
[612b49d]91        if [ -d "$srcdir/.git" ] && type git > /dev/null 2> /dev/null; then
92                timestamp=$(cd "$srcdir"; git show -s --format=%ci HEAD | sed 's/ .*$//; s/-//g')
93                branch=$(cd "$srcdir"; git rev-parse --abbrev-ref HEAD)
[70ec7ab]94
[1d8cbc9]95                search='\(.*\)-\([0-9]*\)-\(g[0-9a-f]*\)'
[70ec7ab]96                replace="\1+$timestamp+$branch+\2-\3-git"
97
[612b49d]98                if ! (cd "$srcdir"; git describe --long --tags 2>/dev/null); then
99                        describe=${REAL_BITLBEE_VERSION}-0-g$(cd "$srcdir"; git rev-parse --short HEAD)
[e28c449]100                fi
[70ec7ab]101
[612b49d]102                BITLBEE_VERSION=$(echo "$describe" | sed "s#$search#$replace#")
[e28c449]103
104                unset timestamp branch search replace describe
[70ec7ab]105        fi
106}
107
108if [ "$1" = "--dump-version" ]; then
[612b49d]109        srcdir=$(cd "$(dirname "$0")"; pwd)
[70ec7ab]110        get_version
[612b49d]111        echo "$BITLBEE_VERSION"
[70ec7ab]112        exit
113fi
114
115echo BitlBee configure
116
[b7d3cc34]117while [ -n "$1" ]; do
[4966712a]118        e="$(expr "X$1" : 'X--\(.*=.*\)')"
[b7d3cc34]119        if [ -z "$e" ]; then
120                cat<<EOF
121
122Usage: $0 [OPTIONS]
123
124Option          Description                             Default
125
126--prefix=...    Directories to put files in             $prefix
127--bindir=...                                            $bindir
[57da960]128--sbindir=...                                           $sbindir
[b7d3cc34]129--etcdir=...                                            $etcdir
130--mandir=...                                            $mandir
131--datadir=...                                           $datadir
[7b23afd]132--plugindir=...                                         $plugindir
[417002e]133--systemdsystemunitdir=...                              $systemdsystemunitdir
[50d0a72]134--sysusersdir=...                                       $sysusersdir
[34b17d9]135--pidfile=...                                           $pidfile
[b7d3cc34]136--config=...                                            $config
137
[65d0dfd]138--verbose=0/1   Disable/enable verbose build            $verbose
139
[b7d3cc34]140--jabber=0/1    Disable/enable Jabber part              $jabber
[4aa0f6b]141--twitter=0/1   Disable/enable Twitter part             $twitter
[b7d3cc34]142
[796da03]143--purple=0/1    Disable/enable libpurple support        $purple
[04f0c10]144                (automatically disables other protocol modules)
[b7d3cc34]145
[a6005da]146--pam=0/1       Disable/enable PAM authentication       $pam
[50bb490]147--ldap=0/1      Disable/enable LDAP authentication      $ldap
[a6005da]148
[a85a8ab]149--doc=0/1       Disable/enable help.txt generation      $doc
[b7d3cc34]150--debug=0/1     Disable/enable debugging                $debug
151--strip=0/1     Disable/enable binary stripping         $strip
[7281ad1]152--pie=0/1       Build position independent executable   $pie
[66b9e86e]153--gcov=0/1      Disable/enable test coverage reporting  $gcov
[e2472dd]154--asan=0/1      Disable/enable AddressSanitizer         $asan
[2abfbc5]155--plugins=0/1   Disable/enable plugins support          $plugins
[04f0c10]156--otr=0/1/auto/plugin
157                Disable/enable OTR encryption support   $otr
[b7d3cc34]158
[85cf37f]159--events=...    Event handler (glib, libevent)          $events
[e1d3f98]160--ssl=...       SSL library to use (gnutls, nss, openssl, auto)
[b7d3cc34]161                                                        $ssl
[da0202a]162--external_json_parser=0/1/auto Use External JSON parser $external_json_parser
[bea6db0]163--systemd=0/1   Enable/disable systemd                  $systemd
[aec56b0]164
[7281ad1]165
[f1e7407]166--target=...    Cross compilation target                same as host
[f5bbaba]167--sysroot=...   Cross compilation sysroot               $sysroot
[b7d3cc34]168EOF
[612b49d]169                exit
[b7d3cc34]170        fi
171        eval "$e"
[612b49d]172        shift
[b7d3cc34]173done
174
175# Expand $prefix and get rid of double slashes
[4966712a]176bindir=$(eval echo "$bindir/" | sed 's/\/\{1,\}/\//g')
177sbindir=$(eval echo "$sbindir/" | sed 's/\/\{1,\}/\//g')
178etcdir=$(eval echo "$etcdir/" | sed 's/\/\{1,\}/\//g')
179mandir=$(eval echo "$mandir/" | sed 's/\/\{1,\}/\//g')
180datadir=$(eval echo "$datadir/" | sed 's/\/\{1,\}/\//g')
181config=$(eval echo "$config/" | sed 's/\/\{1,\}/\//g')
[54b2a36]182libdir=$(eval echo "$libdir/" | sed 's/\/\{1,\}/\//g')
[4966712a]183plugindir=$(eval echo "$plugindir/" | sed 's/\/\{1,\}/\//g')
184includedir=$(eval echo "$includedir"/ | sed 's/\/\{1,\}/\//g')
185libevent=$(eval echo "$libevent"/ | sed 's/\/\{1,\}/\//g')
186
187pidfile=$(eval echo "$pidfile" | sed 's/\/\{1,\}/\//g')
188ipcsocket=$(eval echo "$ipcsocket" | sed 's/\/\{1,\}/\//g')
189pcdir=$(eval echo "$pcdir" | sed 's/\/\{1,\}/\//g')
[b7d3cc34]190
[17f6079]191protocols_mods=""
192
[b95b0c8]193cat <<EOF >Makefile.settings
[b7d3cc34]194## BitlBee settings, generated by configure
[2f8e3ca]195
196# ./configure $configure_args
197
[b7d3cc34]198PREFIX=$prefix
199BINDIR=$bindir
[57da960]200SBINDIR=$sbindir
[b7d3cc34]201ETCDIR=$etcdir
202MANDIR=$mandir
203DATADIR=$datadir
[7b23afd]204PLUGINDIR=$plugindir
[b7d3cc34]205CONFIG=$config
[54b2a36]206LIBDIR=$libdir
[e506d6c]207INCLUDEDIR=$includedir
208PCDIR=$pcdir
[b7d3cc34]209
[1bf9492]210TARGET=$target
[b7d3cc34]211
[25b80e9c]212INSTALL=install -p
213
[b7d3cc34]214DESTDIR=
215LFLAGS=
[7a80925]216EFLAGS=-lm
[b7d3cc34]217EOF
218
[612b49d]219srcdir=$(cd "$(dirname "$0")"; pwd)
[1074806]220currdir=$(pwd)
[612b49d]221if [ "$srcdir" != "$currdir" ]; then
[f60079b]222        echo
223        echo "configure script run from a different directory. Will create some symlinks..."
[612b49d]224        if [ ! -e Makefile ] || [ -L Makefile ]; then
[04dc563]225                COPYDIRS="doc lib protocols tests utils"
[612b49d]226                # shellcheck disable=SC2046,SC2086
[59c9fa4d]227                mkdir -p $(cd "$srcdir"; find $COPYDIRS -type d)
[f60079b]228                find . -name Makefile -type l -print0 | xargs -0 rm 2> /dev/null
229                dst="$PWD"
[59c9fa4d]230                cd "$srcdir"
[612b49d]231                # shellcheck disable=SC2044
[59c9fa4d]232                for i in $(find . -name Makefile -type f); do
[612b49d]233                        ln -s "$PWD${i#.}" "$dst/$i"
[f60079b]234                done
[59c9fa4d]235                cd "$dst"
[f60079b]236                rm -rf .bzr
237        fi
238       
[7fa5c19]239        echo "_SRCDIR_=$srcdir/" >> Makefile.settings
[f60079b]240        CFLAGS="$CFLAGS -I${dst}"
241else
242        srcdir=$PWD
243fi
244
[b95b0c8]245cat<<EOF >config.h
[b7d3cc34]246/* BitlBee settings, generated by configure
[612b49d]247
[b7d3cc34]248   Do *NOT* use any of these defines in your code without thinking twice, most
249   of them can/will be overridden at run-time */
250
[2f8e3ca]251#define BITLBEE_CONFIGURE_ARGS "$configure_args"
252
[b7d3cc34]253#define CONFIG "$config"
254#define ETCDIR "$etcdir"
255#define VARDIR "$datadir"
[7b23afd]256#define PLUGINDIR "$plugindir"
[ad66dcd]257#define DATADIR "$datadir"
[34b17d9]258#define PIDFILE "$pidfile"
[6dff9d4]259#define IPCSOCKET "$ipcsocket"
[b7d3cc34]260EOF
261
[1bf9492]262
263
[f1e7407]264if [ -n "$target" ]; then
[f5bbaba]265        # prepend sysroot to system lib dirs
266
267        systemlibdirs_cross=''
268        for i in $systemlibdirs; do
269                systemlibdirs_cross="$systemlibdirs_cross $sysroot$i"
270        done
271        systemlibdirs=$systemlibdirs_cross
272        unset systemlibdirs_cross
273
274        # backward compatibility
275
276        if [ -z "$PKG_CONFIG_LIBDIR" ]; then
[612b49d]277                PKG_CONFIG_LIBDIR="/usr/$target/lib/pkgconfig"
[f5bbaba]278                export PKG_CONFIG_LIBDIR
279        fi
280
[612b49d]281        if [ -d "/usr/$target/bin" ]; then
282                PATH="/usr/$target/bin:$PATH"
[f5bbaba]283        fi
284
[612b49d]285        if [ -d "/usr/$target/lib" ]; then
[f5bbaba]286                systemlibdirs="$systemlibdirs /usr/$target/lib"
287        fi
288
[f1e7407]289        CC=$target-cc
290        LD=$target-ld
[f5bbaba]291        STRIP=$target-strip
[f1e7407]292fi
293
[e2472dd]294if [ "$asan" = "1" ]; then
295        CFLAGS="$CFLAGS -fsanitize=address"
296        LDFLAGS="$LDFLAGS -fsanitize=address"
297        debug=1
298fi
[1bf9492]299
[65d0dfd]300if [ "$verbose" = "0" ]; then
301        echo 'VERBOSE=@' >> Makefile.settings
302else
303        echo 'VERBOSE=' >> Makefile.settings
304fi
305
[08b0ed8]306cat <<EOF >>Makefile.settings
307
308# Enable/disable output verbosity
309ifdef V
310ifeq (\$(V),1)
311        VERBOSE=
312else
313        VERBOSE=@
314endif
315endif
316
317EOF
318
[b7d3cc34]319if [ "$debug" = "1" ]; then
320        echo 'DEBUG=1' >> Makefile.settings
[e2472dd]321        CFLAGS="$CFLAGS -g3 -DDEBUG -O0"
[b7d3cc34]322else
[e9eee04]323        [ -z "$CFLAGS" ] && CFLAGS="-g -O2"
[b7d3cc34]324fi
325
[7281ad1]326if [ "$pie" = "1" ]; then
327        echo 'CFLAGS_BITLBEE=-fPIE' >> Makefile.settings
328        echo 'LDFLAGS_BITLBEE=-pie' >> Makefile.settings
329fi
330
[612b49d]331cat<<EOF >>Makefile.settings
332LDFLAGS=$LDFLAGS
333CFLAGS=$CFLAGS $CPPFLAGS
334CFLAGS+=-DHAVE_CONFIG_H -D_GNU_SOURCE
335EOF
[f712188]336
[59c9fa4d]337if [ -n "$CC" ]; then
[612b49d]338        :
[59c9fa4d]339elif type gcc > /dev/null 2> /dev/null; then
[5973412]340        CC=gcc
[b7d3cc34]341elif type cc > /dev/null 2> /dev/null; then
[5973412]342        CC=cc
[b7d3cc34]343else
344        echo 'Cannot find a C compiler, aborting.'
[612b49d]345        exit 1
[b7d3cc34]346fi
347
[612b49d]348echo "CC=$CC" >> Makefile.settings
349if echo "$CC" | grep -qw 'gcc\|clang'; then
[daae10f]350        # Apparently -Wall is gcc-specific?
[612b49d]351        echo 'CFLAGS+=-Wall -Wformat -Werror=format-security' >> Makefile.settings
[daae10f]352fi
[5973412]353
[f1e7407]354if [ -z "$LD" ]; then
355        if type ld > /dev/null 2> /dev/null; then
356                LD=ld
357        else
358                echo 'Cannot find ld, aborting.'
[612b49d]359                exit 1
[f1e7407]360        fi
[b7d3cc34]361fi
362
[f1e7407]363echo "LD=$LD" >> Makefile.settings
364
[32c632f]365if [ -z "$PKG_CONFIG" ]; then
366        PKG_CONFIG=pkg-config
367fi
368
[9ae8f82]369if ! $PKG_CONFIG --version > /dev/null 2>/dev/null; then
370        echo
371        echo 'Cannot find pkg-config, aborting.'
372        exit 1
373fi
374
375if $PKG_CONFIG glib-2.0; then
[670204f]376        if $PKG_CONFIG glib-2.0 --atleast-version=$GLIB_MIN_VERSION; then
[b95b0c8]377                cat<<EOF >>Makefile.settings
[4966712a]378EFLAGS+=$($PKG_CONFIG --libs glib-2.0 gmodule-2.0)
379CFLAGS+=$($PKG_CONFIG --cflags glib-2.0 gmodule-2.0)
[b7d3cc34]380EOF
[670204f]381        else
382                echo
[612b49d]383                echo "Found glib2 $($PKG_CONFIG glib-2.0 --modversion), but version $GLIB_MIN_VERSION or newer is required."
[670204f]384                exit 1
385        fi
[b7d3cc34]386else
[670204f]387        echo
[574af7e]388        echo 'Cannot find glib2 development libraries, aborting. (Install libglib2-dev?)'
[670204f]389        exit 1
[b7d3cc34]390fi
391
[85cf37f]392if [ "$events" = "libevent" ]; then
[003553b]393        if ! [ -f "${libevent}include/event.h" ]; then
[85cf37f]394                echo
395                echo 'Warning: Could not find event.h, you might have to install it and/or specify'
396                echo 'its location using the --libevent= argument. (Example: If event.h is in'
397                echo '/usr/local/include and binaries are in /usr/local/lib: --libevent=/usr/local)'
398        fi
399       
400        echo '#define EVENTS_LIBEVENT' >> config.h
[b95b0c8]401        cat <<EOF >>Makefile.settings
[85cf37f]402EFLAGS+=-levent -L${libevent}lib
403CFLAGS+=-I${libevent}include
404EOF
405elif [ "$events" = "glib" ]; then
406        ## We already use glib anyway, so this is all we need (and in fact not even this, but just to be sure...):
407        echo '#define EVENTS_GLIB' >> config.h
[b7d3cc34]408else
409        echo
[85cf37f]410        echo 'ERROR: Unknown event handler specified.'
411        exit 1
[b7d3cc34]412fi
[85cf37f]413echo 'EVENT_HANDLER=events_'$events'.o' >> Makefile.settings
[b7d3cc34]414
[da0202a]415if [ "$external_json_parser" = "auto" ]; then
416        if pkg-config --exists json-parser; then
417                external_json_parser=1
418        else
419                external_json_parser=0
420        fi
421fi
422echo "EXTERNAL_JSON_PARSER=$external_json_parser" >> Makefile.settings
423if [ "$external_json_parser" = "1" ]; then
[612b49d]424        cat <<EOF >>Makefile.settings
425CFLAGS+=$(pkg-config --cflags json-parser)
426CFLAGS+=-DUSE_EXTERNAL_JSON_PARSER
427LDFLAGS_BITLBEE+=$(pkg-config --libs json-parser)
428LDFLAGS_TESTS+=$(pkg-config --libs json-parser)
429EOF
[da0202a]430fi
431
[82149f4]432echo CFLAGS+=-I"${srcdir}" -I"${srcdir}"/lib -I"${srcdir}"/protocols -I. >> Makefile.settings
[da0202a]433
[b7d3cc34]434detect_gnutls()
435{
[4af7b4f]436        if $PKG_CONFIG --exists gnutls; then
[b95b0c8]437                cat <<EOF >>Makefile.settings
[684aca2]438EFLAGS+=$($PKG_CONFIG --libs gnutls) $(pkg-config --libs libgcrypt)
439CFLAGS+=$($PKG_CONFIG --cflags gnutls) $(pkg-config --cflags libgcrypt)
[4af7b4f]440EOF
441                ssl=gnutls
[a59bd11]442                if ! $PKG_CONFIG gnutls --atleast-version=2.8; then
[5513f3e]443                        echo
444                        echo 'Warning: With GnuTLS versions <2.8, certificate expire dates are not verified.'
445                fi
[4af7b4f]446                ret=1
447        elif libgnutls-config --version > /dev/null 2> /dev/null; then
[b95b0c8]448                cat <<EOF >>Makefile.settings
[684aca2]449EFLAGS+=$(libgnutls-config --libs) $(pkg-config --libs libgcrypt)
450CFLAGS+=$(libgnutls-config --cflags) $(pkg-config --cflags libgcrypt)
[b7d3cc34]451EOF
452               
453                ssl=gnutls
[612b49d]454                ret=1
[b7d3cc34]455        else
[612b49d]456                ret=0
457        fi
[b7d3cc34]458}
459
460detect_nss()
461{
[ef043d3]462        if $PKG_CONFIG --version > /dev/null 2>/dev/null && $PKG_CONFIG nss; then
[b95b0c8]463                cat<<EOF >>Makefile.settings
[4966712a]464EFLAGS+=$($PKG_CONFIG --libs nss)
465CFLAGS+=$($PKG_CONFIG --cflags nss)
[b7d3cc34]466EOF
467               
468                ssl=nss
[612b49d]469                ret=1
[b7d3cc34]470        else
[612b49d]471                ret=0
472        fi
[b7d3cc34]473}
474
[36cf9fd]475RESOLV_TESTCODE='
[aee8c19]476#include <sys/types.h>
477#include <netinet/in.h>
[36cf9fd]478#include <arpa/nameser.h>
[612b49d]479#include <resolv.h>
[36cf9fd]480
[632627e]481int main()
482{
483
484        res_query( NULL, 0, 0, NULL, 0);
485        dn_expand( NULL, NULL, NULL, NULL, 0);
486        dn_skipname( NULL, NULL);
487}
488'
489RESOLV_NS_TESTCODE='
490#include <sys/types.h>
491#include <netinet/in.h>
492#include <arpa/nameser.h>
[612b49d]493#include <resolv.h>
[632627e]494
[36cf9fd]495int main()
496{
497        ns_initparse( NULL, 0, NULL );
498        ns_parserr( NULL, ns_s_an, 0, NULL );
499}
500'
[632627e]501RESOLV_NS_TYPES_TESTCODE='
502#include <sys/types.h>
503#include <netinet/in.h>
504#include <arpa/nameser.h>
505
506int main()
507{
508        ns_msg nsh;
509        ns_rr rr;
510
[fb87924]511        /* Not all platforms we want to work on have
512         ns_* routines, so use this to make sure
513         the compiler uses it.*/
514        return (int)(sizeof(nsh) + sizeof(rr));
[632627e]515}
516'
[36cf9fd]517
[0d2cd10]518BACKTRACE_TESTCODE='
519#include <execinfo.h>
520
521int main()
522{
523        void *trace[16];
524        return backtrace(trace, 16);
525}
526'
527
[36cf9fd]528detect_resolv_dynamic()
529{
[aee8c19]530        case "$arch" in
[632627e]531        OpenBSD )
532                # In FreeBSD res_*/dn_* routines are present in libc.so
533                LIBRESOLV=;;
[aee8c19]534        FreeBSD )
[632627e]535                # In FreeBSD res_*/dn_* routines are present in libc.so
536                LIBRESOLV=;;
537        CYGWIN* )
538                # In Cygwin res_*/dn_* routines are present in libc.so
[aee8c19]539                LIBRESOLV=;;
540        * )
541                LIBRESOLV=-lresolv;;
542        esac
[4fca1db]543        TMPFILE=$(mktemp /tmp/bitlbee-configure.XXXXXX)
[8462239]544        ret=1
[612b49d]545        echo "$RESOLV_TESTCODE" | $CC -o "$TMPFILE" -x c - $LIBRESOLV >/dev/null 2>/dev/null
[59c9fa4d]546        if [ "$?" = "0" ]; then
[aee8c19]547                echo "EFLAGS+=$LIBRESOLV" >> Makefile.settings
[8462239]548                ret=0
[36cf9fd]549        fi
550
[612b49d]551        rm -f "$TMPFILE"
[8462239]552        return $ret
[36cf9fd]553}
554
555detect_resolv_static()
556{
[4fca1db]557        TMPFILE=$(mktemp /tmp/bitlbee-configure.XXXXXX)
[8462239]558        ret=1
[36cf9fd]559        for i in $systemlibdirs; do
[612b49d]560                if [ -f "$i/libresolv.a" ]; then
561                        echo "$RESOLV_TESTCODE" | $CC -o "$TMPFILE" -x c - -Wl,"$i/libresolv.a" >/dev/null 2>/dev/null
[59c9fa4d]562                        if [ "$?" = "0" ]; then
[612b49d]563                                echo "EFLAGS+=$i/libresolv.a" >> Makefile.settings
[8462239]564                                ret=0
[36cf9fd]565                        fi
566                fi
567        done
568
[612b49d]569        rm -f "$TMPFILE"
[8462239]570        return $ret
[36cf9fd]571}
572
[632627e]573detect_resolv_ns_dynamic()
574{
575        case "$arch" in
576        FreeBSD )
577                # In FreeBSD ns_ routines are present in libc.so
578                LIBRESOLV=;;
579        * )
580                LIBRESOLV=-lresolv;;
581        esac
582        TMPFILE=$(mktemp /tmp/bitlbee-configure.XXXXXX)
583        ret=1
[612b49d]584        echo "$RESOLV_NS_TESTCODE" | $CC -o "$TMPFILE" -x c - $LIBRESOLV >/dev/null 2>/dev/null
[59c9fa4d]585        if [ "$?" = "0" ]; then
[a67e781]586                ret=0
587        fi
[632627e]588
[612b49d]589        rm -f "$TMPFILE"
[632627e]590        return $ret
591}
592
593detect_resolv_ns_static()
594{
595        TMPFILE=$(mktemp /tmp/bitlbee-configure.XXXXXX)
596        ret=1
597        for i in $systemlibdirs; do
[612b49d]598                if [ -f "$i/libresolv.a" ]; then
599                        echo "$RESOLV_NS_TESTCODE" | $CC -o "$TMPFILE" -x c - -Wl,"$i/libresolv.a" >/dev/null 2>/dev/null
[59c9fa4d]600                        if [ "$?" = "0" ]; then
[a67e781]601                                ret=0
602                        fi
[632627e]603                fi
604        done
605
[612b49d]606        rm -f "$TMPFILE"
[632627e]607        return $ret
608}
609
610detect_nameser_has_ns_types()
611{
[a67e781]612        TMPFILE=$(mktemp /tmp/bitlbee-configure.XXXXXX)
613        ret=1
614        # since we aren't actually linking with ns_* routines
615        # we can just compile the test code
[612b49d]616        echo "$RESOLV_NS_TYPES_TESTCODE" | $CC -o "$TMPFILE" -x c - >/dev/null 2>/dev/null
[59c9fa4d]617        if [ "$?" = "0" ]; then
[a67e781]618                ret=0
619        fi
620
[612b49d]621        rm -f "$TMPFILE"
[a67e781]622        return $ret
[632627e]623}
624
[0d2cd10]625detect_backtrace()
626{
627        TMPFILE=$(mktemp /tmp/bitlbee-configure.XXXXXX)
628        ret=1
[612b49d]629        echo "$BACKTRACE_TESTCODE" | $CC -o "$TMPFILE" -x c - >/dev/null 2>/dev/null
[59c9fa4d]630        if [ "$?" = "0" ]; then
[0d2cd10]631                ret=0
632        fi
633
[612b49d]634        rm -f "$TMPFILE"
[0d2cd10]635        return $ret
636}
637
[b3c467b]638if [ "$ssl" = "auto" ]; then
639        detect_gnutls
[b7d3cc34]640        if [ "$ret" = "0" ]; then
[c5920df]641                # Disable NSS for now as it's known to not work very well ATM.
642                #detect_nss
[191cfb1]643                :
[b7d3cc34]644        fi
[b3c467b]645elif [ "$ssl" = "gnutls" ]; then
646        detect_gnutls
647elif [ "$ssl" = "nss" ]; then
648        detect_nss
649elif [ "$ssl" = "openssl" ]; then
650        echo
651        echo 'No detection code exists for OpenSSL. Make sure that you have a complete'
[b3eee9b]652        echo 'installation of OpenSSL (including devel/header files) before reporting'
[b3c467b]653        echo 'compilation problems.'
654        echo
655        echo 'Also, keep in mind that the OpenSSL is, according to some people, not'
[b3eee9b]656        echo 'completely GPL-compatible. Using GnuTLS is recommended and better supported'
657        echo 'by us. However, on many BSD machines, OpenSSL can be considered part of the'
658        echo 'operating system, which makes it GPL-compatible.'
[b3c467b]659        echo
660        echo 'For more info, see: http://www.openssl.org/support/faq.html#LEGAL2'
661        echo '                    http://www.gnome.org/~markmc/openssl-and-the-gpl.html'
662        echo
663        echo 'Please note that distributing a BitlBee binary which links to OpenSSL is'
664        echo 'probably illegal. If you want to create and distribute a binary BitlBee'
[b3eee9b]665        echo 'package, you really should use GnuTLS instead.'
[b3c467b]666        echo
667        echo 'Also, the OpenSSL license requires us to say this:'
668        echo ' *    "This product includes software developed by the OpenSSL Project'
669        echo ' *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"'
[b7d3cc34]670       
[b3c467b]671        echo 'EFLAGS+=-lssl -lcrypto' >> Makefile.settings
672       
673        ret=1
674else
675        echo
676        echo 'ERROR: Unknown SSL library specified.'
677        exit 1
[b7d3cc34]678fi
679
[b3c467b]680if [ "$ret" = "0" ]; then
681        echo
682        echo 'ERROR: Could not find a suitable SSL library (GnuTLS, libnss or OpenSSL).'
683        echo '       Please note that this script doesn'\''t have detection code for OpenSSL,'
[e1d3f98]684        echo '       so if you want to use that, you have to select it by hand.'
[b7d3cc34]685       
[b3c467b]686        exit 1
[612b49d]687fi
[b3c467b]688
689echo 'SSL_CLIENT=ssl_'$ssl'.o' >> Makefile.settings
690
[632627e]691if detect_nameser_has_ns_types; then
692        echo '#define NAMESER_HAS_NS_TYPES' >> config.h
693fi
[36cf9fd]694if detect_resolv_dynamic || detect_resolv_static; then
695        echo '#define HAVE_RESOLV_A' >> config.h
[a67e781]696        if detect_resolv_ns_dynamic || detect_resolv_ns_static; then
697                echo '#define HAVE_RESOLV_A_WITH_NS' >> config.h
698        fi
[632627e]699else
[a67e781]700        echo 'Insufficient resolv routines. Jabber server must be set explicitly'
[36cf9fd]701fi
[36e9f62]702
[0d2cd10]703if detect_backtrace; then
704        echo '#define HAVE_BACKTRACE' >> config.h
[612b49d]705        echo '#define CRASHFILE "'"$config"'crash.log"' >> config.h
[0d2cd10]706fi
[632627e]707
[ba7d16f]708STORAGES="xml"
[b3c467b]709
710for i in $STORAGES; do
711        STORAGE_OBJS="$STORAGE_OBJS storage_$i.o"
712done
[612b49d]713echo "STORAGE_OBJS=$STORAGE_OBJS" >> Makefile.settings
[b3c467b]714
[8e6ecfe]715authobjs=
716authlibs=
[59c9fa4d]717if [ "$pam" = 0 ]; then
[a6005da]718        echo '#undef WITH_PAM' >> config.h
719else
720        if ! echo '#include <security/pam_appl.h>' | $CC -E - >/dev/null 2>/dev/null; then
721                echo 'Cannot find libpam development libraries, aborting. (Install libpam0g-dev?)'
722                exit 1
723        fi
724        echo '#define WITH_PAM' >> config.h
[612b49d]725        authobjs="${authobjs}auth_pam.o "
726        authlibs="${authlibs}-lpam "
[a6005da]727fi
[59c9fa4d]728if [ "$ldap" = 0 ]; then
[50bb490]729        echo '#undef WITH_LDAP' >> config.h
730else
731        if ! echo '#include <ldap.h>' | $CC -E - >/dev/null 2>/dev/null; then
732                echo 'Cannot find libldap development libraries, aborting. (Install libldap2-dev?)'
733                exit 1
734        fi
735        echo '#define WITH_LDAP' >> config.h
[612b49d]736        authobjs="${authobjs}auth_ldap.o "
737        authlibs="${authlibs}-lldap "
[50bb490]738fi
[612b49d]739echo "AUTH_OBJS=$authobjs" >> Makefile.settings
740echo "EFLAGS+=$authlibs" >> Makefile.settings
[8e6ecfe]741
[59c9fa4d]742if [ "$strip" = 0 ]; then
[612b49d]743        echo "STRIP=\# skip strip" >> Makefile.settings
[b7d3cc34]744else
[59c9fa4d]745        if [ "$debug" = 1 ]; then
[b7d3cc34]746                echo
747                echo 'Stripping binaries does not make sense when debugging. Stripping disabled.'
748                echo 'STRIP=\# skip strip' >> Makefile.settings
[612b49d]749                strip=0
[b7d3cc34]750        elif [ -n "$STRIP" ]; then
[612b49d]751                echo "STRIP=$STRIP" >> Makefile.settings
[b7d3cc34]752        elif type strip > /dev/null 2> /dev/null; then
[612b49d]753                echo "STRIP=strip" >> Makefile.settings
[b7d3cc34]754        else
755                echo
756                echo 'No strip utility found, cannot remove unnecessary parts from executable.'
757                echo 'STRIP=\# skip strip' >> Makefile.settings
[612b49d]758                strip=0
759        fi
[b7d3cc34]760fi
761
[08964da]762if [ ! "$systemd" = "0" ]; then
[612b49d]763        if ! $PKG_CONFIG --exists systemd; then
764                if [ "$systemd" = "1" ]; then
765                        echo "systemd requested but not found"
766                        exit 1
767                else
768                        systemd=0
769                fi
770        elif [ "$systemd" = "auto" ]; then
771                systemd=1
772        fi
[417002e]773fi
[8ca172f]774
775pkgconf_systemd_var() {
[612b49d]776        # First try deprecated variable, use newer variable if not found
777        if $PKG_CONFIG --print-variables systemd | grep -q "$1"; then
778                $PKG_CONFIG --variable="$1" systemd
779        else
780                $PKG_CONFIG --variable="$2" systemd
781        fi
[8ca172f]782}
783
[08964da]784if [ "$systemd" = "1" ]; then
[8ca172f]785        if [ -z "$systemdsystemunitdir" ]; then
786                systemdsystemunitdir=$(pkgconf_systemd_var systemdsystemunitdir systemd_system_unit_dir)
[417002e]787        fi
[08964da]788        if [ -z "$sysusersdir" ]; then
[50d0a72]789                sysusersdir=$(pkgconf_systemd_var sysusersdir sysusers_dir)
790        fi
791fi
[8ca172f]792
[50d0a72]793if [ -n "$systemdsystemunitdir" ]; then
[8ca172f]794        echo "SYSTEMDSYSTEMUNITDIR=$systemdsystemunitdir" >> Makefile.settings
[50d0a72]795fi
796if [ -n "$sysusersdir" ]; then
797        echo "SYSUSERSDIR=$sysusersdir" >> Makefile.settings
[417002e]798fi
799
[66b9e86e]800if [ "$gcov" = "1" ]; then
[31fc3970]801        echo "CFLAGS+=--coverage" >> Makefile.settings
802        echo "EFLAGS+=--coverage" >> Makefile.settings
[66b9e86e]803fi
804
[59c9fa4d]805if [ "$plugins" = 0 ]; then
[489847f]806        plugindir=""
[2abfbc5]807        echo '#undef WITH_PLUGINS' >> config.h
808else
809        echo '#define WITH_PLUGINS' >> config.h
810fi
811
[764c7d1]812if [ "$otr" = "auto" ]; then
[a59bd11]813        ! $PKG_CONFIG --exists libotr
814        otr=$?
815fi
816
[59c9fa4d]817if [ "$otr" != 0 ] && ! $PKG_CONFIG --atleast-version=4.0 --print-errors libotr; then
[a59bd11]818        exit 1
[764c7d1]819fi
[a59bd11]820
[59c9fa4d]821if [ "$otr" = 1 ]; then
[858ea01]822        # BI == built-in
823        echo '#define OTR_BI' >> config.h
[612b49d]824        cat <<EOF >>Makefile.settings
[684aca2]825EFLAGS+=$($PKG_CONFIG --libs libotr) $(pkg-config --libs libgcrypt)
826CFLAGS+=$($PKG_CONFIG --cflags libotr) $(pkg-config --cflags libgcrypt)
[612b49d]827OTR_BI=otr.o
828EOF
[858ea01]829elif [ "$otr" = "plugin" ]; then
[a59bd11]830        # for some mysterious reason beyond the comprehension of my mortal mind,
831        # the libgcrypt flags aren't needed when building as plugin. add them anyway.
[858ea01]832        echo '#define OTR_PI' >> config.h
[612b49d]833        cat <<EOF >>Makefile.settings
[684aca2]834OTRFLAGS=$($PKG_CONFIG --libs libotr) $(pkg-config --libs libgcrypt)
835CFLAGS+=$($PKG_CONFIG --cflags libotr) $(pkg-config --cflags libgcrypt)
[612b49d]836OTR_PI=otr.so
837EOF
[764c7d1]838fi
839
[1cef55f]840if [ -z "$PYTHON" ]; then
[f18209a]841        for pp in python python3 python2; do
[d36ef38]842                if command -v $pp > /dev/null; then
[f18209a]843                        PYTHON=$pp
844                        break
845                fi
846        done
[1cef55f]847fi
848
[a85a8ab]849if [ "$doc" = "1" ]; then
[beb0f54]850        # check this here just in case someone tries to install it in python2.4...
[612b49d]851        if [ ! -e "$srcdir/doc/user-guide/help.txt" ] && ! $PYTHON -m xml.etree.ElementTree > /dev/null 2>&1; then
[a85a8ab]852                echo
[beb0f54]853                echo 'ERROR: Python (>=2.5 or 3.x) is required to generate docs'
[1cef55f]854                echo "(Use the PYTHON environment variable if it's in a weird location)"
[beb0f54]855                exit 1
[a85a8ab]856        fi
[beb0f54]857        echo "DOC=1" >> Makefile.settings
[1cef55f]858        echo "PYTHON=$PYTHON" >> Makefile.settings
[ceebeb1]859fi
860
[70ec7ab]861get_version
[e26aa72]862
[2bd8f39]863if [ ! "$BITLBEE_VERSION" = "$REAL_BITLBEE_VERSION" ]; then
864        echo "Spoofing version number: $BITLBEE_VERSION"
865        echo "#undef BITLBEE_VERSION" >> config.h
[612b49d]866        echo '#define BITLBEE_VERSION "'"$BITLBEE_VERSION"'"' >> config.h
[ffea9b9]867        echo
[b7d3cc34]868fi
869
[4fca1db]870if ! make helloworld > /dev/null 2>&1; then
871        echo "WARNING: Your version of make (BSD make?) does not support BitlBee's makefiles."
872        echo "BitlBee needs GNU make to build properly. On most systems GNU make is available"
873        echo "under the name 'gmake'."
874        echo
875        if gmake helloworld > /dev/null 2>&1; then
876                echo "gmake seems to be available on your machine, great."
877                echo
878        else
879                echo "gmake is not installed (or not working). Please try to install it."
880                echo
881        fi
882fi
883
[54b2a36]884pkgconfiglibs=''
885case "$arch" in
886CYGWIN* )
[612b49d]887        # shellcheck disable=SC2016
[59c9fa4d]888        pkgconfiglibs='-L${libdir} -lbitlbee -no-undefined'
[54b2a36]889esac
890
[82149f4]891pkgconfigrequires='glib-2.0'
892if [ "$external_json_parser" = '1' ]; then
893        pkgconfigrequires="$pkgconfigrequires json-parser"
894fi
895
[b95b0c8]896cat <<EOF >bitlbee.pc
[e506d6c]897prefix=$prefix
898includedir=$includedir
[489847f]899plugindir=$plugindir
[54b2a36]900libdir=$libdir
[ad66dcd]901datadir=$datadir
[e506d6c]902
903Name: bitlbee
904Description: IRC to IM gateway
[82149f4]905Requires: $pkgconfigrequires
[e506d6c]906Version: $BITLBEE_VERSION
[54b2a36]907Libs: $pkgconfiglibs
[e506d6c]908Cflags: -I\${includedir}
909
910EOF
911
[b7d3cc34]912protocols=''
913protoobjs=''
914
[59c9fa4d]915if [ "$purple" = 0 ]; then
[e248c7f]916        echo '#undef WITH_PURPLE' >> config.h
917else
[e08e53c]918        if ! $PKG_CONFIG purple; then
919                echo
920                echo 'Cannot find libpurple development libraries, aborting. (Install libpurple-dev?)'
921                exit 1
922        fi
[e248c7f]923        echo '#define WITH_PURPLE' >> config.h
[b95b0c8]924        cat<<EOF >>Makefile.settings
[612b49d]925EFLAGS+=$($PKG_CONFIG purple --libs)
926PURPLE_CFLAGS+=$($PKG_CONFIG purple --cflags)
[e08e53c]927EOF
[e248c7f]928        protocols=$protocols'purple '
929        protoobjs=$protoobjs'purple_mod.o '
930
[04e2a05]931        # only disable these if the user didn't enable them explicitly
932        [ "$jabber" = "default-on" ] && jabber=0
[18e1f3b]933
934        echo '#undef PACKAGE' >> config.h
935        echo '#define PACKAGE "BitlBee-LIBPURPLE"' >> config.h
[bda2975]936       
937        if [ "$events" = "libevent" ]; then
938                echo 'Warning: Some libpurple modules (including msn-pecan) do their event handling'
939                echo 'outside libpurple, talking to GLib directly. At least for now the combination'
940                echo 'libpurple + libevent is *not* recommended!'
[c775a58]941                echo
[bda2975]942        fi
[e248c7f]943fi
944
[b0a89cc]945case "$CC" in
946*gcc* )
[612b49d]947        echo "CFLAGS+=-MMD -MF .depend/\$@.d" >> Makefile.settings
[fe92921]948        for i in . lib tests protocols protocols/*/; do
[612b49d]949                mkdir -p "$i/.depend"
[b0a89cc]950        done
951esac
952
[59c9fa4d]953if [ "$jabber" = 0 ]; then
[b7d3cc34]954        echo '#undef WITH_JABBER' >> config.h
955else
956        echo '#define WITH_JABBER' >> config.h
957        protocols=$protocols'jabber '
[b5a22e3]958        protoobjs=$protoobjs'jabber_mod.o '
[b7d3cc34]959fi
960
[59c9fa4d]961if [ "$twitter" = 0 ]; then
[1b221e0]962        echo '#undef WITH_TWITTER' >> config.h
963else
964        echo '#define WITH_TWITTER' >> config.h
965        protocols=$protocols'twitter '
966        protoobjs=$protoobjs'twitter_mod.o '
967fi
968
[b7d3cc34]969if [ "$protocols" = "PROTOCOLS = " ]; then
[43462708]970        echo "Warning: You haven't selected any communication protocol to compile!"
[b3c467b]971        echo "         BitlBee will run, but you will be unable to connect to IM servers!"
[b7d3cc34]972fi
973
974echo "PROTOCOLS = $protocols" >> Makefile.settings
975echo "PROTOOBJS = $protoobjs" >> Makefile.settings
976
[612b49d]977echo "Architecture: $arch"
[b7d3cc34]978case "$arch" in
979Linux )
980;;
981GNU/* )
982;;
983*BSD )
984;;
985Darwin )
[caceb06]986        echo 'STRIP=\# skip strip' >> Makefile.settings
[b7d3cc34]987;;
988IRIX )
989;;
990SunOS )
991        echo 'EFLAGS+=-lresolv -lnsl -lsocket' >> Makefile.settings
992        echo 'STRIP=\# skip strip' >> Makefile.settings
[70d7795]993        echo '#define NO_FD_PASSING' >> config.h
[ea3f90f]994        if [ "$arch_rel" = "5.10" ]; then
995                echo '#define NO_STRCASESTR' >> config.h
996        fi
[b7d3cc34]997;;
[8de63c3]998AIX )
999        echo 'EFLAGS+=-Wl,-brtl' >> Makefile.settings
[b7d3cc34]1000;;
1001CYGWIN* )
[54b2a36]1002        echo 'EFLAGS+=-Wl,--export-all,--out-implib,libbitlbee.dll.a' >> Makefile.settings
1003        echo 'IMPLIB=libbitlbee.dll.a' >> Makefile.settings
[b7d3cc34]1004;;
[aec56b0]1005Windows )
[e252d8c]1006        echo 'Native windows compilation is not supported anymore, use cygwin instead.'
[aec56b0]1007;;
[b7d3cc34]1008* )
[8d6c4b1]1009        echo 'We haven'\''t tested BitlBee on many platforms yet, yours is untested. YMMV.'
[92a03a0]1010        echo 'Please report any problems at https://bugs.bitlbee.org/.'
[b7d3cc34]1011;;
1012esac
1013
[f1e7407]1014if [ -n "$target" ]; then
1015        echo "Cross-compiling for: $target"
1016fi
1017
[b7d3cc34]1018echo
1019echo 'Configuration done:'
1020
1021if [ "$debug" = "1" ]; then
[b3c467b]1022        echo '  Debugging enabled.'
[b7d3cc34]1023else
[b3c467b]1024        echo '  Debugging disabled.'
[b7d3cc34]1025fi
1026
[e2472dd]1027if [ "$asan" = "1" ]; then
1028        echo '  AddressSanitizer (ASAN) enabled.'
1029else
1030        echo '  AddressSanitizer (ASAN) disabled.'
1031fi
1032
[7281ad1]1033if [ "$pie" = "1" ]; then
1034        echo '  Building PIE executable'
1035else
1036        echo '  Building non-PIE executable'
1037fi
1038
[b7d3cc34]1039if [ "$strip" = "1" ]; then
[b3c467b]1040        echo '  Binary stripping enabled.'
[b7d3cc34]1041else
[b3c467b]1042        echo '  Binary stripping disabled.'
[b7d3cc34]1043fi
1044
[764c7d1]1045if [ "$otr" = "1" ]; then
1046        echo '  Off-the-Record (OTR) Messaging enabled.'
[858ea01]1047elif [ "$otr" = "plugin" ]; then
1048        echo '  Off-the-Record (OTR) Messaging enabled (as a plugin).'
[764c7d1]1049else
1050        echo '  Off-the-Record (OTR) Messaging disabled.'
1051fi
1052
[2bd8f39]1053if [ "$systemd" = "1" ]; then
[bea6db0]1054        echo '  systemd enabled.'
[417002e]1055else
[bea6db0]1056        echo '  systemd disabled.'
[417002e]1057fi
1058
[612b49d]1059echo "  Using python: $PYTHON"
[da0202a]1060
1061if [ "$external_json_parser" = "1" ]; then
[612b49d]1062        echo '  Using system JSON parser.'
[da0202a]1063else
[612b49d]1064        echo '  Using bundled JSON parser.'
[da0202a]1065fi
1066
[612b49d]1067echo "  Using event handler: $events"
1068echo "  Using SSL library: $ssl"
[4e3df8a]1069#echo '  Building with these storage backends: '$STORAGES
[b7d3cc34]1070
1071if [ -n "$protocols" ]; then
[612b49d]1072        echo "  Building with these protocols: $protocols$protocols_mods"
[4e3df8a]1073        case "$protocols" in
1074        *purple*)
1075                echo "    Note that BitlBee-libpurple is supported on a best-effort basis. It's"
1076                echo "    not *fully* compatible with normal BitlBee. Don't use it unless you"
1077                echo "    absolutely need it (i.e. support for a certain protocol or feature)."
1078        esac
[b7d3cc34]1079else
[b3c467b]1080        echo '  Building without IM-protocol support. We wish you a lot of fun...'
[b7d3cc34]1081fi
Note: See TracBrowser for help on using the repository browser.