Dirk Meyer wrote:
Gorka Olaizola wrote:
On Fri, Feb 24, 2006 at 12:57:13AM +0100, Lucian Muresan wrote:
+have_x11 = 1
+try:
+    dl.open('/usr/lib/libX11.so')
+except dl.error, err:
+    print "System without X11 detected"
+    have_x11 = 0
+

The problem I see with this is that one can have the runtime libX11 but not
the development libraries that I think are needeed to compile kaa.Display.
I think you have to use check_cc because it tries to compile a code snippet
to checks that the compilation of the library actually works.

Right.

Thanks for spotting. I hope now the attached one is better. I do not know If I applied the check_cc variant properly, as I could only call it on an already defined display, respectively xineso object, and afterwards, if X11 is missing, define it again. Well, I'm not sure if that's ok, is the "old" object really destroyed (you see I don't know python :-) ). I couldn't fully test the patch, as on the colinux-gentoo I have at work there is only a older xine-lib and the sysadmin now blocked several ports...), but the X11 detection works (I simulated the absence by temporary moving alternatively Xlib.h and libX11* files out of the way).

Now I guess I have to somehow try to replace X11window/X11Display with DFBwindow/DFBDisplay in the kaa/xine/test samples at home on my system...

kaa.xine is not yet really usable in freevo2 itself right now? Taaaack ;-)!!!

Lucian




diff -Naur --exclude=entries kaa/display/setup.py kaa_noX11/display/setup.py
--- kaa/display/setup.py        2006-02-24 11:15:31.000000000 +0100
+++ kaa_noX11/display/setup.py  2006-02-24 12:21:21.120000000 +0100
@@ -48,29 +48,43 @@
 if fb.check_library('imlib2', '1.1.1'):
     print "+ FB support enabled"
 else:
-    print "+ FB support disabled"
+    print "- FB support disabled"
     fb = None
 
-# the framebuffer so module
+# the DirectFB so module
 dfb = Extension('kaa.display._DFBmodule', [ 'src/dfb.c'] )
 
 if dfb.check_library('directfb', '0.9.20'):
     print "+ DFB support enabled"
 else:
-    print "+ DFB support disabled"
+    print "- DFB support disabled"
     dfb = None
 
-# the display so module
+# the display so module (first, assume X11 is present)
+have_x11 = 1
 display = Extension('kaa.display._Displaymodule',
-                    [ 'src/display.c', 'src/sdl.c', 'src/x11display.c',
-                      'src/x11window.c', 'src/imlib2.c', 'src/evas.c' ],
+                [ 'src/display.c', 'src/sdl.c', 'src/x11display.c',
+                  'src/x11window.c', 'src/imlib2.c', 'src/evas.c' ],
+                libraries = ['png', 'rt'],
+                config='src/config.h')
+display.config('#define HAVE_X11')
+
+# check if X11 is actually present
+try:
+    if not display.check_cc(['<X11/Xlib.h>'], '', '-lX11'):
+       raise AttributeError()
+except AttributeError:
+    print "System without X11 detected! Disabling all X11 dependencies..."
+    display.config('#undef HAVE_X11')
+    have_x11 = 0
+    display = Extension('kaa.display._Displaymodule',
+                    [ 'src/display.c', 'src/sdl.c', 'src/imlib2.c', 
'src/evas.c' ],
                     libraries = ['png', 'rt'],
                     config='src/config.h')
 
-
 if display.check_library('imlib2', '1.1.1'):
     display.config('#define USE_IMLIB2')
-    if 'X11' in display.libraries:
+    if have_x11 & ('X11' in display.libraries):
         display.config('#define USE_IMLIB2_DISPLAY')
         print "+ Imlib2 support enabled"
     else:
diff -Naur --exclude=entries kaa/display/src/display.c 
kaa_noX11/display/src/display.c
--- kaa/display/src/display.c   2006-02-24 11:15:30.000000000 +0100
+++ kaa_noX11/display/src/display.c     2006-02-24 11:19:14.000000000 +0100
@@ -33,8 +33,10 @@
 #include <Python.h>
 #include "config.h"
 #include "display.h"
