[Distutils] Building an intermediate library

Robin Becker robin@jessikat.fsnet.co.uk
Sun Jul 15 09:05:01 2001


In article <cj43lt4htp8ekl1hprbn92tq6cackrdmp7@4ax.com>, Paul Moore <gustav@morpheus.demon.co.uk>
writes
>I have an extension which I am trying to build using distutils. There are a
>series of .c files in a subdirectory, and a couple of driver C files. The
>subdirectory files should, ideally, be compiled and then built into a temporary
>.lib file, which is then linked with the 2 individual driver files to create two
>.pyd extensions. I can do the build by listing all of the subdirectory .c files
>in the build instructions for the 2 .pyds, but if I do this, the compiler (MSVC)
>doesn't seem to eliminate unused object files. So either I need to list exactly
>the right .c files for each extension, or I build the intermediate .lib.
>
>The problem is, I can't work out if it is possible to persuade distutils to
>build an intermediate library like this. Is it possible? If so, can anyone point
>me to any suitable examples of what to do? (Or alternatively, point me at the
>appropriate parts of the source, and appropriate example setup.py files, to
>allow me to work out how to do this for myself.)
>
>Thanks,
>Paul.
...
here's what I'm using with distutils to try and build the imaging stuff
#!/usr/bin/env python
'''Distutils setup for FLundh's imaging library'''
import os, sys, string
from distutils.core import setup, Extension
from distutils.ccompiler import new_compiler

pyVer = string.split(sys.version)[0]
tclVer = pyVer>='1.6' and '83' or '82'
if sys.platform=="win32":
        _imaging_libs=['libImaging','libz','libjpeg','gdi32']
        _imagingtk_libs=['libImaging','tk'+tclVer,'tcl'+tclVer]
        TCL_LIBDIR='../../tcl'
        TCL_INCDIR='/tcl/include'
else:
        _imaging_libs=['Imaging','z','jpeg']
        _imagingtk_libs=['Imaging','tk'+tclVer,'tcl'+tclVer]

# Make sure the user has (configured and) built the C Imaging library.
# Take advantage of the Distutils bureaucracy to generate the filename
# of the library in a portable way.
compiler = new_compiler()
lib_file = os.path.join ("libImaging", compiler.library_filename (_imaging_libs[0]))
JPEGINC='../jpeg-6b'
ZLIBINC='../zlib-1.1.3'
libImagingSRCs=['libImaging\\%s.c'%x for x in string.split('''Access
Bands
BitDecode
Blend
Chops
Convert
ConvertYCbCr
Copy
Crc32
Crop
Dib
Draw
Effects
EpsEncode
Except
File
Fill
Filter
FliDecode
Geometry
GetBBox
GifDecode
GifEncode
HexDecode
Histo
JpegDecode
JpegEncode
LzwDecode
Matrix
MspDecode
Negative
Offset
Pack
PackDecode
Palette
Paste
Quant
QuantHash
QuantHeap
PcdDecode
PcxDecode
PcxEncode
Point
RawDecode
RawEncode
Storage
SunRleDecode
TgaRleDecode
Unpack
UnpackYCC
XbmDecode
XbmEncode
ZipDecode
ZipEncode''')]
_imaging_ext=Extension( '_imaging',
                                                ['_imaging.c', 'decode.c', 'encode.c', 'map.c', 'display.c', 'outline.c', 'path.c'],
                                                include_dirs = ['libImaging',JPEGINC,ZLIBINC],
                                                library_dirs= ['./libImaging'],
                                                libraries= _imaging_libs,
                                                )
_imagingtk_ext=Extension(       '_imagingtk',
                                                ['_imagingtk.c', 'Tk/tkImaging.c'],
                                                include_dirs = ['libImaging',TCL_INCDIR],
                                                library_dirs= ['./libImaging',TCL_LIBDIR],
                                                libraries= _imagingtk_libs,
                                                )

setup(  name = "PIL",
                version = "1.1.2",
                description = "Python Imaging Library",
                author = "Fredrik Lundh",
                author_email = "fredrik@pythonware.com",
                url = "http://www.pythonware.com/downloads.htm",
                packages = ['PIL'],
                libraries=      [('libImaging',
                                        {
                                        'sources':      libImagingSRCs,
                                        'include_dirs': [JPEGINC,ZLIBINC,],
                                        'macros': [],
                                        }
                                        ),
                                        ],
                ext_modules =   [_imaging_ext, _imagingtk_ext],
        )

if sys.platform=='win32' and ('install' in sys.argv or 'install_ext' in sys.argv):
        def MovePYDs(*F):
                for x in sys.argv:
                        if x[:18]=='--install-platlib=': return
                src = sys.exec_prefix
                dst = os.path.join(src,'DLLs')
                for f in F:
                        dstf = os.path.join(dst,f)
                        try:
                                os.remove(dstf)
                        except:
                                pass
                        os.rename(os.path.join(src,f),dstf)
        MovePYDs('_imaging.pyd','_imagingtk.pyd')

-- 
Robin Becker