blob: cb78091bc5055289bc92bef4aa4c4cd97c44235b [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
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +000011from distutils.errors import *
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000012from distutils.core import Extension, setup
13from distutils.command.build_ext import build_ext
14
15# This global variable is used to hold the list of modules to be disabled.
16disabled_module_list = []
17
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000018def find_file(filename, std_dirs, paths):
19 """Searches for the directory where a given file is located,
20 and returns a possibly-empty list of additional directories, or None
21 if the file couldn't be found at all.
Fredrik Lundhade711a2001-01-24 08:00:28 +000022
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000023 'filename' is the name of a file, such as readline.h or libcrypto.a.
24 'std_dirs' is the list of standard system directories; if the
25 file is found in one of them, no additional directives are needed.
26 'paths' is a list of additional locations to check; if the file is
27 found in one of them, the resulting list will contain the directory.
28 """
29
30 # Check the standard locations
31 for dir in std_dirs:
32 f = os.path.join(dir, filename)
33 if os.path.exists(f): return []
34
35 # Check the additional directories
36 for dir in paths:
37 f = os.path.join(dir, filename)
38 if os.path.exists(f):
39 return [dir]
40
41 # Not found anywhere
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000042 return None
43
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000044def find_library_file(compiler, libname, std_dirs, paths):
45 filename = compiler.library_filename(libname, lib_type='shared')
46 result = find_file(filename, std_dirs, paths)
47 if result is not None: return result
Fredrik Lundhade711a2001-01-24 08:00:28 +000048
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000049 filename = compiler.library_filename(libname, lib_type='static')
50 result = find_file(filename, std_dirs, paths)
51 return result
52
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000053def module_enabled(extlist, modname):
54 """Returns whether the module 'modname' is present in the list
55 of extensions 'extlist'."""
56 extlist = [ext for ext in extlist if ext.name == modname]
57 return len(extlist)
Fredrik Lundhade711a2001-01-24 08:00:28 +000058
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000059class PyBuildExt(build_ext):
Fredrik Lundhade711a2001-01-24 08:00:28 +000060
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000061 def build_extensions(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000062
63 # Detect which modules should be compiled
64 self.detect_modules()
65
66 # Remove modules that are present on the disabled list
67 self.extensions = [ext for ext in self.extensions
68 if ext.name not in disabled_module_list]
Fredrik Lundhade711a2001-01-24 08:00:28 +000069
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000070 # Fix up the autodetected modules, prefixing all the source files
71 # with Modules/ and adding Python's include directory to the path.
72 (srcdir,) = sysconfig.get_config_vars('srcdir')
73
Neil Schemenauer726b78e2001-01-24 17:18:21 +000074 # Figure out the location of the source code for extension modules
75 moddir = os.path.join(os.getcwd(), srcdir, 'Modules')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000076 moddir = os.path.normpath(moddir)
77 srcdir, tail = os.path.split(moddir)
78 srcdir = os.path.normpath(srcdir)
79 moddir = os.path.normpath(moddir)
80
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000081 for ext in self.extensions[:]:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000082 ext.sources = [ os.path.join(moddir, filename)
83 for filename in ext.sources ]
84 ext.include_dirs.append( '.' ) # to get config.h
Andrew M. Kuchlinge3d6e412001-01-19 02:50:34 +000085 ext.include_dirs.append( os.path.join(srcdir, './Include') )
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000086
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +000087 # If a module has already been built statically,
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000088 # don't build it here
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +000089 if ext.name in sys.builtin_module_names:
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000090 self.extensions.remove(ext)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +000091
92 # When you run "make CC=altcc" or something similar, you really want
93 # those environment variables passed into the setup.py phase. Here's
94 # a small set of useful ones.
95 compiler = os.environ.get('CC')
96 linker_so = os.environ.get('LDSHARED')
97 args = {}
98 # unfortunately, distutils doesn't let us provide separate C and C++
99 # compilers
100 if compiler is not None:
101 args['compiler_so'] = compiler
102 if linker_so is not None:
103 args['linker_so'] = linker_so + ' -shared'
104 self.compiler.set_executables(**args)
105
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000106 build_ext.build_extensions(self)
107
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000108 def build_extension(self, ext):
109
110 try:
111 build_ext.build_extension(self, ext)
112 except (CCompilerError, DistutilsError), why:
113 self.announce('WARNING: building of extension "%s" failed: %s' %
114 (ext.name, sys.exc_info()[1]))
115
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000116 def get_platform (self):
Fredrik Lundhade711a2001-01-24 08:00:28 +0000117 # Get value of sys.platform
118 platform = sys.platform
119 if platform[:6] =='cygwin':
120 platform = 'cygwin'
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000121
Fredrik Lundhade711a2001-01-24 08:00:28 +0000122 return platform
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000123
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000124 def detect_modules(self):
Fredrik Lundhade711a2001-01-24 08:00:28 +0000125 # Ensure that /usr/local is always used
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000126 if '/usr/local/lib' not in self.compiler.library_dirs:
127 self.compiler.library_dirs.append('/usr/local/lib')
128 if '/usr/local/include' not in self.compiler.include_dirs:
129 self.compiler.include_dirs.append( '/usr/local/include' )
130
131 # lib_dirs and inc_dirs are used to search for files;
132 # if a file is found in one of those directories, it can
133 # be assumed that no additional -I,-L directives are needed.
134 lib_dirs = self.compiler.library_dirs + ['/lib', '/usr/lib']
135 inc_dirs = ['/usr/include'] + self.compiler.include_dirs
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000136 exts = []
137
Fredrik Lundhade711a2001-01-24 08:00:28 +0000138 platform = self.get_platform()
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000139
Fredrik Lundhade711a2001-01-24 08:00:28 +0000140 # Check for MacOS X, which doesn't need libm.a at all
141 math_libs = ['m']
142 if platform == 'Darwin1.2':
143 math_libs = []
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000144
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000145 # XXX Omitted modules: gl, pure, dl, SGI-specific modules
146
147 #
148 # The following modules are all pretty straightforward, and compile
149 # on pretty much any POSIXish platform.
150 #
Fredrik Lundhade711a2001-01-24 08:00:28 +0000151
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000152 # Some modules that are normally always on:
153 exts.append( Extension('regex', ['regexmodule.c', 'regexpr.c']) )
154 exts.append( Extension('pcre', ['pcremodule.c', 'pypcre.c']) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000155
Fred Drake2de74712001-02-01 05:26:54 +0000156 exts.append( Extension('_weakref', ['_weakref.c']) )
Jeremy Hylton5e7cb242001-02-02 18:24:26 +0000157 exts.append( Extension('_symtable', ['symtablemodule.c']) )
Andrew M. Kuchlingd5c43062001-01-17 15:59:25 +0000158 exts.append( Extension('xreadlines', ['xreadlinesmodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000159
160 # array objects
161 exts.append( Extension('array', ['arraymodule.c']) )
162 # complex math library functions
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000163 exts.append( Extension('cmath', ['cmathmodule.c'],
164 libraries=math_libs) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000165
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000166 # math library functions, e.g. sin()
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000167 exts.append( Extension('math', ['mathmodule.c'],
168 libraries=math_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000169 # fast string operations implemented in C
170 exts.append( Extension('strop', ['stropmodule.c']) )
171 # time operations and variables
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000172 exts.append( Extension('time', ['timemodule.c'],
173 libraries=math_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000174 # operator.add() and similar goodies
175 exts.append( Extension('operator', ['operator.c']) )
176 # access to the builtin codecs and codec registry
177 exts.append( Extension('_codecs', ['_codecsmodule.c']) )
Marc-André Lemburg261b8e22001-02-02 12:12:44 +0000178 # Python C API test module
Tim Petersd66595f2001-02-04 03:09:53 +0000179 exts.append( Extension('_testcapi', ['_testcapimodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000180 # static Unicode character database
Marc-André Lemburg14970be2001-01-22 10:38:27 +0000181 exts.append( Extension('unicodedata', ['unicodedata.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000182 # access to ISO C locale support
183 exts.append( Extension('_locale', ['_localemodule.c']) )
184
185 # Modules with some UNIX dependencies -- on by default:
186 # (If you have a really backward UNIX, select and socket may not be
187 # supported...)
188
189 # fcntl(2) and ioctl(2)
190 exts.append( Extension('fcntl', ['fcntlmodule.c']) )
191 # pwd(3)
192 exts.append( Extension('pwd', ['pwdmodule.c']) )
193 # grp(3)
194 exts.append( Extension('grp', ['grpmodule.c']) )
195 # posix (UNIX) errno values
196 exts.append( Extension('errno', ['errnomodule.c']) )
197 # select(2); not on ancient System V
198 exts.append( Extension('select', ['selectmodule.c']) )
199
200 # The md5 module implements the RSA Data Security, Inc. MD5
201 # Message-Digest Algorithm, described in RFC 1321. The necessary files
202 # md5c.c and md5.h are included here.
203 exts.append( Extension('md5', ['md5module.c', 'md5c.c']) )
204
205 # The sha module implements the SHA checksum algorithm.
206 # (NIST's Secure Hash Algorithm.)
207 exts.append( Extension('sha', ['shamodule.c']) )
208
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000209 # Tommy Burnette's 'new' module (creates new empty objects of certain
210 # kinds):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000211 exts.append( Extension('new', ['newmodule.c']) )
212
213 # Helper module for various ascii-encoders
214 exts.append( Extension('binascii', ['binascii.c']) )
215
216 # Fred Drake's interface to the Python parser
217 exts.append( Extension('parser', ['parsermodule.c']) )
218
219 # Digital Creations' cStringIO and cPickle
220 exts.append( Extension('cStringIO', ['cStringIO.c']) )
221 exts.append( Extension('cPickle', ['cPickle.c']) )
222
223 # Memory-mapped files (also works on Win32).
224 exts.append( Extension('mmap', ['mmapmodule.c']) )
225
226 # Lance Ellinghaus's modules:
227 # enigma-inspired encryption
228 exts.append( Extension('rotor', ['rotormodule.c']) )
229 # syslog daemon interface
230 exts.append( Extension('syslog', ['syslogmodule.c']) )
231
232 # George Neville-Neil's timing module:
233 exts.append( Extension('timing', ['timingmodule.c']) )
234
235 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000236 # Here ends the simple stuff. From here on, modules need certain
237 # libraries, are platform-specific, or present other surprises.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000238 #
239
240 # Multimedia modules
241 # These don't work for 64-bit platforms!!!
242 # These represent audio samples or images as strings:
243
Fredrik Lundhade711a2001-01-24 08:00:28 +0000244 # Disabled on 64-bit platforms
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000245 if sys.maxint != 9223372036854775807L:
246 # Operations on audio samples
247 exts.append( Extension('audioop', ['audioop.c']) )
248 # Operations on images
249 exts.append( Extension('imageop', ['imageop.c']) )
250 # Read SGI RGB image files (but coded portably)
251 exts.append( Extension('rgbimg', ['rgbimgmodule.c']) )
252
253 # readline
Marc-André Lemburg2efc3232001-01-26 18:23:02 +0000254 if self.compiler.find_library_file(lib_dirs, 'readline'):
255 readline_libs = ['readline']
256 if self.compiler.find_library_file(lib_dirs +
257 ['/usr/lib/termcap'],
258 'termcap'):
259 readline_libs.append('termcap')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000260 exts.append( Extension('readline', ['readline.c'],
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000261 library_dirs=['/usr/lib/termcap'],
Marc-André Lemburg2efc3232001-01-26 18:23:02 +0000262 libraries=readline_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000263
264 # The crypt module is now disabled by default because it breaks builds
265 # on many systems (where -lcrypt is needed), e.g. Linux (I believe).
266
267 if self.compiler.find_library_file(lib_dirs, 'crypt'):
268 libs = ['crypt']
269 else:
270 libs = []
271 exts.append( Extension('crypt', ['cryptmodule.c'], libraries=libs) )
272
273 # socket(2)
274 # Detect SSL support for the socket module
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000275 ssl_incs = find_file('openssl/ssl.h', inc_dirs,
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +0000276 ['/usr/local/ssl/include',
277 '/usr/contrib/ssl/include/'
278 ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000279 )
280 ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs,
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +0000281 ['/usr/local/ssl/lib',
282 '/usr/contrib/ssl/lib/'
283 ] )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000284
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000285 if (ssl_incs is not None and
286 ssl_libs is not None):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000287 exts.append( Extension('_socket', ['socketmodule.c'],
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000288 include_dirs = ssl_incs,
Fredrik Lundhade711a2001-01-24 08:00:28 +0000289 library_dirs = ssl_libs,
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000290 libraries = ['ssl', 'crypto'],
291 define_macros = [('USE_SSL',1)] ) )
292 else:
293 exts.append( Extension('_socket', ['socketmodule.c']) )
294
295 # Modules that provide persistent dictionary-like semantics. You will
296 # probably want to arrange for at least one of them to be available on
297 # your machine, though none are defined by default because of library
298 # dependencies. The Python module anydbm.py provides an
299 # implementation independent wrapper for these; dumbdbm.py provides
300 # similar functionality (but slower of course) implemented in Python.
301
302 # The standard Unix dbm module:
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000303 if platform not in ['cygwin']:
304 if (self.compiler.find_library_file(lib_dirs, 'ndbm')):
305 exts.append( Extension('dbm', ['dbmmodule.c'],
306 libraries = ['ndbm'] ) )
307 else:
308 exts.append( Extension('dbm', ['dbmmodule.c']) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000309
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000310 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
311 if (self.compiler.find_library_file(lib_dirs, 'gdbm')):
312 exts.append( Extension('gdbm', ['gdbmmodule.c'],
313 libraries = ['gdbm'] ) )
314
315 # Berkeley DB interface.
316 #
317 # This requires the Berkeley DB code, see
318 # ftp://ftp.cs.berkeley.edu/pub/4bsd/db.1.85.tar.gz
319 #
320 # Edit the variables DB and DBPORT to point to the db top directory
321 # and the subdirectory of PORT where you built it.
322 #
323 # (See http://electricrain.com/greg/python/bsddb3/ for an interface to
324 # BSD DB 3.x.)
325
326 # Note: If a db.h file is found by configure, bsddb will be enabled
327 # automatically via Setup.config.in. It only needs to be enabled here
328 # if it is not automatically enabled there; check the generated
329 # Setup.config before enabling it here.
330
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000331 db_incs = find_file('db_185.h', inc_dirs, [])
332 if (db_incs is not None and
333 self.compiler.find_library_file(lib_dirs, 'db') ):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000334 exts.append( Extension('bsddb', ['bsddbmodule.c'],
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000335 include_dirs = db_incs,
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000336 libraries = ['db'] ) )
337
338 # The mpz module interfaces to the GNU Multiple Precision library.
Fredrik Lundhade711a2001-01-24 08:00:28 +0000339 # You need to ftp the GNU MP library.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000340 # This was originally written and tested against GMP 1.2 and 1.3.2.
341 # It has been modified by Rob Hooft to work with 2.0.2 as well, but I
342 # haven't tested it recently. For a more complete module,
343 # refer to pympz.sourceforge.net.
344
345 # A compatible MP library unencombered by the GPL also exists. It was
346 # posted to comp.sources.misc in volume 40 and is widely available from
347 # FTP archive sites. One URL for it is:
348 # ftp://gatekeeper.dec.com/.b/usenet/comp.sources.misc/volume40/fgmp/part01.Z
349
350 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
351 if (self.compiler.find_library_file(lib_dirs, 'gmp')):
352 exts.append( Extension('mpz', ['mpzmodule.c'],
353 libraries = ['gmp'] ) )
354
355
356 # Unix-only modules
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000357 if platform not in ['mac', 'win32']:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000358 # Steen Lumholt's termios module
359 exts.append( Extension('termios', ['termios.c']) )
360 # Jeremy Hylton's rlimit interface
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000361 if platform not in ['cygwin']:
362 exts.append( Extension('resource', ['resource.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000363
364 if (self.compiler.find_library_file(lib_dirs, 'nsl')):
365 exts.append( Extension('nis', ['nismodule.c'],
366 libraries = ['nsl']) )
367
368 # Curses support, requring the System V version of curses, often
Fredrik Lundhade711a2001-01-24 08:00:28 +0000369 # provided by the ncurses library.
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000370 if platform == 'sunos4':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000371 include_dirs += ['/usr/5include']
372 lib_dirs += ['/usr/5lib']
373
374 if (self.compiler.find_library_file(lib_dirs, 'ncurses')):
375 curses_libs = ['ncurses']
376 exts.append( Extension('_curses', ['_cursesmodule.c'],
377 libraries = curses_libs) )
378 elif (self.compiler.find_library_file(lib_dirs, 'curses')):
379 if (self.compiler.find_library_file(lib_dirs, 'terminfo')):
380 curses_libs = ['curses', 'terminfo']
381 else:
382 curses_libs = ['curses', 'termcap']
Fredrik Lundhade711a2001-01-24 08:00:28 +0000383
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000384 exts.append( Extension('_curses', ['_cursesmodule.c'],
385 libraries = curses_libs) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000386
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000387 # If the curses module is enabled, check for the panel module
388 if (os.path.exists('Modules/_curses_panel.c') and
389 module_enabled(exts, '_curses') and
390 self.compiler.find_library_file(lib_dirs, 'panel')):
391 exts.append( Extension('_curses_panel', ['_curses_panel.c'],
392 libraries = ['panel'] + curses_libs) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000393
394
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000395
396 # Lee Busby's SIGFPE modules.
397 # The library to link fpectl with is platform specific.
398 # Choose *one* of the options below for fpectl:
399
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000400 if platform == 'irix5':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000401 # For SGI IRIX (tested on 5.3):
402 exts.append( Extension('fpectl', ['fpectlmodule.c'],
403 libraries=['fpe']) )
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000404 elif 0: # XXX how to detect SunPro?
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000405 # For Solaris with SunPro compiler (tested on Solaris 2.5 with SunPro C 4.2):
406 # (Without the compiler you don't have -lsunmath.)
407 #fpectl fpectlmodule.c -R/opt/SUNWspro/lib -lsunmath -lm
408 pass
409 else:
410 # For other systems: see instructions in fpectlmodule.c.
411 #fpectl fpectlmodule.c ...
412 exts.append( Extension('fpectl', ['fpectlmodule.c']) )
413
414
415 # Andrew Kuchling's zlib module.
416 # This require zlib 1.1.3 (or later).
417 # See http://www.cdrom.com/pub/infozip/zlib/
418 if (self.compiler.find_library_file(lib_dirs, 'z')):
419 exts.append( Extension('zlib', ['zlibmodule.c'],
420 libraries = ['z']) )
421
422 # Interface to the Expat XML parser
423 #
424 # Expat is written by James Clark and must be downloaded separately
425 # (see below). The pyexpat module was written by Paul Prescod after a
426 # prototype by Jack Jansen.
427 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000428 # The Expat dist includes Windows .lib and .dll files. Home page is
429 # at http://www.jclark.com/xml/expat.html, the current production
430 # release is always ftp://ftp.jclark.com/pub/xml/expat.zip.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000431 #
432 # EXPAT_DIR, below, should point to the expat/ directory created by
433 # unpacking the Expat source distribution.
434 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000435 # Note: the expat build process doesn't yet build a libexpat.a; you
436 # can do this manually while we try convince the author to add it. To
437 # do so, cd to EXPAT_DIR, run "make" if you have not done so, then
438 # run:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000439 #
440 # ar cr libexpat.a xmltok/*.o xmlparse/*.o
441 #
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000442 expat_defs = []
443 expat_incs = find_file('expat.h', inc_dirs, [])
444 if expat_incs is not None:
445 # expat.h was found
446 expat_defs = [('HAVE_EXPAT_H', 1)]
447 else:
448 expat_incs = find_file('xmlparse.h', inc_dirs, [])
Fredrik Lundhade711a2001-01-24 08:00:28 +0000449
Martin v. Löwis1ab29b22001-01-21 10:54:52 +0000450 if (expat_incs is not None and
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000451 self.compiler.find_library_file(lib_dirs, 'expat')):
452 exts.append( Extension('pyexpat', ['pyexpat.c'],
453 define_macros = expat_defs,
454 libraries = ['expat']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000455
456 # Platform-specific libraries
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000457 if platform == 'linux2':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000458 # Linux-specific modules
459 exts.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) )
460
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000461 if platform == 'sunos5':
Fredrik Lundhade711a2001-01-24 08:00:28 +0000462 # SunOS specific modules
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000463 exts.append( Extension('sunaudiodev', ['sunaudiodev.c']) )
464
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000465 self.extensions.extend(exts)
466
467 # Call the method for detecting whether _tkinter can be compiled
468 self.detect_tkinter(inc_dirs, lib_dirs)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000469
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000470
471 def detect_tkinter(self, inc_dirs, lib_dirs):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000472 # The _tkinter module.
473 #
474 # The command for _tkinter is long and site specific. Please
475 # uncomment and/or edit those parts as indicated. If you don't have a
476 # specific extension (e.g. Tix or BLT), leave the corresponding line
477 # commented out. (Leave the trailing backslashes in! If you
478 # experience strange errors, you may want to join all uncommented
479 # lines and remove the backslashes -- the backslash interpretation is
480 # done by the shell's "read" command and it may not be implemented on
481 # every system.
482
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000483 # Assume we haven't found any of the libraries or include files
484 tcllib = tklib = tcl_includes = tk_includes = None
Andrew M. Kuchlingd5c43062001-01-17 15:59:25 +0000485 for version in ['8.4', '8.3', '8.2', '8.1', '8.0']:
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000486 tklib = self.compiler.find_library_file(lib_dirs,
487 'tk' + version )
488 tcllib = self.compiler.find_library_file(lib_dirs,
489 'tcl' + version )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000490 if tklib and tcllib:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000491 # Exit the loop when we've found the Tcl/Tk libraries
492 break
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000493
Fredrik Lundhade711a2001-01-24 08:00:28 +0000494 # Now check for the header files
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000495 if tklib and tcllib:
496 # Check for the include files on Debian, where
497 # they're put in /usr/include/{tcl,tk}X.Y
Andrew M. Kuchling9a3fd8c2001-02-06 22:15:27 +0000498 debian_tcl_include = [ '/usr/include/tcl' + version ]
499 debian_tk_include = [ '/usr/include/tk' + version ] + debian_tcl_include
500 tcl_includes = find_file('tcl.h', inc_dirs, debian_tcl_include)
501 tk_includes = find_file('tk.h', inc_dirs, debian_tk_include)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000502
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000503 if (tcllib is None or tklib is None and
504 tcl_includes is None or tk_includes is None):
505 # Something's missing, so give up
506 return
Fredrik Lundhade711a2001-01-24 08:00:28 +0000507
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000508 # OK... everything seems to be present for Tcl/Tk.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000509
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000510 include_dirs = [] ; libs = [] ; defs = [] ; added_lib_dirs = []
511 for dir in tcl_includes + tk_includes:
512 if dir not in include_dirs:
513 include_dirs.append(dir)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000514
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000515 # Check for various platform-specific directories
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000516 platform = self.get_platform()
517 if platform == 'sunos5':
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000518 include_dirs.append('/usr/openwin/include')
519 added_lib_dirs.append('/usr/openwin/lib')
520 elif os.path.exists('/usr/X11R6/include'):
521 include_dirs.append('/usr/X11R6/include')
522 added_lib_dirs.append('/usr/X11R6/lib')
523 elif os.path.exists('/usr/X11R5/include'):
524 include_dirs.append('/usr/X11R5/include')
525 added_lib_dirs.append('/usr/X11R5/lib')
526 else:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000527 # Assume default location for X11
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000528 include_dirs.append('/usr/X11/include')
529 added_lib_dirs.append('/usr/X11/lib')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000530
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000531 # Check for Tix extension
532 if self.compiler.find_library_file(lib_dirs + added_lib_dirs, 'tix4.1.8.0'):
533 defs.append( ('WITH_TIX', 1) )
534 libs.append('tix4.1.8.0')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000535
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000536 # Check for BLT extension
537 if self.compiler.find_library_file(lib_dirs + added_lib_dirs, 'BLT8.0'):
538 defs.append( ('WITH_BLT', 1) )
539 libs.append('BLT8.0')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000540
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000541 # Add the Tcl/Tk libraries
Fredrik Lundhade711a2001-01-24 08:00:28 +0000542 libs.append('tk'+version)
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000543 libs.append('tcl'+version)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000544
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000545 if platform in ['aix3', 'aix4']:
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000546 libs.append('ld')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000547
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000548 # Finally, link with the X11 libraries
549 libs.append('X11')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000550
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000551 ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
552 define_macros=[('WITH_APPINIT', 1)] + defs,
553 include_dirs = include_dirs,
554 libraries = libs,
555 library_dirs = added_lib_dirs,
556 )
557 self.extensions.append(ext)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000558
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000559 # XXX handle these, but how to detect?
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000560 # *** Uncomment and edit for PIL (TkImaging) extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000561 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000562 # *** Uncomment and edit for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000563 # -DWITH_TOGL togl.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000564 # *** Uncomment these for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000565 # -lGL -lGLU -lXext -lXmu \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000566
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000567def main():
568 setup(name = 'Python standard library',
Neil Schemenauere7e2ece2001-01-17 21:58:00 +0000569 version = '%d.%d' % sys.version_info[:2],
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000570 cmdclass = {'build_ext':PyBuildExt},
571 # The struct module is defined here, because build_ext won't be
572 # called unless there's at least one extension module defined.
573 ext_modules=[Extension('struct', ['structmodule.c'])]
574 )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000575
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000576# --install-platlib
577if __name__ == '__main__':
578 sysconfig.set_python_build()
579 main()