as plugins. This way, libcaca does not directly depend on those libraries.tags/v0.99.beta14
@@ -3,6 +3,8 @@ | |||||
EXTRA_DIST = caca.pc.in | EXTRA_DIST = caca.pc.in | ||||
DISTCLEANFILES = caca.pc | DISTCLEANFILES = caca.pc | ||||
AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/cucul -DPLUGINDIR=\"$(plugindir)\" | |||||
pkgconfig_DATA = caca.pc | pkgconfig_DATA = caca.pc | ||||
pkgconfigdir = $(libdir)/pkgconfig | pkgconfigdir = $(libdir)/pkgconfig | ||||
@@ -20,15 +22,28 @@ libcaca_la_SOURCES = \ | |||||
event.c \ | event.c \ | ||||
time.c \ | time.c \ | ||||
driver_conio.c \ | driver_conio.c \ | ||||
driver_gl.c \ | |||||
driver_ncurses.c \ | driver_ncurses.c \ | ||||
driver_raw.c \ | driver_raw.c \ | ||||
driver_slang.c \ | driver_slang.c \ | ||||
driver_vga.c \ | driver_vga.c \ | ||||
driver_win32.c \ | driver_win32.c \ | ||||
driver_x11.c \ | |||||
$(extra_drivers) \ | |||||
$(NULL) | $(NULL) | ||||
AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/cucul | |||||
libcaca_la_LDFLAGS = -no-undefined -version-info @LT_VERSION@ | libcaca_la_LDFLAGS = -no-undefined -version-info @LT_VERSION@ | ||||
libcaca_la_LIBADD = ../cucul/libcucul.la @CACA_LIBS@ | libcaca_la_LIBADD = ../cucul/libcucul.la @CACA_LIBS@ | ||||
if USE_PLUGINS | |||||
plugin_LTLIBRARIES = libx11_plugin.la libgl_plugin.la | |||||
plugindir = $(libdir)/caca | |||||
libx11_plugin_la_SOURCES = driver_x11.c | |||||
libx11_plugin_la_LDFLAGS = -no-undefined -module -no-version | |||||
libx11_plugin_la_LIBADD = libcaca.la ../cucul/libcucul.la @X11_LIBS@ | |||||
libgl_plugin_la_SOURCES = driver_gl.c | |||||
libgl_plugin_la_LDFLAGS = -no-undefined -module -no-version | |||||
libgl_plugin_la_LIBADD = libcaca.la ../cucul/libcucul.la @GL_LIBS@ | |||||
else | |||||
extra_drivers = driver_x11.c driver_gl.c | |||||
endif | |||||
@@ -23,9 +23,15 @@ | |||||
#if !defined(__KERNEL__) | #if !defined(__KERNEL__) | ||||
# include <stdlib.h> | # include <stdlib.h> | ||||
# include <string.h> | # include <string.h> | ||||
# include <stdio.h> | |||||
# if defined(HAVE_ERRNO_H) | # if defined(HAVE_ERRNO_H) | ||||
# include <errno.h> | # include <errno.h> | ||||
# endif | # endif | ||||
# if defined(USE_PLUGINS) | |||||
# if defined(HAVE_DLFCN_H) | |||||
# include <dlfcn.h> | |||||
# endif | |||||
# endif | |||||
#endif | #endif | ||||
#include "cucul.h" | #include "cucul.h" | ||||
@@ -33,7 +39,15 @@ | |||||
#include "caca.h" | #include "caca.h" | ||||
#include "caca_internals.h" | #include "caca_internals.h" | ||||
static int caca_select_driver(caca_display_t *dp); | |||||
#if defined(USE_PLUGINS) | |||||
# define gl_install(p) caca_plugin_install("gl", p) | |||||
# define x11_install(p) caca_plugin_install("x11", p) | |||||
#endif | |||||
static int caca_select_driver(caca_display_t *); | |||||
#if defined(USE_PLUGINS) | |||||
static int caca_plugin_install(char const *, caca_display_t *); | |||||
#endif | |||||
/** \brief Attach a caca graphical context to a cucul canvas. | /** \brief Attach a caca graphical context to a cucul canvas. | ||||
* | * | ||||
@@ -62,9 +76,16 @@ caca_display_t * caca_create_display(cucul_canvas_t * cv) | |||||
} | } | ||||
dp->cv = cv; | dp->cv = cv; | ||||
#if defined(USE_PLUGINS) | |||||
dp->plugin = NULL; | |||||
#endif | |||||
if(caca_select_driver(dp)) | if(caca_select_driver(dp)) | ||||
{ | { | ||||
#if defined(USE_PLUGINS) | |||||
if(dp->plugin) | |||||
dlclose(dp->plugin); | |||||
#endif | |||||
free(dp); | free(dp); | ||||
#if defined(HAVE_ERRNO_H) | #if defined(HAVE_ERRNO_H) | ||||
errno = ENODEV; | errno = ENODEV; | ||||
@@ -74,6 +95,10 @@ caca_display_t * caca_create_display(cucul_canvas_t * cv) | |||||
if(dp->drv.init_graphics(dp)) | if(dp->drv.init_graphics(dp)) | ||||
{ | { | ||||
#if defined(USE_PLUGINS) | |||||
if(dp->plugin) | |||||
dlclose(dp->plugin); | |||||
#endif | |||||
free(dp); | free(dp); | ||||
#if defined(HAVE_ERRNO_H) | #if defined(HAVE_ERRNO_H) | ||||
errno = ENODEV; | errno = ENODEV; | ||||
@@ -128,6 +153,10 @@ caca_display_t * caca_create_display(cucul_canvas_t * cv) | |||||
int caca_free_display(caca_display_t *dp) | int caca_free_display(caca_display_t *dp) | ||||
{ | { | ||||
dp->drv.end_graphics(dp); | dp->drv.end_graphics(dp); | ||||
#if defined(USE_PLUGINS) | |||||
if(dp->plugin) | |||||
dlclose(dp->plugin); | |||||
#endif | |||||
dp->cv->refcount--; | dp->cv->refcount--; | ||||
free(dp); | free(dp); | ||||
@@ -201,3 +230,31 @@ static int caca_select_driver(caca_display_t *dp) | |||||
return -1; | return -1; | ||||
} | } | ||||
#if defined(USE_PLUGINS) | |||||
static int caca_plugin_install(char const *name, caca_display_t *dp) | |||||
{ | |||||
char buf[512]; | |||||
int (*sym) (caca_display_t *); | |||||
sprintf(buf, "%s/lib%s_plugin.so", PLUGINDIR, name); | |||||
dp->plugin = dlopen(buf, RTLD_NOW); | |||||
if(!dp->plugin) | |||||
{ | |||||
sprintf(buf, "lib%s_plugin.so", name); | |||||
dp->plugin = dlopen(buf, RTLD_NOW); | |||||
if(!dp->plugin) | |||||
return -1; | |||||
} | |||||
sprintf(buf, "%s_install", name); | |||||
sym = dlsym(dp->plugin, buf); | |||||
if(!sym) | |||||
{ | |||||
dlclose(dp->plugin); | |||||
return -1; | |||||
} | |||||
return sym(dp); | |||||
} | |||||
#endif | |||||
@@ -88,6 +88,10 @@ struct caca_display | |||||
/* A link to our cucul canvas */ | /* A link to our cucul canvas */ | ||||
cucul_canvas_t *cv; | cucul_canvas_t *cv; | ||||
#if defined(USE_PLUGINS) | |||||
void *plugin; | |||||
#endif | |||||
/* Device-specific functions */ | /* Device-specific functions */ | ||||
struct drv | struct drv | ||||
{ | { | ||||
@@ -62,10 +62,12 @@ AC_ARG_ENABLE(imlib2, | |||||
[ --enable-imlib2 Imlib2 graphics support (default enabled)]) | [ --enable-imlib2 Imlib2 graphics support (default enabled)]) | ||||
dnl conditional builds | dnl conditional builds | ||||
AC_ARG_ENABLE(plugins, | |||||
[ --enable-plugins build X11 and GL drivers as plugins]) | |||||
AC_ARG_ENABLE(doc, | AC_ARG_ENABLE(doc, | ||||
[ --enable-doc build documentation (needs doxygen and LaTeX)]) | [ --enable-doc build documentation (needs doxygen and LaTeX)]) | ||||
AC_CHECK_HEADERS(stdio.h stdarg.h signal.h sys/ioctl.h sys/time.h inttypes.h endian.h unistd.h arpa/inet.h netinet/in.h winsock2.h errno.h locale.h getopt.h) | |||||
AC_CHECK_HEADERS(stdio.h stdarg.h signal.h sys/ioctl.h sys/time.h inttypes.h endian.h unistd.h arpa/inet.h netinet/in.h winsock2.h errno.h locale.h getopt.h dlfcn.h) | |||||
AC_CHECK_FUNCS(signal ioctl vsnprintf getenv putenv strcasecmp htons) | AC_CHECK_FUNCS(signal ioctl vsnprintf getenv putenv strcasecmp htons) | ||||
AC_CHECK_FUNCS(usleep gettimeofday) | AC_CHECK_FUNCS(usleep gettimeofday) | ||||
@@ -156,7 +158,7 @@ if test "${enable_x11}" != "no"; then | |||||
if test -n "${x_libraries}"; then X_LIBS="-L${x_libraries}"; fi | if test -n "${x_libraries}"; then X_LIBS="-L${x_libraries}"; fi | ||||
AC_DEFINE(USE_X11, 1, Define to 1 to activate the X11 backend driver) | AC_DEFINE(USE_X11, 1, Define to 1 to activate the X11 backend driver) | ||||
CPPFLAGS="${CPPFLAGS} ${X_CFLAGS}" | CPPFLAGS="${CPPFLAGS} ${X_CFLAGS}" | ||||
CACA_LIBS="${CACA_LIBS} -lX11 ${X_LIBS}" | |||||
X11_LIBS="${X11_LIBS} -lX11 ${X_LIBS}" | |||||
CACA_DRIVERS="${CACA_DRIVERS} x11"], | CACA_DRIVERS="${CACA_DRIVERS} x11"], | ||||
[ac_cv_my_have_x11="no"], | [ac_cv_my_have_x11="no"], | ||||
[[`if test -n "${x_libraries}"; then echo -L${x_libraries}; fi`]]) | [[`if test -n "${x_libraries}"; then echo -L${x_libraries}; fi`]]) | ||||
@@ -180,7 +182,7 @@ if test "${enable_gl}" != "no"; then | |||||
break]) | break]) | ||||
if test "${ac_cv_my_have_gl}" = "yes"; then | if test "${ac_cv_my_have_gl}" = "yes"; then | ||||
AC_DEFINE(USE_GL, 1, Define to 1 to activate the OpenGL backend driver) | AC_DEFINE(USE_GL, 1, Define to 1 to activate the OpenGL backend driver) | ||||
CACA_LIBS="${CACA_LIBS} -lGL -lglut" | |||||
GL_LIBS="${GL_LIBS} -lGL -lglut" | |||||
CACA_DRIVERS="${CACA_DRIVERS} gl" | CACA_DRIVERS="${CACA_DRIVERS} gl" | ||||
elif test "${enable_gl}" = "yes"; then | elif test "${enable_gl}" = "yes"; then | ||||
AC_MSG_ERROR([cannot find OpenGL+FreeGLUT development files]) | AC_MSG_ERROR([cannot find OpenGL+FreeGLUT development files]) | ||||
@@ -224,6 +226,15 @@ if test "${enable_vga}" = "yes"; then | |||||
fi | fi | ||||
AM_CONDITIONAL(USE_KERNEL, test "${ac_cv_my_have_vga}" = "yes") | AM_CONDITIONAL(USE_KERNEL, test "${ac_cv_my_have_vga}" = "yes") | ||||
if test "${enable_plugins}" = "yes"; then | |||||
ac_cv_my_have_plugins="yes" | |||||
AC_DEFINE(USE_PLUGINS, 1, Define to 1 to activate plugins) | |||||
CACA_LIBS="${CACA_LIBS} -ldl" | |||||
else | |||||
CACA_LIBS="${CACA_LIBS} ${X11_LIBS} ${GL_LIBS}" | |||||
fi | |||||
AM_CONDITIONAL(USE_PLUGINS, test "${ac_cv_my_have_plugins}" = "yes") | |||||
AC_MSG_CHECKING(valid output drivers) | AC_MSG_CHECKING(valid output drivers) | ||||
if test -z "${CACA_DRIVERS}"; then | if test -z "${CACA_DRIVERS}"; then | ||||
AC_MSG_RESULT(no) | AC_MSG_RESULT(no) | ||||
@@ -237,6 +248,8 @@ fi | |||||
AC_SUBST(MATH_LIBS) | AC_SUBST(MATH_LIBS) | ||||
AC_SUBST(GETOPT_LIBS) | AC_SUBST(GETOPT_LIBS) | ||||
AC_SUBST(CACA_LIBS) | AC_SUBST(CACA_LIBS) | ||||
AC_SUBST(X11_LIBS) | |||||
AC_SUBST(GL_LIBS) | |||||
# Optimizations | # Optimizations | ||||
CFLAGS="${CFLAGS} -g -O2 -fno-strength-reduce -fomit-frame-pointer" | CFLAGS="${CFLAGS} -g -O2 -fno-strength-reduce -fomit-frame-pointer" | ||||
@@ -261,7 +274,7 @@ AM_CONDITIONAL(USE_NETWORK, test "${ac_cv_my_have_network}" = "yes") | |||||
# Use Imlib2? | # Use Imlib2? | ||||
if test "${enable_imlib2}" != "no"; then | if test "${enable_imlib2}" != "no"; then | ||||
IMLIB2="no" | IMLIB2="no" | ||||
PKG_CHECK_MODULES(imlib2, imlib2, [IMLIB2="yes"], [AC_MSG_RESULT(no)]) | |||||
PKG_CHECK_MODULES(IMLIB2, imlib2, [IMLIB2="yes"], [AC_MSG_RESULT(no)]) | |||||
if test "${IMLIB2}" = no; then | if test "${IMLIB2}" = no; then | ||||
AC_MSG_ERROR([[cannot find Imlib2 development files. Without Imlib2, cacaview will only open BMP files; if this is really what you want, re-run configure with '--disable-imlib2'.]]) | AC_MSG_ERROR([[cannot find Imlib2 development files. Without Imlib2, cacaview will only open BMP files; if this is really what you want, re-run configure with '--disable-imlib2'.]]) | ||||
fi | fi | ||||
@@ -269,7 +282,7 @@ fi | |||||
# Build development tools? | # Build development tools? | ||||
PANGOFT2="no" | PANGOFT2="no" | ||||
PKG_CHECK_MODULES(pangoft2, pangoft2, [PANGOFT2="yes"], [AC_MSG_RESULT(no)]) | |||||
PKG_CHECK_MODULES(PANGOFT2, pangoft2, [PANGOFT2="yes"], [AC_MSG_RESULT(no)]) | |||||
AM_CONDITIONAL(USE_PANGO, test "${PANGOFT2}" != "no") | AM_CONDITIONAL(USE_PANGO, test "${PANGOFT2}" != "no") | ||||
# Build documentation? | # Build documentation? | ||||