source: configure @ d2394be

Last change on this file since d2394be was b6df23d, checked in by GitHub <noreply@…>, at 2023-02-02T12:05:10Z

configure: fix single quotes in a C string when spoofing BITLBEE_VERSION (#170)

  • 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
[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"
[2bd8f39]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
332echo CFLAGS+=-I"${srcdir}" -I"${srcdir}"/lib -I"${srcdir}"/protocols -I. >> Makefile.settings
[b7d3cc34]333
[41a94dd]334echo CFLAGS+=-DHAVE_CONFIG_H -D_GNU_SOURCE >> Makefile.settings
[f712188]335
[2bd8f39]336if type gcc > /dev/null 2> /dev/null; then
[5973412]337        CC=gcc
[b7d3cc34]338elif type cc > /dev/null 2> /dev/null; then
[5973412]339        CC=cc
[b7d3cc34]340else
341        echo 'Cannot find a C compiler, aborting.'
342        exit 1;
343fi
344
[5973412]345echo "CC=$CC" >> Makefile.settings;
[1de945b]346if echo $CC | grep -qw 'gcc\|clang'; then
[daae10f]347        # Apparently -Wall is gcc-specific?
[1de945b]348        echo CFLAGS+=-Wall -Wformat -Werror=format-security >> Makefile.settings
[daae10f]349fi
[5973412]350
[f1e7407]351if [ -z "$LD" ]; then
352        if type ld > /dev/null 2> /dev/null; then
353                LD=ld
354        else
355                echo 'Cannot find ld, aborting.'
356                exit 1;
357        fi
[b7d3cc34]358fi
359
[f1e7407]360echo "LD=$LD" >> Makefile.settings
361
[32c632f]362if [ -z "$PKG_CONFIG" ]; then
363        PKG_CONFIG=pkg-config
364fi
365
[9ae8f82]366if ! $PKG_CONFIG --version > /dev/null 2>/dev/null; then
367        echo
368        echo 'Cannot find pkg-config, aborting.'
369        exit 1
370fi
371
372if $PKG_CONFIG glib-2.0; then
[670204f]373        if $PKG_CONFIG glib-2.0 --atleast-version=$GLIB_MIN_VERSION; then
[b95b0c8]374                cat<<EOF >>Makefile.settings
[4966712a]375EFLAGS+=$($PKG_CONFIG --libs glib-2.0 gmodule-2.0)
376CFLAGS+=$($PKG_CONFIG --cflags glib-2.0 gmodule-2.0)
[b7d3cc34]377EOF
[670204f]378        else
379                echo
[2bd8f39]380                echo "Found glib2 $($PKG_CONFIG glib-2.0 --modversion), but version $GLIB_MIN_VERSION or newer is required."
[670204f]381                exit 1
382        fi
[b7d3cc34]383else
[670204f]384        echo
[574af7e]385        echo 'Cannot find glib2 development libraries, aborting. (Install libglib2-dev?)'
[670204f]386        exit 1
[b7d3cc34]387fi
388
[85cf37f]389if [ "$events" = "libevent" ]; then
[003553b]390        if ! [ -f "${libevent}include/event.h" ]; then
[85cf37f]391                echo
392                echo 'Warning: Could not find event.h, you might have to install it and/or specify'
393                echo 'its location using the --libevent= argument. (Example: If event.h is in'
394                echo '/usr/local/include and binaries are in /usr/local/lib: --libevent=/usr/local)'
395        fi
396       
397        echo '#define EVENTS_LIBEVENT' >> config.h
[b95b0c8]398        cat <<EOF >>Makefile.settings
[85cf37f]399EFLAGS+=-levent -L${libevent}lib
400CFLAGS+=-I${libevent}include
401EOF
402elif [ "$events" = "glib" ]; then
403        ## We already use glib anyway, so this is all we need (and in fact not even this, but just to be sure...):
404        echo '#define EVENTS_GLIB' >> config.h
[b7d3cc34]405else
406        echo
[85cf37f]407        echo 'ERROR: Unknown event handler specified.'
408        exit 1
[b7d3cc34]409fi
[85cf37f]410echo 'EVENT_HANDLER=events_'$events'.o' >> Makefile.settings
[b7d3cc34]411
[da0202a]412if [ "$external_json_parser" = "auto" ]; then
413        if pkg-config --exists json-parser; then
414                external_json_parser=1
415        else
416                external_json_parser=0
417        fi
418fi
419echo "EXTERNAL_JSON_PARSER=$external_json_parser" >> Makefile.settings
420if [ "$external_json_parser" = "1" ]; then
[2bd8f39]421    # shellcheck disable=SC2129
[da0202a]422    echo "CFLAGS+=$(pkg-config --cflags json-parser)" >> Makefile.settings
423    echo "LDFLAGS_BITLBEE+=$(pkg-config --libs json-parser)" >> Makefile.settings
424    echo "LDFLAGS_TESTS+=$(pkg-config --libs json-parser)" >> Makefile.settings
425fi
426
427
[b7d3cc34]428detect_gnutls()
429{
[4af7b4f]430        if $PKG_CONFIG --exists gnutls; then
[b95b0c8]431                cat <<EOF >>Makefile.settings
[4966712a]432EFLAGS+=$($PKG_CONFIG --libs gnutls) $(libgcrypt-config --libs)
433CFLAGS+=$($PKG_CONFIG --cflags gnutls) $(libgcrypt-config --cflags)
[4af7b4f]434EOF
435                ssl=gnutls
[a59bd11]436                if ! $PKG_CONFIG gnutls --atleast-version=2.8; then
[5513f3e]437                        echo
438                        echo 'Warning: With GnuTLS versions <2.8, certificate expire dates are not verified.'
439                fi
[4af7b4f]440                ret=1
441        elif libgnutls-config --version > /dev/null 2> /dev/null; then
[b95b0c8]442                cat <<EOF >>Makefile.settings
[4966712a]443EFLAGS+=$(libgnutls-config --libs) $(libgcrypt-config --libs)
444CFLAGS+=$(libgnutls-config --cflags) $(libgcrypt-config --cflags)
[b7d3cc34]445EOF
446               
447                ssl=gnutls
448                ret=1;
449        else
450                ret=0;
451        fi;
452}
453
454detect_nss()
455{
[ef043d3]456        if $PKG_CONFIG --version > /dev/null 2>/dev/null && $PKG_CONFIG nss; then
[b95b0c8]457                cat<<EOF >>Makefile.settings
[4966712a]458EFLAGS+=$($PKG_CONFIG --libs nss)
459CFLAGS+=$($PKG_CONFIG --cflags nss)
[b7d3cc34]460EOF
461               
462                ssl=nss
463                ret=1;
464        else
465                ret=0;
466        fi;
467}
468
[36cf9fd]469RESOLV_TESTCODE='
[aee8c19]470#include <sys/types.h>
471#include <netinet/in.h>
[36cf9fd]472#include <arpa/nameser.h>
473#include <resolv.h>
474
[632627e]475int main()
476{
477
478        res_query( NULL, 0, 0, NULL, 0);
479        dn_expand( NULL, NULL, NULL, NULL, 0);
480        dn_skipname( NULL, NULL);
481}
482'
483RESOLV_NS_TESTCODE='
484#include <sys/types.h>
485#include <netinet/in.h>
486#include <arpa/nameser.h>
487#include <resolv.h>
488
[36cf9fd]489int main()
490{
491        ns_initparse( NULL, 0, NULL );
492        ns_parserr( NULL, ns_s_an, 0, NULL );
493}
494'
[632627e]495RESOLV_NS_TYPES_TESTCODE='
496#include <sys/types.h>
497#include <netinet/in.h>
498#include <arpa/nameser.h>
499
500int main()
501{
502        ns_msg nsh;
503        ns_rr rr;
504
[fb87924]505        /* Not all platforms we want to work on have
506         ns_* routines, so use this to make sure
507         the compiler uses it.*/
508        return (int)(sizeof(nsh) + sizeof(rr));
[632627e]509}
510'
[36cf9fd]511
[0d2cd10]512BACKTRACE_TESTCODE='
513#include <execinfo.h>
514
515int main()
516{
517        void *trace[16];
518        return backtrace(trace, 16);
519}
520'
521
[36cf9fd]522detect_resolv_dynamic()
523{
[aee8c19]524        case "$arch" in
[632627e]525        OpenBSD )
526                # In FreeBSD res_*/dn_* routines are present in libc.so
527                LIBRESOLV=;;
[aee8c19]528        FreeBSD )
[632627e]529                # In FreeBSD res_*/dn_* routines are present in libc.so
530                LIBRESOLV=;;
531        CYGWIN* )
532                # In Cygwin res_*/dn_* routines are present in libc.so
[aee8c19]533                LIBRESOLV=;;
534        * )
535                LIBRESOLV=-lresolv;;
536        esac
[4fca1db]537        TMPFILE=$(mktemp /tmp/bitlbee-configure.XXXXXX)
[8462239]538        ret=1
[2bd8f39]539        if echo "$RESOLV_TESTCODE" | $CC -o "$TMPFILE" -x c - $LIBRESOLV >/dev/null 2>/dev/null ; then
[aee8c19]540                echo "EFLAGS+=$LIBRESOLV" >> Makefile.settings
[8462239]541                ret=0
[36cf9fd]542        fi
543
[2bd8f39]544        rm -f "$TMPFILE"
[8462239]545        return $ret
[36cf9fd]546}
547
548detect_resolv_static()
549{
[4fca1db]550        TMPFILE=$(mktemp /tmp/bitlbee-configure.XXXXXX)
[8462239]551        ret=1
[36cf9fd]552        for i in $systemlibdirs; do
[2bd8f39]553                if [ -f "$i"/libresolv.a ]; then
554                        if echo "$RESOLV_TESTCODE" | $CC -o "$TMPFILE" -x c - -Wl,"$i"/libresolv.a >/dev/null 2>/dev/null ; then
555                                echo "EFLAGS+=$i/libresolv.a" >> Makefile.settings
[8462239]556                                ret=0
[36cf9fd]557                        fi
558                fi
559        done
560
[2bd8f39]561        rm -f "$TMPFILE"
[8462239]562        return $ret
[36cf9fd]563}
564
[632627e]565detect_resolv_ns_dynamic()
566{
567        case "$arch" in
568        FreeBSD )
569                # In FreeBSD ns_ routines are present in libc.so
570                LIBRESOLV=;;
571        * )
572                LIBRESOLV=-lresolv;;
573        esac
574        TMPFILE=$(mktemp /tmp/bitlbee-configure.XXXXXX)
575        ret=1
[2bd8f39]576        if echo "$RESOLV_NS_TESTCODE" | $CC -o "$TMPFILE" -x c - $LIBRESOLV >/dev/null 2>/dev/null ; then
[a67e781]577                ret=0
578        fi
[632627e]579
[2bd8f39]580        rm -f "$TMPFILE"
[632627e]581        return $ret
582}
583
584detect_resolv_ns_static()
585{
586        TMPFILE=$(mktemp /tmp/bitlbee-configure.XXXXXX)
587        ret=1
588        for i in $systemlibdirs; do
[2bd8f39]589                if [ -f "$i"/libresolv.a ]; then
590                        if echo "$RESOLV_NS_TESTCODE" | $CC -o "$TMPFILE" -x c - -Wl,"$i"/libresolv.a >/dev/null 2>/dev/null ; then
[a67e781]591                                ret=0
592                        fi
[632627e]593                fi
594        done
595
[2bd8f39]596        rm -f "$TMPFILE"
[632627e]597        return $ret
598}
599
600detect_nameser_has_ns_types()
601{
[a67e781]602        TMPFILE=$(mktemp /tmp/bitlbee-configure.XXXXXX)
603        ret=1
604        # since we aren't actually linking with ns_* routines
605        # we can just compile the test code
[2bd8f39]606        if echo "$RESOLV_NS_TYPES_TESTCODE" | $CC -o "$TMPFILE" -x c -  >/dev/null 2>/dev/null ; then
[a67e781]607                ret=0
608        fi
609
[2bd8f39]610        rm -f "$TMPFILE"
[a67e781]611        return $ret
[632627e]612}
613
[0d2cd10]614detect_backtrace()
615{
616        TMPFILE=$(mktemp /tmp/bitlbee-configure.XXXXXX)
617        ret=1
[2bd8f39]618        if echo "$BACKTRACE_TESTCODE" | $CC -o "$TMPFILE" -x c -  >/dev/null 2>/dev/null ; then
[0d2cd10]619                ret=0
620        fi
621
[2bd8f39]622        rm -f "$TMPFILE"
[0d2cd10]623        return $ret
624}
625
[b3c467b]626if [ "$ssl" = "auto" ]; then
627        detect_gnutls
[b7d3cc34]628        if [ "$ret" = "0" ]; then
[c5920df]629                # Disable NSS for now as it's known to not work very well ATM.
630                #detect_nss
[191cfb1]631                :
[b7d3cc34]632        fi
[b3c467b]633elif [ "$ssl" = "gnutls" ]; then
634        detect_gnutls
635elif [ "$ssl" = "nss" ]; then
636        detect_nss
637elif [ "$ssl" = "openssl" ]; then
638        echo
639        echo 'No detection code exists for OpenSSL. Make sure that you have a complete'
[b3eee9b]640        echo 'installation of OpenSSL (including devel/header files) before reporting'
[b3c467b]641        echo 'compilation problems.'
642        echo
643        echo 'Also, keep in mind that the OpenSSL is, according to some people, not'
[b3eee9b]644        echo 'completely GPL-compatible. Using GnuTLS is recommended and better supported'
645        echo 'by us. However, on many BSD machines, OpenSSL can be considered part of the'
646        echo 'operating system, which makes it GPL-compatible.'
[b3c467b]647        echo
648        echo 'For more info, see: http://www.openssl.org/support/faq.html#LEGAL2'
649        echo '                    http://www.gnome.org/~markmc/openssl-and-the-gpl.html'
650        echo
651        echo 'Please note that distributing a BitlBee binary which links to OpenSSL is'
652        echo 'probably illegal. If you want to create and distribute a binary BitlBee'
[b3eee9b]653        echo 'package, you really should use GnuTLS instead.'
[b3c467b]654        echo
655        echo 'Also, the OpenSSL license requires us to say this:'
656        echo ' *    "This product includes software developed by the OpenSSL Project'
657        echo ' *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"'
[b7d3cc34]658       
[b3c467b]659        echo 'EFLAGS+=-lssl -lcrypto' >> Makefile.settings
660       
661        ret=1
662else
663        echo
664        echo 'ERROR: Unknown SSL library specified.'
665        exit 1
[b7d3cc34]666fi
667
[b3c467b]668if [ "$ret" = "0" ]; then
669        echo
670        echo 'ERROR: Could not find a suitable SSL library (GnuTLS, libnss or OpenSSL).'
671        echo '       Please note that this script doesn'\''t have detection code for OpenSSL,'
[e1d3f98]672        echo '       so if you want to use that, you have to select it by hand.'
[b7d3cc34]673       
[b3c467b]674        exit 1
675fi;
676
677echo 'SSL_CLIENT=ssl_'$ssl'.o' >> Makefile.settings
678
[632627e]679if detect_nameser_has_ns_types; then
680        echo '#define NAMESER_HAS_NS_TYPES' >> config.h
681fi
[36cf9fd]682if detect_resolv_dynamic || detect_resolv_static; then
683        echo '#define HAVE_RESOLV_A' >> config.h
[a67e781]684        if detect_resolv_ns_dynamic || detect_resolv_ns_static; then
685                echo '#define HAVE_RESOLV_A_WITH_NS' >> config.h
686        fi
[632627e]687else
[a67e781]688        echo 'Insufficient resolv routines. Jabber server must be set explicitly'
[36cf9fd]689fi
[36e9f62]690
[0d2cd10]691if detect_backtrace; then
692        echo '#define HAVE_BACKTRACE' >> config.h
[2bd8f39]693        echo "#define CRASHFILE \"${config}crash.log\"" >> config.h
[0d2cd10]694fi
[632627e]695
[ba7d16f]696STORAGES="xml"
[b3c467b]697
698for i in $STORAGES; do
699        STORAGE_OBJS="$STORAGE_OBJS storage_$i.o"
700done
[2bd8f39]701echo "STORAGE_OBJS=$STORAGE_OBJS" >> Makefile.settings
[b3c467b]702
[8e6ecfe]703authobjs=
704authlibs=
[2bd8f39]705if [ "$pam" = "0" ]; then
[a6005da]706        echo '#undef WITH_PAM' >> config.h
707else
708        if ! echo '#include <security/pam_appl.h>' | $CC -E - >/dev/null 2>/dev/null; then
709                echo 'Cannot find libpam development libraries, aborting. (Install libpam0g-dev?)'
710                exit 1
711        fi
712        echo '#define WITH_PAM' >> config.h
713        authobjs=$authobjs'auth_pam.o '
714        authlibs=$authlibs'-lpam '
715fi
[2bd8f39]716if [ "$ldap" = "0" ]; then
[50bb490]717        echo '#undef WITH_LDAP' >> config.h
718else
719        if ! echo '#include <ldap.h>' | $CC -E - >/dev/null 2>/dev/null; then
720                echo 'Cannot find libldap development libraries, aborting. (Install libldap2-dev?)'
721                exit 1
722        fi
723        echo '#define WITH_LDAP' >> config.h
724        authobjs=$authobjs'auth_ldap.o '
725        authlibs=$authlibs'-lldap '
726fi
[2bd8f39]727echo AUTH_OBJS="$authobjs" >> Makefile.settings
728echo EFLAGS+="$authlibs" >> Makefile.settings
[8e6ecfe]729
[2bd8f39]730if [ "$strip" = "0" ]; then
[b7d3cc34]731        echo "STRIP=\# skip strip" >> Makefile.settings;
732else
[2bd8f39]733        if [ "$debug" = "1" ]; then
[b7d3cc34]734                echo
735                echo 'Stripping binaries does not make sense when debugging. Stripping disabled.'
736                echo 'STRIP=\# skip strip' >> Makefile.settings
737                strip=0;
738        elif [ -n "$STRIP" ]; then
739                echo "STRIP=$STRIP" >> Makefile.settings;
740        elif type strip > /dev/null 2> /dev/null; then
741                echo "STRIP=strip" >> Makefile.settings;
742        else
743                echo
744                echo 'No strip utility found, cannot remove unnecessary parts from executable.'
745                echo 'STRIP=\# skip strip' >> Makefile.settings
746                strip=0;
747        fi;
748fi
749
[2bd8f39]750if [ ! "$systemd" = "0" ]; then
[8ca172f]751    if ! $PKG_CONFIG --exists systemd ; then
[2bd8f39]752        if [ -n "$systemdsystemunitdir" ] || [ $systemd -eq 1 ]; then
[8ca172f]753            echo "systemd requested but not found"
754            exit 1
755        else
756            systemd=0
757        fi
758    fi
[417002e]759fi
[8ca172f]760
761pkgconf_systemd_var() {
762    # First try deprecated variable, use newer variable if not found
[2bd8f39]763    if $PKG_CONFIG --print-variables systemd | grep -q "$1" ; then
764        $PKG_CONFIG --variable="$1" systemd
[8ca172f]765    else
[2bd8f39]766        $PKG_CONFIG --variable="$2" systemd
[8ca172f]767    fi
768}
769
[2bd8f39]770if [ "$systemd" = "1" ]; then
[8ca172f]771        if [ -z "$systemdsystemunitdir" ]; then
772                systemdsystemunitdir=$(pkgconf_systemd_var systemdsystemunitdir systemd_system_unit_dir)
[417002e]773        fi
[8ca172f]774    if [ -z "$sysusersdir" ] ; then
775        sysusersdir=$(pkgconf_systemd_var sysusersdir sysusers_dir)
776    fi
777
778        echo "SYSTEMDSYSTEMUNITDIR=$systemdsystemunitdir" >> Makefile.settings
779    echo "SYSUSERSDIR=$sysusersdir" >> Makefile.settings
[417002e]780fi
781
[66b9e86e]782if [ "$gcov" = "1" ]; then
[31fc3970]783        echo "CFLAGS+=--coverage" >> Makefile.settings
784        echo "EFLAGS+=--coverage" >> Makefile.settings
[66b9e86e]785fi
786
[2bd8f39]787if [ "$plugins" = "0" ]; then
[489847f]788        plugindir=""
[2abfbc5]789        echo '#undef WITH_PLUGINS' >> config.h
790else
791        echo '#define WITH_PLUGINS' >> config.h
792fi
793
[764c7d1]794if [ "$otr" = "auto" ]; then
[a59bd11]795        ! $PKG_CONFIG --exists libotr
796        otr=$?
797fi
798
[2bd8f39]799if [ "$otr" != "0" ] && ! $PKG_CONFIG --atleast-version=4.0 --print-errors libotr; then
[a59bd11]800        exit 1
[764c7d1]801fi
[a59bd11]802
[2bd8f39]803if [ "$otr" = "1" ]; then
[858ea01]804        # BI == built-in
805        echo '#define OTR_BI' >> config.h
[2bd8f39]806        # shellcheck disable=SC2129
[872e017]807        echo "EFLAGS+=$($PKG_CONFIG --libs libotr) $(libgcrypt-config --libs)" >> Makefile.settings
808        echo "CFLAGS+=$($PKG_CONFIG --cflags libotr) $(libgcrypt-config --cflags)" >> Makefile.settings
[858ea01]809        echo 'OTR_BI=otr.o' >> Makefile.settings
810elif [ "$otr" = "plugin" ]; then
[a59bd11]811        # for some mysterious reason beyond the comprehension of my mortal mind,
812        # the libgcrypt flags aren't needed when building as plugin. add them anyway.
[858ea01]813        echo '#define OTR_PI' >> config.h
[2bd8f39]814        # shellcheck disable=SC2129
[872e017]815        echo "OTRFLAGS=$($PKG_CONFIG --libs libotr) $(libgcrypt-config --libs)" >> Makefile.settings
816        echo "CFLAGS+=$($PKG_CONFIG --cflags libotr) $(libgcrypt-config --cflags)" >> Makefile.settings
[858ea01]817        echo 'OTR_PI=otr.so' >> Makefile.settings
[764c7d1]818fi
819
[1cef55f]820if [ -z "$PYTHON" ]; then
[f18209a]821        for pp in python python3 python2; do
822                if which $pp > /dev/null; then
823                        PYTHON=$pp
824                        break
825                fi
826        done
[1cef55f]827fi
828
[a85a8ab]829if [ "$doc" = "1" ]; then
[beb0f54]830        # check this here just in case someone tries to install it in python2.4...
[2bd8f39]831        if [ ! -e "$srcdir"/doc/user-guide/help.txt ] && ! $PYTHON -m xml.etree.ElementTree > /dev/null 2>&1; then
[a85a8ab]832                echo
[beb0f54]833                echo 'ERROR: Python (>=2.5 or 3.x) is required to generate docs'
[1cef55f]834                echo "(Use the PYTHON environment variable if it's in a weird location)"
[beb0f54]835                exit 1
[a85a8ab]836        fi
[beb0f54]837        echo "DOC=1" >> Makefile.settings
[1cef55f]838        echo "PYTHON=$PYTHON" >> Makefile.settings
[ceebeb1]839fi
840
[70ec7ab]841get_version
[e26aa72]842
[2bd8f39]843if [ ! "$BITLBEE_VERSION" = "$REAL_BITLBEE_VERSION" ]; then
844        echo "Spoofing version number: $BITLBEE_VERSION"
845        echo "#undef BITLBEE_VERSION" >> config.h
[b6df23d]846        echo '#define BITLBEE_VERSION "'$BITLBEE_VERSION'"' >> config.h
[ffea9b9]847        echo
[b7d3cc34]848fi
849
[4fca1db]850if ! make helloworld > /dev/null 2>&1; then
851        echo "WARNING: Your version of make (BSD make?) does not support BitlBee's makefiles."
852        echo "BitlBee needs GNU make to build properly. On most systems GNU make is available"
853        echo "under the name 'gmake'."
854        echo
855        if gmake helloworld > /dev/null 2>&1; then
856                echo "gmake seems to be available on your machine, great."
857                echo
858        else
859                echo "gmake is not installed (or not working). Please try to install it."
860                echo
861        fi
862fi
863
[54b2a36]864pkgconfiglibs=''
865case "$arch" in
866CYGWIN* )
[2bd8f39]867        pkgconfiglibs="-L${libdir} -lbitlbee -no-undefined"
[54b2a36]868esac
869
[b95b0c8]870cat <<EOF >bitlbee.pc
[e506d6c]871prefix=$prefix
872includedir=$includedir
[489847f]873plugindir=$plugindir
[54b2a36]874libdir=$libdir
[ad66dcd]875datadir=$datadir
[e506d6c]876
877Name: bitlbee
878Description: IRC to IM gateway
879Requires: glib-2.0
880Version: $BITLBEE_VERSION
[54b2a36]881Libs: $pkgconfiglibs
[e506d6c]882Cflags: -I\${includedir}
883
884EOF
885
[b7d3cc34]886protocols=''
887protoobjs=''
888
[2bd8f39]889if [ "$purple" = "0" ]; then
[e248c7f]890        echo '#undef WITH_PURPLE' >> config.h
891else
[e08e53c]892        if ! $PKG_CONFIG purple; then
893                echo
894                echo 'Cannot find libpurple development libraries, aborting. (Install libpurple-dev?)'
895                exit 1
896        fi
[e248c7f]897        echo '#define WITH_PURPLE' >> config.h
[b95b0c8]898        cat<<EOF >>Makefile.settings
[e08e53c]899EFLAGS += $($PKG_CONFIG purple --libs)
900PURPLE_CFLAGS += $($PKG_CONFIG purple --cflags)
901EOF
[e248c7f]902        protocols=$protocols'purple '
903        protoobjs=$protoobjs'purple_mod.o '
904
[04e2a05]905        # only disable these if the user didn't enable them explicitly
906        [ "$jabber" = "default-on" ] && jabber=0
[18e1f3b]907
908        echo '#undef PACKAGE' >> config.h
909        echo '#define PACKAGE "BitlBee-LIBPURPLE"' >> config.h
[bda2975]910       
911        if [ "$events" = "libevent" ]; then
912                echo 'Warning: Some libpurple modules (including msn-pecan) do their event handling'
913                echo 'outside libpurple, talking to GLib directly. At least for now the combination'
914                echo 'libpurple + libevent is *not* recommended!'
[c775a58]915                echo
[bda2975]916        fi
[e248c7f]917fi
918
[b0a89cc]919case "$CC" in
920*gcc* )
[e371011]921        echo CFLAGS+=-MMD -MF .depend/\$@.d >> Makefile.settings
[fe92921]922        for i in . lib tests protocols protocols/*/; do
[2bd8f39]923                mkdir -p "$i"/.depend
[b0a89cc]924        done
925esac
926
[2bd8f39]927if [ "$jabber" = "0" ]; then
[b7d3cc34]928        echo '#undef WITH_JABBER' >> config.h
929else
930        echo '#define WITH_JABBER' >> config.h
931        protocols=$protocols'jabber '
[b5a22e3]932        protoobjs=$protoobjs'jabber_mod.o '
[b7d3cc34]933fi
934
[2bd8f39]935if [ "$twitter" = "0" ]; then
[1b221e0]936        echo '#undef WITH_TWITTER' >> config.h
937else
938        echo '#define WITH_TWITTER' >> config.h
939        protocols=$protocols'twitter '
940        protoobjs=$protoobjs'twitter_mod.o '
941fi
942
[b7d3cc34]943if [ "$protocols" = "PROTOCOLS = " ]; then
[43462708]944        echo "Warning: You haven't selected any communication protocol to compile!"
[b3c467b]945        echo "         BitlBee will run, but you will be unable to connect to IM servers!"
[b7d3cc34]946fi
947
948echo "PROTOCOLS = $protocols" >> Makefile.settings
949echo "PROTOOBJS = $protoobjs" >> Makefile.settings
950
[2bd8f39]951echo Architecture: "$arch"
[b7d3cc34]952case "$arch" in
953Linux )
954;;
955GNU/* )
956;;
957*BSD )
958;;
959Darwin )
[caceb06]960        echo 'STRIP=\# skip strip' >> Makefile.settings
[b7d3cc34]961;;
962IRIX )
963;;
964SunOS )
965        echo 'EFLAGS+=-lresolv -lnsl -lsocket' >> Makefile.settings
966        echo 'STRIP=\# skip strip' >> Makefile.settings
[70d7795]967        echo '#define NO_FD_PASSING' >> config.h
[ea3f90f]968        if [ "$arch_rel" = "5.10" ]; then
969                echo '#define NO_STRCASESTR' >> config.h
970        fi
[b7d3cc34]971;;
[8de63c3]972AIX )
973        echo 'EFLAGS+=-Wl,-brtl' >> Makefile.settings
[b7d3cc34]974;;
975CYGWIN* )
[54b2a36]976        echo 'EFLAGS+=-Wl,--export-all,--out-implib,libbitlbee.dll.a' >> Makefile.settings
977        echo 'IMPLIB=libbitlbee.dll.a' >> Makefile.settings
[b7d3cc34]978;;
[aec56b0]979Windows )
[e252d8c]980        echo 'Native windows compilation is not supported anymore, use cygwin instead.'
[aec56b0]981;;
[b7d3cc34]982* )
[8d6c4b1]983        echo 'We haven'\''t tested BitlBee on many platforms yet, yours is untested. YMMV.'
984        echo 'Please report any problems at http://bugs.bitlbee.org/.'
[b7d3cc34]985;;
986esac
987
[f1e7407]988if [ -n "$target" ]; then
989        echo "Cross-compiling for: $target"
990fi
991
[b7d3cc34]992echo
993echo 'Configuration done:'
994
995if [ "$debug" = "1" ]; then
[b3c467b]996        echo '  Debugging enabled.'
[b7d3cc34]997else
[b3c467b]998        echo '  Debugging disabled.'
[b7d3cc34]999fi
1000
[e2472dd]1001if [ "$asan" = "1" ]; then
1002        echo '  AddressSanitizer (ASAN) enabled.'
1003else
1004        echo '  AddressSanitizer (ASAN) disabled.'
1005fi
1006
[7281ad1]1007if [ "$pie" = "1" ]; then
1008        echo '  Building PIE executable'
1009else
1010        echo '  Building non-PIE executable'
1011fi
1012
[b7d3cc34]1013if [ "$strip" = "1" ]; then
[b3c467b]1014        echo '  Binary stripping enabled.'
[b7d3cc34]1015else
[b3c467b]1016        echo '  Binary stripping disabled.'
[b7d3cc34]1017fi
1018
[764c7d1]1019if [ "$otr" = "1" ]; then
1020        echo '  Off-the-Record (OTR) Messaging enabled.'
[858ea01]1021elif [ "$otr" = "plugin" ]; then
1022        echo '  Off-the-Record (OTR) Messaging enabled (as a plugin).'
[764c7d1]1023else
1024        echo '  Off-the-Record (OTR) Messaging disabled.'
1025fi
1026
[2bd8f39]1027if [ "$systemd" = "1" ]; then
[417002e]1028        echo '  systemd enabled.'
1029else
1030        echo '  systemd disabled.'
1031fi
1032
[f18209a]1033echo '  Using python: '$PYTHON
[da0202a]1034
1035if [ "$external_json_parser" = "1" ]; then
1036    echo '  Using system JSON parser.'
1037else
1038    echo '  Using bundled JSON parser.'
1039fi
1040
[b3c467b]1041echo '  Using event handler: '$events
1042echo '  Using SSL library: '$ssl
[4e3df8a]1043#echo '  Building with these storage backends: '$STORAGES
[b7d3cc34]1044
1045if [ -n "$protocols" ]; then
[2bd8f39]1046        echo '  Building with these protocols:' "$protocols""$protocols_mods"
[4e3df8a]1047        case "$protocols" in
1048        *purple*)
1049                echo "    Note that BitlBee-libpurple is supported on a best-effort basis. It's"
1050                echo "    not *fully* compatible with normal BitlBee. Don't use it unless you"
1051                echo "    absolutely need it (i.e. support for a certain protocol or feature)."
1052        esac
[b7d3cc34]1053else
[b3c467b]1054        echo '  Building without IM-protocol support. We wish you a lot of fun...'
[b7d3cc34]1055fi
Note: See TracBrowser for help on using the repository browser.