Skip to content

Commit

Permalink
libuv: use pkg-config
Browse files Browse the repository at this point in the history
  • Loading branch information
nmaier committed Jul 31, 2017
1 parent 086500c commit 2cfe192
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 89 deletions.
71 changes: 2 additions & 69 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -238,77 +238,10 @@ fi

have_libuv=no
if test "x$with_libuv" = "xyes"; then
case "$host" in
*mingw*|*msvc*)
libuv_cflags="-D_WIN32_WINNT=0x0600"
save_CPPFLAGS=$CPPFLAGS
save_LIBS=$LIBS
CPPFLAGS="$CPPFLAGS $libuv_cflags"
AC_SEARCH_LIBS([uv_poll_init_socket], [uv], [
AC_CHECK_HEADER([uv.h], [have_libuv=yes], [have_libuv=no])
], [have_libuv=no])
if test "x$have_libuv" = "xyes"; then
LIBUV_CFLAGS=$libuv_cflags
LIBUV_LIBS=-luv
AC_SUBST([LIBUV_CFLAGS])
AC_SUBST([LIBUV_LIBS])
fi
CPPFLAGS=$save_CPPFLAGS
LIBS=$save_LIBS
;;

*darwin*)
libuv_ldflags="-framework Foundation -framework CoreServices -framework ApplicationServices"
save_LDFLAGS=$LDFLAGS
save_LIBS=$LIBS
LDFLAGS="$LDFLAGS $libuv_ldflags"
AC_SEARCH_LIBS([uv_poll_init_socket], [uv], [
AC_CHECK_HEADER([uv.h], [have_libuv=yes], [have_libuv=no])
], [have_libuv=no], [-lm])
if test "x$have_libuv" = "xyes"; then
LIBUV_CFLAGS=
LIBUV_LIBS="$libuv_ldflags -luv -lm"
AC_SUBST([LIBUV_CFLAGS])
AC_SUBST([LIBUV_LIBS])
fi
LDFLAGS=$save_LDFLAGS
LIBS=$save_LIBS
;;

*)
dnl Yeah, sucks that luv does not bring a pkg-config or config-tool
AC_MSG_CHECKING([for libuv])
save_LIBS=$LIBS
for combo in "" "-lrt" "-ldl -lrt" "-ldl -lrt -lpthread" "-lkvm"; do
LIBS="-luv $combo $save_LIBS -lm"
AC_LINK_IFELSE([AC_LANG_SOURCE([
extern "C" int uv_poll_init_socket(void);
int main() { return uv_poll_init_socket(); }
])], [
AC_MSG_RESULT(-luv $combo -lm)
AC_CHECK_HEADER([uv.h], [have_libuv=yes], [have_libuv=no])
], [have_libuv=no])
if test "x$have_libuv" = "xyes"; then
LIBUV_CFLAGS=
LIBUV_LIBS="-luv $combo -lm"
AC_SUBST([LIBUV_CFLAGS])
AC_SUBST([LIBUV_LIBS])
break;
fi
done
LIBS=$save_LIBS
if test "x$have_libuv" != "xyes"; then
AC_MSG_RESULT("no")
fi
;;
esac

PKG_CHECK_MODULES([LIBUV], [libuv >= 1.13],
[have_libuv=yes], [have_libuv=no])
if test "x$have_libuv" = "xyes"; then
AC_DEFINE([HAVE_LIBUV], [1], [Define to 1 if you have libuv.])
save_LIBS=$LIBS
LIBS="$LIBUV_LIBS $LIBS"
AC_CHECK_FUNCS([uv_last_error])
LIBS=$save_LIBS
elif test "x$with_libuv_requested" = "xyes"; then
ARIA2_DEP_NOT_MET([libuv])
fi
Expand Down
25 changes: 5 additions & 20 deletions src/LibuvEventPoll.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,10 @@ template <typename T> static void close_callback(uv_handle_t* handle)
delete reinterpret_cast<T*>(handle);
}

#if !defined(UV_VERSION_MINOR) || \
(UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10)

static void timer_callback(uv_timer_t* handle, int status)
static void timer_callback(uv_timer_t* handle)
{
uv_stop(handle->loop);
}

static void timer_callback(uv_timer_t* handle) { timer_callback(handle, 0); }

#else // !defined(UV_VERSION_MINOR) || (UV_VERSION_MAJOR == 0 &&
// UV_VERSION_MINOR <= 10)

static void timer_callback(uv_timer_t* handle) { uv_stop(handle->loop); }

#endif // !defined(UV_VERSION_MINOR) || UV_VERSION_MINOR <= 10
}

namespace aria2 {
Expand Down Expand Up @@ -112,7 +100,10 @@ int LibuvEventPoll::KSocketEntry::getEvents() const
return events;
}

LibuvEventPoll::LibuvEventPoll() { loop_ = uv_loop_new(); }
LibuvEventPoll::LibuvEventPoll()
{
loop_ = uv_loop_new();
}

LibuvEventPoll::~LibuvEventPoll()
{
Expand Down Expand Up @@ -189,14 +180,8 @@ int LibuvEventPoll::translateEvents(EventPoll::EventType events)

void LibuvEventPoll::pollCallback(KPoll* poll, int status, int events)
{
#if HAVE_UV_LAST_ERROR
if (status == -1) {
uv_err_t err = uv_last_error(loop_);
switch (err.code) {
#else
if (status < 0) {
switch (status) {
#endif
case UV_EAGAIN:
case UV_EINTR:
return;
Expand Down

0 comments on commit 2cfe192

Please sign in to comment.