+#ifdef HAVE_X11
 #include "x11display.h"
 #include "x11window.h"
+#endif
 #include "imlib2.h"
 #include "evas.h"
 #include "sdl.h"
@@ -43,11 +45,13 @@
     { "image_to_surface", (PyCFunction) image_to_surface, METH_VARARGS },
     { "render_imlib2_image", (PyCFunction) render_imlib2_image, METH_VARARGS },
 #ifdef USE_EVAS
+#ifdef HAVE_X11
     { "new_evas_software_x11", (PyCFunction) new_evas_software_x11, 
METH_VARARGS | METH_KEYWORDS },
 #ifdef ENABLE_ENGINE_GL_X11
     { "new_evas_gl_x11", (PyCFunction) new_evas_gl_x11, METH_VARARGS | 
METH_KEYWORDS },
 #endif
 #endif
+#endif
     { NULL }
 };
 
@@ -74,7 +78,7 @@
     static void *display_api_ptrs[3];
 
     m = Py_InitModule("_Display", display_methods);
-
+    #ifdef HAVE_X11
     if (PyType_Ready(&X11Display_PyObject_Type) < 0)
         return;
     Py_INCREF(&X11Display_PyObject_Type);
@@ -85,11 +89,12 @@
     Py_INCREF(&X11Window_PyObject_Type);
     PyModule_AddObject(m, "X11Window", (PyObject *)&X11Window_PyObject_Type);
 
+
     // Export display C API
     display_api_ptrs[0] = (void *)X11Window_PyObject__wrap;
     display_api_ptrs[1] = (void *)&X11Window_PyObject_Type;
     display_api_ptrs[2] = (void *)x11window_object_decompose;
-
+    #endif
     display_c_api = PyCObject_FromVoidPtr((void *)display_api_ptrs, NULL);
     PyModule_AddObject(m, "_C_API", display_c_api);
 
@@ -114,7 +119,8 @@
 #else
     Evas_PyObject_Type = NULL;
 #endif
-
+    #ifdef HAVE_X11
     if (!XInitThreads())
         PyErr_Format(PyExc_SystemError, "Unable to initialize X11 threads.");
+    #endif
 }
diff -Naur --exclude=entries kaa/display/src/evas.c kaa_noX11/display/src/evas.c
--- kaa/display/src/evas.c      2006-02-24 11:15:30.000000000 +0100
+++ kaa_noX11/display/src/evas.c        2006-02-24 11:19:14.000000000 +0100
@@ -39,8 +39,10 @@
 #ifdef USE_EVAS
 
 #include "evas.h"
+#ifdef HAVE_X11
 #include "x11display.h"
 #include "x11window.h"
+#endif
 
 Evas *(*evas_object_from_pyobject)(PyObject *pyevas);
 
diff -Naur --exclude=entries kaa/display/src/evas.h kaa_noX11/display/src/evas.h
--- kaa/display/src/evas.h      2006-02-24 11:15:30.000000000 +0100
+++ kaa_noX11/display/src/evas.h        2006-02-24 11:19:14.000000000 +0100
@@ -37,15 +37,17 @@
 #define _EVAS_H_
 
 #ifdef USE_EVAS
+#ifdef HAVE_X11
 #include "x11window.h"
+#endif
 #include <Evas.h>
 extern Evas *(*evas_object_from_pyobject)(PyObject *pyevas);
-
+#ifdef HAVE_X11
 X11Window_PyObject *new_evas_software_x11(PyObject *, PyObject *, PyObject *);
 
 #ifdef ENABLE_ENGINE_GL_X11
 X11Window_PyObject *new_evas_gl_x11(PyObject *, PyObject *, PyObject *);
 #endif
-
+#endif // HAVE_X11
 #endif // USE_EVAS
 #endif // _EVAS_H_
diff -Naur --exclude=entries kaa/xine/setup.py kaa_noX11/xine/setup.py
--- kaa/xine/setup.py   2006-02-24 11:15:27.000000000 +0100
+++ kaa_noX11/xine/setup.py     2006-02-24 12:49:26.270000000 +0100
@@ -34,7 +34,8 @@
 except ImportError:
     print 'kaa.base not installed'
     sys.exit(1)
