blob: 40e65d4176e23dbfdf4855b987620be06c9bff99 [file] [log] [blame]
Andrew M. Kuchling66012fe2001-01-26 21:56:58 +00001# Autodetecting setup.py script for building the Python extensions
2#
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00003# To be fixed:
4# Implement --disable-modules setting
Andrew M. Kuchling66012fe2001-01-26 21:56:58 +00005#
Fredrik Lundhade711a2001-01-24 08:00:28 +00006
Andrew M. Kuchling66012fe2001-01-26 21:56:58 +00007__version__ = "$Revision$"
8
9import sys, os, getopt
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000010from distutils import sysconfig
Andrew M. Kuchling8d7f0862001-02-23 16:32:32 +000011from distutils import text_file
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +000012from distutils.errors import *
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000013from 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:20 +000019def 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:28 +000023
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000024 '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:23 +000043 return None
44
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000045def 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:28 +000049
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000050 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:23 +000054def 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:28 +000059
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000060class PyBuildExt(build_ext):
Fredrik Lundhade711a2001-01-24 08:00:28 +000061
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000062 def build_extensions(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000063
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:28 +000070
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000071 # 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:21 +000075 # 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:23 +000077 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. Kuchlingfbe73762001-01-18 18:44:20 +000082 for ext in self.extensions[:]:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000083 ext.sources = [ os.path.join(moddir, filename)
84 for filename in ext.sources ]
85 ext.include_dirs.append( '.' ) # to get config.h
Andrew M. Kuchlinge3d6e412001-01-19 02:50:34 +000086 ext.include_dirs.append( os.path.join(srcdir, './Include') )
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000087
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +000088 # If a module has already been built statically,
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000089 # don't build it here
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +000090 if ext.name in sys.builtin_module_names:
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000091 self.extensions.remove(ext)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +000092
Andrew M. Kuchling8d7f0862001-02-23 16:32:32 +000093 # Parse Modules/Setup to figure out which modules are turned
94 # on in the file.
95 input = text_file.TextFile('Modules/Setup', join_lines=1)
96 remove_modules = []
97 while 1:
98 line = input.readline()
99 if not line: break
100 line = line.split()
101 remove_modules.append( line[0] )
102 input.close()
103
104 for ext in self.extensions[:]:
105 if ext.name in remove_modules:
106 self.extensions.remove(ext)
107
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000108 # When you run "make CC=altcc" or something similar, you really want
109 # those environment variables passed into the setup.py phase. Here's
110 # a small set of useful ones.
111 compiler = os.environ.get('CC')
112 linker_so = os.environ.get('LDSHARED')
113 args = {}
114 # unfortunately, distutils doesn't let us provide separate C and C++
115 # compilers
116 if compiler is not None:
117 args['compiler_so'] = compiler
118 if linker_so is not None:
119 args['linker_so'] = linker_so + ' -shared'
120 self.compiler.set_executables(**args)
121
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000122 build_ext.build_extensions(self)
123
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000124 def build_extension(self, ext):
125
126 try:
127 build_ext.build_extension(self, ext)
128 except (CCompilerError, DistutilsError), why:
129 self.announce('WARNING: building of extension "%s" failed: %s' %
130 (ext.name, sys.exc_info()[1]))
131
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000132 def get_platform (self):
Fredrik Lundhade711a2001-01-24 08:00:28 +0000133 # Get value of sys.platform
134 platform = sys.platform
135 if platform[:6] =='cygwin':
136 platform = 'cygwin'
Andrew M. Kuchling3c044942001-02-06 23:37:23 +0000137 elif platform[:4] =='beos':
138 platform = 'beos'
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000139
Fredrik Lundhade711a2001-01-24 08:00:28 +0000140 return platform
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000141
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000142 def detect_modules(self):
Fredrik Lundhade711a2001-01-24 08:00:28 +0000143 # Ensure that /usr/local is always used
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000144 if '/usr/local/lib' not in self.compiler.library_dirs:
145 self.compiler.library_dirs.append('/usr/local/lib')
146 if '/usr/local/include' not in self.compiler.include_dirs:
147 self.compiler.include_dirs.append( '/usr/local/include' )
148
149 # lib_dirs and inc_dirs are used to search for files;
150 # if a file is found in one of those directories, it can
151 # be assumed that no additional -I,-L directives are needed.
152 lib_dirs = self.compiler.library_dirs + ['/lib', '/usr/lib']
153 inc_dirs = ['/usr/include'] + self.compiler.include_dirs
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000154 exts = []
155
Fredrik Lundhade711a2001-01-24 08:00:28 +0000156 platform = self.get_platform()
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000157
Fredrik Lundhade711a2001-01-24 08:00:28 +0000158 # Check for MacOS X, which doesn't need libm.a at all
159 math_libs = ['m']
Andrew M. Kuchling3c044942001-02-06 23:37:23 +0000160 if platform in ['Darwin1.2', 'beos']:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000161 math_libs = []
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000162
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000163 # XXX Omitted modules: gl, pure, dl, SGI-specific modules
164
165 #
166 # The following modules are all pretty straightforward, and compile
167 # on pretty much any POSIXish platform.
168 #
Fredrik Lundhade711a2001-01-24 08:00:28 +0000169
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000170 # Some modules that are normally always on:
171 exts.append( Extension('regex', ['regexmodule.c', 'regexpr.c']) )
172 exts.append( Extension('pcre', ['pcremodule.c', 'pypcre.c']) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000173
Fred Drake2de74712001-02-01 05:26:54 +0000174 exts.append( Extension('_weakref', ['_weakref.c']) )
Jeremy Hylton5e7cb242001-02-02 18:24:26 +0000175 exts.append( Extension('_symtable', ['symtablemodule.c']) )
Andrew M. Kuchlingd5c43062001-01-17 15:59:25 +0000176 exts.append( Extension('xreadlines', ['xreadlinesmodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000177
178 # array objects
179 exts.append( Extension('array', ['arraymodule.c']) )
180 # complex math library functions
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000181 exts.append( Extension('cmath', ['cmathmodule.c'],
182 libraries=math_libs) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000183
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000184 # math library functions, e.g. sin()
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000185 exts.append( Extension('math', ['mathmodule.c'],
186 libraries=math_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000187 # fast string operations implemented in C
188 exts.append( Extension('strop', ['stropmodule.c']) )
189 # time operations and variables
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000190 exts.append( Extension('time', ['timemodule.c'],
191 libraries=math_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000192 # operator.add() and similar goodies
193 exts.append( Extension('operator', ['operator.c']) )
194 # access to the builtin codecs and codec registry
195 exts.append( Extension('_codecs', ['_codecsmodule.c']) )
Marc-André Lemburg261b8e22001-02-02 12:12:44 +0000196 # Python C API test module
Tim Petersd66595f2001-02-04 03:09:53 +0000197 exts.append( Extension('_testcapi', ['_testcapimodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000198 # static Unicode character database
Marc-André Lemburg14970be2001-01-22 10:38:27 +0000199 exts.append( Extension('unicodedata', ['unicodedata.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000200 # access to ISO C locale support
201 exts.append( Extension('_locale', ['_localemodule.c']) )
202
203 # Modules with some UNIX dependencies -- on by default:
204 # (If you have a really backward UNIX, select and socket may not be
205 # supported...)
206
207 # fcntl(2) and ioctl(2)
208 exts.append( Extension('fcntl', ['fcntlmodule.c']) )
209 # pwd(3)
210 exts.append( Extension('pwd', ['pwdmodule.c']) )
211 # grp(3)
212 exts.append( Extension('grp', ['grpmodule.c']) )
213 # posix (UNIX) errno values
214 exts.append( Extension('errno', ['errnomodule.c']) )
215 # select(2); not on ancient System V
216 exts.append( Extension('select', ['selectmodule.c']) )
217
218 # The md5 module implements the RSA Data Security, Inc. MD5
219 # Message-Digest Algorithm, described in RFC 1321. The necessary files
220 # md5c.c and md5.h are included here.
221 exts.append( Extension('md5', ['md5module.c', 'md5c.c']) )
222
223 # The sha module implements the SHA checksum algorithm.
224 # (NIST's Secure Hash Algorithm.)
225 exts.append( Extension('sha', ['shamodule.c']) )
226
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000227 # Tommy Burnette's 'new' module (creates new empty objects of certain
228 # kinds):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000229 exts.append( Extension('new', ['newmodule.c']) )
230
231 # Helper module for various ascii-encoders
232 exts.append( Extension('binascii', ['binascii.c']) )
233
234 # Fred Drake's interface to the Python parser
235 exts.append( Extension('parser', ['parsermodule.c']) )
236
237 # Digital Creations' cStringIO and cPickle
238 exts.append( Extension('cStringIO', ['cStringIO.c']) )
239 exts.append( Extension('cPickle', ['cPickle.c']) )
240
241 # Memory-mapped files (also works on Win32).
242 exts.append( Extension('mmap', ['mmapmodule.c']) )
243
244 # Lance Ellinghaus's modules:
245 # enigma-inspired encryption
246 exts.append( Extension('rotor', ['rotormodule.c']) )
247 # syslog daemon interface
248 exts.append( Extension('syslog', ['syslogmodule.c']) )
249
250 # George Neville-Neil's timing module:
251 exts.append( Extension('timing', ['timingmodule.c']) )
252
253 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000254 # Here ends the simple stuff. From here on, modules need certain
255 # libraries, are platform-specific, or present other surprises.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000256 #
257
258 # Multimedia modules
259 # These don't work for 64-bit platforms!!!
260 # These represent audio samples or images as strings:
261
Fredrik Lundhade711a2001-01-24 08:00:28 +0000262 # Disabled on 64-bit platforms
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000263 if sys.maxint != 9223372036854775807L:
264 # Operations on audio samples
265 exts.append( Extension('audioop', ['audioop.c']) )
266 # Operations on images
267 exts.append( Extension('imageop', ['imageop.c']) )
268 # Read SGI RGB image files (but coded portably)
269 exts.append( Extension('rgbimg', ['rgbimgmodule.c']) )
270
271 # readline
Marc-André Lemburg2efc3232001-01-26 18:23:02 +0000272 if self.compiler.find_library_file(lib_dirs, 'readline'):
273 readline_libs = ['readline']
274 if self.compiler.find_library_file(lib_dirs +
275 ['/usr/lib/termcap'],
276 'termcap'):
277 readline_libs.append('termcap')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000278 exts.append( Extension('readline', ['readline.c'],
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000279 library_dirs=['/usr/lib/termcap'],
Marc-André Lemburg2efc3232001-01-26 18:23:02 +0000280 libraries=readline_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000281
282 # The crypt module is now disabled by default because it breaks builds
283 # on many systems (where -lcrypt is needed), e.g. Linux (I believe).
284
285 if self.compiler.find_library_file(lib_dirs, 'crypt'):
286 libs = ['crypt']
287 else:
288 libs = []
289 exts.append( Extension('crypt', ['cryptmodule.c'], libraries=libs) )
290
291 # socket(2)
292 # Detect SSL support for the socket module
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000293 ssl_incs = find_file('openssl/ssl.h', inc_dirs,
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +0000294 ['/usr/local/ssl/include',
295 '/usr/contrib/ssl/include/'
296 ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000297 )
298 ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs,
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +0000299 ['/usr/local/ssl/lib',
300 '/usr/contrib/ssl/lib/'
301 ] )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000302
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000303 if (ssl_incs is not None and
304 ssl_libs is not None):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000305 exts.append( Extension('_socket', ['socketmodule.c'],
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000306 include_dirs = ssl_incs,
Fredrik Lundhade711a2001-01-24 08:00:28 +0000307 library_dirs = ssl_libs,
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000308 libraries = ['ssl', 'crypto'],
309 define_macros = [('USE_SSL',1)] ) )
310 else:
311 exts.append( Extension('_socket', ['socketmodule.c']) )
312
313 # Modules that provide persistent dictionary-like semantics. You will
314 # probably want to arrange for at least one of them to be available on
315 # your machine, though none are defined by default because of library
316 # dependencies. The Python module anydbm.py provides an
317 # implementation independent wrapper for these; dumbdbm.py provides
318 # similar functionality (but slower of course) implemented in Python.
319
320 # The standard Unix dbm module:
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000321 if platform not in ['cygwin']:
322 if (self.compiler.find_library_file(lib_dirs, 'ndbm')):
323 exts.append( Extension('dbm', ['dbmmodule.c'],
324 libraries = ['ndbm'] ) )
325 else:
326 exts.append( Extension('dbm', ['dbmmodule.c']) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000327
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000328 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
329 if (self.compiler.find_library_file(lib_dirs, 'gdbm')):
330 exts.append( Extension('gdbm', ['gdbmmodule.c'],
331 libraries = ['gdbm'] ) )
332
333 # Berkeley DB interface.
334 #
335 # This requires the Berkeley DB code, see
336 # ftp://ftp.cs.berkeley.edu/pub/4bsd/db.1.85.tar.gz
337 #
338 # Edit the variables DB and DBPORT to point to the db top directory
339 # and the subdirectory of PORT where you built it.
340 #
341 # (See http://electricrain.com/greg/python/bsddb3/ for an interface to
342 # BSD DB 3.x.)
343
Andrew M. Kuchlinge06337a2001-02-23 16:27:48 +0000344 dblib = []
345 if self.compiler.find_library_file(lib_dirs, 'db'):
346 dblib = ['db']
347
348 db185_incs = find_file('db_185.h', inc_dirs,
349 ['/usr/include/db3', '/usr/include/db2'])
350 db_inc = find_file('db.h', inc_dirs, ['/usr/include/db1'])
351 if db185_incs is not None:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000352 exts.append( Extension('bsddb', ['bsddbmodule.c'],
Andrew M. Kuchlinge06337a2001-02-23 16:27:48 +0000353 include_dirs = db185_incs,
354 define_macros=[('HAVE_DB_185_H',1)],
355 libraries = dblib ) )
356 elif db_inc is not None:
357 exts.append( Extension('bsddb', ['bsddbmodule.c'],
358 include_dirs = db_inc,
359 libraries = dblib) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000360
361 # The mpz module interfaces to the GNU Multiple Precision library.
Fredrik Lundhade711a2001-01-24 08:00:28 +0000362 # You need to ftp the GNU MP library.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000363 # This was originally written and tested against GMP 1.2 and 1.3.2.
364 # It has been modified by Rob Hooft to work with 2.0.2 as well, but I
365 # haven't tested it recently. For a more complete module,
366 # refer to pympz.sourceforge.net.
367
368 # A compatible MP library unencombered by the GPL also exists. It was
369 # posted to comp.sources.misc in volume 40 and is widely available from
370 # FTP archive sites. One URL for it is:
371 # ftp://gatekeeper.dec.com/.b/usenet/comp.sources.misc/volume40/fgmp/part01.Z
372
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000373 if (self.compiler.find_library_file(lib_dirs, 'gmp')):
374 exts.append( Extension('mpz', ['mpzmodule.c'],
375 libraries = ['gmp'] ) )
376
377
378 # Unix-only modules
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000379 if platform not in ['mac', 'win32']:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000380 # Steen Lumholt's termios module
381 exts.append( Extension('termios', ['termios.c']) )
382 # Jeremy Hylton's rlimit interface
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000383 if platform not in ['cygwin']:
384 exts.append( Extension('resource', ['resource.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000385
Andrew M. Kuchlingcf393f32001-02-21 02:38:24 +0000386 # Generic dynamic loading module
387 exts.append( Extension('dl', ['dlmodule.c']) )
388
389 # Sun yellow pages. Some systems have the functions in libc.
Andrew M. Kuchling6efc6e72001-02-27 20:54:23 +0000390 if platform not in ['cygwin']:
391 if (self.compiler.find_library_file(lib_dirs, 'nsl')):
392 libs = ['nsl']
393 else:
394 libs = []
395 exts.append( Extension('nis', ['nismodule.c'],
396 libraries = libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000397
398 # Curses support, requring the System V version of curses, often
Fredrik Lundhade711a2001-01-24 08:00:28 +0000399 # provided by the ncurses library.
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000400 if platform == 'sunos4':
Andrew M. Kuchlingb69c7582001-02-28 19:49:57 +0000401 inc_dirs += ['/usr/5include']
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000402 lib_dirs += ['/usr/5lib']
403
404 if (self.compiler.find_library_file(lib_dirs, 'ncurses')):
405 curses_libs = ['ncurses']
406 exts.append( Extension('_curses', ['_cursesmodule.c'],
407 libraries = curses_libs) )
408 elif (self.compiler.find_library_file(lib_dirs, 'curses')):
409 if (self.compiler.find_library_file(lib_dirs, 'terminfo')):
410 curses_libs = ['curses', 'terminfo']
411 else:
412 curses_libs = ['curses', 'termcap']
Fredrik Lundhade711a2001-01-24 08:00:28 +0000413
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000414 exts.append( Extension('_curses', ['_cursesmodule.c'],
415 libraries = curses_libs) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000416
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000417 # If the curses module is enabled, check for the panel module
418 if (os.path.exists('Modules/_curses_panel.c') and
419 module_enabled(exts, '_curses') and
420 self.compiler.find_library_file(lib_dirs, 'panel')):
421 exts.append( Extension('_curses_panel', ['_curses_panel.c'],
422 libraries = ['panel'] + curses_libs) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000423
424
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000425
426 # Lee Busby's SIGFPE modules.
427 # The library to link fpectl with is platform specific.
428 # Choose *one* of the options below for fpectl:
429
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000430 if platform == 'irix5':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000431 # For SGI IRIX (tested on 5.3):
432 exts.append( Extension('fpectl', ['fpectlmodule.c'],
433 libraries=['fpe']) )
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000434 elif 0: # XXX how to detect SunPro?
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000435 # For Solaris with SunPro compiler (tested on Solaris 2.5 with SunPro C 4.2):
436 # (Without the compiler you don't have -lsunmath.)
437 #fpectl fpectlmodule.c -R/opt/SUNWspro/lib -lsunmath -lm
438 pass
439 else:
440 # For other systems: see instructions in fpectlmodule.c.
441 #fpectl fpectlmodule.c ...
442 exts.append( Extension('fpectl', ['fpectlmodule.c']) )
443
444
445 # Andrew Kuchling's zlib module.
446 # This require zlib 1.1.3 (or later).
447 # See http://www.cdrom.com/pub/infozip/zlib/
448 if (self.compiler.find_library_file(lib_dirs, 'z')):
449 exts.append( Extension('zlib', ['zlibmodule.c'],
450 libraries = ['z']) )
451
452 # Interface to the Expat XML parser
453 #
454 # Expat is written by James Clark and must be downloaded separately
455 # (see below). The pyexpat module was written by Paul Prescod after a
456 # prototype by Jack Jansen.
457 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000458 # The Expat dist includes Windows .lib and .dll files. Home page is
459 # at http://www.jclark.com/xml/expat.html, the current production
460 # release is always ftp://ftp.jclark.com/pub/xml/expat.zip.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000461 #
462 # EXPAT_DIR, below, should point to the expat/ directory created by
463 # unpacking the Expat source distribution.
464 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000465 # Note: the expat build process doesn't yet build a libexpat.a; you
466 # can do this manually while we try convince the author to add it. To
467 # do so, cd to EXPAT_DIR, run "make" if you have not done so, then
468 # run:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000469 #
470 # ar cr libexpat.a xmltok/*.o xmlparse/*.o
471 #
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000472 expat_defs = []
473 expat_incs = find_file('expat.h', inc_dirs, [])
474 if expat_incs is not None:
475 # expat.h was found
476 expat_defs = [('HAVE_EXPAT_H', 1)]
477 else:
478 expat_incs = find_file('xmlparse.h', inc_dirs, [])
Fredrik Lundhade711a2001-01-24 08:00:28 +0000479
Martin v. Löwis1ab29b22001-01-21 10:54:52 +0000480 if (expat_incs is not None and
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000481 self.compiler.find_library_file(lib_dirs, 'expat')):
482 exts.append( Extension('pyexpat', ['pyexpat.c'],
483 define_macros = expat_defs,
484 libraries = ['expat']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000485
486 # Platform-specific libraries
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000487 if platform == 'linux2':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000488 # Linux-specific modules
489 exts.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) )
490
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000491 if platform == 'sunos5':
Fredrik Lundhade711a2001-01-24 08:00:28 +0000492 # SunOS specific modules
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000493 exts.append( Extension('sunaudiodev', ['sunaudiodev.c']) )
494
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000495 self.extensions.extend(exts)
496
497 # Call the method for detecting whether _tkinter can be compiled
498 self.detect_tkinter(inc_dirs, lib_dirs)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000499
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000500
501 def detect_tkinter(self, inc_dirs, lib_dirs):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000502 # The _tkinter module.
503 #
504 # The command for _tkinter is long and site specific. Please
505 # uncomment and/or edit those parts as indicated. If you don't have a
506 # specific extension (e.g. Tix or BLT), leave the corresponding line
507 # commented out. (Leave the trailing backslashes in! If you
508 # experience strange errors, you may want to join all uncommented
509 # lines and remove the backslashes -- the backslash interpretation is
510 # done by the shell's "read" command and it may not be implemented on
511 # every system.
512
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000513 # Assume we haven't found any of the libraries or include files
514 tcllib = tklib = tcl_includes = tk_includes = None
Andrew M. Kuchlingd5c43062001-01-17 15:59:25 +0000515 for version in ['8.4', '8.3', '8.2', '8.1', '8.0']:
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000516 tklib = self.compiler.find_library_file(lib_dirs,
517 'tk' + version )
518 tcllib = self.compiler.find_library_file(lib_dirs,
519 'tcl' + version )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000520 if tklib and tcllib:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000521 # Exit the loop when we've found the Tcl/Tk libraries
522 break
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000523
Fredrik Lundhade711a2001-01-24 08:00:28 +0000524 # Now check for the header files
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000525 if tklib and tcllib:
526 # Check for the include files on Debian, where
527 # they're put in /usr/include/{tcl,tk}X.Y
Andrew M. Kuchling9a3fd8c2001-02-06 22:15:27 +0000528 debian_tcl_include = [ '/usr/include/tcl' + version ]
529 debian_tk_include = [ '/usr/include/tk' + version ] + debian_tcl_include
530 tcl_includes = find_file('tcl.h', inc_dirs, debian_tcl_include)
531 tk_includes = find_file('tk.h', inc_dirs, debian_tk_include)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000532
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000533 if (tcllib is None or tklib is None and
534 tcl_includes is None or tk_includes is None):
535 # Something's missing, so give up
536 return
Fredrik Lundhade711a2001-01-24 08:00:28 +0000537
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000538 # OK... everything seems to be present for Tcl/Tk.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000539
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000540 include_dirs = [] ; libs = [] ; defs = [] ; added_lib_dirs = []
541 for dir in tcl_includes + tk_includes:
542 if dir not in include_dirs:
543 include_dirs.append(dir)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000544
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000545 # Check for various platform-specific directories
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000546 platform = self.get_platform()
547 if platform == 'sunos5':
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000548 include_dirs.append('/usr/openwin/include')
549 added_lib_dirs.append('/usr/openwin/lib')
550 elif os.path.exists('/usr/X11R6/include'):
551 include_dirs.append('/usr/X11R6/include')
552 added_lib_dirs.append('/usr/X11R6/lib')
553 elif os.path.exists('/usr/X11R5/include'):
554 include_dirs.append('/usr/X11R5/include')
555 added_lib_dirs.append('/usr/X11R5/lib')
556 else:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000557 # Assume default location for X11
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000558 include_dirs.append('/usr/X11/include')
559 added_lib_dirs.append('/usr/X11/lib')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000560
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000561 # Check for Tix extension
562 if self.compiler.find_library_file(lib_dirs + added_lib_dirs, 'tix4.1.8.0'):
563 defs.append( ('WITH_TIX', 1) )
564 libs.append('tix4.1.8.0')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000565
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000566 # Check for BLT extension
567 if self.compiler.find_library_file(lib_dirs + added_lib_dirs, 'BLT8.0'):
568 defs.append( ('WITH_BLT', 1) )
569 libs.append('BLT8.0')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000570
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000571 # Add the Tcl/Tk libraries
Fredrik Lundhade711a2001-01-24 08:00:28 +0000572 libs.append('tk'+version)
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000573 libs.append('tcl'+version)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000574
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000575 if platform in ['aix3', 'aix4']:
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000576 libs.append('ld')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000577
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000578 # Finally, link with the X11 libraries
579 libs.append('X11')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000580
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000581 ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
582 define_macros=[('WITH_APPINIT', 1)] + defs,
583 include_dirs = include_dirs,
584 libraries = libs,
585 library_dirs = added_lib_dirs,
586 )
587 self.extensions.append(ext)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000588
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000589 # XXX handle these, but how to detect?
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000590 # *** Uncomment and edit for PIL (TkImaging) extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000591 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000592 # *** Uncomment and edit for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000593 # -DWITH_TOGL togl.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000594 # *** Uncomment these for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000595 # -lGL -lGLU -lXext -lXmu \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000596
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000597def main():
598 setup(name = 'Python standard library',
Neil Schemenauere7e2ece2001-01-17 21:58:00 +0000599 version = '%d.%d' % sys.version_info[:2],
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000600 cmdclass = {'build_ext':PyBuildExt},
601 # The struct module is defined here, because build_ext won't be
602 # called unless there's at least one extension module defined.
Andrew M. Kuchlingaece4272001-02-28 20:56:49 +0000603 ext_modules=[Extension('struct', ['structmodule.c'])],
604
605 # Scripts to install
606 scripts = ['Tools/scripts/pydoc']
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000607 )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000608
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000609# --install-platlib
610if __name__ == '__main__':
611 sysconfig.set_python_build()
612 main()