blob: 79961da11cf701577556c20678b02c29fb401beb [file] [log] [blame]
Andrew M. Kuchling66012fe2001-01-26 21:56:581# Autodetecting setup.py script for building the Python extensions
2#
Andrew M. Kuchling00e0f212001-01-17 15:23:233# To be fixed:
4# Implement --disable-modules setting
Andrew M. Kuchling66012fe2001-01-26 21:56:585#
Fredrik Lundhade711a2001-01-24 08:00:286
Andrew M. Kuchling66012fe2001-01-26 21:56:587__version__ = "$Revision$"
8
9import sys, os, getopt
Andrew M. Kuchling00e0f212001-01-17 15:23:2310from distutils import sysconfig
Andrew M. Kuchling8d7f0862001-02-23 16:32:3211from distutils import text_file
Marc-André Lemburg7c6fcda2001-01-26 18:03:2412from distutils.errors import *
Andrew M. Kuchling00e0f212001-01-17 15:23:2313from distutils.core import Extension, setup
14from distutils.command.build_ext import build_ext
15
16# This global variable is used to hold the list of modules to be disabled.
17disabled_module_list = []
18
Andrew M. Kuchlingfbe73762001-01-18 18:44:2019def find_file(filename, std_dirs, paths):
20 """Searches for the directory where a given file is located,
21 and returns a possibly-empty list of additional directories, or None
22 if the file couldn't be found at all.
Fredrik Lundhade711a2001-01-24 08:00:2823
Andrew M. Kuchlingfbe73762001-01-18 18:44:2024 'filename' is the name of a file, such as readline.h or libcrypto.a.
25 'std_dirs' is the list of standard system directories; if the
26 file is found in one of them, no additional directives are needed.
27 'paths' is a list of additional locations to check; if the file is
28 found in one of them, the resulting list will contain the directory.
29 """
30
31 # Check the standard locations
32 for dir in std_dirs:
33 f = os.path.join(dir, filename)
34 if os.path.exists(f): return []
35
36 # Check the additional directories
37 for dir in paths:
38 f = os.path.join(dir, filename)
39 if os.path.exists(f):
40 return [dir]
41
42 # Not found anywhere
Andrew M. Kuchling00e0f212001-01-17 15:23:2343 return None
44
Andrew M. Kuchlingfbe73762001-01-18 18:44:2045def find_library_file(compiler, libname, std_dirs, paths):
46 filename = compiler.library_filename(libname, lib_type='shared')
47 result = find_file(filename, std_dirs, paths)
48 if result is not None: return result
Fredrik Lundhade711a2001-01-24 08:00:2849
Andrew M. Kuchlingfbe73762001-01-18 18:44:2050 filename = compiler.library_filename(libname, lib_type='static')
51 result = find_file(filename, std_dirs, paths)
52 return result
53
Andrew M. Kuchling00e0f212001-01-17 15:23:2354def module_enabled(extlist, modname):
55 """Returns whether the module 'modname' is present in the list
56 of extensions 'extlist'."""
57 extlist = [ext for ext in extlist if ext.name == modname]
58 return len(extlist)
Fredrik Lundhade711a2001-01-24 08:00:2859
Andrew M. Kuchling00e0f212001-01-17 15:23:2360class PyBuildExt(build_ext):
Fredrik Lundhade711a2001-01-24 08:00:2861
Andrew M. Kuchling00e0f212001-01-17 15:23:2362 def build_extensions(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:2363
64 # Detect which modules should be compiled
65 self.detect_modules()
66
67 # Remove modules that are present on the disabled list
68 self.extensions = [ext for ext in self.extensions
69 if ext.name not in disabled_module_list]
Fredrik Lundhade711a2001-01-24 08:00:2870
Andrew M. Kuchling00e0f212001-01-17 15:23:2371 # Fix up the autodetected modules, prefixing all the source files
72 # with Modules/ and adding Python's include directory to the path.
73 (srcdir,) = sysconfig.get_config_vars('srcdir')
74
Neil Schemenauer726b78e2001-01-24 17:18:2175 # Figure out the location of the source code for extension modules
76 moddir = os.path.join(os.getcwd(), srcdir, 'Modules')
Andrew M. Kuchling00e0f212001-01-17 15:23:2377 moddir = os.path.normpath(moddir)
78 srcdir, tail = os.path.split(moddir)
79 srcdir = os.path.normpath(srcdir)
80 moddir = os.path.normpath(moddir)
81
Andrew M. Kuchling3da989c2001-02-28 22:49:2682 # Fix up the paths for scripts, too
83 self.distribution.scripts = [os.path.join(srcdir, filename)
84 for filename in self.distribution.scripts]
85
Andrew M. Kuchlingfbe73762001-01-18 18:44:2086 for ext in self.extensions[:]:
Andrew M. Kuchling00e0f212001-01-17 15:23:2387 ext.sources = [ os.path.join(moddir, filename)
88 for filename in ext.sources ]
89 ext.include_dirs.append( '.' ) # to get config.h
Andrew M. Kuchlinge3d6e412001-01-19 02:50:3490 ext.include_dirs.append( os.path.join(srcdir, './Include') )
Andrew M. Kuchlingfbe73762001-01-18 18:44:2091
Andrew M. Kuchlinge7c87322001-01-19 16:58:2192 # If a module has already been built statically,
Andrew M. Kuchlingfbe73762001-01-18 18:44:2093 # don't build it here
Andrew M. Kuchlinge7c87322001-01-19 16:58:2194 if ext.name in sys.builtin_module_names:
Andrew M. Kuchlingfbe73762001-01-18 18:44:2095 self.extensions.remove(ext)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:3496
Andrew M. Kuchling8d7f0862001-02-23 16:32:3297 # Parse Modules/Setup to figure out which modules are turned
98 # on in the file.
99 input = text_file.TextFile('Modules/Setup', join_lines=1)
100 remove_modules = []
101 while 1:
102 line = input.readline()
103 if not line: break
104 line = line.split()
105 remove_modules.append( line[0] )
106 input.close()
107
108 for ext in self.extensions[:]:
109 if ext.name in remove_modules:
110 self.extensions.remove(ext)
111
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34112 # When you run "make CC=altcc" or something similar, you really want
113 # those environment variables passed into the setup.py phase. Here's
114 # a small set of useful ones.
115 compiler = os.environ.get('CC')
116 linker_so = os.environ.get('LDSHARED')
117 args = {}
118 # unfortunately, distutils doesn't let us provide separate C and C++
119 # compilers
120 if compiler is not None:
Thomas Wouters98cc7912001-07-16 16:00:32121 (ccshared,) = sysconfig.get_config_vars('CCSHARED')
122 args['compiler_so'] = compiler + ' ' + ccshared
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34123 if linker_so is not None:
124 args['linker_so'] = linker_so + ' -shared'
125 self.compiler.set_executables(**args)
126
Andrew M. Kuchling00e0f212001-01-17 15:23:23127 build_ext.build_extensions(self)
128
Marc-André Lemburg7c6fcda2001-01-26 18:03:24129 def build_extension(self, ext):
130
131 try:
132 build_ext.build_extension(self, ext)
133 except (CCompilerError, DistutilsError), why:
134 self.announce('WARNING: building of extension "%s" failed: %s' %
135 (ext.name, sys.exc_info()[1]))
136
Andrew M. Kuchling34febf52001-01-24 03:31:07137 def get_platform (self):
Fredrik Lundhade711a2001-01-24 08:00:28138 # Get value of sys.platform
139 platform = sys.platform
140 if platform[:6] =='cygwin':
141 platform = 'cygwin'
Andrew M. Kuchling3c044942001-02-06 23:37:23142 elif platform[:4] =='beos':
143 platform = 'beos'
Andrew M. Kuchling34febf52001-01-24 03:31:07144
Fredrik Lundhade711a2001-01-24 08:00:28145 return platform
Andrew M. Kuchling34febf52001-01-24 03:31:07146
Andrew M. Kuchling00e0f212001-01-17 15:23:23147 def detect_modules(self):
Fredrik Lundhade711a2001-01-24 08:00:28148 # Ensure that /usr/local is always used
Andrew M. Kuchlingfbe73762001-01-18 18:44:20149 if '/usr/local/lib' not in self.compiler.library_dirs:
Andrew M. Kuchling9b5abcd2001-03-17 16:56:35150 self.compiler.library_dirs.insert(0, '/usr/local/lib')
Andrew M. Kuchlingfbe73762001-01-18 18:44:20151 if '/usr/local/include' not in self.compiler.include_dirs:
Andrew M. Kuchling9b5abcd2001-03-17 16:56:35152 self.compiler.include_dirs.insert(0, '/usr/local/include' )
Andrew M. Kuchlingfbe73762001-01-18 18:44:20153
154 # lib_dirs and inc_dirs are used to search for files;
155 # if a file is found in one of those directories, it can
156 # be assumed that no additional -I,-L directives are needed.
157 lib_dirs = self.compiler.library_dirs + ['/lib', '/usr/lib']
Andrew M. Kuchling9b5abcd2001-03-17 16:56:35158 inc_dirs = self.compiler.include_dirs + ['/usr/include']
Andrew M. Kuchling00e0f212001-01-17 15:23:23159 exts = []
160
Fredrik Lundhade711a2001-01-24 08:00:28161 platform = self.get_platform()
Andrew M. Kuchling9b5abcd2001-03-17 16:56:35162
Fredrik Lundhade711a2001-01-24 08:00:28163 # Check for MacOS X, which doesn't need libm.a at all
164 math_libs = ['m']
Andrew M. Kuchling3c044942001-02-06 23:37:23165 if platform in ['Darwin1.2', 'beos']:
Fredrik Lundhade711a2001-01-24 08:00:28166 math_libs = []
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11167
Andrew M. Kuchling00e0f212001-01-17 15:23:23168 # XXX Omitted modules: gl, pure, dl, SGI-specific modules
169
170 #
171 # The following modules are all pretty straightforward, and compile
172 # on pretty much any POSIXish platform.
173 #
Fredrik Lundhade711a2001-01-24 08:00:28174
Andrew M. Kuchling00e0f212001-01-17 15:23:23175 # Some modules that are normally always on:
176 exts.append( Extension('regex', ['regexmodule.c', 'regexpr.c']) )
177 exts.append( Extension('pcre', ['pcremodule.c', 'pypcre.c']) )
Fredrik Lundhade711a2001-01-24 08:00:28178
Fred Drake2de74712001-02-01 05:26:54179 exts.append( Extension('_weakref', ['_weakref.c']) )
Jeremy Hylton5e7cb242001-02-02 18:24:26180 exts.append( Extension('_symtable', ['symtablemodule.c']) )
Andrew M. Kuchlingd5c43062001-01-17 15:59:25181 exts.append( Extension('xreadlines', ['xreadlinesmodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23182
183 # array objects
184 exts.append( Extension('array', ['arraymodule.c']) )
185 # complex math library functions
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11186 exts.append( Extension('cmath', ['cmathmodule.c'],
187 libraries=math_libs) )
Fredrik Lundhade711a2001-01-24 08:00:28188
Andrew M. Kuchling00e0f212001-01-17 15:23:23189 # math library functions, e.g. sin()
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11190 exts.append( Extension('math', ['mathmodule.c'],
191 libraries=math_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23192 # fast string operations implemented in C
193 exts.append( Extension('strop', ['stropmodule.c']) )
194 # time operations and variables
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11195 exts.append( Extension('time', ['timemodule.c'],
196 libraries=math_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23197 # operator.add() and similar goodies
198 exts.append( Extension('operator', ['operator.c']) )
199 # access to the builtin codecs and codec registry
200 exts.append( Extension('_codecs', ['_codecsmodule.c']) )
Marc-André Lemburg261b8e22001-02-02 12:12:44201 # Python C API test module
Tim Petersd66595f2001-02-04 03:09:53202 exts.append( Extension('_testcapi', ['_testcapimodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23203 # static Unicode character database
Marc-André Lemburg14970be2001-01-22 10:38:27204 exts.append( Extension('unicodedata', ['unicodedata.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23205 # access to ISO C locale support
206 exts.append( Extension('_locale', ['_localemodule.c']) )
207
208 # Modules with some UNIX dependencies -- on by default:
209 # (If you have a really backward UNIX, select and socket may not be
210 # supported...)
211
212 # fcntl(2) and ioctl(2)
213 exts.append( Extension('fcntl', ['fcntlmodule.c']) )
214 # pwd(3)
215 exts.append( Extension('pwd', ['pwdmodule.c']) )
216 # grp(3)
217 exts.append( Extension('grp', ['grpmodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23218 # select(2); not on ancient System V
219 exts.append( Extension('select', ['selectmodule.c']) )
220
221 # The md5 module implements the RSA Data Security, Inc. MD5
222 # Message-Digest Algorithm, described in RFC 1321. The necessary files
223 # md5c.c and md5.h are included here.
224 exts.append( Extension('md5', ['md5module.c', 'md5c.c']) )
225
226 # The sha module implements the SHA checksum algorithm.
227 # (NIST's Secure Hash Algorithm.)
228 exts.append( Extension('sha', ['shamodule.c']) )
229
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34230 # Tommy Burnette's 'new' module (creates new empty objects of certain
231 # kinds):
Andrew M. Kuchling00e0f212001-01-17 15:23:23232 exts.append( Extension('new', ['newmodule.c']) )
233
234 # Helper module for various ascii-encoders
235 exts.append( Extension('binascii', ['binascii.c']) )
236
237 # Fred Drake's interface to the Python parser
238 exts.append( Extension('parser', ['parsermodule.c']) )
239
240 # Digital Creations' cStringIO and cPickle
241 exts.append( Extension('cStringIO', ['cStringIO.c']) )
242 exts.append( Extension('cPickle', ['cPickle.c']) )
243
244 # Memory-mapped files (also works on Win32).
245 exts.append( Extension('mmap', ['mmapmodule.c']) )
246
247 # Lance Ellinghaus's modules:
248 # enigma-inspired encryption
249 exts.append( Extension('rotor', ['rotormodule.c']) )
250 # syslog daemon interface
251 exts.append( Extension('syslog', ['syslogmodule.c']) )
252
253 # George Neville-Neil's timing module:
254 exts.append( Extension('timing', ['timingmodule.c']) )
255
256 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34257 # Here ends the simple stuff. From here on, modules need certain
258 # libraries, are platform-specific, or present other surprises.
Andrew M. Kuchling00e0f212001-01-17 15:23:23259 #
260
261 # Multimedia modules
262 # These don't work for 64-bit platforms!!!
263 # These represent audio samples or images as strings:
264
Fredrik Lundhade711a2001-01-24 08:00:28265 # Disabled on 64-bit platforms
Andrew M. Kuchling00e0f212001-01-17 15:23:23266 if sys.maxint != 9223372036854775807L:
267 # Operations on audio samples
268 exts.append( Extension('audioop', ['audioop.c']) )
269 # Operations on images
270 exts.append( Extension('imageop', ['imageop.c']) )
271 # Read SGI RGB image files (but coded portably)
272 exts.append( Extension('rgbimg', ['rgbimgmodule.c']) )
273
274 # readline
Marc-André Lemburg2efc3232001-01-26 18:23:02275 if self.compiler.find_library_file(lib_dirs, 'readline'):
276 readline_libs = ['readline']
277 if self.compiler.find_library_file(lib_dirs +
278 ['/usr/lib/termcap'],
279 'termcap'):
280 readline_libs.append('termcap')
Andrew M. Kuchling00e0f212001-01-17 15:23:23281 exts.append( Extension('readline', ['readline.c'],
Marc-André Lemburg7c6fcda2001-01-26 18:03:24282 library_dirs=['/usr/lib/termcap'],
Marc-André Lemburg2efc3232001-01-26 18:23:02283 libraries=readline_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23284
285 # The crypt module is now disabled by default because it breaks builds
286 # on many systems (where -lcrypt is needed), e.g. Linux (I believe).
287
288 if self.compiler.find_library_file(lib_dirs, 'crypt'):
289 libs = ['crypt']
290 else:
291 libs = []
292 exts.append( Extension('crypt', ['cryptmodule.c'], libraries=libs) )
293
294 # socket(2)
295 # Detect SSL support for the socket module
Andrew M. Kuchlingfbe73762001-01-18 18:44:20296 ssl_incs = find_file('openssl/ssl.h', inc_dirs,
Andrew M. Kuchlinge7c87322001-01-19 16:58:21297 ['/usr/local/ssl/include',
298 '/usr/contrib/ssl/include/'
299 ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:20300 )
301 ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs,
Andrew M. Kuchlinge7c87322001-01-19 16:58:21302 ['/usr/local/ssl/lib',
303 '/usr/contrib/ssl/lib/'
304 ] )
Fredrik Lundhade711a2001-01-24 08:00:28305
Barry Warsaw3c7a3ab2003-08-15 18:18:04306 krb5_h = find_file('krb5.h', inc_dirs,
307 ['/usr/kerberos/include'])
308 if krb5_h:
309 ssl_incs += krb5_h
310
311 if ssl_incs is not None and ssl_libs is not None:
Andrew M. Kuchling00e0f212001-01-17 15:23:23312 exts.append( Extension('_socket', ['socketmodule.c'],
Andrew M. Kuchlingfbe73762001-01-18 18:44:20313 include_dirs = ssl_incs,
Fredrik Lundhade711a2001-01-24 08:00:28314 library_dirs = ssl_libs,
Andrew M. Kuchling00e0f212001-01-17 15:23:23315 libraries = ['ssl', 'crypto'],
316 define_macros = [('USE_SSL',1)] ) )
317 else:
318 exts.append( Extension('_socket', ['socketmodule.c']) )
319
320 # Modules that provide persistent dictionary-like semantics. You will
321 # probably want to arrange for at least one of them to be available on
322 # your machine, though none are defined by default because of library
323 # dependencies. The Python module anydbm.py provides an
324 # implementation independent wrapper for these; dumbdbm.py provides
325 # similar functionality (but slower of course) implemented in Python.
326
327 # The standard Unix dbm module:
Andrew M. Kuchling34febf52001-01-24 03:31:07328 if platform not in ['cygwin']:
329 if (self.compiler.find_library_file(lib_dirs, 'ndbm')):
330 exts.append( Extension('dbm', ['dbmmodule.c'],
331 libraries = ['ndbm'] ) )
332 else:
333 exts.append( Extension('dbm', ['dbmmodule.c']) )
Fredrik Lundhade711a2001-01-24 08:00:28334
Andrew M. Kuchling00e0f212001-01-17 15:23:23335 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
336 if (self.compiler.find_library_file(lib_dirs, 'gdbm')):
337 exts.append( Extension('gdbm', ['gdbmmodule.c'],
338 libraries = ['gdbm'] ) )
339
340 # Berkeley DB interface.
341 #
342 # This requires the Berkeley DB code, see
343 # ftp://ftp.cs.berkeley.edu/pub/4bsd/db.1.85.tar.gz
344 #
345 # Edit the variables DB and DBPORT to point to the db top directory
346 # and the subdirectory of PORT where you built it.
347 #
348 # (See http://electricrain.com/greg/python/bsddb3/ for an interface to
349 # BSD DB 3.x.)
350
Andrew M. Kuchlinge06337a2001-02-23 16:27:48351 dblib = []
352 if self.compiler.find_library_file(lib_dirs, 'db'):
353 dblib = ['db']
354
355 db185_incs = find_file('db_185.h', inc_dirs,
356 ['/usr/include/db3', '/usr/include/db2'])
357 db_inc = find_file('db.h', inc_dirs, ['/usr/include/db1'])
358 if db185_incs is not None:
Andrew M. Kuchling00e0f212001-01-17 15:23:23359 exts.append( Extension('bsddb', ['bsddbmodule.c'],
Andrew M. Kuchlinge06337a2001-02-23 16:27:48360 include_dirs = db185_incs,
361 define_macros=[('HAVE_DB_185_H',1)],
362 libraries = dblib ) )
363 elif db_inc is not None:
364 exts.append( Extension('bsddb', ['bsddbmodule.c'],
365 include_dirs = db_inc,
366 libraries = dblib) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23367
368 # The mpz module interfaces to the GNU Multiple Precision library.
Fredrik Lundhade711a2001-01-24 08:00:28369 # You need to ftp the GNU MP library.
Andrew M. Kuchling00e0f212001-01-17 15:23:23370 # This was originally written and tested against GMP 1.2 and 1.3.2.
371 # It has been modified by Rob Hooft to work with 2.0.2 as well, but I
372 # haven't tested it recently. For a more complete module,
373 # refer to pympz.sourceforge.net.
374
375 # A compatible MP library unencombered by the GPL also exists. It was
376 # posted to comp.sources.misc in volume 40 and is widely available from
377 # FTP archive sites. One URL for it is:
378 # ftp://gatekeeper.dec.com/.b/usenet/comp.sources.misc/volume40/fgmp/part01.Z
379
Andrew M. Kuchling00e0f212001-01-17 15:23:23380 if (self.compiler.find_library_file(lib_dirs, 'gmp')):
381 exts.append( Extension('mpz', ['mpzmodule.c'],
382 libraries = ['gmp'] ) )
383
384
385 # Unix-only modules
Andrew M. Kuchling34febf52001-01-24 03:31:07386 if platform not in ['mac', 'win32']:
Andrew M. Kuchling00e0f212001-01-17 15:23:23387 # Steen Lumholt's termios module
388 exts.append( Extension('termios', ['termios.c']) )
389 # Jeremy Hylton's rlimit interface
Andrew M. Kuchling34febf52001-01-24 03:31:07390 if platform not in ['cygwin']:
391 exts.append( Extension('resource', ['resource.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23392
Andrew M. Kuchlingcf393f32001-02-21 02:38:24393 # Generic dynamic loading module
Andrew M. Kuchling5dfa1372001-03-02 06:24:14394 #exts.append( Extension('dl', ['dlmodule.c']) )
Andrew M. Kuchlingcf393f32001-02-21 02:38:24395
396 # Sun yellow pages. Some systems have the functions in libc.
Andrew M. Kuchling6efc6e72001-02-27 20:54:23397 if platform not in ['cygwin']:
398 if (self.compiler.find_library_file(lib_dirs, 'nsl')):
399 libs = ['nsl']
400 else:
401 libs = []
402 exts.append( Extension('nis', ['nismodule.c'],
403 libraries = libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23404
405 # Curses support, requring the System V version of curses, often
Fredrik Lundhade711a2001-01-24 08:00:28406 # provided by the ncurses library.
Andrew M. Kuchling34febf52001-01-24 03:31:07407 if platform == 'sunos4':
Andrew M. Kuchlingb69c7582001-02-28 19:49:57408 inc_dirs += ['/usr/5include']
Andrew M. Kuchling00e0f212001-01-17 15:23:23409 lib_dirs += ['/usr/5lib']
410
411 if (self.compiler.find_library_file(lib_dirs, 'ncurses')):
412 curses_libs = ['ncurses']
413 exts.append( Extension('_curses', ['_cursesmodule.c'],
414 libraries = curses_libs) )
Jack Jansencec94a52001-12-27 21:51:02415 elif (self.compiler.find_library_file(lib_dirs, 'curses')) and platform[:6] != 'darwin':
Anthony Baxtere6370742001-12-05 06:55:46416 # OSX has an old Berkeley curses, not good enough for the _curses module.
Andrew M. Kuchling00e0f212001-01-17 15:23:23417 if (self.compiler.find_library_file(lib_dirs, 'terminfo')):
418 curses_libs = ['curses', 'terminfo']
419 else:
420 curses_libs = ['curses', 'termcap']
Fredrik Lundhade711a2001-01-24 08:00:28421
Andrew M. Kuchling00e0f212001-01-17 15:23:23422 exts.append( Extension('_curses', ['_cursesmodule.c'],
423 libraries = curses_libs) )
Fredrik Lundhade711a2001-01-24 08:00:28424
Andrew M. Kuchling00e0f212001-01-17 15:23:23425 # If the curses module is enabled, check for the panel module
426 if (os.path.exists('Modules/_curses_panel.c') and
427 module_enabled(exts, '_curses') and
428 self.compiler.find_library_file(lib_dirs, 'panel')):
429 exts.append( Extension('_curses_panel', ['_curses_panel.c'],
430 libraries = ['panel'] + curses_libs) )
Fredrik Lundhade711a2001-01-24 08:00:28431
432
Andrew M. Kuchling00e0f212001-01-17 15:23:23433
434 # Lee Busby's SIGFPE modules.
435 # The library to link fpectl with is platform specific.
436 # Choose *one* of the options below for fpectl:
437
Andrew M. Kuchling34febf52001-01-24 03:31:07438 if platform == 'irix5':
Andrew M. Kuchling00e0f212001-01-17 15:23:23439 # For SGI IRIX (tested on 5.3):
440 exts.append( Extension('fpectl', ['fpectlmodule.c'],
441 libraries=['fpe']) )
Andrew M. Kuchlingfbe73762001-01-18 18:44:20442 elif 0: # XXX how to detect SunPro?
Andrew M. Kuchling00e0f212001-01-17 15:23:23443 # For Solaris with SunPro compiler (tested on Solaris 2.5 with SunPro C 4.2):
444 # (Without the compiler you don't have -lsunmath.)
445 #fpectl fpectlmodule.c -R/opt/SUNWspro/lib -lsunmath -lm
446 pass
447 else:
448 # For other systems: see instructions in fpectlmodule.c.
449 #fpectl fpectlmodule.c ...
450 exts.append( Extension('fpectl', ['fpectlmodule.c']) )
451
452
453 # Andrew Kuchling's zlib module.
454 # This require zlib 1.1.3 (or later).
455 # See http://www.cdrom.com/pub/infozip/zlib/
Guido van Rossume6970912001-04-15 15:16:12456 zlib_inc = find_file('zlib.h', [], inc_dirs)
457 if zlib_inc is not None:
458 zlib_h = zlib_inc[0] + '/zlib.h'
459 version = '"0.0.0"'
460 version_req = '"1.1.3"'
461 fp = open(zlib_h)
462 while 1:
463 line = fp.readline()
464 if not line:
465 break
466 if line.find('#define ZLIB_VERSION', 0) == 0:
467 version = line.split()[2]
468 break
469 if version >= version_req:
470 if (self.compiler.find_library_file(lib_dirs, 'z')):
471 exts.append( Extension('zlib', ['zlibmodule.c'],
472 libraries = ['z']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23473
474 # Interface to the Expat XML parser
475 #
476 # Expat is written by James Clark and must be downloaded separately
477 # (see below). The pyexpat module was written by Paul Prescod after a
478 # prototype by Jack Jansen.
479 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34480 # The Expat dist includes Windows .lib and .dll files. Home page is
481 # at http://www.jclark.com/xml/expat.html, the current production
482 # release is always ftp://ftp.jclark.com/pub/xml/expat.zip.
Andrew M. Kuchling00e0f212001-01-17 15:23:23483 #
484 # EXPAT_DIR, below, should point to the expat/ directory created by
485 # unpacking the Expat source distribution.
486 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34487 # Note: the expat build process doesn't yet build a libexpat.a; you
488 # can do this manually while we try convince the author to add it. To
489 # do so, cd to EXPAT_DIR, run "make" if you have not done so, then
490 # run:
Andrew M. Kuchling00e0f212001-01-17 15:23:23491 #
492 # ar cr libexpat.a xmltok/*.o xmlparse/*.o
493 #
Andrew M. Kuchlingfbe73762001-01-18 18:44:20494 expat_defs = []
495 expat_incs = find_file('expat.h', inc_dirs, [])
496 if expat_incs is not None:
497 # expat.h was found
498 expat_defs = [('HAVE_EXPAT_H', 1)]
499 else:
500 expat_incs = find_file('xmlparse.h', inc_dirs, [])
Fredrik Lundhade711a2001-01-24 08:00:28501
Martin v. Löwis1ab29b22001-01-21 10:54:52502 if (expat_incs is not None and
Andrew M. Kuchlingfbe73762001-01-18 18:44:20503 self.compiler.find_library_file(lib_dirs, 'expat')):
504 exts.append( Extension('pyexpat', ['pyexpat.c'],
505 define_macros = expat_defs,
506 libraries = ['expat']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23507
508 # Platform-specific libraries
Andrew M. Kuchling34febf52001-01-24 03:31:07509 if platform == 'linux2':
Andrew M. Kuchling00e0f212001-01-17 15:23:23510 # Linux-specific modules
511 exts.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) )
512
Andrew M. Kuchling34febf52001-01-24 03:31:07513 if platform == 'sunos5':
Fredrik Lundhade711a2001-01-24 08:00:28514 # SunOS specific modules
Andrew M. Kuchling00e0f212001-01-17 15:23:23515 exts.append( Extension('sunaudiodev', ['sunaudiodev.c']) )
516
Andrew M. Kuchlingfbe73762001-01-18 18:44:20517 self.extensions.extend(exts)
518
519 # Call the method for detecting whether _tkinter can be compiled
520 self.detect_tkinter(inc_dirs, lib_dirs)
Fredrik Lundhade711a2001-01-24 08:00:28521
Andrew M. Kuchlingfbe73762001-01-18 18:44:20522
523 def detect_tkinter(self, inc_dirs, lib_dirs):
Andrew M. Kuchling00e0f212001-01-17 15:23:23524 # The _tkinter module.
Martin v. Löwisb1d19692001-03-21 07:44:53525
Andrew M. Kuchlingfbe73762001-01-18 18:44:20526 # Assume we haven't found any of the libraries or include files
527 tcllib = tklib = tcl_includes = tk_includes = None
Andrew M. Kuchlingd5c43062001-01-17 15:59:25528 for version in ['8.4', '8.3', '8.2', '8.1', '8.0']:
Andrew M. Kuchlingfbe73762001-01-18 18:44:20529 tklib = self.compiler.find_library_file(lib_dirs,
530 'tk' + version )
531 tcllib = self.compiler.find_library_file(lib_dirs,
532 'tcl' + version )
Fredrik Lundhade711a2001-01-24 08:00:28533 if tklib and tcllib:
Andrew M. Kuchling00e0f212001-01-17 15:23:23534 # Exit the loop when we've found the Tcl/Tk libraries
535 break
Andrew M. Kuchling00e0f212001-01-17 15:23:23536
Fredrik Lundhade711a2001-01-24 08:00:28537 # Now check for the header files
Andrew M. Kuchlingfbe73762001-01-18 18:44:20538 if tklib and tcllib:
539 # Check for the include files on Debian, where
540 # they're put in /usr/include/{tcl,tk}X.Y
Andrew M. Kuchling9a3fd8c2001-02-06 22:15:27541 debian_tcl_include = [ '/usr/include/tcl' + version ]
542 debian_tk_include = [ '/usr/include/tk' + version ] + debian_tcl_include
543 tcl_includes = find_file('tcl.h', inc_dirs, debian_tcl_include)
544 tk_includes = find_file('tk.h', inc_dirs, debian_tk_include)
Andrew M. Kuchling00e0f212001-01-17 15:23:23545
Andrew M. Kuchlingfbe73762001-01-18 18:44:20546 if (tcllib is None or tklib is None and
547 tcl_includes is None or tk_includes is None):
548 # Something's missing, so give up
549 return
Fredrik Lundhade711a2001-01-24 08:00:28550
Andrew M. Kuchlingfbe73762001-01-18 18:44:20551 # OK... everything seems to be present for Tcl/Tk.
Andrew M. Kuchling00e0f212001-01-17 15:23:23552
Andrew M. Kuchlingfbe73762001-01-18 18:44:20553 include_dirs = [] ; libs = [] ; defs = [] ; added_lib_dirs = []
554 for dir in tcl_includes + tk_includes:
555 if dir not in include_dirs:
556 include_dirs.append(dir)
Fredrik Lundhade711a2001-01-24 08:00:28557
Andrew M. Kuchlingfbe73762001-01-18 18:44:20558 # Check for various platform-specific directories
Andrew M. Kuchling34febf52001-01-24 03:31:07559 platform = self.get_platform()
560 if platform == 'sunos5':
Andrew M. Kuchlingfbe73762001-01-18 18:44:20561 include_dirs.append('/usr/openwin/include')
562 added_lib_dirs.append('/usr/openwin/lib')
563 elif os.path.exists('/usr/X11R6/include'):
564 include_dirs.append('/usr/X11R6/include')
565 added_lib_dirs.append('/usr/X11R6/lib')
566 elif os.path.exists('/usr/X11R5/include'):
567 include_dirs.append('/usr/X11R5/include')
568 added_lib_dirs.append('/usr/X11R5/lib')
569 else:
Fredrik Lundhade711a2001-01-24 08:00:28570 # Assume default location for X11
Andrew M. Kuchlingfbe73762001-01-18 18:44:20571 include_dirs.append('/usr/X11/include')
572 added_lib_dirs.append('/usr/X11/lib')
Andrew M. Kuchling00e0f212001-01-17 15:23:23573
Andrew M. Kuchlingfbe73762001-01-18 18:44:20574 # Check for BLT extension
575 if self.compiler.find_library_file(lib_dirs + added_lib_dirs, 'BLT8.0'):
576 defs.append( ('WITH_BLT', 1) )
577 libs.append('BLT8.0')
Andrew M. Kuchling00e0f212001-01-17 15:23:23578
Andrew M. Kuchlingfbe73762001-01-18 18:44:20579 # Add the Tcl/Tk libraries
Fredrik Lundhade711a2001-01-24 08:00:28580 libs.append('tk'+version)
Andrew M. Kuchlingfbe73762001-01-18 18:44:20581 libs.append('tcl'+version)
Fredrik Lundhade711a2001-01-24 08:00:28582
Andrew M. Kuchling34febf52001-01-24 03:31:07583 if platform in ['aix3', 'aix4']:
Andrew M. Kuchlingfbe73762001-01-18 18:44:20584 libs.append('ld')
Andrew M. Kuchling00e0f212001-01-17 15:23:23585
Andrew M. Kuchlingfbe73762001-01-18 18:44:20586 # Finally, link with the X11 libraries
587 libs.append('X11')
Andrew M. Kuchling00e0f212001-01-17 15:23:23588
Andrew M. Kuchlingfbe73762001-01-18 18:44:20589 ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
590 define_macros=[('WITH_APPINIT', 1)] + defs,
591 include_dirs = include_dirs,
592 libraries = libs,
593 library_dirs = added_lib_dirs,
594 )
595 self.extensions.append(ext)
Fredrik Lundhade711a2001-01-24 08:00:28596
Andrew M. Kuchlingfbe73762001-01-18 18:44:20597 # XXX handle these, but how to detect?
Andrew M. Kuchling00e0f212001-01-17 15:23:23598 # *** Uncomment and edit for PIL (TkImaging) extension only:
Fredrik Lundhade711a2001-01-24 08:00:28599 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23600 # *** Uncomment and edit for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28601 # -DWITH_TOGL togl.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23602 # *** Uncomment these for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28603 # -lGL -lGLU -lXext -lXmu \
Andrew M. Kuchling00e0f212001-01-17 15:23:23604
Andrew M. Kuchling00e0f212001-01-17 15:23:23605def main():
606 setup(name = 'Python standard library',
Neil Schemenauere7e2ece2001-01-17 21:58:00607 version = '%d.%d' % sys.version_info[:2],
Andrew M. Kuchling00e0f212001-01-17 15:23:23608 cmdclass = {'build_ext':PyBuildExt},
609 # The struct module is defined here, because build_ext won't be
610 # called unless there's at least one extension module defined.
Andrew M. Kuchlingaece4272001-02-28 20:56:49611 ext_modules=[Extension('struct', ['structmodule.c'])],
612
613 # Scripts to install
614 scripts = ['Tools/scripts/pydoc']
Andrew M. Kuchling00e0f212001-01-17 15:23:23615 )
Fredrik Lundhade711a2001-01-24 08:00:28616
Andrew M. Kuchling00e0f212001-01-17 15:23:23617# --install-platlib
618if __name__ == '__main__':
619 sysconfig.set_python_build()
620 main()