distutils about-face
Hmm ... I've changed my mind about using distutils to build htsearch
. It looks like GNU Automake does actually handle Python apps, which means I won't have to mess around getting all the compiler quirk stuff that comes out of Automake working with distutils
. Yay! Now to try and get my Debian install to use the right version of Automake, so it doesn't barf on the configure.in
script.
Debugging notes:
<li>To get Python support, put <code>AM_PATH_PYTHON(2.2)</code> inside <code>configure.in</code>. Then run <code>aclocal</code> to get the Python stuff included in the local library cache (<code>aclocal.m4</code>). If you don't run <code>aclocal</code>, you'll get an error about AM_PATH_PYTHON not being found.<br/></li>
<li> It looks like you need Automake 1.7 to get the Python support ... the Debian package for 1.6 doesn't seem to include the <code>py-compile</code> script. (Gives the error <code>configure.in:186: required file `./py-compile' not found</code>).<br/></li>
<li><code>apt-get install autoconf automake1.7</code> will get you the right versions.<br/></li>
<li>To test changes to <code>configure.in</code>:<br/>
aclocal
autoconf
automake
./configure --prefix=$HOME/htdig/cvs/inst --with-python=yes
<li>Automake seems to get confused if you set <code>prefix</code> but have Python installed under another prefix (it defines <code>PYTHON_PREFIX = $(prefix)</code>). I'm testing ht://Dig in <code>/home/phil/htdig/cvs/inst</code> and the resulting <code>Makefile</code> expects <code>Python.h</code> to be in <code>/home/phil/htdig/cvs/inst/include/python2.2</code>. The workaround is to just use <code>--prefix=/usr</code>, and to install the ht://Dig module in your standard Python site-packages directory later on, I guess.<br/></li>
<li>Automake won't let you make Makefiles that both let you build something as a library with <code>libtool</code> and let you build it as a normal binary (without <code>libtool</code>). So it looks like I can't make this coexist with the normal ht://Dig distribution ... damn. I was hoping to be able to get this included in the official version of ht://Dig, but that's looking much less likely now, unless I can convince them to build most of <code>htsearch</code> as a shared library, and only make little binaries for <code>htsearch</code> and <code>qtest</code> that link to that. That might be OK ...<br/></li>
<li><code>libtool</code> calls <code>gcc</code> rather than <code>g++</code> to generate shared libraries. This will screw up your program if you need to link to the C++ standard library:<br/>
phil@icefloe:~/htdig/cvs/htdig$ python2.2
Python 2.2.1 (#1, Jul 29 2002, 23:15:49)
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import _htsearch
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: /home/phil/htdig/cvs/htdig/htlib/.libs/libht-3.2.0.so: undefined symbol: endl__FR7ostream
>>>
Hmm - looks like libtool officially doesn't like C++. Damn. I wonder if I can
export LD=g++
or something.At least the
libtool
manual is a funny read.If I take the last thing that
libtool
runs and change the gcc
to g++
, then cp .libs/libhtsearch.so.0.0.0 _htsearch.so
and import _htsearch
from python2.2
(as above), it works. Now to automate this.Aha - this may be the solution. Hmm. No, that didn't work.
Here's another crack at it: don't let
libtool
at it at all, but compile as a program (called _htsearch.so
with the link flag -shared
. That's it! It worked!
So there you go. If you want to get something compiling as a Python module under Automake:
- Put
AM_PATH_PYTHON(2.2)
insideconfigure.in
- Put your library file (
_htsearch.so
) in yourbin_PROGRAMS
list - Put
-shared
in theLDFLAGS
:_htsearch_so_LDFLAGS = -shared
- Cross fingers,
aclocal
,autoconf
,automake
,./configure
, and build ...