blob: 7a649c63d95fb6081fa73c627d90f238acc3c8d7 [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
Jack Jansen144ebcc2001-08-05 22:31:19 +000058def find_module_file(module, dirlist):
59 """Find a module in a set of possible folders. If it is not found
60 return the unadorned filename"""
61 list = find_file(module, [], dirlist)
62 if not list:
63 return module
64 if len(list) > 1:
65 self.announce("WARNING: multiple copies of %s found"%module)
66 return os.path.join(list[0], module)
67
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000068class PyBuildExt(build_ext):
Fredrik Lundhade711a2001-01-24 08:00:28 +000069
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000070 def build_extensions(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000071
72 # Detect which modules should be compiled
73 self.detect_modules()
74
75 # Remove modules that are present on the disabled list
76 self.extensions = [ext for ext in self.extensions
77 if ext.name not in disabled_module_list]
Fredrik Lundhade711a2001-01-24 08:00:28 +000078
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000079 # Fix up the autodetected modules, prefixing all the source files
80 # with Modules/ and adding Python's include directory to the path.
81 (srcdir,) = sysconfig.get_config_vars('srcdir')
82
Neil Schemenauer726b78e2001-01-24 17:18:21 +000083 # Figure out the location of the source code for extension modules
84 moddir = os.path.join(os.getcwd(), srcdir, 'Modules')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000085 moddir = os.path.normpath(moddir)
86 srcdir, tail = os.path.split(moddir)
87 srcdir = os.path.normpath(srcdir)
88 moddir = os.path.normpath(moddir)
Jack Jansen144ebcc2001-08-05 22:31:19 +000089
90 moddirlist = [moddir]
91 incdirlist = ['./Include']
92
93 # Platform-dependent module source and include directories
94 platform = self.get_platform()
95 if platform == 'darwin1':
96 # Mac OS X also includes some mac-specific modules
97 macmoddir = os.path.join(os.getcwd(), srcdir, 'Mac/Modules')
98 moddirlist.append(macmoddir)
99 incdirlist.append('./Mac/Include')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000100
Andrew M. Kuchling3da989c2001-02-28 22:49:26 +0000101 # Fix up the paths for scripts, too
102 self.distribution.scripts = [os.path.join(srcdir, filename)
103 for filename in self.distribution.scripts]
104
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000105 for ext in self.extensions[:]:
Jack Jansen144ebcc2001-08-05 22:31:19 +0000106 ext.sources = [ find_module_file(filename, moddirlist)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000107 for filename in ext.sources ]
Jack Jansen144ebcc2001-08-05 22:31:19 +0000108 ext.include_dirs.append( '.' ) # to get config.h
109 for incdir in incdirlist:
110 ext.include_dirs.append( os.path.join(srcdir, incdir) )
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000111
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +0000112 # If a module has already been built statically,
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000113 # don't build it here
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +0000114 if ext.name in sys.builtin_module_names:
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000115 self.extensions.remove(ext)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000116
Andrew M. Kuchling8d7f0862001-02-23 16:32:32 +0000117 # Parse Modules/Setup to figure out which modules are turned
118 # on in the file.
119 input = text_file.TextFile('Modules/Setup', join_lines=1)
120 remove_modules = []
121 while 1:
122 line = input.readline()
123 if not line: break
124 line = line.split()
125 remove_modules.append( line[0] )
126 input.close()
127
128 for ext in self.extensions[:]:
129 if ext.name in remove_modules:
130 self.extensions.remove(ext)
131
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000132 # When you run "make CC=altcc" or something similar, you really want
133 # those environment variables passed into the setup.py phase. Here's
134 # a small set of useful ones.
135 compiler = os.environ.get('CC')
136 linker_so = os.environ.get('LDSHARED')
137 args = {}
138 # unfortunately, distutils doesn't let us provide separate C and C++
139 # compilers
140 if compiler is not None:
Andrew M. Kuchling9eb27a82001-07-14 20:28:10 +0000141 (ccshared,) = sysconfig.get_config_vars('CCSHARED')
142 args['compiler_so'] = compiler + ' ' + ccshared
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000143 if linker_so is not None:
144 args['linker_so'] = linker_so + ' -shared'
145 self.compiler.set_executables(**args)
146
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000147 build_ext.build_extensions(self)
148
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000149 def build_extension(self, ext):
150
151 try:
152 build_ext.build_extension(self, ext)
153 except (CCompilerError, DistutilsError), why:
154 self.announce('WARNING: building of extension "%s" failed: %s' %
155 (ext.name, sys.exc_info()[1]))
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000156 return
157 try:
158 __import__(ext.name)
159 except ImportError:
160 self.announce('WARNING: removing "%s" since importing it failed' %
161 ext.name)
162 assert not self.inplace
163 fullname = self.get_ext_fullname(ext.name)
164 ext_filename = os.path.join(self.build_lib,
165 self.get_ext_filename(fullname))
166 os.remove(ext_filename)
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000167
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000168 def get_platform (self):
Fredrik Lundhade711a2001-01-24 08:00:28 +0000169 # Get value of sys.platform
170 platform = sys.platform
171 if platform[:6] =='cygwin':
172 platform = 'cygwin'
Andrew M. Kuchling3c044942001-02-06 23:37:23 +0000173 elif platform[:4] =='beos':
174 platform = 'beos'
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000175
Fredrik Lundhade711a2001-01-24 08:00:28 +0000176 return platform
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000177
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000178 def detect_modules(self):
Fredrik Lundhade711a2001-01-24 08:00:28 +0000179 # Ensure that /usr/local is always used
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000180 if '/usr/local/lib' not in self.compiler.library_dirs:
Andrew M. Kuchling9b5abcd2001-03-17 16:56:35 +0000181 self.compiler.library_dirs.insert(0, '/usr/local/lib')
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000182 if '/usr/local/include' not in self.compiler.include_dirs:
Andrew M. Kuchling9b5abcd2001-03-17 16:56:35 +0000183 self.compiler.include_dirs.insert(0, '/usr/local/include' )
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000184
185 # lib_dirs and inc_dirs are used to search for files;
186 # if a file is found in one of those directories, it can
187 # be assumed that no additional -I,-L directives are needed.
188 lib_dirs = self.compiler.library_dirs + ['/lib', '/usr/lib']
Andrew M. Kuchling9b5abcd2001-03-17 16:56:35 +0000189 inc_dirs = self.compiler.include_dirs + ['/usr/include']
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000190 exts = []
191
Fredrik Lundhade711a2001-01-24 08:00:28 +0000192 platform = self.get_platform()
Andrew M. Kuchling9b5abcd2001-03-17 16:56:35 +0000193
Fredrik Lundhade711a2001-01-24 08:00:28 +0000194 # Check for MacOS X, which doesn't need libm.a at all
195 math_libs = ['m']
Andrew M. Kuchling3c044942001-02-06 23:37:23 +0000196 if platform in ['Darwin1.2', 'beos']:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000197 math_libs = []
Jack Jansen144ebcc2001-08-05 22:31:19 +0000198
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000199 # XXX Omitted modules: gl, pure, dl, SGI-specific modules
200
201 #
202 # The following modules are all pretty straightforward, and compile
203 # on pretty much any POSIXish platform.
204 #
Fredrik Lundhade711a2001-01-24 08:00:28 +0000205
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000206 # Some modules that are normally always on:
207 exts.append( Extension('regex', ['regexmodule.c', 'regexpr.c']) )
208 exts.append( Extension('pcre', ['pcremodule.c', 'pypcre.c']) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000209
Fred Drake2de74712001-02-01 05:26:54 +0000210 exts.append( Extension('_weakref', ['_weakref.c']) )
Jeremy Hylton5e7cb242001-02-02 18:24:26 +0000211 exts.append( Extension('_symtable', ['symtablemodule.c']) )
Andrew M. Kuchlingd5c43062001-01-17 15:59:25 +0000212 exts.append( Extension('xreadlines', ['xreadlinesmodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000213
214 # array objects
215 exts.append( Extension('array', ['arraymodule.c']) )
216 # complex math library functions
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000217 exts.append( Extension('cmath', ['cmathmodule.c'],
218 libraries=math_libs) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000219
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000220 # math library functions, e.g. sin()
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000221 exts.append( Extension('math', ['mathmodule.c'],
222 libraries=math_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000223 # fast string operations implemented in C
224 exts.append( Extension('strop', ['stropmodule.c']) )
225 # time operations and variables
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000226 exts.append( Extension('time', ['timemodule.c'],
227 libraries=math_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000228 # operator.add() and similar goodies
229 exts.append( Extension('operator', ['operator.c']) )
230 # access to the builtin codecs and codec registry
231 exts.append( Extension('_codecs', ['_codecsmodule.c']) )
Marc-André Lemburg261b8e22001-02-02 12:12:44 +0000232 # Python C API test module
Tim Petersd66595f2001-02-04 03:09:53 +0000233 exts.append( Extension('_testcapi', ['_testcapimodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000234 # static Unicode character database
Marc-André Lemburg14970be2001-01-22 10:38:27 +0000235 exts.append( Extension('unicodedata', ['unicodedata.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000236 # access to ISO C locale support
237 exts.append( Extension('_locale', ['_localemodule.c']) )
238
239 # Modules with some UNIX dependencies -- on by default:
240 # (If you have a really backward UNIX, select and socket may not be
241 # supported...)
242
243 # fcntl(2) and ioctl(2)
244 exts.append( Extension('fcntl', ['fcntlmodule.c']) )
245 # pwd(3)
246 exts.append( Extension('pwd', ['pwdmodule.c']) )
247 # grp(3)
248 exts.append( Extension('grp', ['grpmodule.c']) )
249 # posix (UNIX) errno values
250 exts.append( Extension('errno', ['errnomodule.c']) )
251 # select(2); not on ancient System V
252 exts.append( Extension('select', ['selectmodule.c']) )
253
254 # The md5 module implements the RSA Data Security, Inc. MD5
255 # Message-Digest Algorithm, described in RFC 1321. The necessary files
256 # md5c.c and md5.h are included here.
257 exts.append( Extension('md5', ['md5module.c', 'md5c.c']) )
258
259 # The sha module implements the SHA checksum algorithm.
260 # (NIST's Secure Hash Algorithm.)
261 exts.append( Extension('sha', ['shamodule.c']) )
262
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000263 # Tommy Burnette's 'new' module (creates new empty objects of certain
264 # kinds):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000265 exts.append( Extension('new', ['newmodule.c']) )
266
267 # Helper module for various ascii-encoders
268 exts.append( Extension('binascii', ['binascii.c']) )
269
270 # Fred Drake's interface to the Python parser
271 exts.append( Extension('parser', ['parsermodule.c']) )
272
273 # Digital Creations' cStringIO and cPickle
274 exts.append( Extension('cStringIO', ['cStringIO.c']) )
275 exts.append( Extension('cPickle', ['cPickle.c']) )
276
277 # Memory-mapped files (also works on Win32).
278 exts.append( Extension('mmap', ['mmapmodule.c']) )
279
280 # Lance Ellinghaus's modules:
281 # enigma-inspired encryption
282 exts.append( Extension('rotor', ['rotormodule.c']) )
283 # syslog daemon interface
284 exts.append( Extension('syslog', ['syslogmodule.c']) )
285
286 # George Neville-Neil's timing module:
287 exts.append( Extension('timing', ['timingmodule.c']) )
288
289 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000290 # Here ends the simple stuff. From here on, modules need certain
291 # libraries, are platform-specific, or present other surprises.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000292 #
293
294 # Multimedia modules
295 # These don't work for 64-bit platforms!!!
296 # These represent audio samples or images as strings:
297
Fredrik Lundhade711a2001-01-24 08:00:28 +0000298 # Disabled on 64-bit platforms
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000299 if sys.maxint != 9223372036854775807L:
300 # Operations on audio samples
301 exts.append( Extension('audioop', ['audioop.c']) )
302 # Operations on images
303 exts.append( Extension('imageop', ['imageop.c']) )
304 # Read SGI RGB image files (but coded portably)
305 exts.append( Extension('rgbimg', ['rgbimgmodule.c']) )
306
307 # readline
Marc-André Lemburg2efc3232001-01-26 18:23:02 +0000308 if self.compiler.find_library_file(lib_dirs, 'readline'):
309 readline_libs = ['readline']
310 if self.compiler.find_library_file(lib_dirs +
311 ['/usr/lib/termcap'],
312 'termcap'):
313 readline_libs.append('termcap')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000314 exts.append( Extension('readline', ['readline.c'],
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000315 library_dirs=['/usr/lib/termcap'],
Marc-André Lemburg2efc3232001-01-26 18:23:02 +0000316 libraries=readline_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000317
318 # The crypt module is now disabled by default because it breaks builds
319 # on many systems (where -lcrypt is needed), e.g. Linux (I believe).
320
321 if self.compiler.find_library_file(lib_dirs, 'crypt'):
322 libs = ['crypt']
323 else:
324 libs = []
325 exts.append( Extension('crypt', ['cryptmodule.c'], libraries=libs) )
326
327 # socket(2)
328 # Detect SSL support for the socket module
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000329 ssl_incs = find_file('openssl/ssl.h', inc_dirs,
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +0000330 ['/usr/local/ssl/include',
331 '/usr/contrib/ssl/include/'
332 ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000333 )
334 ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs,
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +0000335 ['/usr/local/ssl/lib',
336 '/usr/contrib/ssl/lib/'
337 ] )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000338
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000339 if (ssl_incs is not None and
340 ssl_libs is not None):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000341 exts.append( Extension('_socket', ['socketmodule.c'],
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000342 include_dirs = ssl_incs,
Fredrik Lundhade711a2001-01-24 08:00:28 +0000343 library_dirs = ssl_libs,
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000344 libraries = ['ssl', 'crypto'],
345 define_macros = [('USE_SSL',1)] ) )
346 else:
347 exts.append( Extension('_socket', ['socketmodule.c']) )
348
349 # Modules that provide persistent dictionary-like semantics. You will
350 # probably want to arrange for at least one of them to be available on
351 # your machine, though none are defined by default because of library
352 # dependencies. The Python module anydbm.py provides an
353 # implementation independent wrapper for these; dumbdbm.py provides
354 # similar functionality (but slower of course) implemented in Python.
355
356 # The standard Unix dbm module:
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000357 if platform not in ['cygwin']:
358 if (self.compiler.find_library_file(lib_dirs, 'ndbm')):
359 exts.append( Extension('dbm', ['dbmmodule.c'],
360 libraries = ['ndbm'] ) )
361 else:
362 exts.append( Extension('dbm', ['dbmmodule.c']) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000363
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000364 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
365 if (self.compiler.find_library_file(lib_dirs, 'gdbm')):
366 exts.append( Extension('gdbm', ['gdbmmodule.c'],
367 libraries = ['gdbm'] ) )
368
369 # Berkeley DB interface.
370 #
371 # This requires the Berkeley DB code, see
372 # ftp://ftp.cs.berkeley.edu/pub/4bsd/db.1.85.tar.gz
373 #
374 # Edit the variables DB and DBPORT to point to the db top directory
375 # and the subdirectory of PORT where you built it.
376 #
377 # (See http://electricrain.com/greg/python/bsddb3/ for an interface to
378 # BSD DB 3.x.)
379
Andrew M. Kuchlinge06337a2001-02-23 16:27:48 +0000380 dblib = []
381 if self.compiler.find_library_file(lib_dirs, 'db'):
382 dblib = ['db']
383
384 db185_incs = find_file('db_185.h', inc_dirs,
385 ['/usr/include/db3', '/usr/include/db2'])
386 db_inc = find_file('db.h', inc_dirs, ['/usr/include/db1'])
387 if db185_incs is not None:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000388 exts.append( Extension('bsddb', ['bsddbmodule.c'],
Andrew M. Kuchlinge06337a2001-02-23 16:27:48 +0000389 include_dirs = db185_incs,
390 define_macros=[('HAVE_DB_185_H',1)],
391 libraries = dblib ) )
392 elif db_inc is not None:
393 exts.append( Extension('bsddb', ['bsddbmodule.c'],
394 include_dirs = db_inc,
395 libraries = dblib) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000396
397 # The mpz module interfaces to the GNU Multiple Precision library.
Fredrik Lundhade711a2001-01-24 08:00:28 +0000398 # You need to ftp the GNU MP library.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000399 # This was originally written and tested against GMP 1.2 and 1.3.2.
400 # It has been modified by Rob Hooft to work with 2.0.2 as well, but I
401 # haven't tested it recently. For a more complete module,
402 # refer to pympz.sourceforge.net.
403
404 # A compatible MP library unencombered by the GPL also exists. It was
405 # posted to comp.sources.misc in volume 40 and is widely available from
406 # FTP archive sites. One URL for it is:
407 # ftp://gatekeeper.dec.com/.b/usenet/comp.sources.misc/volume40/fgmp/part01.Z
408
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000409 if (self.compiler.find_library_file(lib_dirs, 'gmp')):
410 exts.append( Extension('mpz', ['mpzmodule.c'],
411 libraries = ['gmp'] ) )
412
413
414 # Unix-only modules
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000415 if platform not in ['mac', 'win32']:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000416 # Steen Lumholt's termios module
417 exts.append( Extension('termios', ['termios.c']) )
418 # Jeremy Hylton's rlimit interface
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000419 if platform not in ['cygwin']:
420 exts.append( Extension('resource', ['resource.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000421
Andrew M. Kuchlingcf393f32001-02-21 02:38:24 +0000422 # Sun yellow pages. Some systems have the functions in libc.
Andrew M. Kuchling6efc6e72001-02-27 20:54:23 +0000423 if platform not in ['cygwin']:
424 if (self.compiler.find_library_file(lib_dirs, 'nsl')):
425 libs = ['nsl']
426 else:
427 libs = []
428 exts.append( Extension('nis', ['nismodule.c'],
429 libraries = libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000430
431 # Curses support, requring the System V version of curses, often
Fredrik Lundhade711a2001-01-24 08:00:28 +0000432 # provided by the ncurses library.
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000433 if platform == 'sunos4':
Andrew M. Kuchlingb69c7582001-02-28 19:49:57 +0000434 inc_dirs += ['/usr/5include']
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000435 lib_dirs += ['/usr/5lib']
436
437 if (self.compiler.find_library_file(lib_dirs, 'ncurses')):
438 curses_libs = ['ncurses']
439 exts.append( Extension('_curses', ['_cursesmodule.c'],
440 libraries = curses_libs) )
441 elif (self.compiler.find_library_file(lib_dirs, 'curses')):
442 if (self.compiler.find_library_file(lib_dirs, 'terminfo')):
443 curses_libs = ['curses', 'terminfo']
444 else:
445 curses_libs = ['curses', 'termcap']
Fredrik Lundhade711a2001-01-24 08:00:28 +0000446
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000447 exts.append( Extension('_curses', ['_cursesmodule.c'],
448 libraries = curses_libs) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000449
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000450 # If the curses module is enabled, check for the panel module
451 if (os.path.exists('Modules/_curses_panel.c') and
452 module_enabled(exts, '_curses') and
453 self.compiler.find_library_file(lib_dirs, 'panel')):
454 exts.append( Extension('_curses_panel', ['_curses_panel.c'],
455 libraries = ['panel'] + curses_libs) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000456
457
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000458
459 # Lee Busby's SIGFPE modules.
460 # The library to link fpectl with is platform specific.
461 # Choose *one* of the options below for fpectl:
462
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000463 if platform == 'irix5':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000464 # For SGI IRIX (tested on 5.3):
465 exts.append( Extension('fpectl', ['fpectlmodule.c'],
466 libraries=['fpe']) )
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000467 elif 0: # XXX how to detect SunPro?
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000468 # For Solaris with SunPro compiler (tested on Solaris 2.5 with SunPro C 4.2):
469 # (Without the compiler you don't have -lsunmath.)
470 #fpectl fpectlmodule.c -R/opt/SUNWspro/lib -lsunmath -lm
471 pass
472 else:
473 # For other systems: see instructions in fpectlmodule.c.
474 #fpectl fpectlmodule.c ...
475 exts.append( Extension('fpectl', ['fpectlmodule.c']) )
476
477
478 # Andrew Kuchling's zlib module.
479 # This require zlib 1.1.3 (or later).
480 # See http://www.cdrom.com/pub/infozip/zlib/
Guido van Rossume6970912001-04-15 15:16:12 +0000481 zlib_inc = find_file('zlib.h', [], inc_dirs)
482 if zlib_inc is not None:
483 zlib_h = zlib_inc[0] + '/zlib.h'
484 version = '"0.0.0"'
485 version_req = '"1.1.3"'
486 fp = open(zlib_h)
487 while 1:
488 line = fp.readline()
489 if not line:
490 break
491 if line.find('#define ZLIB_VERSION', 0) == 0:
492 version = line.split()[2]
493 break
494 if version >= version_req:
495 if (self.compiler.find_library_file(lib_dirs, 'z')):
496 exts.append( Extension('zlib', ['zlibmodule.c'],
497 libraries = ['z']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000498
499 # Interface to the Expat XML parser
500 #
501 # Expat is written by James Clark and must be downloaded separately
502 # (see below). The pyexpat module was written by Paul Prescod after a
503 # prototype by Jack Jansen.
504 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000505 # The Expat dist includes Windows .lib and .dll files. Home page is
506 # at http://www.jclark.com/xml/expat.html, the current production
507 # release is always ftp://ftp.jclark.com/pub/xml/expat.zip.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000508 #
509 # EXPAT_DIR, below, should point to the expat/ directory created by
510 # unpacking the Expat source distribution.
511 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000512 # Note: the expat build process doesn't yet build a libexpat.a; you
513 # can do this manually while we try convince the author to add it. To
514 # do so, cd to EXPAT_DIR, run "make" if you have not done so, then
515 # run:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000516 #
517 # ar cr libexpat.a xmltok/*.o xmlparse/*.o
518 #
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000519 expat_defs = []
520 expat_incs = find_file('expat.h', inc_dirs, [])
521 if expat_incs is not None:
522 # expat.h was found
523 expat_defs = [('HAVE_EXPAT_H', 1)]
524 else:
525 expat_incs = find_file('xmlparse.h', inc_dirs, [])
Fredrik Lundhade711a2001-01-24 08:00:28 +0000526
Martin v. Löwis1ab29b22001-01-21 10:54:52 +0000527 if (expat_incs is not None and
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000528 self.compiler.find_library_file(lib_dirs, 'expat')):
529 exts.append( Extension('pyexpat', ['pyexpat.c'],
530 define_macros = expat_defs,
531 libraries = ['expat']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000532
533 # Platform-specific libraries
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000534 if platform == 'linux2':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000535 # Linux-specific modules
536 exts.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) )
537
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000538 if platform == 'sunos5':
Fredrik Lundhade711a2001-01-24 08:00:28 +0000539 # SunOS specific modules
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000540 exts.append( Extension('sunaudiodev', ['sunaudiodev.c']) )
Jack Jansen144ebcc2001-08-05 22:31:19 +0000541
542 if platform == 'darwin1':
543 # Mac OS X specific modules. These are ported over from MacPython
544 # and still experimental. Some (such as gestalt or icglue) are
545 # already generally useful, some (the GUI ones) really need to
546 # be used from a framework.
547 exts.append( Extension('gestalt', ['gestaltmodule.c']) )
548 exts.append( Extension('MacOS', ['macosmodule.c']) )
549 exts.append( Extension('icglue', ['icgluemodule.c']) )
550 exts.append( Extension('macfs', ['macfsmodule.c', '../Python/getapplbycreator.c']) )
Jack Jansen194e13c2001-08-08 00:36:53 +0000551## exts.append( Extension('Nav', ['Nav.c']) )
552## exts.append( Extension('AE', ['ae/AEmodule.c']) )
553## exts.append( Extension('App', ['app/Appmodule.c']) )
554## exts.append( Extension('CF', ['cf/CFmodule.c'],
555## extra_link_args=['-framework', 'CoreFoundation']) )
556## exts.append( Extension('Cm', ['cm/Cmmodule.c']) )
557## exts.append( Extension('Ctl', ['ctl/Ctlmodule.c']) )
558## exts.append( Extension('Dlg', ['dlg/Dlgmodule.c']) )
559## exts.append( Extension('Drag', ['drag/Dragmodule.c']) )
560## exts.append( Extension('Evt', ['evt/Evtmodule.c']) )
561## exts.append( Extension('Fm', ['fm/Fmmodule.c']) )
562## exts.append( Extension('Icn', ['icn/Icnmodule.c']) )
563## exts.append( Extension('List', ['list/Listmodule.c']) )
564## exts.append( Extension('Menu', ['menu/Menumodule.c']) )
565## exts.append( Extension('Mlte', ['mlte/Mltemodule.c']) )
566## exts.append( Extension('Qd', ['qd/Qdmodule.c']) )
567## exts.append( Extension('Qdoffs', ['qdoffs/Qdoffsmodule.c']) )
568## exts.append( Extension('Qt', ['qt/Qtmodule.c'],
569## extra_link_args=['-framework', 'QuickTime']) )
570## exts.append( Extension('Res', ['res/Resmodule.c'] ) )
571#### exts.append( Extension('Scrap', ['scrap/Scrapmodule.c']) )
572## exts.append( Extension('Snd', ['snd/Sndmodule.c']) )
573## exts.append( Extension('TE', ['te/TEmodule.c']) )
574#### exts.append( Extension('waste', ['waste/wastemodule.c']) )
575## exts.append( Extension('Win', ['win/Winmodule.c']) )
Jack Jansen144ebcc2001-08-05 22:31:19 +0000576
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000577 self.extensions.extend(exts)
578
579 # Call the method for detecting whether _tkinter can be compiled
580 self.detect_tkinter(inc_dirs, lib_dirs)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000581
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000582
583 def detect_tkinter(self, inc_dirs, lib_dirs):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000584 # The _tkinter module.
Martin v. Löwisb1d19692001-03-21 07:44:53 +0000585
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000586 # Assume we haven't found any of the libraries or include files
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +0000587 # The versions with dots are used on Unix, and the versions without
588 # dots on Windows, for detection by cygwin.
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000589 tcllib = tklib = tcl_includes = tk_includes = None
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +0000590 for version in ['8.4', '84', '8.3', '83', '8.2',
591 '82', '8.1', '81', '8.0', '80']:
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000592 tklib = self.compiler.find_library_file(lib_dirs,
593 'tk' + version )
594 tcllib = self.compiler.find_library_file(lib_dirs,
595 'tcl' + version )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000596 if tklib and tcllib:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000597 # Exit the loop when we've found the Tcl/Tk libraries
598 break
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000599
Fredrik Lundhade711a2001-01-24 08:00:28 +0000600 # Now check for the header files
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000601 if tklib and tcllib:
602 # Check for the include files on Debian, where
603 # they're put in /usr/include/{tcl,tk}X.Y
Andrew M. Kuchling9a3fd8c2001-02-06 22:15:27 +0000604 debian_tcl_include = [ '/usr/include/tcl' + version ]
605 debian_tk_include = [ '/usr/include/tk' + version ] + debian_tcl_include
606 tcl_includes = find_file('tcl.h', inc_dirs, debian_tcl_include)
607 tk_includes = find_file('tk.h', inc_dirs, debian_tk_include)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000608
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000609 if (tcllib is None or tklib is None and
610 tcl_includes is None or tk_includes is None):
611 # Something's missing, so give up
612 return
Fredrik Lundhade711a2001-01-24 08:00:28 +0000613
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000614 # OK... everything seems to be present for Tcl/Tk.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000615
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000616 include_dirs = [] ; libs = [] ; defs = [] ; added_lib_dirs = []
617 for dir in tcl_includes + tk_includes:
618 if dir not in include_dirs:
619 include_dirs.append(dir)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000620
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000621 # Check for various platform-specific directories
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000622 platform = self.get_platform()
623 if platform == 'sunos5':
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000624 include_dirs.append('/usr/openwin/include')
625 added_lib_dirs.append('/usr/openwin/lib')
626 elif os.path.exists('/usr/X11R6/include'):
627 include_dirs.append('/usr/X11R6/include')
628 added_lib_dirs.append('/usr/X11R6/lib')
629 elif os.path.exists('/usr/X11R5/include'):
630 include_dirs.append('/usr/X11R5/include')
631 added_lib_dirs.append('/usr/X11R5/lib')
632 else:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000633 # Assume default location for X11
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000634 include_dirs.append('/usr/X11/include')
635 added_lib_dirs.append('/usr/X11/lib')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000636
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000637 # Check for BLT extension
638 if self.compiler.find_library_file(lib_dirs + added_lib_dirs, 'BLT8.0'):
639 defs.append( ('WITH_BLT', 1) )
640 libs.append('BLT8.0')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000641
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000642 # Add the Tcl/Tk libraries
Fredrik Lundhade711a2001-01-24 08:00:28 +0000643 libs.append('tk'+version)
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000644 libs.append('tcl'+version)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000645
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000646 if platform in ['aix3', 'aix4']:
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000647 libs.append('ld')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000648
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +0000649 # Finally, link with the X11 libraries (not appropriate on cygwin)
650 if platform != "cygwin":
651 libs.append('X11')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000652
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000653 ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
654 define_macros=[('WITH_APPINIT', 1)] + defs,
655 include_dirs = include_dirs,
656 libraries = libs,
657 library_dirs = added_lib_dirs,
658 )
659 self.extensions.append(ext)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000660
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000661 # XXX handle these, but how to detect?
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000662 # *** Uncomment and edit for PIL (TkImaging) extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000663 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000664 # *** Uncomment and edit for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000665 # -DWITH_TOGL togl.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000666 # *** Uncomment these for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000667 # -lGL -lGLU -lXext -lXmu \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000668
Andrew M. Kuchlingf52d27e2001-05-21 20:29:27 +0000669class PyBuildInstall(install):
670 # Suppress the warning about installation into the lib_dynload
671 # directory, which is not in sys.path when running Python during
672 # installation:
673 def initialize_options (self):
674 install.initialize_options(self)
675 self.warn_dir=0
676
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000677def main():
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000678 # turn off warnings when deprecated modules are imported
679 import warnings
680 warnings.filterwarnings("ignore",category=DeprecationWarning)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000681 setup(name = 'Python standard library',
Neil Schemenauere7e2ece2001-01-17 21:58:00 +0000682 version = '%d.%d' % sys.version_info[:2],
Andrew M. Kuchlingf52d27e2001-05-21 20:29:27 +0000683 cmdclass = {'build_ext':PyBuildExt, 'install':PyBuildInstall},
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000684 # The struct module is defined here, because build_ext won't be
685 # called unless there's at least one extension module defined.
Andrew M. Kuchlingaece4272001-02-28 20:56:49 +0000686 ext_modules=[Extension('struct', ['structmodule.c'])],
687
688 # Scripts to install
689 scripts = ['Tools/scripts/pydoc']
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000690 )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000691
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000692# --install-platlib
693if __name__ == '__main__':
694 sysconfig.set_python_build()
695 main()