-    
+
+# first, assume X11 is present
 files = ['src/xine.c', 'src/video_port.c', 'src/audio_port.c', 'src/stream.c',
          'src/post.c', 'src/drivers/x11.c', 'src/drivers/video_out_kaa.c',
          'src/post_out.c', 'src/post_in.c', 'src/event.c', 'src/event_queue.c',
@@ -46,6 +47,22 @@
                    libraries = ["X11"], 
                    # FIXME: don't hardcode this path
                    library_dirs = ["/usr/X11R6/lib"])
+xineso.config('#define HAVE_X11')
+# check if X11 is actually present
+try:
+    if not xineso.check_cc(['<X11/Xlib.h>'], '', '-lX11'):
+       raise AttributeError()
+except AttributeError:
+    print "System without X11 detected! Disabling all X11 dependencies..."
+    xineso.config('#undef HAVE_X11')
+files = ['src/xine.c', 'src/video_port.c', 'src/audio_port.c', 'src/stream.c',
+         'src/post.c', 'src/drivers/video_out_kaa.c',
+         'src/post_out.c', 'src/post_in.c', 'src/event.c', 'src/event_queue.c',
+         'src/utils.c', 'src/vo_driver.c', 'src/drivers/kaa.c',
+         'src/drivers/yuv2rgb.c', 'src/drivers/yuv2rgb_mmx.c', 
'src/drivers/dummy.c',
+         'src/drivers/video_out_dummy.c', 'src/drivers/common.c', 
'src/drivers/fb.c'
+]
+xineso = Extension('kaa.xine._xinemodule', files, config='src/config.h')
 
 if not xineso.check_library('xine', '1.1.1'):
     print 'xine >= 1.1.1 not found'
diff -Naur --exclude=entries kaa/xine/src/drivers/common.c 
kaa_noX11/xine/src/drivers/common.c
--- kaa/xine/src/drivers/common.c       2006-02-24 11:15:27.000000000 +0100
+++ kaa_noX11/xine/src/drivers/common.c 2006-02-24 11:19:14.000000000 +0100
@@ -1,5 +1,7 @@
 #include "common.h"
+#ifdef HAVE_X11
 #include "x11.h"
+#endif
 #include "kaa.h"
 #include "dummy.h"
 
@@ -10,8 +12,12 @@
     *visual_type_return = XINE_VISUAL_TYPE_NONE;
     if (!strcmp(driver, "xv") || !strcmp(driver, "xshm") || !strcmp(driver, 
"auto") ||
         !strcmp(driver, "opengl") || !strcmp(driver, "sdl")) {
+       #ifdef HAVE_X11
         *visual_type_return = XINE_VISUAL_TYPE_X11;
         return x11_get_visual_info(xine, kwargs, visual_return, 
driver_info_return);
+       #endif
+       PyErr_Format(PyExc_ValueError, "Unsupported driver: %s", driver);
+       return 0;       
     } else if (!strcmp(driver, "none")) {
         *driver_info_return = 0;
         *visual_return = 0;
diff -Naur --exclude=entries kaa/xine/src/xine.c kaa_noX11/xine/src/xine.c
--- kaa/xine/src/xine.c 2006-02-24 11:15:27.000000000 +0100
+++ kaa_noX11/xine/src/xine.c   2006-02-24 11:19:14.000000000 +0100
@@ -13,7 +13,9 @@
 #include "drivers/video_out_kaa.h"
 #include "drivers/video_out_dummy.h"
 #include "drivers/kaa.h"
+#ifdef HAVE_X11
 #include "drivers/x11.h"
+#endif
 #include "drivers/dummy.h"
 #include "drivers/common.h"
 
@@ -740,10 +742,14 @@
         PyErr_Format(xine_error, "Failed to import kaa.display");
         return;
     }
+    #ifdef HAVE_X11
     X11Window_PyObject_Type = display_api_ptrs[1];
     x11window_object_decompose = display_api_ptrs[2];
+    #endif
 #else
+    #ifdef HAVE_X11
     X11Window_PyObject_Type = NULL;
+    #endif
 #endif
 
     PyEval_InitThreads();

Reply via email to