Create k5ev verto module from libev sources
authorGreg Hudson <ghudson@mit.edu>
Fri, 2 Sep 2011 17:07:45 +0000 (17:07 +0000)
committerGreg Hudson <ghudson@mit.edu>
Fri, 2 Sep 2011 17:07:45 +0000 (17:07 +0000)
Add configure and build support for libverto and the libverto-k5ev
module.  Fix the version script rules to work for libraries with
hyphens in their names.

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@25127 dc483132-0cff-0310-8789-dd5450dbe970

13 files changed:
src/config/lib.in
src/config/pre.in
src/configure.in
src/util/Makefile.in
src/util/k5ev/Makefile.in [new file with mode: 0644]
src/util/k5ev/README [new file with mode: 0644]
src/util/k5ev/deps [new file with mode: 0644]
src/util/k5ev/k5ev.c [new file with mode: 0644]
src/util/k5ev/libverto-k5ev.exports [new file with mode: 0644]
src/util/k5ev/verto-k5ev.c [new file with mode: 0644]
src/util/verto/Makefile.in [new file with mode: 0644]
src/util/verto/deps [new file with mode: 0644]
src/util/verto/libverto.exports [new file with mode: 0644]

index 66422e01f6b0664345585320d2924d0d2b3c1d04..46727fe0aaeb2fdd83fb11203ce904095b2545db 100644 (file)
@@ -54,7 +54,8 @@ lib$(LIBBASE)$(SHLIBEXT): lib$(LIBBASE)$(SHLIBVEXT)
        $(LN_S) lib$(LIBBASE)$(SHLIBVEXT) $@
 
 binutils.versions: $(SHLIB_EXPORT_FILE) Makefile
-       echo >  binutils.versions "$(LIBBASE)_$(LIBMAJOR)_MIT {"
+       base=`echo "$(LIBBASE)" | sed -e 's/-/_/'`; \
+       echo >  binutils.versions "$${base}_$(LIBMAJOR)_MIT {"
        sed  >> binutils.versions < $(SHLIB_EXPORT_FILE) "s/$$/;/"
        echo >> binutils.versions "};"
        echo >> binutils.versions "HIDDEN { local: __*; _rest*; _save*; *; };"
@@ -89,8 +90,9 @@ hpux10.exports: $(SHLIB_EXPORT_FILE) Makefile
          else :; fi; \
        done; echo "$$a" >> hpux10.tmp
        echo "+e errno" >> hpux10.tmp
-       echo "+e _GLOBAL__FD_lib$(LIBBASE)_$(LIBMAJOR)_$(LIBMINOR)" >> hpux10.tmp
-       echo "+e _GLOBAL__FI_lib$(LIBBASE)_$(LIBMAJOR)_$(LIBMINOR)" >> hpux10.tmp
+       base=`echo "$(LIBBASE)" | sed -e 's/-/_/'`; \
+       echo "+e _GLOBAL__FD_lib$${base}_$(LIBMAJOR)_$(LIBMINOR)" >> hpux10.tmp; \
+       echo "+e _GLOBAL__FI_lib$${base}_$(LIBMAJOR)_$(LIBMINOR)" >> hpux10.tmp
        mv -f hpux10.tmp hpux10.exports
 
 lib$(LIBBASE)$(PFLIBEXT): $(PFOBJLISTS)
index 67117d6b486dd1f9d44bd7615694f8485b6179d8..1ec893725c7a54eb2292f67ed73e42d11c2bc99a 100644 (file)
@@ -378,6 +378,12 @@ SS_LIB-sys = @SS_LIB@
 SS_LIB-k5      = $(TOPLIBD)/libss.a $(RL_LIBS)
 KDB5_LIB       = -lkdb5 $(KDB5_PLUGIN_LIBS)
 
+VERTO_DEPLIB   = $(VERTO_DEPLIB-@VERTO_VERSION@)
+VERTO_DEPLIB-sys = # empty
+VERTO_DEPLIB-k5        = $(TOPLIBD)/libverto$(DEPLIBEXT)
+VERTO_CFLAGS   = @VERTO_CFLAGS@
+VERTO_LIBS     = @VERTO_LIBS@
+
 DL_LIB         = @DL_LIB@
 
 LDAP_LIBS      = @LDAP_LIBS@
