blob: f2a5f554d9c62ba11a3b602d0666448424d8fcc4 [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:
Martin v. Löwis3e4b0e82001-08-10 08:56:17 +0000141 (ccshared,opt) = sysconfig.get_config_vars('CCSHARED','OPT')
142 args['compiler_so'] = compiler + ' ' + opt + ' ' + ccshared
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000143 if linker_so is not None:
Jack Jansendf82e582001-08-15 13:17:45 +0000144 if platform == 'darwin1':
145 args['linker_so'] = linker_so
146 else:
147 args['linker_so'] = linker_so + ' -shared'
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000148 self.compiler.set_executables(**args)
149
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000150 build_ext.build_extensions(self)
151
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000152 def build_extension(self, ext):
153
154 try:
155 build_ext.build_extension(self, ext)
156 except (CCompilerError, DistutilsError), why:
157 self.announce('WARNING: building of extension "%s" failed: %s' %
158 (ext.name, sys.exc_info()[1]))
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000159 return
160 try:
161 __import__(ext.name)
162 except ImportError:
163 self.announce('WARNING: removing "%s" since importing it failed' %
164 ext.name)
165 assert not self.inplace
166 fullname = self.get_ext_fullname(ext.name)
167 ext_filename = os.path.join(self.build_lib,
168 self.get_ext_filename(fullname))
169 os.remove(ext_filename)
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000170
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000171 def get_platform (self):
Fredrik Lundhade711a2001-01-24 08:00:28 +0000172 # Get value of sys.platform
173 platform = sys.platform
174 if platform[:6] =='cygwin':
175 platform = 'cygwin'
Andrew M. Kuchling3c044942001-02-06 23:37:23 +0000176 elif platform[:4] =='beos':
177 platform = 'beos'
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000178
Fredrik Lundhade711a2001-01-24 08:00:28 +0000179 return platform
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000180
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000181 def detect_modules(self):
Fredrik Lundhade711a2001-01-24 08:00:28 +0000182 # Ensure that /usr/local is always used
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000183 if '/usr/local/lib' not in self.compiler.library_dirs:
Andrew M. Kuchling9b5abcd2001-03-17 16:56:35 +0000184 self.compiler.library_dirs.insert(0, '/usr/local/lib')
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000185 if '/usr/local/include' not in self.compiler.include_dirs:
Andrew M. Kuchling9b5abcd2001-03-17 16:56:35 +0000186 self.compiler.include_dirs.insert(0, '/usr/local/include' )
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000187
Martin v. Löwis339d0f72001-08-17 18:39:25 +0000188 try:
189 have_unicode = unicode
190 except NameError:
191 have_unicode = 0
192
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000193 # lib_dirs and inc_dirs are used to search for files;
194 # if a file is found in one of those directories, it can
195 # be assumed that no additional -I,-L directives are needed.
196 lib_dirs = self.compiler.library_dirs + ['/lib', '/usr/lib']
Andrew M. Kuchling9b5abcd2001-03-17 16:56:35 +0000197 inc_dirs = self.compiler.include_dirs + ['/usr/include']
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000198 exts = []
199
Fredrik Lundhade711a2001-01-24 08:00:28 +0000200 platform = self.get_platform()
Andrew M. Kuchling9b5abcd2001-03-17 16:56:35 +0000201
Fredrik Lundhade711a2001-01-24 08:00:28 +0000202 # Check for MacOS X, which doesn't need libm.a at all
203 math_libs = ['m']
Andrew M. Kuchling3c044942001-02-06 23:37:23 +0000204 if platform in ['Darwin1.2', 'beos']:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000205 math_libs = []
Jack Jansen144ebcc2001-08-05 22:31:19 +0000206
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000207 # XXX Omitted modules: gl, pure, dl, SGI-specific modules
208
209 #
210 # The following modules are all pretty straightforward, and compile
211 # on pretty much any POSIXish platform.
212 #
Fredrik Lundhade711a2001-01-24 08:00:28 +0000213
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000214 # Some modules that are normally always on:
215 exts.append( Extension('regex', ['regexmodule.c', 'regexpr.c']) )
216 exts.append( Extension('pcre', ['pcremodule.c', 'pypcre.c']) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000217
Fred Drake2de74712001-02-01 05:26:54 +0000218 exts.append( Extension('_weakref', ['_weakref.c']) )
Jeremy Hylton5e7cb242001-02-02 18:24:26 +0000219 exts.append( Extension('_symtable', ['symtablemodule.c']) )
Andrew M. Kuchlingd5c43062001-01-17 15:59:25 +0000220 exts.append( Extension('xreadlines', ['xreadlinesmodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000221
222 # array objects
223 exts.append( Extension('array', ['arraymodule.c']) )
224 # complex math library functions
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000225 exts.append( Extension('cmath', ['cmathmodule.c'],
226 libraries=math_libs) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000227
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000228 # math library functions, e.g. sin()
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000229 exts.append( Extension('math', ['mathmodule.c'],
230 libraries=math_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000231 # fast string operations implemented in C
232 exts.append( Extension('strop', ['stropmodule.c']) )
233 # time operations and variables
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000234 exts.append( Extension('time', ['timemodule.c'],
235 libraries=math_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000236 # operator.add() and similar goodies
237 exts.append( Extension('operator', ['operator.c']) )
238 # access to the builtin codecs and codec registry
239 exts.append( Extension('_codecs', ['_codecsmodule.c']) )
Marc-André Lemburg261b8e22001-02-02 12:12:44 +0000240 # Python C API test module
Tim Petersd66595f2001-02-04 03:09:53 +0000241 exts.append( Extension('_testcapi', ['_testcapimodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000242 # static Unicode character database
Martin v. Löwis339d0f72001-08-17 18:39:25 +0000243 if have_unicode:
244 exts.append( Extension('unicodedata', ['unicodedata.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000245 # access to ISO C locale support
246 exts.append( Extension('_locale', ['_localemodule.c']) )
247
248 # Modules with some UNIX dependencies -- on by default:
249 # (If you have a really backward UNIX, select and socket may not be
250 # supported...)
251
252 # fcntl(2) and ioctl(2)
253 exts.append( Extension('fcntl', ['fcntlmodule.c']) )
254 # pwd(3)
255 exts.append( Extension('pwd', ['pwdmodule.c']) )
256 # grp(3)
257 exts.append( Extension('grp', ['grpmodule.c']) )
258 # posix (UNIX) errno values
259 exts.append( Extension('errno', ['errnomodule.c']) )
260 # select(2); not on ancient System V
261 exts.append( Extension('select', ['selectmodule.c']) )
262
263 # The md5 module implements the RSA Data Security, Inc. MD5
264 # Message-Digest Algorithm, described in RFC 1321. The necessary files
265 # md5c.c and md5.h are included here.
266 exts.append( Extension('md5', ['md5module.c', 'md5c.c']) )
267
268 # The sha module implements the SHA checksum algorithm.
269 # (NIST's Secure Hash Algorithm.)
270 exts.append( Extension('sha', ['shamodule.c']) )
271
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000272 # Helper module for various ascii-encoders
273 exts.append( Extension('binascii', ['binascii.c']) )
274
275 # Fred Drake's interface to the Python parser
276 exts.append( Extension('parser', ['parsermodule.c']) )
277
278 # Digital Creations' cStringIO and cPickle
279 exts.append( Extension('cStringIO', ['cStringIO.c']) )
280 exts.append( Extension('cPickle', ['cPickle.c']) )
281
282 # Memory-mapped files (also works on Win32).
283 exts.append( Extension('mmap', ['mmapmodule.c']) )
284
285 # Lance Ellinghaus's modules:
286 # enigma-inspired encryption
287 exts.append( Extension('rotor', ['rotormodule.c']) )
288 # syslog daemon interface
289 exts.append( Extension('syslog', ['syslogmodule.c']) )
290
291 # George Neville-Neil's timing module:
292 exts.append( Extension('timing', ['timingmodule.c']) )
293
294 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000295 # Here ends the simple stuff. From here on, modules need certain
296 # libraries, are platform-specific, or present other surprises.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000297 #
298
299 # Multimedia modules
300 # These don't work for 64-bit platforms!!!
301 # These represent audio samples or images as strings:
302
Fredrik Lundhade711a2001-01-24 08:00:28 +0000303 # Disabled on 64-bit platforms
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000304 if sys.maxint != 9223372036854775807L:
305 # Operations on audio samples
306 exts.append( Extension('audioop', ['audioop.c']) )
307 # Operations on images
308 exts.append( Extension('imageop', ['imageop.c']) )
309 # Read SGI RGB image files (but coded portably)
310 exts.append( Extension('rgbimg', ['rgbimgmodule.c']) )
311
312 # readline
Marc-André Lemburg2efc3232001-01-26 18:23:02 +0000313 if self.compiler.find_library_file(lib_dirs, 'readline'):
314 readline_libs = ['readline']
Andrew M. Kuchling5aa3c4a2001-08-16 20:30:18 +0000315 if self.compiler.find_library_file(lib_dirs,
316 'ncurses'):
317 readline_libs.append('ncurses')
318 elif self.compiler.find_library_file(lib_dirs +
Marc-André Lemburg2efc3232001-01-26 18:23:02 +0000319 ['/usr/lib/termcap'],
320 'termcap'):
321 readline_libs.append('termcap')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000322 exts.append( Extension('readline', ['readline.c'],
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000323 library_dirs=['/usr/lib/termcap'],
Marc-André Lemburg2efc3232001-01-26 18:23:02 +0000324 libraries=readline_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000325
Andrew M. Kuchling5aa3c4a2001-08-16 20:30:18 +0000326 # crypt module.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000327
328 if self.compiler.find_library_file(lib_dirs, 'crypt'):
329 libs = ['crypt']
330 else:
331 libs = []
332 exts.append( Extension('crypt', ['cryptmodule.c'], libraries=libs) )
333
334 # socket(2)
335 # Detect SSL support for the socket module
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000336 ssl_incs = find_file('openssl/ssl.h', inc_dirs,
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +0000337 ['/usr/local/ssl/include',
338 '/usr/contrib/ssl/include/'
339 ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000340 )
341 ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs,
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +0000342 ['/usr/local/ssl/lib',
343 '/usr/contrib/ssl/lib/'
344 ] )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000345
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000346 if (ssl_incs is not None and
347 ssl_libs is not None):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000348 exts.append( Extension('_socket', ['socketmodule.c'],
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000349 include_dirs = ssl_incs,
Fredrik Lundhade711a2001-01-24 08:00:28 +0000350 library_dirs = ssl_libs,
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000351 libraries = ['ssl', 'crypto'],
352 define_macros = [('USE_SSL',1)] ) )
353 else:
354 exts.append( Extension('_socket', ['socketmodule.c']) )
355
356 # Modules that provide persistent dictionary-like semantics. You will
357 # probably want to arrange for at least one of them to be available on
358 # your machine, though none are defined by default because of library
359 # dependencies. The Python module anydbm.py provides an
360 # implementation independent wrapper for these; dumbdbm.py provides
361 # similar functionality (but slower of course) implemented in Python.
362
363 # The standard Unix dbm module:
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000364 if platform not in ['cygwin']:
365 if (self.compiler.find_library_file(lib_dirs, 'ndbm')):
366 exts.append( Extension('dbm', ['dbmmodule.c'],
367 libraries = ['ndbm'] ) )
368 else:
369 exts.append( Extension('dbm', ['dbmmodule.c']) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000370
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000371 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
372 if (self.compiler.find_library_file(lib_dirs, 'gdbm')):
373 exts.append( Extension('gdbm', ['gdbmmodule.c'],
374 libraries = ['gdbm'] ) )
375
376 # Berkeley DB interface.
377 #
378 # This requires the Berkeley DB code, see
379 # ftp://ftp.cs.berkeley.edu/pub/4bsd/db.1.85.tar.gz
380 #
381 # Edit the variables DB and DBPORT to point to the db top directory
382 # and the subdirectory of PORT where you built it.
383 #
384 # (See http://electricrain.com/greg/python/bsddb3/ for an interface to
385 # BSD DB 3.x.)
386
Andrew M. Kuchlinge06337a2001-02-23 16:27:48 +0000387 dblib = []
Skip Montanaroe81f4472001-08-21 04:23:21 +0000388 if self.compiler.find_library_file(lib_dirs, 'db-3.1'):
389 dblib = ['db-3.1']
390 elif self.compiler.find_library_file(lib_dirs, 'db2'):
391 dblib = ['db2']
392 elif self.compiler.find_library_file(lib_dirs, 'db1'):
393 dblib = ['db1']
394 elif self.compiler.find_library_file(lib_dirs, 'db'):
Andrew M. Kuchlinge06337a2001-02-23 16:27:48 +0000395 dblib = ['db']
396
397 db185_incs = find_file('db_185.h', inc_dirs,
398 ['/usr/include/db3', '/usr/include/db2'])
399 db_inc = find_file('db.h', inc_dirs, ['/usr/include/db1'])
400 if db185_incs is not None:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000401 exts.append( Extension('bsddb', ['bsddbmodule.c'],
Andrew M. Kuchlinge06337a2001-02-23 16:27:48 +0000402 include_dirs = db185_incs,
403 define_macros=[('HAVE_DB_185_H',1)],
404 libraries = dblib ) )
405 elif db_inc is not None:
406 exts.append( Extension('bsddb', ['bsddbmodule.c'],
407 include_dirs = db_inc,
408 libraries = dblib) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000409
410 # The mpz module interfaces to the GNU Multiple Precision library.
Fredrik Lundhade711a2001-01-24 08:00:28 +0000411 # You need to ftp the GNU MP library.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000412 # This was originally written and tested against GMP 1.2 and 1.3.2.
413 # It has been modified by Rob Hooft to work with 2.0.2 as well, but I
414 # haven't tested it recently. For a more complete module,
415 # refer to pympz.sourceforge.net.
416
417 # A compatible MP library unencombered by the GPL also exists. It was
418 # posted to comp.sources.misc in volume 40 and is widely available from
419 # FTP archive sites. One URL for it is:
420 # ftp://gatekeeper.dec.com/.b/usenet/comp.sources.misc/volume40/fgmp/part01.Z
421
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000422 if (self.compiler.find_library_file(lib_dirs, 'gmp')):
423 exts.append( Extension('mpz', ['mpzmodule.c'],
424 libraries = ['gmp'] ) )
425
426
427 # Unix-only modules
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000428 if platform not in ['mac', 'win32']:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000429 # Steen Lumholt's termios module
430 exts.append( Extension('termios', ['termios.c']) )
431 # Jeremy Hylton's rlimit interface
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000432 if platform not in ['cygwin']:
433 exts.append( Extension('resource', ['resource.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000434
Andrew M. Kuchlingcf393f32001-02-21 02:38:24 +0000435 # Sun yellow pages. Some systems have the functions in libc.
Andrew M. Kuchling6efc6e72001-02-27 20:54:23 +0000436 if platform not in ['cygwin']:
437 if (self.compiler.find_library_file(lib_dirs, 'nsl')):
438 libs = ['nsl']
439 else:
440 libs = []
441 exts.append( Extension('nis', ['nismodule.c'],
442 libraries = libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000443
444 # Curses support, requring the System V version of curses, often
Fredrik Lundhade711a2001-01-24 08:00:28 +0000445 # provided by the ncurses library.
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000446 if platform == 'sunos4':
Andrew M. Kuchlingb69c7582001-02-28 19:49:57 +0000447 inc_dirs += ['/usr/5include']
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000448 lib_dirs += ['/usr/5lib']
449
450 if (self.compiler.find_library_file(lib_dirs, 'ncurses')):
451 curses_libs = ['ncurses']
452 exts.append( Extension('_curses', ['_cursesmodule.c'],
453 libraries = curses_libs) )
Jack Jansen4ca5f382001-09-04 09:05:11 +0000454 elif (self.compiler.find_library_file(lib_dirs, 'curses')) and platform != 'darwin1':
455 # OSX has an old Berkeley curses, not good enough for the _curses module.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000456 if (self.compiler.find_library_file(lib_dirs, 'terminfo')):
457 curses_libs = ['curses', 'terminfo']
458 else:
459 curses_libs = ['curses', 'termcap']
Fredrik Lundhade711a2001-01-24 08:00:28 +0000460
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000461 exts.append( Extension('_curses', ['_cursesmodule.c'],
462 libraries = curses_libs) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000463
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000464 # If the curses module is enabled, check for the panel module
465 if (os.path.exists('Modules/_curses_panel.c') and
466 module_enabled(exts, '_curses') and
467 self.compiler.find_library_file(lib_dirs, 'panel')):
468 exts.append( Extension('_curses_panel', ['_curses_panel.c'],
469 libraries = ['panel'] + curses_libs) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000470
471
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000472
473 # Lee Busby's SIGFPE modules.
474 # The library to link fpectl with is platform specific.
475 # Choose *one* of the options below for fpectl:
476
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000477 if platform == 'irix5':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000478 # For SGI IRIX (tested on 5.3):
479 exts.append( Extension('fpectl', ['fpectlmodule.c'],
480 libraries=['fpe']) )
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000481 elif 0: # XXX how to detect SunPro?
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000482 # For Solaris with SunPro compiler (tested on Solaris 2.5 with SunPro C 4.2):
483 # (Without the compiler you don't have -lsunmath.)
484 #fpectl fpectlmodule.c -R/opt/SUNWspro/lib -lsunmath -lm
485 pass
486 else:
487 # For other systems: see instructions in fpectlmodule.c.
488 #fpectl fpectlmodule.c ...
489 exts.append( Extension('fpectl', ['fpectlmodule.c']) )
490
491
492 # Andrew Kuchling's zlib module.
493 # This require zlib 1.1.3 (or later).
494 # See http://www.cdrom.com/pub/infozip/zlib/
Guido van Rossume6970912001-04-15 15:16:12 +0000495 zlib_inc = find_file('zlib.h', [], inc_dirs)
496 if zlib_inc is not None:
497 zlib_h = zlib_inc[0] + '/zlib.h'
498 version = '"0.0.0"'
499 version_req = '"1.1.3"'
500 fp = open(zlib_h)
501 while 1:
502 line = fp.readline()
503 if not line:
504 break
505 if line.find('#define ZLIB_VERSION', 0) == 0:
506 version = line.split()[2]
507 break
508 if version >= version_req:
509 if (self.compiler.find_library_file(lib_dirs, 'z')):
510 exts.append( Extension('zlib', ['zlibmodule.c'],
511 libraries = ['z']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000512
513 # Interface to the Expat XML parser
514 #
515 # Expat is written by James Clark and must be downloaded separately
516 # (see below). The pyexpat module was written by Paul Prescod after a
517 # prototype by Jack Jansen.
518 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000519 # The Expat dist includes Windows .lib and .dll files. Home page is
520 # at http://www.jclark.com/xml/expat.html, the current production
521 # release is always ftp://ftp.jclark.com/pub/xml/expat.zip.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000522 #
523 # EXPAT_DIR, below, should point to the expat/ directory created by
524 # unpacking the Expat source distribution.
525 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000526 # Note: the expat build process doesn't yet build a libexpat.a; you
527 # can do this manually while we try convince the author to add it. To
528 # do so, cd to EXPAT_DIR, run "make" if you have not done so, then
529 # run:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000530 #
531 # ar cr libexpat.a xmltok/*.o xmlparse/*.o
532 #
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000533 expat_defs = []
534 expat_incs = find_file('expat.h', inc_dirs, [])
535 if expat_incs is not None:
536 # expat.h was found
537 expat_defs = [('HAVE_EXPAT_H', 1)]
538 else:
539 expat_incs = find_file('xmlparse.h', inc_dirs, [])
Fredrik Lundhade711a2001-01-24 08:00:28 +0000540
Martin v. Löwis1ab29b22001-01-21 10:54:52 +0000541 if (expat_incs is not None and
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000542 self.compiler.find_library_file(lib_dirs, 'expat')):
543 exts.append( Extension('pyexpat', ['pyexpat.c'],
544 define_macros = expat_defs,
545 libraries = ['expat']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000546
547 # Platform-specific libraries
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000548 if platform == 'linux2':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000549 # Linux-specific modules
550 exts.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) )
551
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000552 if platform == 'sunos5':
Fredrik Lundhade711a2001-01-24 08:00:28 +0000553 # SunOS specific modules
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000554 exts.append( Extension('sunaudiodev', ['sunaudiodev.c']) )
Jack Jansen144ebcc2001-08-05 22:31:19 +0000555
556 if platform == 'darwin1':
557 # Mac OS X specific modules. These are ported over from MacPython
558 # and still experimental. Some (such as gestalt or icglue) are
559 # already generally useful, some (the GUI ones) really need to
560 # be used from a framework.
Jack Jansen2f760c32001-09-04 21:33:12 +0000561 #
562 # I would like to trigger on WITH_NEXT_FRAMEWORK but that isn't
563 # available here. This Makefile variable is also what the install
564 # procedure triggers on.
565 frameworkdir = sysconfig.get_config_var('PYTHONFRAMEWORKDIR')
Jack Jansen144ebcc2001-08-05 22:31:19 +0000566 exts.append( Extension('gestalt', ['gestaltmodule.c']) )
567 exts.append( Extension('MacOS', ['macosmodule.c']) )
568 exts.append( Extension('icglue', ['icgluemodule.c']) )
569 exts.append( Extension('macfs', ['macfsmodule.c', '../Python/getapplbycreator.c']) )
Jack Jansen2f760c32001-09-04 21:33:12 +0000570 exts.append( Extension('_CF', ['cf/_CFmodule.c'],
571 extra_link_args=['-framework', 'CoreFoundation']) )
572 exts.append( Extension('_Res', ['res/_Resmodule.c'] ) )
573 exts.append( Extension('_Snd', ['snd/_Sndmodule.c']) )
574 if frameworkdir:
575 exts.append( Extension('Nav', ['Nav.c']) )
576 exts.append( Extension('_AE', ['ae/_AEmodule.c']) )
577 exts.append( Extension('_App', ['app/_Appmodule.c']) )
578 exts.append( Extension('_Cm', ['cm/_Cmmodule.c']) )
579 exts.append( Extension('_Ctl', ['ctl/_Ctlmodule.c']) )
580 exts.append( Extension('_Dlg', ['dlg/_Dlgmodule.c']) )
581 exts.append( Extension('_Drag', ['drag/_Dragmodule.c']) )
582 exts.append( Extension('_Evt', ['evt/_Evtmodule.c']) )
583 exts.append( Extension('_Fm', ['fm/_Fmmodule.c']) )
584 exts.append( Extension('_Icn', ['icn/_Icnmodule.c']) )
585 exts.append( Extension('_List', ['list/_Listmodule.c']) )
586 exts.append( Extension('_Menu', ['menu/_Menumodule.c']) )
587 exts.append( Extension('_Mlte', ['mlte/_Mltemodule.c']) )
588 exts.append( Extension('_Qd', ['qd/_Qdmodule.c']) )
589 exts.append( Extension('_Qdoffs', ['qdoffs/_Qdoffsmodule.c']) )
590 exts.append( Extension('_Qt', ['qt/_Qtmodule.c'],
591 extra_link_args=['-framework', 'QuickTime']) )
592## exts.append( Extension('_Scrap', ['scrap/_Scrapmodule.c']) )
593 exts.append( Extension('_TE', ['te/_TEmodule.c']) )
594## exts.append( Extension('waste', ['waste/wastemodule.c']) )
595 exts.append( Extension('_Win', ['win/_Winmodule.c']) )
Jack Jansen144ebcc2001-08-05 22:31:19 +0000596
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000597 self.extensions.extend(exts)
598
599 # Call the method for detecting whether _tkinter can be compiled
600 self.detect_tkinter(inc_dirs, lib_dirs)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000601
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000602
603 def detect_tkinter(self, inc_dirs, lib_dirs):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000604 # The _tkinter module.
Martin v. Löwisb1d19692001-03-21 07:44:53 +0000605
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000606 # Assume we haven't found any of the libraries or include files
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +0000607 # The versions with dots are used on Unix, and the versions without
608 # dots on Windows, for detection by cygwin.
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000609 tcllib = tklib = tcl_includes = tk_includes = None
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +0000610 for version in ['8.4', '84', '8.3', '83', '8.2',
611 '82', '8.1', '81', '8.0', '80']:
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000612 tklib = self.compiler.find_library_file(lib_dirs,
613 'tk' + version )
614 tcllib = self.compiler.find_library_file(lib_dirs,
615 'tcl' + version )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000616 if tklib and tcllib:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000617 # Exit the loop when we've found the Tcl/Tk libraries
618 break
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000619
Fredrik Lundhade711a2001-01-24 08:00:28 +0000620 # Now check for the header files
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000621 if tklib and tcllib:
622 # Check for the include files on Debian, where
623 # they're put in /usr/include/{tcl,tk}X.Y
Andrew M. Kuchling9a3fd8c2001-02-06 22:15:27 +0000624 debian_tcl_include = [ '/usr/include/tcl' + version ]
625 debian_tk_include = [ '/usr/include/tk' + version ] + debian_tcl_include
626 tcl_includes = find_file('tcl.h', inc_dirs, debian_tcl_include)
627 tk_includes = find_file('tk.h', inc_dirs, debian_tk_include)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000628
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000629 if (tcllib is None or tklib is None and
630 tcl_includes is None or tk_includes is None):
631 # Something's missing, so give up
632 return
Fredrik Lundhade711a2001-01-24 08:00:28 +0000633
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000634 # OK... everything seems to be present for Tcl/Tk.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000635
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000636 include_dirs = [] ; libs = [] ; defs = [] ; added_lib_dirs = []
637 for dir in tcl_includes + tk_includes:
638 if dir not in include_dirs:
639 include_dirs.append(dir)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000640
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000641 # Check for various platform-specific directories
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000642 platform = self.get_platform()
643 if platform == 'sunos5':
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000644 include_dirs.append('/usr/openwin/include')
645 added_lib_dirs.append('/usr/openwin/lib')
646 elif os.path.exists('/usr/X11R6/include'):
647 include_dirs.append('/usr/X11R6/include')
648 added_lib_dirs.append('/usr/X11R6/lib')
649 elif os.path.exists('/usr/X11R5/include'):
650 include_dirs.append('/usr/X11R5/include')
651 added_lib_dirs.append('/usr/X11R5/lib')
652 else:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000653 # Assume default location for X11
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000654 include_dirs.append('/usr/X11/include')
655 added_lib_dirs.append('/usr/X11/lib')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000656
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000657 # Check for BLT extension
658 if self.compiler.find_library_file(lib_dirs + added_lib_dirs, 'BLT8.0'):
659 defs.append( ('WITH_BLT', 1) )
660 libs.append('BLT8.0')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000661
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000662 # Add the Tcl/Tk libraries
Fredrik Lundhade711a2001-01-24 08:00:28 +0000663 libs.append('tk'+version)
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000664 libs.append('tcl'+version)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000665
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000666 if platform in ['aix3', 'aix4']:
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000667 libs.append('ld')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000668
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +0000669 # Finally, link with the X11 libraries (not appropriate on cygwin)
670 if platform != "cygwin":
671 libs.append('X11')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000672
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000673 ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
674 define_macros=[('WITH_APPINIT', 1)] + defs,
675 include_dirs = include_dirs,
676 libraries = libs,
677 library_dirs = added_lib_dirs,
678 )
679 self.extensions.append(ext)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000680
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000681 # XXX handle these, but how to detect?
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000682 # *** Uncomment and edit for PIL (TkImaging) extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000683 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000684 # *** Uncomment and edit for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000685 # -DWITH_TOGL togl.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000686 # *** Uncomment these for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000687 # -lGL -lGLU -lXext -lXmu \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000688
Andrew M. Kuchlingf52d27e2001-05-21 20:29:27 +0000689class PyBuildInstall(install):
690 # Suppress the warning about installation into the lib_dynload
691 # directory, which is not in sys.path when running Python during
692 # installation:
693 def initialize_options (self):
694 install.initialize_options(self)
695 self.warn_dir=0
696
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000697def main():
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000698 # turn off warnings when deprecated modules are imported
699 import warnings
700 warnings.filterwarnings("ignore",category=DeprecationWarning)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000701 setup(name = 'Python standard library',
Neil Schemenauere7e2ece2001-01-17 21:58:00 +0000702 version = '%d.%d' % sys.version_info[:2],
Andrew M. Kuchlingf52d27e2001-05-21 20:29:27 +0000703 cmdclass = {'build_ext':PyBuildExt, 'install':PyBuildInstall},
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000704 # The struct module is defined here, because build_ext won't be
705 # called unless there's at least one extension module defined.
Andrew M. Kuchlingaece4272001-02-28 20:56:49 +0000706 ext_modules=[Extension('struct', ['structmodule.c'])],
707
708 # Scripts to install
709 scripts = ['Tools/scripts/pydoc']
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000710 )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000711
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000712# --install-platlib
713if __name__ == '__main__':
714 sysconfig.set_python_build()
715 main()