blob: eab1f594481845a7d436aae15f7fec3a060a2be6 [file] [log] [blame]
Andrew M. Kuchling66012fe2001-01-26 21:56:58 +00001# Autodetecting setup.py script for building the Python extensions
2#
Fredrik Lundhade711a2001-01-24 08:00:28 +00003
Andrew M. Kuchling66012fe2001-01-26 21:56:58 +00004__version__ = "$Revision$"
5
6import sys, os, getopt
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00007from distutils import sysconfig
Andrew M. Kuchling8d7f0862001-02-23 16:32:32 +00008from distutils import text_file
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +00009from distutils.errors import *
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000010from distutils.core import Extension, setup
11from distutils.command.build_ext import build_ext
Andrew M. Kuchlingf52d27e2001-05-21 20:29:27 +000012from distutils.command.install import install
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000013
14# This global variable is used to hold the list of modules to be disabled.
15disabled_module_list = []
16
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000017def find_file(filename, std_dirs, paths):
18 """Searches for the directory where a given file is located,
19 and returns a possibly-empty list of additional directories, or None
20 if the file couldn't be found at all.
Fredrik Lundhade711a2001-01-24 08:00:28 +000021
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000022 'filename' is the name of a file, such as readline.h or libcrypto.a.
23 'std_dirs' is the list of standard system directories; if the
24 file is found in one of them, no additional directives are needed.
25 'paths' is a list of additional locations to check; if the file is
26 found in one of them, the resulting list will contain the directory.
27 """
28
29 # Check the standard locations
30 for dir in std_dirs:
31 f = os.path.join(dir, filename)
32 if os.path.exists(f): return []
33
34 # Check the additional directories
35 for dir in paths:
36 f = os.path.join(dir, filename)
37 if os.path.exists(f):
38 return [dir]
39
40 # Not found anywhere
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000041 return None
42
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000043def find_library_file(compiler, libname, std_dirs, paths):
44 filename = compiler.library_filename(libname, lib_type='shared')
45 result = find_file(filename, std_dirs, paths)
46 if result is not None: return result
Fredrik Lundhade711a2001-01-24 08:00:28 +000047
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000048 filename = compiler.library_filename(libname, lib_type='static')
49 result = find_file(filename, std_dirs, paths)
50 return result
51
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000052def module_enabled(extlist, modname):
53 """Returns whether the module 'modname' is present in the list
54 of extensions 'extlist'."""
55 extlist = [ext for ext in extlist if ext.name == modname]
56 return len(extlist)
Fredrik Lundhade711a2001-01-24 08:00:28 +000057
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000058class PyBuildExt(build_ext):
Fredrik Lundhade711a2001-01-24 08:00:28 +000059
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000060 def build_extensions(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000061
62 # Detect which modules should be compiled
63 self.detect_modules()
64
65 # Remove modules that are present on the disabled list
66 self.extensions = [ext for ext in self.extensions
67 if ext.name not in disabled_module_list]
Fredrik Lundhade711a2001-01-24 08:00:28 +000068
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000069 # Fix up the autodetected modules, prefixing all the source files
70 # with Modules/ and adding Python's include directory to the path.
71 (srcdir,) = sysconfig.get_config_vars('srcdir')
72
Neil Schemenauer726b78e2001-01-24 17:18:21 +000073 # Figure out the location of the source code for extension modules
74 moddir = os.path.join(os.getcwd(), srcdir, 'Modules')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000075 moddir = os.path.normpath(moddir)
76 srcdir, tail = os.path.split(moddir)
77 srcdir = os.path.normpath(srcdir)
78 moddir = os.path.normpath(moddir)
79
Andrew M. Kuchling3da989c2001-02-28 22:49:26 +000080 # Fix up the paths for scripts, too
81 self.distribution.scripts = [os.path.join(srcdir, filename)
82 for filename in self.distribution.scripts]
83
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000084 for ext in self.extensions[:]:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000085 ext.sources = [ os.path.join(moddir, filename)
86 for filename in ext.sources ]
87 ext.include_dirs.append( '.' ) # to get config.h
Andrew M. Kuchlinge3d6e412001-01-19 02:50:34 +000088 ext.include_dirs.append( os.path.join(srcdir, './Include') )
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000089
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +000090 # If a module has already been built statically,
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000091 # don't build it here
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +000092 if ext.name in sys.builtin_module_names:
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000093 self.extensions.remove(ext)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +000094
Andrew M. Kuchling8d7f0862001-02-23 16:32:32 +000095 # Parse Modules/Setup to figure out which modules are turned
96 # on in the file.
97 input = text_file.TextFile('Modules/Setup', join_lines=1)
98 remove_modules = []
99 while 1:
100 line = input.readline()
101 if not line: break
102 line = line.split()
103 remove_modules.append( line[0] )
104 input.close()
105
106 for ext in self.extensions[:]:
107 if ext.name in remove_modules:
108 self.extensions.remove(ext)
109
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000110 # When you run "make CC=altcc" or something similar, you really want
111 # those environment variables passed into the setup.py phase. Here's
112 # a small set of useful ones.
113 compiler = os.environ.get('CC')
114 linker_so = os.environ.get('LDSHARED')
115 args = {}
116 # unfortunately, distutils doesn't let us provide separate C and C++
117 # compilers
118 if compiler is not None:
Andrew M. Kuchling9eb27a82001-07-14 20:28:10 +0000119 (ccshared,) = sysconfig.get_config_vars('CCSHARED')
120 args['compiler_so'] = compiler + ' ' + ccshared
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000121 if linker_so is not None:
122 args['linker_so'] = linker_so + ' -shared'
123 self.compiler.set_executables(**args)
124
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000125 build_ext.build_extensions(self)
126
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000127 def build_extension(self, ext):
128
129 try:
130 build_ext.build_extension(self, ext)
131 except (CCompilerError, DistutilsError), why:
132 self.announce('WARNING: building of extension "%s" failed: %s' %
133 (ext.name, sys.exc_info()[1]))
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000134 return
135 try:
136 __import__(ext.name)
137 except ImportError:
138 self.announce('WARNING: removing "%s" since importing it failed' %
139 ext.name)
140 assert not self.inplace
141 fullname = self.get_ext_fullname(ext.name)
142 ext_filename = os.path.join(self.build_lib,
143 self.get_ext_filename(fullname))
144 os.remove(ext_filename)
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000145
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000146 def get_platform (self):
Fredrik Lundhade711a2001-01-24 08:00:28 +0000147 # Get value of sys.platform
148 platform = sys.platform
149 if platform[:6] =='cygwin':
150 platform = 'cygwin'
Andrew M. Kuchling3c044942001-02-06 23:37:23 +0000151 elif platform[:4] =='beos':
152 platform = 'beos'
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000153
Fredrik Lundhade711a2001-01-24 08:00:28 +0000154 return platform
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000155
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000156 def detect_modules(self):
Fredrik Lundhade711a2001-01-24 08:00:28 +0000157 # Ensure that /usr/local is always used
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000158 if '/usr/local/lib' not in self.compiler.library_dirs:
Andrew M. Kuchling9b5abcd2001-03-17 16:56:35 +0000159 self.compiler.library_dirs.insert(0, '/usr/local/lib')
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000160 if '/usr/local/include' not in self.compiler.include_dirs:
Andrew M. Kuchling9b5abcd2001-03-17 16:56:35 +0000161 self.compiler.include_dirs.insert(0, '/usr/local/include' )
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000162
163 # lib_dirs and inc_dirs are used to search for files;
164 # if a file is found in one of those directories, it can
165 # be assumed that no additional -I,-L directives are needed.
166 lib_dirs = self.compiler.library_dirs + ['/lib', '/usr/lib']
Andrew M. Kuchling9b5abcd2001-03-17 16:56:35 +0000167 inc_dirs = self.compiler.include_dirs + ['/usr/include']
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000168 exts = []
169
Fredrik Lundhade711a2001-01-24 08:00:28 +0000170 platform = self.get_platform()
Andrew M. Kuchling9b5abcd2001-03-17 16:56:35 +0000171
Fredrik Lundhade711a2001-01-24 08:00:28 +0000172 # Check for MacOS X, which doesn't need libm.a at all
173 math_libs = ['m']
Andrew M. Kuchling3c044942001-02-06 23:37:23 +0000174 if platform in ['Darwin1.2', 'beos']:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000175 math_libs = []
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000176
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000177 # XXX Omitted modules: gl, pure, dl, SGI-specific modules
178
179 #
180 # The following modules are all pretty straightforward, and compile
181 # on pretty much any POSIXish platform.
182 #
Fredrik Lundhade711a2001-01-24 08:00:28 +0000183
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000184 # Some modules that are normally always on:
185 exts.append( Extension('regex', ['regexmodule.c', 'regexpr.c']) )
186 exts.append( Extension('pcre', ['pcremodule.c', 'pypcre.c']) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000187
Fred Drake2de74712001-02-01 05:26:54 +0000188 exts.append( Extension('_weakref', ['_weakref.c']) )
Jeremy Hylton5e7cb242001-02-02 18:24:26 +0000189 exts.append( Extension('_symtable', ['symtablemodule.c']) )
Andrew M. Kuchlingd5c43062001-01-17 15:59:25 +0000190 exts.append( Extension('xreadlines', ['xreadlinesmodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000191
192 # array objects
193 exts.append( Extension('array', ['arraymodule.c']) )
194 # complex math library functions
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000195 exts.append( Extension('cmath', ['cmathmodule.c'],
196 libraries=math_libs) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000197
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000198 # math library functions, e.g. sin()
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000199 exts.append( Extension('math', ['mathmodule.c'],
200 libraries=math_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000201 # fast string operations implemented in C
202 exts.append( Extension('strop', ['stropmodule.c']) )
203 # time operations and variables
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000204 exts.append( Extension('time', ['timemodule.c'],
205 libraries=math_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000206 # operator.add() and similar goodies
207 exts.append( Extension('operator', ['operator.c']) )
208 # access to the builtin codecs and codec registry
209 exts.append( Extension('_codecs', ['_codecsmodule.c']) )
Marc-André Lemburg261b8e22001-02-02 12:12:44 +0000210 # Python C API test module
Tim Petersd66595f2001-02-04 03:09:53 +0000211 exts.append( Extension('_testcapi', ['_testcapimodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000212 # static Unicode character database
Marc-André Lemburg14970be2001-01-22 10:38:27 +0000213 exts.append( Extension('unicodedata', ['unicodedata.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000214 # access to ISO C locale support
215 exts.append( Extension('_locale', ['_localemodule.c']) )
216
217 # Modules with some UNIX dependencies -- on by default:
218 # (If you have a really backward UNIX, select and socket may not be
219 # supported...)
220
221 # fcntl(2) and ioctl(2)
222 exts.append( Extension('fcntl', ['fcntlmodule.c']) )
223 # pwd(3)
224 exts.append( Extension('pwd', ['pwdmodule.c']) )
225 # grp(3)
226 exts.append( Extension('grp', ['grpmodule.c']) )
227 # posix (UNIX) errno values
228 exts.append( Extension('errno', ['errnomodule.c']) )
229 # select(2); not on ancient System V
230 exts.append( Extension('select', ['selectmodule.c']) )
231
232 # The md5 module implements the RSA Data Security, Inc. MD5
233 # Message-Digest Algorithm, described in RFC 1321. The necessary files
234 # md5c.c and md5.h are included here.
235 exts.append( Extension('md5', ['md5module.c', 'md5c.c']) )
236
237 # The sha module implements the SHA checksum algorithm.
238 # (NIST's Secure Hash Algorithm.)
239 exts.append( Extension('sha', ['shamodule.c']) )
240
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000241 # Tommy Burnette's 'new' module (creates new empty objects of certain
242 # kinds):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000243 exts.append( Extension('new', ['newmodule.c']) )
244
245 # Helper module for various ascii-encoders
246 exts.append( Extension('binascii', ['binascii.c']) )
247
248 # Fred Drake's interface to the Python parser
249 exts.append( Extension('parser', ['parsermodule.c']) )
250
251 # Digital Creations' cStringIO and cPickle
252 exts.append( Extension('cStringIO', ['cStringIO.c']) )
253 exts.append( Extension('cPickle', ['cPickle.c']) )
254
255 # Memory-mapped files (also works on Win32).
256 exts.append( Extension('mmap', ['mmapmodule.c']) )
257
258 # Lance Ellinghaus's modules:
259 # enigma-inspired encryption
260 exts.append( Extension('rotor', ['rotormodule.c']) )
261 # syslog daemon interface
262 exts.append( Extension('syslog', ['syslogmodule.c']) )
263
264 # George Neville-Neil's timing module:
265 exts.append( Extension('timing', ['timingmodule.c']) )
266
267 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000268 # Here ends the simple stuff. From here on, modules need certain
269 # libraries, are platform-specific, or present other surprises.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000270 #
271
272 # Multimedia modules
273 # These don't work for 64-bit platforms!!!
274 # These represent audio samples or images as strings:
275
Fredrik Lundhade711a2001-01-24 08:00:28 +0000276 # Disabled on 64-bit platforms
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000277 if sys.maxint != 9223372036854775807L:
278 # Operations on audio samples
279 exts.append( Extension('audioop', ['audioop.c']) )
280 # Operations on images
281 exts.append( Extension('imageop', ['imageop.c']) )
282 # Read SGI RGB image files (but coded portably)
283 exts.append( Extension('rgbimg', ['rgbimgmodule.c']) )
284
285 # readline
Marc-André Lemburg2efc3232001-01-26 18:23:02 +0000286 if self.compiler.find_library_file(lib_dirs, 'readline'):
287 readline_libs = ['readline']
288 if self.compiler.find_library_file(lib_dirs +
289 ['/usr/lib/termcap'],
290 'termcap'):
291 readline_libs.append('termcap')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000292 exts.append( Extension('readline', ['readline.c'],
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000293 library_dirs=['/usr/lib/termcap'],
Marc-André Lemburg2efc3232001-01-26 18:23:02 +0000294 libraries=readline_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000295
296 # The crypt module is now disabled by default because it breaks builds
297 # on many systems (where -lcrypt is needed), e.g. Linux (I believe).
298
299 if self.compiler.find_library_file(lib_dirs, 'crypt'):
300 libs = ['crypt']
301 else:
302 libs = []
303 exts.append( Extension('crypt', ['cryptmodule.c'], libraries=libs) )
304
305 # socket(2)
306 # Detect SSL support for the socket module
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000307 ssl_incs = find_file('openssl/ssl.h', inc_dirs,
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +0000308 ['/usr/local/ssl/include',
309 '/usr/contrib/ssl/include/'
310 ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000311 )
312 ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs,
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +0000313 ['/usr/local/ssl/lib',
314 '/usr/contrib/ssl/lib/'
315 ] )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000316
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000317 if (ssl_incs is not None and
318 ssl_libs is not None):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000319 exts.append( Extension('_socket', ['socketmodule.c'],
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000320 include_dirs = ssl_incs,
Fredrik Lundhade711a2001-01-24 08:00:28 +0000321 library_dirs = ssl_libs,
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000322 libraries = ['ssl', 'crypto'],
323 define_macros = [('USE_SSL',1)] ) )
324 else:
325 exts.append( Extension('_socket', ['socketmodule.c']) )
326
327 # Modules that provide persistent dictionary-like semantics. You will
328 # probably want to arrange for at least one of them to be available on
329 # your machine, though none are defined by default because of library
330 # dependencies. The Python module anydbm.py provides an
331 # implementation independent wrapper for these; dumbdbm.py provides
332 # similar functionality (but slower of course) implemented in Python.
333
334 # The standard Unix dbm module:
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000335 if platform not in ['cygwin']:
336 if (self.compiler.find_library_file(lib_dirs, 'ndbm')):
337 exts.append( Extension('dbm', ['dbmmodule.c'],
338 libraries = ['ndbm'] ) )
339 else:
340 exts.append( Extension('dbm', ['dbmmodule.c']) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000341
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000342 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
343 if (self.compiler.find_library_file(lib_dirs, 'gdbm')):
344 exts.append( Extension('gdbm', ['gdbmmodule.c'],
345 libraries = ['gdbm'] ) )
346
347 # Berkeley DB interface.
348 #
349 # This requires the Berkeley DB code, see
350 # ftp://ftp.cs.berkeley.edu/pub/4bsd/db.1.85.tar.gz
351 #
352 # Edit the variables DB and DBPORT to point to the db top directory
353 # and the subdirectory of PORT where you built it.
354 #
355 # (See http://electricrain.com/greg/python/bsddb3/ for an interface to
356 # BSD DB 3.x.)
357
Andrew M. Kuchlinge06337a2001-02-23 16:27:48 +0000358 dblib = []
359 if self.compiler.find_library_file(lib_dirs, 'db'):
360 dblib = ['db']
361
362 db185_incs = find_file('db_185.h', inc_dirs,
363 ['/usr/include/db3', '/usr/include/db2'])
364 db_inc = find_file('db.h', inc_dirs, ['/usr/include/db1'])
365 if db185_incs is not None:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000366 exts.append( Extension('bsddb', ['bsddbmodule.c'],
Andrew M. Kuchlinge06337a2001-02-23 16:27:48 +0000367 include_dirs = db185_incs,
368 define_macros=[('HAVE_DB_185_H',1)],
369 libraries = dblib ) )
370 elif db_inc is not None:
371 exts.append( Extension('bsddb', ['bsddbmodule.c'],
372 include_dirs = db_inc,
373 libraries = dblib) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000374
375 # The mpz module interfaces to the GNU Multiple Precision library.
Fredrik Lundhade711a2001-01-24 08:00:28 +0000376 # You need to ftp the GNU MP library.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000377 # This was originally written and tested against GMP 1.2 and 1.3.2.
378 # It has been modified by Rob Hooft to work with 2.0.2 as well, but I
379 # haven't tested it recently. For a more complete module,
380 # refer to pympz.sourceforge.net.
381
382 # A compatible MP library unencombered by the GPL also exists. It was
383 # posted to comp.sources.misc in volume 40 and is widely available from
384 # FTP archive sites. One URL for it is:
385 # ftp://gatekeeper.dec.com/.b/usenet/comp.sources.misc/volume40/fgmp/part01.Z
386
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000387 if (self.compiler.find_library_file(lib_dirs, 'gmp')):
388 exts.append( Extension('mpz', ['mpzmodule.c'],
389 libraries = ['gmp'] ) )
390
391
392 # Unix-only modules
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000393 if platform not in ['mac', 'win32']:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000394 # Steen Lumholt's termios module
395 exts.append( Extension('termios', ['termios.c']) )
396 # Jeremy Hylton's rlimit interface
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000397 if platform not in ['cygwin']:
398 exts.append( Extension('resource', ['resource.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000399
Andrew M. Kuchlingcf393f32001-02-21 02:38:24 +0000400 # Sun yellow pages. Some systems have the functions in libc.
Andrew M. Kuchling6efc6e72001-02-27 20:54:23 +0000401 if platform not in ['cygwin']:
402 if (self.compiler.find_library_file(lib_dirs, 'nsl')):
403 libs = ['nsl']
404 else:
405 libs = []
406 exts.append( Extension('nis', ['nismodule.c'],
407 libraries = libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000408
409 # Curses support, requring the System V version of curses, often
Fredrik Lundhade711a2001-01-24 08:00:28 +0000410 # provided by the ncurses library.
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000411 if platform == 'sunos4':
Andrew M. Kuchlingb69c7582001-02-28 19:49:57 +0000412 inc_dirs += ['/usr/5include']
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000413 lib_dirs += ['/usr/5lib']
414
415 if (self.compiler.find_library_file(lib_dirs, 'ncurses')):
416 curses_libs = ['ncurses']
417 exts.append( Extension('_curses', ['_cursesmodule.c'],
418 libraries = curses_libs) )
419 elif (self.compiler.find_library_file(lib_dirs, 'curses')):
420 if (self.compiler.find_library_file(lib_dirs, 'terminfo')):
421 curses_libs = ['curses', 'terminfo']
422 else:
423 curses_libs = ['curses', 'termcap']
Fredrik Lundhade711a2001-01-24 08:00:28 +0000424
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000425 exts.append( Extension('_curses', ['_cursesmodule.c'],
426 libraries = curses_libs) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000427
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000428 # If the curses module is enabled, check for the panel module
429 if (os.path.exists('Modules/_curses_panel.c') and
430 module_enabled(exts, '_curses') and
431 self.compiler.find_library_file(lib_dirs, 'panel')):
432 exts.append( Extension('_curses_panel', ['_curses_panel.c'],
433 libraries = ['panel'] + curses_libs) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000434
435
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000436
437 # Lee Busby's SIGFPE modules.
438 # The library to link fpectl with is platform specific.
439 # Choose *one* of the options below for fpectl:
440
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000441 if platform == 'irix5':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000442 # For SGI IRIX (tested on 5.3):
443 exts.append( Extension('fpectl', ['fpectlmodule.c'],
444 libraries=['fpe']) )
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000445 elif 0: # XXX how to detect SunPro?
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000446 # For Solaris with SunPro compiler (tested on Solaris 2.5 with SunPro C 4.2):
447 # (Without the compiler you don't have -lsunmath.)
448 #fpectl fpectlmodule.c -R/opt/SUNWspro/lib -lsunmath -lm
449 pass
450 else:
451 # For other systems: see instructions in fpectlmodule.c.
452 #fpectl fpectlmodule.c ...
453 exts.append( Extension('fpectl', ['fpectlmodule.c']) )
454
455
456 # Andrew Kuchling's zlib module.
457 # This require zlib 1.1.3 (or later).
458 # See http://www.cdrom.com/pub/infozip/zlib/
Guido van Rossume6970912001-04-15 15:16:12 +0000459 zlib_inc = find_file('zlib.h', [], inc_dirs)
460 if zlib_inc is not None:
461 zlib_h = zlib_inc[0] + '/zlib.h'
462 version = '"0.0.0"'
463 version_req = '"1.1.3"'
464 fp = open(zlib_h)
465 while 1:
466 line = fp.readline()
467 if not line:
468 break
469 if line.find('#define ZLIB_VERSION', 0) == 0:
470 version = line.split()[2]
471 break
472 if version >= version_req:
473 if (self.compiler.find_library_file(lib_dirs, 'z')):
474 exts.append( Extension('zlib', ['zlibmodule.c'],
475 libraries = ['z']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000476
477 # Interface to the Expat XML parser
478 #
479 # Expat is written by James Clark and must be downloaded separately
480 # (see below). The pyexpat module was written by Paul Prescod after a
481 # prototype by Jack Jansen.
482 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000483 # The Expat dist includes Windows .lib and .dll files. Home page is
484 # at http://www.jclark.com/xml/expat.html, the current production
485 # release is always ftp://ftp.jclark.com/pub/xml/expat.zip.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000486 #
487 # EXPAT_DIR, below, should point to the expat/ directory created by
488 # unpacking the Expat source distribution.
489 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000490 # Note: the expat build process doesn't yet build a libexpat.a; you
491 # can do this manually while we try convince the author to add it. To
492 # do so, cd to EXPAT_DIR, run "make" if you have not done so, then
493 # run:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000494 #
495 # ar cr libexpat.a xmltok/*.o xmlparse/*.o
496 #
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000497 expat_defs = []
498 expat_incs = find_file('expat.h', inc_dirs, [])
499 if expat_incs is not None:
500 # expat.h was found
501 expat_defs = [('HAVE_EXPAT_H', 1)]
502 else:
503 expat_incs = find_file('xmlparse.h', inc_dirs, [])
Fredrik Lundhade711a2001-01-24 08:00:28 +0000504
Martin v. Löwis1ab29b22001-01-21 10:54:52 +0000505 if (expat_incs is not None and
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000506 self.compiler.find_library_file(lib_dirs, 'expat')):
507 exts.append( Extension('pyexpat', ['pyexpat.c'],
508 define_macros = expat_defs,
509 libraries = ['expat']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000510
511 # Platform-specific libraries
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000512 if platform == 'linux2':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000513 # Linux-specific modules
514 exts.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) )
515
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000516 if platform == 'sunos5':
Fredrik Lundhade711a2001-01-24 08:00:28 +0000517 # SunOS specific modules
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000518 exts.append( Extension('sunaudiodev', ['sunaudiodev.c']) )
519
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000520 self.extensions.extend(exts)
521
522 # Call the method for detecting whether _tkinter can be compiled
523 self.detect_tkinter(inc_dirs, lib_dirs)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000524
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000525
526 def detect_tkinter(self, inc_dirs, lib_dirs):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000527 # The _tkinter module.
Martin v. Löwisb1d19692001-03-21 07:44:53 +0000528
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000529 # Assume we haven't found any of the libraries or include files
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +0000530 # The versions with dots are used on Unix, and the versions without
531 # dots on Windows, for detection by cygwin.
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000532 tcllib = tklib = tcl_includes = tk_includes = None
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +0000533 for version in ['8.4', '84', '8.3', '83', '8.2',
534 '82', '8.1', '81', '8.0', '80']:
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000535 tklib = self.compiler.find_library_file(lib_dirs,
536 'tk' + version )
537 tcllib = self.compiler.find_library_file(lib_dirs,
538 'tcl' + version )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000539 if tklib and tcllib:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000540 # Exit the loop when we've found the Tcl/Tk libraries
541 break
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000542
Fredrik Lundhade711a2001-01-24 08:00:28 +0000543 # Now check for the header files
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000544 if tklib and tcllib:
545 # Check for the include files on Debian, where
546 # they're put in /usr/include/{tcl,tk}X.Y
Andrew M. Kuchling9a3fd8c2001-02-06 22:15:27 +0000547 debian_tcl_include = [ '/usr/include/tcl' + version ]
548 debian_tk_include = [ '/usr/include/tk' + version ] + debian_tcl_include
549 tcl_includes = find_file('tcl.h', inc_dirs, debian_tcl_include)
550 tk_includes = find_file('tk.h', inc_dirs, debian_tk_include)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000551
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000552 if (tcllib is None or tklib is None and
553 tcl_includes is None or tk_includes is None):
554 # Something's missing, so give up
555 return
Fredrik Lundhade711a2001-01-24 08:00:28 +0000556
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000557 # OK... everything seems to be present for Tcl/Tk.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000558
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000559 include_dirs = [] ; libs = [] ; defs = [] ; added_lib_dirs = []
560 for dir in tcl_includes + tk_includes:
561 if dir not in include_dirs:
562 include_dirs.append(dir)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000563
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000564 # Check for various platform-specific directories
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000565 platform = self.get_platform()
566 if platform == 'sunos5':
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000567 include_dirs.append('/usr/openwin/include')
568 added_lib_dirs.append('/usr/openwin/lib')
569 elif os.path.exists('/usr/X11R6/include'):
570 include_dirs.append('/usr/X11R6/include')
571 added_lib_dirs.append('/usr/X11R6/lib')
572 elif os.path.exists('/usr/X11R5/include'):
573 include_dirs.append('/usr/X11R5/include')
574 added_lib_dirs.append('/usr/X11R5/lib')
575 else:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000576 # Assume default location for X11
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000577 include_dirs.append('/usr/X11/include')
578 added_lib_dirs.append('/usr/X11/lib')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000579
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000580 # Check for BLT extension
581 if self.compiler.find_library_file(lib_dirs + added_lib_dirs, 'BLT8.0'):
582 defs.append( ('WITH_BLT', 1) )
583 libs.append('BLT8.0')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000584
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000585 # Add the Tcl/Tk libraries
Fredrik Lundhade711a2001-01-24 08:00:28 +0000586 libs.append('tk'+version)
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000587 libs.append('tcl'+version)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000588
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000589 if platform in ['aix3', 'aix4']:
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000590 libs.append('ld')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000591
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +0000592 # Finally, link with the X11 libraries (not appropriate on cygwin)
593 if platform != "cygwin":
594 libs.append('X11')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000595
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000596 ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
597 define_macros=[('WITH_APPINIT', 1)] + defs,
598 include_dirs = include_dirs,
599 libraries = libs,
600 library_dirs = added_lib_dirs,
601 )
602 self.extensions.append(ext)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000603
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000604 # XXX handle these, but how to detect?
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000605 # *** Uncomment and edit for PIL (TkImaging) extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000606 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000607 # *** Uncomment and edit for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000608 # -DWITH_TOGL togl.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000609 # *** Uncomment these for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000610 # -lGL -lGLU -lXext -lXmu \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000611
Andrew M. Kuchlingf52d27e2001-05-21 20:29:27 +0000612class PyBuildInstall(install):
613 # Suppress the warning about installation into the lib_dynload
614 # directory, which is not in sys.path when running Python during
615 # installation:
616 def initialize_options (self):
617 install.initialize_options(self)
618 self.warn_dir=0
619
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000620def main():
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000621 # turn off warnings when deprecated modules are imported
622 import warnings
623 warnings.filterwarnings("ignore",category=DeprecationWarning)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000624 setup(name = 'Python standard library',
Neil Schemenauere7e2ece2001-01-17 21:58:00 +0000625 version = '%d.%d' % sys.version_info[:2],
Andrew M. Kuchlingf52d27e2001-05-21 20:29:27 +0000626 cmdclass = {'build_ext':PyBuildExt, 'install':PyBuildInstall},
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000627 # The struct module is defined here, because build_ext won't be
628 # called unless there's at least one extension module defined.
Andrew M. Kuchlingaece4272001-02-28 20:56:49 +0000629 ext_modules=[Extension('struct', ['structmodule.c'])],
630
631 # Scripts to install
632 scripts = ['Tools/scripts/pydoc']
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000633 )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000634
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000635# --install-platlib
636if __name__ == '__main__':
637 sysconfig.set_python_build()
638 main()