[Distutils] Oh yeah! one more feature

Greg Ward gward@cnri.reston.va.us
Mon, 4 Oct 1999 08:30:01 -0400

Whoops, I totally forgot to mention the other potentially useful feature
I added this weekend.  Now, entries in the 'libraries' list can include
a directory component, which will tell the compiler interface to
instruct the C compiler to look only in that directory for that
particular library.

Umm, was that too opaque?  Here's an example.  Before this change, the
example pil_setup.py included with the Distutils had this:

       ext_modules = \
             { 'sources': # ...
               # ...
               'library_dirs': ['libImaging', '/usr/local/lib'],
               'libraries': ['Imaging', 'jpeg', 'z', 'tcl8.0', 'tk8.0']

This resulted (on Unix) in a link command like this:

    gcc -shared ... -LlibImaging -L/usr/local/lib \
        -lImaging -ljpeg -lz -ltcl8.0 -ltk8.0

Now, we can specify that the "Imaging" library must come from the
"libImaging" subdirectory, rather than being searched for all over the
place.  The current pil_setup.py has this:

       ext_modules = \
             { 'sources': # ...
               # ...
               'library_dirs': ['/usr/local/lib'],
               'libraries': ['libImaging/Imaging',
                             'jpeg', 'z', 'tcl8.0', 'tk8.0']

Now the link command looks like this:

    gcc -shared ... -L/usr/local/lib \
        libImaging/Imaging.a -ljpeg -lz -ltcl8.0 -ltk8.0

Note that this has the unpleasant consequence that the Distutils
compiler class (UnixCCompiler, in this case) has to second-guess what
the linker does to find a particular library.  This isn't too hard for
me using GCC, since GCC is fairly well documented in this regard.
However I'm sure there are Unices where my rash assumptions (if
"dir/foo" found in 'libraries' list, look for "dir/libfoo.so", then
"dir/libfoo.a") will not hold.

Of course, the directory can be absolute -- this shoots portability to
hell, but should be welcome if you're using the Distutils as a private
build tool and just want to be sure you're linking in *exactly*
such-and-such version of a library.  I know at least one person (hi
Paul!) who will like this.

And the implementation of this feature for MSVC is a wild guess on my
part.  Again, Windows people are kindly requested to take a look and see
how close to reality my guess is.  (See the 'gen_lib_options()' function
in distutils.ccompiler, and then the 'find_library_file()' method in
both distutils.unixccompiler and distutils.msvccompiler.)  This code is
all in yesterday's snapshot.

Greg Ward - software developer                    gward@cnri.reston.va.us
Corporation for National Research Initiatives    
1895 Preston White Drive                           voice: +1-703-620-8990
Reston, Virginia, USA  20191-5434                    fax: +1-703-620-0913