diff -Naur tor-0.2.2.35/configure.in tor-0.2.2.35-haiku/configure.in
--- tor-0.2.2.35/configure.in	2011-12-15 18:00:33.013893632 +0100
+++ tor-0.2.2.35-haiku/configure.in	2011-12-18 01:13:44.216268800 +0100
@@ -215,7 +215,7 @@
 
 AC_C_BIGENDIAN
 
-AC_SEARCH_LIBS(socket, [socket])
+AC_SEARCH_LIBS(socket, [socket network])
 AC_SEARCH_LIBS(gethostbyname, [nsl])
 AC_SEARCH_LIBS(dlopen, [dl])
 AC_SEARCH_LIBS(inet_aton, [resolv])
@@ -340,6 +340,19 @@
 fi
 AC_SUBST(TOR_LIBEVENT_LIBS)
 
+dnl ------------------------------------------------------
+dnl Where do you live, libm?
+
+dnl On some platforms (Haiku/BeOS) the math library is
+dnl part of libroot. In which case don't link against lm
+TOR_LIB_MATH=""
+save_LIBS="$LIBS"
+AC_SEARCH_LIBS(cos, [m], , AC_MSG_ERROR([Could not find libm and libcore does not provide the functions.]))
+if test "$ac_cv_search_cos" != "none required"; then
+    TOR_LIB_MATH="$ac_cv_search_cos"
+fi
+LIBS="$save_LIBS"
+AC_SUBST(TOR_LIB_MATH)
 
 dnl ------------------------------------------------------
 dnl Where do you live, openssl?  And how do we call you?
diff -Naur tor-0.2.2.35/src/or/Makefile.am tor-0.2.2.35-haiku/src/or/Makefile.am
--- tor-0.2.2.35/src/or/Makefile.am	2011-12-15 17:28:37.048758784 +0100
+++ tor-0.2.2.35-haiku/src/or/Makefile.am	2011-12-18 00:53:00.718536704 +0100
@@ -43,7 +43,7 @@
 tor_LDFLAGS = @TOR_LDFLAGS_zlib@ @TOR_LDFLAGS_openssl@ @TOR_LDFLAGS_libevent@
 tor_LDADD = ./libtor.a ../common/libor.a ../common/libor-crypto.a \
 	../common/libor-event.a \
-	@TOR_ZLIB_LIBS@ -lm @TOR_LIBEVENT_LIBS@ @TOR_OPENSSL_LIBS@ @TOR_LIB_WS32@ @TOR_LIB_GDI@
+	@TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ @TOR_LIBEVENT_LIBS@ @TOR_OPENSSL_LIBS@ @TOR_LIB_WS32@ @TOR_LIB_GDI@
 
 noinst_HEADERS = buffers.h circuitbuild.h circuitlist.h circuituse.h \
 	command.h config.h connection_edge.h connection.h connection_or.h \
diff -Naur tor-0.2.2.35/src/test/Makefile.am tor-0.2.2.35-haiku/src/test/Makefile.am
--- tor-0.2.2.35/src/test/Makefile.am	2011-12-15 17:28:37.022806528 +0100
+++ tor-0.2.2.35-haiku/src/test/Makefile.am	2011-12-18 00:53:47.138412032 +0100
@@ -25,6 +25,6 @@
         @TOR_LDFLAGS_libevent@
 test_LDADD = ../or/libtor.a ../common/libor.a ../common/libor-crypto.a \
 	../common/libor-event.a \
-	@TOR_ZLIB_LIBS@ -lm @TOR_LIBEVENT_LIBS@ @TOR_OPENSSL_LIBS@ @TOR_LIB_WS32@ @TOR_LIB_GDI@
+	@TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ @TOR_LIBEVENT_LIBS@ @TOR_OPENSSL_LIBS@ @TOR_LIB_WS32@ @TOR_LIB_GDI@
 
 noinst_HEADERS = tinytest.h tinytest_macros.h test.h
diff -Naur tor-0.2.2.35/src/tools/Makefile.am tor-0.2.2.35-haiku/src/tools/Makefile.am
--- tor-0.2.2.35/src/tools/Makefile.am	2011-12-15 17:28:37.020971520 +0100
+++ tor-0.2.2.35-haiku/src/tools/Makefile.am	2011-12-18 00:54:15.212336640 +0100
@@ -3,16 +3,16 @@
 
 tor_resolve_SOURCES = tor-resolve.c
 tor_resolve_LDFLAGS = @TOR_LDFLAGS_libevent@
-tor_resolve_LDADD = ../common/libor.a -lm @TOR_LIBEVENT_LIBS@ @TOR_LIB_WS32@
+tor_resolve_LDADD = ../common/libor.a @TOR_LIB_MATH@ @TOR_LIBEVENT_LIBS@ @TOR_LIB_WS32@
 
 tor_gencert_SOURCES = tor-gencert.c
 tor_gencert_LDFLAGS = @TOR_LDFLAGS_zlib@ @TOR_LDFLAGS_openssl@ \
         @TOR_LDFLAGS_libevent@
 tor_gencert_LDADD = ../common/libor.a ../common/libor-crypto.a \
-        -lm @TOR_ZLIB_LIBS@ @TOR_LIBEVENT_LIBS@ @TOR_OPENSSL_LIBS@ @TOR_LIB_WS32@ @TOR_LIB_GDI@
+        @TOR_LIB_MATH@ @TOR_ZLIB_LIBS@ @TOR_LIBEVENT_LIBS@ @TOR_OPENSSL_LIBS@ @TOR_LIB_WS32@ @TOR_LIB_GDI@
 
 tor_checkkey_SOURCES = tor-checkkey.c
 tor_checkkey_LDFLAGS = @TOR_LDFLAGS_zlib@ @TOR_LDFLAGS_openssl@ \
         @TOR_LDFLAGS_libevent@
 tor_checkkey_LDADD = ../common/libor.a ../common/libor-crypto.a \
-        -lm @TOR_ZLIB_LIBS@ @TOR_LIBEVENT_LIBS@ @TOR_OPENSSL_LIBS@ @TOR_LIB_WS32@ @TOR_LIB_GDI@
+        @TOR_LIB_MATH@ @TOR_ZLIB_LIBS@ @TOR_LIBEVENT_LIBS@ @TOR_OPENSSL_LIBS@ @TOR_LIB_WS32@ @TOR_LIB_GDI@
