AC_INIT(btpd, 0.13+, btpd@murmeldjur.se) AM_INIT_AUTOMAKE([foreign subdir-objects]) AC_CONFIG_FILES([Makefile]) AC_PROG_CC AC_PROG_CC_C_O AC_PROG_RANLIB AC_USE_SYSTEM_EXTENSIONS 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(clock_gettime, rt,,AC_MSG_FAILURE(btpd needs clock_gettime)) AC_SUBST(CLOCKLIB,$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(whether compiler accepts -Wno-pointer-sign) old_CFLAGS=$CFLAGS CFLAGS="-Wno-pointer-sign" AC_COMPILE_IFELSE(int main(void) { return 0; }, AC_SUBST(WARNNPS,"-Wno-pointer-sign") AC_MSG_RESULT(yes) , AC_MSG_RESULT(no)) CFLAGS=$old_CFLAGS 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; 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) AC_MSG_FAILURE(how do you build with pthreads on this system?);; esac old_CFLAGS=$CFLAGS; CFLAGS="$TD_CFLAGS $CFLAGS" old_LIBS=$LIBS; LIBS="$TD_LIBS $LIBS" AC_MSG_CHECKING(whether pthreads compiles with flags \"$TD_CFLAGS $TD_LIBS\") AC_LANG_CONFTEST([int foo(void) { return 12; }]) $CC $CFLAGS $CPPFLAGS -c conftest.c >conftest.stdout 2>conftest.stderr if test -s conftest.stdout -o -s conftest.stderr; then AC_MSG_RESULT(no) TD_CFLAGS=""; TD_LIBS="" CFLAGS=$old_CFLAGS; LIBS=$old_LIBS rm -f conftest.c conftest.o conftest.stdout conftest.stderr continue fi rm -f conftest.c conftest.o conftest.stdout conftest.stderr AC_LINK_IFELSE([ #include 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