source: configure @ 82149f4

Last change on this file since 82149f4 was 82149f4, checked in by GitHub <noreply@…>, at 2023-03-04T19:59:09Z

Fixes related to external-json-parser (#165)

  • configure: append conditionally json-parser to pc file

json-parser needs to be appended to Requires section of pkg-config file
when bitlbee is configured to use external-json-parser. This change is
needed for external plugins like bitlbee-steam.

  • Makefile: do not install json.h when system json-parser is used

install-dev target should not install bundled json.h when bitlbee is
configured to use external-json-parser.

  • Use correct json.h header file with respect to external_json_parser value

The preprocessor must include correct json.h header file with respect to
external_json_parser value, otherwise function prototypes and other
definitions do not need to correspond with object used for linking.

The state before this commit is that local version lib/json.h is used
always for compilation and external_json_parser variable controls if
local lib/json.o or global libjsonparser.so will be linked.

In order to fix this problem, #include directives in lib/json_util.h and
lib/oauth2.c were changed from "json.h" to <json.h> and preprocessor -I
flags were moved after conditional json-parser flags, which is enough
for solving the issue. Additionally, USE_EXTERNAL_JSON_PARSER macro is
exported when external-json-parser is used and it is used in lib/json.h
to trigger an error message, which should prevent similar mistakes in
future.

  • Property mode set to 100755
File size: 26.1 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
[8ca172f]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
[8ca172f]162--systemd=0/1  Enable/disable systemd support $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
[2bd8f39]753        if [ -n "$systemdsystemunitdir" ] || [ $systemd -eq 1 ]; then
[8ca172f]754            echo "systemd requested but not found"
755            exit 1
756        else
757            systemd=0
758        fi
759    fi
[417002e]760fi
[8ca172f]761
762pkgconf_systemd_var() {
763    # First try deprecated variable, use newer variable if not found
[2bd8f39]764    if $PKG_CONFIG --print-variables systemd | grep -q "$1" ; then
765        $PKG_CONFIG --variable="$1" systemd
[8ca172f]766    else
[2bd8f39]767        $PKG_CONFIG --variable="$2" systemd
[8ca172f]768    fi
769}
770
[2bd8f39]771if [ "$systemd" = "1" ]; then
[8ca172f]772        if [ -z "$systemdsystemunitdir" ]; then
773                systemdsystemunitdir=$(pkgconf_systemd_var systemdsystemunitdir systemd_system_unit_dir)
[417002e]774        fi
[8ca172f]775    if [ -z "$sysusersdir" ] ; then
776        sysusersdir=$(pkgconf_systemd_var sysusersdir sysusers_dir)
777    fi
778
779        echo "SYSTEMDSYSTEMUNITDIR=$systemdsystemunitdir" >> Makefile.settings
780    echo "SYSUSERSDIR=$sysusersdir" >> Makefile.settings
[417002e]781fi
782
[66b9e86e]783if [ "$gcov" = "1" ]; then
[31fc3970]784        echo "CFLAGS+=--coverage" >> Makefile.settings
785        echo "EFLAGS+=--coverage" >> Makefile.settings
[66b9e86e]786fi
787
[2bd8f39]788if [ "$plugins" = "0" ]; then
[489847f]789        plugindir=""
[2abfbc5]790        echo '#undef WITH_PLUGINS' >> config.h
791else
792        echo '#define WITH_PLUGINS' >> config.h
793fi
794
[764c7d1]795if [ "$otr" = "auto" ]; then
[a59bd11]796        ! $PKG_CONFIG --exists libotr
797        otr=$?
798fi
799
[2bd8f39]800if [ "$otr" != "0" ] && ! $PKG_CONFIG --atleast-version=4.0 --print-errors libotr; then
[a59bd11]801        exit 1
[764c7d1]802fi
[a59bd11]803
[2bd8f39]804if [ "$otr" = "1" ]; then
[858ea01]805        # BI == built-in
806        echo '#define OTR_BI' >> config.h
[2bd8f39]807        # shellcheck disable=SC2129
[872e017]808        echo "EFLAGS+=$($PKG_CONFIG --libs libotr) $(libgcrypt-config --libs)" >> Makefile.settings
809        echo "CFLAGS+=$($PKG_CONFIG --cflags libotr) $(libgcrypt-config --cflags)" >> Makefile.settings
[858ea01]810        echo 'OTR_BI=otr.o' >> Makefile.settings
811elif [ "$otr" = "plugin" ]; then
[a59bd11]812        # for some mysterious reason beyond the comprehension of my mortal mind,
813        # the libgcrypt flags aren't needed when building as plugin. add them anyway.
[858ea01]814        echo '#define OTR_PI' >> config.h
[2bd8f39]815        # shellcheck disable=SC2129
[872e017]816        echo "OTRFLAGS=$($PKG_CONFIG --libs libotr) $(libgcrypt-config --libs)" >> Makefile.settings
817        echo "CFLAGS+=$($PKG_CONFIG --cflags libotr) $(libgcrypt-config --cflags)" >> Makefile.settings
[858ea01]818        echo 'OTR_PI=otr.so' >> Makefile.settings
[764c7d1]819fi
820
[1cef55f]821if [ -z "$PYTHON" ]; then
[f18209a]822        for pp in python python3 python2; do
823                if which $pp > /dev/null; then
824                        PYTHON=$pp
825                        break
826                fi
827        done
[1cef55f]828fi
829
[a85a8ab]830if [ "$doc" = "1" ]; then
[beb0f54]831        # check this here just in case someone tries to install it in python2.4...
[2bd8f39]832        if [ ! -e "$srcdir"/doc/user-guide/help.txt ] && ! $PYTHON -m xml.etree.ElementTree > /dev/null 2>&1; then
[a85a8ab]833                echo
[beb0f54]834                echo 'ERROR: Python (>=2.5 or 3.x) is required to generate docs'
[1cef55f]835                echo "(Use the PYTHON environment variable if it's in a weird location)"
[beb0f54]836                exit 1
[a85a8ab]837        fi
[beb0f54]838        echo "DOC=1" >> Makefile.settings
[1cef55f]839        echo "PYTHON=$PYTHON" >> Makefile.settings
[ceebeb1]840fi
841
[70ec7ab]842get_version
[e26aa72]843
[2bd8f39]844if [ ! "$BITLBEE_VERSION" = "$REAL_BITLBEE_VERSION" ]; then
845        echo "Spoofing version number: $BITLBEE_VERSION"
846        echo "#undef BITLBEE_VERSION" >> config.h
[b6df23d]847        echo '#define BITLBEE_VERSION "'$BITLBEE_VERSION'"' >> config.h
[ffea9b9]848        echo
[b7d3cc34]849fi
850
[4fca1db]851if ! make helloworld > /dev/null 2>&1; then
852        echo "WARNING: Your version of make (BSD make?) does not support BitlBee's makefiles."
853        echo "BitlBee needs GNU make to build properly. On most systems GNU make is available"
854        echo "under the name 'gmake'."
855        echo
856        if gmake helloworld > /dev/null 2>&1; then
857                echo "gmake seems to be available on your machine, great."
858                echo
859        else
860                echo "gmake is not installed (or not working). Please try to install it."
861                echo
862        fi
863fi
864
[54b2a36]865pkgconfiglibs=''
866case "$arch" in
867CYGWIN* )
[2bd8f39]868        pkgconfiglibs="-L${libdir} -lbitlbee -no-undefined"
[54b2a36]869esac
870
[82149f4]871pkgconfigrequires='glib-2.0'
872if [ "$external_json_parser" = '1' ]; then
873        pkgconfigrequires="$pkgconfigrequires json-parser"
874fi
875
[b95b0c8]876cat <<EOF >bitlbee.pc
[e506d6c]877prefix=$prefix
878includedir=$includedir
[489847f]879plugindir=$plugindir
[54b2a36]880libdir=$libdir
[ad66dcd]881datadir=$datadir
[e506d6c]882
883Name: bitlbee
884Description: IRC to IM gateway
[82149f4]885Requires: $pkgconfigrequires
[e506d6c]886Version: $BITLBEE_VERSION
[54b2a36]887Libs: $pkgconfiglibs
[e506d6c]888Cflags: -I\${includedir}
889
890EOF
891
[b7d3cc34]892protocols=''
893protoobjs=''
894
[2bd8f39]895if [ "$purple" = "0" ]; then
[e248c7f]896        echo '#undef WITH_PURPLE' >> config.h
897else
[e08e53c]898        if ! $PKG_CONFIG purple; then
899                echo
900                echo 'Cannot find libpurple development libraries, aborting. (Install libpurple-dev?)'
901                exit 1
902        fi
[e248c7f]903        echo '#define WITH_PURPLE' >> config.h
[b95b0c8]904        cat<<EOF >>Makefile.settings
[e08e53c]905EFLAGS += $($PKG_CONFIG purple --libs)
906PURPLE_CFLAGS += $($PKG_CONFIG purple --cflags)
907EOF
[e248c7f]908        protocols=$protocols'purple '
909        protoobjs=$protoobjs'purple_mod.o '
910
[04e2a05]911        # only disable these if the user didn't enable them explicitly
912        [ "$jabber" = "default-on" ] && jabber=0
[18e1f3b]913
914        echo '#undef PACKAGE' >> config.h
915        echo '#define PACKAGE "BitlBee-LIBPURPLE"' >> config.h
[bda2975]916       
917        if [ "$events" = "libevent" ]; then
918                echo 'Warning: Some libpurple modules (including msn-pecan) do their event handling'
919                echo 'outside libpurple, talking to GLib directly. At least for now the combination'
920                echo 'libpurple + libevent is *not* recommended!'
[c775a58]921                echo
[bda2975]922        fi
[e248c7f]923fi
924
[b0a89cc]925case "$CC" in
926*gcc* )
[e371011]927        echo CFLAGS+=-MMD -MF .depend/\$@.d >> Makefile.settings
[fe92921]928        for i in . lib tests protocols protocols/*/; do
[2bd8f39]929                mkdir -p "$i"/.depend
[b0a89cc]930        done
931esac
932
[2bd8f39]933if [ "$jabber" = "0" ]; then
[b7d3cc34]934        echo '#undef WITH_JABBER' >> config.h
935else
936        echo '#define WITH_JABBER' >> config.h
937        protocols=$protocols'jabber '
[b5a22e3]938        protoobjs=$protoobjs'jabber_mod.o '
[b7d3cc34]939fi
940
[2bd8f39]941if [ "$twitter" = "0" ]; then
[1b221e0]942        echo '#undef WITH_TWITTER' >> config.h
943else
944        echo '#define WITH_TWITTER' >> config.h
945        protocols=$protocols'twitter '
946        protoobjs=$protoobjs'twitter_mod.o '
947fi
948
[b7d3cc34]949if [ "$protocols" = "PROTOCOLS = " ]; then
[43462708]950        echo "Warning: You haven't selected any communication protocol to compile!"
[b3c467b]951        echo "         BitlBee will run, but you will be unable to connect to IM servers!"
[b7d3cc34]952fi
953
954echo "PROTOCOLS = $protocols" >> Makefile.settings
955echo "PROTOOBJS = $protoobjs" >> Makefile.settings
956
[2bd8f39]957echo Architecture: "$arch"
[b7d3cc34]958case "$arch" in
959Linux )
960;;
961GNU/* )
962;;
963*BSD )
964;;
965Darwin )
[caceb06]966        echo 'STRIP=\# skip strip' >> Makefile.settings
[b7d3cc34]967;;
968IRIX )
969;;
970SunOS )
971        echo 'EFLAGS+=-lresolv -lnsl -lsocket' >> Makefile.settings
972        echo 'STRIP=\# skip strip' >> Makefile.settings
[70d7795]973        echo '#define NO_FD_PASSING' >> config.h
[ea3f90f]974        if [ "$arch_rel" = "5.10" ]; then
975                echo '#define NO_STRCASESTR' >> config.h
976        fi
[b7d3cc34]977;;
[8de63c3]978AIX )
979        echo 'EFLAGS+=-Wl,-brtl' >> Makefile.settings
[b7d3cc34]980;;
981CYGWIN* )
[54b2a36]982        echo 'EFLAGS+=-Wl,--export-all,--out-implib,libbitlbee.dll.a' >> Makefile.settings
983        echo 'IMPLIB=libbitlbee.dll.a' >> Makefile.settings
[b7d3cc34]984;;
[aec56b0]985Windows )
[e252d8c]986        echo 'Native windows compilation is not supported anymore, use cygwin instead.'
[aec56b0]987;;
[b7d3cc34]988* )
[8d6c4b1]989        echo 'We haven'\''t tested BitlBee on many platforms yet, yours is untested. YMMV.'
990        echo 'Please report any problems at http://bugs.bitlbee.org/.'
[b7d3cc34]991;;
992esac
993
[f1e7407]994if [ -n "$target" ]; then
995        echo "Cross-compiling for: $target"
996fi
997
[b7d3cc34]998echo
999echo 'Configuration done:'
1000
1001if [ "$debug" = "1" ]; then
[b3c467b]1002        echo '  Debugging enabled.'
[b7d3cc34]1003else
[b3c467b]1004        echo '  Debugging disabled.'
[b7d3cc34]1005fi
1006
[e2472dd]1007if [ "$asan" = "1" ]; then
1008        echo '  AddressSanitizer (ASAN) enabled.'
1009else
1010        echo '  AddressSanitizer (ASAN) disabled.'
1011fi
1012
[7281ad1]1013if [ "$pie" = "1" ]; then
1014        echo '  Building PIE executable'
1015else
1016        echo '  Building non-PIE executable'
1017fi
1018
[b7d3cc34]1019if [ "$strip" = "1" ]; then
[b3c467b]1020        echo '  Binary stripping enabled.'
[b7d3cc34]1021else
[b3c467b]1022        echo '  Binary stripping disabled.'
[b7d3cc34]1023fi
1024
[764c7d1]1025if [ "$otr" = "1" ]; then
1026        echo '  Off-the-Record (OTR) Messaging enabled.'
[858ea01]1027elif [ "$otr" = "plugin" ]; then
1028        echo '  Off-the-Record (OTR) Messaging enabled (as a plugin).'
[764c7d1]1029else
1030        echo '  Off-the-Record (OTR) Messaging disabled.'
1031fi
1032
[2bd8f39]1033if [ "$systemd" = "1" ]; then
[417002e]1034        echo '  systemd enabled.'
1035else
1036        echo '  systemd disabled.'
1037fi
1038
[f18209a]1039echo '  Using python: '$PYTHON
[da0202a]1040
1041if [ "$external_json_parser" = "1" ]; then
1042    echo '  Using system JSON parser.'
1043else
1044    echo '  Using bundled JSON parser.'
1045fi
1046
[b3c467b]1047echo '  Using event handler: '$events
1048echo '  Using SSL library: '$ssl
[4e3df8a]1049#echo '  Building with these storage backends: '$STORAGES
[b7d3cc34]1050
1051if [ -n "$protocols" ]; then
[2bd8f39]1052        echo '  Building with these protocols:' "$protocols""$protocols_mods"
[4e3df8a]1053        case "$protocols" in
1054        *purple*)
1055                echo "    Note that BitlBee-libpurple is supported on a best-effort basis. It's"
1056                echo "    not *fully* compatible with normal BitlBee. Don't use it unless you"
1057                echo "    absolutely need it (i.e. support for a certain protocol or feature)."
1058        esac
[b7d3cc34]1059else
[b3c467b]1060        echo '  Building without IM-protocol support. We wish you a lot of fun...'
[b7d3cc34]1061fi
Note: See TracBrowser for help on using the repository browser.