Ignore:
Timestamp:
Oct 20, 2006, 12:43:17 AM (14 years ago)
Author:
Sam Hocevar
Message:
  • Added a --enable-plugins configure flag that builds the GL and X11 drivers as plugins. This way, libcaca does not directly depend on those libraries.
Location:
libcaca/trunk/caca
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca/Makefile.am

    r1013 r1208  
    33EXTRA_DIST = caca.pc.in
    44DISTCLEANFILES = caca.pc
     5
     6AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/cucul -DPLUGINDIR=\"$(plugindir)\"
    57
    68pkgconfig_DATA = caca.pc
     
    2123        time.c \
    2224        driver_conio.c \
    23         driver_gl.c \
    2425        driver_ncurses.c \
    2526        driver_raw.c \
     
    2728        driver_vga.c \
    2829        driver_win32.c \
    29         driver_x11.c \
     30        $(extra_drivers) \
    3031        $(NULL)
    31 AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/cucul
    3232libcaca_la_LDFLAGS = -no-undefined -version-info @LT_VERSION@
    3333libcaca_la_LIBADD = ../cucul/libcucul.la @CACA_LIBS@
    3434
     35if USE_PLUGINS
     36plugin_LTLIBRARIES = libx11_plugin.la libgl_plugin.la
     37plugindir = $(libdir)/caca
     38
     39libx11_plugin_la_SOURCES = driver_x11.c
     40libx11_plugin_la_LDFLAGS = -no-undefined -module -no-version
     41libx11_plugin_la_LIBADD = libcaca.la ../cucul/libcucul.la @X11_LIBS@
     42
     43libgl_plugin_la_SOURCES = driver_gl.c
     44libgl_plugin_la_LDFLAGS = -no-undefined -module -no-version
     45libgl_plugin_la_LIBADD = libcaca.la ../cucul/libcucul.la @GL_LIBS@
     46else
     47extra_drivers = driver_x11.c driver_gl.c
     48endif
     49
  • libcaca/trunk/caca/caca.c

    r1054 r1208  
    2424#   include <stdlib.h>
    2525#   include <string.h>
     26#   include <stdio.h>
    2627#   if defined(HAVE_ERRNO_H)
    2728#       include <errno.h>
     29#   endif
     30#   if defined(USE_PLUGINS)
     31#       if defined(HAVE_DLFCN_H)
     32#           include <dlfcn.h>
     33#       endif
    2834#   endif
    2935#endif
     
    3440#include "caca_internals.h"
    3541
    36 static int caca_select_driver(caca_display_t *dp);
     42#if defined(USE_PLUGINS)
     43#   define gl_install(p) caca_plugin_install("gl", p)
     44#   define x11_install(p) caca_plugin_install("x11", p)
     45#endif
     46
     47static int caca_select_driver(caca_display_t *);
     48#if defined(USE_PLUGINS)
     49static int caca_plugin_install(char const *, caca_display_t *);
     50#endif
    3751
    3852/** \brief Attach a caca graphical context to a cucul canvas.
     
    6377
    6478    dp->cv = cv;
     79#if defined(USE_PLUGINS)
     80    dp->plugin = NULL;
     81#endif
    6582
    6683    if(caca_select_driver(dp))
    6784    {
     85#if defined(USE_PLUGINS)
     86        if(dp->plugin)
     87            dlclose(dp->plugin);
     88#endif
    6889        free(dp);
    6990#if defined(HAVE_ERRNO_H)
     
    7596    if(dp->drv.init_graphics(dp))
    7697    {
     98#if defined(USE_PLUGINS)
     99        if(dp->plugin)
     100            dlclose(dp->plugin);
     101#endif
    77102        free(dp);
    78103#if defined(HAVE_ERRNO_H)
     
    129154{
    130155    dp->drv.end_graphics(dp);
     156#if defined(USE_PLUGINS)
     157    if(dp->plugin)
     158        dlclose(dp->plugin);
     159#endif
    131160    dp->cv->refcount--;
    132161    free(dp);
     
    202231}
    203232
     233#if defined(USE_PLUGINS)
     234static int caca_plugin_install(char const *name, caca_display_t *dp)
     235{
     236    char buf[512];
     237    int (*sym) (caca_display_t *);
     238
     239    sprintf(buf, "%s/lib%s_plugin.so", PLUGINDIR, name);
     240    dp->plugin = dlopen(buf, RTLD_NOW);
     241    if(!dp->plugin)
     242    {
     243        sprintf(buf, "lib%s_plugin.so", name);
     244        dp->plugin = dlopen(buf, RTLD_NOW);
     245        if(!dp->plugin)
     246            return -1;
     247    }
     248
     249    sprintf(buf, "%s_install", name);
     250    sym = dlsym(dp->plugin, buf);
     251    if(!sym)
     252    {
     253        dlclose(dp->plugin);
     254        return -1;
     255    }
     256
     257    return sym(dp);
     258}
     259#endif
     260
  • libcaca/trunk/caca/caca_internals.h

    r978 r1208  
    8989    cucul_canvas_t *cv;
    9090
     91#if defined(USE_PLUGINS)
     92    void *plugin;
     93#endif
     94
    9195    /* Device-specific functions */
    9296    struct drv
Note: See TracChangeset for help on using the changeset viewer.