blob: ce8d13c17907ceed7baffc64a52115a245921873 [file] [log] [blame]
Andrew M. Kuchling66012fe2001-01-26 21:56:58 +00001# Autodetecting setup.py script for building the Python extensions
2#
Fredrik Lundhade711a2001-01-24 08:00:28 +00003
Andrew M. Kuchling66012fe2001-01-26 21:56:58 +00004__version__ = "$Revision$"
5
Michael W. Hudsonaf142892002-01-23 15:07:46 +00006import sys, os, getopt, imp
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00007from distutils import sysconfig
Andrew M. Kuchling8d7f0862001-02-23 16:32:32 +00008from distutils import text_file
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +00009from distutils.errors import *
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000010from distutils.core import Extension, setup
11from distutils.command.build_ext import build_ext
Andrew M. Kuchlingf52d27e2001-05-21 20:29:27 +000012from distutils.command.install import install
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000013
14# This global variable is used to hold the list of modules to be disabled.
15disabled_module_list = []
16
Michael W. Hudson39230b32002-01-16 15:26:48 +000017def add_dir_to_list(dirlist, dir):
18 """Add the directory 'dir' to the list 'dirlist' (at the front) if
19 1) 'dir' is not already in 'dirlist'
20 2) 'dir' actually exists, and is a directory."""
Jack Jansen4439b7c2002-06-26 15:44:30 +000021 if dir is not None and os.path.isdir(dir) and dir not in dirlist:
Michael W. Hudson39230b32002-01-16 15:26:48 +000022 dirlist.insert(0, dir)
23
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000024def find_file(filename, std_dirs, paths):
25 """Searches for the directory where a given file is located,
26 and returns a possibly-empty list of additional directories, or None
27 if the file couldn't be found at all.
Fredrik Lundhade711a2001-01-24 08:00:28 +000028
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000029 'filename' is the name of a file, such as readline.h or libcrypto.a.
30 'std_dirs' is the list of standard system directories; if the
31 file is found in one of them, no additional directives are needed.
32 'paths' is a list of additional locations to check; if the file is
33 found in one of them, the resulting list will contain the directory.
34 """
35
36 # Check the standard locations
37 for dir in std_dirs:
38 f = os.path.join(dir, filename)
39 if os.path.exists(f): return []
40
41 # Check the additional directories
42 for dir in paths:
43 f = os.path.join(dir, filename)
44 if os.path.exists(f):
45 return [dir]
46
47 # Not found anywhere
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000048 return None
49
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000050def find_library_file(compiler, libname, std_dirs, paths):
51 filename = compiler.library_filename(libname, lib_type='shared')
52 result = find_file(filename, std_dirs, paths)
53 if result is not None: return result
Fredrik Lundhade711a2001-01-24 08:00:28 +000054
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000055 filename = compiler.library_filename(libname, lib_type='static')
56 result = find_file(filename, std_dirs, paths)
57 return result
58
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000059def module_enabled(extlist, modname):
60 """Returns whether the module 'modname' is present in the list
61 of extensions 'extlist'."""
62 extlist = [ext for ext in extlist if ext.name == modname]
63 return len(extlist)
Fredrik Lundhade711a2001-01-24 08:00:28 +000064
Jack Jansen144ebcc2001-08-05 22:31:19 +000065def find_module_file(module, dirlist):
66 """Find a module in a set of possible folders. If it is not found
67 return the unadorned filename"""
68 list = find_file(module, [], dirlist)
69 if not list:
70 return module
71 if len(list) > 1:
72 self.announce("WARNING: multiple copies of %s found"%module)
73 return os.path.join(list[0], module)
Michael W. Hudson5b109102002-01-23 15:04:41 +000074
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000075class PyBuildExt(build_ext):
Fredrik Lundhade711a2001-01-24 08:00:28 +000076
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000077 def build_extensions(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000078
79 # Detect which modules should be compiled
80 self.detect_modules()
81
82 # Remove modules that are present on the disabled list
83 self.extensions = [ext for ext in self.extensions
84 if ext.name not in disabled_module_list]
Fredrik Lundhade711a2001-01-24 08:00:28 +000085
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000086 # Fix up the autodetected modules, prefixing all the source files
87 # with Modules/ and adding Python's include directory to the path.
88 (srcdir,) = sysconfig.get_config_vars('srcdir')
89
Neil Schemenauer726b78e2001-01-24 17:18:21 +000090 # Figure out the location of the source code for extension modules
91 moddir = os.path.join(os.getcwd(), srcdir, 'Modules')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000092 moddir = os.path.normpath(moddir)
93 srcdir, tail = os.path.split(moddir)
94 srcdir = os.path.normpath(srcdir)
95 moddir = os.path.normpath(moddir)
Michael W. Hudson5b109102002-01-23 15:04:41 +000096
Jack Jansen144ebcc2001-08-05 22:31:19 +000097 moddirlist = [moddir]
98 incdirlist = ['./Include']
Michael W. Hudson5b109102002-01-23 15:04:41 +000099
Jack Jansen144ebcc2001-08-05 22:31:19 +0000100 # Platform-dependent module source and include directories
101 platform = self.get_platform()
Jack Jansen4439b7c2002-06-26 15:44:30 +0000102 if platform in ('darwin', 'mac'):
Jack Jansen144ebcc2001-08-05 22:31:19 +0000103 # Mac OS X also includes some mac-specific modules
104 macmoddir = os.path.join(os.getcwd(), srcdir, 'Mac/Modules')
105 moddirlist.append(macmoddir)
106 incdirlist.append('./Mac/Include')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000107
Jeremy Hylton340043e2002-06-13 17:38:11 +0000108 alldirlist = moddirlist + incdirlist
109
Andrew M. Kuchling3da989c2001-02-28 22:49:26 +0000110 # Fix up the paths for scripts, too
111 self.distribution.scripts = [os.path.join(srcdir, filename)
112 for filename in self.distribution.scripts]
113
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000114 for ext in self.extensions[:]:
Jack Jansen144ebcc2001-08-05 22:31:19 +0000115 ext.sources = [ find_module_file(filename, moddirlist)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000116 for filename in ext.sources ]
Jeremy Hylton340043e2002-06-13 17:38:11 +0000117 if ext.depends is not None:
118 ext.depends = [find_module_file(filename, alldirlist)
119 for filename in ext.depends]
Jack Jansen144ebcc2001-08-05 22:31:19 +0000120 ext.include_dirs.append( '.' ) # to get config.h
121 for incdir in incdirlist:
122 ext.include_dirs.append( os.path.join(srcdir, incdir) )
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000123
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +0000124 # If a module has already been built statically,
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000125 # don't build it here
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +0000126 if ext.name in sys.builtin_module_names:
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000127 self.extensions.remove(ext)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000128
Jack Jansen4439b7c2002-06-26 15:44:30 +0000129 if platform != 'mac':
130 # Parse Modules/Setup to figure out which modules are turned
131 # on in the file.
132 input = text_file.TextFile('Modules/Setup', join_lines=1)
133 remove_modules = []
134 while 1:
135 line = input.readline()
136 if not line: break
137 line = line.split()
138 remove_modules.append( line[0] )
139 input.close()
140
141 for ext in self.extensions[:]:
142 if ext.name in remove_modules:
143 self.extensions.remove(ext)
Michael W. Hudson5b109102002-01-23 15:04:41 +0000144
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000145 # When you run "make CC=altcc" or something similar, you really want
146 # those environment variables passed into the setup.py phase. Here's
147 # a small set of useful ones.
148 compiler = os.environ.get('CC')
149 linker_so = os.environ.get('LDSHARED')
150 args = {}
151 # unfortunately, distutils doesn't let us provide separate C and C++
152 # compilers
153 if compiler is not None:
Martin v. Löwis3e4b0e82001-08-10 08:56:17 +0000154 (ccshared,opt) = sysconfig.get_config_vars('CCSHARED','OPT')
155 args['compiler_so'] = compiler + ' ' + opt + ' ' + ccshared
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000156 if linker_so is not None:
Martin v. Löwis2f20dab2001-10-08 13:18:37 +0000157 args['linker_so'] = linker_so
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000158 self.compiler.set_executables(**args)
159
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000160 build_ext.build_extensions(self)
161
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000162 def build_extension(self, ext):
163
164 try:
165 build_ext.build_extension(self, ext)
166 except (CCompilerError, DistutilsError), why:
167 self.announce('WARNING: building of extension "%s" failed: %s' %
168 (ext.name, sys.exc_info()[1]))
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000169 return
Jack Jansenf49c6f92001-11-01 14:44:15 +0000170 # Workaround for Mac OS X: The Carbon-based modules cannot be
171 # reliably imported into a command-line Python
172 if 'Carbon' in ext.extra_link_args:
Michael W. Hudson5b109102002-01-23 15:04:41 +0000173 self.announce(
174 'WARNING: skipping import check for Carbon-based "%s"' %
175 ext.name)
176 return
Jason Tishler24cf7762002-05-22 16:46:15 +0000177 # Workaround for Cygwin: Cygwin currently has fork issues when many
178 # modules have been imported
179 if self.get_platform() == 'cygwin':
180 self.announce('WARNING: skipping import check for Cygwin-based "%s"'
181 % ext.name)
182 return
Michael W. Hudsonaf142892002-01-23 15:07:46 +0000183 ext_filename = os.path.join(
184 self.build_lib,
185 self.get_ext_filename(self.get_ext_fullname(ext.name)))
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000186 try:
Michael W. Hudsonaf142892002-01-23 15:07:46 +0000187 imp.load_dynamic(ext.name, ext_filename)
Marc-André Lemburga5d2b4c2002-02-16 18:23:30 +0000188 except ImportError, why:
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000189
Marc-André Lemburga5d2b4c2002-02-16 18:23:30 +0000190 if 1:
Michael W. Hudson7113d962002-03-01 14:16:31 +0000191 self.announce('*** WARNING: renaming "%s" since importing it'
Marc-André Lemburga5d2b4c2002-02-16 18:23:30 +0000192 ' failed: %s' % (ext.name, why))
193 assert not self.inplace
Michael W. Hudson7113d962002-03-01 14:16:31 +0000194 basename, tail = os.path.splitext(ext_filename)
195 newname = basename + "_failed" + tail
196 if os.path.exists(newname): os.remove(newname)
197 os.rename(ext_filename, newname)
Marc-André Lemburga5d2b4c2002-02-16 18:23:30 +0000198
199 # XXX -- This relies on a Vile HACK in
200 # distutils.command.build_ext.build_extension(). The
201 # _built_objects attribute is stored there strictly for
202 # use here.
Neal Norwitz03ffbcd2002-03-25 14:20:09 +0000203 # If there is a failure, _built_objects may not be there,
204 # so catch the AttributeError and move on.
205 try:
206 for filename in self._built_objects:
207 os.remove(filename)
208 except AttributeError:
209 self.announce('unable to remove files (ignored)')
Marc-André Lemburga5d2b4c2002-02-16 18:23:30 +0000210 else:
211 self.announce('*** WARNING: importing extension "%s" '
212 'failed: %s' % (ext.name, why))
Fred Drake9028d0a2001-12-06 22:59:54 +0000213
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000214 def get_platform (self):
Fredrik Lundhade711a2001-01-24 08:00:28 +0000215 # Get value of sys.platform
216 platform = sys.platform
217 if platform[:6] =='cygwin':
218 platform = 'cygwin'
Andrew M. Kuchling3c044942001-02-06 23:37:23 +0000219 elif platform[:4] =='beos':
220 platform = 'beos'
Jack Jansen244e7612001-12-05 15:54:29 +0000221 elif platform[:6] == 'darwin':
222 platform = 'darwin'
Martin v. Löwisf90ae202002-06-11 06:22:31 +0000223 elif platform[:6] == 'atheos':
224 platform = 'atheos'
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000225
Fredrik Lundhade711a2001-01-24 08:00:28 +0000226 return platform
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000227
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000228 def detect_modules(self):
Fredrik Lundhade711a2001-01-24 08:00:28 +0000229 # Ensure that /usr/local is always used
Michael W. Hudson39230b32002-01-16 15:26:48 +0000230 add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
231 add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
232
233 add_dir_to_list(self.compiler.library_dirs,
234 sysconfig.get_config_var("LIBDIR"))
235 add_dir_to_list(self.compiler.include_dirs,
236 sysconfig.get_config_var("INCLUDEDIR"))
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000237
Martin v. Löwis339d0f72001-08-17 18:39:25 +0000238 try:
239 have_unicode = unicode
240 except NameError:
241 have_unicode = 0
242
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000243 # lib_dirs and inc_dirs are used to search for files;
244 # if a file is found in one of those directories, it can
245 # be assumed that no additional -I,-L directives are needed.
246 lib_dirs = self.compiler.library_dirs + ['/lib', '/usr/lib']
Michael W. Hudson5b109102002-01-23 15:04:41 +0000247 inc_dirs = self.compiler.include_dirs + ['/usr/include']
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000248 exts = []
249
Fredrik Lundhade711a2001-01-24 08:00:28 +0000250 platform = self.get_platform()
Martin v. Löwis83012562002-02-14 01:25:37 +0000251 (srcdir,) = sysconfig.get_config_vars('srcdir')
Michael W. Hudson5b109102002-01-23 15:04:41 +0000252
Martin v. Löwisf90ae202002-06-11 06:22:31 +0000253 # Check for AtheOS which has libraries in non-standard locations
254 if platform == 'atheos':
255 lib_dirs += ['/system/libs', '/atheos/autolnk/lib']
256 lib_dirs += os.getenv('LIBRARY_PATH', '').split(os.pathsep)
257 inc_dirs += ['/system/include', '/atheos/autolnk/include']
258 inc_dirs += os.getenv('C_INCLUDE_PATH', '').split(os.pathsep)
259
Fredrik Lundhade711a2001-01-24 08:00:28 +0000260 # Check for MacOS X, which doesn't need libm.a at all
261 math_libs = ['m']
Jack Jansen4439b7c2002-06-26 15:44:30 +0000262 if platform in ['darwin', 'beos', 'mac']:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000263 math_libs = []
Michael W. Hudson5b109102002-01-23 15:04:41 +0000264
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000265 # XXX Omitted modules: gl, pure, dl, SGI-specific modules
266
267 #
268 # The following modules are all pretty straightforward, and compile
269 # on pretty much any POSIXish platform.
270 #
Fredrik Lundhade711a2001-01-24 08:00:28 +0000271
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000272 # Some modules that are normally always on:
273 exts.append( Extension('regex', ['regexmodule.c', 'regexpr.c']) )
274 exts.append( Extension('pcre', ['pcremodule.c', 'pypcre.c']) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000275
Fred Drake3a40f322001-10-12 21:00:48 +0000276 exts.append( Extension('_hotshot', ['_hotshot.c']) )
Fred Drake2de74712001-02-01 05:26:54 +0000277 exts.append( Extension('_weakref', ['_weakref.c']) )
Andrew M. Kuchlingd5c43062001-01-17 15:59:25 +0000278 exts.append( Extension('xreadlines', ['xreadlinesmodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000279
280 # array objects
281 exts.append( Extension('array', ['arraymodule.c']) )
282 # complex math library functions
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000283 exts.append( Extension('cmath', ['cmathmodule.c'],
284 libraries=math_libs) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000285
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000286 # math library functions, e.g. sin()
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000287 exts.append( Extension('math', ['mathmodule.c'],
288 libraries=math_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000289 # fast string operations implemented in C
290 exts.append( Extension('strop', ['stropmodule.c']) )
291 # time operations and variables
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000292 exts.append( Extension('time', ['timemodule.c'],
293 libraries=math_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000294 # operator.add() and similar goodies
295 exts.append( Extension('operator', ['operator.c']) )
296 # access to the builtin codecs and codec registry
297 exts.append( Extension('_codecs', ['_codecsmodule.c']) )
Marc-André Lemburg261b8e22001-02-02 12:12:44 +0000298 # Python C API test module
Tim Petersd66595f2001-02-04 03:09:53 +0000299 exts.append( Extension('_testcapi', ['_testcapimodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000300 # static Unicode character database
Martin v. Löwis339d0f72001-08-17 18:39:25 +0000301 if have_unicode:
302 exts.append( Extension('unicodedata', ['unicodedata.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000303 # access to ISO C locale support
304 exts.append( Extension('_locale', ['_localemodule.c']) )
305
306 # Modules with some UNIX dependencies -- on by default:
307 # (If you have a really backward UNIX, select and socket may not be
308 # supported...)
309
310 # fcntl(2) and ioctl(2)
311 exts.append( Extension('fcntl', ['fcntlmodule.c']) )
312 # pwd(3)
313 exts.append( Extension('pwd', ['pwdmodule.c']) )
314 # grp(3)
315 exts.append( Extension('grp', ['grpmodule.c']) )
316 # posix (UNIX) errno values
317 exts.append( Extension('errno', ['errnomodule.c']) )
318 # select(2); not on ancient System V
319 exts.append( Extension('select', ['selectmodule.c']) )
320
321 # The md5 module implements the RSA Data Security, Inc. MD5
Fred Drake38419c02001-12-06 22:24:47 +0000322 # Message-Digest Algorithm, described in RFC 1321. The
323 # necessary files md5c.c and md5.h are included here.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000324 exts.append( Extension('md5', ['md5module.c', 'md5c.c']) )
325
326 # The sha module implements the SHA checksum algorithm.
327 # (NIST's Secure Hash Algorithm.)
328 exts.append( Extension('sha', ['shamodule.c']) )
329
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000330 # Helper module for various ascii-encoders
331 exts.append( Extension('binascii', ['binascii.c']) )
332
333 # Fred Drake's interface to the Python parser
334 exts.append( Extension('parser', ['parsermodule.c']) )
335
Guido van Rossum2e1c09c2002-04-04 17:52:50 +0000336 # cStringIO and cPickle
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000337 exts.append( Extension('cStringIO', ['cStringIO.c']) )
338 exts.append( Extension('cPickle', ['cPickle.c']) )
339
340 # Memory-mapped files (also works on Win32).
Martin v. Löwisf90ae202002-06-11 06:22:31 +0000341 if platform not in ['atheos']:
342 exts.append( Extension('mmap', ['mmapmodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000343
344 # Lance Ellinghaus's modules:
345 # enigma-inspired encryption
346 exts.append( Extension('rotor', ['rotormodule.c']) )
347 # syslog daemon interface
348 exts.append( Extension('syslog', ['syslogmodule.c']) )
349
350 # George Neville-Neil's timing module:
351 exts.append( Extension('timing', ['timingmodule.c']) )
352
353 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000354 # Here ends the simple stuff. From here on, modules need certain
355 # libraries, are platform-specific, or present other surprises.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000356 #
357
358 # Multimedia modules
359 # These don't work for 64-bit platforms!!!
360 # These represent audio samples or images as strings:
361
Fredrik Lundhade711a2001-01-24 08:00:28 +0000362 # Disabled on 64-bit platforms
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000363 if sys.maxint != 9223372036854775807L:
364 # Operations on audio samples
365 exts.append( Extension('audioop', ['audioop.c']) )
366 # Operations on images
367 exts.append( Extension('imageop', ['imageop.c']) )
368 # Read SGI RGB image files (but coded portably)
369 exts.append( Extension('rgbimg', ['rgbimgmodule.c']) )
370
371 # readline
Marc-André Lemburg2efc3232001-01-26 18:23:02 +0000372 if self.compiler.find_library_file(lib_dirs, 'readline'):
373 readline_libs = ['readline']
Andrew M. Kuchling5aa3c4a2001-08-16 20:30:18 +0000374 if self.compiler.find_library_file(lib_dirs,
375 'ncurses'):
376 readline_libs.append('ncurses')
377 elif self.compiler.find_library_file(lib_dirs +
Marc-André Lemburg2efc3232001-01-26 18:23:02 +0000378 ['/usr/lib/termcap'],
379 'termcap'):
380 readline_libs.append('termcap')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000381 exts.append( Extension('readline', ['readline.c'],
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000382 library_dirs=['/usr/lib/termcap'],
Marc-André Lemburg2efc3232001-01-26 18:23:02 +0000383 libraries=readline_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000384
Andrew M. Kuchling5aa3c4a2001-08-16 20:30:18 +0000385 # crypt module.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000386
387 if self.compiler.find_library_file(lib_dirs, 'crypt'):
388 libs = ['crypt']
389 else:
390 libs = []
391 exts.append( Extension('crypt', ['cryptmodule.c'], libraries=libs) )
392
393 # socket(2)
Guido van Rossum47d3a7a2002-06-13 14:41:32 +0000394 exts.append( Extension('_socket', ['socketmodule.c'],
Jeremy Hylton340043e2002-06-13 17:38:11 +0000395 depends = ['socketmodule.h']) )
Marc-André Lemburga5d2b4c2002-02-16 18:23:30 +0000396 # Detect SSL support for the socket module (via _ssl)
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000397 ssl_incs = find_file('openssl/ssl.h', inc_dirs,
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +0000398 ['/usr/local/ssl/include',
399 '/usr/contrib/ssl/include/'
400 ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000401 )
402 ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs,
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +0000403 ['/usr/local/ssl/lib',
404 '/usr/contrib/ssl/lib/'
405 ] )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000406
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000407 if (ssl_incs is not None and
408 ssl_libs is not None):
Marc-André Lemburga5d2b4c2002-02-16 18:23:30 +0000409 exts.append( Extension('_ssl', ['_ssl.c'],
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000410 include_dirs = ssl_incs,
Fredrik Lundhade711a2001-01-24 08:00:28 +0000411 library_dirs = ssl_libs,
Guido van Rossum47d3a7a2002-06-13 14:41:32 +0000412 libraries = ['ssl', 'crypto'],
Jeremy Hylton340043e2002-06-13 17:38:11 +0000413 depends = ['socketmodule.h']), )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000414
415 # Modules that provide persistent dictionary-like semantics. You will
416 # probably want to arrange for at least one of them to be available on
417 # your machine, though none are defined by default because of library
418 # dependencies. The Python module anydbm.py provides an
419 # implementation independent wrapper for these; dumbdbm.py provides
420 # similar functionality (but slower of course) implemented in Python.
421
Skip Montanaro57454e52002-06-14 20:30:31 +0000422 # Berkeley DB interface.
423 #
424 # This requires the Berkeley DB code, see
425 # ftp://ftp.cs.berkeley.edu/pub/4bsd/db.1.85.tar.gz
426 #
427 # (See http://pybsddb.sourceforge.net/ for an interface to
428 # Berkeley DB 3.x.)
429
430 # when sorted in reverse order, keys for this dict must appear in the
431 # order you wish to search - e.g., search for db3 before db2, db2
432 # before db1
433 db_try_this = {
434 'db4': {'libs': ('db-4.3', 'db-4.2', 'db-4.1', 'db-4.0'),
435 'libdirs': ('/usr/local/BerkeleyDB.4.3/lib',
436 '/usr/local/BerkeleyDB.4.2/lib',
437 '/usr/local/BerkeleyDB.4.1/lib',
438 '/usr/local/BerkeleyDB.4.0/lib',
439 '/usr/lib',
440 '/opt/sfw',
441 '/sw/lib',
442 '/lib',
443 ),
444 'incdirs': ('/usr/local/BerkeleyDB.4.3/include',
445 '/usr/local/BerkeleyDB.4.2/include',
446 '/usr/local/BerkeleyDB.4.1/include',
447 '/usr/local/BerkeleyDB.4.0/include',
448 '/usr/include/db3',
449 '/opt/sfw/include/db3',
450 '/sw/include/db3',
451 '/usr/local/include/db3',
452 ),
453 'incs': ('db_185.h',)},
454 'db3': {'libs': ('db-3.3', 'db-3.2', 'db-3.1', 'db-3.0'),
455 'libdirs': ('/usr/local/BerkeleyDB.3.3/lib',
456 '/usr/local/BerkeleyDB.3.2/lib',
457 '/usr/local/BerkeleyDB.3.1/lib',
458 '/usr/local/BerkeleyDB.3.0/lib',
459 '/usr/lib',
460 '/opt/sfw',
461 '/sw/lib',
462 '/lib',
463 ),
464 'incdirs': ('/usr/local/BerkeleyDB.3.3/include',
465 '/usr/local/BerkeleyDB.3.2/include',
466 '/usr/local/BerkeleyDB.3.1/include',
467 '/usr/local/BerkeleyDB.3.0/include',
468 '/usr/include/db3',
469 '/opt/sfw/include/db3',
470 '/sw/include/db3',
471 '/usr/local/include/db3',
472 ),
473 'incs': ('db_185.h',)},
474 'db2': {'libs': ('db2',),
475 'libdirs': ('/usr/lib', '/sw/lib', '/lib'),
476 'incdirs': ('/usr/include/db2',
477 '/usr/local/include/db2', '/sw/include/db2'),
478 'incs': ('db_185.h',)},
479 # if you are willing to risk hash db file corruption you can
480 # uncomment the lines below for db1. Note that this will affect
481 # not only the bsddb module, but the dbhash and anydbm modules
482 # as well. you have been warned!!!
483 ##'db1': {'libs': ('db1', 'db'),
484 ## 'libdirs': ('/usr/lib', '/sw/lib', '/lib'),
485 ## 'incdirs': ('/usr/include/db1', '/usr/local/include/db1',
486 ## '/usr/include', '/usr/local/include'),
487 ## 'incs': ('db.h',)},
488 }
489
490 # override this list to affect the library version search order
491 # for example, if you want to force version 2 to be used:
492 # db_search_order = ["db2"]
493 db_search_order = db_try_this.keys()
494 db_search_order.sort()
495 db_search_order.reverse()
496
497 find_lib_file = self.compiler.find_library_file
498 class found(Exception): pass
499 try:
500 for dbkey in db_search_order:
501 dbd = db_try_this[dbkey]
502 for dblib in dbd['libs']:
503 for dbinc in dbd['incs']:
504 db_incs = find_file(dbinc, [], dbd['incdirs'])
505 dblib_dir = find_lib_file(dbd['libdirs'], dblib)
506 if db_incs and dblib_dir:
507 dblib_dir = os.path.dirname(dblib_dir)
508 dblibs = [dblib]
509 raise found
510 except found:
Barry Warsaw6fe3d702002-06-24 20:27:33 +0000511 # A default source build puts Berkeley DB in something like
512 # /usr/local/Berkeley.3.3 and the lib dir under that isn't
513 # normally on ld.so's search path, unless the sysadmin has hacked
514 # /etc/ld.so.conf. We add the directory to runtime_library_dirs
515 # so the proper -R/--rpath flags get passed to the linker. This
516 # is usually correct and most trouble free, but may cause problems
517 # in some unusual system configurations (e.g. the directory is on
518 # an NFS server that goes away).
Skip Montanaro57454e52002-06-14 20:30:31 +0000519 if dbinc == 'db_185.h':
520 exts.append(Extension('bsddb', ['bsddbmodule.c'],
521 library_dirs=[dblib_dir],
Barry Warsaw6fe3d702002-06-24 20:27:33 +0000522 runtime_library_dirs=[dblib_dir],
Skip Montanaro57454e52002-06-14 20:30:31 +0000523 include_dirs=db_incs,
524 define_macros=[('HAVE_DB_185_H',1)],
525 libraries=[dblib]))
526 else:
527 exts.append(Extension('bsddb', ['bsddbmodule.c'],
528 library_dirs=[dblib_dir],
Barry Warsaw6fe3d702002-06-24 20:27:33 +0000529 runtime_library_dirs=[dblib_dir],
Skip Montanaro57454e52002-06-14 20:30:31 +0000530 include_dirs=db_incs,
531 libraries=[dblib]))
532 else:
533 db_incs = None
534 dblibs = []
535 dblib_dir = None
536
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000537 # The standard Unix dbm module:
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000538 if platform not in ['cygwin']:
539 if (self.compiler.find_library_file(lib_dirs, 'ndbm')):
540 exts.append( Extension('dbm', ['dbmmodule.c'],
541 libraries = ['ndbm'] ) )
Skip Montanaro57454e52002-06-14 20:30:31 +0000542 elif self.compiler.find_library_file(lib_dirs, 'gdbm'):
Neil Schemenauerc3ffef62001-10-21 22:14:44 +0000543 exts.append( Extension('dbm', ['dbmmodule.c'],
Skip Montanaro57454e52002-06-14 20:30:31 +0000544 libraries = ['gdbm'] ) )
545 elif db_incs is not None:
546 exts.append( Extension('dbm', ['dbmmodule.c'],
547 library_dirs=dblib_dir,
548 include_dirs=db_incs,
549 libraries=dblibs))
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000550 else:
551 exts.append( Extension('dbm', ['dbmmodule.c']) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000552
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000553 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
554 if (self.compiler.find_library_file(lib_dirs, 'gdbm')):
555 exts.append( Extension('gdbm', ['gdbmmodule.c'],
556 libraries = ['gdbm'] ) )
557
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000558 # The mpz module interfaces to the GNU Multiple Precision library.
Fredrik Lundhade711a2001-01-24 08:00:28 +0000559 # You need to ftp the GNU MP library.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000560 # This was originally written and tested against GMP 1.2 and 1.3.2.
561 # It has been modified by Rob Hooft to work with 2.0.2 as well, but I
Guido van Rossum8efd6ce2001-12-17 17:24:43 +0000562 # haven't tested it recently, and it definitely doesn't work with
563 # GMP 4.0. For more complete modules, refer to
564 # http://gmpy.sourceforge.net and
565 # http://www.egenix.com/files/python/mxNumber.html
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000566
Greg Ward57fc2102001-10-03 19:59:30 +0000567 # A compatible MP library unencumbered by the GPL also exists. It was
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000568 # posted to comp.sources.misc in volume 40 and is widely available from
569 # FTP archive sites. One URL for it is:
570 # ftp://gatekeeper.dec.com/.b/usenet/comp.sources.misc/volume40/fgmp/part01.Z
571
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000572 if (self.compiler.find_library_file(lib_dirs, 'gmp')):
573 exts.append( Extension('mpz', ['mpzmodule.c'],
574 libraries = ['gmp'] ) )
575
576
577 # Unix-only modules
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000578 if platform not in ['mac', 'win32']:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000579 # Steen Lumholt's termios module
580 exts.append( Extension('termios', ['termios.c']) )
581 # Jeremy Hylton's rlimit interface
Martin v. Löwisf90ae202002-06-11 06:22:31 +0000582 if platform not in ['atheos']:
583 exts.append( Extension('resource', ['resource.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000584
Andrew M. Kuchlingcf393f32001-02-21 02:38:24 +0000585 # Sun yellow pages. Some systems have the functions in libc.
Martin v. Löwisf90ae202002-06-11 06:22:31 +0000586 if platform not in ['cygwin', 'atheos']:
Andrew M. Kuchling6efc6e72001-02-27 20:54:23 +0000587 if (self.compiler.find_library_file(lib_dirs, 'nsl')):
588 libs = ['nsl']
589 else:
590 libs = []
591 exts.append( Extension('nis', ['nismodule.c'],
592 libraries = libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000593
594 # Curses support, requring the System V version of curses, often
Fredrik Lundhade711a2001-01-24 08:00:28 +0000595 # provided by the ncurses library.
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000596 if platform == 'sunos4':
Andrew M. Kuchlingb69c7582001-02-28 19:49:57 +0000597 inc_dirs += ['/usr/5include']
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000598 lib_dirs += ['/usr/5lib']
599
600 if (self.compiler.find_library_file(lib_dirs, 'ncurses')):
601 curses_libs = ['ncurses']
602 exts.append( Extension('_curses', ['_cursesmodule.c'],
603 libraries = curses_libs) )
Fred Drake38419c02001-12-06 22:24:47 +0000604 elif (self.compiler.find_library_file(lib_dirs, 'curses')
605 and platform != 'darwin'):
Michael W. Hudson5b109102002-01-23 15:04:41 +0000606 # OSX has an old Berkeley curses, not good enough for
607 # the _curses module.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000608 if (self.compiler.find_library_file(lib_dirs, 'terminfo')):
609 curses_libs = ['curses', 'terminfo']
610 else:
611 curses_libs = ['curses', 'termcap']
Fredrik Lundhade711a2001-01-24 08:00:28 +0000612
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000613 exts.append( Extension('_curses', ['_cursesmodule.c'],
614 libraries = curses_libs) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000615
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000616 # If the curses module is enabled, check for the panel module
Andrew M. Kuchlinge7ffbb22001-12-06 15:57:16 +0000617 if (module_enabled(exts, '_curses') and
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000618 self.compiler.find_library_file(lib_dirs, 'panel')):
619 exts.append( Extension('_curses_panel', ['_curses_panel.c'],
620 libraries = ['panel'] + curses_libs) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000621
622
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000623
624 # Lee Busby's SIGFPE modules.
625 # The library to link fpectl with is platform specific.
626 # Choose *one* of the options below for fpectl:
627
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000628 if platform == 'irix5':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000629 # For SGI IRIX (tested on 5.3):
630 exts.append( Extension('fpectl', ['fpectlmodule.c'],
631 libraries=['fpe']) )
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000632 elif 0: # XXX how to detect SunPro?
Fred Drake38419c02001-12-06 22:24:47 +0000633 # For Solaris with SunPro compiler (tested on Solaris 2.5
634 # with SunPro C 4.2): (Without the compiler you don't have
635 # -lsunmath.)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000636 #fpectl fpectlmodule.c -R/opt/SUNWspro/lib -lsunmath -lm
637 pass
638 else:
639 # For other systems: see instructions in fpectlmodule.c.
640 #fpectl fpectlmodule.c ...
641 exts.append( Extension('fpectl', ['fpectlmodule.c']) )
642
643
644 # Andrew Kuchling's zlib module.
645 # This require zlib 1.1.3 (or later).
646 # See http://www.cdrom.com/pub/infozip/zlib/
Guido van Rossume6970912001-04-15 15:16:12 +0000647 zlib_inc = find_file('zlib.h', [], inc_dirs)
648 if zlib_inc is not None:
649 zlib_h = zlib_inc[0] + '/zlib.h'
650 version = '"0.0.0"'
651 version_req = '"1.1.3"'
652 fp = open(zlib_h)
653 while 1:
654 line = fp.readline()
655 if not line:
656 break
657 if line.find('#define ZLIB_VERSION', 0) == 0:
658 version = line.split()[2]
659 break
660 if version >= version_req:
661 if (self.compiler.find_library_file(lib_dirs, 'z')):
662 exts.append( Extension('zlib', ['zlibmodule.c'],
663 libraries = ['z']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000664
665 # Interface to the Expat XML parser
666 #
Fred Drakefc8341d2002-06-17 17:55:30 +0000667 # Expat was written by James Clark and is now maintained by a
668 # group of developers on SourceForge; see www.libexpat.org for
669 # more information. The pyexpat module was written by Paul
670 # Prescod after a prototype by Jack Jansen. Source of Expat
671 # 1.95.2 is included in Modules/expat/. Usage of a system
672 # shared libexpat.so/expat.dll is not advised.
673 #
674 # More information on Expat can be found at www.libexpat.org.
675 #
Martin v. Löwiscf453fe2002-02-11 23:27:45 +0000676 if sys.byteorder == "little":
677 xmlbo = "12"
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000678 else:
Martin v. Löwiscf453fe2002-02-11 23:27:45 +0000679 xmlbo = "21"
Martin v. Löwis83012562002-02-14 01:25:37 +0000680 expatinc = os.path.join(os.getcwd(), srcdir, 'Modules', 'expat')
Martin v. Löwiscf453fe2002-02-11 23:27:45 +0000681 exts.append(Extension('pyexpat',
682 sources = [
683 'pyexpat.c',
684 'expat/xmlparse.c',
685 'expat/xmlrole.c',
686 'expat/xmltok.c',
687 ],
688 define_macros = [
689 ('HAVE_EXPAT_H',None),
Martin v. Löwiscf453fe2002-02-11 23:27:45 +0000690 ('XML_NS', '1'),
691 ('XML_DTD', '1'),
692 ('XML_BYTE_ORDER', xmlbo),
693 ('XML_CONTEXT_BYTES','1024'),
694 ],
Martin v. Löwis83012562002-02-14 01:25:37 +0000695 include_dirs = [expatinc]
Martin v. Löwiscf453fe2002-02-11 23:27:45 +0000696 ))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000697
Michael W. Hudson5b109102002-01-23 15:04:41 +0000698 # Dynamic loading module
Martin v. Löwis93227272002-01-01 20:18:30 +0000699 dl_inc = find_file('dlfcn.h', [], inc_dirs)
Martin v. Löwisf90ae202002-06-11 06:22:31 +0000700 if (dl_inc is not None) and (platform not in ['atheos']):
Michael W. Hudson5b109102002-01-23 15:04:41 +0000701 exts.append( Extension('dl', ['dlmodule.c']) )
702
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000703 # Platform-specific libraries
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000704 if platform == 'linux2':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000705 # Linux-specific modules
706 exts.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) )
707
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000708 if platform == 'sunos5':
Fredrik Lundhade711a2001-01-24 08:00:28 +0000709 # SunOS specific modules
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000710 exts.append( Extension('sunaudiodev', ['sunaudiodev.c']) )
Michael W. Hudson5b109102002-01-23 15:04:41 +0000711
Jack Jansen244e7612001-12-05 15:54:29 +0000712 if platform == 'darwin':
Jack Jansen144ebcc2001-08-05 22:31:19 +0000713 # Mac OS X specific modules. These are ported over from MacPython
714 # and still experimental. Some (such as gestalt or icglue) are
715 # already generally useful, some (the GUI ones) really need to
716 # be used from a framework.
Jack Jansen2f760c32001-09-04 21:33:12 +0000717 #
718 # I would like to trigger on WITH_NEXT_FRAMEWORK but that isn't
719 # available here. This Makefile variable is also what the install
720 # procedure triggers on.
721 frameworkdir = sysconfig.get_config_var('PYTHONFRAMEWORKDIR')
Michael W. Hudson0c46c0c2002-03-07 09:58:56 +0000722 exts.append( Extension('gestalt', ['gestaltmodule.c'],
Neal Norwitz03ffbcd2002-03-25 14:20:09 +0000723 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000724 exts.append( Extension('MacOS', ['macosmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000725 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000726 exts.append( Extension('icglue', ['icgluemodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000727 extra_link_args=['-framework', 'Carbon']) )
Fred Drake38419c02001-12-06 22:24:47 +0000728 exts.append( Extension('macfs',
729 ['macfsmodule.c',
730 '../Python/getapplbycreator.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000731 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen0b06be72002-06-21 14:48:38 +0000732 exts.append( Extension('_CF', ['cf/_CFmodule.c', 'cf/pycfbridge.c'],
Michael W. Hudson0c46c0c2002-03-07 09:58:56 +0000733 extra_link_args=['-framework', 'CoreFoundation']) )
734 exts.append( Extension('_Res', ['res/_Resmodule.c'],
735 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000736 exts.append( Extension('_Snd', ['snd/_Sndmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000737 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen2f760c32001-09-04 21:33:12 +0000738 if frameworkdir:
Jack Jansen666b1e72001-10-31 12:11:48 +0000739 exts.append( Extension('Nav', ['Nav.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000740 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000741 exts.append( Extension('_AE', ['ae/_AEmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000742 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000743 exts.append( Extension('_App', ['app/_Appmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000744 extra_link_args=['-framework', 'Carbon']) )
Jack Jansendd67a8e2001-12-12 23:03:17 +0000745 exts.append( Extension('_CarbonEvt', ['carbonevt/_CarbonEvtmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000746 extra_link_args=['-framework', 'Carbon']) )
Just van Rossume9039b12001-12-13 13:41:36 +0000747 exts.append( Extension('_CG', ['cg/_CGmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000748 extra_link_args=['-framework', 'ApplicationServices',
Just van Rossume9039b12001-12-13 13:41:36 +0000749 '-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000750 exts.append( Extension('_Cm', ['cm/_Cmmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000751 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000752 exts.append( Extension('_Ctl', ['ctl/_Ctlmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000753 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000754 exts.append( Extension('_Dlg', ['dlg/_Dlgmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000755 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000756 exts.append( Extension('_Drag', ['drag/_Dragmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000757 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000758 exts.append( Extension('_Evt', ['evt/_Evtmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000759 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000760 exts.append( Extension('_Fm', ['fm/_Fmmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000761 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000762 exts.append( Extension('_Icn', ['icn/_Icnmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000763 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000764 exts.append( Extension('_List', ['list/_Listmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000765 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000766 exts.append( Extension('_Menu', ['menu/_Menumodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000767 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000768 exts.append( Extension('_Mlte', ['mlte/_Mltemodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000769 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000770 exts.append( Extension('_Qd', ['qd/_Qdmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000771 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000772 exts.append( Extension('_Qdoffs', ['qdoffs/_Qdoffsmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000773 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen2f760c32001-09-04 21:33:12 +0000774 exts.append( Extension('_Qt', ['qt/_Qtmodule.c'],
Fred Drake38419c02001-12-06 22:24:47 +0000775 extra_link_args=['-framework', 'QuickTime',
776 '-framework', 'Carbon']) )
Jack Jansen796720b2002-01-21 23:10:36 +0000777 exts.append( Extension('_Scrap', ['scrap/_Scrapmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000778 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000779 exts.append( Extension('_TE', ['te/_TEmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000780 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen0b06be72002-06-21 14:48:38 +0000781 # As there is no standardized place (yet) to put
782 # user-installed Mac libraries on OSX, we search for "waste"
783 # in parent directories of the Python source tree. You
784 # should put a symlink to your Waste installation in the
785 # same folder as your python source tree. Or modify the
786 # next few lines:-)
787 waste_incs = find_file("WASTE.h", [],
788 ['../'*n + 'waste/C_C++ Headers' for n in (0,1,2,3,4)])
Jack Jansenedeea042001-12-09 23:08:54 +0000789 waste_libs = find_library_file(self.compiler, "WASTE", [],
Jack Jansen0b06be72002-06-21 14:48:38 +0000790 ["../"*n + "waste/Static Libraries" for n in (0,1,2,3,4)])
Jack Jansenedeea042001-12-09 23:08:54 +0000791 if waste_incs != None and waste_libs != None:
Jack Jansen0b06be72002-06-21 14:48:38 +0000792 (srcdir,) = sysconfig.get_config_vars('srcdir')
Michael W. Hudson5b109102002-01-23 15:04:41 +0000793 exts.append( Extension('waste',
Jack Jansen0b06be72002-06-21 14:48:38 +0000794 ['waste/wastemodule.c'] + [
795 os.path.join(srcdir, d) for d in
Jack Jansenedeea042001-12-09 23:08:54 +0000796 'Mac/Wastemods/WEObjectHandlers.c',
797 'Mac/Wastemods/WETabHooks.c',
798 'Mac/Wastemods/WETabs.c'
799 ],
Jack Jansen0b06be72002-06-21 14:48:38 +0000800 include_dirs = waste_incs + [os.path.join(srcdir, 'Mac/Wastemods')],
Jack Jansenedeea042001-12-09 23:08:54 +0000801 library_dirs = waste_libs,
802 libraries = ['WASTE'],
803 extra_link_args = ['-framework', 'Carbon'],
804 ) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000805 exts.append( Extension('_Win', ['win/_Winmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000806 extra_link_args=['-framework', 'Carbon']) )
807
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000808 self.extensions.extend(exts)
809
810 # Call the method for detecting whether _tkinter can be compiled
811 self.detect_tkinter(inc_dirs, lib_dirs)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000812
Jack Jansen0b06be72002-06-21 14:48:38 +0000813 def detect_tkinter_darwin(self, inc_dirs, lib_dirs):
814 # The _tkinter module, using frameworks. Since frameworks are quite
815 # different the UNIX search logic is not sharable.
816 from os.path import join, exists
817 framework_dirs = [
818 '/System/Library/Frameworks/',
819 '/Library/Frameworks',
820 join(os.getenv('HOME'), '/Library/Frameworks')
821 ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000822
Jack Jansen0b06be72002-06-21 14:48:38 +0000823 # Find the directory that contains the Tcl.framwork and Tk.framework
824 # bundles.
825 # XXX distutils should support -F!
826 for F in framework_dirs:
827 # both Tcl.framework and Tk.framework should be present
828 for fw in 'Tcl', 'Tk':
829 if not exists(join(F, fw + '.framework')):
830 break
831 else:
832 # ok, F is now directory with both frameworks. Continure
833 # building
834 break
835 else:
836 # Tk and Tcl frameworks not found. Normal "unix" tkinter search
837 # will now resume.
838 return 0
839
840 # For 8.4a2, we must add -I options that point inside the Tcl and Tk
841 # frameworks. In later release we should hopefully be able to pass
842 # the -F option to gcc, which specifies a framework lookup path.
843 #
844 include_dirs = [
845 join(F, fw + '.framework', H)
846 for fw in 'Tcl', 'Tk'
847 for H in 'Headers', 'Versions/Current/PrivateHeaders'
848 ]
849
850 # For 8.4a2, the X11 headers are not included. Rather than include a
851 # complicated search, this is a hard-coded path. It could bail out
852 # if X11 libs are not found...
853 include_dirs.append('/usr/X11R6/include')
854 frameworks = ['-framework', 'Tcl', '-framework', 'Tk']
855
856 ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
857 define_macros=[('WITH_APPINIT', 1)],
858 include_dirs = include_dirs,
859 libraries = [],
860 extra_compile_args = frameworks,
861 extra_link_args = frameworks,
862 )
863 self.extensions.append(ext)
864 return 1
865
866
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000867 def detect_tkinter(self, inc_dirs, lib_dirs):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000868 # The _tkinter module.
Michael W. Hudson5b109102002-01-23 15:04:41 +0000869
Jack Jansen0b06be72002-06-21 14:48:38 +0000870 # Rather than complicate the code below, detecting and building
871 # AquaTk is a separate method. Only one Tkinter will be built on
872 # Darwin - either AquaTk, if it is found, or X11 based Tk.
873 platform = self.get_platform()
874 if platform == 'darwin' and \
875 self.detect_tkinter_darwin(inc_dirs, lib_dirs):
876 return
877
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000878 # Assume we haven't found any of the libraries or include files
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +0000879 # The versions with dots are used on Unix, and the versions without
880 # dots on Windows, for detection by cygwin.
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000881 tcllib = tklib = tcl_includes = tk_includes = None
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +0000882 for version in ['8.4', '84', '8.3', '83', '8.2',
883 '82', '8.1', '81', '8.0', '80']:
Michael W. Hudson5b109102002-01-23 15:04:41 +0000884 tklib = self.compiler.find_library_file(lib_dirs,
885 'tk' + version )
886 tcllib = self.compiler.find_library_file(lib_dirs,
887 'tcl' + version )
888 if tklib and tcllib:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000889 # Exit the loop when we've found the Tcl/Tk libraries
890 break
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000891
Fredrik Lundhade711a2001-01-24 08:00:28 +0000892 # Now check for the header files
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000893 if tklib and tcllib:
894 # Check for the include files on Debian, where
895 # they're put in /usr/include/{tcl,tk}X.Y
Andrew M. Kuchling9a3fd8c2001-02-06 22:15:27 +0000896 debian_tcl_include = [ '/usr/include/tcl' + version ]
Fred Drake38419c02001-12-06 22:24:47 +0000897 debian_tk_include = [ '/usr/include/tk' + version ] + \
898 debian_tcl_include
Andrew M. Kuchling9a3fd8c2001-02-06 22:15:27 +0000899 tcl_includes = find_file('tcl.h', inc_dirs, debian_tcl_include)
900 tk_includes = find_file('tk.h', inc_dirs, debian_tk_include)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000901
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000902 if (tcllib is None or tklib is None and
903 tcl_includes is None or tk_includes is None):
904 # Something's missing, so give up
905 return
Fredrik Lundhade711a2001-01-24 08:00:28 +0000906
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000907 # OK... everything seems to be present for Tcl/Tk.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000908
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000909 include_dirs = [] ; libs = [] ; defs = [] ; added_lib_dirs = []
910 for dir in tcl_includes + tk_includes:
911 if dir not in include_dirs:
912 include_dirs.append(dir)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000913
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000914 # Check for various platform-specific directories
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000915 if platform == 'sunos5':
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000916 include_dirs.append('/usr/openwin/include')
917 added_lib_dirs.append('/usr/openwin/lib')
918 elif os.path.exists('/usr/X11R6/include'):
919 include_dirs.append('/usr/X11R6/include')
920 added_lib_dirs.append('/usr/X11R6/lib')
921 elif os.path.exists('/usr/X11R5/include'):
922 include_dirs.append('/usr/X11R5/include')
923 added_lib_dirs.append('/usr/X11R5/lib')
924 else:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000925 # Assume default location for X11
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000926 include_dirs.append('/usr/X11/include')
927 added_lib_dirs.append('/usr/X11/lib')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000928
Andrew M. Kuchling89fb72d2001-09-18 20:32:13 +0000929 # If Cygwin, then verify that X is installed before proceeding
930 if platform == 'cygwin':
931 x11_inc = find_file('X11/Xlib.h', [], inc_dirs)
932 if x11_inc is None:
933 # X header files missing, so give up
934 return
935
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000936 # Check for BLT extension
Fred Drake38419c02001-12-06 22:24:47 +0000937 if self.compiler.find_library_file(lib_dirs + added_lib_dirs,
938 'BLT8.0'):
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000939 defs.append( ('WITH_BLT', 1) )
940 libs.append('BLT8.0')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000941
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000942 # Add the Tcl/Tk libraries
Fredrik Lundhade711a2001-01-24 08:00:28 +0000943 libs.append('tk'+version)
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000944 libs.append('tcl'+version)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000945
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000946 if platform in ['aix3', 'aix4']:
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000947 libs.append('ld')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000948
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +0000949 # Finally, link with the X11 libraries (not appropriate on cygwin)
950 if platform != "cygwin":
951 libs.append('X11')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000952
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000953 ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
954 define_macros=[('WITH_APPINIT', 1)] + defs,
955 include_dirs = include_dirs,
956 libraries = libs,
957 library_dirs = added_lib_dirs,
958 )
959 self.extensions.append(ext)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000960
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000961 # XXX handle these, but how to detect?
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000962 # *** Uncomment and edit for PIL (TkImaging) extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000963 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000964 # *** Uncomment and edit for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000965 # -DWITH_TOGL togl.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000966 # *** Uncomment these for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000967 # -lGL -lGLU -lXext -lXmu \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000968
Andrew M. Kuchlingf52d27e2001-05-21 20:29:27 +0000969class PyBuildInstall(install):
970 # Suppress the warning about installation into the lib_dynload
971 # directory, which is not in sys.path when running Python during
972 # installation:
973 def initialize_options (self):
974 install.initialize_options(self)
975 self.warn_dir=0
Michael W. Hudson5b109102002-01-23 15:04:41 +0000976
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000977def main():
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000978 # turn off warnings when deprecated modules are imported
979 import warnings
980 warnings.filterwarnings("ignore",category=DeprecationWarning)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000981 setup(name = 'Python standard library',
Neil Schemenauere7e2ece2001-01-17 21:58:00 +0000982 version = '%d.%d' % sys.version_info[:2],
Andrew M. Kuchlingf52d27e2001-05-21 20:29:27 +0000983 cmdclass = {'build_ext':PyBuildExt, 'install':PyBuildInstall},
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000984 # The struct module is defined here, because build_ext won't be
985 # called unless there's at least one extension module defined.
Andrew M. Kuchlingaece4272001-02-28 20:56:49 +0000986 ext_modules=[Extension('struct', ['structmodule.c'])],
987
988 # Scripts to install
989 scripts = ['Tools/scripts/pydoc']
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000990 )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000991
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000992# --install-platlib
993if __name__ == '__main__':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000994 main()