source: configure @ bea6db0

Last change on this file since bea6db0 was bea6db0, checked in by GitHub <noreply@…>, at 2023-03-07T21:43:36Z

Fix systemd autodetection (#175)

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