index 4e61e8f59157708a7823f293247158548730b47c..5d3f5264d1e7d9c0455a6ee80e695548e67cd5ee 100644 (file)
@@ -1142,10 +1142,38 @@ fi
 AC_SUBST([RL_CFLAGS])
 AC_SUBST([RL_LIBS])
 
+AC_ARG_WITH([system-verto],
+  [AC_HELP_STRING([--with-system-verto], [always use system verto library])],
+  [], [with_system_verto=default])
+VERTO_CFLAGS=
+VERTO_LIBS=-lverto
+VERTO_VERSION=k5
+if test "x$with_system_verto" != xno; then
+  if verto_cflags=`pkg-config --cflags libverto 2>&1`; then
+    VERTO_CFLAGS=$verto_cflags
+    VERTO_LIBS=`pkg-config --libs libverto`
+    VERTO_VERSION=sys
+  else
+    AC_CHECK_LIB([verto], [verto_run], [VERTO_VERSION=sys],
+      [if test "x$with_system_verto" = xyes; then
+        AC_MSG_ERROR([cannot detect system libverto])
+      fi])
+  fi
+fi
+if test "x$VERTO_VERSION" = xsys; then
+  AC_MSG_NOTICE([Using system libverto])
+else
+  AC_MSG_RESULT([Using built-in libverto])
+fi
+AC_SUBST([VERTO_CFLAGS])
+AC_SUBST([VERTO_LIBS])
+AC_SUBST([VERTO_VERSION])
+
 AC_CONFIG_FILES(krb5-config, [chmod +x krb5-config])
 V5_AC_OUTPUT_MAKEFILE(.
 
        util util/support util/profile util/profile/testmod util/send-pr
+       util/verto util/k5ev
 
        lib lib/kdb
 
index b6e7af6e21c50df0de86cb6cf38bfc66ad638152..6c7f8a7ff0426ea6f28cbe67117102e7af44ba69 100644 (file)
@@ -4,7 +4,7 @@ mydir=util
 # configure scripts, so hide this.
 ##WIN32##!if 0
 SUBDIRS=support $(MAYBE_ET_@COM_ERR_VERSION@) $(MAYBE_SS_@SS_VERSION@) \
-       profile send-pr gss-kernel-lib
+       profile send-pr gss-kernel-lib $(MAYBE_VERTO_@VERTO_VERSION@)
 ##WIN32##!endif
 WINSUBDIRS=windows support et profile
 BUILDTOP=$(REL)..
@@ -14,6 +14,8 @@ MAYBE_SS_k5 = ss
 MAYBE_ET_sys =
 MAYBE_ET_intlsys =
 MAYBE_SS_sys =
+MAYBE_VERTO_sys =
+MAYBE_VERTO_k5 = verto k5ev
 
 all-recurse:
 
diff --git a/src/util/k5ev/Makefile.in b/src/util/k5ev/Makefile.in
new file mode 100644 (file)
index 0000000..857a85b
--- /dev/null
@@ -0,0 +1,42 @@
+mydir=util$(S)k5ev
+BUILDTOP=$(REL)..$(S)..
+RELDIR=../util/k5ev
+DEFS=
+
+SED = sed
+
+LIBBASE=verto-k5ev
+LIBMAJOR=0
+LIBMINOR=0
+
+LOCALINCLUDES=-I. -I$(srcdir)/../verto
+
+# Turn off extra warnings since we're not going to clean up libev's code.
+WARN_CFLAGS=
+
+STLIBOBJS=verto-k5ev.o
+LIBOBJS=$(OUTPRE)verto-k5ev.$(OBJEXT)
+SRCS=verto-k5ev.c
+
+STOBJLISTS=OBJS.ST
+SHLIB_EXPLIBS= $(LIBS) -lverto -lm      # libm needed for ceil() currently.
+SHLIB_DIRS=-L$(TOPLIBD)
+SHLIB_RDIRS=$(KRB5_LIBDIR)
+
+all-unix:: all-liblinks
+
+install-unix:: install-libs
+
+clean-unix:: clean-liblinks clean-libs clean-libobjs
+
+rename.h: $(srcdir)/Symbols.ev
+       $(RM) $@
+       $(SED) -e 's/.*/#define & k5&/' < $(srcdir)/Symbols.ev > $@
+
+clean::
+       $(RM) rename.h
+
+depend:: rename.h
+
+@lib_frag@
+@libobj_frag@
diff --git a/src/util/k5ev/README b/src/util/k5ev/README
new file mode 100644 (file)
index 0000000..1165f37
--- /dev/null
@@ -0,0 +1,29 @@
+This directory builds a private libverto module using an embedded
+libev with renamed symbols (so we don't leak libev symbols into the
+namespace on platforms where we can't control the export list).  The
+module is not intended to be used directly by applications, so it has
+no header file.
+
+libev has built-in support for this kind of embedding, so we don't
+have to modify the libev sources.  Following libev's documentation,
+the following files have been copied from the ev sources:
+
+  ev.h
+  ev_vars.h
+  ev_wrap.h
+  ev.c
+  ev_select.c
+  ev_poll.c
+  ev_win32.c
+  Symbols.ev
+
+(Symbols.ev wasn't included in the 4.04 tar file due to an oversight,
+so it is taken from the appropriate tag in libev's source repository.)
+
+To rename the exported symbols, we create rename.h from Symbols.ev.
+We also use Symbols.ev to construct the library export list.
+(Renaming libev's symbols would be unnecessary if libev's embedding
+had support for making its API symbols static, but it currently does
+not.)  The source file verto-k5ev.c wraps ev.c with appropriate
+embedding defines, and then defines the libverto module functions
+using the slightly modified contents of libverto's verto-ev.c.
diff --git a/src/util/k5ev/deps b/src/util/k5ev/deps
new file mode 100644 (file)
index 0000000..2921c31
--- /dev/null
@@ -0,0 +1,7 @@
+# 
+# Generated makefile dependencies follow.
+#
+verto-k5ev.so verto-k5ev.po $(OUTPRE)verto-k5ev.$(OBJEXT): \
+  $(BUILDTOP)/include/autoconf.h $(BUILDTOP)/include/verto.h \
+  $(srcdir)/../verto/verto-module.h ev.c ev.h ev_poll.c \
+  ev_vars.h ev_wrap.h rename.h verto-k5ev.c
diff --git a/src/util/k5ev/k5ev.c b/src/util/k5ev/k5ev.c
new file mode 100644 (file)
index 0000000..42e4df8
--- /dev/null
@@ -0,0 +1,36 @@
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/* util/k5ev/k5ev.c - Wrapper to create libk5ev from libev sources */
+/*
+ * Copyright (C) 2011 by the Massachusetts Institute of Technology.
+ * All rights reserved.
+ *
+ * Export of this software from the United States of America may
+ *   require a specific license from the United States Government.
+ *   It is the responsibility of any person or organization contemplating
+ *   export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission.  Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose.  It is provided "as is" without express
+ * or implied warranty.
+ */
+
+#include "rename.h"
+#include "autoconf.h"
+#define EV_STANDALONE 1
+#define EV_FEATURES 0x5f        /* Everything but back ends */
+#ifdef HAVE_POLL_H
+#define EV_USE_POLL 1
+#else
+#define EV_USE_SELECT 1
+#endif
+#include "ev.c"
diff --git a/src/util/k5ev/libverto-k5ev.exports b/src/util/k5ev/libverto-k5ev.exports
new file mode 100644 (file)
index 0000000..ee1b8d0
--- /dev/null
@@ -0,0 +1 @@
+verto_module_table
diff --git a/src/util/k5ev/verto-k5ev.c b/src/util/k5ev/verto-k5ev.c
new file mode 100644 (file)
index 0000000..947085b
--- /dev/null
@@ -0,0 +1,163 @@
+/*
+ * Copyright 2011 Red Hat, Inc.
+ *
+ * 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.
+ */
+
+/* An edited version of verto's verto-libev.c, using an embedded libev with
+ * renamed symbols. */
+
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include <verto.h>
+#include <verto-module.h>
+#include "rename.h"
+#include "autoconf.h"
+#define EV_STANDALONE 1
+#define EV_FEATURES 0x5f        /* Everything but back ends */
+#ifdef HAVE_POLL_H
+#define EV_USE_POLL 1
+#else
+#define EV_USE_SELECT 1
+#endif
+#include "ev.c"
+
+static void
+libev_ctx_free(void *ctx)
+{
+    if (ctx != EV_DEFAULT)
+        ev_loop_destroy(ctx);
+}
+
+static void
+libev_ctx_run(void *ctx)
+{
+    ev_run(ctx, 0);
+}
+
+static void
+libev_ctx_run_once(void *ctx)
+{
+    ev_run(ctx, EVRUN_ONCE);
+}
+
+static void
+libev_ctx_break(void *ctx)
+{
+    ev_break(ctx, EVBREAK_ONE);
+}
+
+static void
+libev_callback(EV_P_ ev_watcher *w, int revents)
+{
+    if (verto_get_type(w->data) == VERTO_EV_TYPE_CHILD)
+        verto_set_proc_status(w->data, ((ev_child*) w)->rstatus);
+
+    verto_fire(w->data);
+}
+
+#define setuptype(type, priv, ...) \
+    type ## w = malloc(sizeof(ev_ ## type)); \
+    if (!type ## w) \
+        return NULL; \
+    ev_ ## type ## _init(type ## w, (EV_CB(type, (*))) __VA_ARGS__); \
+    type ## w->data = (void *) priv; \
+    ev_ ## type ## _start(ctx, type ## w); \
+    return type ## w
+
+static void *
+libev_ctx_add(void *ctx, const verto_ev *ev, verto_ev_flag *flags)
+{
+    ev_io *iow = NULL;
+    ev_timer *timerw = NULL;
+    ev_idle *idlew = NULL;
+    ev_signal *signalw = NULL;
+    ev_child *childw = NULL;
+    ev_tstamp interval;
+    int events = EV_NONE;
+
+    *flags |= VERTO_EV_FLAG_PERSIST;
+    switch (verto_get_type(ev)) {
+        case VERTO_EV_TYPE_IO:
+            if (verto_get_flags(ev) & VERTO_EV_FLAG_IO_READ)
+                events |= EV_READ;
+            if (verto_get_flags(ev) & VERTO_EV_FLAG_IO_WRITE)
+                events |= EV_WRITE;
+            setuptype(io, ev, libev_callback, verto_get_fd(ev), events);
+        case VERTO_EV_TYPE_TIMEOUT:
+            interval = ((ev_tstamp) verto_get_interval(ev)) / 1000.0;
+            setuptype(timer, ev, libev_callback, interval, interval);
+        case VERTO_EV_TYPE_IDLE:
+            setuptype(idle, ev, libev_callback);
+        case VERTO_EV_TYPE_SIGNAL:
+            setuptype(signal, ev, libev_callback, verto_get_signal(ev));
+        case VERTO_EV_TYPE_CHILD:
+            *flags &= ~VERTO_EV_FLAG_PERSIST; /* Child events don't persist */
+            setuptype(child, ev, libev_callback, verto_get_proc(ev), 0);
+        default:
+            return NULL; /* Not supported */
+    }
+}
+
+static void
+libev_ctx_del(void *ctx, const verto_ev *ev, void *evpriv)
+{
+    switch (verto_get_type(ev)) {
+        case VERTO_EV_TYPE_IO:
+            ev_io_stop(ctx, evpriv);
+        case VERTO_EV_TYPE_TIMEOUT:
+            ev_timer_stop(ctx, evpriv);
+        case VERTO_EV_TYPE_IDLE:
+            ev_idle_stop(ctx, evpriv);
+        case VERTO_EV_TYPE_SIGNAL:
+            ev_signal_stop(ctx, evpriv);
+        case VERTO_EV_TYPE_CHILD:
+            ev_child_stop(ctx, evpriv);
+        default:
+            break;
+    }
+
+    free(evpriv);
+}
+
+static verto_ctx *verto_new_libev(void);
+static verto_ctx *verto_default_libev(void);
+
+VERTO_MODULE(libev, ev_loop_new,
+             VERTO_EV_TYPE_IO |
+             VERTO_EV_TYPE_TIMEOUT |
+             VERTO_EV_TYPE_IDLE |
+             VERTO_EV_TYPE_SIGNAL |
+             VERTO_EV_TYPE_CHILD);
+
+static verto_ctx *
+verto_new_libev()
+{
+    return verto_convert(libev, ev_loop_new(EVFLAG_AUTO));
+}
+
+static verto_ctx *
+verto_default_libev()
+{
+    return verto_convert(libev, ev_default_loop(EVFLAG_AUTO));
+}
diff --git a/src/util/verto/Makefile.in b/src/util/verto/Makefile.in
new file mode 100644 (file)
index 0000000..3e07227
--- /dev/null
@@ -0,0 +1,45 @@
+mydir=util$(S)verto
+BUILDTOP=$(REL)..$(S)..
+RELDIR=../util/verto
+
+LIBBASE=verto
+LIBMAJOR=0
+LIBMINOR=0
+
+LOCALINCLUDES=-I$(srcdir)
+DEFINES=-DDEFAULT_LIBRARY=\"k5ev\"
+
+# Turn off extra warnings since we're not going to clean up libverto's code.
+WARN_CFLAGS=
+
+STLIBOBJS=verto.o
+LIBOBJS=$(OUTPRE)verto.$(OBJEXT)
+SRCS=verto.c
+
+STOBJLISTS=OBJS.ST
+SHLIB_EXPLIBS= $(DL_LIB)
+SHLIB_DIRS=
+SHLIB_RDIRS=$(KRB5_LIBDIR)
+
+VERTO_HDR=$(BUILDTOP)$(S)include$(S)verto.h
+
+all-unix:: all-liblinks includes
+
+install-unix:: install-libs
+
+clean-unix:: clean-liblinks clean-libs clean-libobjs
+       $(RM) $(VERTO_HDR)
+
+includes:: $(VERTO_HDR)
+
+$(VERTO_HDR): $(srcdir)/verto.h
+       $(RM) $@
+       $(CP) $(srcdir)/verto.h $@
+
+install::
+       $(INSTALL_DATA) $(srcdir)/verto.h $(DESTDIR)$(KRB5_INCDIR)/verto.h
+       $(INSTALL_DATA) $(srcdir)/verto-module.h \
+               $(DESTDIR)$(KRB5_INCDIR)/verto-module.h
+
+@lib_frag@
+@libobj_frag@
diff --git a/src/util/verto/deps b/src/util/verto/deps
new file mode 100644 (file)
index 0000000..b64cc82
--- /dev/null
@@ -0,0 +1,5 @@
+# 
+# Generated makefile dependencies follow.
+#
+verto.so verto.po $(OUTPRE)verto.$(OBJEXT): $(BUILDTOP)/include/verto.h \
+  verto-module.h verto.c
diff --git a/src/util/verto/libverto.exports b/src/util/verto/libverto.exports
new file mode 100644 (file)
index 0000000..dcf3956
--- /dev/null
@@ -0,0 +1,26 @@
+verto_add_child
+verto_add_idle
+verto_add_io
+verto_add_signal
+verto_add_timeout
+verto_break
+verto_convert_funcs
+verto_default
+verto_del
+verto_fire
+verto_free
+verto_get_fd
+verto_get_flags
+verto_get_interval
+verto_get_private
+verto_get_proc
+verto_get_proc_status
+verto_get_signal
+verto_get_supported_types
+verto_get_type
+verto_new
+verto_run
+verto_run_once
+verto_set_default
+verto_set_private
+verto_set_proc_status