build: link eloop statically

We don't want to export libeloop so link it statically. Avoid installing
into into the system.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
This commit is contained in:
David Herrmann 2013-10-29 10:24:31 +01:00
parent 6ef8db0790
commit 35fbe621e4
8 changed files with 4 additions and 614 deletions

View File

@ -3,14 +3,6 @@
# Copyright (c) 2012-2013 David Herrmann <dh.herrmann@googlemail.com>
#
#
# Library Version Numbers
#
LIBELOOP_CURRENT = 1
LIBELOOP_REVISION = 0
LIBELOOP_AGE = 0
#
# Global Configurations and Initializations
#
@ -30,9 +22,7 @@ EXTRA_DIST = \
COPYING \
NEWS \
docs/kmscon.service \
docs/kmsconvt@.service \
docs/pc/libeloop.pc.in \
docs/sym/libeloop.sym
docs/kmsconvt@.service
CLEANFILES =
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA =
@ -196,11 +186,7 @@ libshl_la_LIBADD = \
# compiled into a separate object to allow using it in several other programs.
#
if BUILD_ENABLE_ELOOP
lib_LTLIBRARIES += libeloop.la
include_HEADERS += src/eloop.h
pkgconfig_DATA += docs/pc/libeloop.pc
endif
noinst_LTLIBRARIES += libeloop.la
libeloop_la_SOURCES = \
src/eloop.h \
@ -208,21 +194,7 @@ libeloop_la_SOURCES = \
libeloop_la_LIBADD = libshl.la
libeloop_la_CPPFLAGS = $(AM_CPPFLAGS)
EXTRA_libeloop_la_DEPENDENCIES = ${top_srcdir}/docs/sym/libeloop.sym
libeloop_la_LDFLAGS = \
$(AM_LDFLAGS) \
-version-info $(LIBELOOP_CURRENT):$(LIBELOOP_REVISION):$(LIBELOOP_AGE) \
-Wl,--version-script=$(top_srcdir)/docs/sym/libeloop.sym
if BUILD_ENABLE_ELOOP_DBUS
libeloop_la_SOURCES += \
external/dbus-common.h \
external/dbus-loop.h \
external/dbus-loop.c
libeloop_la_CPPFLAGS += $(DBUS_CFLAGS)
libeloop_la_LIBADD += $(DBUS_LIBS)
endif
libeloop_la_LDFLAGS = $(AM_LDFLAGS)
#
# libuterm

3
README
View File

@ -63,7 +63,6 @@ Released tarballs can be found at:
currently mandatory and cannot be disabled. [default: on]
--enable-debug: Enable debug mode/messages [default: on]
--enable-optimizations: Enable code optimizations [default: on]
--enable-eloop-dbus: Build dbus extension for eloop library [default: off]
Backends for several subsystems in kmscon can be selected with the following
options (all of them take a comma-separated list of backend names):
@ -91,8 +90,6 @@ Released tarballs can be found at:
dependency-checks fail, they are disabled by default unless explicitly enabled
on the command line:
--enable-kmscon: Build kmscon application [default: on]
--enable-eloop: Build eloop event loop library [default: off]
--enable-uterm: Build uterm library [default: off]
== Running ==

View File

