Skip to content
This repository
tree: b1328200a1
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 154 lines (139 sloc) 4.077 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
AC_PREREQ(2.61)
AC_INIT(btpd, 0.15, btpd@murmeldjur.se)

AM_INIT_AUTOMAKE([1.10 foreign subdir-objects])

AC_CONFIG_FILES([Makefile])

AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_RANLIB
AC_USE_SYSTEM_EXTENSIONS

AC_DEFUN([PROG_SILENT_IFELSE],
ac_output=`$1 2>&1`
if test x"$ac_output" != x; then
echo $1 nonsilent >&AS_MESSAGE_LOG_FD
echo $ac_output >&AS_MESSAGE_LOG_FD
[$3]
else
[$2]
fi)
AC_DEFUN([CC_ARGS_OK_IFELSE],
AC_LANG_PUSH(C)
AC_LANG_CONFTEST([int foo(void) { return 12; }])
AC_LANG_POP(C)
PROG_SILENT_IFELSE([$CC $1 -c conftest.c],
rm -f conftest.c conftest.$OBJEXT
[$2],
rm -f conftest.c conftest.$OBJEXT
[$3]))

AC_ARG_WITH(openssl,
[ --with-openssl=dir use openssl installed in dir],
[
    AC_SUBST(openssl_LDFLAGS,["-L${withval}/lib -Wl,-R,${withval}/lib"])
    AC_SUBST(openssl_CPPFLAGS,"-I${withval}/include")
])

AC_ARG_WITH(evloop-method,
[ --with-evloop-method select evloop method (epoll,poll,kqueue)],
    evloop_methods=$withval,
    evloop_methods="epoll kqueue poll")

old_LIBS=$LIBS
LIBS=""
AC_SEARCH_LIBS(inet_ntop, nsl,,AC_MSG_FAILURE(btpd needs inet_ntop))
AC_SEARCH_LIBS(bind, socket,,AC_MSG_FAILURE(btpd needs bind))
AC_SUBST(INETLIBS,$LIBS)
LIBS=$old_LIBS
AC_CHECK_FUNCS(asprintf)

AC_MSG_CHECKING(for CLOCK_MONOTONIC)
AC_COMPILE_IFELSE([
    #include <sys/time.h>
    #include <time.h>
    int main(void) { return clock_gettime(CLOCK_MONOTONIC, (void *)0); }
], clock_gettime=yes, clock_gettime=no)
AC_MSG_RESULT($clock_gettime)
if test $clock_gettime == yes; then
    old_LIBS=$LIBS
    LIBS=""
    AC_SEARCH_LIBS(clock_gettime,rt,clock_gettime=yes,clock_gettime=no)
    AC_SUBST(CLOCKLIB,$LIBS)
    LIBS=$old_LIBS
    AC_DEFINE(HAVE_CLOCK_MONOTONIC)
fi
if test $clock_gettime == no; then
    AC_CHECK_FUNCS(mach_absolute_time,,
        AC_MSG_FAILURE(no supported time mechanism found))
fi

AC_MSG_CHECKING(whether compiler accepts -Wno-pointer-sign)
CC_ARGS_OK_IFELSE(-Wno-pointer-sign,
    AC_SUBST(WARNNPS,"-Wno-pointer-sign")
    AC_MSG_RESULT(yes)
,
    AC_MSG_RESULT(no))

old_LDFLAGS="$LDFLAGS"
LDFLAGS="$LDFLAGS $openssl_LDFLAGS"
AC_CHECK_LIB(crypto, SHA1_Final,:,AC_MSG_FAILURE(btpd needs openssl's libraries and headers))
LDFLAGS=$old_LDFLAGS

for m in $evloop_methods; do
    case $m in
    epoll)
        AC_CHECK_FUNC(epoll_wait,[
            AC_SUBST(EVLOOP_IMPL,"evloop/epoll.${OBJEXT}")
            AC_SUBST(EVLOOP_METHOD,EVLOOP_EPOLL)
            break])
        ;;
    kqueue)
        AC_CHECK_FUNC(kqueue,[
            AC_SUBST(EVLOOP_IMPL,"evloop/kqueue.${OBJEXT}")
            AC_SUBST(EVLOOP_METHOD,EVLOOP_KQUEUE)
            break])
        ;;
    poll)
        AC_CHECK_FUNC(poll,[
            AC_SUBST(EVLOOP_IMPL,"evloop/poll.${OBJEXT}")
            AC_SUBST(EVLOOP_METHOD,EVLOOP_POLL)
            break])
        break
        ;;
    *)
        AC_MSG_ERROR($m is not a valid evloop method)
        exit 1
        ;;
    esac
done
if test x"$EVLOOP_METHOD" == x; then
    AC_MSG_FAILURE(no suitable evloop method found)
    exit 1
else
    AC_MSG_NOTICE(selected evloop method $EVLOOP_METHOD)
fi

for i in 0 1 2 3 4 5 6 7; do
    case $i in
    0) if test x"$TD_CFLAGS$TD_LIBS" == x; then continue; fi;;
    1) TD_CFLAGS=-pthread;;
    2) TD_CFLAGS=-pthreads;;
    3) TD_CFLAGS=-kthread;;
    4) TD_CFLAGS=-mt;;
    5) TD_LIBS=-lpthread;;
    6) ;;
    7) AC_MSG_FAILURE(how do you build with pthreads on this system?);;
    esac
    AC_MSG_CHECKING(whether pthreads compiles with flags \"$TD_CFLAGS $TD_LIBS\")
    CC_ARGS_OK_IFELSE($TD_CFLAGS $CFLAGS $TD_LIBS $LIBS,,
        AC_MSG_RESULT(no)
        TD_CFLAGS=""; TD_LIBS=""
        continue)

    old_CFLAGS=$CFLAGS; old_LIBS=$LIBS
    CFLAGS="$TD_CFLAGS $CFLAGS"; LIBS="$TD_LIBS $LIBS"
    AC_LINK_IFELSE([
        #include <pthread.h>
        int main(void) { return pthread_create(0,0,0,0);}
    ], [
        AC_MSG_RESULT(yes)
        CFLAGS=$old_CFLAGS; LIBS=$old_LIBS
        break
    ], [
        AC_MSG_RESULT(no)
        TD_CFLAGS=""; TD_LIBS=""
        CFLAGS=$old_CFLAGS; LIBS=$old_LIBS
    ])
done
AC_SUBST(TD_CFLAGS)
AC_SUBST(TD_LIBS)

AC_OUTPUT
Something went wrong with that request. Please try again.