Stefan Behnel | 11 May 09:01

Re: install lxml 2.0.5 on Mac OS X Leopard - why is it so hard?

Hi Kumar,

you ask why this is so hard? Simple answer: because no-one has contributed a
way so far to make it easier.

We had lots of reports about stuff not working and almost as many
work-arounds, but no-one came up with a patch that would allow building lxml
reliably at least on a subset of Mac-OS systems. And I just cannot believe
that there is no-one amongst the Mac-OS-X users who knows how to use distutils
to build a binary extension. Or at least someone who knows how to build C code
statically against a C library.

>From my POV, Mac-OS seems to lack three things that make this problem
non-trivial. It doesn't have a standard package management system. Neither
does it have something like the Linux Standard Base, which dictates where
newly installed things belong. And it doesn't seem to support "rpath", which
would allow a binary to say "I know where my dependencies come from". Or at
least distutils don't support that on Mac. So everything I could try here on
Linux to make it work better is bound to fail.

Kumar McMillan wrote:
> I know this has been discussed over and over but I'm writing to see if
> anyone has made a breakthrough yet.  The problem of course is that
> Leopard's builtin libxml2 and libxslt are too old for lxml 2.0.  You
> have to build libxml2 either from source or use a port.
[lots of important details skipped to keep this at a higer level for now]
> Next, I tried doing a static build of lxml by setting
> STATIC_LIBRARY_DIRS = ['/opt/local/lib'] in setup.py and running:
> 
> python setup.py bdist_egg --static
> --with-xml2-config=/opt/local/bin/xml2-config
> --with-xslt-config=/opt/local/bin/xslt-config
> 
> I had to fiddle with gcc to get this to build but otherwise it built
> fine and installed ok but I did not see any difference.  Still
> consistent segfaults that are fixed by setting the dyld path.

This is because the --static switch was made specifically for static building
on Windows, which has even less support for package management or even
half-decent software installation. It just doesn't support Mac-OS as no-one
ever told me how to support it.

If you want this to run, let's make a deal. Here is a patch (against the
trunk, but should work with 2.0.x) that lets --static require setting the
STATIC_*_DIRS variables only on Windows, which should result in reading the
directories from xml2-config/xslt-config if the hard-coded setup is not
provided. Given your above example, this should be the right thing to do. Now,
please look at the function "libraries()" in setupinfo.py and fix it up for
Mac-OS-X (and for whatever sys.platform calls it) to find the correct static
libraries in these directories. If you get it to run reliably on your system,
just with your above command line, I'll make sure it gets into 2.0.6.

Stefan

=== setupinfo.py
==================================================================
--- setupinfo.py	(revision 4205)
+++ setupinfo.py	(local)
@@ -127,8 +127,10 @@
     if OPTION_STATIC:
         if not static_library_dirs:
             static_library_dirs = env_var('LIBRARY')
-        assert static_library_dirs, "Static build not configured, see doc/build.txt"
-        return static_library_dirs
+        if static_library_dirs:
+            return static_library_dirs
+        elif sys.platform in ('win32',):
+            assert static_library_dirs, "Static build not configured, see doc/build.txt"
     # filter them from xslt-config --libs
     result = []
     possible_library_dirs = flags('libs')
@@ -141,8 +143,10 @@
     if OPTION_STATIC:
         if not static_include_dirs:
             static_include_dirs = env_var('INCLUDE')
-        assert static_include_dirs, "Static build not configured, see doc/build.txt"
-        return static_include_dirs
+        if static_include_dirs:
+            return static_include_dirs
+        elif sys.platform in ('win32',):
+            assert static_include_dirs, "Static build not configured, see doc/build.txt"
     # filter them from xslt-config --cflags
     result = []
     possible_include_dirs = flags('cflags')
@@ -159,9 +163,11 @@
     if OPTION_STATIC:
         if not static_cflags:
             static_cflags = env_var('CFLAGS')
-        assert static_cflags, "Static build not configured, see doc/build.txt"
-        result.extend(static_cflags)
-        return result
+        if static_cflags:
+            result.extend(static_cflags)
+            return result
+        elif sys.platform in ('win32',):
+            assert static_cflags, "Static build not configured, see doc/build.txt"

     # anything from xslt-config --cflags that doesn't start with -I
     possible_cflags = flags('cflags')
_______________________________________________
lxml-dev mailing list
lxml-dev <at> codespeak.net
http://codespeak.net/mailman/listinfo/lxml-dev

Gmane