@ -126,18 +126,6 @@ if test "x$enable_all" = "x" ; then
fi
AC_MSG_RESULT([$enable_all])
# eloop
AC_MSG_CHECKING([whether user wants eloop])
AC_ARG_ENABLE([eloop],
[AS_HELP_STRING([--enable-eloop],
[build eloop library])])
if test "x$enable_all" = "xyes" ; then
enable_eloop="yes"
elif test "x$enable_eloop" = "x" ; then
enable_eloop="no (default)"
fi
AC_MSG_RESULT([$enable_eloop])
# kmscon
AC_MSG_CHECKING([whether user wants kmscon])
AC_ARG_ENABLE([kmscon],
@ -198,18 +186,6 @@ elif test "x$enable_hotplug" = "x" ; then
fi
AC_MSG_RESULT([$enable_hotplug])
# eloop-dbus
AC_MSG_CHECKING([whether user wants eloop dbus support])
AC_ARG_ENABLE([eloop-dbus],
[AS_HELP_STRING([--enable-eloop-dbus],
[enable eloop dbus support])])
if test "x$enable_all" = "xyes" ; then
enable_eloop_dbus="yes"
elif test "x$enable_eloop_dbus" = "x" ; then
enable_eloop_dbus="no (default)"
fi
AC_MSG_RESULT([$enable_eloop_dbus])
# video backends
AC_MSG_CHECKING([which video backends the user wants])
AC_ARG_WITH([video],
@ -380,34 +356,6 @@ else
optimizations_missing="enable-optimizations"
fi
# eloop-dbus
eloop_dbus_avail=no
eloop_dbus_missing=""
if test ! "x$enable_eloop_dbus" = "xno" ; then
eloop_dbus_avail=yes
if test "x$have_dbus" = "xno" ; then
eloop_dbus_avail=no
eloop_dbus_missing="libdbus"
fi
if test "x$eloop_dbus_avail" = "xno" ; then
if test "x$enable_eloop_dbus" = "xyes" ; then
AC_ERROR([missing for eloop-dbus: $eloop_dbus_missing])
fi
fi
else
eloop_dbus_missing="enable-eloop-dbus"
fi
# eloop
eloop_avail=no
eloop_missing=""
if test ! "x$enable_eloop" = "xno" ; then
eloop_avail=yes
else
eloop_missing="enable-eloop"
fi
# video fbdev
video_fbdev_avail=no
video_fbdev_missing=""
@ -614,11 +562,6 @@ kmscon_avail=no
kmscon_missing=""
if test ! "x$enable_kmscon" = "xno" ; then
kmscon_avail=yes
if test "x$eloop_avail" = "xno" ; then
kmscon_avail=no
kmscon_missing="$eloop_missing,$kmscon_missing"
fi
if test "x$have_tsm" = "xno" ; then
kmscon_avail=no
kmscon_missing="libtsm,$kmscon_missing"
@ -646,7 +589,6 @@ kmscon_enabled=no
if test "x$kmscon_avail" = "xyes" ; then
if test "x${enable_kmscon% *}" = "xyes" ; then
kmscon_enabled=yes
enable_eloop=yes
fi
fi
@ -746,22 +688,6 @@ if test "x$video_fbdev_avail" = "xyes" ; then
fi
fi
# eloop
eloop_enabled=no
if test "x$eloop_avail" = "xyes" ; then
if test "x${enable_eloop% *}" = "xyes" ; then
eloop_enabled=yes
fi
fi
# eloop-dbus
eloop_dbus_enabled=no
if test "x$eloop_dbus_avail" = "xyes" ; then
if test "x${enable_eloop_dbus% *}" = "xyes" ; then
eloop_dbus_enabled=yes
fi
fi
# optimizations
optimizations_enabled=no
if test "x$optimizations_avail" = "xyes" ; then
@ -800,14 +726,6 @@ AM_CONDITIONAL([BUILD_ENABLE_DEBUG],
AM_CONDITIONAL([BUILD_ENABLE_OPTIMIZATIONS],
[test "x$optimizations_enabled" = "xyes"])
# eloop-dbus
AM_CONDITIONAL([BUILD_ENABLE_ELOOP_DBUS],
[test "x$eloop_dbus_enabled" = "xyes"])
# eloop
AM_CONDITIONAL([BUILD_ENABLE_ELOOP],
[test "x$eloop_enabled" = "xyes"])
# video fbdev
if test "x$video_fbdev_enabled" = "xyes" ; then
AC_DEFINE([BUILD_ENABLE_VIDEO_FBDEV], [1],
@ -981,8 +899,7 @@ fi
# makefiles.
#
AC_CONFIG_FILES([Makefile
docs/pc/libeloop.pc])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
#
@ -1000,14 +917,12 @@ AC_MSG_NOTICE([Build configuration:
Applications and Libraries:
kmscon: $kmscon_enabled ($kmscon_avail: $kmscon_missing)
eloop: $eloop_enabled ($eloop_avail: $eloop_missing)
Miscellaneous Options:
debug: $debug_enabled ($debug_avail: $debug_missing)
optimizations: $optimizations_enabled ($optimizations_avail: $optimizations_missing)
multi-seat: $multi_seat_enabled ($multi_seat_avail: $multi_seat_missing)
hotplug: $hotplug_enabled ($hotplug_avail: $hotplug_missing)
eloop-dbus: $eloop_dbus_enabled ($eloop_dbus_avail: $eloop_dbus_missing)
Video Backends:
fbdev: $video_fbdev_enabled ($video_fbdev_avail: $video_fbdev_missing)

View File

@ -1,11 +0,0 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: eloop
Description: Epoll-based Event-Loop Library
URL: @PACKAGE_URL@
Version: @PACKAGE_VERSION@
Libs: -L${libdir} -leloop
Cflags: -I${includedir}

View File

@ -1,107 +0,0 @@
/***
* libeloop - Simple Event-Loop Library
*
* Copyright (c) 2012-2013 David Herrmann <dh.herrmann@googlemail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
***/
LIBELOOP_1 {
global:
ev_eloop_new;
ev_eloop_ref;
ev_eloop_unref;
local:
*;
};
LIBELOOP_2 {
global:
ev_eloop_flush_fd;
ev_eloop_dispatch;
ev_eloop_run;
ev_eloop_exit;
ev_eloop_get_fd;
ev_eloop_new_eloop;
ev_eloop_add_eloop;
ev_eloop_rm_eloop;
ev_fd_new;
ev_fd_ref;
ev_fd_unref;
ev_fd_enable;
ev_fd_disable;
ev_fd_is_enabled;
ev_fd_is_bound;
ev_fd_set_cb_data;
ev_fd_update;
ev_eloop_new_fd;
ev_eloop_add_fd;
ev_eloop_rm_fd;
ev_timer_new;
ev_timer_ref;
ev_timer_unref;
ev_timer_enable;
ev_timer_disable;
ev_timer_is_enabled;
ev_timer_is_bound;
ev_timer_set_cb_data;
ev_timer_update;
ev_timer_drain;
ev_eloop_new_timer;
ev_eloop_add_timer;
ev_eloop_rm_timer;
ev_counter_new;
ev_counter_ref;
ev_counter_unref;
ev_counter_enable;
ev_counter_disable;
ev_counter_is_enabled;
ev_counter_is_bound;
ev_counter_set_cb_data;
ev_counter_inc;
ev_eloop_new_counter;
ev_eloop_add_counter;
ev_eloop_rm_counter;
ev_eloop_register_signal_cb;
ev_eloop_unregister_signal_cb;
ev_eloop_register_child_cb;
ev_eloop_unregister_child_cb;
ev_eloop_register_idle_cb;
ev_eloop_unregister_idle_cb;
ev_eloop_register_pre_cb;
ev_eloop_unregister_pre_cb;
ev_eloop_register_post_cb;
ev_eloop_unregister_post_cb;
} LIBELOOP_1;

View File

@ -1,84 +0,0 @@
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2011 Lennart Poettering
systemd is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdlib.h>
#define new0(_x, _y) zero_alloc(sizeof(_x) * (_y))
static void *zero_alloc(size_t s)
{
void *mem = malloc(s);
if (mem)
memset(mem, 0, s);
return mem;
}
#define zero(_x) memset(&(_x), 0, sizeof(_x))
#define PTR_TO_INT(_x) ((int) ((intptr_t) (_x)))
#define INT_TO_PTR(u) ((void*) ((intptr_t) (u)))
#define close_nointr_nofail(_x) close(_x)
#define assert_se(_x) (void)(_x)
#define USEC_PER_MSEC 1000ULL
#define USEC_PER_SEC 1000000ULL
#define NSEC_PER_USEC 1000ULL
#define log_error(...)
static struct timespec *timespec_store(struct timespec *ts, int64_t u) {
assert(ts);
ts->tv_sec = (time_t) (u / USEC_PER_SEC);
ts->tv_nsec = (long int) ((u % USEC_PER_SEC) * NSEC_PER_USEC);
return ts;
}
uint32_t bus_flags_to_events(DBusWatch *bus_watch) {
unsigned flags;
uint32_t events = 0;
assert(bus_watch);
/* no watch flags for disabled watches */
if (!dbus_watch_get_enabled(bus_watch))
return 0;
flags = dbus_watch_get_flags(bus_watch);
if (flags & DBUS_WATCH_READABLE)
events |= EPOLLIN;
if (flags & DBUS_WATCH_WRITABLE)
events |= EPOLLOUT;
return events | EPOLLHUP | EPOLLERR;
}
unsigned bus_events_to_flags(uint32_t events) {
unsigned flags = 0;
if (events & EPOLLIN)
flags |= DBUS_WATCH_READABLE;
if (events & EPOLLOUT)
flags |= DBUS_WATCH_WRITABLE;
if (events & EPOLLHUP)
flags |= DBUS_WATCH_HANGUP;
if (events & EPOLLERR)
flags |= DBUS_WATCH_ERROR;
return flags;
}

262
external/dbus-loop.c vendored
View File

@ -1,262 +0,0 @@
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2011 Lennart Poettering
systemd is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdbool.h>
#include <assert.h>
#include <sys/epoll.h>
#include <string.h>
#include <errno.h>
#include <sys/timerfd.h>
#include <unistd.h>
#include "external/dbus-loop.h"
#include "external/dbus-common.h"
/* Minimal implementation of the dbus loop which integrates all dbus
* events into a single epoll fd which we can triviall integrate with
* other loops. Note that this is not used in the main systemd daemon
* since we run a more elaborate mainloop there. */
typedef struct EpollData {
int fd;
void *object;
bool is_timeout:1;
bool fd_is_dupped:1;
} EpollData;
static dbus_bool_t add_watch(DBusWatch *watch, void *data) {
EpollData *e;
struct epoll_event ev;
assert(watch);
e = new0(EpollData, 1);
if (!e)
return FALSE;
e->fd = dbus_watch_get_unix_fd(watch);
e->object = watch;
e->is_timeout = false;
zero(ev);
ev.events = bus_flags_to_events(watch);
ev.data.ptr = e;
if (epoll_ctl(PTR_TO_INT(data), EPOLL_CTL_ADD, e->fd, &ev) < 0) {
if (errno != EEXIST) {
free(e);
return FALSE;
}
/* Hmm, bloody D-Bus creates multiple watches on the
* same fd. epoll() does not like that. As a dirty
* hack we simply dup() the fd and hence get a second
* one we can safely add to the epoll(). */
e->fd = dup(e->fd);
if (e->fd < 0) {
free(e);
return FALSE;
}
if (epoll_ctl(PTR_TO_INT(data), EPOLL_CTL_ADD, e->fd, &ev) < 0) {
close_nointr_nofail(e->fd);
free(e);
return FALSE;
}
e->fd_is_dupped = true;
}
dbus_watch_set_data(watch, e, NULL);
return TRUE;
}
static void remove_watch(DBusWatch *watch, void *data) {
EpollData *e;
assert(watch);
e = dbus_watch_get_data(watch);
if (!e)
return;
assert_se(epoll_ctl(PTR_TO_INT(data), EPOLL_CTL_DEL, e->fd, NULL) >= 0);
if (e->fd_is_dupped)
close_nointr_nofail(e->fd);
free(e);
}
static void toggle_watch(DBusWatch *watch, void *data) {
EpollData *e;
struct epoll_event ev;
assert(watch);
e = dbus_watch_get_data(watch);
if (!e)
return;
zero(ev);
ev.events = bus_flags_to_events(watch);
ev.data.ptr = e;
assert_se(epoll_ctl(PTR_TO_INT(data), EPOLL_CTL_MOD, e->fd, &ev) == 0);
}
static int timeout_arm(EpollData *e) {
struct itimerspec its;
assert(e);
assert(e->is_timeout);
zero(its);
if (dbus_timeout_get_enabled(e->object)) {
timespec_store(&its.it_value, dbus_timeout_get_interval(e->object) * USEC_PER_MSEC);
its.it_interval = its.it_value;
}
if (timerfd_settime(e->fd, 0, &its, NULL) < 0)
return -errno;
return 0;
}
static dbus_bool_t add_timeout(DBusTimeout *timeout, void *data) {
EpollData *e;
struct epoll_event ev;
assert(timeout);
e = new0(EpollData, 1);
if (!e)
return FALSE;
e->fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK|TFD_CLOEXEC);
if (e->fd < 0)
goto fail;
e->object = timeout;
e->is_timeout = true;
if (timeout_arm(e) < 0)
goto fail;
zero(ev);
ev.events = EPOLLIN;
ev.data.ptr = e;
if (epoll_ctl(PTR_TO_INT(data), EPOLL_CTL_ADD, e->fd, &ev) < 0)
goto fail;
dbus_timeout_set_data(timeout, e, NULL);
return TRUE;
fail:
if (e->fd >= 0)
close_nointr_nofail(e->fd);
free(e);
return FALSE;
}
static void remove_timeout(DBusTimeout *timeout, void *data) {
EpollData *e;
assert(timeout);
e = dbus_timeout_get_data(timeout);
if (!e)
return;
assert_se(epoll_ctl(PTR_TO_INT(data), EPOLL_CTL_DEL, e->fd, NULL) >= 0);
close_nointr_nofail(e->fd);
free(e);
}
static void toggle_timeout(DBusTimeout *timeout, void *data) {
EpollData *e;
int r;
assert(timeout);
e = dbus_timeout_get_data(timeout);
if (!e)
return;
r = timeout_arm(e);
if (r < 0)
log_error("Failed to rearm timer: %s", strerror(-r));
}
int bus_loop_open(DBusConnection *c) {
int fd;
assert(c);
fd = epoll_create1(EPOLL_CLOEXEC);
if (fd < 0)
return -errno;
if (!dbus_connection_set_watch_functions(c, add_watch, remove_watch, toggle_watch, INT_TO_PTR(fd), NULL) ||
!dbus_connection_set_timeout_functions(c, add_timeout, remove_timeout, toggle_timeout, INT_TO_PTR(fd), NULL)) {
close_nointr_nofail(fd);
return -ENOMEM;
}
return fd;
}
int bus_loop_dispatch(int fd) {
int n;
struct epoll_event event;
EpollData *d;
assert(fd >= 0);
zero(event);
n = epoll_wait(fd, &event, 1, 0);
if (n < 0)
return errno == EAGAIN || errno == EINTR ? 0 : -errno;
assert_se(d = event.data.ptr);
if (d->is_timeout) {
DBusTimeout *t = d->object;
if (dbus_timeout_get_enabled(t))
dbus_timeout_handle(t);
} else {
DBusWatch *w = d->object;
if (dbus_watch_get_enabled(w))
dbus_watch_handle(w, bus_events_to_flags(event.events));
}
return 0;
}

30
external/dbus-loop.h vendored
View File

@ -1,30 +0,0 @@
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
#ifndef foodbusloophfoo
#define foodbusloophfoo
/***
This file is part of systemd.
Copyright 2011 Lennart Poettering
systemd is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <dbus/dbus.h>
int bus_loop_open(DBusConnection *c);
int bus_loop_dispatch(int fd);
#endif