blob: a204acf0d9172052c74b6277e6973868aa5c6287 [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."""
21 if os.path.isdir(dir) and dir not in dirlist:
22 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 Jansen244e7612001-12-05 15:54:29 +0000102 if platform == 'darwin':
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
Andrew M. Kuchling8d7f0862001-02-23 16:32:32 +0000129 # Parse Modules/Setup to figure out which modules are turned
Michael W. Hudson5b109102002-01-23 15:04:41 +0000130 # on in the file.
Andrew M. Kuchling8d7f0862001-02-23 16:32:32 +0000131 input = text_file.TextFile('Modules/Setup', join_lines=1)
132 remove_modules = []
133 while 1:
134 line = input.readline()
135 if not line: break
136 line = line.split()
137 remove_modules.append( line[0] )
138 input.close()
Michael W. Hudson5b109102002-01-23 15:04:41 +0000139
Andrew M. Kuchling8d7f0862001-02-23 16:32:32 +0000140 for ext in self.extensions[:]:
141 if ext.name in remove_modules:
142 self.extensions.remove(ext)
Michael W. Hudson5b109102002-01-23 15:04:41 +0000143
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000144 # When you run "make CC=altcc" or something similar, you really want
145 # those environment variables passed into the setup.py phase. Here's
146 # a small set of useful ones.
147 compiler = os.environ.get('CC')
148 linker_so = os.environ.get('LDSHARED')
149 args = {}
150 # unfortunately, distutils doesn't let us provide separate C and C++
151 # compilers
152 if compiler is not None:
Martin v. Löwis3e4b0e82001-08-10 08:56:17 +0000153 (ccshared,opt) = sysconfig.get_config_vars('CCSHARED','OPT')
154 args['compiler_so'] = compiler + ' ' + opt + ' ' + ccshared
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000155 if linker_so is not None:
Martin v. Löwis2f20dab2001-10-08 13:18:37 +0000156 args['linker_so'] = linker_so
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000157 self.compiler.set_executables(**args)
158
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000159 build_ext.build_extensions(self)
160
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000161 def build_extension(self, ext):
162
163 try:
164 build_ext.build_extension(self, ext)
165 except (CCompilerError, DistutilsError), why:
166 self.announce('WARNING: building of extension "%s" failed: %s' %
167 (ext.name, sys.exc_info()[1]))
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000168 return
Jack Jansenf49c6f92001-11-01 14:44:15 +0000169 # Workaround for Mac OS X: The Carbon-based modules cannot be
170 # reliably imported into a command-line Python
171 if 'Carbon' in ext.extra_link_args:
Michael W. Hudson5b109102002-01-23 15:04:41 +0000172 self.announce(
173 'WARNING: skipping import check for Carbon-based "%s"' %
174 ext.name)
175 return
Jason Tishler24cf7762002-05-22 16:46:15 +0000176 # Workaround for Cygwin: Cygwin currently has fork issues when many
177 # modules have been imported
178 if self.get_platform() == 'cygwin':
179 self.announce('WARNING: skipping import check for Cygwin-based "%s"'
180 % ext.name)
181 return
Michael W. Hudsonaf142892002-01-23 15:07:46 +0000182 ext_filename = os.path.join(
183 self.build_lib,
184 self.get_ext_filename(self.get_ext_fullname(ext.name)))
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000185 try:
Michael W. Hudsonaf142892002-01-23 15:07:46 +0000186 imp.load_dynamic(ext.name, ext_filename)
Marc-André Lemburga5d2b4c2002-02-16 18:23:30 +0000187 except ImportError, why:
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000188
Marc-André Lemburga5d2b4c2002-02-16 18:23:30 +0000189 if 1:
Michael W. Hudson7113d962002-03-01 14:16:31 +0000190 self.announce('*** WARNING: renaming "%s" since importing it'
Marc-André Lemburga5d2b4c2002-02-16 18:23:30 +0000191 ' failed: %s' % (ext.name, why))
192 assert not self.inplace
Michael W. Hudson7113d962002-03-01 14:16:31 +0000193 basename, tail = os.path.splitext(ext_filename)
194 newname = basename + "_failed" + tail
195 if os.path.exists(newname): os.remove(newname)
196 os.rename(ext_filename, newname)
Marc-André Lemburga5d2b4c2002-02-16 18:23:30 +0000197
198 # XXX -- This relies on a Vile HACK in
199 # distutils.command.build_ext.build_extension(). The
200 # _built_objects attribute is stored there strictly for
201 # use here.
Neal Norwitz03ffbcd2002-03-25 14:20:09 +0000202 # If there is a failure, _built_objects may not be there,
203 # so catch the AttributeError and move on.
204 try:
205 for filename in self._built_objects:
206 os.remove(filename)
207 except AttributeError:
208 self.announce('unable to remove files (ignored)')
Marc-André Lemburga5d2b4c2002-02-16 18:23:30 +0000209 else:
210 self.announce('*** WARNING: importing extension "%s" '
211 'failed: %s' % (ext.name, why))
Fred Drake9028d0a2001-12-06 22:59:54 +0000212
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000213 def get_platform (self):
Fredrik Lundhade711a2001-01-24 08:00:28 +0000214 # Get value of sys.platform
215 platform = sys.platform
216 if platform[:6] =='cygwin':
217 platform = 'cygwin'
Andrew M. Kuchling3c044942001-02-06 23:37:23 +0000218 elif platform[:4] =='beos':
219 platform = 'beos'
Jack Jansen244e7612001-12-05 15:54:29 +0000220 elif platform[:6] == 'darwin':
221 platform = 'darwin'
Martin v. Löwisf90ae202002-06-11 06:22:31 +0000222 elif platform[:6] == 'atheos':
223 platform = 'atheos'
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000224
Fredrik Lundhade711a2001-01-24 08:00:28 +0000225 return platform
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000226
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000227 def detect_modules(self):
Fredrik Lundhade711a2001-01-24 08:00:28 +0000228 # Ensure that /usr/local is always used
Michael W. Hudson39230b32002-01-16 15:26:48 +0000229 add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
230 add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
231
232 add_dir_to_list(self.compiler.library_dirs,
233 sysconfig.get_config_var("LIBDIR"))
234 add_dir_to_list(self.compiler.include_dirs,
235 sysconfig.get_config_var("INCLUDEDIR"))
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000236
Martin v. Löwis339d0f72001-08-17 18:39:25 +0000237 try:
238 have_unicode = unicode
239 except NameError:
240 have_unicode = 0
241
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000242 # lib_dirs and inc_dirs are used to search for files;
243 # if a file is found in one of those directories, it can
244 # be assumed that no additional -I,-L directives are needed.
245 lib_dirs = self.compiler.library_dirs + ['/lib', '/usr/lib']
Michael W. Hudson5b109102002-01-23 15:04:41 +0000246 inc_dirs = self.compiler.include_dirs + ['/usr/include']
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000247 exts = []
248
Fredrik Lundhade711a2001-01-24 08:00:28 +0000249 platform = self.get_platform()
Martin v. Löwis83012562002-02-14 01:25:37 +0000250 (srcdir,) = sysconfig.get_config_vars('srcdir')
Michael W. Hudson5b109102002-01-23 15:04:41 +0000251
Martin v. Löwisf90ae202002-06-11 06:22:31 +0000252 # Check for AtheOS which has libraries in non-standard locations
253 if platform == 'atheos':
254 lib_dirs += ['/system/libs', '/atheos/autolnk/lib']
255 lib_dirs += os.getenv('LIBRARY_PATH', '').split(os.pathsep)
256 inc_dirs += ['/system/include', '/atheos/autolnk/include']
257 inc_dirs += os.getenv('C_INCLUDE_PATH', '').split(os.pathsep)
258
Fredrik Lundhade711a2001-01-24 08:00:28 +0000259 # Check for MacOS X, which doesn't need libm.a at all
260 math_libs = ['m']
Jack Jansen244e7612001-12-05 15:54:29 +0000261 if platform in ['darwin', 'beos']:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000262 math_libs = []
Michael W. Hudson5b109102002-01-23 15:04:41 +0000263
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000264 # XXX Omitted modules: gl, pure, dl, SGI-specific modules
265
266 #
267 # The following modules are all pretty straightforward, and compile
268 # on pretty much any POSIXish platform.
269 #
Fredrik Lundhade711a2001-01-24 08:00:28 +0000270
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000271 # Some modules that are normally always on:
272 exts.append( Extension('regex', ['regexmodule.c', 'regexpr.c']) )
273 exts.append( Extension('pcre', ['pcremodule.c', 'pypcre.c']) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000274
Fred Drake3a40f322001-10-12 21:00:48 +0000275 exts.append( Extension('_hotshot', ['_hotshot.c']) )
Fred Drake2de74712001-02-01 05:26:54 +0000276 exts.append( Extension('_weakref', ['_weakref.c']) )
Andrew M. Kuchlingd5c43062001-01-17 15:59:25 +0000277 exts.append( Extension('xreadlines', ['xreadlinesmodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000278
279 # array objects
280 exts.append( Extension('array', ['arraymodule.c']) )
281 # complex math library functions
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000282 exts.append( Extension('cmath', ['cmathmodule.c'],
283 libraries=math_libs) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000284
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000285 # math library functions, e.g. sin()
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000286 exts.append( Extension('math', ['mathmodule.c'],
287 libraries=math_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000288 # fast string operations implemented in C
289 exts.append( Extension('strop', ['stropmodule.c']) )
290 # time operations and variables
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000291 exts.append( Extension('time', ['timemodule.c'],
292 libraries=math_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000293 # operator.add() and similar goodies
294 exts.append( Extension('operator', ['operator.c']) )
295 # access to the builtin codecs and codec registry
296 exts.append( Extension('_codecs', ['_codecsmodule.c']) )
Marc-André Lemburg261b8e22001-02-02 12:12:44 +0000297 # Python C API test module
Tim Petersd66595f2001-02-04 03:09:53 +0000298 exts.append( Extension('_testcapi', ['_testcapimodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000299 # static Unicode character database
Martin v. Löwis339d0f72001-08-17 18:39:25 +0000300 if have_unicode:
301 exts.append( Extension('unicodedata', ['unicodedata.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000302 # access to ISO C locale support
303 exts.append( Extension('_locale', ['_localemodule.c']) )
304
305 # Modules with some UNIX dependencies -- on by default:
306 # (If you have a really backward UNIX, select and socket may not be
307 # supported...)
308
309 # fcntl(2) and ioctl(2)
310 exts.append( Extension('fcntl', ['fcntlmodule.c']) )
311 # pwd(3)
312 exts.append( Extension('pwd', ['pwdmodule.c']) )
313 # grp(3)
314 exts.append( Extension('grp', ['grpmodule.c']) )
315 # posix (UNIX) errno values
316 exts.append( Extension('errno', ['errnomodule.c']) )
317 # select(2); not on ancient System V
318 exts.append( Extension('select', ['selectmodule.c']) )
319
320 # The md5 module implements the RSA Data Security, Inc. MD5
Fred Drake38419c02001-12-06 22:24:47 +0000321 # Message-Digest Algorithm, described in RFC 1321. The
322 # necessary files md5c.c and md5.h are included here.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000323 exts.append( Extension('md5', ['md5module.c', 'md5c.c']) )
324
325 # The sha module implements the SHA checksum algorithm.
326 # (NIST's Secure Hash Algorithm.)
327 exts.append( Extension('sha', ['shamodule.c']) )
328
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000329 # Helper module for various ascii-encoders
330 exts.append( Extension('binascii', ['binascii.c']) )
331
332 # Fred Drake's interface to the Python parser
333 exts.append( Extension('parser', ['parsermodule.c']) )
334
Guido van Rossum2e1c09c2002-04-04 17:52:50 +0000335 # cStringIO and cPickle
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000336 exts.append( Extension('cStringIO', ['cStringIO.c']) )
337 exts.append( Extension('cPickle', ['cPickle.c']) )
338
339 # Memory-mapped files (also works on Win32).
Martin v. Löwisf90ae202002-06-11 06:22:31 +0000340 if platform not in ['atheos']:
341 exts.append( Extension('mmap', ['mmapmodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000342
343 # Lance Ellinghaus's modules:
344 # enigma-inspired encryption
345 exts.append( Extension('rotor', ['rotormodule.c']) )
346 # syslog daemon interface
347 exts.append( Extension('syslog', ['syslogmodule.c']) )
348
349 # George Neville-Neil's timing module:
350 exts.append( Extension('timing', ['timingmodule.c']) )
351
352 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000353 # Here ends the simple stuff. From here on, modules need certain
354 # libraries, are platform-specific, or present other surprises.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000355 #
356
357 # Multimedia modules
358 # These don't work for 64-bit platforms!!!
359 # These represent audio samples or images as strings:
360
Fredrik Lundhade711a2001-01-24 08:00:28 +0000361 # Disabled on 64-bit platforms
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000362 if sys.maxint != 9223372036854775807L:
363 # Operations on audio samples
364 exts.append( Extension('audioop', ['audioop.c']) )
365 # Operations on images
366 exts.append( Extension('imageop', ['imageop.c']) )
367 # Read SGI RGB image files (but coded portably)
368 exts.append( Extension('rgbimg', ['rgbimgmodule.c']) )
369
370 # readline
Marc-André Lemburg2efc3232001-01-26 18:23:02 +0000371 if self.compiler.find_library_file(lib_dirs, 'readline'):
372 readline_libs = ['readline']
Andrew M. Kuchling5aa3c4a2001-08-16 20:30:18 +0000373 if self.compiler.find_library_file(lib_dirs,
374 'ncurses'):
375 readline_libs.append('ncurses')
376 elif self.compiler.find_library_file(lib_dirs +
Marc-André Lemburg2efc3232001-01-26 18:23:02 +0000377 ['/usr/lib/termcap'],
378 'termcap'):
379 readline_libs.append('termcap')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000380 exts.append( Extension('readline', ['readline.c'],
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000381 library_dirs=['/usr/lib/termcap'],
Marc-André Lemburg2efc3232001-01-26 18:23:02 +0000382 libraries=readline_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000383
Andrew M. Kuchling5aa3c4a2001-08-16 20:30:18 +0000384 # crypt module.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000385
386 if self.compiler.find_library_file(lib_dirs, 'crypt'):
387 libs = ['crypt']
388 else:
389 libs = []
390 exts.append( Extension('crypt', ['cryptmodule.c'], libraries=libs) )
391
392 # socket(2)
Guido van Rossum47d3a7a2002-06-13 14:41:32 +0000393 exts.append( Extension('_socket', ['socketmodule.c'],
Jeremy Hylton340043e2002-06-13 17:38:11 +0000394 depends = ['socketmodule.h']) )
Marc-André Lemburga5d2b4c2002-02-16 18:23:30 +0000395 # Detect SSL support for the socket module (via _ssl)
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000396 ssl_incs = find_file('openssl/ssl.h', inc_dirs,
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +0000397 ['/usr/local/ssl/include',
398 '/usr/contrib/ssl/include/'
399 ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000400 )
401 ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs,
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +0000402 ['/usr/local/ssl/lib',
403 '/usr/contrib/ssl/lib/'
404 ] )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000405
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000406 if (ssl_incs is not None and
407 ssl_libs is not None):
Marc-André Lemburga5d2b4c2002-02-16 18:23:30 +0000408 exts.append( Extension('_ssl', ['_ssl.c'],
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000409 include_dirs = ssl_incs,
Fredrik Lundhade711a2001-01-24 08:00:28 +0000410 library_dirs = ssl_libs,
Guido van Rossum47d3a7a2002-06-13 14:41:32 +0000411 libraries = ['ssl', 'crypto'],
Jeremy Hylton340043e2002-06-13 17:38:11 +0000412 depends = ['socketmodule.h']), )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000413
414 # Modules that provide persistent dictionary-like semantics. You will
415 # probably want to arrange for at least one of them to be available on
416 # your machine, though none are defined by default because of library
417 # dependencies. The Python module anydbm.py provides an
418 # implementation independent wrapper for these; dumbdbm.py provides
419 # similar functionality (but slower of course) implemented in Python.
420
421 # The standard Unix dbm module:
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000422 if platform not in ['cygwin']:
423 if (self.compiler.find_library_file(lib_dirs, 'ndbm')):
424 exts.append( Extension('dbm', ['dbmmodule.c'],
425 libraries = ['ndbm'] ) )
Neil Schemenauerc3ffef62001-10-21 22:14:44 +0000426 elif self.compiler.find_library_file(lib_dirs, 'db1'):
427 exts.append( Extension('dbm', ['dbmmodule.c'],
428 libraries = ['db1'] ) )
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000429 else:
430 exts.append( Extension('dbm', ['dbmmodule.c']) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000431
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000432 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
433 if (self.compiler.find_library_file(lib_dirs, 'gdbm')):
434 exts.append( Extension('gdbm', ['gdbmmodule.c'],
435 libraries = ['gdbm'] ) )
436
437 # Berkeley DB interface.
438 #
439 # This requires the Berkeley DB code, see
440 # ftp://ftp.cs.berkeley.edu/pub/4bsd/db.1.85.tar.gz
441 #
442 # Edit the variables DB and DBPORT to point to the db top directory
443 # and the subdirectory of PORT where you built it.
444 #
Greg Ward02fac832001-09-13 15:05:08 +0000445 # (See http://pybsddb.sourceforge.net/ for an interface to
446 # Berkeley DB 3.x.)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000447
Andrew M. Kuchlinge06337a2001-02-23 16:27:48 +0000448 dblib = []
Martin v. Löwisf5c76772001-11-24 09:28:42 +0000449 if self.compiler.find_library_file(lib_dirs, 'db-3.2'):
450 dblib = ['db-3.2']
451 elif self.compiler.find_library_file(lib_dirs, 'db-3.1'):
Skip Montanaroe81f4472001-08-21 04:23:21 +0000452 dblib = ['db-3.1']
Neil Schemenauerc3ffef62001-10-21 22:14:44 +0000453 elif self.compiler.find_library_file(lib_dirs, 'db3'):
454 dblib = ['db3']
Skip Montanaroe81f4472001-08-21 04:23:21 +0000455 elif self.compiler.find_library_file(lib_dirs, 'db2'):
456 dblib = ['db2']
457 elif self.compiler.find_library_file(lib_dirs, 'db1'):
458 dblib = ['db1']
459 elif self.compiler.find_library_file(lib_dirs, 'db'):
Andrew M. Kuchlinge06337a2001-02-23 16:27:48 +0000460 dblib = ['db']
Michael W. Hudson5b109102002-01-23 15:04:41 +0000461
Andrew M. Kuchlinge06337a2001-02-23 16:27:48 +0000462 db185_incs = find_file('db_185.h', inc_dirs,
463 ['/usr/include/db3', '/usr/include/db2'])
464 db_inc = find_file('db.h', inc_dirs, ['/usr/include/db1'])
465 if db185_incs is not None:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000466 exts.append( Extension('bsddb', ['bsddbmodule.c'],
Andrew M. Kuchlinge06337a2001-02-23 16:27:48 +0000467 include_dirs = db185_incs,
468 define_macros=[('HAVE_DB_185_H',1)],
469 libraries = dblib ) )
470 elif db_inc is not None:
471 exts.append( Extension('bsddb', ['bsddbmodule.c'],
472 include_dirs = db_inc,
473 libraries = dblib) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000474
475 # The mpz module interfaces to the GNU Multiple Precision library.
Fredrik Lundhade711a2001-01-24 08:00:28 +0000476 # You need to ftp the GNU MP library.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000477 # This was originally written and tested against GMP 1.2 and 1.3.2.
478 # 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 +0000479 # haven't tested it recently, and it definitely doesn't work with
480 # GMP 4.0. For more complete modules, refer to
481 # http://gmpy.sourceforge.net and
482 # http://www.egenix.com/files/python/mxNumber.html
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000483
Greg Ward57fc2102001-10-03 19:59:30 +0000484 # A compatible MP library unencumbered by the GPL also exists. It was
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000485 # posted to comp.sources.misc in volume 40 and is widely available from
486 # FTP archive sites. One URL for it is:
487 # ftp://gatekeeper.dec.com/.b/usenet/comp.sources.misc/volume40/fgmp/part01.Z
488
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000489 if (self.compiler.find_library_file(lib_dirs, 'gmp')):
490 exts.append( Extension('mpz', ['mpzmodule.c'],
491 libraries = ['gmp'] ) )
492
493
494 # Unix-only modules
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000495 if platform not in ['mac', 'win32']:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000496 # Steen Lumholt's termios module
497 exts.append( Extension('termios', ['termios.c']) )
498 # Jeremy Hylton's rlimit interface
Martin v. Löwisf90ae202002-06-11 06:22:31 +0000499 if platform not in ['atheos']:
500 exts.append( Extension('resource', ['resource.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000501
Andrew M. Kuchlingcf393f32001-02-21 02:38:24 +0000502 # Sun yellow pages. Some systems have the functions in libc.
Martin v. Löwisf90ae202002-06-11 06:22:31 +0000503 if platform not in ['cygwin', 'atheos']:
Andrew M. Kuchling6efc6e72001-02-27 20:54:23 +0000504 if (self.compiler.find_library_file(lib_dirs, 'nsl')):
505 libs = ['nsl']
506 else:
507 libs = []
508 exts.append( Extension('nis', ['nismodule.c'],
509 libraries = libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000510
511 # Curses support, requring the System V version of curses, often
Fredrik Lundhade711a2001-01-24 08:00:28 +0000512 # provided by the ncurses library.
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000513 if platform == 'sunos4':
Andrew M. Kuchlingb69c7582001-02-28 19:49:57 +0000514 inc_dirs += ['/usr/5include']
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000515 lib_dirs += ['/usr/5lib']
516
517 if (self.compiler.find_library_file(lib_dirs, 'ncurses')):
518 curses_libs = ['ncurses']
519 exts.append( Extension('_curses', ['_cursesmodule.c'],
520 libraries = curses_libs) )
Fred Drake38419c02001-12-06 22:24:47 +0000521 elif (self.compiler.find_library_file(lib_dirs, 'curses')
522 and platform != 'darwin'):
Michael W. Hudson5b109102002-01-23 15:04:41 +0000523 # OSX has an old Berkeley curses, not good enough for
524 # the _curses module.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000525 if (self.compiler.find_library_file(lib_dirs, 'terminfo')):
526 curses_libs = ['curses', 'terminfo']
527 else:
528 curses_libs = ['curses', 'termcap']
Fredrik Lundhade711a2001-01-24 08:00:28 +0000529
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000530 exts.append( Extension('_curses', ['_cursesmodule.c'],
531 libraries = curses_libs) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000532
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000533 # If the curses module is enabled, check for the panel module
Andrew M. Kuchlinge7ffbb22001-12-06 15:57:16 +0000534 if (module_enabled(exts, '_curses') and
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000535 self.compiler.find_library_file(lib_dirs, 'panel')):
536 exts.append( Extension('_curses_panel', ['_curses_panel.c'],
537 libraries = ['panel'] + curses_libs) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000538
539
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000540
541 # Lee Busby's SIGFPE modules.
542 # The library to link fpectl with is platform specific.
543 # Choose *one* of the options below for fpectl:
544
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000545 if platform == 'irix5':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000546 # For SGI IRIX (tested on 5.3):
547 exts.append( Extension('fpectl', ['fpectlmodule.c'],
548 libraries=['fpe']) )
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000549 elif 0: # XXX how to detect SunPro?
Fred Drake38419c02001-12-06 22:24:47 +0000550 # For Solaris with SunPro compiler (tested on Solaris 2.5
551 # with SunPro C 4.2): (Without the compiler you don't have
552 # -lsunmath.)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000553 #fpectl fpectlmodule.c -R/opt/SUNWspro/lib -lsunmath -lm
554 pass
555 else:
556 # For other systems: see instructions in fpectlmodule.c.
557 #fpectl fpectlmodule.c ...
558 exts.append( Extension('fpectl', ['fpectlmodule.c']) )
559
560
561 # Andrew Kuchling's zlib module.
562 # This require zlib 1.1.3 (or later).
563 # See http://www.cdrom.com/pub/infozip/zlib/
Guido van Rossume6970912001-04-15 15:16:12 +0000564 zlib_inc = find_file('zlib.h', [], inc_dirs)
565 if zlib_inc is not None:
566 zlib_h = zlib_inc[0] + '/zlib.h'
567 version = '"0.0.0"'
568 version_req = '"1.1.3"'
569 fp = open(zlib_h)
570 while 1:
571 line = fp.readline()
572 if not line:
573 break
574 if line.find('#define ZLIB_VERSION', 0) == 0:
575 version = line.split()[2]
576 break
577 if version >= version_req:
578 if (self.compiler.find_library_file(lib_dirs, 'z')):
579 exts.append( Extension('zlib', ['zlibmodule.c'],
580 libraries = ['z']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000581
582 # Interface to the Expat XML parser
583 #
584 # Expat is written by James Clark and must be downloaded separately
585 # (see below). The pyexpat module was written by Paul Prescod after a
Martin v. Löwiscf453fe2002-02-11 23:27:45 +0000586 # prototype by Jack Jansen. Source of Expat 1.95.2 is included
587 # in Modules/expat. Usage of a system shared libexpat.so/expat.dll
588 # is only advised if that has the same or newer version and was
589 # build using the same defines.
590 if sys.byteorder == "little":
591 xmlbo = "12"
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000592 else:
Martin v. Löwiscf453fe2002-02-11 23:27:45 +0000593 xmlbo = "21"
Martin v. Löwis83012562002-02-14 01:25:37 +0000594 expatinc = os.path.join(os.getcwd(), srcdir, 'Modules', 'expat')
Martin v. Löwiscf453fe2002-02-11 23:27:45 +0000595 exts.append(Extension('pyexpat',
596 sources = [
597 'pyexpat.c',
598 'expat/xmlparse.c',
599 'expat/xmlrole.c',
600 'expat/xmltok.c',
601 ],
602 define_macros = [
603 ('HAVE_EXPAT_H',None),
Martin v. Löwiscf453fe2002-02-11 23:27:45 +0000604 ('XML_NS', '1'),
605 ('XML_DTD', '1'),
606 ('XML_BYTE_ORDER', xmlbo),
607 ('XML_CONTEXT_BYTES','1024'),
608 ],
Martin v. Löwis83012562002-02-14 01:25:37 +0000609 include_dirs = [expatinc]
Martin v. Löwiscf453fe2002-02-11 23:27:45 +0000610 ))
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000611
Michael W. Hudson5b109102002-01-23 15:04:41 +0000612 # Dynamic loading module
Martin v. Löwis93227272002-01-01 20:18:30 +0000613 dl_inc = find_file('dlfcn.h', [], inc_dirs)
Martin v. Löwisf90ae202002-06-11 06:22:31 +0000614 if (dl_inc is not None) and (platform not in ['atheos']):
Michael W. Hudson5b109102002-01-23 15:04:41 +0000615 exts.append( Extension('dl', ['dlmodule.c']) )
616
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000617 # Platform-specific libraries
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000618 if platform == 'linux2':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000619 # Linux-specific modules
620 exts.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) )
621
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000622 if platform == 'sunos5':
Fredrik Lundhade711a2001-01-24 08:00:28 +0000623 # SunOS specific modules
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000624 exts.append( Extension('sunaudiodev', ['sunaudiodev.c']) )
Michael W. Hudson5b109102002-01-23 15:04:41 +0000625
Jack Jansen244e7612001-12-05 15:54:29 +0000626 if platform == 'darwin':
Jack Jansen144ebcc2001-08-05 22:31:19 +0000627 # Mac OS X specific modules. These are ported over from MacPython
628 # and still experimental. Some (such as gestalt or icglue) are
629 # already generally useful, some (the GUI ones) really need to
630 # be used from a framework.
Jack Jansen2f760c32001-09-04 21:33:12 +0000631 #
632 # I would like to trigger on WITH_NEXT_FRAMEWORK but that isn't
633 # available here. This Makefile variable is also what the install
634 # procedure triggers on.
635 frameworkdir = sysconfig.get_config_var('PYTHONFRAMEWORKDIR')
Michael W. Hudson0c46c0c2002-03-07 09:58:56 +0000636 exts.append( Extension('gestalt', ['gestaltmodule.c'],
Neal Norwitz03ffbcd2002-03-25 14:20:09 +0000637 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000638 exts.append( Extension('MacOS', ['macosmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000639 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000640 exts.append( Extension('icglue', ['icgluemodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000641 extra_link_args=['-framework', 'Carbon']) )
Fred Drake38419c02001-12-06 22:24:47 +0000642 exts.append( Extension('macfs',
643 ['macfsmodule.c',
644 '../Python/getapplbycreator.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000645 extra_link_args=['-framework', 'Carbon']) )
Michael W. Hudson0c46c0c2002-03-07 09:58:56 +0000646 exts.append( Extension('_CF', ['cf/_CFmodule.c'],
647 extra_link_args=['-framework', 'CoreFoundation']) )
648 exts.append( Extension('_Res', ['res/_Resmodule.c'],
649 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000650 exts.append( Extension('_Snd', ['snd/_Sndmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000651 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen2f760c32001-09-04 21:33:12 +0000652 if frameworkdir:
Jack Jansen666b1e72001-10-31 12:11:48 +0000653 exts.append( Extension('Nav', ['Nav.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000654 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000655 exts.append( Extension('_AE', ['ae/_AEmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000656 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000657 exts.append( Extension('_App', ['app/_Appmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000658 extra_link_args=['-framework', 'Carbon']) )
Jack Jansendd67a8e2001-12-12 23:03:17 +0000659 exts.append( Extension('_CarbonEvt', ['carbonevt/_CarbonEvtmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000660 extra_link_args=['-framework', 'Carbon']) )
Just van Rossume9039b12001-12-13 13:41:36 +0000661 exts.append( Extension('_CG', ['cg/_CGmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000662 extra_link_args=['-framework', 'ApplicationServices',
Just van Rossume9039b12001-12-13 13:41:36 +0000663 '-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000664 exts.append( Extension('_Cm', ['cm/_Cmmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000665 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000666 exts.append( Extension('_Ctl', ['ctl/_Ctlmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000667 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000668 exts.append( Extension('_Dlg', ['dlg/_Dlgmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000669 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000670 exts.append( Extension('_Drag', ['drag/_Dragmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000671 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000672 exts.append( Extension('_Evt', ['evt/_Evtmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000673 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000674 exts.append( Extension('_Fm', ['fm/_Fmmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000675 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000676 exts.append( Extension('_Icn', ['icn/_Icnmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000677 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000678 exts.append( Extension('_List', ['list/_Listmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000679 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000680 exts.append( Extension('_Menu', ['menu/_Menumodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000681 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000682 exts.append( Extension('_Mlte', ['mlte/_Mltemodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000683 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000684 exts.append( Extension('_Qd', ['qd/_Qdmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000685 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000686 exts.append( Extension('_Qdoffs', ['qdoffs/_Qdoffsmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000687 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen2f760c32001-09-04 21:33:12 +0000688 exts.append( Extension('_Qt', ['qt/_Qtmodule.c'],
Fred Drake38419c02001-12-06 22:24:47 +0000689 extra_link_args=['-framework', 'QuickTime',
690 '-framework', 'Carbon']) )
Jack Jansen796720b2002-01-21 23:10:36 +0000691 exts.append( Extension('_Scrap', ['scrap/_Scrapmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000692 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000693 exts.append( Extension('_TE', ['te/_TEmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000694 extra_link_args=['-framework', 'Carbon']) )
Jack Jansenedeea042001-12-09 23:08:54 +0000695 # As there is no standardized place (yet) to put user-installed
696 # Mac libraries on OSX you should put a symlink to your Waste
697 # installation in the same folder as your python source tree.
698 # Or modify the next two lines:-)
699 waste_incs = find_file("WASTE.h", [], ["../waste/C_C++ Headers"])
700 waste_libs = find_library_file(self.compiler, "WASTE", [],
701 ["../waste/Static Libraries"])
702 if waste_incs != None and waste_libs != None:
Michael W. Hudson5b109102002-01-23 15:04:41 +0000703 exts.append( Extension('waste',
Jack Jansenedeea042001-12-09 23:08:54 +0000704 ['waste/wastemodule.c',
705 'Mac/Wastemods/WEObjectHandlers.c',
706 'Mac/Wastemods/WETabHooks.c',
707 'Mac/Wastemods/WETabs.c'
708 ],
709 include_dirs = waste_incs + ['Mac/Wastemods'],
710 library_dirs = waste_libs,
711 libraries = ['WASTE'],
712 extra_link_args = ['-framework', 'Carbon'],
713 ) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000714 exts.append( Extension('_Win', ['win/_Winmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000715 extra_link_args=['-framework', 'Carbon']) )
716
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000717 self.extensions.extend(exts)
718
719 # Call the method for detecting whether _tkinter can be compiled
720 self.detect_tkinter(inc_dirs, lib_dirs)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000721
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000722
723 def detect_tkinter(self, inc_dirs, lib_dirs):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000724 # The _tkinter module.
Michael W. Hudson5b109102002-01-23 15:04:41 +0000725
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000726 # Assume we haven't found any of the libraries or include files
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +0000727 # The versions with dots are used on Unix, and the versions without
728 # dots on Windows, for detection by cygwin.
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000729 tcllib = tklib = tcl_includes = tk_includes = None
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +0000730 for version in ['8.4', '84', '8.3', '83', '8.2',
731 '82', '8.1', '81', '8.0', '80']:
Michael W. Hudson5b109102002-01-23 15:04:41 +0000732 tklib = self.compiler.find_library_file(lib_dirs,
733 'tk' + version )
734 tcllib = self.compiler.find_library_file(lib_dirs,
735 'tcl' + version )
736 if tklib and tcllib:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000737 # Exit the loop when we've found the Tcl/Tk libraries
738 break
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000739
Fredrik Lundhade711a2001-01-24 08:00:28 +0000740 # Now check for the header files
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000741 if tklib and tcllib:
742 # Check for the include files on Debian, where
743 # they're put in /usr/include/{tcl,tk}X.Y
Andrew M. Kuchling9a3fd8c2001-02-06 22:15:27 +0000744 debian_tcl_include = [ '/usr/include/tcl' + version ]
Fred Drake38419c02001-12-06 22:24:47 +0000745 debian_tk_include = [ '/usr/include/tk' + version ] + \
746 debian_tcl_include
Andrew M. Kuchling9a3fd8c2001-02-06 22:15:27 +0000747 tcl_includes = find_file('tcl.h', inc_dirs, debian_tcl_include)
748 tk_includes = find_file('tk.h', inc_dirs, debian_tk_include)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000749
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000750 if (tcllib is None or tklib is None and
751 tcl_includes is None or tk_includes is None):
752 # Something's missing, so give up
753 return
Fredrik Lundhade711a2001-01-24 08:00:28 +0000754
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000755 # OK... everything seems to be present for Tcl/Tk.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000756
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000757 include_dirs = [] ; libs = [] ; defs = [] ; added_lib_dirs = []
758 for dir in tcl_includes + tk_includes:
759 if dir not in include_dirs:
760 include_dirs.append(dir)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000761
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000762 # Check for various platform-specific directories
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000763 platform = self.get_platform()
764 if platform == 'sunos5':
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000765 include_dirs.append('/usr/openwin/include')
766 added_lib_dirs.append('/usr/openwin/lib')
767 elif os.path.exists('/usr/X11R6/include'):
768 include_dirs.append('/usr/X11R6/include')
769 added_lib_dirs.append('/usr/X11R6/lib')
770 elif os.path.exists('/usr/X11R5/include'):
771 include_dirs.append('/usr/X11R5/include')
772 added_lib_dirs.append('/usr/X11R5/lib')
773 else:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000774 # Assume default location for X11
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000775 include_dirs.append('/usr/X11/include')
776 added_lib_dirs.append('/usr/X11/lib')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000777
Andrew M. Kuchling89fb72d2001-09-18 20:32:13 +0000778 # If Cygwin, then verify that X is installed before proceeding
779 if platform == 'cygwin':
780 x11_inc = find_file('X11/Xlib.h', [], inc_dirs)
781 if x11_inc is None:
782 # X header files missing, so give up
783 return
784
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000785 # Check for BLT extension
Fred Drake38419c02001-12-06 22:24:47 +0000786 if self.compiler.find_library_file(lib_dirs + added_lib_dirs,
787 'BLT8.0'):
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000788 defs.append( ('WITH_BLT', 1) )
789 libs.append('BLT8.0')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000790
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000791 # Add the Tcl/Tk libraries
Fredrik Lundhade711a2001-01-24 08:00:28 +0000792 libs.append('tk'+version)
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000793 libs.append('tcl'+version)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000794
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000795 if platform in ['aix3', 'aix4']:
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000796 libs.append('ld')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000797
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +0000798 # Finally, link with the X11 libraries (not appropriate on cygwin)
799 if platform != "cygwin":
800 libs.append('X11')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000801
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000802 ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
803 define_macros=[('WITH_APPINIT', 1)] + defs,
804 include_dirs = include_dirs,
805 libraries = libs,
806 library_dirs = added_lib_dirs,
807 )
808 self.extensions.append(ext)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000809
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000810 # XXX handle these, but how to detect?
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000811 # *** Uncomment and edit for PIL (TkImaging) extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000812 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000813 # *** Uncomment and edit for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000814 # -DWITH_TOGL togl.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000815 # *** Uncomment these for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000816 # -lGL -lGLU -lXext -lXmu \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000817
Andrew M. Kuchlingf52d27e2001-05-21 20:29:27 +0000818class PyBuildInstall(install):
819 # Suppress the warning about installation into the lib_dynload
820 # directory, which is not in sys.path when running Python during
821 # installation:
822 def initialize_options (self):
823 install.initialize_options(self)
824 self.warn_dir=0
Michael W. Hudson5b109102002-01-23 15:04:41 +0000825
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000826def main():
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000827 # turn off warnings when deprecated modules are imported
828 import warnings
829 warnings.filterwarnings("ignore",category=DeprecationWarning)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000830 setup(name = 'Python standard library',
Neil Schemenauere7e2ece2001-01-17 21:58:00 +0000831 version = '%d.%d' % sys.version_info[:2],
Andrew M. Kuchlingf52d27e2001-05-21 20:29:27 +0000832 cmdclass = {'build_ext':PyBuildExt, 'install':PyBuildInstall},
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000833 # The struct module is defined here, because build_ext won't be
834 # called unless there's at least one extension module defined.
Andrew M. Kuchlingaece4272001-02-28 20:56:49 +0000835 ext_modules=[Extension('struct', ['structmodule.c'])],
836
837 # Scripts to install
838 scripts = ['Tools/scripts/pydoc']
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000839 )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000840
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000841# --install-platlib
842if __name__ == '__main__':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000843 main()