blob: c94df0b25d5630a520d0aac9343e4ea96f253e1c [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')
Guido van Rossume0fea6c2002-10-14 20:48:09 +000089 if not srcdir:
90 # Maybe running on Windows but not using CYGWIN?
91 raise ValueError("No source directory; cannot proceed.")
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000092
Neil Schemenauer726b78e2001-01-24 17:18:21 +000093 # Figure out the location of the source code for extension modules
94 moddir = os.path.join(os.getcwd(), srcdir, 'Modules')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000095 moddir = os.path.normpath(moddir)
96 srcdir, tail = os.path.split(moddir)
97 srcdir = os.path.normpath(srcdir)
98 moddir = os.path.normpath(moddir)
Michael W. Hudson5b109102002-01-23 15:04:41 +000099
Jack Jansen144ebcc2001-08-05 22:31:19 +0000100 moddirlist = [moddir]
101 incdirlist = ['./Include']
Michael W. Hudson5b109102002-01-23 15:04:41 +0000102
Jack Jansen144ebcc2001-08-05 22:31:19 +0000103 # Platform-dependent module source and include directories
104 platform = self.get_platform()
Jack Jansen4439b7c2002-06-26 15:44:30 +0000105 if platform in ('darwin', 'mac'):
Jack Jansen144ebcc2001-08-05 22:31:19 +0000106 # Mac OS X also includes some mac-specific modules
107 macmoddir = os.path.join(os.getcwd(), srcdir, 'Mac/Modules')
108 moddirlist.append(macmoddir)
109 incdirlist.append('./Mac/Include')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000110
Jeremy Hylton340043e2002-06-13 17:38:11 +0000111 alldirlist = moddirlist + incdirlist
112
Andrew M. Kuchling3da989c2001-02-28 22:49:26 +0000113 # Fix up the paths for scripts, too
114 self.distribution.scripts = [os.path.join(srcdir, filename)
115 for filename in self.distribution.scripts]
116
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000117 for ext in self.extensions[:]:
Jack Jansen144ebcc2001-08-05 22:31:19 +0000118 ext.sources = [ find_module_file(filename, moddirlist)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000119 for filename in ext.sources ]
Jeremy Hylton340043e2002-06-13 17:38:11 +0000120 if ext.depends is not None:
121 ext.depends = [find_module_file(filename, alldirlist)
122 for filename in ext.depends]
Jack Jansen144ebcc2001-08-05 22:31:19 +0000123 ext.include_dirs.append( '.' ) # to get config.h
124 for incdir in incdirlist:
125 ext.include_dirs.append( os.path.join(srcdir, incdir) )
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000126
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +0000127 # If a module has already been built statically,
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000128 # don't build it here
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +0000129 if ext.name in sys.builtin_module_names:
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000130 self.extensions.remove(ext)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000131
Jack Jansen4439b7c2002-06-26 15:44:30 +0000132 if platform != 'mac':
133 # Parse Modules/Setup to figure out which modules are turned
134 # on in the file.
135 input = text_file.TextFile('Modules/Setup', join_lines=1)
136 remove_modules = []
137 while 1:
138 line = input.readline()
139 if not line: break
140 line = line.split()
141 remove_modules.append( line[0] )
142 input.close()
143
144 for ext in self.extensions[:]:
145 if ext.name in remove_modules:
146 self.extensions.remove(ext)
Michael W. Hudson5b109102002-01-23 15:04:41 +0000147
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000148 # When you run "make CC=altcc" or something similar, you really want
149 # those environment variables passed into the setup.py phase. Here's
150 # a small set of useful ones.
151 compiler = os.environ.get('CC')
152 linker_so = os.environ.get('LDSHARED')
153 args = {}
154 # unfortunately, distutils doesn't let us provide separate C and C++
155 # compilers
156 if compiler is not None:
Martin v. Löwis3e4b0e82001-08-10 08:56:17 +0000157 (ccshared,opt) = sysconfig.get_config_vars('CCSHARED','OPT')
158 args['compiler_so'] = compiler + ' ' + opt + ' ' + ccshared
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000159 if linker_so is not None:
Martin v. Löwis2f20dab2001-10-08 13:18:37 +0000160 args['linker_so'] = linker_so
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000161 self.compiler.set_executables(**args)
162
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000163 build_ext.build_extensions(self)
164
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000165 def build_extension(self, ext):
166
167 try:
168 build_ext.build_extension(self, ext)
169 except (CCompilerError, DistutilsError), why:
170 self.announce('WARNING: building of extension "%s" failed: %s' %
171 (ext.name, sys.exc_info()[1]))
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000172 return
Jack Jansenf49c6f92001-11-01 14:44:15 +0000173 # Workaround for Mac OS X: The Carbon-based modules cannot be
174 # reliably imported into a command-line Python
175 if 'Carbon' in ext.extra_link_args:
Michael W. Hudson5b109102002-01-23 15:04:41 +0000176 self.announce(
177 'WARNING: skipping import check for Carbon-based "%s"' %
178 ext.name)
179 return
Jason Tishler24cf7762002-05-22 16:46:15 +0000180 # Workaround for Cygwin: Cygwin currently has fork issues when many
181 # modules have been imported
182 if self.get_platform() == 'cygwin':
183 self.announce('WARNING: skipping import check for Cygwin-based "%s"'
184 % ext.name)
185 return
Michael W. Hudsonaf142892002-01-23 15:07:46 +0000186 ext_filename = os.path.join(
187 self.build_lib,
188 self.get_ext_filename(self.get_ext_fullname(ext.name)))
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000189 try:
Michael W. Hudsonaf142892002-01-23 15:07:46 +0000190 imp.load_dynamic(ext.name, ext_filename)
Marc-André Lemburga5d2b4c2002-02-16 18:23:30 +0000191 except ImportError, why:
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000192
Marc-André Lemburga5d2b4c2002-02-16 18:23:30 +0000193 if 1:
Michael W. Hudson7113d962002-03-01 14:16:31 +0000194 self.announce('*** WARNING: renaming "%s" since importing it'
Marc-André Lemburga5d2b4c2002-02-16 18:23:30 +0000195 ' failed: %s' % (ext.name, why))
196 assert not self.inplace
Michael W. Hudson7113d962002-03-01 14:16:31 +0000197 basename, tail = os.path.splitext(ext_filename)
198 newname = basename + "_failed" + tail
199 if os.path.exists(newname): os.remove(newname)
200 os.rename(ext_filename, newname)
Marc-André Lemburga5d2b4c2002-02-16 18:23:30 +0000201
202 # XXX -- This relies on a Vile HACK in
203 # distutils.command.build_ext.build_extension(). The
204 # _built_objects attribute is stored there strictly for
205 # use here.
Neal Norwitz03ffbcd2002-03-25 14:20:09 +0000206 # If there is a failure, _built_objects may not be there,
207 # so catch the AttributeError and move on.
208 try:
209 for filename in self._built_objects:
210 os.remove(filename)
211 except AttributeError:
212 self.announce('unable to remove files (ignored)')
Marc-André Lemburga5d2b4c2002-02-16 18:23:30 +0000213 else:
214 self.announce('*** WARNING: importing extension "%s" '
215 'failed: %s' % (ext.name, why))
Fred Drake9028d0a2001-12-06 22:59:54 +0000216
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000217 def get_platform (self):
Fredrik Lundhade711a2001-01-24 08:00:28 +0000218 # Get value of sys.platform
219 platform = sys.platform
220 if platform[:6] =='cygwin':
221 platform = 'cygwin'
Andrew M. Kuchling3c044942001-02-06 23:37:23 +0000222 elif platform[:4] =='beos':
223 platform = 'beos'
Jack Jansen244e7612001-12-05 15:54:29 +0000224 elif platform[:6] == 'darwin':
225 platform = 'darwin'
Martin v. Löwisf90ae202002-06-11 06:22:31 +0000226 elif platform[:6] == 'atheos':
227 platform = 'atheos'
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000228
Fredrik Lundhade711a2001-01-24 08:00:28 +0000229 return platform
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000230
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000231 def detect_modules(self):
Fredrik Lundhade711a2001-01-24 08:00:28 +0000232 # Ensure that /usr/local is always used
Michael W. Hudson39230b32002-01-16 15:26:48 +0000233 add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
234 add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
235
Michael W. Hudson90b8e4d2002-08-02 13:55:50 +0000236 if os.path.normpath(sys.prefix) != '/usr':
237 add_dir_to_list(self.compiler.library_dirs,
238 sysconfig.get_config_var("LIBDIR"))
239 add_dir_to_list(self.compiler.include_dirs,
240 sysconfig.get_config_var("INCLUDEDIR"))
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000241
Martin v. Löwis339d0f72001-08-17 18:39:25 +0000242 try:
243 have_unicode = unicode
244 except NameError:
245 have_unicode = 0
246
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000247 # lib_dirs and inc_dirs are used to search for files;
248 # if a file is found in one of those directories, it can
249 # be assumed that no additional -I,-L directives are needed.
250 lib_dirs = self.compiler.library_dirs + ['/lib', '/usr/lib']
Michael W. Hudson5b109102002-01-23 15:04:41 +0000251 inc_dirs = self.compiler.include_dirs + ['/usr/include']
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000252 exts = []
253
Fredrik Lundhade711a2001-01-24 08:00:28 +0000254 platform = self.get_platform()
Martin v. Löwis83012562002-02-14 01:25:37 +0000255 (srcdir,) = sysconfig.get_config_vars('srcdir')
Michael W. Hudson5b109102002-01-23 15:04:41 +0000256
Martin v. Löwisf90ae202002-06-11 06:22:31 +0000257 # Check for AtheOS which has libraries in non-standard locations
258 if platform == 'atheos':
259 lib_dirs += ['/system/libs', '/atheos/autolnk/lib']
260 lib_dirs += os.getenv('LIBRARY_PATH', '').split(os.pathsep)
261 inc_dirs += ['/system/include', '/atheos/autolnk/include']
262 inc_dirs += os.getenv('C_INCLUDE_PATH', '').split(os.pathsep)
263
Fredrik Lundhade711a2001-01-24 08:00:28 +0000264 # Check for MacOS X, which doesn't need libm.a at all
265 math_libs = ['m']
Jack Jansen4439b7c2002-06-26 15:44:30 +0000266 if platform in ['darwin', 'beos', 'mac']:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000267 math_libs = []
Michael W. Hudson5b109102002-01-23 15:04:41 +0000268
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000269 # XXX Omitted modules: gl, pure, dl, SGI-specific modules
270
271 #
272 # The following modules are all pretty straightforward, and compile
273 # on pretty much any POSIXish platform.
274 #
Fredrik Lundhade711a2001-01-24 08:00:28 +0000275
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000276 # Some modules that are normally always on:
277 exts.append( Extension('regex', ['regexmodule.c', 'regexpr.c']) )
278 exts.append( Extension('pcre', ['pcremodule.c', 'pypcre.c']) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000279
Fred Drake3a40f322001-10-12 21:00:48 +0000280 exts.append( Extension('_hotshot', ['_hotshot.c']) )
Fred Drake2de74712001-02-01 05:26:54 +0000281 exts.append( Extension('_weakref', ['_weakref.c']) )
Andrew M. Kuchlingd5c43062001-01-17 15:59:25 +0000282 exts.append( Extension('xreadlines', ['xreadlinesmodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000283
284 # array objects
285 exts.append( Extension('array', ['arraymodule.c']) )
286 # complex math library functions
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000287 exts.append( Extension('cmath', ['cmathmodule.c'],
288 libraries=math_libs) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000289
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000290 # math library functions, e.g. sin()
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000291 exts.append( Extension('math', ['mathmodule.c'],
292 libraries=math_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000293 # fast string operations implemented in C
294 exts.append( Extension('strop', ['stropmodule.c']) )
295 # time operations and variables
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000296 exts.append( Extension('time', ['timemodule.c'],
297 libraries=math_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000298 # operator.add() and similar goodies
299 exts.append( Extension('operator', ['operator.c']) )
300 # access to the builtin codecs and codec registry
301 exts.append( Extension('_codecs', ['_codecsmodule.c']) )
Marc-André Lemburg261b8e22001-02-02 12:12:44 +0000302 # Python C API test module
Tim Petersd66595f2001-02-04 03:09:53 +0000303 exts.append( Extension('_testcapi', ['_testcapimodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000304 # static Unicode character database
Martin v. Löwis339d0f72001-08-17 18:39:25 +0000305 if have_unicode:
306 exts.append( Extension('unicodedata', ['unicodedata.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000307 # access to ISO C locale support
Jason Tishlerd28216b2002-08-14 11:13:52 +0000308 if platform in ['cygwin']:
309 locale_libs = ['intl']
310 else:
311 locale_libs = []
312 exts.append( Extension('_locale', ['_localemodule.c'],
313 libraries=locale_libs ) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000314
315 # Modules with some UNIX dependencies -- on by default:
316 # (If you have a really backward UNIX, select and socket may not be
317 # supported...)
318
319 # fcntl(2) and ioctl(2)
320 exts.append( Extension('fcntl', ['fcntlmodule.c']) )
Jack Jansen73aa1ff2002-06-27 22:06:49 +0000321 if platform not in ['mac']:
322 # pwd(3)
323 exts.append( Extension('pwd', ['pwdmodule.c']) )
324 # grp(3)
325 exts.append( Extension('grp', ['grpmodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000326 # select(2); not on ancient System V
327 exts.append( Extension('select', ['selectmodule.c']) )
328
329 # The md5 module implements the RSA Data Security, Inc. MD5
Fred Drake38419c02001-12-06 22:24:47 +0000330 # Message-Digest Algorithm, described in RFC 1321. The
331 # necessary files md5c.c and md5.h are included here.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000332 exts.append( Extension('md5', ['md5module.c', 'md5c.c']) )
333
334 # The sha module implements the SHA checksum algorithm.
335 # (NIST's Secure Hash Algorithm.)
336 exts.append( Extension('sha', ['shamodule.c']) )
337
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000338 # Helper module for various ascii-encoders
339 exts.append( Extension('binascii', ['binascii.c']) )
340
341 # Fred Drake's interface to the Python parser
342 exts.append( Extension('parser', ['parsermodule.c']) )
343
Guido van Rossum2e1c09c2002-04-04 17:52:50 +0000344 # cStringIO and cPickle
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000345 exts.append( Extension('cStringIO', ['cStringIO.c']) )
346 exts.append( Extension('cPickle', ['cPickle.c']) )
347
348 # Memory-mapped files (also works on Win32).
Jack Jansen73aa1ff2002-06-27 22:06:49 +0000349 if platform not in ['atheos', 'mac']:
Martin v. Löwisf90ae202002-06-11 06:22:31 +0000350 exts.append( Extension('mmap', ['mmapmodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000351
352 # Lance Ellinghaus's modules:
353 # enigma-inspired encryption
354 exts.append( Extension('rotor', ['rotormodule.c']) )
Jack Jansen73aa1ff2002-06-27 22:06:49 +0000355 if platform not in ['mac']:
356 # syslog daemon interface
357 exts.append( Extension('syslog', ['syslogmodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000358
359 # George Neville-Neil's timing module:
360 exts.append( Extension('timing', ['timingmodule.c']) )
361
362 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000363 # Here ends the simple stuff. From here on, modules need certain
364 # libraries, are platform-specific, or present other surprises.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000365 #
366
367 # Multimedia modules
368 # These don't work for 64-bit platforms!!!
369 # These represent audio samples or images as strings:
370
Fredrik Lundhade711a2001-01-24 08:00:28 +0000371 # Disabled on 64-bit platforms
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000372 if sys.maxint != 9223372036854775807L:
373 # Operations on audio samples
374 exts.append( Extension('audioop', ['audioop.c']) )
375 # Operations on images
376 exts.append( Extension('imageop', ['imageop.c']) )
377 # Read SGI RGB image files (but coded portably)
378 exts.append( Extension('rgbimg', ['rgbimgmodule.c']) )
379
380 # readline
Marc-André Lemburg2efc3232001-01-26 18:23:02 +0000381 if self.compiler.find_library_file(lib_dirs, 'readline'):
382 readline_libs = ['readline']
Andrew M. Kuchling5aa3c4a2001-08-16 20:30:18 +0000383 if self.compiler.find_library_file(lib_dirs,
384 'ncurses'):
385 readline_libs.append('ncurses')
386 elif self.compiler.find_library_file(lib_dirs +
Marc-André Lemburg2efc3232001-01-26 18:23:02 +0000387 ['/usr/lib/termcap'],
388 'termcap'):
389 readline_libs.append('termcap')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000390 exts.append( Extension('readline', ['readline.c'],
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000391 library_dirs=['/usr/lib/termcap'],
Marc-André Lemburg2efc3232001-01-26 18:23:02 +0000392 libraries=readline_libs) )
Jack Jansen73aa1ff2002-06-27 22:06:49 +0000393 if platform not in ['mac']:
394 # crypt module.
395
396 if self.compiler.find_library_file(lib_dirs, 'crypt'):
397 libs = ['crypt']
398 else:
399 libs = []
400 exts.append( Extension('crypt', ['cryptmodule.c'], libraries=libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000401
402 # socket(2)
Guido van Rossum47d3a7a2002-06-13 14:41:32 +0000403 exts.append( Extension('_socket', ['socketmodule.c'],
Jeremy Hylton340043e2002-06-13 17:38:11 +0000404 depends = ['socketmodule.h']) )
Marc-André Lemburga5d2b4c2002-02-16 18:23:30 +0000405 # Detect SSL support for the socket module (via _ssl)
Michael W. Hudsonc4c71802002-08-03 16:39:22 +0000406 ssl_incs = find_file('openssl/ssl.h', inc_dirs,
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +0000407 ['/usr/local/ssl/include',
408 '/usr/contrib/ssl/include/'
409 ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000410 )
411 ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs,
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +0000412 ['/usr/local/ssl/lib',
413 '/usr/contrib/ssl/lib/'
414 ] )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000415
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000416 if (ssl_incs is not None and
417 ssl_libs is not None):
Marc-André Lemburga5d2b4c2002-02-16 18:23:30 +0000418 exts.append( Extension('_ssl', ['_ssl.c'],
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000419 include_dirs = ssl_incs,
Fredrik Lundhade711a2001-01-24 08:00:28 +0000420 library_dirs = ssl_libs,
Guido van Rossum47d3a7a2002-06-13 14:41:32 +0000421 libraries = ['ssl', 'crypto'],
Jeremy Hylton340043e2002-06-13 17:38:11 +0000422 depends = ['socketmodule.h']), )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000423
424 # Modules that provide persistent dictionary-like semantics. You will
425 # probably want to arrange for at least one of them to be available on
426 # your machine, though none are defined by default because of library
427 # dependencies. The Python module anydbm.py provides an
428 # implementation independent wrapper for these; dumbdbm.py provides
429 # similar functionality (but slower of course) implemented in Python.
430
Skip Montanaro57454e52002-06-14 20:30:31 +0000431 # Berkeley DB interface.
432 #
433 # This requires the Berkeley DB code, see
434 # ftp://ftp.cs.berkeley.edu/pub/4bsd/db.1.85.tar.gz
435 #
436 # (See http://pybsddb.sourceforge.net/ for an interface to
437 # Berkeley DB 3.x.)
438
439 # when sorted in reverse order, keys for this dict must appear in the
Martin v. Löwis6aa4a1f2002-11-19 08:09:52 +0000440 # order you wish to search - e.g., search for db4 before db3
Skip Montanaro57454e52002-06-14 20:30:31 +0000441 db_try_this = {
442 'db4': {'libs': ('db-4.3', 'db-4.2', 'db-4.1', 'db-4.0'),
443 'libdirs': ('/usr/local/BerkeleyDB.4.3/lib',
444 '/usr/local/BerkeleyDB.4.2/lib',
445 '/usr/local/BerkeleyDB.4.1/lib',
446 '/usr/local/BerkeleyDB.4.0/lib',
Skip Montanaroccfdde82002-08-15 01:34:38 +0000447 '/usr/local/lib',
Skip Montanaro57454e52002-06-14 20:30:31 +0000448 '/usr/lib',
449 '/opt/sfw',
450 '/sw/lib',
451 '/lib',
452 ),
453 'incdirs': ('/usr/local/BerkeleyDB.4.3/include',
454 '/usr/local/BerkeleyDB.4.2/include',
455 '/usr/local/BerkeleyDB.4.1/include',
456 '/usr/local/BerkeleyDB.4.0/include',
Martin v. Löwiscc40ced2002-11-09 19:53:04 +0000457 '/usr/local/include/db4',
458 '/opt/sfw/include/db4',
459 '/sw/include/db4',
460 '/usr/include/db4',
Skip Montanaro57454e52002-06-14 20:30:31 +0000461 ),
Martin v. Löwis6aa4a1f2002-11-19 08:09:52 +0000462 'incs': ('db.h',)},
Skip Montanaro57454e52002-06-14 20:30:31 +0000463 'db3': {'libs': ('db-3.3', 'db-3.2', 'db-3.1', 'db-3.0'),
464 'libdirs': ('/usr/local/BerkeleyDB.3.3/lib',
465 '/usr/local/BerkeleyDB.3.2/lib',
466 '/usr/local/BerkeleyDB.3.1/lib',
467 '/usr/local/BerkeleyDB.3.0/lib',
Skip Montanaroccfdde82002-08-15 01:34:38 +0000468 '/usr/local/lib',
Skip Montanaro57454e52002-06-14 20:30:31 +0000469 '/opt/sfw',
470 '/sw/lib',
Skip Montanaroccfdde82002-08-15 01:34:38 +0000471 '/usr/lib',
Skip Montanaro57454e52002-06-14 20:30:31 +0000472 '/lib',
473 ),
474 'incdirs': ('/usr/local/BerkeleyDB.3.3/include',
475 '/usr/local/BerkeleyDB.3.2/include',
476 '/usr/local/BerkeleyDB.3.1/include',
477 '/usr/local/BerkeleyDB.3.0/include',
Skip Montanaroccfdde82002-08-15 01:34:38 +0000478 '/usr/local/include/db3',
Skip Montanaro57454e52002-06-14 20:30:31 +0000479 '/opt/sfw/include/db3',
480 '/sw/include/db3',
Skip Montanaroccfdde82002-08-15 01:34:38 +0000481 '/usr/include/db3',
Skip Montanaro57454e52002-06-14 20:30:31 +0000482 ),
Martin v. Löwis6aa4a1f2002-11-19 08:09:52 +0000483 'incs': ('db.h',)},
Skip Montanaro57454e52002-06-14 20:30:31 +0000484 }
485
Skip Montanaro57454e52002-06-14 20:30:31 +0000486 db_search_order = db_try_this.keys()
487 db_search_order.sort()
488 db_search_order.reverse()
489
490 find_lib_file = self.compiler.find_library_file
491 class found(Exception): pass
492 try:
493 for dbkey in db_search_order:
494 dbd = db_try_this[dbkey]
495 for dblib in dbd['libs']:
496 for dbinc in dbd['incs']:
497 db_incs = find_file(dbinc, [], dbd['incdirs'])
498 dblib_dir = find_lib_file(dbd['libdirs'], dblib)
499 if db_incs and dblib_dir:
500 dblib_dir = os.path.dirname(dblib_dir)
501 dblibs = [dblib]
502 raise found
503 except found:
Jack Jansend1b20452002-07-08 21:39:36 +0000504 dblibs = [dblib]
Barry Warsaw6fe3d702002-06-24 20:27:33 +0000505 # A default source build puts Berkeley DB in something like
506 # /usr/local/Berkeley.3.3 and the lib dir under that isn't
507 # normally on ld.so's search path, unless the sysadmin has hacked
508 # /etc/ld.so.conf. We add the directory to runtime_library_dirs
509 # so the proper -R/--rpath flags get passed to the linker. This
510 # is usually correct and most trouble free, but may cause problems
511 # in some unusual system configurations (e.g. the directory is on
512 # an NFS server that goes away).
Martin v. Löwis6aa4a1f2002-11-19 08:09:52 +0000513 exts.append(Extension('_bsddb', ['_bsddb.c'],
514 library_dirs=[dblib_dir],
515 runtime_library_dirs=[dblib_dir],
516 include_dirs=db_incs,
517 libraries=dblibs))
Skip Montanaro57454e52002-06-14 20:30:31 +0000518 else:
519 db_incs = None
520 dblibs = []
521 dblib_dir = None
522
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000523 # The standard Unix dbm module:
Jack Jansend1b20452002-07-08 21:39:36 +0000524 if platform not in ['cygwin']:
525 if (self.compiler.find_library_file(lib_dirs, 'ndbm')
526 and find_file("ndbm.h", inc_dirs, []) is not None):
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000527 exts.append( Extension('dbm', ['dbmmodule.c'],
Jack Jansend1b20452002-07-08 21:39:36 +0000528 define_macros=[('HAVE_NDBM_H',None)],
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000529 libraries = ['ndbm'] ) )
Jack Jansend1b20452002-07-08 21:39:36 +0000530 elif (platform in ['darwin']
531 and find_file("ndbm.h", inc_dirs, []) is not None):
532 # Darwin has ndbm in libc
Neil Schemenauerc3ffef62001-10-21 22:14:44 +0000533 exts.append( Extension('dbm', ['dbmmodule.c'],
Jack Jansend1b20452002-07-08 21:39:36 +0000534 define_macros=[('HAVE_NDBM_H',None)]) )
535 elif (self.compiler.find_library_file(lib_dirs, 'gdbm')
536 and find_file("gdbm/ndbm.h", inc_dirs, []) is not None):
537 exts.append( Extension('dbm', ['dbmmodule.c'],
538 define_macros=[('HAVE_GDBM_NDBM_H',None)],
Skip Montanaro57454e52002-06-14 20:30:31 +0000539 libraries = ['gdbm'] ) )
540 elif db_incs is not None:
541 exts.append( Extension('dbm', ['dbmmodule.c'],
Jack Jansend1b20452002-07-08 21:39:36 +0000542 library_dirs=[dblib_dir],
Skip Montanaro57454e52002-06-14 20:30:31 +0000543 include_dirs=db_incs,
Jack Jansend1b20452002-07-08 21:39:36 +0000544 define_macros=[('HAVE_BERKDB_H',None),
545 ('DB_DBM_HSEARCH',None)],
Skip Montanaro57454e52002-06-14 20:30:31 +0000546 libraries=dblibs))
Fredrik Lundhade711a2001-01-24 08:00:28 +0000547
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000548 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
549 if (self.compiler.find_library_file(lib_dirs, 'gdbm')):
550 exts.append( Extension('gdbm', ['gdbmmodule.c'],
551 libraries = ['gdbm'] ) )
552
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000553 # The mpz module interfaces to the GNU Multiple Precision library.
Fredrik Lundhade711a2001-01-24 08:00:28 +0000554 # You need to ftp the GNU MP library.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000555 # This was originally written and tested against GMP 1.2 and 1.3.2.
556 # 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 +0000557 # haven't tested it recently, and it definitely doesn't work with
558 # GMP 4.0. For more complete modules, refer to
559 # http://gmpy.sourceforge.net and
560 # http://www.egenix.com/files/python/mxNumber.html
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000561
Greg Ward57fc2102001-10-03 19:59:30 +0000562 # A compatible MP library unencumbered by the GPL also exists. It was
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000563 # posted to comp.sources.misc in volume 40 and is widely available from
564 # FTP archive sites. One URL for it is:
565 # ftp://gatekeeper.dec.com/.b/usenet/comp.sources.misc/volume40/fgmp/part01.Z
566
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000567 if (self.compiler.find_library_file(lib_dirs, 'gmp')):
568 exts.append( Extension('mpz', ['mpzmodule.c'],
569 libraries = ['gmp'] ) )
570
571
572 # Unix-only modules
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000573 if platform not in ['mac', 'win32']:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000574 # Steen Lumholt's termios module
575 exts.append( Extension('termios', ['termios.c']) )
576 # Jeremy Hylton's rlimit interface
Martin v. Löwisf90ae202002-06-11 06:22:31 +0000577 if platform not in ['atheos']:
578 exts.append( Extension('resource', ['resource.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000579
Andrew M. Kuchlingcf393f32001-02-21 02:38:24 +0000580 # Sun yellow pages. Some systems have the functions in libc.
Martin v. Löwisf90ae202002-06-11 06:22:31 +0000581 if platform not in ['cygwin', 'atheos']:
Andrew M. Kuchling6efc6e72001-02-27 20:54:23 +0000582 if (self.compiler.find_library_file(lib_dirs, 'nsl')):
583 libs = ['nsl']
584 else:
585 libs = []
586 exts.append( Extension('nis', ['nismodule.c'],
587 libraries = libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000588
589 # Curses support, requring the System V version of curses, often
Fredrik Lundhade711a2001-01-24 08:00:28 +0000590 # provided by the ncurses library.
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000591 if platform == 'sunos4':
Andrew M. Kuchlingb69c7582001-02-28 19:49:57 +0000592 inc_dirs += ['/usr/5include']
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000593 lib_dirs += ['/usr/5lib']
594
595 if (self.compiler.find_library_file(lib_dirs, 'ncurses')):
596 curses_libs = ['ncurses']
597 exts.append( Extension('_curses', ['_cursesmodule.c'],
598 libraries = curses_libs) )
Fred Drake38419c02001-12-06 22:24:47 +0000599 elif (self.compiler.find_library_file(lib_dirs, 'curses')
600 and platform != 'darwin'):
Michael W. Hudson5b109102002-01-23 15:04:41 +0000601 # OSX has an old Berkeley curses, not good enough for
602 # the _curses module.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000603 if (self.compiler.find_library_file(lib_dirs, 'terminfo')):
604 curses_libs = ['curses', 'terminfo']
605 else:
606 curses_libs = ['curses', 'termcap']
Fredrik Lundhade711a2001-01-24 08:00:28 +0000607
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000608 exts.append( Extension('_curses', ['_cursesmodule.c'],
609 libraries = curses_libs) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000610
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000611 # If the curses module is enabled, check for the panel module
Andrew M. Kuchlinge7ffbb22001-12-06 15:57:16 +0000612 if (module_enabled(exts, '_curses') and
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000613 self.compiler.find_library_file(lib_dirs, 'panel')):
614 exts.append( Extension('_curses_panel', ['_curses_panel.c'],
615 libraries = ['panel'] + curses_libs) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000616
617
Barry Warsaw259b1e12002-08-13 20:09:26 +0000618 # Andrew Kuchling's zlib module. Note that some versions of zlib
619 # 1.1.3 have security problems. See CERT Advisory CA-2002-07:
620 # http://www.cert.org/advisories/CA-2002-07.html
621 #
622 # zlib 1.1.4 is fixed, but at least one vendor (RedHat) has decided to
623 # patch its zlib 1.1.3 package instead of upgrading to 1.1.4. For
624 # now, we still accept 1.1.3, because we think it's difficult to
625 # exploit this in Python, and we'd rather make it RedHat's problem
626 # than our problem <wink>.
627 #
628 # You can upgrade zlib to version 1.1.4 yourself by going to
629 # http://www.gzip.org/zlib/
Guido van Rossume6970912001-04-15 15:16:12 +0000630 zlib_inc = find_file('zlib.h', [], inc_dirs)
631 if zlib_inc is not None:
632 zlib_h = zlib_inc[0] + '/zlib.h'
633 version = '"0.0.0"'
Barry Warsaw259b1e12002-08-13 20:09:26 +0000634 version_req = '"1.1.3"'
Guido van Rossume6970912001-04-15 15:16:12 +0000635 fp = open(zlib_h)
636 while 1:
637 line = fp.readline()
638 if not line:
639 break
Guido van Rossum8cdc03d2002-08-06 17:28:30 +0000640 if line.startswith('#define ZLIB_VERSION'):
Guido van Rossume6970912001-04-15 15:16:12 +0000641 version = line.split()[2]
642 break
643 if version >= version_req:
644 if (self.compiler.find_library_file(lib_dirs, 'z')):
645 exts.append( Extension('zlib', ['zlibmodule.c'],
646 libraries = ['z']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000647
Gustavo Niemeyerf8ca8362002-11-05 16:50:05 +0000648 # Gustavo Niemeyer's bz2 module.
649 if (self.compiler.find_library_file(lib_dirs, 'bz2')):
650 exts.append( Extension('bz2', ['bz2module.c'],
651 libraries = ['bz2']) )
652
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000653 # Interface to the Expat XML parser
654 #
Fred Drakefc8341d2002-06-17 17:55:30 +0000655 # Expat was written by James Clark and is now maintained by a
656 # group of developers on SourceForge; see www.libexpat.org for
657 # more information. The pyexpat module was written by Paul
658 # Prescod after a prototype by Jack Jansen. Source of Expat
659 # 1.95.2 is included in Modules/expat/. Usage of a system
660 # shared libexpat.so/expat.dll is not advised.
661 #
662 # More information on Expat can be found at www.libexpat.org.
663 #
Martin v. Löwiscf453fe2002-02-11 23:27:45 +0000664 if sys.byteorder == "little":
665 xmlbo = "12"
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000666 else:
Martin v. Löwiscf453fe2002-02-11 23:27:45 +0000667 xmlbo = "21"
Martin v. Löwis83012562002-02-14 01:25:37 +0000668 expatinc = os.path.join(os.getcwd(), srcdir, 'Modules', 'expat')
Martin v. Löwiscf453fe2002-02-11 23:27:45 +0000669 exts.append(Extension('pyexpat',
670 sources = [
671 'pyexpat.c',
672 'expat/xmlparse.c',
673 'expat/xmlrole.c',
674 'expat/xmltok.c',
675 ],
676 define_macros = [
677 ('HAVE_EXPAT_H',None),
Martin v. Löwiscf453fe2002-02-11 23:27:45 +0000678 ('XML_NS', '1'),
679 ('XML_DTD', '1'),
680 ('XML_BYTE_ORDER', xmlbo),
681 ('XML_CONTEXT_BYTES','1024'),
682 ],
Martin v. Löwis83012562002-02-14 01:25:37 +0000683 include_dirs = [expatinc]
Martin v. Löwiscf453fe2002-02-11 23:27:45 +0000684 ))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000685
Michael W. Hudson5b109102002-01-23 15:04:41 +0000686 # Dynamic loading module
Guido van Rossum770acd32002-09-12 14:41:20 +0000687 if sys.maxint == 0x7fffffff:
688 # This requires sizeof(int) == sizeof(long) == sizeof(char*)
689 dl_inc = find_file('dlfcn.h', [], inc_dirs)
690 if (dl_inc is not None) and (platform not in ['atheos']):
691 exts.append( Extension('dl', ['dlmodule.c']) )
Michael W. Hudson5b109102002-01-23 15:04:41 +0000692
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000693 # Platform-specific libraries
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000694 if platform == 'linux2':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000695 # Linux-specific modules
696 exts.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) )
697
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000698 if platform == 'sunos5':
Fredrik Lundhade711a2001-01-24 08:00:28 +0000699 # SunOS specific modules
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000700 exts.append( Extension('sunaudiodev', ['sunaudiodev.c']) )
Michael W. Hudson5b109102002-01-23 15:04:41 +0000701
Jack Jansen244e7612001-12-05 15:54:29 +0000702 if platform == 'darwin':
Jack Jansend1b20452002-07-08 21:39:36 +0000703 # Mac OS X specific modules. Modules linked against the Carbon
704 # framework are only built for framework-enabled Pythons. As
705 # of MacOSX 10.1 importing the Carbon framework from a non-windowing
706 # application (MacOSX server, not logged in on the console) may
707 # result in Python crashing.
Jack Jansen2f760c32001-09-04 21:33:12 +0000708 #
709 # I would like to trigger on WITH_NEXT_FRAMEWORK but that isn't
710 # available here. This Makefile variable is also what the install
711 # procedure triggers on.
Jack Jansen0b06be72002-06-21 14:48:38 +0000712 exts.append( Extension('_CF', ['cf/_CFmodule.c', 'cf/pycfbridge.c'],
Michael W. Hudson0c46c0c2002-03-07 09:58:56 +0000713 extra_link_args=['-framework', 'CoreFoundation']) )
Jack Jansend1b20452002-07-08 21:39:36 +0000714
715 framework = sysconfig.get_config_var('PYTHONFRAMEWORK')
716 if framework:
717 exts.append( Extension('gestalt', ['gestaltmodule.c'],
718 extra_link_args=['-framework', 'Carbon']) )
719 exts.append( Extension('MacOS', ['macosmodule.c'],
720 extra_link_args=['-framework', 'Carbon']) )
721 exts.append( Extension('icglue', ['icgluemodule.c'],
722 extra_link_args=['-framework', 'Carbon']) )
723 exts.append( Extension('macfs',
724 ['macfsmodule.c',
725 '../Python/getapplbycreator.c'],
726 extra_link_args=['-framework', 'Carbon']) )
727 exts.append( Extension('_Res', ['res/_Resmodule.c'],
728 extra_link_args=['-framework', 'Carbon']) )
729 exts.append( Extension('_Snd', ['snd/_Sndmodule.c'],
730 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000731 exts.append( Extension('Nav', ['Nav.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000732 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000733 exts.append( Extension('_AE', ['ae/_AEmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000734 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen983258e2002-08-29 21:09:00 +0000735 exts.append( Extension('_AH', ['ah/_AHmodule.c'],
736 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000737 exts.append( Extension('_App', ['app/_Appmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000738 extra_link_args=['-framework', 'Carbon']) )
Jack Jansendd67a8e2001-12-12 23:03:17 +0000739 exts.append( Extension('_CarbonEvt', ['carbonevt/_CarbonEvtmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000740 extra_link_args=['-framework', 'Carbon']) )
Just van Rossume9039b12001-12-13 13:41:36 +0000741 exts.append( Extension('_CG', ['cg/_CGmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000742 extra_link_args=['-framework', 'ApplicationServices',
Just van Rossume9039b12001-12-13 13:41:36 +0000743 '-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000744 exts.append( Extension('_Cm', ['cm/_Cmmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000745 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000746 exts.append( Extension('_Ctl', ['ctl/_Ctlmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000747 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000748 exts.append( Extension('_Dlg', ['dlg/_Dlgmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000749 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000750 exts.append( Extension('_Drag', ['drag/_Dragmodule.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('_Evt', ['evt/_Evtmodule.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('_Fm', ['fm/_Fmmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000755 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen983258e2002-08-29 21:09:00 +0000756 exts.append( Extension('_Help', ['help/_Helpmodule.c'],
757 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000758 exts.append( Extension('_Icn', ['icn/_Icnmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000759 extra_link_args=['-framework', 'Carbon']) )
Jack Jansena30d1442002-08-04 22:04:25 +0000760 exts.append( Extension('_IBCarbon', ['ibcarbon/_IBCarbon.c'],
761 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000762 exts.append( Extension('_List', ['list/_Listmodule.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('_Menu', ['menu/_Menumodule.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('_Mlte', ['mlte/_Mltemodule.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('_Qd', ['qd/_Qdmodule.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('_Qdoffs', ['qdoffs/_Qdoffsmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000771 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen2f760c32001-09-04 21:33:12 +0000772 exts.append( Extension('_Qt', ['qt/_Qtmodule.c'],
Fred Drake38419c02001-12-06 22:24:47 +0000773 extra_link_args=['-framework', 'QuickTime',
774 '-framework', 'Carbon']) )
Jack Jansen796720b2002-01-21 23:10:36 +0000775 exts.append( Extension('_Scrap', ['scrap/_Scrapmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000776 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000777 exts.append( Extension('_TE', ['te/_TEmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000778 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen0b06be72002-06-21 14:48:38 +0000779 # As there is no standardized place (yet) to put
780 # user-installed Mac libraries on OSX, we search for "waste"
781 # in parent directories of the Python source tree. You
782 # should put a symlink to your Waste installation in the
783 # same folder as your python source tree. Or modify the
784 # next few lines:-)
785 waste_incs = find_file("WASTE.h", [],
786 ['../'*n + 'waste/C_C++ Headers' for n in (0,1,2,3,4)])
Jack Jansenedeea042001-12-09 23:08:54 +0000787 waste_libs = find_library_file(self.compiler, "WASTE", [],
Jack Jansend1b20452002-07-08 21:39:36 +0000788 [ "../"*n + "waste/Static Libraries" for n in (0,1,2,3,4)])
Jack Jansenedeea042001-12-09 23:08:54 +0000789 if waste_incs != None and waste_libs != None:
Jack Jansen0b06be72002-06-21 14:48:38 +0000790 (srcdir,) = sysconfig.get_config_vars('srcdir')
Michael W. Hudson5b109102002-01-23 15:04:41 +0000791 exts.append( Extension('waste',
Jack Jansen0b06be72002-06-21 14:48:38 +0000792 ['waste/wastemodule.c'] + [
793 os.path.join(srcdir, d) for d in
Jack Jansenedeea042001-12-09 23:08:54 +0000794 'Mac/Wastemods/WEObjectHandlers.c',
795 'Mac/Wastemods/WETabHooks.c',
796 'Mac/Wastemods/WETabs.c'
797 ],
Jack Jansen0b06be72002-06-21 14:48:38 +0000798 include_dirs = waste_incs + [os.path.join(srcdir, 'Mac/Wastemods')],
Jack Jansenedeea042001-12-09 23:08:54 +0000799 library_dirs = waste_libs,
800 libraries = ['WASTE'],
801 extra_link_args = ['-framework', 'Carbon'],
802 ) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000803 exts.append( Extension('_Win', ['win/_Winmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000804 extra_link_args=['-framework', 'Carbon']) )
805
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000806 self.extensions.extend(exts)
807
808 # Call the method for detecting whether _tkinter can be compiled
809 self.detect_tkinter(inc_dirs, lib_dirs)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000810
Jack Jansen0b06be72002-06-21 14:48:38 +0000811 def detect_tkinter_darwin(self, inc_dirs, lib_dirs):
812 # The _tkinter module, using frameworks. Since frameworks are quite
813 # different the UNIX search logic is not sharable.
814 from os.path import join, exists
815 framework_dirs = [
816 '/System/Library/Frameworks/',
817 '/Library/Frameworks',
818 join(os.getenv('HOME'), '/Library/Frameworks')
819 ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000820
Jack Jansen0b06be72002-06-21 14:48:38 +0000821 # Find the directory that contains the Tcl.framwork and Tk.framework
822 # bundles.
823 # XXX distutils should support -F!
824 for F in framework_dirs:
825 # both Tcl.framework and Tk.framework should be present
826 for fw in 'Tcl', 'Tk':
827 if not exists(join(F, fw + '.framework')):
828 break
829 else:
830 # ok, F is now directory with both frameworks. Continure
831 # building
832 break
833 else:
834 # Tk and Tcl frameworks not found. Normal "unix" tkinter search
835 # will now resume.
836 return 0
837
838 # For 8.4a2, we must add -I options that point inside the Tcl and Tk
839 # frameworks. In later release we should hopefully be able to pass
840 # the -F option to gcc, which specifies a framework lookup path.
841 #
842 include_dirs = [
843 join(F, fw + '.framework', H)
844 for fw in 'Tcl', 'Tk'
845 for H in 'Headers', 'Versions/Current/PrivateHeaders'
846 ]
847
848 # For 8.4a2, the X11 headers are not included. Rather than include a
849 # complicated search, this is a hard-coded path. It could bail out
850 # if X11 libs are not found...
851 include_dirs.append('/usr/X11R6/include')
852 frameworks = ['-framework', 'Tcl', '-framework', 'Tk']
853
854 ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
855 define_macros=[('WITH_APPINIT', 1)],
856 include_dirs = include_dirs,
857 libraries = [],
858 extra_compile_args = frameworks,
859 extra_link_args = frameworks,
860 )
861 self.extensions.append(ext)
862 return 1
863
864
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000865 def detect_tkinter(self, inc_dirs, lib_dirs):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000866 # The _tkinter module.
Michael W. Hudson5b109102002-01-23 15:04:41 +0000867
Jack Jansen0b06be72002-06-21 14:48:38 +0000868 # Rather than complicate the code below, detecting and building
869 # AquaTk is a separate method. Only one Tkinter will be built on
870 # Darwin - either AquaTk, if it is found, or X11 based Tk.
871 platform = self.get_platform()
872 if platform == 'darwin' and \
873 self.detect_tkinter_darwin(inc_dirs, lib_dirs):
874 return
875
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000876 # Assume we haven't found any of the libraries or include files
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +0000877 # The versions with dots are used on Unix, and the versions without
878 # dots on Windows, for detection by cygwin.
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000879 tcllib = tklib = tcl_includes = tk_includes = None
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +0000880 for version in ['8.4', '84', '8.3', '83', '8.2',
881 '82', '8.1', '81', '8.0', '80']:
Michael W. Hudson5b109102002-01-23 15:04:41 +0000882 tklib = self.compiler.find_library_file(lib_dirs,
883 'tk' + version )
884 tcllib = self.compiler.find_library_file(lib_dirs,
885 'tcl' + version )
886 if tklib and tcllib:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000887 # Exit the loop when we've found the Tcl/Tk libraries
888 break
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000889
Fredrik Lundhade711a2001-01-24 08:00:28 +0000890 # Now check for the header files
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000891 if tklib and tcllib:
892 # Check for the include files on Debian, where
893 # they're put in /usr/include/{tcl,tk}X.Y
Andrew M. Kuchling9a3fd8c2001-02-06 22:15:27 +0000894 debian_tcl_include = [ '/usr/include/tcl' + version ]
Fred Drake38419c02001-12-06 22:24:47 +0000895 debian_tk_include = [ '/usr/include/tk' + version ] + \
896 debian_tcl_include
Andrew M. Kuchling9a3fd8c2001-02-06 22:15:27 +0000897 tcl_includes = find_file('tcl.h', inc_dirs, debian_tcl_include)
898 tk_includes = find_file('tk.h', inc_dirs, debian_tk_include)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000899
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000900 if (tcllib is None or tklib is None and
901 tcl_includes is None or tk_includes is None):
902 # Something's missing, so give up
903 return
Fredrik Lundhade711a2001-01-24 08:00:28 +0000904
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000905 # OK... everything seems to be present for Tcl/Tk.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000906
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000907 include_dirs = [] ; libs = [] ; defs = [] ; added_lib_dirs = []
908 for dir in tcl_includes + tk_includes:
909 if dir not in include_dirs:
910 include_dirs.append(dir)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000911
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000912 # Check for various platform-specific directories
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000913 if platform == 'sunos5':
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000914 include_dirs.append('/usr/openwin/include')
915 added_lib_dirs.append('/usr/openwin/lib')
916 elif os.path.exists('/usr/X11R6/include'):
917 include_dirs.append('/usr/X11R6/include')
918 added_lib_dirs.append('/usr/X11R6/lib')
919 elif os.path.exists('/usr/X11R5/include'):
920 include_dirs.append('/usr/X11R5/include')
921 added_lib_dirs.append('/usr/X11R5/lib')
922 else:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000923 # Assume default location for X11
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000924 include_dirs.append('/usr/X11/include')
925 added_lib_dirs.append('/usr/X11/lib')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000926
Andrew M. Kuchling89fb72d2001-09-18 20:32:13 +0000927 # If Cygwin, then verify that X is installed before proceeding
928 if platform == 'cygwin':
929 x11_inc = find_file('X11/Xlib.h', [], inc_dirs)
930 if x11_inc is None:
931 # X header files missing, so give up
932 return
933
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000934 # Check for BLT extension
Fred Drake38419c02001-12-06 22:24:47 +0000935 if self.compiler.find_library_file(lib_dirs + added_lib_dirs,
936 'BLT8.0'):
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000937 defs.append( ('WITH_BLT', 1) )
938 libs.append('BLT8.0')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000939
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000940 # Add the Tcl/Tk libraries
Fredrik Lundhade711a2001-01-24 08:00:28 +0000941 libs.append('tk'+version)
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000942 libs.append('tcl'+version)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000943
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000944 if platform in ['aix3', 'aix4']:
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000945 libs.append('ld')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000946
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +0000947 # Finally, link with the X11 libraries (not appropriate on cygwin)
948 if platform != "cygwin":
949 libs.append('X11')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000950
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000951 ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
952 define_macros=[('WITH_APPINIT', 1)] + defs,
953 include_dirs = include_dirs,
954 libraries = libs,
955 library_dirs = added_lib_dirs,
956 )
957 self.extensions.append(ext)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000958
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000959 # XXX handle these, but how to detect?
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000960 # *** Uncomment and edit for PIL (TkImaging) extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000961 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000962 # *** Uncomment and edit for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000963 # -DWITH_TOGL togl.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000964 # *** Uncomment these for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000965 # -lGL -lGLU -lXext -lXmu \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000966
Andrew M. Kuchlingf52d27e2001-05-21 20:29:27 +0000967class PyBuildInstall(install):
968 # Suppress the warning about installation into the lib_dynload
969 # directory, which is not in sys.path when running Python during
970 # installation:
971 def initialize_options (self):
972 install.initialize_options(self)
973 self.warn_dir=0
Michael W. Hudson5b109102002-01-23 15:04:41 +0000974
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000975def main():
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000976 # turn off warnings when deprecated modules are imported
977 import warnings
978 warnings.filterwarnings("ignore",category=DeprecationWarning)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000979 setup(name = 'Python standard library',
Neil Schemenauere7e2ece2001-01-17 21:58:00 +0000980 version = '%d.%d' % sys.version_info[:2],
Andrew M. Kuchlingf52d27e2001-05-21 20:29:27 +0000981 cmdclass = {'build_ext':PyBuildExt, 'install':PyBuildInstall},
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000982 # The struct module is defined here, because build_ext won't be
983 # called unless there's at least one extension module defined.
Andrew M. Kuchlingaece4272001-02-28 20:56:49 +0000984 ext_modules=[Extension('struct', ['structmodule.c'])],
985
986 # Scripts to install
987 scripts = ['Tools/scripts/pydoc']
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000988 )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000989
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000990# --install-platlib
991if __name__ == '__main__':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000992 main()