blob: ae08f4a6136f8ee90a2c11299f150eab4e3c0406 [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
6import sys, os, getopt
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
Andrew M. Kuchling3da989c2001-02-28 22:49:26 +0000108 # Fix up the paths for scripts, too
109 self.distribution.scripts = [os.path.join(srcdir, filename)
110 for filename in self.distribution.scripts]
111
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000112 for ext in self.extensions[:]:
Jack Jansen144ebcc2001-08-05 22:31:19 +0000113 ext.sources = [ find_module_file(filename, moddirlist)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000114 for filename in ext.sources ]
Jack Jansen144ebcc2001-08-05 22:31:19 +0000115 ext.include_dirs.append( '.' ) # to get config.h
116 for incdir in incdirlist:
117 ext.include_dirs.append( os.path.join(srcdir, incdir) )
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000118
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +0000119 # If a module has already been built statically,
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000120 # don't build it here
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +0000121 if ext.name in sys.builtin_module_names:
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000122 self.extensions.remove(ext)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000123
Andrew M. Kuchling8d7f0862001-02-23 16:32:32 +0000124 # Parse Modules/Setup to figure out which modules are turned
Michael W. Hudson5b109102002-01-23 15:04:41 +0000125 # on in the file.
Andrew M. Kuchling8d7f0862001-02-23 16:32:32 +0000126 input = text_file.TextFile('Modules/Setup', join_lines=1)
127 remove_modules = []
128 while 1:
129 line = input.readline()
130 if not line: break
131 line = line.split()
132 remove_modules.append( line[0] )
133 input.close()
Michael W. Hudson5b109102002-01-23 15:04:41 +0000134
Andrew M. Kuchling8d7f0862001-02-23 16:32:32 +0000135 for ext in self.extensions[:]:
136 if ext.name in remove_modules:
137 self.extensions.remove(ext)
Michael W. Hudson5b109102002-01-23 15:04:41 +0000138
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000139 # When you run "make CC=altcc" or something similar, you really want
140 # those environment variables passed into the setup.py phase. Here's
141 # a small set of useful ones.
142 compiler = os.environ.get('CC')
143 linker_so = os.environ.get('LDSHARED')
144 args = {}
145 # unfortunately, distutils doesn't let us provide separate C and C++
146 # compilers
147 if compiler is not None:
Martin v. Löwis3e4b0e82001-08-10 08:56:17 +0000148 (ccshared,opt) = sysconfig.get_config_vars('CCSHARED','OPT')
149 args['compiler_so'] = compiler + ' ' + opt + ' ' + ccshared
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000150 if linker_so is not None:
Martin v. Löwis2f20dab2001-10-08 13:18:37 +0000151 args['linker_so'] = linker_so
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000152 self.compiler.set_executables(**args)
153
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000154 build_ext.build_extensions(self)
155
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000156 def build_extension(self, ext):
157
158 try:
159 build_ext.build_extension(self, ext)
160 except (CCompilerError, DistutilsError), why:
161 self.announce('WARNING: building of extension "%s" failed: %s' %
162 (ext.name, sys.exc_info()[1]))
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000163 return
Jack Jansenf49c6f92001-11-01 14:44:15 +0000164 # Workaround for Mac OS X: The Carbon-based modules cannot be
165 # reliably imported into a command-line Python
166 if 'Carbon' in ext.extra_link_args:
Michael W. Hudson5b109102002-01-23 15:04:41 +0000167 self.announce(
168 'WARNING: skipping import check for Carbon-based "%s"' %
169 ext.name)
170 return
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000171 try:
172 __import__(ext.name)
173 except ImportError:
174 self.announce('WARNING: removing "%s" since importing it failed' %
175 ext.name)
176 assert not self.inplace
177 fullname = self.get_ext_fullname(ext.name)
178 ext_filename = os.path.join(self.build_lib,
179 self.get_ext_filename(fullname))
180 os.remove(ext_filename)
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000181
Fred Drake9028d0a2001-12-06 22:59:54 +0000182 # XXX -- This relies on a Vile HACK in
183 # distutils.command.build_ext.build_extension(). The
184 # _built_objects attribute is stored there strictly for
185 # use here.
186 for filename in self._built_objects:
187 os.remove(filename)
188
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000189 def get_platform (self):
Fredrik Lundhade711a2001-01-24 08:00:28 +0000190 # Get value of sys.platform
191 platform = sys.platform
192 if platform[:6] =='cygwin':
193 platform = 'cygwin'
Andrew M. Kuchling3c044942001-02-06 23:37:23 +0000194 elif platform[:4] =='beos':
195 platform = 'beos'
Jack Jansen244e7612001-12-05 15:54:29 +0000196 elif platform[:6] == 'darwin':
197 platform = 'darwin'
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000198
Fredrik Lundhade711a2001-01-24 08:00:28 +0000199 return platform
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000200
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000201 def detect_modules(self):
Fredrik Lundhade711a2001-01-24 08:00:28 +0000202 # Ensure that /usr/local is always used
Michael W. Hudson39230b32002-01-16 15:26:48 +0000203 add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
204 add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
205
206 add_dir_to_list(self.compiler.library_dirs,
207 sysconfig.get_config_var("LIBDIR"))
208 add_dir_to_list(self.compiler.include_dirs,
209 sysconfig.get_config_var("INCLUDEDIR"))
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000210
Martin v. Löwis339d0f72001-08-17 18:39:25 +0000211 try:
212 have_unicode = unicode
213 except NameError:
214 have_unicode = 0
215
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000216 # lib_dirs and inc_dirs are used to search for files;
217 # if a file is found in one of those directories, it can
218 # be assumed that no additional -I,-L directives are needed.
219 lib_dirs = self.compiler.library_dirs + ['/lib', '/usr/lib']
Michael W. Hudson5b109102002-01-23 15:04:41 +0000220 inc_dirs = self.compiler.include_dirs + ['/usr/include']
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000221 exts = []
222
Fredrik Lundhade711a2001-01-24 08:00:28 +0000223 platform = self.get_platform()
Michael W. Hudson5b109102002-01-23 15:04:41 +0000224
Fredrik Lundhade711a2001-01-24 08:00:28 +0000225 # Check for MacOS X, which doesn't need libm.a at all
226 math_libs = ['m']
Jack Jansen244e7612001-12-05 15:54:29 +0000227 if platform in ['darwin', 'beos']:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000228 math_libs = []
Michael W. Hudson5b109102002-01-23 15:04:41 +0000229
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000230 # XXX Omitted modules: gl, pure, dl, SGI-specific modules
231
232 #
233 # The following modules are all pretty straightforward, and compile
234 # on pretty much any POSIXish platform.
235 #
Fredrik Lundhade711a2001-01-24 08:00:28 +0000236
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000237 # Some modules that are normally always on:
238 exts.append( Extension('regex', ['regexmodule.c', 'regexpr.c']) )
239 exts.append( Extension('pcre', ['pcremodule.c', 'pypcre.c']) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000240
Fred Drake3a40f322001-10-12 21:00:48 +0000241 exts.append( Extension('_hotshot', ['_hotshot.c']) )
Fred Drake2de74712001-02-01 05:26:54 +0000242 exts.append( Extension('_weakref', ['_weakref.c']) )
Andrew M. Kuchlingd5c43062001-01-17 15:59:25 +0000243 exts.append( Extension('xreadlines', ['xreadlinesmodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000244
245 # array objects
246 exts.append( Extension('array', ['arraymodule.c']) )
247 # complex math library functions
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000248 exts.append( Extension('cmath', ['cmathmodule.c'],
249 libraries=math_libs) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000250
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000251 # math library functions, e.g. sin()
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000252 exts.append( Extension('math', ['mathmodule.c'],
253 libraries=math_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000254 # fast string operations implemented in C
255 exts.append( Extension('strop', ['stropmodule.c']) )
256 # time operations and variables
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000257 exts.append( Extension('time', ['timemodule.c'],
258 libraries=math_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000259 # operator.add() and similar goodies
260 exts.append( Extension('operator', ['operator.c']) )
261 # access to the builtin codecs and codec registry
262 exts.append( Extension('_codecs', ['_codecsmodule.c']) )
Marc-André Lemburg261b8e22001-02-02 12:12:44 +0000263 # Python C API test module
Tim Petersd66595f2001-02-04 03:09:53 +0000264 exts.append( Extension('_testcapi', ['_testcapimodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000265 # static Unicode character database
Martin v. Löwis339d0f72001-08-17 18:39:25 +0000266 if have_unicode:
267 exts.append( Extension('unicodedata', ['unicodedata.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000268 # access to ISO C locale support
269 exts.append( Extension('_locale', ['_localemodule.c']) )
270
271 # Modules with some UNIX dependencies -- on by default:
272 # (If you have a really backward UNIX, select and socket may not be
273 # supported...)
274
275 # fcntl(2) and ioctl(2)
276 exts.append( Extension('fcntl', ['fcntlmodule.c']) )
277 # pwd(3)
278 exts.append( Extension('pwd', ['pwdmodule.c']) )
279 # grp(3)
280 exts.append( Extension('grp', ['grpmodule.c']) )
281 # posix (UNIX) errno values
282 exts.append( Extension('errno', ['errnomodule.c']) )
283 # select(2); not on ancient System V
284 exts.append( Extension('select', ['selectmodule.c']) )
285
286 # The md5 module implements the RSA Data Security, Inc. MD5
Fred Drake38419c02001-12-06 22:24:47 +0000287 # Message-Digest Algorithm, described in RFC 1321. The
288 # necessary files md5c.c and md5.h are included here.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000289 exts.append( Extension('md5', ['md5module.c', 'md5c.c']) )
290
291 # The sha module implements the SHA checksum algorithm.
292 # (NIST's Secure Hash Algorithm.)
293 exts.append( Extension('sha', ['shamodule.c']) )
294
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000295 # Helper module for various ascii-encoders
296 exts.append( Extension('binascii', ['binascii.c']) )
297
298 # Fred Drake's interface to the Python parser
299 exts.append( Extension('parser', ['parsermodule.c']) )
300
301 # Digital Creations' cStringIO and cPickle
302 exts.append( Extension('cStringIO', ['cStringIO.c']) )
303 exts.append( Extension('cPickle', ['cPickle.c']) )
304
305 # Memory-mapped files (also works on Win32).
306 exts.append( Extension('mmap', ['mmapmodule.c']) )
307
308 # Lance Ellinghaus's modules:
309 # enigma-inspired encryption
310 exts.append( Extension('rotor', ['rotormodule.c']) )
311 # syslog daemon interface
312 exts.append( Extension('syslog', ['syslogmodule.c']) )
313
314 # George Neville-Neil's timing module:
315 exts.append( Extension('timing', ['timingmodule.c']) )
316
317 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000318 # Here ends the simple stuff. From here on, modules need certain
319 # libraries, are platform-specific, or present other surprises.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000320 #
321
322 # Multimedia modules
323 # These don't work for 64-bit platforms!!!
324 # These represent audio samples or images as strings:
325
Fredrik Lundhade711a2001-01-24 08:00:28 +0000326 # Disabled on 64-bit platforms
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000327 if sys.maxint != 9223372036854775807L:
328 # Operations on audio samples
329 exts.append( Extension('audioop', ['audioop.c']) )
330 # Operations on images
331 exts.append( Extension('imageop', ['imageop.c']) )
332 # Read SGI RGB image files (but coded portably)
333 exts.append( Extension('rgbimg', ['rgbimgmodule.c']) )
334
335 # readline
Marc-André Lemburg2efc3232001-01-26 18:23:02 +0000336 if self.compiler.find_library_file(lib_dirs, 'readline'):
337 readline_libs = ['readline']
Andrew M. Kuchling5aa3c4a2001-08-16 20:30:18 +0000338 if self.compiler.find_library_file(lib_dirs,
339 'ncurses'):
340 readline_libs.append('ncurses')
341 elif self.compiler.find_library_file(lib_dirs +
Marc-André Lemburg2efc3232001-01-26 18:23:02 +0000342 ['/usr/lib/termcap'],
343 'termcap'):
344 readline_libs.append('termcap')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000345 exts.append( Extension('readline', ['readline.c'],
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000346 library_dirs=['/usr/lib/termcap'],
Marc-André Lemburg2efc3232001-01-26 18:23:02 +0000347 libraries=readline_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000348
Andrew M. Kuchling5aa3c4a2001-08-16 20:30:18 +0000349 # crypt module.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000350
351 if self.compiler.find_library_file(lib_dirs, 'crypt'):
352 libs = ['crypt']
353 else:
354 libs = []
355 exts.append( Extension('crypt', ['cryptmodule.c'], libraries=libs) )
356
357 # socket(2)
358 # Detect SSL support for the socket module
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000359 ssl_incs = find_file('openssl/ssl.h', inc_dirs,
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +0000360 ['/usr/local/ssl/include',
361 '/usr/contrib/ssl/include/'
362 ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000363 )
364 ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs,
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +0000365 ['/usr/local/ssl/lib',
366 '/usr/contrib/ssl/lib/'
367 ] )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000368
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000369 if (ssl_incs is not None and
370 ssl_libs is not None):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000371 exts.append( Extension('_socket', ['socketmodule.c'],
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000372 include_dirs = ssl_incs,
Fredrik Lundhade711a2001-01-24 08:00:28 +0000373 library_dirs = ssl_libs,
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000374 libraries = ['ssl', 'crypto'],
375 define_macros = [('USE_SSL',1)] ) )
376 else:
377 exts.append( Extension('_socket', ['socketmodule.c']) )
378
379 # Modules that provide persistent dictionary-like semantics. You will
380 # probably want to arrange for at least one of them to be available on
381 # your machine, though none are defined by default because of library
382 # dependencies. The Python module anydbm.py provides an
383 # implementation independent wrapper for these; dumbdbm.py provides
384 # similar functionality (but slower of course) implemented in Python.
385
386 # The standard Unix dbm module:
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000387 if platform not in ['cygwin']:
388 if (self.compiler.find_library_file(lib_dirs, 'ndbm')):
389 exts.append( Extension('dbm', ['dbmmodule.c'],
390 libraries = ['ndbm'] ) )
Neil Schemenauerc3ffef62001-10-21 22:14:44 +0000391 elif self.compiler.find_library_file(lib_dirs, 'db1'):
392 exts.append( Extension('dbm', ['dbmmodule.c'],
393 libraries = ['db1'] ) )
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000394 else:
395 exts.append( Extension('dbm', ['dbmmodule.c']) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000396
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000397 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
398 if (self.compiler.find_library_file(lib_dirs, 'gdbm')):
399 exts.append( Extension('gdbm', ['gdbmmodule.c'],
400 libraries = ['gdbm'] ) )
401
402 # Berkeley DB interface.
403 #
404 # This requires the Berkeley DB code, see
405 # ftp://ftp.cs.berkeley.edu/pub/4bsd/db.1.85.tar.gz
406 #
407 # Edit the variables DB and DBPORT to point to the db top directory
408 # and the subdirectory of PORT where you built it.
409 #
Greg Ward02fac832001-09-13 15:05:08 +0000410 # (See http://pybsddb.sourceforge.net/ for an interface to
411 # Berkeley DB 3.x.)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000412
Andrew M. Kuchlinge06337a2001-02-23 16:27:48 +0000413 dblib = []
Martin v. Löwisf5c76772001-11-24 09:28:42 +0000414 if self.compiler.find_library_file(lib_dirs, 'db-3.2'):
415 dblib = ['db-3.2']
416 elif self.compiler.find_library_file(lib_dirs, 'db-3.1'):
Skip Montanaroe81f4472001-08-21 04:23:21 +0000417 dblib = ['db-3.1']
Neil Schemenauerc3ffef62001-10-21 22:14:44 +0000418 elif self.compiler.find_library_file(lib_dirs, 'db3'):
419 dblib = ['db3']
Skip Montanaroe81f4472001-08-21 04:23:21 +0000420 elif self.compiler.find_library_file(lib_dirs, 'db2'):
421 dblib = ['db2']
422 elif self.compiler.find_library_file(lib_dirs, 'db1'):
423 dblib = ['db1']
424 elif self.compiler.find_library_file(lib_dirs, 'db'):
Andrew M. Kuchlinge06337a2001-02-23 16:27:48 +0000425 dblib = ['db']
Michael W. Hudson5b109102002-01-23 15:04:41 +0000426
Andrew M. Kuchlinge06337a2001-02-23 16:27:48 +0000427 db185_incs = find_file('db_185.h', inc_dirs,
428 ['/usr/include/db3', '/usr/include/db2'])
429 db_inc = find_file('db.h', inc_dirs, ['/usr/include/db1'])
430 if db185_incs is not None:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000431 exts.append( Extension('bsddb', ['bsddbmodule.c'],
Andrew M. Kuchlinge06337a2001-02-23 16:27:48 +0000432 include_dirs = db185_incs,
433 define_macros=[('HAVE_DB_185_H',1)],
434 libraries = dblib ) )
435 elif db_inc is not None:
436 exts.append( Extension('bsddb', ['bsddbmodule.c'],
437 include_dirs = db_inc,
438 libraries = dblib) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000439
440 # The mpz module interfaces to the GNU Multiple Precision library.
Fredrik Lundhade711a2001-01-24 08:00:28 +0000441 # You need to ftp the GNU MP library.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000442 # This was originally written and tested against GMP 1.2 and 1.3.2.
443 # 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 +0000444 # haven't tested it recently, and it definitely doesn't work with
445 # GMP 4.0. For more complete modules, refer to
446 # http://gmpy.sourceforge.net and
447 # http://www.egenix.com/files/python/mxNumber.html
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000448
Greg Ward57fc2102001-10-03 19:59:30 +0000449 # A compatible MP library unencumbered by the GPL also exists. It was
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000450 # posted to comp.sources.misc in volume 40 and is widely available from
451 # FTP archive sites. One URL for it is:
452 # ftp://gatekeeper.dec.com/.b/usenet/comp.sources.misc/volume40/fgmp/part01.Z
453
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000454 if (self.compiler.find_library_file(lib_dirs, 'gmp')):
455 exts.append( Extension('mpz', ['mpzmodule.c'],
456 libraries = ['gmp'] ) )
457
458
459 # Unix-only modules
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000460 if platform not in ['mac', 'win32']:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000461 # Steen Lumholt's termios module
462 exts.append( Extension('termios', ['termios.c']) )
463 # Jeremy Hylton's rlimit interface
Andrew M. Kuchlingfda3c3d2001-09-17 16:19:16 +0000464 exts.append( Extension('resource', ['resource.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000465
Andrew M. Kuchlingcf393f32001-02-21 02:38:24 +0000466 # Sun yellow pages. Some systems have the functions in libc.
Andrew M. Kuchling6efc6e72001-02-27 20:54:23 +0000467 if platform not in ['cygwin']:
468 if (self.compiler.find_library_file(lib_dirs, 'nsl')):
469 libs = ['nsl']
470 else:
471 libs = []
472 exts.append( Extension('nis', ['nismodule.c'],
473 libraries = libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000474
475 # Curses support, requring the System V version of curses, often
Fredrik Lundhade711a2001-01-24 08:00:28 +0000476 # provided by the ncurses library.
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000477 if platform == 'sunos4':
Andrew M. Kuchlingb69c7582001-02-28 19:49:57 +0000478 inc_dirs += ['/usr/5include']
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000479 lib_dirs += ['/usr/5lib']
480
481 if (self.compiler.find_library_file(lib_dirs, 'ncurses')):
482 curses_libs = ['ncurses']
483 exts.append( Extension('_curses', ['_cursesmodule.c'],
484 libraries = curses_libs) )
Fred Drake38419c02001-12-06 22:24:47 +0000485 elif (self.compiler.find_library_file(lib_dirs, 'curses')
486 and platform != 'darwin'):
Michael W. Hudson5b109102002-01-23 15:04:41 +0000487 # OSX has an old Berkeley curses, not good enough for
488 # the _curses module.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000489 if (self.compiler.find_library_file(lib_dirs, 'terminfo')):
490 curses_libs = ['curses', 'terminfo']
491 else:
492 curses_libs = ['curses', 'termcap']
Fredrik Lundhade711a2001-01-24 08:00:28 +0000493
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000494 exts.append( Extension('_curses', ['_cursesmodule.c'],
495 libraries = curses_libs) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000496
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000497 # If the curses module is enabled, check for the panel module
Andrew M. Kuchlinge7ffbb22001-12-06 15:57:16 +0000498 if (module_enabled(exts, '_curses') and
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000499 self.compiler.find_library_file(lib_dirs, 'panel')):
500 exts.append( Extension('_curses_panel', ['_curses_panel.c'],
501 libraries = ['panel'] + curses_libs) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000502
503
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000504
505 # Lee Busby's SIGFPE modules.
506 # The library to link fpectl with is platform specific.
507 # Choose *one* of the options below for fpectl:
508
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000509 if platform == 'irix5':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000510 # For SGI IRIX (tested on 5.3):
511 exts.append( Extension('fpectl', ['fpectlmodule.c'],
512 libraries=['fpe']) )
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000513 elif 0: # XXX how to detect SunPro?
Fred Drake38419c02001-12-06 22:24:47 +0000514 # For Solaris with SunPro compiler (tested on Solaris 2.5
515 # with SunPro C 4.2): (Without the compiler you don't have
516 # -lsunmath.)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000517 #fpectl fpectlmodule.c -R/opt/SUNWspro/lib -lsunmath -lm
518 pass
519 else:
520 # For other systems: see instructions in fpectlmodule.c.
521 #fpectl fpectlmodule.c ...
522 exts.append( Extension('fpectl', ['fpectlmodule.c']) )
523
524
525 # Andrew Kuchling's zlib module.
526 # This require zlib 1.1.3 (or later).
527 # See http://www.cdrom.com/pub/infozip/zlib/
Guido van Rossume6970912001-04-15 15:16:12 +0000528 zlib_inc = find_file('zlib.h', [], inc_dirs)
529 if zlib_inc is not None:
530 zlib_h = zlib_inc[0] + '/zlib.h'
531 version = '"0.0.0"'
532 version_req = '"1.1.3"'
533 fp = open(zlib_h)
534 while 1:
535 line = fp.readline()
536 if not line:
537 break
538 if line.find('#define ZLIB_VERSION', 0) == 0:
539 version = line.split()[2]
540 break
541 if version >= version_req:
542 if (self.compiler.find_library_file(lib_dirs, 'z')):
543 exts.append( Extension('zlib', ['zlibmodule.c'],
544 libraries = ['z']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000545
546 # Interface to the Expat XML parser
547 #
548 # Expat is written by James Clark and must be downloaded separately
549 # (see below). The pyexpat module was written by Paul Prescod after a
550 # prototype by Jack Jansen.
551 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000552 # The Expat dist includes Windows .lib and .dll files. Home page is
553 # at http://www.jclark.com/xml/expat.html, the current production
554 # release is always ftp://ftp.jclark.com/pub/xml/expat.zip.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000555 #
556 # EXPAT_DIR, below, should point to the expat/ directory created by
557 # unpacking the Expat source distribution.
558 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000559 # Note: the expat build process doesn't yet build a libexpat.a; you
560 # can do this manually while we try convince the author to add it. To
561 # do so, cd to EXPAT_DIR, run "make" if you have not done so, then
562 # run:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000563 #
564 # ar cr libexpat.a xmltok/*.o xmlparse/*.o
565 #
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000566 expat_defs = []
567 expat_incs = find_file('expat.h', inc_dirs, [])
568 if expat_incs is not None:
569 # expat.h was found
570 expat_defs = [('HAVE_EXPAT_H', 1)]
571 else:
572 expat_incs = find_file('xmlparse.h', inc_dirs, [])
Fredrik Lundhade711a2001-01-24 08:00:28 +0000573
Martin v. Löwis1ab29b22001-01-21 10:54:52 +0000574 if (expat_incs is not None and
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000575 self.compiler.find_library_file(lib_dirs, 'expat')):
576 exts.append( Extension('pyexpat', ['pyexpat.c'],
577 define_macros = expat_defs,
578 libraries = ['expat']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000579
Michael W. Hudson5b109102002-01-23 15:04:41 +0000580 # Dynamic loading module
Martin v. Löwis93227272002-01-01 20:18:30 +0000581 dl_inc = find_file('dlfcn.h', [], inc_dirs)
582 if dl_inc is not None:
Michael W. Hudson5b109102002-01-23 15:04:41 +0000583 exts.append( Extension('dl', ['dlmodule.c']) )
584
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000585 # Platform-specific libraries
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000586 if platform == 'linux2':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000587 # Linux-specific modules
588 exts.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) )
589
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000590 if platform == 'sunos5':
Fredrik Lundhade711a2001-01-24 08:00:28 +0000591 # SunOS specific modules
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000592 exts.append( Extension('sunaudiodev', ['sunaudiodev.c']) )
Michael W. Hudson5b109102002-01-23 15:04:41 +0000593
Jack Jansen244e7612001-12-05 15:54:29 +0000594 if platform == 'darwin':
Jack Jansen144ebcc2001-08-05 22:31:19 +0000595 # Mac OS X specific modules. These are ported over from MacPython
596 # and still experimental. Some (such as gestalt or icglue) are
597 # already generally useful, some (the GUI ones) really need to
598 # be used from a framework.
Jack Jansen2f760c32001-09-04 21:33:12 +0000599 #
600 # I would like to trigger on WITH_NEXT_FRAMEWORK but that isn't
601 # available here. This Makefile variable is also what the install
602 # procedure triggers on.
603 frameworkdir = sysconfig.get_config_var('PYTHONFRAMEWORKDIR')
Jack Jansen144ebcc2001-08-05 22:31:19 +0000604 exts.append( Extension('gestalt', ['gestaltmodule.c']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000605 exts.append( Extension('MacOS', ['macosmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000606 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000607 exts.append( Extension('icglue', ['icgluemodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000608 extra_link_args=['-framework', 'Carbon']) )
Fred Drake38419c02001-12-06 22:24:47 +0000609 exts.append( Extension('macfs',
610 ['macfsmodule.c',
611 '../Python/getapplbycreator.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000612 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000613 exts.append( Extension('_CF', ['cf/_CFmodule.c']) )
614 exts.append( Extension('_Res', ['res/_Resmodule.c']) )
615 exts.append( Extension('_Snd', ['snd/_Sndmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000616 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen2f760c32001-09-04 21:33:12 +0000617 if frameworkdir:
Jack Jansen666b1e72001-10-31 12:11:48 +0000618 exts.append( Extension('Nav', ['Nav.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000619 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000620 exts.append( Extension('_AE', ['ae/_AEmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000621 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000622 exts.append( Extension('_App', ['app/_Appmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000623 extra_link_args=['-framework', 'Carbon']) )
Jack Jansendd67a8e2001-12-12 23:03:17 +0000624 exts.append( Extension('_CarbonEvt', ['carbonevt/_CarbonEvtmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000625 extra_link_args=['-framework', 'Carbon']) )
Just van Rossume9039b12001-12-13 13:41:36 +0000626 exts.append( Extension('_CG', ['cg/_CGmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000627 extra_link_args=['-framework', 'ApplicationServices',
Just van Rossume9039b12001-12-13 13:41:36 +0000628 '-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000629 exts.append( Extension('_Cm', ['cm/_Cmmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000630 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000631 exts.append( Extension('_Ctl', ['ctl/_Ctlmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000632 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000633 exts.append( Extension('_Dlg', ['dlg/_Dlgmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000634 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000635 exts.append( Extension('_Drag', ['drag/_Dragmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000636 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000637 exts.append( Extension('_Evt', ['evt/_Evtmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000638 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000639 exts.append( Extension('_Fm', ['fm/_Fmmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000640 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000641 exts.append( Extension('_Icn', ['icn/_Icnmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000642 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000643 exts.append( Extension('_List', ['list/_Listmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000644 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000645 exts.append( Extension('_Menu', ['menu/_Menumodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000646 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000647 exts.append( Extension('_Mlte', ['mlte/_Mltemodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000648 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000649 exts.append( Extension('_Qd', ['qd/_Qdmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000650 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000651 exts.append( Extension('_Qdoffs', ['qdoffs/_Qdoffsmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000652 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen2f760c32001-09-04 21:33:12 +0000653 exts.append( Extension('_Qt', ['qt/_Qtmodule.c'],
Fred Drake38419c02001-12-06 22:24:47 +0000654 extra_link_args=['-framework', 'QuickTime',
655 '-framework', 'Carbon']) )
Jack Jansen796720b2002-01-21 23:10:36 +0000656 exts.append( Extension('_Scrap', ['scrap/_Scrapmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000657 extra_link_args=['-framework', 'Carbon']) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000658 exts.append( Extension('_TE', ['te/_TEmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000659 extra_link_args=['-framework', 'Carbon']) )
Jack Jansenedeea042001-12-09 23:08:54 +0000660 # As there is no standardized place (yet) to put user-installed
661 # Mac libraries on OSX you should put a symlink to your Waste
662 # installation in the same folder as your python source tree.
663 # Or modify the next two lines:-)
664 waste_incs = find_file("WASTE.h", [], ["../waste/C_C++ Headers"])
665 waste_libs = find_library_file(self.compiler, "WASTE", [],
666 ["../waste/Static Libraries"])
667 if waste_incs != None and waste_libs != None:
Michael W. Hudson5b109102002-01-23 15:04:41 +0000668 exts.append( Extension('waste',
Jack Jansenedeea042001-12-09 23:08:54 +0000669 ['waste/wastemodule.c',
670 'Mac/Wastemods/WEObjectHandlers.c',
671 'Mac/Wastemods/WETabHooks.c',
672 'Mac/Wastemods/WETabs.c'
673 ],
674 include_dirs = waste_incs + ['Mac/Wastemods'],
675 library_dirs = waste_libs,
676 libraries = ['WASTE'],
677 extra_link_args = ['-framework', 'Carbon'],
678 ) )
Jack Jansen666b1e72001-10-31 12:11:48 +0000679 exts.append( Extension('_Win', ['win/_Winmodule.c'],
Michael W. Hudson5b109102002-01-23 15:04:41 +0000680 extra_link_args=['-framework', 'Carbon']) )
681
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000682 self.extensions.extend(exts)
683
684 # Call the method for detecting whether _tkinter can be compiled
685 self.detect_tkinter(inc_dirs, lib_dirs)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000686
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000687
688 def detect_tkinter(self, inc_dirs, lib_dirs):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000689 # The _tkinter module.
Michael W. Hudson5b109102002-01-23 15:04:41 +0000690
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000691 # Assume we haven't found any of the libraries or include files
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +0000692 # The versions with dots are used on Unix, and the versions without
693 # dots on Windows, for detection by cygwin.
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000694 tcllib = tklib = tcl_includes = tk_includes = None
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +0000695 for version in ['8.4', '84', '8.3', '83', '8.2',
696 '82', '8.1', '81', '8.0', '80']:
Michael W. Hudson5b109102002-01-23 15:04:41 +0000697 tklib = self.compiler.find_library_file(lib_dirs,
698 'tk' + version )
699 tcllib = self.compiler.find_library_file(lib_dirs,
700 'tcl' + version )
701 if tklib and tcllib:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000702 # Exit the loop when we've found the Tcl/Tk libraries
703 break
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000704
Fredrik Lundhade711a2001-01-24 08:00:28 +0000705 # Now check for the header files
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000706 if tklib and tcllib:
707 # Check for the include files on Debian, where
708 # they're put in /usr/include/{tcl,tk}X.Y
Andrew M. Kuchling9a3fd8c2001-02-06 22:15:27 +0000709 debian_tcl_include = [ '/usr/include/tcl' + version ]
Fred Drake38419c02001-12-06 22:24:47 +0000710 debian_tk_include = [ '/usr/include/tk' + version ] + \
711 debian_tcl_include
Andrew M. Kuchling9a3fd8c2001-02-06 22:15:27 +0000712 tcl_includes = find_file('tcl.h', inc_dirs, debian_tcl_include)
713 tk_includes = find_file('tk.h', inc_dirs, debian_tk_include)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000714
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000715 if (tcllib is None or tklib is None and
716 tcl_includes is None or tk_includes is None):
717 # Something's missing, so give up
718 return
Fredrik Lundhade711a2001-01-24 08:00:28 +0000719
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000720 # OK... everything seems to be present for Tcl/Tk.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000721
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000722 include_dirs = [] ; libs = [] ; defs = [] ; added_lib_dirs = []
723 for dir in tcl_includes + tk_includes:
724 if dir not in include_dirs:
725 include_dirs.append(dir)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000726
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000727 # Check for various platform-specific directories
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000728 platform = self.get_platform()
729 if platform == 'sunos5':
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000730 include_dirs.append('/usr/openwin/include')
731 added_lib_dirs.append('/usr/openwin/lib')
732 elif os.path.exists('/usr/X11R6/include'):
733 include_dirs.append('/usr/X11R6/include')
734 added_lib_dirs.append('/usr/X11R6/lib')
735 elif os.path.exists('/usr/X11R5/include'):
736 include_dirs.append('/usr/X11R5/include')
737 added_lib_dirs.append('/usr/X11R5/lib')
738 else:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000739 # Assume default location for X11
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000740 include_dirs.append('/usr/X11/include')
741 added_lib_dirs.append('/usr/X11/lib')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000742
Andrew M. Kuchling89fb72d2001-09-18 20:32:13 +0000743 # If Cygwin, then verify that X is installed before proceeding
744 if platform == 'cygwin':
745 x11_inc = find_file('X11/Xlib.h', [], inc_dirs)
746 if x11_inc is None:
747 # X header files missing, so give up
748 return
749
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000750 # Check for BLT extension
Fred Drake38419c02001-12-06 22:24:47 +0000751 if self.compiler.find_library_file(lib_dirs + added_lib_dirs,
752 'BLT8.0'):
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000753 defs.append( ('WITH_BLT', 1) )
754 libs.append('BLT8.0')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000755
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000756 # Add the Tcl/Tk libraries
Fredrik Lundhade711a2001-01-24 08:00:28 +0000757 libs.append('tk'+version)
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000758 libs.append('tcl'+version)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000759
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000760 if platform in ['aix3', 'aix4']:
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000761 libs.append('ld')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000762
Martin v. Löwis3db5b8c2001-07-24 06:54:01 +0000763 # Finally, link with the X11 libraries (not appropriate on cygwin)
764 if platform != "cygwin":
765 libs.append('X11')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000766
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000767 ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
768 define_macros=[('WITH_APPINIT', 1)] + defs,
769 include_dirs = include_dirs,
770 libraries = libs,
771 library_dirs = added_lib_dirs,
772 )
773 self.extensions.append(ext)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000774
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000775 # XXX handle these, but how to detect?
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000776 # *** Uncomment and edit for PIL (TkImaging) extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000777 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000778 # *** Uncomment and edit for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000779 # -DWITH_TOGL togl.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000780 # *** Uncomment these for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000781 # -lGL -lGLU -lXext -lXmu \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000782
Andrew M. Kuchlingf52d27e2001-05-21 20:29:27 +0000783class PyBuildInstall(install):
784 # Suppress the warning about installation into the lib_dynload
785 # directory, which is not in sys.path when running Python during
786 # installation:
787 def initialize_options (self):
788 install.initialize_options(self)
789 self.warn_dir=0
Michael W. Hudson5b109102002-01-23 15:04:41 +0000790
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000791def main():
Andrew M. Kuchling62686692001-05-21 20:48:09 +0000792 # turn off warnings when deprecated modules are imported
793 import warnings
794 warnings.filterwarnings("ignore",category=DeprecationWarning)
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000795 setup(name = 'Python standard library',
Neil Schemenauere7e2ece2001-01-17 21:58:00 +0000796 version = '%d.%d' % sys.version_info[:2],
Andrew M. Kuchlingf52d27e2001-05-21 20:29:27 +0000797 cmdclass = {'build_ext':PyBuildExt, 'install':PyBuildInstall},
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000798 # The struct module is defined here, because build_ext won't be
799 # called unless there's at least one extension module defined.
Andrew M. Kuchlingaece4272001-02-28 20:56:49 +0000800 ext_modules=[Extension('struct', ['structmodule.c'])],
801
802 # Scripts to install
803 scripts = ['Tools/scripts/pydoc']
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000804 )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000805
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000806# --install-platlib
807if __name__ == '__main__':
808 sysconfig.set_python_build()
809 main()